UP  |  HOME

Vim

Table of Contents

Vim uses a couple plugins, a color theme, and the associated config.

vimrc

Listing 1: ~/.vim/vimrc
set autochdir           " changes working dir to current file's
set nocompatible        " use vim defaults
set nomousehide         " don't hide cursor when typing
set belloff=all         " no beeps
syntax on               " enable syntax highlighting
set number              " display line numbers
filetype plugin indent on " enable filetype detect, plugins, indentation
set autoindent          " for unknown types, keep indent from prev. line
set tabstop=4           " tabs are 4 columns wide
set shiftwidth=4        " indent is 4 columns wide
"set noexpandtab        " don't convert tabs to spaces
set expandtab           " convert tabs to spaces
set wrap                " wrap long lines
set linebreak           " wrap at some characters (default " ^I!@*-+;:,./?")
set hlsearch            " highlight searched terms
set incsearch           " incremental search
set foldopen-=search    " don't open folds, only hit them once per search
set scrolloff=10        " display lines before/after search term
set enc=utf-8           " utf-8 encoding, default is latin1
set spelllang=en_us     " set spell lang, set encoding before this
set nospell             " disable spellcheck, use set spell as needed
set mouse=a             " mouse on terminal
set splitbelow          " open new horizontal split to the bottom
set splitright          " open new vertical split to the right
set wildmenu            " command-line completion. <Tab> moves <CR> completes
if isdirectory($HOME . '/.vim/undo') == 0
    :silent !mkdir -p ~/.vim/undo >/dev/null 2>&1
endif
set undodir=~/.vim/undo
set undofile            " store undo information for next session
set viminfo+=n~/.vim/viminfo
let &titleold = getcwd()
set title

" netrw
let g:netrw_keepdir = 0 " keep current dir same as browsing dir
let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+'
autocmd filetype netrw noremap <buffer> <TAB> /

" Leader mapping
let mapleader = ","
let maplocalleader = "-"

" Map semicolon to avoid shift, double ;; for repeat f/t behavior
map ; :
map ;; ;

" W is also write
command! W write

" Hightlight 79th column of long lines
highlight ColorColumn ctermbg=237 guibg=#333333
call matchadd('ColorColumn', '\%79v.', 100)

" fix matching brace highlighting to be consistent
hi MatchParen ctermfg=white ctermbg=black guifg=white guifg=black

colorscheme molokai
if has("gui_running")
    " Fix issue with Help button scaling: https://superuser.com/questions/1795492/how-to-resize-toolbar-in-gvim
    aunmenu ToolBar.Help
    " Original #465457 had too little contrast
    highlight Comment guifg=#666666
    highlight SpecialComment guifg=#666666 gui=bold
    " set window size
    set lines=35 columns=85
    " set font for various platforms
    if has ("gui_gtk2") || has("gui_gtk3")
        set guifont=Fira\ Code\ Medium\ 8
        "set guifont=DejaVu\ Sans\ Mono\ 8
    elseif has("gui_win32")
        set guifont=Fira\ Code:h8:cANSI
        "set guifont=DejaVu\ Sans\ Mono:h8:cANSI
    endif
endif

" shows some hidden chars when :set list
" tabs, trailing spaces, eol,
" extends/precedes are for long lines when wrap is disabled
set listchars=tab:‣•,trail:␣,eol:␤,extends:▸,precedes:◂

" Sane Line Joins (C-style comment blocks join nicely)
if v:version > 703 || v:version == 703 && has('patch541')
  set formatoptions+=j
endif

" Toggles colorcolumn highlighting, key set below
function! Togglecc()
    if &colorcolumn == 80
        :set colorcolumn=0
    else
        :set colorcolumn=80
    endif
endfunction

" F6 toggles colorcolumn
noremap <F6> :call Togglecc()<CR>

" F2 toggles list on
noremap <F2> :set list!<CR>

" F3/F4 are used by autotags plugin

" F5 runs make
noremap <F5> :make<CR>

" Open links with Utl (ctrl-click or <Leader>gu)
nnoremap <C-LeftMouse> <LeftMouse>:Utl<CR>
nnoremap <Leader>gu :Utl<CR>

" Add descriptions to tex usepackage lines
function! Texdesc()
    %s/^\\usepackage\(\[[a-zA-Z0-9_,-]*\]\)\={\([a-zA-Z0-9_-]\+\)}$/\=submatch(0) . ' % ' .substitute(system("~\/.local\/bin\/texdesc.sh ".submatch(2)), "\n", "", "")/g
endfunction
command! Texdesc call Texdesc()

" K inserts newline and places cursor after current line
nnoremap K i<CR><Esc>"_d^==k $

