Kakoune: Using spaces instead of tabs

Created on 14 Sep 2020  Â·  14Comments  Â·  Source: mawww/kakoune

I'm trying to understand how to get kakoune using spaces instead of tabs for Ruby files.

First I looked around the wiki, and found this https://github.com/mawww/kakoune/wiki/Indentation-and-Tabulation
There doesn't seem to be any information there on using spaces.

Then, I figured I would try editorconfig. Your built-in script for setting up editorconfig is super-weird though. It seems to require an executable called editorconfig? What is this? https://github.com/mawww/kakoune/blob/master/rc/detection/editorconfig.kak#L16

Am I missing something? Hardly any projects use tabs nowadays.

This has really stumped me, and unfortunately I'm going to have to go back to vim to actually get work done. :cry:

Most helpful comment

Kakoune has > and < commands that can insert tabs or spaces, depending on the indentwidth option.

It also has the @ and <a-@> commands to convert between tabs and spaces, based on the tabstop option.

The <tab> key will, by default, always insert a tab character — much like the other typable keys on the keyboard.

By combining these building-blocks with each other, and with hooks and mappings and maybe even a little shell-scripting, you can build just about any tab-handling behaviour you like. This is the opposite of most mainstream text editors, which often provide sophisticated indent-handling out of the box but don't necessarily allow much customisation of that behaviour. This can be frustrating for new users, but Kakoune values "easy to customise" over "easy to use".

All 14 comments

In the first sentence you wrote “tabs instead of spaces”. I assume this was an accident.

This is what I use:

hook global WinSetOption filetype=(rust|python|zig|ruby) %{
    expandtab # must be before softtabstop
    set-option buffer indentwidth 4
    set-option global softtabstop 4 # number of spaces to delete on backspace
}

expandtab is provided by smarttab.kak. Feel free to change 4 to your preferred amount of spaces.

Thanks but that project is unmaintained. I'm still confused why there's no
simple config for using spaces. Why do I have to install a plugin for the
most simple feature?

On Mon, Sep 14, 2020, 13:50 Lennard Hofmann notifications@github.com
wrote:

In the first sentence you wrote “tabs instead of spaces”. I assume this
was an accident.

This is what I use:

hook global WinSetOption filetype=(rust|python|zig|ruby) %{

expandtab # must be before softtabstop

set-option buffer indentwidth 4

set-option global softtabstop 4 # number of spaces to delete on backspace

}

expandtab is provided by smarttab.kak
https://github.com/andreyorst/smarttab.kak. Feel free to change 4 to
your preferred amount of spaces.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/mawww/kakoune/issues/3727#issuecomment-692030599, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AACYYYWRNYXKCRGMOVLI7DLSFYGSPANCNFSM4RLRBBUA
.

unmaintained doesnt mean that it doesnt work. it is a simple feature, after all.

@SolitudeSF Yes, but unmaintained makes me think that using spaces in kakoune is unsupported. It's not a very nice experience for potential new users.

Also, why should we install a plugin for something that should be built in? It just seems to odd to me.

There's so much functionality built in to kakoune, like for example git blame is an important feature but soft tabs is not?

And also, I think this feels important because I've been using vim for a long time, and when I found kakoune I felt like "wow now I don't have to mess around with my vimrc anymore to get the behaviour I want". Kakoune seemed to have everything good built in.

yes, i too dont understand why smarttab's functionality is still not bundled with kakoune.

@SolitudeSF do you know of any public statement on this? Perhaps @mawww has an opinion?

Kakoune's indentwidth option sets the number of spaces to use for indenting (with the < and > normal-mode commands, so it's like Vim's shiftwidth). As long as it's non-zero, Kakoune won't insert tabs in your file unless you hit the Tab key yourself.

If you want the tab key to indent or dedent rather than inserting a tab character, you can map the Tab key to > — that doesn't necessarily insert spaces, since the > key's behaviour depends on the indentwidth option.

If you look at Vim's tab-handling options (tabstop, expandtab, softtabstop) there's a bunch of different tab-handling behaviours with sometimes surprising interactions (softtabstop without expandtab results in a mixture of tabs and spaces, infuriating everybody). Rather than add all that complexity into Kakoune's core, though, it's much better suited to a plugin, where people can tweak their own configuration to exactly the way they want it.

Your built-in script for setting up editorconfig is super-weird though. It seems to require an executable called editorconfig? What is this?

The editorconfig specification is simple enough that you can support it pretty easily in a general-purpose language, but not so simple that you can support it in plain shell-script. Since the editorconfig project provides an official command-line tool to read the config files (apt install editorconfig on Debian), it's a lot easier to write a plugin to use that command and parse the output with a shell-script than to actually handle editorconfig files directly.

Kakoune's indentwidth option sets the number of spaces to use for indenting (with the < and > normal-mode commands, so it's like Vim's shiftwidth). As long as it's non-zero, Kakoune won't insert tabs in your file unless you hit the Tab key yourself.

If you want the tab key to indent or dedent rather than inserting a tab character, you can map the Tab key to > — that doesn't necessarily insert spaces, since the > key's behaviour depends on the indentwidth option.

So if I understand this correctly, @Screwtapello, kakoune uses spaces for indentation when using > and <, but when you press tab it inserts a tab character? This is extremely surprising default behaviour.

I'm not proposing kakoune copies what vim does.

The editorconfig specification is simple enough that you can support it pretty easily in a general-purpose language, but not so simple that you can support it in plain shell-script. Since the editorconfig project provides an official command-line tool to read the config files (apt install editorconfig on Debian), it's a lot easier to write a plugin to use that command and parse the output with a shell-script than to actually handle editorconfig files directly.

Thanks, that makes sense. This script doesn't have any packages on Arch unfortunately. I have updated the wiki page accordingly: https://github.com/mawww/kakoune/wiki/EditorConfig

Kakoune has > and < commands that can insert tabs or spaces, depending on the indentwidth option.

It also has the @ and <a-@> commands to convert between tabs and spaces, based on the tabstop option.

The <tab> key will, by default, always insert a tab character — much like the other typable keys on the keyboard.

By combining these building-blocks with each other, and with hooks and mappings and maybe even a little shell-scripting, you can build just about any tab-handling behaviour you like. This is the opposite of most mainstream text editors, which often provide sophisticated indent-handling out of the box but don't necessarily allow much customisation of that behaviour. This can be frustrating for new users, but Kakoune values "easy to customise" over "easy to use".

Thanks @Screwtapello. I take your points.

However, what I'm trying to get at here is that most every other text editor gets this right by default. Kakoune has weird behaviour. This is not a great onboarding experience, and I think it should be different.

I don't want to combine building blocks, and write shell scripts to get a code editor to understand that indentation and pressing is the same thing. I'm also arguing that most developers picking up this editor would be surprised by this.

#1038 (comment)

Thanks, I've just seen this comment. Fair enough then, I suppose.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hwmack picture hwmack  Â·  4Comments

lenormf picture lenormf  Â·  4Comments

lenormf picture lenormf  Â·  4Comments

alexherbo2 picture alexherbo2  Â·  4Comments

dpc picture dpc  Â·  4Comments