[R-sig-Debian] Open a text file with vi/vim in another Terminal

Dirk Eddelbuettel edd @end|ng |rom deb|@n@org
Fri Dec 17 19:32:13 CET 2021

On 17 December 2021 at 18:48, Patrice Kiener wrote:
| With Debian and macOS, the default editor (getenv("EDITOR") or 
| getOption("editor")) is "vi" which opens vi/vim. The following instruction:
|    fileREP <- file.path(R.home("etc"), "repositories")
|    system2(getOption("editor"), fileREP, wait = FALSE)
| works fine with Windows but is inappropriate in the Debian/RStudio/RCode 
| console as it launchs vi/vim, warns about input and outputs and prints 
| the text file WITHIN the R console and then does nothing. Closing vi/vim 
| requires a manual action. In several tests, I even had to force R to 
| recover. Hence My question is:
| What is the system(), sytem2(), eventually file.edit() instruction that 
| opens the text file with vi/vim in a NEW Unix terminal and allows to 
| keep working in the R console?

It all depends on (on all systems including Debian) your value of EDITOR,
which also reflects the value of VISUAL. In shell that is written (in
Renviron) as

    ## Default editor

which takes vi if VISUAL is not set, and the value of that if EDITOR is not

Now vi itself can be one several vi implementations. Right now on my system

    /etc/alternatives/vi -> /usr/bin/vim.basic

but one could also use nvi etc. You could possibly set up a shell script to
take the file name argument and do tricks with terminal (say) and or
sessions.  So the idea is that this under your control.

That said, I don't have tips. If I need to edit, I edit outside of R and/or R
already runs in an editor, or ...


https://dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org

More information about the R-SIG-Debian mailing list