VIM1、vim 下实现代码像 source insight 一样的跳转功能2、ctags 更多精美的配置本文来自http://www.cnblogs.com/feisky/archive/2012/02/07/2341932.html1、生成标签文件2、跳转3、在 vim中输入:Tlist即可自动的开/关切换4、这位朋友的 .vimrc3、vimdiff 的使用A、打开方式B、符号意义C、差异跳转D、左右窗口内容复制E、退出vimdiffF、选中并且复制单词4、字符串替换5、列编辑,如全部注释6、vim 中清除 ^M,实测第四种方法可行7、vim 打开文件后,指定行范围替换8、vim 打开二进制文件后,以二进制方式查看
1、首先要下载到 ctags.
因为 taglist 基于 ctags,或到 http://share.wishcell.cn/2018/2018-01.html 下载
2、解压后将插件脚本文件(.vim)和帮助文件(.txt)分别放入vim常用目录
下载到的压缩包为:
taglist_46.zip解压之:
[root@localhost packages]# mkdir tmp[root@localhost packages]# unzip -n taglist_46.zip -d ./tmp/Archive: taglist_46.zipinflating: ./tmp/plugin/taglist.viminflating: ./tmp/doc/taglist.txt将其解压到指定目录 ./tmp下面,然后将 脚本文件
.vim和帮助文件.txt分别放入常用目录:
$HOME/.vim/或者$HOEM/vimfiles/或者$VIM/vimfiles下面的plugin/taglist.vim
/doc/taglist.txt然后重启 vim.
x[root@localhost .vim]# ls /packages/tmp/plugin/taglist.vim[root@localhost .vim]# cp /packages/tmp/plugin/taglist.vim ./[root@localhost .vim]# pwd/home/wishcell/.vim[wishcell@localhost .vim]$ mkdir ~/.vim/doc/[wishcell@localhost .vim]$ cp /packages/tmp/doc/taglist.txt ~/.vim/doc/[wishcell@localhost .vim]$ ls /packages/tmp/doc/taglist.txt[wishcell@localhost .vim]$3、导入帮助文件
xxxxxxxxxx:helptags ~/.vim/doc执行完毕后,帮助文件已经被导入。然后使用
xxxxxxxxxx:help taglist.txt来详细查看手册
xxxxxxxxxxtaglist.txt Plugin for browsing source codeAuthor: Yegappan Lakshmanan (yegappan AT yahoo DOT com)For Vim version 6.0 and aboveLast change: 2013 Feburary 261. Overview taglist-intro2. Taglist on the internet taglist-internet3. Requirements taglist-requirements4. Installation taglist-install5. Usage taglist-using6. Options taglist-options7. Commands taglist-commands8. Global functions taglist-functions9. Extending taglist-extend10. FAQ taglist-faq11. License taglist-license12. Todo taglist-todo==============================================================================taglist.txt [Help][RO] 1,1 Top} else {study/c/EasyLogger/easylogger/src/elog.c 644,1 99%"taglist.txt" [readonly] 1515L, 69979C4、正式使用
A、在vim中,打开
taglist窗口使用xxxxxxxxxx:TlistOpen得到这样的窗口:左侧窗口,光标在函数上,可上下移动。先中一个回车,即跳到相应函数
B、在vim中,关闭
taglist窗口使用xxxxxxxxxx:TlistClose问题:
xxxxxxxxxx执行 :Tlist (:TlistOpen, :TlistToggle) 命令后,得到错误提示:E488: Trailing characters由于太复杂,只得放弃跟踪5、多种使用选项,快捷键
- 回车`---跳到光标所在代码处。即光标在哪个函数。回车后就跳上
o--- 新开一个窗口,显示 tag 的内容。与 source Insight 很像了
u--- 更新 taglist 窗口中的 tag
s---两种排序方式切换:名称排序/出现顺序
x--- taglist 窗口放大/缩小,方便查看较长的 tag
<space>---空格,在下文显示当前 tag 的定义。
+---打开一个折叠,同zo
----将一个 tag 折叠起来,同zc
*--- 打开所有的折叠,同zR
=---将所有 tag 折叠起来,同zM
[[---跳到前一个文件
]]---跳到下一个文件
q---关闭taglist窗口
<F1>显示帮助6、其它可以在
vimrc脚本中添加的功能xxxxxxxxxx"设置ctags路径let Tlist_Ctags_Cmd = '/usr/bin/ctags'"启动vim后自动打开taglist窗口let Tlist_Auto_Open = 1"不同时显示多个文件的tag,仅显示一个let Tlist_Show_One_File = 1"taglist为最后一个窗口时,退出vimlet Tlist_Exit_OnlyWindow = 1"taglist窗口显示在右侧,缺省为左侧let Tlist_Use_Right_Window =1"设置taglist窗口大小"let Tlist_WinHeight = 100let Tlist_WinWidth = 40"设置taglist打开关闭的快捷键F8noremap <F8> :TlistToggle<CR>"更新ctags标签文件快捷键设置noremap <F6> :!ctags -R<CR>
还有许多其他的设置,请参考帮助文档:help taglist.txt 其英文原版手册: http://vim-taglist.sourceforge.net/manual.html
在当前目录下(运行$提示符后面的命令):
xxxxxxxxxx$ctags -R .-R表示recursive,递归,为当前目录及其子目录中的c文件生成标签文件。最后一个.表示在当前目录。
运行完当前目录会多一个文件tags,就是c标签的索引文件。
1.用vim打开一个已经建过标签的c文件
ctrl+]找到光标所在位置的标签定义的地方ctrl+t回到跳转之前的标签处 注意:此时运行vim,必须在"tags"文件所在的目录下运行。否则,运行它会找不到"tags"文件,而需要在vim中用":set tags="命令设定"tags"文件的路径。对于一个稍微大点的项目,你可能在任何一个目录下打开vim,然而在每个目录下都生成一个tags文件并不 是个好主意,那么如何解决呢?方法是在.vimrc中增加一行:
xxxxxxxxxxset tags=tags;/这是告诉vim在当前目录找不到tags文件时请到上层目录查找。
vim中输入:Tlist即可自动的开/关切换一个简单的方法是设定快捷键,在.vimrc中增加一行:
nnoremap <silent> <F8> :TlistToggle<CR>这样在vim中按F8就可以打开/关闭taglist了。
更多相关配置请看后面关于.vimrc的介绍。
.vimrcxxxxxxxxxx".vimrc"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" General""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""For ctags, then it can find the 'tags' file even not in current directoryset tags=tags;/"Get out of VI's compatible mode..set nocompatible"Sets how many lines of history VIM har to rememberset history=400"Set to auto read when a file is changed from the outsideset autoread"Have the mouse enabled all the time:"when you need to copy from vim, maybe you have to ':set mouse=' firstset mouse=a"""""""""""""""""""""""""""""""""""""" Colors and Fonts""""""""""""""""""""""""""""""""""""""Enable syntax highlightsyntax enable"set colorschemecolorscheme elflord"endif"""""""""""""""""""""""""""""""""""""" VIM userinterface""""""""""""""""""""""""""""""""""""""Set 7 lines to the curors away from the border- when moving vertical..set so=7"Turn on WiLd menuset wildmenu"Always show current positionset ruler"The commandbar is 2 highset cmdheight=2"Show line numberset nu"Set backspaceset backspace=eol,start,indent"Bbackspace and cursor keys wrap toset whichwrap+=<,>,h,l"show matching bracetsset showmatch"How many tenths of a second to blinkset mat=2"Highlight search thingsset hlsearch"imediately show the search resultset is"""""""""""""""""""""""""""""""""""""" Folding""""""""""""""""""""""""""""""""""""""Enable folding, I find it very usefulset nofenset fdl=0"""""""""""""""""""""""""""""""""""""" Text options"""""""""""""""""""""""""""""""""""""set expandtabset shiftwidth=2set ambiwidth=doubleset smarttab"Set Tab=4 spacesset ts=4set lbrset tw=500set selection=inclusive """""""""""""""""""""""""""""" " Indent """""""""""""""""""""""""""""" "Auto indent set ai "Set auto indent width = 4 spaces set sw=4 "Smart indet set si "C-style indenting set cindent "usage: select codes, press '=' key, the codes will autoindenting "Wrap lines set wrap"Encoding settingsif has("multi_byte") " Set fileencoding priority if getfsize(expand("%")) > 0 set fileencodings=ucs-bom,utf-8,cp936,big5,euc-jp,euc-kr,latin1 else set fileencodings=cp936,big5,euc-jp,euc-kr,latin1 endif " CJK environment detection and corresponding setting if v:lang =~ "^zh_CN" " Use cp936 to support GBK, euc-cn == gb2312 set encoding=cp936 set termencoding=cp936 set fileencoding=cp936 elseif v:lang =~ "^zh_TW" " cp950, big5 or euc-tw " Are they equal to each other? set encoding=big5 set termencoding=big5 set fileencoding=big5 elseif v:lang =~ "^ko" " Copied from someone's dotfile, untested set encoding=euc-kr set termencoding=euc-kr set fileencoding=euc-kr elseif v:lang =~ "^ja_JP" " Copied from someone's dotfile, unteste set encoding=euc-jp set termencoding=euc-jp set fileencoding=euc-jp endif " Detect UTF-8 locale, and replace CJK setting if needed if v:lang =~ "utf8$" || v:lang =~ "UTF-8$" set encoding=utf-8 set termencoding=utf-8 set fileencoding=utf-8 endifelse echoerr "Sorry, this version of (g)vim was not compiled with multi_byte"endif""""""""""""""""""""""""""""""""""""""plugins"""""""""""""""""""""""""""""""""""""" Tlistif &difflet Tlist_Auto_Open=0 "don't auto pen when compare two fileselselet Tlist_Auto_Open=1 "auto pen Tlist when open a fileendif"set taglist window in right, delete the following line if you don't likelet Tlist_Use_Right_Window=1let Tlist_Auto_Update=1 let Tlist_File_Fold_Auto_Close=1"auto close Tlist when exiting file.let Tlist_Exit_OnlyWindow = 1 nmap <F7> :copen<CR>nmap <F6> :cclose<CR>用法主要整理来源于
https://jingyan.baidu.com/article/ae97a646da05debbfd461d33.html
1、水平打开
xxxxxxxxxxvimdiff a.c b.c或者vimdiff -d a.c b.c2、垂直打开
xxxxxxxxxxvimdiff -o a.c b.c
1、折叠行
xxxxxxxxxx+-- 7 lines: #include <stdio.h>------------------- 表示折叠的行2、删除的行
xxxxxxxxxx二.------------------------------------------------------------ 表示删除的行3、对行进行
折叠/展开
zo展开折叠的行zc将行折叠
1、跳到上一个差异
]c2、跳到下一个差异
[c3、左右窗口切换
ctrl + ww
1、从当前窗口复制给另一窗口
dp2、从另一窗口复制到当前窗口
do
1、保存所有文件并退出
xxxxxxxxxx:wqa!2、不保存所有文件并退出
xxxxxxxxxx:qa!
v + e选中单词
v + e + y复制选中的单词
v + e + p粘贴选中的文本
x
:1,$s/old_str/new_str/g引用 https://www.cnblogs.com/xiaowant/articles/1992923.html
x删除列1.光标定位到要操作的地方。2.CTRL+v 进入“可视 块”模式,选取这一列操作多少行。3.d 删除。插入列插入操作的话知识稍有区别。例如我们在每一行前都插入"() ":1.光标定位到要操作的地方。2.CTRL+v 进入“可视 块”模式,选取这一列操作多少行。3.SHIFT+i(I) 输入要插入的内容。4.ESC 按两次,会在每行的选定的区域出现插入的内容。
^M,实测第四种方法可行xxxxxxxxxx第一种方法:cat -A filename 就可以看到windows下的断元字符 ^M要去除他,最简单用下面的命令:dos2unix filename 第二种方法: sed -i 's/^M//g' filename#注意:^M的输入方式是 Ctrl + v ,然后Ctrl + M 第三种方法:#vi filename :1,$ s/^M//g^M 输入方法: ctrl+V ,ctrl+M 第四种方法:#cat filename |tr -d '/r' > newfile#^M 可用 /r 代替xxxxxxxxxx将101~130行中的 "../source" 替换成 "$(PrjDir)".103s后面的s表示替换,最后的 g 表示全部范围内:101,130s/..\/source/$(PrjDir)/gxxxxxxxxxx此关键字可以在windows gvim 的菜单中快捷查看 :%!xxd