4

I am doing some scripting related to tmux and Vim. In my tmux window, I have Vim in one tmux pane and a Tcl command line in another tmux pane.

I want to create a Tcl proc which will dump a string to /tmp/file and then use tmux send-keys to send :read /tmp/file to the Vim pane. This is a way for the results of Tcl commands to be automatically read into my Vim buffer.

This is working fine except that I use normal mode Vim mappings where I swap the colon : and the semi-colon ;. This means that I actually want tmux send-keys to send ;read /tmp/file.

My colon/semi-colon swap means that whatever I write won't work for someone who doesn't swap colon/semi-colon.

Is it possible for an external program to discover if a open Vim window has remapped the : key? or run an Ex command without preceding it with a colon?

5
  • 1
    I… can't think of any way to do this that doesn't involve colon (:execute "normal! : …\<CR>", :call feedkeys(': …', 'n'), etc.). The only solution might be the magic key <cmd>, but you would be dependent on the internal representation of such a key.
    – D. Ben Knoble
    Commented May 11, 2022 at 18:58
  • 2
    Possible hacks: gQ, commands, :visual. Or q: to open the command-line window.
    – D. Ben Knoble
    Commented May 11, 2022 at 18:59
  • 1
    There might be something in the client/server or jobs API that could help
    – D. Ben Knoble
    Commented May 11, 2022 at 19:00
  • 1
    The gQ hack would do the trick. Thanks! Commented May 11, 2022 at 19:39
  • Feel free to self-answer :)
    – D. Ben Knoble
    Commented May 12, 2022 at 13:43

1 Answer 1

1

Ex commands can be executed in Ex mode. The Q key in Normal mode enters Ex mode, but this is often mapped to a no-operation by users to avoid Ex mode entirely. In fact, $VIMRUNTIME/defaults.vim now remaps Q to gq.

But Vim being Vim, there's yet another way to enter Ex mode. gQ will enter Ex mode and will update the buffer after each command.

My Tcl proc can now include this code to tell Vim in another tmux pane to read a tmp file:

    set keys "gQread $tmp_file"
    lappend keys "C-m"
    lappend keys "visual" "C-m"

    exec tmux send-keys -t $target {*}$keys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.