Home : Linux : KDE :

Kate


NOTE: This is all pre 4.0 and likely no longer of much use.

On this page:
   Kate MimeTypes
   Regular Expressions in Kate
   Single instance of Kate

Filesystem Browser

The first time the Filesystem Browser is used, the last directory viewed becomes the default directory for all subsequent sessions. I don't know if this is a bug or has something to do with my setup and how I use Kate. The only way I have found to change the default Filesystem Browser directory is to edit the [fileselector] section in ~/.kde/share/config/katerc.

...Same issue w/ TDE, fixed using: $ nano ~/.trinity/share/config/katerc
[ comment | link | top ]

Kate MimeTypes

Kate MimeTypesBy default, the only MimeType associated with Kate (and KWrite) is text/plain. The problem is that there are a lot of text files with mime types other than text/plain. You cannot right-click and 'open with Kate' untill the mime type is associated with Kate. Adding mime types and giving Kate priority over KWrite is a pain, it can be time consuming and messy. This is one of those instances where editing text files is easier.

If you don't have a ~/.local/share/applications/kde-kate.desktop file and aren't interested in a single instance of Kate, go to the start menu, right-click on kate, select Edit Item (install kdebase-kmenuedit if nothing happens), add some text to the comment field, click on the save icon, remove the comment and save again (you have to change the system wide defaults in some way for the file to be created and that's an easy way to do it). You'll now have a kde-kate.desktop file.

By default kde-kate.desktop will only contain MimeType=text/plain. To add more mime types you can right-click on the kde-kate.desktop file and and go to Properties : Application (image). Knowing and finding all the appropriate mime types is time consuming (I'm still working on it).

To speed things up you can open kde-kate.desktop as a plain text file to cut and paste the following (remove the space and line breaks)*. You can then go to Properties : Application to remove any you don't want, and add any others that you may want. This is my current list, it may be incomplete and there may be overlaps:

   MimeType=text/plain;text/html;text/xml;text/css;
   text/x-sh;text/x-csv;text/x-diff;
   audio/m3u;
   application/x-php;
   application/x-desktop;application/x-shellscript;
   application/xhtml+xml;application/xml;application/xml-dtd;
   application/x-perl;application/x-perl-module;application/x-cgi

The next thing to do is give Kate priority over KWrite for text/plain, to have as many text files as possible open with Kate by default. On way to do this is to go to Konqueror's Settings > Configure Konqueror > Configure File Associations, find each text/plain mime type with Kate and KWrite associations and move Kate above KWrite. A much easier/faster way is to create a kde-kwrite.desktop (like we did for Kate, comment method above) and remove the text/plain MimeType. You'll have to restart X for it to take effect. The added bonus is files with mime types, that only had Kate and KWrite associated with them, will open with a (double-)click, i.e. no more right-click 'open with' selecting.

If you want a desktop link to Kate, drag-n-drop kde-kate.desktop to the desktop and select Link Here. If you use Copy Here and change any properties later, only the one you edit will change. Using Link Here, editing one edits both.

*You could also change the first line to Encoding=ISO 8859-1 if you edit stuff that isn't compatible with UTF8. I've decided to just set it in Tools > Encoding (that and other user configs are stored in ~/.kde/share/config/katerc).
[ comment | link | top ]

Regular Expressions in Kate

Regular Expressions in KateI use regular expressions a lot in Perl. It appears that they work pretty much the same in Kate. While the options aren't all listed, the functions are there.

One thing I had to figure out is how storing works. Maybe I'm just clueless but I am used to $1, $2, etc., with Kate its \1, \2, etc. In the image I match to the start of the line ('^'), escape ('\') the special '!' characters, used \d+ in parenthesis to store one or more digits and used .+ in parenthesis to store one or more characters (long, unique, HTML titles that I wanted to markup as bold).

...Exclusions also work. I wanted to exclude titles indented with a space ( ), so I changed (.+) to ([^&]+) so that I could exclude '&' from my 'any character' match. If there was a '&' anywhere else (e.g. in the title text) I would have had to use a more complex match... Excluding string matches also works, ((!&nbsp)+).

...One thing I haven't been able to do is remove blank lines, ^\n and a number of other things don't work.
[ comment | link | top ]

Single instance of Kate

Kate: Using Named SessionsI use Kate, like I use Konqueror, with tabs (plugin) and opening / working with multiple files in a single window. Since the introduction of named sessions, opening multiple files in a single instance of Kate requires a couple of tweaks. When opening Kate, open the default session, make any customizations you want, set

   Settings : Configure Kate : Application : Sessions

to look like the screenshot. Close Settings and do Sessions > Save. It seems that the save sessions setting doesn't save interface changes (e.g. toolbar changes). If you do any future interface customizations, do a Sessions > Save before quiting.

In
   /usr/share/applications/kde/kate.desktop (system wide)
or
   ~/.local/share/applications/kde-kate.desktop (user only)
change

   Exec=kate %U
to
   Exec=kate --use %U

...If the local/user kde-kate.desktop file doesn't exist: Go to the start menu, right-click on kate, select Edit Item (install kdebase-kmenuedit if nothing happens), add --use and save. You will now have an edited kde-kate.desktop.

Feb '09: I was a bit slow to discover that multiple saved sessions and a single instance are not mutually exclusive. From the Sessions menu you can easily create, save, manage and (quick) open sessions. Set "Behavior on Application Startup" (image) to whatever works for you. All a single instance means is that when there's an open session (default, new or saved), all other 'open with kate' requests will be opened in that session.

See also: Using Named Sessions
[ comment | link | top ]

Back to: KDE