如何从vim中的长选项名称获取短选项名称

时间:2010-09-30 09:42:40

标签: vim

我有一个vim长选项名称列表作为字符串(例如[“tabstop”,“shiftwidth”])。将它转换为仅包含短名称的列表的最佳方式是什么(例如[“ts,”sw“])。如果原始列表是短名称和长名称的混合怎么办?

2 个答案:

答案 0 :(得分:9)

:help options.txt
:" retaining lines with a tag surrounded by quotes
:g/^\s*\(\*'\w\+'\*\s*\)\+$/y A
:winc n
"ap

结果:

aleph al aleph Aleph
allowrevins ari 
noallowrevins noari
altkeymap akm 
noaltkeymap noakm
ambiwidth ambw
antialias anti 
noantialias noanti
autochdir acd 
noautochdir noacd
arabic arab 
noarabic noarab
arabicshape arshape
noarabicshape noarshape
autoindent ai 
noautoindent noai
autoread ar 
noautoread noar
autowrite aw 
noautowrite noaw
autowriteall awa 
noautowriteall noawa
background bg
backspace bs
backup bk 
nobackup nobk
backupcopy bkc
backupdir bdir
backupext bex
backupskip bsk
balloondelay bdlay
ballooneval beval 
noballooneval nobeval
balloonexpr bexpr
binary bin 
nobinary nobin
bioskey biosk 
nobioskey nobiosk
bomb 
nobomb
breakat brk
browsedir bsdir
bufhidden bh
buflisted bl 
nobuflisted nobl
buftype bt
casemap cmp
cdpath cd
cedit
charconvert ccv
cindent cin 
nocindent nocin
cinkeys cink
cinoptions cino
cinwords cinw
clipboard cb
cmdheight ch
cmdwinheight cwh
columns co
comments com
commentstring cms
compatible cp 
nocompatible nocp
complete cpt
completefunc cfu
completeopt cot
concealcursor cocu
conceallevel cole
confirm cf 
noconfirm nocf
conskey consk 
noconskey noconsk
copyindent ci 
nocopyindent noci
cpoptions cpo
cryptmethod cm
cscopepathcomp cspc
cscopeprg csprg
cscopequickfix csqf
cscopetag cst 
nocscopetag nocst
cscopetagorder csto
cscopeverbose csverb
nocscopeverbose nocsverb
cursorbind crb 
nocursorbind nocrb
cursorcolumn cuc 
nocursorcolumn nocuc
cursorline cul 
nocursorline nocul
debug
define def
delcombine deco 
nodelcombine nodeco
dictionary dict
diff 
nodiff
dex diffexpr
dip diffopt
digraph dg 
nodigraph nodg
directory dir
display dy
eadirection ead
ed edcompatible 
noed noedcompatible
encoding enc
endofline eol 
noendofline noeol
equalalways ea 
noequalalways noea
equalprg ep
errorbells eb 
noerrorbells noeb
errorfile ef
errorformat efm
esckeys ek 
noesckeys noek
eventignore ei
expandtab et 
noexpandtab noet
exrc ex 
noexrc noex
fileencoding fenc
fe
fileencodings fencs
fileformat ff
fileformats ffs
filetype ft
fillchars fcs
fkmap fk 
nofkmap nofk
foldclose fcl
foldcolumn fdc
foldenable fen 
nofoldenable nofen
foldexpr fde
foldignore fdi
foldlevel fdl
foldlevelstart fdls
foldmarker fmr
foldmethod fdm
foldminlines fml
foldnestmax fdn
foldopen fdo
foldtext fdt
formatoptions fo
formatlistpat flp
formatprg fp
formatexpr fex
fsync fs
gdefault gd 
nogdefault nogd
grepformat gfm
grepprg gp
guicursor gcr
guifont gfn
guifontset gfs
guifontwide gfw
guiheadroom ghr
guioptions go
guipty 
noguipty
guitablabel gtl
guitabtooltip gtt
helpfile hf
helpheight hh
helplang hlg
hidden hid 
nohidden nohid
highlight hl
hlsearch hls 
nohlsearch nohls
history hi
hkmap hk 
nohkmap nohk
hkmapp hkp 
nohkmapp nohkp
icon 
noicon
iconstring
ignorecase ic 
noignorecase noic
imactivatekey imak
imcmdline imc 
noimcmdline noimc
imdisable imd 
noimdisable noimd
iminsert imi
imsearch ims
include inc
includeexpr inex
incsearch is 
noincsearch nois
indentexpr inde
indentkeys indk
infercase inf 
noinfercase noinf
insertmode im 
noinsertmode noim
isfname isf
isident isi
iskeyword isk
isprint isp
joinspaces js 
nojoinspaces nojs
key
keymap kmp
keymodel km
keywordprg kp
langmap lmap
langmenu lm
laststatus ls
lazyredraw lz 
nolazyredraw nolz
linebreak lbr 
nolinebreak nolbr
lines
linespace lsp
lisp 
nolisp
lispwords lw
list 
nolist
listchars lcs
lpl 
nolpl loadplugins noloadplugins
macatsui 
nomacatsui
magic 
nomagic
makeef mef
makeprg mp
colorcolumn cc
matchpairs mps
matchtime mat
maxcombine mco
maxfuncdepth mfd
maxmapdepth mmd
maxmem mm
maxmempattern mmp
maxmemtot mmt
menuitems mis
mkspellmem msm
modeline ml 
nomodeline noml
modelines mls
modifiable ma 
nomodifiable noma
modified mod 
nomodified nomod
more 
nomore
mouse
mousefocus mousef 
nomousefocus nomousef
mousehide mh 
nomousehide nomh
mousemodel mousem
mouseshape mouses
mousetime mouset
mzquantum mzq
nrformats nf
number nu 
nonumber nonu
numberwidth nuw
omnifunc ofu
opendevice odev 
noopendevice noodev
operatorfunc opfunc
osfiletype oft
paragraphs para
paste 
nopaste
pastetoggle pt
pex patchexpr
patchmode pm
path pa
preserveindent pi 
nopreserveindent nopi
previewheight pvh
previewwindow 
nopreviewwindow
pvw 
nopvw
printdevice pdev
printencoding penc
printexpr pexpr
printfont pfn
printheader pheader
printmbcharset pmbcs
printmbfont pmbfn
printoptions popt
prompt 
noprompt
pumheight ph
quoteescape qe
readonly ro 
noreadonly noro
redrawtime rdt
relativenumber rnu 
norelativenumber nornu
remap 
noremap
report
restorescreen rs 
norestorescreen nors
revins ri 
norevins nori
rightleft rl 
norightleft norl
rightleftcmd rlc
ruler ru 
noruler noru
rulerformat ruf
runtimepath rtp vimfiles
scroll scr
scrollbind scb 
noscrollbind noscb
scrolljump sj
scrolloff so
scrollopt sbo
sections sect
secure 
nosecure
selection sel
selectmode slm
sessionoptions ssop
shell sh
shellcmdflag shcf
shellpipe sp
shellquote shq
shellredir srr
shellslash ssl 
noshellslash nossl
shelltemp stmp 
noshelltemp nostmp
shelltype st
shellxquote sxq
shiftround sr 
noshiftround nosr
shiftwidth sw
shortmess shm
shortname sn 
noshortname nosn
showbreak sbr
showcmd sc 
noshowcmd nosc
showfulltag sft 
noshowfulltag nosft
showmatch sm 
noshowmatch nosm
showmode smd 
noshowmode nosmd
showtabline stal
sidescroll ss
sidescrolloff siso
smartcase scs 
nosmartcase noscs
smartindent si 
nosmartindent nosi
smarttab sta 
nosmarttab nosta
softtabstop sts
spell 
nospell
spellcapcheck spc
spellfile spf
spelllang spl
spellsuggest sps
splitbelow sb 
nosplitbelow nosb
splitright spr 
nosplitright nospr
startofline sol 
nostartofline nosol
statusline stl
suffixes su
suffixesadd sua
swapfile swf 
noswapfile noswf
swapsync sws
switchbuf swb
synmaxcol smc
syntax syn
tabline tal
tabpagemax tpm
tabstop ts
tagbsearch tbs 
notagbsearch notbs
taglength tl
tagrelative tr 
notagrelative notr
tags tag
tagstack tgst 
notagstack notgst
term
termbidi tbidi
notermbidi notbidi
termencoding tenc
terse 
noterse
textauto ta 
notextauto nota
textmode tx 
notextmode notx
textwidth tw
thesaurus tsr
tildeop top 
notildeop notop
timeout to 
notimeout noto
ttimeout 
nottimeout
timeoutlen tm
ttimeoutlen ttm
title 
notitle
titlelen
titleold
titlestring
toolbar tb
toolbariconsize tbis
ttybuiltin tbi 
nottybuiltin notbi
ttyfast tf 
nottyfast notf
ttymouse ttym
ttyscroll tsl
ttytype tty
undodir udir
undofile udf
undolevels ul
undoreload ur
updatecount uc
updatetime ut
verbose vbs
verbosefile vfile
viewdir vdir
viewoptions vop
viminfo vi
virtualedit ve
visualbell vb 
novisualbell novb beep
warn 
nowarn
weirdinvert wiv 
noweirdinvert nowiv
whichwrap ww
wildchar wc
wildcharm wcm
wildignore wig
wildmenu wmnu 
nowildmenu nowmnu
wildmode wim
wildoptions wop
winaltkeys wak
window wi
winheight wh
winfixheight wfh 
nowinfixheight nowfh
winfixwidth wfw 
nowinfixwidth nowfw
winminheight wmh
winminwidth wmw
winwidth wiw
wrap 
nowrap
wrapmargin wm
wrapscan ws 
nowrapscan nows
write 
nowrite
writeany wa 
nowriteany nowa
writebackup wb 
nowritebackup nowb
writedelay wd

