dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE

vimrc (6799B)


      1 set nocompatible
      2 filetype plugin indent on
      3 syntax enable
      4 set clipboard=unnamed " use system clipboard
      5 set dictionary+=/usr/share/dict/words " word completion using Ctrl-x Ctrl-k
      6 set directory=.,~/tmp,/var/tmp,/tmp " location for swap files
      7 set go+=c           " do not show popups in gui
      8 set hlsearch        " highlight search matches
      9 set ignorecase      " case-insensitive search
     10 set incsearch       " search as you type
     11 set laststatus=2    " always show the statusline
     12 set lbr             " break lines between words
     13 set list            " rendering of invisible characters
     14 set listchars=tab:▸\ ,eol:¬ " Use symbols for tab and end-of-line
     15 set nojoinspaces    " disable double spaces after periods
     16 set nomodeline      " disable per-file options
     17 set pastetoggle=<F2> " toggle paste mode
     18 set scrolloff=3     " show context above-below cursorline
     19 set shiftwidth=4    " width for autoindents
     20 set smartcase       " case-sensitive search if any caps
     21 set tabstop=4       " number of spaces for tab
     22 set textwidth=80    " default line width in number of characters
     23 set wildmenu        " show a navigable menu for tab completion
     24 set wildmode=longest,list,full
     25 
     26 " use faster :grep alternatives when available
     27 if executable("rg")
     28     set grepprg=rg\ --vimgrep\ --no-heading
     29     set grepformat=%f:%l:%c:%m,%f:%l:%m
     30 elseif executable("ag")
     31     set grepprg=ag\ --nogroup\ --nocolor\ --ignore-case\ --column
     32     set grepformat=%f:%l:%c:%m,%f:%l:%m
     33 endif
     34 
     35 " highlight 81st column
     36 set colorcolumn=+1
     37 
     38 colorscheme adbasic
     39 
     40 " statusline helper functions
     41 function! StatuslineLinterWarnings() abort
     42     let l:counts = ale#statusline#Count(bufnr(''))
     43     let l:all_errors = l:counts.error + l:counts.style_error
     44     let l:all_non_errors = l:counts.total - l:all_errors
     45     return l:all_non_errors == 0 ? '' : printf(' %d ⚠ ', all_non_errors)
     46 endfunction
     47 "
     48 function! StatuslineLinterErrors() abort
     49     let l:counts = ale#statusline#Count(bufnr(''))
     50     let l:all_errors = l:counts.error + l:counts.style_error
     51     let l:all_non_errors = l:counts.total - l:all_errors
     52     return l:all_errors == 0 ? '' : printf(' %d ✖', all_errors)
     53 endfunction
     54 
     55 function! StatuslineLinterOK() abort
     56     let l:counts = ale#statusline#Count(bufnr(''))
     57     let l:all_errors = l:counts.error + l:counts.style_error
     58     let l:all_non_errors = l:counts.total - l:all_errors
     59     return l:counts.total == 0 ? '✓' : ''
     60 endfunction
     61 
     62 augroup StatuslineConfig
     63 
     64     " define custom highlight groups for statusline coloring
     65     highlight User1 ctermfg=NONE guifg=#d0d0d0 ctermbg=NONE guibg=#585858
     66     " highlight User2 ctermfg=NONE guifg=#969696 ctermbg=NONE guibg=#585858
     67     " highlight User3 ctermbg=NONE guibg=#808080 ctermfg=NONE guifg=#444444
     68     " highlight User4 ctermfg=NONE guifg=#d0d0d0 ctermbg=NONE guibg=#444444
     69 
     70     " empty statusline and populate later
     71     set statusline=
     72 
     73     " left
     74     set statusline+=%1*           " set User1 color
     75     set statusline+=\%t\         " tail of filename
     76     " set statusline+=%4*           " set User4 color
     77     set statusline+=\ %h%w%m%r\   " flags for help file, preview, modified, R/O
     78     "set statusline+=%#LineNr#     " set default background
     79 
     80     " center spacing
     81     set statusline+=%=            " add separation between left and right items
     82 
     83     " right
     84     " set statusline+=%3*           " set User3 color
     85     set statusline+=\ %c:%l       " line and column view
     86 augroup END
     87 let user_correct_dict = {
     88             \ 'Anders': ['ANders'],
     89             \ 'anders@adamsgaard.dk': ['@@'],
     90             \ 'https://adamsgaard.dk': ['adweb'],
     91             \ }
     92 
     93 augroup danish_symbols
     94     " escape any of these by pressinv C-v before inserting the character
     95     inoremap AE æ
     96     inoremap OE ø
     97     inoremap AA å
     98 augroup END
     99 
    100 augroup abbreviations
    101     iabbrev ssig -- <cr>Anders Damsgaard<cr>https://adamsgaard.dk
    102 augroup END
    103 """ Keyboard shortcuts
    104 
    105 " use space instead of \ as leader
    106 let mapleader="\<Space>"
    107 
    108 " Shortcut to reload .vimrc and ~/.vim/plugin/*.vim
    109 nnoremap <leader>R :source $MYVIMRC<cr>:runtime! plugin/*.vim<cr>:echo "Configuration reloaded"<cr>
    110 
    111 nnoremap <Leader>w :w<cr>
    112 nnoremap <Leader>W :wa<cr>
    113 nnoremap <Leader>q :q<cr>
    114 nnoremap <leader>Q :qa<cr>
    115 nnoremap <Leader>x :x<cr>
    116 
    117 nnoremap <leader>s :set spell!<cr>
    118 nnoremap <leader>N :set number!<cr>
    119 nnoremap <leader>n :set relativenumber!<cr>
    120 
    121 nnoremap <leader>d :Lex<cr>
    122 
    123 " https://www.vi-improved.org/recommendations/
    124 "" add files with wildcards
    125 nnoremap <leader>a :argadd <c-r>=fnameescape(expand('%:p:h'))<cr>/*<c-d>
    126 "" go to file open prompt
    127 nnoremap <leader>e :e **/
    128 nnoremap <leader>g :grep<space>
    129 "" ilist function from qlist, make ilist go into quickfix window
    130 nnoremap <leader>i :Ilist<space>
    131 nnoremap <leader>m :make<cr>
    132 autocmd VimEnter * if exists(":Make") |
    133             \ exe "nnoremap <leader>m :Make<cr>" |
    134             \ endif
    135 
    136 "" go to last used buffer
    137 nnoremap <leader><tab> :b#<cr>
    138 
    139 nnoremap <leader>% :vsplit<space>
    140 nnoremap <leader>" :split<space>
    141 
    142 " shortcuts to commonly used files
    143 nnoremap <leader>CC :e $MYVIMRC<cr>
    144 nnoremap <leader>T :e ~/doc/todo.md<cr>
    145 nnoremap <leader>B :e $BIB \| :windo normal G<cr>
    146 
    147 nnoremap <leader>r :read !scholarref<space>
    148 
    149 " insert date and time
    150 nnoremap <leader>D :read !date +"\# \%Y-\%m-\%d \%T \%Z (\%z UTC)"<cr>
    151 
    152 " toggle x mark in checklist fields
    153 nnoremap <leader>X :s/\[[x ]\]/\=submatch(0) == '[x]' ? '[ ]': '[x]'/<cr>:noh<cr>
    154 
    155 if exists(':tnoremap')
    156     " escape from terminal mode
    157     tnoremap <Esc> <C-\><C-n>
    158 
    159     " send escape to terminal
    160     tnoremap <M-[> <Esc>
    161     tnoremap <C-v><Esc> <Esc>
    162 
    163     " navigate away from terminals
    164     tnoremap <C-h> <C-\><C-n><C-w>h
    165     tnoremap <C-j> <C-\><C-n><C-w>j
    166     tnoremap <C-k> <C-\><C-n><C-w>k
    167     tnoremap <C-l> <C-\><C-n><C-w>l
    168 end
    169 
    170 " launch terminal in current window
    171 nnoremap <leader><cr> :terminal<cr>
    172 
    173 " Use home row keys as Esc
    174 inoremap jk <Esc>
    175 
    176 nnoremap <leader>o :browse oldfiles<cr>
    177 nnoremap <leader>, :b <c-d>
    178 nnoremap <leader>f :e <c-d>
    179 
    180 " cycle through quickfix items
    181 nnoremap <silent> ]c :cnext<cr>
    182 nnoremap <silent> [c :cprevious<cr>
    183 
    184 " Add completion bindings (cycle with C-n, C-p), see :h ins-completion
    185 " <C-x><C-l>: while line
    186 " <C-x><C-n>: keywords in current file
    187 " <C-x><C-i>: keywords in current and included files
    188 " <C-x><C-k>: keywords in dictionary (:set dictionary)
    189 " <C-x><C-t>: keywords in thesaurus (not functional)
    190 " <C-x><C-]>: tags
    191 " <C-x><C-f>: file names
    192 " <C-x><C-d>: definitions or macros
    193 " <C-x><C-v>: vim command-line
    194 " <C-x><C-v>: omni completion
    195 " <C-x>s:     spelling suggestions
    196 
    197 " save current session
    198 " (open with `vim -S <sessionname>.vim` or :source <sessionname>
    199 nnoremap <leader>S :mksession! <c-r>%.session.vim
    200 
    201 " analyze written text with statistics and neural network
    202 nnoremap <leader>L :w<cr>:cexpr system('languagetool-vim ' . shellescape(expand('%')))<cr>