vimrc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. set nocompatible " Don't have to try to be compatible with old vi
  2. set encoding=utf-8
  3. """"""""
  4. "" Plugin Loading with Pathogen
  5. """""""""""""""""""""""""""""""""""""""""""""""""""
  6. call pathogen#infect()
  7. call pathogen#helptags()
  8. """"""""
  9. "" Environment - What kind of machine are we on?
  10. """""""""""""""""""""""""""""""""""""""""""""""""""
  11. if has("unix")
  12. " remove the newline character from the uname command
  13. let s:uname = substitute(system("uname"), "\n", "", "")
  14. endif
  15. """"""""
  16. "" General Behaviours
  17. """""""""""""""""""""""""""""""""""""""""""""""""""
  18. set splitbelow " New splits appear below current window instead of above
  19. set splitright " New splits appear right of current window
  20. set ttyfast " Smooth movement
  21. set ttymouse=xterm2
  22. " Persistent undo
  23. if has("persistent_undo")
  24. set undofile
  25. set undodir=~/.vimundo
  26. endif
  27. if has("autocmd")
  28. " Enable filetype specific features
  29. filetype plugin indent on
  30. " Clear existing autocmd
  31. autocmd!
  32. " When editing a file, always jump to the last cursor position
  33. autocmd BufReadPost *
  34. \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  35. \ exe "normal! g'\"" |
  36. \ endif
  37. " Maps for Quickfix and Location List windows
  38. autocmd FileType qf nnoremap <silent> <buffer> q :ccl<CR>:lcl<CR>
  39. autocmd FileType qf nnoremap <silent> <buffer> o <CR>
  40. autocmd FileType qf nnoremap <silent> <buffer> go <CR><C-W><C-W>
  41. " Any actions on startup
  42. autocmd VimEnter * call StartUp()
  43. autocmd WinEnter * setlocal cursorline
  44. autocmd WinLeave * setlocal nocursorline
  45. " Show trailing white space
  46. autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
  47. autocmd InsertLeave * match ExtraWhitespace /\s\+$/
  48. " Source the vimrc file after saving it
  49. autocmd bufwritepost .vimrc source $MYVIMRC
  50. autocmd bufwritepost .vimrc call Pl#Load()
  51. " Reload Powerline colours after source
  52. " https://github.com/Lokaltog/vim-powerline/issues/28
  53. " if the last window is NERDTree, then close Vim
  54. "autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
  55. else
  56. set autoindent on
  57. endif
  58. """"""""
  59. "" Tabs and Text Formatting
  60. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  61. set expandtab " change to single spaces
  62. set tabstop=2 " actual tab press distance
  63. set shiftround " indent to nearest tabstops
  64. set shiftwidth=2 " amount to indent with > and <
  65. set smarttab " backspace tabs where appropriate even if spaces
  66. set softtabstop=2 " let backspace delete by indents
  67. set nowrap " do not wrap long lines of text
  68. set backspace=eol,start,indent "backspace over everything
  69. set textwidth=80 " try to keep text within 80 characters
  70. set colorcolumn=+1 " mark out the limits of the textwidth
  71. set listchars=trail:_,tab:>.,eol:$
  72. """"""""
  73. "" UI - Colours
  74. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  75. syntax enable
  76. colorscheme solarized
  77. set t_Co=16
  78. set background=dark
  79. " set colour for folded lines
  80. highlight Folded term=none cterm=none ctermfg=darkred ctermbg=none
  81. " show trailing white space
  82. highlight ExtraWhitespace ctermfg=red ctermbg=red guifg=red guibg=red
  83. """"""""
  84. "" UI - Numbering
  85. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  86. set number " show line numbers
  87. "set relativenumber " current line always 0 (requires 7.3 and up)
  88. """"""""
  89. "" UI - Statusline (now using powerline)
  90. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  91. set laststatus=2 " status line is second last line (not hidden by commands)
  92. """"""""
  93. "" UI - Code Folding
  94. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  95. set foldmethod=indent
  96. set foldlevel=10
  97. set foldtext=FoldText()
  98. """"""""
  99. "" UI - Search
  100. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  101. set hlsearch " make searches highlighted
  102. set incsearch " vim will search as you type!
  103. set ignorecase " ignore case for searches
  104. set smartcase " well, unless a user puts in uppercase search characters
  105. set magic " enables wildcard searching
  106. """"""""
  107. "" Key Remaps
  108. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  109. let mapleader = "," " easier to use than \
  110. " More convenient escape
  111. imap ii <Esc>
  112. imap II <Esc>
  113. " Yank to end of line, like D deletes to end of line
  114. nmap Y y$
  115. " Space as a folding toggle in normal mode.
  116. nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
  117. " Clear trailing white space
  118. nmap <silent> <leader>$ :%s/\s\+$//g<CR>
  119. " Add extra lines up and down
  120. nmap <leader>j o<Esc>k
  121. nmap <leader>k O<Esc>j
  122. " Edit .vimrc
  123. nmap <leader>v :e $MYVIMRC<CR>
  124. nmap <silent> <leader>n :set number!<CR>
  125. nmap <silent> <leader>w :set wrap!<CR>
  126. " Toggle paste mode - no autoindenting of pasted material
  127. nmap <silent> <leader>p :set paste! paste?<CR>
  128. " Toggle visible whitespace characters
  129. nmap <silent> <leader>l :set list!<CR>
  130. " Toggle scrollbind for moving multiple splits in sync together
  131. nmap <silent> <leader>s :set scrollbind! scrollbind?<CR>
  132. " Toggle mouse support.
  133. nmap <silent> <leader>m :call ToggleMouse()<CR>
  134. " Toggle NERDTree file browser
  135. nmap <silent> <leader>d :NERDTreeToggle<CR>
  136. " Toggle Commenting out lines with NERDCommenter
  137. nmap <silent> <leader>, :call NERDComment("n", "toggle")<CR>
  138. vmap <silent> <leader>, <ESC>:call NERDComment("x", "toggle")<CR>
  139. " Traverse undo tree with Gundo!
  140. nmap <silent> <leader>u :GundoToggle<CR>
  141. " Git blame with Fugitive!
  142. nmap <silent> <leader>b :Gblame<CR>
  143. " Code heirarchy with Tagbar!
  144. nmap <silent> <leader>t :TagbarToggle<CR>
  145. """"""""
  146. "" Key Remaps - Movement and Windows
  147. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  148. " jump to beginning and end of line easier
  149. nmap H ^
  150. nmap L $
  151. " Smart way to move between windows
  152. nmap <C-j> <C-W>j
  153. nmap <C-k> <C-W>k
  154. nmap <C-h> <C-W>h
  155. nmap <C-l> <C-W>l
  156. " mapping to make movements operate on 1 screen line in wrap mode
  157. onoremap <silent> <expr> j ScreenMovement("j")
  158. onoremap <silent> <expr> k ScreenMovement("k")
  159. onoremap <silent> <expr> 0 ScreenMovement("0")
  160. onoremap <silent> <expr> ^ ScreenMovement("^")
  161. onoremap <silent> <expr> $ ScreenMovement("$")
  162. nnoremap <silent> <expr> j ScreenMovement("j")
  163. nnoremap <silent> <expr> k ScreenMovement("k")
  164. nnoremap <silent> <expr> 0 ScreenMovement("0")
  165. nnoremap <silent> <expr> ^ ScreenMovement("^")
  166. nnoremap <silent> <expr> $ ScreenMovement("$")
  167. """"""""
  168. "" Plugin options
  169. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  170. """"""""" NERDTree
  171. let g:NERDTreeQuitOnOpen = 1 " close sidebar after we go to selection
  172. """"""""" Gundo
  173. let g:gundo_width = 30
  174. let g:gundo_preview_height = 12
  175. let g:gundo_preview_bottom = 1
  176. """"""""" Powerline
  177. let g:Powerline_symbols = 'fancy' " alternatives: fancy, unicode
  178. """"""""" Tagbar
  179. let g:tagbar_autoclose = 1 " close sidebar after we go to selection
  180. """"""""" EasyGrep
  181. let g:EasyGrepJumpToMatch = 0
  182. let g:EasyGrepHighlightQfMatches = 1
  183. """"""""
  184. "" Functions
  185. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  186. function! StartUp()
  187. " start NERDTree if vim called with no arguments
  188. if 0 == argc()
  189. NERDTree
  190. end
  191. endfunction
  192. function! FoldText()
  193. let line = getline(v:foldstart)
  194. let indent = indent(v:foldstart)
  195. let indentOnly = strpart(line, 0, indent-1)
  196. let linecount = v:foldend+1 - v:foldstart
  197. let foldtext = '+'.indentOnly.'... ('.linecount.' More lines)'
  198. return foldtext
  199. endfunction
  200. function! ToggleMouse()
  201. if &mouse == 'a'
  202. set mouse=
  203. echo "Mouse usage disabled"
  204. else
  205. set mouse=a
  206. echo "Mouse usage enabled"
  207. endif
  208. endfunction
  209. function! ScreenMovement(movement)
  210. if &wrap
  211. return "g" . a:movement
  212. else
  213. return a:movement
  214. endif
  215. endfunction