VIM类似source insight的用法

前端之家收集整理的这篇文章主要介绍了VIM类似source insight的用法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

install ctags

ctags是taglist插件需要的
sudo apt install ctags

安装插件

vim配置

以下配置项都保存在.vimrc这个配置文件里,可以将此文件替换掉/etc/vim/vimrc这个文件,不过不建议这么做,我们可以将.vimrc这个文件放到当前user目录下面,比如/home/jack

jack@jack-VirtualBox@H_403_26@:~$ ll .@H_403_26@vimrc 
-rw@H_403_26@-rw@H_403_26@-r@H_403_26@--@H_403_26@ 1@H_403_26@ jack jack 3343@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:55@H_403_26@ .@H_403_26@vimrc

vim常规配置

"==================================================@H_403_26@
"Jack Vim Configuration (~/.vimrc)@H_403_26@
"Created by Jack lee. 603557966@qq.com@H_403_26@
"Copyright (c) 2017.All rights reserved.@H_403_26@
"@H_403_26@
"Descriptions:@H_403_26@
"1.Normal settings@H_403_26@
"2.Plugin management@H_403_26@
"==================================================@H_403_26@

"=================================================@H_403_26@
"Normal settings@H_403_26@
"=================================================@H_403_26@
"highlight programa@H_403_26@
Syntax on
"show line num@H_403_26@
set number
"auto indent & C-type indent@H_403_26@
set autoindent
set cindent
"indent width@H_403_26@
set tabstop=4@H_403_26@
set softtabstop=4@H_403_26@
set shiftwidth=4@H_403_26@
set expandtab "expand tab to space@H_403_26@
"switch case asign-type@H_403_26@
set cino=g0,:0@H_403_26@
"use mouse@H_403_26@
"set mouse=a@H_403_26@
"charachter encoding sets@H_403_26@
set fileencodings=ucs-bom,utf-8@H_403_26@,gbk,chinese,cp936

”双引号表示注释

配置taglist

"================================================= "@H_403_26@config taglist
"================================================= "@H_403_26@only show current file@H_403_26@'s tag
let Tlist_Show_One_File=1@H_403_26@
"set taglist width let Tlist_WinWidth=30 "@H_403_26@exit@H_403_26@ vim if@H_403_26@ talist window is@H_403_26@ the@H_403_26@ last@H_403_26@ one
let Tlist_Exit_OnlyWindow=1@H_403_26@
"show taglist window on the left of the vim window let Tlist_Use_Left_Window=1@H_403_26@
@H_403_138@配置SrcExpl
"================================================== "@H_403_26@config SrcExpl
"================================================== "@H_403_26@ //@H_403_26@ The switch@H_403_26@ of@H_403_26@ the Source Explorer 
nmap <F8> :SrcExplToggle<CR> 

" // Set the height of Source Explorer window let g:SrcExpl_winHeight = 8 "@H_403_26@ //@H_403_26@ Set 100@H_403_26@ ms for@H_403_26@ refreshing the Source Explorer 
let@H_403_26@ g@H_403_26@:SrcExpl_refreshTime = 100@H_403_26@ 

" // Set "@H_403_26@Enter" key to jump into the exact definition context let g:SrcExpl_jumpKey = "@H_403_26@<ENTER>" "@H_403_26@ //@H_403_26@ Set "Space"@H_403_26@ key for@H_403_26@ back from the definition context 
let@H_403_26@ g@H_403_26@:SrcExpl_gobackKey = "<SPACE>"@H_403_26@ 

" // In order to avoid conflicts,the Source Explorer should know what plugins "@H_403_26@ //@H_403_26@ except itself are using buffers. And you need add their buffer names into
" // below listaccording to the command "@H_403_26@:buffers!" let g:SrcExpl_pluginList = [ \ "@H_403_26@__Tag_List__",\ "@H_403_26@_NERD_tree_" \ ] "@H_403_26@ //@H_403_26@ Enable/Disable the local definition searching,and@H_403_26@ note that this@H_403_26@ is@H_403_26@ not@H_403_26@
" // guaranteed to work,the Source Explorer doesn't check the Syntax for now. "@H_403_26@ //@H_403_26@ It only searches for@H_403_26@ a match with@H_403_26@ the keyword according to command 'gd'@H_403_26@ 
let@H_403_26@ g@H_403_26@:SrcExpl_searchLocalDef = 1@H_403_26@ 

" // Do not let the Source Explorer update the tags file when opening let g:SrcExpl_isUpdateTags = 0 "@H_403_26@ //@H_403_26@ Use 'Exuberant Ctags'@H_403_26@ with@H_403_26@ '--sort=foldcase -R .'@H_403_26@ or@H_403_26@ '-L cscope.files'@H_403_26@ to 
 " // create/update the tags file let g:SrcExpl_updateTagsCmd = "@H_403_26@ctags --sort=foldcase -R ." "@H_403_26@ //@H_403_26@ Set "<F12>"@H_403_26@ key for@H_403_26@ updating the tags file artificially 
 let@H_403_26@ g@H_403_26@:SrcExpl_updateTagsKey = "<F12>"@H_403_26@ 

 " // Set "@H_403_26@<F3>" key for displaying the prevIoUs definition in the jump list let g:SrcExpl_prevDefKey = "@H_403_26@<F3>" "@H_403_26@ //@H_403_26@ Set "<F4>"@H_403_26@ key for@H_403_26@ displaying the next definition in@H_403_26@ the jump list 
 let@H_403_26@ g@H_403_26@:SrcExpl_nextDefKey = "<F4>"@H_403_26@

