Vim tip: excluding files and paths from searches with Grepper

Grepper is a plugin for Vim to search your project asynchronously using your preferred search tool. By default Grepper will search Vim’s current directory and its subdirectories, in many projects that I work on this includes things I generally do not want to search in (with directories container vendor libraries such as node_modules).

You can pass extra options for the tool of your choice to the Grepper commands, ripgrep (which is what I use) supports a glob argument which you can use to exclude paths (and files) like so:

:GrepperRg --glob '!vendor' --glob '!node_modules' --glob '!public' --glob '!test/vcr_cassettes' 'Hello Word'

To prevent yourself from typing a ton of globs each time you want to search you can add a command to your vimrc for common combinations like so:

command! -nargs=+ -complete=file Search :GrepperRg --glob '!vendor' --glob '!node_modules' --glob '!public' --glob '!doc'

The above snippet adds a Search command to vim which excludes paths I generally do not want to search within in Rails projects which you can use like so:

:Search 'Hello World'

Vim tip: Visual block editing

Vim is my favourite editor, it has been for many years. Over 10 years ago, in May 2010, I wrote a blog post about visual block editing in Vim. Much to my surprise that article is still read by people every month to this very day. Since its still relevant I have updated it and placed it here on my current blog.

This article assumes that you are familiar with the basics of Vim. If you are not yet familiar with vim then the vimtutor is a good place to start, you run it by executing “vimtutor” instead of “vim”. With that said, on to visual block editing!

Continue reading “Vim tip: Visual block editing”