Software Overview
Kate is a cross-platform text editor with many features. Kate also comes with a variety of plugins, including an embedded terminal that lets you launch console commands directly from Kate, powerful search and replace plugins, and a preview plugin that can render MD, HTML, and even SVG files. It supports recovering data after a system crash through swap files, autocompletion with parameter hints, and LSP (Language Server Protocol) for more powerful completion.
Download and Installation
Open the Kate official website, then go to the Get It page. Then install it according to your operating system and preferred installation method.
Usage and Features
Preventing Data Loss with Swap Files
Similar to Vim, Kate writes unsaved changes to a swap file (usually by adding a dot before the original filename and appending .kate-swp). If an unexpected event such as a power failure or program crash occurs, unsaved changes will not be lost the next time it starts.
Syntax Highlighting
Kate supports syntax highlighting for more than 300 languages. Generally, Kate can automatically select the corresponding language for syntax highlighting, but it can occasionally make mistakes. In that case, click the button at the bottom right and select the correct language.
Writing Your Own Syntax Highlighting File
Although Kate supports syntax highlighting for more than 300 languages, some languages are inevitably not covered. In that case, you can write a syntax highlighting file yourself. Kate's own files are located at Syntax Highlighting Powered By KSyntaxHighlighting Framework. Refer to Working with Syntax Highlighting for the syntax, and place the completed file according to Syntax definition files. CoelacanthusHex/dotfiles@80a913c/pam_env.xml provides an example configuration file written by the author.
Switching Languages
Click 设置/Setting in the toolbar above, then click 配置语言/Configure Language, and select a language. Note that an alternative language can also be selected.
Encoding and End-of-Line Characters
Kate can automatically recognize the encoding used by the current file. If it is recognized incorrectly, click the second-to-last button at the bottom right and select the correct encoding.
Kate can also automatically recognize the end-of-line characters used by the current file. If they are recognized incorrectly, click 工具→行尾/Tool→End of line and select the correct end-of-line characters.
Find and Replace
Click 编辑→查找 (shortcut Ctrl+F) in sequence to open the Find page. Click 编辑→替换 (shortcut Ctrl+R) in sequence to open the Find and Replace page. You can also click 搜索与替换 at the bottom left to open the Find and Replace page.
The specific operations are not very different from those in other editors, but some additional features are supported, such as:
- Whether to distinguish between uppercase and lowercase
- Support for regular expressions (including capture groups)
- Scopes ranging from the current file, to multiple files, to the current project
- Selective replacement of search results
Language Server Protocol
Kate has supported an LSP client since 19.12. It initially supported only C/C++, D, Fortran, Go, Latex/BibTeX, OCaml, Python, and Rust. It now supports the languages in the following table:
| Language | LSP Server |
|---|---|
| Bash | bash-language-server |
| LaTeX | texlab |
| BibTeX | texlab |
| C | clangd |
| C++ | clangd |
| D | serve-d |
| Fortran | fortls |
| Go | gopls |
| Haskell | haskell-language-server-wrapper |
| JavaScript | typescript-language-server |
| OCaml | ocamllsp |
| Perl | Perl-LanguageServer |
| Python | pyls |
| Rust | rls |
| TypeScript | typescript-language-server |
| R | RLanguageServer |
| zig | zls |
To enable LSP-related features, go to 设置→配置 Kate, then select 插件 and enable LSP 客户端. When a file in the corresponding language is opened, Kate automatically starts the corresponding LSP Server.
Adding Configuration
In addition, users can write configuration manually. The specific format is:
{
"servers": {
"bibtex": {
"use": "latex",
"highlightingModeRegex": "^BibTeX$"
},
"c": {
"command": ["clangd", "-log=error", "--background-index"],
"commandDebug": ["clangd", "-log=verbose", "--background-index"],
"url": "https://clang.llvm.org/extra/clangd/",
"highlightingModeRegex": "^(C|ANSI C89|Objective-C)$"
},
"cpp": {
"use": "c",
"highlightingModeRegex": "^(C\\+\\+|ISO C\\+\\+|Objective-C\\+\\+)$"
},
"haskell": {
"command": ["haskell-language-server-wrapper", "--lsp"],
"rootIndicationFileNames": ["*.cabal", "stack.yaml", "cabal.project", "package.yaml"],
"url": "https://github.com/haskell/haskell-language-server",
"highlightingModeRegex": "^Haskell$"
},
"latex": {
"command": ["texlab"],
"url": "https://texlab.netlify.com/",
"highlightingModeRegex": "^LaTeX$"
},
"rust": {
"command": ["rls"],
"rootIndicationFileNames": ["Cargo.lock", "Cargo.toml"],
"url": "https://github.com/rust-lang/rls",
"highlightingModeRegex": "^Rust$"
}
}
}
Each item in server represents a language. For that language, command represents the command used to start the LSP Server. command is an array containing the command to execute, split into arguments by spaces; url is the LSP URL; rootIndicationFileNames is used to determine the project root; and highlightingModeRegex matches the name of a syntax highlighting mode to determine which LSP to use. If a use item exists, it means to use the configuration for the language specified by the use item.
This configuration is located at 设置→配置 Kate→LSP 客户端→用户服务器设置. The LSP 客户端 section is visible only after the LSP 客户端 plugin has been enabled in 插件.
Built-in Terminal
Note
The built-in terminal depends on KDE's Konsole1, and Konsole is a package exclusive to * nix. In other words, this feature is unavailable on Windows.
Press F4 to open or close the built-in terminal. You can also click the 终端 button at the bottom left to open it. The current directory of the built-in terminal automatically stays consistent with the current file and changes as you select files. Otherwise, it is not very different from a general terminal.
External Tools
Click 工具→外部工具 to execute an external tool.
Click 工具→外部工具→配置 to configure external tools.
Adding an External Tool
Adding from a Preset Configuration
After entering the configuration page, click 添加→从默认工具添加 at the bottom left, and then click the corresponding tool.
Adding with a Handwritten Configuration
After entering the configuration page, click 添加→添加工具 at the bottom left, and fill it in as prompted. You can refer to this document (English) to write your own external tool configuration. Note that you can click the following icon to view the available variables.

