diff options
| author | pablu <me@pablu.de> | 2026-07-03 11:09:56 +0200 |
|---|---|---|
| committer | pablu <me@pablu.de> | 2026-07-03 11:09:56 +0200 |
| commit | 5650e2f96a619cbbb9b45bc3a8b5e091d22037bb (patch) | |
| tree | a6ac2ae79dcdadaf2d0e0e6fab424db1be0815a2 /dot_config/nvim | |
| parent | bdb56cb1c7733a0dfd04b1dc2e312810a8d088b4 (diff) | |
make hypr-nvim smart-nav better, now use ipc for quicker communication than synth binds
Diffstat (limited to 'dot_config/nvim')
| -rw-r--r-- | dot_config/nvim/init.lua.tmpl | 35 | ||||
| -rw-r--r-- | dot_config/nvim/lua/hypr-nav.lua | 56 | ||||
| -rw-r--r-- | dot_config/nvim/lua/plugins/autoclose.lua | 6 |
3 files changed, 74 insertions, 23 deletions
diff --git a/dot_config/nvim/init.lua.tmpl b/dot_config/nvim/init.lua.tmpl index b04e420..0912ed5 100644 --- a/dot_config/nvim/init.lua.tmpl +++ b/dot_config/nvim/init.lua.tmpl @@ -40,29 +40,8 @@ end, { desc = "Pane split down" }) -- Movement {{ if eq .chezmoi.hostname "gentoo" }} -local function smart_move(direction, vim_cmd) - return function() - local before = vim.api.nvim_get_current_win() - vim.cmd("wincmd " .. vim_cmd) - - if before == vim.api.nvim_get_current_win() then - vim.system({ - "hyprctl", - "dispatch", - string.format( - "hl.dsp.focus({direction = '%s' })", - direction - ) - }) - end - end -end - -vim.keymap.set({ 'n', 'i', 'v' }, '<D-h>', smart_move("left", "h"), { noremap = true, silent = false, desc = "Move to left windows" }); -vim.keymap.set({ 'n', 'i', 'v' }, '<D-l>', smart_move("right", "l"), { noremap = true, silent = false, desc = "Move to right windows" }); -vim.keymap.set({ 'n', 'i', 'v' }, '<D-j>', smart_move("down", "j"), { noremap = true, silent = false, desc = "Move to down window" }); -vim.keymap.set({ 'n', 'i', 'v' }, '<D-k>', smart_move("up", "k"), { noremap = true, silent = false, desc = "Move to up window" }); +require("hypr-nav") {{ end }} @@ -285,3 +264,15 @@ for _, key in ipairs({ }) do vim.keymap.set("n", key, "<Nop>") end + +for _, key in ipairs({ + "<C-z>", + "<Up>", + "<Down>", + "<Left>", + "<Right>", + "<S-Down>", + "<S-Up>" +}) do + vim.keymap.set("i", key, "<Nop>") +end diff --git a/dot_config/nvim/lua/hypr-nav.lua b/dot_config/nvim/lua/hypr-nav.lua new file mode 100644 index 0000000..fc05495 --- /dev/null +++ b/dot_config/nvim/lua/hypr-nav.lua @@ -0,0 +1,56 @@ +local direction_map = { + left = "h", + right = "l", + up = "k", + down = "j" +} + +local runtime_dir = os.getenv("XDG_RUNTIME_DIR") or "/tmp" +local function get_stable_id() + local handle = io.popen("hyprctl activewindow -j 2>/dev/null") + local data = handle:read("*a") + handle:close() + local ok, json = pcall(vim.json.decode, data) + if ok and json and json.stableId then + return tostring(json.stableId) + end + return "unknown" +end + +local stable_id = get_stable_id() + +local socket_path = string.format("%s/nvim-hypr-nav-%s.sock", runtime_dir, stable_id) + +local server = vim.uv.new_pipe(false) +server:bind(socket_path) +server:listen(128, function(err) + if err then vim.notify("hypr-nav: " .. err, vim.log.levels.ERROR) end + + local conn = vim.uv.new_pipe(false) + server:accept(conn) + + conn:read_start(function(err, data) + if not data then + pcall(function() conn:close() end) + return + end + local direction = data:match("nav:(%a+)") + if not direction then + pcall(function() conn:write("invalid\n") end) + + pcall(function() conn:close() end) + return + end + + vim.schedule(function() + local before = vim.api.nvim_get_current_win() + local wincmd_dir = direction_map[direction] or direction:sub(1, 1) + vim.cmd("wincmd " .. wincmd_dir) + local after = vim.api.nvim_get_current_win() + local response = (before == after) and "failed\n" or "success\n" + + pcall(function() conn:write(response) end) + pcall(function() conn:close() end) + end) + end) +end) diff --git a/dot_config/nvim/lua/plugins/autoclose.lua b/dot_config/nvim/lua/plugins/autoclose.lua index cd9e6ce..16ca5f1 100644 --- a/dot_config/nvim/lua/plugins/autoclose.lua +++ b/dot_config/nvim/lua/plugins/autoclose.lua @@ -1,6 +1,10 @@ return { 'm4xshen/autoclose.nvim', config = function() - require('autoclose').setup() + require('autoclose').setup({ + keys = { + ["'"] = { escape = true, close = false, pair = "''" }, + } + }) end } |
