A text or source code editor based on a graphical interface, providing some functions such as text selection. What I'm trying to say is that probably most people don't think this is a feature. But this is not the case with command line-based editors like Vim. When you use Vim only with the keyboard, you need to learn specific commands to select the text you want. In this tutorial, we will discuss in detail the functionality of text selection and the flags functionality in Vim.
Before this, it should be noted that the examples, commands and instructions mentioned in this tutorial were all tested in the Ubuntu 16.04 environment. Vim version is 7.4.
Vim’s text selection function
We assume that you already have basic knowledge of the Vim editor (if not, you can read: https://www.jb51.net/os/Ubuntu/547230.html). You should know that the d command can cut/delete a line of content. If you want to cut 3 lines, repeat the command 3 times. But what if 15 lines need to be cut? Is repeating the d command 15 times a practical solution?
Obviously not. The best approach in this case is to select the lines you want to cut/delete and then run the d command. for example:
Suppose I want to cut/delete the first paragraph of the INTRODUCTION section in the screenshot below:
Then what I do is: put the cursor at the beginning of the first line, (make sure you exit the Insert mode) and press the V (ie Shift v) command. At this time, Vim will open view mode and select the first line.
Now, I can use the arrow key "Down" to select the entire paragraph.
This is what we want, right! Now just press the d key to cut/delete the selected paragraph. Of course, you can do anything to the selected text except cut/delete.
This brings us to another important question: what should we do when we don’t need to delete the entire row? In other words, the solution we just discussed is only suitable for situations where you want to operate on the entire row. So what if we only want to delete the first three sentences of the paragraph?
In fact, there is a corresponding command - just use lowercase v instead of uppercase V. In the example below, I use v to select the first three sentences of the paragraph:
Sometimes, the data you need to process consists of separate columns, and your need may be to select a specific column. Consider the following screenshot:
Suppose we only need to select the second column of text, which is the name of the country. In this case, you can place the cursor on the first letter of the column and press Ctrl v once. Then, press the "Down" arrow key to select the first letter of each country's name:
Then press the "right" arrow key to select this column.
Tips: If you selected a text block before and now want to reselect that text block, just press gv in command mode.
Use flags
Sometimes, when you are working on a large file (such as a source code file or a shell script), you may want to switch to a specific location and then return to the same line. This isn't a problem if the two rows are not far apart, or if you don't do this kind of thing very often.
However, if you need to frequently switch between the current position and some further rows, then the best way is to use flags. You only need to mark the current position, and then you can return to the current position from any position in the file through the mark name.
In Vim, we use the m command followed by a letter to mark a line (the letter represents the flag name, lowercase a - z can be used). For example ma. You can then use the command 'a (including the single quote on the left) to go back to the line marked with a.
Tips: You can use "single quote" ' to jump to the first character of the flag line, or use "backtick" ` to jump to a specific column of the flag line.
Vim’s flag function has many other uses. For example, you can mark a line first, then move the cursor to other lines and run the following command:
d'[logo name]
to delete everything between the current position and the flag line.
In the official Vim documentation, there is an important content:
Each file has some flags defined by lowercase letters (a-z). In addition, there are global flags defined by uppercase letters (A-Z) that define a location in a specific file. For example, you might be editing ten files at the same time. Each file can have the flag a, but only one file can have the flag a.
We've discussed the basic use of lowercase letters for Vim logos, and how convenient they are. The following excerpt explains it clearly enough:
Due to various limitations, the uppercase letter logo may not be as useful as the lowercase letter logo at first glance, but it can be used as a quick file bookmark. For example, open a .vimrc file, press mV, and exit. Next time you want to edit the .vimrc file, press 'V to open it.
Finally, we use the delmarks command to delete marks. For example:
:delmarks a
This command will remove a flag from the file. Of course, you can also delete the line where the flag is located, so that the flag will be automatically deleted.
Summarize
When you start using Vim as your preferred editor, features like the ones mentioned in this tutorial will be very useful tools and can save a lot of time. You have to admit, the text selection and marking features described here require almost no learning, just a little practice.
The above is the detailed content of How to use markers for text selection in the Vim editor. For more information, please follow other related articles on the PHP Chinese website!

如何在iPad键盘上将CapsLock重新映射为ESC准备好让CapsLock成为iPad上的ESC键了吗?这是您需要做的所有事情:在iPad上打开“设置”应用转到“常规”,然后转到“键盘”转到“硬件键盘”选择“修改键”选择“CapsLockKey”并选择“Escape”作为修饰键现在您已准备好通过按CapsLock在iPad上试用新的硬件ESC键。转到任何使用Escape键的应用程序,您可以立即对其进行测试,例如vi/vim。现在您可以使用物理键盘从

删除偶数行的方法如下::g/^/+1d上面用到了:gbobal命令,gbobal命令格式如下::[range]global/{pattern}/{command}global命令实际上是分成两步执行:首先扫描[range]指定范围内的所有行,给匹配{pattern}的行打上标记;然后依次对打有标记的行执行{command}命令,如果被标记的行在对之前匹配行的命令操作中被删除、移动或合并,则其标记自动消失,而不对该行执行{command}命令。{command}可以是一个ex命令,也可以是用|分隔

在 PHP 开发中,使用 Vim 是非常普遍的。然而,在 Alpine Linux 中安装 Vim 可能会遇到一些问题。本篇文章将分享如何在 Alpine Linux 上安装 Vim。

前言vim是个强大的文本编辑的工具,在Linux端得到极大的使用热度。最近在另外一台服务器上使用vim时,遇到了一个奇怪的问题:当我将本地编写好的脚本复制并粘贴到服务器中的空白文件时,出现了自动缩进的情况。用个简单的例子来说,就是我在本地写的脚本如下:aaabbbcccddd当我将上述内容复制后,粘贴到服务器中的空白文件后得到的却是:aabbbcccddd很明显,这是vim给我们自动进行了格式缩进。但是,这个自动有点不智能。这里记录下解决方案。解决方案:设置.vimrc配置文件我们在家目录下,新

在CentOS操作系统中,smbclient和vim是两个非常常用的工具,smbclient是一个用于与SMB/CIFS服务器进行通信的客户端工具,而vim是一款强大的文本编辑器,本文将详细介绍如何在CentOS上安装smbclient和vim,并提供一些相关的使用技巧。1.打开终端并以root用户身份登录。2.运行以下命令以更新系统软件包列表:```yumupdate3.运行以下命令以安装smbclient:yuminstallsmbclient4.系统将提示您确认安装,按下y键并按下回车键以

Vim分屏功能是通过分割窗口来实现的,这是提高工作效率的一大利器。无论我们想同时显示两个文件,或者同时显示一个文件的两个不同的位置,又或者并排比较两个文件,等等,这些都能通过分屏来实现,这样子很方便代码的比对和复制粘贴。

CentOS用vim/vi给文件加密和解密一、利用vim/vi加密:优点:加密后,如果不知道密码,就看不到明文,包括root用户也看不了;缺点:很明显让别人知道加密了,容易让别人把加密的文件破坏掉,包括内容破坏和删除;vi编辑器相信大家都很熟悉了吧,vi里有一个命令是给文件加密的,举个例子吧:1)首先在root主目录/root/下建立一个实验文件text.txt:[root@www~]#vim/vitext.txt2)进到编辑模式,输入完内容后按ESC,然后输入:X(注意是大写的X),回车;3)


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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

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