您好,Stack Overflow vim用户,我最近发现自己花了相当多的时间在我学校的计算机科学实验室编写代码.我已经在无数的Linux系统上配置了vim,并且从未遇到过这个错误:
E499: Empty file name for '%' or '#', only works with ":p:h"
Run Code Online (Sandbox Code Playgroud)
在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
Run Code Online (Sandbox Code Playgroud)
我已经注释掉了最后几个插件,看看它们是否与错误有任何关联,但这似乎没有帮助.我像往常一样使用Git安装vim:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
Run Code Online (Sandbox Code Playgroud)
之后我所做的就是运行:PluginInstall来安装插件,然后尝试使用:source%,导致错误.
这真是难倒我了,我希望能解决这个问题,因为我想用我定制的vim设置这个CS类,但我可以处理股票VIM甚至六,或者如果它涉及到它...纳米.
编辑:使用Ubuntu 15.04
这似乎与空有关%。您可以做两件事:在调用 vim: 时传递文件名:vim myscript.vim然后调用:source %,或将文件名传递给:source( :source myscript.vim)。
根据文档,:help registers列出%为包含当前文件名的只读寄存器。因此,如果您正在编辑没有文件名(未保存)的缓冲区,则该%寄存器为空,从而导致您收到错误消息。