VIM 配置

VIM配置及其插件


一、VIM配置文件

Window下的配置文件位置在:C:Program FilesVim,Linux下的在~/.vimrc
参考:
1、The ultimate Vim_R_C
https://github.com/amix/vimrc
2、VIM 中文手册

二、Exuberant Ctags 程序 和 Taglist.vim 脚本

1、ctags下载
2、Taglist.vim 脚本
3、Vimrc打开filetype on
4、使用Taglist插件
5、设置 快捷键 来代替TlistToggle来 开/关 右侧的 Taglish窗口。
6、ctags 帮助手册
可能涉及到的配置:

:help :tags
:help CTRL-] "CTRL 和 ] 跳转到光标所在处的关键字的定义源
:help CTRL-T "CTRL和T 跳转到刚刚的文件和行

第一次设置好了之后,出现错误:E434 Cannot find tag pattern。但是,该tags在tags文件中是存在的。其他,像函数memset(),在按下CTRL+]的时候,错误提示为:E426 tag not found
无意中找到了解决办法,在对应的sourcefile中去掉末尾的^M,相当于将文件格式/fileformat从Windows转换成Unix。然后重新生成tags文件之后,就正常了。

生成系统/usr/include目录下面的tags文件,方法:(输入命令的时候,不要前面的$(dollar)符号)

ctags -f newtags -R /usr/include

注:上面的指令,会在当前文件夹生成一个名叫newtags的tags文件。看了一下文件,总共只有9万多行。
另外,最好在~/.vimrc文件内添加上一句set tags+=~/xxx/xxx/newtags,使vim启动的时候会自动加载这个tags文件。或者是也可以在vimrc中设置一个条件变量,当编译某些特定程序的时候,开启这个tags文件。

REFER: Issue "E434: Can't find tag pattern"

三、NerdTree

1、NerdTree Vim下载
2、NerdTree 配置

四、Vimgrep + QuickFix

Global+Regular_Expression+Search搜索+QuickFix

1、[Quickfix Vim下载]
2、Quickfix 在线帮助
3、Vimgrep
4、vim :quickfix
5、Quickfix 中文帮助

:helo copen "打开quickfix 窗口
:help cclose "关闭quickfix 窗口

五、自动补全

Vim 7已经内置了代码补全功能[6],补全操作可分为两种:

关键字补全
即简单地补全到文档中已有的词,快捷键为 Ctrl-NCtrl-P
智能补全
Vim 7中引入 Omni Complete,可根据语义补全,快捷键为 Ctrl-X Ctrl-O

六、代码折叠

代码较长时可启用代码折叠功能,如按语法高亮元素折叠:

set foldmethod=syntax
"默认情况下不折叠
set foldlevel=99

随后即可使用z系列命令管理代码折叠。如za会翻转当前位置的折叠状态,zA会递归翻转当前层所有代码的折叠状态等。当然也可以把功能键映射到za:

map <F3> za

七、多色高亮显示

1、在vimrc中区分vimgvim
vimrc(Linux在~/.vimrc,Windows在C:Program FilesVim_vimrc)中添加上这样一段:

""""""""""""""""""""""""""""""""""""""""""""""
" Only apply this in non-gui Vim
""""""""""""""""""""""""""""""""""""""""""""""
if !has("gui_running")
	highlight Normal ctermfg=grey ctermbg=black "Set Vim's background color and foreground color
endif 

gui_running存在时,表示当前的编辑器是GVim,否则是Vim。

参考:
1、I want to add background color to vimrc but it's not working

八、VIM + C_scope

C_scope is a developer's tool for browsing source code/scoping C language source code. It has an impeccable Unix pedigree, having been originally developed at Bell Labs back in the days of the PDP-11. Cscope was part of the official AT&T Unix distribution for many years, and has been used to manage projects involving 20 million lines of code!

In April, 2000, thanks to the Santa Cruz Operation, Inc. (SCO) (since merged with Caldera), the code for Cscope was open sourced under the BSD license.

NOTE:系统中需要提前安装libcurse。libncurse的下载地址

curses is a terminal control library for Unix-like systems, enabling the construction of text user interface (TUI) applications.

The name is a pun on the term “**cursor** optimization”. It is a library of functions that manage an application's display on character-cell terminals (e.g., VT100).[1]

ncurse means new curse

REFER:C_SCOPE 下载
REFER:Vim/Cscope 入门指导
REFER:CSCOPE 主页
REFER:vi/Vim + Cscope/Ctags
REFER:GNU ncurse 主页

参考


1、用Vim编程——配置与技巧
2、易水 Vim :quickfix
3、Quickfix 在线帮助
4、amix的Vimrc
5、高效率编辑器 Vim
6、手把手教你把Vim改装成一个IDE编程环境(图文)
7、Wu Yin(吴垠)的 vimrc
8、USC/中科大 vimrc
9、LinuxTutorialAdvanced_vi

原文地址:https://www.cnblogs.com/xuanyuanchen/p/5807224.html