Home  >  Q&A  >  body text

vim - Is it possible to maintain vertical alignment when pasting?

The system pasteboard contains the following content.

home
help
variables
vi compatibility
modelines
word&line completion
searching
text selection
markets
indenting
reformatting

I want to copy the file into the following format.

    home
    help
    variables
    vi compatibility
    modelines
    word&line completion
    searching
    text selection
    markets
    indenting
    reformatting

Excuse me, is there any way to be lazy?

The first time the cursor is at the beginning of the line, the result of using "+p to paste

home
help
variables
vi compatibility
modelines
word&line completion
searching
text selection
markets
indenting
reformatting

The second time the cursor is in the fifth column, use "+p to paste the result

    home
help
variables
vi compatibility
modelines
word&line completion
searching
text selection
markets
indenting
reformatting

Can I paste it like this at once?
The result of the first paste, run %s/^/ /g
The result of the second paste, run 1, $s/^/ /g
can get the following results, I think I achieved this result just once by being lazy. Can I do it?

    home
    help
    variables
    vi compatibility
    modelines
    word&line completion
    searching
    text selection
    markets
    indenting
    reformatting
巴扎黑巴扎黑2712 days ago565

reply all(5)I'll reply

  • 高洛峰

    高洛峰2017-05-16 16:35:57

    :set ai

    then i tab Ctrl-v

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-16 16:35:57

    "+pVG>

    reply
    0
  • ringa_lee

    ringa_lee2017-05-16 16:35:57

    Try setting it to automatic indentation

    :set autoindent

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-16 16:35:57

    :set paste

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 16:35:57

    First use shift+v to select one line, then press j to select multiple lines downwards, and finally shift + >, I don’t know if this is what you want.

    reply
    0
  • Cancelreply