-
Notifications
You must be signed in to change notification settings - Fork 5
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to change the cwd in nvim when yazi exits? #83
Comments
That's a great idea. I think it could be done if I add a way to know what the last directory was when yazi was quit, and if you then add a custom hook. It sounds good. I actually started adding this feature (last yazi directory) yesterday because I had an idea for another feature. My idea was to add an optional keybinding for closing yazi and grepping the selected directory using telescope or whatever the user wants to do. Let's keep this open. |
By the way, when you change the cwd in nvim, does it cause issues for your other tools such as LSPs or linters, etc? I typically don't change the cwd in my workflow right now, so I don't know. |
I do move around a lot in nvim and it's often convenient to change the cwd.
The yazi site has this code to create a function in .bashrc to do exactly that:
function yy() {
local tmp
tmp="$(mktemp -t "yazi-cwd.XXXXXX")"
yazi "$@" --cwd-file="$tmp"
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
cd -- "$cwd" || exit
fi
rm -f -- "$tmp"
}
…On Wed, May 22, 2024, at 12:34, Mika Vilpas wrote:
That's a great idea. I think it could be done if I add a way to know what the last directory was when yazi was quit, and if you then add a custom hook.
It sounds good. I actually started adding this feature (last yazi directory) yesterday because I had an idea for another feature.
My idea was to add an optional keybinding for closing yazi and grepping the selected directory using telescope or whatever the user wants to do.
Let's keep this open.
—
Reply to this email directly, view it on GitHub <#83 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALLYYRL5TIPBZACMY2YMOVTZDRYFFAVCNFSM6AAAAABIDDQX36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRUGQ3DKMJWGY>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
I use the same thing in my shell, actually. It's really useful. How have you found LSP and other tools to work if you change your cwd in neovim? |
I've had no problems at all. i'm not a programmer, but I use nvim for all my text editing, especially markdown. Accessing yazi from within nvim has been a big help to me.
…On Wed, May 22, 2024, at 14:43, Mika Vilpas wrote:
I use the same thing in my shell, actually. It's really useful.
How have you found LSP and other tools to work if you change your cwd in neovim?
—
Reply to this email directly, view it on GitHub <#83 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALLYYRNJMK2KJJMIT4KH4JDZDSHHRAVCNFSM6AAAAABIDDQX36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRUGY4TSNJXGQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Ok, I have something that might work for you in the PR autolinked above. Here's how I set it up in my config: {
-- "mikavilpas/yazi.nvim",
dir = "~/git/yazi.nvim/",
dependencies = {
"nvim-lua/plenary.nvim",
},
event = "VeryLazy",
keys = {
{
"<up>",
function()
require("yazi").yazi()
end,
desc = "Open the file manager",
},
{
"<s-up>",
function()
require("yazi").yazi(nil, vim.fn.getcwd())
end,
desc = "Open the file manager in the cwd",
},
},
---@type YaziConfig
opts = {
open_for_directories = true,
enable_mouse_support = true,
-- log_level = vim.log.levels.DEBUG,
---@diagnostic disable-next-line: missing-fields
hooks = {
yazi_closed_successfully = function(chosen_file, config, state)
vim.notify(vim.inspect({ chosen_file, state.last_directory.filename }))
end,
},
},
} Basically, you can use the Do you know how to try that out? You can add |
Attached is my yazi config. When I enter yazi and change directory then exit it does not change the cwd. Instead I get this notification.
.{
[2] = "/home/bert/.config/nvim"
}
…On Wed, May 22, 2024, at 20:24, Mika Vilpas wrote:
Ok, I have something that might work for you in the PR autolinked above.
Here's how I set it up in my config:
{
-- "mikavilpas/yazi.nvim",
dir = "~/git/yazi.nvim/",
dependencies = {
"nvim-lua/plenary.nvim",
},
event = "VeryLazy",
keys = {
{
"<up>",
function()
require("yazi").yazi()
end,
desc = "Open the file manager",
},
{
"<s-up>",
function()
require("yazi").yazi(nil, vim.fn.getcwd())
end,
desc = "Open the file manager in the cwd",
},
},
***@***.*** YaziConfig
opts = {
open_for_directories = true,
enable_mouse_support = true,
-- log_level = vim.log.levels.DEBUG,
***@***.*** disable-next-line: missing-fields
hooks = {
yazi_closed_successfully = function(chosen_file, config, state)
vim.notify(vim.inspect({ chosen_file, state.last_directory.filename }))
end,
},
},
}
Basically, you can use the `yazi_closed_successfully` hook. I added a new parameter for information that is known when yazi has closed.
Do you know how to try that out? You can add Cto your lazy.nvim spec if you're using that.
—m
Reply to this email directly, view it on GitHub <#83 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALLYYRJCL6S4I3LELMZW5O3ZDTPHVAVCNFSM6AAAAABIDDQX36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRVGQ3TMNBWG4>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
The directory in the notification is the directory to which I have changed in yazi.
…On Wed, May 22, 2024, at 21:59, Bert wrote:
Attached is my yazi config. When I enter yazi and change directory then exit it does not change the cwd. Instead I get this notification.
.{
[2] = "/home/bert/.config/nvim"
}
On Wed, May 22, 2024, at 20:24, Mika Vilpas wrote:
>
>
> Ok, I have something that might work for you in the PR autolinked above.
>
> Here's how I set it up in my config:
>
> {
> -- "mikavilpas/yazi.nvim",
> dir = "~/git/yazi.nvim/",
> dependencies = {
> "nvim-lua/plenary.nvim",
> },
> event = "VeryLazy",
> keys = {
> {
> "<up>",
> function()
> require("yazi").yazi()
> end,
> desc = "Open the file manager",
> },
> {
> "<s-up>",
> function()
> require("yazi").yazi(nil, vim.fn.getcwd())
> end,
> desc = "Open the file manager in the cwd",
> },
> },
> ***@***.*** YaziConfig
> opts = {
> open_for_directories = true,
> enable_mouse_support = true,
> -- log_level = vim.log.levels.DEBUG,
> ***@***.*** disable-next-line: missing-fields
> hooks = {
> yazi_closed_successfully = function(chosen_file, config, state)
> vim.notify(vim.inspect({ chosen_file, state.last_directory.filename }))
> end,
> },
> },
> }
> Basically, you can use the `yazi_closed_successfully` hook. I added a new parameter for information that is known when yazi has closed.
>
> Do you know how to try that out? You can add Cto your lazy.nvim spec if you're using that.
>
>
>
> —m
> Reply to this email directly, view it on GitHub <#83 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALLYYRJCL6S4I3LELMZW5O3ZDTPHVAVCNFSM6AAAAABIDDQX36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRVGQ3TMNBWG4>.
> You are receiving this because you authored the thread.Message ID: ***@***.***>
>
>
*Attachments:*
• yazi.lua
|
Ok, it seems to be working then. hooks = {
yazi_closed_successfully = function(chosen_file, config, state)
if state.last_directory.filename then
vim.notify("Changing directory to " .. state.last_directory.filename)
vim.fn.chdir(state.last_directory.filename)
end
end,
}, You can remove the notifying once you have made sure it works. |
Works now. Cool!
Only issue is that it changes cwd if I open a file from yazi. Not sure if this is what I want. I do want it to change directory if I exit yazi without picking a file. What behavior do you think is best?
…On Thu, May 23, 2024, at 07:46, Mika Vilpas wrote:
Ok, it seems to be working then.
Try this:
hooks = {
yazi_closed_successfully = function(chosen_file, config, state)
if state.last_directory.filename then
vim.notify("Changing directory to " .. state.last_directory.filename)
vim.fn.chdir(state.last_directory.filename)
end
end,
},
You can remove the notifying once you have made sure it works.
—
Reply to this email directly, view it on GitHub <#83 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALLYYROJTXSXQRGMECT7FHTZDV7BRAVCNFSM6AAAAABIDDQX36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRWGI4DCNRXHA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
I've played with this awhile and I think the behavior I would like is to change CWD if I exit yazi without opening a file. If I open a file and yazi exits, I would not want to change the cwd. Does this make sense? Is it an easy change?
…On Thu, May 23, 2024, at 08:33, Bert wrote:
Works now. Cool!
Only issue is that it changes cwd if I open a file from yazi. Not sure if this is what I want. I do want it to change directory if I exit yazi without picking a file. What behavior do you think is best?
On Thu, May 23, 2024, at 07:46, Mika Vilpas wrote:
>
>
>
>
> Ok, it seems to be working then.
> Try this:
>
>
> hooks = {
> yazi_closed_successfully = function(chosen_file, config, state)
> if state.last_directory.filename then
> vim.notify("Changing directory to " .. state.last_directory.filename)
> vim.fn.chdir(state.last_directory.filename)
> end
> end,
> },
> You can remove the notifying once you have made sure it works.
>
>
>
> —
> Reply to this email directly, view it on GitHub <#83 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALLYYROJTXSXQRGMECT7FHTZDV7BRAVCNFSM6AAAAABIDDQX36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRWGI4DCNRXHA>.
> You are receiving this because you authored the thread.Message ID: ***@***.***>
>
>
|
Ah, good point! I think this does what you want: ---@diagnostic disable-next-line: missing-fields
hooks = {
yazi_closed_successfully = function(chosen_file, config, state)
if chosen_file == nil and state.last_directory.filename then
vim.notify("Changing directory to " .. state.last_directory.filename)
vim.fn.chdir(state.last_directory.filename)
end
end,
}, I am thinking this could be a built in feature in yazi.nvim, but I'm not sure how I could make it happen just yet. If I come up with a way, I'll notify you via this issue, but for now that should work! |
Perfect!
How about a setting on opt for this with these options for no cwd change, cwd change always, cwd change except on file open?
…On Thu, May 23, 2024, at 08:50, Mika Vilpas wrote:
Ah, good point! I think this does what you want:
***@***.*** disable-next-line: missing-fields
hooks = {
yazi_closed_successfully = function(chosen_file, config, state)
if chosen_file == nil and state.last_directory.filename then
vim.notify("Changing directory to " .. state.last_directory.filename)
vim.fn.chdir(state.last_directory.filename)
end
end,
},
I am thinking this could be a built in feature in yazi.nvim, but I'm not sure how I could make it happen just yet. If I come up with a way, I'll notify you via this issue, but for now that should work!
—
Reply to this email directly, view it on GitHub <#83 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALLYYRK3N6PYGUDX4S5VAGDZDWGTZAVCNFSM6AAAAABIDDQX36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRWGM2TONRWGU>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Another idea, pass the options when yazi is called. That way one could have different keymaps for different options.
…On Thu, May 23, 2024, at 09:17, Bert wrote:
Perfect!
How about a setting on opt for this with these options for no cwd change, cwd change always, cwd change except on file open?
On Thu, May 23, 2024, at 08:50, Mika Vilpas wrote:
>
>
> Ah, good point! I think this does what you want:
>
> ***@***.*** disable-next-line: missing-fields
> hooks = {
> yazi_closed_successfully = function(chosen_file, config, state)
> if chosen_file == nil and state.last_directory.filename then
> vim.notify("Changing directory to " .. state.last_directory.filename)
> vim.fn.chdir(state.last_directory.filename)
> end
> end,
> },
> I am thinking this could be a built in feature in yazi.nvim, but I'm not sure how I could make it happen just yet. If I come up with a way, I'll notify you via this issue, but for now that should work!
>
>
>
> —
> Reply to this email directly, view it on GitHub <#83 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALLYYRK3N6PYGUDX4S5VAGDZDWGTZAVCNFSM6AAAAABIDDQX36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRWGM2TONRWGU>.
> You are receiving this because you authored the thread.Message ID: ***@***.***>
>
>
|
Those are good suggestions, thanks. I'd like to keep this open for now. They can probably be implemented, but so many things are open about the near future in terms of possibilities that I don't know what to do yet. |
Thank you so much for what you've already done. Works great for me. As for the rest, not critical... maybe some day/
…On Fri, May 24, 2024, at 17:18, Mika Vilpas wrote:
Those are good suggestions, thanks. I'd like to keep this open for now. They can probably be implemented, but so many things are open about the near future in terms of possibilities that I don't know what to do yet.
—
Reply to this email directly, view it on GitHub <#83 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALLYYRLQLNBPKKE3IWXVZ33ZD5K27AVCNFSM6AAAAABIDDQX36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRZG44TQMRXGI>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I would like to be able to use yazi to change directories in nvim... similar to yy in bashrc. In other words, if in yazi I change the directory to /bin, when I exit yazi the cwd in nvim would change to /bin.
The text was updated successfully, but these errors were encountered: