search

Summarize some common commands of VIM

Jun 27, 2017 am 11:20 AM
getting StartedOrderCommonly usedfast

There are many detailed commands in VIM. We have selected some commonly used entry-level commands, which are enough for daily code editing work. If you need to use other commands in the future, it is not too late to check again.

vim generally has three editing modes, namely insert mode, normal mode, and last line mode.

The following are mainly operations in normal mode. Operations in other modes will indicate the relevant modes

1.1 Moving the cursor

h------>Move left each time you press

j------>Down each time you press Move

k------>Move up each time

##l------>Every time Press to move right

1.2 Entering and exiting vim

Press < ;Esc> key to enter normal mode

Then enter the following methods to exit

:q           #不保存并退出vim:q!          #强制退出:wq           #保存文件并退出:x            #相当于:wq

1.3 Delete text editing

In normal mode (Normal mode), you can press the x key to Delete the character at the cursor position.

1.4 Insertion of text editing

Enter insert mode in normal mode, you can There are several methods:

You can press the i key to insert text at the cursor.

Press the a key to insert text behind the cursor.

Press the capital A key to insert text after the last character on the line where the cursor is.

1.5 Text Editing Add

Press the A key and click on the line where the cursor is. Add

to the end of the text. Press the a key and add

after the cursor position. 2.1 Delete command

Enter dw to delete from the cursor to the end of a word.

2.2 About commands and objects

Many commands that change text are composed of an operation The symbol is composed of an action.

The format of the delete command using the delete operator d is as follows:

 dmotion

Among them:

## d   -Delete operator

 motion                                    die through in >> motion     - Delete operator

##A short action list:

w - From the current cursor position to the beginning of the next word, excluding its first characters.

 e - From the current cursor position to the end of the word, including the last character.

 $ - From the current cursor position to the end of the current line.

2.3 Use counting to formulate actions

Enter the number n before the action, it will It repeats n times.

Enter 2w to move the cursor back 2 words.

Enter 3e to move the cursor backward to the end of the 3rd word.

Enter 0 (number zero) to move the cursor to the beginning of the line.

2.4 Use counting to delete more

Enter the number n when using the operator , which can be repeated n times.

For example: operation number (number) motion

d2w You can delete 2 words.

2.5 Operate the entire line

Enter dd to delete a current line and save it to the register, which functions like a "cut" operation and can be used in conjunction with the p operation.

######

2.6 Undo commands

Enter u to undo the last executed command, and enter U to undo modifications to the entire line.

Use Ctrl + r to undo a previous undo command.

3.1 Insert class command

Enter p to "cut" the last time The content is placed after the cursor.

3.2 Replacement command

Move the cursor to the character position to be modified and enter r and a character to replace the character at the cursor position.

3.3 Change command (c command, meaning "change")

To change text until the end of a word, enter ce.

3.4 Use c to change more

 c [number] motion

The action parameter motion is the same, it can be w, e, $d.

4.1 Positioning and file status

Enter Ctrl + g to display the currently edited file The line position of the current cursor and file status information.

Enter capital G to jump directly to the last line of the file.

Enter nG to jump to the line with line number n.

Enter gg to jump to the first line of the file.

4.2 Search command

Enter / plus a string, you can Find this string in the current file. To find the next string, press the n key. To search in reverse, enter a capital N.

If you want to search in reverse, enter ? replace / .

4.3 Search for matching brackets

Position the cursor at the bracket to be matched , enter % to find another bracket that matches it), ], }.

4.4 Replacement command

Enter: s/old/new, you can replace it once The string at old in this line is the string at new.

Enter :s/old/new/g to replace all the strings at old in the line with the strings at new.

Input:#,#s/old/new/g, where #,# represent the line numbers of the starting line and the ending line of the replacement operation.

Enter :%s/old/new/g to replace every matching string in the entire file.

Enter :%s/old/new/gc, each matching string in the entire file will be found, and each matching string will be prompted whether to replace it.

5.1 How to execute external commands in VIM

Enter:! Then enter an external command immediately Execute this external command.

For example, :!ls + Enter, this command lists the contents of your current directory.

5.2 More information about saving files

To save changes to a file, enter :w filename.

5.3 A selective save command

Select by pressing the v key To save part of the file, then enter:w file name to save the selected content to the target file.

5.4 Extract and merge files

To insert another file into the current file For the content, please enter:r file name.

6.1 Open the class command

Enter o, a new file will be opened under the cursor row and enter insert mode.

Enter a capital O to open a new line above the cursor and enter insert mode.

6.2 Another version of the substitution command

Enter uppercase R, you can Replace multiple characters in a row.

6.3 Copy and paste text

Use operator y to copy text and p to paste text.

Enter yy to copy the line where the cursor is.

can be used with the action parameter motion:

Enter yw to copy a word.

The above is the detailed content of Summarize some common commands of VIM. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
Maintenance Mode in Linux: A System Administrator's GuideMaintenance Mode in Linux: A System Administrator's GuideApr 26, 2025 am 12:20 AM

Maintenance mode plays a key role in Linux system management, helping to repair, upgrade and configuration changes. 1. Enter maintenance mode. You can select it through the GRUB menu or use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can perform file system repair and system update operations. 3. Advanced usage includes tasks such as resetting the root password. 4. Common errors such as not being able to enter maintenance mode or mount the file system, can be fixed by checking the GRUB configuration and using the fsck command.

Maintenance Mode in Linux: When and Why to Use ItMaintenance Mode in Linux: When and Why to Use ItApr 25, 2025 am 12:15 AM

The timing and reasons for using Linux maintenance mode: 1) When the system starts up, 2) When performing major system updates or upgrades, 3) When performing file system maintenance. Maintenance mode provides a safe and controlled environment, ensuring operational safety and efficiency, reducing impact on users, and enhancing system security.

Linux: Essential Commands and OperationsLinux: Essential Commands and OperationsApr 24, 2025 am 12:20 AM

Indispensable commands in Linux include: 1.ls: list directory contents; 2.cd: change working directory; 3.mkdir: create a new directory; 4.rm: delete file or directory; 5.cp: copy file or directory; 6.mv: move or rename file or directory. These commands help users manage files and systems efficiently by interacting with the kernel.

Linux Operations: Managing Files, Directories, and PermissionsLinux Operations: Managing Files, Directories, and PermissionsApr 23, 2025 am 12:19 AM

In Linux, file and directory management uses ls, cd, mkdir, rm, cp, mv commands, and permission management uses chmod, chown, and chgrp commands. 1. File and directory management commands such as ls-l list detailed information, mkdir-p recursively create directories. 2. Permission management commands such as chmod755file set file permissions, chownuserfile changes file owner, and chgrpgroupfile changes file group. These commands are based on file system structure and user and group systems, and operate and control through system calls and metadata.

What is Maintenance Mode in Linux? ExplainedWhat is Maintenance Mode in Linux? ExplainedApr 22, 2025 am 12:06 AM

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo

Linux: A Deep Dive into Its Fundamental PartsLinux: A Deep Dive into Its Fundamental PartsApr 21, 2025 am 12:03 AM

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

Linux Architecture: Unveiling the 5 Basic ComponentsLinux Architecture: Unveiling the 5 Basic ComponentsApr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Linux Operations: Utilizing the Maintenance ModeLinux Operations: Utilizing the Maintenance ModeApr 19, 2025 am 12:08 AM

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

See all articles

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

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

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),

MinGW - Minimalist GNU for Windows

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.