vimrc 4.9 KB

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