Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indenting in vim #20

Open
th0bse opened this issue Feb 24, 2022 · 2 comments
Open

Indenting in vim #20

th0bse opened this issue Feb 24, 2022 · 2 comments

Comments

@th0bse
Copy link

th0bse commented Feb 24, 2022

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 :

  • v "visual mode" (select stuff)
  • 3 "repeat" the next thing "3 times"
  • j "move one line down" (which is being repeated 3 times)
  • > "indent"
    So the whole translated "sentence" (it is a very reasonable way to think of those "chains" of commands as sentences, you can even construct a complete formal language for them) would be this:
visually select 3 lines down, indent that

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

  • v again, "visual mode" (select something)
  • i "inside" (this is a modifier for addressing a text object. A bit more on that in the next bullet point.)
  • } the delimiter for the "inside" from before. This means, that the text object we want to interact with is everything inside the nearest curly brackets.
  • > "indent" again
visually select everything inside the nearest curly brackets, indent that

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
Copy link
Author

th0bse commented Feb 24, 2022

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants