How to modify and save files by using the vi command in linux

Source: Internet
Author: User


Run vi filename: to open or create a file, place the cursor at the beginning of line vi n filename: to open the file, and place the cursor at the beginning of line n vi filename: open the file, place the cursor in the first line of vi/pattern filename: open the file, and place the cursor in the first string matching pattern vi-r filename: a system crash occurred when editing with vi last time. Restore filenamevi filename .... filename: open multiple files, edit and move the cursor commands in sequence h: move the cursor one character left l: move the cursor one character space right: move the cursor one character Backspace right: move the cursor one character to the left k or Ctrl p: move the cursor up one line j or Ctrl n: move the cursor down one line Enter: move the cursor down one line w or W: move the cursor one word to the first B or B: move the cursor one word left to the beginning e or E: move the cursor one word right to the end of the word): move the cursor to the end of the sentence (: move the cursor to the end of the sentence}: move the cursor Beginning of a paragraph {: move the cursor to the end of a paragraph nG: move the cursor to the beginning of n rows n: move the cursor down n rows n-: move the cursor up n rows n $: move the cursor to the end of line n H: move the cursor to the top line of the screen M: move the cursor to the middle line of the screen L: move the cursor to the screen line 0 :( Note: number 0) move the cursor to the beginning of the current line $: move the cursor to the end of the current line. Run the "Ctrl u" command to flip the screen to the beginning of the file. Press Ctrl d to flip the screen to the end of the file. Press Ctrl f to flip the screen to the end of the file. Press Ctrl + B; flip a screen at the beginning of the file nz: roll line n to the top of the screen. If n is not specified, roll the current line to the top of the screen. insert text command I: Before the cursor I: After the cursor at the beginning of the current line a: After the cursor A: at the end of the current line o: open a new line under the current line O: open a new line above the current line r: Replace the current character R: Replace the current character and the character behind it until Press ESC key s: Start from the current cursor position, replace the specified number of characters with the input text to save the command and press the ESC key to jump to the command mode, and then: w to save the file but do not exit vi: w file to save the modification and save it to the file, do not exit vi: w! Force save, do not release vi: wq to save the file and exit vi: wq! Force save the file, and exit viq: Do not save the file, exit vi: q! Do not save the file, force exit vi: e! Discard all modifications. After the last file is saved and edited, press Enter. OK! Run vi filename: to open or create a file, place the cursor at the beginning of line vi n filename: to open the file, and place the cursor at the beginning of line n vi filename: open the file, place the cursor in the first line of vi/pattern filename: open the file, and place the cursor in the first string matching pattern vi-r filename: a system crash occurred when editing with vi last time. Restore filenamevi filename .... filename: open multiple files, edit www.2cto.com, move the cursor command h: move the cursor to the left one character l: move the cursor to the right one character space: move the cursor to the right one character Backspace: move the cursor one character to the left k or Ctrl p: move the cursor up one line j or Ctrl n: move the cursor down one line Enter: move the cursor down one line w or W: move the cursor one word to the first B or B: move the cursor one word left to the beginning e or E: move the cursor one word right to the end of the word): move the cursor to the end of the sentence (: Move the cursor to the beginning of the paragraph}: move the cursor to the beginning of the paragraph {: move the cursor to the end of the paragraph nG: move the cursor to the first n rows n: move the cursor down n rows n -: move the cursor up n rows n $: move the cursor to the end of n rows H: move the cursor to the top line of the screen M: move the cursor to the middle line of the screen L: move the cursor to the screen line 0 :( Note that the number is zero) move the cursor to the beginning of the current line $: move the cursor to the end of the current line www.2cto.com screen tumble command Ctrl u: Flip the half screen to the first of the file Ctrl d: Flip the half screen to the end of the file Ctrl f: press Ctrl + B at the end of the file, and press nz at the beginning of the file to roll line n to the top of the screen. If n is not specified, the current row is rolled to the top of the screen. insert text command I: Before the cursor I: After the cursor at the beginning of the current line a: After the cursor A: at the end of the current line o: open a new line under the current line O: open a new line above the current line r: Replace the current character R: Replace the current character and the character behind it until Press ESC key s: Start from the current cursor position, replace the specified number of characters with the input text to save the command and Press ESC to jump to the command mode, and then: www.2cto.com: w to save the file but not Exit vi: w file and save the modification to file. Do not exit vi: w! Force save, do not release vi: wq to save the file and exit vi: wq! Force save the file, and exit viq: Do not save the file, exit vi: q! Do not save the file, force exit vi: e! Discard all modifications. After the last file is saved and edited, press Enter. OK! Author wwyu8901

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.