In Vim, how can I shift a block of code to right?

Viewed 40783

I am using the Vim editor. Here is my situation:

1111111111111
2222222222222
3333333333333
4444444444444

Above is the original code, I want to make them like below. What should I do to shift them all to the right?

    1111111111111
    2222222222222
    3333333333333
    4444444444444
9 Answers
  1. Press Ctlt+v to select multiple lines.
  2. Type :
  3. Type sed substitute pattern matching s/^/ /g (e.g: for adding 4 spaces)
  4. Press enter

vim indent multiple lines

Vim follows sed to remove/add extra spaces from the start of lines like this:

sed -i 's/^/    /g'  test.txt
sed -i 's/^    //g'  test.txt
  1. Ctl+v # for the Visual Block mode
  2. Move with arrows up or down to select the block
  3. Once block is selected you can do >
  4. OR while block is selected click on 'I'. Cursor will move to the first selected line in Insert mode.
  5. Start moving it by adding spaces. Dont worry that only first line moves.
  6. Once first line is aligned as you expected hit Esc and then arrow down
Related