Vim learning step by step

Source: Internet
Author: User
Tags manual writing

# Step 1

Summary of v I m tutorial (version 1.5)

(Note: This article is only a personal study summary. We recommend that you start this tutorial. You only need to enter the command $ vimtutor in VI)

Vim is a powerful editor with many commands. Limited space, in this tutorial
I will not go into details. The purpose of this tutorial is to describe some necessary basic commands.
Some commands, you can easily use Vim as a universal editor.

It takes about 25-30 minutes to complete this tutorial, depending on your training time.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Summary

1. move the cursor in the screen text. You can use either the arrow keys or the hjkl keyboard key.
H (left shift) J (downstream) K (upstream) L (right shift)

2. To enter the vim Editor (from the command line prompt), enter the: Vim file name <press enter>

3. to exit the vim Editor, enter the following command to discard all modifications:

<ESC>: Q! <Press enter>

Alternatively, run the following command to save all the changes:

<ESC>: WQ <press enter>

4. Delete the character at the cursor position in normal mode. Press: X.

5. In normal mode, to insert text at the cursor position, Press:

I. Enter necessary text <ESC>

Note: pressing the <ESC> button will bring you back to normal mode or cancel an unexpected or partially completed task.
.

Okay. The first step is to end. Next we will continue with the second lecture.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Summary

1. to delete from the current cursor to the end of a word/word, enter: DW

2. to delete the cursor from the current row to the end of the current row, enter: d $

3. to delete the entire row, enter: dd

4. The format of the next command in normal mode is:

[Number] command object or command [number] Object
It means:
Number-indicates the number of command executions
Command-indicates what to do. For example, d Indicates deletion.
Object-indicates the object to be operated. For example, W represents a single word/Word, and $ represents the end of a row.
$ (To the end of line), etc.

5. to cancel the previous operation, enter U (lower case U)
To cancel the changes made in one row, enter U (uppercase U)
To undo the previous undo command, restore the results of the previous operation, enter: CTRL-R
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Summary

1. to re-insert the deleted text content, enter the lower-case letter P. This operation can delete
After the cursor. If the last row is deleted
In the row where the current cursor is located.

2. To replace the character at the position of the cursor, enter the lower-case character R and the new character to replace the original position.
.

3. The change class command allows you to change the specified object from the current cursor position to the end of the object.
For example, input CW can replace the content from the current cursor to the end of the word; input C $ can replace
Front cursor to the end of the line.

4. Change the class command format:

[Number] C object or C [number] Object

Next, let's continue with our next lecture.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Conclusion 4

1. CTRL-G is used to display the current cursor position and file status information. Shift-G is used to jump the cursor
Go to the last line of the file. First, press shift-g to move the cursor to the row.
Number indicates the row.

2. Input/followed by a string, which is to be searched backward in the document currently edited.
Enter question mark? Followed by a string, the word is searched forward in the document being edited.
String. After a search is completed, press the n key to repeat the previous command.
Locate the Next string, or find the string in the opposite direction by shift-n.

3. If the current position of the cursor is parentheses (,), [,], {,}, you can press % to move the cursor to the paired
Brackets.

4. Replace the header string old with the new string new in a row. Enter "s/old/new ".
Replace all the strings old with the new string new in one line. Enter: S/old/new/g.
Replace all the strings old with the new string new in the two rows. Enter: #, # S/old/new/g.
Replace all the strings old with the new string new in the file. Enter % S/old/new/g.
During full-text replacement, ask the user to confirm that C option is required for each replacement. Enter % S/old/new/GC.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Summary

1 .:! Command is used to execute an external command.

See some examples:
:! Dir-displays the content of the current directory.
:! Rm filename-used to delete a file named filename.

2.: W filename can save the file being edited in VIM to the file named filename.
.

3.: #, # W filename can save the content of row # To row # Of the current edited file to the file
In filename.

4.: R filename can extract the disk file filename and insert it to the cursor position of the current file.
.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Summary

1. Input lowercase o to open a new line under the cursor and place the cursor at the beginning of the new line to enter
Insert mode.
Enter an uppercase o to open a new line above the cursor and place the cursor at the beginning of the new line to enter
Insert mode.

2. Input lowercase A to insert text after the cursor position.
Input uppercase A can insert text after the end of the row where the cursor is located.

3. If you enter an uppercase value, r enters the replacement mode until you press <ESC> to exit the replacement mode.
Mode.

4. Input: Set XXX to set the xxx option.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lecture 7: online help commands

** Use the online help system **

Vim has a comprehensive online help system. To start the help system, select the following three
Method:
-Press the -Press the <F1> key (if any on the keyboard)
-Input: Help <press enter>

Enter q <press enter> to close the Help window.

