Vim enters edit mode, vim command mode, VIM practice

Source: Internet
Author: User
Tags decrypt


Three common modes of VIM
    • General mode

Move cursor Position

Delete, copy, paste

    • Enter edit mode

"I" current word match either insert

"I" is inserted at the beginning of the line where the cursor is located

"A" is inserted in the current word specifier

"A" is inserted at the end of the line where the cursor is

"O" inserts a new line on the next line of the current line

"O" inserts a new line on the previous line of the current row

ESC key exits edit mode

  • Enter Command mode
  • Press ":" or "/" key to enter command mode after exiting edit mode
    • Usage:

/word find a string after the cursor word, press N to go back to search

? Word looks for a string after the cursor word, press N to go back to search

: N1,n2s/word1/word2/g finds Word1 and replaces Word2 before N1 and N2, and replaces only the first word1 of each row without "G".

1, $s/word1/word2/g replace all word1 in the document with Word2, and no G replaces only the first word1 of each row

  • Other uses:

: W--------------------Save text

: Q--------------------Exit vim

: w! -------------------force save, under root user, even if the text is read-only can be saved

: q! -------------------forced exit, all changes do not take effect

: Wq------------------Save and exit

: Set Nu--------------Display line number

: Set Nonu------------do not display line numbers

Shortcuts commonly used in vim


1, note all lines: Ctrl + V j/k+ shift +i



2. Check the cursor's current man manual shift+k



3,d+f+ characters



4, check area v+t+ characters



5. Delete all characters after the cursor in VIM shift+d



6, delete the word on the current cursor d+i+w



7, select the word on the current cursor v+i+w


Vim Paste Code Auto indent cause all messed up


Use VIM to open a blank document, and then paste the copied code into it, found that it has automatic indentation function, resulting in the pasted text line is more than one line on the right, looks mess. The quicker solution is to enter the document in command-line mode before pasting it


:set noai nosi


Sometimes, such a method is not good to use, you can try this:


:set paste
Client putty, Xshell connection to vim in Linux keypad problem


When using VI on the putty, when opening numlock, press the numeric key on the keypad and not enter a number, but a letter and then newline (in fact, the command mode corresponds to the upper and lower keys). Workaround



Option Terminal->features, find disable application keypad mode, select on it.



The Xshell in Xmanager 4 also has a small keyboard problem resolution of



Modify session Properties--terminal->VT mode--Initial numeric keypad mode



Select Set as normal.


Linux uses Vim/vi to encrypt and decrypt files
    • First, using VIM/VI encryption:


Advantages: After encryption, if you do not know the password, you can not see the plaintext, including the root user can not see;



Cons: Obviously let others know encryption, it is easy for others to destroy the encrypted files, including content destruction and
Delete



VI Editor believe that everyone is familiar with it, VI has a command is to encrypt the file, for example:



1) First create an experimental file under the root master directory/root/Text.txt:


[[email protected] ~]#  vim/vi  text.txt


2) Enter the edit mode, press ESC after entering the content, then enter: X (note is the uppercase X), enter;



3) Then the system prompts you to enter the password, 2 times, as follows:


input the password: *******please input it Again: *******


4) After saving the exit, now this file has been encrypted;



5) Use cat or more to view the contents of the file, displayed as garbled; re-edit this file with Vim/vi, will prompt for the password, if the password entered is incorrect, the same will be displayed as garbled!
Note: Do not forget the password after the file is encrypted!


    • Second, decrypt the files encrypted with VI (provided that you know the encrypted password):


1) Open the file with Vim/vi, such as Text.txt, to enter the correct password, and then at the time of editing, set the password to empty, by entering the following command:


:set key=


Then directly enter, after saving the file, the file has been decrypted.



2) or This is OK:



After opening the file correctly with ": X" instruction, and then give a blank password can also. Save with "wq!" Save.
The two methods actually have the same effect.



Vim enters edit mode, vim command mode, VIM practice


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.