IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> Ctags Cscope and Vim -> 正文阅读

[开发工具]Ctags Cscope and Vim

Ctags and expecially Cscope in combination with Vim can really boost productivity when working with home-grown and foreign source-trees.

Both tools basically generate references out of source-files, which can be used to locate and cross-reference source-symbols.

While Cscope does come with its own curses-based UI, Vim provides a really nice interface to either tool.

Installation
Ctags
In Arch Linux, package ctags is actually Exuberant Ctags. The binary is called ‘ctags’.

In NetBSD, you can use ctags in base, or Exuberant Ctags (‘exctags’ in pkgsrc). The latter generates more tags; e.g. simple C functions are not (always?) found using the ctags in base.

Cscope
in Arch Linux, package cscope is in the standard repository. From what I can see, it’s available as NetBSD package as well.

As far as I can see, there is just 1 flavour of Cscope.

Create database
vanilla Ctags (NetBSD base)
go to the dir you want to work in (does not have to be the root of a project-source)
ctags -d -t $( find $root_of_tree -name *.c -o -name *.h ) will create file tags
Exuberant Ctags
go to the dir you want to work in
exctags $( find $root_of_tree -name *.c -o -name *.h )
Helper-script to generate tags for C-files in multiple given dirs (recursive):

#!/usr/bin/bash
    
dirs=$*
[ -n "$dirs" ]  ||  dirs=.
    
rm -f tags
    
for d in $dirs; do
    ctags -a $( find $d -name \*.c -o -name \*.h )
done

Cscope
go to the dir you want to work in
SOURCEDIRS=/some/where:/else/where:… cscope -b -R will create file cscope.out
(For non-native source-trees, -k (‘kernel’) can be given to exclude system include-dirs - ‘/usr/include’ etc - from trying to locate #included files.)

(To generate ASCII-only cscope.out files, add the -c switch. This makes it easier to debug Cscope-lookup, when e.g. lookup of a symbol fails.)

Use in Vim
Ctags
see :help ctags for more info - this here is not complete by far
set ‘tags’ (:help tags-option) to /.tags,tags,~/tags. This searches in the current file’s dir first, then in the dir from which Vim was started, then in the home-dir. (By default, ‘tags’ may not include the start-dir as location.)
jump to definition using ^] and jump back using ^o
(:h tagsrch.txt if interested)
Cscope
see :help cscope for more info
if necessary, manually add generated database-files using :cs add /some/where/cscope.out.
if cscopetag is set, all/most tag-related commands will use Cscope-tags instead of ctag ones.
To automate things a bit, I use the following snippet in .vimrc (as found somewhere on the net - thank you, original author):

if has("cscope")
    set csprg=/usr/bin/cscope
    set csto=0
    set cst
    set nocsverb
    " add any database in current directory
    if filereadable("cscope.out")
        cs add cscope.out . -C                            (*)
    " else add database pointed to by environment
    elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB . -C                            (*)
    endif
    set csverb
    " 0 or s: Find this C symbol
    " 1 or g: Find this definition
    " 2 or d: Find functions called by this function
    " 3 or c: Find functions calling this function
    " 4 or t: Find this text string
    " 6 or e: Find this egrep pattern
    " 7 or f: Find this file
    " 8 or i: Find files #including this file
      nmap <C-m>s :cs find s <C-R>=expand("<cword>")<CR><CR>
      nmap <C-m>g :cs find g <C-R>=expand("<cword>")<CR><CR>
      nmap <C-m>c :cs find c <C-R>=expand("<cword>")<CR><CR>
      nmap <C-m>t :cs find t <C-R>=expand("<cword>")<CR><CR>
      nmap <C-m>e :cs find e <C-R>=expand("<cword>")<CR><CR>
      nmap <C-m>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
      nmap <C-m>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
      nmap <C-m>d :cs find d <C-R>=expand("<cword>")<CR><CR>
endif

…which basically does the following:

prefer Cscope DB over ctags tags if both are present

set cscopetag as hinted above

add cscope.out in current dir or environment-given dir.

(*): the -C flag (search case-insensitive) and dummy . dir necessary to add that flag. Case-insensitive search is what you (or at least I) always want, really.

set some convenient mappings: +letter to issue queries.

See either Vim or Cscope docs (or the comment, above) for different types of queries.

Have fun!

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2022-05-18 17:51:32  更:2022-05-18 17:52:03 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/14 15:09:22-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码