vim introduction, vim color display and moving the cursor, moving the cursor in vim normal mode, copying, cutting and pasting in vim normal mode

what is vim

what is vim? We have used vi when we contacted Linux before and edited the network card configuration file. vim is simply an upgraded version of vi. Like vi, it is a text editing tool in the Linux system.

If there is no vim in the system, you need to install it: yum install -y vim-enhanced

After installation, it can be used normally. We use vi and vim to open /etc/passwd and find that there is no color difference in the content of the file when using vi, but there are many colors when editing with vim. Whether it is with or without color, as long as it can achieve the purpose we need, it is enough to use any editing tool.

Three common modes of vim

  • general mode
  • edit mode
  • command mode

general mode

When you use the vim_ filename_ command to edit a file, you enter the normal mode. In the normal mode, we can use the arrow keys to move the cursor, and you can also use many things similar to shortcut keys.

  • h cursor moves one character to the left
  • l Move the cursor one character to the right
  • j cursor moves down one character
  • k cursor moves up one character
  • Ctrl+B Text page forward one page
  • Ctrl+F Text page flips back one page
  • The number 0 or shift+6 moves the cursor to the beginning of the line
  • shift+4 move the cursor to the end of the line
  • gg cursor moves to the first line
  • G cursor to end line
  • nG cursor moves to n lines (n is any number)

In normal mode, we can also use shortcut keys to copy, cut, and paste the content of the text

  • x means to delete a character backward (the deleted content is in the clipboard, you can press the p key to paste)
  • X means to delete a character forward (the deleted content is in the clipboard, you can press the p key to paste)
  • nx/nX means to delete n characters backward/forward (the deleted content is in the clipboard, you can press the p key to paste)
  • dd means to delete the content of the line where the cursor is located (the deleted content is in the clipboard, you can press the p key to paste it)
  • ndd means to delete the content of n lines after the line where the cursor is located (for example, delete the line where the cursor is located and 10 lines below it, press 10gg, the deleted content is also in the clipboard)
  • yy Copy the content of the line where the cursor is located
  • nyy Copy a total of n lines including the line where the cursor is located and below
  • p Paste the copied or cut content down from the line where the cursor is located
  • P Paste the copied or cut content upwards from the line where the cursor is located
  • u Restore the previous operation (equivalent to Ctrl+z undo in Windows), restore up to 50 steps
  • Ctrl+r Undo and restore the previous operation (equivalent to undoing the undo operation just now)
  • v Press v to move the cursor, the specified character will be selected, and operations such as copying and cutting can be realized.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325341721&siteId=291194637