theicfire / vimsheet

Vim cheat sheet from beginners to pros
http://vimsheet.com
MIT License
609 stars 206 forks source link

Indenting in vim #20

Open th0bse opened 2 years ago

th0bse commented 2 years ago

The claim made on the website, that "indenting multiple lines" is a missing feature for vim is actually untrue, even for the old vi:

You correctly say that > is indent and < is unindent.

Now those operators can be combined with a motion, for example the infamous h, j, k or l for left, up, down or right respectively, which means that "indenting the next three lines" becomes:

v3j>

Which translates to :

Another example would be to indent everything inside a certain block delimited by a curly bracket (for example useful in programming), or indent one paragraph. That would look like this:

vi}>

Which translates to

This is actually the biggest difference in design philosophy of vi/vim and virtually every other editor, and also what makes it such a great tool for increasing productivity: You can quite literally speak with vim in some sort of "sentences" to tell it what to do. Combined with the extensibility of newer versions, this creates virtually endless options to chain these commands together.

th0bse commented 2 years ago

I just hacked this explanation together without having time to think about how to condense it into a "user friendly" and easy to understand cheatsheet format, but if you want me to, I can try to do just that some time in the future. Not sure when I'll have time tho.

theicfire commented 2 years ago

Thanks! I wasn't too clear about the indenting problem, so I made some edits. What I meant was repeatedly indenting/unindenting. In an interactive way. Something that typical IDEs make really easy. You can use things like gv to reselect, or . to repeat, but these are just cumbersome. My .vimrc has a way to re-select after an indent operation happens, to make it more intuitive.