Skip to content

Commit

Permalink
neovim: improve kitty integration
Browse files Browse the repository at this point in the history
  • Loading branch information
geodimm committed Jan 4, 2025
1 parent 5e00169 commit 2f36553
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 19 deletions.
43 changes: 32 additions & 11 deletions kitty/kitty.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ kitty_mod ctrl+shift
scrollback_lines -1

# UI {{{1

# Theme
include themes.conf

Expand All @@ -32,19 +31,12 @@ cursor_shape block
cursor_blink_interval 0
shell_integration no-cursor no-title

# vim-kitty-navigator {{{1
# Remote control{{{1
allow_remote_control yes
listen_on unix:/tmp/mykitty

map ctrl+j kitten pass_keys.py bottom ctrl+j
map ctrl+k kitten pass_keys.py top ctrl+k
map ctrl+h kitten pass_keys.py left ctrl+h
map ctrl+l kitten pass_keys.py right ctrl+l

# Keyboard shortcuts

# Keyboard shortcuts{{{1
copy_on_select yes

macos_option_as_alt yes

# Zoom on a window just like in tmux
Expand All @@ -60,7 +52,6 @@ map cmd+t new_tab_with_cwd
map kitty_mod+x detach_window new-tab

# tmux {{{1

# Jump to tabs
map ctrl+a>1 goto_tab 1
map ctrl+a>2 goto_tab 2
Expand All @@ -85,4 +76,34 @@ map ctrl+a>space next_layout
# Choose layout
map ctrl+a>l kitten choose_layout.py

# kitty-scrollback.nvim {{{1
# Kitten alias
action_alias kitty_scrollback_nvim kitten ~/.local/share/nvim/lazy/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py
# Browse scrollback buffer in nvim
map kitty_mod+h kitty_scrollback_nvim
# Browse output of the last shell command in nvim
map kitty_mod+g kitty_scrollback_nvim --config ksb_builtin_last_cmd_output
# Show clicked command output in nvim
mouse_map ctrl+shift+right press ungrabbed combine : mouse_select_command_output : kitty_scrollback_nvim --config ksb_builtin_last_visited_cmd_output

# smart-splits.nvim {{{1
# Move
map ctrl+h neighboring_window left
map ctrl+j neighboring_window down
map ctrl+k neighboring_window up
map ctrl+l neighboring_window right
map --when-focus-on var:IS_NVIM ctrl+h
map --when-focus-on var:IS_NVIM ctrl+j
map --when-focus-on var:IS_NVIM ctrl+k
map --when-focus-on var:IS_NVIM ctrl+l
# Resize
map alt+h kitten relative_resize.py left 3
map alt+j kitten relative_resize.py down 3
map alt+k kitten relative_resize.py up 3
map alt+l kitten relative_resize.py right 3
map --when-focus-on var:IS_NVIM alt+h
map --when-focus-on var:IS_NVIM alt+j
map --when-focus-on var:IS_NVIM alt+k
map --when-focus-on var:IS_NVIM alt+l

# }}}
45 changes: 43 additions & 2 deletions nvim/lua/plugins/kitty.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
return {
{ 'fladson/vim-kitty' },
{
'knubie/vim-kitty-navigator',
build = 'cp ./*.py ~/.config/kitty/',
'mrjones2014/smart-splits.nvim',
build = './kitty/install-kittens.bash',
opts = {},
config = function()
local keymap = require('utils.keymap')
local smartsplits = require('smart-splits')
keymap.set('n', '<A-h>', smartsplits.resize_left, { desc = 'Increase window width' })
keymap.set('n', '<A-j>', smartsplits.resize_down, { desc = 'Increase window height' })
keymap.set('n', '<A-k>', smartsplits.resize_up, { desc = 'Decrease window height' })
keymap.set('n', '<A-l>', smartsplits.resize_right, { desc = 'Decrease window width' })

keymap.set('n', '<C-h>', smartsplits.move_cursor_left, { desc = 'Go to the left window' })
keymap.set('n', '<C-j>', smartsplits.move_cursor_down, { desc = 'Go to the down window' })
keymap.set('n', '<C-k>', smartsplits.move_cursor_up, { desc = 'Go to the up window' })
keymap.set('n', '<C-l>', smartsplits.move_cursor_right, { desc = 'Go to the right window' })
keymap.set('n', '<C-\\>', smartsplits.move_cursor_previous, { desc = 'Switch to the last window' })

-- keymap.set('n', '<leader><leader>h', smartsplits.swap_buf_left, { desc = 'Swap with left window' })
-- keymap.set('n', '<leader><leader>j', smartsplits.swap_buf_down, { desc = 'Swap with down window' })
-- keymap.set('n', '<leader><leader>k', smartsplits.swap_buf_up, { desc = 'Swap with up window' })
-- keymap.set('n', '<leader><leader>l', smartsplits.swap_buf_right, { desc = 'Swap with right window' })
end,
},
{
'mikesmithgh/kitty-scrollback.nvim',
enabled = true,
lazy = true,
cmd = {
'KittyScrollbackGenerateKittens',
'KittyScrollbackCheckHealth',
'KittyScrollbackGenerateCommandLineEditing',
},
event = { 'User KittyScrollbackLaunch' },
opts = {
status_window = {
show_timer = true,
icons = {
kitty = '󰄛 ',
heart = '󰣐 ',
nvim = '',
},
},
},
},
}
8 changes: 2 additions & 6 deletions nvim/lua/user/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ vim.g.maplocalleader = '\\'

