vimrc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. if 0 == argc()
  11. NERDTree
  12. end
  13. endfunction
  14. autocmd VimEnter * call StartUp()
  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 ttyfast "Smooth movement
  21. " Enable filetype specific features
  22. filetype plugin on
  23. filetype indent on
  24. "if version >= 700
  25. " set mouse=a "mouse support for 7.x, but don't use this if we use screen
  26. " because it has no effect, and then just becomes annoying for copy/paste
  27. "endif
  28. " Source the vimrc file after saving it
  29. autocmd! bufwritepost .vimrc source $MYVIMRC
  30. " Remember last location in file
  31. " Only do this part when compiled with support for autocommands
  32. if has("autocmd")
  33. augroup redhat
  34. " In text files, always limit the width of text to 78 characters
  35. autocmd BufRead *.txt set tw=78
  36. " When editing a file, always jump to the last cursor position
  37. autocmd BufReadPost *
  38. \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  39. \ exe "normal! g'\"" |
  40. \ endif
  41. augroup END
  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 laststatus=2 "always show a status line
  71. if version >= 730
  72. set relativenumber "current line always 0 (requires 7.3 and up)
  73. endif
  74. """"""""
  75. "" UI - Code Folding
  76. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  77. set foldmethod=indent
  78. set foldlevel=5
  79. set foldtext=MyFoldText()
  80. function! MyFoldText()
  81. let line = getline(v:foldstart)
  82. let indent = indent(v:foldstart)
  83. let indentOnly = strpart(line, 0, indent-1)
  84. let linecount = v:foldend+1 - v:foldstart
  85. let plural = ""
  86. if linecount != 1
  87. let plural = "s"
  88. endif
  89. let foldtext = '+'.indentOnly.'... ('.linecount.' More lines)'
  90. return foldtext
  91. endfunction
  92. """"""""
  93. "" UI - Search
  94. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  95. set hlsearch "make searches highlighted
  96. set incsearch "vim will search as you type!
  97. set ignorecase "ignore case for searches
  98. set smartcase " well, unless a user puts in uppercase search characters
  99. set magic "enables wildcard searching
  100. """"""""
  101. "" Key Remaps and Shortcuts
  102. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  103. let mapleader = "," "Leader key lets you make more kinds of shortcuts!
  104. " More convenient escape
  105. imap ii <Esc>
  106. imap II <Esc>
  107. " Add extra lines up and down
  108. map <leader>j o<Esc>k
  109. map <leader>k O<Esc>j
  110. """"""""
  111. "" Key Remaps - Movement and Windows
  112. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  113. " Smart way to move btw. windows
  114. map <C-j> <C-W>j
  115. map <C-k> <C-W>k
  116. map <C-h> <C-W>h
  117. map <C-l> <C-W>l
  118. " window resizing
  119. noremap + <C-w>10+
  120. noremap - <C-w>10-
  121. " mapping to make movements operate on 1 screen line in wrap mode
  122. function! ScreenMovement(movement)
  123. if &wrap
  124. return "g" . a:movement
  125. else
  126. return a:movement
  127. endif
  128. endfunction
  129. onoremap <silent> <expr> j ScreenMovement("j")
  130. onoremap <silent> <expr> k ScreenMovement("k")
  131. onoremap <silent> <expr> 0 ScreenMovement("0")
  132. onoremap <silent> <expr> ^ ScreenMovement("^")
  133. onoremap <silent> <expr> $ ScreenMovement("$")
  134. nnoremap <silent> <expr> j ScreenMovement("j")
  135. nnoremap <silent> <expr> k ScreenMovement("k")
  136. nnoremap <silent> <expr> 0 ScreenMovement("0")
  137. nnoremap <silent> <expr> ^ ScreenMovement("^")
  138. """"""""
  139. "" Plugin options
  140. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  141. " let g:NERDTreeQuitOnOpen = 1
  142. let g:SuperTabDefaultCompletionType = "context"