[download]

vim/vimrc

   1 lang messages C
   2 scriptencoding utf8
   3 
   4 set viminfo+=n~/.vim/viminfo history=1000
   5 set noswapfile undofile undodir=~/.cache/vim/undo//
   6 if !isdirectory(expand(&undodir)) " {{{
   7     call mkdir(expand(&undodir), 'p')
   8 endif " }}}
   9 
  10 set titlestring=%F%{&mod?'*':''}\ -\ Vim
  11 set tabline=%!TabLine() tabpagemax=1000
  12 function! TabLine() " {{{
  13     let s = ''
  14 
  15     for i in range(tabpagenr('$'))
  16         let n  = (i + 1)
  17         let s .= (n == tabpagenr() ? '%#TabLineSel#' : '%#TabLine#')
  18         let s .= '%'.n.'T '.n.':%{TabLineLabel('.n.')} '
  19     endfor
  20 
  21     return s.'%#TabLine#%T'
  22 endfunction
  23 
  24 function! TabLineLabel(n)
  25     let list = tabpagebuflist(a:n)
  26     let num  = list[tabpagewinnr(a:n) - 1]
  27 
  28     let name = fnamemodify(bufname(num), ':t')
  29     let mod  = (getbufvar(num, '&mod') ? '*' : '')
  30 
  31     return (name == '' ? '[No Name]' : name.mod)
  32 endfunction " }}}
  33 
  34 set mouse=a mousefocus mousemodel=popup
  35 set virtualedit=block keymodel=startsel
  36 set keymap=russian-jcukenwin iminsert=0
  37 let [&t_SI, &t_SR, &t_EI] = ["\e[5 q", "\e[3 q", "\e[0 q"]
  38 
  39 set autochdir modeline lazyredraw splitbelow splitright
  40 set foldmethod=marker foldcolumn=2 foldtext=FoldText()
  41 function! FoldText() " {{{
  42     let fold = (v:foldend - v:foldstart + 1).' lines'
  43 
  44     let line = foldtext()
  45     let line = substitute(line, '\(\d\+\)', ' \1', '')
  46     let line = substitute(line, ' .*: ', ' ', '')
  47     let line = substitute(line, '^+', '-', '')
  48 
  49     if strlen(v:folddashes) > 1 || line =~ '(' || line =~ '{' || line =~ '['
  50         let line = substitute(line, ')[^)}]*$', ') ', '')
  51         let line = substitute(line, '^-* ', '', '').fold
  52         let fill = getline(v:foldstart)
  53 
  54         if match(fill, '^\s') == 0
  55             let line = substitute(fill, '^\(\s\+\).*', '\1', '').line
  56         endif
  57     else
  58         let char = matchstr(&fillchars, '.*fold:\zs.')
  59         let fill = (&colorcolumn ? &colorcolumn : 80)
  60         let fill = (fill - 1 - 4 - strlen(line))
  61 
  62         let fold  = ' '.fold
  63         let line .= repeat(char, (fill - strlen(fold)))
  64         let line .= fold.' '.repeat(char, 3)
  65     endif
  66 
  67     redraw
  68     return line.repeat(' ', (winwidth(0) - strlen(line)))
  69 endfunction " }}}
  70 
  71 set list listchars=tab:›\ ,space:·
  72 set spelllang+=ru fileencodings=utf8,cp1251
  73 set hlsearch incsearch ignorecase smartcase nowrapscan
  74 
  75 set nowrap linebreak display=lastline
  76 set tabstop=4 shiftwidth=0 expandtab
  77 set autoindent smartindent shiftround smarttab
  78 
  79 set ttimeoutlen=0 completeopt=menuone,noinsert
  80 set whichwrap+=<,>,[,] backspace=indent,eol,start
  81 set nojoinspaces formatoptions+=j
  82 
  83 set confirm report=0 showcmd
  84 set wildmenu wildignorecase wildmode=list:longest,full
  85 
  86 " Keys {{{
  87 
  88 let mapleader = ' '
  89 inoremap <C-a> <C-^>
  90 
  91 let &langremap = 0
  92 let &langmap   =
  93 \ 'ё`,йq,цw,уe,кr,еt,нy,гu,шi,щo,зp,х[,ъ],'.
  94 \ "фa,ыs,вd,аf,пg,рh,оj,лk,дl,ж\\;,э',".
  95 \ 'яz,чx,сc,мv,иb,тn,ьm,б\,,ю.,'.
  96 \ 'Ё~,ЙQ,ЦW,УE,КR,ЕT,HY,ГU,ШI,ЩO,ЗP,Х{,Ъ},'.
  97 \ 'ФA,ЫS,ВD,АF,ПG,РH,ОJ,ЛK,ДL,Ж:,Э",'.
  98 \ 'ЯZ,ЧX,СC,МV,ИB,ТN,ЬM,Б<,Ю>'
  99 
 100 nnoremap Y  y$
 101 nnoremap n  nzvzz
 102 nnoremap *  *<C-o>
 103 nnoremap gx :call job_start('xdg-open '.expand('<cfile>'))<Cr>
 104 
 105 vnoremap > >gv
 106 vnoremap < <gv
 107 vnoremap <Tab>   >gv
 108 vnoremap <S-Tab> <gv
 109 
 110 nnoremap _ :call Ranger('sp')<Cr>
 111 nnoremap - :call Ranger('tabe')<Cr>
 112 function! Ranger(cmd) " {{{
 113     let s:ranger_c = a:cmd..' '
 114     let s:ranger_f = tempname()
 115 
 116     call term_start(
 117         \ ['ranger', '--choosefiles', s:ranger_f, '--selectfile', expand('%')],
 118         \ { 'term_finish': 'close', 'exit_cb': 'RangerCb' }
 119     \ )
 120 endfunction
 121 
 122 function! RangerCb(msg, code)
 123     if !filereadable(s:ranger_f) | redraw! | return | endif
 124     exec s:ranger_c.join(readfile(s:ranger_f), ' | '.s:ranger_c)
 125     redraw! | call delete(s:ranger_f)
 126 endfunction " }}}
 127 
 128 nnoremap <Leader>h :nohls<Cr>
 129 nnoremap <Leader>g :MagitOnly<Cr>
 130 nnoremap <Leader>n :setl nu! nornu<Cr>
 131 nnoremap <Leader>s :setl spell! spell?<Cr>
 132 nnoremap <Leader>R :redraw! \| SignifyRefresh<Cr>
 133 
 134 au FileType *       noremap  <F5> :w \| make!<Cr>
 135 au FileType vimwiki noremap  <F5> :VimwikiAll2HTML<Cr>
 136 
 137 nnoremap <Bs>  X
 138 vnoremap <Bs>  x
 139 vnoremap <C-c> "+y
 140 vnoremap <C-x> "+x
 141 noremap  <C-v> "+gP
 142 inoremap <C-v> <C-r>+
 143 cnoremap <C-v> <C-r>+
 144 noremap  <C-z> u
 145 inoremap <C-z> <C-o>u
 146 noremap  <C-y> <C-r>
 147 inoremap <C-y> <C-o><C-r>
 148 noremap  <C-s>      :call Update()<Cr>
 149 vnoremap <C-s> <C-c>:call Update()<Cr>
 150 inoremap <C-s> <C-o>:call Update()<Cr>
 151 function! Update() " {{{
 152     let r=@/ | %s/\s\+$//e | let @/=r
 153     setl eol | retab | update
 154 endfunction " }}}
 155 
 156 for s:i in range(1, 9)
 157     exec 'set      <A-'.s:i.">=\e".s:i
 158     exec 'noremap  <A-'.s:i.'>      '.s:i.'gt'
 159     exec 'inoremap <A-'.s:i.'> <C-o>'.s:i.'gt'
 160 endfor
 161 
 162 " }}}
 163 " Colors {{{
 164 
 165 set t_RV=
 166 set t_Co=16
 167 
 168 syntax enable
 169 colors default
 170 
 171 hi! clear
 172 
 173 hi! Visual ctermbg=NONE ctermfg=grey cterm=reverse
 174 
 175 hi! Search     ctermbg=NONE ctermfg=yellow cterm=reverse
 176 hi! IncSearch  ctermbg=NONE ctermfg=NONE   cterm=reverse
 177 hi! MatchParen ctermbg=NONE ctermfg=yellow cterm=reverse
 178 
 179 hi! SpellBad ctermbg=NONE ctermfg=red  cterm=underline
 180 hi! SpellCap ctermbg=NONE ctermfg=blue cterm=underline
 181 
 182 hi! link TabLine    StatusLine
 183 hi! link TabLineSel StatusLineMode
 184 
 185 hi! LineNr     ctermbg=NONE ctermfg=grey
 186 hi! SignColumn ctermbg=NONE ctermfg=NONE
 187 hi! VertSplit  ctermbg=NONE ctermfg=NONE cterm=NONE
 188 
 189 hi! Folded     ctermbg=NONE ctermfg=grey
 190 hi! FoldColumn ctermbg=NONE ctermfg=grey
 191 
 192 hi! DiffAdd    ctermbg=green  ctermfg=black
 193 hi! DiffChange ctermbg=yellow ctermfg=black
 194 hi! DiffDelete ctermbg=red    ctermfg=black
 195 hi! DiffText   ctermbg=white  ctermfg=black cterm=NONE
 196 
 197 hi! Error ctermbg=NONE ctermfg=red
 198 hi! Todo  ctermbg=NONE ctermfg=yellow cterm=bold
 199 
 200 hi! ErrorMsg   ctermbg=NONE ctermfg=red
 201 hi! SpecialKey ctermbg=NONE ctermfg=darkGrey
 202 au  BufEnter * call matchadd('SpecialKey', '[ \t]')
 203 
 204 hi! ALEErrorSign   ctermbg=NONE ctermfg=red    cterm=bold
 205 hi! ALEWarningSign ctermbg=NONE ctermfg=yellow cterm=bold
 206 
 207 " }}}
 208 " Statusline {{{
 209 
 210 function! StatusLine() " {{{
 211     if mode() == s:statusline | return '' | endif
 212 
 213     let s:statusline = mode()[0]
 214     exec 'hi! link StatusLineMode Mode'.get({
 215         \ 'i': 'Insert', 'R': 'Replace',
 216         \ 'v': 'Visual', 'V': 'Visual', "\<C-v>": 'Visual'
 217     \ }, s:statusline, 'Normal')
 218 
 219     if v:version < 801
 220         redraw!
 221     else
 222         redrawstatus
 223         redrawtabline
 224     endif
 225 
 226     return ''
 227 endfunction
 228 
 229 let s:statusline = '' " }}}
 230 
 231 set laststatus=2
 232 set statusline=%{StatusLine()}
 233 set statusline+=%a %<%F%{&mod?'*':''} %r  %=
 234 set statusline+=   %{&ft}  %{&enc}  %{&ff}
 235 set statusline+=   %#StatusLineMode# %P %0*
 236 
 237 hi!      StatusLine     cterm=NONE
 238 hi!      StatusLineNC   cterm=NONE
 239 hi! link StatusLineMode ModeNormal
 240 
 241 hi! ModeNormal  ctermbg=NONE ctermfg=NONE   cterm=reverse,bold
 242 hi! ModeInsert  ctermbg=NONE ctermfg=blue   cterm=reverse,bold
 243 hi! ModeVisual  ctermbg=NONE ctermfg=yellow cterm=reverse,bold
 244 hi! ModeReplace ctermbg=NONE ctermfg=red    cterm=reverse,bold
 245 
 246 " }}}
 247 " Plugins {{{
 248 
 249 if !filereadable(expand('~/.vim/autoload/plug.vim'))
 250     silent !curl -sLo ~/.vim/autoload/plug.vim --create-dirs
 251     \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
 252 endif
 253 
 254 call plug#begin('~/.vim/plug')
 255 
 256 Plug 'https://github.com/ctrlpvim/ctrlp.vim'
 257 Plug 'https://github.com/junegunn/fzf.vim'
 258 Plug 'https://github.com/junegunn/vim-peekaboo'
 259 
 260 Plug 'https://github.com/jreybert/vimagit'
 261 Plug 'https://github.com/mhinz/vim-signify'
 262 Plug 'https://github.com/tpope/vim-fugitive'
 263 Plug 'https://github.com/junegunn/gv.vim'
 264 
 265 Plug 'https://github.com/w0rp/ale'
 266 Plug 'https://github.com/lifepillar/vim-mucomplete'
 267 
 268 Plug 'https://github.com/sheerun/vim-polyglot'
 269 Plug 'https://github.com/jamessan/vim-gnupg'
 270 Plug 'https://github.com/clktmr/vim-gdscript3'
 271 
 272 Plug 'https://github.com/tpope/vim-endwise'
 273 Plug 'https://github.com/adelarsq/vim-matchit'
 274 
 275 Plug 'https://github.com/tpope/vim-commentary'
 276 Plug 'https://github.com/nelstrom/vim-visual-star-search'
 277 
 278 Plug 'https://github.com/vimwiki/vimwiki'
 279 
 280 call plug#end()
 281 
 282 let fzf_buffers_jump = 1
 283 let fzf_command_prefix = 'Z'
 284 let ale_sign_warning = '>>'
 285 let ale_linters = {'c': ['gcc'], 'lua': ['luac']}
 286 let ale_c_gcc_options = '-std=gnu11 -Wall'
 287 let ale_gdscript3_godotheadless_executable = 'godot-headless'
 288 let ctrlp_prompt_mappings = {
 289     \ 'AcceptSelection("e")': ['<2-LeftMouse>'],
 290     \ 'AcceptSelection("t")': ['<Cr>', '<C-t>']
 291 \ }
 292 let mucomplete#minimum_prefix_length  = 1
 293 let mucomplete#enable_auto_at_startup = 1
 294 let mucomplete#chains = {'default' : ['path', 'c-n', 'omni', 'uspl']}
 295 let vimwiki_list = [{'path': '~/Wiki/', 'path_html': '~/Wiki/html'}]
 296 
 297 au FileType vimwiki inoremap <buffer> <expr> <Cr>
 298 \ pumvisible() ? '<Cr>' : '<Esc>:VimwikiReturn 1 5<Cr>'
 299 
 300 " }}}
 301 
 302 au VimResized  * wincmd =
 303 au BufReadPost * normal g`"zz
 304 
 305 au FileType git,magit          setl fdl=9 ts=2
 306 au FileType c,h,cc,cpp,php     setl cms=//\ %s
 307 au FileType *commit,mail,*wiki setl wrap spell ts=2
 308 au BufEnter */Lexa.by/*        setl makeprg=./build.*
 309 
 310 au VimEnter,BufEnter,FocusGained *
 311 \ if exists('v:servername') && v:servername != '' |
 312     \ call writefile([v:servername], expand('~/.vim/vimsid')) |
 313 \ endif