fm-nvim
fm-nvim copied to clipboard
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?
Try this out...
local function chg_cwd()
local file = vim.fn.readfile("/tmp/fm-nvim")[1]
if vim.fn.isdirectory(file) == 1 then
vim.cmd("cd " .. file)
os.remove("/tmp/fm-nvim")
end
end
require('fm-nvim').setup {
on_close = {
chg_cwd,
}
}
Note that including --print-pwd-as-result
will prevent this from working (but other args are fine)
You can still open files normally but when a directory is chosen, nvim will cd to that directory.
Hmm, that didn't work for me, pressing enter on a dir still opens it instead of changing the working directory.
Here's the installation of fm-nvim by packer
local cfg = function(name)
return string.format('require("cfg.%s")', name)
end
return require('packer').startup(function(use)
use {
'is0n/fm-nvim',
config = cfg('fm'),
}
end)
and here's the config file fm.lua
itself
local ok, fm = pcall(require, 'fm-nvim')
if not ok then
vim.notify('unable to find fm-nvim')
return
end
local function chg_cwd()
local file = vim.fn.readfile('/tmp/fm-nvim')[1]
if vim.fn.isdirectory(file) == 1 then
vim.cmd('cd ' .. file)
os.remove('/tmp/fm-nvim')
end
end
fm.setup {
ui = {
default = 'split',
split = {
size = 50,
},
},
on_close = {
chg_cwd,
},
}
I wasn't sure about the [1]
and I removed it but that help either. I've also disabled netrw and I enabled it but just opens up the directory I select in netrw.
Are you on the latest version of fm-nvim
?
Yeah. I updated fm-nvim to add the latest commit, f75cdf4, but that doesn't help either.
This is me using the chg_cwd
function and it works for me. I'm not sure what's preventing it from working on your machine.
https://user-images.githubusercontent.com/57725322/153719480-720beb05-c0c4-4309-b296-9d2fea2c0bb7.mp4
Here's the my config in case you might help:
local function chg_cwd()
local file = vim.fn.readfile("/tmp/fm-nvim")[1]
if vim.fn.isdirectory(file) == 1 then
vim.cmd("cd " .. file)
os.remove("/tmp/fm-nvim")
end
end
require('fm-nvim').setup{
ui = {
default = "float",
float = {
border = "single",
border_hl = "NONE",
},
},
cmds = {
fzf_cmd = "fzf --preview 'fzf-preview {}' -1 -m",
},
on_close = {
chg_cwd,
}
}
This is the output of nvim -v
:
NVIM v0.6.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@iMac-Pro
From what I can tell, the problem isn't with the chg_cwd
function but rather something with your config.
@is0n while what you are doing is definitely changing the directory, I believe the intended behavior @ayushnix wanted is to change the directory in xplr, not vim. This solution results in a flicker ~~but gets the job done~~. The problem with this solution is that every time you hit enter to on a folder, you have to reenter insert mode with i
.
local function chg_cwd()
local file = vim.fn.readfile("/tmp/fm-nvim")[1]
if vim.fn.isdirectory(file) == 1 then
vim.cmd.Xplr(file)
os.remove("/tmp/fm-nvim")
end
end
require('fm-nvim').setup {
on_close = {
chg_cwd,
},
}