Vim配置(一)

来源:互联网 发布:手机维修记账软件 编辑:程序博客网 时间:2024/06/13 11:43

关于Vim

  Vimis a highly configurable text editor built to enable efficienttextediting. It is an improved version of the vi editor distributedwithmost UNIX systems.

   Vimis often called a "programmer's editor," and so usefulforprogramming that many consider it an entire . It's not just forprogrammers,though. Vim is perfect for all kinds of text editing,from composingemail to editing configuration files.

   Despitewhat the above comic suggests, Vim can be configured to work in averysimple (Notepad-like) way, called evim or Easy Vim.

                                                                                                                                          ——http://www.vim.org/

   Vim是一个极其强大的文本编辑器,强大之处是在于它的自由,有非常丰富的插件资源以及很完善的命令(那些我刚开始看得头都晕了的命令),完全依靠键盘进行文本编辑,也许刚接触Vim时,会感觉非常不顺手,就像玫瑰一样。但请相信,在你不断了解之后会沉迷其中。

Vimrc

   VimrcVim的配置文件,一般在/ect/vimˎ/usr/share/vim(/usr下的Vimrc已经链接到/ect下的Vimrc上,因此修改二者任意一个皆可)以及/home/用户名/vim(只对该用户起效)中,有关于Vim界面ˎ编程语言支持ˎ插件等等一切关于Vim使用时的配置信息。当然若我们需要修改配置时,就需要在Vimrc中修改ˎ添加配置语句。

现在先看一下配置之前的Vimrc文件(版本VIM- Vi IMproved 7.3)

All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime" you can find below.  If you wish to change any of those settings, you should" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten" everytime an upgrade of the vim packages is performed.  It is recommended to" make changes after sourcing debian.vim since it alters the value of the" 'compatible' option." 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.runtime! 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 compatible" Vim5 and later versions support syntax highlighting. Uncommenting the next" line enables syntax highlighting by default.if has("syntax")  syntax onendif" 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"endif" Uncomment the following to have Vim load indentation rules and plugins" according to the detected filetype."if has("autocmd")"  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 showcmd" Show (partial) command in status line."set showmatch" Show matching brackets."set ignorecase" Do case insensitive matching"set smartcase" Do smart case matching"set incsearch" Incremental search"set autowrite" Automatically save before commands like :next and :make"set hidden             " Hide buffers when they are abandoned“set mouse=a" Enable mouse usage (all modes)" Source a global configuration file if availableif filereadable("/etc/vim/vimrc.local")  source /etc/vim/vimrc.localendif

       可以看到在配置之前的.Vimrc中,有大量注释语句,如"setshowcmd " Show (partial) command in statusline.之类这些也是配置语句,后面还有对其配置的解释。这些都是默认没有打开的配置。若要使用这些配置,只需将前面的注释符号‘” ’删除即可。


手动配置

  • 色彩配置

       默认的色彩配置也许不合很多人的口味,那该怎么办?没关系,六百多种色彩配置的方案在http://www.vim.org/scripts/script_search_results.php?keywords=&script_type=color+scheme&order_by=rating&direction=descending&search=search

cheme色彩配置方案等待你一一尝试,当然在http://www.vim.org/scripts/script.php?script_id=625中有已经打包

的配置方案,可以直接下载使用。(注意压缩包应直接在~./vim解压,单独下载的色彩配置方案应cp~./vim/colors)

     然后只需要在Vimrc中加入

colorscheme 色彩配置方案

      即可

  • 格式配置

                set autoindent" 自动缩进set cindentset smartindent" 为C程序提供自动缩进set tabstop=4" Tab键的宽度set softtabstop=4" 统一缩进为4set shiftwidth=4set smarttab" 在行和段开始处使用制表符set number" 显示行号set showmatch " 高亮显示匹配的括号set history=600" 保留历史记录set clipboard+=unnamed" 共享外部剪贴板

  • 文件及语言支持

filetype plugin indent on"开启文件类型检测set completeopt=longest,menu"开启智能补全set completeopt=preview,menu"开启代码补全 "自动补全:inoremap ( ()<esc>i:inoremap ) <c-r>=ClosePair(')')<cr>:inoremap { {<cr>}<esc>O:inoremap } <c-r>=ClosePair('}')<cr>:inoremap [ []<esc>i:inoremap ] <c-r>=ClosePair(']')<cr>:inoremap " ""<esc>i:inoremap ' ''<esc>ifunction! ClosePair(char)if getline('.')[col('.') - 1] == a:charreturn "\<right>"elsereturn a:charendifendfunction

       Vim的大部分基本配置就差不多结束了,另外提醒一下,由于CSDN的博文编辑器和Vim的粘贴问题,copy过去的代码应该很多都会乱掉,所以最好自己把配置文件敲一遍,同时也会发现一些问题,不断地解决问题之后,才能学到更多。
                                             
0 0
原创粉丝点击