[download]

vim/vimrc

   1 source $VIMRUNTIME/mswin.vim
   2 
   3 unmap  <C-a>
   4 behave xterm
   5 lang messages C
   6 scriptencoding utf8
   7 
   8 set viminfo+=n~/.vim/viminfo history=1000
   9 set noswapfile undofile undodir=~/.cache/vim//
  10 call mkdir(expand(&undodir), 'p')
  11 
  12 set titlestring=%F%{&mod?'*':''}\ -\ Vim
  13 set tabline=%!TabLine() tabpagemax=1000
  14 function! TabLine() " {{{
  15     let s = ''
  16 
  17     for i in range(tabpagenr('$'))
  18         let n  = (i + 1)
  19         let s .= (n == tabpagenr() ? '%#TabLineSel#' : '%#TabLine#')
  20         let s .= '%'.n.'T '.n.':%{TabLineLabel('.n.')} '
  21     endfor
  22 
  23     return s.'%#TabLine#%T'
  24 endfunction
  25 
  26 function! TabLineLabel(n)
  27     let list = tabpagebuflist(a:n)
  28     let num  = list[tabpagewinnr(a:n) - 1]
  29 
  30     let name = fnamemodify(bufname(num), ':t')
  31     let mod  = (getbufvar(num, '&mod') ? '*' : '')
  32 
  33     return (name == '' ? '[No Name]' : name.mod)
  34 endfunction " }}}
  35 
  36 set autochdir lazyredraw
  37 set splitbelow splitright
  38 set fileencodings=utf8,cp1251
  39 
  40 set mouse=a virtualedit=block
  41 set keymap=russian-jcukenwin iminsert=0
  42 let [&t_SI, &t_SR, &t_EI] = ["\e[5 q", "\e[3 q", "\e[0 q"]
  43 
  44 set list listchars=tab:›\ ,space:·
  45 set nowrap linebreak display=lastline
  46 set foldmethod=marker foldcolumn=2 foldtext=FoldText()
  47 function! FoldText() " {{{
  48     let line = getline(v:foldstart)
  49     let fold = (v:foldend - v:foldstart + 1).' lines'
  50 
  51     let text = foldtext()
  52     let text = substitute(text, '\(\d\+\)', ' \1', '')
  53     let text = substitute(text, ' .*: ', ' ', '')
  54     let text = substitute(text, '^+', '-', '')
  55 
  56     if v:foldlevel > 1 || line[0] == ' ' || match(text, '[({\[]') > -1
  57         let text = substitute(text, ')[^)}]*$', ') ', '')
  58         let text = substitute(text, '^-* ', '', '').fold
  59 
  60         if line[0] == ' '
  61             let text = substitute(line, '^\(\s\+\).*', '\1', '').text
  62         endif
  63     else
  64         let fold = ' '.fold
  65 
  66         let fill = (&colorcolumn ? &colorcolumn : 80)
  67         let fill = (fill > winwidth(0) ? winwidth(0) - 3 : fill)
  68         let fill = (fill - 1 - 4 - strlen(text))
  69 
  70         let text  = (text == '--- ' ? '----' : text)
  71         let text .= repeat('-', (fill - strlen(fold)))
  72         let text .= fold.' '.repeat('-', 3)
  73     endif
  74 
  75     redraw
  76     return text.repeat(' ', (winwidth(0) - strlen(text)))
  77 endfunction " }}}
  78 
  79 set tabstop=4 shiftwidth=4 expandtab
  80 set autoindent smartindent smarttab shiftround
  81 
  82 set keywordprg=:term\ ++close\ man
  83 set hlsearch incsearch ignorecase nowrapscan
  84 set spelllang+=ru completeopt=menuone,noinsert
  85 set ttimeoutlen=0 nojoinspaces formatoptions+=j
  86 
  87 set confirm report=0 showcmd
  88 set wildmenu wildignorecase wildmode=list:longest,full
  89 
  90 " Keys {{{
  91 
  92 let mapleader  = ' '
  93 let &langremap = 0 " {{{
  94 let &langmap   =
  95 \ 'ё`,йq,цw,уe,кr,еt,нy,гu,шi,щo,зp,х[,ъ],'.
  96 \ "фa,ыs,вd,аf,пg,рh,оj,лk,дl,ж\\;,э',".
  97 \ 'яz,чx,сc,мv,иb,тn,ьm,б\,,ю.,'.
  98 \ 'Ё~,ЙQ,ЦW,УE,КR,ЕT,HY,ГU,ШI,ЩO,ЗP,Х{,Ъ},'.
  99 \ 'ФA,ЫS,ВD,АF,ПG,РH,ОJ,ЛK,ДL,Ж:,Э",'.
 100 \ 'ЯZ,ЧX,СC,МV,ИB,ТN,ЬM,Б<,Ю>' " }}}
 101 for s:i in range(1, 9) " {{{
 102     exec 'set      <A-'.s:i.">=\e".s:i
 103     exec 'noremap  <A-'.s:i.'>      '.s:i.'gt'
 104     exec 'inoremap <A-'.s:i.'> <C-o>'.s:i.'gt'
 105 endfor " }}}
 106 
 107 nnoremap Y  y$
 108 nnoremap n  nzvzz
 109 nnoremap *  *<C-o>
 110 nnoremap gx :call job_start('xdg-open '.expand('<cfile>'))<Cr>
 111 
 112 vnoremap > >gv
 113 vnoremap < <gv
 114 vnoremap <Tab>   >gv
 115 vnoremap <S-Tab> <gv
 116 
 117 nnoremap <Bs> X
 118 vnoremap <Bs> x
 119 
 120 noremap! <C-Space> <C-^>
 121 noremap! <C-@>     <C-^>
 122 
 123 nnoremap <C-r> :redraw!<Cr>
 124 nnoremap <C-s> :call Update()<Cr>
 125 function! Update() " {{{
 126     setl eol nobomb
 127     if &et | retab | endif
 128     let r=@/ | %s/\s\+$//e | let @/=r
 129     update
 130 endfunction " }}}
 131 
 132 nnoremap <F5> :up \| make!<Cr>
 133 nnoremap <F6> :up \| make! install<Cr>
 134 
 135 nnoremap  _ :call Ranger('sp')<Cr>
 136 nnoremap  - :call Ranger('tabe')<Cr>
 137 nnoremap \| :call Ranger('vs')<Cr>
 138 function! Ranger(cmd) " {{{
 139     let s:ranger_c = a:cmd..' '
 140     let s:ranger_f = tempname()
 141 
 142     call term_start(
 143         \ ['ranger', '--choosefiles', s:ranger_f, '--selectfile', expand('%')],
 144         \ { 'exit_cb': 'RangerCb', 'term_finish': 'close', 'vertical': a:cmd == 'vs' }
 145     \ )
 146 endfunction
 147 
 148 function! RangerCb(msg, code)
 149     if !filereadable(s:ranger_f) | redraw! | return | endif
 150     exec s:ranger_c.join(readfile(s:ranger_f), ' | '.s:ranger_c)
 151     redraw! | call delete(s:ranger_f)
 152 endfunction " }}}
 153 
 154 nnoremap <Leader>h :nohls<Cr>
 155 nnoremap <Leader>n :setl nu! nornu<Cr>
 156 nnoremap <Leader>s :setl spell! spell?<Cr>
 157 
 158 nnoremap <Leader>G :term ++close tig %<Cr>
 159 nnoremap <Leader>P :term ++close git push<Cr>
 160 
 161 " }}}
 162 " Colors {{{
 163 
 164 set t_RV=
 165 set t_Co=16
 166 
 167 syntax enable
 168 colors default
 169 
 170 hi! clear
 171 
 172 hi! Visual ctermbg=NONE ctermfg=grey cterm=reverse
 173 
 174 hi! Error ctermbg=NONE ctermfg=red
 175 hi! Todo  ctermbg=NONE ctermfg=yellow cterm=bold
 176 
 177 hi! SpecialKey ctermbg=NONE ctermfg=darkGrey
 178 au  BufEnter * call matchadd('SpecialKey', '[ \t]')
 179 
 180 hi! Search     ctermbg=NONE ctermfg=yellow cterm=reverse
 181 hi! IncSearch  ctermbg=NONE ctermfg=NONE   cterm=reverse
 182 hi! MatchParen ctermbg=NONE ctermfg=yellow cterm=reverse
 183 
 184 hi! Pmenu    ctermbg=darkGrey ctermfg=white
 185 hi! PmenuSel ctermbg=darkGrey ctermfg=white cterm=bold,reverse
 186 
 187 hi! DiffAdd    ctermbg=green  ctermfg=black
 188 hi! DiffChange ctermbg=yellow ctermfg=black
 189 hi! DiffDelete ctermbg=red    ctermfg=black
 190 hi! DiffText   ctermbg=white  ctermfg=black cterm=NONE
 191 
 192 hi! SpellBad ctermbg=NONE ctermfg=red  cterm=underline
 193 hi! SpellCap ctermbg=NONE ctermfg=blue cterm=underline
 194 
 195 hi! link TabLine    StatusLine
 196 hi! link TabLineSel StatusLineMode
 197 
 198 hi! LineNr     ctermbg=NONE ctermfg=grey
 199 hi! SignColumn ctermbg=NONE ctermfg=NONE
 200 hi! VertSplit  ctermbg=NONE ctermfg=NONE cterm=NONE
 201 
 202 hi! Folded     ctermbg=NONE ctermfg=grey
 203 hi! FoldColumn ctermbg=NONE ctermfg=grey
 204 
 205 hi! ALEErrorSign   ctermbg=NONE ctermfg=red  cterm=bold
 206 hi! ALEWarningSign ctermbg=NONE ctermfg=blue cterm=bold
 207 
 208 hi! ErrorMsg ctermbg=NONE ctermfg=red
 209 
 210 " }}}
 211 " Statusline {{{
 212 
 213 function! StatusLine() " {{{
 214     if s:statusline == mode() | return '' | endif
 215     let s:statusline = mode()
 216 
 217     exec 'hi! link StatusLineMode Mode'.get({
 218         \ 'i': 'Insert', 'R': 'Replace', 'S': 'Replace',
 219         \ 'v': 'Visual', 'V': 'Visual', "\<C-v>": 'Visual'
 220     \ }, s:statusline, 'Normal')
 221 
 222     if v:version < 801
 223         redraw!
 224     else
 225         redrawstatus
 226         redrawtabline
 227     endif
 228 
 229     return ''
 230 endfunction
 231 
 232 let s:statusline = '' " }}}
 233 
 234 set laststatus=2
 235 set statusline=%{StatusLine()}
 236 set statusline+=%a %<%F%{&mod?'*':''} %r  %=
 237 set statusline+=   %{&ft}  %{&enc}  %{&ff}
 238 set statusline+=   %#StatusLineMode# %P %0*
 239 
 240 hi!      StatusLine       cterm=nocombine
 241 hi!      StatusLineNC     cterm=NONE
 242 hi! link StatusLineMode   ModeNormal
 243 hi! link StatusLineTerm   StatusLine
 244 hi! link StatusLineTermNC StatusLineNC
 245 
 246 hi! ModeNormal  ctermbg=NONE ctermfg=NONE   cterm=bold,reverse
 247 hi! ModeInsert  ctermbg=NONE ctermfg=blue   cterm=bold,reverse
 248 hi! ModeVisual  ctermbg=NONE ctermfg=yellow cterm=bold,reverse
 249 hi! ModeReplace ctermbg=NONE ctermfg=red    cterm=bold,reverse
 250 
 251 " }}}
 252 
 253 if filereadable(expand('~/.vim/plugins.vim'))
 254     source ~/.vim/plugins.vim
 255 endif
 256 
 257 au VimResized  * wincmd =
 258 au BufReadPost * normal g`"zz
 259 
 260 au VimEnter,FocusGained * call s:vimsid(0)
 261 au BufNew,BufEnter      * call s:vimsid(0)
 262 au VimLeave             * call s:vimsid(1)
 263 function! s:vimsid(act) " {{{
 264     let f = expand('~/.vim/vimsid')
 265 
 266     if a:act == 0 && exists('v:servername') && v:servername != ''
 267         call writefile([v:servername], f)
 268     endif
 269 
 270     if a:act == 1 && filereadable(f)
 271         call delete(f)
 272     endif
 273 endfunction " }}}
 274 
 275 au FileType help nnoremap q ZQ
 276 au BufEnter * if &diff | setl nocul | endif