Provide a correct parameter to the ": Help" command. You can find help on this topic. Please test
Parameters (do not forget to press Enter. :):

: Help W <press enter>
: Help C _ <t <press enter>
: Help insert-index <press enter>
: Help user-manual <press enter>

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lecture 8: Create a STARTUP script

** Enable Vim **

Vim has many more features than vi, but most features are not activated by default. To start more
Function. You must create a vimrc file.

1. Start editing the vimrc file, depending on the operating system you are using:

: Edit ~ /. Vimrc this is the command used by the UNIX System
: Edit $ Vim/_ vimrc: The Command Used in windows.

2. Import the vimrc sample file:

: Read $ vimruntime/vimrc_example.vim

3. Save the file. The command is:

: Write

When you start Vim next time, the editor will have the syntax highlighting function. You can continue
Other feature settings of Huan are added to the vimrc file.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The Vim tutorial ends now. This tutorial is only intended to briefly introduce the vim editor, but it is sufficient for you
This editor is easy to use. There are many other commands in vim.
Shao is still far away. So if you want to be proficient, we hope you can continue to work hard. For more information, see
Vim manual, the command used is:
: Help user-Manual

# Step 2

(Note: This article is only a personal learning abstract. We recommend you download this article online)

Introduction to VI improved

Edyfox@smth.org (dianhu)

Http://edyfox.codecarver.org

School of software, Tsinghua University
Peking University Linux Club

 
Full-screen visual editor in UNIX

Because its source code is not available, many clone versions are derived.

Nvi, Elvis, vile, Vim...

Vim is one of the clone versions of VI improved and VI.

Vim Introduction

The most popular clone VI version
Supports most platforms currently
Windows, UNIX, Linux, MacOS, dos...
Powerful functions and high scalability
Bram moolenaar Compilation
Complete the first version in November 1991
The latest stable version is 6.3.
Charity Software
Not forced registration
All Vim functions can be used even if you do not pass the registration.

Registered users can vote for desired features
Individual Household Use Registration Fee: 10 euro
For professional field editing, the registration fee is 30 Euro
The registration fee will be used to help poor children in Uganda

It is mainly used to help orphans who lose their parents in areas where AIDS is raging.

Who should use Vim?

Programmers pursuing Editing efficiency
The author of VIM is a programmer.
He has developed many useful functions for programmers.
Others who often process plain text
Web developers for Small and Medium Enterprises
Researchers who write latex documents
Unix/Linux System Administrator

 
Who is not suitable for Vim?

People who live, work, and study without dealing with plain text
Dedicated tools are available for processing other types of files.
Persons whose typing speed is slower than smart sensing speed
Currently, VIM does not support smart sensing.
People who are spoiled by powerful ides are more important than convenient and quick editors.

 

Main Content

Vim Introduction

Vim getting started

Vim basic operations

Vim quick edit example

Compile your own. vimrc

 

Vim advanced

Shielding vimrc

Linux Users

Create ~ /. Vimrc File

Windows users

Create an empty text file _ vimrc in the Home Directory

Note the display Extension

 

Chinese processing in Linux

You cannot enter Chinese Characters During editing.

: Set encoding = cp936

 

The menu is garbled

: So $ vimruntime/delmenu. Vim

 

: So $ vimruntime/menu. Vim

 

 

Select the font you like

Select font in the menu and dialog box

Edit --> select font

Only the same width font can be selected

Font principles suitable for programmers

Bitstream Vera sans mono

 

0oo 1il

 

 

: Set guifont?

 

Remember the selected font name

Copy the displayed result to the backup
Write. vimrc

Vim cannot automatically remember the configuration changes you have made

Manual writing is required. vimrc

Lines starting with double quotation marks indicate comments

Your current. vimrc may look like this:

"Set encoding = cp936 is also recommended in windows.
"Only in Linux, so $ vimruntime/delmenu. Vim so $ vimruntime/menu. Vim is required.
"Set the font. "The font name can be obtained through the statement described in the previous section." If the font name contains spaces, add a backslash before the space, as shown in the following code: Set guifont = courier/9.
Vim basic operations

Vim is a pattern editor.

Commands for key sequence in Normal Mode

Press I to enter insert mode

Press: Enter command mode

 

You can enter text in insert mode.

Press ESC to return to normal mode

Enter commands in command mode

 

Mode causes short Vim shortcut keys

Use hjkl

Vim supports moving the cursor with the arrow key

It is easier to move the cursor in the Insert state.

Hjkl makes it more efficient to move the cursor and edit it.

 

Close to, convenient button, eyes do not need to leave the screen
Tetris

Http://vim.sf.net/scripts/script.php? Script_id = 1, 172

Vimtutor

Vimtutor is a good learning material for VIM beginners.

 

Linux Users

Enter vimtutor in the terminal

Vimtutor on the startup character Interface

 

Windows users

Find the vimtutor shortcut in the Start Menu

Garbled characters appear after startup. Select a Chinese font again.

 

Quick edit example

No more detailed Vim basic operations

Time Limit: it is impossible to introduce Vim in all aspects.

The level is limited, and the content cannot be stronger than vimtutor

 

Several Vim quick edit examples are introduced.

Further Enhancing memory for old users

Strong determination to learn Vim for new users

 

Search and replace

Preparations

Open vim, press I, and enter:

This is a test

 

Search and replace

 

Press ESC to return to normal. Enter:

: % S // ^ M/G

Where ^ m is input using Ctrl-v.Ctrl-m

Replace all spaces with carriage return and four lines of text

Splicing of rows

You can concatenate search/n with spaces.

Use the J command to concatenate rows.

Press ggvg to select all

Press:. The command line is displayed:

: '<,'>

 

Enter J and press Enter.

Splicing completed

 

Copy, paste, and repeat actions

In the normal state, press YY to copy the current row.

Press 12 p to display 13 rows of the above words on the screen

 

12 indicates executing the subsequent command 12 times.

P indicates to paste it to the current row

In vim, a number can be added to most commands to indicate the number of executions.

Column Operations

Select the first column of the full text

Press Gg to start

Press ctrl-V to enter the column selection status

Jump to the end by G

 

Converts the first column of each row to uppercase.

Change the selected content to uppercase according to u

Press u to reduce the selected content and write it

By ~ Indicates to flip the original case

 

Column Operations

Add an asterisk and a space before each line.

 

Select the first column

Press I to enter the insert status

Enter * and Press ESC

 

Select the first two columns and Press X to delete the columns.

 

It can be used for batch comments and batch comments during programming.
Macro recording

Change a of all even rows to another.

Recording macro

Press Gg to enter the first line

Press QM to enter macro recording status, recording to register m

Press J to enter the second row, and press $ to jump to the end of the row.

Press 2B and move the cursor over letter.

Press caw, input another, Press ESC, and press J to enter the next line

End macro recording by Q

 

Macro playback

Single playback

Press @ M to execute the macro in the M register.

We can see that row A of Row 3 also becomes another.

 

 

Multiple playback

Enter 1000 @ M

It can be found that a of all even rows has become another

An error occurs when the macro execution reaches the bottom of the file and the macro will stop automatically.

It was not actually executed 1000 times.

 

Point command

Add an exclamation point at the end of each line

You do not need to use macros for simple operations with few executions.

 

Press Gg to enter the first line, press a to enter the end of the line to add the status

Enter! , Press ESC, and press J to enter the second line

Repeat the previous operation by., that is, adding at the end of the row!

Repeatedly press J.

We recommend that you use the left-hand mouse.

 

: % S/$ /! /G

 

Vim getting started

21-day learning plan

Read more documents and avoid detours

WEEK 1: vimtutor once a day

Be familiar with basic operations and do what you want

Week 2 and week 3: Read User Manual

Revise your own. vimrc when reading the user manual

The Chinese version of the manual is available for download.

 

 

. Vimrc for beginners
Basic settings

Set nocp-set incompatible Mode

Set Ru-open the status bar ruler

Set HLS-highlight the found text during search

Set is-progressive search

Syntax on-enable keyword coloring

Set backspace = indent, EOL, start

 

Set whichwrap = B, S, <,>, [,]

 

H, L ,~

Encoding settings
A script that can automatically guess the encoding. It is very strong.

"Encoding settings

If has ("multi_byte ")
"Set fileencoding priority
If getfsize (expand ("%")> 0

Set fileencodings = ucs-bom, UTF-8, cp936, big5, EUC-JP, EUC-KR, Latin1
Else
Set fileencodings = cp936, big5, EUC-JP, EUC-KR, Latin1
Endif

"CJK environment detection and corresponding setting

If V: lang = ~ "^ Zh_cn"
"Use cp936 to support GBK, EUC-Cn = gb2312
Set encoding = cp936
Set termencoding = cp936
Set fileencoding = cp936

Elseif V: lang = ~ "^ Zh_tw"
"Cp950, big5 or EUC-TW
"Are they equal to each other?
Set encoding = big5
Set termencoding = big5
Set fileencoding = big5

Encoding settings
Previous Page
Elseif V: lang = ~ "^ Ko"
"Copied from someone's dotfile, untested
Set encoding = EUC-KR
Set termencoding = EUC-KR
Set fileencoding = EUC-KR

Elseif V: lang = ~ "^ Ja_jp"
"Copied from someone's dotfile, unteste
Set encoding = EUC-JP
Set termencoding = EUC-JP
Set fileencoding = EUC-JP

Endif
& Quot; detect UTF-8 locale, and replace CJK setting if needed
If V: lang = ~ "Utf8 $" | V: lang = ~ UTF-8 $"

Set encoding = UTF-8
Set termencoding = UTF-8
Set fileencoding = UTF-8

Endif
Else
Echoerr "sorry, this version of (g) Vim was not compiled with multi_byte"
Endif

. Vimrc for beginners
Text editing settings

Set Sw = 4-indent size 4 spaces

Set Ts = 4-the tab width is 4 characters

 

Set et-replace all tabs with spaces

. Vimrc for beginners

C/C ++ encoding settings

Set Cin-auto indent

Set Ai-or automatic indent

Set cino =: 0g0t0 (Sus

 

Set Sm-matching of display parentheses

 

Layout problems of pasting on the console

": Set paste" and "Set nopaste"

"=" Command Format re-adjusted

 

. Vimrc for beginners

Disconnection settings

Set LBR-do not break a line in a word

Set fo + = Mb-enable the disconnected line module for Asian languages

 

Other settings

Set selectmode =

 

Set mousemodel = popup

 

Set keymodel =

 

Set selection = random sive

 

 

. Vimrc for beginners

Gui and character interface settings

If (has ("gui_running")-set nowrap on the GUI-line set guioptions + = B-horizontal scroll bar Colo torte-Color Scheme

 

Set the set wrap-line Colo ron-color scheme on the else-character Interface

Endif

 

 

Main Content

Vim Introduction

Vim getting started

Vim advanced

Introduction to common Vim plug-ins

Write programs in VIM

Write latex documents in VIM

 

Plugin installation path

$ Home/. vim or % home %/vimfiles

$ Vim/vimfiles

$ Vimruntime

$ Home/. Vim/after or % home %/vimfiles/after

$ Vim/vimfiles/after

Plug-in directory structure

Colors

Ftplugin

Compiler

Indent

Doc

Keymap

Plugin

 

Etc

Ftdetect

Syntax

Recommendation of common plug-ins
Calendar tool

 

Recommendation of common plug-ins
Graffiti plug-in sketch

 

Recommendation of common plug-ins

Vim. Ide implemented by a series of plug-ins

Window Manager + file browser (Window Manager plug-in)

Tlist + ctags

VIM + ctags + cs.pdf

 

Ctags and csflood

Recommendation of common plug-ins

Viki + deplate

Wiki-like syntax

Used to create a simple personal homepage based on content

The personal homepage of Dian Hu is made using Viki.

 

Advantages

Easy to use and powerful functions

Disadvantages

 

Complicated configuration, too many Dependencies
Write programs in VIM

Write makefile correctly

Set the appropriate makeprg

For example, in some systems, you may want to use gmake

It is best to install tee in windows.

See the compilation process

: Set shellpipe = 2> & 1/|/Tee

 

 

Correctly set errorformat Based on the compiler output

Write programs in VIM

Common compilers can use Vim scripts to set parameters.

: Compiler xxx

Menu item: tool --> set Compiler

Use: Make to compile the program

Use: Copen to view the Error List

 

: Make
: Make clean

Copen tips

Search for a specified string in multiple files

List search results in a buffer

You can jump entries to the corresponding file location.

Copen has this capability

 

Requirement

A tool used to search for a specified string in a file

 

Provide the file name and row number information in the search result.

Proper errorformat settings

 

Copen tips

Set grep Parameters

: Set grepprg = grep/-NH/$ *

It is recommended to write to. vimrc.

Use the grep command to search for files

: Grep "test string 2 "*

 

: Grep-R "test string 2"

 

: Grep "function" *. cpp

 

 

Write latex documents in VIM

Install latex suite

Configure forward and reverse search

Forward search

Find the elements corresponding to the source code in the generated DVI File

 

Reverse search

 

Find the source code location of the element in the generated DVI file.

<++> Puzzles for beginners

 

Is a very useful function of latex suite.
Main Content

Vim Introduction

Vim getting started

Vim advanced

Vim usage Summary

Vim is a powerful and convenient text editor.

Learning is required to make it good enough.

The learning effort is worthwhile.

Don't complain that Vim is not powerful enough as IDE

First, think about how much money you have paid for the so-called "powerful" Ide.

Open-source community projects require everyone to work.

 

Thank you!

Thank you for your support!

Q &
Happy vimming ~~

# Step 3...

Http://blog.csdn.net/iiprogram/archive/2006/03/14/624403.aspx

Learning Resources

Vim website

Http://www.vim.org

Http://vim.sourceforge.org

Chinese site

 

The Vim version of shuimu community and the page attached FTP

Learning Resources
Vim email list

Vim-announce@vim.org

Vim@vim.org

Vim-dev@vim.org

Vim-mac@vim.org

Vim-multibyte@vim.org

 

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.