VIM突出显示缓冲区中的唯一单词?

标签 vim highlighting

当使用 vim 对文件/缓冲区中的任何唯一单词进行编程时,很可能是拼写错误(以太变量名称、方法名称或语言结构)。因此,通过突出显示文件中任何独特单词的能力来捕获此类拼写错误将是一种非常好的方法,而无需任何花哨的语言分析或解析,甚至不需要知道正在使用的编程语言。当然,最好在您键入时发生这种情况,以便您可以立即看到您的拼写错误。不知何故,我不认为我是第一个提出这样一个想法的人,所以也许有人有这样的设置或有什么建议?

最佳答案

创意。

我用这个 Vimscript 片段做了一些快速原型(prototype)设计:

let stat = {}
for ii in range(1, line('$'))
    for word in split(getline(ii), '\(\k\@!.\)\+')
        let stat[word] = get(stat, word, 0) + 1
    endfor
endfor
echo sort(keys(filter(copy(stat), 'v:val == 1')))

在 $VIM/vim73/autoload/vimball.vim (一个 737 行的 23.2 k 文件)上运行它,我得到以下单个关键字的出现:
12, 1502, 2004, 2009, 2010, 299, 31, 4, 702, Allow, Apr, At, Author,
AutoInstall, Constants, Copyright, Date, DechoTabOn, ENTER, Error,
Functions, GetLatestVimScripts, Input, LICENSE, Listing, Load, Modelines,
No, Normal, Once, Output, Own, Ph, Risk, Statement, Usage, Use, VIM,
Version, Vim, Windoze, Your, about, accomplished, actions, allow, already,
appear, appears, applies, apportion, assume, attempts, automatically, base,
based, bash, both, bypass, c, ch, change, construct, continue, copyright,
cp, cr, create, creates, cygwin, decompress, decompression, defined, did,
dir, distribute, does, doesn, embedded, enc, endfor, even, events,
evidence, except, existing, express, extraction, fmr, fo, force, function,
getpos, give, given, grab, ie, implied, included, index, initialize, input,
inputrestore, inputsave, insure, invoked, its, just, keep, keepcpo, list,
listing, loop, made, messages, missing, mkvimball, named, neither, next,
noacd, nofile, noma, nor, normal, noruler, noshowcmd, ok, older, on,
option, options, over, patch, pick, picked, placed, present, previous,
prologue, prompt, read, readable, redraw, removed, same, see, setpos,
setting, settings, shell, showing, skip, specified, specify, spite, split,
standard, string, strlen, sure, suspect, switch, ta, tab#, take, that,
title, true, un, undefined, under, used, v31, various, warning, warranty,
was, when, where, will, wrote, your, zsh

嗯,对我来说看起来不是很有用(排除评论时它也不会变得更好),但也许你可以接受并改进它。

关于VIM突出显示缓冲区中的唯一单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11188988/

相关文章:

linux - 为什么更改方法输入会导致 xmodmap 'caps to esc' 无效

linux - 将 Octave 4.0/4.2.1 中的默认编辑器设置为 Vim

java - 在 JavaFX TextArea 中突出显示字符串

css - 在 knockout validation 错误或成功时添加或删除元素

Vim:不同模式下不同的行号颜色

editor - 如何理解这个vim脚本?

linux - Vim:将所有注释移至文件顶部

newline - vim 注释换行意外行为

javascript - 定期检测 HTML 元素内的特定字符串