Rookie Vimer Growth record--chapter 2.3, insert mode

Source: Internet
Author: User

Most of the VIM commands are executed in non-insert mode, but some features are better implemented in insert mode.

If there is no requirement to enter new text that does not exist for the current file, it is recommended that the operation be done through other modes.

Objective

Mastering the syntax and concepts of common operations in Inser mode

Cursor movement

Move the cursor position, which is basically consistent with the other editors. There are several common ones, others are not listed.

Common syntax:

Operation Use
Ctrl+left Move one word backwards
Ctrl+right Move forward one word
Home Move to the beginning of the line
End Move to end of line
Ctrl+home Move to the first line of the file
Ctrl+end Move to the last line of the file
PageUp Up one screen
PageDown Down one screen

View more: H ins-special-special

Correcting errors

In the input, it is inevitable that you will lose the wrong. How to correct these errors more quickly?

Scenario One: Wrong typing at input    we can use BACKSPACE to delete the wrong text and then enter the correct content. If the error is near the end of the word, this is probably the quickest way to fix it. Scenario Two: Where the error occurs at the beginning of a word a    professional typist would suggest deleting the entire word before re-entering it again. If you can enter at a speed of more than 60 words per minute, it only takes 1 seconds to re-enter a word. Even if you can't beat it so fast, it's best to use it this way. I've always been wrong about certain words, but since I've adopted this advice, I've become more aware of the words that make me wrong, so I'm making a lot less mistakes.    Alternatively, you can switch to normal mode, then jump to the beginning of the word and correct the error, then press A to return to the location. But it may take more than 1 seconds to complete this set of actions, and it will not help you improve your blind playing skills. Although we can switch modes, that doesn't mean you have to switch.

So deleting the error and re-entering is the best method.

The following shortcut key actions are available when deleting:

Operation Use
Ctrl+h Delete the previous character (same as BACKSPACE)
Del Delete the last character. Rarely used
Ctrl+w Delete a previous word
Ctrl+u Delete to beginning of line

Precautions:

    • These deletions can be used in the same way as the shell and Cmd-line.
Insert existing text

If the text is not currently available, the keyboard entry is inserted into the current cursor. If it is currently existing text to, you can insert the current cursor in several ways.

These pathways are as follows:

On the downside

Copies the upper and lower characters of the cursor at position. Copies one character at a time for each operation.

  

Grammar:

Operation Use
Ctrl+e Copy the character of the next line cursor position to the current cursor
Ctrl+y Copy the character of the previous line cursor position to the current cursor

Last time

Copy the last entry inserted into insert mode.

Grammar:

Operation Use
CTRL + A Copy the last entry inserted into insert mode.
Ctrl+o Copy the last entry inserted into insert mode, and go back to normal mode

Register

Copy the contents of the register.

