如何解决此错误:
E499: Empty file name for '%' or '#', only works with ":p:h"
每当我在 vim 命令中使用
%
时,都会发生此错误。我以前从未见过这个。这是我的 .vimrc:
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
"Plugin 'scrooloose/nerdtree'
"Plugin 'bling/vim-airline'
"Plugin 'altercation/vim-colors-solarized'
call vundle#end()
filetype plugin indent on
我已经注释掉了最后几个插件,看看它们是否与错误有任何相关性,但这似乎没有帮助。我像往常一样使用 Git 安装 vim:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
之后我所做的就是运行
:PluginInstall
来安装插件,然后运行:source %
,这给出了错误。
操作系统:Ubuntu 15.04
这似乎与空的
%
有关。你可以做两件事:调用 vim 时传递文件名:vim myscript.vim
,然后调用 :source %
,或者将文件名传递给 :source
(:source myscript.vim
)。
根据文档,
:help registers
将%
列为包含当前文件名的只读寄存器。因此,如果您正在编辑没有文件名(未保存)的缓冲区,则此 %
寄存器为空,从而导致您收到错误消息。
在没有任何文件的情况下打开 vim 后使用 :source % 时会出现此错误。你可以做的是使用文件名打开 vim,例如vim file1.js ,然后尝试 :source %