Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple selections in VIM

Tags:

vim

selection

Is it possible to select multiple non-consecutive lines (or sections) in VIM's visual mode? If so, how?

like image 950
Marcin Avatar asked Oct 22 '09 15:10

Marcin


People also ask

How do I select multiple lines in vi?

Manipulate multiple lines of textPlace your cursor anywhere on the first or last line of the text you want to manipulate. Press Shift+V to enter line mode. The words VISUAL LINE will appear at the bottom of the screen. Use navigation commands, such as the Arrow keys, to highlight multiple lines of text.

How do I select multiple words in vim?

So you put your cursor somewhere in a word, press *cgn , type the replacement, hit <esc> , and then hit . to change the next occurence. If you already searched for the word, ignore the * and just cgn . There do exist multi-cursor-emulation plugins for vim.

How do I allow multiple selections?

For windows: Hold down the control (ctrl) button to select multiple options. For Mac: Hold down the command button to select multiple options.

How do I select a specific line in vim?

If you want to select the entire line in a file, press V. Now when you press k or j to go up and down, vim will select the entire line above and below your cursor. Finally, you can select text in columns by pressing ctrl+v and moving up or down the block.


1 Answers

No, this is not possible without plugins.

But you can copy multiple lines into the same buffer, if that solves your problem.

  • To start the 'Accumulation Buffer':
    • mark a section to copy in visual mode,
    • press "a to operate on the buffer a with the next command and
    • yank it as usual (y).
  • To add to that buffer:
    • mark the next section and
    • press "A (capitalizing the buffer name means "do not overwrite the buffer, append to it instead")
    • and yank again using y.
  • You can then paste the accumulated buffer a at any time using "ap.
like image 87
soulmerge Avatar answered Sep 26 '22 00:09

soulmerge