Vim Configuration File
Table of Contents
1 ~/.config/vim/vimrc
1.1 set default directories
" XDG Base Directory {{{ "from https://wiki.archlinux.org/title/Vim if empty($XDG_CACHE_HOME) | let $XDG_CACHE_HOME = $HOME."/.cache" | endif if empty($XDG_CONFIG_HOME) | let $XDG_CONFIG_HOME = $HOME."/.config" | endif if empty($XDG_DATA_HOME) | let $XDG_DATA_HOME = $HOME."/.local/share" | endif if empty($XDG_STATE_HOME) | let $XDG_STATE_HOME = $HOME."/.local/state" | endif set runtimepath^=$XDG_CONFIG_HOME/vim set runtimepath+=$XDG_DATA_HOME/vim set runtimepath+=$XDG_CONFIG_HOME/vim/after set packpath^=$XDG_DATA_HOME/vim,$XDG_CONFIG_HOME/vim set packpath+=$XDG_CONFIG_HOME/vim/after,$XDG_DATA_HOME/vim/after let g:netrw_home = $XDG_DATA_HOME."/vim" call mkdir($XDG_DATA_HOME."/vim/spell", 'p') set backupdir=$XDG_STATE_HOME/vim/backup | call mkdir(&backupdir, 'p') set directory=$XDG_STATE_HOME/vim/swap | call mkdir(&directory, 'p') set undodir=$XDG_STATE_HOME/vim/undo | call mkdir(&undodir, 'p') set viewdir=$XDG_STATE_HOME/vim/view | call mkdir(&viewdir, 'p') call mkdir($XDG_DATA_HOME."/vim/spell", 'p', 0700) if !has('nvim') | set viminfofile=$XDG_STATE_HOME/vim/viminfo | endif " }}}
1.2 Sane default from archlinux
Use Vim defaults instead of 100% vi compatibility
if &compatible set nocompatible endif
1.3 move temporary files into a secure location
if exists('$XDG_CACHE_HOME') let &g:directory=$XDG_CACHE_HOME else let &g:directory=$HOME . '/.cache' endif let &g:undodir=&g:directory . '/vim/undo//' let &g:backupdir=&g:directory . '/vim/backup/' let &g:directory.='/vim/swap//' " Create directories if they doesn't exist if ! isdirectory(expand(&g:directory)) silent! call mkdir(expand(&g:directory), 'p', 0700) endif if ! isdirectory(expand(&g:backupdir)) silent! call mkdir(expand(&g:backupdir), 'p', 0700) endif if ! isdirectory(expand(&g:undodir)) silent! call mkdir(expand(&g:undodir), 'p', 0700) endif
1.4 Make shift-insert work like in Xterm
if has('gui_running') map <S-Insert> <MiddleMouse> map! <S-Insert> <MiddleMouse> endif
1.5 Misc sane defaults
" Load plugins according to detected filetype. filetype plugin indent on " Enable syntax highlighting. syntax on " Indent according to previous line. set autoindent " Use spaces instead of tabs. set expandtab " Tab key indents by 4 spaces. set softtabstop =4 " >> indents by 4 spaces. set shiftwidth =4 " >> indents to next multiple of 'shiftwidth'. set shiftround " Make backspace work as you would expect. set backspace =indent,eol,start " Switch between buffers without having to save first. set hidden " Always show statusline. set laststatus =2 " Show as much as possible of the last line. set display =lastline " Show current mode in command-line. set showmode " Show already typed keys when more are expected. set showcmd " Highlight while searching with / or ?. set incsearch " Keep matches highlighted. set hlsearch " Faster redrawing. set ttyfast " Only redraw when necessary. set lazyredraw " Open new windows below the current window. set splitbelow " Open new windows right of the current window. set splitright " Find the current line quickly. set cursorline " Searches wrap around end-of-file. set wrapscan " Always report changed lines. set report =0 " Only highlight the first 200 columns. set synmaxcol =200 " Show non-printable characters. set list set noruler if has('multi_byte') && &encoding ==# 'utf-8' let &listchars = 'tab:▸ ,extends:❯,precedes:❮,nbsp:±' else let &listchars = 'tab:> ,extends:>,precedes:<,nbsp:.' endif " Ignore case when searching set ignorecase " When searching try to be smart about cases set smartcase " Show matching brackets when text indicator is over them set showmatch
1.6 modular
runtime modules/plug.vim runtime modules/keybindings.vim runtime modules/ui.vim
1.6.1 plug
call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.local/share/vim/plugged') Plug 'preservim/nerdtree' Plug 'easymotion/vim-easymotion' call plug#end()
1.6.2 keybindings
let mapleader = "\<Space>" " Fast saving nmap <leader>w :w!<cr> " :W sudo saves the file " (useful for handling the permission-denied error) command! W execute 'w !sudo tee % > /dev/null' <bar> edit! " Close the current buffer map <leader>bd :Bclose<cr>:tabclose<cr>gT " Close all the buffers map <leader>ba :bufdo bd<cr> map <leader>l :bnext<cr> map <leader>h :bprevious<cr>
1.6.3 ui
" Enable syntax highlighting syntax enable " Set regular expression engine automatically set regexpengine=0 " Enable 256 colors palette in Gnome Terminal if $COLORTERM == 'gnome-terminal' set t_Co=256 endif " Set extra options when running in GUI mode if has("gui_running") set guioptions-=T set guioptions-=e set t_Co=256 set guitablabel=%M\ %t endif " Set utf8 as standard encoding and en_US as the standard language set encoding=utf8 " Use Unix as the standard file type set ffs=unix,dos,mac " Disable scrollbars (real hackers don't use scrollbars for navigation!) set guioptions-=r set guioptions-=R set guioptions-=l set guioptions-=L " No annoying sound on errors set noerrorbells set novisualbell set t_vb= set tm=500 " set mouse for all modes set mouse=a set mousemodel=popup_setpos silent! set ttymouse=sgr " title set title set titlestring= set titlestring+=%t%(\ %M%)%(\ (%{expand(\"%:p:~:.:h\")}/)%) set titlestring+=\ \|\ %{$USER}@%{hostname()}:%{substitute(getcwd(),$HOME,'~','')} " Start NERDTree, unless a file or session is specified, eg. vim -S session_file.vim. autocmd StdinReadPre * let s:std_in=1 autocmd VimEnter * if argc() == 0 && !exists('s:std_in') && v:this_session == '' | NERDTree | endif " Close the tab if NERDTree is the only window remaining in it. autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif