How to clear the line number in Vim when copying?

2020-02-02 06:16发布

I copy some code from one part of one file to another part in vim, I find that, there are line numbers in each line and the format is gone, how to set correct format as origin ?

like this:

            40         root /opt/release/current/public;
 67             41         passenger_enabled on;
 68              42 

标签: linux vim
10条回答
家丑人穷心不美
2楼-- · 2020-02-02 06:42

Have a look at the pastetoggle option sometimes set to F11.

As an alternative you could always write the section you want to copy into a temporary file (ma, goto end line then use :'a,.w tempfile) then read it into the second file.

For further investigation you might want to look at the autoindent option.

查看更多
够拽才男人
3楼-- · 2020-02-02 06:43

If you have line numbers, I'm quite sure you are not using Vim's yank/put operations (these will never copy the linenumbers, foldcolumn, icons etc) because in terms of the edit buffer, they don't exist.

My guess is you are working in a terminal emulator and using the mouse to copy stuff to the clipboard, which possibly selects the 'extraneous' room of the screen (including virtual spaces at the end, line numbers, fold markers etc)

You might have luck setting

:se mouse+=a

in order to get the behaviour of the mouse like you expect it. Otherwise, do the selection with V<movement>...y (y for yank, which corresponds to 'copy')

Then on the destination use p (put at cursor), or P (put before cursor)

Let me know if that helped or you need more info

查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-02-02 06:45

On Windows VIM GUI: :set nu and then hold down Ctrl-Shift while highlighting the desired text with the mouse. This yanks the line numbers into the buffer.

查看更多
我命由我不由天
5楼-- · 2020-02-02 06:56

I mapped the below command to a key.
It strips the whitespace around the copied line numbers.
It ignores the line text and any blank lines behind.

:1,$s/^\s*[0-9]\+\s//\|1,$s/^\s*[0-9]\+\n/\r/<cr>
查看更多
登录 后发表回答