开发者

How to break lines before one column?

I want to insert return before one column of multiple lines, so I select the characters of this column with Ctrl+V in normal mode, then type I, Vim enters insert mode. After typing Enter key, and press key Esc, only one line is broken. Is there any way to perf开发者_Go百科orm this function? Thanks.


To break lines just before a particular column, use \%v search pattern atom that matches in a given position with zero-width (see :help /\%v). The following example command inserts new line character between the seventh and the eighth columns.

:%s/\%8v/\r/

This idea could be extended to use the number of the column where the cursor is currently located.

:exe'%s/\%'.virtcol('.').'v/\r/'

The commands above does not require neither of those columns to be selected. However, if it is easier for you to specify the split column with blockwise Visual mode, use \%V zero-width atom matching inside the selected area (see :help \%V).

:'<,'>s/\%V/\r/


quick and dirty solution - first, insert some character which is not in column (say, #) , then, gv, then '<,'>s/#/\r/g.

will be glad if one provide more clever solution.


After selecting the desired lines, to break on third column:

:'<,'>g/./norm! 3|a^M

(^M inserted by pressing <c-v><CR> or <c-q><CR>)

, similar to answer on Find every third value and insert cr or newline in VIM

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