2012-06-25 52 views
4

當使用vim編寫文件/緩衝區中的任何唯一字時,很可能是打印錯誤(以太網變量名稱,方法名稱或語言結構)。因此,如果能夠突出顯示文件中的任何獨特單詞,而不需要任何花哨的語言分析或解析,或者甚至不需要知道正在使用什麼編程語言,這將是一種非常好的方式來捕獲此類拼寫錯誤。當然,鍵入內容會發生這種情況,以便您可以立即看到您的拼寫錯誤。不知何故,我不是我第一個想出這樣的想法,所以也許有人有這樣的設置或有任何建議?VIM突出顯示緩衝區中的唯一字?

+0

我覺得這樣會對眼睛造成壓力。你看過[ctags](http://ctags.sourceforge.net/ctags.html)還是使用linter? (例如,[pflakes](https://github.com/kevinw/pyflakes-vim)將突出顯示/下劃線代碼中不存在的變量)。 –

+2

也許,你是第一個想出這樣一個想法的人。 :) – kev

+0

我不認爲它會有壓力,因爲源代碼幾乎總是有大多數單詞重複不止一次,至少對於大型文件。 – morphles

回答

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 /自動加載/ vimball.vim(23.2 K銼與737線),我得到以下單個關鍵詞事件:

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 

嗯,看起來不是很對我有用(它也不會得到更好的意見時除外),但也許你可以藉此和改進它。