Is it possible to select multiple non-consecutive lines (or sections) in VIM's visual mode? If so, how?
3 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 buffera
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
.

- 73,842
- 19
- 118
- 155
-
2I wish I could accept two responses. This is good to know too. Thank you. – Marcin Oct 22 '09 at 19:57
-
If you would remove that "No this is not possible" bit, then I would upvote this answer. – Michael Dillon Oct 23 '09 at 20:45
-
Not actually removed, but adjusted first sentence. Should be correct now. – soulmerge Oct 28 '09 at 18:02
-
3Hint: to empty your accumulated buffer `a` again, type `:let @a=''` – eckes Jan 25 '11 at 14:21
You have to install the multiselect plugin to get this capability. Find it here: http://www.vim.org/scripts/script.php?script_id=953

- 31,973
- 6
- 70
- 106
-
4For people who don't bother reading all the answers, there is a link to a more up-to-date and more sublime-like plugin below. http://stackoverflow.com/a/16568663/608155 – Jon Thoroddsen Oct 23 '14 at 11:51
-
1
A more up-to-date answer is this plugin.
(disclaimer: I personally don't actually use it, it interferes too much with the rest of my vim setup. If your vim is relatively clean and you are moving over from sublime, this may certainly be your cup of tea.)
I would also like to point out the record/replay functionality of vim (the q
key). Quite often recording is also unnecessary, I can do the tasks normally done with sublime's multi-select by doing it iteratively (e.g. search for something, perform the fix on the first instance of it, and then subsequent repeats are achieved by hitting n
and N
to move around and .
to repeat the edit operation).
I do have my ,
comma key nnoremap
'd to @q
, this repeats the sequence that is recorded by pressing qq
(record into q
register).

- 41,389
- 58
- 210
- 364
-
I've thought about doing the `,` mapping, but then how do I search backwards after using `f` or `t` to jump to a character on a line? – SO_fix_the_vote_sorting_bug Sep 08 '20 at 08:20
-
I can’t comment on that since I never learned to use the comma key (which is why I mapped it away)... presumably it’s useful once you overshoot what you’re seeking via the use of `;`. Well you can just use T or F to do the same in the opposite direction – Steven Lu Sep 10 '20 at 01:02
-
deprecation strikes again! use https://github.com/mg979/vim-visual-multi – Avinash R Oct 11 '22 at 07:38