What a response! The original “Vim After 11 Years” post was very popular, and it prompted a lot of good responses on Hacker News and Reddit which were peppered with useful tips and plugins I didn’t know about. I compiled all of them along with some additional tips from friends and coworkers, then tried a lot of them out, and finally distilled it for you here. Enjoy!
There were a lot of comments about mapping the ; key away from its default behavior:
Indeed, ; seems pretty useful. I can recall having looped over a txn sequence to move to subsequent
x’s on a line, and ; would’ve made that easier. I wrote previously that I had bound ; to
:CtrlPBuffer, but now that might need to change.
Speaking of motion, a plugin brought to my attention was [EasyMotion][easymotion] which gives you a novel way of moving around using visual anchors. The trick is to keep your eye on the location where you want to move (my leader key is ,):
I’ve installed EasyMotion and it seems neat, but after so many years of using Vim’s advanced movement keys, I’m don’t think that I’ll ever remember to use it. For example, if I needed to move to the second word three lines down, I would remember jjjww
Someone also mentioned vim-seek which “aims to make inline navigation effortless.” I don’t have time to learn of it and nobody I know has smashed down my door to tell me how life-changing it is, but I felt compelled to mention it here.
A bit of discussion involved the leader key: an arbitrary key that plugins use for keybindings so that they don’t interfere with your own custom bindings. By default it’s \, but a lot of people remap it to , for similar reasons as the semicolon.
A handful of comments on Reddit and Hacker News recommended changing it to the space bar which, unlike the ; and , keys, is redundant; it performs the motion as l and →).
It’s also worth mentioning that some folks use folds so much that Space is bound to toggle folds:
I tried this but it never caught on. I always felt that zo and zc were easier to remember.
Macros are well known. Hit qa to record keystrokes to register
a, hit q when you’re finished, hit @a to play the macro in register
a and @@ to repeat the last macro.
How is this useful? You could emulate
grep -v by deleting lines that match
Or you could append all lines matching
foo to register
Or you could change
bar only on comment lines that begin with a
As Mark told me, “I only use it once a month, but I’m so glad I have it when I need it.”
Other People’s Code
Different projects may have different style conventions and I recommended keybindings for quickly changing whitespace settings among four common standards. Alternatively, there’ a plugin called “dirsettings” which reads
.vimrc files in the current or parent directory(ies). Try the original script or check out the sequel which walks up the directory tree and sources all settings along the way.
If the only project settings you set are whitespace it might be worth looking into Tim Pope’s vim-sleuth plugin. It “adjusts
expandtab heuristically based on the current file, or, in the case the current file is new, blank, or otherwise insufficient, by looking at other files of the same type in the current and parent directories.” I’ve installed this and it seems to do a good job.
I mentioned at the bottom of the original post that I missed Emacs’ CSS color-highlighting mode, which highlights CSS colors the editor. A few people were quick to respond with Max Vasiliev’s vim-css-color plugin, which does this but causes a long delay when opening files. Then I was referred to Aristotle Pagaltzis’ fork which causes no delay
but causes errors when opening files such as the stylesheet for this site and works fine. Hooray!
Multiple people mentioned binding Ctrl-direction to window-movement keys:
A friend goes further and appends Ctrl-W_. This maximizes the window’s height after the cursor has switched to it, which produces an interesting effect similar to some tiling window managers I’ve used:
A lot of the forums discussed tmux, iTerm, screen. I’ll summarize.
GNU Screen has been the standard of terminal multiplexors for a long time. Most of the bugs have been fixed since its original release in 1987 but novel features are lacking, such as vertical window splits. Also, getting Unicode and 256 colors to work can be a battle.
tmux is the new hotness. It has vertical splits and great shell-scripting capabilities and much more. However, I’ve had an occasional crash and also experienced the keyboard slowness as described in this tmux vs. screen comparison, but it’s under heavy development and maybe I just need keep up with the latest versions.
iTerm2 is a replacement for Terminal.app on Mac OS X. It does horizontal and vertical splits, you can change font sizes in each pane (tmux and screen can’t do that, of course), and I think it “feels” faster than the built-in terminal application. I also recently notice that iTerm doesn’t have keybindings for directional pane navigation by default but you can add them in the preferences.
You can even integrate iTerm and tmux such that iTerm panes are mapped to tmux session panes. There’s a blog post illustrating how this works here.
Finally, someone mentioned vimux, a plugin which lets you “easily interact with tmux from vim.” The description says, “When you call
RunVimTmuxCommand, vimux will create a 20% tall horizontal pane under your current tmux pane and execute a command in it without losing focus of vim.” Sounds useful, but I think I’ll stick with my Ctrl-Z solution I outlined in the original post.
The responses to the post highlighted a few plugins I hadn’t heard of.
Jedi looks awesome. If I were still writing Python daily I would definitely try it out:
There was a lot of discussion of YouCompleteMe, a powerful completion system for “C-family” (C/C++/ObjC/ObjC++) languages:
A lot of people swear by Cscope, “a very powerful interface allowing you to easily navigate C-like code files.” You can read about integrating it here on the Vim wiki.
Eclim deserves a mention. By using Eclipse as a backend it brings a lot of features to Vim such as code completion, refactoring, generation, and whatnot. I’ve only gotten it to work once in my life and I didn’t have a positive experience. Besides, if you’re writing Java, the winner is IntelliJ IDEA – it’s got a Vim emulation plugin, too.
Finally, everyone knows about Ctrl-N and Ctrl-P for basic completion. But did you know about Ctrl-XCtrl-L for whole-line completion? Give it a try. (Credit: Mark.)
Pathogen and Vundle are not the same thing: Pathogen could be called a “runtimepath manager” while Vundle is a “plugin manager”. The difference is huge:
Pathogen’s only purpose is to “inject” the directories located in
~/.vim/bundleinto Vim’s runtimepath and make sure the documentation for all those plugins is correctly indexed. How they end up there and whether they are up-to-date or not is not Pathogen’s business.
Vundle, in addition to what Pathogen does, tries to deal with everything else plugin-related: installating, removing, disabling, updating…
So both plugins serve different purposes and solve different problems.
I don’t like to have my plugins scattered around my
~/.vimdirectory but I don’t need any help for updating or installing them. That’s not something I do often enough that I need a plugin to automatize it. Pathogen is all I need/want and it does its job perfectly. –a comment on Reddit
Vundle uses the service at vim-scripts.org (which I had never seen before) to find and install packages into
~/.vim/bundle/, which seems great. It even has a search mechanism and interactive installer. However, at the time of this writing, it’s still very new software.
I tried to replace my own management system with Vundle and it was not a good experience. I added the
Bundle statements to my
vimrc per the instructions but I was a little alarmed; to my knowledge, the ancient Vim script registry has no index or API, and I was uncertain what would be installed when I requested to install an unqualified, non-GitHub package like
Zenburn. It was only after reading the source code that I discovered the new vim-scripts.org site which appears to be the source of the plugins.
Bundle I ran the
vim +BundleInstall command which dropped me into a weird interactive installer. It took a minute to realize that I was supposed to press i on each line to install the module. Then, trying to install half of the modules from GitHub resulted in GitHub asking me for a username and password (which is weird) and the installs failed with an error. Eventually I got everything installed (or so I think) and things seemed to work, but I wasn’t reassured. Maybe I’m just too dumb to know how to use it.
Vundle is promising, but it’s got a ways to go before I can call it a solid package manager that’s on the tier of cpan, gem, apt, npm or pip. And until then I’ll stick with my trusty Pathogen-based management system.
Maybe you don’t want to spend any time configuring your editor and you want all the whiz-bang included. If so, check out spf13-vim, which comes with all of the good plugins mentioned here and before and colors and everything. There’s also Janus but it’s less impressive. I still think the right path is to start with an unconfigured, stock Vim distribution, but to each their own. Some seem to reject configuration outright:
“Every time I read an article like this, it’s how a power user installs an array of plugins and customizations to really soup up Vim, which to me kind of misses the point. If you want that level whiz-bang, use Coda or Sublime Text 2 or Eclipse or whatever.” –Hacker News
“I’ve seen one too many love-letter-to-Vim blog posts where the author recommends a flashy plugin that does nothing to really improve productivity. You know what improves productivity? Mastering motions and operators.” –“Stop the Vim Configuration Madness”
Vim has a lot of intelligent stuff in its default distribution, but the authors couldn’t think of everything, hence plugins. Compare visual block mode with numbered ranges of lines – of course you should be able to select a block of text with the cursor instead of esoterically entering line numbers. Compare
:e foo.txt with fast, fuzzy filename file-finding – of course you should be able to jump to any file by hitting a key and typing any part of its name. Sometimes plugins really do help.
Vim is toolbox – it doesn’t come with everything you’ll ever need; it grows slowly over years. Sometimes eleven of them.