vim/vimrc

   1 lang messages C
   2 set nocompatible
   3 scriptencoding utf8
   4 let &langmap =
   5 \ 'ё`,йq,цw,уe,кr,еt,нy,гu,шi,щo,зp,х[,ъ],'.
   6 \ "фa,ыs,вd,аf,пg,рh,оj,лk,дl,ж\\;,э',".
   7 \ 'яz,чx,сc,мv,иb,тn,ьm,б\,,ю.,'.
   8 \ 'Ё~,ЙQ,ЦW,УE,КR,ЕT,HY,ГU,ШI,ЩO,ЗP,Х{,Ъ},'.
   9 \ 'ФA,ЫS,ВD,АF,ПG,РH,ОJ,ЛK,ДL,Ж:,Э",'.
  10 \ 'ЯZ,ЧX,СC,МV,ИB,ТN,ЬM,Б<,Ю>'
  11 
  12 set viminfo+=n~/.vim/viminfo
  13 set directory=~/.vim/swap//
  14 set undofile undodir=~/.vim/undo//
  15 if !isdirectory(expand(&directory)) " {{{
  16     call mkdir(expand(&directory), 'p')
  17 endif
  18 
  19 if !isdirectory(expand(&undodir))
  20     call mkdir(expand(&undodir), 'p')
  21 endif " }}}
  22 
  23 set titlestring=%F%{&mod?'*':''}\ -\ Vim tabpagemax=100
  24 set tabline=%!TabLine() guitablabel=%N:%t%{&mod?'*':''}
  25 function! TabLine() " {{{
  26     let s = ''
  27 
  28     for i in range(tabpagenr('$'))
  29         let n = (i + 1)
  30         let s .= (n == tabpagenr() ? '%#TabLineSel#' : '%#TabLine#')
  31         let s .= '%'.n.'T '.n.':%{TabLineLabel('.n.')} '
  32     endfor
  33 
  34     return s.'%#TabLine#%T'
  35 endfunction
  36 
  37 function! TabLineLabel(n)
  38     let list = tabpagebuflist(a:n)
  39     let num = list[tabpagewinnr(a:n) - 1]
  40 
  41     let name = fnamemodify(bufname(num), ':t')
  42     let mod = (getbufvar(num, '&mod') ? '*' : '')
  43 
  44     return (name == '' ? '[No Name]' : name.mod)
  45 endfunction " }}}
  46 
  47 set mouse=a virtualedit=block whichwrap+=<,>,[,]
  48 set mousemodel=popup_setpos keymodel=startsel
  49 set guicursor+=a:blinkwait500-blinkon500-blinkoff500
  50 let [&t_SI, &t_SR, &t_EI] = ["\e[5 q", "\e[3 q", "\e[0 q"]
  51 
  52 set autochdir lazyredraw
  53 set confirm shortmess+=A
  54 set splitbelow splitright
  55 
  56 set foldtext=FoldText() cursorline
  57 set nowrap linebreak display=lastline
  58 set hlsearch incsearch ignorecase smartcase
  59 function! FoldText() " {{{
  60     let char = matchstr(&fillchars, '.*fold:\zs.')
  61     let fold = (v:foldend - v:foldstart + 1).' lines'
  62 
  63     let line = foldtext()
  64     let line = substitute(line, '\(\d\+\)', ' \1', '')
  65     let line = substitute(line, ' .*: ', ' ', '')
  66     let line = substitute(line, '^+', '-', '')
  67 
  68     if strlen(v:folddashes) > 1 || line =~ '(' || line =~ '{'
  69         let line = substitute(line, '^-\+ ', '', '').'('.fold.')'
  70         let fill = getline(v:foldstart)
  71 
  72         if match(fill, '^\s') == 0
  73             let line = substitute(fill, '^\(\s\+\).*', '\1', '').line
  74         endif
  75     else
  76         let fold = ' '.fold
  77         let line .= repeat(char, (80 - strlen(fold) - 4 - strlen(line)))
  78         let line .= fold.' '.repeat(char, 3)
  79     endif
  80 
  81     redraw
  82     return line.repeat(' ', (winwidth(0) - strlen(line)))
  83 endfunction " }}}
  84 
  85 set spelllang+=ru fileformats+=mac
  86 set fileencodings=utf8,cp1251
  87 
  88 set ttimeoutlen=0 nrformats-=octal
  89 set nojoinspaces formatoptions+=j
  90 set completeopt=menu,menuone,longest,preview
  91 
  92 set autoindent smartindent shiftround
  93 set shiftwidth=4 tabstop=4 expandtab smarttab
  94 
  95 set report=0 showcmd
  96 set wildmenu wildignorecase
  97 set wildmode=list:longest,full
  98 
  99 " Binds {{{
 100 
 101 for s:i in range(char2nr('a'), char2nr('z'))
 102     exec 'set <A-'.nr2char(s:i).">=\e".nr2char(s:i)
 103 endfor
 104 
 105 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 106 
 107 noremap <C-a> ggVG
 108 inoremap <C-a> <C-c>ggVG
 109 
 110 vnoremap <Tab> >gv
 111 vnoremap <S-Tab> <gv
 112 inoremap <S-Tab> <C-o><<
 113 
 114 noremap <Bs> X
 115 vnoremap <Bs> <Del>
 116 
 117 noremap <C-v> "+gP
 118 inoremap <C-v> <C-r>+
 119 cnoremap <C-v> <C-r>+
 120 
 121 vnoremap <C-c> "+y
 122 vnoremap <C-x> "+x
 123 
 124 noremap <C-z> u
 125 inoremap <C-z> <C-o>u
 126 
 127 noremap <C-y> <C-r>
 128 inoremap <C-y> <C-O><C-r>
 129 
 130 noremap <C-s> :update<Cr>
 131 vnoremap <C-s> <C-c>:update<Cr>
 132 inoremap <C-s> <C-o>:update<Cr>
 133 
 134 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 135 
 136 vnoremap > >gv
 137 vnoremap < <gv
 138 
 139 nnoremap * *<C-o>
 140 nnoremap g* g*<C-o>
 141 
 142 nnoremap n nzvzz
 143 nnoremap N Nzvzz
 144 
 145 nnoremap Y y$
 146 nnoremap S i<Cr><Esc>^
 147 
 148 nnoremap <A-v> <C-v>
 149 nnoremap <A-z> <C-z>
 150 nnoremap <A-a> <C-a>
 151 nnoremap <A-x> <C-x>
 152 
 153 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 154 
 155 noremap <C-Tab> gt
 156 inoremap <C-Tab> <C-o>gt
 157 
 158 noremap <C-S-Tab> gT
 159 inoremap <C-S-Tab> <C-o>gT
 160 
 161 for s:i in range(1, 9)
 162     exec 'set <A-'.s:i.">=\e".s:i
 163     exec 'noremap <A-'.s:i.'> '.s:i.'gt'
 164     exec 'inoremap <A-'.s:i.'> <C-o>'.s:i.'gt'
 165 endfor
 166 
 167 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 168 
 169 let mapleader = ' '
 170 
 171 nmap <Leader>h :set hls!<Cr>
 172 nmap <Leader>s :set spell!<Cr>
 173 nmap <Leader>w :set wrap!<Cr>
 174 
 175 nmap <Leader>n :set nu! nornu<Cr>
 176 nmap <Leader>r :set rnu! nonu<Cr>
 177 
 178 nmap - :call OpenRangerIn('%:p', 'tabedit ')<Cr>
 179 nmap <Leader>z :Goyo<Cr>
 180 nmap <Leader>T :tab sball<Cr>
 181 
 182 " }}}
 183 " Colors {{{
 184 
 185 set t_Co=16
 186 colorscheme default
 187 
 188 hi clear
 189 syntax on
 190 
 191 hi! Visual ctermbg=NONE ctermfg=grey cterm=reverse
 192 
 193 hi! Search ctermbg=NONE ctermfg=darkYellow cterm=reverse
 194 hi! IncSearch ctermbg=NONE ctermfg=yellow cterm=reverse
 195 hi! SpellBad ctermbg=NONE ctermfg=red cterm=reverse
 196 hi! SpellCap ctermbg=NONE ctermfg=blue cterm=reverse
 197 
 198 hi! TabLine ctermbg=NONE ctermfg=grey cterm=NONE
 199 hi! LineNr ctermbg=NONE ctermfg=grey
 200 
 201 hi! SignColumn ctermbg=NONE ctermfg=NONE
 202 hi! Folded ctermbg=NONE ctermfg=grey
 203 hi! FoldColumn ctermbg=NONE ctermfg=grey
 204 
 205 hi! DiffAdd ctermbg=NONE ctermfg=green cterm=reverse
 206 hi! DiffChange ctermbg=NONE ctermfg=darkYellow cterm=reverse
 207 hi! DiffDelete ctermbg=NONE ctermfg=red cterm=reverse
 208 hi! DiffText ctermbg=NONE ctermfg=NONE cterm=reverse
 209 
 210 hi! Error ctermbg=NONE ctermfg=red
 211 hi! ErrorMsg ctermbg=NONE ctermfg=red
 212 
 213 " }}}
 214 " Statusline {{{
 215 
 216 set laststatus=2
 217 let s:statusline = ''
 218 set statusline=%1*%{StatusLine()}\ %<%F%{&mod?'*':''}\ %R%=
 219 set statusline+=%{&ff}%{&fenc!=''?'\ \ '.&fenc:''}\ %2*\ %P\ %0*
 220 function! StatusLine() " {{{
 221     let now = mode()
 222     let map = {
 223         \ 'n': 'Normal', 'i': 'Insert',
 224         \ 'v': 'Visual', 'V': 'Visual', "\<C-v>": 'Visual',
 225         \ 's': 'Replace', 'S': 'Replace', "\<C-s>": 'Replace',
 226         \ 'R': 'Replace', 'Rv': 'Replace'
 227     \ }
 228 
 229     if now == s:statusline
 230         return ''
 231     endif
 232 
 233     let s:statusline = now
 234 
 235     exec join(['hi! link', 'User2', 'Mode'.get(map, now, 'Normal')], ' ')
 236     redrawstatus
 237 
 238     return ''
 239 endfunction " }}}
 240 
 241 hi! StatusLine cterm=reverse
 242 hi! StatusLineNC ctermbg=white ctermfg=black
 243 
 244 hi! User1 ctermbg=NONE
 245 hi! link User2 ModeNormal
 246 
 247 hi! ModeNormal ctermbg=NONE ctermfg=NONE cterm=reverse
 248 hi! ModeInsert ctermbg=NONE ctermfg=blue cterm=reverse
 249 hi! ModeVisual ctermbg=NONE ctermfg=darkYellow cterm=reverse
 250 hi! ModeReplace ctermbg=NONE ctermfg=red cterm=reverse
 251 
 252 " }}}
 253 " Commands {{{
 254 
 255 au VimEnter * redraw
 256 
 257 au BufReadPre *
 258     \ if getfsize(expand('<afile>')) > (1024 * 1024) |
 259     \ setl ei+=FileType | else | setl ei-=FileType |
 260     \ endif
 261 au BufReadPost * normal g`"zz
 262 au BufWritePre *
 263     \ setl eol | retab |
 264     \ let _reg=@/ | %s/\s\+$//e | let @/=_reg | unlet _reg |
 265     \ if &fenc == 'utf-8' && &bomb | setl nobomb | endif
 266 
 267 au FileType qf setl wrap
 268 au FileType mail setl wrap spell
 269 au FileType markdown setl wrap spell
 270 au FileType *commit setl spell tw=72 sw=2
 271 au BufRead ~/.*,$HOME/.* setl fdm=marker fdc=2
 272 
 273 " }}}
 274 " Plugins {{{
 275 
 276 if !filereadable(expand('~/.vim/autoload/plug.vim'))
 277     silent exe '!curl -sLo ~/.vim/autoload/plug.vim --create-dirs
 278     \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
 279 endif
 280 
 281 call plug#begin('~/.vim/plug')
 282 
 283 Plug 'https://github.com/gmarik/vundle.vim'
 284 Plug 'https://github.com/mhinz/vim-startify' " {{{
 285 let startify_list_order = [
 286     \ ['   Bookmarks:'], 'bookmarks',
 287     \ ['   Sessions:'], 'sessions',
 288     \ ['   Recent Files:'], 'files'
 289 \ ]
 290 " }}}
 291 
 292 Plug 'https://github.com/ctrlpvim/ctrlp.vim' " {{{
 293 let g:ctrlp_prompt_mappings = {
 294     \ 'AcceptSelection("e")': ['<2-LeftMouse>'],
 295     \ 'AcceptSelection("t")': ['<Cr>', '<C-t>']
 296 \ }
 297 " }}}
 298 Plug 'https://github.com/francoiscabrol/ranger.vim'
 299 
 300 Plug 'https://github.com/junegunn/goyo.vim'
 301 Plug 'https://github.com/mhinz/vim-signify'
 302 Plug 'https://github.com/junegunn/vim-peekaboo'
 303 Plug 'https://github.com/yggdroot/indentLine' " {{{
 304 let indentLine_faster = 1
 305 let indentLine_concealcursor = 0
 306 let indentLine_color_term = 'black'
 307 " }}}
 308 
 309 Plug 'https://github.com/shougo/neocomplcache.vim' " {{{
 310 let neocomplcache_enable_at_startup = 1
 311 let neocomplcache_enable_smart_case = 1
 312 let neocomplcache_min_syntax_length = 2
 313 let neocomplcache_min_keyword_length = 2
 314 let neocomplcache_enable_insert_char_pre = 1
 315 " }}}
 316 Plug 'https://github.com/scrooloose/syntastic' " {{{
 317 let syntastic_check_on_open = 1
 318 let syntastic_check_on_wq = 0
 319 let syntastic_auto_loc_list = 1
 320 let syntastic_loc_list_height = 4
 321 " }}}
 322 
 323 Plug 'https://github.com/sheerun/vim-polyglot'
 324 Plug 'https://github.com/jamessan/vim-gnupg' " {{{
 325 let GPGPreferSymmetric = 1
 326 " }}}
 327 
 328 " Plugin 'https://github.com/jiangmiao/auto-pairs'
 329 Plug 'https://github.com/tpope/vim-endwise'
 330 Plug 'https://github.com/adelarsq/vim-matchit'
 331 
 332 Plug 'https://github.com/tpope/vim-repeat'
 333 Plug 'https://github.com/tpope/vim-surround'
 334 Plug 'https://github.com/tpope/vim-commentary'
 335 Plug 'https://github.com/dhruvasagar/vim-table-mode'
 336 
 337 call plug#end()
 338 
 339 " }}}