Linux下的vim环境配置
2016-06-05 18:17
465 查看
【概述】
首先,vim是干嘛的??vim是从vi发展而来的一个功能强大、高度可定制的文本编辑器,在代码补全、编译及错误跳转等方 便编程的功能特别丰富,所以Vim普遍被推崇为类Vi编辑器中最好的一个,在程序员中被广泛只使用。
【vim环境配置】
为什么要对vim 进行配置呢,我们可能已经习惯了在windows下进行代码的编译等功能,为了在Linux环境下能有和VS类似的编译 窗口和功能,我们要对vim进行环境配置。这种配置因人而宜,自己可以根据自己的需要进行环境配置,如下是我的vim环境配置。先上 效果图解解馋:
创建.vim文件夹和.vimrc配置文件
在Linux中打开自己的工作目录,可能会发现只有几个文件夹,这是因为有的文件夹和文件被隐藏了,按照下图操作显示被隐藏的 文件夹和文件,如果没有.vim文件夹和.vimrc文件则像在windows系统中创建文件夹和文件一样创建.vim文件夹和.vimrc文件,然后 在.vim文件夹中创建doc和plugin文件夹,如果有的话就不用创建了。
配置TagList插件
下载taglist_xx.zip ,解压完成,将解压出来的doc的内容拷贝到~/.vim/doc, 将解压出来的plugin下的内容拷贝到 ~/.vim/plugin,下载链接如下:
http://www.vim.org/scripts/script.php?script_id=273
在.vimrc中添加如下配置信息: let Tlist_Show_One_File=1 let Tlist_Exit_OnlyWindow=1 let Tlist_Use_Right_Window=1
配置WinManager插件
下载winmanager.zip,解压完成,将解压出来的doc的内容拷贝到~/.vim/doc, 将解压出来的plugin下的内容拷贝到 ~/.vim/plugin,下载链接如下:
http://www.vim.org/scripts/script.php?script_id=95
在.vimrc中添加如下配置信息: let g:winManagerWindowLayout=‘FileExplorer|TagList' nmap wm :WMToggle<cr>
配置中文help插件
下载vimcdoc-xx.tar.gz,解压后其中有个doc文件夹, 将其中的内容全部复制到~/.vim/doc, 此时vim中的help信息已经 是中文的了。如果无法显示中文, 在~/.vimrc中增加下面这条配置信息:set helplang=cn,下载链接如下:
http://vimcdoc.sf.net
在vim中输入:help就会显示中文的help文件:
配置Ctags插件
ctags插件可以转到函数的定义处,首先要下载ctags-5.8.tar.gz安装包,然后将下载的安装包拷贝到工作目录下,用以下命令 来解压安装,*组后一条指令需要使用root用户权限。* tar zxvf ctags-5.8.tar.gz cd ctags-5.8 ./configure make make install 安装好之后在工作目录下使用ctags -R来创建索引文件
http://prdownloads.sourceforge.net/ctags/ctags-5.8.tar.gz
使用方法:
在工作目录下创建一个test_6_5文件夹,用ctags -R来创建文件索引,在这个文件夹中创建三个文 件:test.h\test.c\main.c,在test.h中声明一个print_hello函数,在test.c中实现这个函数,在main.c中调用这个函数,用 vim打开main.c文件,将光标放在print_hello函数上,按键盘的Ctrl + ],将会自动跳转到这个函数的定义处。
配置.vimrc文件
vim的配置信息都放在.vimrc文件中,我的.vimrc配置文件如下:
" This line should not be removed as it ensures that various options are " properly set to work with the Vim-related packages available in Debian. ""debian.vim " Uncomment the next line to make Vim more Vi-compatible " NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous " options, so any other options should be set AFTER setting 'compatible'. set nocompatible " Vim5 and later versions support syntax highlighting. Uncommenting the " following enables syntax highlighting by default. if has("syntax") syntax on " 语法高亮 endif colorscheme ron " elflord ron peachpuff default 设置配色方案,vim自带的配色方案保存在/usr/share/vim/vim72/colors目录下 " detect file type filetype on filetype plugin on " If using a dark background within the editing area and syntax highlighting " turn on this option as well set background=dark " Uncomment the following to have Vim jump to the last position when " reopening a file if has("autocmd") au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif "have Vim load indentation rules and plugins according to the detected filetype filetype plugin indent on endif " The following are commented out as they cause vim to behave a lot " differently from regular Vi. They are highly recommended though. "set ignorecase " 搜索模式里忽略大小写 "set smartcase " 如果搜索模式包含大写字符,不使用 'ignorecase' 选项。只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用。 set autowrite " 自动把内容写回文件: 如果文件被修改过,在每个 :next、:rewind、:last、:first、:previous、:stop、:suspend、:tag、:!、:make、CTRL-] 和 CTRL-^命令时进行;用 :buffer、CTRL-O、CTRL-I、'{A-Z0-9} 或 `{A-Z0-9} 命令转到别的文件时亦然。 set autoindent " 设置自动对齐(缩进):即每行的缩进值与上一行相等;使用 noautoindent 取消设置 "set smartindent " 智能对齐方式 set tabstop=4 " 设置制表符(tab键)的宽度 set softtabstop=4 " 设置软制表符的宽度 set shiftwidth=4 " (自动) 缩进使用的4个空格 set cindent " 使用 C/C++ 语言的自动缩进方式 set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s "设置C/C++语言的具体缩进方式 "set backspace=2 " 设置退格键可用 set showmatch " 设置匹配模式,显示匹配的括号 set linebreak " 整词换行 set whichwrap=b,s,<,>,[,] " 光标从行首和行末时可以跳到另一行去 "set hidden " Hide buffers when they are abandoned set mouse=a " Enable mouse usage (all modes) "使用鼠标 set number " Enable line number "显示行号 "set previewwindow " 标识预览窗口 set history=50 " set command history to 50 "历史记录50条 "--状态行设置-- set laststatus=2 " 总显示最后一个窗口的状态行;设为1则窗口数多于一个的时候显示最后一个窗口的状态行;0不显示最后一个窗口的状态行 set ruler " 标尺,用于显示光标位置的行号和列号,逗号分隔。每个窗口都有自己的标尺。如果窗口有状态行,标尺在那里显示。否则,它显示在屏幕的最后一行上。 "--命令行设置-- set showcmd " 命令行显示输入的命令 set showmode " 命令行显示vim当前模式 "--find setting-- set incsearch " 输入字符串就显示匹配点 set hlsearch "--ctags setting-- " 按下F5重新生成tag文件,并更新taglist map <F5> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR> :TlistUpdate<CR> imap <F5> <ESC>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR> :TlistUpdate<CR> set tags=tags set tags+=./tags "add current directory's generated tags file set tags+=/home/clown/Test/tags "add new tags file(刚刚生成tags的路径,在ctags -R 生成tags文件后,不要将tags移动到别的目录,否则ctrl+]时,会提示找不到源码文件) let Tlist_Show_One_File=1 let Tlist_Exit_OnlyWindow=1 let Tlist_Use_Right_Window=1 let g:winManagerWindowLayout='FileExplorer|TagList' nmap wm :WMToggle<cr> :inoremap <S-ENTER> <c-r>=SkipPair()<CR> :inoremap <S-SPACE> <ESC>la :inoremap <C-ENTER> <ESC>A;<CR> :inoremap ( ()<ESC>i :inoremap ) <c-r>=ClosePair(')')<CR> ":inoremap { {<CR>}<ESC>0 ":inoremap } <c-r>=ClosePair('}')<CR> :inoremap [ []<ESC>i :inoremap ] <c-r>=ClosePair(']')<CR> :inoremap ;; <ESC>A;<CR> function ClosePair(char) if getline('.')[col('.') - 1] == a:char return "\<Right>" else return a:char endif endf function Semicolon() "echo getline('.')[col('.')] if getline('.')[col('.')] == ')' return "<ESC>A;" elseif getline('.')[col('.')] == '}' return "\<ESC>A;" elseif getline('.')[col('.')] == ']' return "\<ESC>A;" else return ";" endif endf function SkipPair() if getline('.')[col('.') - 1] == ')' return "\<ESC>o" else normal j let curline = line('.') let nxtline = curline while curline == nxtline if getline('.')[col('.') - 1] == '}' normal j let nxtline = nxtline + 1 let curline = line('.') continue else return "\<ESC>i" endif endwhile return "\<ESC>o" endif endf function ClsoeBrace() if getline('.')[col('.') - 2] == '=' return "{}\<ESC>i" elseif getline('.')[col('.') - 3] == '=' return "{}\<ESC>i" elseif getline('.')[col('.') - 1] == '{' return "{}\<ESC>i" elseif getline('.')[col('.') - 2] == '{' return "{}\<ESC>i" elseif getline('.')[col('.') - 2] == ',' return "{}\<ESC>i" elseif getline('.')[col('.') - 3] == ',' return "{}\<ESC>i" else return "{\<ENTER>}\<ESC>O" endif endf syntax enable syntax on set helplang=cn
重启vim,打开一个文件键入wm就可以看到自己的配置效果啦~
相关文章推荐
- 《和墙角00征服 Linux》之mkdir命令
- 【Linux】Centos下的"vim"的配置
- Makefile文件的编写
- vmware下centos6 安装jdk1.7
- 一天一个shell命令 linux文本内容操作系列-awk命令详解
- linux 命令大全
- Linux下快速设定ip bond
- vmware8安装centos6
- 开源新闻速递:Linux AIO Ubuntu 16.04 发布
- CentOS7安装Hadoop2.7完整流程
- 极度简约 最小 Linux 发行版 Tiny Core Linux 7.1 发布
- 详解Linux中的进程描述符task_struct
- 第二章:Linux如何学习
- 一天一个shell命令 linux文本内容操作系列-sed命令详解
- centos安装python-pip和networkx包
- 一天一个shell命令 linux文本内容操作系列-cut命令详解
- Handoop安装并启动(centos6.5+HDFS HA+Fedaration+YARN)
- Linux下的进程控制块(PCB)
- 一天一个shell命令 linux文本内容操作系列-grep命令详解
- inux的进程-进程的概念和fork创建进程