Comments (7)
Hi, Just here in case anyone else is having similar issues with switching and restoring user state for command modes when going in and out of neo-tree with a mouse clicker or other means...
Thnxs!
-- initialize user command-mode state (just for neo-tree)
vim.g.forgetfulme = "n"
return {
"nvim-neo-tree/neo-tree.nvim",
config = function()
require("neo-tree").setup {
...
-- Set-up event handlers to manage and restore user command-mode state
event_handlers = {
{
event = "neo_tree_buffer_enter",
handler = function()
vim.g.forgetfulme = vim.api.nvim_get_mode().mode
if vim.g.forgetfulme == "i" then vim.cmd "stopinsert" end
end,
},
{
event = "neo_tree_buffer_leave",
handler = function()
if vim.g.forgetfulme == "i" then vim.cmd "startinsert" end
vim.g.forgetfulme = vim.api.nvim_get_mode().mode
end,
},
},
}
end,
}
from neo-tree.nvim.
Are you sure you want a plugin to mess around with your mode automatically?
from neo-tree.nvim.
Hi! thnxs @pysan3. Good point.
Perhaps it could be temporarily store the current mode when focus is moved to the neotree window and restore it when it leaves.
Otherwise, having focus while on insert mode has no value...adding an extra unnecessary keystroke to exit to normal mode and do something with it. Makes sense?
from neo-tree.nvim.
I don't think it is the place of any plugin to control the mode. Here's what I would suggest:
- If you are insert mode and done with your edits, exit insert mode. Always.
- If you have a mapping that allows you to switch windows while still in insert mode, you should update that mapping to leave insert mode before switching windows.
- Clicking with a mouse: 😱
- ...but seriously, see 1.
All that being said, the best solution is to create an autocmd to run stopinsert
when you switch windows:
augroup ForgetfulMe
autocmd!
autocmd WinEnter * :stopinsert
augroup end
If someone wanted to put up a PR that does that autocmd specifically for neo-tree windows, I would probably accept it.
from neo-tree.nvim.
If you enter help page I think you'll get the same error. I don't think that is a bug but a feature so same for us.
from neo-tree.nvim.
Ok. Thanks for the response!
I'm pretty new at this so I thought I'd follow up with your suggestion with something like this, but somehow it is not triggering on neovim...may need to spend more time with it...Thnks!
vim.g.forgetfulme = "n"
vim.api.nvim_create_augroup("ForgetfulMe", { clear = true })
vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained" }, {
group = "ForgetfulMe",
pattern = { "neo-tree" },
callback = function()
vim.g.forgetfulme = vim.api.nvim_get_mode().mode
if vim.g.forgetfulme == "i" then
vim.cmd "stopinsert"
end
end,
})
vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost" }, {
group = "ForgetfulMe",
pattern = { "neo-tree" },
callback = function()
if vim.g.forgetfulme == "i" then
vim.cmd "startinsert"
end
vim.g.forgetfulme = vim.api.nvim_get_mode().mode
end,
})
from neo-tree.nvim.
Use neo-tree's event handlers instead of autocmds.
:h neo-tree-events
from neo-tree.nvim.
Related Issues (20)
- FEATURE: Enhancement for the `set_root` command HOT 1
- BUG: Maps to '<C-W>' don't work while fuzzy finding, moving, etc. HOT 3
- BUG: Explorer (Root Dir) doesn't toggle until I've toggled Explorer (cwd) before HOT 1
- Feature Request: Option to disable "Neo-tree Popup" text in prompt HOT 1
- BUG: Buffer with this name already exists when changing other source selection - close and reopen neotree HOT 1
- FEATURE: Default search to visible items
- FEATURE: the cursor automatically focuses on the newly created file
- BUG: LazyVim delete folder
- BUG: can execute neo-tree commands HOT 3
- BUG: close_all() function in event handler does not work when opening in new tab HOT 1
- FEATURE: adding hotkey to switch between open buffers HOT 1
- FEATURE: Relative line number HOT 2
- BUG: Can not open file insde App router with parentheses in its name. (Windows only) HOT 15
- BUG: Yank a file and paste bug
- FEATURE: Allow overriding default window selection logic when opening files HOT 1
- FEATURE: [BUG?] Remove expander when empty folder is detected
- BUG: fuzzy find does not take always_show into account HOT 4
- BUG: Filter doesn't work
- BUG: Custom commands breaks `?` HOT 2
- BUG: can't navigate up when folder removed from under neo-tree
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 neo-tree.nvim.