vimidevim-plugin

"zsh:1: no such file or directory" when trying to use :CompileRun in Vim


I just started to use Vim as my main IDE and set up some plugins like syntastic. But when I try to compile and run my program inside Vim by the :CompileRun command, I get this error:

zsh:1: no such file or directory:.//mnt/Storage/C++/EX/test.cpp

Here is my .vimrc:

set number

call plug#begin('~/.vim/plugged')

Plug 'preservim/nerdtree'                             
Plug 'airblade/vim-gitgutter'                         
Plug 'scrooloose/nerdcommenter'                       
Plug 'vim-airline/vim-airline'                         
Plug 'vim-airline/vim-airline-themes'                  
Plug 'ycm-core/YouCompleteMe'                         
Plug 'tmux-plugins/vim-tmux', { 'branch': 'master' }
Plug 'git@github.com:cpp0x/vim-cpp-modern.git'                            

Plug 'vim-syntastic/syntastic'
command! CompileRun execute './"%:p:r".out'


" Enable clangd for C++ support (for autocompletion, diagnostics)
let g:coc_global_extensions = ['coc-clangd']
let g:syntastic_mode_map = { 'mode': 'active' }
let g:syntastic_cpp_checkers = ['gcc']


call plug#end()

And I tried to replace the command! line with the correct one and tried multiple things, but it didn't work.


Solution

  • The error is in './"%:p:r".out': %:p returns full path from the root of the filesystem, but you prepend ./ and spoiled the full path. Just remove ./:

    command! CompileRun execute '"%:p:r".out'