Compare commits
18
Commits
2593080439
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62a4e161c9
|
||
|
|
59e49cad95
|
||
|
|
91cc2a642d | ||
|
|
3ca790ee34 | ||
|
|
366935eeb5 | ||
|
|
8a595653a9 | ||
|
|
346cd5e1ab | ||
|
|
0c192fb18b | ||
|
|
e216aeebae | ||
|
|
ede42a5ac0 | ||
|
|
1d6657d8b8
|
||
|
|
511e9b7bb7
|
||
|
|
2e6cbe6ab1
|
||
|
|
4fa0225331 | ||
|
|
5c588a0918 | ||
|
|
e11d413ed2 | ||
|
|
2bc42accec | ||
|
|
d452fe37f0 |
No files matched your search
-11
@@ -1,11 +0,0 @@
|
|||||||
image: alpine/edge
|
|
||||||
secrets:
|
|
||||||
- 88cce185-d2ec-4573-9546-e33f36f79bbf
|
|
||||||
sources:
|
|
||||||
- git+ssh://git@git.sr.ht/~swaits/zellij-nav.nvim
|
|
||||||
tasks:
|
|
||||||
- mirror-to-github: |
|
|
||||||
cd ~/zellij-nav.nvim
|
|
||||||
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
|
|
||||||
git remote add github git@github.com:swaits/zellij-nav.nvim.git
|
|
||||||
git push --mirror github
|
|
||||||
@@ -13,6 +13,10 @@ Commands:
|
|||||||
- `ZellijNavigateDown`
|
- `ZellijNavigateDown`
|
||||||
- `ZellijNavigateUp`
|
- `ZellijNavigateUp`
|
||||||
- `ZellijNavigateRight`
|
- `ZellijNavigateRight`
|
||||||
|
- `ZellijNavigateLeftTab`
|
||||||
|
- `ZellijNavigateDownTab`
|
||||||
|
- `ZellijNavigateUpTab`
|
||||||
|
- `ZellijNavigateRightTab`
|
||||||
|
|
||||||
It also exports the `lua` versions, which you can call like this:
|
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").down()`
|
||||||
- `require("zellij-nav").up()`
|
- `require("zellij-nav").up()`
|
||||||
- `require("zellij-nav").right()`
|
- `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
|
This is written in the spirit of
|
||||||
[vim-tmux-navigator](https://github.com/alexghergh/nvim-tmux-navigation/), but
|
[vim-tmux-navigator](https://github.com/alexghergh/nvim-tmux-navigation/), but
|
||||||
@@ -32,14 +40,14 @@ possible.
|
|||||||
|
|
||||||
```lua
|
```lua
|
||||||
{
|
{
|
||||||
"https://git.sr.ht/~swaits/zellij-nav.nvim",
|
"swaits/zellij-nav.nvim",
|
||||||
lazy = true,
|
lazy = true,
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
keys = {
|
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-j>", "<cmd>ZellijNavigateDown<cr>", { silent = true, desc = "navigate down" } },
|
||||||
{ "<c-k>", "<cmd>ZellijNavigateUp<cr>", { silent = true, desc = "navigate up" } },
|
{ "<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 = {},
|
opts = {},
|
||||||
}
|
}
|
||||||
@@ -49,15 +57,15 @@ possible.
|
|||||||
|
|
||||||
```lua
|
```lua
|
||||||
{
|
{
|
||||||
"https://git.sr.ht/~swaits/zellij-nav.nvim",
|
"https://git.swaits.com/swaits/zellij-nav.nvim",
|
||||||
config = function()
|
config = function()
|
||||||
require("zellij-nav").setup()
|
require("zellij-nav").setup()
|
||||||
|
|
||||||
local map = vim.keymap.set
|
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-j>", "<cmd>ZellijNavigateDown<cr>", { desc = "navigate down" })
|
||||||
map("n", "<c-k>", "<cmd>ZellijNavigateUp<cr>", { desc = "navigate up" })
|
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
|
end
|
||||||
}
|
}
|
||||||
@@ -66,7 +74,7 @@ possible.
|
|||||||
### [vim-plug](https://github.com/junegunn/vim-plug)
|
### [vim-plug](https://github.com/junegunn/vim-plug)
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
Plug 'https://git.sr.ht/~swaits/zellij-nav.nvim'
|
Plug 'https://git.swaits.com/swaits/zellij-nav.nvim'
|
||||||
lua require("zellij-nav").setup()
|
lua require("zellij-nav").setup()
|
||||||
|
|
||||||
nnoremap <c-h> <cmd>ZellijNavigateLeft<cr>
|
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
|
This plugin only covers the Neovim side of things. To achieve a fully seamless
|
||||||
workflow, we also need zellij to perform a few tasks.
|
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
|
When an instance of neovim is active, change zellij into lock mode using [zellij-autoloc](https://github.com/fresh2dev/zellij-autolock).
|
||||||
in both zellij and Neovim, but unfortunately, that is not possible. Currently,
|
an example section of the config could be
|
||||||
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
|
autolock location="https://github.com/fresh2dev/zellij-autolock/releases/latest/download/zellij-autolock.wasm" {
|
||||||
[known bug](https://github.com/zellij-org/zellij/issues/2679).
|
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.
|
||||||
Secondly, and more importantly, when any of the `C-hjkl` keystrokes are used in
|
watch_interval "1.0" // When monitoring, check every X seconds.
|
||||||
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
|
And to achieve unlocking when neovim is unfocused, you can add the following to your neovim config:
|
||||||
the zellij `Write` action.
|
```lua
|
||||||
3. If it is not, directly perform the keystroke action in zellij by using the
|
-- NOTE: Ensures that when exiting NeoVim, Zellij returns to normal mode
|
||||||
`MoveFocus <direction>` action.
|
vim.api.nvim_create_autocmd("VimLeave", {
|
||||||
|
pattern = "*",
|
||||||
Currently, I have not found a way to accomplish this, even through the zellij
|
command = "silent !zellij action switch-mode normal"
|
||||||
[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.
|
|
||||||
|
|
||||||
## MIT License
|
## MIT License
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.check = function()
|
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")
|
local version = vim.fn.system("zellij --version")
|
||||||
if vim.v.shell_error ~= 0 then
|
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
|
else
|
||||||
vim.health.report_ok("found zellij version " .. string.gsub(version, "zellij ", ""))
|
report_ok("found zellij version " .. string.gsub(version, "zellij ", ""))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+36
-6
@@ -1,6 +1,15 @@
|
|||||||
local M = {}
|
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
|
-- get window ID, try switching windows, and get ID again to see if it worked
|
||||||
local cur_winnr = vim.fn.winnr()
|
local cur_winnr = vim.fn.winnr()
|
||||||
vim.api.nvim_command("wincmd " .. short_direction)
|
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 the window ID didn't change, then we didn't switch
|
||||||
if cur_winnr == new_winnr then
|
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
|
if vim.v.shell_error ~= 0 then
|
||||||
error("zellij executable not found in path")
|
error("zellij executable not found in path")
|
||||||
end
|
end
|
||||||
@@ -16,19 +25,35 @@ local function nav(short_direction, direction)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.up()
|
function M.up()
|
||||||
nav("k", "up")
|
nav("k", "up", nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.down()
|
function M.down()
|
||||||
nav("j", "down")
|
nav("j", "down", nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.right()
|
function M.right()
|
||||||
nav("l", "right")
|
nav("l", "right", nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.left()
|
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
|
end
|
||||||
|
|
||||||
-- create our exported setup() function
|
-- 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("ZellijNavigateDown", M.down, {})
|
||||||
vim.api.nvim_create_user_command("ZellijNavigateLeft", M.left, {})
|
vim.api.nvim_create_user_command("ZellijNavigateLeft", M.left, {})
|
||||||
vim.api.nvim_create_user_command("ZellijNavigateRight", M.right, {})
|
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
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
Reference in new issue
Block a user