vimrc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. """"""""
  2. "" Plugin Loading with Pathogen
  3. """""""""""""""""""""""""""""""""""""""""""""""""""
  4. call pathogen#infect()
  5. """"""""
  6. "" Start Up
  7. """""""""""""""""""""""""""""""""""""""""""""""""""
  8. function! StartUp()
  9. if 0 == argc()
  10. NERDTree
  11. end
  12. endfunction
  13. autocmd VimEnter * call StartUp()
  14. """"""""
  15. "" General Behaviours
  16. """""""""""""""""""""""""""""""""""""""""""""""""""
  17. set nocompatible "Don't have to try to be compatible with old vi
  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 on
  58. set t_Co=256
  59. colorscheme desert
  60. hi Folded ctermfg=darkred "set colour for folded lines
  61. if version >= 730
  62. set colorcolumn=80
  63. endif
  64. """"""""
  65. "" UI - Numbering
  66. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  67. set number "show line numbers
  68. set ruler "show row,col count in status line
  69. set laststatus=2 "always show a status line
  70. if version >= 730
  71. set relativenumber "current line always 0 (requires 7.3 and up)
  72. endif
  73. """"""""
  74. "" UI - Code Folding
  75. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  76. set foldmethod=indent
  77. set foldlevel=5
  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. map <leader>j o<Esc>k
  108. map <leader>k O<Esc>j
  109. """"""""
  110. "" Key Remaps - Movement and Windows
  111. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  112. " Smart way to move btw. windows
  113. map <C-j> <C-W>j
  114. map <C-k> <C-W>k
  115. map <C-h> <C-W>h
  116. map <C-l> <C-W>l
  117. " window resizing
  118. noremap + <C-w>10+
  119. noremap - <C-w>10-
  120. " mapping to make movements operate on 1 screen line in wrap mode
  121. function! ScreenMovement(movement)
  122. if &wrap
  123. return "g" . a:movement
  124. else
  125. return a:movement
  126. endif
  127. endfunction
  128. onoremap <silent> <expr> j ScreenMovement("j")
  129. onoremap <silent> <expr> k ScreenMovement("k")
  130. onoremap <silent> <expr> 0 ScreenMovement("0")
  131. onoremap <silent> <expr> ^ ScreenMovement("^")
  132. onoremap <silent> <expr> $ ScreenMovement("$")
  133. nnoremap <silent> <expr> j ScreenMovement("j")
  134. nnoremap <silent> <expr> k ScreenMovement("k")
  135. nnoremap <silent> <expr> 0 ScreenMovement("0")
  136. nnoremap <silent> <expr> ^ ScreenMovement("^")
  137. """"""""
  138. "" Plugin options
  139. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  140. " let g:NERDTreeQuitOnOpen = 1
  141. let g:SuperTabDefaultCompletionType = "context"