vimrc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. """"""""
  2. "" Plugin Loading with Pathogen
  3. """""""""""""""""""""""""""""""""""""""""""""""""""
  4. call pathogen#infect()
  5. """"""""
  6. "" General Behaviours
  7. """""""""""""""""""""""""""""""""""""""""""""""""""
  8. set nocompatible "Don't have to try to be compatible with old vi
  9. set autoread "Read a file if it's changed from outside of vim
  10. set splitbelow "New splits appear below current window instead of above
  11. set ttyfast "Smooth movement
  12. " Enable filetype specific features
  13. filetype plugin on
  14. filetype indent on
  15. "if version >= 700
  16. " set mouse=a "mouse support for 7.x, but don't use this if we use screen
  17. " because it has no effect, and then just becomes annoying for copy/paste
  18. "endif
  19. " Source the vimrc file after saving it
  20. autocmd! bufwritepost .vimrc source $MYVIMRC
  21. " Remember last location in file
  22. " Only do this part when compiled with support for autocommands
  23. if has("autocmd")
  24. augroup redhat
  25. " In text files, always limit the width of text to 78 characters
  26. autocmd BufRead *.txt set tw=78
  27. " When editing a file, always jump to the last cursor position
  28. autocmd BufReadPost *
  29. \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  30. \ exe "normal! g'\"" |
  31. \ endif
  32. augroup END
  33. endif
  34. """"""""
  35. "" Formatting
  36. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  37. set tabstop=4 "actual tab press distance
  38. set shiftwidth=4 "for autoindent
  39. set softtabstop=4 " let backspace delete indent
  40. set expandtab "change to single spaces
  41. set autoindent "use last line to set next indent
  42. set smartindent "guess harder, based on C-like language
  43. set wrap lbr "wrap long lines of text
  44. set backspace=eol,start,indent "backspace over everything
  45. """"""""
  46. "" UI - Colours
  47. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  48. syntax on
  49. colorscheme desert
  50. hi Folded ctermfg=darkred "set colour for folded lines
  51. if version >= 730
  52. set colorcolumn=80
  53. endif
  54. """"""""
  55. "" UI - Numbering
  56. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  57. set number "show line numbers
  58. set ruler "show row,col count in status line
  59. set laststatus=2 "always show a status line
  60. if version >= 730
  61. set relativenumber "current line always 0 (requires 7.3 and up)
  62. endif
  63. """"""""
  64. "" UI - Code Folding
  65. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  66. set foldmethod=indent
  67. set foldlevel=5
  68. set foldtext=MyFoldText()
  69. function! MyFoldText()
  70. let line = getline(v:foldstart)
  71. let indent = indent(v:foldstart)
  72. let indentOnly = strpart(line, 0, indent-1)
  73. let linecount = v:foldend+1 - v:foldstart
  74. let plural = ""
  75. if linecount != 1
  76. let plural = "s"
  77. endif
  78. let foldtext = '+'.indentOnly.'... ('.linecount.' More lines)'
  79. return foldtext
  80. endfunction
  81. """"""""
  82. "" UI - Search
  83. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  84. set hlsearch "make searches highlighted
  85. set incsearch "vim will search as you type!
  86. set ignorecase "ignore case for searches
  87. set smartcase " well, unless a user puts in uppercase search characters
  88. set magic "enables wildcard searching
  89. """"""""
  90. "" Key Remaps and Shortcuts
  91. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  92. let mapleader = "," "Leader key lets you make more kinds of shortcuts!
  93. " More convenient escape
  94. imap ii <Esc>
  95. imap II <Esc>
  96. " Add extra lines up and down
  97. map <leader>j o<Esc>k
  98. map <leader>k O<Esc>j
  99. """"""""
  100. "" Key Remaps - Movement and Windows
  101. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  102. " Smart way to move btw. windows
  103. map <C-j> <C-W>j
  104. map <C-k> <C-W>k
  105. map <C-h> <C-W>h
  106. map <C-l> <C-W>l
  107. " window resizing
  108. noremap + <C-w>10+
  109. noremap - <C-w>10-
  110. " mapping to make movements operate on 1 screen line in wrap mode
  111. function! ScreenMovement(movement)
  112. if &wrap
  113. return "g" . a:movement
  114. else
  115. return a:movement
  116. endif
  117. endfunction
  118. onoremap <silent> <expr> j ScreenMovement("j")
  119. onoremap <silent> <expr> k ScreenMovement("k")
  120. onoremap <silent> <expr> 0 ScreenMovement("0")
  121. onoremap <silent> <expr> ^ ScreenMovement("^")
  122. onoremap <silent> <expr> $ ScreenMovement("$")
  123. nnoremap <silent> <expr> j ScreenMovement("j")
  124. nnoremap <silent> <expr> k ScreenMovement("k")
  125. nnoremap <silent> <expr> 0 ScreenMovement("0")
  126. nnoremap <silent> <expr> ^ ScreenMovement("^")