简体   繁体   English

Vim脚本:带有“前缀”的用户定义命令

[英]Vim Script: User-defined command with “prefix”

I have created a simple user-defined command using the following vim script 我使用以下vim脚本创建了一个简单的用户定义命令

command! -nargs=* -complete=file EE :call EE(<f-args>)

function! EE(...)
  if filereadable(expand(a:1))
    exec 'edit ' . a:1
  endif
endfunction

:EE file will open a file (like the built-in command ":edit file ) :EE file将打开一个文件(如内置命令":edit file

But unlike :tab edit file the command :tab EE file will not open a new tab. 但是与:tab edit file ,命令:tab EE file不会打开新的标签。

Is it possible to enhance the script so that a "prefix" like :tab or :vert could be used? 是否可以增强脚本,以便使用诸如:tab:vert类的“前缀”?

No, unfortunately, the prefix command isn't exposed to custom commands; 不,不幸的是,前缀命令没有公开给自定义命令。 it would be great to have a v:prefixcommand variable that one could evaluate. 拥有一个可以评估的v:prefixcommand变量会很棒。

You so far have to write separate alternative commands, eg :TEE for :tab EE . 到目前为止,您必须编写单独的替代命令,例如:TEE代表:tab EE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM