I’ve just found something rather useful in vim: :set wildmode. Normally in vim, you can use TAB to complete filenames. So you enter :e some/ve<TAB>
and vim pads it out to :e some/very_long_filename.html
. Lovely.
But in a directory full of files with similar prefixes, it’s less than helpful. I hit :e acc<TAB>
and vim expands to :e acc_click_here_to_continue.html
. But then I need to backspace all the way back so it reads :e acc
and hit TAB again. This is a pain.
But, if you stick set wildmode=longest,full
into ~/.vimrc
, then vim stops when it’s completed the longest unique prefix (“acc”) and gives you a chance to type. Or, if you just keep banging on the TAB key like a deranged gibbon it will start rotating through all the possible completions. But by stopping at that point, I get a chance to intervene.
It sounds like a teeny-tiny little thing. But it’s one less thing that’s getting in the way of me doing things.
That said, any time saved has already been wiped out by writing this blog entry. 🙂
2 replies on “vim completion”
You need to backspace?! Over here, I can simply keep hitting [Tab] and vim will cycle through the available completions.
However, if you type [a][Tab] and you have 100 files that start with “a”, that’s kinda useless. So in that case you can type [Ctrl-L] instead, in which case vim will complete only up to the longest common prefix, just like setting
wildmode
would make [Tab] behave.Aha — more magic I was missing. That Ctrl-L sounds like just what I was requiring. But I’m trying to get both on a single key the way I’ve got zsh working: one tab to get the longest, then multiple tabs to start rotating through the choices. I did think that longest,full would do the trick, but I’m not so sure now. More playing definitely required.