Syntax: ctrl-r {0-9a-z "%#*+:.-=}

Precautions:

    • Ways to view all registers: Reg
    • Using put {0-9a-z "%#*+:.-=} in Normal mode, you can implement the paste.

The type of register is introduced in this article by the way. Note: The name of the register below will be preceded by a "(double quotation mark). View more: H Registers

Nameless (unnamed) registers

"", cache the last action;

Digital (numbered) registers

"0 ~" 9, cache the most recent action content, copy and delete is different.

    • The 0 register caches the content that was last copied.
    • "1-" 9 Cache last 9 rows delete content
Inline Delete (small delete) register

"-, cache in-line delete content

Named (named) registers

"A ~" Z or "A-" 0Z, available when specified;

Defines the syntax for a named register: "{name}y{motion}" in normal mode. This input can pay attention to the lower right corner, there will be a corresponding input prompt.

Read-only (read-only) registers
Register Device what is represented
": Commands recently executed by Cmd-line mode
". Text inserted in insert mode last entry
"% Current file name
"# Last rotated file name.

Expressions (expression) register

"=, read-only, used to execute an expression command;

For example:

#假设我们刚输入完下列内容, we want to calculate the total price and then enter 6 chairs, each costing $, totals $
#只要输入 <C-r>=6*35<CR> to get results

Selecting and dragging (selection and drop) registers

"*," +, "~, Access GUI Select text, can be used to interact with external applications, using the prerequisite for the system Clipboard (clipboard) available;

Other commands are only available in Vim.

Black Hole Register

"_, do not cache the contents of the operation (clean delete);

This command works well when you delete text but do not want to overwrite content in the nameless register.

Mode register (last search pattern)

"/, caches the most recent search mode.

Auto Prompt

Grammar:

Command Complement Type
<C-n> Normal keywords
<C-x><C-n> Current buffer keyword
<C-x><C-i> Include file keywords
<C-x><C-]> Tag file keywords.?? This is temporarily put in the back, may open an article to explain.
<C-x><C-k> Dictionary Lookup
<C-x><C-l> Complete line Completion
<C-x><C-f> File name completion
<C-x><C-o> Universal (Omni) Full complement
<C-x><C-s> Spelling suggestions
<C-x><C-v> Vim command
<C-x><C-d> Complement macros.?? This has not been found to use the corresponding method

Regardless of which AutoComplete command is used, the pop-up menu appears.

Commands available for use with pop-up menus:

Key Operation function
<C-n> Use the next occurrence from the complement list (next match
<C-p> Use the previous match from the complement list (previous matches)
<Down> Select the next occurrence from the complement list
<Up> Select the previous match from the complement list
<C-y> Confirm that the currently selected match is used (yes)
<C-e> Restore the oldest input text (exit from auto-completion)
<C-h> (and <BS>) Remove a character from the current match
<C-l> Add a character from the current match
{char} Abort Auto-completion and insert character {char}

There are also some use techniques as follows

Use words in a dictionary for auto-completion

This is actually <C-X><C-K>

Sometimes, we might want to enter a word with auto-completion, but it doesn't appear in any open buffers, include files, or tag files. In this case, you can find them in the dictionary.

in order to activate this feature, we need to provide a suitable list of words for VIM. The simplest way is to activate the spell check function of VIM by running: Set spell.

If you do not want to activate the spell check feature, you can also specify one or more files with the word list (see: H ' Dictionary ') by using the ' Dictionary ' option.

  When you want to enter a long word or a word that is hard to spell, the dictionary auto-completion may be the most useful. Here 's an example.

  

Auto-Complete file name

This is actually <C-X><C-F>

Vim always maintains a current working directory, which is similar to the shell. At any given point in time, We can obtain this information through the: PWD command (print working directory), or by: the CD{path} command (change directory) to switch the working directory at any time. In addition, Vim's file name auto-completion can only be extended relative to the path of the working directory, rather than the path of the currently edited file, it is important to understand this point.

If the completion of the file is not the current working directory, we operate in two ways:

1, write the root directory of the path, and then continuously through <C-X><C-F> to select the complete file name. In fact, I like this way more.

2, first through: Cd{path} to switch directories, and then <C-X><C-F> complete, and then through: CD-cut back to the original directory.

Auto-complete based on context

This is actually <C-X><C-O>

  all in all, it will provide a list of complements that are tailored to the context in which the cursor is located.

  

In fact, this feature is implemented by a dedicated file type plug-in, so we must first load the following configuration lines:

Set Nocompatiblefiletype plugin on

The release version of Vim natively supports more than 10 languages, including HTML, CSS, JavaScript, PHP, and SQL. You can find the complete list by: H compl-omni-filetypes

Reduce the number of keystrokes

As long as there are no conflicts with other shortcuts, you can turn two operations into one.

The recommended settings are as follows:

  

Indent in

Grammar:

Operation Use
Ctrl+t Insert an indent
Ctrl+d Delete an indent
0 (number 0) +ctrl+d Delete all indents for the current line
^+ctrl+d Deletes all indents for the current line. And the above differences have not yet been tried out??

Abbreviation

Abbreviations can be used for insert and cmd-line modes. These commands are all about the same, just by prefixing the difference. A single character is a representation of I that is suitable for insert mode. If the representation of C is suitable for cmd-line mode. If not written, it means two can be used.

The following lists are only applicable to the list, the other people

where {LHS} represents an abbreviated string. {RHS} represents a real string, where the polygon supports map-<expr>,map-<buffer>

Operation Use
: AB {LHS} View a list of abbreviations. If you do not write is the list of all abbreviations, if there is a write to find a matching list
: AB {LHS} {RHS} Define an abbreviation
: una {LHS} Deletes an abbreviated list. Delete all lists if not written, or delete a matching list if one is written

Using an abbreviated example

#定义了一个: AB syso System.out.println (); #列举insert模式例子, cmd-linemode is the same. ${cursor} represents the abbreviation that the cursor position # can take effect.  "  syso{cursor}"     #注意, there is a blank text in front of SYSO # just keep clicking the non-key character (tab |  Space Key | Enter key | ESC key, etc.) #不能生效的缩写 "  sysob{cursor}" "testsyso{cursor}" 

Therefore, the abbreviation method is: the abbreviation must be a complete independent {RHS} input. Before {RHS} input, you need to have blank text in front of you. No additional key character input can be entered after {RHS} input.

There are others that you can look at: H abbreviations:h map-<expr>,:h map-<buffer>

Little Tricks

If the abbreviation is set by Cmd-line, the vim is removed after it is closed. In order to be able to use, can write a common abbreviation list file, and then put in the VIMRC file

#vimrc文件source $VIMRUNTIME/my/ab.vim

Insert Normal Mode

It allows us to execute a universal mode command. In this mode, we can execute a normal mode command, and then return to insert mode immediately after execution.

Grammar:

Ctrl+o

For example:

Scene: When the current line is exactly at the top or bottom of the window, sometimes I scroll the screen to see more context.
The ZZ command allows you to redraw the screen and display the current line in the middle of the window so that you can read the half-screen content above and below the current line. I often type <c-o>zz and trigger This command in insert-Normal mode. When this is done, it goes straight back to insert mode, so I can continue typing without interruption.

Rookie Vimer Growth record--chapter 2.3, insert mode

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.