Lets say I've got 10 lines:

1. Foo
2. Bar
3. Baz
4. Quz
5. Qaz

How could I select lines 1-3 and than 4-5.

link|improve this question

61% accept rate
1  
Isn't that identical to selecting lines 1-5? – Christian Mann Oct 9 '11 at 1:41
feedback

2 Answers

You'll need to use registers, because there's no way to highlight more than a single block at a time without using plugins.

The structure is "<register><action>.

Basic example:

Do a visual selection with either <C-v> (block) or <S-v> (line). Select your first block.

enter image description here

Yank/cut it into a register with "qy or "qx. q can be any letter, it's just the identifier of the register.

enter image description here

Do the same thing for the next block, but with a different register. "wy or "wx.

enter image description here

Now, both selections are in registers q and w respectively. Navigate to your targeted location and paste them with "qp or "wp.

enter image description here enter image description here

If you want to append the contents of the w register into the q register, you can do the following in command mode.

:let @q .= @w

You can also yank multiple lines without even entering visual mode. The command is "<register><number><action><movement>. Say if you want to yank the current row to 3 rows down into register z, type "z3yj". You should see a 4 lines yanked confirmation in the status bar.

link|improve this answer
feedback

Using registers would be the best way to go about it. But if you insist on having non-contiguous visual selection, then here's a plugin that does that -

http://www.vim.org/scripts/script.php?script_id=953

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.