[download]

vim/vimrc

   1 lang messages C
   2 scriptencoding utf8
   3 source $VIMRUNTIME/mswin.vim
   4 
   5 set viminfo+=n~/.vim/viminfo history=1000
   6 set noswapfile undofile undodir=~/.cache/vim//
   7 call mkdir(expand(&undodir), 'p')
   8 
   9 set titlestring=%F%{&mod?'*':''}\ -\ Vim
  10 set tabline=%!TabLine() tabpagemax=1000
  11 function! TabLine() " {{{
  12     let s = ''
  13 
  14     for i in range(tabpagenr('$'))
  15         let n  = (i + 1)
  16         let s .= (n == tabpagenr() ? '%#TabLineSel#' : '%#TabLine#')
  17         let s .= '%'.n.'T '.n.':%{TabLineLabel('.n.')} '
  18     endfor
  19 
  20     return s.'%#TabLine#%T'
  21 endfunction
  22 
  23 function! TabLineLabel(n)
  24     let list = tabpagebuflist(a:n)
  25     let num  = list[tabpagewinnr(a:n) - 1]
  26 
  27     let name = fnamemodify(bufname(num), ':t')
  28     let mod  = (getbufvar(num, '&mod') ? '*' : '')
  29 
  30     return (name == '' ? '[No Name]' : name.mod)
  31 endfunction " }}}
  32 
  33 set mouse=a mousefocus
  34 set selectmode=key selection=inclusive
  35 set virtualedit=block keymodel=startsel
  36 set keymap=russian-jcukenwin iminsert=0
  37 
  38 set autochdir lazyredraw splitbelow splitright
  39 set foldmethod=marker foldcolumn=2 foldtext=FoldText()
  40 function! FoldText() " {{{
  41     let line = getline(v:foldstart)
  42     let fold = (v:foldend - v:foldstart + 1).' lines'
  43 
  44     let text = foldtext()
  45     let text = substitute(text, '\(\d\+\)', ' \1', '')
  46     let text = substitute(text, ' .*: ', ' ', '')
  47     let text = substitute(text, '^+', '-', '')
  48 
  49     if v:foldlevel > 1 || line[0] == ' ' || match(text, '[({\[]') > -1
  50         let text = substitute(text, ')[^)}]*$', ') ', '')
  51         let text = substitute(text, '^-* ', '', '').fold
  52 
  53         if line[0] == ' '
  54             let text = substitute(line, '^\(\s\+\).*', '\1', '').text
  55         endif
  56     else
  57         let fold = ' '.fold
  58 
  59         let fill = (&colorcolumn ? &colorcolumn : 80)
  60         let fill = (fill > winwidth(0) ? winwidth(0) - 3 : fill)
  61         let fill = (fill - 1 - 4 - strlen(text))
  62 
  63         let text  = (text == '--- ' ? '----' : text)
  64         let text .= repeat('-', (fill - strlen(fold)))
  65         let text .= fold.' '.repeat('-', 3)
  66     endif
  67 
  68     redraw
  69     return text.repeat(' ', (winwidth(0) - strlen(text)))
  70 endfunction " }}}
  71 
  72 set list listchars=tab:›\ ,space:·
  73 set nowrap linebreak display=lastline
  74 set spelllang+=ru fileencodings=utf8,cp1251
  75 
  76 set tabstop=4 shiftwidth=4 expandtab
  77 set autoindent smartindent smarttab shiftround
  78 
  79 set hlsearch incsearch ignorecase nowrapscan
  80 set ttimeoutlen=0 nojoinspaces formatoptions+=j
  81 set completeopt=menuone,noinsert omnifunc=ale#completion#OmniFunc
  82 let [&t_SI, &t_SR, &t_EI] = ["\e[5 q", "\e[3 q", "\e[0 q"]
  83 
  84 set confirm report=0 showcmd
  85 set wildmenu wildignorecase wildmode=list:longest,full
  86 
  87 " Keys {{{
  88 
  89 let mapleader  = ' '
  90 let &langremap = 0
  91 let &langmap   =
  92 \ 'ё`,йq,цw,уe,кr,еt,нy,гu,шi,щo,зp,х[,ъ],'.
  93 \ "фa,ыs,вd,аf,пg,рh,оj,лk,дl,ж\\;,э',".
  94 \ 'яz,чx,сc,мv,иb,тn,ьm,б\,,ю.,'.
  95 \ 'Ё~,ЙQ,ЦW,УE,КR,ЕT,HY,ГU,ШI,ЩO,ЗP,Х{,Ъ},'.
  96 \ 'ФA,ЫS,ВD,АF,ПG,РH,ОJ,ЛK,ДL,Ж:,Э",'.
  97 \ 'ЯZ,ЧX,СC,МV,ИB,ТN,ЬM,Б<,Ю>'
  98 for s:i in range(1, 9) " {{{
  99     exec 'set      <A-'.s:i.">=\e".s:i
 100     exec 'noremap  <A-'.s:i.'>      '.s:i.'gt'
 101     exec 'inoremap <A-'.s:i.'> <C-o>'.s:i.'gt'
 102 endfor " }}}
 103 
 104 nnoremap Y  y$
 105 nnoremap n  nzvzz
 106 nnoremap *  *<C-o>
 107 nnoremap gx :call job_start('xdg-open '.expand('<cfile>'))<Cr>
 108 
 109 vnoremap > >gv
 110 vnoremap < <gv
 111 vnoremap <Tab>   >gv
 112 vnoremap <S-Tab> <gv
 113 
 114 nnoremap <Bs> X
 115 vnoremap <Bs> x
 116 
 117 noremap  <C-a> <C-^>
 118 nnoremap <C-a> <C-a>
 119 noremap! <C-a> <C-^>
 120 nnoremap <C-s> :call Update()<Cr>
 121 function! Update() " {{{
 122     setl eol nobomb
 123     if &et | retab | endif
 124     let r=@/ | %s/\s\+$//e | let @/=r
 125     update
 126 endfunction " }}}
 127 
 128 nnoremap _ :call Ranger('sp')<Cr>
 129 nnoremap - :call Ranger('tabe')<Cr>
 130 function! Ranger(cmd) " {{{
 131     let s:ranger_c = a:cmd..' '
 132     let s:ranger_f = tempname()
 133 
 134     call term_start(
 135         \ ['ranger', '--choosefiles', s:ranger_f, '--selectfile', expand('%')],
 136         \ { 'term_finish': 'close', 'exit_cb': 'RangerCb' }
 137     \ )
 138 endfunction
 139 
 140 function! RangerCb(msg, code)
 141     if !filereadable(s:ranger_f) | redraw! | return | endif
 142     exec s:ranger_c.join(readfile(s:ranger_f), ' | '.s:ranger_c)
 143     redraw! | call delete(s:ranger_f)
 144 endfunction " }}}
 145 
 146 nnoremap <Leader>h :nohls<Cr>
 147 nnoremap <Leader>R :redraw! \| SignifyRefresh<Cr>
 148 
 149 nnoremap <Leader>G :GV!<Cr>
 150 nnoremap <Leader>g :up \| MagitOnly<Cr>
 151 nnoremap <Leader>P :term ++close git push<Cr>
 152 
 153 nnoremap <Leader>l :Limelight!!<Cr>
 154 nnoremap <Leader>a :ALEToggleBuffer<Cr>
 155 
 156 nnoremap <Leader>n :setl nu! nornu<Cr>
 157 nnoremap <Leader>s :setl spell! spell?<Cr>
 158 
 159 au FileType *        nnoremap <buffer> <F5> :up \| make!<Cr>
 160 au FileType *        nnoremap <buffer> <F6> :up \| make! install<Cr>
 161 
 162 au FileType vimwiki  nnoremap <buffer> <F5> :up \| silent Vimwiki2HTML<Cr>
 163 au FileType vimwiki  nnoremap <buffer> <F6> :up \| Vimwiki2HTMLBrowse<Cr>
 164 
 165 au FileType gdscript nnoremap <buffer> <F5> :up \| GodotRun<Cr>
 166 au FileType gdscript nnoremap <buffer> <F6> :up \| GodotRunFZF<Cr>
 167 au FileType gdscript nnoremap <buffer> K    :ALEHover<Cr>
 168 
 169 " }}}
 170 " Colors {{{
 171 
 172 set t_RV=
 173 set t_Co=16
 174 
 175 syntax enable
 176 colors default
 177 
 178 hi! clear
 179 
 180 hi! Visual ctermbg=NONE ctermfg=grey cterm=reverse
 181 
 182 hi! Error ctermbg=NONE ctermfg=red
 183 hi! Todo  ctermbg=NONE ctermfg=yellow cterm=bold
 184 
 185 hi! SpecialKey ctermbg=NONE ctermfg=darkGrey
 186 au  BufEnter * call matchadd('SpecialKey', '[ \t]')
 187 
 188 hi! Search     ctermbg=NONE ctermfg=yellow cterm=reverse
 189 hi! IncSearch  ctermbg=NONE ctermfg=NONE   cterm=reverse
 190 hi! MatchParen ctermbg=NONE ctermfg=yellow cterm=reverse
 191 
 192 hi! Pmenu    ctermbg=darkGrey ctermfg=white
 193 hi! PmenuSel ctermbg=darkGrey ctermfg=white cterm=bold,reverse
 194 
 195 hi! DiffAdd    ctermbg=green  ctermfg=black
 196 hi! DiffChange ctermbg=yellow ctermfg=black
 197 hi! DiffDelete ctermbg=red    ctermfg=black
 198 hi! DiffText   ctermbg=white  ctermfg=black cterm=NONE
 199 
 200 hi! SpellBad ctermbg=NONE ctermfg=red  cterm=underline
 201 hi! SpellCap ctermbg=NONE ctermfg=blue cterm=underline
 202 
 203 hi! link TabLine    StatusLine
 204 hi! link TabLineSel StatusLineMode
 205 
 206 hi! LineNr     ctermbg=NONE ctermfg=grey
 207 hi! SignColumn ctermbg=NONE ctermfg=NONE
 208 hi! VertSplit  ctermbg=NONE ctermfg=NONE cterm=NONE
 209 
 210 hi! Folded     ctermbg=NONE ctermfg=grey
 211 hi! FoldColumn ctermbg=NONE ctermfg=grey
 212 
 213 hi! ALEErrorSign   ctermbg=NONE ctermfg=red  cterm=bold
 214 hi! ALEWarningSign ctermbg=NONE ctermfg=blue cterm=bold
 215 
 216 hi! ErrorMsg ctermbg=NONE ctermfg=red
 217 
 218 " }}}
 219 " Statusline {{{
 220 
 221 function! StatusLine() " {{{
 222     if s:statusline == mode() | return '' | endif
 223     let s:statusline = mode()
 224 
 225     exec 'hi! link StatusLineMode Mode'.get({
 226         \ 'i': 'Insert', 'R': 'Replace', 'S': 'Replace',
 227         \ 'v': 'Visual', 'V': 'Visual', "\<C-v>": 'Visual'
 228     \ }, s:statusline, 'Normal')
 229 
 230     if v:version < 801
 231         redraw!
 232     else
 233         redrawstatus
 234         redrawtabline
 235     endif
 236 
 237     return ''
 238 endfunction
 239 
 240 let s:statusline = '' " }}}
 241 
 242 set laststatus=2
 243 set statusline=%{StatusLine()}
 244 set statusline+=%a %<%F%{&mod?'*':''} %r  %=
 245 set statusline+=   %{&ft}  %{&enc}  %{&ff}
 246 set statusline+=   %#StatusLineMode# %P %0*
 247 
 248 hi!      StatusLine       cterm=nocombine
 249 hi!      StatusLineNC     cterm=NONE
 250 hi! link StatusLineMode   ModeNormal
 251 hi! link StatusLineTerm   StatusLine
 252 hi! link StatusLineTermNC StatusLineNC
 253 
 254 hi! ModeNormal  ctermbg=NONE ctermfg=NONE   cterm=bold,reverse
 255 hi! ModeInsert  ctermbg=NONE ctermfg=blue   cterm=bold,reverse
 256 hi! ModeVisual  ctermbg=NONE ctermfg=yellow cterm=bold,reverse
 257 hi! ModeReplace ctermbg=NONE ctermfg=red    cterm=bold,reverse
 258 
 259 " }}}
 260 " Plugins {{{
 261 
 262 if !filereadable(expand('~/.vim/autoload/plug.vim'))
 263     silent !curl -sLo ~/.vim/autoload/plug.vim --create-dirs
 264     \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
 265 endif
 266 
 267 call plug#begin('~/.vim/plug')
 268 
 269 Plug 'https://github.com/vimwiki/vimwiki'
 270 Plug 'https://github.com/michal-h21/vimwiki-sync'
 271 
 272 Plug 'https://github.com/junegunn/fzf.vim'
 273 Plug 'https://github.com/ctrlpvim/ctrlp.vim'
 274 Plug 'https://github.com/junegunn/vim-peekaboo'
 275 Plug 'https://github.com/junegunn/limelight.vim'
 276 
 277 Plug 'https://github.com/junegunn/gv.vim'
 278 Plug 'https://github.com/jreybert/vimagit'
 279 Plug 'https://github.com/mhinz/vim-signify'
 280 Plug 'https://github.com/tpope/vim-fugitive'
 281 
 282 Plug 'https://github.com/w0rp/ale'
 283 Plug 'https://github.com/tpope/vim-endwise'
 284 Plug 'https://github.com/habamax/vim-godot'
 285 Plug 'https://github.com/jamessan/vim-gnupg'
 286 Plug 'https://github.com/andrewradev/id3.vim'
 287 Plug 'https://github.com/sheerun/vim-polyglot'
 288 Plug 'https://github.com/lifepillar/vim-mucomplete'
 289 
 290 Plug 'https://github.com/adelarsq/vim-matchit'
 291 Plug 'https://github.com/tpope/vim-commentary'
 292 Plug 'https://github.com/nelstrom/vim-visual-star-search'
 293 
 294 call plug#end()
 295 
 296 let vimwiki_list = [{
 297     \ 'path': '~/Wiki',
 298     \ 'index': 'Индекс',
 299     \ 'auto_tags': 1,
 300     \
 301     \ 'auto_toc': 1,
 302     \ 'auto_generate_links': 1,
 303     \ 'auto_generate_tags':  1,
 304     \
 305     \ 'diary_rel_path': './',
 306     \ 'diary_index':  'Блоге',
 307     \ 'diary_header': 'Блоге',
 308     \ 'auto_diary_index': 1,
 309     \
 310     \ 'path_html':     '~/Wiki/html',
 311     \ 'template_path': '~/Wiki/meta',
 312     \ 'auto_export': 1,
 313 \ }]
 314 let vimwiki_global_ext   = 0
 315 let vimwiki_toc_header   = 'Содержание'
 316 let vimwiki_links_header = 'Страницы'
 317 let vimwiki_tags_header  = 'Теги'
 318 let vimwiki_diary_months = {
 319     \ 1:  'Январь',   2: 'Февраль', 3: 'Март',
 320     \ 4:  'Апрель',   5: 'Май',     6: 'Июнь',
 321     \ 7:  'Июль',     8: 'Август',  9: 'Сентябрь',
 322     \ 10: 'Октябрь', 11: 'Ноябрь', 12: 'Декабрь'
 323 \ }
 324 
 325 let fzf_buffers_jump   = 1
 326 let fzf_command_prefix = 'Z'
 327 let fzf_action = {
 328     \ 'enter':  'tab split', 'ctrl-s': 'split',
 329     \ 'ctrl-t': 'tab split', 'ctrl-v': 'vsplit',
 330 \ }
 331 let ctrlp_prompt_mappings = {
 332     \ 'AcceptSelection("e")': ['<2-LeftMouse>'],
 333     \ 'AcceptSelection("t")': ['<Cr>', '<C-t>'],
 334 \ }
 335 
 336 let ale_sign_error   = '>'
 337 let ale_sign_warning = '>'
 338 let signify_sign_show_text    = 0
 339 let ale_completion_autoimport = 1
 340 let ale_c_cc_options = '-std=gnu11 -Wall'
 341 cal ale#linter#Define('gdscript', {
 342     \ 'name': 'godot',  'project_root': 'project.godot',
 343     \ 'lsp' : 'socket', 'address': '127.0.0.1:6008',
 344 \ })
 345 
 346 let mucomplete#cycle_with_trigger = 1
 347 let mucomplete#enable_auto_at_startup = 1
 348 let mucomplete#minimum_prefix_length  = 1
 349 let mucomplete#always_use_completeopt = 1
 350 let mucomplete#spel#regex = '[a-zA-Zа-яА-Я]'
 351 let mucomplete#chains = { 'default': {
 352     \   'default'  : ['path', 'uspl', 'c-n', 'omni'],
 353     \ '.*string.*' : ['path', 'uspl', 'c-n'],
 354     \ '.*comment.*': ['path', 'uspl', 'c-n'],
 355 \ }}
 356 let mucomplete#can_complete = { 'default': {
 357     \ 'omni': { s -> s =~# '\m\S\%(\k\|\.\|->\|::\)$' },
 358 \ }}
 359 
 360 " }}}
 361 
 362 au VimResized  * wincmd =
 363 au BufReadPost * normal g`"zz
 364 
 365 au FileType ale-pr* setl wrap
 366 au FileType *git*   setl sw=2 fdl=9
 367 au FileType vimwiki setl sw=2
 368 
 369 au VimEnter,FocusGained * call s:vimsid(0)
 370 au BufNew,BufEnter      * call s:vimsid(0)
 371 au VimLeave             * call s:vimsid(1)
 372 function! s:vimsid(act) " {{{
 373     let f = expand('~/.vim/vimsid')
 374 
 375     if a:act == 0 && exists('v:servername') && v:servername != ''
 376         call writefile([v:servername], f)
 377     endif
 378 
 379     if a:act == 1 && filereadable(f)
 380         call delete(f)
 381     endif
 382 endfunction " }}}
 383 
 384 au FileType vimwiki inoremap <buffer> <expr> <Cr>
 385 \ pumvisible() ? '<Cr>' : '<Esc>:VimwikiReturn 1 5<Cr>'