From time to time I have to work with code that isn't indented to the level of indentation I have Vim set up to (4 spaces per level), usually after copy/pasting something in the file. I usually make do with << and >>. The problem is they don't jump to the next indentation level, they just add or subtract 4 spaces.
If I have code like this
if condition:
do this
do that
doing >> on do that will result in
if condition:
do this
do that
I want it to go to this
if condition:
do this
do that
Beside easily matching the indentation of the line above, I want it to jump to the next level of indentation, not add 4 spaces.
This is what I have in my .vimrc regarding indentation
:set tabstop=4 shiftwidth=4 expandtab
filetype plugin indent onin your.vimrc, filetype (and plugin) indentation-related rules will apply. I.e. check what yourtabstopvalue actually is (set tabstop?will do; same for the other settings), when editing, and change those values by adding your line to an 'after' file, something like: http://stackoverflow.com/a/159066/5000478 – VanLaser Oct 10 '16 at 13:43>>and<<respectively add and remove indent which is not what you want. What you want is "formatting", which is done with==. – romainl Oct 10 '16 at 14:01:nnoremap >> ^i<tab><esc>if you really want tab behaviour on>>– Wolfie Oct 10 '16 at 14:07==will jump to the level of the line above. While a good thing to know, it would not work in all cases I'm interested in. As an addition to the question, what I want is for>>and<<to indent/dedent up to the next multiple of shiftwidth from the border in that direction. – Dumitru Oct 10 '16 at 14:51==uses eitherequalexprorequalprgto reformat the given lines. – romainl Oct 10 '16 at 19:26'shiftround'option in your vimrc:set shiftround– user9433424 Oct 10 '16 at 19:39