Vim editor setting file

Source: Internet
Author: User
Tags set background sorted by name

Vim configuration 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. 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.

 


The following is the configuration file:

"""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" """"""""""


"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: [email protected]")

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: [email protected]")

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

"File set complete


Note:

The following is a blog I found on the Internet that I wrote in my blog, called xiaocode, and reproduced it in my blog.

(Because you cannot write a link in the csdn blog, I 'd like to explain it to Tom here. Thank you for sharing !)


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.