首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >vim:加载插件后启动命令

vim:加载插件后启动命令
EN

Stack Overflow用户
提问于 2014-03-14 23:49:31
回答 5查看 2.7K关注 0票数 3

使用vim,我可以在vim打开时启动一个命令,例如:打开vim并创建一个拆分

代码语言:javascript
复制
vim +sp

我使用vim-fugitive插件,我使用的是

代码语言:javascript
复制
vim +Gstatus

我得到了

代码语言:javascript
复制
E492: No es una orden del editor: Gstatus

可能是因为在vim启动Gstatus时没有加载逃犯

当我从终端启动vim时,如何在加载插件后执行命令?

特别是如何从预加载Gstatus的终端启动vim。

EN

回答 5

Stack Overflow用户

发布于 2014-03-16 04:16:18

您的一般问题的答案包含在:help startup中。以下是一些相关的部分:

代码语言:javascript
复制
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或类似的代码中:

代码语言:javascript
复制
:au VimEnter * if exists(':Gstatus') | Gstatus | endif

这将测试命令是否已定义;如果已定义,它将调用该命令。

票数 5
EN

Stack Overflow用户

发布于 2014-03-15 00:05:58

:Gstatus是特定于缓冲区的命令。因此,除非您在存储库中打开一个文件,否则该命令将不存在。点击此处阅读更多内容::h :command-buffer和第一段点击此处:h fugitive-commands

示例:

代码语言:javascript
复制
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)
票数 3
EN

Stack Overflow用户

发布于 2015-04-21 21:41:47

Fugitive在打开目标存储库的.git/index文件后会自动运行:Gstatus。使用以下命令,而不是尝试手动运行Gstatus

代码语言:javascript
复制
vim .git/index

注意:

如果您希望按照OP建议的方式调用Gstatus ($ vim +Gstatus),则可以在vimrc中添加以下内容

代码语言:javascript
复制
command Gstatus edit .git/index

但是,只有当你在你的git库的根目录下时,这才能起作用。

逃逸插件使用command!定义Gstatus命令。这意味着fugitive会悄悄地覆盖此命令定义。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22409816

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档