This question already has answers here:
Multiple selections in VIM
(3 answers)
Closed 2 years ago.
Is there a way in VIM to visually select multiple sections / non-consecutive lines in a document that are not directly connected?
My goal is to copy certain parts of a document to a different one, open on a different buffer in the current VIM instance. However the same procedure could also be used to delete such a selection.
Let's say in the below example I want to select the rows 2,6 and 11.
1 global _main
2 extern _printf
3
4 section .text
5 _main:
6 push message
7 call _printf
8 add esp, 4
9 ret
10 message:
11 db 'Hello, World', 10, 0
Thanks to #Andrea Baldini's higlight of a similar question I see one of the answers a workable solution for my problem that doesn't need any plugins.
For reference I copy the response from #soulmerge
To start the 'Accumulation Buffer':
1. mark a section to copy in visual mode,
2. press "a to operate on the buffer a with the next command and
3. yank it as usual (y).
To add to that buffer:
1. mark the next section and
2. press "A (capitalizing the buffer name means "do not overwrite the buffer, append to it instead")
3. and yank again using y.
You can then paste the accumulated buffer a at any time using "ap.
Related
I'm reading the practical vim book on page 30 it talks about registers. Can you have different assigned registers? The default register is 0 once I put something in reg 0 how can I keep this in there and put something in reg 1 then 2, 3 ect
I want to store tags in these registers so I can quickly just paste them in. Is it possible?
Registers 0-9 have special purpose, actually. When you cut something longer than one line, the contents of your register 9 is discarded, the contents of register 8 moves to register 9, 7 to 8, etc. and the contents of register 0 moves to 1. Then the text you cut appears in 0.
But you can freely use named registers (a-z) and they won't be overwritten unless you tell Vim to do so. For this instead of y or d do "ay or "ad to copy or delete to register a. Using "A instead of "a will append to register a instead of overwriting its contents.
To paste use "ap. To paste in Insert Mode use Ctrl+Ra.
For more info read :help registers.
There's a Vimgolf exercise to convert this:
- One number per line -
-----------------------
2,3,5,7,
11,13,17,
19,23,29,
To this using Vim:
2
3
5
7
11
13
17
19
23
29
One possible solution is:
dj3JAwr<CR><Esc>ux09#.ZZ
My question is - what does the "09#." part of the command do? I understand 0 is the beginning of a sentence, 9 is the end, and "." means repeat command.
But what command is being repeated? And do "09#." mean something different when strung together in sequence?
09#. is:
0: go to first character of the line.
9#.: execute the content of register . 9 times.
The register . is defined as:
quote_. quote. E29
". Contains the last inserted text (the same as what is inserted
with the insert mode commands CTRL-A and CTRL-#). (...)
You can still check its content by executing:
:register .
which gives wr^# So vim here is changing the newline into a null character and do not give what you expect.
So dj3JAwr<CR><Esc>ux09#.ZZ can never be a solution for the problem especially as J leave also a space when joining lines.
This question already has answers here:
Pasting inside delimiters without using visual selection
(5 answers)
Closed 8 years ago.
Is there any known, straight-forward way to perform inner <text-object>-functons in Vim similar to yank-inner and delete-inner, only with paste? I know how to do this with Visual mode but it feels a few steps too long.
Example:
delete-inner (di<text-object>):
user.name("Carl") -> di" -> user.name("") + Carl is copied to clipboard.
Now, I occasionally find myself wanting to do something like this as well:
user.name("") -> pi" -> user.name("Carl")
I don't like taking the extra step inside Visual-mode, nor performing acharacter/string-search (/,f,t). Is there any way around this? Plugin-recommendations are also welcome if necessary.
I need this so often, I wrote a plugin to simplify (i.e. without the intermediate visual mode) and allow maximum speed: ReplaceWithRegister.
This plugin offers a two-in-one gr command that replaces text covered by a {motion} / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard . command. Should you not like it, its page has links to alternatives.
So, your example would be g r i ".
Edit: Previous plugin versions didn't handle an empty text object well; fixed in the latest version 1.41.
"_di"P
works for me, it pastes to the left instead of right which leaves it inside the quotes
assuming you want to change the value with the one on the clipboard
Alternately you can use :map to map pi" to either the command above or the Visual method keys
This question already has answers here:
Delete n lines in the up direction in vim
(5 answers)
Closed 9 years ago.
Is there a way to apply a vim command backward? For example, I want to kill 5 lines backward, instead of 5dd, is there something like -5dd?
From :he d:
["x]d{motion} Delete text that {motion} moves over [into
register
x]. See below for exceptions.
How about 5dk 4dk (k being the motion for upwards)?
Edit: changed count to 4 as this results in 5 lines being deleted apparently...
I understand that the numbered registers 1-9 are only filled with things that were _d_eleted or _c_hanged, but is there a way to make _y_anked items also fill these buffers, short of defining a custom yank as a delete and put?
For instance, if I have
one
two
three
and I'm on line "one" and do yykyykyy, I'd expect register 3 to have "one", register 2 to have "two", and register 1 to have "three", with registers 4 and up having whatever was already there bumped up.
Maybe this script is what you're looking for? YankRing maintains a history of previous yanks, changes and deletes.
Have you tried
"3yyk"2yyk"1yyk