これらの2つのコマンドは、マッピングでうまく動作するので、関数で動作するようにするにはどうすればよいですか?vimscript:マッピングでは機能するが、機能では動作しないコマンド
:if has_key(glos,@g)==1<cr>:let @j=eval('glos.'[email protected])<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 '[email protected]' &'
pkill display
@i
elseif @c==toupper(@c)
let @n=search('^'[email protected],'sw')
elseif @[email protected]
let @f=3
let @g=tolower(@c)
while @f>0
try
let @j=eval('glos.'[email protected])
catch
let @[email protected]
let @g=strpart(@g,0,strlen(@g)-1)
continue
endtry
break
endwh
if @f>0
let @h=substitute(@j," glosimgs.*",'','')
if @[email protected]
let @i='!xv -geometry +0+380 '.substitute(@j,'^.\{-}\(glosimgs.*\)$','\1','').' &'
!pkill xv
@i
endif
echo @h
else
echo 'No matching entry for '[email protected]
endif
elseif @c=~'\u\l\+$'
let @n=search('^'[email protected],'sw')
elseif @c=~'\l\+$'
norm *
elseif @c=~'^_\w\+$'
let @/='^'[email protected]'$'
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 '[email protected]' &'<cr>:pkill display<cr>:@i<cr>:elseif @c==toupper(@c)<cr>:let @n=search('^'[email protected],'sw')<cr>:elseif @[email protected]<cr>:let @f=3<cr>:let @g=tolower(@c)<cr>:while @f>0<cr>:try<cr>:let @j=eval('glos["'[email protected]'"]')<cr>:catch<cr>:let @[email protected]<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 @[email protected]<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 '[email protected]<cr>:endif<cr>:elseif @c=~'\u\l\+$'<cr>:let @n=search('^'[email protected],'sw')<cr>:elseif @c=~'\l\+$'<cr>:norm *<cr>:elseif @c=~'^_\w\+$'<cr>:let @/='^'[email protected]'$'<cr>:norm nzz<cr>:endif<cr>
マッピングを投稿できますか?そのフラグメントは有効な式ではありません。あなたのマッピングがどのように機能するのかよく分かりません。 (もしそうなら) – FDinoff
ああ、私...申し訳ありませんが、私はここですべてを解釈したくありません。最初のステップとして、レジスタの代わりに実際の変数を使うのに役立つでしょう。 '@ [a-z]はあなたの関数が一般的に上書きしてはならないレジスタです。変数の仕組みを理解するには、 ':help internal-variables'を読んでみてください。 (記述的な変数名は良いことです)あなたのマッピングに関して、私はそれが実際に動作するとは思わない。私は末尾の文字エラーを取得します。 – FDinoff
心配しないでください。私のマッピングがうまくいくが、あなたにエラーが出るなら、私たちの設定は違う。これはvimでの繰り返しの問題です(なぜ、balky関数を実行するために非常に多くのメソッドを必要とするのですか?exe呼び出しとレジスタにロードしてコマンドとして使用する)、私は最も簡単なオプションは長いマッピングを1行の形式で1つのコマンドに書き戻し、メンテナンス/デバッグのために読みやすいようにマッピングを書き戻します。あなたの助けをありがとう – user985675