【Linux】-- Ubuntu vimtutor official tutorial (Chinese translation version)

        After entering the Ubuntu system, first open the terminal (ctrl + alt + t), and enter sudo apt-get install vim-gtk in the terminal command line. After the installation is successful, enter: vimtutor to open the VIM tutorial.

The following is the Chinese version of the official VIM tutorial, just follow along!


==================================================== ========================
                       = Welcome to "VIM Tutorial" - Version 1.7 =
================= ==================================================== ========

     Vim is a very powerful editor with many commands.
     Due to space limitations, it will not be introduced in detail in this tutorial . The design goal of this tutorial is to describe some necessary basic commands, and mastering
     these commands, you can easily use Vim as a general-purpose editor.

     Completing the content of this tutorial will take approximately 25-30 minutes, depending on how long you train.

     NOTE:
     Command actions for each section will change this article. It is recommended that you make a copy of this article and train on the copy
     (if you started the tutorial through "vimtutor", then this article is already a copy).

     Remember one thing: the design idea of ​​this tutorial is to learn in use. That is, you need to
     learn the proper usage of the commands themselves by executing them. If you just read and don't do it, you might
     quickly forget these commands!

     Ok, now make sure your Shift-Lock (Caps Lock) key is not pressed, then press the
     letter j on your keyboard enough times to move the cursor until the content of the first section fills the screen completely.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Lecture 1 Section 1: Moving the Cursor


         ** To move the cursor, press the h, j, k, l keys as instructed. **

         ^
         k Hint: The h key is on the left and moves left each time it is pressed.
       < h l > The key for l is on the right and moves right each time it is pressed.
         j The j key looks like an arrow pointing down.
         v

  1. Feel free to move the cursor around the screen until you feel comfortable.

  2. Press the down key (j) until the cursor appears to repeat down.

---> Now you should have learned how to move to the next lecture.

  3. Now use the down key to move the cursor to the second section of the first lecture.

Tip: If you are not sure which letter you pressed, please press <ESC> key to return to normal (Normal) mode.
      Then enter the command you want from the keyboard again.

Tip: The cursor keys should work as well.
      But with the hjkl keys, you'll be able to move the cursor around the screen much faster once you get used to it . It really is!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Lecture 1 Section 2: VIM entry and exit


  !! Special Note: Please read the entire content of this section before executing the commands explained below.

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

  2. Then enter: :q! <Enter>
     Exiting the editor in this way will discard the changes you have made since entering the editor.

  3. If you see a command line prompt, enter the command that will take you back to this tutorial, which is:
     vimtutor <enter>

  4. If you are confident that you have memorized these steps firmly, please execute from step 1 to step 3 to exit,
     and then enter the editor again.

Tip: :q! <ENTER> discards any changes you have made. After a few lectures you'll learn how to save changes to a file.

  5. Move the cursor down to the third section of the first lecture.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Lecture 1 Section 3: Deletion in Text Editing


   ** In Normal mode, you can press the x key to delete the character at the cursor position. **

  1. Please move the cursor to the line marked with ---> below in this section.

  2. To correct an input error, move the cursor to the character to be deleted.

  3. Then press the x key to delete the wrong character.

  4. Repeat steps 2 to 4 until the sentence is corrected.

---> The ccow jumpedd ovverr thhe mooon.

  5. Well, the line has been corrected, the following is the fourth section of the first lecture.

Special tip: When going through this tutorial, don't force yourself to memorize it. Remember one thing: learn by using.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             Lecture 1 Section 4: Insertion in Text Editing


     ** In normal mode, you can press the i key to insert text. **

  1. Please move the cursor to the first line marked with ---> below in this section.

  2. In order to make the content of the first line the same as the second line, please move the cursor to the first
     position of the character to be inserted in the text.

  3. Then press the i key and enter the necessary text characters.

  4. After each error correction, press the <ESC> key to return to normal mode.
     Repeat steps 2 to 4 to correct the sentence.

---> There is text misng this .
---> There is some text missing from this line.

  5. If you are satisfied with the text insertion operation, please continue to read the fifth section of the first lecture below.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             Lecture 1 Section 5: Addition of Text Editing


            ** Press the A key to add text. **

  1. Move the cursor to the first line marked with ---> below.
     It doesn't matter which character on that line the cursor is on.

  2. Press the A key to enter the necessary additions.

  3. After adding the text, press the <ESC> key to return to the normal mode.

  4. Move the cursor to the second line marked with ---> below. Repeat steps 2 and 3 to correct the sentence.

---> There is some text missing from th
     There is some text missing from this line.
---> There is also some text miss
     There is also some text missing here.

  5. When you are comfortable with adding text, proceed to Lecture 1, Section 6.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             Lecture 1 Section 6: Editing files

            ** Use :wq to save the file and exit. **

  Special Note: Please read the entire section before performing the following steps!

  1. Exit the tutorial as you did in the second part of the first lecture: :q!
     Or, if you have access to another terminal, do the following there.

  2. Enter the command at the prompt of the shell: vim tutor <Enter>
     'vim' is the command to start the Vim editor, 'tutor' is the name of the file you want to edit.
     Please use a modifiable file.

  3. Use the commands you learned in the previous tutorials to insert and delete text.

  4. To save the changed file and exit Vim, press these keys: :wq <Enter>

  5. If you have exited vimtutor in step 1, please restart vimtutor. Move to the summary section below.

  6. After reading the above steps, understand their meaning, and then practice in practice.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   The first lecture summary


  1. The cursor can be moved in the screen text either by arrow keys or hjkl letter keys.
     h (move left) j (move down) k (move up) l (move right)

  2. To enter the Vim editor (from a command line prompt), type: vim filename <Enter>

  3. To exit the Vim editor, please enter <ESC> :q! <Enter> to discard all changes.
                      Or type <ESC> :wq <Enter> to save the changes.

  4. To delete the character at the cursor position in normal mode, press: x

  5. To insert or add text, enter:

     i Input text to be inserted <ESC> Insert text before the cursor
     A Input text to add <ESC> Add text after a line

Special Note: Pressing the <ESC> key will take you back to normal mode or undo an unwanted or partially completed
command.

Well, that's the end of the first lecture. Next, continue with the content of the second lecture.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Lecture 2 Section 1: Delete Command


        ** Enter dw to delete from the cursor to the end of a word. **

  1. Press the <ESC> key to make sure you are in normal mode.

  2. Please move the cursor to the line marked with ---> below in this section.

  3. Please move the cursor to the beginning of the word to be deleted.

  4. Then type dw to delete the word.

  Special reminder: When you type, the letter d will appear on the last line of the screen at the same time. Vim is waiting for you to type
  the letter w. If you see anything other than d, you made a mistake; press <ESC> and
  try again.

---> There are a some words fun that don't belong paper in this sentence.

  5. Repeat steps 3 and 4 until the sentence is corrected. Continue to the second part of the second lecture.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              Lecture 2 Section 2: More delete commands


           ** Enter d$ to delete from the current cursor to the end of the line. **

  1. Press the <ESC> key to make sure you are in normal mode.

  2. Please move the cursor to the line marked with ---> below in this section.

  3. Please move the cursor to the end of the line (that is, after the first dot '.').

  4. Then enter d$ to delete from the cursor to the end of the current line.

---> Somebody typed the end of this line twice. end of this line twice.


  5. Please continue to study the third section of the second lecture to know what is going on.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             Lecture 2 Section 3: About commands and objects


  Many commands that change text consist of an operator and an action.
  The format of the delete command using the delete operator d is as follows:

    d   motion

  where:
    d - the delete operator.
    motion - The operator to operate on (listed below).

  A short list of actions:
    w - from the current cursor position until the start of the next word, not including its first character.
    e - From the current cursor position until the end of the word, including the last character.
    $ - From the current cursor position until the end of the current line.

  So typing de will delete from the current cursor position to the end of the word.

