当前位置:网站首页>Real time operation of vim editor

Real time operation of vim editor

2022-04-23 16:27:00 qjwthink

Catalog

Lesson one

1、 Move the cursor

2、VIM The entry and exit of

3、 Deletion of text editing

4、 Text editor insert

5、 Addition of text editing

6、 Edit the file

7、 Summary

The second is

1、 Delete class Command

 2、 More delete class commands

 3、 About orders and objects

4、 Use count to specify actions

5、 Use count to delete more

 6、 Operate the whole line

 7、 Undo class Command

 8、 Delete and undo summary

3、 ... and 、 Implantation 、 Displacement and change

1、 Put class Command

 2、 Replace class Command

3、 Change class Command

4、 Use c Change more

5、 Summary

Lesson four

1、 Location and file status

 2、 Search class commands

 3、 Finding matching brackets

 4、 Replace the command

 5、 Summary

The first five lectures

1、 stay VIM The method of executing external commands inside

 2、 More about saving files

 3、 An optional Save command

4、  Extract and merge files

5、 Summary

About 6

1、 Open class Command

2、 Additional class commands

3、 Another version of the permutation class Command

4、 Copy and paste text

5、 Set options for class commands

6、 The sixth part is a summary

Lecture 7

1、 Get help

​2、 Create startup script

3、 Complement function

4、 The seventh part is a summary


Lesson one

1、 Move the cursor

Skilled use and h、j、k、l key

  Tips : h The key of is on the left , Every time you press it, it moves left .
             l On the right , Every time you press it, it moves to the right .
             j The key looks like an arrow pointing down at the tip .

2、VIM The entry and exit of

1. Press <ESC> key ( This is to make sure you are in normal mode ).

 2. Then input " shift+ :"    next     :q! < enter >
      Exiting the editor in this way will discard the changes you have made since you entered the editor .

3.vimtutor < enter >, Can enter the vim practice

Tips : :q! < enter > Any changes you make will be discarded . After a few lectures you will learn how to save changes to a file .

3、 Deletion of text editing

In normal (Normal) In mode , Can be pressed x Key to delete the character where the cursor is .

 

4、 Text editor insert

In normal mode , Can be pressed i Key to insert text . Press esc Exit and return to normal mode

5、 Addition of text editing

1. Press A Key to add text .

2. After the text is added , Press <ESC> Key back to normal mode .

With the last section of i The keys are somewhat similar

But the difference is i What changes is the position of the cursor , and a Will move back one space

6、 Edit the file

  Use :wq To save the file and exit .

When we finish editing a document, we can press ESC Exit to normal mode , then shift+:, Last input :wq To save your edits and exit .

7、 Summary

1. You can use the arrow keys to move the cursor in the screen text , You can also use hjkl Alphabet Key .
         h ( Move left )       j ( The downside )       k ( The upside )     l ( Move right )

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

  3. To withdraw from Vim Editor , Please enter <ESC>   :q!   < enter > Discard all changes .
                                         Or input <ESC>   :wq   < enter > Save changes .

  4. Delete the character where the cursor is in normal mode , Please press : x

  5. To insert or add text , Please enter :

         i   Enter the text you want to insert   <ESC>             Inserts text in front of the cursor
         A   Enter the text you want to add   <ESC>             Add text after a line

hot tip : Press down <ESC> Key will take you back to normal mode or undo one that you don't want to type or partially complete
The order of .

The second is

1、 Delete class Command

Input dw Can be removed from the cursor to the end of a word .

 2、 More delete class commands

Input d$(d+shfit+4) Delete from the current cursor to the end of the line .

1. Please press <ESC> Key to make sure you are in normal mode .

2. Please move the cursor to the end of the line ( That is, at the first point ‘.’ Back ).

3. Then input d$ Delete from the cursor to the end of the current line .


 

 3、 About orders and objects

Many commands that change text are made up of an operator and an action .
  Use the delete operator d The format of the delete command is as follows :

        d   motion

  among :
    d      - Delete operator .
    motion - Operator's operands ( List below ).

  A short list of actions :
    w - From the current position of the cursor to the beginning of the next word , Not including its first character .
    e - From the current cursor position to the end of the word , Include the last character .
    $ - From the current cursor position to the end of the current line .

  So input de Will be removed from the current cursor position to the end of the word .

hot tip :
    For those who dare to explore , In normal mode, just press the key representing the corresponding action instead of using the operator , you
    You will see the cursor move as represented by the object list above .

4、 Use count to specify actions

Entering a number before the action will make it repeat that many times .

1. Input 2w Move the cursor forward two words .

2. Input 3e Move the cursor forward to the end of the third word .

3. Input 0 ( The number zero ) Move cursor to the beginning of line .

 

 

 

5、 Use count to delete more

Entering a number when using an operator can make it repeat that many times .

As mentioned above, the combination of delete operator and action , You can insert a number before the action in the combination to
Delete more :
         d   number( Numbers )   motion
1. Input d2w To delete two uppercase words .

 6、 Operate the whole line

  Input dd You can delete the entire current line .

 1. Please move the cursor to the second line of the short sentence paragraph below in this section .
  2. Input dd Delete the line .
  3. Then move to the fourth line .
  4. Then the input 2dd Delete two lines .

 

 

 7、 Undo class Command

Input small u To undo the last order , Input Big U To undo changes to the entire line .

Delete the contents of the document first

 

 8、 Delete and undo summary

1. To delete from the current cursor to the next word , Please enter :dw
  2. To delete from the current cursor to the end of the current line , Please enter :d$
  3. To delete the entire line , Please enter :dd

  4. To repeat an action , Please put a number before it :2w
  5. The format of the modify command in normal mode is :
               operator   [number]   motion
      among :
       operator - The operator , Represents what to do , such as d On behalf of the delete
       [number] - Can add numbers , Represents the number of repetitions
       motion   - action , Represents movement on the text being manipulated , for example w For the word (word),
                  $ Representative bank end and so on .

  6. To move the cursor to the beginning of the line , Please press the number 0 key :0

  7. To undo a previous operation , Please enter :u ( Lowercase u)
      To undo changes made in one line , Please enter :U ( uppercase U)
      To revoke a previous order to revoke , Restore previous operation results , Please enter :CTRL-R

3、 ... and 、 Implantation 、 Displacement and change

1、 Put class Command

Input p Place the last deleted content behind the cursor .

1、 Input dd Delete the line , This will save the line to Vim In a register of .

2. Then move the cursor to c) a line , It's the top of the place where you're going to put it . remember : It's the top .

3. Then in normal mode (<ESC> Key in ) Input p Paste the line into .

 2、 Replace class Command

Input r Replace the character where the cursor is with a character .

1、 Please move the cursor to the first wrong position .

2. Then the input r And the characters to replace with , This will replace the mistake .

 

3、 Change class Command

Change the text until the end of a word , Please enter ce

1. Put the cursor on the word lubw The letter of u Where is the location of .

2. Then input ce And the right words ( In this case, input ine ).

Tips : Please note that ce The command doesn't just delete a word , It also puts you in insert mode . 

 

4、 Use c Change more

The change class operator can be used in conjunction with the same action used in delete .

 1. Changing class operators works the same way as deleting classes . The operation format is :

         c    [number]   motion

  2. Action parameters (motion) It's the same , such as w For the word ,$ Representative bank end and so on .

  3. Please move the cursor to the lower part of this section marked with ---> The first line of .

  4. Then move the cursor to the first error .

  5. Then input c$ Make the rest of the line correct as in the second line . Finally according to the <ESC> key .

 

5、 Summary

1. To re insert deleted text content , Please press lowercase p key . This operation can delete
      After the cursor . If the last delete is an entire line , Then the line will be set
      Next line in the current cursor line .

2. To replace the character where the cursor is located , Please enter lower case r And a new word to replace the original character
      You can .

3. The change class command allows you to change the text from the current cursor position to the middle of the position indicated by the action .
      Such as input ce Can replace the current cursor to the end of the word ; Input c$ Can replace when
      The content from the front cursor to the end of the line .

4. The format of the change class command is :

         c   [number]   motion

Lesson four

1、 Location and file status

Input CTRL-G Display the line position of the current cursor in the current editing file and the file status information .
Type uppercase G Jump directly to a specific line in the file .

1. Press down CTRL Don't let go and press g key . We call this bond combination CTRL-G.
      You will see a status line at the bottom of the page , The content displayed is the file name currently edited
      And the cursor position in the file .

2. Type uppercase G Enables the current cursor to jump directly to the last line of the file .
      Input gg You can make the current cursor jump directly to the first line of the file .

3. Enter the line number you have stayed in , Then type uppercase G. This will return you to the first time you press
     CTRL-G It's time to go .

 

 2、 Search class commands

Input / Add a string to find the string in the current file .

1. Enter... In normal mode / character . You will notice that both the character and the cursor appear at the bottom of the screen
      Ministry , This one : The order is the same .

2. Then the input errroor < enter >. that errroor Is the string you are looking for .

3. To find the last string , Just press n key . To find the last word in the opposite direction
      Fu string , Please enter uppercase N that will do .

4. If you want to reverse find strings , Please use ? Instead of / Conduct .

5. To return to your previous position, press CTRL-O ( Hold down Ctrl Press the letters at the same time o). Press repeatedly to
      Step back more .CTRL-I Will jump to a new position .

 

 

 

 3、 Finding matching brackets

  Input % You can find the matching brackets )、]、}.

1. Place the cursor at the bottom of this section and mark --> Any one in that line (、[ or { It's about .

2. Press next % character .

3. At this time, the cursor position should be in the matching brackets .

4. Press again % You can jump back to the first bracket of the pair .

5. Move the cursor to another (、)、[、]、{ or } It's about , Press % Look at what it did .

 

 4、 Replace the command

Input :s/old/new/g Can replace old by new.

1. Please move the cursor to the lower part of this section marked with ---> That line .

  2. Input :s/thee/the < enter > . Note that this command only changes the first match of the line where the cursor is located
      strand .

  3. Input :s/thee/the/g Replace the matching string of the whole line , All of the "thee" Will be
      change .

  4. To replace every matching string that appears between two lines , please
      Input   :#,#s/old/new/g   among #,# Represents a number of lines in the replace operation
                              The line numbers of the first and last two lines .
      Input   :%s/old/new/g     Replace every matching string in the whole file .
      Input   :%s/old/new/gc     Will find every matching string in the entire file , And for each matching string
                              Prompt whether to replace .

 

 5、 Summary

 1. CTRL-G Used to display the current cursor position and file status information .
     G Used to jump the cursor to the last line of the file .
      Type in a line number and then type in uppercase G Move the cursor to the line represented by the line number .
     gg Used to jump the cursor to the first line of the file .

  2. Input / The next string is the forward lookup of the string in the currently edited document .
      Input ? The next string is the reverse lookup of the string in the currently edited document .
      Press... After a search n Key is to repeat the last command , You can check in the same direction
      Find the next matching string ; Or in capitals N Find the next matching string in the opposite direction .
     CTRL-O Take you back to the old position ,CTRL-I Take you to a new location .

  3. If the current position of the cursor is bracket (、)、[、]、{、}, Press % Will move the cursor over the matching brackets .

  4. Replace the first string in a line old For the new string new, Please enter  :s/old/new
      Replace all strings in one line old For the new string new, Please enter  :s/old/new/g
      Replace all strings in two lines old For the new string new, Please enter  :#,#s/old/new/g
      Replace all strings in the file old For the new string new, Please enter  :%s/old/new/g
      When performing full-text replacement, ask the user to confirm that each replacement needs to be added c sign        :%s/old/new/gc

The first five lectures

1、 stay VIM The method of executing external commands inside

Input :! Then you can enter an external command to execute the external command .

1. Press what we are familiar with : Command to move the cursor to the bottom of the screen . So you can type a line of commands .

  2. Then type in the exclamation point ! This character , This allows you to perform external shell The command .

  3. We use ls Command as an example . Input !ls < enter > . This command will list the
      Content , Just as you type... At the command line prompt ls The result of the order is the same . If !ls I didn't get up
      effect , You can try :!dir have a look .

Tips : All external commands can be executed in this way , Including those with command line arguments .

Tips : be-all : All orders must be given by knocking < enter > Key end . We won't always mention that from now on
      了 .

 2、 More about saving files

To save changes to a file , Please enter :w FILENAME .

1. Input :!dir perhaps :!ls Get the contents of the current catalog . You should have known that at the end of the day
     < enter > Well .

  2. Select an unused filename , such as TEST.

  3. Then the input :w TEST  ( here TEST Is the filename of your choice .)

  4. The order will be based on TEST Save the entire file for the filename (Vim course ). To test this ,
      Please enter again :!dir or :!ls View the contents of your catalog list .

Please note that : If you exit Vim Then by order vim TEST Start again Vim, So in this document
      Content should be exactly the same as the content of the file you saved .

  5. Now you can delete TEST The file . stay MS-DOS Next , Please enter :   :!del TEST
                                  stay Unix Next ,                                Please enter :    :!rm TEST

 

 

 3、 An optional Save command

To save part of the file , Please enter v motion :w FILENAME

1. Move the cursor to the line .

2. Press next v key , Move the cursor over the fifth entry below . You will notice that the text between is highlighted .

3. Then press : character . You will see... At the bottom of the screen :'<,'> .

4. Now please input w TEST, among TEST Is an unused filename . Make sure you see
     :'<,'>w TEST Then press < enter > key .

5. At this time Vim The selected line will be written to TEST Go to the named file . Use :!dir or :!ls
      Make sure the file is saved correctly . Don't delete it this time ! We'll use it in the next lecture .

Tips : Press v Keying Vim Enter visual mode to select . You can move the cursor around to make the selection larger or
      smaller . You can then use an operator to manipulate the selected text . for example , Press d Key will delete
      Selected text content .

 

4、  Extract and merge files

To insert the contents of another file into the current file , Please enter :r FILENAME

1. Please move the cursor to the line above the line .

hot tip : Execution steps 2 After that, you will see the text of the fifth lecture and the third section , Please move down at that time
          To see the content of this lecture again .

2. Then by order :r TEST Name the one you created earlier TEST The files of the .
      The file you extract will be placed from where the cursor is .

3. To confirm that the file has been extracted successfully , Move the cursor back to the original position to notice that there are two copies of the
      5. The third section , One is the original , The other is a copy from the document .

Tips : You can also read the output of external commands . for example , :r !ls Can read ls Output of command , and
      Place it under the cursor .

5、 Summary


  1. :!command Used to execute an external command command.

      Please look at some practical examples :
         (MS-DOS)         (Unix)
          :!dir            :!ls            -   Used to display the contents of the current directory .
          :!del FILENAME   :!rm FILENAME   -   Used to delete the name FILENAME The file of .

  2. :w FILENAME   The current VIM The file being edited in is saved to a file named FILENAME The article of
      In the piece .

  3. v motion :w FILENAME You can save the selected content in the visual mode of the current editing file to the file
     FILENAME in .

  4. :r FILENAME Can extract disk files FILENAME And insert it into the cursor position of the current file
      Back .

  5. :r !dir Can read dir The output of the command and places it behind the cursor position of the current file .

About 6

1、 Open class Command

Input o A new line will open below the cursor and enter insert mode .

 

  Big O Insert... Above

2、 Additional class commands

  Input a Will be able to insert text after the cursor .

1. Input e Until the cursor is at li At the end of .

2. Enter lowercase a You can insert text after the cursor .

  Tips :a、i and A Will take you into insert mode , The only difference is where the characters are inserted .

3、 Another version of the permutation class Command

  Type in uppercase R Can replace multiple characters in succession .

Type in uppercase R Start typing the remaining characters in the first line that are different from the second line one by one , You can replace all the original characters and make the first line exactly the same as the second line ..

4、 Copy and paste text

Using operators y Copy text , Use p Paste text

1. Use v Enter visual mode , Move the cursor to "first" In front of .

2. Now the input y To draw out ( Copy ) Highlighted text .

3. Then move the cursor to the end of the next line :j$

4. Then the input p To place ( Paste ) Copied text . Then input :a second <ESC>.

5. Use visual mode to select " item.", use y Copy , Reuse j$ Move the cursor to the end of the next line ,
      use p Paste the text there .

5、 Set options for class commands

Set the option to find or replace cases that can be ignored

 1. To find the word ignore You can enter... In normal mode /ignore < enter >.
      To find the word repeatedly , You can press... Repeatedly n key .

  2. Then set the ic Options (Ignore Case, Ignore case ), Please enter : :set ic

  3. Now you can type n Key to find the word again ignore. be aware Ignore and IGNORE Now?
      It's also found .

  4. Then set the hlsearch and incsearch These two options , Please enter : :set hls is

  5. Now you can type the search command again , See what effect it will have : /ignore < enter >

  6. To disable ignore case , Please enter : :set noic

Tips : To remove the highlight of a match , Please enter :  :nohlsearch
Tips : If you want to ignore the case of letters when searching only once , You can use \c:
      /ignore\c < enter >

6、 The sixth part is a summary

  1. Enter lowercase o You can open a new line under the cursor and enter insert mode .
      Type in uppercase O You can open a new line above the cursor .

  2. Enter lowercase a You can insert text after the cursor position .
      Type in uppercase A You can insert text after the end of the line where the cursor is .

  3. e Command to move the cursor to the end of a word .

  4. The operator y Copy text ,p Paste the previously copied text .

  5. Type in uppercase R Will enter replace mode , Until you press <ESC> Key back to normal mode .

  6. Input :set xxx You can set xxx Options . Some useful options are as follows :
        'ic' 'ignorecase'       Ignore letter case when searching
        'is' 'incsearch'         Show partial matches when looking for phrases
        'hls' 'hlsearch'         Highlight all matching phrases
      Option names can be in full version , You can also use an abbreviated version .

  7. Add... Before the options no You can turn off options :  :set noic

Lecture 7

1、 Get help

Use the online help system

Vim Have a detailed and comprehensive online help system . To start the help system , Please choose the following three ways
  One of the ways :
        - Press down <HELP> key ( If there is one on the keyboard )
        - Press down <F1> key ( If there is one on the keyboard )
        - Input  :help < enter >

  Read the text in the help window to see how help works .
  Input CTRL-W CTRL-W   Enables you to jump between windows .
  Input :q < enter > You can close the help window .


2、 Create startup script

Enable Vim Characteristics of

  Vim It's more functional than Vi A lot more , But most of them are not enabled by default . In order to use more
  characteristic , You have to create a vimrc file .

  1. Start editing vimrc file , The specific command depends on the operating system you are using :
        :edit ~/.vimrc           This is a Unix Commands used by the system
        :edit $VIM/_vimrc       This is a MS-Windows Commands used by the system

  2. Then read vimrc The contents of the sample file :
        :r $VIMRUNTIME/vimrc_example.vim

  3. Save the file , The order is :
        :write

  Next time you start Vim when , The editor will have the function of syntax highlighting .
  You can add your favorite settings to this vimrc In file .
  To learn more, type :help vimrc-intro

3、 Complement function

  Use CTRL-D and <TAB> You can complete the command line

 

4、 The seventh part is a summary


  1. Input :help Or press <F1> Key or <Help> Key to open the help window .

  2. Input :help cmd You can find out about cmd Aid of command .

  3. Input CTRL-W CTRL-W   Enables you to jump between windows .

  4. Input :q To close the help window

  5. You can create a vimrc The startup script file is used to save your preferences .

  6. When the input : On command , Press CTRL-D You can view the possible completion results .
      Press <TAB> You can use a complement .

版权声明
本文为[qjwthink]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231624474015.html