tags:

views:

154

answers:

5

Hi all

I am using the VIM.Here is my situation:

1111111111111
2222222222222
3333333333333
4444444444444

Above is the original code, I want to make them like below. After I select these four lines, what should I do to shift them?

    1111111111111
    2222222222222
    3333333333333
    4444444444444

Best Regards,

+6  A: 

In command mode, you can use >> to indent a single line. 4>> will indent the current and next three lines.

How they're indented depends on a couple of things like your shiftwidth settings. I always have my shiftwidth and tabstop settings the same to avoid problems:

:set ts=4 sw=4

(for example).

paxdiablo
Nitpick: You use `>>` in *normal* mode; command mode is when you have typed `:` and are typing a command.
too much php
Actually, I'm going to dissent on that one. Vi has _always_ referred to command and insert modes, wikipedia errors notwithstanding :-). The colon commands are simply `ex` commands allowed in command mode by prefixing them with `:`.
paxdiablo
Vim does make a distinction between normal and command *line* mode, and it's important to remember that they are different, for purpose of mappings, etc. To avoid confusion, vim help will always refer to "normal mode". However `:help command-mode` will tell you about normal mode, and "this is also known as command mode".
nicholas a. evans
+1  A: 

Hit >

That's all.

Alok
+1  A: 

Use the > key.

Michael Ulm
A: 

Use v to select the block and then press > key.

Rumple Stiltskin
+5  A: 

If you've already selected the four lines in visual mode: > will shift them shiftwidth to the right. After they are shifted, the visual selection will be gone, but you can indent again via . (repeat last command).

If you are normal mode, with your cursor anywhere on the first line:

  • >> will indent that line,
  • 4>> will indent all four lines,
  • >3j will do the same thing in a different way (indent from this line to three lines down),
  • >} will indent all of the lines until the end of the paragraph (i.e. to the first empty line, see :help object-motions), and
  • >ap will indent all of the lines for a p-aragraph (see :help text-objects), even if your cursor isn't on the first line.

Again, you can repeat these commands via . for deeper indentation levels (or you can set shiftwidth appropriately).

If your file is nicely composed of "paragraphs" (and most of my code and prose is), I think you'll find the ap text-object to be the most common way to work on blocks of text like this. You can also use text-objects to speed up visual selection.

nicholas a. evans