Explore Linux Source Code by vim === ###### tags: `linux` `vim` `cscope` `ctags` ## cscope Create 'cscope.sh' under 'linux-5.10.1/',and copy the below text to 'cscope.sh': #!/bin/sh find ./ -name "*.c" -o -name "*.h" -o -name "*.cpp" > cscope.files cscope -Rbqk -i cscope.files Execute the script: ./cscope.sh It will create cscope.file, and then cscope.out, cscopt.po.out, cscopt.in.out ## ctag Type the following command under 'linux-5.10.1/', it will create a file called 'tags' sudo ctags -R * ![](https://i.imgur.com/ewKDbia.png) ## ~/.vimrc add the below text to ~/.vimrc 將"/home/user/Downloads/linux-5.10.1"取代為實際的linux source路徑 set tags=/home/user/Downloads/linux-5.10.1/tags ~/.vimrc looks like: execute pathogen#infect() syntax on filetype plugin indent on set tags=/home/user/Downloads/linux-5.10.1/tags set number set hlsearch set bg=dark hi Comment ctermfg=green nmap zs :cs find s <C-R>=expand("<cword>")<CR><CR> nmap zg :cs find g <C-R>=expand("<cword>")<CR><CR> nmap zc :cs find c <C-R>=expand("<cword>")<CR><CR> nmap zd :cs find d <C-R>=expand("<cword>")<CR><CR> nmap zt :cs find t <C-R>=expand("<cword>")<CR><CR> nmap ze :cs find e <C-R>=expand("<cword>")<CR><CR> nmap zf :cs find f <C-R>=expand("<cfile>")<CR><CR> nmap zi :cs find i <C-R>=expand("<cfile>")<CR><CR> ## vim Go to the folder 'linux-5.10.1/', and open vim: vim Type the following command in vim's cmd mode: :NERDTree :cs add cscope.out Now you can explore linux by vim: ![](https://i.imgur.com/KnvAc1N.png) ![](https://i.imgur.com/lZCvgPR.png)