Update README amd rename zellij to neolij.
5 files changed, 288 insertions(+), 248 deletions(-)
@@ -1,93 +1,133 @@
# zellij.nvim
# Neolij.nvim
A lightweight Neovim plugin that integrates Neovim window navigation with [Zellij](https://zellij.dev/). If Neovim can’t move to another window, it automatically falls back to Zellij actions.
giving you seamless navigation between Neovim splits and Zellij panes/tabs
## Installing
### lazyvim
```lua
{
"y2w8/zellij.nvim",
"y2w8/neolij.nvim",
event = "VeryLazy",
opts = {}, -- Important even if empty
keys = {
-- Window navigation
{ "<C-k>", ":ZellijUp<CR>", mode = { "n", "t" }, desc = "Move up", silent = true },
{ "<C-j>", ":ZellijDown<CR>", mode = { "n", "t" }, desc = "Move down", silent = true },
{ "<C-h>", ":ZellijLeftTab<CR>", mode = { "n", "t" }, desc = "Move left", silent = true },
{ "<C-l>", ":ZellijRightTab<CR>", mode = { "n", "t" }, desc = "Move right", silent = true },
{ "<C-k>", ":NeolijUp<CR>", mode = { "n", "t" }, desc = "Move up", silent = true },
{ "<C-j>", ":NeolijDown<CR>", mode = { "n", "t" }, desc = "Move down", silent = true },
{ "<C-h>", ":NeolijLeftTab<CR>", mode = { "n", "t" }, desc = "Move left", silent = true },
{ "<C-l>", ":NeolijRightTab<CR>", mode = { "n", "t" }, desc = "Move right", silent = true },
-- Tab actions
{ "<leader>zt", ":ZellijNewTab<CR>", desc = "New Zellij Tab", silent = true },
{ "<leader>zr", ":ZellijRenameTab<CR>", desc = "Rename Zellij Tab", silent = true },
{ "<leader>zl", ":ZellijMoveTabLeft<CR>", desc = "Move Tab Left", silent = true },
{ "<leader>zL", ":ZellijMoveTabRight<CR>", desc = "Move Tab Right", silent = true },
{ "<leader>zt", ":NeolijNewTab<CR>", desc = "New Zellij Tab", silent = true },
{ "<leader>zr", ":NeolijRenameTab<CR>", desc = "Rename Zellij Tab", silent = true },
{ "<leader>zl", ":NeolijMoveTabLeft<CR>", desc = "Move Tab Left", silent = true },
{ "<leader>zL", ":NeolijMoveTabRight<CR>", desc = "Move Tab Right", silent = true },
-- Pane actions
{ "<leader>zp", ":ZellijNewPane -d right<CR>", desc = "New Zellij Pane vertical", silent = true },
{ "<leader>zP", ":ZellijNewPane -d down<CR>", desc = "New Zellij Pane horizontal", silent = true },
{ "<leader>zf", ":ZellijNewPane -f<CR>", desc = "New Zellij Floating Pane", silent = true },
{ "<leader>zn", ":ZellijRenamePane<CR>", desc = "Rename Zellij Pane", silent = true },
{ "<leader>zu", ":ZellijMovePaneUp<CR>", desc = "Move Pane Up", silent = true },
{ "<leader>zd", ":ZellijMovePaneDown<CR>", desc = "Move Pane Down", silent = true },
{ "<leader>zh", ":ZellijMovePaneLeft<CR>", desc = "Move Pane Left", silent = true },
{ "<leader>zR", ":ZellijMovePaneRight<CR>", desc = "Move Pane Right", silent = true },
{ "<leader>zp", ":NeolijNewPane -d right<CR>", desc = "New Zellij Pane vertical", silent = true },
{ "<leader>zP", ":NeolijNewPane -d down<CR>", desc = "New Zellij Pane horizontal", silent = true },
{ "<leader>zf", ":NeolijNewPane -f<CR>", desc = "New Zellij Floating Pane", silent = true },
{ "<leader>zn", ":NeolijRenamePane<CR>", desc = "Rename Zellij Pane", silent = true },
{ "<leader>zu", ":NeolijMovePaneUp<CR>", desc = "Move Pane Up", silent = true },
{ "<leader>zd", ":NeolijMovePaneDown<CR>", desc = "Move Pane Down", silent = true },
{ "<leader>zh", ":NeolijMovePaneLeft<CR>", desc = "Move Pane Left", silent = true },
{ "<leader>zR", ":NeolijMovePaneRight<CR>", desc = "Move Pane Right", silent = true },
},
}
```
### Zellij
```kdl
keybinds clear-defaults=true {
shared_except "locked" {
bind "Ctrl left" { MoveFocusOrTab "left"; }
bind "Ctrl down" { MoveFocus "down"; }
bind "Ctrl up" { MoveFocus "up"; }
bind "Ctrl right" { MoveFocusOrTab "right"; }
}
}
plugins {
// Required
autolock location="https://github.com/fresh2dev/zellij-autolock/releases/latest/download/zellij-autolock.wasm" {
// Enabled at start?
is_enabled true
// Lock when any open these programs open.
triggers "nvim|vim"
// Reaction to input occurs after this many seconds. (default=0.3)
// (An existing scheduled reaction prevents additional reactions.)
reaction_seconds "0.3"
// Print to Zellij log? (default=false)
print_to_log false
}
}
// Plugins to load in the background when a new session starts
load_plugins {
autolock
}
```
## Commands
### Navigation
| Command | Function | Description |
| --------------- | --------------- | --------------- |
| `:ZellijUp` | require("zellij").move("up") | Move up |
| `:ZellijDown` | require("zellij").move("down") | Move down |
| `:ZellijLeft` | require("zellij").move("left") | Move left |
| `:ZellijRight` | require("zellij").move("right") | Move right |
| `:ZellijLeftTab` | require("zellij").move_or_tab("left", false) | Move left or switch tab (zellij tabs) |
| `:ZellijRightTab` | require("zellij").move_or_tab("right", false) | Move right or switch tab (zellij tabs) |
| `:ZellijLeftSmart` | require("zellij").move_or_tab("left", true) | Move left or switch tab (nvim tab or zellij tab) |
| `:ZellijRightSmart` | require("zellij").move_or_tab("right", true) | Move right or switch tab (nvim tab or zellij tab) |
| `:NeolijUp` | require("neolij").move("up") | Move up |
| `:NeolijDown` | require("neolij").move("down") | Move down |
| `:NeolijLeft` | require("neolij").move("left") | Move left |
| `:NeolijRight` | require("neolij").move("right") | Move right |
| `:NeolijLeftTab` | require("neolij").move_or_tab("left", false) | Move left or switch tab (zellij tabs) |
| `:NeolijRightTab` | require("neolij").move_or_tab("right", false) | Move right or switch tab (zellij tabs) |
| `:NeolijLeftSmart` | require("neolij").move_or_tab("left", true) | Move left or switch tab (nvim tab or zellij tab) |
| `:NeolijRightSmart` | require("neolij").move_or_tab("right", true) | Move right or switch tab (nvim tab or zellij tab) |
### Tab Managment
> [!TIP]
> If `name` is not provided, you will be prompted for input.
> type this in the terminal to see options
> [!TIP]
> type this in the terminal to see possible arguments
> ```sh
> zellij action new-tab --help
> ```
| Command | Function | Description |
| --------------- | --------------- | --------------- |
| `:ZellijNewTab [args?]` | require("zellij").new_tab(args?) | Create new tab |
| `:ZellijRenameTab [name?]` | require("zellij").rename_tab(name?) | Rename current zellij tab |
| `:ZellijMoveTabLeft` | require("zellij").move_tab("left") | Move tab left |
| `:ZellijMoveTabRight` | require("zellij").move_tab("right") | Move tab right |
| `:NeolijNewTab [args?]` | require("neolij").new_tab(args?) | Create new tab |
| `:NeolijRenameTab [name?]` | require("neolij").rename_tab(name?) | Rename current zellij tab |
| `:NeolijMoveTabLeft` | require("neolij").move_tab("left") | Move tab left |
| `:NeolijMoveTabRight` | require("neolij").move_tab("right") | Move tab right |
### Pane Managment
> [!TIP]
> If `name` is not provided, you will be prompted for input.
> type this in the terminal to see options
> [!TIP]
> type this in the terminal to see possible arguments
> ```sh
> zellij action new-pane --help
> ```
| Command | Function | Description |
| --------------- | --------------- | --------------- |
| `:ZellijNewPane [args?]` | require("zellij").new_pane(args?) | Create new pane |
| `:ZellijRenamePane [name?]` | require("zellij").rename_pane(name?) | Rename current zellij pane |
| `:ZellijMovePaneUp` | require("zellij").move_pane("up") | Move pane up |
| `:ZellijMovePaneDown` | require("zellij").move_pane("down") | Move pane down |
| `:ZellijMovePaneLeft` | require("zellij").move_pane("left") | Move pane left |
| `:ZellijMovePaneRight` | require("zellij").move_pane("right") | Move pane right |
| `:NeolijNewPane [args?]` | require("neolij").new_pane(args?) | Create new pane |
| `:NeolijRenamePane [name?]` | require("neolij").rename_pane(name?) | Rename current zellij pane |
| `:NeolijMovePaneUp` | require("neolij").move_pane("up") | Move pane up |
| `:NeolijMovePaneDown` | require("neolij").move_pane("down") | Move pane down |
| `:NeolijMovePaneLeft` | require("neolij").move_pane("left") | Move pane left |
| `:NeolijMovePaneRight` | require("neolij").move_pane("right") | Move pane right |
### Custom
You can run any zellij action using:
```lua
require("zellij").zellij_action("toggle-fullscreen")
require("neolij").zellij_action("toggle-fullscreen")
```
> [!TIP]
> type this in terminal to see possible action
> type this in terminal to see possible actions
>```sh
>zellij action help
>```
@@ -95,7 +135,7 @@
#### Examples
##### Toggle fullscreen for the current zellij pane
```lua
require("zellij").zellij_action("toggle-fullscreen")
require("neolij").zellij_action("toggle-fullscreen")
```
##### Create a pane while asking for direction and name:
@@ -123,9 +163,9 @@
args = args .. " -n " .. name
end
require("zellij").new_pane({ args = args })
require("neolij").new_pane({ args = args })
end,
{ desc = "Zellij: New pane (ask direction & name)" }
{ desc = "Neolij: New pane (ask direction & name)" }
)
```
@@ -1,0 +1,24 @@
local health = vim.health or require("health")
health.start("neolij.nvim")
-- Neovim version check
if vim.fn.has("nvim-0.9") == 1 then
health.ok("Neovim version >= 0.9")
else
health.error("Neovim 0.9+ is required")
end
-- Zellij executable check
if vim.fn.executable("zellij") == 1 then
health.ok("zellij found in PATH")
else
health.error("zellij not found in PATH")
end
-- check if inside zellij session
if vim.env.ZELLIJ then
health.ok("Running inside Zellij session")
else
health.warn("Not running inside Zellij (plugin will still load, but actions will fail)")
end
@@ -1,0 +1,181 @@
local M = {}
local direction_translation = {
up = "k",
down = "j",
left = "h",
right = "l",
}
-- Run zellij action safely
function M.zellij_action(args)
if not os.getenv("ZELLIJ") then
return
end
vim.fn.system("zellij action " .. args)
if vim.v.shell_error ~= 0 then
error("zellij executable not found in PATH")
end
end
-- Try vim window move, fallback to zellij
local function navigate(direction, vim_key, fallback_zellij, fallback_nvim)
local before = vim.fn.winnr()
vim.cmd("wincmd " .. vim_key)
local after = vim.fn.winnr()
-- If vim didn't move, fallback to zellij
if before == after then
if fallback_nvim then
local current_tab = vim.fn.tabpagenr()
local last_tab = vim.fn.tabpagenr("$")
-- 2. Fallback to Tab switching based on direction
-- We'll use 'l' (right) and 'h' (left) to trigger tab movement
if direction == "right" and current_tab < last_tab then
vim.cmd("tabnext")
return
elseif direction == "left" and current_tab > 1 then
vim.cmd("tabprevious")
return
end
-- If we reach here, neither window nor tab could move: escape to Zellij
M.zellij_action(fallback_zellij .. " " .. direction)
end
end
end
-- Window navigation
function M.move(direction)
navigate(direction, direction_translation[direction], "move-focus")
end
-- Window navigation or tab switch
function M.move_or_tab(direction, fallback_nvim)
navigate(direction, direction_translation[direction], "move-focus-or-tab", fallback_nvim)
end
-- Tab actions
function M.new_tab(opts)
if type(opts) == "table" then
opts = opts.args
end
if opts ~= "" then
M.zellij_action("new-tab " .. opts)
else
M.zellij_action("new-tab")
end
end
function M.rename_tab(name)
if type(name) == "table" then
name = name.args
end
if name == "" or name == nil then
name = vim.fn.input("Tab name: ")
end
if name == nil or name == "" then
vim.notify("No tab name provided", vim.log.levels.ERROR)
return
end
M.zellij_action("rename-tab " .. name)
end
function M.move_tab(direction)
M.zellij_action("move-tab " .. direction)
end
-- Pane actions
function M.new_pane(opts)
if type(opts) == "table" then
opts = opts.args
end
if opts ~= "" then
-- allow custom flags like -d right, -n name, etc
M.zellij_action("new-pane " .. opts)
else
M.zellij_action("new-pane")
end
end
function M.rename_pane(name)
if type(name) == "table" then
name = name.args
end
if name == "" or name == nil then
name = vim.fn.input("Pane name: ")
end
if name == nil or name == "" then
vim.notify("No pane name provided", vim.log.levels.ERROR)
return
end
M.zellij_action("rename-pane " .. name)
end
function M.move_pane(direction)
M.zellij_action("move-pane " .. direction)
end
-- Setup user commands
function M.setup()
vim.api.nvim_create_user_command("NeolijUp", function()
M.move("up")
end, {})
vim.api.nvim_create_user_command("NeolijDown", function()
M.move("down")
end, {})
vim.api.nvim_create_user_command("NeolijLeft", function()
M.move("left")
end, {})
vim.api.nvim_create_user_command("NeolijRight", function()
M.move("right")
end, {})
vim.api.nvim_create_user_command("NeolijLeftTab", function()
M.move_or_tab("left", false)
end, {})
vim.api.nvim_create_user_command("NeolijRightTab", function()
M.move_or_tab("right", false)
end, {})
vim.api.nvim_create_user_command("NeolijLeftSmart", function()
M.move_or_tab("left", true)
end, {})
vim.api.nvim_create_user_command("NeolijRightSmart", function()
M.move_or_tab("right", true)
end, {})
vim.api.nvim_create_user_command("NeolijNewTab", M.new_tab, { nargs = "*" })
vim.api.nvim_create_user_command("NeolijRenameTab", M.rename_tab, { nargs = "?" })
vim.api.nvim_create_user_command("NeolijMoveTabRight", function()
M.move_tab("right")
end, {})
vim.api.nvim_create_user_command("NeolijMoveTabLeft", function()
M.move_tab("left")
end, {})
vim.api.nvim_create_user_command("NeolijNewPane", M.new_pane, { nargs = "*" })
vim.api.nvim_create_user_command("NeolijRenamePane", M.rename_pane, { nargs = "?" })
vim.api.nvim_create_user_command("NeolijMovePaneUp", function()
M.move_pane("up")
end, {})
vim.api.nvim_create_user_command("NeolijMovePaneDown", function()
M.move_pane("down")
end, {})
vim.api.nvim_create_user_command("NeolijMovePaneRight", function()
M.move_pane("right")
end, {})
vim.api.nvim_create_user_command("NeolijMovePaneLeft", function()
M.move_pane("left")
end, {})
end
return M
@@ -1,24 +1,0 @@
local health = vim.health or require("health")
health.start("zellij.nvim")
-- Neovim version check
if vim.fn.has("nvim-0.9") == 1 then
health.ok("Neovim version >= 0.9")
else
health.error("Neovim 0.9+ is required")
end
-- Zellij executable check
if vim.fn.executable("zellij") == 1 then
health.ok("zellij found in PATH")
else
health.error("zellij not found in PATH")
end
-- check if inside zellij session
if vim.env.ZELLIJ then
health.ok("Running inside Zellij session")
else
health.warn("Not running inside Zellij (plugin will still load, but actions will fail)")
end
@@ -1,181 +1,0 @@
local M = {}
local direction_translation = {
up = "k",
down = "j",
left = "h",
right = "l",
}
-- Run zellij action safely
function M.zellij_action(args)
if not os.getenv("ZELLIJ") then
return
end
vim.fn.system("zellij action " .. args)
if vim.v.shell_error ~= 0 then
error("zellij executable not found in PATH")
end
end
-- Try vim window move, fallback to zellij
local function navigate(direction, vim_key, fallback_zellij, fallback_nvim)
local before = vim.fn.winnr()
vim.cmd("wincmd " .. vim_key)
local after = vim.fn.winnr()
-- If vim didn't move, fallback to zellij
if before == after then
if fallback_nvim then
local current_tab = vim.fn.tabpagenr()
local last_tab = vim.fn.tabpagenr("$")
-- 2. Fallback to Tab switching based on direction
-- We'll use 'l' (right) and 'h' (left) to trigger tab movement
if direction == "right" and current_tab < last_tab then
vim.cmd("tabnext")
return -- Success
elseif direction == "left" and current_tab > 1 then
vim.cmd("tabprevious")
return -- Success
end
-- If we reach here, neither window nor tab could move: escape to Zellij
M.zellij_action(fallback_zellij .. " " .. direction)
end
end
end
-- Window navigation
function M.move(direction)
navigate(direction, direction_translation[direction], "move-focus")
end
-- Window navigation or tab switch
function M.move_or_tab(direction, fallback_nvim)
navigate(direction, direction_translation[direction], "move-focus-or-tab", fallback_nvim)
end
-- Tab actions
function M.new_tab(opts)
if type(opts) == "table" then
opts = opts.args
end
if opts ~= "" then
M.zellij_action("new-tab " .. opts)
else
M.zellij_action("new-tab")
end
end
function M.rename_tab(name)
if type(name) == "table" then
name = name.args
end
if name == "" or name == nil then
name = vim.fn.input("Tab name: ")
end
if name == nil or name == "" then
vim.notify("No tab name provided", vim.log.levels.ERROR)
return
end
M.zellij_action("rename-tab " .. name)
end
function M.move_tab(direction)
M.zellij_action("move-tab " .. direction)
end
-- Pane actions
function M.new_pane(opts)
if type(opts) == "table" then
opts = opts.args
end
if opts ~= "" then
-- allow custom flags like -d right, -n name, etc
M.zellij_action("new-pane " .. opts)
else
M.zellij_action("new-pane")
end
end
function M.rename_pane(name)
if type(name) == "table" then
name = name.args
end
if name == "" or name == nil then
name = vim.fn.input("Pane name: ")
end
if name == nil or name == "" then
vim.notify("No pane name provided", vim.log.levels.ERROR)
return
end
M.zellij_action("rename-pane " .. name)
end
function M.move_pane(direction)
M.zellij_action("move-pane " .. direction)
end
-- Setup user commands
function M.setup()
vim.api.nvim_create_user_command("ZellijUp", function()
M.move("up")
end, {})
vim.api.nvim_create_user_command("ZellijDown", function()
M.move("down")
end, {})
vim.api.nvim_create_user_command("ZellijLeft", function()
M.move("left")
end, {})
vim.api.nvim_create_user_command("ZellijRight", function()
M.move("right")
end, {})
vim.api.nvim_create_user_command("ZellijLeftTab", function()
M.move_or_tab("left", false)
end, {})
vim.api.nvim_create_user_command("ZellijRightTab", function()
M.move_or_tab("right", false)
end, {})
vim.api.nvim_create_user_command("ZellijLeftSmart", function()
M.move_or_tab("left", true)
end, {})
vim.api.nvim_create_user_command("ZellijRightSmart", function()
M.move_or_tab("right", true)
end, {})
vim.api.nvim_create_user_command("ZellijNewTab", M.new_tab, { nargs = "*" })
vim.api.nvim_create_user_command("ZellijRenameTab", M.rename_tab, { nargs = "?" })
vim.api.nvim_create_user_command("ZellijMoveTabRight", function()
M.move_tab("right")
end, {})
vim.api.nvim_create_user_command("ZellijMoveTabLeft", function()
M.move_tab("left")
end, {})
vim.api.nvim_create_user_command("ZellijNewPane", M.new_pane, { nargs = "*" })
vim.api.nvim_create_user_command("ZellijRenamePane", M.rename_pane, { nargs = "?" })
vim.api.nvim_create_user_command("ZellijMovePaneUp", function()
M.move_pane("up")
end, {})
vim.api.nvim_create_user_command("ZellijMovePaneDown", function()
M.move_pane("down")
end, {})
vim.api.nvim_create_user_command("ZellijMovePaneRight", function()
M.move_pane("right")
end, {})
vim.api.nvim_create_user_command("ZellijMovePaneLeft", function()
M.move_pane("left")
end, {})
end
return M