Common Vim operations, plug-ins, and vimrc files

Source: Internet
Author: User
Tags set background alphanumeric characters

Common Vim operations, plug-ins, and vimrc files

First:

My custom color scheme:

The evening color scheme of the system:

1. Common Operations
Vim, as a text editor, is powerful. In my opinion, it is quick editing, and rich extension plug-ins.
Therefore, it is very important to master Vim's quick editing method. Here we will list some efficiency-related operations that must be memorized.

<Basic edit operation>
Move up to bottom left and right: corresponding to top (K), bottom (J), left (H), right (l); this is the basic requirement, do not use direction keys, friends who use the direction keys cannot afford to hurt ~.
GG: Jump to the beginning of the document
G: jump to the end of the document
W: Jump to the beginning of the next word; 4 W: Jump to the beginning of the fourth word, and so on.
E: jump to the end of the next word.
B: Jump to the beginning of the previous word; 4b: Jump to the beginning of the fourth word, and so on.
0: Jump to the beginning of the line
^: Jump to the first character at the beginning of the line
$: Jump to the end of the row

<Quick edit operation>
=: Quickly adjust the indentation of the current line Gg = G: Quick indent adjustment for all documents
CTRL + P (CTRL + n): the quick completion command.CodeIt is very useful. In editing mode, enter a few characters and then enter this command to start searching and matching words at the beginning (bottom, enter this command repeatedly to search cyclically. this command willProgram.
CTRL + x + L: automatically fills in the content of a row. You can only search for matched lines in the current document. If multiple options are selected, you can use the quick completion command to select.
CTRL + x + F: Automatically complete the directory. If I enter c: \ P and press Ctrl + x + F, the c: \ Program Files \
Abbr: Abbreviation settings, such as: Abbr cmain int main (INT argc, char ** argv), you only need to enter cmain next time and then enter other non-alphanumeric characters, it will be automatically extended to int main (INT argc, char ** argv)
QA: the recording macro, which is not explained much, is prepared to repeat a series of operations. A better editor can record macros.
Q: End recording.
@ A: execute a macro, 100 @ A: repeat 100 times

<Search related>
By default, the search is case-sensitive. If it is case-insensitive, set ignorecase first.
F: Search for characters in the current row, for example, FX search for X, ';' find the next, ',' find the previous one.
/XXX: Search down XXX. XXX allows regular expressions.
? XXX: Lookup XXX. XXX allows regular expressions.
N: Find the next
N search for the previous one
*: Find and highlight words under the current cursor.
G *: search for and highlight the string containing the current word. For example, "helloworld world". Press g * on the world after the space, and "helloworld" is highlighted.
%: Search for the parentheses matching the position of the cursor, including () [] {}

<Replace related>
Replacement is Vim's strength, because regular expressions can be used to match strings.
Replace some characters in the expression:
%: Full Document Search
G: replace all
C: Confirm before replacement
The following are examples.
: S/AA/BB/G: replace AA in all strings containing AA in the row where the cursor is located with BB. G indicates that all matching points are replaced, if there is no G, replace the first matched
: S/\ <AA \>/BB/G: replace all AA that appears in the row where the cursor is located with BB. Replace only the word AA, which is similar to avel and will not be replaced.
: % S/AA/BB/G: replace AA in all strings containing AA in this document with bb
: S/AA/BB/G: replace AA in all strings containing aa that appear from row 12 to row 23 with bb
: 12, 23 S/^/#/: add the first line from 12 to 23 characters #
: % S = * $ ==: Delete unnecessary spaces at the end of all rows
: G/^ \ s * $/D: delete all blank lines that do not contain characters (spaces are not included.

<Copy and paste>
Y indicates copy, d Indicates delete, and P indicates paste. The copy and delete commands are used to move the cursor.
YY: copy the entire row
DD: deletes the entire row.
DDP: exchange the current row and the next row
Ggyg: Indicates copying the entire document.
Ggdg: Indicates deleting the entire document.
YW: copy the content from the current cursor to the end of the word where the cursor is located.
DW: deletes the content from the current cursor to the end of the word where the cursor is located.
Y0: copy the content from the current cursor to the beginning of the row where the cursor is located.
D0: deletes content from the current cursor to the beginning of the row where the cursor is located.
Y $: copy the content from the current cursor to the end of the row where the cursor is located.
D $: deletes content from the current cursor to the end of the row where the cursor is located.
Yfa: Indicates copying the content from the current cursor to the first a character after the cursor.
DFA: deletes the content from the current cursor to the first a character after the cursor.

 

2. Common plug-ins

This is not a plug-in. It is an independent program and needs to be installed in the directory contained in the system path.
the installation is simple. Download ctags.exe directly (in Windows) and put ctags In the System32 directory.
for ease of operation, you can set some shortcut keys in vimrc:
"----------------------------------------------- CAGs ------------------------------>
Map :! Ctags-r -- fields = + ls "generate tag files. If you like it, press F8"
"ing jump shortcut key to jump to the definition of words under the cursor, g] will list the jumps. If you need to automatically jump to the first record, map FJ "
map FJ g]
" jump back to the previous position "
map FF


this plug-in is used to view the variables and functions defined in the current file. It is very useful and widely used.
the installation is simple. Download taglist. put Vim in the plug-in directory of VIM.
In vimrc, set some options: (for more information, enter help taglist.txt.pdf. Remember to put taglist.txt into the vim doc directory)
"--------------------------------------------- taglist -------------------------- >>< br>" shortcut key "
noremap : tlisttoggle
"the following are some taglist Settings"
"set the location of the ctags program in Windows"
If mysys () = "Windows"
"specifies the location of the ctags program"
let tlist_ctags_cmd = 'ctags '
elseif mysys () = "Linux"
let tlist_ctags_cmd = '/usr/bin/ctags'
endif
"the tags of multiple files are not displayed at the same time, only show the current file "
let tlist_show_one_file = 1
" if the taglist window is the last window, exit Vim "
let tlist_exit_onlywindow = 1
" display the taglist window in the right window "
let tlist_use_right_window = 1
" and set to sort by name, in this way, it may be easier to find the function name "
tlist_sort_type =" name "
" The taglist window is automatically opened when Vim is started "
" tlist_auto_open = 1
"Open when taglist is used, the focus is automatically transferred to the taglist window. "
" tlist_gainfocus_on_toggleopen = 1
"The taglist always interprets the tag in the file, whether the taglist window is opened or not, "
" tlist_process_file_always = 1

<Nerd_tree.vim>
Directory tree. You can also open the file by using vim.
Download nerd_tree.vim and add it to the vim plugin directory.
In vimrc, set the following parameters:
"------------------------------------------- Nerd_tree.vim --------------------->
"Set shortcut keys"
NMAP <F2>: nerdtreetoggle <CR>

"Disable all commands related to nerd_tree"
"Let loaded_nerd_tree = 1
"Do Not Display specified types of files"
"Let nerdtreeignore = ['/. Vim $ ','/~ $ ']
"Do not show hidden files (as if only valid in Linux )"
Let nerdtreeshowhidden = 0
"Sort"
Let nerdtreesortorder = ['// $ ','/. CPP $ ','/. C $ ','/. h $ ','/. PY $ ','/. lua $ ',' * ']
"Case-insensitive sorting"
Let nerdtreecasesensitivesort = 0
"Set window size"
Let nerdtreewinsize = 30
"Show row number"
"Let nerdtreeshowlinenumbers = 1
"Show bookmarks"
"Let nerdtreeshowbookmarks = 1
"Close the nerdtrre window after opening the file"
"Let nerdtreequitonopen = 1
"Highlight the current row in the nerdtrre window"
Let nerdtreehighlightcursorline = 1

<Bufexplorer. Vim>
Used to switch the file currently opened by VIM.
Install bufexplorer. Vim in the plug-in directory of vim.
In vimrc, set the following parameters:
"--------------------------------------- Bufexplorer. Vim --------->"
Noremap ZZ: bufexplorer <CR>

After installing the above plug-ins, VIM is ready for use. <F2> open directory browsing, <F11> open taglist, <F5> Generate tag, FJ jump, FF jump return ZZ open buffer file window

Vimrc File
If the vimrc file is configured well, the operation will be more convenient and convenient. I will not mention it any more. attach my vimrc file:

------------------------------------------- Basic settings --------------------------- >>< br> set fileencodings = ucs-bom, UTF-8, cp936 "automatically recognized file encoding
set nocompatible" incompatible VI
set magic
set Ru "ruler Information
set ai" automatic indent
set Sw = 4 "auto indent width
set Ts = 4
set DY = lastline" displays the maximum number of rows, no @
set backspace = indent, EOL, start
Colo evening
sy on
set go = "no menu, toolbar
set nobackup
set hlsearch
set incsearch
set HLS
set showmatch
set autochdir "you need to automatically change the current Vim directory to the directory where the opened file is located. Set this item
set showcmd
set smartindent
set tags = tags; "set the search path of the Tag file
set tags + =/usr/include/tags;
filetype plugin on "support plug-ins
set cursorline" the current row has an underscore
set virtualedit = onemore
"set number" This item is set if a row number is to be displayed
BR> "set Path = ., /usr/include, include "additional search path for vimgrep
" highlight comment ctermfg = gray "set annotation color
" highlight macro ctermfg = Blue "set macro-defined color
" hi folded ctermfg = red ctermbg = darkblue
"Hi foldcolumn guibg = green guifg = grey20 ctermfg = 4 ctermbg = 7

"------------------------------------------- Shortcut key settings ----------------------->
Noremap <C-S>: Update <CR>
Noremap <F5>: W <CR> :! Python % <CR>

"File search
Noremap <F3>: vimgrep/<C-R> = expand ("<cword>") <CR>/J *. TXT *. CPP *. H *. PY *. java *. lua <CR >\|: Copen <CR>
Noremap <F7>: vimgrep/<C-R> = expand ("<cword>") <CR>/J **/*. TXT **/*. CPP **/*. h **/*. PY **/*. java **/*. lua <CR >\|: Copen <CR>
Noremap <C-F7>: vimgrep/<C-R> = expand ("<C-R> +") <CR>/J **/*. TXT **/*. CPP **/*. h **/*. PY **/*. java **/*. lua <CR >\|: Copen <CR>

"Tabedit
NMAP te: tabedit
Nmap tn: tabnew <CR>
Noremap <tab>: tabn <CR>

"------------------------------------------- Function Definition ------------------------->
Fun! Togglefold ()
If foldlevel ('.') = 0
Normal! L
Else
If foldclosed ('.') <0
. Foldclose!
Else
. Foldopen!
Endif
Endif
"Clear status line
Echo
Endfun

"Space key fold/expand fold
Noremap <space>: Call togglefold () <CR>

function foldbrace ()
If Getline (V: lnum + 1) [0] = '{'
return 1
endif
If Getline (V: lnum) = ~ '{'
return 1
endif
If Getline (V: lnum) [0] = ~ '}'
return '<1'
endif
return-1
endfunction
If has ("autocmd ")
filetype plugin indent on
augroup vimrcex
Au!
autocmd filetype text setlocal textwidth = 78
autocmd bufreadpost *
\ If line ("'\" ")> 0 & line ("'\" ") <= line (" $ ") |
\ exe "normal G' \" |
\ endif
au bufreadpost *. H ,*. HH ,*. C ,*. EC ,*. CPP ,*. HPP ,*. ecpp ,*. PC set foldexpr = foldbrace ()
au bufreadpost *. H ,*. HH ,*. C ,*. EC ,*. CPP ,*. HPP ,*. ecpp ,*. PC set foldmethod = expr
au bufreadpost *. H ,*. HH ,*. C ,*. EC ,*. CPP ,*. HPP ,*. ecpp ,*. PC set foldenable
au bufwinleave *. ztx mkview
au bufwinenter *. ztx silent loadview
au bufnewfile, bufread *. txt setf txt
augroup end
endif

"" Dialog box, asking the user to enter the string to be queried
"Search in the include and source directories. You can modify them as needed.
Function S: searchwordzx ()
Let findstring = inputdialog ("search string:", expand ("<cword> "))
If findstring! = ""
Execute "vimgrep" findstring "*"
Endif

Endfunction

"" ============================================== =
"" Reads the directory from sdir.txt and searches for the specified string under these directories,
"Ipvsdir.txt should be placed in the same directory as the source program.
Function S: searchwordglzx ()
Let searchstring = expand ("<cword> ")

Let searchdir =''
For line in readfile ("sdir.txt", '', 6)
Let searchdir. = fnameescape (Line). '*. [CSH]'
Endfor

If searchstring! = ""
Execute "vimgrep" searchstring searchdir
Endif

Endfunction

"============================================== ============================== Plug-in ============ ========================================================== ================
"------------------------------------------- Ctags ---------------------------->
Noremap <F8> :! Ctags-r -- fields = + ls <CR>
Nmap fj g]
Nmap ff <C-T>

