💾 Archived View for bbs.geminispace.org › s › vim › 5376 captured on 2024-08-31 at 12:55:35. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-08-18)

🚧 View Differences

-=-=-=-=-=-=-

Vim as an IDE

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

Posted in: s/vim

🚀 stack [mod]

2023-09-16 · 1 year ago · 👍 drh3xx, wasolili, norayr, lanterm

3 Comments ↓

🐦 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))