Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the line number in Vim when copying?

Tags:

linux

vim

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  
like image 975
why Avatar asked Apr 20 '11 09:04

why


People also ask

How do you not copy line numbers in vim?

Make the vi/vim text editor show or hide line numbers Press ESC key. At the : prompt type the following command to run on line numbers: set number. To turn off line numbering, type the following command at the : prompt set nonumber.

How do I move line numbers in vim?

The Vim goto line number command For example, press [ESC] key and type 10G (Shift-g) goto line number 10.

How do I copy line numbers in vi?

Press the ESC key to be sure you are in vi Command mode. Place the cursor on the first line of the text you wish to copy. Type 12yy to copy the 12 lines. Move the cursor to the place where you wish to insert the copied lines.

How do I delete a specific line in Vim?

Deleting a single line in Vim editor: First, bring your cursor to the line you want to delete. Press the “Esc” key to change the mode. Now type, “:d”, and press “Enter” to delete the line or quickly press “dd”.


2 Answers

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

like image 143
sehe Avatar answered Oct 27 '22 08:10

sehe


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.

like image 26
Sandeep Singh Avatar answered Oct 27 '22 10:10

Sandeep Singh