nnn icon indicating copy to clipboard operation
nnn copied to clipboard

tmux nnn split cd

Open dv-blk opened this issue 5 years ago • 12 comments

Is your feature request related to a problem? Please describe.

tmux -> nnn -> vim -> tmux split -> wrong directory

Describe the solution you'd like

If there aren't any hooks within nnn to accomplish this and/or not intended to be, I am posting to ask if anyone has implemented this somehow or that can advise

Describe alternatives you've considered

I have tried using $PWD from within the tmux split script, sourcing NNN_TMPFILE from that script, using vim's lcd lchdir functions on file open, to no avail.

Additional context

Open to any old dirty solution, and hopefully I haven't missed any obvious ones while searching myself

Consider contributing

Thank you!

dv-blk avatar May 04 '21 01:05 dv-blk

I am not sure what your expectation is but I see this (taking vim out of the equation:

  • open tmux at ~
  • cd to Pictures directory
  • tmux split
  • new pane starts at ~

Not sure what nnn can do here.

You may find something similar in #759. However, fork()s are costly and we do not want to maintain such code either.

BTW, something that may help you - open the file in vim in a new pane in tmux (I am not sure how though, share if you have a way to do that).

In my case I use xfce4-terminal and open text files detached in a new tab so I don't get block. See here: https://github.com/jarun/nnn/wiki/Basic-use-cases#detached-text

jarun avatar May 04 '21 01:05 jarun

@luukvbaal are you aware of a way to open a file with vim in a new pane in tmux?

jarun avatar May 04 '21 01:05 jarun

I was trying to avoid implementing a hybrid vim/tmux key command pattern for doing splits but if I have to do that i'm totally cool with it.

My hope here was someone may know somehow perhaps to supercede nnn and change the directory that tmux is watching - maybe writing that into a script that is called with EDITOR, or executed from vim

dv-blk avatar May 04 '21 02:05 dv-blk

I do not use too many tabs myself (not even previews for that matter). If I need to open multiple files together for editing I use vim with the nnn.vim plugin but that's a rare scenario. If your main purpose is to edit multiple files together from different locations, probably that's a better way to do that. Check out the vim Mini Buffer Explorer plugin too.

jarun avatar May 04 '21 02:05 jarun

With a tip from an earlier thread https://github.com/jarun/nnn/issues/565#issuecomment-626358927 ...

I resolved my issue with a little bash, example:

newpanecurdir() {
  cwd=
  cc=$(tmux display -p '#{pane_current_command}')
  if [ $cc == "nnn" ] ; then
    cwd=$(lsof -w -c nnn | grep cwd | tail -n 1 | awk '{print $9}')
  else
    cwd=$(tmux display -p '#{pane_current_path}')
  fi

  tmux split-window -c "$cwd"
}

I have this function in the tmux path and run it with run-shell

Now I have nnn -> split and nnn -> vim -> split using the cwd from nnn

Nnn is worth the effort, TY!

dv-blk avatar May 04 '21 07:05 dv-blk

Thanks! Can you please update the Wiki with this info?

The right section should be: https://github.com/jarun/nnn/wiki/Troubleshooting#tmux-configuration

jarun avatar May 04 '21 09:05 jarun

Sounds good. I have it written, do I need permission to go add it?

dv-blk avatar May 04 '21 20:05 dv-blk

Not at all! Anyone can edit.

jarun avatar May 05 '21 00:05 jarun

Updated :+1:

dv-blk avatar May 05 '21 04:05 dv-blk

nnn does not change the process cwd while navigating

This is not correct. Now we do it:

5948 begin:
5949         /* Can fail when permissions change while browsing.
5950          * It's assumed that path IS a directory when we are here.
5951          */
5952         if (chdir(path) == -1) {                                                                      
5953                 DPRINTF_S("directory inaccessible");
5954                 valid_parent(path, lastname);
5955                 setdirwatch();
5956         }

jarun avatar May 05 '21 07:05 jarun

But we do not advertise that out of nnn is probably the issue.

jarun avatar May 05 '21 07:05 jarun

Updated.

jarun avatar May 05 '21 07:05 jarun