vimrc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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
  17. endif
  18. " Source the vimrc file after saving it
  19. autocmd! bufwritepost .vimrc source $MYVIMRC
  20. " Remember last location in file
  21. " Only do this part when compiled with support for autocommands
  22. if has("autocmd")
  23. augroup redhat
  24. " In text files, always limit the width of text to 78 characters
  25. autocmd BufRead *.txt set tw=78
  26. " When editing a file, always jump to the last cursor position
  27. autocmd BufReadPost *
  28. \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  29. \ exe "normal! g'\"" |
  30. \ endif
  31. augroup END
  32. endif
  33. """"""""
  34. "" Formatting
  35. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  36. set tabstop=4 "actual tab press distance
  37. set shiftwidth=4 "for autoindent
  38. set softtabstop=4 " let backspace delete indent
  39. set expandtab "change to single spaces
  40. set autoindent "use last line to set next indent
  41. set smartindent "guess harder, based on C-like language
  42. set wrap lbr "wrap long lines of text
  43. set backspace=eol,start,indent "backspace over everything
  44. """"""""
  45. "" UI - Colours
  46. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  47. syntax on
  48. colorscheme desert
  49. hi Folded ctermfg=darkred "set colour for folded lines
  50. if version >= 730
  51. set colorcolumn=80
  52. endif
  53. """"""""
  54. "" UI - Numbering
  55. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  56. set number "show line numbers
  57. set ruler "show row,col count in status line
  58. set laststatus=2 "always show a status line
  59. if version >= 730
  60. set relativenumber "current line always 0 (requires 7.3 and up)
  61. endif
  62. """"""""
  63. "" UI - Code Folding
  64. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  65. "set foldmethod=indent
  66. "set foldlevel=5
  67. "set foldtext=MyFoldText()
  68. "
  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
  87. set magic "enables wildcard searching
  88. """"""""
  89. "" Key Remaps and Shortcuts
  90. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  91. let mapleader = "," "Leader key lets you make more kinds of shortcuts!
  92. " More convenient escape
  93. imap ii <Esc>
  94. imap II <Esc>
  95. " Add extra lines up and down
  96. map <leader>j o<Esc>k
  97. map <leader>k O<Esc>j
  98. """"""""
  99. "" Key Remaps - Movement and Windows
  100. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  101. " Smart way to move btw. windows
  102. map <C-j> <C-W>j
  103. map <C-k> <C-W>k
  104. map <C-h> <C-W>h
  105. map <C-l> <C-W>l
  106. " window resizing
  107. noremap + <C-w>10+
  108. noremap - <C-w>10-
  109. " mapping to make movements operate on 1 screen line in wrap mode
  110. function! ScreenMovement(movement)
  111. if &wrap
  112. return "g" . a:movement
  113. else
  114. return a:movement
  115. endif
  116. endfunction
  117. onoremap <silent> <expr> j ScreenMovement("j")
  118. onoremap <silent> <expr> k ScreenMovement("k")
  119. onoremap <silent> <expr> 0 ScreenMovement("0")
  120. onoremap <silent> <expr> ^ ScreenMovement("^")
  121. onoremap <silent> <expr> $ ScreenMovement("$")
  122. nnoremap <silent> <expr> j ScreenMovement("j")
  123. nnoremap <silent> <expr> k ScreenMovement("k")
  124. nnoremap <silent> <expr> 0 ScreenMovement("0")
  125. nnoremap <silent> <expr> ^ ScreenMovement("^")