我有一个插件(FindFile.vim),需要在每次启动vim时运行:FindFileCache .
来收集文件缓存以便快速打开。但是每次启动vim都需要手动运行这个命令。
我该如何编写一个命令,在每次启动vim时只运行一次?
我有一个插件(FindFile.vim),需要在每次启动vim时运行:FindFileCache .
来收集文件缓存以便快速打开。但是每次启动vim都需要手动运行这个命令。
我该如何编写一个命令,在每次启动vim时只运行一次?
把配置文件放在.vimrc中是最好的选择。但是,它加载得太早了,可以查看:h startup
:
At startup, Vim checks environment variables and files and sets values
accordingly. Vim proceeds in this order:
1. Set the 'shell' and 'term' option *SHELL* *COMSPEC* *TERM*
2. Process the arguments
3. Execute Ex commands, from environment variables and/or files *vimrc* *exrc*
4. Load the plugin scripts. *load-plugins*
5. Set 'shellpipe' and 'shellredir'
6. Set 'updatecount' to zero, if "-n" command argument used
7. Set binary options
8. Perform GUI initializations
9. Read the viminfo file
10. Read the quickfix file
11. Open all windows
12. Execute startup commands
正如您所看到的,您的.vimrc将在插件之前加载。如果您在其中放置:FindFileCache .
,则会出现错误,因为该命令尚不存在。(一旦在第4步加载插件,它就存在了。)
为解决此问题,请不要直接执行命令,而是创建一个自动命令。自动命令在事件发生时执行某些命令。在这种情况下,VimEnter事件似乎很合适(来自:h VimEnter
):
*VimEnter*
VimEnter After doing all the startup stuff, including
loading .vimrc files, executing the "-c cmd"
arguments, creating all windows and loading
the buffers in them.
然后,在你的.vimrc文件中添加这行代码:
autocmd VimEnter * FindFileCache .
vim -c "vnew"
nvim -c "colorscheme mustang" some_file
vim -c‘:colo default’ test.txt
- van abelxolox/vim-notes
,我想要一个打开 Vim 并准备好新笔记的 fish 函数。 - wsamsvim -c 'help | only'
或简写为:vim -c'h|on'
。这将启动vim并显示帮助信息,然后执行:only
命令以将其转换为单个窗口。 - MacMartinvim -c "command1" -c "command2"
- Claudiu创建一个名为~/.vim/after/plugin/whatever_name_you_like.vim
的文件,并将其填充。
FindFileCache .
在 vim 目录中读取和执行脚本的顺序已在 :help 'runtimepath'
中描述。
function DelayedSetVariables(timer)
let g:ycm_filetype_blacklist['ignored'] = 1
endfunction
let timer=timer_start(500,'DelayedSetVariables')
这个例子中的变量是来自YouCompleteMe插件的黑名单。我猜测,该插件会异步启动一些其他进程,这些进程创建变量时可能还没有准备好,但在vim启动时就已经尝试设置了该变量。无论是在.vimrc、after文件或VimEnter事件中尝试设置该变量都不起作用。这种情况似乎只针对我的Windows系统,YCM文档表示应该可以通过.vimrc来设置选项。
vim file.txt "+:FindFileCache ."
。+/
究竟是什么意思。 - Sridhar Sarnobat