vim/vimrc

   1 lang messages C
   2 scriptencoding utf8
   3 
   4 set viminfo+=n~/.vim/viminfo history=1000
   5 set noswapfile undofile undodir=~/.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=100
  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 let [&t_SI, &t_SR, &t_EI] = ["\e[5 q", "\e[3 q", "\e[0 q"]
  37 
  38 set autochdir lazyredraw splitbelow splitright
  39 set foldmethod=marker foldcolumn=2 foldtext=FoldText()
  40 function! FoldText() " {{{
  41     let char = matchstr(&fillchars, '.*fold:\zs.')
  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 =~ '{'
  50         let line = substitute(line, '^-\+ ', '', '').'('.fold.')'
  51         let fill = getline(v:foldstart)
  52 
  53         if match(fill, '^\s') == 0
  54             let line = substitute(fill, '^\(\s\+\).*', '\1', '').line
  55         endif
  56     else
  57         let fold = ' '.fold
  58         let line .= repeat(char, (80 - strlen(fold) - 4 - strlen(line)))
  59         let line .= fold.' '.repeat(char, 3)
  60     endif
  61 
  62     redraw
  63     return line.repeat(' ', (winwidth(0) - strlen(line)))
  64 endfunction " }}}
  65 
  66 set nowrap linebreak display=lastline
  67 set hlsearch incsearch ignorecase smartcase
  68 set spelllang+=ru fileencodings=utf8,cp1251
  69 
  70 set ttimeoutlen=0 completeopt=menuone,noinsert
  71 set whichwrap+=<,>,[,] backspace=indent,eol,start
  72 set nojoinspaces formatoptions+=j
  73 
  74 set tabstop=4 shiftwidth=0 expandtab
  75 set autoindent smartindent shiftround smarttab
  76 
  77 set confirm report=0 showcmd
  78 set wildmenu wildignorecase wildmode=list:longest,full
  79 
  80 " Keys {{{
  81 
  82 let mapleader = ' '
  83 let &langmap  =
  84 \ 'ё`,йq,цw,уe,кr,еt,нy,гu,шi,щo,зp,х[,ъ],'.
  85 \ "фa,ыs,вd,аf,пg,рh,оj,лk,дl,ж\\;,э',".
  86 \ 'яz,чx,сc,мv,иb,тn,ьm,б\,,ю.,'.
  87 \ 'Ё~,ЙQ,ЦW,УE,КR,ЕT,HY,ГU,ШI,ЩO,ЗP,Х{,Ъ},'.
  88 \ 'ФA,ЫS,ВD,АF,ПG,РH,ОJ,ЛK,ДL,Ж:,Э",'.
  89 \ 'ЯZ,ЧX,СC,МV,ИB,ТN,ЬM,Б<,Ю>'
  90 
  91 nnoremap Y y$
  92 nnoremap * *<C-o>
  93 nnoremap n nzvzz
  94 
  95 nnoremap <Bs> X
  96 vnoremap <Bs> x
  97 vnoremap <Tab> >gv
  98 vnoremap <S-Tab> <gv
  99 
 100 vnoremap <C-c> "+y
 101 vnoremap <C-x> "+x
 102 noremap  <C-v> "+gP
 103 inoremap <C-v> <C-r>+
 104 cnoremap <C-v> <C-r>+
 105 
 106 noremap  <C-z> u
 107 inoremap <C-z> <C-o>u
 108 noremap  <C-y> <C-r>
 109 inoremap <C-y> <C-o><C-r>
 110 
 111 noremap  <C-s> :update<Cr>
 112 vnoremap <C-s> <C-c>:update<Cr>
 113 inoremap <C-s> <C-o>:update<Cr>
 114 
 115 nnoremap - :call Ranger()<Cr>
 116 function! Ranger() " {{{
 117     call term_start(
 118         \ ['ranger', '--choosefiles', s:ranger_f, '--selectfile', expand('%')],
 119         \ { 'term_finish': 'close', 'exit_cb': 'RangerCb' }
 120     \ )
 121 endfunction
 122 
 123 function! RangerCb(msg, code)
 124     if !filereadable(s:ranger_f)
 125         redraw! | return
 126     endif
 127 
 128     exec 'tabe '.join(readfile(s:ranger_f), ' | tabe ')
 129     redraw! | call delete(s:ranger_f)
 130 endfunction
 131 let s:ranger_f = tempname() " }}}
 132 nnoremap <F5> :w \| make!<Cr>
 133 
 134 nmap <Leader>h :nohls<Cr>
 135 nmap <Leader>s :setl spell!<Cr>
 136 nmap <Leader>w :setl wrap!<Cr>
 137 nmap <Leader>n :setl nu! nornu<Cr>
 138 nmap <Leader>g :tabe \| call magit#show_magit('c', 1, 2)<Cr>
 139 
 140 for s:i in range(1, 9)
 141     exec 'set <A-'.s:i.">=\e".s:i
 142     exec 'noremap <A-'.s:i.'> '.s:i.'gt'
 143     exec 'inoremap <A-'.s:i.'> <C-o>'.s:i.'gt'
 144 endfor
 145 
 146 " }}}
 147 " Colors {{{
 148 
 149 set t_Co=16
 150 colors default
 151 
 152 hi! clear
 153 
 154 hi! Visual ctermbg=NONE ctermfg=grey cterm=reverse
 155 
 156 hi! Search ctermbg=NONE ctermfg=darkYellow cterm=reverse
 157 hi! IncSearch ctermbg=NONE ctermfg=yellow cterm=reverse
 158 
 159 hi! SpellBad ctermbg=NONE ctermfg=red cterm=underline
 160 hi! SpellCap ctermbg=NONE ctermfg=blue cterm=underline
 161 
 162 hi! link TabLine User1
 163 hi! link TabLineSel User2
 164 
 165 hi! LineNr ctermbg=NONE ctermfg=grey
 166 hi! SignColumn ctermbg=NONE ctermfg=NONE
 167 
 168 hi! Folded ctermbg=NONE ctermfg=grey
 169 hi! FoldColumn ctermbg=NONE ctermfg=grey
 170 
 171 hi! DiffAdd ctermbg=NONE ctermfg=green cterm=reverse
 172 hi! DiffChange ctermbg=NONE ctermfg=darkYellow cterm=reverse
 173 hi! DiffDelete ctermbg=NONE ctermfg=red cterm=reverse
 174 hi! DiffText ctermbg=NONE ctermfg=NONE cterm=reverse
 175 
 176 hi! Error ctermbg=NONE ctermfg=red
 177 hi! ErrorMsg ctermbg=NONE ctermfg=red
 178 
 179 " }}}
 180 " Statusline {{{
 181 
 182 set laststatus=2
 183 set statusline=%1*%{StatusLine()}
 184 set statusline+=\ %<%F%{&mod?'*':''}\ %r%=
 185 set statusline+=%{&et?'':'\\t\ '}%{&spell?'ая\ ':''}
 186 set statusline+=%{&fenc}\ %{&ff}\ %2*\ %P\ %0*
 187 function! StatusLine() " {{{
 188     if mode() == s:statusline
 189         return ''
 190     endif
 191 
 192     let s:statusline = mode()
 193     let mode = get({
 194         \ 'n': 'Normal', 'i': 'Insert',
 195         \ 'v': 'Visual', 'V': 'Visual', "\<C-v>": 'Visual'
 196     \ }, s:statusline, 'Replace')
 197 
 198     exec 'hi! link User2 Mode'.mode
 199     redrawstatus | redrawtabline
 200 
 201     return ''
 202 endfunction
 203 let s:statusline = '' " }}}
 204 
 205 hi! StatusLine cterm=reverse
 206 hi! StatusLineNC ctermbg=white ctermfg=black
 207 
 208 hi! User1 ctermbg=NONE
 209 hi! link User2 ModeNormal
 210 
 211 hi! ModeNormal ctermbg=NONE ctermfg=NONE cterm=reverse,bold
 212 hi! ModeInsert ctermbg=NONE ctermfg=blue cterm=reverse,bold
 213 hi! ModeVisual ctermbg=NONE ctermfg=darkYellow cterm=reverse,bold
 214 hi! ModeReplace ctermbg=NONE ctermfg=red cterm=reverse,bold
 215 
 216 " }}}
 217 " Commands {{{
 218 
 219 au BufReadPost * normal g`"zz
 220 au BufWritePre * setl eol | retab | %s/\s\+$//e
 221 
 222 au FileType *commit setl spell tw=72 sw=2
 223 au FileType mail,markdown setl wrap spell
 224 
 225 au BufRead *newsboat/urls nmap <Leader>S Vip:'<,'>!sort -k 2,3<Cr>
 226 
 227 " }}}
 228 " Plugins {{{
 229 
 230 if !filereadable(expand('~/.vim/autoload/plug.vim')) " {{{
 231     silent exe '!curl -sLo ~/.vim/autoload/plug.vim --create-dirs
 232     \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
 233 endif " }}}
 234 
 235 call plug#begin('~/.vim/plug')
 236 
 237 Plug 'https://github.com/mhinz/vim-signify'
 238 Plug 'https://github.com/yggdroot/indentLine' " {{{
 239 let indentLine_faster = 1
 240 let indentLine_char = '·'
 241 let indentLine_color_term = 'darkGrey'
 242 let indentLine_leadingSpaceEnabled = 1
 243 let indentLine_leadingSpaceChar = '·'
 244 " }}}
 245 
 246 Plug 'https://github.com/ctrlpvim/ctrlp.vim' " {{{
 247 let ctrlp_prompt_mappings = {
 248     \ 'AcceptSelection("e")': ['<2-LeftMouse>'],
 249     \ 'AcceptSelection("t")': ['<Cr>', '<C-t>']
 250 \ }
 251 " }}}
 252 Plug 'https://github.com/junegunn/vim-peekaboo'
 253 Plug 'https://github.com/jreybert/vimagit' " {{{
 254 let magit_auto_close = 1
 255 " }}}
 256 
 257 Plug 'https://github.com/lifepillar/vim-mucomplete' " {{{
 258 let mucomplete#enable_auto_at_startup = 1
 259 " let mucomplete#minimum_prefix_length = 1
 260 let mucomplete#chains = {
 261     \ 'default' : ['path', 'c-n', 'omni', 'uspl']
 262 \ }
 263 " }}}
 264 Plug 'https://github.com/w0rp/ale' " {{{
 265 let ale_sign_warning = '>>'
 266 let ale_c_gcc_options = '-std=gnu11 -Wall'
 267 " }}}
 268 
 269 Plug 'https://github.com/sheerun/vim-polyglot'
 270 Plug 'https://github.com/jamessan/vim-gnupg' " {{{
 271 let GPGPreferSymmetric = 1
 272 " }}}
 273 Plug 'https://github.com/calviken/vim-gdscript3'
 274 
 275 Plug 'https://github.com/tpope/vim-endwise'
 276 Plug 'https://github.com/adelarsq/vim-matchit'
 277 
 278 Plug 'https://github.com/tpope/vim-commentary'
 279 Plug 'https://github.com/dhruvasagar/vim-table-mode'
 280 
 281 call plug#end()
 282 
 283 " }}}
 284 " Blo {{{
 285 
 286 let s:blo_id = -1
 287 let s:blo_lines = []
 288 let s:blo_f = expand('~/Projects/lexa.by/bloge/2019/news.txt')
 289 
 290 au BufEnter blo+,blo[0-9]\+ setl bt=acwrite ft=markdown
 291 au BufNewFile blo+ silent! call BloNew()
 292 au BufNewFile blo- nested silent! call BloRecent()
 293 au BufNewFile blo[0-9]\+ silent! call BloEdit()
 294 au BufWriteCmd blo+,blo[0-9]\+ silent! call BloWrite()
 295 au BufWriteCmd blo+ nested silent! call BloNewWrite()
 296 
 297 function! BloNew() " {{{
 298     let s:blo_id = -1
 299 
 300     %!date +'\%F \%H:\%M '
 301 endfunction " }}}
 302 function! BloRecent() " {{{
 303     exec 'e! blo'.len(readfile(s:blo_f))
 304 endfunction " }}}
 305 function! BloEdit() " {{{
 306     let s:blo_id = (expand('%')[3:] - 1)
 307     let s:blo_lines = readfile(s:blo_f)
 308 
 309     :1,$d | call append(0, s:blo_lines[s:blo_id])
 310     %s/\\n/\r\r/g | %!pandoc -f html -t markdown
 311 endfunction " }}}
 312 function! BloWrite() " {{{
 313     2,$!pandoc -f markdown -t html5
 314     2,$s/\n/\\n/g | normal! ggJx$xx0
 315     %!sed 'y/“‘’”/«„“»/'
 316 
 317     if s:blo_id > -1
 318         let s:blo_lines[s:blo_id] = getline('.')
 319         call writefile(s:blo_lines, s:blo_f)
 320     else
 321         call writefile([getline('.')], s:blo_f, 'a')
 322     endif
 323 
 324     normal! u
 325     !cd ~/Projects/lexa.by/bloge && ./build.php
 326     nohls | redraw! | set nomod
 327 endfunction " }}}
 328 function! BloNewWrite() " {{{
 329     e! blo-
 330 endfunction " }}}
 331 
 332 " }}}