The vi command is used to enter vi, the most versatile full-screen plain text editor in the UNIX operating system. The vi editor supports edit mode and command mode. In the edit mode, you can complete the text editing function, and in the command mode, you can complete the file operation commands. To use the vi editor correctly, you must be proficient in switching between the two modes.
vi command
vi command is in UNIX operating systems and UNIX-like operating systems The most versatile full-screen plain text editor. The vi editor in Linux is called vim, which is an enhanced version of vi (vi Improved). It is fully compatible with the vi editor and implements many enhanced functions.
vi editor supports edit mode and command mode. In edit mode, you can complete text editing functions, and in command mode, you can complete file operation commands. To use the vi editor correctly, you must be proficient in both. Mode switching. By default, the vi editor automatically enters command mode after opening it. Use the "esc" key to switch from edit mode to command mode, and use the "A", "a", "O", "o", "I", and "i" keys to switch from command mode to edit mode.
The vi editor provides a wealth of built-in commands. Some built-in commands can be completed using keyboard key combinations, and some built-in commands need to be entered starting with a colon ":". Commonly used built-in commands are as follows:
Ctrl+u:向文件首翻半屏; Ctrl+d:向文件尾翻半屏; Ctrl+f:向文件尾翻一屏; Ctrl+b:向文件首翻一屏; Esc:从编辑模式切换到命令模式; ZZ:命令模式下保存当前文件所做的修改后退出vi; :行号:光标跳转到指定行的行首; :$:光标跳转到最后一行的行首; x或X:删除一个字符,x删除光标后的,而X删除光标前的; D:删除从当前光标到光标所在行尾的全部字符;dd:删除光标行正行内容; ndd:删除当前行及其后n-1行; nyy:将当前行及其下n行的内容保存到寄存器?中,其中?为一个字母,n为一个数字; p:粘贴文本操作,用于将缓存区的内容粘贴到当前光标所在位置的下方; P:粘贴文本操作,用于将缓存区的内容粘贴到当前光标所在位置的上方; /字符串:文本查找操作,用于从当前光标所在位置开始向文件尾部查找指定字符串的内容,查找的字符串会被加亮显示; ?name:文本查找操作,用于从当前光标所在位置开始向文件头部查找指定字符串的内容,查找的字符串会被加亮显示; a,bs/F/T:替换文本操作,用于在第a行到第b行之间,将F字符串换成T字符串。其中,“s/”表示进行替换操作; a:在当前字符后添加文本; A:在行末添加文本; i:在当前字符前插入文本; I:在行首插入文本; o:在当前行后面插入一空行; O:在当前行前面插入一空行; :wq:在命令模式下,执行存盘退出操作; :w:在命令模式下,执行存盘操作; :w!:在命令模式下,执行强制存盘操作; :q:在命令模式下,执行退出vi操作; :q!:在命令模式下,执行强制退出vi操作; :e文件名:在命令模式下,打开并编辑指定名称的文件; :n:在命令模式下,如果同时打开多个文件,则继续编辑下一个文件; :f:在命令模式下,用于显示当前的文件名、光标所在行的行号以及显示比例; :set number:在命令模式下,用于在最左端显示行号; :set nonumber:在命令模式下,用于在最左端不显示行号;
Syntax
Options
+<行号>:从指定行号的行开始先是文本内容; -b:以二进制模式打开文件,用于编辑二进制文件和可执行文件; -c<指令>:在完成对第一个文件编辑任务后,执行给出的指令; -d:以diff模式打开文件,当多个文件编辑时,显示文件差异部分; -l:使用lisp模式,打开“lisp”和“showmatch”; -m:取消写文件功能,重设“write”选项; -M:关闭修改功能; -n:不实用缓存功能; -o<文件数目>:指定同时打开指定数目的文件; -R:以只读方式打开文件; -s:安静模式,不现实指令的任何错误信息。
Parameters
Knowledge expansion
Command mode
Enter the command vi after the Shell prompt to enter the vi editor and be in vi command mode. At this time, any characters entered from the keyboard are interpreted as editing commands. For example, a (append) represents an append command, i (insert) represents an insert command, x represents a delete character command, etc. If the entered character is not a legal command of vi, the machine will sound an "alarm sound" and the cursor will not move. In addition, the characters entered in command mode (i.e. vi command) are not displayed on the screen. For example, if you enter i, there will be no change on the screen, but by executing the i command, the working mode of the editor will change: by command mode Change to input mode.Input method
By inputting vi’s insert command (i), append command (a), open command (o), replace command (s), and modify command (c) or replace the command (r) to enter the input mode from the command mode. In input mode, all characters entered from the keyboard are inserted into the buffer being edited and treated as the text of the file. After entering the input mode, all the visible characters entered are displayed on the screen, but the editing commands no longer work and only appear as ordinary letters. For example, if you enter the letter i in command mode, enter the input mode, and then enter i again, a letter i will be added to the corresponding cursor on the screen. The way to return to the command mode from the input mode is to press the Esc key. If you are already in command mode, pressing the Esc key will make a "beep" sound. In order to ensure that the vi command that the user wants to execute is entered in command mode, you may wish to press the Esc key a few more times and enter the command after hearing the beep. ex escape methodThe functions of vi and ex editor are the same, the main difference between them is the user interface. In vi, commands are usually single letters, such as a, x, r, etc. In ex, the command is a command line that ends with the Enter; key. vi has a dedicated "escape" command that provides access to many line-oriented ex commands. To use ex escape mode, enter a colon (:). As with the ex command prompt, the colon appears on the status line (usually the bottom line of the screen). Press the interrupt key (usually the Del key) to terminate the executing command. Most file management commands are executed in ex escape mode (for example, reading a file, writing the contents of the edit buffer to a file, etc.). After the escape command is executed, it automatically returns to the command mode. For example::1,$s/I/i/g 按Enter键will replace all uppercase I's with lowercase i's from the first line of the file to the end of the file ($).
The above is the detailed content of What is the function of linux file editing command vi?. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!