Weird behavior with fzopen plugin
Closed this issue ยท 21 comments
Describe the bug
When open a file using fzopen plugin, the file opened in float window
To Reproduce
Steps to reproduce the behavior and with the most minimal configuration.
With only nnn.vim installed and additional configurations/plugins that helps reproduce the bug:
- Open vim
- Run nnn.vim
- Press key combination for fzopen
- Select file
- File opened in float window
Expected behavior
I want the file to open in a new buffer instead of nested in float window
Screenshots
Environment:
- OS: Pop!_OS 20.04 LTS
- Terminal: Tilix 1.9.1
- Shell: zsh 5.8
- Vim version: neovim v0.4.4
- Plugin manager: vim-plug
- Plugin version: master
- Nnn version: 3.5
I haven't taken a deeper look at yet. However I assume when using a nnn plugin such as fzopen
nnn will pass the selected files to whatever opener is set (via EDITOR
or NNN_OPENER
). Probably to fix this, nnn should instead output the selected files to the file specified in picker mode -p <output file>
.
@jarun Thoughts on what's happening here?
would really love this to work, since it means I can get rid of fzf and just use nnn
Currently nnn
doesn't have any way to pass the picker mode or the picker file to the plugins.
I have no plans to spend time on that either. Thanks.
Could the picker file possibly be passed as an argument to spawn()
?
https://github.com/jarun/nnn/blob/715abc7a3fff052755c7bee22be1effb7cb7d45f/src/nnn.c#L2002-L2006
Not sure if there are other complications to making it work.
That's the only way but the problem is when you open in picker mode nnn
tries to write to the output file itself. So we also need a way to synchronize the plugin with the core program.
In addition, there's also the question of whether nnn
gets the list of files from the plugin and write them to the output file OR the plugin writes to the output file and informs nnn
.
I am still thinking about it but I find the solutions more complex than the problem so far.
I think the plugin should write to the output file anyway. The reason is - it can avoid packing the files and send them to nnn
which nnn
will unpack and write to the output file.
I will try to work out a feasible solution for this.
Implemented at jarun/nnn@cbc4587.
Please confirm that it works as expected. Note that you need to install the fzopen
plugin from master.
Works for me on Neovim!
Thanks a lot for confirming!
If possible, please check out the other defects as well.
I closed around 3 of them now. Would love to take the outstanding count to 0 as in the base project.
At first I thought this worked.
When I try this with the nnn branch you mentioned, and a new pull of all the plugins, using fzopen still creates a "sub-vim" instance, or a vim instance running inside the shell that nnn is opened with.
I'm using vim-8
Just to double check, what does your fzopen
script look like that is being run?
and a new pull of all the plugins
run getplugs master
and a new pull of all the plugins
run
getplugs master
did not work for me on vim v8.2
Can you copy the contents from your fzopen
plugin from ~/.config/nnn/plugins
?
Also, how did you compile nnn
?
here is the content of the fzopen:
#!/usr/bin/env sh
# Description: Regular mode:
# Fuzzy find a file in directory subtree.
# Opens in $VISUAL or $EDITOR if text.
# Opens other type of files with xdg-open.
# Work only with a single file selected.
#
# Picker mode:
# If picker mode output file is passed, it
# will be overwritten with any picked files.
# Leaves untouched if no file is picked.
# Works with single/multiple files selected.
#
# Dependencies: fd/find, fzf/skim, xdg-open
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana
. "$(dirname "$0")"/.nnn-plugin-helper
if type fzf >/dev/null 2>&1; then
cmd="$FZF_DEFAULT_COMMAND"
if type fd >/dev/null 2>&1; then
[ -z "$cmd" ] && cmd="fd -t f 2>/dev/null"
else
[ -z "$cmd" ] && cmd="find . -type f 2>/dev/null"
fi
entry="$(eval "$cmd" | fzf -m --delimiter / --nth=-1 --tiebreak=begin --info=hidden)"
# To show only the file name
# entry=$(find . -type f 2>/dev/null | fzf --delimiter / --with-nth=-1 --tiebreak=begin --info=hidden)
elif type sk >/dev/null 2>&1; then
entry=$(find . -type f 2>/dev/null | sk)
else
exit 1
fi
# Check for picker mode
if [ "$3" ]; then
if [ "$entry" ]; then
if [ "-" = "$3" ]; then
printf "%s\n" "$entry"
else
printf "%s\n" "$entry" > "$3"
fi
# Tell `nnn` to clear its internal selection
printf "%s" "0p" > "$NNN_PIPE"
fi
exit 0
fi
# Open the file (works for a single file only)
case "$(file -biL "$entry")" in
*text*)
"${VISUAL:-$EDITOR}" "$entry" ;;
*)
if uname | grep -q "Darwin"; then
open "$entry" >/dev/null 2>&1
else
xdg-open "$entry" >/dev/null 2>&1
fi
;;
esac
I clone the master and then simply compiled it with sudo make O_NERD=1
I can't open the results with pressing Enter now. When I press Enter on the result of my search on fzopen, nnn goes to the file-explorer mode (the default view of nnn)
I see now, when I enter on the result, it only opens it on the main window if I close the nnn window manually. @jarun
Fixed at jarun/nnn@45ac90d.
Can confirm working now in vim 8. Thanks!!
Thanks for the confirmation.