.vimrc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. " Sensible.vim
  2. if exists('g:loaded_sensible') || &compatible
  3. else
  4. let g:loaded_sensible = 1
  5. if has('autocmd')
  6. filetype plugin indent on
  7. endif
  8. if has('syntax') && !exists('g:syntax_on')
  9. syntax enable
  10. endif
  11. " Use :help 'option' to see the documentation for the given option.
  12. set autoindent
  13. set backspace=indent,eol,start
  14. set complete-=i
  15. set smarttab
  16. set nrformats-=octal
  17. set ttimeout
  18. set ttimeoutlen=100
  19. set incsearch
  20. " Use <C-L> to clear the highlighting of :set hlsearch.
  21. if maparg('<C-L>', 'n') ==# ''
  22. nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
  23. endif
  24. set laststatus=2
  25. set ruler
  26. set wildmenu
  27. if !&scrolloff
  28. set scrolloff=1
  29. endif
  30. if !&sidescrolloff
  31. set sidescrolloff=5
  32. endif
  33. set display+=lastline
  34. if &encoding ==# 'latin1' && has('gui_running')
  35. set encoding=utf-8
  36. endif
  37. if &listchars ==# 'eol:$'
  38. set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
  39. endif
  40. if v:version > 703 || v:version == 703 && has("patch541")
  41. set formatoptions+=j " Delete comment character when joining commented lines
  42. endif
  43. if has('path_extra')
  44. setglobal tags-=./tags tags-=./tags; tags^=./tags;
  45. endif
  46. if &shell =~# 'fish$' && (v:version < 704 || v:version == 704 && !has('patch276'))
  47. set shell=/bin/bash
  48. endif
  49. set autoread
  50. if &history < 1000
  51. set history=1000
  52. endif
  53. if &tabpagemax < 50
  54. set tabpagemax=50
  55. endif
  56. if !empty(&viminfo)
  57. set viminfo^=!
  58. endif
  59. set sessionoptions-=options
  60. " Allow color schemes to do bright colors without forcing bold.
  61. if &t_Co == 8 && $TERM !~# '^linux\|^Eterm'
  62. set t_Co=16
  63. endif
  64. " Load matchit.vim, but only if the user hasn't installed a newer version.
  65. if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# ''
  66. runtime! macros/matchit.vim
  67. endif
  68. inoremap <C-U> <C-G>u<C-U>
  69. endif
  70. " change terminal title
  71. set title
  72. " xdg-ish settings
  73. set undodir=~/.cache/vim/undo,.
  74. set backupdir=~/.cache/vim/backup,.
  75. set directory=~/.cache/vim/swap//,.
  76. " default indentation
  77. set shiftwidth=2
  78. set tabstop=4
  79. set expandtab
  80. " permanent undo history
  81. set undofile
  82. " allow switching buffers
  83. set hidden
  84. " always scroll
  85. set scrolloff=99
  86. " show line numbers
  87. set number
  88. set relativenumber
  89. " set wordwrap indent
  90. set nowrap
  91. set linebreak
  92. if exists("&breakindent")
  93. set breakindent
  94. set breakindentopt=shift:2,sbr
  95. endif
  96. " show whitespace
  97. set list
  98. " make a new copy of the file for backup
  99. " setting to no or auto messes with filewatchers
  100. set backupcopy=yes
  101. " ------ key bindings ------
  102. " ; as :
  103. nnoremap ; :
  104. vnoremap ; :
  105. " allow <ESC> via jj in insert mode
  106. inoremap jj <ESC>
  107. " fix j/k with wraps
  108. nnoremap j gj
  109. nnoremap k gk
  110. vnoremap j gj
  111. vnoremap k gk
  112. augroup formatting
  113. au!
  114. " strip trailing whitespace
  115. autocmd BufWritePre * :%s/\s\+$//e
  116. autocmd FileType markdown :set tw=80
  117. augroup end
  118. if filereadable(expand('~/.vimrc.local'))
  119. source ~/.vimrc.local
  120. endif
  121. highlight StatusLine cterm=NONE ctermbg=8
  122. highlight StatusLineNC cterm=NONE ctermbg=0
  123. highlight StatusLineModeInsert ctermbg=14 ctermfg=0
  124. highlight StatusLineModeVisual ctermbg=3 ctermfg=0
  125. highlight StatusLineModeNormal ctermbg=11 ctermfg=0
  126. function GetMode()
  127. let m = mode()
  128. " echom m
  129. if m ==# 'i'
  130. return '%#StatusLineModeInsert# I '
  131. elseif m =~# '\(v\|V\|\)'
  132. return '%#StatusLineModeVisual# V '
  133. else
  134. return '%#StatusLineModeNormal# N '
  135. endif
  136. endfunction
  137. function StatusLine()
  138. let line=''
  139. let line.=GetMode()
  140. let line.='%*%< %f %h%m%r'
  141. let line.='%='
  142. " let line.='%-14.(%l,%c%V%) %P'
  143. let line.=' %y '
  144. let line.=' %{&fenc}[%{&ff}]'
  145. let line.=' %3p%% %7(%l/%L%): %3(%c%V%) '
  146. return line
  147. endfunction
  148. set statusline=%!StatusLine()