Home System Tutorial LINUX Vim Text Editor Getting Started Guide

Vim Text Editor Getting Started Guide

Jan 02, 2024 pm 04:58 PM
linux linux tutorial Red Hat linux system linux command linux certification red hat linux linux video

Vim 文本编辑器 入门指南

For a programmer, choosing a text editor is a very important thing. Because there are many differences between different editors: graphical interface or non-graphical interface, different shortcut keys, different programming language support, different plug-ins and custom settings, etc. My advice is not to search for the best editor, but to choose the one that best suits your habits and best suits your tasks. If you plan to work in a group, it's best to choose the same editor as your colleagues. This way, if you encounter problems during use, you can go to them for help.

This is exactly why I started using Vim a few years ago. Generally speaking, Vim is placed in opposition to the legendary Emacs. I admit I know very little about Emacs, but what you need to know about both is that they are both deeply customizable and can be very confusing at first. This tutorial won't cover everything there is to know about Vim, but it will cover the basics so you can get it right from the start, and then show you some tips that will (hopefully) give you the ability to explore on your own. study.

The word Vim comes from "Vi IMproved". Vi is a non-graphical text editor widely installed on Unix systems, and it is also installed by default on Linux systems. Vim is an enhanced version of this original editor, but unlike Vi, not every distribution has it installed by default.

Install

You can use the following command to install Vim in Ubuntu:

sudo apt-get install vim
Copy after login

If you are already interested in certain plug-ins, use the following command:

sudo apt-cache search vim
Copy after login

This command will output you a long list of packages related to Vim. Among these, there are tools for different programming languages, plug-in managers, and so on.

In this series of tutorials, I will use the latest version of Vim (7.3.154, LCTT Annotation: the latest version is now 8.0) on Ubuntu. Of course you can use any other version.

warm up

Enter the vim command in the terminal, and you will see a great welcome interface.

Vim 文本编辑器 入门指南

(LCTT translation annotation: Did you see the line "Help poor children in Uganda!" in the welcome interface?)

If you've never used Vi or Vim before, chances are you don't even know how to exit it... Yes, that's true. Any shortcut keys you commonly use in Vim will lose their original effects. (LCTT translation annotation: There is a joke circulating on the Internet - "How to create garbled code" and "Let novices exit vi")

First, use any imperative function like Save () or Exit ( ), you must first enter a colon (:). Saving is :w and exiting is :q. If you want to exit without saving the file, use the force exit command :q!. The great thing about Vim is that you don't need to enter each command separately. In other words, if you want to save and exit, you can just use :wq.

Now, we exit Vim and open a text file. To do this, just add the name of the file you want to edit after the command:

vim [文本文件名]
Copy after login

Vim 文本编辑器 入门指南

Generally speaking, when you open a text file, you will be in view mode. This makes Vim unique and initially confusing. Vim mainly consists of two modes: viewing mode and editing mode. View mode is used to view content and use some commands. To enter edit mode, just press the i key to insert () or the a key to Add to(). To return to view mode or perform command function operations, press the Escape key. The difference between inserting () and adding () is just that you want Enter edit mode and enter text before or after the cursor position. To fully understand, you should try it yourself. My suggestion: use to add () only at the end of the line, and to insert (## at other times #).

(LCTT Translation: The original text of "view mode" in this paragraph is "visual mode", which is suspected to be "view mode". In this mode, text can be viewed but cannot be edited; while "visual mode" is editing mode. One, you can press the

v key to enter, and then you can use the direction keys to select starting from the current cursor position, and it will be displayed with a reversed visual effect. Normally, you can press y after selection. Copy, press d to cut, etc. In addition, the author's terminology is not standard. According to Vim's own terminology, the so-called "view mode" here should be called "normal mode" ", "Edit mode" should be called "Insert mode", but the meaning is the same.)

To move the cursor within text, you can usually use the arrow keys on the keyboard, which work in both view mode and edit mode. However, a true purist will tell you to use the keys

h for left, j for down, k for up, and i for Come right (in view mode) to move.

Now that you understand how to control Vim simply, let's go a little deeper.

Some simple commands Now that you are familiar with switching between normal mode and insert mode, here are some commands you can use in normal mode:

  • x: Delete a character
  • u: Undo an operation (equivalent to Ctrl z)
  • dd: Delete a line of content
  • dw: Delete a word
  • yy: Copy a line of content
  • yw: Copy a word
  • p: Paste a previously deleted or copied line or word
  • e: Jump to the next word (LCTT translation annotation: end of word) (faster than simply using the arrow keys)
  • r: Replace a letter (press r, release, then press new letter)

Of course there is more than this, but these are enough for now. If you master all of the above, you will be able to use Vim smoothly.

For those who want to know more, I will mention a few more. You can add a value before any of these commands and the command will be repeated the corresponding number of times. For example, 5x will delete 5 consecutive letters on the current line, while 3p will paste 3 times.

Advanced commands

Finally, as an encouragement and example for you to continue exploring, here are several advanced and commonly used commands:

  • /Searched content: Search for specific content in the text
  • :sp text file name: Split the screen into upper and lower halves horizontally, and the new file is displayed in the other half. If you want to switch focus on both sides, you can use the Ctrl w ​​shortcut key.
    Vim 文本编辑器 入门指南
  • :vsp text file name: Same as above, but split the screen vertically
  • Ctrl Shift C and Ctrl Shift V: Copy and paste text in Terminal
  • :! Command name: Run terminal commands outside Vim in Vim and send them directly to the shell. For example, :! ls will display the files in your current directory without exiting the editor.
    Vim 文本编辑器 入门指南
in conclusion

I think you should be ready enough to start using Vim now. You can also use interactive tutorials to learn more by installing various plugins, editing the ~.vimrc file, or entering the vimtutor command in the shell.

If you have any other Vim commands you’d like to share, please let us know in the comments.


The above is the detailed content of Vim Text Editor Getting Started Guide. 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)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 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.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

See all articles