Vim learning Notes configuration file (vimrc)

Source: Internet
Author: User
Vim learning Notes configuration file (vimrc)

When Vim is started, it first searches for the configuration file and runs the command. These initialization files are generally vimrc, gvimrc, and exrc.

Exploitation:versionCommand to obtain detailed information about the configuration file.

NOTE: If gvim is executed, $ vimruntime/menu. Vim is also executed.

Configuration File Location

VimrcIs the main configuration file, which has two versions: Global and user.

The global vimrc file is stored in the vim installation directory. Run the following command to check the vim installation directory:

:echo $VIM

By default, the system vimrc is stored in the following locations:

Linux:/usr/share/Vim/vimrc

Windows: C: \ Program Files \ vimrc

The user vimrc file is stored in the user's home directory. You can use the following command to determine the user's main directory:

:echo $HOME

By default, user vimrc is stored in the following locations:

Linux:/home/username/. vimrc

Windows: C: \ Documents ents and Settings \ USERNAME \ _ vimrc

Note: The user configuration file takes precedence over the system configuration file.

GvimrcIs the configuration file of gvim. It also has global and user versions and is stored in the same directory as vimrc.

By default, gvimrc is stored in the following locations:

Linux:/usr/share/Vim/gvimrc

Windows: C: \ Program Files \ Vim \ _ gvimrc

By default, gvimrc is stored in the following locations:

Linux:/home/username/. gvimrc

Windows: C: \ Documents ents and Settings \ USERNAME \ _ gvimrc

ExrcFile, used only for backward compatibility with olvi/ex. Its global and user versions are also placed in the same directory of vimrc. You do not need to pay attention to the exrc configuration file unless you use the Vi-compatible mode.

Note: in UNIX and Linux, the vim configuration file is named as a hidden file starting with a dot. In Windows, the configuration file starts with an underscore.

Edit configuration file

You can use the following command to create a buffer to edit the configuration file:

:edit $MYVIMRC

You can also use the following command to create a tab to edit the configuration file:

:tabedit $MYVIMRC

For example, you can use the following command in the configuration file to set Vim options:

: Syntax on "enable the syntax brightening Function

: Set shiftwidth = 4 "set indent width to 4 spaces