Special note:
    For the adventurous explorers, please just press the key representing the corresponding action without using the operator in normal mode, and you
    will see the cursor move as represented by the object list above.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
             Section 4: Use a counting specified action


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

  1. Move the cursor to the beginning of the line marked with ---> below.

  2. Type 2w to move the cursor forward two words.

  3. Enter 3e to move the cursor forward to the end of the third word.

  4. Enter 0 (the number zero) to move the cursor to the beginning of the line.

  5. Repeat steps 2 and 3 to try different numbers.

---> This is just a line with words you can move around in.

  6. Please continue to study the fifth section of the second lecture.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
               @


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

  The combination of delete operator and motion has been mentioned above, you can insert a number before the action in the combination to
  delete more:
     d number(number) motion

  1. Move the cursor over the first capitalized word in the line marked with ---> below.

  2. Type d2w to delete two uppercase words.

  3. Repeat steps 1 and 2, using different numbers so that all adjacent uppercase
     words can be deleted with one command

--->  this ABC DE line FGHI JK LMN OP of words is Q RS TUV cleaned up.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                @


             ** Enter dd to delete the entire current line. **

  In view of the high frequency of deleting entire lines, the designers of Vi decided to simplify the operation of deleting entire lines. You only need to hit d twice on the same line to
  delete the entire line where the cursor is located.

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

--->  1)  Roses are red,
--->  2)  Mud is fun,
--->  3)  Violets are blue,
--->  4)  I have a car,
--->  5)  Clocks tell time,
--->  6)  Sugar is sweet
--->  7)  And so are you.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
               Lecture 2 Section 7: Undo commands


    ** Type u to undo the last executed command, and type U to undo changes to the entire line. **

  1. Please move the cursor to the line marked with ---> below in this section and place it at the first error
     .
  2. Enter x to delete the first letter you don't want to keep.
  3. Then type u to undo the last (one) command executed.
  4. This time use x to fix any errors in this line.
  5. Now enter an uppercase U to revert to the line's original state.
  6. Then type u several times to undo U and previous commands.
  7. Then enter CTRL-R multiple times (first press the CTRL key and hold it, then press the R key), so that you
     can redo the undone command, that is, undo the undo command.

---> Fiix the errors oon thhis line and reeplace them witth undo.

  8. These are very useful commands. The following is a summary of the second lecture.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   Second Lecture 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 add a number in front of it: 2w
  5. The format of the modification command in normal mode is:
               operator [number] motion
     Among them:
       operator - operator, representing what to do, such as d for Delete
       [number] - a number that can be appended, representing the number of times the action is repeated
       motion - a motion, representing movement on the text being manipulated, such as w for word,
          $ for end of line, etc.

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

  7. To undo the previous operation, please enter: u (lowercase u)
     To undo the changes made in a line, please enter: U (uppercase U)
     To undo the previous undo command and restore the previous operation results, please Type: CTRL-R

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
               Lecture 1: Putting into the class command


        ** Enter p to place the last deleted content after the cursor. **

  1. Please move the cursor to the first line marked with ---> in this section.

  2. Type dd to delete the line, which saves the line in a register in Vim.

  3. Then move the cursor to line c) above the position to be placed. Remember: it is above.

  4. Then enter p in normal mode (<ESC> key to enter) and paste this line into it.

  5. Repeat steps 2 to 4 to place all the rows in the correct position in sequence.

---> d) Can you learn too?
---> b) Violets are blue,
---> c) Intelligence is learned,
---> a) Roses are red,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
               Lecture 3 Section 2: Replacement commands


      ** Type r and a character to replace the character at the cursor position. **

  1. Please move the cursor to the first line marked with ---> below in this section.

  2. Please move the cursor to the first error position.

  3. Then enter r and the character to be replaced, so that the error can be replaced.

  4. Repeat steps 2 and 3 until the first line has been modified.

--->  Whan this lime was tuoed in, someone presswd some wrojg keys!
--->  When this line was typed in, someone pressed some wrong keys!

  5. Then we continue to study the third part of the third lecture.

