GithubHelp home page GithubHelp logo

is0n / fm-nvim Goto Github PK

View Code? Open in Web Editor NEW
266.0 3.0 17.0 1.1 MB

πŸ—‚ Neovim plugin that lets you use your favorite terminal file managers (and fuzzy finders) from within Neovim.

License: GNU General Public License v3.0

Lua 100.00%
neovim lua file-manager nvim neovim-plugin ranger lf nnn vifm fzf

fm-nvim's Introduction

GitHub Stars PRs Welcome Last Commit GitHub Open Issues GitHub Closed Issues GitHub License Lua

fm-nvim

fm-nvim is a Neovim plugin that lets you use your favorite terminal file managers (and fuzzy finders) from within Neovim.

Supported File Managers

Supported Fuzzy Finders

Extra

Keep in mind that support for fuzzy finding is quite limited and using seperate plugins would be more practical.

1. Partial Support as files cannot be opened.

Demo and Screenshots:

Demo

Screenshots

Fzf

Fzy

Skim

Fm

Lf

Twf

Fff

Nnn

Vifm

Xplr

Broot

Ranger

Joshuto

Installation:

Configuration:

The following configuration contains the defaults so if you find them satisfactory, there is no need to use the setup function.

require('fm-nvim').setup{
	-- (Vim) Command used to open files
	edit_cmd = "edit",

	-- See `Q&A` for more info
	on_close = {},
	on_open = {},

	-- UI Options
	ui = {
		-- Default UI (can be "split" or "float")
		default = "float",

		float = {
			-- Floating window border (see ':h nvim_open_win')
			border    = "none",

			-- Highlight group for floating window/border (see ':h winhl')
			float_hl  = "Normal",
			border_hl = "FloatBorder",

			-- Floating Window Transparency (see ':h winblend')
			blend     = 0,

			-- Num from 0 - 1 for measurements
			height    = 0.8,
			width     = 0.8,

			-- X and Y Axis of Window
			x         = 0.5,
			y         = 0.5
		},

		split = {
			-- Direction of split
			direction = "topleft",

			-- Size of split
			size      = 24
		}
	},

	-- Terminal commands used w/ file manager (have to be in your $PATH)
	cmds = {
		lf_cmd      = "lf", -- eg: lf_cmd = "lf -command 'set hidden'"
		fm_cmd      = "fm",
		nnn_cmd     = "nnn",
		fff_cmd     = "fff",
		twf_cmd     = "twf",
		fzf_cmd     = "fzf", -- eg: fzf_cmd = "fzf --preview 'bat --style=numbers --color=always --line-range :500 {}'"
		fzy_cmd     = "find . | fzy",
		xplr_cmd    = "xplr",
		vifm_cmd    = "vifm",
		skim_cmd    = "sk",
		broot_cmd   = "broot",
		gitui_cmd   = "gitui",
		ranger_cmd  = "ranger",
		joshuto_cmd = "joshuto",
		lazygit_cmd = "lazygit",
		neomutt_cmd = "neomutt",
        taskwarrior_cmd = "taskwarrior-tui"
	},

	-- Mappings used with the plugin
	mappings = {
		vert_split = "<C-v>",
		horz_split = "<C-h>",
		tabedit    = "<C-t>",
		edit       = "<C-e>",
		ESC        = "<ESC>"
	},

	-- Path to broot config
	broot_conf = vim.fn.stdpath("data") .. "/site/pack/packer/start/fm-nvim/assets/broot_conf.hjson"
}

Usage:

Any of the following commands are fine...

  • Commands
    • :Neomutt
    • :Lazygit
    • :Joshuto
    • :Ranger
    • :Broot
    • :Gitui
    • :Xplr
    • :Vifm
    • :Skim
    • :Nnn
    • :Fff
    • :Twf
    • :Fzf
    • :Fzy
    • :Lf
    • :Fm
    • :TaskWarriorTUI

