vim

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

vimrc (5436B)


      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 call plug#begin('~/.vim/plugged')
     10 Plug 'rhysd/vim-clang-format'   " clang-format.
     11 Plug 'vim-scripts/spacehi.vim'  " Highlight bad whitespace.
     12 
     13 " Language support plugins.
     14 Plug 'cespare/vim-toml'
     15 Plug 'dart-lang/dart-vim-plugin'
     16 Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
     17 Plug 'google/vim-ft-bzl'
     18 Plug 'keith/swift.vim'
     19 Plug 'rust-lang/rust.vim'
     20 Plug 'https://gn.googlesource.com/gn', { 'rtp': 'misc/vim' }
     21 call plug#end()
     22 
     23 " Bind fancier manpage plugin to Shift-k.
     24 runtime ftplugin/man.vim
     25 set keywordprg=:Man
     26 
     27 let mapleader=','
     28 let s:cpo_save=&cpo
     29 set cpo&vim
     30 
     31 " Enable middle-mouse paste.
     32 map!     <S-Insert> <MiddleMouse>
     33 map      <S-Insert> <MiddleMouse>
     34 
     35 " Kill ex mode.
     36 noremap  Q          <NOP>
     37 
     38 " Disable visual-mode mouse select.
     39 set mouse=
     40 
     41 " Kill arrow keys, for great justice.
     42 noremap  <Up>       <NOP>
     43 noremap  <Down>     <NOP>
     44 noremap  <Left>     <NOP>
     45 noremap  <Right>    <NOP>
     46 
     47 " Retain selection on <,>.
     48 vmap     < <gv
     49 vmap     > >gv
     50 let &cpo=s:cpo_save
     51 unlet s:cpo_save
     52 
     53 " Basic options
     54 set incsearch                " Turn on incrememental searching.
     55 set hlsearch                 " Highlight search.
     56 set visualbell               " Less noise.
     57 set number                   " Use line numbering.
     58 set ruler                    " Show row/col in status.
     59 set laststatus=1             " Only show status line if > 1 window.
     60 set showmatch                " Highlight matching bracket.
     61 set history=50               " Keep 50 lines of cmdline history.
     62 set wildmenu                 " Nicer autocomplete.
     63 set wildmode=longest,full
     64 set wildignore=*.o,*.pyc     " Ignore some filetypes during completion.
     65 set spelllang=en_ca          " Set the spelling language.
     66 
     67 " Omnicomplete
     68 set completeopt+=longest
     69 
     70 " Indentation/tabulation
     71 set autoindent      " Copy indent from current line when starting a new line.
     72 set smartindent     " Attempt to autoindent when starting a new line.
     73 set smarttab        " Use shiftwidth rather than tabstop at start of line.
     74 set tabstop=2       " Number of spaces per tab.
     75 set shiftwidth=2    " Number of spaces for each step of autoindent.
     76 set softtabstop=2   " Number of spaces per tab when editing.
     77 set expandtab       " Insert spaces in place of tabs.
     78 
     79 " Configure whitespace highlighting.
     80 let g:spacehi_spacecolor="ctermbg=red guibg=red"
     81 let g:spacehi_tabcolor="ctermbg=red guibg=red"
     82 
     83 " Configure tag file locations.
     84 set tags+=~/.local/tags/system.tags
     85 set tags+=~/.local/tags/cxx.tags
     86 
     87 " Configure golang support.
     88 let g:go_fmt_command = "goimports"
     89 let g:go_highlight_functions = 1
     90 let g:go_highlight_methods = 1
     91 let g:go_highlight_structs = 1
     92 let g:go_highlight_operators = 1
     93 let g:go_highlight_build_constraints = 1
     94 let g:syntastic_go_checkers = ["go", "golint", "errcheck"]
     95 
     96 " Snippets
     97 nmap <leader>sch :0r ~/.vim/snippets/cc.h<CR>
     98 nmap <leader>sci :0r ~/.vim/snippets/cc.cc<CR>
     99 nmap <leader>scn :.-1r ~/.vim/snippets/namespace.cc<CR>
    100 nmap <leader>scs :.-1r ~/.vim/snippets/struct.cc<CR>
    101 nmap <leader>scc :.-1r ~/.vim/snippets/class.cc<CR>
    102 nmap <leader>sjn :.-1r ~/.vim/snippets/journal.md<CR>
    103 
    104 " Configure colour scheme and syntax highlighting.
    105 if &t_Co > 2
    106   syntax enable
    107   set background=dark
    108 
    109   " No background colour in terminal.
    110   hi Normal ctermbg=none
    111 
    112   " Visual selection colour.
    113   hi Visual ctermbg=237
    114 
    115   " Spelling mistake hightlight colour.
    116   hi SpellLocal cterm=underline ctermbg=58
    117   hi SpellBad cterm=underline ctermbg=88
    118 
    119   " Completion menu colour.
    120   hi Pmenu ctermbg=0 ctermfg=8
    121   hi PmenuSel ctermbg=8 ctermfg=15
    122 
    123   " Line number colour.
    124   hi LineNr ctermfg=7
    125 
    126   " Highlight cursor line, max column.
    127   set cursorline
    128   hi ColorColumn guibg=grey24 ctermbg=235
    129   hi CursorLine guibg=grey24 ctermbg=235 cterm=bold
    130   hi CursorLineNr ctermbg=235 cterm=bold
    131 
    132   if has("autocmd")
    133     " Cursor line highlighting
    134     au WinLeave * setlocal nocursorline
    135     au WinEnter * setlocal cursorline
    136     au BufLeave * setlocal nocursorline
    137     au BufEnter * setlocal cursorline
    138 
    139     " Highlight over-length lines
    140     au BufEnter,InsertLeave * set colorcolumn=80
    141     au BufEnter,InsertLeave *.txt,*.md,*.wiki set colorcolumn=80
    142     au BufEnter,InsertLeave *.txt,*.md,*.wiki set textwidth=80
    143     au BufEnter,InsertLeave *.java,*.m,*.mm set colorcolumn=100
    144     au BufEnter,InsertLeave *.java,*.m,*.mm set textwidth=100
    145 
    146     " Highlight trailing space
    147     au BufEnter,InsertLeave *.bzl,*.c,*.cc,*.cpp,*.cs,*.dart,*.h,*.java,*.m,*.mm,*.py,*.s SpaceHi
    148 
    149     " Fix python's indent overrides.
    150     au FileType python setl ts=2 sw=2 sts=2 et
    151   endif
    152 endif
    153 
    154 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    155 " Functions
    156 
    157 " Apply clang-format to a range of lines (or all).
    158 function ClangFormat()
    159   let l:line_start = getpos("'<")[1]
    160   let l:line_end = getpos("'>")[1]
    161   let l:lines = "all"
    162   if l:line_start != 0 && l:line_end != 0
    163     let l:lines = l:line_start . ":" . l:line_end
    164   endif
    165   py3f ~/share/clang/clang-format.py
    166 endfunction
    167 autocmd FileType c,cpp,objc nnoremap <buffer><Leader>cf :<C-u>ClangFormat<CR>
    168 autocmd FileType c,cpp,objc vnoremap <buffer><Leader>cf :ClangFormat<CR>
    169 
    170 " Toggle absolute/relative numbering.
    171 function! ToggleNumbering()
    172   if (&number == 0)
    173     set number
    174   elseif (&relativenumber == 0)
    175     set relativenumber
    176   else
    177     set norelativenumber
    178     set nonumber
    179   endif
    180 endfunc
    181 nmap <C-n> :call ToggleNumbering()<CR>