This week, I have a quick couple of tips for Vim users that should make life just a little bit easier when using Vim in command mode and completing filenames.
By default, when you use Vim you can type the first letter or first few letters of a command, and you’ll be able to cycle through the commands using
Tab. For example, type
:e, and you can cycle through all the commands that begin with
That’s just a short list. But what if you’d like to see a quick menu of the available commands instead? For this, you have a little-known Vim option,
wildmenu. As a reminder for folks not particularly well-versed with Vim, the
: tells Vim to enter command mode from its normal mode.
While in Vim, just run
:set wildmenu, and you’ll toggle the option to enable the enhanced command-line completion. Note that you enable this any time by adding it to your
So what does this little toggle get you? Now when you hit
Tab, you’ll get a one-line menu at the bottom so you can see all the options that begin with the letters you’ve typed. So
:e will give you the same list as before, but in a one-line menu at the bottom. Hit
Tab again, and it will move to the next command, and so forth. You can also use
Ctrl-n to move backward and forward (respectively) through the list.
This doesn’t work just with commands, though–it also works with filenames. If you’re looking to open a file, for example, using
read) and you type the first character or characters, hitting
Tab will display all the filenames that match in a one-line menu at the bottom.
wildmenu is a minor thing, but it’s another way to boost productivity and make Vim a bit more usable. I recommend giving this a shot. See if you don’t find that it makes life a bit easier!
Joe ‘Zonker’ Brockmeier is a freelance writer and editor with more than 10 years covering IT. Formerly the openSUSE Community Manager for Novell, Brockmeier has written for Linux Magazine, Sys Admin, Linux Pro Magazine, IBM developerWorks, Linux.com, CIO.com, Linux Weekly News, ZDNet, and many other publications. You can reach Zonker at [email protected] and follow him on Twitter.