Skip to content

Indenting in vim #20

Description

@th0bse

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions