Comments (9)
Here is how I use tui-nvim
now, replacing the fm-nvim
. It's amazing that I can easily open any command now, not just file managers. Really cool!
" vim/plugin/tui-nvim-cmds.vim
command! Btop :lua require('tui-nvim-cmds').btop()<CR>
command! -nargs=? -complete=file Ranger :lua require('tui-nvim-cmds').ranger(<f-args>)<CR>
command! -nargs=? -complete=file Xplr :lua require('tui-nvim-cmds').xplr(<f-args>)<CR>
-- vim/lua/tui-nvim-cmds.lua
local M = {}
M.btop = function()
local temp = '/tmp/tui-nvim-btop'
require('tui-nvim'):new {
cmd = 'btop',
temp = temp,
width = 1,
height = 1,
}
end
M.ranger = function(path)
local temp = '/tmp/tui-nvim-ranger'
if path == nil or path == '' then
path = vim.fn.expand('%:p')
end
require('tui-nvim'):new {
cmd = 'ranger --choosefiles=' .. temp .. ' --selectfile=' .. vim.fn.fnameescape(path),
temp = temp,
width = 1,
height = 1,
}
end
M.xplr = function(path)
local temp = '/tmp/tui-nvim-xplr'
if path == nil or path == '' then
path = vim.fn.expand('%:p')
end
require('tui-nvim'):new {
cmd = 'xplr ' .. vim.fn.fnameescape(path),
temp = temp,
width = 1,
height = 1,
}
end
return M
from fm-nvim.
I've gotten this to work, although, it is very hacky. 😅
require('fm-nvim').setup{
cmds = {
ranger_cmd = "ranger --selectfile=" .. vim.fn.expand("%:p")
},
on_open = {
function()
require('fm-nvim').setup{
cmds = {
ranger_cmd = "ranger --selectfile=" .. vim.fn.expand("%:p")
},
}
end
}
}
from fm-nvim.
The on_open tip from @is0n doesn't work for me. Don't know what's wrong yet. But I figured out a way to open Ranger & Xplr with current file selected. Try if you think it helps.
This work is amazing! Support for Xplr was definitely a nice touch 👍🏽
In case you might want a cleaner approach to this, consider checking out tui-nvim. The README includes code that opens ranger with the current file selected in just a few lines.
from fm-nvim.
@is0n tui-nvim is cool and more configurable 👍 Looking forward to the user-defined keybinds.
from fm-nvim.
Great package 😍
For those interested, I have solved this for my needs, by creating two keybinds for xplr
.
["<leader>n"] = { "<cmd>Xplr<cr>", desc = "XPLR cwd" },
["<leader>m"] = { "<cmd>Xplr %:p:h<cr>", desc = "XPLR selected file" },
from fm-nvim.
For lf
, we can use require('fm-nvim').Lf(vim.fn.expand('%:p'))
to achieve this.
As for ranger
, maybe we can provide another function parameter for require('fm-nvim').Ranger()
to pass in the selected file so that we can use this lua API to open ranger with current file selected?
from fm-nvim.
It would be best to implement it as an option, like:
require('fm-nvim').setup {
focus_selected_file = true
}
So that new users wouldn't have to know how to set up the on_open
callback.
from fm-nvim.
The on_open
tip from @is0n doesn't work for me. Don't know what's wrong yet. But I figured out a way to open Ranger & Xplr with current file selected. Try if you think it helps.
The lua part:
-- vim/lua/fm_open.lua
-- workaround for selected file issue: https://github.com/is0n/fm-nvim/issues/13
-- command! -nargs=? -complete=dir Ranger :lua require'fm_open'.open('Ranger', '<f-args>')
local M = {}
local fm_nvim = require('fm-nvim')
M.open = function(fn, dir)
if not fm_nvim[fn] then
print('Invalid file manager.')
return false
end
local fpath = vim.fn.expand('%:p')
local override_cmds = {
ranger_cmd = 'ranger',
xplr_cmd = 'xplr'
}
if dir == nil or dir == '' then
-- If no dir arg passed, open fm with current file selected
override_cmds = {
ranger_cmd = 'ranger --selectfile ' .. fpath,
xplr_cmd = 'xplr ' .. fpath
}
fm_nvim.setup { cmds = override_cmds }
-- fn-nvim append '.' to ranger_cmd, which causes Ranger opens 2 paths
-- so we pass the empty '' as dir arg to avoid this behavior
dir = override_cmds[string.lower(fn) .. '_cmd'] and '' or '.'
else
-- If dir passed, undo the fpath cmds
fm_nvim.setup { cmds = override_cmds }
end
fm_nvim[fn](dir)
end
return M
The vim commands part:
" vim/after/plugin/fm-nvim.vim
command! -nargs=? -complete=dir Ranger :lua require'fm_open'.open('Ranger', '<f-args>')
command! -nargs=? -complete=dir Xplr :lua require'fm_open'.open('Xplr', '<f-args>')
Still, I wish fm-nvim got a builtin option for selected file in future, maybe by rewriting the builtin functions like M.Ranger
to do it.
from fm-nvim.
For vifm currently I have this ugly way to open and select file
maps.n["<leader>fe"] = {
function()
local dir_arg = vim.fn.expand("%:p:h")
local current_file = vim.fn.expand("%:p")
if current_file ~= "" then
dir_arg = "--select=" .. current_file
end
require("fm-nvim").Vifm(dir_arg)
end,
}
when you run vifm with only vifm --select=
it will fail. Maybe <fm>_cmd
option in configuration can accept fn
.
from fm-nvim.
Related Issues (20)
- Allow directional splits HOT 1
- Ctrl-j and Ctrl-k not working when using Broot HOT 4
- enter key doesn't work as expected when using xplr HOT 6
- FEATURE:bookmark HOT 2
- LF icons not working HOT 6
- split mode does not work HOT 1
- [Feature] Change current directory HOT 2
- Close buffer along with window HOT 1
- Update buffer on file action with LF HOT 9
- [Feature Request] Allow custom border characters HOT 1
- Joshuto does not work HOT 3
- Make it possible to disable or override a mapping
- lazygit not open file in nvim HOT 3
- Xplr not open file inside already open buffer
- Can it run in the background permanently
- Joshuto does not work HOT 2
- broot just.. doesn't work?
- Add support for Yazi HOT 1
- Cannot open files that contain spaces in file/path name
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fm-nvim.