Home > System Tutorial > LINUX > body text

VIM Editor Operation Guide

王林
Release: 2024-09-02 15:47:23
Original
1183 people have browsed it
vim [参数] [文件 ..] 编辑指定的文件
或: vim [参数] - 从标准输入(stdin)读取文本
或: vim [参数] -t tag 编辑 tag 定义处的文件
或: vim [参数] -q [errorfile] 编辑第一个出错处的文件
Copy after login
Parameters:
--  在这以后只有文件名
-v Vi 模式 (同 "vi")
-e Ex 模式 (同 "ex")
-E Improved Ex mode
-s 安静(批处理)模式 (只能与 "ex" 一起使用)
-d Diff 模式 (同 "vimdiff")
-y 容易模式 (同 "evim",无模式)
-R 只读模式 (同 "view")
-Z 限制模式 (同 "rvim")
-m 不可修改(写入文件)
-M 文本不可修改
-b 二进制模式
-l Lisp 模式
-C 兼容传统的 Vi: 'compatible'
-N 不完全兼容传统的 Vi: 'nocompatible'
-V[N][fname] Be verbose [level N] [log messages to fname]
-D 调试模式
-n 不使用交换文件,只使用内存
-r 列出交换文件并退出
-r(跟文件名) 恢复崩溃的会话
-L 同 -r
-A 以 Arabic 模式启动
-H 以 Hebrew 模式启动
-F 以 Farsi 模式启动
-T  设定终端类型为
--not-a-term Skip warning for input/output not being a terminal
-u  使用 替代任何 .vimrc
--noplugin 不加载 plugin 脚本
-P[N] 打开 N 个标签页 (默认值: 每个文件一个)
-o[N] 打开 N 个窗口 (默认值: 每个文件一个)
-O[N] 同 -o 但垂直分割
+ 启动后跳到文件末尾
+ 启动后跳到第 行
--cmd <command></command> 加载任何 vimrc 文件前执行
<command></command>   -c <command></command> 加载第一个文件后执行
<command></command>   -S  加载第一个文件后执行文件
<command></command>   -s  从文件 读入正常模式的命令
<command></command>   -w  将所有输入的命令追加到文件
<command></command>   -W  将所有输入的命令写入到文件
<command></command>   -x 编辑加密的文件
<command></command>   --startuptime Write startup timing messages to
<command></command>   -i  使用 取代 .viminfo
<command></command>   -h 或 --help 打印帮助(本信息)并退出
<command></command>   --version 打印版本信息并退出
Copy after login
Editor mode:

Vi has three basic working modes:

VIM 编辑器操作指南

Command line mode

At any time, no matter what mode the user is in, just press the ESC key to enter Vi into the command mode; when we enter the start Vi command in the shell environment (the prompt is $), when entering the editor, we are also in in this mode. In this mode, users can enter various legal Vi commands to manage their own documents. At this time, any character entered from the keyboard is interpreted as an editing command. If the entered character is a legal Vi command, Vi completes the corresponding action after accepting the user command. However, it should be noted that the entered commands are not displayed on the screen. If the characters entered are not legal commands for Vi, Vi will ring the alarm.

Text input mode

In command mode, enter the insert command i, append command a, open command o, modify command c, replace command r or replace command s to enter text input mode. In this mode, any characters entered by the user are saved by Vi as file content and displayed on the screen. During the text input process, if you want to return to the command mode, just press the ESC key.

Last line mode

Last line mode is also called ex escape mode. In command mode, the user presses the ":" key to enter the last line mode. At this time, Vi will display a ":" on the last line of the display window (usually the last line of the screen) as the prompt for the last line mode. Wait for the user to enter a command. Most file management commands are executed in this mode (such as writing the contents of the edit buffer to a file, etc.). After the last command line is executed, Vi automatically returns to command mode. For example:

:sp newfile
Copy after login

will separate a window to edit the newfile file. If you want to switch from command mode to edit mode, you can type the command a or i; if you need to return from text mode, just press the Esc key. Enter ":" in command mode to switch to last line mode, and then enter the command.

Enter insert mode:

i: 插入光标前一个字符

I: 插入行首

a: 插入光标后一个字符

A: 插入行未

o: 向下新开一行,插入行首

O: 向上新开一行,插入行首
Copy after login

Enter command mode:

ESC:从插入模式或末行模式进入命令模式

移动光标:

h: 左移

j: 下移

k: 上移

l: 右移

M: 光标移动到中间行

L: 光标移动到屏幕最后一行行首

G: 移动到指定行,行号 -G

w: 向后一次移动一个字

b: 向前一次移动一个字

{: 按段移动,上移

}: 按段移动,下移

Ctr-d: 向下翻半屏

Ctr-u: 向上翻半屏

Ctr-f: 向下翻一屏

Ctr-b: 向上翻一屏

gg: 光标移动文件开头

G: 光标移动到文件末尾
Copy after login

Delete command:

x: 删除光标后一个字符,相当于

Del X: 删除光标前一个字符,相当于 Backspace

dd: 删除光标所在行,n dd 删除指定的行数

D: 删除光标后本行所有内容,包含光标所在字符

d0: 删除光标前本行所有内容,不包含光标所在字符

dw: 删除光标开始位置的字,包含光标所在字符
Copy after login

Cancel command:

u: 一步一步撤销

Ctr-r: 反撤销
Copy after login

Repeat command:

.: 重复上一次操作的命令

文本行移动:

>>: 文本行右移

<<: 文本行左移 复制粘贴: yy: 复制当前行,n yy 复制 n 行 p: 在光标所在位置向下新开辟一行,粘贴 可视模式: v: 按字符移动,选中文本 V: 按行移动,选中文本可视模式可以配合 d, y, >>, << 实现对文本块的删除,复制,左右移动

替换操作:

r: 替换当前字符

R: 替换当前行光标后的字符

查找命令:

/: str查找

n: 下一个

N:上一个
Copy after login

Replace command:

把abc全部替换成123

末行模式下,将当前文件中的所有abc替换成123

:%s/abc/123/g

末行模式下,将第一行至第10行之间的abc替换成123

:1, 10s/abc/123/g

vim里执行 shell 下命令:

末行模式里输入!,后面跟命令
Copy after login

The above is the detailed content of VIM Editor Operation Guide. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!