Skip to content

Category Archives: Vim

Go and vim

The default vim go language syntax file uses a tabstop of 8, which is a bit excessive. Adding the following to ~/.vimrc makes the code nice and compact : ” Use a tabstop of 2 for go files autocmd FileType go setlocal shiftwidth=2 tabstop=2

Replace last occurrence of a character in vim

This stackoverflow post has a cool way to remove the last occurrence of a character in vim : :%s/.*\zs,/|/ This replaces the last occurrence of a comma with a pipe. Other examples can be found on the vim wikia.

Highlight the current line in Vim

To highlight the current line in Vim, you have to set the cursorline setting. :set cursorline :set cul These two are the same. This can also be set in your _vimrc file, you don’t need the colon then. Here’s an extract from my vimrc file: set nowrap set ic ” Ignore case set ai ” […]

Substituting from this line to the end of the file (in Vim)

In vim, if you want to change something from the current line until the end of the line, you can use .,$ as the range segment of the s command. :.,$s/COMPILE/COMPILE BODY/g Substituting over the full file is done by using the % range, which is a shortcut for 1,$, ie from the first to […]