Bonus tip: Remember that you learn by using, not by memorizing.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
            att


         ** To change the text until the end of a word, enter ce **

  1. Please move the cursor to the first line marked with ---> below in this section.

  2. Next place the cursor where the letter u of the word lubw is.

  3. Then enter cw and the correct word (in this example, enter ine).

  4. Finally press the <ESC> key, and then the cursor is positioned at the first letter to be changed in the next error.

  5. Repeat steps 3 and 4 until the first sentence is exactly the same as the second sentence.

---> This lubw has a few wptfd that mrrf changing usf the change operator.
---> This line has a few words that need changing using the change operator.

Tip: Note that the ce command doesn't just delete a word, it also puts you in insert mode.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
               Lecture 3 Section 4: Use c to change more


       ** The change class operator can be used with the same actions used in delete. **

  1. The change class operator works the same way as the delete class. The format of operation is:

         c    [number]   motion

  2. The motion parameter (motion) is also the same, such as w represents a word, $ represents the end of a line, and so on.

  3. Please move the cursor to the first line marked with ---> below in this section.

  4. Then move the cursor to the first error.

  5. Then type c$ to make the rest of the line correct like the second line. Finally press the <ESC> key.

---> The end of this line needs some help to make it like the second.
---> The end of this line needs to be corrected using the  c$  command.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  Lecture 3 Summary


  1. To reposition deleted text, press the lowercase p key. This action places the deleted
     text content after the cursor. If the last deleted line is a whole line, then the line
     will be placed in the next line of the current cursor line.

  2. To replace the character at the cursor position, please enter a lowercase r and a new
     character .

  3. Change commands allow you to change the text between the current cursor position and the position indicated by the action.
     For example, enter ce to replace the content from the current cursor to the end of the word; enter c$ to replace the content from
     the current cursor to the end of the line.

  4. The format of the change class command is:

     c   [number]   motion

Now we move on to the next lesson.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             ?

  ** Enter CTRL-G to display the line position of the current cursor and file status information in the currently edited file.
     Enter capital G to directly jump to a specified line in the file. **

  Tip: Remember to read this section thoroughly before performing the following steps!!!

  1. Hold down the CTRL key and press the g key. We call this key combination CTRL-G.
     You will see a status information line appear at the bottom of the page, displaying the name of the currently edited file
     and the position of the cursor in the file. Remember the line number, it will be used in step 3.

Tip: You may see the cursor position in the lower right corner of the screen, this happens when the 'ruler' option is set
      (see :help 'ruler')

  2. Enter capital G to make the current cursor directly jump to the last line of the file.
     Enter gg to make the current cursor jump directly to the first line of the file.

  3. Enter the line number you were on, followed by a capital G.
     This will return you to the line you were on when you first pressed CTRL-G.

  4. If you think there is no problem, please perform steps 1 to 3 for practice.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Lecture 4 Section 2: Search Commands


     ** Enter / plus a string can be used to find the string in the current file. **

  1. Enter the / character in normal mode. You will now notice that both the character and the cursor appear at
     the bottom of , just like the : command.

  2. Then type errroor <Enter>. That errroor is the string you're looking for.

  3. To search for the same character string as last time, just press the n key. To find the same
     string , please enter capital N.

  4. If you want to look up a string in reverse, use ? instead of /.

  5. To return to your previous position press CTRL-O (hold down the Ctrl key while pressing the letter o). Press repeatedly to
     go back more steps. CTRL-I jumps to the newer location.

