Vim basic configuration and Common commands

Source: Internet
Author: User
Advantages and application scenarios of VIM

Vim's advantage lies in its pure editing and the perfect integration of Linux with command lines. If you can only use SSH to perform operations on the server, you can only use Vim in this case. Vim is also one of the most powerful generic text editors. For scenarios where different texts need to be edited, VIM is also quite advantageous. Therefore, it is necessary to master the basic use of vim.


Vim is developed based on VI with a lot of new features, while gvim adds a graphical front-end to vim. If you use Vim in Windows, you can install the latest gvim directly.


Here is a basic vimrc configuration file. No plug-ins are configured, but the subject is changed to the built-in evening dark-tuned topic, the font is changed to the wide font like Las LAS, And the row number is indented, search and other basic settings. In addition, the key ing <ESC>-> II is implemented. I was originally switched to the insert mode. Double-click I quickly, and then switched back to the normal mode.
  • In Linux, A. vimrc file is usually created in the user's home directory for modification. Instead of modifying the global configuration under the/etc/Vim directory, it affects all users.
  • In Windows, vimrc is located in the c: \ Program Files (x86) \ Vim directory and named _ vimrc. If everything is installed, you can directly search for vimrc to locate it.
Vim configuration file vimrc
"Identifier: imap ii <ESC>" Key ing <ESC>-> II "appearance colorscheme evening" Configure color theme set guifont = consolas: h12 "Set Font and size set number" display row number set guioptions-= T "Hide toolbar set r0000" open status bar ruler set cursorline" highlight current row set syntax = on "syntax highlight set showmatch "highlighted matching parentheses set matchtime = 3" matching the time when brackets are highlighted (unit: 0.1 s) set scroloff = 10 "move the cursor to the bottom of the screen to keep 10 rows (the cursor is at the bottom of the screen and looks uncomfortable)" Search for set ignorecase smartcase "Search ignore case sensitivity, however, when there are uppercase letters, the set hlsearch "highlighted search set incsearch" incremental search is still case sensitive, highlight by character "operation set clipboard + = unnamed" shared clipboard set showcmd "the input command shows set iskeyword + =_, $, @, % ,#, -"Do not use line breaks to separate words with the following symbols: Set noexpandtab" do not use spaces to replace tab (makefile often uses tab) set tabstop = 4 "The width of the tab key set shiftwidth = 4" The line staggered width set mouse = A "The mouse can use set autoindent" to inherit the indent of the previous line, it is particularly applicable when the multi-line comment "Backup set confirm" is not saved or read-only, pop-up confirmation set nobackup "do not generate backup file setlocal noswapfile" do not generate swap file set bufhidden = hide "when the buffer is discarded, hide set noerrorbells" no warning "decoding set fenc = UTF-8 set fencs = UTF-8, USC-bom, EUC-JP, gb18030, GBK, gb2312, cp936

Common Vim commands

# Efficiency. # repeat recent text operations # file: Q # exit Q-> quit: W # Save w-> write: Q! # Force exit and not save: WQ # Save and exit ZZ # Save and exit, same as: WQ # move the cursor hjkl # The most basic left bottom top right, move a character ZZ # move the cursor to the middle of the screen W # Move a word forward, stop the cursor at the word header B # Move a word backward, and stop the cursor at the word header e # The same W, cursor stops at the end of the word Ge # Same as B, cursor stops at the end of the word 0 # the first character of the line (same as the <Home> key) ^ # The first non-blank character of the line $ # Move to the end of the line (same as the <End> key) gg # Move to the file header G # Move to the end of the file FX # Move to the cursor after the first X character find FX # Same as F, move Ctrl + D # scroll down half screen Ctrl + u # scroll up half screen Ctrl + F # scroll down half screen Ctrl + B # scroll up half screen % # Jump to matching brackets (common) (# Move to the start of the current sentence) # Move to the start of the next sentence h # Move the top of the page H-> Hi GHM # Move the middle of the page M-> middlel # Move the bottom of the page L-> low # Find/test # search for text (remember to use a regular expression), then n down, N up n-> next? Test # search for text, reverse # Replace Ra # Replace the current character with, r-> replace % S/old/new/G # Replace all matching G-> global % S/old/new/# Replace the first matching S/old of all rows. /New/G # Replace all matching S/old/new/# Replace the first matching of the current row # insert a after the current position a-> appenda # in the current row insert I at the end # insert I at the current position-> inserti # insert O at the beginning of the current row # insert one row after the current Row O # insert a row before the current row # select V # From the cursor starts at the current position, the cursor is selected, followed by V (similar to <shift> + direction) V-> View visual mode V # starts from the current row of the cursor, all rows passing by the cursor will be selected, and then click V to end # delete D # Delete selected (the deleted content can be pasted in the buffer, which is equivalent to cutting) d-> deletex # Delete the current character 3x # Delete the three characters behind the current cursor (Vim often uses the <number> + <command> combination) dd # Delete the current row d $ # Delete the current character to the end of the row %-> regular expression is the end of the row 3D # Delete the current row and start with three lines J # merge two lines (that is, delete when the end of the row) line Break) j-> join # undo U # undou # undo the right row operation Ctrl + R # undo # copy and paste y # copy selected YY # copy current row p # In paste the current cursor, if you copy a row, paste it to the next row p-pastep # paste DDP before the current cursor # swap the current row and next line (cleverly use cut paste) XP # swap the current character and next line

Vim basic configuration and Common commands

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.