vimrc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. set nocompatible "Don't have to try to be compatible with old vi
  2. """"""""
  3. "" Plugin Loading with Pathogen
  4. """""""""""""""""""""""""""""""""""""""""""""""""""
  5. call pathogen#infect()
  6. """"""""
  7. "" Start Up
  8. """""""""""""""""""""""""""""""""""""""""""""""""""
  9. function! StartUp()
  10. " Stuff in here will be called by autocmd below
  11. if 0 == argc()
  12. NERDTree
  13. end
  14. endfunction
  15. """"""""
  16. "" General Behaviours
  17. """""""""""""""""""""""""""""""""""""""""""""""""""
  18. set autoread "Read a file if it's changed from outside of vim
  19. set splitbelow "New splits appear below current window instead of above
  20. set splitright "New splits appear right of current window
  21. set ttyfast "Smooth movement
  22. " Persistent undo
  23. set undofile
  24. set undodir=~/.vimundo
  25. "if version >= 700
  26. " set mouse=a "mouse support for 7.x, but don't use this if we use screen
  27. " because it has no effect, and then just becomes annoying for copy/paste
  28. "endif
  29. if has("autocmd")
  30. " Enable filetype specific features
  31. filetype plugin indent on
  32. " Clear existing autocmd
  33. autocmd!
  34. " When editing a file, always jump to the last cursor position
  35. autocmd BufReadPost *
  36. \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  37. \ exe "normal! g'\"" |
  38. \ endif
  39. " Source the vimrc file after saving it
  40. autocmd bufwritepost .vimrc source $MYVIMRC
  41. " so far, this startup just opens NERDTree when there are no arguments
  42. autocmd VimEnter * call StartUp()
  43. else
  44. set autoindent on
  45. endif
  46. """"""""
  47. "" Tabs and Text Formatting
  48. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  49. set expandtab " change to single spaces
  50. set tabstop=2 " actual tab press distance
  51. set shiftround " indent to nearest tabstops
  52. set shiftwidth=2 " amount to indent with > and <
  53. set smarttab " backspace tabs where appropriate even if spaces
  54. set softtabstop=2 " let backspace delete indent
  55. set wrap lbr " wrap long lines of text
  56. set backspace=eol,start,indent "backspace over everything
  57. set textwidth=80
  58. """"""""
  59. "" UI - Colours
  60. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  61. syntax enable
  62. set t_Co=16
  63. set background=dark
  64. colorscheme solarized
  65. hi Folded ctermfg=darkred "set colour for folded lines
  66. set colorcolumn=+1
  67. """"""""
  68. "" UI - Numbering
  69. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  70. set number "show line numbers
  71. set ruler "show row,col count in status line
  72. set rulerformat=%55(%{strftime('%a\ %b\ %e\ %I:%M\ %p')}\ %5l,%-6(%c%V%)\ %P%)
  73. nnoremap <silent> <expr> $ ScreenMovement("$")
  74. set laststatus=2 "always show a status line
  75. "set relativenumber "current line always 0 (requires 7.3 and up)
  76. """"""""
  77. "" UI - Code Folding
  78. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  79. set foldmethod=indent
  80. set foldlevel=7
  81. set foldtext=MyFoldText()
  82. function! MyFoldText()
  83. let line = getline(v:foldstart)
  84. let indent = indent(v:foldstart)
  85. let indentOnly = strpart(line, 0, indent-1)
  86. let linecount = v:foldend+1 - v:foldstart
  87. let plural = ""
  88. if linecount != 1
  89. let plural = "s"
  90. endif
  91. let foldtext = '+'.indentOnly.'... ('.linecount.' More lines)'
  92. return foldtext
  93. endfunction
  94. """"""""
  95. "" UI - Search
  96. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  97. set hlsearch " make searches highlighted
  98. set incsearch " vim will search as you type!
  99. set ignorecase " ignore case for searches
  100. set smartcase " well, unless a user puts in uppercase search characters
  101. set magic " enables wildcard searching
  102. """"""""
  103. "" Key Remaps and Shortcuts
  104. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  105. let mapleader = "," "Leader key lets you make more kinds of shortcuts!
  106. " More convenient escape
  107. imap ii <Esc>
  108. imap II <Esc>
  109. " Add extra lines up and down
  110. nmap <leader>j o<Esc>k
  111. nmap <leader>k O<Esc>j
  112. " Toggle numbering
  113. nmap <silent> <leader>n :set number!<CR>
  114. " Toggle NERDTree instead of the normal dir browser
  115. nnoremap <silent> <leader>d :NERDTreeToggle<CR>
  116. " Toggle Commenting out lines with NERDCommenter
  117. nnoremap <silent> <leader>, :call NERDComment(0, "toggle")<CR>
  118. vnoremap <silent> <leader>, <ESC>:call NERDComment(1, "toggle")<CR>
  119. " Edit .vimrc
  120. map <leader>v :e $MYVIMRC<CR>
  121. """"""""
  122. "" Key Remaps - Movement and Windows
  123. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  124. " jump to beginning and end of line easier
  125. nmap H ^
  126. nmap L $
  127. " Smart way to move btw. windows
  128. map <C-j> <C-W>j
  129. map <C-k> <C-W>k
  130. map <C-h> <C-W>h
  131. map <C-l> <C-W>l
  132. " window resizing
  133. noremap + <C-w>10+
  134. noremap - <C-w>10-
  135. " mapping to make movements operate on 1 screen line in wrap mode
  136. function! ScreenMovement(movement)
  137. if &wrap
  138. return "g" . a:movement
  139. else
  140. return a:movement
  141. endif
  142. endfunction
  143. onoremap <silent> <expr> j ScreenMovement("j")
  144. onoremap <silent> <expr> k ScreenMovement("k")
  145. onoremap <silent> <expr> 0 ScreenMovement("0")
  146. onoremap <silent> <expr> ^ ScreenMovement("^")
  147. onoremap <silent> <expr> $ ScreenMovement("$")
  148. nnoremap <silent> <expr> j ScreenMovement("j")
  149. nnoremap <silent> <expr> k ScreenMovement("k")
  150. nnoremap <silent> <expr> 0 ScreenMovement("0")
  151. nnoremap <silent> <expr> ^ ScreenMovement("^")
  152. """"""""
  153. "" Plugin options
  154. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  155. " let g:NERDTreeQuitOnOpen = 1
  156. " let g:SuperTabDefaultCompletionType = "context"