Hello fellow Stack Overflow vim users, I have recently found myself spending a considerable amount of time in my school's Computer Science lab writing code. I've configured vim on countless linux systems and have never encountered this error:
E499: Empty file name for '%' or '#', only works with ":p:h"
This error happens anytime I use % in a command in vim. I've never seen this before, but I will give as much info as I can. Here is my .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
I've commented out those last few plugins to see if they had any correlation with the error, but that didn't seem to help. I used Git to install vim as usual:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
All I did after that was run :PluginInstall to install the plugins, and then tried to use :source %, resulting in the error.
This has really stumped me, and I hope to solve it, as I'd like to use my customized vim setup for this CS class, but I can deal with stock ViM or even Vi, or if it comes to it... nano.
EDIT: Using Ubuntu 15.04
This seems to be related to empty %
. You can do two things: pass the filename when invoking vim: vim myscript.vim
and then calling :source %
, or passing the filename to :source
(:source myscript.vim
).
If you issue :help registers
, there is listed that %
is a read-only register containing the current filename. So, if you are editing a buffer that doesn't have a filename (not saved), this register is empty and so you get error message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With