如何重写这两个命令,这些命令在映射中工作正常,以便它们可以在函数中工作?
:if has_key(glos,@g)==1<cr>:let @j=eval('glos.'.@g)<cr>
有关的函数由vim执行而没有注释,但@j保持不变,就好像它们已经失败,但没有生成消息/错误。
以下是涉及的完整代码,加载字典的命令,不起作用的函数以及来自该函数的映射。
" read the glossary into the dictionary, glos
let glos=eval(join(readfile("glossary.dict")))
" 2click item of interest and this will
" send image filepath to xv
" if item all-caps find same at start of its line
" If capitalized at eol find same at start of its line
" if all lower-case at eol find next occurrence of same
" look lower-case or capitalized word up in glossary.txt
" find _\d\+ (page no.) alone on its line in text
com! F call F()
function! F()
normal "ayiw"cyE"by$
let @c=substitute(@c,"[,.?':;!]\+","","g")
if @c=~'images\/ss\d\d\d*'
let @i='!display -geometry +0+0 '.@c.' &'
pkill display
@i
elseif @c==toupper(@c)
let @n=search('^'.@c,'sw')
elseif @c!=@b
let @f=3
let @g=tolower(@c)
while @f>0
try
let @j=eval('glos.'.@g)
catch
let @f=@f-1
let @g=strpart(@g,0,strlen(@g)-1)
continue
endtry
break
endwh
if @f>0
let @h=substitute(@j," glosimgs.*",'','')
if @h!=@j
let @i='!xv -geometry +0+380 '.substitute(@j,'^.\{-}\( glosimgs.*\)$','\1','').' &'
!pkill xv
@i
endif
echo @h
else
echo 'No matching entry for '.@c
endif
elseif @c=~'\u\l\+$'
let @n=search('^'.@c,'sw')
elseif @c=~'\l\+$'
norm *
elseif @c=~'^_\w\+$'
let @/='^'.@c.'$'
norm nzz
endif
endfunction
map <silent> <2-LeftMouse> "ayiw"cyE"by$:let @c=substitute(@c,"[,.?':;!]\+","","g")<cr>:if @c=~'images\/ss\d\d\d*'<cr>:let @i='!display -geometry +0+0 '.@c.' &'<cr>:pkill display<cr>:@i<cr>:elseif @c==toupper(@c)<cr>:let @n=search('^'.@c,'sw')<cr>:elseif @c!=@b<cr>:let @f=3<cr>:let @g=tolower(@c)<cr>:while @f>0<cr>:try<cr>:let @j=eval('glos["'.@g.'"]')<cr>:catch<cr>:let @f=@f-1<cr>:let @g=strpart(@g,0,strlen(@g)-1)<cr>:continue<cr>:endtry<cr>:break<cr>:endwh<cr>:if @f>0<cr>:let @h=substitute(@j," glosimgs.*",'','')<cr>:if @h!=@j<cr>:let @i='!xv -geometry +0+380 '.substitute(@j,'^.\{-}\( glosimgs.*\)$','\1','').' &'<cr>:!pkill xv<cr>:@i<cr>:endif<cr><cr<cr>>:echo @h<cr>:else<cr>:echo 'No matching entry for '.@c<cr>:endif<cr>:elseif @c=~'\u\l\+$'<cr>:let @n=search('^'.@c,'sw')<cr>:elseif @c=~'\l\+$'<cr>:norm *<cr>:elseif @c=~'^_\w\+$'<cr>:let @/='^'.@c.'$'<cr>:norm nzz<cr>:endif<cr>
答案 0 :(得分:0)
具体来说,我应该写:
:if has_key(** g:** glos,@ g)== 1:让@ j = eval(&#39; ** g:** glos。&#39;。@ g)
:h g:直接了解问题的核心;在函数中,所有引用都是该函数的本地引用,因此对函数外部的任何变量的引用必须是全局的,前提是&#39; g:&#39;到变量名。当我创建独立于函数的字典时,函数必须将其作为全局项引用。
当然,如果你不知道&#39; g,&#39;很难找到帮助参考,但这是使用帮助的常见问题。
当然,围绕g:不是必需的**,显然是这个网站给你的东西代替粗体文字。