]> Sergey Matveev's repositories - nnn.git/commitdiff
Prefer VISUAL, if defined over EDITOR
authorArun Prakash Jana <engineerarun@gmail.com>
Sun, 8 Apr 2018 00:43:33 +0000 (06:13 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sun, 8 Apr 2018 00:45:24 +0000 (06:15 +0530)
README.md
nnn.1
nnn.c
nnn.h

index 9651aab442d58b70e9e8add36fd9575f9f587786..10eb59ed661a2cf9b9cf189958d7ddc77a5fc6d7 100644 (file)
--- a/README.md
+++ b/README.md
@@ -293,7 +293,7 @@ The following abbreviations are used in the detail view:
 | atool | list and extract archives |
 | vidir from moreutils | batch rename, move, delete dir entries |
 | vlock (Linux) | terminal locker |
-| $EDITOR | edit files (fallback vi) |
+| $EDITOR ($VISUAL, if defined) | edit files (fallback vi) |
 | $PAGER | page through files (fallback less) |
 | $SHELL | spawn a shell, run script (fallback sh) |
 
diff --git a/nnn.1 b/nnn.1
index 451318ab3721bb8fe3a1382fb46143eecb4ae69f..4e303154334d114b02a53e112dfa3d2b784ab344 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -216,7 +216,7 @@ In this mode it's possible to
 .Pp
 Pressing \fI^Y\fR again copies the paths to clipboard and exits the multi-copy mode.
 .Sh ENVIRONMENT
-The SHELL, EDITOR and PAGER environment variables take precedence
+The SHELL, EDITOR (VISUAL, if defined) and PAGER environment variables take precedence
 when dealing with the !, e and p commands respectively.
 .Pp
 \fBNNN_BMS:\fR bookmark string as \fIkey:location\fR pairs (max 10) separated by
diff --git a/nnn.c b/nnn.c
index 740041dc851b26f8efaab529cb4bb7d3a4b7ba57..1c3f7a7b8c74ae943a5bf111356573fa065bb69f 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -2038,7 +2038,9 @@ show_help(char *path)
                dprintf(fd, "SHELL: %s\n", getenv("SHELL"));
        if (getenv("SHLVL"))
                dprintf(fd, "SHLVL: %s\n", getenv("SHLVL"));
-       if (getenv("EDITOR"))
+       if (getenv("VISUAL"))
+               dprintf(fd, "VISUAL: %s\n", getenv("VISUAL"));
+       else if (getenv("EDITOR"))
                dprintf(fd, "EDITOR: %s\n", getenv("EDITOR"));
        if (getenv("PAGER"))
                dprintf(fd, "PAGER: %s\n", getenv("PAGER"));
@@ -3237,6 +3239,8 @@ nochange:
                        goto begin;
                case SEL_RUNARG:
                        run = xgetenv(env, run);
+                       if ((!run || !run[0]) && (xstrcmp("VISUAL", env) == 0))
+                               run = editor ? editor : xgetenv("EDITOR", "vi");
                        spawn(run, dents[cur].name, NULL, path, F_NORMAL);
                        break;
 #ifdef __linux__
@@ -3396,8 +3400,11 @@ main(int argc, char *argv[])
 #endif
 
        /* Edit text in EDITOR, if opted */
-       if (getenv("NNN_USE_EDITOR"))
-               editor = xgetenv("EDITOR", "vi");
+       if (getenv("NNN_USE_EDITOR")) {
+               editor = xgetenv("VISUAL", NULL);
+               if (!editor)
+                       editor = xgetenv("EDITOR", "vi");
+       }
 
        /* Set player if not set already */
        if (!player)
diff --git a/nnn.h b/nnn.h
index 680200f2d93d63e118e962cd3e79b4ebab5571f1..fa92523325b73a91b83f2f574b0ccc95a77492de 100644 (file)
--- a/nnn.h
+++ b/nnn.h
@@ -174,7 +174,7 @@ static struct key bindings[] = {
        /* Run a custom script */
        { 'R',            SEL_RUNSCRIPT, "sh",   "SHELL" },
        /* Run command with argument */
-       { 'e',            SEL_RUNARG,    "vi",   "EDITOR" },
+       { 'e',            SEL_RUNARG,    "",     "VISUAL" },
        { 'p',            SEL_RUNARG,    "less", "PAGER" },
 #ifdef __linux__
        /* Lock screen */