Home Operation and Maintenance Linux Operation and Maintenance What is the vim find and replace command?

What is the vim find and replace command?

Jun 30, 2020 am 11:28 AM
vim replace Find

The vim search command is [wq] to save and exit, [q] is to modify the dimension and exit, [q!] is to force exit without saving; the vim replacement command is [s/old/new] to use New replaces the first occurrence of old in the line. [s/old/new/g] replaces all old in the line with new.

What is the vim find and replace command?

vim search and replace command is:

1. (Command mode) colon command

If you want to exit from the vim command mode interface, you need to enter a colon and command

:wq 保存并退出
:q  维修改退出
:q! 强制退出并不保存
Copy after login

2. (Command mode) move the cursor

In vim Interface, cursor movement method in command mode

1、使用上下左右方向键
2、命令模式下:
h   向左
j   向下 
k   向上
l  向右
空格键 向右
Backspace  向左
Enter  移动到下一行首
-  移动到上一行首。
:set  nu     //显示行号
:set nonu    //取消显示行号
n+        //向下跳n行
n-         //向上跳n行
nG        //跳到行号为n的行
G           //跳至文件的底部
g         //跳转到文件头部
Copy after login

3, (insert mode) editing mode

以下按键进入编辑插入模式
a      //在当前光标位置的右边添加文本
i       //在当前光标位置的左边添加文本
A     //在当前行的末尾位置添加文本
I      //在当前行的开始处添加文本(非空字符的行首)
O     //在当前行的上面新建一行
o     //在当前行的下面新建一行
R    //替换(覆盖)当前光标位置及后面的若干文本
J    //合并光标所在行及下一行为一行(依然在命令模式)
ESC可以退出编辑模式
Copy after login

4, (command mode) deletion and copy

In vim, in addition to modifying files in edit mode, you can delete and copy in command mode

x         //删除当前字符
nx         //删除从光标开始的n个字符
dd       //删除当前行
ndd      //向下删除当前行在内的n行
u        //撤销上一步操作
U        //撤销对当前行的所有操作
yy       //将当前行复制到缓存区,也可以用 "ayy 复制,"a 为缓冲区,a也可以替换为a到z的任意字母,可以完成多个复制任务。
nyy      //将当前行向下n行复制到缓冲区,也可以用 "anyy 复制,"a 为缓冲区,a也可以替换为a到z的任意字母,可以完成多个复制任务。
yw       //复制从光标开始到词尾的字符。
nyw      //复制从光标开始的n个单词。
y^       //复制从光标到行首的内容。  VPS侦探
y$       //复制从光标到行尾的内容。
p        //粘贴剪切板里的内容在光标后,如果使用了前面的自定义缓冲区,建议使用"ap 进行粘贴。
P        //粘贴剪切板里的内容在光标前,如果使用了前面的自定义缓冲区,建议使用"aP 进行粘贴。
Copy after login

5. (Command mode) search and replace

In command mode (esc exits insert mode)

/keyword     //向光标下搜索keyword字符串,keyword可以是正则表达式
?keyword     //向光标上搜索keyword字符串
n           //向下搜索前一个搜素动作
N         //向上搜索前一个搜索动作
*(#)      //当光标停留在某个单词上时, 输入这条命令表示查找与该单词匹配的下(上)一个单词. 同样, 再输入 n 查找下一个匹配处, 输入 N 反方向查找.
g*(g#)        //此命令与上条命令相似, 只不过它不完全匹配光标所在处的单词, 而是匹配包含该单词的所有字符串.
:s/old/new      //用new替换行中首次出现的old
:s/old/new/g         //用new替换行中所有的old
:n,m s/old/new/g     //用new替换从n到m行里所有的old
:%s/old/new/g      //用new替换当前文件里所有的old
Copy after login

Related learning recommendations: linux video tutorial

The above is the detailed content of What is the vim find and replace command?. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to turn off Find My iPhone How to turn off Find My iPhone Nov 09, 2023 pm 02:21 PM

What happens when you turn off Find My on iPhone? Find My iPhone helps you locate a lost or stolen device. When enabled, Find My iPhone lets you track your device's location on a map, plays sounds, and helps you find your device. Find My also includes an Activation Lock to prevent anyone from using your iPhone. When you turn off Find My iPhone, you lose all these features, which may make recovering a lost Apple device difficult. While Find My iPhone is very useful, you should disable it when you want to sell, donate, trade in your phone, or send it for battery replacement or any other service. Doing this will ensure that no one can access information about you

Find the index of an element in an array using the Array.IndexOf function in C# Find the index of an element in an array using the Array.IndexOf function in C# Nov 18, 2023 am 09:59 AM

Use the Array.IndexOf function in C# to find the index of an element in an array. In a C# program, when we need to find the index of an element in an array, we can use the Array.IndexOf function. The Array.IndexOf function finds the specified element within the specified array range and returns the index of its first occurrence. If the element is not found, -1 is returned. The following is a sample code that demonstrates how to use the Array.IndexOf function to find an element in an array.

4 Ways to Turn Off Find My on iPhone 4 Ways to Turn Off Find My on iPhone Feb 02, 2024 pm 04:15 PM

Apple's Find My app allows you to locate your iPhone or other device to prevent it from being lost or forgotten. While Find My is a useful tool for tracking devices, you may want to disable it if you're concerned about privacy issues, don't want to drain your battery, or for other reasons. Fortunately, there are several ways to turn off Find My on iPhone, all of which we will explain in this article. How to Turn off Find My on iPhone [4 Methods] You can turn off Find My on iPhone in four ways. If you used Method 1 to turn off Find, you can do this from the device you want to disable it on. To proceed with methods 2, 3, and 4, the iPhone that you want to turn off Find Finder should be powered off or

How to check the hard disk serial number and mac address How to check the hard disk serial number and mac address Feb 18, 2024 pm 07:45 PM

Hard drive serial numbers and MAC addresses are important identifiers in computer hardware and are very useful in managing and maintaining computer systems. This article will introduce how to find the hard disk serial number and MAC address. 1. Find the hard drive serial number. The hard drive serial number is a unique identifier used by the hard drive manufacturer to identify and track the hard drive. In different operating systems, the method of finding the hard drive serial number is slightly different. Windows: Open Command Prompt (search for "cmd" in the Start menu) and enter the following command and press Enter: wmicdisk

Linux Tips: Cancel automatic indentation when pasting in vim Linux Tips: Cancel automatic indentation when pasting in vim Mar 07, 2024 am 08:30 AM

Preface: vim is a powerful text editing tool, which is very popular on Linux. Recently, I encountered a strange problem when using vim on another server: when I copied and pasted a locally written script into a blank file on the server, automatic indentation occurred. To use a simple example, the script I wrote locally is as follows: aaabbbcccddd. When I copy the above content and paste it into a blank file on the server, what I get is: aabbbcccddd. Obviously, this is what vim does automatically for us. Format indentation. However, this automatic is a bit unintelligent. Record the solution here. Solution: Set the .vimrc configuration file in our home directory, new

Master PyCharm replacement shortcut keys in 5 minutes and easily increase your programming speed! Master PyCharm replacement shortcut keys in 5 minutes and easily increase your programming speed! Feb 22, 2024 am 10:57 AM

PyCharm is a commonly used Python integrated development environment with rich functions and shortcut keys that can help developers improve programming efficiency. In the daily programming process, mastering PyCharm's shortcut key replacement skills can help developers complete tasks more quickly. This article will introduce you to some commonly used replacement shortcut keys in PyCharm to help you easily improve your programming speed. 1.Ctrl+R replacement In PyCharm, you can use the Ctrl+R shortcut key to perform replacement operations.

The glob() function in PHP is used to find files or directories The glob() function in PHP is used to find files or directories Nov 18, 2023 pm 06:17 PM

The glob() function in PHP is used to find files or directories and is a powerful file operation function. It can return the path of a file or directory based on a specified pattern match. The syntax of the glob() function is as follows: glob(pattern, flags) where pattern represents the pattern string to be matched, which can be a wildcard expression, such as *.txt (matching files ending with .txt), or a specific file path. flags is an optional parameter used to control the function

PyCharm Beginner's Guide: Comprehensive Analysis of Replacement Functions PyCharm Beginner's Guide: Comprehensive Analysis of Replacement Functions Feb 25, 2024 am 11:15 AM

PyCharm is a powerful Python integrated development environment with rich functions and tools that can greatly improve development efficiency. Among them, the replacement function is one of the functions frequently used in the development process, which can help developers quickly modify the code and improve the code quality. This article will introduce PyCharm's replacement function in detail, combined with specific code examples, to help novices better master and use this function. Introduction to the replacement function PyCharm's replacement function can help developers quickly replace specified text in the code

See all articles