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 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> vim+cscope阅读源码 -> 正文阅读

[开发工具]vim+cscope阅读源码

vim+cscope阅读源码

前言

做嵌入式开发时,可以使用vim+cscope打造一个舒适的源码阅读环境。
1.添加自定义的vim配置文件使vim更易用。
2.cscope是查看代码的利器。可以定位函数、变量定义及被引用的代码位置。

1 vim配置文件

Vim 启动时,会根据配置文件(.vimrc)来设置 Vim,因此我们可以通过此文件来定制适合自己的 Vim。
Vim 配置文件分为系统配置文件和用户配置文件:

  • 系统配置文件位于 Vim 的安装目录(默认路径为 /etc/.vimrc);
  • 用户配置文件位于主目录 ~/.vimrc,即通过执行 vim ~/.vimrc 命令即可对此配置文件进行合理修改。通常情况下,Vim 用户配置文件需要自己手动创建。

注意,Vim 用户配置文件比系统配置文件的优先级高,换句话说,Vim 启动时,会优先读取 Vim 用户配置文件(位于主目录中的),所以我们只需要修改用户配置文件即可(不建议直接修改系统配置文件)。

我使用的.vimrc文件配置:

" 显示命令菜单
set wildmenu
" 打开行号
set number
" 不使用兼容模式
set nocompatible
" 自动缩进
set autoindent
" 历史记录条数
set history=50
" 在Vim窗口的右下角显示当前光标位置
set ruler
" 会在输入命令时,在屏幕底部显示出部分命令
set showcmd
" 实时匹配搜索输入
set incsearch
" 开启自动缩进
set ai
" 设置匹配模式,类似当输入一个左括号时会匹配相应的右括号
set showmatch
" 在底部显示当前模式
set showmode
" 对搜索词高亮显示
set hlsearch
" terminal Color,默认是8色
set t_Co=8
set cino=:0
"c语言缩进风格
set cindent

"打开语法高亮
colo ron
syntax on

"-- set tab \t space
set shiftwidth=4                
set backspace=2
set tabstop=4
set expandtab
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CSCOPE settings for vim           
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    set csto=0
    " add any cscope database in current directory
    if filereadable("cscope.out")
    	cs add cscope.out  
    "else add the database pointed to by environment variable 
    elseif $CSCOPE_DB != ""
       cs add $CSCOPE_DB
    endif

    " show msg when any other cscope db added
    set cscopeverbose  

    """"""""""""" My cscope/vim key mappings
    "
    " The following maps all invoke one of the following cscope search types:
    "
    "   's'   symbol: find all references to the token under cursor
    "   'g'   global: find global definition(s) of the token under cursor
    "   'c'   calls:  find all calls to the function name under cursor
    "   't'   text:   find all instances of the text under cursor
    "   'e'   egrep:  egrep search for the word under cursor
    "   'f'   file:   open the filename under cursor
    "   'i'   includes: find files that include the filename under cursor
    "   'd'   called: find functions that function under cursor calls
    "
    " To do the first type of search, hit 'CTRL-\', followed by one of the
    " cscope search types above (s,g,c,t,e,f,i,d).  The result of your cscope
    " search will be displayed in the current window.  You can use CTRL-T to
    " go back to where you were before the search.  
    "
    nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>	
    nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>	
    nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
    nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>	

2 使用cscope

安装cscope

sudo apt-get install cscope

cscope的用法很简单,首先需要为你的代码生成一个cscope数据库:

cscope -Rbkq 

-R:为当前目录下所有子目录创建数据库
-b:生成数据库之后退出,不启动自带界面
-q:生成cscope.in.out和cscope.po.out,加快搜索速度
-k:跳过/usr/include目录

在vim可以输入以下命令:

:cs f g start_kernel  看函数start_kernel 定义的地方
:cs f c start_kernel	看哪些地方调用start_kernel函数

如果看到函数代码后需要了解定义和调用的地方:

1.光标移到该函数 
2.ctrl+\ 抬起来g   看函数定义的地方
3.ctrl+\ 抬起来c    看哪些地方调用函数
  开发工具 最新文章
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-12-25 11:29:10  更:2022-12-25 11:30:40 
 
开发: 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年7日历 -2024/7/27 8:21:25-

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