Vim tricks
hillelwayne.com
hillelwayne.com
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.
Thanks
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).
Do you rebind your caps to control as well? That was another thing I did which is 10/10
[0]see my git rebindings instead of using tpope's plugin
Read my README for most of my favorite tricks.
https://github.com/9mm/dotfiles
Things that come to mind
- 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'll think of more later!
c-f Move forward
c-b Move backward
c-p Move up
c-n Move down
c-a Jump to beginning of line
c-e Jump to end of line
c-d Delete forward
c-h Delete backward
c-k Delete forward to end of line
c-u Delete entire line
This is disturbingly accurate from my point of view. I keep wondering if I should finally jump ship and stop tweaking vim with questionable results. Spacemacs? Pure emacs + evil? Suggestions welcome.
Plug 'tmhedberg/SimpylFold'
"Plug 'python-mode/python-mode', { 'branch': 'develop' }
"let g:pymode_python = 'python3'
... in different combinations. Deleting any char takes surprising amount of time, so much so that I usually mark block to delete instead of char by char even if it is three char block. Of course I may be using wrong plugins, however that's what I found that should be used in various articles online.But at the very least, they’re both good gateway drugs to get your first hit of the hard stuff
After using vim for about 20 years, I switched to emacs+evil about 10 to 15 years ago.. and spent a lot of time in the first 5 years or so tweaking stuff. Things have mostly stabilized in the last 5 years, and I still use evil.
One thing that helped me a ton was using hydra. Whenever I install a new mode or package, I bind all of its useful functions to hydras. Hydra and evil allow me to keep all virtually all my bindings vim-like.
However, you will probably need to do some customizations in doom-emacs. Spacemacs works mostly only using its internal layers, however when you try to do something that isn't included already... Well, it is less than optimal. doom-emacs assumes that you will want to customize things.
[1]: https://github.com/hlissner/doom-emacs/
[2]: And as for why it isn't Ctrl+X to decrease number like in Vim, it is because Ctrl+X is probably the most important keymapping in Emacs itself. However I find Ctrl+Shift+A quite good because it follows the Vim convention of the reverse of some operation is on Shift.
However this is the trade-off. You have to spend more time in doom-emacs, however there is less friction to customize.
Something that starts from bare(ish) emacs, includes emacs lisp, and gradually adds in plugins sort of like how this post does it but maybe more comprehensive and less individual tricks oriented.
Meanwhile, there's every reason to use Vim's bindings, as they specifically sidestep the ‘move cursor and then type’ approach. Besides, with Evil you'll still have plenty of Emacs chords to do for stuff that's not in Vim.
The discover ability of Spacemacs is really second to none and makes it much faster to learn and keep learning.
Spacemacs is Nutella to keep the analogy going...
I see that I can do `set keywordprg=pydoc` but I want modules too.
au FileType mail set keywordprg=~/bin/dictlessWhile I do have a few of these IDE-like plugins (undotree, for example), I think it's better to try plugins which embrace the "vim way" first before investing in a full IDE-like plugin. I don't mean to gatekeep by criticizing IDE-like plugins, but just to say that spending the time to learn normal mode as a true language (verbs, nouns, and all) and using plugins that follow this idea is a worthy investment. Then, add IDE-like plugins to work around the frustrating rough edges of vim once you've milked all that you can out of it.
That seems like a mouthful. I use :<up arrow> to run the last command and <up arrow> some more to run the ones before that.
I guess I might press and hold at ten.
But that aside, if you’re into arrow pressing, a few lines in your .inputrc can go a long ways
Test this out sometime:
# Incremental searching with Up and Down and Left and Right
"\e[A": history-search-backward
"\e[B": history-search-forward
Now you can type “find” and press up/down arrow to just cycle through history that starts with findUnless I’m mistaken, this is the default undo behavior for emacs...What horror to only have vim’s forward and backward undo history! Said the emacser on the vimmer’s post.
Edit: this also seems to be in the original post
:help undo-branches http://vimdoc.sourceforge.net/htmldoc/undo.html#undo-branche...
> command! Vimrc :vs $MYVIMRC
I just use marks for this. Capital letter marks work across files, I use 'I (for init.vim, I use neovim).
Sometimes efficiency is not about "tricks"
I do think there's Pareto principle at play with all this obscure stuff. Knowing 20% gets you 80% of the benefit, every additional percent gets you exponentially smaller fraction of the remaining 20%. That's how I play it anyway. I don't feel like I'm any less productive with my 20%.
Regardless, the benefit cannot be overstated. I am not exaggerating that it was the single greatest decision I ever made.
So, you’re saying you are making too much money to learn something new?
https://www.invidio.us/watch?v=wlR5gYd6um0
Unfortunately, this aspect is poorly documented. Thoughtbot's video is among the best I've found. And that's with 30 years' experience.