preservim / vimux

easily interact with tmux from vim
MIT License
2.2k stars 159 forks source link

VimuxSendText() escaping #87

Closed smondet closed 3 years ago

smondet commented 10 years ago

I was having trouble with VimuxSendText when the text contained '$' characters.

The function only escapes '"', c.f https://github.com/benmills/vimux/blob/master/plugin/vimux.vim#L45

I was luckier with

call VimuxSendKeys("'" . escape(@k, "'") . "'")

i.e. call system with single quotes and only escape those.

Maybe it can be usefull for others (?).

Cheers

kindlychung commented 10 years ago

I used this:

call VimuxSendKeys("'" . escape(a:text, "'") . "'")

Shouldn't this be patched?

kindlychung commented 10 years ago

This make it impossible to send a line containing single quotes to shell, for example:

echo 'a'

I got an error:

Error detected while processing function VimSendText..VimSendKeys Line 2: E484: can't open file /tmp/vo4zhg75/2

kindlychung commented 10 years ago

I have rewritten the function in python, and it now works flawlessly:

function! VimuxSendText(text)
python << endpy
import subprocess
import vim
mytext = vim.eval("a:text")
mytarget = vim.eval("g:VimuxRunnerIndex")
print mytext
subprocess.call(["tmux", "send-keys", "-t", mytarget, mytext])
endpy
endfunction
wilywampa commented 10 years ago

Now try sending a semicolon as the last character. Escaping is nasty.

alerque commented 3 years ago

This should be addressed by 46377b8. Feel free to comment if this doesn't cover all the possible escaping issues, but I think it will.