Coder Social home page Coder Social logo

luukvbaal / nnn.nvim Goto Github PK

View Code? Open in Web Editor NEW
402.0 4.0 9.0 160 KB

File manager for Neovim powered by nnn.

License: BSD 3-Clause "New" or "Revised" License

Lua 100.00%
neovim nvim plugin lua terminal file-manager nnn neovim-lua neovim-plugin

nnn.nvim's Introduction

nnn.nvim

File manager for Neovim powered by nnn.

img

Install

Requires nnn to be installed, follow the instructions.

NOTE: Explorer mode requires nnn version v4.3. If your distribution doesn't provide version v4.3 from its repositories, install one of the provided static binaries, OBS packages or build from source.

Then install the plugin using your plugin manager:

Install with vim-plug:

Plug 'luukvbaal/nnn.nvim'
call plug#end()

lua << EOF
require("nnn").setup()
EOF

Install with packer:

use {
  "luukvbaal/nnn.nvim",
  config = function() require("nnn").setup() end
}

Usage

The plugin offers two possible modes of operation.

Explorer Mode

Run command :NnnExplorer to open nnn in a vertical split similar to NERDTree/nvim-tree.

In this mode, the plugin makes use of nnn's -F flag to listen for opened files. Pressing Enter on a file will open that file in a new buffer, while keeping the nnn window open.

Picker Mode

Run command :NnnPicker to open nnn in a floating window.

In this mode nnn's -p flag is used to listen for opened files on program exit. Picker mode implies only a single selection will be made before quitting nnn and thus the floating window.

Selection

In both modes it's possible to select multiple files before pressing Enter. Doing so will open the entire selection all at once, excluding the hovered file.

Bindings

Bind NnnExplorer/NnnPicker to toggle the plugin on/off in normal and terminal mode. The commands accept a path as optional argument. To always open nnn in the directory of the currently active buffer, use %:p:h as argument:

Custom Command Argument

Additionally, passing cmd=<custom command> as argument will override the configured nnn command. This allows you to for example run one-off nnn commands with different option flags. :NnnExplorer cmd=nnn\ -Pf /mnt will open explorer mode in /mnt and run the nnn plugin mapped to f. Spaces in the cmd string must be escaped.

tnoremap <C-A-n> <cmd>NnnExplorer<CR>
nnoremap <C-A-n> <cmd>NnnExplorer %:p:h<CR>
tnoremap <C-A-p> <cmd>NnnPicker<CR>
nnoremap <C-A-p> <cmd>NnnPicker<CR>

Configuration

Default options

local cfg = {
  explorer = {
    cmd = "nnn",       -- command override (-F1 flag is implied, -a flag is invalid!)
    width = 24,        -- width of the vertical split
    side = "topleft",  -- or "botright", location of the explorer window
    session = "",      -- or "global" / "local" / "shared"
    tabs = true,       -- separate nnn instance per tab
    fullscreen = true, -- whether to fullscreen explorer window when current tab is empty
  },
  picker = {
    cmd = "nnn",       -- command override (-p flag is implied)
    style = {
      width = 0.9,     -- percentage relative to terminal size when < 1, absolute otherwise
      height = 0.8,    -- ^
      xoffset = 0.5,   -- ^
      yoffset = 0.5,   -- ^
      border = "single"-- border decoration for example "rounded"(:h nvim_open_win)
    },
    session = "",      -- or "global" / "local" / "shared"
    tabs = true,       -- separate nnn instance per tab
    fullscreen = true, -- whether to fullscreen picker window when current tab is empty
  },
  auto_open = {
    setup = nil,       -- or "explorer" / "picker", auto open on setup function
    tabpage = nil,     -- or "explorer" / "picker", auto open when opening new tabpage
    empty = false,     -- only auto open on empty buffer
    ft_ignore = {      -- dont auto open for these filetypes
      "gitcommit",
    }
  },
  auto_close = false,  -- close tabpage/nvim when nnn is last window
  replace_netrw = nil, -- or "explorer" / "picker"
  mappings = {},       -- table containing mappings, see below
  windownav = {        -- window movement mappings to navigate out of nnn
    left = "<C-w>h",
    right = "<C-w>l",
    next = "<C-w>w",
    prev = "<C-w>W",
  },
  buflisted = false,   -- whether or not nnn buffers show up in the bufferlist
  quitcd = nil,        -- or "cd" / tcd" / "lcd", command to run on quitcd file if found
  offset = false,      -- whether or not to write position offset to tmpfile(for use in preview-tui)
}

