set nocompatible source $VIMRUNTIME/vimrc_example.vim source $VIMRUNTIME/mswin.vim behave mswin set diffexpr=MyDiff() function MyDiff() let opt = '-a --binary ' if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif let arg1 = v:fname_in if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif let arg2 = v:fname_new if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif let arg3 = v:fname_out if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif let eq = '' if $VIMRUNTIME =~ ' ' if &sh =~ ' ' . arg3 . eq endfunction "配色 colorscheme slate "字体 set guifont=Bitstream_Vera_Sans_Mono:h10:cANSI "行号,行号栏目宽度 set nu set numberwidth=2 "tab长度 set tabstop=2 "自动对齐 set autoindent "语法高亮 syntax on "设置gbk字符会有编码问题,设置字符集 set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 "行间距 set linespace=2 "<>调整缩进时的长度 set shiftwidth=2 "初始化窗口宽度高度 set columns=150 set lines=30 "初始化窗口位置 winpos 52 42 "禁止自动换行 set nowrap "在输入命令时列出匹配项目 set wildmenu "显示光标位置 set ruler "分割窗口保持相等宽高 set equalalways "匹配括号规则,增加html的<> set matchpairs=(:),{:},[:],<:> "让退格,空格,上下箭头遇到行首位自动移到下一行(包括insert模式) set whichwrap=b,s,<,>,[,] "取消自动备份 set nobackup "关闭文件之前保留一个备份 set writebackup "js语法高亮脚本 let g:javascript_enable_domhtmlcss=1 "光标准星 set cursorline hi cursorline guibg=NONE gui=underline set cursorcolumn hi cursorcolum gui=underline "自动修改 set autoread "不明字体宽度,按照double的来 set ambiwidth=double "打开javascript折叠 " setlocal foldlevel=1 let g:tlist_javascript_settings = 'javascript;s:string;a:array;o:object;f:function;m:member' let b:javascript_fold=1 "开启折叠 "自动补齐括号等 :inoremap ( ()i :inoremap ) =ClosePair(')') :inoremap { {}O :inoremap } =ClosePair('}') :inoremap [ []i :inoremap ] =ClosePair(']') :inoremap " ""i :inoremap ' ''i function ClosePair(char) if getline('.')[col('.') - 1] == a:char return "/" else return a:char endif endfunction "自动补齐html" function! InsertHtmlTag() let pat = 'c<w+s*(s+w+s*=s*[''#$;,()."a-z0-9]+)*s*>' normal! a> let save_cursor = getpos('.') let result = matchstr(getline(save_cursor[1]), pat) "if (search(pat, 'b', save_cursor[1]) && searchpair('<','','>','bn',0, getline('.')) > 0) if (search(pat, 'b', save_cursor[1])) normal! lyiwf> normal! a endif :call cursor(save_cursor[1], save_cursor[2], save_cursor[3]) endfunction inoremap > :call InsertHtmlTag()a "半透明设置" au GUIEnter * call libcallnr("vimtweak.dll", "SetAlpha", 234) "git 配置" set laststatus=2 set statusline=%{GitBranch()} command Gogm cd E:apachehtdocsgm
看注释就明白了,简单说一下目前我觉得足够用的功能,其实都是想到了现google搜的,全部解决。然后在淘宝师傅给我的vim键盘表也排上了用场,这里也要谢谢猥琐的师傅啊……- -
简单说一下,之前用aptana主要是使用他得js,css,html代码提示功能。在vim里,用ctrl+n和p其实是可以直接调用的,牛逼的是提示不区分语言,而是从缓存里直接去读,甚至目录,我当时就被震惊了……这尼玛还要什么代码提示,先开一个jquery源文件,然后再写jq代码,确实是爽的不行,之后又安装了自动弹出提示的插件,感觉比那半残的aptana不知道好多少……。
然后是自定义的命令使用,每次打开vim都要cd一堆到我的工作目录,然后再开启目录树那个NERDTree插件,后来编辑了直接cd到目录的快捷命令,方便很多了,再之后调用bat脚本,直接!强制执行就OK了……更是便捷……再最后,增加括号补全,自动保存,一些颜色配置等,视觉效果比aptana牛逼多了,而且半透明的界面有时候还可以边抄边写代码。。。真是不错- -||
最后在aptana下有一个localstore,是我比较喜欢的,最后在vim下安装了git-vim插件,再也不用开bash界面了,再也不用再bash界面看恶心的diff了。。真是……而且也强迫了我把gitpro前面入门的章节看完了。。- -|| 总之 store的东西也就这样解决了~
" vimrc by Godson@ustcbbs " Last Update: 2010-02-08 let mapleader = ";" " 比较习惯用;作为命令前缀,右手小拇指直接能按到 " 把空格键映射成: nmap <space> : " 快捷打开编辑vimrc文件的键盘绑定 map <silent> <leader>ee :e $HOME/.vimrc<cr> autocmd! bufwritepost *.vimrc source $HOME/.vimrc " 保存文件 nmap <leader>ww :w!<cr> " ^z快速进入shell nmap <C-Z> :shell<cr> " 判断操作系统 if (has("win32") || has("win64") || has("win32unix")) let g:isWin = 1 else let g:isWin = 0 endif " 判断是终端还是gvim if has("gui_running") let g:isGUI = 1 else let g:isGUI = 0 endif set nocompatible " 关闭兼容模式 syntax enable " 语法高亮 filetype plugin on " 文件类型插件 filetype indent on set autoindent autocmd BufEnter * :syntax sync fromstart set nu " 显示行号 set showcmd " 显示命令 set lz " 当运行宏时,在命令执行完成之前,不重绘屏幕 set hid " 可以在没有保存的情况下切换buffer set backspace=eol,start,indent set whichwrap+=<,>,h,l " 退格键和方向键可以换行 set incsearch " 增量式搜索 set hlsearch " 高亮搜索 set ignorecase " 搜索时忽略大小写 set magic " 额,自己:h magic吧,一行很难解释 set showmatch " 显示匹配的括号 set nobackup " 关闭备份 set nowb set noswapfile " 不使用swp文件,注意,错误退出后无法恢复 set lbr " 在breakat字符处而不是最后一个字符处断行 set ai " 自动缩进 set si " 智能缩进 set cindent " C/C++风格缩进 set wildmenu set nofen set fdl=10 " tab转化为4个字符 set expandtab set smarttab set shiftwidth=4 set tabstop=4 " 不使用beep或flash set vb t_vb= set background=dark colorscheme desert "set t_Co=256 set history=400 " vim记住的历史操作的数量,默认的是20 set autoread " 当文件在外部被修改时,自动重新读取 set mouse=a " 在所有模式下都允许使用鼠标,还可以是n,v,i,c等 "在gvim中高亮当前行 if (g:isGUI) set cursorline hi cursorline guibg=#333333 hi CursorColumn guibg=#333333 set guifont=Consolas\ 14 set guifontwide=Consolas\ 14 endif " 设置字符集编码,默认使用utf8 if (g:isWin) let &termencoding=&encoding " 通常win下的encoding为cp936 set fileencodings=utf8,cp936,ucs-bom,latin1 else set encoding=utf8 set fileencodings=utf8,gb2312,gb18030,ucs-bom,latin1 endif " 状态栏 set laststatus=2 " 总是显示状态栏 highlight StatusLine cterm=bold ctermfg=yellow ctermbg=blue " 获取当前路径,将$HOME转化为~ function! CurDir() let curdir = substitute(getcwd(), $HOME, "~", "g") return curdir endfunction set statusline=[%n]\ %f%m%r%h\ \|\ \ pwd:\ %{CurDir()}\ \ \|%=\|\ %l,%c\ %p%%\ \|\ ascii=%b,hex=%b%{((&fenc==\"\")?\"\":\"\ \|\ \".&fenc)}\ \|\ %{$USER}\ @\ %{hostname()}\ " 第80列往后加下划线 "au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1) " 根据给定方向搜索当前光标下的单词,结合下面两个绑定使用 function! VisualSearch(direction) range let l:saved_reg = @" execute "normal! vgvy" let l:pattern = escape(@", '\\/.*$^~[]') let l:pattern = substitute(l:pattern, "\n$", "", "") if a:direction == 'b' execute "normal ?" . l:pattern . "<cr>" else execute "normal /" . l:pattern . "<cr>" endif let @/ = l:pattern let @" = l:saved_reg endfunction " 用 */# 向 前/后 搜索光标下的单词 vnoremap <silent> * :call VisualSearch('f')<CR> vnoremap <silent> # :call VisualSearch('b')<CR> " 在文件名上按gf时,在新的tab中打开 "map gf :tabnew <cfile><cr> " 用c-j,k在buffer之间切换 nn <C-J> :bn<cr> nn <C-K> :bp<cr> " Bash(Emacs)风格键盘绑定 imap <C-e> <END> imap <C-a> <HOME> "imap <C-u> <esc>d0i "imap <C-k> <esc>d$i " 与自动补全中的绑定冲突 " 恢复上次文件打开位置 set viminfo='10,\"100,:20,%,n~/.viminfo au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif " 删除buffer时不关闭窗口 command! Bclose call <SID>BufcloseCloseIt() function! <SID>BufcloseCloseIt() let l:currentBufNum = bufnr("%") let l:alternateBufNum = bufnr("#") if buflisted(l:alternateBufNum) buffer # else bnext endif if bufnr("%") == l:currentBufNum new endif if buflisted(l:currentBufNum) execute("bdelete! ".l:currentBufNum) endif endfunction " 快捷输入 " 自动完成括号和引号 inoremap <leader>1 ()<esc>:let leavechar=")"<cr>i inoremap <leader>2 []<esc>:let leavechar="]"<cr>i inoremap <leader>3 {}<esc>:let leavechar="}"<cr>i inoremap <leader>4 {<esc>o}<esc>:let leavechar="}"<cr>O inoremap <leader>q ''<esc>:let leavechar="'"<cr>i inoremap <leader>w ""<esc>:let leavechar='"'<cr>i " 缩写 iab idate <c-r>=strftime("%Y-%m-%d")<CR> iab itime <c-r>=strftime("%H:%M")<CR> iab imail Stephen <stephenpcg@gmail.com> iab iumail stephen1@mail.ustc.edu.cn iab igmail stephenpcg@gmail.com iab iname Zhang Cheng " 插件窗口的宽度,如TagList,NERD_tree等,自己设置 let s:PlugWinSize = 30 " ShowFunc.vim <-------- 暂时没有使用 " http://www.vim.org/scripts/script.php?script_id=397 " F2打开ShowFunc TagList窗口,显示C/C++函数原型 " map <F2> <Plug>ShowFunc " map! <F2> <Plug>ShowFunc " taglist.vim " http://www.vim.org/scripts/script.php?script_id=273 " <leader>t 打开TagList窗口,窗口在右边 nmap <silent> <leader>t :TlistToggle<cr> "let Tlist_Ctags_Cmd = '/usr/bin/ctags' let Tlist_Show_One_File = 0 let Tlist_Exit_OnlyWindow = 1 let Tlist_Use_Right_Window = 1 let Tlist_File_Fold_Auto_Close = 1 let Tlist_GainFocus_On_ToggleOpen = 0 let Tlist_WinWidth = s:PlugWinSize let Tlist_Auto_Open = 0 let Tlist_Display_Prototype = 0 "let Tlist_Close_On_Select = 1 " minibufexpl.vim " http://www.vim.org/scripts/script.php?script_id=159 " 不需要配置 " OmniCppComplete.vim " http://www.vim.org/scripts/script.php?script_id=1520 set completeopt=menu let OmniCpp_ShowPrototypeInAbbr = 1 let OmniCpp_DefaultNamespaces = ["std"] " 逗号分割的字符串 let OmniCpp_MayCompleteScope = 1 let OmniCpp_ShowPrototypeInAbbr = 0 let OmniCpp_SelectFirstItem = 2 " c-j自动补全,当补全菜单打开时,c-j,k上下选择 imap <expr> <c-j> pumvisible()?"\<C-N>":"\<C-X><C-O>" imap <expr> <c-k> pumvisible()?"\<C-P>":"\<esc>" " f:文件名补全,l:行补全,d:字典补全,]:tag补全 imap <C-]> <C-X><C-]> imap <C-F> <C-X><C-F> imap <C-D> <C-X><C-D> imap <C-L> <C-X><C-L> " NERD_commenter.vim " http://www.vim.org/scripts/script.php?script_id=1218 " Toggle单行注释/“性感”注释/注释到行尾/取消注释 map <leader>cc ,c<space> map <leader>cs ,cs map <leader>c$ ,c$ map <leader>cu ,cu " NERD tree " http://www.vim.org/scripts/script.php?script_id=1658 let NERDTreeShowHidden = 1 let NERDTreeWinPos = "right" let NERDTreeWinSize = s:PlugWinSize nmap <leader>n :NERDTreeToggle<cr> " DoxygenToolkit.vim " http://www.vim.org/scripts/script.php?script_id=987 " 暂时没有使用 " 更新ctags和cscope索引 " href: http://www.vimer.cn/2009/10/把vim打造成一个真正的ide2.html " 稍作修改,提取出DeleteFile函数,修改ctags和cscope执行命令 map <F12> :call Do_CsTag()<cr> function! Do_CsTag() let dir = getcwd() "先删除已有的tags和cscope文件,如果存在且无法删除,则报错。 if ( DeleteFile(dir, "tags") ) return endif if ( DeleteFile(dir, "cscope.files") ) return endif if ( DeleteFile(dir, "cscope.out") ) return endif if(executable('ctags')) silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ." endif if(executable('cscope') && has("cscope") ) if(g:isWin) silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files" else silent! execute "!find . -iname '*.[ch]' -o -name '*.cpp' > cscope.files" endif silent! execute "!cscope -b" execute "normal :" if filereadable("cscope.out") execute "cs add cscope.out" endif endif " 刷新屏幕 execute "redr!" endfunction function! DeleteFile(dir, filename) if filereadable(a:filename) if (g:isWin) let ret = delete(a:dir."\\".a:filename) else let ret = delete("./".a:filename) endif if (ret != 0) echohl WarningMsg | echo "Failed to delete ".a:filename | echohl None return 1 else return 0 endif endif return 0 endfunction " cscope 绑定 if has("cscope") set csto=1 set cst set nocsverb if filereadable("cscope.out") cs add cscope.out endif set csverb " s: C语言符号 g: 定义 d: 这个函数调用的函数 c: 调用这个函数的函数 " t: 文本 e: egrep模式 f: 文件 i: include本文件的文件 nmap <leader>ss :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<CR> nmap <leader>sg :cs find g <C-R>=expand("<cword>")<CR><CR> nmap <leader>sc :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR> nmap <leader>st :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR> nmap <leader>se :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR> nmap <leader>sf :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR> nmap <leader>si :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR> nmap <leader>sd :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR> endif " Quick Fix 设置 map <leader>cw :cw<cr> map <F3> :cp<cr> map <F4> :cn<cr> " lookup file " http://www.vim.org/scripts/script.php?script_id=1581 " 增加一行(line 295): let pattern = '\c' . a:pattern " 按F5或者;ff打开文件搜索窗口 let g:LookupFile_MinPatLength = 0 let g:LookupFile_PreserveLastPattern = 0 let g:LookupFile_PreservePatternHistory = 0 let g:LookupFile_AlwaysAcceptFirst = 1 let g:LookupFile_AllowNewFiles = 0 if filereadable("./filenametags") let g:LookupFile_TagExpr = '"./filenametags"' endif nmap <silent> <leader>ff :LookupFile<cr> function! LookupFile_IgnoreCaseFunc(pattern) let _tags = &tags try let &tags = eval(g:LookupFile_TagExpr) let newpattern = '\c' . a:pattern let tags = taglist(newpattern) catch echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE return "" finally let &tags = _tags endtry " Show the matches for what is typed so far. let files = map(tags, 'v:val["filename"]') return files endfunction let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc' " Buffers Explorer (需要genutils.vim) " http://vim.sourceforge.net/scripts/script.php?script_id=42 " http://www.vim.org/scripts/script.php?script_id=197 let g:bufExplorerDefaultHelp=0 " Do not show default help. let g:bufExplorerShowRelativePath=1 " Show relative paths. let g:bufExplorerSortBy='mru' " Sort by most recently used. let g:bufExplorerSplitRight=0 " Split left. let g:bufExplorerSplitVertical=1 " Split vertically. let g:bufExplorerSplitVertSize = s:PlugWinSize " Split width let g:bufExplorerUseCurrentWindow=1 " Open in new window. autocmd BufWinEnter \[Buf\ List\] setl nonumber nmap <silent> <Leader>b :BufExplorer<CR>