Let's say i create a filename with this:
xb@dnxb:/tmp/test$ touch '"i'"'"'m noob.mp4"'
xb@dnxb:/tmp/test$ ls -1
"i'm noob.mp4"
xb@dnxb:/tmp/test$
Then vim .
to go inside Netrw directory listing.
" ============================================================================
" Netrw Directory Listing (netrw v156)
" /tmp/test
" Sorted by name
" Sort sequence: [\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:special
" ==============================================================================
../
./
"i'm noob.mp4"
Then press Enter to view the file. Type:
:!ls -l %
It will shows error:
xb@dnxb:/tmp/test$ vim .
ls: cannot access '/tmp/test/i'\''m noob.mp4': No such file or directory
shell returned 2
Press ENTER or type command to continue
I also tried:
[1] :!ls -l '%'
:
Press ENTER or type command to continue
/bin/bash: -c: line 0: unexpected EOF while looking for matching `"'
/bin/bash: -c: line 1: syntax error: unexpected end of file
shell returned 1
Press ENTER or type command to continue
[2] :!ls -l "%"
:
Press ENTER or type command to continue
/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/bin/bash: -c: line 1: syntax error: unexpected end of file
shell returned 1
Press ENTER or type command to continue
[3] :!ls -l expand("%")
:
/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `ls -l expand(""i'm noob.mp4"")'
shell returned 1
Press ENTER or type command to continue
[4] !ls -l shellescape("%")
:
/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `ls -l shellescape("/tmp/test/"i'm noob.mp4"")'
shell returned 1
Press ENTER or type command to continue
[5] !ls -l shellescape(expand("%"))
:
/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `ls -l shellescape(expand("/tmp/test/"i'm noob.mp4""))'
shell returned 1
Press ENTER or type command to continue
My ultimate goal is perform rsync
by Ctrl+c, e.g:
nnoremap <C-c> :!eval `ssh-agent -s`; ssh-add; rsync -azvb --no-t % [email protected]:/home/xiaobai/storage/
My platform is Kali Linux's vim.gtk3
, bash. Fedora's vim
and gvim
also have the same problem.
What's the correct syntax to escape filename containing single and double quotes ?
exec '!ls -l' shellescape(expand('%'))
?rsync
syntax not working. Can you provide a key mapping answer based onrsync
above as answer ? I think i might need to add single quote to destination but failed. e.g.nnoremap <C-c> :exec '!eval `ssh-agent -s`; ssh-add; rsync -azvb --no-t' shellescape(expand('%')) '[email protected]:/tmp/'