+" tabs and indent {{{2
+set shiftwidth=4 " number of spaces used for each step of (auto)indent
+set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
+set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
+set shiftround " round to 'shiftwidth' for "<<" and ">>"
+set expandtab " expand <Tab> to spaces in Insert mode
+set autoindent
+
+set pastetoggle=<F11> " key sequence to toggle paste mode
+
+" folding {{{2
+set foldmethod=marker " folding type
+set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
+
+" save and restore folds
+set viewoptions=cursor " only save cursor position
+
+" diff mode {{{2
+set diffopt=filler,vertical
+
+" reading and writing files {{{2
+set modeline " read modelines
+set modelines=2 " only check first/last 2 lines
+
+set writebackup " write a backup file before overwriting a file
+set backup " keep a backup after owerwriting a file
+set backupdir=$XDG_CACHE_HOME/vim/backup//
+
+set backupskip+=.netrc " skip netrc
+set backupskip+=/dev/shm/pass* " skip passwordstore files
+
+set undofile " persistent undo history
+set undodir=$XDG_CACHE_HOME/vim/undo//
+
+augroup undoskip
+ au!
+ au BufWritePre .netrc setlocal noundofile
+ au BufWritePre /dev/shm/pass* setlocal noundofile
+ au BufWritePre /tmp/* setlocal noundofile
+augroup END
+
+set autowrite " automatically write a file when leaving a modified buffer
+set autoread " automatically read a file that has been modified
+
+" the swap file {{{2
+set noswapfile
+set directory=$XDG_CACHE_HOME/vim/swap//
+
+" command line editing {{{2
+set history=5000 " how many command lines are remembered
+set wildmenu " command-line completion shows a list of matches
+set wildmode=longest:full,full " specifies how command line completion works
+
+set wildignore+=.hg,.git,.svn " Version control
+set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
+set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
+set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
+set wildignore+=*.spl " compiled spelling word lists
+set wildignore+=*.sw? " Vim swap files
+set wildignore+=*.luac " Lua byte code
+set wildignore+=*.pyc " Python byte code
+set wildignore+=*.orig " Merge resolution files
+
+" various {{{2
+set virtualedit=block " let cursor move past last char in <C-V> mode
+set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
+
+set viewdir=$XDG_CACHE_HOME/vim/view//
+
+" autocmds {{{1
+" Resize splits when the window is resized {{{2
+augroup resize
+ au!
+ autocmd VimResized * :wincmd =
+augroup END
+
+" Only show cursorline in the current window and in normal mode {{{2
+augroup cline
+ au!
+ au WinLeave,InsertEnter * set nocursorline
+ au WinEnter,InsertLeave * set cursorline
+augroup END
+
+" Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
+augroup ft_stdin
+ au!
+ au StdinReadPost * :set buftype=nofile
+augroup END
+
+" Jump to last known cursor position {{{2
+augroup cursor_pos
+ au!
+ " blacklist certain filetype
+ let blacklist = ['gitcommit']
+ autocmd BufReadPost *
+ \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
+ \ exe "normal! g`\"" |
+ \ endif
+augroup END
+
+" bindings {{{1
+
+" allow both <space> and / to be <leader>
+map <space> <leader>
+
+" make
+nnoremap <leader>r :make<cr>
+nnoremap <leader><cr> :make<cr>
+
+" unhighlight search
+nnoremap <silent> <Leader>/ :silent nohl<CR>
+
+" Tabs
+nnoremap <leader>[ :tabprev<cr>
+nnoremap <leader>] :tabnext<cr>
+
+" paste from selection
+nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
+" paste from clipboard
+nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
+
+" Clean trailing whitespace
+nnoremap <silent> <leader>ww m':%s/\s\+$//<cr>:let @/=''<cr>``zz
+
+" Source
+vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
+nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
+
+" jump to last cursor position
+noremap ' `
+
+" Select (charwise) the contents of the current line, excluding indentation.
+nnoremap vv ^vg_
+
+" Unfuck my screen
+nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
+
+" Ranger
+" nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
+" nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
+
+" Use sane regexes.
+nnoremap / /\v
+vnoremap / /\v
+cnoremap s/ s/\v
+
+" display the number of matches for the last search
+nmap <Leader># :%s:<C-R>/::gn<CR>
+
+" center cursor after search and open folds
+nnoremap n nzzzv
+nnoremap N Nzzzv
+
+" same when jumping around
+nnoremap g; g;zzzv
+nnoremap g, g,zzzv
+nnoremap <c-o> <c-o>zzzv
+
+" Not using the default mappings of 'To line from top/bottom'
+noremap H ^
+noremap L $
+vnoremap H ^
+vnoremap L g_
+
+" Heresy, emacs insert bindings
+inoremap <c-a> <esc>I
+inoremap <c-e> <esc>A
+cnoremap <c-a> <home>
+cnoremap <c-e> <end>
+
+" proper movement when lines are wrapped
+noremap <expr> j (v:count == 0 ? 'gj' : 'j')
+noremap <expr> k (v:count == 0 ? 'gk' : 'k')
+
+" disable arrows
+noremap <Up> <NOP>
+noremap <Down> <NOP>
+noremap <Left> <NOP>
+noremap <Right> <NOP>
+inoremap <Up> <NOP>
+inoremap <Down> <NOP>
+inoremap <Left> <NOP>
+inoremap <Right> <NOP>
+cnoremap <Up> <NOP>
+cnoremap <Down> <NOP>
+cnoremap <Left> <NOP>
+cnoremap <Right> <NOP>
+cnoremap <C-K> <Up>
+cnoremap <C-J> <Down>
+cnoremap <C-H> <Left>
+cnoremap <C-L> <Right>
+
+" close all folds open fold in cursor
+nnoremap zx zMzxzt
+
+map <F1> :ls<CR>:b<space>
+
+nnoremap <C-L> <C-W>w
+nnoremap <C-H> <C-W>W
+
+"xterm mouse with middleclick paste
+nnoremap <MiddleMouse> i<MiddleMouse>
+vnoremap <MiddleMouse> s<MiddleMouse>