Kate
Software Introduction
Kate is a cross-platform text editor with numerous features. Kate also comes with various plugins, including an embedded terminal that allows you to launch console commands directly from Kate, a powerful search and replace plugin, and a preview plugin that can render MD, HTML, and even SVG files. It supports data recovery via swap files in case of system crashes, auto-completion with parameter hints, and also supports LSP (Language Server Protocol) for more powerful completion.
Download and Installation
You can open the Kate official website, then go to the Get It page. Afterwards, install it according to your operating system and preferred installation method.
Usage and Features
Swap Files to Prevent Data Loss
Similar to Vim, Kate writes unsaved changes to a swap file (typically the original filename prefixed with a dot and suffixed with .kate-swp). In case of unexpected events like power outages or program crashes, unsaved changes will not be lost upon the next startup.
Syntax Highlighting
Kate supports syntax highlighting for over three hundred languages. Generally, Kate can automatically select the corresponding language for syntax highlighting, but occasionally it may make mistakes. In such cases, you can click the button at the bottom right corner and select the correct language.
Writing Your Own Syntax Highlighting Files
Although Kate supports syntax highlighting for over three hundred languages, there might still be languages not covered. In such cases, you can write your own syntax highlighting files. Kate's built-in files are located at Syntax Highlighting Powered By KSyntaxHighlighting Framework. The syntax can be referenced from Working with Syntax Highlighting. Place the written files according to Syntax definition files. CoelacanthusHex/dotfiles@80a913c/pam_env.xml contains a configuration file written by the author for reference.
Switching Language
Click Settings in the top toolbar, then click Configure Language, and select the language. Note that you can choose alternative languages.
Encoding and Line Endings
Kate can automatically detect the encoding used by the current file. If the detection is incorrect, you can click the second-to-last button at the bottom right corner and select the correct encoding.
Simultaneously, Kate can also automatically detect the line endings used by the current file. If the detection is incorrect, you can click Tools→End of line to select the correct line ending.
Find and Replace
Click Edit→Find (shortcut Ctrl+F) to open the "Find" page. Click Edit→Replace (shortcut Ctrl+R) to open the "Find and Replace" page. Alternatively, clicking Search and Replace at the bottom left corner also opens the "Find and Replace" page.
The specific operations are not much different from other editors, but it supports some additional features, such as:
- Case sensitivity
- Support for regular expressions (including capture groups)
- Ranging from the current file to multiple files to the current project
- Selective replacement of search results
Language Server Protocol
Kate has supported LSP Client since version 19.12. Initially, it only supported C/C++, D, Fortran, Go, Latex/BibTeX, OCaml, Python, Rust. Currently, it supports the languages listed in the table below:
| 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 the menu bar Settings→Configure Kate, then select LSP Client in Plugins to enable the features. When opening a file of the corresponding language, Kate will automatically launch the corresponding LSP Server.
Adding Configuration
Additionally, users can manually write configurations. The specific format is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
Each item in servers represents a language. Within a language, command represents the command used to start the LSP Server. command is an array, which is the result of splitting the required command by spaces. url is the LSP's website. rootIndicationFileNames are files used to determine the project root directory. highlightingModeRegex matches the name of a syntax highlighting mode to determine which LSP to use. If a use item exists, it means using the configuration of the language corresponding to the use item.
This configuration item is located at Settings→Configure Kate→LSP Client→User Server Settings. The LSP Client section becomes visible only after enabling the LSP Client plugin in Plugins.
Built-in Terminal
Note
The built-in terminal depends on KDE's Konsole1, and Konsole is a package exclusive to *nix systems. This means this feature is not available on Windows.
Press F4 to open or close the built-in terminal. You can also click the Terminal button at the bottom left corner to open it. The current directory of the built-in terminal automatically matches the current file and changes as you select different files. Otherwise, it is not much different from a general terminal.
External Tools
Click Tools→External Tools to execute.
Click Tools→External Tools→Configure to configure external tools.
Adding External Tools
Adding from Preset Configurations
After entering the configuration page, click Add→Add from Default Tools at the bottom left corner, then click the corresponding tool.
Adding by Writing Configuration Manually
After entering the configuration page, click Add→Add Tool at the bottom left corner, then fill 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 available variables.

Commonly Used External Tools
Compile and Execute a Single C++ File
On *nix systems, open any C++ source file, find Compile and Run cpp in the external tools, and click it.
For Windows Users
By default, because the executable file for this tool is sh, this tool is not available on Windows. However, users can modify this tool to make it usable on Windows systems.
To modify it, first ensure you have a usable C++ compiler in your system. Then add Compile and Run cpp from the default tools. Change the Executable 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 will open showing the result of git blame.
Formatting
The formatting feature requires the corresponding package or application to be available. For example, C/C++ formatting requires clang-format to be available. For other languages, users can check the default executable in the external tool configuration as a reference.
Open any source file, find Format with xxx in the external tools, and click it. Additionally, for C/C++ source files, clang-format can format selected text.
Git Blame
To enable this feature, go to the menu bar Settings→Configure Kate, then select Git Blame in Plugins.
After enabling this feature, Kate will display in a lighter font at the end of each line who last modified it in Git and when. Hovering the mouse over the text will show a tooltip with detailed commit 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
-
In the description of this package in Arch Linux, it optionally depends on
konsole, described asopen a terminal in Kate. ↩ -
If
g++is not in thePATHenvironment variable, change it to the absolute path of the compiler. ↩ -
Alternatively, if using Clang, change
g++toclang++. ↩
本页面最近更新:,更新历史
发现错误?想一起完善? 在 GitHub 上编辑此页!
本页面贡献者:OI-wiki
本页面的全部内容在 CC BY-SA 4.0 和 SATA 协议之条款下提供,附加条款亦可能应用