I like the Kate editor, so I write this post to list all of my settings to make it usable as a data science environment (for R / Python). This guide relies on the VI editing mode of Kate, which may not be for everyone (however, I am a VI noob myself). I explain some optimizations for writing in Kate (e.g., filling paragraphs) and how to submit code to the (R or Python) console.
These are my (non-data-science) related configurations.
Configure Kate -> Editing
CTRL-f
to “Search and Replace” rather than ordinary Search. This even has some advantages, as this search option directly shows all matches and can also be used to search in multiple files.As I prefer hard versus soft linebreaks when writing, for example R Markdown documents, I need some functionality for hard line breaks. In my opinion, emacs has the best option for hard line breaks with the fill paragraph option. I have not seen this option in any other text editor so far. However, I found out how to emulate this functionality in Kate:
Configure Kate -> Editing -> VI editing
<a-q>
: mz { j V } k gq `z. This adds the fill paragraph option to ALT-Q
key binding in VI normal modei
around the command to leave and re-enter visual mode.Settings -> Configure Shortcuts -> Apply Word Wrap
), e.g. use CTRL-ALT-Q
One problem is that this keybinding sets a vim mark, which in turn converts to a Kate bookmark. So I added a Kate keybinding for clearing all bookmarks (CRTL-ALT-M), which can be appended to the above command. This implies that the fill paragraph command removes all of your marks, but I guess this is not terribly important (for me, at least).
This way, I can mostly reproduce the emacs fill paragraph command. There is one caveat however: If I use fill paragraph in insert mode and the cursor is at the end of the current line, the cursor sometimes moves back one character. Maybe this can be fixed somehow, not sure.
Documentation -> Annotation
and Comment Variable
to something more colorful (something that is easily recognized among grey comment font)Kate requires that the KDE terminal konsole
is available. On non-KDE desktops this may need to be installed, on Ubuntu for example with.
$ sudo apt install konsole
Next, some configurations for the terminal.
Synchronize Terminal with Current Document
in the settings. This is crucial to prevent the terminal trying to cd
to the directory of every document that is opened, which raises an erron when you are in the python or R console.Edit current profile
to change the appearance of the terminal to your liking. In the terminal, we will start the R or python consoles, as explained below.In this section, I describe the functionalities of Kate making it useful as a Data Science environment.
For python, I use the ipython konsole, and for R, I use radian. Then, we have an “intelligent” console, while the editor itself is still rather “dumb”. For example, in RStudio or rkward the editor understands the R environment and may offer completion suggestions for function arguments. When using Kate, we do not have this convenience.
To submit code to the console via CRTL-Shift-C, add the following VI keybindings:
<s-c-c>
: } V { y <f4> <s-c-v> <cr> <f4> <esc> }
<s-c-c>
: <esc> } V { y <f4> <s-c-v> <cr> <f4> <esc> } i
<s-c-c>
: y <f4> <s-c-v> <cr> <f4> <esc>
This way, CTRL-Shift-C will execute either the current (or following) code block or, when in visual mode, the code selection.
To send the entire document to the console via CTRL-Shift-Z, add this keybinding:
<s-c-z>
: mz ggVG y <f4> <s-c-v> <cr> <f4> <esc> `z<c-a-m><s-c-z>
: <esc> mz ggVG y <f4> <s-c-v> <cr> <f4> <esc> `z<c-a-m>iIn the current version of Kate that I use, the konsole terminal does not play entirely flawlessly with R or radian; it has to be started using sudo radian
and then, the user R library is not found, meaning that depending on how the R packages were installed, these cannot be found when using R in Kate. I expect that this problem will vanish in future releases. For now, I had to add a .radian_profile
file that adds my user R library to the search path .libPaths()
.
Another option I use in my .radian_profile file is for changing the color mode:
options(radian.color_scheme = "colorful")
Otherwise the text in the console is not very readable on my machine.
The standard syntax highlighting scheme for R code ist rather old. Use my improved syntax highlighting, instead, which for example includes syntax highlighting for roxygen documentation in R packages. Get the syntax highlighting file here. and add it to
~/.local/share/katepart5/syntax
or
~/.local/share/org.kde.syntax-highlighting/syntax
Create these directories if they do not exist.
In this section I will describe how to optimally use indentation in Kate, as soon as I understand it.
Last updated: 2020-11-19