There's a few commands I LOVE but find frequently unmentioned.
In insert mode, <C-x> is a contextual completion. So like the normal <C-n> or <C-p> you just do <C-x><C-n> and you can keep hammering the <C-n> to fill in multiple "words". You can also complete lines, file paths, dictionary words, thesaurus words, tags, spelling, etc. See `help ins-completion`. Seriously, I can't do without this command. <C-x> needs to be in everyone's daily use.
Also in insert mode: <C-w> deletes a word back. You'll commonly find this is a lot of editors and stuff where it doesn't close a window. Similar to <C-backspace>, though I many times accidentally hit <C-w> in my browser instead of <C-backspace> because I use this so much (bad speller).
<C-[> much easier than pressing Esc
0 much easier than pressing ^ (honestly I have anything that is $,%,^,&. They aren't easy to reach)
Honestly, vim has some of the best written documentation I've read. If you really want to master vim, just read the docs on commands you already use. I guarantee you'll find something you didn't know.
can you give more examples of <C-x><C-n> in code editing? I have tested that out in vim and its cool but i cant think of times I want to repeat a series in another part of the document, perhaps I'm just very uncreative right now
Totally. But I will tell you, <C-x> is a habit built around the other options too. So I just use <C-x> on any completion (which I frequently use <C-x><C-f>).
Here's a dumb example (dumb because there's other ways to do it that are better)
Let's say I'm overloading a function.
void foo(int a, int b)
{}
I could do v<C-x><C-p> until I fill in the b, then type ", int c)". Now it'd be totally easier to do "v<C-x><C-l> backspace , int c)", but that's a different point.
Maybe this one is a little more useful
"def _<C-x><C-p><C-x><C-p>" may expand to "def __init__(self" Note that here I'm holding down ctrl and just hitting "xpxp"
Honestly I end up finding a lot of patterns in my code just because I started thinking about it this way. It is more one of those things where once you start thinking about it with it in mind you will find patterns.
It is also an easy habit to develop, if you already use <C-n>, because when you press ctrl you just also hit x and keep your pinky down on ctrl. I feel like there is just no downside to using <C-x> because in reality it is just one more keystroke, which is done with the other hand (so even less increase in work).
Yeah I rebind keys and write my own functions. I have a preference for distilling things that I use out of plugins[0] and into just vanilla vim (I still use plugins). I'll share my configurations[1]. I don't document it well btw and there's frequently changes. But I find that looking at others rc files many times gives me ideas that I hadn't seen before. Also, if you have any suggestions I'd love to hear them.
[0]see my git rebindings instead of using tpope's plugin
- ZSH-autocomplete is probably by far my favorite thing ever
- iterm3 full overlay with <C-i> means that i have a full overlay terminal immediately available no matter what im doing. No messing with stupid windows
- i made my own custom theme etc you can check out
Vim favorite things
- `gx` opens the current URL under the cursor in your browser
- `gq` for word rewrapping comments on the fly
- `Bda!` look in my .vimrc for Bda! which deletes all open buffers, useful when youre working and have 40 open buffers you forgot about and want to start fresh
I forgot to mention these are also critical to know, because they apply to pretty much everywhere in OSX (even inside chrome address bar, terminal, plain text areas like the HN reply box, etc):
In insert mode, <C-x> is a contextual completion. So like the normal <C-n> or <C-p> you just do <C-x><C-n> and you can keep hammering the <C-n> to fill in multiple "words". You can also complete lines, file paths, dictionary words, thesaurus words, tags, spelling, etc. See `help ins-completion`. Seriously, I can't do without this command. <C-x> needs to be in everyone's daily use.
Also in insert mode: <C-w> deletes a word back. You'll commonly find this is a lot of editors and stuff where it doesn't close a window. Similar to <C-backspace>, though I many times accidentally hit <C-w> in my browser instead of <C-backspace> because I use this so much (bad speller).
<C-[> much easier than pressing Esc
0 much easier than pressing ^ (honestly I have anything that is $,%,^,&. They aren't easy to reach)
Honestly, vim has some of the best written documentation I've read. If you really want to master vim, just read the docs on commands you already use. I guarantee you'll find something you didn't know.