Vim Learning Note configuration file (VIMRC)

Source: Internet
Author: User
Vim Learning Note configuration file (VIMRC)


During the vim startup process, the configuration file is first looked up and the commands are executed. And these initialization files generally have VIMRC, GVIMRC and EXRC three kinds.



Using the: Version command, you can get details of the configuration file.






Note: If the gvim is executed, then $vimruntime/menu.vim will also be executed.



Configuration file Location



VIMRC is the primary configuration file, which has both global and user versions.



Global VIMRC files, stored in the VIM installation directory. You can use the following command to determine the installation directory for VIM:



: Echo $VIM



By default, the system VIMRC is stored in the following location:



Linux:/USR/SHARE/VIM/VIMRC



Windows:c:\program FILES\VIMRC



User vimrc files, stored in the user's home directory. You can use the following command to determine the user-headed directory:



: Echo $HOME



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



Linux:/HOME/USERNAME/.VIMRC



Windows:c:\documents and SETTINGS\USERNAME\_VIMRC



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



GVIMRC is a gvim configuration file that has both global and user versions and is stored in the same directory as VIMRC.



By default, the system GVIMRC is stored in the following location:



Linux:/USR/SHARE/VIM/GVIMRC



Windows:c:\program FILES\VIM\_GVIMRC



By default, the user GVIMRC is stored in the following location:



Linux:/HOME/USERNAME/.GVIMRC



Windows:c:\documents and SETTINGS\USERNAME\_GVIMRC



exrc file, used only for backward-compatible OLVI/EX, and both global and user versions are placed in the same directory as VIMRC. Unless you use the vi-compatible mode, you do not need to focus on the EXRC configuration file.



Note: Under UNIX and Linux, Vim's configuration file is named as a hidden file that starts with a dot, while under Windows, the configuration file is named after an underscore.



Edit configuration file



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



: Edit $MYVIMRC



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



: Tabedit $MYVIMRC



For example, we can set the VIM option by using the following command in the configuration file:



: Syntax on "Turn on syntax highlighting features"



: Set shiftwidth=4 Setting indent width to 4 spaces



Where the single quotation mark (") is the annotation content.



Apply configuration file



After you modify the configuration file, you need to restart Vim or use the source command to apply the new settings:



: Source $MYVIMRC



We can add the following command to the configuration file and apply the configuration automatically after the Save:



Autocmd bufwritepost. VIMRC Source $MYVIMRC



Configuration file Instance



The following is my VIM profile content for your reference:


set ignorecase smartcase "ignore case when searching, but remain case-sensitive when there is one or more capital letters

set nu "show line number
set ruler
set rulerformat =% 55 (% (strftime ('% a \% b \% e \% I:% M \% p')) \% 5l,%-6 (% c% V%) \% P%)
set guioptions + = b
set guioptions- = T

set paste
"set clipboard = unnamed" Let Vim and Win share the clipboard

set cursorline cursorcolumn

syntax enable "to enable syntax highlighting
"syntax on" allows syntax highlighting by specified theme instead of default theme
colorscheme xoria256 "specify color scheme

set showcmd "show the currently entered command on the command line

set langmenu = en_US "Set menus and messages to English
let $ LANG = 'en_US'
source $ VIMRUNTIME / delmenu.vim
source $ VIMRUNTIME / menu.vim

set fileencoding = utf-8 "Set multiencoding
set encoding = utf-8
set tenc = utf-8
set fileencodings = ucs-bom, utf-8, cp936, gb18030, big5, euc-jp, euc-kr, latin1
"language message en_US.UTF-8

filetype on "Turn on filetype detection
filetype plugin on "Load the corresponding plugin based on the detected type


if has ("autocmd") && exists ("+ omnifunc")
autocmd Filetype *
\ if & omnifunc == "" |
\ setlocal omnifunc = syntaxcomplete # Complete |
\ endif
endif

set laststatus = 2 "Set the status bar
set statusline =% 2 *% n% m% r% h% w% * \% F \% 1 * [FORMAT =% 2 *% {& ff}:% {& fenc! = ''? & fenc: & enc}% 1 *] \ [TYPE =% 2 *% Y% 1 *] \ [COL =% 2 *% 03v% 1 *] \ [ROW =% 2 *% 03l% 1 * /% 3 *% L (% p% %)% 1 *] \ [DATE =% 2 *% {strftime (\ "% c \", getftime (expand (\ "%% \")))}% 1 *]
"set statusline =% F% m% r% h% w \ [FORMAT =% {& ff}] \ [TYPE =% Y] \ [ASCII = \% 03.3b] \ [HEX = \% 02.2B] \ [ POS =% 04l,% 04v] [% p %%] \ [LEN =% L]

function! InsertStatuslineColor (mode)
  if a: mode == 'i'
    hi statusline guibg = peru
  elseif a: mode == 'r'
    hi statusline guibg = blue
  else
    hi statusline guibg = black
  endif
endfunction

au InsertEnter * call InsertStatuslineColor (v: insertmode)
au InsertLeave * hi statusline guibg = orange guifg = white
hi statusline guibg = black

hi User1 guifg = gray
hi User2 guifg = red
hi User3 guifg = white

set winaltkeys = no

"map
nmap <tab> V>
nmap <s-tab> V <
vmap <tab>> gv
vmap <s-tab> <gv
"Open Save As Dialog
map <F2> <Esc>: browse saveas <CR>
"Viewing Project Files with the NERDTree Plugin
nmap <F3>: NERDTreeToggle planning <CR>
"Enable / Disallow Wrap
nmap <silent> <F5> <Esc>: call ToggleWrap () <CR>
"Show / Suppress Column Cursors
nmap <silent> <F6> <Esc>: call ToggleCursor () <CR>
"New Tab
map <F10> <Esc>: tabnew <CR>
"Show / Suppress Find High Brightness
nmap <silent> <A-f> <Esc>: call ToggleHLSearch () <CR>

function! ToggleWrap ()
     if & wrap
          set nowrap
     else
          set wrap
     endif
endfunction

function! ToggleHLSearch ()
     if & hls
          set nohls
     else
          set hls
     endif
endfunction

function! ToggleCursor ()
     if & cursorcolumn
          set nocursorline nocursorcolumn
     else
          set cursorline cursorcolumn
     endif
endfunction


let mapleader = ";" "defines the prefix of the shortcut, ie <Leader>
nmap <leader> v: tabedit $ MYVIMRC <CR>

"Configuration File
autocmd bufwritepost _vimrc source $ MYVIMRC

"Setting the file format
set fileformats = unix, dos, mac

"Template
autocmd! BufNewFile * silent! 0r $ VIM / vimfiles / skel / Template.%: e

"Specifying the backup file directory
set backupdir = F: \ Bak
set backupskip = D: / Temp / *

"Cancel Code Collapse
autocmd! BufNewFile, BufRead * setlocal nofoldenable
"Open / Close Code Collapse
nnoremap <space> za

"Optimizing Large File Editing
let g: LargeFile = 10

"Automatically load files
set autoread

set list!
set listchars = nbsp: ¬, tab: ┈┈, precedes: «, extends:», trail:
hi NonText ctermfg = 247 guifg = # a73111 cterm = bold gui = bold
hi SpecialKey ctermfg = 77 guifg = # 654321

augroup filetypedetect
   au BufNewFile, BufRead * .mxl setf mxl
augroup END 






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.