Powerful Vim configuration to make programming more casual

Source: Internet
Author: User
Tags set background

It took a long time to sort out and shared it easily.

My Vim configuration has the following advantages:

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. The code is highlighted and automatically indented. The line number and status line are displayed.

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:

Vim is a very powerful and convenient editor. With my code added, it will certainly become even more powerful. Maybe readers can modify it based on their own needs using other programming languages, annotations have been added to the configuration file.

If you are interested, copy the following code to a text file and rename it ". vimrc (do not forget the previous ". "), and then put the file under the root directory of the user folder. Open Vim again to see the effect.

"""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" "Display related """"""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" "set shortmess = ATI" does not display the prompt to assist children in Uganda when it is started. "winpos 5 5" set window position "set lines = 40 columns = 155" set window size "set nu" display row number set go = "do not graphic button" color asmanian2 "Set background topic set guifont = courier_new: h10: cansi "Set Font" syntax on "syntax highlight 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 rter" display ruler set showcmd "the command entered is displayed, clear the height of the "set height Height = 1" command line (under the Status line), set to 1 "set whichwrap + = <,>, H, L "allow 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 from 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 \ ")}" Set laststatus = 1 "Start display status line (1), always show status line (2) set foldenable "allow fold set foldmethod = manual" manual fold "Set background = Dark" background use black set nocompatible "Remove annoying VI consistency modes, avoid bugs and limitations in earlier versions "show Chinese help if version> = 603 set helplang = cn set encoding = utf-8endif" set color scheme "colorscheme Murphy" font "If (has (" gui_running ")) "Set guifont = bitstream \ Vera \ Sans \ mono \ 10" endif set fencs = UTF-8, uc-bom, shift-JIS, gb18030, GBK, gb2312, cp936set termencoding = utf-8set encoding = utf-8set fileencodings = UCS-bom, UTF-8, cp936set fileencoding = UTF-8 """""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" """"""""""" """""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" "New. C ,. H ,. sh ,. java file, automatically Insert the file header autocmd bufnewfile *. CPP ,*. [CH], *. sh ,*. java EXEC ": CA Ll settitle () "defines the function settitle, automatically inserts the file header func settitle ()" If the file type is. sh file 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 Ppend (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 creating a file, it is automatically located at the end of the file. autocmd bufnewfile * normal gendfunc "" """""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" """"""""""""""""" """""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" "NMAP <leader> W: w! <CR> NMAP <leader> F: Find <CR> "ing all select + copy Ctrl + AMAP <C-A> ggvgymap! <C-A> <ESC> ggvgymap <F12> GG = G "press Ctrl + C to copy vmap <c-c>" + Y "to empty line nnoremap <F2>: g/^ \ s * $/d <CR> "Compare file nnoremap <C-F2>: vert diffsplit" new tag Map <M-F2>: tabnew <CR> "list the current directory file Map <F3>: tabnew. <CR> "Open the tree file directory Map <C-F3> \ be" C, C ++ press F5 to compile and run 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 ':!. /% Endifendfunc "C, C ++ debugging Map <F8>: Call rungdb () <CR> func! Rungdb () EXEC "W" EXEC "! G ++ %-g-o % <"EXEC "! GDB. /% <"endfunc """"""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" """"""""" """""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" "sets to automatically load set autoread when a file is changed." quickfix mode: autocmd filetype C, CPP Map <buffer> <leader> <space>: W <CR>: Make <CR> "Code Completion set completeopt = preview, menu" allow plug-in filetype plugin on "share clipboard set Clipboard + = unnamed "never back up set nobackup" Make run: set makeprg = g ++ \-wall \ % "automatically save set autowriteset rloud" Open the status bar ruler set cursorline "highlight the current row set magic" set magic set guioptions-= t" hide toolbar set guioptions-= m "Hide menu bar" set statusline =\% <% F [% 1 * % m % * % N % R % H] %=\% Y \ % 0 (% {& fileformat} \%{ & encoding} \ % C: % L/% L %) \ "set foldcolumn = 0 set foldmethod = indent set foldlevel = 3 set foldenable" start to fold "do not use VI's keyboard mode, but Vim's own S Et nocompatible "syntax highlight set syntax = on" voice set noeb "when processing unsaved or read-only files, pop-up confirmation set confirm "automatic indent set autoindentset cindent" tab key width set tabstop = 4 "unified indent to 4 set softtabstop = 4 set shiftwidth = 4" do not use spaces to replace the tab set noexpandtab "Use the tab set smarttab at the beginning of the row and segment" display the row number set number "Number of historical records set history = 1000" prohibit the generation of temporary files set nobackupset noswapfile "Search ignore case-sensitive set ignorecase" search character highlight set hlsearchset incsearch "intra-row replacement set gdefault" encoding settings set ENC = utf-8se T fencs = UTF-8, ucs-bom, shift-JIS, gb18030, GBK, gb2312, cp936 "language settings set langmenu = zh_CN.UTF-8set helplang = cn" my status line shows the content (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 shows the height of the Status line set laststatus = 2" command line (under the Status line). The default value is 1, here is 2 set upload Height = 2 "detects file type filetype on" loads file type plug-in filetype plugin On "loading the relevant indent file filetype indent on for a specific file type" Save the global variable set viminfo + =! "Do not use line breaks to separate words with the following symbols: Set iskeyword + =_, $, @, % ,#, -"Number of pixel lines inserted between characters" set linespace = 0 "command lines in enhancement mode automatically complete operation set wildmenu" enable backspace to process indent, EOL, set backspace = 2, such as start, "allow backspace and the optical mark key to span the row Boundary set whichwrap + = <,>, H, L "set mouse = aset selection = exclusiveset selectmode = mouse, key" can be used anywhere in the buffer (similar to double-clicking the mouse in the workspace in the office) by using the commands command, tell us which row of the file has been changed. Set Report = 0 "Blank is displayed in the split window. It is easy to read set fillchars = vert: \, STL: \, stlnc :\" Highlighted matching parentheses set showmatch "the time when matching parentheses are highlighted (unit: 10 s) set matchtime = 1 "when the cursor moves to the top and bottom of the buffer, keep three lines away from set scroloff = 3" provides automatic indentation for the c program set smartindent "to highlight common TXT files (txt is required. vim script) 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> ifunction! Closepair (char) If Getline ('. ') [col ('. ')-1] = A: Char return "\ <right>" else return a: Char endifendfunctionfiletype plugin indent on "open file type detection, this sentence can be used to intelligently complete set completeopt = longest, menu """"""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" "ctags """""""""""""""""" """""""""""""""""""""""""""""""""""""""" "Let tlist_sort_type = "name" "sort 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 let tlist_enable_fold_column = 0" do not show 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 tags of multiple files at the same time, only "set tags = tags" set autochdir """"""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" "other """""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" "opens the default taglist let tlist_auto_open = 1 """"""""""""""""""""""""""" "tag list (ctags) "Let tlist_ctags_cmd = '/usr/bin /ctags 'let tlist_show_one_file = 1 "does not display tags of multiple files at the same time, only show the current file's 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 in the right window" minibufexpl plug-in general settings Let G: minibufexplmapwindownavvim = 1let G: Fill = 1let G: Fill = 1 Let G: minibufexplmodseltarget = 1
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.