使用vim,我可以在vim打开时启动一个命令,例如:打开vim并创建一个拆分
vim +sp我使用vim-fugitive插件,我使用的是
vim +Gstatus我得到了
E492: No es una orden del editor: Gstatus可能是因为在vim启动Gstatus时没有加载逃犯
当我从终端启动vim时,如何在加载插件后执行命令?
特别是如何从预加载Gstatus的终端启动vim。
发布于 2014-03-16 04:16:18
您的一般问题的答案包含在:help startup中。以下是一些相关的部分:
3. Execute Ex commands, from environment variables and/or files
...
*VIMINIT* *.vimrc* *_vimrc* *EXINIT* *.exrc* *_exrc* *$MYVIMRC*
c. Four places are searched for initializations. The first that exists
is used, the others are ignored. ...
- The user vimrc file(s):
"$HOME/.vimrc" (for Unix and OS/2) (*)
...
"$HOME/_vimrc" (for MS-DOS and Win32) (*)
"$VIM/_vimrc" (for MS-DOS and Win32) (*)
...
4. Load the plugin scripts. *load-plugins*
This does the same as the command: >
:runtime! plugin/**/*.vim
...
8. Perform GUI initializations
Only when starting "gvim", the GUI initializations will be done. See
|gui-init|.
...
12. Execute startup commands
If a "-t" flag was given to Vim, the tag is jumped to.
The commands given with the |-c| and |+cmd| arguments are executed.
The starting flag is reset, has("vim_starting") will now return zero.
If the 'insertmode' option is set, Insert mode is entered.
The |VimEnter| autocommands are executed.这是一种欺骗,在终端中不能与vim一起工作,但你可以在gvimrc文件中放入命令,这些命令将在所有插件加载后运行。正如@Peter Rincker在他的答案后的评论中所建议的那样,更可靠的是使用VimEnter自动命令。
对于您的特定问题,fugitive使用在其插件文件中定义的VimEnter自动命令来定义:Gstatus和其他命令。如果你想自动执行:Gstatus,你应该使用类似的自动命令,并确保它是在逃犯的命令之后定义的,这样你的命令就会在逃犯的命令之后执行。例如,将下面这行(未测试的)放在~/.vim/after/plugin/myfugitive.vim或类似的代码中:
:au VimEnter * if exists(':Gstatus') | Gstatus | endif这将测试命令是否已定义;如果已定义,它将调用该命令。
发布于 2014-03-15 00:05:58
:Gstatus是特定于缓冲区的命令。因此,除非您在存储库中打开一个文件,否则该命令将不存在。点击此处阅读更多内容::h :command-buffer和第一段点击此处:h fugitive-commands
示例:
vim -c Gstatus <filename> # -c "cmd" will be executed after the first file has been read.
vim +Gstatus <filename> # +command is a shortcut for `-c command`
vim .git/index # opens :Gstatus without a file (answer by derenio)发布于 2015-04-21 21:41:47
Fugitive在打开目标存储库的.git/index文件后会自动运行:Gstatus。使用以下命令,而不是尝试手动运行Gstatus:
vim .git/index注意:
如果您希望按照OP建议的方式调用Gstatus ($ vim +Gstatus),则可以在vimrc中添加以下内容
command Gstatus edit .git/index但是,只有当你在你的git库的根目录下时,这才能起作用。
逃逸插件使用command!定义Gstatus命令。这意味着fugitive会悄悄地覆盖此命令定义。
https://stackoverflow.com/questions/22409816
复制相似问题