免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3791 | 回复: 4
打印 上一主题 下一主题

怎么才能把VIM配得跟eclipse一样好用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-01 21:52 |只看该作者 |倒序浏览
能做到吗,各位大侠。怎么老是感觉VIM不好配不好用呢,怎么才能让我脱离eclipse用VIM了

论坛徽章:
11
技术图书徽章
日期:2014-03-01 14:44:34天蝎座
日期:2014-05-21 22:11:59金牛座
日期:2014-05-30 17:06:14
2 [报告]
发表于 2012-03-01 22:56 |只看该作者
还是用eclipse吧。。。
都是编码工具,能提高效率就行

论坛徽章:
1
天蝎座
日期:2013-12-06 18:23:58
3 [报告]
发表于 2012-03-02 06:34 |只看该作者
本帖最后由 crazyhadoop 于 2012-03-02 06:35 编辑

http://amix.dk/vim/vimrc.html  参考下这个配置!

  1. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  2. " Maintainer: amix the lucky stiff
  3. "             http://amix.dk - amix@amix.dk
  4. "
  5. " Version: 3.6 - 25/08/10 14:40:30
  6. "
  7. " Blog_post:
  8. "       http://amix.dk/blog/post/19486#The-ultimate-vim-configuration-vimrc
  9. " Syntax_highlighted:
  10. "       http://amix.dk/vim/vimrc.html
  11. " Raw_version:
  12. "       http://amix.dk/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 <system>
  19. "      <sytem> 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 - http://www.vim.org/scripts/script.php?script_id=159
  47. "       Makes it easy to get an overview of buffers:
  48. "           info -> :e ~/.vim_runtime/plugin/minibufexpl.vim
  49. "
  50. "     > bufexplorer - http://www.vim.org/scripts/script.php?script_id=42
  51. "       Makes it easy to switch between buffers:
  52. "           info -> :help bufExplorer
  53. "
  54. "     > yankring.vim - http://www.vim.org/scripts/script.php?script_id=1234
  55. "       Emacs's killring, useful when using the clipboard:
  56. "           info -> :help yankring
  57. "
  58. "     > surround.vim - http://www.vim.org/scripts/script.php?script_id=1697
  59. "       Makes it easy to work with surrounding text:
  60. "           info -> :help surround
  61. "
  62. "     > snipMate.vim - http://www.vim.org/scripts/script.php?script_id=2540
  63. "       Snippets for many languages (similar to TextMate's):
  64. "           info -> :help snipMate
  65. "
  66. "     > mru.vim - http://www.vim.org/scripts/script.php?script_id=521
  67. "       Plugin to manage Most Recently Used (MRU) files:
  68. "           info -> :e ~/.vim_runtime/plugin/mru.vim
  69. "
  70. "     > Command-T - http://www.vim.org/scripts/script.php?script_id=3025
  71. "       Command-T plug-in provides an extremely fast, intuitive mechanism for opening filesa:
  72. "           info -> :help CommandT
  73. "           screencast and web-help -> http://amix.dk/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 <leader>w saves the current file
  98. let mapleader = ","
  99. let g:mapleader = ","

  100. " Fast saving
  101. nmap <leader>w :w!<cr>

  102. " Fast editing of the .vimrc
  103. map <leader>e :e! ~/.vim_runtime/vimrc<cr>

  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 <silent> * :call VisualSearch('f')<CR>
  197. vnoremap <silent> # :call VisualSearch('b')<CR>

  198. " When you press gv you vimgrep after the selected text
  199. vnoremap <silent> gv :call VisualSearch('gv')<CR>
  200. map <leader>g :vimgrep // **/*.<left><left><left><left><left><left><left>


  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 <C-\>eCurrentFileDir("e")<cr>

  230. " $q is super useful when browsing on the command line
  231. cno $q <C-\>eDeleteTillSlash()<cr>

  232. " Bash like keys for the command line
  233. cnoremap <C-A>      <Home>
  234. cnoremap <C-E>      <End>
  235. cnoremap <C-K>      <C-U>

  236. cnoremap <C-P> <Up>
  237. cnoremap <C-N> <Down>

  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 <space> /
  271. map <c-space> ?
  272. map <silent> <leader><cr> :noh<cr>

  273. " Smart way to move btw. windows
  274. map <C-j> <C-W>j
  275. map <C-k> <C-W>k
  276. map <C-h> <C-W>h
  277. map <C-l> <C-W>l

  278. " Close the current buffer
  279. map <leader>bd :Bclose<cr>

  280. " Close all the buffers
  281. map <leader>ba :1,300 bd!<cr>

  282. " Use the arrows to something usefull
  283. map <right> :bn<cr>
  284. map <left> :bp<cr>

  285. " Tab configuration
  286. map <leader>tn :tabnew<cr>
  287. map <leader>te :tabedit
  288. map <leader>tc :tabclose<cr>
  289. map <leader>tm :tabmove

  290. " When pressing <leader>cd switch to the directory of the open buffer
  291. map <leader>cd :cd %:p:h<cr>


  292. command! Bclose call <SID>BufcloseCloseIt()
  293. function! <SID>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 <esc>`>a)<esc>`<i(<esc>
  336. vnoremap $2 <esc>`>a]<esc>`<i[<esc>
  337. vnoremap $3 <esc>`>a}<esc>`<i{<esc>
  338. vnoremap $ <esc>`>a"<esc>`<i"<esc>
  339. vnoremap $q <esc>`>a'<esc>`<i'<esc>
  340. vnoremap $e <esc>`>a"<esc>`<i"<esc>

  341. " Map auto complete of (, ", ', [
  342. inoremap $1 ()<esc>i
  343. inoremap $2 []<esc>i
  344. inoremap $3 {}<esc>i
  345. inoremap $4 {<esc>o}<esc>O
  346. inoremap $q ''<esc>i
  347. inoremap $e ""<esc>i
  348. inoremap $t <><esc>i


  349. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  350. " => General Abbrevs
  351. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  352. iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>


  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 <M-j> mz:m+<cr>`z
  360. nmap <M-k> mz:m-2<cr>`z
  361. vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
  362. vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z

  363. if MySys() == "mac"
  364.   nmap <D-j> <M-j>
  365.   nmap <D-k> <M-k>
  366.   vmap <D-j> <M-j>
  367.   vmap <D-k> <M-k>
  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 <leader>cc :botright cope<cr>
  382. map <leader>n :cn<cr>
  383. map <leader>p :cp<cr>


  384. """"""""""""""""""""""""""""""
  385. " => bufExplorer plugin
  386. """"""""""""""""""""""""""""""
  387. let g:bufExplorerDefaultHelp=0
  388. let g:bufExplorerShowRelativePath=1
  389. map <leader>o :BufExplorer<cr>


  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 <leader>u :TMiniBufExplorer<cr>


  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 <leader>ss :setlocal spell!<cr>

  412. "Shortcuts using <leader>
  413. map <leader>sn ]s
  414. map <leader>sp [s
  415. map <leader>sa zg
  416. map <leader>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 <buffer> $r return
  425. au FileType python inoremap <buffer> $i import
  426. au FileType python inoremap <buffer> $p print
  427. au FileType python inoremap <buffer> $f #--- PH ----------------------------------------------<esc>FP2xi
  428. au FileType python map <buffer> <leader>1 /class
  429. au FileType python map <buffer> <leader>2 /def
  430. au FileType python map <buffer> <leader>C ?class
  431. au FileType python map <buffer> <leader>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 <c-t> AJS.log();<esc>hi
  439. au FileType javascript imap <c-a> alert();<esc>hi

  440. au FileType javascript inoremap <buffer> $r return
  441. au FileType javascript inoremap <buffer> $f //--- PH ----------------------------------------------<esc>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 <leader>f :MRU<CR>


  456. """"""""""""""""""""""""""""""
  457. " => Command-T
  458. """"""""""""""""""""""""""""""
  459. let g:CommandTMaxHeight = 15
  460. set wildignore+=*.o,*.obj,.git,*.pyc
  461. noremap <leader>j :CommandT<cr>
  462. noremap <leader>y :CommandTFlush<cr>


  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 <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm

  473. "Quickly open a buffer for scripbble
  474. map <leader>q :e ~/buffer<cr>
  475. au BufRead,BufNewFile ~/buffer iab <buffer> xh1 ===========================================

  476. map <leader>pp :setlocal paste!<cr>

  477. map <leader>bb :cd ..<cr>
复制代码

论坛徽章:
0
4 [报告]
发表于 2012-03-11 00:01 |只看该作者
vim强大插件 jeffy-vim:网址 http://code.google.com/p/jeffy-vim/

论坛徽章:
1
天蝎座
日期:2013-12-06 18:23:58
5 [报告]
发表于 2012-03-11 23:59 |只看该作者
多摸索摸索,找到适合自己的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP