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
In normal mode, type
:se nonu
This is the easiest way to remove the line numbers and you will be able to copy the text without the line numbers.
All the previously entered solution are very good one. However, sometimes your are using vim on a remote server (so you cant copy to your clipboard using
"+y
). Often terminals support copy paste operation.I use vim to output visual selection to a new shell where I can copy text using terminal feature:
Then I can easily copy the output.
Same pattern for pasting in vim:
Then I paste and send EOF to cat using Ctrl+d. This method also avoid reindenting the text you paste (Note: you can disable automatic indentation using
:set pi!
).You can also consider using
sed
andpbcopy
to copy the lines to a clipboard, where you can paste to another terminal or apps outside of vim.sed -n <line start #>,<line end #>p <file name> | pbcopy
In case anyone wants a quicker way (on Linux anyways), I have noticed in vim you can hold down ctrl and drag over the region you want to copy and you'll avoid the line numbers and select the part you want.
Steps:
A permanent solution for this is to add the below code at the end of your
.vimrc
file located in your home directory.By adding this you will be able to select only text and not the line numbers as shown in below image:
If you are not getting your
.vimrc
file in your home directory (i faced this problem), type the command:scriptnames
in vi editor, it will display the location of your.vimrc
file. ReferenceOn Mac: I found out that you can select the desired area with Option+Command and copy paste it to another editor.