---> "errroor" is not the way to spell error; errroor is an error.
Note: If the search has reached the end of the file, the search will automatically continue from the beginning of the file, unless the
      'wrapscan' option is reset.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
           Lecture 4: Search for parentheses


          ** Type % to find paired parentheses ), ], }. **

  1. Put the cursor on any (, [ or { in the line marked with --> below this section.

  2. Then press the % character.

  3. The position of the cursor should be at the matching bracket.

  4. Press % again to jump back to the first paired parenthesis.

  5. Move the cursor to another (, ), [, ], { or } and press % to see what it does.

---> This ( is a test line with ('s, ['s ] and {'s } in it. ))


Tip: This feature is useful for finding unpaired parentheses when debugging a program.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              Lecture 4 Section 4: Substitution Command


        ** Input: s/old/new/g can replace old with new. **

  1. Please move the cursor to the line marked with ---> below in this section.

  2. Type: s/thee/the <Enter>. Please note that this command only changes the first matching string on the line where the cursor is located
     .

  3. Input: s/thee/the/g is the matching string to replace the whole line, and all "thee" in this line will be
     changed.

---> thee best time to see thee flowers is in thee spring.

  4. To replace every matching string that occurs between two lines, please enter :#,#s/old/new/g where #,# represent                               the line numbers of
     the first and last lines in the lines to be replaced .      Enter :%s/old/new/g to replace every matching string in the entire file.      Entering :%s/old/new/gc will find every matching string in the entire file, and prompt                               whether to replace each matching string.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   Lecture 4 Summary


  1. CTRL-G is used to display the current cursor position and file status information.
     G is used to jump the cursor to the last line of the file.
     Type in a line number first and then enter a capital G to move the cursor to the line represented by the line number.
     gg is used to jump the cursor to the first line of the file.

  2. Enter / followed by a string to search forward for that string in the document currently being edited.
     Entering ? followed by a string is to look up the string in reverse in the document currently being edited.
     After completing a search, press the n key to repeat the previous command, and you can
     find ; or press capital N to find the next matching string in the opposite direction.
     CTRL-O takes you back to an older location, CTRL-I takes you to a newer location.

  3. If the current position of the cursor is a bracket (,), [,], {, }, pressing % will move the cursor to the matching bracket.

  4. To replace the first character string old in a line with the new character string new, please enter: s/old/new To
     replace all the character strings old in a line with the new character string new, please enter: s/old/new /g
     Replace all the strings old in two lines with the new string new, please enter: #,#s/old/new/g Replace all the
     strings old in the file with the new string new, please enter: %s/old/new/g
     asks the user to confirm that each replacement needs to add the c flag when performing full-text replacements: %s/old/new/gc

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Lecture 5 Section 1: How to execute external commands in VIM


       ** Enter:! and then enter an external command to execute the external command. **

  1. Press the familiar : command to move the cursor to the bottom of the screen. This will allow you to enter a one-line command.

  2. Then enter the exclamation point! character, which allows you to execute external shell commands.

  3. Let's take the ls command as an example. Type !ls <Enter>. This command lists
     the contents of your current directory, just as if you had entered the ls command at the command prompt. If !ls doesn't
     work , you can try :!dir to see.

Tip: All external commands can be executed this way, including those with command-line arguments.

Note: All : commands must be terminated with the <Enter> key. We will not always mention this from now on
      .

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              …


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

  1. Enter :!dir or :!ls to get the contents of the current directory. You should already know that you have to hit
     <Enter> at the end.

  2. Choose an unused file name, such as TEST.

  3. Then type:w TEST (where TEST is the file name you chose.)

  4. This command will save the entire file with the name TEST (Vim Tutorial). To verify this,
     type :!dir or :!ls again to see the contents of your directory listing.

Please note: If you quit Vim and then start Vim again with the command vim TEST, the file
     content should be exactly the same as when you saved it.

  5. Now you can delete the TEST file. Under MS-DOS, type: :!del TEST
                                 Under Unix, type: :!rm TEST


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Lecture 5 Section 3: A Selective Save Command


        ** To save part of a file, enter v motion :w FILENAME **

  1. Move the cursor to the current line.

  2. Then press the v key to move the cursor to the fifth item below. You'll notice that the text between is highlighted.

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

  4. Now enter w TEST, where TEST is an unused filename. Make sure you see
     :'<,'>w TEST and press <Enter>.

  5. At this time, Vim will write the selected line to the file named TEST. Use :!dir or :!ls
     to confirm that the file was saved correctly. Don't delete it this time! We'll use it in the next lecture.

Tip: Press v to put Vim into visual mode for selection. You can move the cursor around to make the selection larger or
      smaller. You can then use an operator to operate on the selected text. For example, pressing the d key will delete
      the selected text content.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           Lecture 5 Section 4: Extracting and Merging Files


       ** To insert the contents of another file into the current file, type: r FILENAME **

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

Special reminder: After step 2, you will see the text of the third section of the fifth lecture, please scroll down
          to see the content of this lecture again.

  2. Then use the command: r TEST to extract the previously created file named TEST.
     The files you have extracted will be placed starting from where the cursor is located.

  3. In order to confirm that the file has been successfully extracted, move the cursor back to the original position to notice that there are two copies of the third section of Lecture
     5 , one is the original content, and the other is a copy from the file.

Tip: You can also read the output of external commands. For example, :r !ls reads the output of the ls command and
      places it under the cursor.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   Lecture 5 Summary


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

     See some practical examples:
     (MS-DOS) (Unix)
      :!dir :!ls - Displays the contents of the current directory.
      :!del FILENAME :!rm FILENAME - Used to delete the file named FILENAME.

  2. :w FILENAME can save the file being edited in the current VIM to
     the file .

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

  4. :r FILENAME extracts the disk file FILENAME and inserts it
     after the cursor position in the current file.

  5. :r !dir can read the output of the dir command and place it behind the cursor position of the current file.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             …


     ** Entering o will open a new line below the cursor and enter insert mode. **

  1. Please move the cursor to the line marked with ---> below in this section.

  2. Then enter a lowercase o to open a new line *below* the cursor, this command will put you
     in insert mode.

  3. Then enter some text, then press <ESC> key to exit insert mode and enter normal mode.

---> After typing  o  the cursor is placed on the open line in Insert mode.

  4. To open a new line *above* the cursor, just type an uppercase O instead of a lowercase o
     . Please test it in the downlink.

---> Open up a line above this by typing O while the cursor is on this line.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            …


             ** Enter a to insert text after the cursor. **

  1. Please move the cursor to the beginning of the first line marked with ---> in this section in normal mode.

  2. Then type e until the cursor is at the end of li.

  3. Enter lowercase a to insert text after the cursor.

  4. Complete the word, as in the next line. Then press the <ESC> key to exit Insert mode and return to
     normal mode.

  5. Use e to move the cursor to the next incomplete word, repeat steps 3 and 4.

---> This li will allow you to pract appendi text to a line.
---> This line will allow you to practice appending text to a line.

Tip: a, i, and A all take you to insert mode, the only difference being where the character is inserted.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            …


              ** Enter an uppercase R to replace multiple characters in succession. **

  1. Please move the cursor to the first line marked with ---> below in this section. Move the cursor to the starting position of the first xxx
     .

  2. Then input uppercase R to start inputting the remaining characters in the first line that are different from the second line one by one, then
     all the original characters can be replaced so that the first line is exactly the same as the second line.

  3. Then press the <ESC> key to exit the replacement mode and return to the normal mode. You can notice that text that has not been replaced
     remains as it is.

  4. Repeat the above steps to replace the remaining xxx.

---> Adding 123 to xxx gives you xxx.
---> Adding 123 to 456 gives you 579.

Tip: Replace mode is similar to Insert mode, but each entered character deletes an existing character.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              …


         ** Use operator y to copy text, p to paste text**

  1. Navigate to the line marked with ---> below, and move the cursor after "a)".

  2. Then use v to enter visual mode, and move the cursor to the front of "first".

  3. Now type y to yank (copy) the highlighted text.

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

  5. Then type p to place (paste) the copied text. Then type: a second <ESC>.

  6. Use visual mode to select "item.", copy with y, move the cursor to the end of the next line with j$, and
     paste the text there with p.

--->  a) this is the first item.
      b)

  Tip: You can also use y as an operator; for example yw can be used to copy a word.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
                Section 5: Set the option of the class command


          ** Set options to make find or replace case-insensitive**

  1. To find the word ignore type /ignore <Enter> in normal mode.
     To look up the word repeatedly, press the n key repeatedly.

  2. Then set the ic option (Ignore Case, ignore case), please input: :set ic

  3. Now you can look up the word ignore again by typing the n key. Note that Ignore and IGNORE
     are now also found.

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

  5. You can now enter the find command again to see what happens: /ignore <Enter>

  6. To disable ignoring case, enter: :set noic

Tip: To remove highlighting of matches, type: :nohlsearch
Tip: If you want to ignore letter case only for one search, you can use \c:
      /ignore\c <enter>
~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
                   Lecture 6 Summary

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

  2. Enter lowercase a to insert text after the cursor position.
     Enter an uppercase A to insert text after the end of the line where the cursor is located.

  3. The e command can move the cursor to the end of the word.

  4. The operator y copies text and p pastes previously copied text.

  5. Typing an uppercase R will enter replace mode until <ESC> is pressed to return to normal mode.

  6. Enter: set xxx to set the xxx option. Some useful options are:
      '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 used in full version, An abbreviated version is also available.

  7. Add no before the option to turn off the option: :set noic

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              …


              **Use the online help system**

  Vim has a detailed and comprehensive online help system. To start the help system, choose one of three
  methods :
    - Press the <HELP> key (if available on the keyboard)
    - Press the <F1> key (if available on the keyboard)
    - Type :help <Enter>

  Please read the text in the help window to understand how the help works.
  Typing CTRL-W CTRL-W will allow you to jump between windows.
  Enter: q <Enter> to close the help window.

  Provide a correct argument to the ":help" command and you can find help on the topic. Please experiment with
  the following parameters (don't forget to press the Enter key):

    :help w
    :help c_CTRL-D
    :help insert-index
    :help user-manual
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              Lecture 7 Section 2: Create a startup script


              ** Enable Vim features**

  Vim has many more features than Vi, but most of them are not enabled by default. In order to use more
  features, you have to create a vimrc file.

  1. Start editing the vimrc file, the command depends on your operating system:
        :edit ~/.vimrc This is the command for Unix systems
        : edit $VIM/_vimrc This is the command for MS-Windows systems

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

  3. Save the file, the command is:
        :write

  The next time you start Vim, the editor will have syntax highlighting.
  You can add various settings you like to this vimrc file.
  For more information type: help vimrc-intro

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                Lecture 7 Section 3: Completion Function


          ** Use CTRL-D and <TAB> for command line completion**

  1. Make sure Vim is not running in compatibility mode: :set nocp

  2. To check which files already exist in the current directory, enter: :!ls or :!dir

  3. Now enter the beginning of a directory, for example: :e

  4. Then press CTRL-D, Vim will display a list of commands starting with e.

  5. Then press the <TAB> key, Vim will complete the command as :edit.

  6. Now add a space, and the beginning of the filename of an existing file, eg: :edit FIL

  7. Then press the <TAB> key, Vim will complete the filename (if it is the only match).

Tip: Completion works for many commands. You just try pressing CTRL-D and <TAB>.
      It is very useful for :help command.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  Lecture Seven Summary


  1. Enter: help or press <F1> key or <Help> key to open the help window.

  2. Enter: help cmd to find help about the cmd command.

  3. Type CTRL-W CTRL-W will allow you to jump between windows.

  4. Type :q to close the help window

  5. You can create a vimrc startup script file to save your preferred settings.

  6. When typing the : command, press CTRL-D to view possible completion results.
     Press <TAB> to use a completion.

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

  This concludes the vim tutorial. This tutorial is just a brief introduction to the Vim editor, but it's enough to get you
  started with the editor easily. There is no doubt that vim has many, many commands, and the ones
  introduced are far from complete. So if you want to be proficient, please continue to work hard. Next you can read
  the Vim user manual with the command: :help user-manual

Guess you like

Origin blog.csdn.net/Tir_zhang/article/details/130208468