Notes on Vim

Source: Internet
Author: User
Tags variable scope

I sorted out Vim notes and filled the gaps in China in some aspects-it's about tabs and spaces (background sound: You can throw tomatoes ).

 

1. Open the horizontal scroll bar.
A, set guioptions + = B # (bottom scrollbar)
B, set nowrap

2. scrolling
A, a row [down: ctrl + e, up: ctrl + y (Win32 + p)]
B, half screen [down: ctrl + d, up: ctrl + u]
C. Full Screen [down: ctrl + f, up: ctrl + B]

3. Move the rows on the screen (valid for auto-discount rows)
A. Move down a line of gj on the screen
B. Move up the gk line of the screen

4. Enter the Visual (select) mode.
A, single character [v]
B, the whole line [shift + v]
C, Block [Win32: ctrl + q, Unix: ctrl + v]

5, fold
A. Create a line -- [zf {motion}]
B. Open -- [zo] to open all nested rows -- [zO] to open all rows -- [zR]
C, fold -- [zc] Fold the hidden line -- [zC] Fold all the lines -- [zM]
D. Delete -- [zd] delete all rows (valid only for the first line of the line) -- [zD]
E. Show the left-side line mark: set foldcolumn = 4

6. display the control character [help listchars]
A, set listchars = tab:>-, eol: $, trail :-
B, trick & tips: using searching hightline:
B, 1: [/\ t] -- show tabs.
B, 2: [/\ s \ + $] -- show trailing whitespace.
B, 3: [/\ + \ ze \ t] -- show spaces before a tab.

7. display the row number
A, set number
B, set nonumber

8. character width control
A. number of characters displayed per line: textwidth = 72
B. Number of characters occupied by indentation: shiftwidth = 2 | increase the indentation of the current row (filled with spaces):>
C. Number of characters in a Tab: tabstop = 4
B .1, tabstop -- (display angle) the length of a tab (binary encoding: 0x09 at the underlying layer );
B .2, softtabstop -- vim indicates the total number of spaces (0x20) that must be completed when the tab key is pressed ).
For example, when softtabstop is 4,
> When there is one space before the cursor, you press tab to add three spaces to complete four spaces;
> When there are two spaces before the cursor, you press tab to add two spaces to complete the four spaces.
> If there are four spaces before the cursor, you do not need to complete them. Continue to the next round and find that there are only 0 spaces, so there are 4 spaces at a time. -- It is equivalent to four Space key connections.
Note (Key Point): When you press softtabstop to complete the number of spaces (including the preceding spaces), you can generate a tab, vim automatically converts all leading spaces to the width of tabstop (0x20 for each tabstop width) to a tab (0x09) character.
B .3, expandtab -- convert a tab to a space (expand the tab as blankspaces where you are typing, the amount of expanding based on settings of softtabstop/tabstop)
B .4, retab {number} -- Re-calculate the tab based on the number (the spaces around the tab are also included ),
For example, if the current tabstop is 8, you perform two actions when you [retab 2:
> Step 1: Split a tab (Originally 8 characters) into four tabs (now 2 Characters for tab ).
> Step 2: Set tabstop to 2.

9. view the file in binary mode.
A, %! Xxd -- the entire file (%) dump is in binary format
B, %! Xxd-r -- reverse the file to the original format

10. Auto-completion
A, I _CTRL_P -- Previous Match, I _CTRL_N -- Next Match
B, I _CTRL_X (entering the completion mode) + CTRL_O

11, special characters
A, I _CTRL_V + {special char} Or I _CTRL_V + {digits} [CTRL_Q instead of CTRL_V in Win32]
B, weird symbol (fit word, Digraphs) I _CTRL_K + {digraphs} |: digraphs -- Show all of digraphs
C. view the character encoding under the current cursor [ga]

12. Compare the buffer zone with the original file-display the changes that have been made
A, DiffOrig

13. addition and subtraction
A, addition: {count} CTRL + A -- add the number under the cursor to count. (unmap is used in Win32 to cancel the "select all" function of CTRL +)
B, subtraction: {count} CTRL + X

14. case-sensitive Conversion
A, rule -- Current Character guw -- current word
B, rule -- Current Character gUw -- current word

15. Virtual editing
A, set virtualedit = all -- you can move the cursor to any position (column) in a row ).
Note: if this is not a blank line (blank line & empty line), the cursor automatically returns to the end of the line.
> If you want to avoid this problem, you can use r to replace it. All the spaces from the replacement to the cursor position are automatically filled with spaces.
B. Virtual replacement: gr or gR (entering the virtual replacement mode) -- allows the replaced character to occupy the proper space, which is particularly useful when replacing the tab (0x09.

16. Fast Moving
A, f + {character} looks for a character forward (parked on this character)
B, F + {character} searches for a character (parked on this character ).

17. Jump cursor
A, ''(two delimiters) return to the previous position. Note: commands such as w, B, and fx cannot be considered jumps.
B, CTRL_O jump back (older)
C, CTRL_ I jump forward

18. Movement in the program
A, [+ {-- this block header, [+/-- This annotation header, [+ m -- this function Header
B,] + {-- end of the block,] +/-- end of the comment,] + m -- end of the Function

19. format the program code.
A, = current row, gg = G entire file
B. Auto indent by file type: filetype indent on

20. format the text.
A, set textwidth = 78
B, gggqG -- format the entire document

21. Delete empty rows.
A,: g/^ $/d -- delete empty rows
B,: g/\ s \ +/d -- Delete trailing whitespace.

22. variables in the Vim script
A. Special variables in the script
$ NAME environment variable NAME
& Name options in Vim (such as ts and sw)
@ Name Register name in Vim
B. variable scope identifier
Name Function
B: The name is partial to a buffer zone.
W: name is partial to a window
G: name global variable
V: name Vim pre-defined variable

99. Solution for occupying the corresponding key combinations in Windows
A, unmap {<C-A >}-- Disable CTRL + A (all selected) in Windows.

# Vim: set shiftwidth = 2 foldmethod = indent tabstop = 8 :#


 

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.