Tech and travel

Category: Vim

Go and vim

2014-11-11

The default vim go language syntax file uses a tabstop of 8, which is a bit excessive.

Replace last occurrence of a character in vim

2013-06-03

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

2007-08-15

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 cursorline set nowrap set ic " Ignore case set ai " autoindent set tabstop=4 set shiftwidth=4 set expandtab set cul " Cursor highlight map <f1> ^hhxxj0 map <f2> ^i <esc>j0 The last 2 entries add mappings for F1 and F2, to dedent and indent the current line.

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

2007-08-07

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 the last line. :%s/COMPILE/COMPILE BODY/g

Inserting the current filename in Vim

2006-11-02

To insert the current file name in Vim, go to insert mode. Then type Control-R % . With Control-R you can do more things : Control-R =5*4 This inserts 20 into the current cursor position. Some examples can be found here

Copyright (c) 2024 Michel Hollands