Compare commits
16
Commits
2593080439
...
91cc2a642d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91cc2a642d | ||
|
|
3ca790ee34 | ||
|
|
366935eeb5 | ||
|
|
8a595653a9 | ||
|
|
346cd5e1ab | ||
|
|
0c192fb18b | ||
|
|
e216aeebae | ||
|
|
ede42a5ac0 | ||
|
|
1d6657d8b8
|
||
|
|
511e9b7bb7
|
||
|
|
2e6cbe6ab1
|
||
|
|
4fa0225331 | ||
|
|
5c588a0918 | ||
|
|
e11d413ed2 | ||
|
|
2bc42accec | ||
|
|
d452fe37f0 |
No files matched your search
@@ -13,6 +13,10 @@ Commands:
|
||||
- `ZellijNavigateDown`
|
||||
- `ZellijNavigateUp`
|
||||
- `ZellijNavigateRight`
|
||||
- `ZellijNavigateLeftTab`
|
||||
- `ZellijNavigateDownTab`
|
||||
- `ZellijNavigateUpTab`
|
||||
- `ZellijNavigateRightTab`
|
||||
|
||||
It also exports the `lua` versions, which you can call like this:
|
||||
|
||||
@@ -20,6 +24,10 @@ It also exports the `lua` versions, which you can call like this:
|
||||
- `require("zellij-nav").down()`
|
||||
- `require("zellij-nav").up()`
|
||||
- `require("zellij-nav").right()`
|
||||
- `require("zellij-nav").left_tab()`
|
||||
- `require("zellij-nav").down_tab()`
|
||||
- `require("zellij-nav").up_tab()`
|
||||
- `require("zellij-nav").right_tab()`
|
||||
|
||||
This is written in the spirit of
|
||||
[vim-tmux-navigator](https://github.com/alexghergh/nvim-tmux-navigation/), but
|
||||
@@ -32,14 +40,14 @@ possible.
|
||||
|
||||
```lua
|
||||
{
|
||||
"https://git.sr.ht/~swaits/zellij-nav.nvim",
|
||||
"swaits/zellij-nav.nvim",
|
||||
lazy = true,
|
||||
event = "VeryLazy",
|
||||
keys = {
|
||||
{ "<c-h>", "<cmd>ZellijNavigateLeft<cr>", { silent = true, desc = "navigate left" } },
|
||||
{ "<c-h>", "<cmd>ZellijNavigateLeftTab<cr>", { silent = true, desc = "navigate left or tab" } },
|
||||
{ "<c-j>", "<cmd>ZellijNavigateDown<cr>", { silent = true, desc = "navigate down" } },
|
||||
{ "<c-k>", "<cmd>ZellijNavigateUp<cr>", { silent = true, desc = "navigate up" } },
|
||||
{ "<c-l>", "<cmd>ZellijNavigateRight<cr>", { silent = true, desc = "navigate right" } },
|
||||
{ "<c-l>", "<cmd>ZellijNavigateRightTab<cr>", { silent = true, desc = "navigate right or tab" } },
|
||||
},
|
||||
opts = {},
|
||||
}
|
||||
@@ -49,15 +57,15 @@ possible.
|
||||
|
||||
```lua
|
||||
{
|
||||
"https://git.sr.ht/~swaits/zellij-nav.nvim",
|
||||
"https://github.com/swaits/zellij-nav.nvim",
|
||||
config = function()
|
||||
require("zellij-nav").setup()
|
||||
|
||||
local map = vim.keymap.set
|
||||
map("n", "<c-h>", "<cmd>ZellijNavigateLeft<cr>", { desc = "navigate left" })
|
||||
map("n", "<c-h>", "<cmd>ZellijNavigateLeftTab<cr>", { desc = "navigate left or tab" })
|
||||
map("n", "<c-j>", "<cmd>ZellijNavigateDown<cr>", { desc = "navigate down" })
|
||||
map("n", "<c-k>", "<cmd>ZellijNavigateUp<cr>", { desc = "navigate up" })
|
||||
map("n", "<c-l>", "<cmd>ZellijNavigateRight<cr>", { desc = "navigate right" })
|
||||
map("n", "<c-l>", "<cmd>ZellijNavigateRightTab<cr>", { desc = "navigate right or tab" })
|
||||
|
||||
end
|
||||
}
|
||||
@@ -66,7 +74,7 @@ possible.
|
||||
### [vim-plug](https://github.com/junegunn/vim-plug)
|
||||
|
||||
```vim
|
||||
Plug 'https://git.sr.ht/~swaits/zellij-nav.nvim'
|
||||
Plug 'https://github.com/swaits/zellij-nav.nvim'
|
||||
lua require("zellij-nav").setup()
|
||||
|
||||
nnoremap <c-h> <cmd>ZellijNavigateLeft<cr>
|
||||
@@ -80,28 +88,25 @@ nnoremap <c-l> <cmd>ZellijNavigateRight<cr>
|
||||
This plugin only covers the Neovim side of things. To achieve a fully seamless
|
||||
workflow, we also need zellij to perform a few tasks.
|
||||
|
||||
In an ideal scenario, we would be able to map `C-hjkl` to function identically
|
||||
in both zellij and Neovim, but unfortunately, that is not possible. Currently,
|
||||
zellij has a few issues that prevent us from reaching that point.
|
||||
|
||||
Firstly, zellij does not allow us to bind `C-j` to any function. This is a
|
||||
[known bug](https://github.com/zellij-org/zellij/issues/2679).
|
||||
|
||||
Secondly, and more importantly, when any of the `C-hjkl` keystrokes are used in
|
||||
zellij, we need to be able to:
|
||||
|
||||
1. Determine if the focused pane is running `nvim`.
|
||||
2. If it is, forward the keystrokes to the application, for example, by using
|
||||
the zellij `Write` action.
|
||||
3. If it is not, directly perform the keystroke action in zellij by using the
|
||||
`MoveFocus <direction>` action.
|
||||
|
||||
Currently, I have not found a way to accomplish this, even through the zellij
|
||||
[plugin system](https://zellij.dev/documentation/plugins).
|
||||
|
||||
Therefore, my configuration uses `A-hjkl` in zellij. As a result, I use
|
||||
`C-hjkl` to navigate within Neovim and to switch from Neovim to another zellij
|
||||
pane. However, if I'm in a non-`nvim` pane, I use `A-hjkl` to change focus.
|
||||
When an instance of neovim is active, change zellij into lock mode using [zellij-autoloc](https://github.com/fresh2dev/zellij-autolock).
|
||||
an example section of the config could be
|
||||
```
|
||||
...
|
||||
autolock location="https://github.com/fresh2dev/zellij-autolock/releases/latest/download/zellij-autolock.wasm" {
|
||||
triggers "nvim|vim|v|nv" // Lock when any open these programs open. They are expected to unlock themselves when closed (e.g., using zellij.vim plugin).
|
||||
watch_triggers "fzf|zoxide|atuin|atac" // Lock when any of these open and monitor until closed.
|
||||
watch_interval "1.0" // When monitoring, check every X seconds.
|
||||
}
|
||||
...
|
||||
```
|
||||
And to achieve unlocking when neovim is unfocused, you can add the following to your neovim config:
|
||||
```lua
|
||||
-- NOTE: Ensures that when exiting NeoVim, Zellij returns to normal mode
|
||||
vim.api.nvim_create_autocmd("VimLeave", {
|
||||
pattern = "*",
|
||||
command = "silent !zellij action switch-mode normal"
|
||||
})
|
||||
```
|
||||
|
||||
## MIT License
|
||||
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
local M = {}
|
||||
|
||||
M.check = function()
|
||||
vim.health.report_start("zellij-nav.nvim")
|
||||
local start = vim.health.start
|
||||
local report_ok = vim.health.ok
|
||||
local report_error = vim.health.error
|
||||
|
||||
start("zellij-nav.nvim")
|
||||
local version = vim.fn.system("zellij --version")
|
||||
if vim.v.shell_error ~= 0 then
|
||||
vim.health.report_error("zellij executable not found in user's path")
|
||||
report_error("zellij executable not found in user's path")
|
||||
else
|
||||
vim.health.report_ok("found zellij version " .. string.gsub(version, "zellij ", ""))
|
||||
report_ok("found zellij version " .. string.gsub(version, "zellij ", ""))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+36
-6
@@ -1,6 +1,15 @@
|
||||
local M = {}
|
||||
|
||||
local function nav(short_direction, direction)
|
||||
local function nav(short_direction, direction, action)
|
||||
-- Use "move-focus" if action is nil.
|
||||
if not action then
|
||||
action = "move-focus"
|
||||
end
|
||||
|
||||
if action ~= "move-focus" and action ~= "move-focus-or-tab" then
|
||||
error("invalid action: " .. action)
|
||||
end
|
||||
|
||||
-- get window ID, try switching windows, and get ID again to see if it worked
|
||||
local cur_winnr = vim.fn.winnr()
|
||||
vim.api.nvim_command("wincmd " .. short_direction)
|
||||
@@ -8,7 +17,7 @@ local function nav(short_direction, direction)
|
||||
|
||||
-- if the window ID didn't change, then we didn't switch
|
||||
if cur_winnr == new_winnr then
|
||||
vim.fn.system("zellij action move-focus " .. direction)
|
||||
vim.fn.system("zellij action " .. action .. " " .. direction)
|
||||
if vim.v.shell_error ~= 0 then
|
||||
error("zellij executable not found in path")
|
||||
end
|
||||
@@ -16,19 +25,35 @@ local function nav(short_direction, direction)
|
||||
end
|
||||
|
||||
function M.up()
|
||||
nav("k", "up")
|
||||
nav("k", "up", nil)
|
||||
end
|
||||
|
||||
function M.down()
|
||||
nav("j", "down")
|
||||
nav("j", "down", nil)
|
||||
end
|
||||
|
||||
function M.right()
|
||||
nav("l", "right")
|
||||
nav("l", "right", nil)
|
||||
end
|
||||
|
||||
function M.left()
|
||||
nav("h", "left")
|
||||
nav("h", "left", nil)
|
||||
end
|
||||
|
||||
function M.up_tab()
|
||||
nav("k", "up", "move-focus-or-tab")
|
||||
end
|
||||
|
||||
function M.down_tab()
|
||||
nav("j", "down", "move-focus-or-tab")
|
||||
end
|
||||
|
||||
function M.right_tab()
|
||||
nav("l", "right", "move-focus-or-tab")
|
||||
end
|
||||
|
||||
function M.left_tab()
|
||||
nav("h", "left", "move-focus-or-tab")
|
||||
end
|
||||
|
||||
-- create our exported setup() function
|
||||
@@ -38,6 +63,11 @@ function M.setup(opts)
|
||||
vim.api.nvim_create_user_command("ZellijNavigateDown", M.down, {})
|
||||
vim.api.nvim_create_user_command("ZellijNavigateLeft", M.left, {})
|
||||
vim.api.nvim_create_user_command("ZellijNavigateRight", M.right, {})
|
||||
|
||||
vim.api.nvim_create_user_command("ZellijNavigateUpTab", M.up_tab, {})
|
||||
vim.api.nvim_create_user_command("ZellijNavigateDownTab", M.down_tab, {})
|
||||
vim.api.nvim_create_user_command("ZellijNavigateLeftTab", M.left_tab, {})
|
||||
vim.api.nvim_create_user_command("ZellijNavigateRightTab", M.right_tab, {})
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in new issue
Block a user