Advertisement
Guest User

OsoGato

a guest
Sep 4th, 2009
922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.30 KB | None | 0 0
  1. " Vim 7.2 vimrc
  2. " Section: options {{{1
  3. set nocompatible " use vim settings instead of vi settings
  4. set mouse=a " enable mouse in all modes
  5. set noinsertmode " enforce in case of EZ-mode
  6. set shellcmdflag=-lc " use login shell (read .profile)
  7. set noexpandtab " whether to expand tabs into spaces
  8. set tabstop=4 " number of spaces for tab character
  9. set shiftwidth=4 " number of spaces for autoindent and soft tab stops
  10. set visualbell t_vb= " disable bell
  11. set scrolloff=3 " minimum lines of buffer when vertically scrolling
  12. set sidescroll=1 " redraw with every column when side scrolling
  13. set winminheight=0 " really minimize split windows
  14. set winminwidth=0 " really minimize vertically split windows
  15. set cmdwinheight=12 " set command-line window height
  16. set cmdheight=1 " number of command lines
  17. set wildmenu " enhanced command-line completion menu
  18. set wildcharm=<C-Z> " character for command-line completion in mappings
  19. set wildignore+=*.o " files to ignore for filename completion
  20. set wildignore+=*.class
  21. set wildignore+=*.pyc
  22. set showcmd " display incomplete commands
  23. set ruler " show the cursor position at all times
  24. set number " show line numbers by default
  25. set numberwidth=1 " only use as much space as needed for line numbers
  26. set shortmess=atToOI " abbreviate file messages
  27. set timeoutlen=666 " milliseconds before mapped key sequences time out
  28. set updatetime=1000 " interval for CursorHold updates and swap file writes
  29. set listchars=tab:>-,precedes:<,extends:>
  30. " display characters for tabs and extended lines
  31. set nobackup " do not keep a backup file
  32. set history=1000 " lines of command line history to keep
  33. set viminfo='50,s100,h " settings for vim cache
  34. set sessionoptions=curdir,folds,tabpages,winsize,localoptions
  35. " what to save with mksession
  36. set incsearch " do incremental searching
  37. set ignorecase " ignore case for search patterns
  38. " (override with \C anywhere in a search pattern)
  39. set smartcase " don't ignore case for patterns with uppercase chars
  40. set hlsearch " highlight search pattern matches
  41. set nowrap " don't wrap lines by default
  42. set linebreak " don't break mid-word when wrapping
  43. set whichwrap=b,<,>,[,] " move freely between lines
  44. set formatoptions+=n " recognize numbered lists when formatting
  45. set backspace=2 " allow backspacing over everything in insert mode
  46. set virtualedit=block " allow virtual selection in blockwise visual mode
  47. set complete-=i " don't scan included files
  48. set completeopt+=longest
  49. " complete to the longest common match in insert mode
  50. set cpoptions+=> " put a line break before appending to a register
  51. set diffopt+=iwhite " ignore whitespace in diff mode
  52. set foldmethod=indent " define folds automatically based on indent level
  53.  
  54. " Section: gui options {{{1
  55. if has("gui_running")
  56. set mousemodel=popup " use popup menu when right-clicking
  57. set guicursor=a:blinkon0 " disable cursor blinking
  58. set guioptions-=m " disable menu bar and toolbar
  59. set guioptions-=T
  60. set guioptions+=c " use console dialogs
  61.  
  62. if hostname() ==# "perro"
  63. set guioptions-=e " disable gui tabs
  64. set guioptions-=L " disable left scrollbar
  65. else
  66. set cursorline " enable current line highlighting
  67. endif
  68.  
  69. function! <SID>SetGUIFont(font) " {{{
  70. if has("gui_win32") || has("gui_mac")
  71. let sep = ':h'
  72. else
  73. let sep = ' '
  74. endif
  75. exec 'set guifont='.escape(a:font[0].sep.string(a:font[1]), ' ')
  76. endfunction " }}}
  77.  
  78. " display font (:set guifont=* to select interactively)
  79. if has("gui_win32")
  80. let g:font_select = [ ['Consolas', 9.5], ['DejaVu Sans Mono', 8] ]
  81. else
  82. let g:font_select = [ ['DejaVu Sans Mono', 9], ['Consolas', 10.5] ]
  83. endif
  84. let g:font_index = 0
  85. call <SID>SetGUIFont(g:font_select[g:font_index])
  86.  
  87. " pop-up balloon evaluation
  88. function! MyBalloonEval() " {{{
  89. let beval = <SID>PlugBalloonEval()
  90. if beval != '' | return beval | endif
  91. " tooltips for spelling suggestions and folds
  92. let size = 6
  93. let lines = []
  94. let foldStart = foldclosed(v:beval_lnum)
  95. let foldEnd = foldclosedend(v:beval_lnum)
  96. if foldStart < 0
  97. " try to find misspelling
  98. let lines = spellsuggest(spellbadword(v:beval_text)[0], size, 0)
  99. else
  100. let numLines = foldEnd - foldStart + 1
  101. " if too many lines in fold, show only first and last 'size' lines
  102. if numLines > size*2
  103. let lines = getline(foldStart, foldStart + (size-1))
  104. let lines += [ "+----- " . (numLines - size*2) . " lines -----" ]
  105. let lines += getline(foldEnd - (size-1), foldEnd)
  106. else
  107. let lines = getline(foldStart, foldEnd)
  108. endif
  109. endif
  110. return join(lines, has("balloon_multiline") ? "\n" : " ")
  111. endfunction " }}}
  112. set balloonexpr=MyBalloonEval()
  113. set balloondelay=250
  114. set ballooneval
  115. endif
  116.  
  117. " Section: terminal options {{{1
  118. if !has("gui_running")
  119. set ttimeoutlen=50 " timeout for terminal keycodes (in ms)
  120. " emenu access
  121. source $VIMRUNTIME/menu.vim
  122.  
  123. " keycodes {{{
  124. if &term =~ 'xterm'
  125. " unset vim keycodes
  126. set <Help>=
  127. set <Undo>=
  128. " associate terminal keycodes with vim keycodes
  129. exec "set <xF1>=\eO1;*P"
  130. exec "set <xF2>=\eO1;*Q"
  131. exec "set <xF3>=\eO1;*R"
  132. exec "set <xF4>=\eO1;*S"
  133. exec "set <F13>=\e[25;*~"
  134. exec "set <F14>=\e[26;*~"
  135. endif
  136.  
  137. " map <C-Space>
  138. map <Nul> <C-Space>
  139. map! <Nul> <C-Space>
  140.  
  141. " map terminal keycodes if no vim keycodes are available
  142. " (only needed for keycodes longer than a single keystroke)
  143. " makes use of unused vim keycodes <[S-]F15> to <[S-]F37>.
  144. let s:i = 0
  145.  
  146. " Meta sends <Esc> prefix
  147. " let s:keys = []
  148. " let s:c = char2nr('a')
  149. " for s:n in range(25)
  150. " call add(s:keys, nr2char(s:c+s:n))
  151. " endfor
  152. " only catch used Meta combos to prevent breaking macros containing
  153. " <Esc> followed by a mapped character
  154. let s:keys = [ 'a', 'x', 'c', 'v', 'h', 'j', 'k', 'l', 'p', 'n',
  155. \ 'b', 'f', 'd', 'r', 'y', '/', '?',
  156. \ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ]
  157. for s:k in range(len(s:keys))
  158. if s:i == 46 | break | endif
  159. exec "set <".(s:i/23==0 ? '' : 'S-')."F".(15+s:i%23)."> =\e".s:keys[s:k]
  160. exec "map <".(s:i/23==0 ? '' : 'S-')."F".(15+s:i%23)."> <M-".s:keys[s:k].">"
  161. exec "map! <".(s:i/23==0 ? '' : 'S-')."F".(15+s:i%23)."> <M-".s:keys[s:k].">"
  162. let s:i += 1
  163. endfor
  164. " }}}
  165. endif
  166.  
  167. " Section: colors {{{1
  168. if has("gui_running") || &t_Co > 2
  169. " enable syntax highlighting
  170. syntax on
  171.  
  172. function! <SID>SetColorScheme(color) " {{{
  173. set background=dark
  174. try
  175. exec "colorscheme" a:color
  176. catch
  177. return
  178. endtry
  179. " custom highlighting
  180. if g:colors_name == 'desert256'
  181. hi Normal ctermbg=234 guibg=#1c1c1c
  182. hi Cursor guifg=#222222
  183. hi LineNr ctermbg=233 guibg=#121212
  184. hi! link NonText LineNr
  185. hi SpecialKey ctermfg=240 ctermbg=235 guifg=#585858 guibg=#262626
  186. hi CursorLine cterm=NONE ctermbg=236 guibg=#303030
  187. hi! link CursorColumn CursorLine
  188. hi Search ctermfg=darkcyan ctermbg=18 guifg=#87ceeb guibg=#000087
  189. elseif g:colors_name == 'zenburn'
  190. hi Normal ctermbg=237 guibg=#3a3a38
  191. hi Cursor guifg=#081220 guibg=#ecee90 gui=NONE
  192. hi MatchParen guifg=#ecee90 guibg=#081220 gui=bold
  193. hi Statement gui=bold
  194. hi Todo ctermfg=240 ctermbg=Yellow guifg=#585858 guibg=Yellow
  195. hi! link NonText LineNr
  196. hi SpecialKey ctermfg=241 ctermbg=237 guifg=#626262 guibg=#363634
  197. hi CursorLine cterm=NONE gui=NONE
  198. hi! link CursorColumn CursorLine
  199. hi Search ctermbg=22 guifg=#ecee90 guibg=#105f00
  200. endif
  201. " highlighting for ColumnMarker
  202. hi RightMargin ctermbg=239 guibg=#4e4e4e
  203. endfunction " }}}
  204.  
  205. " hack - assume xterm has 256 colors
  206. if &term =~ 'xterm' && &t_Co > 2 | set t_Co=256 | endif
  207.  
  208. " color schemes from ~/.vim/colors
  209. let g:colors_select = [ 'wombat256', 'zenburn', 'desert256' ]
  210.  
  211. " set the default color scheme
  212. call <SID>SetColorScheme(g:colors_select[0])
  213. endif
  214.  
  215. " Section: autocommands {{{1
  216. if !has("autocmd")
  217. " always set autoindenting on
  218. set autoindent
  219. else
  220. " enable file type detection
  221. " use the default filetype settings, so that mail gets 'tw' set to 72,
  222. " 'cindent' is on in C files, etc
  223. " also load indent files for language-dependent indenting
  224. filetype plugin indent on
  225.  
  226. " default group
  227. augroup vimrc
  228. au!
  229. " restore cursor position, except when the position is invalid or
  230. " when inside an event handler (when dropping a file on gvim)
  231. au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
  232.  
  233. " don't auto-split lines
  234. au BufReadPost * set textwidth=0
  235. " open all folds
  236. au BufReadPost * normal! zR
  237.  
  238. " enable soft tab stops
  239. au BufWinEnter * let &softtabstop=&shiftwidth
  240.  
  241. " reading Word documents
  242. au BufReadPre *.doc set readonly
  243. au BufReadPost *.doc %! antiword "%"
  244. augroup END
  245.  
  246. " automatically enter hex mode and handle file writes properly
  247. " see vim -b
  248. augroup Binary
  249. au!
  250. au BufReadPre *.bin,*.hex setlocal binary
  251. au BufReadPost * if &binary | Hexmode | endif
  252. au BufWritePre *
  253. \ if exists("b:edit_hex") && b:edit_hex && &binary |
  254. \ let ro_save = &ro | set noreadonly |
  255. \ let ma_save = &ma | set modifiable |
  256. \ exec '%!xxd -r' |
  257. \ let &ro = ro_save | let &ma = ma_save |
  258. \ unlet ro_save | unlet ma_save |
  259. \ endif
  260. au BufWritePost *
  261. \ if exists("b:edit_hex") && b:edit_hex && &binary |
  262. \ let ro_save = &ro | set noreadonly |
  263. \ let ma_save = &ma | set modifiable |
  264. \ exec '%!xxd' |
  265. \ exe "set nomod" |
  266. \ let &ro = ro_save | let &ma = ma_save |
  267. \ unlet ro_save | unlet ma_save |
  268. \ endif
  269. augroup END
  270. endif
  271.  
  272. " Section: utility functions {{{1
  273. " return text with all instances of 'pat' removed
  274. function! StripFrom(text, pat)
  275. return substitute(a:text, a:pat, '', 'g')
  276. endfunction
  277.  
  278. " return a new list with duplicate items removed
  279. function! RemoveDuplicates(list)
  280. let uniq = []
  281. for i in range(len(a:list))
  282. if index(uniq, a:list[i]) == -1
  283. call add(uniq, a:list[i])
  284. endif
  285. endfor
  286. return uniq
  287. endfunction
  288.  
  289. " return most recently selected text
  290. function! <SID>GetSelection()
  291. if has("x11")
  292. return @*
  293. else
  294. exec 'normal `<'.visualmode().'`>"zy'
  295. return @z
  296. endif
  297. endfunction
  298.  
  299. " echo a warning message
  300. function! <SID>WarningMsg(msg)
  301. echohl WarningMsg | echomsg a:msg | echohl None
  302. endfunction
  303.  
  304. " echo an error message
  305. function! <SID>ErrorMsg(msg)
  306. echohl ErrorMsg | echomsg a:msg | echohl None
  307. endfunction
  308.  
  309. " Section: commands {{{1
  310. " diff {{{2
  311. " compare the current buffer and the saved file
  312. command! -nargs=0 DiffOrig vertical new | set buftype=nofile |
  313. \ read # | 0 delete _ | diffthis | wincmd p | diffthis
  314.  
  315. " diff contents of two registers {{{3
  316. " usage: DiffRegs a z || DiffRegs az
  317. command! -nargs=+ DiffRegs call s:DiffRegs(<f-args>)
  318. function! s:DiffRegs(...)
  319. if a:0 > 2
  320. call <SID>ErrorMsg("Diff is between two registers")
  321. return
  322. endif
  323. let reg1 = a:1[0]
  324. if a:0 == 2
  325. let reg2 = a:2[0]
  326. else
  327. let reg2 = a:1[1]
  328. endif
  329. for reg in [ reg1, reg2 ]
  330. if reg == ''
  331. call <SID>ErrorMsg("Missing register")
  332. return
  333. elseif getregtype(reg) == ''
  334. call <SID>WarningMsg("Empty or invalid register ".reg)
  335. return
  336. endif
  337. endfor
  338. tabnew | set buftype=nofile
  339. exec "silent put" reg2
  340. 0 delete _ | diffthis
  341. vertical new | set buftype=nofile
  342. exec "silent put" reg1
  343. 0 delete _ | diffthis
  344. endfunction " }}}3
  345.  
  346. " registers {{{2
  347. " check full contents of registers
  348. command! -nargs=1 Reg call s:Reg(<q-args>)
  349. function! s:Reg(regstr)
  350. for i in range(len(a:regstr))
  351. let reg = a:regstr[i]
  352. let contents = getreg(reg)
  353. if contents != ''
  354. echohl Visual | echo '"'.reg | echohl None
  355. echo contents
  356. endif
  357. endfor
  358. endfunction
  359.  
  360. " clear a register
  361. command! -nargs=0 -register ClearRegister
  362. \ if "<reg>" != '' |
  363. \ let @<reg> = @_ |
  364. \ else |
  365. \ let @" = @_ |
  366. \ let @z = @_ |
  367. \ endif |
  368.  
  369. " files {{{2
  370. " open files in new tabs {{{3
  371. command! -nargs=* -complete=file TabOpen call s:TabOpen(<f-args>)
  372. function! s:TabOpen(...)
  373. if a:0 == 0
  374. tabnew | return
  375. endif
  376. let error = 0
  377. let wd = fnameescape(getcwd())
  378. for arg in a:000
  379. for file in split(glob(arg),'\n')
  380. exec "cd" wd
  381. if !filereadable(file)
  382. let error = 1
  383. call <SID>ErrorMsg("Can't read ".file)
  384. continue
  385. endif
  386. if error | echo '' | endif
  387. if @% != ''
  388. exec "tabedit" file
  389. else | exec "edit" file
  390. endif
  391. endfor
  392. endfor
  393. endfunction " }}}3
  394.  
  395. " change the working directory to the current file's directory
  396. command! -nargs=0 CD exec 'cd' expand('%:h')
  397.  
  398. " delete current file from disk
  399. command! -nargs=0 RmFile echo "rm" @% "(".delete(@%).")"
  400.  
  401. " settings and views {{{2
  402. " highlight with RightMargin beyond a column number
  403. command! -nargs=? ColumnMarker if "<args>" != '' | try |
  404. \ match RightMargin /\%><args>v.\+/ |
  405. \ catch | endtry |
  406. \else | match |
  407. \endif
  408.  
  409. " view/set the number of text columns
  410. command! -nargs=? Columns if "<args>" != '' | try |
  411. \ if &number | exec 'set columns='.(len(line('$'))+1+<args>) |
  412. \ else | set columns=<args> |
  413. \ endif | endtry |
  414. \else |
  415. \ if &number | echo &columns-len(line('$'))-1 |
  416. \ else | echo &columns |
  417. \ endif |
  418. \endif
  419.  
  420. " view/set textwidth
  421. command! -nargs=? TextWidth if "<args>" != '' | setlocal textwidth=<args> |
  422. \ else | set tw? | endif
  423.  
  424. " change the current font size {{{3
  425. command! -nargs=1 FontSize call s:FontSize(<q-args>)
  426. function! s:FontSize(op)
  427. if !exists("g:font_increment")
  428. let g:font_increment = 0.5
  429. endif
  430. let curfont = escape(StripFrom(&guifont, '\d\+\(\.\d\)\?$'), ' ')
  431. let cursize = str2float(matchstr(&guifont, '\d\+\(\.\d\)\?$'))
  432. if cursize == 0
  433. let newsize = ''
  434. elseif a:op == '+'
  435. let newsize = string(cursize + g:font_increment)
  436. elseif a:op == '-'
  437. let newsize = string(cursize - g:font_increment)
  438. else
  439. let newsize = a:op
  440. endif
  441. exec 'set guifont='.curfont.StripFrom(newsize, '\.0$')
  442. endfunction " }}}3
  443.  
  444. " editing {{{2
  445. " copy matches of the last search to a register
  446. " accepts a range (default is the whole file)
  447. " matches are appended to the register and each match is terminated by \n
  448. command! -nargs=0 -range=% -register CopyMatches
  449. \ call s:CopyMatches(<line1>, <line2>, "<reg>")
  450. function! s:CopyMatches(line1, line2, reg)
  451. let ic_save = &ignorecase
  452. set noignorecase
  453. let reg = a:reg != '' ? a:reg : '"'
  454. exec "let @".reg." = @_"
  455. for line in range(a:line1, a:line2)
  456. let txt = getline(line)
  457. let idx = match(txt, @/)
  458. while idx > -1
  459. exec "let @".reg." .= matchstr(txt, @/, idx) . \"\n\""
  460. let end = matchend(txt, @/, idx)
  461. let idx = match(txt, @/, end)
  462. endwhile
  463. endfor
  464. let &ic = ic_save
  465. endfunction
  466.  
  467. " convert leading spaces to tabs if they agree with the current tabstop
  468. command! -nargs=0 -range=% LeadingSpacesToTabs
  469. \ call s:LeadingSpacesToTabs(<line1>, <line2>)
  470. function! s:LeadingSpacesToTabs(line1, line2)
  471. for line in range(a:line1, a:line2)
  472. while matchend(getline(line), '^ \+') % &tabstop == 0
  473. exec line.'s/^ *\zs \{'.&tabstop.'}\ze/\t/'
  474. endwhile
  475. endfor
  476. endfunction
  477.  
  478. " toggle for hex mode {{{3
  479. command! -nargs=0 -bar Hexmode call s:ToggleHex()
  480. function! s:ToggleHex()
  481. let mod_save = &modified
  482. let ro_save = &readonly | set noreadonly
  483. let ma_save = &modifiable | set modifiable
  484. if !exists("b:edit_hex") || !b:edit_hex
  485. let b:ft_save = &filetype
  486. let b:bin_save = &binary
  487. setlocal binary
  488. set ft=xxd
  489. let b:edit_hex = 1
  490. %!xxd
  491. else
  492. let &ft = b:ft_save
  493. if !b:bin_save
  494. setlocal nobinary
  495. endif
  496. let b:edit_hex = 0
  497. %!xxd -r
  498. endif
  499. let &mod = mod_save
  500. let &ro = ro_save
  501. let &modifiable = ma_save
  502. endfunction " }}}3
  503. " character conversion {{{3
  504. " convert quotes, apostrophes, and dashes into their unicode counterparts
  505. command! -nargs=0 -range=% WordProcess call s:WordProcess(<line1>, <line2>)
  506. function! s:WordProcess(line1, line2)
  507. let w = '[0-9A-Za-z]'
  508. let W = '[^0-9A-Za-z]'
  509. let punct = '[.,!?]'
  510. for line in range(a:line1, a:line2)
  511. exec line.'s/\('.w.'\|\s\|"\|^\)\zs--\ze\('.w.'\|\s\|'.punct.'\|"\|$\)/�/ge'
  512. exec line.'s/'.punct.'\zs"\ze\('.W.'\|$\)/�/ge'
  513. exec line.'s/\('.W.'\|^\)\zs"\ze\S/�/ge'
  514. exec line.'s/\S\zs"\ze\('.W.'\|$\)/�/ge'
  515. exec line.'s/\('.W.'\|^\)\zs'."'".'\ze\S/�/ge'
  516. exec line.'s/\S\zs'."'".'\ze\('.W.'\|$\)/�/ge'
  517. exec line.'s/'.w.'\zs'."'".'\ze\a/�/ge'
  518. endfor
  519. endfunction
  520.  
  521. " enforce ASCII-ness
  522. command! -nargs=0 -range=% Ascii call s:Ascii(<line1>, <line2>)
  523. function! s:Ascii(line1, line2)
  524. for line in range(a:line1, a:line2)
  525. exec line.'s/�/"/ge'
  526. exec line.'s/�/"/ge'
  527. exec line.'s/��/"/ge'
  528. exec line.'s/��/"/ge'
  529. exec line."s/�/'/ge"
  530. exec line."s/�/'/ge"
  531. exec line.'s/�/--/ge'
  532. endfor
  533. endfunction " }}}3
  534. " .XCompose {{{3
  535. " convert a line such as "&#601; U+0259 LATIN SMALL LETTER SCHWA"
  536. " use c flag for canonical bind (<ampersand> <x> <x> <x> <x>)
  537. command! -nargs=? -range XCompose call s:XCompose(<line1>, <line2>, <q-args>)
  538. function! s:XCompose(line1, line2, foo)
  539. if a:foo == 'c'
  540. let cflag = 1
  541. else
  542. let cflag = 0
  543. endif
  544. for line in range(a:line1, a:line2)
  545. let txt = getline(line)
  546. let m = matchlist(txt, '\v^(.)\s*(U\+?\x\x\x\x)?\s*#?\s*(.*)')
  547. if empty(m) | continue | endif
  548. let m[2] = substitute(m[2], '\vU\+?(\x\x\x\x)', 'U\U\1', '')
  549. if cflag && m[2] =~ 'U\x\x\x\x'
  550. let bind = '<ampersand>'
  551. for x in split(m[2][1:], '\ze.')
  552. let bind .= ' <'.tolower(x).'>'
  553. endfor
  554. else
  555. let bind = '<> <>'
  556. endif
  557. let txt = "<Multi_key> ".bind."\t\t\t: \"".m[1].'"'.(len(m[2]) ? "\t".m[2] : "").(len(m[3]) ? " # ".m[3] : "")
  558. call setline(line, txt)
  559. endfor
  560. endfunction " }}}3
  561.  
  562. " }}}1 commands
  563. " Section: mappings {{{1
  564. " see :help map-modes
  565. " general {{{2
  566. " externally map CapsLock to Control
  567.  
  568. " No-ops
  569. vnoremap K <Nop>
  570.  
  571. " make <Enter> more useful - enter command line or cancel pending operation
  572. noremap <CR> :
  573. onoremap <CR> <C-C>
  574.  
  575. " set <Space> to toggle a fold
  576. noremap<silent><Space> :<C-U>exec 'silent! normal! za'.(foldlevel('.')?'':'')<CR>
  577.  
  578. " use <C-Space> as <Esc>
  579. noremap <C-Space> <Esc>
  580. inoremap <C-Space> <Esc>
  581. cnoremap <C-Space> <C-\><C-N>
  582.  
  583. " use <BackSpace> for deleting visual selections
  584. xnoremap <BS> d
  585. snoremap <BS> <BS>i
  586.  
  587. " make Y consistent with D and C
  588. nnoremap Y y$
  589.  
  590. " don't clobber registers when doing character deletes
  591. nnoremap x "_x
  592. nnoremap X "_X
  593. nnoremap s "_s
  594.  
  595. " reset 'hlsearch'
  596. nnoremap<silent>n :set hlsearch<CR>n
  597. nnoremap<silent>N :set hlsearch<CR>N
  598.  
  599. " define C-[HLJK] and M-[hljk] behavior {{{3
  600. " first remap <C-K> (digraphs) to <C-B>
  601. noremap! <C-B> <C-K>
  602. " and <C-L> (redraw) to <C-Y>
  603. noremap <C-Y> <C-L>
  604. noremap <C-E> <Nop>
  605. " anchor the cursor and scroll
  606. noremap <C-H> zh
  607. noremap <C-L> zl
  608. noremap <C-J> <C-E>
  609. noremap <C-K> <C-Y>
  610. inoremap <C-J> <C-X><C-E>
  611. inoremap <C-K> <C-X><C-Y>
  612. " kill line
  613. cnoremap <C-K> <C-F>D<C-C><End>
  614. " <C-H> remains <BS> by default; use <C-L> to go right
  615. noremap! <C-L> <Right>
  616. " in command-line mode, use <C-T> for partial completion and listing matches
  617. cnoremap <C-T> <C-L><C-D>
  618.  
  619. " move in virtual lines
  620. nnoremap j gj
  621. vnoremap j gj
  622. nnoremap k gk
  623. vnoremap k gk
  624. " use as movement keys
  625. noremap! <M-h> <Left>
  626. noremap! <M-l> <Right>
  627. inoremap <M-j> <C-O>gj
  628. inoremap <M-k> <C-O>gk
  629. " switch between windows
  630. nnoremap <M-h> <C-W>h
  631. nnoremap <M-l> <C-W>l
  632. nnoremap <M-j> <C-W>j
  633. nnoremap <M-k> <C-W>k
  634. " go from select mode to insert mode
  635. snoremap <M-h> <C-\><C-N>`<i
  636. snoremap <M-l> <C-\><C-N>`>a
  637. " }}}3
  638.  
  639. " move in virtual lines with <Up> and <Down>
  640. noremap <Up> gk
  641. inoremap <Up> <C-O>gk
  642. noremap <Down> gj
  643. inoremap <Down> <C-O>gj
  644.  
  645. " emacs-style bindings for word movement and deletion {{{3
  646. noremap <M-b> b
  647. noremap <M-f> w
  648. noremap! <M-b> <S-Left>
  649. noremap! <M-f> <S-Right>
  650.  
  651. function! <SID>KillWord()
  652. return (col('.')==col('$') ? "\<Del>" : "\<C-O>de")
  653. endfunction
  654. inoremap<silent><M-d> <C-R>=<SID>KillWord()<CR>
  655. noremap! <M-BS> <C-W>
  656.  
  657. " use <C-O>D for <C-K>
  658. inoremap <C-A> <C-O>^
  659. cnoremap <C-A> <Home>
  660. noremap! <C-E> <End>
  661. cnoremap <C-D> <Del>
  662. " in insert mode:
  663. " use <C-F> as the default <C-A> (insert previously inserted text),
  664. " and <C-G> as the default <C-E> (insert the char below cursor)
  665. inoremap <C-F> <C-A>
  666. inoremap <C-G> <C-E>
  667. " }}}3
  668. " register yank, delete, and paste {{{3
  669. vnoremap<silent><M-y> :<C-U>exec 'normal `<'.visualmode().'`>"'.nr2char(getchar()).'y'<CR>
  670. vnoremap<silent><M-d> :<C-U>exec 'normal `<'.visualmode().'`>"'.nr2char(getchar()).'d'<CR>
  671.  
  672. function! <SID>PasteRegister(visual)
  673. exec 'normal '.(a:visual ? '`<'.visualmode().'`>' : '' ).
  674. \'"'.nr2char(getchar()).'p'
  675. endfunction
  676. noremap <silent><M-r> :<C-U>call <SID>PasteRegister(0)<CR>
  677. vnoremap<silent><M-r> :<C-U>call <SID>PasteRegister(1)<CR>
  678. " }}}3
  679.  
  680. " paste most recently used register
  681. nnoremap <M-p> o<C-R>"<C-C>
  682. nnoremap <M-S-p> O<C-R>"<C-C>
  683. inoremap <M-p> <C-R>"
  684.  
  685. " recall command history, matching current command line
  686. cnoremap <M-p> <Up>
  687. cnoremap <M-n> <Down>
  688.  
  689. " paste X selection register
  690. noremap! <S-Insert> <C-R>*
  691.  
  692. " tab switching
  693. noremap <C-Tab> :<C-U>tabnext<CR>
  694. noremap <C-S-Tab> :<C-U>tabprevious<CR>
  695. nnoremap <Tab> :<C-U>tabnext<CR>
  696. nnoremap <S-Tab> :<C-U>tabprevious<CR>
  697. onoremap <Tab> :<C-U>tabnext<CR>
  698. onoremap <S-Tab> :<C-U>tabprevious<CR>
  699.  
  700. " indent and dedent with <Tab> in visual mode
  701. xnoremap <Tab> >
  702. xnoremap <S-Tab> <
  703.  
  704. " very magic search
  705. noremap <M-/> <C-\><C-N>/\v
  706. noremap <M-?> <C-\><C-N>?\v
  707. vnoremap <M-/> /\v
  708. vnoremap <M-?> ?\v
  709.  
  710. " windows-style clipboard shortcuts emulated with meta {{{3
  711. " select all
  712. noremap <M-a> <C-\><C-N>ggVG
  713. " cut
  714. vnoremap <M-x> "+x
  715. " copy
  716. vnoremap <M-c> "+y
  717. " paste
  718. noremap <M-v> <C-\><C-N>"+gP
  719. exec 'vnoremap <script> <M-v>' paste#paste_cmd['v']
  720. exec 'inoremap <script> <M-v>' paste#paste_cmd['i']
  721. cnoremap <M-v> <C-R>+
  722. " }}}3
  723.  
  724. " save shortcut
  725. nnoremap <C-S> :w<CR>
  726. inoremap <C-S> <C-O>:w<CR>
  727.  
  728. " nothing to see here, move along {{{3
  729. if !has("gui_running") && &term =~ 'xterm' && &t_Co == 256
  730. fun! Rave(time)
  731. let ravers = [ 'Number', 'String', 'Comment', 'Statement', 'Function', 'Special' ]
  732. let len = len(ravers)
  733. if !exists("g:wtf")
  734. let g:wtf = []
  735. let rand = localtime()
  736. for i in range(len)
  737. let rand += 232 / len
  738. let g:wtf += [ rand ]
  739. endfor
  740. endif
  741. for i in range(len)
  742. let g:wtf[i] = (g:wtf[i]+a:time) % 232
  743. if g:wtf[i] == 0
  744. let g:wtf[i] = 1
  745. elseif g:wtf[i] == 7 || g:wtf[i] == 8
  746. let g:wtf[i] = 9
  747. elseif g:wtf[i] == 15 || g:wtf[i] == 16
  748. let g:wtf[i] = 17
  749. endif
  750. exec "hi ".ravers[i]." ctermfg=".g:wtf[i]
  751. endfor
  752. hi! link Constant Number
  753. hi! link PreProc Number
  754. hi! link Identifier Function
  755. hi! link Type Function
  756. hi! link Keyword Statement
  757. endfun
  758. fun! Raveon(auto)
  759. if !exists("g:bpm")
  760. let g:bpm = 240
  761. endif
  762. while 1
  763. call Rave(a:auto) | redraw
  764. exec "sleep" float2nr(60000/g:bpm) "m"
  765. endwhile
  766. endfun
  767. silent! unlet g:wtf
  768. map <silent><M-F14> :call Rave(1)<CR>
  769. map <silent><M-F13> :call Rave(64)<CR>
  770. map <silent><M-F12> :call Raveon(1)<CR>
  771. endif " }}}3
  772. " }}}2
  773. " <F1> to <F8> {{{2
  774. function! <SID>ClearMapsF(key1, key2)
  775. for fkey in range(a:key1, a:key2)
  776. for modifier in [ '', 'C-', 'S-' ]
  777. exec 'map <silent> <'.modifier.'F'.fkey.'> '.
  778. \':<C-U>call <SID>WarningMsg("Unmapped")<CR>'
  779. exec 'silent! unmap! <'.modifier.'F'.fkey.'>'
  780. exec 'inoremap <'.modifier.'F'.fkey.'> <Nop>'
  781. endfor
  782. endfor
  783. endfunction
  784. call <SID>ClearMapsF(1,14)
  785.  
  786. " toggle taglist
  787. map <F1> :<C-U>TlistToggle<CR>
  788. vmap <F1> :<C-U>TlistToggle<CR>gv
  789. " toggle NERD Tree
  790. map <F2> :<C-U>NERDTreeToggle<CR>
  791. " open yank ring
  792. map <F3> :<C-U>YRShow<CR>
  793.  
  794. " toggle clipboard
  795. function! <SID>ToggleClipBrd()
  796. let clipnr = bufnr('*\[Clip Board\]$')
  797. if bufwinnr(clipnr) == winnr()
  798. exit!
  799. else
  800. let reg = input(":ClipBrd ", g:clipbrdDefaultReg)
  801. try
  802. if reg != ''
  803. exec "ClipBrd" reg
  804. endif
  805. catch | endtry
  806. endif
  807. endfunction
  808. map <silent><C-F3> :<C-U>call <SID>ToggleClipBrd()<CR>
  809.  
  810. " trim trailing whitespace
  811. function! <SID>Trim()
  812. try " snippetsEmu housekeeping
  813. if expand('%:t') !~ '.vimrc\|.XCompose' && exists("*CleanupArgs") &&
  814. \ g:snip_start_tag != '' && g:snip_end_tag != ''
  815. exec '%s/('.g:snip_start_tag.'\(.*\))/\="(".CleanupArgs(submatch(1)).")"/e'
  816. exec '%s/'.g:snip_start_tag.'//eg'
  817. exec '%s/'.g:snip_end_tag.'//eg'
  818. endif
  819. catch | endtry
  820. %s/\s\+$//e
  821. endfunction
  822. map <silent><F4> :<C-U>let @z=@/<CR>maHmz:call <SID>Trim()<CR>:let @/=@z<CR>`zzt`a
  823. vmap<silent><F4> :<C-U>let @z=@/<CR>maHmz:call <SID>Trim()<CR>:let @/=@z<CR>`zzt`agv
  824. imap<silent><F4> <C-C>:let @z=@/<CR>maHmz:call <SID>Trim()<CR>:let @/=@z<CR>`zzt`agi
  825. " autoindent entire file
  826. map <C-F4> <C-\><C-N>maHmzgg=G`zzt`a
  827. vmap <C-F4> <C-\><C-N>maHmzgg=G`zzt`agv
  828.  
  829. " remove search highlighting
  830. " let @/=@_
  831. map <silent><F5> :<C-U>nohlsearch<CR>
  832. vmap<silent><F5> :<C-U>nohlsearch<CR>gv
  833. imap<silent><F5> <C-O>:nohlsearch<CR>
  834. " toggle scrollbind
  835. map <silent><C-F5> :<C-U>setlocal scrollbind! scb?<CR>
  836. vmap<silent><C-F5> :<C-U>setlocal scrollbind! scb?<CR>gv
  837. imap<silent><C-F5> <C-O>:setlocal scrollbind! scb?<CR>
  838. " toggle list mode (show tabs)
  839. map <silent><F6> :<C-U>setlocal list! list?<CR>
  840. vmap<silent><F6> :<C-U>setlocal list! list?<CR>gv
  841. imap<silent><F6> <C-O>:setlocal list! list?<CR>
  842. " highlight characters beyond a column
  843. map <C-F6> :<C-U>ColumnMarker<Space>
  844. imap <C-F6> <C-O>:ColumnMarker<Space>
  845.  
  846. " toggle tabstop
  847. function! <SID>ToggleTabstop()
  848. if &tabstop == 4
  849. setlocal tabstop=8
  850. elseif &tabstop == 8
  851. setlocal tabstop=4
  852. endif
  853. set ts?
  854. endfunction
  855. map <silent><F7> :<C-U>call <SID>ToggleTabstop()<CR>
  856. vmap<silent><F7> :<C-U>call <SID>ToggleTabstop()<CR>gv
  857. imap<silent><F7> <C-O>:call <SID>ToggleTabstop()<CR>
  858.  
  859. " toggle expandtab
  860. map <silent><C-F7> :<C-U>setlocal expandtab! et?<CR>
  861. vmap<silent><C-F7> :<C-U>setlocal expandtab! et?<CR>gv
  862. imap<silent><C-F7> <C-O>:setlocal expandtab! et?<CR>
  863.  
  864. " toggle line wrapping
  865. map <silent><F8> :<C-U>setlocal wrap! wrap?<CR>
  866. vmap<silent><F8> :<C-U>setlocal wrap! wrap?<CR>gv
  867. imap<silent><F8> <C-O>:setlocal wrap! wrap?<CR>
  868. " set/view maximum line length (set to 0 to disable auto-truncation)
  869. map <C-F8> :<C-U>TextWidth<Space>
  870. imap <C-F8> <C-O>:TextWidth<Space>
  871.  
  872. " <F9> to <F14> {{{2
  873. " change color scheme
  874. function! <SID>NextColorScheme()
  875. if !exists("g:colors_select")
  876. let g:colors_name = "nocolors"
  877. return
  878. endif
  879. let idx = 0
  880. if exists("g:colors_name")
  881. for name in g:colors_select
  882. if g:colors_name == name | break | endif
  883. let idx += 1
  884. endfor
  885. endif
  886. let next = (idx+1) % len(g:colors_select)
  887. call <SID>SetColorScheme(g:colors_select[next])
  888. endfunction
  889. map <silent><F9> :<C-U>call <SID>NextColorScheme()<CR>:echo g:colors_name<CR>
  890. vmap<silent><F9> :<C-U>call <SID>NextColorScheme()<CR>:echo g:colors_name<CR>gv
  891. imap<silent><F9> <C-C>:call <SID>NextColorScheme()<CR>:echo g:colors_name<CR>gi
  892.  
  893. " change font
  894. function! <SID>NextFont(incr)
  895. if !exists("g:font_select") || !exists("g:font_index")
  896. return
  897. endif
  898. let g:font_index = (g:font_index + a:incr) % len(g:font_select)
  899. call <SID>SetGUIFont(g:font_select[g:font_index])
  900. endfunction
  901. map <silent><C-F9> :<C-U>call <SID>NextFont(1)<CR>:echo &guifont<CR>
  902. vmap<silent><C-F9> :<C-U>call <SID>NextFont(1)<CR>:echo &guifont<CR>gv
  903. imap<silent><C-F9> <C-C>:call <SID>NextFont(1)<CR>:echo &guifont<CR>gi
  904.  
  905. " toggle line numbers
  906. map <silent><S-F9> :<C-U>setlocal number! nu?<CR>
  907. vmap<silent><S-F9> :<C-U>setlocal number! nu?<CR>gv
  908. imap<silent><S-F9> <C-O>:setlocal number! nu?<CR>
  909.  
  910. " toggle menu bar and toolbar
  911. function! <SID>ToggleBars()
  912. if &guioptions =~# 'm'
  913. set guioptions-=m
  914. set guioptions-=T
  915. else
  916. set guioptions+=m
  917. set guioptions+=T
  918. endif
  919. set go?
  920. endfunction
  921. map <silent><F10> :<C-U>call <SID>ToggleBars()<CR>
  922. vmap<silent><F10> :<C-U>call <SID>ToggleBars()<CR>gv
  923.  
  924. " maximize current window
  925. map <F11> <C-\><C-N><C-W>_<C-W>\|
  926. vmap <F11> <C-\><C-N><C-W>_<C-W>\|gv
  927. " change window width
  928. map <C-F10> <C-\><C-N>3<C-W><
  929. vmap <C-F10> <C-\><C-N>3<C-W><gv
  930. map <C-F11> <C-\><C-N>3<C-W>>
  931. vmap <C-F11> <C-\><C-N>3<C-W>>gv
  932. " change window height
  933. map <S-F10> <C-\><C-N>3<C-W>-
  934. vmap <S-F10> <C-\><C-N>3<C-W>-gv
  935. map <S-F11> <C-\><C-N>3<C-W>+
  936. vmap <S-F11> <C-\><C-N>3<C-W>+gv
  937.  
  938. " toggle spellcheck and autocorrect
  939. function! <SID>ToggleSpellCorrect()
  940. if &spell
  941. iabclear
  942. else
  943. runtime autocorrect.vim
  944. endif
  945. setlocal spell! spell?
  946. endfunction
  947. map <silent><F12> :<C-U>call <SID>ToggleSpellCorrect()<CR>
  948. vmap<silent><F12> :<C-U>call <SID>ToggleSpellCorrect()<CR>gv
  949. imap<silent><F12> <C-O>:call <SID>ToggleSpellCorrect()<CR>
  950.  
  951. " extra buttons
  952. " switch buffers
  953. map <F13> :<C-U>bprevious<CR>
  954. map <F14> :<C-U>bnext<CR>
  955. map <C-F13> :<C-U>ls<CR>:buffer<Space>
  956. " split all buffers
  957. map <C-F14> :<C-U>tab ball<CR>
  958. " redirect command-line output to register z
  959. map <S-F13> :<C-U>let @z=@_<CR>:redir @z><CR>
  960. vmap <S-F13> :<C-U>let @z=@_<CR>:redir @z><CR>gv
  961. nmap <S-F14> :<C-U>redir END<CR>
  962. vmap <S-F14> :<C-U>redir END<CR>gv
  963.  
  964. " macros {{{2
  965. " <M-0> to <M-9> {{{3
  966. function! <SID>ClearMapsM(key1, key2)
  967. for mkey in range(a:key1, a:key2)
  968. exec 'map <silent> <M-'.mkey.'> '.
  969. \':<C-U>call <SID>WarningMsg("Unmapped")<CR>'
  970. exec 'silent! unmap! <M-'.mkey.'>'
  971. endfor
  972. endfunction
  973. call <SID>ClearMapsM(0,9)
  974.  
  975. " quickfix
  976. map <M-1> <C-\><C-N>:cprevious<CR>
  977. map <M-2> <C-\><C-N>:cnext<CR>
  978. map <M-3> <C-\><C-N>:clist<CR>
  979. map <M-4> <C-\><C-N>:make<Space><Up><CR>
  980. cmap<silent><M-4> <C-R>=expand('%:t:r')<CR>
  981. " fold one level
  982. map <M-5> <C-\><C-N>:%foldclose<CR>
  983. " highlight without jumping
  984. xmap<silent><M-8> :<C-U>let @/="\\V<C-R>=escape(<SID>FidgetWhitespace(escape(<SID>GetSelection(),'\')),'\"')<CR>"<CR>
  985. " exec "let @/='\\<".expand("<cword>")."\\>'"
  986. nmap<silent><M-8> :<C-U>normal #*<CR>
  987. imap<silent><M-8> <C-O>:normal #*<CR>
  988.  
  989. " change font size
  990. map <silent><M-0> :<C-U>call <SID>NextFont(0)<CR>
  991. vmap<silent><M-0> :<C-U>call <SID>NextFont(0)<CR>
  992. map <silent><M--> :<C-U>FontSize -<CR>:set guifont?<CR>
  993. vmap<silent><M--> :<C-U>FontSize -<CR>:set guifont?<CR>gv
  994. map <silent><M-=> :<C-U>FontSize +<CR>:set guifont?<CR>
  995. vmap<silent><M-=> :<C-U>FontSize +<CR>:set guifont?<CR>gv
  996. " }}}3
  997.  
  998. " surround selected area
  999. xnoremap ' <C-C>`>a'<C-C>`<i'<C-C>
  1000. xnoremap ( <C-C>`>a)<C-C>`<i(<C-C>
  1001.  
  1002. " diff mode
  1003. noremap du :<C-U>diffupdate<CR>
  1004. " jump between diffs
  1005. noremap dN <C-\><C-N>[czz
  1006. noremap dn <C-\><C-N>]czz
  1007.  
  1008. " display current file in two columns
  1009. noremap<silent>ZC :<C-U>let @z=&so<CR>:set so=0<CR>maHmz:set noscb<CR>
  1010. \:vs<CR><C-W>wLzt:set scb<CR><C-W>p:set scb<CR>
  1011. \`zzt`a:let &so=@z<CR>
  1012.  
  1013. " <leader> {{{3
  1014. " load this file for editing and re-source
  1015. map <leader>v :<C-U>TabOpen $MYVIMRC<CR>
  1016. map <leader>u :<C-U>source $MYVIMRC<CR>
  1017. " load config files for editing
  1018. map <silent><leader>b :<C-U>TabOpen ~/.bash{rc,_aliases,_hacks}<CR>:tabnext 2<CR>
  1019. map <silent><leader>f :<C-U>TabOpen ~/.mozilla/firefox/*.default/chrome/user{Content,Chrome}.css<CR>
  1020.  
  1021. " expand tabs in selected lines to spaces
  1022. xmap<silent><leader>e :<C-U>let @z=&et<CR>:set et<CR>gv:retab<CR>:let &et=@z<CR>
  1023. " convert spaces to tabs
  1024. xmap<silent><leader>t :retab!<CR>
  1025.  
  1026. " delete into the null register
  1027. map <leader>d "_d
  1028. map <leader>D "_D
  1029. map <leader>c "_c
  1030. map <leader>C "_C
  1031. " delete the stretch of whitespace at or before the cursor
  1032. nmap<silent><leader><BS> :normal! gE<CR>
  1033. \:exec(getline('.')[col('.')-1]=~'\S' ? "normal! \<lt>Right>":"")<CR>
  1034. \:exec(getline('.')[col('.')-1]=~'\s' ? 'normal! dw':'')<CR>
  1035.  
  1036. " custom operations
  1037. " switch .XCompose key bindings
  1038. xmap<silent><leader>X :<C-U>let @z=&hls.@/<CR>:set nohls<CR>
  1039. \:'<,'>s/\v^(\<\w+\>)(%(\s*\<\w+\>)*)(\s*\<\w+\>)/\1\3\2/e<CR>
  1040. \:let @/=@z[1:]<CR>:let &hls=@z[0]<CR>
  1041.  
  1042. " spellchecking
  1043. nmap <leader>[ [s
  1044. nmap <leader>] ]s
  1045. nmap <leader>= z=
  1046.  
  1047. " text insertion {{{3
  1048. " append modeline
  1049. nmap <leader>m ovim:set ts=4 sw=4 noet:<C-C>^
  1050.  
  1051. " date
  1052. imap <leader>dd <C-R>=strftime('%F')<CR>
  1053. for s:i in range(1,5)
  1054. exec "imap <leader>d".s:i." <C-R>=strftime('%F', localtime() - ".s:i."*86400)<CR>"
  1055. endfor
  1056.  
  1057. " log date
  1058. nmap <leader>l o<C-R>=strftime('%m/%d %a \| ')<CR>
  1059. imap <leader>l <C-R>=strftime('%m/%d %a \| ')<CR>
  1060.  
  1061. " search {{{3
  1062. " search for a word
  1063. map <leader>w <C-\><C-N>/\<\><Left><Left>
  1064. " search for visually selected text
  1065. function! <SID>FidgetWhitespace(pat)
  1066. let pat = substitute(a:pat,'\_s\+$','\\s\\*', '')
  1067. let pat = substitute(pat, '^\_s\+', '\\s\\*', '')
  1068. return substitute(pat, '\_s\+', '\\_s\\+','g')
  1069. endfunction
  1070. xmap<silent> * <C-C>/\V<C-R>=<SID>FidgetWhitespace(escape(<SID>GetSelection(),'/\'))<CR><CR>
  1071. xmap<silent> # <C-C>?\V<C-R>=<SID>FidgetWhitespace(escape(<SID>GetSelection(),'?\'))<CR><CR>
  1072. nmap<silent><leader>* /\V<C-R>=substitute(escape(<SID>GetSelection(),'/\'),'\n','\\n','g')<CR><CR>
  1073. xmap<silent><leader>* <C-C>/\V<C-R>=substitute(escape(<SID>GetSelection(),'/\'),'\n','\\n','g')<CR><CR>
  1074. nmap<silent><leader># ?\V<C-R>=substitute(escape(<SID>GetSelection(),'?\'),'\n','\\n','g')<CR><CR>
  1075. xmap<silent><leader># <C-C>?\V<C-R>=substitute(escape(<SID>GetSelection(),'?\'),'\n','\\n','g')<CR><CR>
  1076.  
  1077. " regex shortcuts
  1078. " brace multi, non-greedy multi
  1079. cmap <leader>{ \{}<Left>
  1080. cmap <leader>- \{-}
  1081. " white space
  1082. cmap <leader><Space> \_s\+
  1083.  
  1084. " replace last search pattern
  1085. map <leader>s :%s///gc<Left><Left><Left>
  1086. xmap <leader>s :s///gc<Left><Left><Left>
  1087. " execute command on lines matching last search pattern
  1088. map <leader>g :g//
  1089.  
  1090. " }}}2
  1091. " }}}1 mappings
  1092. " Section: plugins {{{1
  1093. " external balloon evaluation
  1094. function! <SID>PlugBalloonEval()
  1095. if exists("*BalloonDeclaration")
  1096. " echofunc
  1097. return BalloonDeclaration()
  1098. else | return '' | endif
  1099. endfunction
  1100.  
  1101. " genutils
  1102. " matchit
  1103.  
  1104. " taglist " {{{2
  1105. """""""""""
  1106. let g:Tlist_Show_One_File = 1
  1107.  
  1108. " echofunc " {{{2
  1109. """"""""""""
  1110. let g:EchoFuncKeyPrev = '<M-p>'
  1111. let g:EchoFuncKeyNext = '<M-n>'
  1112. let g:EchoFuncMaxBalloonDeclarations = 6
  1113.  
  1114. " YankRing " {{{2
  1115. """"""""""""
  1116. let g:yankring_history_file = ".yankring_history"
  1117. " custom maps - extend to or bar from YankRing
  1118. function! YRRunAfterMaps()
  1119. nnoremap<silent>Y :<C-U>YRYankCount 'y$'<CR>
  1120. nnoremap x "_x
  1121. nnoremap X "_X
  1122. nnoremap s "_s
  1123. endfunction
  1124. if exists("loaded_yankring") | call YRRunAfterMaps() | endif
  1125.  
  1126. " ClipBrd " {{{2
  1127. """""""""""
  1128. let g:clipbrdDefaultReg = '+'
  1129.  
  1130. " NERD Commenter " {{{2
  1131. """"""""""""""""""
  1132. let g:NERDBlockComIgnoreEmpty = 1
  1133. let g:NERDCommentWholeLinesInVMode = 2
  1134. let g:NERDDefaultNesting = 0
  1135. let g:NERDMenuMode = 0
  1136. let g:NERDSpaceDelims = 1
  1137. let g:NERDSexyComs = 0
  1138. let g:NERDCompactSexyComs = 0
  1139. let g:NERDShutUp = 1
  1140.  
  1141. " NERD Tree " {{{2
  1142. """""""""""""
  1143. let g:NERDTreeWinPos = "right"
  1144.  
  1145. " snippetsEmu " {{{2
  1146. """""""""""""""
  1147. let g:snip_start_tag = "�"
  1148. let g:snip_end_tag = "�"
  1149.  
  1150. " edit snippets for the current or given filetype
  1151. command! -nargs=* -complete=custom,EditSnippetsComplete EditSnippets
  1152. \ call s:EditSnippets(<f-args>)
  1153. function! s:EditSnippets(...)
  1154. let args = (a:0==0 ? [&filetype] : a:000)
  1155. for type in args
  1156. if type == '' | continue | endif
  1157. let snips = reverse(split(globpath(&rtp, "after/*/".type."_".(type=='*'? 'my' : '*')."snip*s.vim")))
  1158. if len(snips) == 0
  1159. call <SID>ErrorMsg("No snippets found for filetype ".type)
  1160. continue
  1161. endif
  1162. for file in snips | exec "TabOpen" file | endfor
  1163. endfor
  1164. endfunction
  1165. function! EditSnippetsComplete(a,l,p)
  1166. let types = split(globpath(&rtp, "after/*/*_*snip*s.vim"))
  1167. for i in range(len(types))
  1168. let types[i] = StripFrom(fnamemodify(types[i], ':t'), '_.*snip.*s\.vim$')
  1169. endfor
  1170. return join(RemoveDuplicates(types), "\n")
  1171. endfunction
  1172.  
  1173. " session_dialog " {{{2
  1174. """"""""""""""""""
  1175. let g:SessionSaveDirectory = "~"
  1176. let g:SessionPath = ".,~"
  1177. " let g:SessionFilePrefix = ""
  1178. " let g:SessionFileSuffix = ""
  1179. let g:SessionDefault = ""
  1180. let g:SessionConfirmOverwrite = 0
  1181. let g:SessionQuitAfterSave = 0
  1182. let g:SessionCreateDefaultMaps = 1
  1183.  
  1184. " }}}1 plugins
  1185. " Section: development {{{1
  1186. if !has("autocmd")
  1187. finish
  1188. endif
  1189.  
  1190. " C/C++ {{{2
  1191. augroup cpp
  1192. au!
  1193. " use syntax folding
  1194. au FileType c,cpp setl foldmethod=syntax
  1195. augroup END
  1196.  
  1197. " python {{{2
  1198. if has("python")
  1199. python << EOF
  1200. # script {{{
  1201. import os
  1202. import sys
  1203. import vim
  1204. # set up path (allowing jumps to library files)
  1205. for p in sys.path:
  1206. if os.path.isdir(p):
  1207. vim.command(r"set path+=%s" % p.replace(" ",r"\ "))
  1208. # toggle a breakpoint at the current line
  1209. def ToggleBreakpoint():
  1210. import re
  1211. strLine = vim.current.line
  1212. if strLine.lstrip()[:15] == 'pdb.set_trace()':
  1213. vim.command('normal dd')
  1214. return
  1215. strWhite = re.search('^(\s*)', strLine).group(1)
  1216. if strWhite == '': return
  1217. nLine = int(vim.eval('line(".")'))
  1218. vim.current.buffer.append(
  1219. "%(space)spdb.set_trace() %(mark)s Breakpoint %(mark)s" %
  1220. {'space':strWhite, 'mark':'#'*20}, nLine-1)
  1221. for strLine in vim.current.buffer:
  1222. if strLine == "import pdb":
  1223. break
  1224. else:
  1225. vim.current.buffer.append('import pdb', 0)
  1226. vim.command('normal j^')
  1227. # remove all breakpoints
  1228. def RemoveBreakpoints():
  1229. import re
  1230. nCurrentLine = int(vim.eval('line(".")'))
  1231. rmLines = []
  1232. nLine = 0
  1233. for strLine in vim.current.buffer:
  1234. nLine += 1
  1235. if strLine.lstrip().startswith('pdb.set_trace()') or strLine == 'import pdb':
  1236. rmLines.append(nLine)
  1237. rmLines.reverse()
  1238. for nLine in rmLines:
  1239. vim.command('normal %dG' % nLine)
  1240. vim.command('normal dd')
  1241. if nLine < nCurrentLine:
  1242. nCurrentLine -= 1
  1243. vim.command('normal %dG' % nCurrentLine)
  1244. # }}}
  1245. EOF
  1246. endif
  1247.  
  1248. let g:python_highlight_all = 1
  1249.  
  1250. augroup python
  1251. au!
  1252. au FileType python setl expandtab
  1253. au FileType python setl diffopt-=iwhite
  1254. " make
  1255. au FileType python setl mp=python\ -c\ \"import\ py_compile;py_compile.compile(r'%')\"\ -t
  1256. au FileType python setl efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%C^,%C%[%^\ ]%\\@=%m,%Z
  1257. " breakpoints
  1258. au FileType python map <buffer> <M-9> <C-\><C-N>:python ToggleBreakpoint()<CR>
  1259. au FileType python map <buffer> <M-0> <C-\><C-N>:python RemoveBreakpoints()<CR>
  1260. augroup END
  1261.  
  1262. " java {{{2
  1263. augroup java
  1264. au!
  1265. " use syntax folding
  1266. au FileType java setl foldmethod=syntax
  1267. " make
  1268. au FileType java setl mp=javac\ -g\ $*\ %
  1269. au FileType java setl efm=%A%f:%l:\ %m,%-Z%p^,%-C%.%#,%-G%.%#
  1270. augroup END
  1271.  
  1272. " }}}1 development
  1273. " vim:set ts=4 sw=4 noet fdl=0 fdm=marker:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement