Dropping CtrlP and other Vim plugins
At the end of July I dropped CtrlP and other plugins from my Vim setup. CtrlP was one of the first that I installed and until a couple of weeks ago I would’ve deemed it an essential plugin.
The truth is that I never learned how to navigate effectively with Vim’s
built-in commands. I know how to use :e
and its companions, but beyond that I
never gave it any thought.
It turns out that Vim’s tab completion, coupled with the wildmenu
option,
works really well since it can complete everything from buffers, unopened files
to tags.
Built-ins
Navigating buffers
I use this for listing and switching buffers:
The §
key is on the same row as the numbers on my keyboard, which makes it
fitting. I also have this in my .vimrc
:
This will jump to the last edited file. Typing ^
requires two keystrokes for
me, hence the remapping.
Navigating tags
You can also search for a tag by pattern:
I find tags extra useful when I’m dealing with CSS. If I want to jump to a class
named .block
I can do :tag .bl
, press <Tab>
and then hit <Enter>
.
Finding files
I unfortunately find tab completion to be a bit slow with the above command, but since I don’t work with large codebases I don’t use it that much.
To make it work recursively you need to modify the path
option:
You also need to make sure to modify the wildignore
option too, unless you
want to include files that belong to your dependencies:
Grepping
I regularly grep for all kinds of things. I’ve used
ack.vim,
ctrlsf.vim and I even wrote my own
plugin. I ended up removing it and
changing the grepprg
and grepformat
options instead:
I use ack since it works well on both Linux and Windows systems. I also added a small helper command, courtesy of thoughtbot’s guide on “Faster Grepping in Vim”:
Which I then use like this:
If I want to use git-grep instead of ack I
run :Ggrep
, a feature from
vim-fugitive.
One of the nicest features that comes with ack.vim and other grepping plugins is that the quickfix window opens automatically after searching. Luckily, it’s not hard to enable that either:
The above snippet comes from vim-fugitive’s FAQ.
Alternatives
When I removed CtrlP I actually swapped it for another plugin, DidYouMean. I think the author describes its use case best:
If you’re like me and you want to edit a specific file with Vim, say,
test.py
, you typevim te
into the terminal, then you hit<Tab>
and<Enter>
immediately because you think your shell expands the characters to the right file name. But if there’s another file starting withte
, Vim fires up with an empty file calledte
, laughing at you. That’s annoying. This simple plugin makes Vim ask for the right file to open.
The plugin is only a handful of lines long, but it saves me from so much frustration.