Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim select the ends of multiple lines (block mode, but where the ending column varies)

Tags:

vim

Is there any way in vim that I can select the end of all these lines? (I'm only showing the end of the lines in these screenshots).

In block mode I can get them all if the bottom line is longer than the rest, but if the bottom line is shorter, the longer lines are truncated.

EDIT | I guess I can just pad out the bottom line with spaces before I select, then delete the spaces later.

enter image description hereenter image description here

like image 286
d11wtq Avatar asked May 27 '12 08:05

d11wtq


2 Answers

  1. Put your cursor on the top-left character you want to be part of the block.
  2. Enter block selection mode with ctrl+v
  3. Select to the end of the line with $ (this is the step you're missing; if you move to the end of the first line using $ then the selection will extend to the end of subsequent lines as well)
  4. Move down 3 lines with 3j

There's more information in the Vim documentation's section on visual mode which you can read online, or just type :help v_$ in Vim.

like image 68
georgebrock Avatar answered Nov 09 '22 17:11

georgebrock


  1. Click somewhere (anywhere) in the first line you wish to append text to.

  2. Press Control + V.

  3. Press Down to create an arbitrary vertical block selection that spans the desired lines.

  4. Press $ to expand the visual block selection to the ends of every line selected.

  5. Press Shift + A to append text to every selected line.

  6. Type the text you want to append.

  7. Press Escape and the text will be appended across the selected lines.

like image 17
FocusedWolf Avatar answered Nov 09 '22 16:11

FocusedWolf