配置trinity

"==================================================== "@H_403_26@config trinity(NERD_tree@H_403_26@.vim,trinity.vim)
 "==================================================== "@H_403_26@ Open@H_403_26@ and@H_403_26@ close all the three plugins on the same time 
 nmap <F8@H_403_26@>  :TrinityToggleAll<CR>@H_403_26@

 " Open and close the Source Explorer separately nmap <F9> :TrinityToggleSourceExplorer<CR> "@H_403_26@ Open@H_403_26@ and@H_403_26@ close the Taglist@H_403_26@ separately 
 nmap <F10@H_403_26@> :TrinityToggleTagList<CR>@H_403_26@

 " Open and close the NERD Tree separately nmap <F11> :TrinityToggleNERDTree<CR>@H_403_26@

类似source insight的配置

  • 打开关闭插件的快捷键
    通过Trinity插件可以管理上面安装的插件,按F8打开关闭所有的功能框,F9打开关闭SourceExplorer功能框,F10与F11分别打开关闭taglist和nerdtree插件
  • 类似source insight的工程资源的同步
    先在工程目录下执行ctags -R
$cd@H_403_26@ ..@H_403_26@/project path
$ctags@H_403_26@ -R@H_403_26@

然后用vim打开工程目录下任一个源码文档,就会看到类似source insight的效果,这时可以用鼠标点击或双击某个变量名,或函数名,就看到爽爽的source insight效果
如果在工程下更新修改了某个文档,按下F10(F10的另一个功能)就会自动更新ctags的内容
如果想知道ctags更多使用,可以

$man@H_403_26@ ctags

插件安装

插件下载下来后只有doc和plugin这个目录及其配置文件,将它们也放到当前user目录下的.vim目录里即可,如下所示:

jack@jack-VirtualBox@H_403_26@:~$ ll .@H_403_26@vim
total 20@H_403_26@
drwxr-xr@H_403_26@-x@H_403_26@  4@H_403_26@ jack jack 4096@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ .@H_403_26@/@H_403_26@
drwxr-xr@H_403_26@-x@H_403_26@ 17@H_403_26@ jack jack 4096@H_403_26@ 7@H_403_26@月   3@H_403_26@ 15@H_403_26@:01@H_403_26@ ..@H_403_26@/@H_403_26@
drwxrwxr-x@H_403_26@  2@H_403_26@ jack jack 4096@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ doc/@H_403_26@
-rw@H_403_26@-rw@H_403_26@-r@H_403_26@--@H_403_26@  1@H_403_26@ jack jack  136@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ .@H_403_26@netrwhist
drwxrwxr-x@H_403_26@  2@H_403_26@ jack jack 4096@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ plugin/@H_403_26@
jack@jack-VirtualBox@H_403_26@:~$ ll .@H_403_26@vim/doc
total 92@H_403_26@
drwxrwxr-x@H_403_26@ 2@H_403_26@ jack jack  4096@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ .@H_403_26@/@H_403_26@
drwxr-xr@H_403_26@-x@H_403_26@ 4@H_403_26@ jack jack  4096@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ ..@H_403_26@/@H_403_26@
-rw@H_403_26@-rw@H_403_26@-r@H_403_26@--@H_403_26@ 1@H_403_26@ jack jack 14573@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ srcexpl.@H_403_26@txt
-rw@H_403_26@-rw@H_403_26@-r@H_403_26@--@H_403_26@ 1@H_403_26@ jack jack 69366@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ taglist.@H_403_26@txt
jack@jack-VirtualBox@H_403_26@:~$ ll .@H_403_26@vim/plugin
total 336@H_403_26@
drwxrwxr-x@H_403_26@ 2@H_403_26@ jack jack   4096@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ .@H_403_26@/@H_403_26@
drwxr-xr@H_403_26@-x@H_403_26@ 4@H_403_26@ jack jack   4096@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ ..@H_403_26@/@H_403_26@
-rw@H_403_26@-rw@H_403_26@-r@H_403_26@--@H_403_26@ 1@H_403_26@ jack jack 115607@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ NERD_tree.@H_403_26@vim
-rw@H_403_26@-rw@H_403_26@-r@H_403_26@--@H_403_26@ 1@H_403_26@ jack jack  47611@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ srcexpl.@H_403_26@vim
-rw@H_403_26@-rw@H_403_26@-r@H_403_26@--@H_403_26@ 1@H_403_26@ jack jack 147930@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ taglist.@H_403_26@vim
-rw@H_403_26@-rw@H_403_26@-r@H_403_26@--@H_403_26@ 1@H_403_26@ jack jack  13976@H_403_26@ 7@H_403_26@月   3@H_403_26@ 14@H_403_26@:54@H_403_26@ trinity.@H_403_26@vim

我习惯用的几个快捷键

命令行模式下

输入G直接定位到文档的最后;输入gg直接回到文档的开头

打开即跳到指定行

vim xxx.txt +100 //打开后光标直接定位到第100行,如果没有100行,就是文档最后

在命令行模式下

/ 搜索某个字符,然后按n查下一个,按N查上一个
N,N为行号,也可跳到指定行
:set mouse=a这是启用鼠标功能
其他还有一些基本操作快捷键,如x,xx,i,a,y,p等等用于删除,输入,复制,黏贴

ubuntu多标签终端

shift+ctrl+t不同于常规的alt+ctrl+t

制作好的配置插件,下载后直接放到user下面

http://download.csdn.net/detail/js_gary/9887411

猜你在找的Bash相关文章