search
HomeSystem TutorialLINUXVim Text Editor Getting Started Guide
Vim Text Editor Getting Started GuideJan 02, 2024 pm 04:58 PM
linuxlinux tutorialRed Hatlinux systemlinux commandlinux certificationred hat linuxlinux 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

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

sudo apt-cache search vim

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 [文本文件名]

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
This article is reproduced at:Linux就该这么学. If there is any infringement, please contact admin@php.cn delete
什么是linux设备节点什么是linux设备节点Apr 18, 2022 pm 08:10 PM

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

Linux中open和fopen的区别有哪些Linux中open和fopen的区别有哪些Apr 29, 2022 pm 06:57 PM

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

linux中什么叫端口映射linux中什么叫端口映射May 09, 2022 pm 01:49 PM

端口映射又称端口转发,是指将外部主机的IP地址的端口映射到Intranet中的一台计算机,当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上;可以通过使用动态或固定的公共网络IP路由ADSL宽带路由器来实现。

什么是linux交叉编译什么是linux交叉编译Apr 29, 2022 pm 06:47 PM

在linux中,交叉编译是指在一个平台上生成另一个平台上的可执行代码,即编译源代码的平台和执行源代码编译后程序的平台是两个不同的平台。使用交叉编译的原因:1、目标系统没有能力在其上进行本地编译;2、有能力进行源代码编译的平台与目标平台不同。

linux中eof是什么linux中eof是什么May 07, 2022 pm 04:26 PM

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

linux怎么判断pcre是否安装linux怎么判断pcre是否安装May 09, 2022 pm 04:14 PM

在linux中,可以利用“rpm -qa pcre”命令判断pcre是否安装;rpm命令专门用于管理各项套件,使用该命令后,若结果中出现pcre的版本信息,则表示pcre已经安装,若没有出现版本信息,则表示没有安装pcre。

linux怎么查询mac地址linux怎么查询mac地址Apr 24, 2022 pm 08:01 PM

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。

linux中rpc是什么意思linux中rpc是什么意思May 07, 2022 pm 04:48 PM

在linux中,rpc是远程过程调用的意思,是Reomote Procedure Call的缩写,特指一种隐藏了过程调用时实际通信细节的IPC方法;linux中通过RPC可以充分利用非共享内存的多处理器环境,提高系统资源的利用率。

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

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.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment