Vim 系列 (一) Using Marks in Vim

Guide

Vim's motion commands are very flexible and work well for general use. You can go to the beginning of a line, replace a word, or change a sentence. What about things that are semantically relevant to your files, like an important or buggy function definition, the point of entry for your application, or a stack you're trying to trace? For these, you can use marks (read as: "bookmarks"). These are "save points" in your files that you can set, jump between, and even use with commands.

Vim 的运动命令非常灵活,适用于一般用途。您可以转到行首、替换单词或更改句子。如果内容与文件相关,例如重要或错误的函数定义、应用程序的入口点或尝试跟踪的堆栈,该怎么办?对于这些,您可以使用标记(读作:"书签")。这些是文件中的"保存点",您可以设置、在它们之间跳转,甚至与命令一起使用。

Local and Global Marks 本地和全球商标

A local mark is specific to a particular file and is indicated by a lowercase letter, while global marks are universal across all of your files and use uppercase letters. That is, many files can have an a`` mark, while A`` points to a particular location in one particular file.

本地标记特定于特定文件,由小写字母表示,而全局标记在所有文件中都是通用的,并使用大写字母。也就是说,许多文件可以有一个 a`` 标记,同时 A`` 指向一个特定文件中的特定位置。

Viewing Marks 查看标记

View a list of your current marks with :marks. Note that marks are invisible in vim without the use of a (plug-in).

Setting Marks 设置标记

Set marks with m key in normal mode. To set a local mark of a where the cursor is, type ma. To jump to this location, type ```a`` anywhere in the file.

在正常模式下用 m 键设置标记。若要设置光标所在位置的 a 本地标记,请键入 ma 。若要跳转到此位置,请在文件中的任意位置键入 ```a`` 。

Deleting Marks 删除标记

You can delete marks with the :delm command. To delete marks a``, e, and ```G, you would type :delm aeG. You can delete all local marks with :delm!.

您可以使用该 :delm 命令删除标记。若要删除标记 a`` 、 e 和 ```G ,请键入 :delm aeG 。您可以使用 :delm! 删除所有本地标记。

Some tips 一些提示

  • Marks are motions, so you can use them with actions. For example, y`w will copy everything between your current cursor location and the w`` mark. 标记是动作,因此您可以将它们与动作一起使用。例如, ``y`w`` 将复制当前光标位置和 w`` 标记之间的所有内容。
  • will return you to the last place you jumped from 复制代码
    ```````` 将把你送回你最后跳下的地方
  • 0`` will return you to the last file you had open before you quit vim 0`` 将返回到退出 Vim 之前打开的最后一个文件
  • Using ' (single-quote) instead of (backtick) will jump you to the first non-blank character on the same line as the mark 使用 `'` (单引号) 而不是 (反引号) 会跳转到与标记同一行的第一个非空白字符
  • If set V`` to the top of your `.vimrc` file, you can jump to it from any file (saved between `vim` sessions by default) 如果设置为 V`` 文件顶部,则可以从任何 .vimrc 文件跳转到该文件(默认情况下在会话之间 vim 保存)
  • You can cycle through local marks with [``` / ] 您可以使用 ``[ / ``]``` 循环浏览本地标记
  • The kshenoy/vim-signature plug-in will add visual indications of marks to your line numbers, as well as giving you the ability to delete marks with dm[mark letter], assign the next available mark with m,, and more
    kshenoy/vim-signature 插件将为您的行号添加标记的视觉指示,并使您能够删除 dm[mark letter] 标记 ,使用 m, ,分配下一个可用标记 ,等等
相关推荐
tedcloud1232 分钟前
Awesome DSH Plugin 怎么用?给 DeepSeek Harness 搭建自己的插件生态
大数据·linux·服务器·人工智能·音视频
钓鱼的小小猫20 分钟前
从零拿捏Linux(一) ---- 命令(视频秒解)
linux·linux命令
明王明王37 分钟前
Ubuntu 26.04 使用 Windows Spotlight:给 Bing Wallpaper 加上 Spotlight 支持
linux·windows·ubuntu
夜月yeyue39 分钟前
SOME/IP 服务模型
linux·服务器·单片机·安全·车载系统
一直C1 小时前
【数据结构】哈希表+算法复杂度与经典排序查找(C语言)
java·linux·开发语言·数据结构·算法·ubuntu·散列表
λqaq72 小时前
MySQL 数据库基础(2)约束、用户权限、远程连接、外键与 TCP/UDP 理解
linux·数据库·python·tcp/ip·mysql
CedarQR2 小时前
云卓 G20 遥控器 Android 开发实录:从 USB 设备到读取摇杆/按键通道值
android·linux·无人机
lxw20230271162 小时前
k8s的pod管理
linux·容器·kubernetes
qetfw3 小时前
Debian Samba 与 OpenLDAP 统一认证配置
linux·debian
初願致夕霞3 小时前
《为什么公网访问不了内网?正向代理、内网穿透与 NAT 打洞一次说清》
linux·网络·tcp/ip·智能路由器