Skip to content

Use ctrl b as prefix

Cason Adams edited this page May 26, 2023 · 4 revisions

neovim lazy setup

-- ~/.config/nvim/lua/plugins/navigator.lua

return {
  "numToStr/Navigator.nvim",
  keys = {
    {
      "<C-w>h",
      "<C-\\><C-n><cmd>NavigatorLeft<cr>",
      desc = "NavigatorLeft",
      silent = true,
      mode = { "v", "n", "i", "t" },
    },
    {
      "<C-w>l",
      "<C-\\><C-n><cmd>NavigatorRight<cr>",
      desc = "NavigatorRight",
      silent = true,
      mode = { "v", "n", "i", "t" },
    },
    {
      "<C-w>k",
      "<C-\\><C-n><cmd>NavigatorUp<cr>",
      desc = "NavigatorUp",
      silent = true,
      mode = { "v", "n", "i", "t" },
    },
    {
      "<C-w>j",
      "<C-\\><C-n><cmd>NavigatorDown<cr>",
      desc = "NavigatorDown",
      silent = true,
      mode = { "v", "n", "i", "t" },
    },
  },
  config = function()
    require("Navigator").setup()
  end,
}

wezterm setup

-- ~/.config/wezterm/wezterm.lua

local wezterm = require("wezterm")
local keys = require("keys")

return {
  keys = keys,
  leader = { key = "b", mods = "CTRL" },
}
-- ~/.config/wezterm/keys.lua

local wezterm = require("wezterm")
local act = wezterm.action
local function isVim(pane)
  local tty = pane:get_tty_name()
  if tty == nil then
    return false
  end

  local success, _, _ = wezterm.run_child_process({
    "sh",
    "-c",
    "ps -o state= -o comm= -t"
    .. wezterm.shell_quote_arg(tty)
    .. " | "
    .. "grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?)(diff)?$'",
  })

  return success
end

local function activatePane(window, pane, direction, vim_key)
  if isVim(pane) then
    window:perform_action(
      act.Multiple({
        act.SendKey({ key = "w", mods = "CTRL" }),
        act.SendKey({ key = vim_key }),
      }),
      pane
    )
  else
    window:perform_action(act.ActivatePaneDirection(direction), pane)
  end
end

wezterm.on("ActivatePaneRight", function(window, pane)
  activatePane(window, pane, "Right", "l")
end)
wezterm.on("ActivatePaneLeft", function(window, pane)
  activatePane(window, pane, "Left", "h")
end)
wezterm.on("ActivatePaneUp", function(window, pane)
  activatePane(window, pane, "Up", "k")
end)
wezterm.on("ActivatePaneDown", function(window, pane)
  activatePane(window, pane, "Down", "j")
end)

local keys = {
  { key = "b", mods = "LEADER|CTRL",  action = wezterm.action.SendString("\x02") },
  { key = "h", mods = "LEADER",       action = act.EmitEvent("ActivatePaneLeft") },
  { key = "j", mods = "LEADER",       action = act.EmitEvent("ActivatePaneDown") },
  { key = "k", mods = "LEADER",       action = act.EmitEvent("ActivatePaneUp") },
  { key = "l", mods = "LEADER",       action = act.EmitEvent("ActivatePaneRight") }
}

return keys

tmux setup

# ~/.tmux.conf

is_vim="ps -o state= -o comm= -t '#{pane_tty}' | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?)(diff)?$'"

bind 'h' if-shell "$is_vim" 'send-keys C-w h' 'select-pane -L'
bind 'j' if-shell "$is_vim" 'send-keys C-w j' 'select-pane -D'
bind 'k' if-shell "$is_vim" 'send-keys C-w k' 'select-pane -U'
bind 'l' if-shell "$is_vim" 'send-keys C-w l' 'select-pane -R'