Ubuntu 下 Kitty 终端配置记录
- [Ubuntu 下 Kitty 终端配置记录](#Ubuntu 下 Kitty 终端配置记录)
Ubuntu 下 Kitty 终端配置记录
最近把 Ubuntu 默认终端换成了 Kitty,主要看中它的 GPU 加速、原生分屏、Tab、主题以及丰富的快捷键。
我的环境:
text
Ubuntu 20.04
Kitty 0.47.0
FiraCode Nerd Font Mono
X11 + fcitx
Kitty 配置文件位于:
bash
~/.config/kitty/kitty.conf
可以使用:
bash
vim ~/.config/kitty/kitty.conf
进行修改。
基础配置
conf
# 性能
input_delay 0
repaint_delay 2
sync_to_monitor no
scrollback_lines 10000
cursor_blink_interval 0
# 字体
font_family FiraCode Nerd Font Mono
font_size 12.0
bold_font auto
italic_font auto
# 窗口
remember_window_size yes
initial_window_width 1600
initial_window_height 900
分屏配置
Kitty 想实现类似 tmux / Terminator 的自由分屏,需要使用 splits layout。
conf
enabled_layouts splits
# 左右分屏
map alt+\ launch --location=vsplit
# 上下分屏
map alt+- launch --location=hsplit
# 调整当前窗口大小
map ctrl+shift+r start_resizing_window
# 关闭当前分屏
map ctrl+shift+w close_window
这里需要注意:
text
vsplit → 左右分屏
hsplit → 上下分屏
例如:
text
Alt + \
┌──────────┬──────────┐
│ │ │
│ 1 │ 2 │
│ │ │
└──────────┴──────────┘
而:
text
Alt + -
┌─────────────────────┐
│ 1 │
├─────────────────────┤
│ 2 │
└─────────────────────┘
一个踩过的坑
enabled_layouts 的正确写法是:
conf
enabled_layouts splits
不要写成:
conf
enabled_layouts_splits
否则 Kitty 不会进入 splits 布局,可能出现第一次总是上下分、后续窗口又全部排列在下面的情况。
另外不要写:
conf
launch --type=split
因为 split 并不是 launch --type 的合法参数。
正确写法就是:
conf
launch --location=vsplit
launch --location=hsplit
Tab 配置
conf
map ctrl+shift+t new_tab
map ctrl+tab next_tab
map ctrl+shift+tab previous_tab
map alt+1 goto_tab 1
map alt+2 goto_tab 2
map alt+3 goto_tab 3
map alt+4 goto_tab 4
map alt+5 goto_tab 5
这样可以像浏览器一样使用多个 Tab。
鼠标复制和粘贴
我比较喜欢"选中自动复制,右键直接粘贴":
conf
copy_on_select clipboard
mouse_map right press ungrabbed paste_from_clipboard
操作方式:
text
左键拖动选择文字 → 自动复制
右键 → 粘贴
键盘仍然可以使用:
text
Ctrl + Shift + C 复制
Ctrl + Shift + V 粘贴
URL Hints
Kitty 可以直接识别终端里的 URL:
conf
map ctrl+shift+e kitten hints --type url
按:
text
Ctrl + Shift + E
即可选择并打开当前终端中的链接。
Kitty Themes
Kitty 自带主题选择器:
bash
kitten themes
或者:
bash
kitty +kitten themes
选择主题后,通常会在配置中加入:
conf
# BEGIN_KITTY_THEME
include current-theme.conf
# END_KITTY_THEME
实用默认快捷键
text
Ctrl + Shift + F2 编辑 kitty.conf
Ctrl + Shift + F5 重新加载配置
Ctrl + Shift + F6 查看配置
Ctrl + Shift + G 查看上一条命令输出
Ctrl + Shift + H 查看终端历史
Ctrl + Shift + / 搜索终端历史
Ctrl + Shift + T 新建 Tab
Ctrl + Shift + W 关闭当前 pane
最终配置
目前我的 kitty.conf 核心配置如下:
conf
# Performance
input_delay 0
repaint_delay 2
sync_to_monitor no
scrollback_lines 10000
cursor_blink_interval 0
# Font
font_family FiraCode Nerd Font Mono
font_size 12.0
bold_font auto
italic_font auto
# Window
remember_window_size yes
initial_window_width 1600
initial_window_height 900
# Splits
enabled_layouts splits
map alt+\ launch --location=vsplit
map alt+- launch --location=hsplit
map ctrl+shift+r start_resizing_window
map ctrl+shift+w close_window
# Tabs
map ctrl+shift+t new_tab
map ctrl+tab next_tab
map ctrl+shift+tab previous_tab
map alt+1 goto_tab 1
map alt+2 goto_tab 2
map alt+3 goto_tab 3
map alt+4 goto_tab 4
map alt+5 goto_tab 5
# Clipboard
copy_on_select clipboard
mouse_map right press ungrabbed paste_from_clipboard
# Hints
map ctrl+shift+e kitten hints --type url
# Theme
include current-theme.conf
总结
Kitty 真正比较实用的地方并不只是 GPU 加速,而是它可以把:
text
分屏
Tab
Shell
日志查看
复制粘贴
主题
Hints
整合在一个终端里。
对于日常 Linux 开发来说,一套简单的 splits + Tab + 快捷键 配置就已经非常舒服了。
参考:https://blog.csdn.net/gitblog_00387/article/details/150816121