jarun / nnn

n³ The unorthodox terminal file manager
BSD 2-Clause "Simplified" License
19.43k stars 765 forks source link

Can't run "batch rename" when $EDITOR is set to vscode (usr/bin/code) #1134

Closed denik1981 closed 3 years ago

denik1981 commented 3 years ago

Environment details (Put x in the checkbox along with the information)

Exact steps to reproduce the issue

  1. Set EDITOR to /usr/bin/code or whatever path you have located the vscode executable.
  2. Open nnn.
  3. Select some files for batch renaming them.
  4. Press 'r' to execute the renamer.

The problem is that despite the renamer is aware of VSCODE being the prefered EDITOR, it sends and EMPTY file (wihouth the files being selected) on a temp directory named with the .nnn prefix plus a 6 letter hash (eg .nnnYHjhyZ).

I checked that the command runs without any issue when using the default nnn editor. I'm not sure if this is related to VSCODE or to any GUI editor.

jarun commented 3 years ago

What is your $VISUAL? Are you using detached edits?

jarun commented 3 years ago

I am able to use mousepad. So no issues with GUI programs in general. Can you try with a regular GUI editor?

jarun commented 3 years ago

Also, do you have plugins installed?

0xACE commented 3 years ago

I can replicate. Seems like code is the problem.

nnn waits for the $EDITOR to finish running and then returning execution to nnn.

But: when you spawn code it practically uses some IPC to another instance of code and then it closes. Also for w/e reason code spawns as a child of init rather than w/e process spawned it, I wont delve deeper into this.

denik1981 commented 3 years ago

@jarun ..

export VISUAL=/usr/bin/code export EDITOR=/usr/bin/vim export NNN_TRASH=1 alias nnn='nnn -de'

Those are my current settings. But thanks anyway because I guess I solved the issue by adding the "E" flag, instructing nnn to use vim (EDITOR) for undettached edits. Maybe the documentation can make a tiny notice about this. It is not a rare case to use nnn in conjunction with VSCODE and batch renaming is such a powerful feature.

luukvbaal commented 3 years ago

EDITOR="code -w" seems to work.

  -w --wait                         Wait for the files to be closed before
                                    returning.
0xACE commented 3 years ago

EDITOR="code -w" seems to work.

Also beware of the potential issues with setting EDITOR="code -w" it probably more portable to introduce your own script code-blocking:

#!/usr/bin/env sh
code -w "$@"

and use EDITOR=code-blocking

jarun commented 3 years ago

I am closing this.

Sorry, we can't document vscode-specific behaviour. But I'll add a generic note that the instance of the editor must wait for the editing to complete.