只要在 vim 里:
:e $MYVIMRCVIM 就会打开你的 vimrc 文件。如果没有就会创建一个。
有 vimrc 文件后,vim 默认就会是非兼容模式。不过习惯上,最好还是加上:
set nocompatible
这句如果有,必须是 vimrc 的第一句。因为改变它的值,会使很多选项产生连锁变化,即副作用很大。
这是 vim 自带的 vimrc 例子,如果你没有自己的,从这里开始是个不错的注意。
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last change: 2011 Apr 15
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
" 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
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 <C-U> <C-G>u<C-U>
" 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.
" 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.
filetype plugin indent on
" 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).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
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
1
/usr/share/vim/vimrc
这个文件是系统级的 vimrc 配置文件,为了保证 vim 的正常运行,一般并不会修改这个文件,而是应该在你自己的用户目录下(~ 下)创建一个新的用户级 vimrc 文件。也就是说先在终端中执行
1
vi ~/.vimrc
然后再在打开的 vimrc 文件中进行你的 vim 配置修改,修改完成之后使用 wq 命令保存。如图:
要查看你当前使用的 vimrc 配置文件是哪一个,请在 vim 命令中输入(在 vim 中按 esc,然后按冒号,接着输入命令)
1
echo $MYVIMRC
如图:
回车结果如下:
可见我当前使用的是 /Users 下的用户级 vimrc。
如果还是想修改系统级 vimrc 文件的话,需要先将此文件的写入权限开启。终端中输入
1
sudo chmod a+w /usr/share/vim/vimrc
来将此文件写入权限打开(需要管理员密码),然后就可以输入
1
vi /usr/share/vim/vimrc
编辑并保存了。如下图:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)