vimrc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 "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("^")