vimrc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. "" Formatting
  45. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  46. set tabstop=4 "actual tab press distance
  47. set shiftwidth=4 "for autoindent
  48. set softtabstop=4 " let backspace delete indent
  49. set expandtab "change to single spaces
  50. set autoindent "use last line to set next indent
  51. set smartindent "guess harder, based on C-like language
  52. set wrap lbr "wrap long lines of text
  53. set backspace=eol,start,indent "backspace over everything
  54. """"""""
  55. "" UI - Colours
  56. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  57. syntax enable
  58. set t_Co=16
  59. set background=dark
  60. colorscheme solarized
  61. hi Folded ctermfg=darkred "set colour for folded lines
  62. if version >= 730
  63. set colorcolumn=80
  64. endif
  65. """"""""
  66. "" UI - Numbering
  67. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  68. set number "show line numbers
  69. set ruler "show row,col count in status line
  70. set rulerformat=%55(%{strftime('%a\ %b\ %e\ %I:%M\ %p')}\ %5l,%-6(%c%V%)\ %P%)
  71. nnoremap <silent> <expr> $ ScreenMovement("$")
  72. set laststatus=2 "always show a status line
  73. if version >= 730
  74. set relativenumber "current line always 0 (requires 7.3 and up)
  75. endif
  76. """"""""
  77. "" UI - Code Folding
  78. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  79. set foldmethod=indent
  80. set foldlevel=5
  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. map <leader>j o<Esc>k
  111. map <leader>k O<Esc>j
  112. """"""""
  113. "" Key Remaps - Movement and Windows
  114. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  115. " Smart way to move btw. windows
  116. map <C-j> <C-W>j
  117. map <C-k> <C-W>k
  118. map <C-h> <C-W>h
  119. map <C-l> <C-W>l
  120. " window resizing
  121. noremap + <C-w>10+
  122. noremap - <C-w>10-
  123. " mapping to make movements operate on 1 screen line in wrap mode
  124. function! ScreenMovement(movement)
  125. if &wrap
  126. return "g" . a:movement
  127. else
  128. return a:movement
  129. endif
  130. endfunction
  131. onoremap <silent> <expr> j ScreenMovement("j")
  132. onoremap <silent> <expr> k ScreenMovement("k")
  133. onoremap <silent> <expr> 0 ScreenMovement("0")
  134. onoremap <silent> <expr> ^ ScreenMovement("^")
  135. onoremap <silent> <expr> $ ScreenMovement("$")
  136. nnoremap <silent> <expr> j ScreenMovement("j")
  137. nnoremap <silent> <expr> k ScreenMovement("k")
  138. nnoremap <silent> <expr> 0 ScreenMovement("0")
  139. nnoremap <silent> <expr> ^ ScreenMovement("^")
  140. """"""""
  141. "" Plugin options
  142. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  143. " let g:NERDTreeQuitOnOpen = 1
  144. let g:SuperTabDefaultCompletionType = "context"