"------------------------------------------- Taglist. Vim ---------------------->
Noremap <F11>: tlisttoggle <CR>

Let tlist_show_one_file = 1
Let tlist_exit_onlywindow = 1
Let tlist_use_right_window = 1

"------------------------------------------- Nerd_tree.vim -------------------->
"Set shortcut keys"
Noremap <F2>: nerdtreetoggle <CR>

"Disable all commands related to nerd_tree"
"Let loaded_nerd_tree = 1
"Do Not Display specified types of files"
"Let nerdtreeignore = ['/. Vim $ ','/~ $ ']
"Do not show hidden files (as if only valid in Linux )"
Let nerdtreeshowhidden = 0
"Sort"
Let nerdtreesortorder = ['// $ ','/. CPP $ ','/. C $ ','/. h $ ','/. PY $ ','/. lua $ ',' * ']
"Case-insensitive sorting"
Let nerdtreecasesensitivesort = 0
"Set window size"
"Let nerdtreewinsize = 30
"Show row number"
"Let nerdtreeshowlinenumbers = 1
"Show bookmarks"
"Let nerdtreeshowbookmarks = 1
"Close the nerdtrre window after opening the file"
"Let nerdtreequitonopen = 1
"Highlight the current row in the nerdtrre window"
Let nerdtreehighlightcursorline = 1