Edit (part of) this table to your preferences and pass it to the setup() function i.e.:

require("nnn").setup({
  picker = {
    cmd = "tmux new-session nnn -Pp",
    style = { border = "rounded" },
    session = "shared",
  },
  replace_netrw = "picker",
  windownav = "<C-l>"
})

Mappings

It's possible to map custom lua functions to keys which are passed the selected file or active nnn selection. A set of builtin functions is provided which can be used as follows:

  local builtin = require("nnn").builtin
  mappings = {
    { "<C-t>", builtin.open_in_tab },       -- open file(s) in tab
    { "<C-s>", builtin.open_in_split },     -- open file(s) in split
    { "<C-v>", builtin.open_in_vsplit },    -- open file(s) in vertical split
    { "<C-p>", builtin.open_in_preview },   -- open file in preview split keeping nnn focused
    { "<C-y>", builtin.copy_to_clipboard }, -- copy file(s) to clipboard
    { "<C-w>", builtin.cd_to_path },        -- cd to file directory
    { "<C-e>", builtin.populate_cmdline },  -- populate cmdline (:) with file(s)
  }

To create your own function mapping follow the function signature of the builtin functions which are passed a table of file names.

Note that in both picker and explorer mode, the mapping will execute on the nnn selection if it exists.

Session

You can enable persistent sessions in nnn(-S flag) by setting picker and explorer mode session to one of ""(disabled), "global" or "local".

Alternatively you can set the session "shared" to share the same session between both explorer and picker mode (setting either one to "shared" will make the session shared).

Colors

Three highlight groups NnnNormal, NnnNormalNC and NnnBorder are available to configure the colors for the active, inactive and picker window borders respectively.

Tips and tricks

Git status

Build and install nnn with the gitstatus enable git status symbols in detail mode. Add the -G flag to your command override to also enable symbols in normal mode.

img

preview-tui

Setting the command override for picker mode to for example tmux new-session nnn -P<plugin-key> will open tmux inside the picker window and can be used to open preview-tui inside the floating window:

img

Include option offset = true in your config to write the offset of the NnnPicker window to a temporary file. This will allow preview-tui to correctly draw ueberzug image previews, accounting for said offset.

nnn.nvim's People

Contributors

cantoromc avatar ggustafsson avatar github-actions[bot] avatar hezhizhen avatar itaranto avatar luukvbaal avatar stelcodes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nnn.nvim's Issues

previews problem

Hi, I just installed nnn and previews-tui.
It works ok if I run in console (alacritty) :
tmux new-session
and then
nnn -P <preview_key> (it is not updating preview when navigating files thought)
The real problem is when i runs above as single command:
tmux new-session nnn -P <preview_key>
Then nnn previews-tui is complaining about missing env :
image
Same story when running above command from nnn.nvim . Any ideas why joined command gives error, while run in sequence it works almost ok (well except previews not updating when navigating file) ?

nnn.nvim vs nnn.vim colors

Hey there,

I'm looking at moving from nnn.nvim from nnn.vim.

I notice that nnn.vim will actually use different colors in the NNN ui then nnn.nvim.

The colors are more aligned to my color scheme, so they seem to be either picking up on my terminal colors or my Vim color scheme. Anyway to achieve this effect in nnn.nvim?

image
nnn.nvim ^

image
nnn.vim ^

Unusual behaviour when using :NnnExplorer

I recently updated all my plugins after a long time and this started to happen

nnnExplorer_problem.mp4

Everytime this extra buffer window pops up and I end with two nnn windows.

When i close nnn, my previous file from which i was working was lost and this new empty buffer took its place.

:NnnPicker is working perfectly fine

Listing buffer in floating mode

I used to use floaterm to load nnn. I also have the barbar plugin to display opened buffers as tabs. With your plugin, when I open a floating nnn, barbar shows a new buffer. When I close nnn, the buffer remains, and if I click it on it, I get an error. With floaterm, when you open a floating terminal, barbar doesn't show a new buffer, and the issue I just described doesn't exist. While this is not a big deal, I wonder if you can unlist the floating nnn from the buffer list.

Buffer is opened up in wrong window if NnnExplorer is executed after tabnew in function

Hello!

It seems that NnnExplorer/NnnPicker is not always able to get the correct id of the last window. I've encountered a scenario where it works if each command is performed manually but consistently broken if executed through a function.

I want to use the following function to set things up in a new tab view:

function! DocsMode()
  tabnew
  tcd ~/Documents/Text
  NnnExplorer
endfunction

The result is that NnnExplorer opens up the new buffer in the last window in the previous tab. In other words the new window from tabnew is not registered as the previous window.

See problem in action here: https://asciinema.org/a/bzT1IKDQ5Bh69PkaapXT5noxT

Same thing but manually executed: https://asciinema.org/a/KSCRHMivzr3fnMDAdm1xf7wjz

Best regards,
Gรถran Gustafsson

If i open NnnPicker and then close it, the statusline is messed up.

simplescreenrecorder-2021-10-06_19.38.13.mp4

And also, NnnExplorer doent work. It opens but i have an error. And none of the files open if i click enter on it.

simplescreenrecorder-2021-10-06_19.39.47.mp4

Here i clicked enter or double click on the file and it just won't open.

Feature Request: Replace netrw if the first argument of vi is a directory

netrw, the default file explorer of vim, can be disable with

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

I would like to open NnnPicker or NnnExplorer when Vim starts with a directory argument, in a similar way of NERDtree.

The option replace_netrw = picker/explorer, open a sort of non-interactive window, which is not usable.

Thanks

picker with preview - always open in home dir.

Using picker - 'tmux new-session nnn -P u' always starts in home directory.
Expected result: nnn picker should open in current file dir.
Changing back to cmd='nnn -G -C will open nnn in current file dir (or is it project dir) .
I hope someone can confirm.

disable quitcd within neovim only

In my ~/.zshrc, I have configured nnn to cd on quit.
I like this feature in the terminal but not when I am using the nnn.nvim plugin within neovim.

To disable quitcd within neovim only, I have tried the following settings:

    quitcd = ""
    quitcd = "false"

Neither of these worked.
Is there a way to do this?

Install as nvim package

Usually to install I plugin I just clone it to .local/share/nvim/site/pack/plugins/start but it isn't working with this plugin. By that I mean there are no :Nnn* commands available. Is the only way to install this plugin to use a plugin manager?

`tui-preview` vertical split

Hi, I just can't get tui-preview to split vertically. IIUC, I have to set SPLIT=v as a envvar (at least that's how I got it working outside nvim), but I can't seem to get it to work.

Currently using this config:

local builtin = require("nnn").builtin
local cfg = {
	explorer = {
		cmd = "nnn -G",    -- command overrride (-F1 flag is implied, -a flag is invalid!)
		width = 24,        -- width of the vertical split
		side = "topleft",  -- or "botright", location of the explorer window
		session = "shared",      -- or "global" / "local" / "shared"
		tabs = true,       -- seperate nnn instance per tab
	},
	picker = {
		cmd = "tmux new-session nnn -Pp -G",       -- command override (-p flag is implied)
		style = {
			width = 0.9,     -- percentage relative to terminal size when < 1, absolute otherwise
			height = 0.8,    -- ^
			xoffset = 0.5,   -- ^
			yoffset = 0.5,   -- ^
			border = "rounded"-- border decoration for example "rounded"(:h nvim_open_win)
		},
		session = "shared",      -- or "global" / "local" / "shared"
	},
	auto_open = {
		setup = nil,       -- or "explorer" / "picker", auto open on setup function
		tabpage = nil,     -- or "explorer" / "picker", auto open when opening new tabpage
		empty = false,     -- only auto open on empty buffer
		ft_ignore = {      -- dont auto open for these filetypes
			"gitcommit",
		}
	},
	auto_close = true,  -- close tabpage/nvim when nnn is last window
	replace_netrw = nil, -- or "explorer" / "picker"
    mappings = {
		{ "t", builtin.open_in_tab },       -- open file(s) in tab
		{ "s", builtin.open_in_split },     -- open file(s) in split
		{ "v", builtin.open_in_vsplit },    -- open file(s) in vertical split
		{ "y", builtin.copy_to_clipboard }, -- copy file(s) to clipboard
	},
	windownav = {        -- window movement mappings to navigate out of nnn
		left = "<C-Left>",
		right = "<C-Right>"
	},
}
require("nnn").setup(cfg)

