vim 中能够定义F5为vim 跳到函数定义吗

python补全与函数定义跳转的vim插件 jedi-vim 介绍 - 为程序员服务
python补全与函数定义跳转的vim插件 jedi-vim 介绍
10368 阅读
用vim写c程序时,如果想要看一个include的头文件里面的内容,直接使用gf命令就可以跳转到对应头文件定义的地方,使用ctrl+t就可以跳转回来,如果是查找一个函数的定义,那么使用ctags/cscope插件,就可以在函数定义与调用之间跳转了,在浏览代码和自己编写程序时,非常的方便。
最近半年开始写python程序,一直只用了一个语法文件python.vim,但是却没有import及函数定义与实现之间的跳转了,自己写程序时,还不算太麻烦。但是,浏览库代码时,就感觉有点麻烦了,最开始是使用的pycharm来浏览程序。但是,基于两点:
pycharm使用的盗版,心理过意不去;
每次都要把想看的代码导出放在windows下面,才能在pycharm里面浏览,很麻烦。
所以,我在考虑,万能的vim上有无方便的插件来实现python的函数定义跳转呢?经过搜索,找到了两个:
基于我半个小时的体验,感觉jedi-vim更好用些,下面就详细的介绍一下jedi-vim这个方便python程序编写的vim插件。
jedi-vim 的源码地址:
pathogen 的源码地址:
就vim上插件安装来说,一般有大概三种方式来管理,我这里使用的是pathogen的方法
pathogen 的安装
pathogen 的安装非常方便,只需要两个步骤:
1.终端中执行以下命令
mkdir -p ~/.vim/autoload ~/.vim/bundle && curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
2.编辑 ~/.vimrc 文件,添加
execute pathogen#infect()
这里需要注意的是,如果vimrc文件中有包含
filetype plugin indent on
等语句,那么就要把上面的语句放在这些之前,比如下面这样:
execute pathogen#infect()
filetype plugin indent on
如此,就算是pathogen安装好了,以后如果要下载vimscript的话,只需要在bundle中clone代码即可,比如:
此处要下载jedi-vim,那么就是下面这样的:
cd ~/.vim/bundle && git clone https://github.com/davidhalter/jedi-vim.git
即可,非常方便。
jedi-vim 的安装与使用
任何一个软件的安装或者使用,第一件要干的事就是阅读文档,文档阅读后,基本上对于如何安装与使用,心里就有底了,
此处也不例外,关于jedi-vim的安装,上面已经说了,照着做就ok了。
不过需要注意的是,这个依赖于jedi包,所以可以使用 easy_install jedi 来进行安装。
下面说一下使用,使用也是非常的简单与方便。
以下内容都是摘自官方的文档,
Completion &C-Space&
Goto assignments &leader&g (typical goto function)
Goto definitions &leader&d (follow identifier as far as possible,
includes imports and statements)
Show Documentation/Pydoc K (shows a popup with assignments)
Renaming &leader&r
Usages &leader&n (shows all the usages of a name)
Open module, e.g. :Pyimport os (opens the os module)
这里说一下,& leader > 这里在vim默认的是反斜杠 "\",所以跳转到函数定义处的命令 d 即在normal模式下按下 \d 即可跳转到对应位置。
关于自动补全,默认情况下,输入一个module名后跟点后,就会自动弹出来自动补全的提示,当选中一个后,在vim的窗口中默认上下分割,在上面显示出当前方法的一些说明,如下图所示,调用了 urllib2.Request后,出来的窗口界面:
关于其补全以及其他使用方法,有兴趣的可以自己去看官方文档,
这里就不多说了。
1、记录技术学习、软件折腾过程中遇到的坑以及解决的办法;
2、翻译国外关于web安全、开源软件、linux小技巧等内容;
原文地址:, 感谢原作者分享。
您可能感兴趣的代码博客访问: 5422
博文数量: 3
注册时间:
分类: Linux操作系统 14:33:16
授权方式:署名,非商业用途,保持一致,转载时请务必以超链接()的形式标明文章原始出处和作者信息及本声明。
图形界面下的很多编辑软件都可以列出当前编辑文件中的函数列表,以便在编辑的时候能够快速的跳转。vim虽然没有直接提供这种功能,但配合适当的工具和设定,可以完美的实现!
首先还是安装,vim不用装了,ubuntu中自带,用到的ctags需要自己安装一下,不要用旧的那个ctags,新的叫,apt安装即可:apt-get install exuberant-ctags。
然后按照,下载taglist_42.zip,解压到home目录下的.vim子目录中:
~/.vim$ unzip /home/fwolf/taglist_42.zip
Archive: /home/fwolf/taglist_42.zip
inflating: plugin/taglist.vim
inflating: doc/taglist.txt
进入$HOME/.vim/doc目录,打开目录,运行“.helptags .”命令,注意后面的点不要拉了,这是为了生成ctags帮助文件的索引,然后才能正常使用帮助。(原来vi帮助中的ctrl+]进入链接、ctrl+T返回也是这么来的)
现在,再启动vim,tags功能就可以用了。
大概用法:
在使用vim的时候,使用:TlistToggle命令切换函数列表的开、关。
按住ctrl键然后按两下w键在正常编辑区域和tags区域中切换。
在tags区域中,把光标移动到变量、函数名称上,然后敲回车,就会自动在正常编辑区域中定位到指定内容了,很方便的。
常用的几项.vimrc设置:
“禁止自动改变当前Vim窗口的大小
let Tlist_Inc_Winwidth=0
“把方法列表放在屏幕的右侧
let Tlist_Use_Right_Window=1
“让当前不被编辑的文件的方法列表自动折叠起来, 这样可以节约一些屏幕空间
let Tlist_File_Fold_Auto_Close=1
阅读(690) | 评论(0) | 转发(0) |
下一篇:没有了
相关热门文章
给主人留下些什么吧!~~
请登录后评论。拒绝访问 | www.colabug.com | 百度云加速
请打开cookies.
此网站 (www.colabug.com) 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(433b8dc73f1543b3-ua98).
重新安装浏览器,或使用别的浏览器VIM-一键编译单个源文件 | Vimer的程序世界
& VIM-一键编译单个源文件
用vim也有几年了,从windows开发到Linux,从在校大学生到在职员工,始终想为这个过程记录点什么,为一直陪伴自己的vim,也为自己。
之前在百度贴吧混迹过,结果发的代码全被判定为非法字符,于是打消了在百度发展的计划,而只在上面留了一个QQ号码,结果问问题的人却络绎不绝,我想也许,是该开个博客,不敢说教授,就是分享一下自己的经验吧,希望对感兴趣的各位有所帮助。
这是这个博客的第一篇日志,所以就写个Vimer们经常会遇到的一个需求吧—-一键编译单个源文件。ps:本站所有文章都是直接通过vim编写的哦。
具体功能如下:
1.按F5编译单个文件,支持C,C++,C#,也可以支持java。
2.获取编译器错误描述,在错误描述上回车,可以直接跳转到错误行。
先贴上代码,可以看出,我把C#相关的注释掉了,实际上C#也是支持的,只是后来由于不再做C#相关开发,有需要的朋友可以去掉注释,还是可以编译C#的。
"单个文件编译
map &F5& :call Do_OneFileMake()&CR&
function Do_OneFileMake()
if expand("%:p:h")!=getcwd()
echohl WarningMsg | echo "Fail to make! This file is not in the current dir! Press &F7& to redirect to the dir of this file." | echohl None
let sourcefileename=expand("%:t")
if (sourcefileename=="" || (&filetype!="cpp" && &filetype!="c"))
echohl WarningMsg | echo "Fail to make! Please select the right file!" | echohl None
let deletedspacefilename=substitute(sourcefileename,' ','','g')
if strlen(deletedspacefilename)!=strlen(sourcefileename)
echohl WarningMsg | echo "Fail to make! Please delete the spaces in the filename!" | echohl None
if &filetype=="c"
if g:iswindows==1
set makeprg=gcc\ -o\ %&.exe\ %
set makeprg=gcc\ -o\ %&\ %
elseif &filetype=="cpp"
if g:iswindows==1
set makeprg=g++\ -o\ %&.exe\ %
set makeprg=g++\ -o\ %&\ %
"elseif &filetype=="cs"
"set makeprg=csc\ \/nologo\ \/out:%&.exe\ %
if(g:iswindows==1)
let outfilename=substitute(sourcefileename,'\(\.[^.]*\)' ,'.exe','g')
let toexename=outfilename
let outfilename=substitute(sourcefileename,'\(\.[^.]*\)' ,'','g')
let toexename=outfilename
if filereadable(outfilename)
if(g:iswindows==1)
let outdeletedsuccess=delete(getcwd()."\\".outfilename)
let outdeletedsuccess=delete("./".outfilename)
if(outdeletedsuccess!=0)
set makeprg=make
echohl WarningMsg | echo "Fail to make! I cannot delete the ".outfilename | echohl None
execute "silent make"
set makeprg=make
execute "normal :"
if filereadable(outfilename)
if(g:iswindows==1)
execute "!".toexename
execute "!./".toexename
execute "copen"
endfunction
"进行make的设置
map &F6& :call Do_make()&CR&
map &c-F6& :silent make clean&CR&
function Do_make()
set makeprg=make
execute "silent make"
execute "copen"
endfunction
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
"单个文件编译map &F5& :call Do_OneFileMake()&CR&function Do_OneFileMake()&&&&if expand("%:p:h")!=getcwd()&&&&&&&&echohl WarningMsg | echo "Fail to make! This file is not in the current dir! Press &F7& to redirect to the dir of this file." | echohl None&&&&&&&&return&&&&endif&&&&let sourcefileename=expand("%:t")&&&&if (sourcefileename=="" || (&filetype!="cpp" && &filetype!="c"))&&&&&&&&echohl WarningMsg | echo "Fail to make! Please select the right file!" | echohl None&&&&&&&&return&&&&endif&&&&let deletedspacefilename=substitute(sourcefileename,' ','','g')&&&&if strlen(deletedspacefilename)!=strlen(sourcefileename)&&&&&&&&echohl WarningMsg | echo "Fail to make! Please delete the spaces in the filename!" | echohl None&&&&&&&&return&&&&endif&&&&if &filetype=="c"&&&&&&&&if g:iswindows==1&&&&&&&&&&&&set makeprg=gcc\ -o\ %&.exe\ %&&&&&&&&else&&&&&&&&&&&&set makeprg=gcc\ -o\ %&\ %&&&&&&&&endif&&&&elseif &filetype=="cpp"&&&&&&&&if g:iswindows==1&&&&&&&&&&&&set makeprg=g++\ -o\ %&.exe\ %&&&&&&&&else&&&&&&&&&&&&set makeprg=g++\ -o\ %&\ %&&&&&&&&endif&&&&&&&&"elseif &filetype=="cs"&&&&&&&&"set makeprg=csc\ \/nologo\ \/out:%&.exe\ %&&&&endif&&&&if(g:iswindows==1)&&&&&&&&let outfilename=substitute(sourcefileename,'\(\.[^.]*\)' ,'.exe','g')&&&&&&&&let toexename=outfilename&&&&else&&&&&&&&let outfilename=substitute(sourcefileename,'\(\.[^.]*\)' ,'','g')&&&&&&&&let toexename=outfilename&&&&endif&&&&if filereadable(outfilename)&&&&&&&&if(g:iswindows==1)&&&&&&&&&&&&let outdeletedsuccess=delete(getcwd()."\\".outfilename)&&&&&&&&else&&&&&&&&&&&&let outdeletedsuccess=delete("./".outfilename)&&&&&&&&endif&&&&&&&&if(outdeletedsuccess!=0)&&&&&&&&&&&&set makeprg=make&&&&&&&&&&&&echohl WarningMsg | echo "Fail to make! I cannot delete the ".outfilename | echohl None&&&&&&&&&&&&return&&&&&&&&endif&&&&endif&&&&execute "silent make"&&&&set makeprg=make&&&&execute "normal :"&&&&if filereadable(outfilename)&&&&&&&&if(g:iswindows==1)&&&&&&&&&&&&execute "!".toexename&&&&&&&&else&&&&&&&&&&&&execute "!./".toexename&&&&&&&&endif&&&&endif&&&&execute "copen"endfunction"进行make的设置map &F6& :call Do_make()&CR&map &c-F6& :silent make clean&CR&function Do_make()&&&&set makeprg=make&&&&execute "silent make"&&&&execute "copen"endfunction
主要介绍如下几点:
1.如果是windows用户,需要安装mingw,并且将他的bin目录添加到对应的环境变量里。
2.g:iswindows 是个我定义的全局变量,用来判断系统是linux还是windows,这样就不用写两套vimrc了,实现如下:
if(has("win32") || has("win95") || has("win64") || has("win16"))
let g:iswindows=1
let g:iswindows=0
if(has("win32") || has("win95") || has("win64") || has("win16"))&&&&let g:iswindows=1else&&&&let g:iswindows=0endif
3.makeprg 是vim内置的编译命令,可以通过更改来实现编译对应类型文件。具体可参考vim官方说明文件。
4.最后的copen是打开quickfix,在错误描述上回车,可以直接跳转到错误行。
鉴于有些朋友说的网页会自动转化某些字符,我在这里把txt版的文档放在这里供大家下载:
版权所有,转载请注明出处。
您可能也喜欢:
相信不少朋友像我一样,无论在linux还是windows下都用vim来办公,但是毕竟vim原生于linux,windows下的某些支持还是做的不太好。
这个系列的文章,我们就一起...
前一段时间在博客中和fuadam讨论过python中调用print的时候,是否可以直接打印decode之后的字符的问题。(原文:python-django的中文编码总结)
一开始我...
之前已经写了一篇linux下搭建python+apache的文章。但由于windows下的支持python2.6的mod_python.so一直没有找到下载(http://www.apache.org/dist/httpd/mod...Talk is cheap, Show me the code!
vim自定义设置-配置文件
http://vim自定义键盘映射使用:map命令,可以将键盘上的某个按键与Vim的命令绑定起来。例如使用以下命令,可以通过F5键将单词用花括号括起来::map &F5& i{e&Esc&a}&Esc&其中:i{将插入字符{,然后使用Esc退回到命令状态;接着用e移到单词结尾,a}增加字符},最后退至命令状态。在执行以上命令之后,光标定位在一个单词上(例如amount),按下F5键,这时字符就会变成{amount}的形式。nmap为普通模式,imap为编辑模式
C表示ctrl,A表示Alt,S表示Shift,&CR&表示回车。Alt键可以使用&M-key&或&A-key&来表示。关于键盘符号的详细说明,请使用:h key-notation命令查看帮助信息。 不同模式下的键盘映射使用下表中不同形式的map命令,可以针对特定的模式设置键盘映射:Command命令Normal
Visual可视化模式Operator Pending运算符模式Insert Only插入模式Command Line命令行模式:mapyyy
y查看键盘映射使用:map命令,可以列出所有键盘映射。其中第一列标明了映射在哪种模式下工作:标记 模式
&space& 常规模式,可视化模式,运算符模式
n 常规模式
v 可视化模式
o 运算符模式
! 插入模式,命令行模式
i 插入模式
c 命令模式使用:map!命令,则只列出插入和命令行模式的映射。而:imap,:vmap,:omap,:nmap命令则只是列出相应模式下的映射。vim设置的一些说明.vimrc中的mapleaderThe &Leader& key is mapped to \ by default.
So if you have a map of &Leader&t, you can execute it by default with \+t.
For more detail or re-assigning it using the mapleader variable, see:help leaderTo define a mapping which uses the "mapleader" variable, the special string
"&Leader&" can be used.
It is replaced with the string value of "mapleader".
If "mapleader" is not set or empty, a backslash is used instead.
:map &Leader&A
oanother line &Esc&
Works like:
oanother line &Esc&
But after:
:let mapleader = ","
It works like:
oanother line &Esc&[][]插件安装管理插件的命令:PlugInstall
:PlugUpdate
install or update
:PlugClean
remove plugin not in list
删除本地无用插件
:PlugUpgrade
Upgrade vim-plug itself
:PlugStatus
Check the status of plugins
查看插件状态
[/]vim的配置文件示例{主要用于C++和python开发,当然一般使用也可以啦}修改vimrc文件,如果不存在就创建一个vim ~/.vimrcNote: 第330行可以改成这样的:autocmd BufWinEnter \[Buf\ List\] setl nonumber"let mapleader = ";"
" 比较习惯用;作为命令前缀,右手小拇指直接能按到
" 把空格键映射成:
"nmap &space& :
" 快捷打开编辑vimrc文件的键盘绑定
map &silent& &leader&ee :e $HOME/.vimrc&cr&
autocmd! bufwritepost *.vimrc source $HOME/.vimrc
" ^z快速进入shell
nmap &C-Z& :shell&cr&
inoremap &leader&n &esc&
" 判断操作系统
if (has("win32") || has("win64") || has("win32unix"))
let g:isWin = 1
let g:isWin = 0
" 判断是终端还是gvim
if has("gui_running")
let g:isGUI = 1
let g:isGUI = 0
set nocompatible
" 关闭兼容模式
syntax enable
" 语法高亮
filetype plugin on
" 文件类型插件
filetype indent on
set shortmess=atI
" 去掉欢迎界面
set autoindent
autocmd BufEnter * :syntax sync fromstart
" 显示行号
set showcmd
" 显示命令
" 当运行宏时,在命令执行完成之前,不重绘屏幕
" 可以在没有保存的情况下切换buffer
set backspace=eol,start,indent
set whichwrap+=&,&,h,l " 退格键和方向键可以换行
set incsearch
" 增量式搜索
set nohlsearch
"set hlsearch
" 高亮搜索
set ignorecase
" 搜索时忽略大小写
" 额,自己:h magic吧,一行很难解释
set showmatch
" 显示匹配的括号
set nobackup
" 关闭备份
"set noswapfile
" 不使用swp文件,注意,错误退出后无法恢复
" 在breakat字符处而不是最后一个字符处断行
" 自动缩进
" 智能缩进
set cindent
" C/C++风格缩进
set wildmenu
set fdl=10
" tab转化为4个字符
set expandtab
set smarttab
set shiftwidth=4
set tabstop=4
" 不使用beep或flash
set vb t_vb=
set background=dark
set t_Co=256
"colorscheme xoria256
set history=400
" vim记住的历史操作的数量,默认的是20
set autoread
" 当文件在外部被修改时,自动重新读取
set mouse=n
" 在所有模式下都允许使用鼠标,还可以是n,v,i,c等
"在gvim中高亮当前行
if (g:isGUI)
set cursorline
colorscheme wombat
hi cursorline guibg=#333333
hi CursorColumn guibg=#333333
"set guifont=Consolas\ 10
"set guifontwide=Consolas\ 10
set guifont=DejaVu\ Sans\ Mono\ 10
set gfw=DejaVu\ Sans\ Mono\ 10
" 不显示toolbar
set guioptions-=T
" 不显示菜单栏
"set guioptions-=m
" 设置字符集编码,默认使用utf8
if (g:isWin)
let &termencoding=&encoding " 通常win下的encoding为cp936
set fileencodings=utf8,cp936,ucs-bom,latin1
set encoding=utf8
set fileencodings=utf8,gb2312,gb18030,ucs-bom,latin1
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&"
execute "normal /" . l:pattern . "&cr&"
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
" 与自动补全中的绑定冲突
"从系统剪切板中复制,剪切,粘贴
map &F7& "+y
map &F8& "+x
map &F9& "+p
" 恢复上次文件打开位置
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)
if bufnr("%") == l:currentBufNum
if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
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
" 插件窗口的宽度,如TagList,NERD_tree等,自己设置
let s:PlugWinSize = 25
" 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
" 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 = "left"
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 &F6& :call Do_CsTag()&cr&
function! Do_CsTag()
let dir = getcwd()
"先删除已有的tags和cscope文件,如果存在且无法删除,则报错。
if ( DeleteFile(dir, "tags") )
if ( DeleteFile(dir, "cscope.files") )
if ( DeleteFile(dir, "cscope.out") )
if(executable('ctags'))
silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
if(executable('cscope') && has("cscope") )
if(g:isWin)
silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs && cscope.files"
silent! execute "!find . -iname '*.[ch]' -o -name '*.cpp' & cscope.files"
silent! execute "!cscope -b"
execute "normal :"
if filereadable("cscope.out")
execute "cs add cscope.out"
" 刷新屏幕
execute "redr!"
endfunction
function! DeleteFile(dir, filename)
if filereadable(a:filename)
if (g:isWin)
let ret = delete(a:dir."\\".a:filename)
let ret = delete("./".a:filename)
if (ret != 0)
echohl WarningMsg | echo "Failed to delete ".a:filename | echohl None
endfunction
" cscope 绑定
if has("cscope")
set csto=1
set nocsverb
if filereadable("cscope.out")
cs add cscope.out
set csverb
" s: C语言符号
d: 这个函数调用的函数 c: 调用这个函数的函数
e: egrep模式
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&
" Quick Fix 设置
map &F3& :cw&cr&
map &F4& :cp&cr&
map &F5& :cn&cr&
" 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.
set numbernmap &silent& &Leader&b :BufExplorer&CR&
" Vimwiki配置
let g:vimwiki_list = [{'path': '~/Dropbox/MyWiki/my_site/',
\ 'path-html': '~/Dropbox/MyWiki/my_site_html/',
\ 'html-header': '~/Dropbox/MyWiki/templates/header.tpl',
\ 'html-footer': '~/Dropbox/MyWiki/templates/footer.tpl'}]
let g:vimwiki_camel_case=0
let wiki = {}
let wiki.path = '~/Dropbox/MyWiki/my_site/'
let wiki.nested_syntaxes = {'python': 'python', 'c++': 'cpp'}
let g:vimwiki_list = [wiki]
"pythoncomplete配置
autocmd filetype python set omnifunc=pythoncomplete#Complete其它可以添加的" Simulate maximize,打开python文件时自动最大化autocmd FileType python setlocal et sta lines=999 columns=999下面两个好像都不行"窗口自动最大化,Linux下需要安装wmctrl
if has("win32")
au GUIEnter * simalt ~x
function Maximize_Window()
silent !wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
endfunction
au GUIEnter * call Maximize_Window()
[/]"一般IDE和很多编辑器都提供command+/快速添加(取消)注释,使用nerdcommenter的ci命令map &c-_& &leader&ci &CR&"多行注释只需要在normal模式下按v并移动光标选择需要注释的行,再按ctrl+/。写&c-_&是由于历史原因Vim不会收到Ctrl+/键盘消息,但多数键盘布局上绑定&c-_&具有同样的效果(你按下 的仍然是Ctrl+/)Vim中显示不可见字符Linux中,cat -A file可以把文件中的所有可见的和不可见的字符都显示出来。在Vim中,可以这样:%!cat -A在Vim中调用cat转换显示。这样的做法不便于编辑。只需要:set invlist即可以将不可见的字符显示出来。或者,你还可以自己定义不可见字符的显示方式:set listchars=eol:$,tab:&-,trail:~,extends:&,precedes:&set list:set nolist可以回到正常的模式。出错解决.vimrc使能鼠标后,vim鼠标右键不能复制在~/.vimrc中加入 set mouse=a 后,vim鼠标右键变得不能复制了,解决办法如下:按住 shift 键,然后选择,此时表示由 X 处理该选择,copy 选项就 enable 了。如果放掉shift键,则由 vim处理该选择。[]from:ref: **[知乎:]
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!

我要回帖

更多关于 vim 跳转到函数定义 的文章

 

随机推荐