"------------------------------------------- Bufexplorer. Vim -------------------->
Noremap ZZ: bufexplorer <CR>

My custom color scheme file (for the effect, see the first image ):

 

Self. Vim (put the file in the colors directory of VIM, and then enter the command: Colo self in VIM to switch to the color scheme, which can also be specified in vimrc)

"Vim color file
"Maintainer: Bram moolenaar <Bram@vim.org>
"Last change: 2006 Apr 14

"This color scheme uses a dark gray background.

"First remove all existing highlighting.
Set background = dark
Hi clear
If exists ("syntax_on ")
Syntax Reset
Endif

Let colors_name = "self"

Hi normal ctermbg = black ctermfg = gray guifg = # c0c0c0 guibg = black GUI = none

"Groups used in the 'highlight 'and 'guicursor' options default value.
Hi errormsg term = standout ctermbg = darkred ctermfg = white guibg = red guifg = white
Hi incsearch term = reverse cterm = reverse GUI = reverse
Hi modemsg term = bold cterm = bold GUI = bold
Hi statusline term = reverse, bold cterm = reverse, bold guifg = none guifg = blackguibg = #606060
Hi statuslinenc term = reverse cterm = reverse GUI = none guifg = blackguibg = #606060
Hi vertsplit term = reverse cterm = reverse guifg = #606060 guibg = #606060 GUI = none
Hi visual term = reverse ctermbg = black guibg = #353535
Hi visualnos term = underline, bold cterm = underline, bold GUI = underline, bold
Hi difftext term = reverse cterm = bold ctermbg = red GUI = bold guibg = red
Hi cursor guibg = # dddddd guifg = black
Hi lcursor guibg = cyan guifg = black
Hi directory term = bold ctermfg = lightcyan guifg = lightgreen GUI = underline
Hi linenr term = underline ctermfg = cyan guifg = #388080
Hi moremsg term = bold ctermfg = lightgreen GUI = bold guifg = seagreen
Hi nontext term = bold ctermfg = lightblue guifg = lightblue guibg = black
Hi question term = standout ctermfg = lightgreen GUI = bold guifg = green
Hi search term = reverse ctermbg = yellow ctermfg = black guibg = lightyellow guifg = black
Hi specialkey term = bold ctermfg = lightblue guifg = cyan
Hi title term = bold ctermfg = lightmagenta GUI = bold guifg = Magenta
Hi warningmsg term = standout ctermfg = lightred guifg = red
Hi wildmenu term = standout ctermbg = yellow ctermfg = black guibg = yellow guifg = black
Hi folded term = standout ctermbg = lightgrey ctermfg = darkblue guibg = darkgrey guifg = darkblue
Hi foldcolumn term = standout ctermbg = lightgrey ctermfg = darkblue guibg = grey guifg = darkblue
Hi diffadd term = bold ctermbg = darkblue guibg = darkblue
Hi diffchange term = bold ctermbg = darkmagenta guibg = darkmagenta
Hi diffdelete term = bold ctermfg = blue ctermbg = darkcyan GUI = bold guifg = blue guibg = darkcyan
Hi cursorcolumn term = reverse ctermbg = black guibg = grey40
Hi cursorline terms = underline cterm = underline guibg = #202020
"Syntax keyword
Hi statementguifg = #005 cffctermfg = bluectermbg = blackgui = none
Hi preprocguifg = #005 cffctermfg = blue
"Type keyword
Hi typeguifg = #005 cffctermfg = bluectermbg = blackgui = none
"Comment
Hi commentguifg = greenctermfg = greenctermbg = blackgui = none
"Constant
Hi constant term = underline ctermfg = Magenta guifg = # ff8000 GUI = none
"Number
Hi number term = underline ctermfg = Magenta guifg = Magenta GUI = none
"Identifier, such as function end if in Lua
Hi identifierguifg = #005 cffctermfg = redgui = none
"Tag
Hi labelguifg = yellowctermfg = yellow
Hi operatorguifg = orangectermfg = lightredctermbg = darkblue
Hi tabline guifg = black GUI = none
Hi tablineselgui = none
Hi tablinefillguibg = darkgreygui = none
Hi matchparen ctermbg = blue guibg = lightblue guifg = black
Hi pmenuguibg = #101010 guifg = #909090 GUI = none

 

"Groups for syntax highlighting
Hi special term = bold ctermfg = lightred guifg = Orange guibg = grey5
Hi ignore ctermfg = darkgrey guifg = grey20

"VIM: Sw = 2

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.