Git Product home page Git Product logo

vim-kitty-navigator's Introduction

Vim Kitty Navigator

This plugin is a port of Chris Toomey's vim-tmux-navigator plugin. When combined with a set of kitty key bindings and kittens, the plugin will allow you to navigate seamlessly between vim and kitty splits using a consistent set of hotkeys.

NOTE: This requires kitty v0.13.1 or higher.

Usage

This plugin provides the following mappings which allow you to move between Vim panes and kitty splits seamlessly.

  • <ctrl-h> => Left
  • <ctrl-j> => Down
  • <ctrl-k> => Up
  • <ctrl-l> => Right

If you want to use alternate key mappings, see the configuration section below.

Installation

Vim

If you don't have a preferred installation method, I recommend using vim-plug. Assuming you have vim-plug installed and configured, the following steps will install the plugin:

Add the following line to your ~/.vimrc file

Plug 'knubie/vim-kitty-navigator'

Then run

:PlugInstall

kitty

To configure the kitty side of this customization there are three parts:

Add pass_keys.py and neighboring_window.py kittens

Move both pass_keys.py and neighboring_window.py kittens to the ~/.config/kitty/. It can be done manually or with the vim-plug post-update hook

Plug 'knubie/vim-kitty-navigator', {'do': 'cp ./*.py ~/.config/kitty/'}

The pass_keys.py kitten is used to intercept keybindings defined in your kitty conf and "pass" them through to vim when it is focused. The neighboring_window.py kitten is used to send the neighboring_window command (e.g. kitten @ neighboring_window.py right) from vim when you've reached the last pane and are ready to switch to a non-vim kitty window.

Add this snippet to kitty.conf

Add the following to your ~/.config/kitty/kitty.conf file:

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

By default vim-kitty-navigator uses the name of the current foreground process to detect when it is in a (neo)vim session or not. If that doesn't work, (or if you want to support applications other than vim) you can supply a fourth optional argument to the pass_keys.py call in your kitty.conf file to match the process name.

map ctrl+j kitten pass_keys.py neighboring_window bottom ctrl+j "^.* - nvim$"
map ctrl+k kitten pass_keys.py neighboring_window top    ctrl+k "^.* - nvim$"
map ctrl+h kitten pass_keys.py neighboring_window left   ctrl+h "^.* - nvim$"
map ctrl+l kitten pass_keys.py neighboring_window right  ctrl+l "^.* - nvim$"

Make kitty listen to control messages

Start kitty with the listen-on option so that vim can send commands to it.

# For linux only:
kitty -o allow_remote_control=yes --single-instance --listen-on unix:@mykitty

# Other unix systems:
kitty -o allow_remote_control=yes --single-instance --listen-on unix:/tmp/mykitty

Configuration

Custom Key Bindings

If you don't want the plugin to create any mappings, you can use the five provided functions to define your own custom maps. You will need to define custom mappings in your ~/.vimrc as well as update the bindings in kitty to match.

Vim

Add the following to your ~/.vimrc to define your custom maps:

let g:kitty_navigator_no_mappings = 1

nnoremap <silent> {Left-Mapping} :KittyNavigateLeft<cr>
nnoremap <silent> {Down-Mapping} :KittyNavigateDown<cr>
nnoremap <silent> {Up-Mapping} :KittyNavigateUp<cr>
nnoremap <silent> {Right-Mapping} :KittyNavigateRight<cr>

Note Each instance of {Left-Mapping} or {Down-Mapping} must be replaced in the above code with the desired mapping. Ie, the mapping for <ctrl-h> => Left would be created with nnoremap <silent> <c-h> :KittyNavigateLeft<cr>.

Troubleshooting

If you are not able to navigate around vim, try the following:

  1. Add a print statement in pass_keys.py between line 7 and 8 like this:
    def is_window_vim(window, vim_id):
     fp = window.child.foreground_processes
     print(fp)
     return any(re.search(vim_id, p['cmdline'][0], re.I) for p in fp)
  2. Then run kitty in a debug mode:
    kitty --debug-keyboard
    
  3. when the new window is opened, open up vim and some splits and try navigating around. When navigating your vim splits you should see some output similar to this:
    KeyPress matched action: kitten
    [{'pid': 97247, 'cmdline': ['nvim', '.'], 'cwd': '/Users/matt/.config/kitty'}]
    

The 'cmdline': ['nvim', '.'] part will tell us the title of the vim window that we're using to match against in the script. Double check the regex in pass_keys.py, or the regex you passed in to kitty.confg with that title to make sure they match.

vim-kitty-navigator's People

Contributors

fladson avatar idevat avatar knubie avatar lovetocode999 avatar mindtooth avatar mrossinek avatar pedro-hs avatar popkat412 avatar sam-sjs avatar strogonoff avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.