如何将 Vim 函数参数传递给命令?
How to pass Vim function argument to a command?
我正在使用以下函数 + 命令在 Vim 中调用调试器:
function! TermDebugArm(executable)
packadd termdebug
let g:termdebugger="arm-none-eabi-gdb"
Termdebug a:executable
endfunction
command! -complete=file -nargs=1 TermDebugArm :call TermDebugArm(<f-args>)
不幸的是,Termdebug
命令得到的是文字参数“a:executable”,而不是它应该表示的实际值(即传递给调用该函数的命令的文件名)。
我做错了什么?
您需要使用 :execute
命令从字符串构建命令,这将允许您使用 a:executable
的值作为文字:
execute "Termdebug ".a:executable
或者您可以使用 :execute
的功能,它将多个参数与 space 连接起来,因此您不需要显式连接:
execute "Termdebug" a:executable
见:help :execute
。
我正在使用以下函数 + 命令在 Vim 中调用调试器:
function! TermDebugArm(executable)
packadd termdebug
let g:termdebugger="arm-none-eabi-gdb"
Termdebug a:executable
endfunction
command! -complete=file -nargs=1 TermDebugArm :call TermDebugArm(<f-args>)
不幸的是,Termdebug
命令得到的是文字参数“a:executable”,而不是它应该表示的实际值(即传递给调用该函数的命令的文件名)。
我做错了什么?
您需要使用 :execute
命令从字符串构建命令,这将允许您使用 a:executable
的值作为文字:
execute "Termdebug ".a:executable
或者您可以使用 :execute
的功能,它将多个参数与 space 连接起来,因此您不需要显式连接:
execute "Termdebug" a:executable
见:help :execute
。