Vim configuration instructions
Vim is widely recognized as perfect, but it is not easy for new users to get started. In Windows, many programmers like the Source Insight tool to view the code. The syntax highlighting is very comfortable. Vim is an editor created for programmers. It makes no sense not to allow programmers to easily edit code through configuration. However, it is difficult for new users to configure vim as an easy-to-use environment.
You only need to modify the. vimrc configuration file content in the home directory to customize the vim function.
You can set ~ /. Replace the content in vimrc with the following content, or directly modify the content as needed ("the content below is the comment content ):
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""
"Display related
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""
"Set shortmess = atI" does not display the prompt to assist children in Uganda at startup
"Winpos 5 5": Set the window position
"Set lines = 40 columns = 155" sets the window size.
"Set nu" display row number
Set go = "do not use graphical buttons
"Color asmanian2" sets the background topic
Set guifont = Courier_New: h10: cANSI "set the font
"Syntax on" syntax highlighting
Autocmd InsertLeave * se nocul "highlight the current line with a light color
Autocmd InsertEnter * se cul "highlight the current line with a light color
"Set ruler" display ruler
Set showcmd "the input command is displayed, which is clear.
"Set height Height = 1" height of the command line (under the Status line), set to 1
"Set whichwrap + = <,>, h, l" allows backspace and cursor keys to span row boundaries (not recommended)
"Set scroloff = 3" move the cursor to the top and bottom of the buffer to keep three rows away.
Set novisualbell "Do Not flash (do not understand)
Set statusline = % F % m % r % h % w \ [FORMAT = % {& ff}] \ [TYPE = % Y] \ [POS = % l, % v] [% p %] \%{ strftime (\ "% d/% m/% y \-\ % H: % M \")} "status line display content
Set laststatus = 1 "Start display status line (1), always display status line (2)
Set foldenable "folding allowed
Set foldmethod = manual "manual folding
"Set background = dark" background black
Set nocompatible "removes the annoying vi consistency mode to avoid bugs and limitations in earlier versions.
"Show Chinese help
If version> = 603
Set helplang = cn
Set encoding = UTF-8
Endif
"Set the color scheme
"Colorscheme murphy
"Font
"If (has (" gui_running "))
"Set guifont = Bitstream \ Vera \ Sans \ Mono \ 10
"Endif
Set fencs = UTF-8, ucs-bom, shift-jis, gb18030, gbk, gb2312, cp936
Set termencoding = UTF-8
Set encoding = UTF-8
Set fileencodings = ucs-bom, UTF-8, cp936
Set fileencoding = UTF-8
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""
"New File title
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""
"Create A. c,. h,. sh,. java file and insert the file header automatically.
Autocmd BufNewFile *. cpp, *. [ch], *. sh, *. java exec ": call SetTitle ()"
"" Defines the SetTitle function to automatically insert a file header.
Func SetTitle ()
"If the file type is. sh
If & filetype = 'sh'
Call setline (1, "\###################################### ###################################")
Call append (line ("."), "# File Name:". expand ("% "))
Call append (line (".") + 1, "# Author: ma6174 ")
Call append (line (".") + 2, "# mail: ma6174@163.com ")
Call append (line (".") + 3, "\ # Created Time:". strftime ("% c "))
Call append (line (". ") + 4, "\###################################### ###################################")
Call append (line (".") + 5 ,"\#! /Bin/bash ")
Call append (line (".") + 6 ,"")
Else
Call setline (1, "/************************************** ***********************************")
Call append (line ("."), "> File Name:". expand ("% "))
Call append (line (".") + 1, "> Author: ma6174 ")
Call append (line (".") + 2, "> Mail: ma6174@163.com ")
Call append (line (".") + 3, "> Created Time:". strftime ("% c "))
Call append (line (". ") + 4, "*************************************** *********************************/")
Call append (line (".") + 5 ,"")
Endif
If & filetype = 'cpp'
Call append (line (".") + 6, "# include <iostream> ")
Call append (line (".") + 7, "using namespace std ;")
Call append (line (".") + 8 ,"")
Endif
If & filetype = 'C'
Call append (line (".") + 6, "# include <stdio. h> ")
Call append (line (".") + 7 ,"")
Endif
"After a new file is created, it is automatically located at the end of the file.
Autocmd BufNewFile * normal G
Endfunc
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""
"Keyboard commands
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""
Nmap <leader> w: w! <Cr>
Nmap <leader> f: find <cr>
"Select all ing + copy ctrl +
Map <C-A> ggVGY
Map! <C-A> <Esc> ggVGY
Map <F12> gg = G
"Ctrl + c copy in selected state
Vmap <C-c> "+ y
"Empty row Removal
Nnoremap <F2>: g/^ \ s * $/d <CR>
"Compare files
Nnoremap <C-F2>: vert diffsplit
"New tag
Map <M-F2>: tabnew <CR>
"List current directory files
Map <F3>: tabnew. <CR>
"Open the tree file directory
Map <C-F3> \ be
"C, C ++ compile and run by F5
Map <F5>: call CompileRunGcc () <CR>
Func! CompileRunGcc ()
Exec "w"
If & filetype = 'C'
Exec "! G ++ %-o % <"
Exec "! ./% <"
Elseif & filetype = 'cpp'
Exec "! G ++ %-o % <"
Exec "! ./% <"
Elseif & filetype = 'java'
Exec "! Javac %"
Exec "! Java % <"
Elseif & filetype = 'sh'
:!. /%
Endif
Endfunc
Debugging of "C, C ++
Map <F8>: call Rungdb () <CR>
Func! Rungdb ()
Exec "w"
Exec "! G ++ %-g-o % <"
Exec "! Gdb./% <"
Endfunc
"""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""
"" Practical settings
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""
"Set automatic loading when the file is changed
Set autoread
"Quickfix Mode
Autocmd FileType c, cpp map <buffer> <leader> <space>: w <cr>: make <cr>
"Code Completion
Set completeopt = preview, menu
"Allow plug-ins
Filetype plugin on
"Share clipboard
Set clipboard + = unnamed
"Never back up
Set nobackup
"Make run
: Set makeprg = g ++ \-Wall \ %
"Automatically save
Set autowrite
Set ruler "Open the status bar ruler
Set cursorline "to highlight the current row
Set magic "set magic
Set guioptions-= T "Hide Toolbar
Set guioptions-= m "hide the menu bar
"Set statusline =\% <% F [% 1 * % M % * % n % R % H] %=\% y \ % 0 (% {& fileformat} \ % {& encoding} \ % c: % l/% L % )\
"Set the information displayed in the status line
Set foldcolumn = 0
Set foldmethod = indent
Set foldlevel = 3
Set foldenable
"Do not use the vi keyboard mode, but vim's own
Set nocompatible
"Syntax highlighting
Set syntax = on
"Remove the input error prompt sound
Set noeb
"Confirmation pops up when processing unsaved or read-only files
Set confirm
"Auto indent
Set autoindent
Set cindent
"Tab key width
Set tabstop = 4
"Unified indent to 4
Set softtabstop = 4
Set shiftwidth = 4
"Do not use spaces instead of tabs
Set noexpandtab
"Use a tab at the beginning of a row and segment
Set smarttab
"Display row number
Set number
"Number of historical records
Set history = 1000
"Do not generate temporary files
Set nobackup
Set noswapfile
"Case-insensitive search
Set ignorecase
"Search for highlighted characters by character
Set hlsearch
Set incsearch
"Intra-row replacement
Set gdefault
"Encoding settings
Set enc = UTF-8
Set fencs = UTF-8, ucs-bom, shift-jis, gb18030, gbk, gb2312, cp936
"Language settings
Set langmenu = zh_CN.UTF-8
Set helplang = cn
"Content displayed in my status line (including file type and decoding)
"Set statusline = % F % m % r % h % w \ [FORMAT = % {& ff}] \ [TYPE = % Y] \ [POS = % l, % v] [% p %] \%{ strftime (\ "% d/% m/% y \-\ % H: % M \")}
"Set statusline = [% F] % y % r % m % * % = [Line: % l/% L, Column: % c] [% p %]
"Always show status line
Set laststatus = 2
"The height of the command line (under the Status line). The default value is 1. Here is 2.
Set bytes Height = 2
"File type detection
Filetype on
"Load file type plug-in
Filetype plugin on
"Load indent files for a specific file type
Filetype indent on
"Save global variables
Set viminfo + =!
"Do not separate words with the following symbols by line breaks
Set iskeyword + =_, $, @, % ,#,-
"Number of pixel rows inserted between characters
Set linespace = 0
"The command line in enhanced mode automatically completes the operation
Set wildmenu
"Enable backspace to process indent, eol, start, and so on.
Set backspace = 2
"Allow backspace and cursor keys to span row boundaries
Set whichwrap + = <,>, h, l
"You can use the mouse anywhere in the buffer (similar to double-click the mouse in the workspace in office to locate the location)
Set mouse =
Set selection = exclusive
Set selectmode = mouse, key
"The commands command tells us which row of the file has been changed.
Set report = 0
"White space is displayed between Split windows for ease of reading
Set fillchars = vert: \, stl: \, stlnc :\
"Highlight matching brackets
Set showmatch
"Matching the time when brackets are highlighted (unit: 10 seconds)
Set matchtime = 1
"Move the cursor to the top and bottom of the buffer to keep the distance between three rows
Set scroloff = 3
"Provides automatic indentation for C Programs
Set smartindent
"Highlight common txt files (txt. vim script is required)
Au BufRead, BufNewFile * setfiletype txt
"Auto-completion
: Inoremap () <ESC> I
: Inoremap) <c-r> = ClosePair (') <CR>
: Inoremap {<CR >}< ESC> O
: Inoremap} <c-r >= ClosePair ('}') <CR>
: Inoremap [[] <ESC> I
: Inoremap] <c-r> = ClosePair (']') <CR>
: Inoremap "" <ESC> I
: Inoremap ''' <ESC> I
Function! ClosePair (char)
If getline ('.') [col ('.')-1] = a: char
Return "\ <Right>"
Else
Return a: char
Endif
Endfunction
Filetype plugin indent on
"Enable the file type check. You can use this sentence to complete it intelligently.
Set completeopt = longest, menu
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""
"CTags settings
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""
Let Tlist_Sort_Type = "name" "sorted by name
Let Tlist_Use_Right_Window = 1 "display the window on the right
Let Tlist_Compart_Format = 1 "compression mode
Let Tlist_Exist_OnlyWindow = 1 "if there is only one buffer, the kill window also kill the buffer.
Let Tlist_File_Fold_Auto_Close = 0 "do not close the tags of other files
Let Tlist_Enable_Fold_Column = 0 "do not display the folding tree
Autocmd FileType java set tags + = D: \ tools \ java \ tags
"Autocmd FileType h, cpp, cc, c set tags + = D: \ tools \ cpp \ tags
"Let Tlist_Show_One_File = 1" does not display the tags of multiple files at the same time, only displays
"Set tags
Set tags = tags
"Set autochdir
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""
"Other things
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""
"Open Taglist by default
Let Tlist_Auto_Open = 1
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""
"Tag list (ctags)
"""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""
Let Tlist_Ctags_Cmd = '/usr/bin/ctags'
Let Tlist_Show_One_File = 1 "the tag of multiple files is not displayed at the same time, only
Let Tlist_Exit_OnlyWindow = 1 "if the taglist window is the last window, exit vim
Let Tlist_Use_Right_Window = 1 "display the taglist window on the right
"General settings of the minibufexpl plug-in
Let g: miniBufExplMapWindowNavVim = 1
Let g: miniBufExplMapWindowNavArrows = 1
Let g: miniBufExplMapCTabSwitchBufs = 1
Let g: miniBufExplModSelTarget = 1
Vim configurations have the following features:
1. Press F5 to directly compile and execute C, C ++, java code, and shell scripts. Press F8 to debug C and C ++ code.
2. the file header is automatically inserted. When a C and C ++ source file is created, the header is automatically inserted, including the file name, author, contact information, and creation time. You can change the header as needed.
3. Map "Ctrl + A" to select all and copy the shortcut keys to facilitate code copying.
4. Press F2 to directly eliminate empty lines in the code
5. "F3" can list the current directory file and open the tree file directory.
6. Support mouse selection and direction key movement
7. Code highlight, automatic indent, line number, and status line
8. Press Ctrl + P to automatically complete
9. [], {}, (), "", '', and so on are all automatically completed.
10. Readers of other functions can study the following documents:
-------------------------------------- Split line --------------------------------------
Build VIM into a simple and practical IDE
Vim Learning Guide
Quick learn Vi Editor
Powerful Vim Editor
Build a Vim Development Environment on CentOS 6.2
Install the highlighted Vim editing tool in CentOS 5.4
Vim tips: C language settings
Set the Vim row number in Ubuntu
Vim editor basic tutorial
-------------------------------------- Split line --------------------------------------
This article permanently updates the link address: