VI常用技巧总结
VI常用技巧 VI命令可以说是Unix/Linux世界里最常用的编辑文件的命令了,但是因为它的命令集众多,很多人都不习惯使用它,其实您只需要掌握基本命令,然后加以灵活运用,就会发现它的优势,并会逐渐喜欢使用这种方法。本文旨在介绍VI的一些最常用命令和高级应
VI常用技巧VI命令可以说是Unix/Linux世界里最常用的编辑文件的命令了,但是因为它的命令集众多,很多人都不习惯使用它,其实您只需要掌握基本命令,然后加以灵活运用,就会发现它的优势,并会逐渐喜欢使用这种方法。本文旨在介绍VI的一些最常用命令和高级应用技巧。
1.vi 模式
a) 一般模式: vi 处理文件时,一进入该文件,就是一般模式了.
b) 编辑模式:在一般模式下可以进行删除,复制,粘贴等操作,却无法进行编辑操作。等按下‘i,I,o,O,a,A,r,R’等
字母之后才能进入编辑模式.通常在linux中,按下上述字母时,左下方会出现'INSERT'或者‘REPLACE’字样,才可以
输入任何文字到文件中.要回到一般模式,按下[ESC]键即可.
c) 命令行模式:在一般模式中,输入“: 或者/或者?”,即可将光标移动到最下面一行,在该模式下,您可以搜索数据,而且读取,
存盘,大量删除字符,离开vi,显示行号等操作.
2.vi 常用命令汇总:
2.1 一般模式
a) 移动光标:
--> 上下左右方向键 ↑↓← →
--> 翻页 pagedown / pageup 按键
--> 数字 0 : 将光标移动到当前行首
--> $ : 将光标移动到当前行尾
--> G : 移动到这个文件的最后一行 nG : n 为数字,移动到这个文件的第n行.
--> gg: 移动到这个文件的第一行 相当于 1G
b) 搜索与替换
--> /word : 从光标开始,向下查询一个名为word的字符串。
--> :n1、n2s/word1/word2/g : n1 与n2 为数字.在第n1与n2行之间寻找word1这个字符串,
并将该字符串替换为word2。
--> :1、$s/word1/word2/g : 从第一行到最后一行寻找word1字符串,并将该字符串替换为word2
--> :1、$s/word1/word2/gc: 从第一行到最后一行寻找word1字符串,并将该字符串替换为word2。
并且在替换之前显示提示符给用户确认(conform)是否需要替换。
c) 删除,复制,粘贴
--> x,X : 在一行中,x为向后删除一个字符(相当于del键),X为向前删除一个字符(相当于backspace键)。
--> dd : 删除光标所在的那一整行。
--> ndd : n 为数字。从光标开始,删除向下n列。
--> yy : 复制光标所在的那一行。
--> nyy : n为数字。复制光标所在的向下n行。
--> p,P : p 为将已复制的数据粘贴到光标的下一行,P则为贴在光标的上一行。
--> u : 复原前一个操作
--> CTRL + r : 重做上一个操作。
--> 小数点'.': 重复前一个动作。
2.2 编辑模式:
a) i, I : 在光标所在处插入输入文字,已存在的文字向后退。i 为‘从当前光标所在处插入’,I 为‘在当前所在行的一个非空格符处开始插入’。
b) a, A : a 为‘从当前光标所在处的下一个字符开始插入’。A 为‘从光标所在行的最后一个字符处开始插入’。
c) o,O : 这是英文o的大小写。o为‘在当前光标所在行的下一行处插入新的一行’。O表示‘在当前光标所在行的上一行插入新的一行’。
d) r,R : 替换:r 会替换光标所在的那一个字符。 R : 会一直替换光标所在的字符,直到按下esc 键为止。
e) ESC : 进入一般模式。
2.3 命令模式:
a) :w : 将编辑的数据写入硬盘
b) :q : 离开vi
c) :q! : 强制离开,不存储
d) :wq : 存储后离开
e) :wq! : 强制存储后离开
3. vim 附加命令行
3.1 块选择(visual block)
v 字符选择,将光标经过的地方反白显示
V 行选择,会将光标经过的行反白选择
ctrl + v 块选择,可以用长方形的方式选择数据
y 复制反白的地方
d 将反白的地方删除掉
3.2 多文件编辑
:n 编辑下一个文件
:N 编辑上一个文件
:files 列出当前vim 打开的所有文件
3.3 多窗口功能
:sp 【filename】打开一个新窗口,如果加filename,表示在新窗口打开一个新文件
否则表示两个窗口为同一个文件内容
ctrl+wj 先按下ctrl ,再按下w后,放开所有按键,然后按下j,则光标可移动到下方的窗口
ctrl+wk 同上,不过光标移动到上面的窗口
ctrl+wq 其实就是:q结束离开。

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Win11 Tips Sharing: One trick to skip Microsoft account login Windows 11 is the latest operating system launched by Microsoft, with a new design style and many practical functions. However, for some users, having to log in to their Microsoft account every time they boot up the system can be a bit annoying. If you are one of them, you might as well try the following tips, which will allow you to skip logging in with a Microsoft account and enter the desktop interface directly. First, we need to create a local account in the system to log in instead of a Microsoft account. The advantage of doing this is

Widgets are a new feature of the Win11 system. They are turned on by default. However, it is inevitable that some users do not use widgets very much and want to disable them because they take up space. So how should they do this? The editor below will teach you how to operate it, and you can try it out. What are widgets? Widgets are small cards that display dynamic content from your favorite apps and services on your Windows desktop. They appear on the widget board, where you can discover, pin, unpin, arrange, resize, and customize widgets to reflect your interests. The widget board is optimized to display relevant widgets and personalized content based on usage. Open the widget panel from the left corner of the taskbar, where you can see live weather

In C language, it represents a pointer, which stores the address of other variables; & represents the address operator, which returns the memory address of a variable. Tips for using pointers include defining pointers, dereferencing pointers, and ensuring that pointers point to valid addresses; tips for using address operators & include obtaining variable addresses, and returning the address of the first element of the array when obtaining the address of an array element. A practical example demonstrating the use of pointer and address operators to reverse a string.

What is the correct way to restart a service in Linux? When using a Linux system, we often encounter situations where we need to restart a certain service, but sometimes we may encounter some problems when restarting the service, such as the service not actually stopping or starting. Therefore, it is very important to master the correct way to restart services. In Linux, you can usually use the systemctl command to manage system services. The systemctl command is part of the systemd system manager

We often create and edit tables in excel, but as a novice who has just come into contact with the software, how to use excel to create tables is not as easy as it is for us. Below, we will conduct some drills on some steps of table creation that novices, that is, beginners, need to master. We hope it will be helpful to those in need. A sample form for beginners is shown below: Let’s see how to complete it! 1. There are two methods to create a new excel document. You can right-click the mouse on a blank location on the [Desktop] - [New] - [xls] file. You can also [Start]-[All Programs]-[Microsoft Office]-[Microsoft Excel 20**] 2. Double-click our new ex

LSOF (ListOpenFiles) is a command line tool mainly used to monitor system resources similar to Linux/Unix operating systems. Through the LSOF command, users can get detailed information about the active files in the system and the processes that are accessing these files. LSOF can help users identify the processes currently occupying file resources, thereby better managing system resources and troubleshooting possible problems. LSOF is powerful and flexible, and can help system administrators quickly locate file-related problems, such as file leaks, unclosed file descriptors, etc. Via LSOF Command The LSOF command line tool allows system administrators and developers to: Determine which processes are currently using a specific file or port, in the event of a port conflict

After several pre-releases, the KDE Plasma development team unveiled version 6.0 of its desktop environment for Linux and BSD systems on 28 February, using the Qt6 framework for the first time. KDE Plasma 6.1 now comes with a number of new features t

VSCode (Visual Studio Code) is an open source code editor developed by Microsoft. It has powerful functions and rich plug-in support, making it one of the preferred tools for developers. This article will provide an introductory guide for beginners to help them quickly master the skills of using VSCode. In this article, we will introduce how to install VSCode, basic editing operations, shortcut keys, plug-in installation, etc., and provide readers with specific code examples. 1. Install VSCode first, we need
