Advertisement
Guest User

Untitled

a guest
Oct 1st, 2009
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.96 KB | None | 0 0
  1. " Basic Settings {{{1
  2.  
  3. " set nocompatible " This should be set automatically upon detection of .vimrc
  4.  
  5. set background=dark
  6. color hhdgray
  7.  
  8. " Activate auto filetype detection
  9. filetype plugin indent on
  10. syntax enable
  11.  
  12. set tags=./tags,tags,~/tags
  13.  
  14. set ignorecase " Don't care about case...
  15. set smartcase " ... unless the query contains upper case characters
  16. set nowrap " No fake carriage returns
  17. set showcmd " Show command in statusline as it's being typed
  18. set showmatch " Jump to matching bracket
  19. set ruler " Show row,col %progress through file
  20. set laststatus=2 " Always show filename (2 is always)
  21. set hidden " Let us move between buffers without writing them. Don't :q! or :qa! frivolously!
  22. set softtabstop=4 " Vim sees 4 spaces as a tab
  23. set shiftwidth=4 " < and > uses spaces
  24. set expandtab " Tabs mutate into spaces
  25. set foldmethod=indent " Default folding
  26. set backspace=indent,eol,start " Make backspace work like other editors.
  27. " set tabstop=4 " 4-space indents
  28. " set smarttab " <TAB> width determined by shiftwidth instead of tabstop.
  29.  
  30. autocmd BufNewFile,BufRead /*apache* setfiletype apache
  31. autocmd BufNewFile,BufRead /*lighttpd*.conf setfiletype lighty
  32. autocmd BufNewFile,BufRead {.,_}vimrc set foldmethod=marker
  33.  
  34. " Nicer highlighting of completion popup
  35. highlight Pmenu guibg=brown gui=bold
  36.  
  37. function! CHANGE_CURR_DIR()
  38. let _dir = expand("%:p:h")
  39. exec "cd " . _dir
  40. unlet _dir
  41. endfunction
  42. autocmd BufEnter * call CHANGE_CURR_DIR()
  43.  
  44. " }}}1
  45.  
  46. " Backups & .vimrc Editing (Filesystem-dependent) {{{1
  47.  
  48. if has('win32')
  49. " Windows filesystem
  50. set directory=C:\VimBackups
  51. set backupdir=C:\VimBackups
  52. if($MYVIMRC == "") " Pre-Vim 7
  53. let $MYVIMRC = $VIM."\_vimrc"
  54. endif
  55. else
  56. " Linux filesystem
  57. set directory=$HOME/.backups//
  58. set backupdir=$HOME/.backups//
  59. if($MYVIMRC == "") " Pre-Vim 7
  60. let $MYVIMRC = $HOME."/.vimrc"
  61. endif
  62. endif
  63.  
  64. " }}}1
  65.  
  66. " Basic Key Mappings {{{1
  67.  
  68. " Quit like in bash
  69. nnoremap <C-d> :q<CR>
  70.  
  71. " Switch to recent buffer
  72. nnoremap K :b#<CR>
  73.  
  74. " Easy saving
  75. nnoremap <C-u> :w<CR>
  76. inoremap <C-u> <ESC>:w<CR>
  77. vnoremap <C-u> <ESC>:w<CR>
  78.  
  79. " Create a new HTML document.
  80. nnoremap ,html :set ft=html<CR>i<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><CR><html lang="en"><CR><head><CR><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><CR><title></title><CR><link rel="stylesheet" type="text/css" href="style.css"><CR><script type="text/javascript" src="script.js"></script><CR></head><CR><body><CR></body><CR></html><ESC>?title<CR>2hi
  81.  
  82. " Bind for easy pasting
  83. set pastetoggle=<F12>
  84.  
  85. " Editing vimrc
  86. nnoremap ,v :source $MYVIMRC<CR>
  87. nnoremap ,e :edit $MYVIMRC<CR>
  88.  
  89. " Quickly change search hilighting
  90. nnoremap ; :set invhlsearch<CR>
  91.  
  92. " Change indent continuously
  93. vmap < <gv
  94. vmap > >gv
  95.  
  96. " Movement between split windows
  97. nnoremap <C-k> <C-w>k
  98. nnoremap <C-j> <C-w>j
  99. nnoremap <C-l> <C-w>l
  100. nnoremap <C-h> <C-w>h
  101.  
  102. " Fold everything but the parent class in a Ruby file
  103. nnoremap z, :set foldlevel=1<CR>
  104.  
  105. " Tabs
  106. if exists( '*tabpagenr' ) && tabpagenr('$') != 1
  107. nnoremap ,V :tabdo source $MYVIMRC<CR>
  108. nnoremap tn :tabnew<CR>
  109. nnoremap tw :tabclose<CR>
  110. else
  111. nnoremap ,V :bufdo source $MYVIMRC<CR>
  112. endif
  113.  
  114. " Turns visually selected camelCase into camel_case
  115. vnoremap ,case :s/\v\C(([a-z]+)([A-Z]))/\2_\l\3/g<CR>
  116.  
  117. " Session mappings
  118. nnoremap ,s :mksession! Session.vim<CR>
  119. nnoremap ,q :bufdo :w<CR>:mksession! Session.vim<CR>:qall<CR>
  120.  
  121. " Instant Python constructors
  122. nnoremap ,c 0f(3wyt)o<ESC>pV:s/\([a-z_]\+\),\?/self.\1 = \1<C-v><CR>/g<CR>ddV?def<CR>j
  123.  
  124. " Diff Mode
  125. nnoremap <silent> ,j :if &diff \| exec 'normal ]czz' \| endif<CR>
  126. nnoremap <silent> ,k :if &diff \| exec 'normal [czz' \| endif<CR>
  127. nnoremap <silent> ,p :if &diff \| exec 'normal dp' \| endif<CR>
  128. nnoremap <silent> ,o :if &diff \| exec 'normal do' \| endif<CR>
  129. nnoremap <silent> ZD :if &diff \| exec ':qall' \| endif<CR>
  130.  
  131. " }}}1
  132.  
  133. " Custom Functions {{{1
  134. " Custom Function Key Mapping {{{2
  135.  
  136. " Movement between tabs OR buffers
  137. nnoremap L :call MyNext()<CR>
  138. nnoremap H :call MyPrev()<CR>
  139.  
  140. " Resizing split windows
  141. nnoremap ,w :call SwapSplitResizeShortcuts()<CR>
  142.  
  143. " Easy changing for scrolloff
  144. nnoremap ,b :call SwapBrowseMode()<CR>
  145.  
  146. " Wraps visual selection in an HTML tag
  147. vnoremap ,w <ESC>:call VisualHTMLTagWrap()<CR>
  148.  
  149. " For Notepad-like handling of wrapped lines
  150. nnoremap ,n :call NotepadLineToggle()<CR>
  151.  
  152. " Quick function prototype
  153. nnoremap ,f :call QuickFunctionPrototype()<CR>
  154.  
  155. " }}}2
  156.  
  157. " Custom Function Defaults {{{2
  158.  
  159. " Set defaults in an !exists clause so we don't clobber existing setting
  160. " if .vimrc is being sourced during an editing session (instead of on open).
  161. if !exists( 'g:resizeshortcuts' )
  162. let g:resizeshortcuts = 'horizontal'
  163. nnoremap _ <C-w>-
  164. nnoremap + <C-w>+
  165. endif
  166.  
  167. if !exists( 'g:browsemode' )
  168. let g:browsemode = 'nobrowse'
  169. set sidescrolloff=0
  170. set scrolloff=0
  171. endif
  172.  
  173. if !exists( 'g:notepadlines' )
  174. let g:notepadlines = 'false'
  175. endif
  176.  
  177. " }}}2
  178.  
  179. " Custom Function Definitions {{{2
  180. " MyNext() and MyPrev(): Movement between tabs OR buffers {{{3
  181. function! MyNext()
  182. if exists( '*tabpagenr' ) && tabpagenr('$') != 1
  183. " Tab support && tabs open
  184. normal gt
  185. else
  186. " No tab support, or no tabs open
  187. execute ":bnext"
  188. endif
  189. endfunction
  190. function! MyPrev()
  191. if exists( '*tabpagenr' ) && tabpagenr('$') != '1'
  192. " Tab support && tabs open
  193. normal gT
  194. else
  195. " No tab support, or no tabs open
  196. execute ":bprev"
  197. endif
  198. endfunction
  199. " }}}3
  200.  
  201. " SwapSplitResizeShortcuts(): Resizing split windows {{{3
  202. function! SwapSplitResizeShortcuts()
  203. if g:resizeshortcuts == 'horizontal'
  204. let g:resizeshortcuts = 'vertical'
  205. nnoremap _ <C-w><
  206. nnoremap + <C-w>>
  207. echo "Vertical split-resizing shortcut mode."
  208. else
  209. let g:resizeshortcuts = 'horizontal'
  210. nnoremap _ <C-w>-
  211. nnoremap + <C-w>+
  212. echo "Horizontal split-resizing shortcut mode."
  213. endif
  214. endfunction
  215. " }}}3
  216.  
  217. " SwapBrowseMode(): Easy changing for scrolloff {{{3
  218. function! SwapBrowseMode()
  219. if g:browsemode == 'nobrowse'
  220. let g:browsemode = 'browse'
  221. set sidescrolloff=999
  222. set scrolloff=999
  223. echo "Browse mode enabled."
  224. else
  225. let g:browsemode = 'nobrowse'
  226. set sidescrolloff=0
  227. set scrolloff=0
  228. echo "Browse mode disabled."
  229. endif
  230. endfunction
  231. " }}}3
  232.  
  233. " VisualHTMLTagWrap(): Wraps visual selection in an HTML tag {{{3
  234. function! VisualHTMLTagWrap()
  235. let html_tag = input( "html_tag to wrap block: ")
  236. let jumpright = 2 + strlen( html_tag )
  237. normal `<
  238. let init_line = line( "." )
  239. exe "normal i<".html_tag.">"
  240. normal `>
  241. let end_line = line( "." )
  242. " Don't jump if we're on a new line
  243. if( init_line == end_line )
  244. " Jump right to compensate for the characters we've added
  245. exe "normal ".jumpright."l"
  246. endif
  247. exe "normal a</".html_tag.">"
  248. endfunction
  249. " }}}3
  250.  
  251. " QuickFunctionPrototype(): Quickly generate a function prototype. {{{3
  252. function! QuickFunctionPrototype()
  253. let function_name = input( "function name: ")
  254. if &ft == "php"
  255. " The extra a\<BS> startinsert! is because this function drops
  256. " out of insert mode when it finishes running, and startinsert
  257. " ignores auto-indenting.
  258. exe "normal ofunction ".function_name."(){\<CR>}\<ESC>Oa\<BS>"
  259. startinsert!
  260. else
  261. echo "Filetype not supported."
  262. endif
  263. endfunction
  264. " }}}3
  265.  
  266. " NotepadLineToggle(): For Notepad-like handling of wrapped lines {{{3
  267. function! NotepadLineToggle()
  268. if g:notepadlines == 'false'
  269. nnoremap j gj
  270. nnoremap k gk
  271. let g:notepadlines = 'true'
  272. set wrap
  273. echo "Notepad wrapped lines enabled."
  274. else
  275. unmap j
  276. unmap k
  277. let g:notepadlines = 'false'
  278. set nowrap
  279. echo "Notepad wrapped lines disabled."
  280. endif
  281. endfunction
  282. " }}}3
  283. " }}}2
  284. " }}}1
  285.  
  286. " Local Settings {{{1
  287.  
  288. if filereadable($HOME."/.local/vim/.vimrc")
  289. source $HOME/.local/vim/.vimrc
  290. endif
  291.  
  292. " }}}1
  293.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement