突出显示VIM中的任意行 [英] Highlighting arbitrary lines in VIM

查看:68
本文介绍了突出显示VIM中的任意行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在程序的实施过程中,我通常会插入许多附加代码行,主要是使用print命令,以帮助我理解和调试已实施的程序.不幸的是,我通常会忘记代码中的哪些行以及这些行是附加的,并应在一段时间后删除.对于大型程序,此问题变得最严重.

During the implementation process of a program I generally insert many append code lines, mainly with print command, to help me understand and debug the implemented program. Unfortunately, it is common to me to forget which lines are from the code and with were appended and should be deleted some time after. This problem gets worst with large programs.

好吧,我发现了这个文章,该文章教导了如何使一个任意用户选择的行保持突出显示(请参阅部分:光标移动后仍保留的突出显示).本文提供的解决方案是在.vimrc中包含以下代码:

Well, I found this article that teaches how to keep one arbitrary user selected line highlighted (see section: Highlighting that stays after cursor moves). The solution given by the article is to include in .vimrc the following code:

:nnoremap <silent> <Leader>l ml:execute 'match Search /\%'.line('.').'l/'<CR>

因此,每当我按 \ l 时,当前行都会突出显示并保持不变,而前一个突出显示的行(如果有的话)将不突出显示.

So, every time when I press \l the current line is highlighted and kept so, and the previous highlighted line, if there are one, is unhighlighted.

这不是我想要的行为.相反,我希望能够突出显示任意多的行,而不会取消突出显示先前突出显示的行.如果可能的话,请使用 \ l 这样的独特命令.

This isn't the behavior that I would like. Instead, I would like to be able to highlight as many arbitrary lines as I want without unhighlighting the previous highlighted lines. And if it is possible, with a unique command like \l.

有人知道解决方案吗?

谢谢.

已编辑:

yolenoyer 提出的命令解决了最初的问题.但是,现在又出现了其他问题.以下命令:

The command proposed by yolenoyer solved the initial problem. But, now other problem raised. The following command:

:call clearmatches()

提议清除突出显示的行的

会清除所有行,我希望能够清除特定突出显示的行,而不是一次清除所有行.有可能吗?

proposed to clean the highlighted lines cleans all lines and I would like to be able to clean specific highlighted lines, instead off all of them at once. Is it possible?

推荐答案

我在C语言中进行了大量编程,并且在调试时倾向于在调试打印中添加代码.

I program in C quite alot, and when debugging tend to pepper the code with debug prints.

我使用vim命令

:syntax match Error /\<debug_printf\>/

以确保单词"debug_printf"以特定颜色方案的默认错误"颜色突出显示.

to ensure the word 'debug_printf' is highlighted in the default 'Error' colors for the particular colorscheme.

这不能帮助您为一系列行添加书签,但是为此,您应该签出书签"插件,该插件可让您在整个文件中创建和删除书签.

This doesn't help you bookmarking a series of lines, but for that you should check out the 'bookmark' plugin which allows you to create and remove bookmarks throughout the file.

VIM书签插件

这篇关于突出显示VIM中的任意行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