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:~$ ll .vimrc 
-rw-rw-r-- 1 jack jack 3343 73 14:55 .vimrc

vim常规配置

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

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

”双引号表示注释

配置taglist

"================================================= "config taglist
"================================================= "only show current file's tag
let Tlist_Show_One_File=1
"set taglist width let Tlist_WinWidth=30 "exit vim if talist window is the last one
let Tlist_Exit_OnlyWindow=1
"show taglist window on the left of the vim window let Tlist_Use_Left_Window=1

配置SrcExpl

"================================================== "config SrcExpl
"================================================== " // The switch of the Source Explorer 
nmap <F8> :SrcExplToggle<CR> 

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

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

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

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

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

配置trinity

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

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

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

类似source insight的配置

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

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

$man ctags

插件安装

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

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

原文链接:https://www.f2er.com/bash/392305.html

猜你在找的Bash相关文章