1

Let's say I have a text file called index.html.slim that looks like this:

- if post.published?
    section.post
    h1 = post.title
    p = post.description
    a = link_to 'Read more', post

What I'd like to do is indent the last 3 lines so that the file looks like this:

- if post.published?
    section.post
      h1 = post.title
      p = post.description
      a = link_to 'Read more', post

What's the most efficient way to do this in Vim?

Right now to do this I would go to line 3 with 3 return, i to enter insert mode, spacebar twice to indent two characters and then esc to exit insert mode. To do this on line 4 and 5 I would move down with j and press . followed and then wq to save.

That's a total of 10 keystrokes. I'm sure there's a better way to accomplish this; however, I'm not sure what the best method is.

Andrew Hendrie
  • 6,205
  • 4
  • 40
  • 71

1 Answers1

1

One way to do is to select column and then insert 2 spaces for last 3 lines.

  • Move cursor to character h.
  • Press Ctrl+v to change to selection mode
  • move cursor 2 down using j twice
  • press I (capital i) to change to insert mode
  • now press space twice and hit esc and press any other key like j, that should do it.
Atri
  • 5,511
  • 5
  • 30
  • 40
  • @AndrewHendrie Did you press esc after 2 spaces? Try pressing any other key like `j` after you hit esc. I just tried it and it works. – Atri Jan 29 '16 at 03:33
  • right on - it works. moved me from 10 keystrokes down to 7. I still think there's got to be a more efficient way to do this though... – Andrew Hendrie Jan 29 '16 at 03:36
  • @AndrewHendrie Well, if there were lets say 100 lines you wanted to indent you could just do `G` instead of moving cursor down using `j`. That would save you lots of keystokes. – Atri Jan 29 '16 at 05:48