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

时间:2012-06-25 12:02:18

标签: vim highlighting

当使用vim进行编程时,文件/缓冲区中的任何唯一单词很可能是一个拼写错误(以太变量名,方法名或语言结构)。因此,捕获这样的拼写错误是一种非常好的方法,能够突出文件中的任何独特单词,无需任何花哨的语言分析或解析,或者甚至不需要知道正在使用的编程语言。当然,最好在你输入时发生这种情况,这样你就可以立即看到你的拼写错误。不知怎的,我不是第一个想出这样一个想法的人,所以也许某人有这样的设置或有任何建议?

1 个答案:

答案 0 :(得分:2)

创意。

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

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

嗯,对我来说看起来并不是很有用(当评论被排除在外时也没有那么好),但也许你可以采取这些并改进它。