Skip to content

Vim Tricks (for academics)

Vince Buffalo edited this page Mar 31, 2016 · 11 revisions

Why Vim?

This is probably the best essay on the subject: https://medium.com/@mkozlows/why-atom-cant-replace-vim-433852f4b4d1

Also, this too: http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118

Text Objects

Text objects are what make Vim > Emacs in my opinion (and I do like Emacs — a lot). This article does a terrific job introducing them.

LaTeX

There are two options: LaTeX-Box and vimtex. I went with vimtex because it's newer. There's nice features like scanning of *.bib files and then autocompleting BibTeX citation keys:

Vimtex likes folding -- you can open folds with zo and close them with zc. You can also move efficiently between sections with ]] (forward) and [[.

Quickly changing environments: cse for change surronding environment.

Commands are run through the local leader, which is by default \. For example, \lt opens the table of contents.

Highlight LaTeX inline comments

My advisor uses a notation like \vb{comment} to LaTeX files. This is defined as:

\newcommand{\vb}[1]{{\it \color{blue} #1}}

The following code highlights our two colors in Vim:

" |- LaTeX comment hacks
function! FindLaTeXComments()
  highlight CommentGC ctermfg=red
  highlight CommentVB ctermfg=blue
  call matchadd('CommentGC', '\\gc{\_[^}]*}')
  call matchadd('CommentVB', '\\vb{\_[^}]*}')
endfunction

command! GC call FindLaTeXComments()
nnoremap <leader>gc :GC<cr>

Clone this wiki locally