Vim - Tips

(how to) make all tab windows equally high and wide

(how to) check current mode in vimscript

function! SetDiffMode()
  if &diff
    " ...

(how to) count number of matches of a pattern


count matches:


count lines with matches:


(how to) repeat previous search in history


(how to) paste the word under cursor to command line


(how to) tweak colorscheme for specific filetype

  3. :help syn-match

say, I want to use different foreground color for Elixir typespecs.

create ~/.vim/syntax/elixir.vim to override current colorscheme settings:

hi Typespec guifg=#A0A0B0 gui=italic
syn match Typespec /^\s*@spec.*$/

syn match command wouldn’t work in ~/vim/after/ftplugin/elixir.vim for some reason.

(how to) get relative path of current file


Although expand(‘%’) often works, there are rare occasions where it does not.

show current file path relative to PWD or path relative to home directory if current file is not in PWD:

:echo fnamemodify(expand('%'), ':~:.')

or else it’s possible to show absolute path if current file is not in PWD:

:echo fnamemodify(expand('%'), ':.')

(how to) wrap text on demand


gq command formats text which includes wrapping: