I have been using vim for about 3 weeks now and have been having problem with tabs.
What I usually do is do gg
to go to the top, do a ctrl+v
for visual block, do a G
to select everything to below(one column), do a $
to select to the right, then press <
or >
to tab.
However having to do all this, I lose the selection and I have to do all those commands to do another tab.
How do I not lose selection? Or is there a better way?
NOTE: I sometimes don't need to select everything sometimes just a portion of the file.
To reselect a visual selection use the gv
command followed by your command. Although this is not the best way.
Instead select the whole buffer with ggVG
then indent with >
. This will indent the selection. To repeat the command again just press .
. The .
command will repeat the last normal command, in this case the >
command. If you have indent a few times to many just use the undo command, u
, as many times as necessary. This vimcast is a great screencast describing this technique and this one describe more indention techniques.
Others prefer the following mappings:
xnoremap <Tab> >gv
xnoremap <S-Tab> <gv
I am not sure what is important here: being able to do multiple indents in a single go or keeping the visual block. Assuming you want to do multiple indents, just prefix the >
with a number, e.g. 3>
will indent the selected block three times.
Also, you don't need to select the entire line to indent it (i.e. the $
is not needed).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With