.vimrc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. " disable modelines
  102. set nomodeline
  103. " ------ key bindings ------
  104. " ; as :
  105. nnoremap ; :
  106. vnoremap ; :
  107. " allow <ESC> via jj in insert mode
  108. inoremap jj <ESC>
  109. " fix j/k with wraps
  110. nnoremap j gj
  111. nnoremap k gk
  112. vnoremap j gj
  113. vnoremap k gk
  114. augroup formatting
  115. au!
  116. " strip trailing whitespace
  117. autocmd BufWritePre * :%s/\s\+$//e
  118. autocmd FileType markdown :set tw=80
  119. augroup end
  120. if filereadable(expand('~/.vimrc.local'))
  121. source ~/.vimrc.local
  122. endif
  123. highlight StatusLine cterm=NONE ctermbg=8
  124. highlight StatusLineNC cterm=NONE ctermbg=0
  125. highlight StatusLineModeInsert ctermbg=14 ctermfg=0
  126. highlight StatusLineModeVisual ctermbg=3 ctermfg=0
  127. highlight StatusLineModeNormal ctermbg=11 ctermfg=0
  128. function GetMode()
  129. let m = mode()
  130. " echom m
  131. if m ==# 'i'
  132. return '%#StatusLineModeInsert# I '
  133. elseif m =~# '\(v\|V\|\)'
  134. return '%#StatusLineModeVisual# V '
  135. else
  136. return '%#StatusLineModeNormal# N '
  137. endif
  138. endfunction
  139. function StatusLine()
  140. let line=''
  141. let line.=GetMode()
  142. let line.='%*%< %f %h%m%r'
  143. let line.='%='
  144. " let line.='%-14.(%l,%c%V%) %P'
  145. let line.=' %y '
  146. let line.=' %{&fenc}[%{&ff}]'
  147. let line.=' %3p%% %7(%l/%L%): %3(%c%V%) '
  148. return line
  149. endfunction
  150. set statusline=%!StatusLine()