views:

286

answers:

5

I am using putty and vi editor if select 5 lines using mouse and i want to delete those lines how can i do that

Also how can i select the lines from keyboard like in windows i pres shift and move the arrows to select the text. how can i do that in vi

A: 

Highlighting with your mouse only highlights characters on the terminal. VI doesn't really get this information, so you have to highlight differently.

Press 'v' to enter a select mode, and use arrow keys to move that around. To delete, press x. To select lines at a time, press shift+v. To select blocks, try ctrl+v. That's good for, say, inserting lots of comment lines in front of your code :).

I'm OK with VI, but it took me a while to improve. My work mates recommended me this cheat sheet. I keep a printout on the wall for those odd moments when I forget something.

Happy hacking!

The Daemons Advocate
+1  A: 

When using a terminal like Putty, usually mouse clicks and selections are not transmitted to the remote system. So, vi has no idea that you just selected some text. (There are exceptions to this, but in general mouse actions aren't transmitted.)

To delete multiple lines in vi, use something like 5dd to delete 5 lines.

If you're not using Vim, I would strongly recommend doing so. You can use visual selection, where you press V to start a visual block, move the cursor to the other end, and press d to delete (or any other editing command, such as y to copy).

Greg Hewgill
Out of curiosity, how did you format those keys?
Justin L.
@Justin L.: Use `<kbd>a</kbd>`.
Greg Hewgill
Thanks! :D Are there any more of these hidden around somewhere?
Justin L.
+3  A: 

I am using putty and vi editor if select 5 lines using mouse and i want to delete those lines how can i do that

Forget the mouse. To remove 5 lines, either:

  • Go to the first line and type d5d (dd deletes one line, d5d deletes 5 lines) ~or~
  • Type Shift-v to enter linewise selection mode, then move the cursor down using j (yes, use h, j, k and l to move left, down, up, right respectively, that's much more efficient than using the arrows) and type d to delete the selection.

Also how can i select the lines from keyboard like in windows i pres shift and move the arrows to select the text. how can i do that in vi

As I said, either use Shift-v to enter linewise selection mode or v to enter characterwise selection mode or Ctrl-v to enter blockwise selection mode. Then move with h, j, k and l.

I suggest spending some time with the VIM Tutor (run vimtutor) to get more familiar with VIM in a very didactic way.

See also

Pascal Thivent
Actually, vim has great mouse support if your terminal supports it. For example using the `gpm` daemon in a console, or running `xterm` or `konsole` in a graphical environment, you can tell vim `set mouse=a` (or add it to your .vimrc) and the mouse can be used for selection, resizing splits, etc.
Ben Voigt
@Ben You're right, I don't use the mouse at all but this doesn't mean VIM can't deal with it (in certain circumstances). I was actually removing this inaccurate part from my answer while you were typing.
Pascal Thivent
Also, it's really hard to tell when your V is capital or not... I'd suggest saying [Shift] + [V] for line-mode selection.
Ben Voigt
@Ben Good suggestion, it was indeed hard to read. Thanks.
Pascal Thivent
+2  A: 

Do it the vi way.

To delete 5 lines press: 5dd ( 5 delete )

To select ( actually copy them to the clipboard ) you type: 10yy

It is a bit hard to grasp, but very handy to learn when using those remote terminals

Be aware of the learning curves for some editors:

OscarRyz
+1 for learning curves alone.
Marcel Korpel