vim编辑器中cscope自动加载cscope.out文件的方法
方法一 :vim 插件——autoload_cscope.vim
步骤:
插件下载地址:autoload_cscope.vim
下载之后,讲autoload_cscope.vim
放到~/.vim/plugin
目录下,如果没有该目录那就创建一个,重新打开终端即可。
优点:
有人维护(不过貌似很久没有更新了),稳定。
缺点:
只对*.c/*.h
等代码文件有效,对一些辅助文件(例如Makefile)无效。
补充:
下面贴上代码,方便下载不成功时,可以直接复制到空文件中,并改名为autoload_cscope.vim
,并按上述方法处理即可。
" Vim global plugin for autoloading cscope databases.
" Last Change: Wed Jan 26 10:28:52 Jerusalem Standard Time 2011
" Maintainer: Michael Conrad Tadpol Tilsra <tadpol@tadpol.org>
" Revision: 0.5if exists("loaded_autoload_cscope")finish
endif
let loaded_autoload_cscope = 1" requirements, you must have these enabled or this is useless.
if( !has('cscope') || !has('modify_fname') )finish
endiflet s:save_cpo = &cpo
set cpo&vim" If you set this to anything other than 1, the menu and macros will not be
" loaded. Useful if you have your own that you like. Or don't want my stuff
" clashing with any macros you've made.
if !exists("g:autocscope_menus")let g:autocscope_menus = 1
endif"==
" windowdir
" Gets the directory for the file in the current window
" Or the current working dir if there isn't one for the window.
" Use tr to allow that other OS paths, too
function s:windowdir()if winbufnr(0) == -1let unislash = getcwd()else let unislash = fnamemodify(bufname(winbufnr(0)), ':p:h')endifreturn tr(unislash, '\', '/')
endfunc
"
"==
" Find_in_parent
" find the file argument and returns the path to it.
" Starting with the current working dir, it walks up the parent folders
" until it finds the file, or it hits the stop dir.
" If it doesn't find it, it returns "Nothing"
function s:Find_in_parent(fln,flsrt,flstp)let here = a:flsrtwhile ( strlen( here) > 0 )if filereadable( here . "/" . a:fln )return hereendiflet fr = match(here, "/[^/]*$")if fr == -1breakendiflet here = strpart(here, 0, fr)if here == a:flstpbreakendifendwhilereturn "Nothing"
endfunc
"
"==
" Cycle_macros_menus
" if there are cscope connections, activate that stuff.
" Else toss it out.
" TODO Maybe I should move this into a seperate plugin?
let s:menus_loaded = 0
function s:Cycle_macros_menus()if g:autocscope_menus != 1returnendifif cscope_connection()if s:menus_loaded == 1returnendiflet s:menus_loaded = 1set csto=0set cstsilent! map <unique> <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>silent! map <unique> <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>silent! map <unique> <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>silent! map <unique> <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>silent! map <unique> <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>silent! map <unique> <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>silent! map <unique> <C-\>f :cs find f <C-R>=expand("<cword>")<CR><CR>silent! map <unique> <C-\>i :cs find i <C-R>=expand("<cword>")<CR><CR>if has("menu")nmenu &Cscope.Find.Symbol<Tab><c-\\>s\ :cs find s <C-R>=expand("<cword>")<CR><CR>nmenu &Cscope.Find.Definition<Tab><c-\\>g\ :cs find g <C-R>=expand("<cword>")<CR><CR>nmenu &Cscope.Find.Called<Tab><c-\\>d\ :cs find d <C-R>=expand("<cword>")<CR><CR>nmenu &Cscope.Find.Calling<Tab><c-\\>c\ :cs find c <C-R>=expand("<cword>")<CR><CR>nmenu &Cscope.Find.Assignment<Tab><c-\\>t\ :cs find t <C-R>=expand("<cword>")<CR><CR>nmenu &Cscope.Find.Egrep<Tab><c-\\>e\ :cs find e <C-R>=expand("<cword>")<CR><CR>nmenu &Cscope.Find.File<Tab><c-\\>f\ :cs find f <C-R>=expand("<cword>")<CR><CR>nmenu &Cscope.Find.Including<Tab><c-\\>i\ :cs find i <C-R>=expand("<cword>")<CR><CR>
" nmenu &Cscope.Add :cs add
" nmenu &Cscope.Remove :cs kill nmenu &Cscope.Reset :cs reset<cr>nmenu &Cscope.Show :cs show<cr>" Need to figure out how to do the add/remove. May end up writing" some container functions. Or tossing them out, since this is supposed" to all be automatic.endifelselet s:menus_loaded = 0set nocstsilent! unmap <C-\>ssilent! unmap <C-\>gsilent! unmap <C-\>dsilent! unmap <C-\>csilent! unmap <C-\>tsilent! unmap <C-\>esilent! unmap <C-\>fsilent! unmap <C-\>iif has("menu") " would rather see if the menu exists, then remove...silent! nunmenu Cscopeendifendif
endfunc
"
"==
" Unload_csdb
" drop cscope connections.
function s:Unload_csdb()if exists("b:csdbpath")if cscope_connection(3, "out", b:csdbpath)let save_csvb = &csverbset nocsverbexe "cs kill " . b:csdbpathset csverblet &csverb = save_csvbendifendif
endfunc
"
"==
" Cycle_csdb
" cycle the loaded cscope db.
function s:Cycle_csdb()if exists("b:csdbpath")if cscope_connection(3, "out", b:csdbpath)return"it is already loaded. don't try to reload it.endifendiflet newcsdbpath = s:Find_in_parent("cscope.out",s:windowdir(),$HOME)
" echo "Found cscope.out at: " . newcsdbpath
" echo "Windowdir: " . s:windowdir()if newcsdbpath != "Nothing"let b:csdbpath = newcsdbpathif !cscope_connection(3, "out", b:csdbpath)let save_csvb = &csverbset nocsverbexe "cs add " . b:csdbpath . "/cscope.out " . b:csdbpathset csverblet &csverb = save_csvbendif"else " No cscope database, undo things. (someone rm-ed it or somesuch)call s:Unload_csdb()endif
endfunc" auto toggle the menu
augroup autoload_cscopeau!au BufEnter *.[chly] call <SID>Cycle_csdb() | call <SID>Cycle_macros_menus()au BufEnter *.cc call <SID>Cycle_csdb() | call <SID>Cycle_macros_menus()au BufUnload *.[chly] call <SID>Unload_csdb() | call <SID>Cycle_macros_menus()au BufUnload *.cc call <SID>Unload_csdb() | call <SID>Cycle_macros_menus()
augroup ENDlet &cpo = s:save_cpo
方法二 :.vimrc脚本法
步骤:
在~/.vimrc
文件中添加如下内容后,保存即可。
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cscope 自动加载cscope.out文件
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("cscope") set csprg=/usr/bin/cscope set csto=0 set cst set csverb set cspc=3 "add any database in current dir if filereadable("cscope.out") cs add cscope.out "else search cscope.out elsewhere else let cscope_file=findfile("cscope.out",".;") let cscope_pre=matchstr(cscope_file,".*/") if !empty(cscope_file) && filereadable(cscope_file) set nocsverbexe "cs add" cscope_file cscope_preset csverbendif endif
endif
优点
对目标目录下所有文件有效。包括Makefile
等辅助文件等。
缺点
目前没有发现缺点。
vim编辑器中cscope自动加载cscope.out文件的方法相关推荐
- ThinkPHP 3.2.3 自动加载公共函数文件的方法
方法一.加载默认的公共函数文件 在 ThinkPHP 3.2.3 中,默认的公共函数文件位于公共模块 ./Application/Common 下,访问所有的模块之前都会首先加载公共模块下面的配置文件 ...
- yii2 引入php文件,Yii2中YiiBase自动加载类、引用文件方法分析(autoload)
本文实例分析了Yii2中YiiBase自动加载类.引用文件的方法.分享给大家供大家参考,具体如下: 在Yii2中这个函数是用来加载类的,没有直接引用文件的相关实现.但是这个也可以用来引用文件. pub ...
- php自动加载基类文件
原文地址 问题描述 偶尔我们可能不使用php框架写一些代码,会自己写一个框架或者包,这时一般会涉及多个文件. 这种情况下,如果只使用命名空间是不能加载其他需要的文件的. 使用php的 spl_auto ...
- android 加载三方so的方法_Android开发教程之动态加载so库文件的方法
Android开发教程之动态加载so库文件的方法,我想对于静态加载 so 库文件,大家都已经很熟悉了,这里就不多说了.在 Android 开发中调用动态库文件(*.so)都是通过 jni 的方式,而静 ...
- 在 AutoCAD 中如何自动加载 DLL
问题: 您创建或使用的应用程序存储在 DLL 文件中,但在自动加载的情况下,APPLOAD 函数不允许添加此类文件. 如何自动加载此类文件? 解决方案: A:要自动加载 DLL 文件,您可以按照以下步 ...
- [PHP] 项目实践中的自动加载实现
1.使用spl_autoload_register函数注册一个自己定义的自动加载函数 2.当在代码中new一个不存在的类的时候,上面的函数会被调用,不存在的类名会被作为参数传入该函数中 3.兼容了两种 ...
- php自动加载原理,php中的自动加载类机制原理
PHP最早讀取套件的方法 初學PHP時,最早會面對的問題之一就是require與include差別何在? require_once與include_once又是什麼? 弄懂這些問題之後,如果不使用fr ...
- Jquery中使用JsonP加载本地json文件解决跨域问题
场景 jquery中直接请求本地json文件时会提示跨域问题. Jsonp(JSON with Padding) 是 json 的一种"使用模式",可以让网页从别的域名(网站)那获 ...
- Unity中游戏重新加载玩家位置不变的方法
在玩游戏时,有时候会遇见需要保存玩家位置,这种游戏在做游戏和玩游戏时还是很常见的,那么我们是如何来保存玩家的位置,以做到让玩家下次加载时不会受到位置的丢失.下面是我在游戏中的解决方法. 1.先看下我做 ...
最新文章
- kubernetes ConfigMap
- 工业组态领头羊--组态王开始涉足.net程序开发(与林伟先生一次近距离接触)...
- java 并发包学习_Java学习笔记—多线程(java.util.concurrent并发包概括,转载)
- ubuntu权限管理
- 为了方便大家下载四级资料,开通FTP
- E. Pattern Matching(题意理解+拓扑排序)
- 安卓系统挂载NTFS格式硬盘_苹果电脑挥之不去的烦恼!怎样兼容NTFS格式的U盘移动硬盘?...
- node升级命令_Vue CLI 4 发布:自动化升级过程,支持自定义包管理器
- 前端知识点查文档网站
- 常见工具识别集锦---Windows应急响应工具
- 基于MATLAB/Simulink的电力电子电路仿真技术——直流降压(Buck)变换器及Powergui的使用
- android studio基础教程:2.程序在哪写
- Microsoft Teams安装教程
- Git学习之旅--撤销与删除
- 区块链大讲堂第一期丨什么是区块链?怎样通俗的理解区块链?
- 数据产品经理修炼手册_AI产品经理之数据标注
- linux安装——管理应用程序
- MATLAB科学计算机lnx代码,[2018年最新整理]Matlab科学计算.ppt
- 选型帮推荐:上海音锋机器人【托盘四向车】
- 地下水动力学--地下水水文学(持续更新)
热门文章
- 数字图像处理 第三章 图像变换
- PHP实现文本快速查找 - 二分查找法
- Android商城开发系列
- Python mac运行pygame一片空白不显示内容-解决方案
- 2019中科实数杯( Q1内存镜像取证分析、Q4加密磁盘分析)
- PHP模块加载失败:PHP Warning: Module ‘modulename‘ already loaded in Unknown on line 0
- 极速系列04—python批量获取word/PDF/网页中的表格
- Python遥感可视化 — folium模块展示热力图
- web前端学习css“北方高温“案例
- ThinkServer RD640 设置RAID1