How to program zz with vi

Source: Internet
Author: User

After using Emacs for nearly two years, I did not expect that I would not have the opportunity to feel it when I entered the company .. All of them are in the bare environment, and once or twice it is okay ..

Switch to the VI camp is not just an environmental reason. I feel that the VI operation is faster and it will greatly improve the efficiency if I stick to some commands for a long time.

3.27. The ctags are still being explored in several new areas ·

Zero-browsing code

When getting open source code or similar legacy code, reading is essential. I usually like to browse the code, length, format, and whether it meets my personal aesthetic point of view first, then start learning. Therefore, the first commonly used command is to open the text Browser: {} is still a habit in Windows for many years. It is still very nice to check the code in coloring and freely available, in one breath, open the code file in the folder. From the main point of view, you can guess the name, and open all the files if you cannot guess the name. IDE functions.

 

1. open the file:

Different from step 1, here we will introduce some of the commands required to use VI to view Code recently. It takes a lot of time for Bing. Remember this and save searching for it.

VI filename

Will open the file and stay in the Last edited location

 

Improve efficiency:

When you modify the code, you often remember the number of lines you want to modify and the features of the field. After all, the code is problematic or you have considered finding it. Therefore, locating the file opening location can greatly improve the efficiency.

Vi + N filename specifies the number of lines to jump to the Open File

Vi +/XX filename open the file and jump to the line containing content

 

2. Browsing

Next Previous Page

CTRL + F Ctrl + B 0 $ [[]

The most commonly used commands are the following. These commands have been used for the past few days. I tried to press ESC and then press and hold L...

You can directly enter numbers and then enter these commands. For example, you can switch back to line 200 at 200 K.

The next line, the last line, the last one, the last one, and the next word

J k h l e B

 

Use

Ctrl + g report current row and column information

Ngg or: n jump to the specified row n

Jump to the first line and you can directly use gg

H move to the top of the screen

M moves to the center of the screen

L move to the bottom of the screen

 

Edit 3

Editing, no nonsense, very fond of vi input, all the functions you Want to do are available

I insert at the cursor

Insert at the beginning of period I

Insert after a cursor

Insert at the end of A sentence

O Insert a new row

J. Merge the next row into the current row

Improve efficiency:

: Set ai to enable automatic alignment. It is better to write code ~

R replacement of characters at the specified position does not enter the insert mode. It is the perfect solution to replace a few letters. We strongly recommend that you use

R replacement Mode

S is inserted after the current character is deleted. It is also often used as a replacement of the character s + esc before entering the edit mode after the character needs to be replaced .. Until we find the strongly pushed r

Cc deletes and edits the entire row.

Add vim Configuration:

Create or edit the. vimrc file in the user directory

Add set autoindent

Set softtabstop = 4

Automatic Alignment and soft tab.

Delete

Delete the current character using x or dl

X or dh Delete the previous character

Dd deletes the current row

D] Delete to the end of the document

Copying and pasting is also a common task for programmers. Similar statements are used to copy and paste the three or four lines, and then use regular expressions to change the regular expression to the desired word.

Copy a word from yw

Yy copy a row

Nyy copy n rows

Copy yG to the end of the article

Copy y1G to the beginning of the article

"Xnyy copies n rows to the variable x (any letter). The output function can be copied to p, so that nothing else needs to be copied, and the output will be copied back :)

: You can use the command to view the information if reg copies a variable that you do not remember ~

P paste corresponds to the yy command

Copy selected multiple rows

V enters visual mode and moves the cursor to select the text. V is the unit of action.

Y Copy d Delete

 

: S/old/new/g easily replaces all old-new in a row. If only the first one in the row is replaced, removing the last/g is a common regular expression.

If you want to replace the number of rows in the specified range, simply add the preceding

: S/create/delete/g where. indicates the current row and # indicates the last row.

You can use

: % S/old/new/g

 

Search

One of the most common functions is to see the code before dozens of lines to modify, but when the number of lines is not estimated, you can directly look at the features and then find ~

/Xx

? Xx search for the previous xx

N Continue search

N reverse search

Undo

U cancels the last operation

Ctrl + R restore u

 

Iv. Functional commands

: W save

: Q exit

Saving and exiting a quick command can save the programmer a lot of time. After I input n + 1 wq sadly, I found that they are collectively called x

ZZ saved and exited and found a new one, which is better!

5. Tips

Historical name

: Ctrl + p. This is obviously a traditional usage.

: Ctrl + f Recent History commands, which are newly discovered and easy to use!

Place the output result of command to the current line

: R! Command can be used to insert some local information such as: r! Ifconfig eth0 grep "inet" puts the IP address information of the local machine directly in the vi document.

Display man content of words under the cursor

K

Display the hexadecimal value of Unicode characters under the cursor

G8

 

Bookmarks

When you need to mark the Code:

MX: X is any letter

Jump to bookmarks:

'X

Save and exit: ZZ is very convenient

Code Movement

: Set sw? View the number of code moves at a time

: Set sw = 4 set 4 bits (it is important to write code or 4 bits :)

: Le |: ce |: ri positioning left-right

Vi. Multi-document editing

Previously, I thought it was inconvenient to edit multiple vi Documents. Now I have some contact with MiniBufExplorer and found that it is not very comfortable. It is better to use ls.