local keymap = require('utils.keymap')

keymap.set('n', '<leader>w', ':w<CR>', { desc = 'Save' })
keymap.set('v', '<leader>w', '<Esc>:w<CR>gv', { desc = 'Save' })
keymap.set('n', '<leader>w', ':w<CR>', { desc = 'Save buffer' })
keymap.set('v', '<leader>w', '<Esc>:w<CR>gv', { desc = 'Save buffer' })
keymap.set('n', '<leader>q', ':q<CR>', { desc = 'Close/Quit' })
keymap.set('v', '<leader>q', '<Esc>:q<CR>gv', { desc = 'Close/Quit' })
keymap.set('n', '<leader><CR>', ':noh<CR>', { desc = 'Turn off search highlights' })
Expand All @@ -21,10 +21,6 @@ keymap.set('n', 'j', "v:count == 0 ? 'gj' : '<Esc>'.v:count.'j'", { desc = 'Go t
keymap.set('n', 'k', "v:count == 0 ? 'gk' : '<Esc>'.v:count.'k'", { desc = 'Go to previous wrapped line', expr = true })

keymap.set('n', '<C-f>', ':vertical wincmd f<CR>', { desc = 'Open file under cursor' })
keymap.set('n', '<M-j>', ':resize -2<CR>', { desc = 'Decrease window height' })
keymap.set('n', '<M-k>', ':resize +2<CR>', { desc = 'Increase window height' })
keymap.set('n', '<M-h>', ':vertical resize -10<CR>', { desc = 'Decrease window width' })
keymap.set('n', '<M-l>', ':vertical resize +10<CR>', { desc = 'Increase window width' })
keymap.set('n', '0', '^', { desc = 'Go to first non-whitespace character of the line' })
keymap.set('n', 'Y', 'y$', { desc = 'Yank til end of line' })
keymap.set('n', 'ZX', ':qa<CR>', { desc = 'Quitall' })
Expand Down
1 change: 1 addition & 0 deletions nvim/lua/utils/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ local function configure_keymaps(bufnr)

keymap.register_group('<leader>g', 'Goto', { buffer = bufnr })
keymap.register_group('<leader>c', 'LSP', { buffer = bufnr })
keymap.register_group('<leader>r', 'Run', { buffer = bufnr })
keymap.register_group('<leader>ce', 'Enable features', { buffer = bufnr })
keymap.register_group('<leader>cd', 'Disable features', { buffer = bufnr })
keymap.register_group('<leader>c', 'LSP', { buffer = bufnr, mode = 'v' })
Expand Down
14 changes: 14 additions & 0 deletions zsh/zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ zstyle ':fzf-tab:*' prefix ''
# Whether to automatically insert a space after the result.
zstyle ':fzf-tab:*' insert-space false

# Command line editing {{{2
autoload -Uz edit-command-line
zle -N edit-command-line

function kitty_scrollback_edit_command_line() {
local VISUAL="${HOME}/.local/share/nvim/lazy/kitty-scrollback.nvim/scripts/edit_command_line.sh"
zle edit-command-line
zle kill-whole-line
}

zle -N kitty_scrollback_edit_command_line
bindkey '^x^e' kitty_scrollback_edit_command_line
bindkey -M vicmd ' ' kitty_scrollback_edit_command_line

# Other {{{2

# disable highlighting of pasted text
Expand Down

0 comments on commit 2f36553

Please sign in to comment.