It works great horizontally, tho.

Question, How do I get the plugin to jump to a window if it is already open?

I use a lot of side by side windows to view multiple buffers as I edit. Is there a way to get it to jump to an already open window if it is already open?

As a bonus what I would really like to do is define my layout and have it open the buffer in the first window and shift all the other ones down. Is this setup possible with a little config?
example: given 4 buffers - a , b , c ,d in a four square grid layout

image

Then I open a buffer 'e' I would like to see the following behavior

image

The buffer 'd' is then hidden. If the window is already on the screen no change is made and the cursor jumps to the new window. If a new buffer is opened the cursor is moved to the top left quadrant where the new buffer is.

Is this possible? Can someone point me in the right direction?

Built-in actions not working

Hello, I faced a problem with the built-in actions.
Executing an action turns the Nnn window into a normal buffer. In the case of NnnPicker, the window doesn't close and no action occurs.

Here is a screencast of this behavior:

Screencast.from.26.06.2022.23.53.48.webm.mov
  1. Trying to Ctrl+T on flutter-tools.lua: it turns floating window in normal buffer;
  2. Trying same on autocompletion.lua - same here;
  3. Trying select autopairs.lua with Space and then press Ctrl+T - nothing changes.

Also I reproduce it in NnnExplorer and with open_in_split, open_in_vsplit actions - got the same problem.

My configurations:

nnn.nvim
local builtin = require("nnn").builtin

-- Nnn setup
require('nnn').setup {
  replace_netrw = 'picker',
  mappings = {
    { "<C-t>", builtin.open_in_tab },     -- open file(s) in tab
    -- { "<C-s>", builtin.open_in_split },   -- open file(s) in split
    -- { "<C-v>", builtin.open_in_vsplit },  -- open file(s) in vertsplit
  }
}
.bashrc
# Nnn configuration
export NNN_OPTS='eR'
export NNN_COLORS='#a8a8a8a8'
export NNN_FCOLORS='a8a8a8fbfbfbfbfbfbfbfbfb'
export NNN_FIFO='/tmp/nnn.fifo'
export NNN_PLUG='f:autojump'
eval "$(jump shell bash --bind=f)"
t ()
{
  # Block nesting of nnn in subshells
  if [ -n $NNNLVL ] && [ "${NNNLVL:-0}" -ge 1 ]; then
      echo "nnn is already running"
      return
  fi

  export NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"

  nnn "$@"

  if [ -f "$NNN_TMPFILE" ]; then
          . "$NNN_TMPFILE"
          rm -f "$NNN_TMPFILE" > /dev/null
  fi
}

nnn reverse layout on the screenshot

How do you get this reverse layout of detailed view like on the screenshot in the preview-tui section in the README?
The nnn -d gives me a layout like ls -l with the name at the end of the line.

Empty buffer opens when opening files from recently used list

I use this plugin to display the recently used files in vim during startup.

Opening a file directly (by pressing thr number displayed next to the file name) opens the file in a new buffer.

However, if I open nnn through this plugin, close it, and open a file just as before, an empty buffer is created.

While this is not a big issue, it's irritating to have to always close the empty buffer manually.

Here's a screen recording of the issue.

video.mp4

some quick thoughts on some implementations

hi! sorry to open an issue with one vague title. i just discovered this plugin, i really like its writing style.
though i had some doubts on its some impl, i hope you dont mind i putting these rough thoughts here.

  • tmpdir is not per nvim instance nor per user, this line has a race condition
    io.open(tmpdir .. "/nnn-preview-tui-posoffset", "w")
    
  • TERM: fwik termopen will ignore TERM env and set it to xterm-256color, so set a different TERM to nnn, i think that could lead to unknown problem
  • tabe|NnnExplorer will run nnn in full screen mode, no tabline and statusline showed.
    is that intended?
  • opening NnnExplorer in different tab will create multiple nnn instance by default.
    is that intended? since nnn already has the tab feature, IMO there is an overlap on functionality.

(since i have not used this plugin for a long time, my thoughts could be naive, sorry about that)

netrw error when opening nvim in directory

Using replace_netrw = 'picker' in my configuration, whenever I start nvim in a directory (say nvim ~/Documents/), the error bellow appears.

