tags:

views:

350

answers:

7

So I've figured out how to add line numbers to vim (:set no or :set number) but how can I make it so that when I use my mouse in a terminal emulator to select a block of lines, it does not also select the numbers?

For example, say I have three lines that look like so in vim:

1    First line
2    Second
3    Third

If I want to select the three lines with the mouse what I want is for it to ONLY select the actual text. But what ends up happening is it selects the line numbers as well as all the space to the left and right of the line numbers.

Is there any way to change this behavior? BTW, I'm using the gnome terminal editor in gnome if that makes a difference.

+4  A: 

I'm pretty sure this is not possible in terminal-vim. There is no accepted standard (e.g. a TTY escape) for indicating blocks of characters that aren't highlightable by mouse, as far as I know.

I would use gvim if you want to be able to do this at any cost. Its behavior is as you describe.

Josh K
A: 

I agree with the first answer. If you use gvim, you can experiment with using set mouse=n and set mouse=a, which should change the line number selecting behavior.

Grant
A: 

My recommendation is to get used to the little box on the right hand corner of the screen which has the current line's number and character position information. Before I used vim I could never imagine living without line numbers, but since then I've moved beyond this. Not having line numbers clutter up the screen allows for distraction free code viewing, and do you really need to know that the line number above your current active line is one less than your current line's number, and the line below is one more?

apphacker
I don't understand the down votes, but ok whatever.
apphacker
+1  A: 

When I want to select text into a terminal, I remove line numbers.

:set nonu

When I finished

:set nu
Luc M
+7  A: 

AFAIK, that is not possible.

The only thing I can add at the moment is that you'd be better off with

:set invnumber

It will inverse the current condition, so you can map it to a key, and toggle it. That way you don't have to remember two commands.

ldigas
Better than mine! You learn something every day with VIM :-)
Luc M
+1  A: 

You're probably not on a Macintosh, and I can't tell if you mean you want to use system copy rather than vim's yank.

But if you are both those things, you can use option-drag to select text. This creates a 2d box over the text, selecting things that are under it. It should be functionally the same as 'take columns x1 to x2 of rows y1 to y2'.

John McDonnell
A: 

Use

:set mouse=a

to turn on xterm style mousing in all modes. This will allow you to do what you want. Keep in mind if the vim is remote via ssh, you'll need X11 forwarding turned on for the selection to make it to your local clipboard.