红联Linux门户
Linux帮助

vim配置方便浏览linux内核文件

发布时间:2015-12-25 15:27:42来源:linux网站作者:疯雨

1.安装ctags+cscope


2.下载vim插件 Source Explorer/NERD Tree/Tag List

网址:www.vim.org  Scrips-->Bowse all -->在keyword中搜索上述三个插件并下载解压到~/.vim文件夹下


3.vim 配置

打开vim配置文件,(ubuntu是在/etc/vim/vimrc中),在最后添加如下内容:

"------------------------------------------" 
"vim env setting" 
"------------------------------------------" 
set nu  "display line number" 
set ai  "auto indent" 
set ts=4"tab size" 
set bg=dark "blackground color" 
filetype plugin on 
 
"------------------------------------------" 
"ctags database setting" 
"------------------------------------------" 
set tags=/home/software/linux-3.8.3/tags "ctags DB position 根据自己的文件路劲进行修改" 
 
"------------------------------------------" 
"ctags database setting" 
"------------------------------------------" 
set csprg=/usr/bin/cscope"cscope install position" 
set csto=0   "cscope DB search first" 
set cst  "cscope DB tag DB search" 
set nocsverb "verbose off" 
 
cs add /home/software/linux-3.8.3/cscope.out   /home/software/linux-3.8.3   "根据自己的文件路径进行修改" 
set csverb  
 
"------------------------------------------" 
"Tap List env setting" 
"------------------------------------------" 
filetype on 
nmap <F7> :TlistToggle<CR> 
let Tlist_Ctags_Cmd = "/usr/bin/ctags" 
let Tlist_Inc_Winwidth = 0 
let Tlist_Exit_OnlyWindow = 0 
let Tlist_Auto_Open = 0 
let Tlist_Use_Right_Window = 1 
 
"------------------------------------------" 
"Source explorer env setting" 
"------------------------------------------" 
nmap <F8> :SrcExplToggle<CR> 
nmap <C-H> <C-W>h 
nmap <C-J> <C-W>j 
nmap <C-K> <C-W>k 
nmap <C-L> <C-W>l 
 
let g:SrcExpl_WinHeight = 8 
let g:SrcExpl_refreshTime = 100 
let g:SrcExpl_jumpkey = "<ENTER>" 
let g:SrcExpl_gobackKey = "<SPACE>" 
let g:SrcExpl_isUpdateTags = 0 
 
"------------------------------------------" 
"NERD Tree env setting" 
"------------------------------------------" 
let NERDTreeWinPos = "left" 
nmap <F9> :NERDTreeToggle<CR> 
 
" Open and close all the three plugins on the same time 
"nmap <F8>   :TrinityToggleAll<CR> 
 
" Open and close the srcexpl.vim separately 
"nmap <F9>   :TrinityToggleSourceExplorer<CR> 
 
" Open and close the taglist.vim separately 
"nmap <F10>  :TrinityToggleTagList<CR> 
 
" Open and close the NERD_tree.vim separately 
"nmap <F11>  :TrinityToggleNERDTree<CR> 
 
" --------------------------------------------------- 
 
"  < 编写文件时的配置 > 
 
" --------------------------------------------------- 
 
filetype on   "启用文件类型侦测 
 
filetype plugin on"针对不同的文件类型加载对应的插件 
 
filetype plugin indent on "启用缩进 
 
set smartindent   "启用智能对齐方式 
 
set expandtab "将Tab键转换为空格 
 
set tabstop=4 "设置Tab键的宽度,可以更改,如:宽度为2 
 
set shiftwidth=4  "换行时自动缩进宽度,可更改(宽度同tabstop) 
 
set smarttab  "指定按一次backspace就删除shiftwidth宽度 
 
set foldenable"启用折叠 
 
"set foldmethod=indent "indent 折叠方式 
" 常规模式下用空格键来开关光标行所在折叠(注:zR 展开所有折叠,zM 关闭所有折叠) 
 
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR> 
 
" 当文件在外部被修改,自动更新该文件 

set autoread 

" 语法高亮 
set syntax=on 


4.进入linux 内核顶层目录

make tags  ARCH=arm

make cscope ARCH=arm


5.使用方法

在终端输入vim

依次输入F7/F8/F9


Linux kernel 3.0内核文件系统EXT4与Btrfs测试比较:http://www.linuxdiyf.com/linux/6686.html

几个重要的Linux内核文件介绍:http://www.linuxdiyf.com/linux/106.html