开发者

How to get short option name from long option name in vim

开发者 https://www.devze.com 2023-01-18 09:06 出处:网络
I have a list of vim long option names as strings (e.g. [\"tabstop\",\"shiftwidth\"]). What would be the best way to convert it into a list containing only short names (e.g. [\"ts,\"sw\"]). What about

I have a list of vim long option names as strings (e.g. ["tabstop","shiftwidth"]). What would be the best way to convert it into a list containing only short names (e.g. ["ts,"sw"]). What about if the original list i开发者_Python百科s a mix of short and long names?


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

Result:

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

Happy vimming!


I don't believe there's a straightforward way to do this. My best suggestion is to use this little python script to generate a Vim hash:

#!/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\\ }'

Run it with python vimoptions.py > vimoptions.vim

Then open vim and :source vimoptions.vim. You can then do something like this to convert your list (assuming the list is a variable rather than text: edit as appropriate if this isn't true):

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

The python code is a bit flaky (it assumes a fairly rigid syntax in the options.c file). If I wanted this to be more robust and maintainable, I'd use the python C API to compile options.c into a python module and import the table into some python code for parsing. That may be a lot more hassle than you really need right now though.

0

精彩评论

暂无评论...
验证码 换一张
取 消