Skip to content

Instantly share code, notes, and snippets.


getcompletion() hell

As if string comparisons being influenced by 'ignorecase' wasn't bad enough determining what will come out of getcompletion() is a like a bag of cats.

Type Follows 'ignorecase' Force case (in)sensitivity
arglist Always insensitive With \\C
augroup Always insensitive With \\C

Switching buffers and opening files

Out of the box Vim allows us to pretty easily open a buffer on a partial match or make wildcard searches for files to edit. As illustrated along with some other things in [this excellent post][1].

So we certainly don't need something like a flashy fuzzy matcher as we have the functionality built in. However what we do lack is the uniform interface. One of the more common patterns I find myself in is thinking if I want to use the :buffer or :edit command.


As of 8.1.2233 Vim has v:argv available to represent the arguments Vim was invoked with as a list.

We can get an equivalent list on *NIX systems with the following, useful if the version of Vim does not support v:args.

split(system('ps -o command= -p' . getpid()))

Enable hlsearch whenever the cursor is on any part of a match and disable hlsearch otherwise.

Whenever the cursor is moved the current line is checked if it contains a match for the current search. If it does a range is created that can be compared to the cursor's current column. This matching is repeated for the current line until no more matches are found.

function! AutoHL() abort

Searching in Vim isn't limited to / and ? however those other searches don't have the same easy one key command to move through matches and I'm lazy. So let's make N and n move to the next match for whatever the last type of search was performed. I'm mainly interested in the quickfix list but I've written this generically so it can be easily adapted to other sources.

function! Cycle(type, forward) abort
george-b /
Last active Nov 30, 2020
Lazy case correction for user commands

Some user commands are intended as replacements for built-in commands, for example :Grep may replace :grep. Given the existence of such a "replacement" user command when typing :grep it would be convenient to have it replaced with :Grep for the sake of muscle memory.

For other user commands a similar replacement scheme may be desirable simply to avoid having to chord with the shift key.

We can achieve this with command-line abbreviations.


Vim will not create parent directories if they do not exist on write.

A common method to ensure the path exists is to use an autocmd to check if the parent path exists and if not create it.

function! MkDir(path) abort
  if !isdirectory(a:path)
    call mkdir(a:path, 'p')

Many people (myself included) have set wildcharm=<C-Z> as suggested by :help 'wildcharm' in their config. However in mappings I often see this is repeated explicitly, e.g.

nnoremap <key> :buffer<Space><C-Z><S-Tab>

I prefer to refer to the setting itself, avoiding repetition and also making things more portable. A conversion of the above would be as follows.



Some functions that I think should exist or re-implementations of existing functions with modified behaviour.


Check if a list contains an item or not, returns a boolean.

Typically the index() function is used to do this. However as it



In an effort to consolidate my focus in Vim I wondered what it would be like if I limited myself to a single window. This notion came about because I knew I wasn't utilizing things like tags, jumps, and the quickfix list as effectively could be done.

It's important to remember that no configuration is a substitute for discipline when learning to change. This is simply a journey I went on and sharing what I learnt about Vim along the way.