function <SNR>27_VimEnter[10]..<SNR>27_LocalBrowse ใฎๅ‡ฆ็†ไธญใซใ‚จใƒฉใƒผใŒๆคœๅ‡บใ•ใ‚Œใพใ—ใŸ:
่กŒ   32:
E117: ๆœช็Ÿฅใฎ้–ขๆ•ฐใงใ™: netrw#LocalBrowseCheck
็ถšใ‘ใ‚‹ใซใฏENTERใ‚’ๆŠผใ™ใ‹ใ‚ณใƒžใƒณใƒ‰ใ‚’ๅ…ฅๅŠ›ใ—ใฆใใ ใ•ใ„

After pressing ENTER nnn is opened as expected.

Is it possible to silence this error?

Feature Request: Support ^G / NNN_TMPFILE a.k.a. "QuitCD"

Hello!

It would be really great if nnn.nvim could support builtin ^G / NNN_TMPFILE in addition to builtin.cd_to_path. Basically source last path if file exists after quit.

  1. Check if NNN_TMPFILE is set. Use ${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd as fallback.
  2. Check if file exists.
  3. Read first line and extract second word (path).
  4. Run "tcd" or "cd" on path. This should probably be a setting.
  5. Delete file.

Similiar to:

And related to:

Best regards,
Gรถran Gustafsson

nvim_add_user_command

Hi there. Just installed nnn.nvim and get error:

packer.nvim: Error running config for nnn.nvim: ...l/share/nvim/site/pack/packer/start/nnn.nvim/lua/nnn.lua:528: attempt to call field 'nvim_add_user_command' (a nil value)

Looks like your plugin using nvim_add_user_command from Neovim 0.7.0+ which is not even released (0.6.1 current latest). With all due respect, do you think it's sane?

Using NNN changes what expand('%') returns

Hey there,

Not 100% sure this is an issue with NNN but let me describe.

I'm writing a Neovim plugin which keeps track of file URI's to some degree.

When vim opens up to a root directory and the "edit" command is used to open a file in that directory, vim.fn.expand('%') will return the relative path to that file, something like "file1".

Now, if within the same Neovim instance you then open file2 with NNN vim.fn.expand('%') shows an absolute path to file2. Funny enough if you use NNN to go and open file1, expand still shows the relative path.

Here is a small video demonstrating that when edit command is expand returns relative paths and when NnnPicker is used expand returns absolute.

2021-12-08T09.34.08-05.00.mp4

[Bug] Using toggle causes "attempt to concatenate upvalue 'explorersession' (a nil value)"

Firstly, love the plugin ๐Ÿ‘๐Ÿผ .

When I run:

lua require('nnn').toggle('explorer')

I get the following error

E5108: Error executing lua ...l/share/nvim/site/pack/packer/start/nnn.nvim/lua/nnn.lua:143: attempt to concatenate upvalue 'explorersession' (a nil value)

Basically I'm trying to come up with a cool way to toggle the split and I saw the toggle function within the source code. I had created my own function but it's a bit ๐Ÿ’ฉ compared to something native:

function ToggleNNN()
    if vim.g.togglednnn == true then
        vim.cmd("Bwipeout!")
        vim.cmd("close!")
        vim.g.togglednnn = false
        return
    end

    vim.cmd("NnnExplorer")
    vim.g.togglednnn = true
end

Question about explorer vs picker

I currently have autochdir = true in my vimrc. When I open a file in a buffer, the working directory changes to the directory where the file is located. Let's call this directory p1. When I execute :NnnExploer, nnn opens at p1. If I run :NnnExploer again, nnn hides. Now, if I open another file from a different directory, say p2, and run :NnnExplorer, nnn opens at p1 instead of p2. Meanwhile, :NnnPicker opens at p2. Is the intended behaviour for NnnExplorer to not change directory after it has been invoked the first time?

Mappings don't work on hovered file in picker mode

Hi,
So I just found this plugin, and it works better than the nnn.vim plugin for me.
However, the custom mappings (aside from enter) do not work for the picker, where there is no selection (i.e. on the hovered file).
The other plugin works as expected in this case.
Here are my settings:

lua << EOF
local builtin = require("nnn").builtin
local cfg = {
	explorer = {
		cmd = "nnn",       -- command overrride (-F1 flag is implied, -a flag is invalid!)
		width = 40,        -- width of the vertical split
		side = "topleft",  -- or "botright", location of the explorer window
		session = "local",      -- or "global" / "local" / "shared"
		tabs = true,       -- seperate nnn instance per tab
	},
	picker = {
		cmd = "nnn",       -- command override (-p flag is implied)
		style = {
			width = 0.7,     -- width in percentage of the viewport
			height = 0.7,    -- height in percentage of the viewport
			xoffset = 0.5,   -- xoffset in percentage
			yoffset = 0.5,   -- yoffset in percentage
			border = "rounded" -- border decoration for example "rounded"(:h nvim_open_win)
		},
		session = "shared",      -- or "global" / "local" / "shared"
	},
	auto_open = {
		setup = nil,       -- or "explorer" / "picker", auto open on setup function
		tabpage = nil,     -- or "explorer" / "picker", auto open when opening new tabpage
		empty = false,     -- only auto open on empty buffer
		ft_ignore = {      -- dont auto open for these filetypes
			"gitcommit",
		}
	},
	auto_close = true,  -- close tabpage/nvim when nnn is last window
	replace_netrw = "explorer", -- or "explorer" / "picker"
	mappings = {
		{ "<C-t>", builtin.open_in_tab },       -- open file(s) in tab
		{ "<C-s>", builtin.open_in_split },     -- open file(s) in split
		{ "<C-v>", builtin.open_in_vsplit },    -- open file(s) in vertical split
		{ "<C-p>", builtin.open_in_preview },   -- open file in preview split keeping nnn focused
		{ "<C-y>", builtin.copy_to_clipboard }, -- copy file(s) to clipboard
		{ "<C-w>", builtin.cd_to_path },        -- cd to file directory
		{ "<C-e>", builtin.populate_cmdline },  -- populate cmdline (:) with file(s)
	},
	windownav = {        -- window movement mappings to navigate out of nnn
		left = "<C-w>h",
		right = "<C-w>l"
	},
}
require("nnn").setup(cfg)
EOF

For example, if I were to press <C-v> on a hovered file in the picker (no selection), it should just
open the hovered file in a vertical split. But it simply exits (without opening the hovered file) when I do that.

Bookmarks not displaying when using a GUI client

I have recently been playing with neovim GUI clients like neovide and noticed that pressing b (to get the bookmarks menu) does not work. However, if I open a terminal (:term) and launch nnn inside the terminal, b works. Any idea why this might be happening?

README with wrong highlight group name

In the session Colors in the README, it is written:

Three highlight groups NnnNormal, NnnNormalNC and NnnFloatBorder are available to configure the colors for the active, inactive and picker window borders respectively.

The group NnnFloatBorder does not exist. I looked at the code and the correct group is NnnBorder. Could you fix it?

empty NNN_OPTS gives attempt to index a nil value error

Thanks for this plugin !

I was trying to install it but I keep having this error at startup : E5113: Error while calling lua chunk: ...l/share/nvim/site/pack/packer/start/nnn.nvim/lua/nnn.lua:19: attempt to index a nil value which seems related to NNN_OPTS.

nnn works for me but as I've never really took time to configure it (I imagine this error wants a config file and options)

Just in case, here's my config :

-- Packer config
    use({
        'luukvbaal/nnn.nvim',
        config = [[require('modules.plugins.nnn')]],
    })
-- lua/modules.plugins.nnn
local function cd_to_path(files)
    local dir = files[1]:match('.*/')
    local read = io.open(dir, 'r')
    if read ~= nil then
        io.close(read)
        vim.cmd("execute 'cd " .. dir .. "'")
        print('working directory changed to: ' .. dir)
    end
end

local cfg = {
    explorer = {
        cmd = 'nnn',
        width = 24,
        session = 'shared',
    },
    picker = {
        cmd = 'tmux new-session nnn -Pp',
        style = {
            width = 0.9,
            height = 0.8,
            xoffset = 0.5,
            yoffset = 0.5,
            border = 'rounded',
        },
        session = 'shared',
    },
    replace_netrw = 'picker',
    mappings = {
        { '<C-t>', 'tabedit' },
        { '<C-s>', 'split' },
        { '<C-v>', 'vsplit' },
        { '<C-w>', cd_to_path },
    },
}

local nnn = require('nnn')
nnn.setup({ cfg })

Hope it helps

Running picker from startify menu

I use the startify plugin to list folders, sessions, and recently edited files. If I run NnnPicker (immediately after launching neovim), and select a file from nnn, the file opens in neovim, but the picker floating window doesn't close. This is how it looks.

:vsplit and :edit a folder doesn't work

Hi,

I have been trying nnn for the past few days as an alternative to the existing tree plugins and netrw.
Thanks for all your hard work!

Something that I tend to do a lot is to use :vsplit and have multiple buffers side by side.

If I run :vsplit and after that, I try to edit a folder on the new buffer :e /some-folder/ nnn is triggered but any selection from the nnn will throw out an error when in explorer mode and it silently fails in picker mode.

Picker mode:
https://asciinema.org/a/wAiGWbpjmutXfbx8mgKKlEwey
I open a :vsplit, that it's closed by nnn when I :edit a folder and when I pick a different file init.vim nothing happens

Explorer mode 1:
https://asciinema.org/a/wAiGWbpjmutXfbx8mgKKlEwey
I have nnn tree open. I open a :vsplit and then :edit a folder. nnn closes/toggles the current explorer

Explorer mode 2:
https://asciinema.org/a/wAiGWbpjmutXfbx8mgKKlEwey
I close nnn, I do a vsplit. Inside the vsplit I do a edit of a folder. This closes the vsplit and opens the explorer. I then try to open a file init.vim and it shows an error.

The error is:

Error executing vim.schedule lua callback: ...l/share/nvim/site/pack/packer/start/nnn.nvim/lua/nnn.lua:101: Invalid window id: 1002
stack traceback:
        [C]: in function 'nvim_set_current_win'
        ...l/share/nvim/site/pack/packer/start/nnn.nvim/lua/nnn.lua:101: in function 'handle_files'
        ...l/share/nvim/site/pack/packer/start/nnn.nvim/lua/nnn.lua:130: in function <...l/share/nvim/site/pack/packer/start/nnn.nvim/lua/nnn.lua:129>

I guess that the issue is that I have nnn replacing netrw. When using :e netrw would open on the new buffer and the selection after would replace netrw.

Opening files in split or vertical split doesn't work

I've tried to setup nnn.nvim to open files in split and vsplit but it doesn't work. Instead 0 selected is logged.
Here is my config

require("nnn").setup({
  picker = {
    cmd = "nnn -o",      
    style = {
      width = 0.4,   
      height = 0.6,   
      border = "rounded"
    },
  },
  auto_open = {
    setup = "explorer",      
    tabpage = "explorer",     
    empty = true,     
    ft_ignore = {      
      "gitcommit",
    }
  },
  auto_close = false,  
  replace_netrw = "picker", 
})
local builtin = require("nnn").builtin
mappings = {
  { "<C-t>", builtin.open_in_tab },       -- open file(s) in tab
  { "<C-s>", builtin.open_in_split },     -- open file(s) in split
  { "<C-v>", builtin.open_in_vsplit },    -- open file(s) in vertical split
  { "<C-p>", builtin.open_in_preview },   -- open file in preview split keeping nnn focused
  { "<C-y>", builtin.copy_to_clipboard }, -- copy file(s) to clipboard
  { "<C-w>", builtin.cd_to_path },        -- cd to file directory
  { "<C-e>", builtin.populate_cmdline },  -- populate cmdline (:) with file(s)
}

`replace_netrw` throws error when configured via Packer

Thanks for the great plugin! I'm a big fan of nnn and am surprised to see how well it works as a file tree.

I'm having a small issue with the replace_netrw setting that I wasn't able to figure out by going through the code. This is the minimal config required to replicate the issue:

vim.cmd("packadd packer.nvim")

require("packer").startup(function()
    use({ "wbthomason/packer.nvim", opt = true })

    use({
        "luukvbaal/nnn.nvim",
        config = function()
            require("nnn").setup({ replace_netrw = "explorer" })
        end,
    })
end)

With this config, opening Neovim with nvim . immediately throws the following error:

Error detected while processing function <SNR>13_VimEnter[10]..<SNR>13_LocalBrowse:
line   32:
E117: Unknown function: netrw#LocalBrowseCheck

The explorer does open correctly, and opening subsequent directories (e.g. with :e .) once Neovim is open doesn't throw any errors.

The strange part is that moving the config outside of packer.startup makes everything work properly:

vim.cmd("packadd packer.nvim")

require("packer").startup(function()
    use({ "wbthomason/packer.nvim", opt = true })

    use("luukvbaal/nnn.nvim")
end)

require("nnn").setup({ replace_netrw = "explorer" })

With this config, nvim . opens the explorer without any errors.

It's also worth mentioning that I get this issue with the latest Neovim master (NVIM v0.6.0-dev+622-gfd6df7481) but not with 0.5.1, which works as expected with both configs. I have no idea what might have changed since 0.5.1 that affects this. It's not a dealbreaker for me, since I can achieve the same result with nvim -c NnnExplorer and everything works once Neovim is actually open, but I figured it might be worth reporting in case there's an easy fix that I'm unaware of.

Setting to delete buffer when not visible

Is there a setting to disable the buffer when it is not visible anymore? I tried several things but none worked:

  1. Set the bufhidden option to delete: even though the option is on and the buffer is hidden it does not get deleted.

  2. Add an autocomand autocmd BufHidden * :lua delete_nnn_hidden()

          function delete_nnn_hidden()
            local bufnr = vim.fn.bufnr(vim.fn.expand("<afile>:p"))
            if vim.api.nvim_buf_get_option(bufnr, "filetype") ~= "nnn" then return end
            -- TODO figure out how to delete the buffer
            -- as the current command does not currently work
            vim.api.nvim_buf_delete(bufnr, { force = true })
          end

    Again, the call to vim.api.nvim_buf_delete(bufnr, { force = true }) does not get rid of the buffer. In fact it does not seem to do anything. When debugging, I added print statements before and after the call to delete to make sure the code reaches these sections. Indeed the code reaches these sections.

How to cd to empty directory?

Hi,
Thanks for this plugin.

looking at this

{ "<C-w>", builtin.cd_to_path },        -- cd to file directory

How to change directory which is empty or directory containing just directories (not regular file) using C-w? This works only when directory has at least a regular file.

Stop nnn from going/showing into the buffer when toggling nnn

When i toggle nnn, it goes to buffer which cause problems when i move between my actual files in buffers. I know i can quit instead of toggling but I don't want to do that because i keep several directories open in nnn contexts (1,2,3,4).

When i toggle terminal it doesn't show into the buffer.
can i make nnn behave like that ?

Allow opening picker at specific directory

With nnn.vim I had a mapping to do the following:

vim.api.nvim_set_keymap("n", "<leader><leader>", "<cmd>NnnPicker %:p:h<CR>", opts)

When I hit my leader key twice it would open NNN in picker mode in the directory of the file I'm currently editing. This is very useful in large code bases where you don't want to traverse the long tree to get to a file which resides adjacent to the one you're editing.

Is this possible? This seems to not work with nnn.nvim

nnn disables numbers and splits have different sizes

Still related to this #65

Since you have disabled having an empty buffer when starting nvim . numbers is set to false on the window level.

If I start nvim . I don't have numbers if I start nvim some-random-file and then open nnn everything is fine.

asciicast

Another thing that I have noticed is that if I do nvim . then open a file, then do a :vsplit the splits aren't identical in size
Screenshot 2022-09-14 at 09 58 13

Icons not showing in vim

Hi,
I have the icons working successfully in terminal nnn,
but for some reason the icons do not display when using
nnn in nvim. Here is a screenshot:
image
I am certain this has to do with enabling 256 color support in neovim,
but can't quite figure it out. Any directions would be helpful!
Thanks,
Amanjit

Flashing text message with mkfifo error

I'm getting following error message when I run my NeoVim:

mkfifo: cannot create file: /var/folders/k7/v1rr45_12xxb2w7jc9bxxv600000gp/T/nvimt20KFb/2-explorer

It flashes too fast, so perhaps there's something else. File already exists, its empty and nnn itself works without issues.

Disabling nnn.nvim helps (that's the only plugin I have that mentions mkfifo).

:version
NVIM v0.6.0-dev
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by antonparkhomenko

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/nix/store/vw381ijplpsy50c80rgbk56fdxjbk53r-neovim-unwrapped-master/share/nvim"
$ mkfifo --version
mkfifo (GNU coreutils) 8.32
Packaged by https://NixOS.org
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.

I run it on macOS with nix.

[Bug] Open file can not return to nnn

Hi.

  • Launching nnn picker
  • Trying to "Open with"
  • Do not insert nothing, then press enter

image

image

Check the bottom of the image, I can not close nnn, or use it.
image

nnn does not close or return to nnn

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.