Filtering all posts in Vim

4 December 2017

I set Firefox 57 — the new version with the overhauled browsing engine — as my default browser this morning, replacing Chrome.

The same 4 extensions are installed on every browser I use: Ghostery, uBlock Origin, HTTPS Everywhere and a fourth that provides Vim keybindings. In Chrome, that plugin has always been Vimium.

Vimium is available for Firefox, but it isn’t yet compatible with version 57. In fact, after looking around a little, most Vim keybinding plugins seem to be incompatible with version 57.

My search eventually led me to Saka Key, the pot of gold at the end of the rainbow. It’s fast (not that that was ever a problem with Vimium), open source, configurable, well designed (that was a problem with Vimium), and supports the same bindings as Vimium1. It even has a Chrome version.


  1. Vimium’s bindings aren’t the default ones. To use them, go to “Add Ons” → “Saka Key” → “Preferences” and choose “vimium” from the dropdown next to the “Keybindings” heading. [return]

The scripts I use for blogging with Vim and Hugo

Nearly 4 months ago to the day I setup a publishing workflow for this site that allows me to create, update, and delete content via Google Drive. It’s a setup that has worked flawlessly for me.

In my quest to streamline the blogging process as much as possible, I also wrote a couple of scripts around the same time. The first to create a new post, the second to publish the post currently open in Vim. These too have worked very well, so let’s take a look at them.

Continue Reading →

1 May 2017
12 April 2017

MVC mappings for CtrlP

It’s been a while since I last shared anything Vim related.

My favourite somewhat-recent addition to my .vimrc is a set of CtrlP mappings for searching directly within an apps model, view, controller, or helper directories.

nnoremap <leader>c :CtrlP src/controllers<cr>
nnoremap <leader>h :CtrlP src/helpers<cr>
nnoremap <leader>m :CtrlP src/models<cr>
nnoremap <leader>v :CtrlP src/views<cr>

Chances are, your MVC directories don’t live in src/ in your project. If you build Rails apps for example, then you’ll want to change that to app/.

I first saw these mappings in Gary Bernhardt‘s dotfiles, so full credit to him.

26 January 2017
19 January 2017
13 December 2016

Section comments with centred text in Vim

Everyone has their own taste when it comes to comment styles. I personally like section comments with centred text as shown below. They’re time consuming to get right though so I tend to opt for a simpler format.

/* -------------------------------------------------------------------------- *
 *                                 COMPONENTS                                 *
 * -------------------------------------------------------------------------- */

Some light procrastination led me to investigating how much of the above layout could be automated in Vim. As it turns out, all of it. Here’s what the final workflow looks like in action.

The mapping isn’t particularly pleasant to read, but it works.

nnoremap <leader>sh VU:center 79<cr>0c2l<space>*<space><esc>A<space><esc>40A<space><esc>d79<bar>ch<space>*<esc>YPS<esc>i/*<space><esc>74A-<esc>A<space>*<esc>jo<esc>S<esc>i<space>*<space><esc>74A-<esc>A<space>*/<esc>o<esc>o<bs>

As a reminder, you can change the mapped commands based on the filetype of the file being edited. That way, <leader>sh can always be “section header” but the comment syntax can be changed for languages that don’t use /* */.

autocmd BufRead,BufNewFile *.{es6,js,scss,css} nnoremap <leader>sh VU:center 79<cr>…
22 November 2016

Setup CtrlP to use ripgrep in Vim

A few weeks ago I wrote about switching from CtrlP and The Silver Searcher to fzf and ripgrep. I have since returned to CtrlP and thought I’d share how to set that up with ripgrep too.

From my time with fzf, I can attest to the fact that it is indeed faster than CtrlP when the time comes to search for something. Having said that, I later discovered via a quick process of elimination that it also drags down Vim’s general performance.

Continue Reading →

14 November 2016

Sorting lines in Vim

Amongst Vim’s many commands, there’s the humble yet powerful :sort. As you’d expect, it takes a selection or a range and sorts it. By default, that sort is numerical (`through9), then alphabetical (AthroughZfollowed byathroughz`).

All that to say that running a generic :sort on the characters to the left in the following example would result in them being reordered to how you see them on the right.

Continue Reading →

30 October 2016

Using ripgrep and fzf instead of The Silver Searcher and CtrlP in Vim

Update 22/11/2016: I have gone back to CtrlP. If you would like to know how to set that up to use ripgrep, please see here.

I have been using The Silver Searcher and CtrlP with caching turned off for my file-opening needs and it’s a setup that has served me well. Turning off caching doesn’t drag down performance too much, however there is still a noticable speed decrease (as you might expect).

Continue Reading →

30 August 2016

Better find and replace in Vim

Doing a document-wide find and replace in Vim looks like this:

:%s/find this/replace with this/g

Alternatively, we can drop the range of the find and replace from all lines to only the current one by removing the %:

:s/find this/replace with this/g

Continue Reading →

You can keep up to date with new posts by subscribing to the RSS Feed or by following me on Micro.blog.