Terminal Multiplexing

... and all that because I don't want to use RStudio.

Falk Mielke, University of Antwerp, August 30, 2024

productivity keyboards computer

I learned what terminal multiplexing is good for. Here is a quick demo! Below you will find references and the configs I copied together.

References

Thank you to the creators of the following online videos and documentations:

(and several StackOverflow pages which I lost on the way)

Steps

Configs

.tmux.conf

    # source: https://github.com/mischavandenburg/dotfiles
    
    set-option -g history-limit 25000
    set -g mouse on
    
    # for neovim
    set -sg escape-time 10
    set-option -g focus-events on
    
    # vi for copy mode
    setw -g mode-keys vi
    
    # status bar
    set -g status-style "fg=#665c54"
    set -g status-left-style "fg=#928374"
    
    set -g status-bg default
    set -g status-position top
    set -g status-interval 1
    set -g status-left ""
    
    # rename panes to current working directory
    set-option -g automatic-rename on
    set-option -g automatic-rename-format '#{b:pane_current_path}'
    
    # disable status
    # set -g status off
    # set -g status on
    
    # count the panes from 1
    set -g base-index 1
    setw -g pane-base-index 1
    
    # reload configuration
    bind-key -r r source-file ~/.tmux.conf
    
    # term colors, these are the correct ones according to neovim checkhealth
    set -g default-terminal "tmux-256color"
    set-option -sa terminal-overrides ',xterm-256color:RGB'

.SpaceVim.d/init.toml

    # ++ [[options]]
        bootstrap_before = "config_keybindings#before"

.SpaceVim.d/init.toml

    function! config_keybindings#before() abort
        call SpaceVim#custom#SPCGroupName(['r'], '+run in tmux testing')
        call SpaceVim#custom#SPC('nore', ['r', 'r'], "'<,'>w !xargs -0 -I{} tmux send {} ENTER", 'send to tmux', 1)
        call SpaceVim#custom#SPC('nore', ['r', 'f'], "w !xargs -0 -I{} tmux send {} ENTER", 'send whole file to tmux "testing"', 1)
        call SpaceVim#custom#SPC('nore', ['r', 'l'], ".w !xargs -0 -I{} tmux send {} ENTER", 'send line to tmux "testing"', 1)
    
        augroup RMD_CMD
          autocmd!
            autocmd Filetype rmd noremap <F5> :!echo<space>"require(rmarkdown);<space>render('<c-r>%')"<space>\|<space>R<space>--vanilla<enter>
            autocmd Filetype rmd inoremap ;r ```{r,<space>echo=TRUE}<CR>```<CR><CR><esc>2kO
        augroup END
    endfunction

.doom.d/config.el

(requires tmux and some other packages)

    ;; R Markdown Rendering
    ;; spa/rmd-render - modified
    ;; https://www.stefanavey.com/lessons/2018/01/04/ess-render
    ;; render commands and propose as suggestions in the minibuffer.
    (defun rmd-render (arg)
      "Render the current Rmd file to PDF output."
      (interactive "P")
      ;; Build the default R render command
      (setq rcmd (concat "rmarkdown::render('" buffer-file-name "')"))
      ;; Build and evaluate the shell command
      (setq command (concat "echo \"" rcmd "\" | R --vanilla"))
      (compile command))
    
    
    ;; tmux
    ;; https://www.youtube.com/watch?v=QRmKpqDP5yE
    (map! :leader
        (:prefix ("r"."run in tmux")
          :desc "run selection in tmux"
                 "r" #'+tmux/send-region
          :desc "compile RMarkdown"
                 "m" #'rmd-render
         )
    )