65 lines
2.3 KiB
Lua
65 lines
2.3 KiB
Lua
return {
|
|
'numToStr/Navigator.nvim',
|
|
config = function()
|
|
local navigator = require('Navigator')
|
|
navigator.setup({
|
|
disable_on_zoom = true,
|
|
})
|
|
|
|
local augroup = vim.api.nvim_create_augroup('mux', { clear = true })
|
|
if vim.env.TMUX ~= nil then
|
|
-- Integrate tmux navigation flag
|
|
local navigation_flag =
|
|
'@vim' .. vim.fn.substitute(vim.env.TMUX_PANE, '%', '\\%', 'g')
|
|
local function set_navigation_flag()
|
|
vim.fn.system('tmux set-window-option ' .. navigation_flag .. ' 1')
|
|
end
|
|
local function unset_navigation_flag()
|
|
-- FIXME: Due to a regression this causes SIGABRT when RelWithDebInfo
|
|
-- vim.fn.system('tmux set-window-option -u ' .. navigation_flag)
|
|
-- https://github.com/neovim/neovim/issues/21856 contains a workaround
|
|
vim.fn.jobstart(
|
|
'tmux set-window-option -u ' .. navigation_flag, { detach = true })
|
|
end
|
|
|
|
-- [Un]set tmux window option to detect when to change pane.
|
|
set_navigation_flag()
|
|
vim.api.nvim_create_autocmd('FocusGained', {
|
|
pattern = '*', group = augroup, callback = set_navigation_flag,
|
|
})
|
|
vim.api.nvim_create_autocmd('VimLeave', {
|
|
pattern = '*', group = augroup, callback = unset_navigation_flag,
|
|
})
|
|
elseif vim.env.TERM_PROGRAM ~= nil and vim.env.TERM_PROGRAM == 'WezTerm' then
|
|
local function set_wezterm_user_var(in_vim)
|
|
local value = in_vim and '1' or '0'
|
|
local template = "\x1b]1337;SetUserVar=%s=%s\a"
|
|
local command = template:format('vim', vim.base64.encode(tostring(value)))
|
|
vim.api.nvim_chan_send(vim.v.stderr, command)
|
|
end
|
|
|
|
vim.api.nvim_create_autocmd({ 'VimEnter', 'VimResume' }, {
|
|
pattern = '*',
|
|
group = augroup,
|
|
callback = function()
|
|
set_wezterm_user_var(true)
|
|
end,
|
|
})
|
|
|
|
vim.api.nvim_create_autocmd({ 'VimLeave', 'VimSuspend' }, {
|
|
pattern = '*',
|
|
group = augroup,
|
|
callback = function()
|
|
set_wezterm_user_var(false)
|
|
end,
|
|
})
|
|
end
|
|
|
|
-- Map nativation bindings
|
|
vim.keymap.set('n', "<C-h>", navigator.left)
|
|
vim.keymap.set('n', "<C-j>", navigator.down)
|
|
vim.keymap.set('n', "<C-k>", navigator.up)
|
|
vim.keymap.set('n', "<C-l>", navigator.right)
|
|
end
|
|
}
|