Skip to main content

Cloning and Integration

Kitty lets you clone your current shell environment — working directory, SSH connection, and all — into a new window or tab. Combined with editor integration, this creates a seamless development workflow.

Learning Focus

Use cloning to duplicate your exact shell context, integrate kitty with vim/neovim for image display, and pipe output between applications.

Cloning: Duplicate Your Shell Context

The clone feature duplicates your current shell's working directory and environment into a new kitty window, tab, or OS window.

How to Clone

ShortcutAction
Ctrl+Shift+Alt+lClone current shell into a new window
Ctrl+Shift+Alt+tClone current shell into a new tab
Ctrl+Shift+Alt+wClone current shell into a new OS window

Using Remote Control to Clone

# Clone current window into a new tab with same cwd
kitty @ launch --type=tab --cwd=current

# Clone into a new OS window
kitty @ launch --type=os-window --cwd=current

# Clone with a specific program
kitty @ launch --type=window --cwd=current vim

# Clone with environment variable override
kitty @ launch --type=window --cwd=current --env MODE=debug bash

Clone with Different Layout

# Clone into a split pane (right)
kitty @ launch --type=window --cwd=current --location=hsplit

# Clone into a split pane (bottom)
kitty @ launch --type=window --cwd=current --location=vsplit

Clone Across SSH

When connected via SSH, cloning preserves the SSH connection:

# On a remote server via kitty +kitten ssh:
# Clone will open a new window also connected to the remote
kitty @ launch --type=window --cwd=current

Editing Remote Files Locally

The remote_file kitten lets you open remote files in your local editor:

# Open a remote file locally
kitty +kitten remote_file user@server:/etc/nginx/nginx.conf

# Specify which editor to use
EDITOR=vim kitty +kitten remote_file user@server:/srv/myapp/config.yml

This downloads the file, opens it in your local editor, and uploads the changes when you save and close.

Integration with Vim/Neovim

Image Display in Neovim

With the kitty graphics protocol, neovim can display images inline:

" In your init.vim / init.lua
" Requires a plugin like image.nvim
Plug 'adelarsq/image.nvim'

" Or use kitty's built-in icat
:!kitty +kitten icat --place 80x40@0x0 image.png

Clipboard Integration

Kitty shares clipboard with vim/neovim automatically:

" Yank to kitty's clipboard
"+y " Yank to system clipboard via kitty protocol

" Paste from kitty clipboard in insert mode
<Ctrl+Shift+v>

Configure Neovim for Kitty

~/.config/nvim/init.lua
-- Detect kitty terminal
if vim.env.TERM == 'kitty' then
-- Enable kitty protocol features
vim.g.kitty_term = true

-- Better mouse support
vim.opt.mouse = 'a'

-- True color support
vim.opt.termguicolors = true
end

Integration with File Managers

ranger

~/.config/ranger/rifle.conf
# Open images in kitty using icat
image/*, video/*, font/*, image/x-eps, application/pdf
flag f = kitty +kitten icat --place 80x40@0x0 "$@"

lf (terminal file manager)

~/.config/lf/lfrc
&kitty +kitten icat --clear 2>/dev/null; kitty +kitten icat --place ${w}x${h}@${x}x${y} $f

previewer:
kitty +kitten icat --place ${w}x${h}@${x}x${y} $f

fzf integration

# Use fzf with kitty previews
fzf --preview 'kitty +kitten icat --place 60x30@0x0 {} 2>/dev/null || cat {}'

The Piping Environment

Kitty can launch with piping, connecting output between programs:

# Launch a new window that receives piped input
echo "hello" | kitty @ launch --type=window --stdin-source=@last stdout

# Launch with a command that reads from stdin
kitty @ launch --type=window --stdin-source=@last vim -

Real-World Example: Development Workflow

~/bin/dev-clone.sh
#!/bin/bash
# Clone the current environment into a development layout

SESSION_DIR=$(pwd)
SESSION_NAME=$(basename "$SESSION_DIR")

# Create a tab with the dev layout
kitty @ launch --type=tab --cwd=current --title "$SESSION_NAME:editor"
kitty @ launch --type=window --cwd=current --title "$SESSION_NAME:terminal"
kitty @ launch --type=window --cwd=current --title "$SESSION_NAME:logs"

echo "Development layout created in new tab"

Integration with Other Tools

ToolIntegration MethodUse
Vim/Neovimkitty @ send-text, clipboard sharingEdit in kitty with full graphics support
ranger/lfIcat previewImage preview in file manager
fzfkitty +kitten icat previewFuzzy find with image preview
tmuxkitty @ launch inside tmuxNest kitty features within tmux sessions
SSHkitty +kitten sshRemote shells with full protocol
Gitkitty +kitten diff as difftoolVisual git diffs

Common Pitfalls

PitfallSymptomFix
Clone creates new cwd instead of currentNew window at $HOMEUse --cwd=current explicitly
Remote file kitten asks for password repeatedlySSH auth not cachedUse SSH key-based auth or ssh-agent
Icat in neovim shows garbled outputImage protocol conflictUse --transfer-mode=stream or update neovim plugin
Clone across SSH loses connectionClone creates local windowEnsure kitty +kitten ssh was used to connect
fzf preview shows text instead of imageIcat not in PATHUse full path: /usr/bin/kitty +kitten icat

Hands-On Practice

# Test cloning
kitty @ launch --type=window --cwd=current --title "cloned-shell"

# Test launching with a specific program
kitty @ launch --type=window --cwd=current vim

# Test piping environment
echo "Hello from piped input" | kitty @ launch --type=window --stdin-source=@last cat

# Test remote_file (if you have SSH access to localhost)
echo -e "key=value\nport=8080" > /tmp/test-remote.conf
kitty +kitten remote_file localhost:/tmp/test-remote.conf

# Clean up
rm /tmp/test-remote.conf 2>/dev/null

What's Next