How can I indent a line by several steps in VIM? - vim

How can I indent a line by several steps in VIM?
To understand my question, see the example blow:
>> indents the current line by one step. 2>> indents two lines by one step Or V2> indents the current line by two steps.
Is there any way to repeat this action without going into visual mode?

While in normal mode, you can repeat your last keystroke by using the preiod key(.).

The answer is: :h shift-left-right

Related

How do I make vim's visual lines indent correctly?

When I press enter to create a logical line, vim keeps the indent of the previous line. However, for visual lines, since they are all one logical line, the new lines always start at first column. Is there a way to make new visual lines also auto-indent correctly?
Ok, I figured this out with some additional searching around on SO and google. I used set breakindent and set lbr and it now produces the output that I want.

Move to the beginning of New Line - VIM

while in insert mode in vim how do i move to a new line correctly indented.
In many editors this action would be CTRL+ENTER
There is a similar stackoverflow question here however this answer takes you back to the start of the current line SO start of current line
So assuming this is my code, my cursor is just at the T in POST and i want to go to the start of the next line or next line with correct indentation if its a function(using snippets for function so now great concern).
#app.route('/add', method=['POST | '])
expected result
#app.route('/add', method=['POST'])
|
I would use <esc>o. Assuming you have filetype plugin indent on in your vimrc o will automatically go to the correct indent level.
Search for indentation and map to some keys, so you cannot search for every time.
/^^I
^I is tab

vim 7.4 comment/uncomment lines in Vim without plugins

I tried out answers in What's a quick way to comment/uncomment lines in Vim?, but they don't work. Pressing shift i on visual mode after selection just brings me in insert mode. I run it with --noplugin, no use.
You might need to take visual block before proceeding , Ctrl-v to use it. More at help blockwise-visual
Then, use any nagivation keys like h,j,k,l, followed by I, then insert your comment character like # or // and finalize by Esc.
This should comment whole block.
To uncomment, repeat the same operation of visual block and navigation but replace I by any delete operation like x for # or 2x for //.
Hope this helps
There are many ways to comment/uncomment in Vim. Anyway, assuming "C++-style" comments, eg. // foobar…
Commenting a single line
I// <Esc>
Uncommenting a single line
^dw
Commenting several lines
vjjj
:'<,'>norm! I// <CR>
or
<C-v>jjj
I// <Esc>
Uncommenting several lines
vjjj
:'<,'>norm! ^dw<CR>
or
<C-v>jjjllld

Always indent in vim

So far I've always used xemacs for source code editing (C++), but for several reasons i'd like to switch to or at least try out vim. One of the very basic things is indentation, where I'm super happy with xemacs behaviour. However I have yet to find a solution for having this behaviour in vim.
What I'm talking about is basically the ability to press Tab in any position of a line, and the line will always be indented to the correct level. This means:
1) pressing Tab multiple times will not indent multiple times, instead the text will be (re-)aligned to the indentation level suitable for the current code
2) pressing Tab e.g. in the middle of a word will not insert spaces or a tab in between this word, but rather indent the whole line
Is it possible to achieve this with vim?
Currently I have:
filetype indent plugin on
set cident
set autoindent
set shiftwidth=3
set softtabstop=3
set expandtab
In normal mode, pressing == should fix the indentation of the current line.
You can fix the indentation of several lines by:
selecting them and pressing =,
using a motion, =},
using a text-object, =ip.
In insert mode, you can fix the indentation of the current line with <C-o>== but the insertion point moves as well. You are not supposed to do that kind of thing in insert mode anyway.

"Snappy" Indenting in Vim?

I'm just starting out in Vim. One feature I like is >> and << for indenting / unindenting a line without needing to place the cursor at the beginning of the line. I use a shiftwidth of 3, expanded to spaces.
My question is, when using >> or << is there a way to make that line "snap" to the nearest "perfect" indent? i.e. for me that would be the fourth column, seventh, tenth, and so on. This would be very handy to me at deeply nested indentation levels.
Alternatively (though slightly unsatisfying / less optimal): a way to remove all whitespace from the beginning of a line, then I could just use >> multiple times.
The shiftround option will round to the nearest shiftwidth amount of space.
Vim has automatic indentation modes. This is a somewhat big topic for one answer, but :help autoindent may be a good start.
Additionally, the == command will indent the current line according to the previous lines and the behavior of the current indent mode. (This applies the = filter to the current line.)
I usually apply == to a line first to "calibrate" it to the reference indentation, and from there fiddle with >> and <<.
Or, over multiple lines: visually select, then =.

Resources