: Ls displays all open documents

: Switch xn to the x document below

N ctrl + 6: switch to the nth buffer

Ctrl + 6 or: e # return to the previous editing File

  

Split screen

: New xxx

Ctrl + w s split-screen display of the current document content

Ctrl + w q close the split screen

Ctrl + w o only displays the current split screen content

Ctrl + w j k select up/down split screen

I personally think the most useful command is ctrl + w to quickly switch between the two screens on the split screen.

 

I haven't written the following ~ After reading this article, I think these are pretty good.

: N1, n2 co n3: copy the content from line n1 to line n2 to line n3.
: N1, n2 m n3: Move the content from line n1 to line n2 to line n3
: N1, N2 D: Delete content from line N1 to line N2

: N1, N2 W! Command: The content from line N1 to line N2 in the file is used as the command input and executed,
If N1, N2 is not specified, the entire file is used as the command input.

 

This article is very helpful:

Http://blog.csdn.net/wooin/article/details/1858917

 

Zero, Code Completion

Extremely powerful functions, in editing mode

CTRL + P or Ctrl + N: it is a good habit to complete the word writing code.

CTRL + x + L: Find the same row for completion similar to the copy Function

CTRL + x + F: it is very useful to complete the path. For example, remember/usr/lib/python2.6 when I need to add the system path to the tags ~

CTRL + x + D: You can use Ctrl + P to complete the macros.

  

I. Color

Python code has been written a lot, and it gets an idle style. What nice looks can you recommend?

Http://www.vim.org/scripts/download_script.php? Src_id = 1, 15771

 

2. Powerful tag ctags

0. It is best to allow the local version to Exceed 5.0. Otherwise, the unrecognized option '-- format = 2' type error will be displayed in the future.

Ctags: Official Website

1. pre-process the source code directory of the tag. For example, ctags-R *. py is used here.

2. Jump to definition: ctrl +] Jump Back: ctrl + t

3. Set multiple tags paths: Just jump across your project. What should I do if I want to see the system function? Use :! Man is fine, but what should I do if I want to see python library functions?

You can edit your own vimrc directly in vi: e $ MYVIMRC, but of course you don't need to input so much. After entering MY, you can use the tab to complete it,

Set tags =./tags,/usr/lib/python2.6/tags

4. Display All tags of a keyword:

: Ts keywords used when you want to quickly find the Function Definition

 

Iii. Common plug-ins

Plugin installation steps:

1. copy the file to the corresponding folder. You can select $ HOME/. vim $ HOME/vimfiles or $ VIM/vimfiles.

2. Go to the doc folder, open vi, and run helptags. Add the help document.

3. Configure the. vimrc file as needed and use let to set some environments.

 

Common commands:

Ctrl + w window switch

Ctrl + w + o only display the current form

 

Plug-in recommendation

1. You will know if taglist has been used!

: Http://www.vim.org/scripts/script.php? Script_id = 1, 273

Common configurations:

Only the current document list is displayed. Only the List window is closed. The list tree is displayed on the right.

Let Tlist_Show_One_File = 1
Let Tlist_Exit_OnlyWindow = 1
Let Tlist_Use_Right_Window = 1

Enter the command: Tl [tab] to complete

Common commands:

X maximized/restored Tlist window

-Or zc folding

+ Or zo

= Fold all

* Open all

2. Grep thinks this should be necessary.

Download: http://www.vim.org/scripts/script.php? Script_id = 1, 311

: Grep or bind directly to the shortcut key
Map <silent> <F7>: Grep <CR> Search all in the current directory.

  

Note that the special ing in the keyboard in putty will correspond the F1-F12 to different sending content, you can select the keyboard in Terminal

The function keys and keypad correspond to xterms to make it available after F5 :)

  

I also downloaded a fun little plug-in for matrix. vim.

Pydiction-1.2 Python code completion

Nerdtree is rarely used. You can browse the directory if necessary.

Omnicppcomplete-0.41 C-class code completion

Iv. Macro recording

Powerful text editors must support all functions

P [A-Z]: The next action recording is saved to the letter X.

Run a command and then run ESC and Q. In this way, the previous actions are saved.

N @ [A-Z]: calls a macro n times

For example, I often like to comment out the full text:

0. gg 1. QA 2. I 3. #4. ESC 5.j 6. Q 7. 100 @

Of course, you can also use the method of literature and art: % S/^ /#

V. Replacement

To replace a piece of text, but do not know the start and end lines, you can enter V to enter, visual mode, to include the selected text up or down, and then execute: will appear: '<''>' style. Then, input S/old/new/g to replace all the content in the selected text.

 

This is what we use for the time being. I feel that writing code is sufficient. Paste. vimrc and update it later.

Set autoindent
Set syntax = on
Set softtabstop = 4
Filetype plugin on
Colorscheme IDLE

Let g: pydiction_location = '/root/conf/vi/complete-dict'

Let Tlist_Show_One_File = 1
Let Tlist_Exit_OnlyWindow = 1
Let Tlist_Use_Right_Window = 1

Set tags =./tags,/usr/lib/python2.6/tags
Map <silent> <F7>: Grep <CR>
Imap <silent> <F7> <ESC>: Grep <CR>

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.