The single quotation mark (") is the comment content.

Application configuration file

After modifying the configuration file, you need to restart vim or use the: Source command to apply the new settings:

:source $MYVIMRC

You can add the following command to the configuration file to automatically apply the configuration after saving it:

autocmd bufwritepost .vimrc source $MYVIMRC

Configuration file instance

The following is my vim configuration file for your reference:

Set ignorecase smartcase "Case Insensitive during search, however, when one or more upper-case letters exist, the data remains case sensitive. </P> <p> set nu "indicates the row number. <br/> set rlimit <br/> set rulerformat = % 55 (% {strftime ('% A \ % B \ % E \ % I: % m \ % p')} \ % 5l, %-6 (% C % v %) \ % P %) <br/> set guioptions + = B <br/> set guioptions-= T </P> <p> set paste <br/> "set clipboard = unnamed" enables vim and win shared clipboard </P> <p> set cursorline cursorcolumn </P> <p> syntax enable "enable syntax highlighting <br/> syntax on" allows syntax highlighting based on specified topics, rather than the default highlighted topic <br/> colorsche Me xoria256 "specify the color scheme </P> <p> set showcmd" display the currently entered command on the command line </P> <p> set langmenu = en_us "set menu and information set to English <br/> let $ lang = 'en _ us' <br/> source $ vimruntime/delmenu. vim <br/> source $ vimruntime/menu. vim </P> <p> set fileencoding = UTF-8 "sets multi-encoding <br/> set encoding = UTF-8 <br/> set tenc = UTF-8 <br/> set fileencodings = ucs-bom, UTF-8, cp936, gb18030, big5, EUC-JP, EUC-KR, Latin1 <br/> "language message zh_CN.UTF-8 </P> <p> filetype on "Enable file type detection <br/> filetype plugin on" load the corresponding plug-in based on different types detected </P> <p> If has ("autocmd ") & exists ("+ omnifunc ") <br/> autocmd filetype * <br/> \ If & omnifunc = "" | <br/> \ setlocal omnifunc = syntaxcomplete # complete | <br/> \ endif <br /> endif </P> <p> set laststatus = 2 "sets the status bar <br/> set statusline = % 2 * % N % m % R % H % w % *\ % F \ % 1 * [format = % 2 * % {& ff }: % {& fenc! = ''? & Fenc: & ENC} % 1 *] \ [type = % 2 * % Y % 1 *] \ [col = % 2 * % 03 v % 1 *] \ [ROW = % 2 * % 03l % 1 */% 3 * % L (% P %) % 1 *] \ [date = % 2 * % {strftime (\ "% C \", getftime (expand (\ "% \")))} % 1 *] <br/> "set statusline = % F % m % R % H % w \ [format =%{ & ff}] \ [type = % Y] \ [ASCII = \ % 03.3b] \ [hex = \ % 02.2b] \ [Pos = % 04l, % 04 V] [% P %] \ [Len = % L] </P> <p> function! Insertstatuslinecolor (mode) <br/> If a: mode = 'I' <br/> Hi statusline guibg = Peru <br/> elseif: mode = 'R' <br/> Hi statusline guibg = blue <br/> else <br/> Hi statusline guibg = black <br/> endif <br/> endfunction </P> <p> au insertenter * Call insertstatuslinecolor (V: insertmode) <br/> au insertleave * Hi statusline guibg = Orange guifg = white <br/> Hi statusline guibg = black </P> <p> Hi user1 guifg = gray <br/> h I user2 guifg = red <br/> Hi user3 guifg = white </P> <p> set winaltkeys = No </P> <p> "Map <br/> NMAP <tab> V> <br/> NMAP <s-tab> v <br/> vmap <tab> GV <br/> vmap <s-tab> <GV <br /> "Open the Save As dialog box <br/> Map <F2> <ESC>: browse saveas <CR> <br/> "Use the nerdtree plug-in to view project files <br/> NMAP <F3>: nerdtreetoggle planning <CR> <br/> "enable/disable line breaks <br/> NMAP <silent> <F5> <ESC>: Call togglewrap () <CR> <br/> "display/disable row and column cursor <br/> NMAP <silent> <F6> <ESC>: Call togglecursor () <CR> <br/> "new tab <br/> Map <F10> <ESC>: tabnew <CR> <br/> "display/disable High Brightness search <br/> NMAP <silent> <A-F> <ESC>: Call togglehlsearch () <CR> </P> <p> function! Togglewrap () <br/> If & wrap <br/> set nowrap <br/> else <br/> set wrap <br/> endif <br/> endfunction </P> <p> function! Togglehlsearch () <br/> If & HLS <br/> set nohls <br/> else <br/> set HLS <br/> endif <br/> endfunction </P> <p> function! Togglecursor () <br/> If & cursorcolumn <br/> set nocursorline nocursorcolumn <br/> else <br/> set cursorline cursorcolumn <br/> endif <br/> endfunction </P> <p> let mapleader = "; "" defines the prefix of the shortcut key, that is, <leader> <br/> NMAP <leader> V: tabedit $ myvimrc <CR> </P> <p> "configuration file <br/> autocmd bufwritepost _ vimrc source $ myvimrc </P> <p>" set file format <br /> set fileformats = UNIX, dos, Mac </P> <p> "template <br/> autocmd! Bufnewfile * silent! 0r $ Vim/vimfiles/skel/template. %: E </P> <p> "specifies the backup file directory <br/> set backupdir = F: \ Bak <br/> set backupskip = D: /temp/* </P> <p> "cancel Automatic Code folding <br/> autocmd! Bufnewfile, bufread * setlocal nofoldenable <br/> "enable/disable code folding <br/> nnoremap <space> za </P> <p>" optimize large file editing <br/> let g: largefile = 10 </P> <p> "automatically load files <br/> set autoread </P> <p> set list! <Br/> set listchars = nbsp: Hangzhou, Tab: Hangzhou, precedes: «, extends:», trail: <br/> Hi nontext ctermfg = 247 guifg = # a73111 cterm = bold GUI = bold <br/> Hi specialkey ctermfg = 77 guifg = #654321 </P> <p> augroup filetypedetect <br/> au bufnewfile, bufread *. mxl SETF mxl <br/> augroup end </P> <p>

From: http://yyq123.blogspot.com/2012/01/vim-vimrc.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.