but you can add a directory path w/ the command (doesn't work with skim, fzy, or fzf).

Example:

:Lf ~/.config/nvim/

Q&A

Q: What if I want to open files in splits or tabs?

A: Use any of the default mappings (unless you've changed them)...

  • <C-h> for horizontal split
  • <C-v> for vertical split
  • <C-e> for normal edit
  • <C-t> for tabs

Q: Can I run a function once exiting or entering the plugin?

A: Yes you can! Use the following code as a guide...

local function yourFunction()
	-- Your code goes here
end

require('fm-nvim').setup{
	-- Runs yourFunction() upon exiting the floating window (can only be a function)
	on_close = { yourFunction },

	-- Runs yourFunction() upon opening the floating window (can only be a function)
	on_open = { yourFunction }
}

Q: What if I want to map <ESC> to close the window?

A: You can do this by mapping <ESC> to whatever closes your file manager (note that this may bring up other issues). This can be done with the following code...

require('fm-nvim').setup{
	mappings = {
		-- Example for Vifm
		ESC        = ":q<CR>"
	}
}

or you could map <ESC> to quit in your file manager...

Example for Lf:

map <esc> :quit

Q: Am I able to have image previews?

A: Yes and no. Assuming you are on Linux, it is possible with the help of tools like Überzug. If you are on Mac or Windows, it is not possible.

Q: Can I use splits instead of a floating window

A: It's possible by changing the "default" option in the "ui" table to "split"

Q: Why isn't my Broot configuration working?

A: In order to support Broot, a custom configuration file is used, however, you can change this by modifying the broot_conf option to your configuration. Just be sure to include the following in your config file...

{
	verbs: [
		{
			key: enter
			execution: ":print_path"
			apply_to: file
		}
	]
}

fm-nvim's People

Contributors

abdallahz3 avatar amiroslaw avatar is0n avatar lvim-tech avatar navinkarkera avatar saccarosium 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

fm-nvim's Issues

Update CWD on file manager close

Hi, great plugin, looking forward to using it.

One feature I would like is to be able to navigate to a folder and exit, with the CWD updated to that folder. Example usage would be navigate to a project root, exit and have CWD in that folder.

broot just.. doesn't work?

window flashes after running the command, and thats it.
using the stock config, yes both broot and br are in my $PATH

Unable to open multiple selected files in Vifm

πŸ‘‹πŸΌ,

Cheers for a great plugin.

Like the title says: it's currently not possible to select multiple files in vifm and open them with fm-nvim.

Steps to reproduce:

  • Execute :Vifm.
  • Press V and select multiple files.
  • Press CR.
  • It only opens the first file and not all files.

split mode does not work

The following error message raises when using split ui mode:

stack traceback:
        [C]: in function 'nvim_buf_set_option'
        ...hare/nvim/site/pack/packer/start/fm-nvim/lua/fm-nvim.lua:85: in function 'postCreation'
        ...hare/nvim/site/pack/packer/start/fm-nvim/lua/fm-nvim.lua:150: in function 'createSplit'
        ...hare/nvim/site/pack/packer/start/fm-nvim/lua/fm-nvim.lua:225: in function 'Vifm'
        [string ":lua"]:1: in main chunk

The problem is - if I understand correctly - that vim.cmd("topleft 24vnew") command in fn-nvim.lua line 148 (in function createSplit) does not return with a buffer number. Adding a line to get buffer number solved the issue on my side:

index 69daf52..842f961 100644
--- a/lua/fm-nvim.lua
+++ b/lua/fm-nvim.lua
@@ -146,6 +146,7 @@ end

 local function createSplit(cmd, suffix)
     M.buf = vim.cmd(config.ui.split.direction .. " " .. config.ui.split.size .. "vnew")
+    M.buf = vim.call("bufnr", "%")
     postCreation(suffix)
     vim.fn.termopen(cmd, {on_exit = on_exit})
     vim.api.nvim_command("startinsert")

nvim version information:

NVIM v0.7.0-dev+1269-g746a29c58
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused
-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=alw
ays -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/ho
me/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/
neovim/neovim/build/include
Compiled by runner@fv-az87-703

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

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/home/runner/work/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Make it possible to disable or override a mapping

I tried to override the vertical split mapping so that it would open the file in a vertical split right away rather than waiting for the user to manually close vifm.

I achieved this with some hacky config:

local function mappings()
	-- make ctrl-v close the file manager and open the file in a split pane. The default behaviour is to only
	-- open the split pane once the flie manager has been closed manually by the user.
	vim.api.nvim_buf_set_keymap(
		0,
		"t",
		"<c-v>",
		'<C-\\><C-n>:lua require("fm-nvim").setMethod("vsplit | edit")<CR>il<cr>',
		{ silent = true }
	)
end

fm_nvim.setup({
	on_open = {
		mappings,
	},
	mappings = {
		-- something that I'm unlikely to press so that it is effectively disabled (these mappings are set after on_open
		-- so it would override the <c-v> defined in mappings if we didn't set it)
		vert_split = "sirerofpuwyq-;ufwyq-;pufyqw-;pufyqw-;",
	},
})

This works, but it's a bit messy. Providing an empty string to, or omitting, the vert_spilt mappings map entry causes it to error or default to <c-v> and because the default mappings are set up after on_open it would override my override.

Adding an override was my use case, but it would also be nice to disable mappings that users have no intention to use as they may conflict with other mappings, and generally create unnecessary noise.

Cannot see image preview

I am using vifm with image previews with the help of two scripts vifmimg (used for preview) and vifmrun (used to run vifm). They are documented here cirala/vifmimg. But I am not able to get previews while using fm-nvim. But floaterm does show a preview.

I have shown the problem in this gif

Peek 2021-11-13 14-52

LF icons not working

Recently my LF icons stopped working with this plugin. They still work outside of vim. Do I need to add any specific configuration to get them working again? Thanks!

Cannot open files that contain spaces in file/path name

Lf cannot open to a file or folder that contains a space in the filename or anywhere in its path

this doesn't work:
:Lf /path/folder one/file one.txt (space in path and file name)
:Lf /path/folder-one/file one.txt (space in filename)

this does:
Lf /path/folder-one/file-one.txt (no spaces)

escaping the spaces doesn't work either

vim.cmd("Lf " .. string.gsub(vim.api.nvim_buf_get_name(0), ' ', '\\ '))

Open browser with current file selected

This is an awesome plugin! I used to have a really big function I wrote that would open ranger, and you have implemented it even better.

I'm not sure how relevant this would be to other file managers, but one thing I had before (as can be seen in the link above, myselectFile argument) is opening ranger to the folder of the current file, with the current file selected.

Is this something possible to do with your plugin? I'm not necessarily requesting a feature as this may only prove to be possible or easy with a subset of your supported browsers (I know it is on vifm as well, as I used to use that one and do the same thing). But I would like some help making this work. Perhaps I can write something to do this in an on_open function?

I was playing around with the lua API and I will definitely be able to at least open the file browser in the current directory, and that will certainly be good enough as a fallback until/unless we can figure out how to also select the current file.

Thank you for your time.

Joshuto does not work

Hi, I'm using this plugin in my neovim on the macos platform. I can open it in using Ranger, but when I run :Joshuto, it doesn't work. The pop-up flashed and then nothing happened.

These are informations of my enviorment:

os: macos 13.4.1
neovim: v0.9.1
isOn/fm-nvim: commit 8e6a770
joshuto: 0.9.5

Xplr not open file inside already open buffer

Hi, this is a great plugin. At this moment i'm using xplr as my regular file manager and I would like to useit inside nvim. But i have same problem that layzigit. The plugin is open the file inside the floating window and not inside already open buffer.
Thanks for help in advance.

Joshuto does not work

Hi, big fan of your plugin here.

I found that Joshuto is not working properly.
Seems like the --choosefiles subcommand it's been deprecated and substituted.

Thanks for such a useful plugin.

Launch in splits

Good day to you!

Is it possible to launch fm in vert or hor split?

Thank you!

when `nushell` is default shell...

i've setted nushell to be my default shell

And after that :Xplr-command just flashing float window and that's it. without any error.
If i override xplr_cmd with zsh -c xplr - it works, but it won't be opening files in neovim.

Is there a way to debug and figure out what's problem with it?

Thank you!

Allow directional splits

I opened another issue with a link to a big vim function in my old vim config. Right above that is this block, unrelated to the other issue:

" Seamless splits
let g:fzf_action = {
	\ 'ctrl-t': 'tab split',
	\ 'ctrl-k': 'leftabove split',
	\ 'ctrl-j': 'rightbelow split',
	\ 'ctrl-h': 'leftabove vsplit',
	\ 'ctrl-l': 'rightbelow vsplit',
\ }

This let me open selected file(s) in fzf in a certain direction. So <ctrl>+hjkl would open the file(s) in the expected cardinal direction when inside fzf. I loved this workflow because I don't always know where I want to open files until I'm about to choose them from a finder.

Despite the above confusingly being about fzf which you also support, my question is actually about the file browsers part of the plugin. If I could achieve this with Ranger+vim I believe it would push me into a state of nerd nirvana. I was never quite able to get it working, though I also didn't try incredibly hard at the time. Do you think this is currently possible to implement in user-land? If not, I believe it could become possible if you opened up some of the mappings or internal API functions like postCreation.

lazygit not open file in nvim

Press e at some lazygit file, neovim will be opened inside lazygit instead open it in original neovim like ranger

Closing command and closing message

I am getting this message when I close vifm

...hare/nvim/site/pack/packer/start/fm-nvim/lua/fm-nvim.lua:43: attempt to concatenate a nil value                            
stack traceback:
^I...hare/nvim/site/pack/packer/start/fm-nvim/lua/fm-nvim.lua:43: in function <...hare/nvim/site/pack/packer/start/fm-nvim/lua/fm-nvim.l
ua:39>

Can be seen here

Peek 2021-11-13 14-52

Also, I cannot close with <Esc> as it sends q which is not my close command.

Can we have an option to define <Esc> ? Like if I want to send qa or Q instead ?

[Feature] Change current directory

Is it possible to change current directory using this plugin? It would be much more convenient using file managers to do this intead of using :cd command.

enter key doesn't work as expected when using xplr

If I run xplr on my terminal with xplr --print-pwd-with-results and press enter on a directory, xplr exits and prints the parent dir and exits. This is also mentioned on the xplr docs.

However, when using xplr with fm-nvim, when I press the enter key on a dir, the dir gets opened in a buffer window and the working directory isn't changed. I have this code in the fm-nvim config

local chg_cwd = function()
  local cwd = io.open('/tmp/fm-nvim', 'r')
  io.input(cwd)
  local pwd = io.read()
  vim.api.nvim_command('cd ' .. pwd)
  os.remove(cwd)
end

require('fm-nvim').setup {
  cmds = {
    xplr_cmd = 'xplr --print-pwd-as-result',
  },
  on_close = {
    chg_cwd,
  },
}

Is there an issue with this config?

Float position or direction

Good day to you!

Is it possible for float-window set position ( [x,y] coordinates of top-left-cornet) or direction (North, NorthEast, East, ...) ?

Thank you!

Opening files only works once

The first time a command is used, the selected file works. This, for whatever reason, doesn't work on the second time a command is used.

Only guess that I have is that the on_exit function isn't being called upon terminal exit as file paths are still being written.

Close buffer along with window

In case of floats:
the window is closed, but the buffer is not completely wiped.
image

buflist contained this buffer:
image


I tried adding a line to `closeCmd()` inside `createWin()`:

image

and it was temporarily fixed, but i dont know if it breaks anything else πŸ˜…

Update buffer on file action with LF

Is there a way to update the buffer when a file action is performed with LF? For example, if I delete or rename a file with LF and then return to the buffer, the old file exists - which will lead to errors if I then try to edit it. Thanks in advance, love this plugin!

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.