" Backspace and enter navigate paragraphs in normal mode
" onoremaps ensures paragraph object is also respected
nnoremap <expr> <CR> empty(&buftype) ? '}' : '<CR>'
onoremap <expr> <CR> empty(&buftype) ? '}' : '<CR>'
vnoremap <CR> }
" backspace also clears highlighting (if anything is highlighted)
nnoremap <expr> <BS> v:hlsearch?':noh<cr>':'{'
onoremap <BS> {
vnoremap <BS> {

" Save your swap files to .vim-swap in the current directory
" Otherwise to ~/.vim/swap, ~/tmp or .
if isdirectory($HOME . '/.vim/swap') == 0
    :silent !mkdir -p ~/.vim/swap >/dev/null 2>&1
endif
set directory=./.vim-swap//
set directory+=~/.vim/swap//
set directory+=.

" Syntastic 
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

noremap ]l :lnext<CR>
noremap [l :lprevious<CR>

" Enable pep8 checker for python
let g:syntastic_python_checkers = ['flake8', 'python']

" vim-orgmode settings
let g:org_export_init_script = "~/.emacs.d/elisp/org-settings.el"

" voom outliner
let g:voom_default_mode = 'org'

" Keep visual selection when indenting
vnoremap < <gv
vnoremap > >gv

" Search for visually selected text
vnoremap // y/<C-R>"<CR>

" Tabularize mappings for common things
nmap <Leader>t<Space>  :Tabularize /<Space><CR>
vmap <Leader>t<Space>  :Tabularize /<Space><CR>
nmap <Leader>t= :Tabularize /=<CR>
vmap <Leader>t= :Tabularize /=<CR>
nmap <Leader>t: :Tabularize /:\zs<CR>
vmap <Leader>t: :Tabularize /:\zs<CR>
nmap <Leader>t, :Tabularize /,\zs<CR>
vmap <Leader>t, :Tabularize /,\zs<CR>

" Alphabetic subscripts for some letters
" Used by typing <ctrl-k> then the digraph symbol and s in insert mode
" ₁₂₃₄₅₆₇₈₉₀ₐₑₕᵢₖₗₘₙₒₚᵣₛₜᵤᵥₓβγ
execute "digraphs as " . 0x2090
execute "digraphs es " . 0x2091
execute "digraphs hs " . 0x2095
execute "digraphs is " . 0x1D62
execute "digraphs ks " . 0x2096
execute "digraphs ls " . 0x2097
execute "digraphs ms " . 0x2098
execute "digraphs ns " . 0x2099
execute "digraphs os " . 0x2092
execute "digraphs ps " . 0x209A
execute "digraphs rs " . 0x1D63
execute "digraphs ss " . 0x209B
execute "digraphs ts " . 0x209C
execute "digraphs vs " . 0x1D65
execute "digraphs xs " . 0x2093
" beta and gamma
execute "digraphs bs " . 0x03B2
execute "digraphs gs " . 0x03B3
execute "digraphs us " . 0x03BC

" Remove trailing whitespace on write (for common source code) (disabled, too
" many issues with external codebases)
" autocmd FileType c,cpp,java,rust,sh,bash,python  autocmd BufWritePre <buffer> %s/\s\+$//e

autocmd BufNewFile *.html 0r ~/.vim/skeleton/html5.html|$

" Add system installed plugins, silent because I don't want errors
packadd! matchit
silent! packadd! doxygen-toolkit
silent! packadd! surround

" Load all plugins now.
packloadall
" Load all of the helptags now, ignore messages and errors.
silent! helptags ALL

Plugins

For those packaged in Debian, install them:

sudo apt install vim-scripts vim-tabular vim-snippets vim-tabular

Then enable them for your user with:

vim-addon-manager install doxygen-toolkit matchit surround syntastic snippets tabular

Plugin info

Plugin: autotags.vim
Purpose: Generates and updates ctags database
Author: Basil Gor
Site: http://github.com/basilgor/vim-autotags
Plugin: DoxygenToolkit.vim
Purpose: Generates Doxygen comments
Author: Mathias Lorente
Site: http://www.vim.org/scripts/script.php?script_id=987
Plugin: matchit.vim
Purpose: Extends matching functionality of the % key
Author: Benji Fisher
Site: http://www.vim.org/scripts/script.php?script_id=39
Plugin: syntastic.vim
Purpose: Syntax checking hacks
Author: Martin Grenfell
Site: https://github.com/vim-syntastic/syntastic
Color Scheme: molokai.vim
Info: Based on monokai color scheme
Author: Tomas Restreto
Site: https://github.com/tomasr/molokai

vim-orgmode

Install using vim8 plugin manager

mkdir -p  /.vim/pack/git-plugins/start
yadm submodule add https://github.com/jceb/vim-orgmode ~/.vim/pack/git-plugins/start/vim-orgmode

Ensure plugin manager is enabled

Listing 2: vimrc (excerpt)
" Load all plugins now.
packloadall
" Load all of the helptags now, ignore messages and errors.
silent! helptags ALL

Unmap conflicting keybinds after org mode (or other ftplugin) loads. Note that orgmode binds are all buffer-local

Listing 3: ~/.vim/after/ftplugin/org.vim
unmap <buffer> <CR>
set textwidth=0         " disable auto-breaking text
set foldlevel=99        " disable folding
set conceallevel=0      " don't conceal anything
set tabstop=4           " tabs are 8 columns wide

Fetch other plugins helpful to orgmode

Plugin: UTL.vim
Info: Universal Text Linking
Author: Steffan Bittner
Site: https://www.vim.org/scripts/script.php?script_id=293
Plugin: speeddating.vim
Info: Increment dates, times, etc.
Author: Tim Pope
Site: https://www.vim.org/scripts/script.php?script_id=2120
Plugin: calendar.vim
Info: Calendar date window in vim
Author: mattn
Site: https://github.com/mattn/calendar-vim
Install: git clone https://github.com/mattn/calendar-vim ~/.vim/pack/git-plugins/start/calendar-vim
Plugin: syntaxrange.vim
Info: Allows multiple syntax within a file
Author: Ingo Karkat
Site: https://www.vim.org/scripts/script.php?script_id=4168
Plugin: ingolibrary.vim
Info: Dependency of Syntax Range
Author: Ingo Karkat
Site: https://www.vim.org/scripts/script.php?script_id=4433