开发者

Using regular paste (p) in normal mode breaks indentation - vim

I saw that there is an set paste option that allows c开发者_StackOverflow中文版orrect indentation when pasting from the system clipboard in terminal vim, but I miss how to paste from vim's buffer "inner clipboard" with the p or P command and apply = to the pasted text. Until now I manually do that.

Doing set paste or its inverse doesn't fix the indentation for the pasted text.

Could you help making a .vimrc mapping for it ? Or is there an built-in option for that ?

Thank you.


The ]p and ]P commands will paste and place the contents at the indentation of the current line instead of using the original indentation of the copied lines. For example:

line 1
line 2
    line 3
    line 4

Copying lines 2 & 3, moving to line 3 and pressing ]p would result in

line 1
line 2
    line 3
    line 2
        line 3
    line 4


Try ]p and ]P

From :help p:

["x]]p              or                                  ]p ]<MiddleMouse>
["x]]<MiddleMouse>      Like "p", but adjust the indent to the current line.
                        Using the mouse only works when 'mouse' contains 'n'
                        or 'a'.  {not in Vi}

["x][P              or                                  [P
["x]]P              or                                  ]P
["x][p              or                                  [p [<MiddleMouse>
["x][<MiddleMouse>      Like "P", but adjust the indent to the current line.
                        Using the mouse only works when 'mouse' contains 'n'
                        or 'a'.  {not in Vi}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