index : neolij.nvim
Seamless Neovim/Zellij integration with built-in navigation, pane/tab management, and Lua scripting.
about summary refs log tree commit diff
neolij.nvim / README.md
-rw-r--r-- blob 07e683734811758fc564764bc94a4e604b20ecbc 8389 bytes (plain)
1
# Neolij.nvim
2
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.
3
giving you seamless navigation between Neovim splits and Zellij panes/tabs
4
## Installing
5
### lazyvim
6
```lua
7
{
8
   "y2w8/neolij.nvim",
9
    event = "VeryLazy",
10
    opts = {}, -- Important even if empty
11
    keys = {
12
    -- Window navigation
13
    { "<C-k>", ":NeolijUp<CR>", mode = { "n", "t" }, desc = "Move up", silent = true  },
14
    { "<C-j>", ":NeolijDown<CR>", mode = { "n", "t" }, desc = "Move down", silent = true  },
15
    { "<C-h>", ":NeolijLeftTab<CR>", mode = { "n", "t" }, desc = "Move left", silent = true  },
16
    { "<C-l>", ":NeolijRightTab<CR>", mode = { "n", "t" }, desc = "Move right", silent = true  },
17
18
    -- Tab actions
19
    { "<leader>zt", ":NeolijNewTab<CR>", desc = "New Zellij Tab", silent = true  },
20
    { "<leader>zr", ":NeolijRenameTab<CR>", desc = "Rename Zellij Tab", silent = true  },
21
    { "<leader>zl", ":NeolijMoveTabLeft<CR>", desc = "Move Tab Left", silent = true  },
22
    { "<leader>zL", ":NeolijMoveTabRight<CR>", desc = "Move Tab Right", silent = true  },
23
24
    -- Pane actions
25
    { "<leader>zp", ":NeolijNewPane -d right<CR>", desc = "New Zellij Pane vertical", silent = true  },
26
    { "<leader>zP", ":NeolijNewPane -d down<CR>", desc = "New Zellij Pane horizontal", silent = true  },
27
    { "<leader>zf", ":NeolijNewPane -f<CR>", desc = "New Zellij Floating Pane", silent = true  },
28
    { "<leader>zn", ":NeolijRenamePane<CR>", desc = "Rename Zellij Pane", silent = true  },
29
    { "<leader>zu", ":NeolijMovePaneUp<CR>", desc = "Move Pane Up", silent = true  },
30
    { "<leader>zd", ":NeolijMovePaneDown<CR>", desc = "Move Pane Down", silent = true  },
31
    { "<leader>zh", ":NeolijMovePaneLeft<CR>", desc = "Move Pane Left", silent = true  },
32
    { "<leader>zR", ":NeolijMovePaneRight<CR>", desc = "Move Pane Right", silent = true  },
33
  },
34
}
35
```
36
37
### Zellij
38
39
40
<details>
41
  <summary>Autolock plugin</summary>
42
43
```kdl
44
keybinds clear-defaults=true {
45
    shared_except "locked" {
46
        bind "Ctrl left" { MoveFocusOrTab "left"; }
47
        bind "Ctrl down" { MoveFocus "down"; }
48
        bind "Ctrl up" { MoveFocus "up"; }
49
        bind "Ctrl right" { MoveFocusOrTab "right"; }
50
    }
51
}
52
53
plugins {
54
    // Required
55
    autolock location="https://github.com/fresh2dev/zellij-autolock/releases/latest/download/zellij-autolock.wasm" {
56
        // Enabled at start?
57
        is_enabled true
58
        // Lock when any open these programs open.
59
        triggers "nvim|vim"
60
        // Reaction to input occurs after this many seconds. (default=0.3)
61
        // (An existing scheduled reaction prevents additional reactions.)
62
        reaction_seconds "0.3"
63
        // Print to Zellij log? (default=false)
64
        print_to_log false
65
    }
66
67
    // OR
68
69
    vim_zellij_navigator location="https://github.com/hiasr/vim-zellij-navigator/releases/download/0.3.0/vim-zellij-navigator.wasm"
70
}
71
72
// Plugins to load in the background when a new session starts
73
load_plugins {
74
    autolock
75
}
76
```
77
</details>
78
79
<details>
80
  <summary>vim-zellij-navigator plugin</summary>
