vim

vim config files
git clone https://git.bracken.jp/vim.git
Log | Files | Refs | LICENSE

vimrc (7465B)


      1 set nocompatible
      2 set encoding=utf-8
      3 
      4 " Remove any autocmds defined by the system for consistency.
      5 if has("autocmd")
      6   autocmd!
      7 endif
      8 
      9 .
     10 
     11 filetype off
     12 call plug#begin('~/.vim/plugged')
     13 Plug 'rhysd/vim-clang-format'
     14 Plug 'vim-scripts/spacehi.vim'  " Highlight bad whitespace
     15 Plug 'https://git.bracken.jp/vimwiki.git', { 'branch': 'space-link-resolution' }
     16 
     17 " Language support plugins.
     18 Plug 'nathangrigg/vim-beancount'
     19 Plug 'cespare/vim-toml'
     20 Plug 'dart-lang/dart-vim-plugin'
     21 Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
     22 Plug 'google/vim-ft-bzl'
     23 Plug 'lervag/vimtex'
     24 Plug 'keith/swift.vim'
     25 Plug 'rust-lang/rust.vim'
     26 Plug 'https://gn.googlesource.com/gn', { 'rtp': 'misc/vim' }
     27 call plug#end()
     28 filetype plugin indent on
     29 
     30 " Bind fancier manpage plugin to Shift-k.
     31 runtime ftplugin/man.vim
     32 set keywordprg=:Man
     33 
     34 let mapleader=','
     35 let s:cpo_save=&cpo
     36 set cpo&vim
     37 
     38 " Enable middle-mouse paste.
     39 map!     <S-Insert> <MiddleMouse>
     40 map      <S-Insert> <MiddleMouse>
     41 
     42 " Kill ex mode.
     43 noremap  Q          <NOP>
     44 
     45 " Disable visual-mode mouse select.
     46 set mouse=
     47 
     48 " Kill arrow keys, for great justice.
     49 noremap  <Up>       <NOP>
     50 noremap  <Down>     <NOP>
     51 noremap  <Left>     <NOP>
     52 noremap  <Right>    <NOP>
     53 
     54 " Retain selection on <,>.
     55 vmap     < <gv
     56 vmap     > >gv
     57 let &cpo=s:cpo_save
     58 unlet s:cpo_save
     59 
     60 " Basic options
     61 set incsearch                " Turn on incrememental searching.
     62 set hlsearch                 " Highlight search.
     63 set visualbell               " Less noise.
     64 set number                   " Use line numbering.
     65 set ruler                    " Show row/col in status.
     66 set laststatus=1             " Only show status line if > 1 window.
     67 set showmatch                " Highlight matching bracket.
     68 set history=50               " Keep 50 lines of cmdline history.
     69 set wildmenu                 " Nicer autocomplete.
     70 set wildmode=longest,full
     71 set wildignore=*.o,*.pyc     " Ignore some filetypes during completion.
     72 set spelllang=en_ca          " Set the spelling language.
     73 
     74 " Omnicomplete
     75 set completeopt+=longest
     76 
     77 " Indentation/tabulation
     78 set autoindent      " Copy indent from current line when starting a new line.
     79 set smartindent     " Attempt to autoindent when starting a new line.
     80 set smarttab        " Use shiftwidth rather than tabstop at start of line.
     81 set tabstop=2       " Number of spaces per tab.
     82 set shiftwidth=2    " Number of spaces for each step of autoindent.
     83 set softtabstop=2   " Number of spaces per tab when editing.
     84 set expandtab       " Insert spaces in place of tabs.
     85 
     86 " Fix python's indent overrides.
     87 au FileType python setl ts=2 sw=2 sts=2 et
     88 
     89 " Configure whitespace highlighting.
     90 let g:spacehi_spacecolor="ctermbg=red guibg=red"
     91 let g:spacehi_tabcolor="ctermbg=red guibg=red"
     92 
     93 " Configure tag file locations.
     94 set tags+=~/.local/tags/system.tags
     95 set tags+=~/.local/tags/cxx.tags
     96 
     97 " Configure golang support.
     98 let g:go_fmt_command = "goimports"
     99 let g:go_highlight_functions = 1
    100 let g:go_highlight_methods = 1
    101 let g:go_highlight_structs = 1
    102 let g:go_highlight_operators = 1
    103 let g:go_highlight_build_constraints = 1
    104 let g:syntastic_go_checkers = ["go", "golint", "errcheck"]
    105 
    106 " Configure ledger.
    107 let g:ledger_date_format = '%Y-%m-%d'
    108 au FileType ledger inoremap <silent> <Tab> <C-r>=ledger#autocomplete_and_align()<CR>
    109 au FileType ledger vnoremap <silent> <Tab> :LedgerAlign<CR>
    110 
    111 " Configure beancount.
    112 let g:beancount_separator_col = 60
    113 function! BeancountComplete()
    114   let line = getline('.')
    115   if matchend(line, '^\s\+') >= col('.') - 1
    116     return '\<C-x>\<C-o>'
    117   endif
    118   return '\<Tab>'
    119 endfunction
    120 au FileType beancount inoremap <buffer> <silent> <Tab> <C-r>=BeancountComplete()<CR>
    121 au FileType beancount inoremap <buffer> . .<C-\><C-o>:AlignCommodity<CR>
    122 au FileType beancount nnoremap <buffer> <leader>= :AlignCommodity<CR>
    123 au FileType beancount vnoremap <buffer> <leader>= :AlignCommodity<CR>
    124 
    125 " Configure VimWiki.
    126 let wiki_1 = {}
    127 let wiki_1.index = 'Home'
    128 let wiki_1.path = '~/Documents/Wiki/personal/'
    129 let wiki_1.path_html = '~/Documents/Wiki/personal.html/'
    130 let wiki_1.diary_rel_path = 'Daily Notes/'
    131 let wiki_1.nested_syntaxes = {'c': 'c', 'c++': 'cpp', 'dart': 'dart', 'shell': 'sh'}
    132 let wiki_1.syntax = 'markdown'
    133 let wiki_1.ext = '.md'
    134 let g:vimwiki_list = [wiki_1]
    135 
    136 " Use Home.md for the diary index to match GitHub's main wiki page.
    137 let g:vimwiki_diary_index = 'Home'
    138 
    139 " Only consider files under a VimWiki path to be VimWiki.
    140 let g:vimwiki_global_ext = 0
    141 
    142 " Don't shorten URLs.
    143 let g:vimwiki_url_maxsave = 0
    144 
    145 " Personal wiki index, diary, new entry.
    146 nmap <leader>jw <Plug>VimwikiIndex
    147 nmap <leader>jd <Plug>VimwikiDiaryIndex
    148 nmap <leader>jn <Plug>VimwikiMakeDiaryNote
    149 nmap <leader>jg :VimwikiGoto 
    150 
    151 " Use markdown syntax highlighting in vimwiki.
    152 " By default it wants to set syntax=vimwiki even for files with extension md.
    153 au BufEnter,InsertLeave *.md setlocal syntax=markdown
    154 
    155 " Wiki diary previous, next day.
    156 au FileType vimwiki nmap <leader>dp <Plug>VimwikiDiaryPrevDay
    157 au FileType vimwiki nmap <leader>dn <Plug>VimwikiDiaryNextDay
    158 
    159 " Snippets
    160 nmap <leader>sch :0r ~/.vim/snippets/cc.h<CR>
    161 nmap <leader>sci :0r ~/.vim/snippets/cc.cc<CR>
    162 nmap <leader>scn :.-1r ~/.vim/snippets/namespace.cc<CR>
    163 nmap <leader>scs :.-1r ~/.vim/snippets/struct.cc<CR>
    164 nmap <leader>scc :.-1r ~/.vim/snippets/class.cc<CR>
    165 nmap <leader>sjn :.-1r ~/.vim/snippets/journal.md<CR>
    166 
    167 " Configure colour scheme and syntax highlighting.
    168 if &t_Co > 2
    169   syntax enable
    170   set background=dark
    171 
    172   " No background colour in terminal.
    173   hi Normal ctermbg=none
    174 
    175   " Visual selection colour.
    176   hi Visual ctermbg=237
    177 
    178   " Spelling mistake hightlight colour.
    179   hi SpellLocal cterm=underline ctermbg=58
    180   hi SpellBad cterm=underline ctermbg=88
    181 
    182   " Completion menu colour.
    183   hi Pmenu ctermbg=0 ctermfg=8
    184   hi PmenuSel ctermbg=8 ctermfg=15
    185 
    186   " Line number colour.
    187   hi LineNr ctermfg=7
    188 
    189   " Highlight cursor line, max column.
    190   set cursorline
    191   hi ColorColumn guibg=grey24 ctermbg=235
    192   hi CursorLine guibg=grey24 ctermbg=235 cterm=bold
    193   hi CursorLineNr ctermbg=235 cterm=bold
    194 
    195   if has("autocmd")
    196     " Cursor line highlighting
    197     au WinLeave * setlocal nocursorline
    198     au WinEnter * setlocal cursorline
    199     au BufLeave * setlocal nocursorline
    200     au BufEnter * setlocal cursorline
    201 
    202     " Highlight over-length lines
    203     au BufEnter,InsertLeave * set colorcolumn=80
    204     au BufEnter,InsertLeave *.txt,*.md,*.wiki set colorcolumn=80
    205     au BufEnter,InsertLeave *.txt,*.md,*.wiki set textwidth=80
    206     au BufEnter,InsertLeave *.java,*.m,*.mm set colorcolumn=100
    207     au BufEnter,InsertLeave *.java,*.m,*.mm set textwidth=100
    208 
    209     " Highlight trailing space
    210     au BufEnter,InsertLeave *.bzl,*.c,*.cc,*.cpp,*.cs,*.dart,*.h,*.java,*.m,*.mm,*.py,*.s SpaceHi
    211   endif
    212 endif
    213 
    214 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    215 " Functions
    216 
    217 " Apply clang-format to a range of lines (or all).
    218 function ClangFormat()
    219   let l:line_start = getpos("'<")[1]
    220   let l:line_end = getpos("'>")[1]
    221   let l:lines = "all"
    222   if l:line_start != 0 && l:line_end != 0
    223     let l:lines = l:line_start . ":" . l:line_end
    224   endif
    225   py3f ~/share/clang/clang-format.py
    226 endfunction
    227 autocmd FileType c,cpp,objc nnoremap <buffer><Leader>cf :<C-u>ClangFormat<CR>
    228 autocmd FileType c,cpp,objc vnoremap <buffer><Leader>cf :ClangFormat<CR>
    229 
    230 " Toggle absolute/relative numbering.
    231 function! ToggleNumbering()
    232   if (&number == 0)
    233     set number
    234   elseif (&relativenumber == 0)
    235     set relativenumber
    236   else
    237     set norelativenumber
    238     set nonumber
    239   endif
    240 endfunc
    241 nmap <C-n> :call ToggleNumbering()<CR>