Question about hints kitten: Open code with line number in existing neovim window #8936
-
I have a kitty tab with 2 windows: On top Neovim with my code, below a terminal window which runs a server. What I want to achieve is: In the bottom window hit CTRL + G and select a path:line entry which is being logged. The selected file should be opened in the upper window. Is this possible, if yes - how? Bases on the docs
In both cases, what happens is, that the file is being opened on the correct line but in the wrong (bottom) window. I also tried different matching methods to make sure that I address the correct window. Without mapping I was able to send keys to the upper window and open a file programmatically. Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Use linenum-action=background and have it run a script that uses kitty remote control to do whatever you like with the match result. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for your quick reply. I was not able to do it exactly as suggested, but I found a solution which worked for me. The shortcut: open-in-nvim.py: import re
PATH_LINE_REGEX = re.compile(r'(?P<path>(?:/[^:\s]+)+):(?P<line>\d+)')
def mark(text, args, Mark, extra_cli_args, *a):
for idx, m in enumerate(PATH_LINE_REGEX.finditer(text)):
start, end = m.span()
mark_text = text[start:end].replace('\n', '').replace('\0', '')
yield Mark(idx, start, end, mark_text, m.groupdict())
def handle_result(args, data, target_window_id, boss, extra_cli_args, *a):
w = boss.window_id_map.get(target_window_id)
if w is None:
return
for match, g in zip(data['match'], data['groupdicts']):
path = g.get("path")
line = g.get("line")
if path and line:
nvim_cmd = f":e +{line} {path}\r"
boss.call_remote_control( w, ('send-text', f'--match=neighbor:top', nvim_cmd))
boss.call_remote_control( w, ('focus-window', '--match=neighbor:top')) This solution works for my use case (terminal is always in a window below my code editor). These are the only two windows in a kitty tab. Maybe it helps somebody who wants to achieve something similar. I also tried the suggested The shortcut: open-in-nvim.sh: #!/usr/bin/env zsh
file="$1"
line="$2"
cmd_prefix='\e:e +'
cmd_suffix='\r'
cmd="$cmd_prefix$line $file $cmd_suffix"
{
# working commands
echo "$(date '+%Y-%m-%d %H:%M:%S')\n"
echo file: $file
echo line: $line "\n"
# points to /Applications/kitty.app/Contents/MacOS/kitten
# and not to /usr/local/bin/kitten (my symlink)
which kitten
# this and other kittens do not run
kitten @ ls
# my PATH when running the shell script is different from my terminals PATH.
env
} >~/.config/kitty/output.txt |
Beta Was this translation helpful? Give feedback.
Use linenum-action=background and have it run a script that uses kitty remote control to do whatever you like with the match result.