6.1 vimrc文件
如果你厌倦了手工键入常用的命令,或者要使你喜好的选项和映射一次性准备好,这时可以统统写入到vimrc(vim run command)的文件里,Vim在启动时会读取这个文件.
vimrc位置:
Unix and OS/2: ~/.vimrc
Windows : $VIM\_vimrc
6.2 vimrc示例文件
" An example for a vimrc file.
" Maintainer: DaiDai
" Last change: 2017年6月29日
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file (restore to previous version)
set undofile " keep an undo file (undo changes after closing)
endif
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
" 打开语法高亮
set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
if has('langmap') && exists('+langnoremap')
" Prevent that the langmap option applies to characters that result from a
" mapping. If unset (default), this may break plugins (but it's backward
" compatible).
set langnoremap
endif
" Add optional packages.
"
" The matchit plugin makes the % command work better, but it is not backwards
" compatible.
packadd matchit
6.3 简单的映射
一个映射可以把一连串Vim命令用一个按键来表示.
如:用一个功能键或字符串,将某个word单词,变成{word},可以使用:map命令.
:map
:map \abc i{
{amount}
6.4 选项窗口
:options命令:在帮助主题中寻找或设置相应的选项.
" Each "set" line shows the current value of an option (on the left).
" Hit
" A boolean option will be toggled.
" For other options you can edit the value before hitting
" Hit
" Hit
" Hit
:set all命令:查看所有的设置选项.
6.5 常用选项
:help 'wrap':查看某个选项的帮助.
:set shiftwidth&:shiftwidth修改为默认值8.
set nowrap:不要折行.
set sidescroll=10:自动左右滚动10个字符.
set whichwrap=b,s :跨行移动命令
set whichwrap=b,s,<,> :跨行移动命令 智能上上下下
set whichwrap=b,s,<,>,[,] :跨行移动命令 智能上上下下 Insert模式下,也能如此.
set list :show
set listchars=tab:>-,trail:-,eol:$$ :修改样式
set iskeyword=@,48-57,_,192-255 :关键字默认字符要求 @:代表所有的字母;48-57 ASCII从48>到57 即0到9;192-225 可以打印的字符;
set iskeyword+=- :增加连词符
set iskeyword-=- :去掉连词符
fdafd-fdasfdasfs
set cmdheight=3 :number of lines used for the command-line 命令行高度.
6.6 使用高亮
:syntax enable:打开语法支持
:set filetype=c :改变当前文件所属类型.
:set filetype=java :int boolean
:set filetype=vim
:syntax clear 关闭当前高亮.
:colorscheme evening:打开不同的颜色主题.