I just discovered the existence of markers in vi. How do you use it, what do you know about them? are they useful, say for a C++ developer?
I use them all the time for:
Commenting out:
ma
:'a,.s/^/#
(or whatever comment character you need)Copying and moving:
mb
:'a,'bco .
or :'a,'bmo .
to copy or move resp.Yanking to a named buffer:
:'a,.ya a
will yank the block into buffer a or :'a,.ya A
will append the block onto the current contents of buffer aEdit: Substituting in a block of text:
:'a,.s/search_string/replace_string/[gc]
which will subtitute in your text block. Adding 'g' or 'c' after the last slash will invoke the usual global and confirm functionality.Edit: Forgot to say, remember that 'a
(apostrophe a) refers to the line containing the marker and `a
(backtick a) refers to the character on the line that you marked.
So `ad`b
(bactic-a-d-backtic-b) is a useful little snippet to delete the text in a line from the char marked with 'a' up to the char before the char marked with b.
By the way, in Vim, entering :reg
will give you the contents of all your registers incl. your delete registers.
I use them when I need to jump around in a large file. For example, if I'm working on two interrelated functions, one which is defined near the top of the file and one which is defined near the bottom, I can set markers to quickly jump back and forth between the two locations.
If I'm declaring a class or working with a declaration I'm not familiar with, it's often helpful to mark the spot where things are first explained so that I can jump back for a quick reference.
Markers are useful in general, but I don't think they're any more (or less) useful just becuase you're developing in C++.
These are only some ideas -- I'm sure there will be many other good ones out there.
The most common use is for copy-paste or deleting large blocks.
Move to the first line of the block, type mx
Move to the last line of the block, type y'x
to copy the whole block (to the clipboard), or d'x
to delete (cut) it. In either case, p
or P
can be used to paste it elsewhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With