Chinaunix首页 | 论坛 | 博客
  • 博客访问: 55805
  • 博文数量: 10
  • 博客积分: 374
  • 博客等级: 一等列兵
  • 技术积分: 95
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-04 09:05
文章分类

全部博文(10)

文章存档

2012年(3)

2011年(4)

2009年(2)

2008年(1)

我的朋友
最近访客

分类: LINUX

2011-01-21 19:00:10

  1. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  2. " Maintainer: amix the lucky stiff
  3. " - amix@amix.dk
  4. "
  5. " Version: 3.6 - 25/08/10 14:40:30
  6. "
  7. " Blog_post:
  8. " /blog/post/19486#The-ultimate-vim-configuration-vimrc
  9. " Syntax_highlighted:
  10. " /vim/vimrc.html
  11. " Raw_version:
  12. " /vim/vimrc.txt
  13. "
  14. " How_to_Install_on_Unix:
  15. " $ mkdir ~/.vim_runtime
  16. " $ svn co svn://orangoo.com/vim ~/.vim_runtime
  17. " $ cat ~/.vim_runtime/install.sh
  18. " $ sh ~/.vim_runtime/install.sh
  19. " can be `mac`, `linux` or `windows`
  20. "
  21. " How_to_Upgrade:
  22. " $ svn update ~/.vim_runtime
  23. "
  24. " Sections:
  25. " -> General
  26. " -> VIM user interface
  27. " -> Colors and Fonts
  28. " -> Files and backups
  29. " -> Text, tab and indent related
  30. " -> Visual mode related
  31. " -> Command mode related
  32. " -> Moving around, tabs and buffers
  33. " -> Statusline
  34. " -> Parenthesis/bracket expanding
  35. " -> General Abbrevs
  36. " -> Editing mappings
  37. "
  38. " -> Cope
  39. " -> Minibuffer plugin
  40. " -> Omni complete functions
  41. " -> Python section
  42. " -> JavaScript section
  43. "
  44. "
  45. " Plugins_Included:
  46. " > minibufexpl.vim -
  47. " Makes it easy to get an overview of buffers:
  48. " info -> :e ~/.vim_runtime/plugin/minibufexpl.vim
  49. "
  50. " > bufexplorer -
  51. " Makes it easy to switch between buffers:
  52. " info -> :help bufExplorer
  53. "
  54. " > yankring.vim -
  55. " Emacs's killring, useful when using the clipboard:
  56. " info -> :help yankring
  57. "
  58. " > surround.vim -
  59. " Makes it easy to work with surrounding text:
  60. " info -> :help surround
  61. "
  62. " > snipMate.vim -
  63. " Snippets for many languages (similar to TextMate's):
  64. " info -> :help snipMate
  65. "
  66. " > mru.vim -
  67. " Plugin to manage Most Recently Used (MRU) files:
  68. " info -> :e ~/.vim_runtime/plugin/mru.vim
  69. "
  70. " > Command-T -
  71. " Command-T plug-in provides an extremely fast, intuitive mechanism for opening filesa:
  72. " info -> :help CommandT
  73. " screencast and web-help -> /blog/post/19501
  74. "
  75. "
  76. " Revisions:
  77. " > 3.6: Added lots of stuff (colors, Command-T, Vim 7.3 persistent undo etc.)
  78. " > 3.5: Paste mode is now shown in status line if you are in paste mode
  79. " > 3.4: Added mru.vim
  80. " > 3.3: Added syntax highlighting for Mako mako.vim
  81. " > 3.2: Turned on python_highlight_all for better syntax
  82. " highlighting for Python
  83. " > 3.1: Added revisions ;) and bufexplorer.vim
  84. "
  85. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  86. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  87. " => General
  88. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  89. " Sets how many lines of history VIM has to remember
  90. set history=700
  91. " Enable filetype plugin
  92. filetype plugin on
  93. filetype indent on
  94. " Set to auto read when a file is changed from the outside
  95. set autoread
  96. " With a map leader it's possible to do extra key combinations
  97. " like w saves the current file
  98. let mapleader = ","
  99. let g:mapleader = ","
  100. " Fast saving
  101. nmap w :w!
  102. " Fast editing of the .vimrc
  103. map e :e! ~/.vim_runtime/vimrc
  104. " When vimrc is edited, reload it
  105. autocmd! bufwritepost vimrc source ~/.vim_runtime/vimrc
  106. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  107. " => VIM user interface
  108. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  109. " Set 7 lines to the curors - when moving vertical..
  110. set so=7
  111. set wildmenu "Turn on WiLd menu
  112. set ruler "Always show current position
  113. set cmdheight=2 "The commandbar height
  114. set hid "Change buffer - without saving
  115. " Set backspace config
  116. set backspace=eol,start,indent
  117. set whichwrap+=<,>,h,l
  118. set ignorecase "Ignore case when searching
  119. set smartcase
  120. set hlsearch "Highlight search things
  121. set incsearch "Make search act like search in modern browsers
  122. set nolazyredraw "Don't redraw while executing macros
  123. set magic "Set magic on, for regular expressions
  124. set showmatch "Show matching bracets when text indicator is over them
  125. set mat=2 "How many tenths of a second to blink
  126. " No sound on errors
  127. set noerrorbells
  128. set novisualbell
  129. set t_vb=
  130. set tm=500
  131. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  132. " => Colors and Fonts
  133. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  134. syntax enable "Enable syntax hl
  135. " Set font according to system
  136. if MySys() == "mac"
  137. set gfn=Menlo:h14
  138. set shell=/bin/bash
  139. elseif MySys() == "windows"
  140. set gfn=Bitstream\ Vera\ Sans\ Mono:h10
  141. elseif MySys() == "linux"
  142. set gfn=Monospace\ 10
  143. set shell=/bin/bash
  144. endif
  145. if has("gui_running")
  146. set guioptions-=T
  147. set t_Co=256
  148. set background=dark
  149. colorscheme peaksea
  150. set nonu
  151. else
  152. colorscheme zellner
  153. set background=dark
  154. set nonu
  155. endif
  156. set encoding=utf8
  157. try
  158. lang en_US
  159. catch
  160. endtry
  161. set ffs=unix,dos,mac "Default file types
  162. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  163. " => Files, backups and undo
  164. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  165. " Turn backup off, since most stuff is in SVN, git anyway...
  166. set nobackup
  167. set nowb
  168. set noswapfile
  169. "Persistent undo
  170. try
  171. if MySys() == "windows"
  172. set undodir=C:\Windows\Temp
  173. else
  174. set undodir=~/.vim_runtime/undodir
  175. endif
  176. set undofile
  177. catch
  178. endtry
  179. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  180. " => Text, tab and indent related
  181. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  182. set expandtab
  183. set shiftwidth=4
  184. set tabstop=4
  185. set smarttab
  186. set lbr
  187. set tw=500
  188. set ai "Auto indent
  189. set si "Smart indet
  190. set wrap "Wrap lines
  191. """"""""""""""""""""""""""""""
  192. " => Visual mode related
  193. """"""""""""""""""""""""""""""
  194. " Really useful!
  195. " In visual mode when you press * or # to search for the current selection
  196. vnoremap * :call VisualSearch('f')
  197. vnoremap # :call VisualSearch('b')
  198. " When you press gv you vimgrep after the selected text
  199. vnoremap gv :call VisualSearch('gv')
  200. map g :vimgrep // **/*.
  201. function! CmdLine(str)
  202. exe "menu Foo.Bar :" . a:str
  203. emenu Foo.Bar
  204. unmenu Foo
  205. endfunction
  206. " From an idea by Michael Naumann
  207. function! VisualSearch(direction) range
  208. let l:saved_reg = @"
  209. execute "normal! vgvy"
  210. let l:pattern = escape(@", '\\/.*$^~[]')
  211. let l:pattern = substitute(l:pattern, "\n$", "", "")
  212. if a:direction == 'b'
  213. execute "normal ?" . l:pattern . "^M"
  214. elseif a:direction == 'gv'
  215. call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
  216. elseif a:direction == 'f'
  217. execute "normal /" . l:pattern . "^M"
  218. endif
  219. let @/ = l:pattern
  220. let @" = l:saved_reg
  221. endfunction
  222. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  223. " => Command mode related
  224. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  225. " Smart mappings on the command line
  226. cno $h e ~/
  227. cno $d e ~/Desktop/
  228. cno $j e ./
  229. cno $c e eCurrentFileDir("e")
  230. " $q is super useful when browsing on the command line
  231. cno $q eDeleteTillSlash()
  232. " Bash like keys for the command line
  233. cnoremap
  234. cnoremap
  235. cnoremap
  236. cnoremap
  237. cnoremap
  238. " Useful on some European keyboards
  239. map $
  240. imap $
  241. vmap $
  242. cmap $
  243. func! Cwd()
  244. let cwd = getcwd()
  245. return "e " . cwd
  246. endfunc
  247. func! DeleteTillSlash()
  248. let g:cmd = getcmdline()
  249. if MySys() == "linux" || MySys() == "mac"
  250. let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "")
  251. else
  252. let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "")
  253. endif
  254. if g:cmd == g:cmd_edited
  255. if MySys() == "linux" || MySys() == "mac"
  256. let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "")
  257. else
  258. let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "")
  259. endif
  260. endif
  261. return g:cmd_edited
  262. endfunc
  263. func! CurrentFileDir(cmd)
  264. return a:cmd . " " . expand("%:p:h") . "/"
  265. endfunc
  266. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  267. " => Moving around, tabs and buffers
  268. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  269. " Map space to / (search) and c-space to ? (backgwards search)
  270. map /
  271. map ?
  272. map :noh
  273. " Smart way to move btw. windows
  274. map j
  275. map k
  276. map h
  277. map l
  278. " Close the current buffer
  279. map bd :Bclose
  280. " Close all the buffers
  281. map ba :1,300 bd!
  282. " Use the arrows to something usefull
  283. map :bn
  284. map :bp
  285. " Tab configuration
  286. map tn :tabnew
  287. map te :tabedit
  288. map tc :tabclose
  289. map tm :tabmove
  290. " When pressing cd switch to the directory of the open buffer
  291. map cd :cd %:p:h
  292. command! Bclose call BufcloseCloseIt()
  293. function! BufcloseCloseIt()
  294. let l:currentBufNum = bufnr("%")
  295. let l:alternateBufNum = bufnr("#")
  296. if buflisted(l:alternateBufNum)
  297. buffer #
  298. else
  299. bnext
  300. endif
  301. if bufnr("%") == l:currentBufNum
  302. new
  303. endif
  304. if buflisted(l:currentBufNum)
  305. execute("bdelete! ".l:currentBufNum)
  306. endif
  307. endfunction
  308. " Specify the behavior when switching between buffers
  309. try
  310. set switchbuf=usetab
  311. set stal=2
  312. catch
  313. endtry
  314. """"""""""""""""""""""""""""""
  315. " => Statusline
  316. """"""""""""""""""""""""""""""
  317. " Always hide the statusline
  318. set laststatus=2
  319. " Format the statusline
  320. set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c
  321. function! CurDir()
  322. let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
  323. return curdir
  324. endfunction
  325. function! HasPaste()
  326. if &paste
  327. return 'PASTE MODE '
  328. else
  329. return ''
  330. endif
  331. endfunction
  332. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  333. " => Parenthesis/bracket expanding
  334. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  335. vnoremap $1 `>a)`
  336. vnoremap $2 `>a]`
  337. vnoremap $3 `>a}`
  338. vnoremap $$ `>a"`
  339. vnoremap $q `>a'`
  340. vnoremap $e `>a"`
  341. " Map auto complete of (, ", ', [
  342. inoremap $1 ()i
  343. inoremap $2 []i
  344. inoremap $3 {}i
  345. inoremap $4 {o}O
  346. inoremap $q ''i
  347. inoremap $e ""i
  348. inoremap $t <>i
  349. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  350. " => General Abbrevs
  351. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  352. iab xdate =strftime("%d/%m/%y %H:%M:%S")
  353. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  354. " => Editing mappings
  355. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  356. "Remap VIM 0
  357. map 0 ^
  358. "Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
  359. nmap mz:m+`z
  360. nmap mz:m-2`z
  361. vmap :m'>+`mzgv`yo`z
  362. vmap :m'<-2`>my`
  363. if MySys() == "mac"
  364. nmap
  365. nmap
  366. vmap
  367. vmap
  368. endif
  369. "Delete trailing white space, useful for Python ;)
  370. func! DeleteTrailingWS()
  371. exe "normal mz"
  372. %s/\s\+$//ge
  373. exe "normal `z"
  374. endfunc
  375. autocmd BufWrite *.py :call DeleteTrailingWS()
  376. set guitablabel=%t
  377. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  378. " => Cope
  379. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  380. " Do :help cope if you are unsure what cope is. It's super useful!
  381. map cc :botright cope
  382. map n :cn
  383. map p :cp
  384. """"""""""""""""""""""""""""""
  385. " => bufExplorer plugin
  386. """"""""""""""""""""""""""""""
  387. let g:bufExplorerDefaultHelp=0
  388. let g:bufExplorerShowRelativePath=1
  389. map o :BufExplorer
  390. """"""""""""""""""""""""""""""
  391. " => Minibuffer plugin
  392. """"""""""""""""""""""""""""""
  393. let g:miniBufExplModSelTarget = 1
  394. let g:miniBufExplorerMoreThanOne = 2
  395. let g:miniBufExplModSelTarget = 0
  396. let g:miniBufExplUseSingleClick = 1
  397. let g:miniBufExplMapWindowNavVim = 1
  398. let g:miniBufExplVSplit = 25
  399. let g:miniBufExplSplitBelow=1
  400. let g:bufExplorerSortBy = "name"
  401. autocmd BufRead,BufNew :call UMiniBufExplorer
  402. map u :TMiniBufExplorer
  403. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  404. " => Omni complete functions
  405. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  406. autocmd FileType css set omnifunc=csscomplete#CompleteCSS
  407. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  408. " => Spell checking
  409. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  410. "Pressing ,ss will toggle and untoggle spell checking
  411. map ss :setlocal spell!
  412. "Shortcuts using
  413. map sn ]s
  414. map sp [s
  415. map sa zg
  416. map s? z=
  417. """"""""""""""""""""""""""""""
  418. " => Python section
  419. """"""""""""""""""""""""""""""
  420. let python_highlight_all = 1
  421. au FileType python syn keyword pythonDecorator True None False self
  422. au BufNewFile,BufRead *.jinja set syntax=htmljinja
  423. au BufNewFile,BufRead *.mako set ft=mako
  424. au FileType python inoremap $r return
  425. au FileType python inoremap $i import
  426. au FileType python inoremap $p print
  427. au FileType python inoremap $f #--- PH ----------------------------------------------FP2xi
  428. au FileType python map 1 /class
  429. au FileType python map 2 /def
  430. au FileType python map C ?class
  431. au FileType python map D ?def
  432. """"""""""""""""""""""""""""""
  433. " => JavaScript section
  434. """""""""""""""""""""""""""""""
  435. au FileType javascript call JavaScriptFold()
  436. au FileType javascript setl fen
  437. au FileType javascript setl nocindent
  438. au FileType javascript imap AJS.log();hi
  439. au FileType javascript imap alert();hi
  440. au FileType javascript inoremap $r return
  441. au FileType javascript inoremap $f //--- PH ----------------------------------------------FP2xi
  442. function! JavaScriptFold()
  443. setl foldmethod=syntax
  444. setl foldlevelstart=1
  445. syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend
  446. function! FoldText()
  447. return substitute(getline(v:foldstart), '{.*', '{...}', '')
  448. endfunction
  449. setl foldtext=FoldText()
  450. endfunction
  451. """"""""""""""""""""""""""""""
  452. " => MRU plugin
  453. """"""""""""""""""""""""""""""
  454. let MRU_Max_Entries = 400
  455. map f :MRU
  456. """"""""""""""""""""""""""""""
  457. " => Command-T
  458. """"""""""""""""""""""""""""""
  459. let g:CommandTMaxHeight = 15
  460. set wildignore+=*.o,*.obj,.git,*.pyc
  461. noremap j :CommandT
  462. noremap y :CommandTFlush
  463. """"""""""""""""""""""""""""""
  464. " => Vim grep
  465. """"""""""""""""""""""""""""""
  466. let Grep_Skip_Dirs = 'RCS CVS SCCS .svn generated'
  467. set grepprg=/bin/grep\ -nH
  468. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  469. " => MISC
  470. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  471. " Remove the Windows ^M - when the encodings gets messed up
  472. noremap m mmHmt:%s///ge'tzt'm
  473. "Quickly open a buffer for scripbble
  474. map q :e ~/buffer
  475. au BufRead,BufNewFile ~/buffer iab xh1 ===========================================
  476. map pp :setlocal paste!
  477. map bb :cd ..
阅读(888) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~