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:
- Luke Smith (2018) “An Intro to R Markdown”; https://www.youtube.com/watch?v=4J5a0JWIF-0
- DistroTube (2020) “A First Look At SpaceVim”; https://www.youtube.com/watch?v=iXPS_NHLj9k
- Bhalla Kunal (2020) “Notes on using tmux”;https://explog.in/notes/tmux.html
- System Crafters (2021) “Give Your Dotfiles a Home with GNU Stow”; https://www.youtube.com/watch?v=4J5a0JWIF-0
- Mischa van den Burg (2024) “My Entire Neovim + Tmux Workflow […]”; https://www.youtube.com/watch?v=iagjeLuxnMs, https://github.com/mischavandenburg/dotfiles
- Stevan Avey (2018) “Something like RStudio’s Knit Button in Emacs”; https://www.stefanavey.com/lessons/2018/01/04/ess-render
- Emacs Doomcasts (2021) “Custom keybindings in Doom Emacs (28)”; https://www.youtube.com/watch?v=QRmKpqDP5yE
- Spacevim Documentation; https://spacevim.org/documentation/
xargs
: https://en.wikipedia.org/wiki/Xargs
(and several StackOverflow pages which I lost on the way)
Steps
- install
r
,tmux
, andvim
- in
R
,install.packages(c('rmarkdown'))
- install spacevim: https://spacevim.org
- adjust configs, as shown below
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
)
)