vim - 在 Vim 中,即使光标进入该行,如何保持字符隐藏

标签 vim syntax-highlighting

我这里可能有一个特殊的情况。我希望 gVim(Linux 中的 GUI 版本)无论如何都能隐藏隐藏的字符,即使光标位于该行或该字符被选择时也是如此。 (如果字符从未存在过,则应该尽可能接近。)当前,当光标进入该行时,隐藏的字符会自行显示,这会导致文本在滚动和选择文本时跳转。

我们使用 gView(只读 gVim)来查看日志,以便利用其强大的语法高亮功能。问题是,这些日志包含大量转义字符和 TTY 颜色代码,导致阅读困难。 (^[33mSomeText^[0m)

我使用这一行来隐藏它们:

syntax match Ignore /\%o33\[[0-9]\{0,5}m/ conceal

由于这些文件是由非 vim 专家查看的,因此当文本本身不隐藏时,它看起来会出现故障和损坏。 (如果颜色代码存在,也会看起来有问题和损坏,如果颜色代码被涂黑变得不可见,但在选择时仍然显示并在复制/粘贴后出现,也会看起来有问题和损坏。)

这应该没问题,因为这些文件在 gview 中以只读方式打开,并且额外的 set nomodabilible 使得保存文件变得更加困难。虽然可以编辑并尝试保存日志,但这样做被认为是无效的事情,也是无害的事情,并且需要足够的 Vim 技能,如果有人设法编辑文件,他们知道自己在做什么。能够编辑带有隐藏文本的行的问题不适用。

如果 'conceal' 无法配置为隐藏隐藏文本,则可接受的替代方案是在文件打开时用空格替换 TTY 颜色代码。但是,这必须在只读模式下完成,并且我们不能让 gview 在关闭窗口时弹出保存对话框,因为文件已被其 .vimrc 修改。

注意:我可以完全控制读取这些脚本时获取的 .vim 脚本文件,但无法控制 TTY 颜色代码或在 gview 中打开日志文件的代码的存在。 (即我无法通过 sed 或类似的东西传递它。)理想的解决方案是任何可以透明地从 .vimrc 中删除颜色代码的解决方案,但我会听到任何建议。 “隐藏” 功能是我最有希望的领先优势。

那么,有什么想法如何在文件 View 中永久删除这些内容,而不会在关闭时弹出对话框吗?

最佳答案

:帮助隐藏

When the "conceal" argument is given, the item is marked as concealable. Whether or not it is actually concealed depends on the value of the 'conceallevel' option. The 'concealcursor' option is used to decide whether concealable items in the current line are displayed unconcealed to be able to edit the line.

:帮助隐藏光标

Sets the modes in which text in the cursor line can also be concealed. When the current mode is listed then concealing happens just like in other lines.

  • n Normal mode
  • v Visual mode
  • i Insert mode
  • c Command line editing, for 'incsearch'

'v' applies to all lines in the Visual area, not only the cursor. A useful value is "nc". This is used in help files. So long as you are moving around text is concealed, but when starting to insert text or selecting a Visual area the concealed text is displayed, so that you can see what you are doing. Keep in mind that the cursor position is not always where it's displayed. E.g., when moving vertically it may change column.

另外,:help hidelevel

Determine how text with the "conceal" syntax attribute |:syn-conceal| is shown:

Value Effect ~

  • 0 Text is shown normally
  • 1 Each block of concealed text is replaced with one character. If the syntax item does not have a custom replacement character defined (see |:syn-cchar|) the character defined in 'listchars' is used (default is a space). It is highlighted with the "Conceal" highlight group.
  • 2 Concealed text is completely hidden unless it has a custom replacement character defined (see |:syn-cchar|).
  • 3 Concealed text is completely hidden.

关于vim - 在 Vim 中,即使光标进入该行,如何保持字符隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9604011/

相关文章:

ruby - 如何更轻松地编写 ruby​​ 代码?(我的意思是在终端中编写然后运行它)

vim - E518 : Unknown option: #

java - 如何使用 DocumentFilter 和样式修复 java swing jtextpane 中的自动换行奇怪行为?

python - 按名称配色方案参数pycharm

javascript - Highlight.js 为每个 <code> 标签使用特定的 css 文件

vim - 显示 Vim 命令选项

linux - 在 VIM 中不再弄乱空格

vim - vim中查找光标下的字符

xcode4 - 在 Prefix.pch 中包含 Constants.h 文件会破坏代码完成、语法突出显示

html - HAML 语法突出显示错位