当前位置:网站首页>Differences between VI and vim and common commands

Differences between VI and vim and common commands

2022-06-26 09:29:00 Great white bear_ BlankBear

I'm free these days , look down linux Something about , I saw it vi and vim, I've used both of them , It doesn't make much difference , General pure version linux No, vim, There are many differences , Find a detailed article on the Internet , Reprinted

​​​​​​vi And vim Common commands and differences _ Bakabakawa's blog -CSDN Blog _vi and vim

One 、vi And vim The difference between
1、 Multi level undo  
        stay vi Editor , Press u You can only undo the last command , And in the vim You can undo it without limit .
2、 Ease of use
        vi The editor can only run on unix in , and vim Not only can it run on unix, It can also be used for windows、mac Wait for multiple operating platforms .
3、 Grammar highlighting
        vim You can use different colors to highlight your code .
        Compare the following two figures :
            vi main.c


            vim main.c

4、 Visual operation
        vim Not only can it run on the terminal , It can also run on windows、 mac os、 windows.
5、 Yes vi Fully compatible with
        You can put vim As a vi To use .
Summary :vi and vim All are Linux Editor in , The difference is vim More advanced , Can be regarded as vi Updated version of .vi Used in text editing , however vim More applicable to coding.
Two 、VI Pattern
1、 Command line mode (command mode/ General pattern )
        anytime , No matter what mode the user is in , Just press “ESC” key , Can make Vi Enter command line mode ; We are shell Environmental Science ( The prompt is $) Lower input start vi command , When you enter the editor , Also in this mode . 
        In this mode , Users can enter all kinds of legal vi command , For managing your own documents . Any character entered from the keyboard is interpreted as an edit command , If the input character is legal Vi command , be vi After receiving the user's command, complete the corresponding action . But it should be noted that , The command entered is not displayed on the screen . If the input character is not Vi The legal order of ,vi Will ring the alarm .
2、 Text input mode (input mode/ Edit mode )
        Enter the insert command in command mode i(insert)、 Additional orders a (append)、 Open command o(open)、 Modify the order c(change)、 In place of orders r Or replace the command s You can enter text input mode . In this mode , Any character entered by the user is vi Save it as file content , And show it on the screen . In the process of text input , If you want to return to command line mode , Press ”ESC” Press the key .
3、 Last row mode (last line mode/ Command line command mode )
        Last line mode is also called escape mode . 
        vi and Ex The editor functions the same , The main difference between the two is the user interface . stay vi in , The command is usually a single key , for example i、a、o etc. ; And in the Ex in , A command is a line of text that ends with the Enter key .vi There is a special “ escape ” command , Access a lot of line oriented Ex command . 
        In command mode , User presses “:” Key to enter the last line mode , here vi In the last line of the display window ( It's usually the last line of the screen ) Display a “:” As a prompt for the last line mode , Wait for the user to enter the command . Most file management commands are executed in this mode ( Write the contents of the edit buffer to a file ). After the last command is executed ,vi Automatically return to command mode .
3、 ... and 、VIM Pattern
1、 Normal mode (Normal-mode)
        start-up vim After default in normal mode ( Command line mode ). No matter in what mode , Press down <Esc> key ( Sometimes you need to press twice ) Will go into normal mode .
2、 Insertion mode (Insert-mode)
        Press... In normal mode i, a, o, I,A,O key , Will enter insert mode . Now just remember to press i The key will perform the insert mode . In insert mode , The corresponding characters will be written when the key is pressed .
3、 Command mode (Command-mode)
        In normal mode , Press down :( English colon ) key , Will enter command mode .
        In command mode, you can execute some inputs and execute some vim Or the instructions provided by the plug-in , As in the shell Same as in . These instructions include setting up the environment 、 File operations 、 Call a function and so on .
4、 Visual Modes (Visual-mode)
        Press... In normal mode v,V,<ctrl>+v, You can go into visual mode .
        The operation in visual mode is a bit like operating with a mouse , When selecting text, there is a visual sense of mouse selection , Sometimes it's convenient .
Four 、VI And VIM Common commands
notes : because VI And VIM Almost the same in command , So here and there VIM For example .
1、 Mode conversion
        normal --> Input : The following parameters realize the function of changing to input mode , Only the cursor position after conversion is different ( If you are interested, you can try , It doesn't mean much !)
            i: In front of the current cursor character , Switch to input mode ;
            a: After the character of the current cursor , Switch to input mode ;
            o: Below the line of the current cursor , Create a new line , And switch to input mode ;
            I: At the beginning of the current cursor line , Switch to input mode ;
            A: At the end of the current cursor line , Switch to input mode ;
            O: Above the line of the current cursor , Create a new line , And switch to input mode ;
        Input --> normal :
            ESC
        normal --> Last line :
            :( English colon )
        Last line --> normal :
            ESC,ESC
Be careful : There is no direct switch between input mode and last line mode .
2、 Close file ( Last row mode )
        :q         sign out ;
        :q!         Exit without saving ;
        :w         preservation ;
        :w!         Forcibly preserve ;
        :wq         Save and exit
        :wq!         Force save and exit
Be careful : Press the key combination in normal mode shift zz You can save and exit
3、 Move the cursor ( Normal mode )
    1) Move character by character :
       h: Left ;
        l: Right ;
        j: Next ;
        k: On ;
        #h: Move # Characters
    2) Move in words
        w: Move to the beginning of the next word ;
        e: Jump to the end of the current or next word ;
        b: Jump to the beginning of the current or previous word ;
        #w: Move # Word
    3) Intra line jump :
        0: Absolutely first line ;
        ^: The first non white space character at the beginning of a line ;
        $: Absolute end of line
    4) Line jump
        #G: Jump to # That's ok ;
        gg: first line ;
        G: The last line
    5) Last row mode
        .: Indicates the current line ;
        $: The last line ;
        #: The first # That's ok ;
        +#: Downward # That's ok
4、 Flip screen ( Normal mode )
        Ctrl+f: Flip down one screen ;
        Ctrl+b: Turn up one screen ;
        Ctrl+d: Turn down half screen ;
        Ctrl+u: Turn up half screen
5、 Copy characters
    1) Normal mode
        Copy :
        yy: Copy the current row
        nyy: Copy the current line to n That's ok
        Paste :
        p: Paste behind the cursor
        P: Paste in front of the cursor
    2) Visual Modes
        Copy :
        y: Copy the current row
        ny: Copy the current line to n That's ok
        Paste :
        p: Paste behind the cursor
        P: Paste in front of the cursor
6、 Delete character ( Normal mode )
        x: Delete the single character at the cursor ;
        #x: Delete the total... At the cursor and back # Characters ;
        d$ or D: Delete from the current cursor to the end of the line ;
        d^: Deletes the beginning of the line from the current cursor ;
        dd: Delete the current cursor line ;
        #dd: Delete the line including the current cursor # That's ok ;
notes :dd It is equivalent to cutting operation , If you dd Then press p perhaps P You can paste .
7、 Replace character
        r: Replace single characters ( Finish r Just press the character you want to replace )
        R: Replace multiple characters ( Start at the place you want to replace , Until you exit normal mode )
8、 Undo editing :u
        u: Undo the previous edit operation ;
        #u: Undo recent directly # Edit operation ;
        reminder : continuity u The command can undo the previous n Edit operation ;
9、 Put another file (/path/sunhui.txt) The contents of are filled in the current folder
:r   /path/sunhui.txt : Fill after the cursor of the current file
10、 modify vim The configuration file
        vim   ~/.vimrc: Modify the current user's vim The configuration file
        vim    /etc/vimrc: Modify all users' vim The configuration file
        example : In the current user's vim Add a command to the configuration file to display the number of lines
        vim    ~/.vimrc: Add... In the last line set nu that will do
11、 expand ( Last row mode )
    1) Show or suppress the line number
        :set    nu            // Show
        :set    number    // Show
        :set    nonu        // Cancel
    2) Set syntax highlighting
        :syntax    on    // Turn on
        :syntax    off    // close
    3) Split screen
        :vsp xxx.x    // Split the two files vertically
        :ctrl+w w   // Cut screen
notes : This feature is currently valid , If you want to be valid permanently, you need to modify the configuration file
 

原网站

版权声明
本文为[Great white bear_ BlankBear]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170550232372.html