usr_05 选项设置
05.1 vimrc 文件
可以使用如下命令打开 Vim 配置文件
:edit $MYVIMRC
可以在开头放上
source $VIMRUNTIME/defaults.vim
来导入默认配置。vimrc 文件可以包含任何冒号命令。
05.2 vimrc 示例解释
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)
if has('persistent_undo')
set undofile " keep an undo file (undo changes after closing)
endif
endif
有关覆盖保存生成备份文件,和可持久化撤销。
if &t_Co > 2 || has("gui_running")
" Switch on highlighting the last used search pattern.
set hlsearch
endif
高亮上次搜索
" 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
augroup END
text 文件行长度超过 78 自动换行。
" Add optional packages.
"
" The matchit plugin makes the % command work better, but it is not backwards
" compatible.
" The ! means the package won't be loaded right away but when plugins are
" loaded during initialization.
if has('syntax') && has('eval')
packadd! matchit
endif
载入 matchit 插件增强 %
命令。
05.3 defaults.vim 文件解释
" Bail out if something that ran earlier, e.g. a system wide vimrc, does not
" want Vim to use these default values.
if exists('skip_defaults_vim')
finish
endif
该文件的载入可以使用
let skip_defaults_vim = 1
跳过。
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
" Avoid side effects when it was already reset.
if &compatible
set nocompatible
endif
" When the +eval feature is missing, the set command above will be skipped.
" Use a trick to reset compatible only when the +eval feature is missing.
silent! while 0
set nocompatible
silent! endwhile
" Allow backspacing over everything in insert mode.
set backspace=indent,eol,start
set history=200 " keep 200 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set wildmenu " display completion matches in a status line
set ttimeout " time out for key codes
set ttimeoutlen=100 " wait up to 100ms after Esc for special key
" Show @@@ in the last line if it is truncated.
set display=truncate
" Show a few lines of context around the cursor. Note that this makes the
" text scroll if you mouse-click near the start or end of the window.
set scrolloff=5
" Do incremental searching when it's possible to timeout.
if has('reltime')
set incsearch
endif
" Do not recognize octal numbers for Ctrl-A and Ctrl-X, most users find it
" confusing.
set nrformats-=octal
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries.
if has('win32')
set guioptions-=t
endif
" Don't use Ex mode, use Q for formatting.
" Revert with ":unmap Q".
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.
" Revert with ":iunmap <C-U>".
inoremap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine. By enabling it you
" can position the cursor, Visually select and scroll with the mouse.
" Only xterm can grab the mouse events when using the shift key, for other
" terminals use ":", select text and press Esc.
if has('mouse')
if &term =~ 'xterm'
set mouse=a
else
set mouse=nvi
endif
endif
" Only do this part when Vim was compiled with the +eval feature.
if 1
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
" Revert with ":filetype off".
filetype plugin indent on
" Put these in an autocmd group, so that you can revert them with:
" ":augroup vimStartup | au! | augroup END"
augroup vimStartup
au!
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid, when inside an event handler
" (happens when dropping a file on gvim) and for a commit message (it's
" likely a different one than last time).
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
\ | exe "normal! g`\""
\ | endif
augroup END
endif
" Switch syntax highlighting on when the terminal has colors or when using the
" GUI (which always has colors).
if &t_Co > 2 || has("gui_running")
" Revert with ":syntax off".
syntax on
" I like highlighting strings inside C comments.
" Revert with ":unlet c_comment_strings".
let c_comment_strings=1
endif
" 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.
" Revert with: ":delcommand DiffOrig".
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
if has('langmap') && exists('+langremap')
" Prevent that the langmap option applies to characters that result from a
" mapping. If set (default), this may break plugins (but it's backward
" compatible).
set nolangremap
endif
05.4 简单键盘映射
映射可以把一系列命令映射到一个单独的按键,例如用 <F5>
给一个单词加括号
:map <F5> i{<ESC>ea}<ESC>
可以给 \<CHAR>
绑定命令
使用
:map
可以列出当前已经定义的映射。
05.5 添加软件包
05.6 添加插件
05.7 添加帮助
05.8 选项窗口
:options
会打开一个新的窗口更改选项。
可以使用 <ENTER>
更改其中选项打开关闭。或者修改后使用 <ENTER>
使选项生效。
05.9 常用选项
查询某个选项 <OP>
:help '<OP>'
恢复某个选项默认值
:set <OP>&
长行不回绕
:set nowrap
不回绕一次滚动的字符数
:set sidescroll=10
移动命令换行
:set whichwrap=b,s,<,>,[,]
这样 <BS>
,<SPACE>
,<LEFT>
,<RIGHT>
(<,>
针对普通模式方向键,[,]
针对插入模式方向键)将都可以跨行使用。
显示 TAB
:set list
或者
:set listchars=tab:>-,trail:-
关键字
查看那些字母可以出现在字母中
:set iskeyword
显示
iskeyword=@,48-57,_,128-167,224-235
其中数字是字符的 ASCII 码。
可以加入或者删除某些新字符。
:set iskeyword+=-
:set iskeyword-=-
显示消息的空间
:set cmdheight=3
Next: [Vim] usr_06