我试图从.
vimrc文件中运行一个
shell脚本(脚本中标记了三个问题):
function! CheckMe(file) let shellcmd = 'checkme '.a:file " Start the command and return 0 on success. " XXX: How do you evaluate the return code? execute '!'.shellcmd if !result return 0 endif " Ending up here,the command returned an error. " XXX: Where to you get the output? let pair = split(output,'\S') let line = pair[0] let char = pair[1] " Jump to the errenous column and line. " XXX: Why does this not work? normal '/\%'.line.'l\%'.char.'c' return 1 endfunction
总而言之,如何获得脚本的结果/输出,以及为什么跳转语句不起作用?
额外细节:
> shell脚本在成功时返回0,在失败时返回1.如果失败,脚本会将两个数字(行号和列号)打印到stdout,用空格字符分隔.
>根据Vim docs,“普通”关键字的参数是“像打字一样执行”,但显然情况并非如此.当我输入它时(在正常命令模式下,没有前导’:’)它工作正常,但在脚本中没有(“E78:未知标记”).
function! CheckMe(file) let shellcmd = 'checkme '.a:file let output=system(shellcmd) if !v:shell_error return 0 endif " Are you sure you want to split on non-blanks? This " will result in list of blank strings. " My variant: let [line,char]=split(output) " normal is not an execute: this is what it will do: " «'/» means «Go to mark /»,produces an error E78 because / " is not a valid symbol for mark. Than normal stops after error occured. " If you need to use variables in nomal use «execute 'normal '.ncmd». " And you can not use «normal» to perform search execute '/\%'.line.'l\%'.char.'c' " or call setpos('.',[0,line,char,0]) return 1 endfunction
According to the Vim docs,the argument of the “normal” keyword is “executed like it is typed”,but apparently that is not the case. It works fine when I type it (in the normal command mode,without leading ‘:’),but doesn’t in the script (“E78: UnkNown mark).
只需输入«’/»即可得到此错误.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。