diff --git a/README.md b/README.md index 4e0c6755..06669c0d 100644 --- a/README.md +++ b/README.md @@ -332,6 +332,8 @@ The following indicators are used in the detail view: - To edit all text files in EDITOR (preferably CLI, fallback vi): export NNN_USE_EDITOR=1 + Note: Arguments to the editor should be combined together, e.g., + export EDITOR='vim -xR' #### Help diff --git a/nnn.1 b/nnn.1 index 68862112..27ce89da 100644 --- a/nnn.1 +++ b/nnn.1 @@ -277,6 +277,10 @@ when dealing with the !, e and p commands respectively. files. .Bd -literal export NNN_USE_EDITOR=1 + + NOTE: Arguments to the editor should be combined together, e.g., + + export EDITOR='vim -xR' .Ed .Pp \fBNNN_IDLE_TIMEOUT:\fR set idle timeout (in seconds) to invoke terminal locker. @@ -289,7 +293,7 @@ files. cat /path/to/.nnncp | xargs -0 | xsel -bi ----------------------------------------- - Note: By default file paths are copied to the tmp file \fBDIR/.nnncp\fR, where 'DIR' (by priority) is: \fI$HOME\fR or, \fI$TMPDIR\fR or, \fI/tmp\fR. + NOTE: By default file paths are copied to the tmp file \fBDIR/.nnncp\fR, where 'DIR' (by priority) is: \fI$HOME\fR or, \fI$TMPDIR\fR or, \fI/tmp\fR. .Ed .Pp \fBNNN_SCRIPT:\fR path to a custom script to invoke with currently selected file name as argument 1. diff --git a/src/nnn.c b/src/nnn.c index c673c55d..f76a68de 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -290,7 +290,7 @@ static int ndents, cur, total_dents = ENTRY_INCR; static uint idle; static uint idletimeout, copybufpos, copybuflen; static char *copier; -static char *editor; +static char *editor, *editor_arg; static blkcnt_t ent_blocks; static blkcnt_t dir_blocks; static ulong num_files; @@ -2638,12 +2638,10 @@ nochange: if (cfg.nonavopen && sel == SEL_NAV_IN) continue; - /* If NNN_USE_EDITOR is set, - * open text in EDITOR - */ + /* If NNN_USE_EDITOR is set, open text in EDITOR */ if (editor) { if (getmime(dents[cur].name)) { - spawn(editor, newpath, NULL, path, F_NORMAL); + spawn(editor, editor_arg, newpath, path, F_NORMAL); continue; } @@ -2654,7 +2652,7 @@ nochange: continue; if (strstr(g_buf, "text/") == g_buf) { - spawn(editor, newpath, NULL, path, F_NORMAL); + spawn(editor, editor_arg, newpath, path, F_NORMAL); continue; } } @@ -3545,6 +3543,18 @@ int main(int argc, char *argv[]) editor = xgetenv("VISUAL", NULL); if (!editor) editor = xgetenv("EDITOR", "vi"); + if (editor) { + /* copier used as a temp var */ + copier = editor; + while (*copier) { + if (*copier == ' ') { + *copier = '\0'; + editor_arg = ++copier; + break; + } + ++copier; + } + } } /* Get locker wait time, if set; copier used as tmp var */