💾 Archived View for bbs.geminispace.org › s › vim › 5376 captured on 2024-05-12 at 18:21:05. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-05-10)
-=-=-=-=-=-=-
A combination of tmux and vim makes a minimal REPL IDE. I managed to cobble it together in a few minutes in spite of knowing nothing about vimscript and nearly nothing about tmux.
My workflow is this: I open tmux and split it into at least two panes. The first one is where I run my Forth in, and according to tmux the pane is named '%0'. The second one is for vim. Now I need vim to send paragraphs of source into pane %0, as if they were typed.
Tmux has a function 'send-keys' which does just that. Since we know the destination pane is %0, the rest is getting vim to invoke a proper tmux command and send the current paragraph.
let g:tmux_target = "%0" function Send_to_Pane(text) echo system("tmux send-keys -t " . g:tmux_target . " '" . substitute(a:text, "'", "'\\\\''", 'g') . "'") endfunction vmap <C-c><C-c> "ry :call Send_to_Pane(@r)<CR> nmap <C-c><C-c> vip<C-c><C-c>
I cobbled it up from crap I found on the bigweb. Like I said, I don't know shite from vimscript, but it seems to work (after I threw 90% of what seemed like really stupid code away), albeit inelegantly forcing you into the %0 target pane. I really have no clue about why the bindings look the way they do. I suppose vip selects a paragraph, when we are in normal mode, and the visual mode binding puts the selection into register r, passed to the function..
And now I can keep my forth running as before, command line and all, and keep a source window with vim capable of pumping definitions into forth when I press C-c C-c. It's almost like a poor man's Lisp REPL.
P.S. It took me longer to write it up than to get it done. At least I'll know where to look when I forget what I did.
https://tildegit.org/stack/nforth
2023-09-16 · 8 months ago · 👍 drh3xx, wasolili, norayr, lanterm
🐦 wasolili [...] · 2023-09-23 at 04:24:
is that substitute call just to deal with characters that break the shell command? you may consider calling `shellescape` instead.
🚀 stack [OP/mod] · 2023-09-23 at 16:43:
Hmm. What the heck does it substitute?
🐦 wasolili [...] · 2023-09-23 at 17:11:
the substitute function is replacing ' with '\''. shellescape will do basically the same thing, but will adjust how it escapes characters based on the shell you're using. so it will work with multiple different shells
echo system("tmux send-keys -t " . g:tmux_target . " " . shellescape(a:text))