快乐的vimming!

答案 1 :(得分:3)

我不相信有这么简单的方法。我最好的建议是使用这个小python脚本生成一个Vim哈希:

#!/usr/bin/python
# Assumes the vim source code is available in ./vim_src
# save this as vimoptions.py
import re
import os
vim_src_dir = './vim_src'
matcher = re.compile(r'^\s*{"(?P<longname>[^"]+)",\s*"(?P<shortname>[^"]+)",')
fh = open(os.path.join(vim_src_dir, 'src/option.c')
option_dict = {}
for line in fh:
    m = matcher.match(line)
    if m is not None:
        option_dict[m.group('longname')] = m.group('shortname')
fh.close()
print "let option_dict = {"
for key, value in option_dict.iteritems():
    print '\t\t\t\\ "%s": "%s",' % (key, value)
print '\t\t\t\\ }'

使用python vimoptions.py > vimoptions.vim

运行它

然后打开vim和:source vimoptions.vim。然后你可以做这样的事情来转换你的列表(假设列表是一个变量而不是文本:如果不是这样,则适当地编辑):

for index in range(len(optlist))
    if has_key(option_dict, optlist[index])
        let optlist[index] = option_dict[optlist[index]]
    endif
endfor

python代码有点不稳定(它假设options.c文件中的语法相当严格)。如果我希望它更健壮和可维护,我将使用python C API将options.c编译到python模块中,并将表导入一些python代码进行解析。这可能比你现在真正需要的麻烦更多。