Linked List

A personal knowledge base

Vim

#Rebuild Project on Write

Using the terminal built into Neovim you can trigger a build of a project whenever you write a file. In the example below, whenever a Rust file is written cargo build is run. The example makes use of neoterm, which provides the T command to make dealing with the Neovim terminal easier.

autocmd! bufwritepost *.rs T cargo build

#Use vim as a Syntax Highlighted Pager

vim/neovim come with a script that makes vim behave as a pager (like less). It’s basically a syntax highlighted version of less. Great for inspecting the content of source files. On my Arch box it’s at /usr/share/nvim/runtime/macros/less.sh.

#Underline the Current Line With Dashes

yyp<c-v>$r-

http://vim.wikia.com/wiki/Underline_using_dashes_automatically#Using_a_mapping

#Convert Ruby Hash Syntax

%s/:\([a-z_]\+\) => /\1: /gc

#Convert Image tag to Rails Image Helper

%s/img src="site\/images\/\([^"]\+\)" width="\([^"]\+\)" height="\([^"]\+\)" class="\([^"]\+\)"\/>/%= image_tag '\1', :width => \2, :height => \3, :class => '\4' %>/

#Replace HTML Comments With ERB Comments

%s/<!--\(.*\)-->/<%#\1%>/

#Repeat Macro to End of File

%normal @q

#Open Paths With Line Numbers in Vim

See: http://www.wezm.net/technical/2015/09/vim-open-file-at-colon-line-number/

#Specify File Encoding on Command Line

This example was used to open a UTF-16LE file generated by iTunes (Export Playlist… > Unicode Text):

vim -c "e ++enc=utf-16le ++ff=mac" file.txt

#Perform Replacement on 2nd Line of all Buffers

bufdo 2s/foo/bar/ | w

#Virtual Replace Mode

Virtual Replace mode is similar to Replace mode, but instead of replacing actual characters in the file, you are replacing screen real estate, so that characters further on in the file never appear to move.

http://vimdoc.sourceforge.net/htmldoc/insert.html#Virtual-Replace-mode

Last modified: 21 Aug 2017