81
82
> [!NOTE] 
83
> if you use `vim-zellij-navigator` you have to set `vim_zellij_navigator = true` in the configuration.
84
> ```lua
85
> require("neolij").setup({
86
>   vim_zellij_navigator = true
87
> })
88
> ```
89
90
```kdl
91
keybinds clear-defaults=true {
92
    shared_except "locked" {
93
        bind "Ctrl j" {
94
            MessagePlugin "vim_zellij_navigator" {
95
                name "move_focus";
96
                payload "down";
97
98
                move_mod "ctrl";
99
                use_arrow_keys "false";
100
            };
101
        }
102
103
        bind "Ctrl k" {
104
            MessagePlugin "vim_zellij_navigator" {
105
                name "move_focus";
106
                payload "up";
107
108
                move_mod "ctrl";
109
                use_arrow_keys "false";
110
            };
111
        }
112
113
        bind "Ctrl l" {
114
            MessagePlugin "vim_zellij_navigator" {
115
                name "move_focus_or_tab";
116
                payload "right";
117
118
                move_mod "ctrl"; // Optional, should be added on every command if you want to use it
119
                use_arrow_keys "false";
120
            };
121
        }
122
123
        bind "Alt h" {
124
            MessagePlugin "vim_zellij_navigator" {
125
                name "resize";
126
                payload "left";
127
128
                resize_mod "alt"; 
129
            };
130
        }
131
132
        bind "Alt j" {
133
            MessagePlugin "vim_zellij_navigator" {
134
                name "resize";
135
                payload "down";
136
137
                resize_mod "alt";
138
            };
139
        }
140
141
        bind "Alt k" {
142
            MessagePlugin "vim_zellij_navigator" {
143
                name "resize";
144
                payload "up";
145
146
                resize_mod "alt";
147
            };
148
        }
149
150
        bind "Alt l" {
151
            MessagePlugin "vim_zellij_navigator" {
152
                name "resize";
153
                payload "right";
154
155
                resize_mod "alt";
156
            };
157
        }
158
    }
159
}
160
161
plugins {
162
    vim_zellij_navigator location="https://github.com/hiasr/vim-zellij-navigator/releases/download/0.3.0/vim-zellij-navigator.wasm"
163
}
164
```
165
</details>
166
167
168
169
## Commands
170
### Navigation
171
| Command | Function | Description |
172
| --------------- | --------------- | --------------- |
173
| `:NeolijUp` | require("neolij").move("up") | Move up |
174
| `:NeolijDown` | require("neolij").move("down") | Move down |
175
| `:NeolijLeft` | require("neolij").move("left") | Move left |
176
| `:NeolijRight` | require("neolij").move("right") | Move right |
177
| `:NeolijLeftTab` | require("neolij").move_or_tab("left", false) | Move left or switch tab (zellij tabs) |
178
| `:NeolijRightTab` | require("neolij").move_or_tab("right", false) | Move right or switch tab (zellij tabs) |
179
| `:NeolijLeftSmart` | require("neolij").move_or_tab("left", true) | Move left or switch tab (nvim tab or zellij tab) |
180
| `:NeolijRightSmart` | require("neolij").move_or_tab("right", true) | Move right or switch tab (nvim tab or zellij tab) |
181
182
183
### Tab Managment
184
> [!TIP]
185
> If `name` is not provided, you will be prompted for input.
186
187
> [!TIP]
188
> type this in the terminal to see possible arguments
189
> ```sh
190
> zellij action new-tab --help
191
> ```
192
193
| Command | Function | Description |
194
| --------------- | --------------- | --------------- |
195
| `:NeolijNewTab [args?]` | require("neolij").new_tab(args?) | Create new tab |
196
| `:NeolijRenameTab [name?]` | require("neolij").rename_tab(name?) | Rename current zellij tab  |
197
| `:NeolijMoveTabLeft` | require("neolij").move_tab("left") | Move tab left |
198
| `:NeolijMoveTabRight` | require("neolij").move_tab("right") | Move tab right |
199
200
201
### Pane Managment
202
> [!TIP]
203
> If `name` is not provided, you will be prompted for input. 
204
205
> [!TIP]
206
> type this in the terminal to see possible arguments
207
> ```sh
208
> zellij action new-pane --help
209
> ```
210
211
| Command | Function | Description |
212
| --------------- | --------------- | --------------- |
213
| `:NeolijNewPane [args?]` | require("neolij").new_pane(args?) | Create new pane |
214
| `:NeolijRenamePane [name?]` | require("neolij").rename_pane(name?) | Rename current zellij pane  |
215
| `:NeolijMovePaneUp` | require("neolij").move_pane("up") | Move pane up |
216
| `:NeolijMovePaneDown` | require("neolij").move_pane("down") | Move pane down |
217
| `:NeolijMovePaneLeft` | require("neolij").move_pane("left") | Move pane left |
218
| `:NeolijMovePaneRight` | require("neolij").move_pane("right") | Move pane right |
219
220
### Custom
221
You can run any zellij action using:
222
```lua
223
require("neolij").zellij_action("toggle-fullscreen")
224
```
225
226
> [!TIP]
227
> type this in terminal to see possible actions 
228
>```sh
229
>zellij action help
230
>```
231
232
#### Examples
233
##### Toggle fullscreen for the current zellij pane
234
```lua
235
require("neolij").zellij_action("toggle-fullscreen")
236
```
237
238
##### Create a pane while asking for direction and name:
239
```lua
240
241
vim.keymap.set(
242
  "n",
243
  "<leader>zP",
244
  function()
245
    local dir = vim.fn.input("Direction (up/down/left/right): ")
246
    if dir == "" then
247
      -- default direction 
248
      dir = "right"
249
    end
250
251
    local name = vim.fn.input("Pane name: ")
252
253
    if name == "" then
254
      -- default name 
255
      name = "Pane"
256
    end
257
258
    local args = "-d " .. dir
259
    if name ~= "" then
260
      args = args .. " -n " .. name
261
    end
262
263
    require("neolij").new_pane({ args = args })
264
  end,
265
  { desc = "Neolij: New pane (ask direction & name)" }
266
)
267
268
```