Common External Tools
Compile and Run a Single C++ File
On a * nix system, open any C++ source file, find 编译执行 cpp in the external tools, and click it.
For Windows Users
By default, this tool is unavailable on Windows because its executable file is sh. However, users can modify the tool so that it can be used on Windows.
To modify it, first make sure that a usable C++ compiler is installed on your system. Then add 编译运行 cpp from the default tools, change its 可执行文件 from sh to powershell, and change the arguments to -ExecutionPolicy Bypass -Command "g++ %{Document:FilePath} -o %{Document:FileBaseName}.exe;./%{Document:FileBaseName}.exe" 23.
Git Blame
Open any file, find git blame in the external tools, and click it. A window displaying the result of git blame will open.
Formatting
The formatting feature requires the corresponding package or application to be available. For example, formatting C/C++ requires clang-format to be available. For other languages, users can view the default executable in the external tool configuration for reference.
Open any source file, find 用 xxx 格式化 in the external tools, and click it. In addition, for C/C++ source files, clang-format can format selected text.
Git Blame
To enable this feature, go to 设置→配置 Kate, then select 插件 and enable Git Blame.
After enabling this feature, Kate displays, after each line in a lighter font, when and by whom it was last modified in Git. Moving the mouse over the text displays a pop-up window with the commit's specific information.
Related External Links
- The Kate Handbook
- How to Write Your Own LSP Client Configuration (English)
- How to Write Your Own External Tool Configuration (English)
References and Footnotes
Footnotes
-
In the description of this package in Arch Linux, it optionally depends on
konsole, described asopen a terminal in Kate(open a terminal in Kate). ↩ -
If
g++is not in thePATHenvironment variable, replace it with the compiler's absolute path. ↩ -
Alternatively, if using Clang, replace
g++withclang++. ↩