This was originally written for VsVim, which is a vim emulator for VS. Years later, after also trying a few vim emulators for VSC, I'm convinced that marks and registers are the same among vim emulators for any IDEs and code editors.
-
-
Save dogfuntom/a6a6c220b5baa0d5e59574edb2178454 to your computer and use it in GitHub Desktop.
When it comes to Vim emulators, how to do an advanced operation is not the hard part. The hard part is remembering/recognizing that some routine operation can be helped by Vim.
Useful for understanding sloppily/poorly written legacy code. Given a bunch of methods like this:
private void ConfusinglyNamedAndConfusinglyUsedMethod()
{
// confusing code here...
}
Record a macro with a following algorithm: starting at line with name, go to name, yank name, go down, open new line, type logging method, paste name, finish calling logging name, done. Apply this macro to every method with unclear purpose.
Result:
private void ConfusinglyNamedAndConfusinglyUsedMethod()
{
Debug.Log(nameof(ConfusinglyNamedAndConfusinglyUsedMethod), this);
// confusing code here...
}
This file is about marks in Vim emulators.
`.
— Jump to last change.
` `
— Jump back (in other words, unjump, i.e. navigate back or undo/reverse last jump).
''
— Jump back to line (instead of exact position).
mm
— Place mark m.
'm
— Jump to line containing mark m.
`m
— Jump to mark m exact position.
Don't forget that all jump operations above, similarly to most (all?) other kinds of jump operations, can be used together with d
, c
or y
.
This file is about registers in Vim emulators.
"0
— Last yank. (Very useful when you yanked something, then deleted something in target location, then want to paste yanked text instead of just deleted: "0p
.)
"+
— System clipboard.
:echo @r
— Print register r.
""
— Unnamed register used automatically on dd
, yy
, etc.
"/
— Last search pattern.
"_
— Black hole. (E.g. "_dd
will delete a line without remembering it. Undo will still work as usual though.)
"1
— Big delete (deleted line or lines).
"2
–"9
— Previous big deletes.
"-
— Small delete (deleted text within a single line).
"a
–"z
— Named registers.
"rd
— Delete into register r.
"ry
— Yank into register r.
"Rd
, "Ry
— Delete or yank appending into register r.
Macros mostly reuse the same register system described above. You can't execute @+
in VsVim though.
qr
— Record into register r.
@r
— Playback from register r.
@@
— Repeat last playback.
This file is about quirks of VsVim in particular. Ignore it if you're using another Vim emulator.
When you type a new method, VS aids you and you end up with this:
private void Foo()
{
}
If you don't write anything there immediately, but return to it later, VsVim forces you to type from the hard BoL of the empty line. I don't know any good way to deal with it, but at least there's certainly a nice assortment of acceptable ways:
ddO
i
, End- If the expression is simple, just do
i
and type it (ignoring intendation), it'll auto-format automatically when you type “;” or other trigger.