Ivy Occur Customizations

I really like ivy-occur and the way you can take a list of Ivy completion candidates and put it in a separate buffer that you can manipulate in any of the usual Emacs ways. The easiest way to use it is to type Ctrl+c Ctrl+o in a selection list.

It turns out that you can customize what gets put in the ivy-occur buffer for a specific command by writing a function to fill the buffer and registering it with Ivy. One really nice example is that is set by default is the swiper command. You can do a Swiper search and capture all the candidates with ivy-occur. That’s useful if you want to interact with more than one of the selections but what’s really nice is that the buffer inherits grep-mode and can be made writable with the usual Ctrl+x Ctrl+q. That makes it really easy to make multiple changes to a buffer, especially if you leverage something like iedit or multiple-cursors.

Recently, abo-abo announced a new ivy-occur customization: this time for find-file type commands. It results in the occur buffer becoming a Dired buffer. That means you can use the power of Dired to manipulate the list of files. As a real-world example, I often preview my blog posts locally in my browser. That causes the post to be rendered in HTML and placed in a file that the browser can display. Ideally, I delete that file after I publish the post but I usually forget and end up with several useless HTML files in my posts directory.

I used to deal with that by bringing up Dired, typing * . html to mark all the HTML files and then delete them by typing D. With the abo-abo’s latest change I can just type Ctrl+x Ctrl+f html$ to get a list of the HTML files and then Ctrl+c Ctrl+o t D y to delete them.

Follow the link to abo-abo’s post for all the details. And if you aren’t already using Ivy/Counsel/Swiper, you really should try them out. As I keep saying, they are my most useful package.

UPDATE [2017-11-21 Tue 15:48]: git-modegrep-mode

This entry was posted in General and tagged . Bookmark the permalink.