[dev] suckless indentation with vim

51 views
Skip to first unread message

NRK

unread,
Jul 2, 2022, 1:08:19 PM7/2/22
to d...@suckless.org
Hi,

The suckless coding style follows "tabs for indent, spaces for
alignment" philosophy. But afaik, vim doesn't support it natively.

I remember trying out a couple plugins from here:
https://vim.fandom.com/wiki/Indent_with_tabs,_align_with_spaces
but they all failed miserably on many cases.

'clang-format' can do this with 'UseTab: AlignWithSpaces' but it also
does a bunch of *other* stuff (which I don't like) and I also don't like
external formatters and would much rather have my editor do the
formatting as I'm typing.

If someone's using vim and follows this style, what plugin and/or
setting do you use?

- NRK

Rene Kita

unread,
Jul 2, 2022, 2:07:12 PM7/2/22
to dev mail list
On Sat, Jul 02, 2022 at 11:07:48PM +0600, NRK wrote:
> Hi,
>
> The suckless coding style follows "tabs for indent, spaces for
> alignment" philosophy. But afaik, vim doesn't support it natively.

It does. Just press Tab to indent and press Space to align. You don't
need a plugin. ;)

NRK

unread,
Jul 2, 2022, 2:27:41 PM7/2/22
to dev mail list
On Sat, Jul 02, 2022 at 07:29:03PM +0200, Rene Kita wrote:
> It does. Just press Tab to indent and press Space to align. You don't
> need a plugin. ;)

One of the main reason I use vim is because it makes it VERY easy to
edit/refactor code. A lot of things which are very cumbersome on other
point-and-click style editors can be done in 1~3 just keystrokes.

It can do auto-indentation with `=`, which makes moving a block of code
from one place to another very easy. But in cases where spaces need to
used for alignment, it can mess it up and end up using tabs instead.

The following (indentation related) settings is what I've got on my
vimrc:

set cinoptions+=t0 " Don't outdent function return types
set cinoptions+=:0 " No extra indentation for case labels
set cinoptions+=(0 " Lineup function args

which pretty much does everything I need, except using spaces for
alignment. I see no reason why that needs to be manual when everything
else vim can do automatially.

- NRK

Страхиња Радић

unread,
Jul 2, 2022, 5:03:31 PM7/2/22
to dev mail list
On 22/07/02 11:07, NRK wrote:
> If someone's using vim and follows this style, what plugin and/or
> setting do you use?

set tabstop=8
set softtabstop=0
set shiftwidth=0
set noexpandtab

Not being lazy to type text, and indenting each line manually.

Side note: vim is bloated compared to vi and vis.
signature.asc

David Demelier

unread,
Jul 5, 2022, 2:59:27 AM7/5/22
to d...@suckless.org
I'm not sure if it's really easy to implement a smart alignment. I use
some mapping to switch between et/noet option to insert spaces instead
of tabs and align manually.

nmap ,<TAB> :set et!<CR>

Of course, always better to view whitespaces when dealing with that
mix.

--
David

NRK

unread,
Jul 5, 2022, 4:00:41 AM7/5/22
to dev mail list
On Tue, Jul 05, 2022 at 08:54:20AM +0200, David Demelier wrote:
> I'm not sure if it's really easy to implement a smart alignment.

Do you mean implementing it in vimscript/externally or internally?

Because I don't think implementing it internally should be difficult,
given that it already can do alignment, it just continues to use tabs as
long as possible rather than using it as much as the previous line.

Though I could be wrong, as I've never taken a look at the vim codebase.

> Of course, always better to view whitespaces when dealing with that
> mix.

Even suckless indentation aside, it's useful when you deal with multiple
codebases which use different styles.

- NRK

fo...@dnmx.org

unread,
Jul 5, 2022, 8:45:44 AM7/5/22
to dev mail list
Yeah, Vim is extremely bloated.. I tried counting it's SLOC, both C and .vim
and stuff, and it's above 700000, I think.. if I counted it well, not sure.
Vi seems minimalistic - skimmed a it's source code.. but just A BIT too
minimal (suckless-style patches needed xD).

This is why I'm creating my own text terminal.
I don't give a shit if it doesn't become 1/1000 as popular as Vim is, I
want it
to be simple, suckless, and powerful-ish.
The cross-platform compatibility might be a shit-thing.


Robert Winkler

unread,
Jul 5, 2022, 7:43:50 PM7/5/22
to dev mail list
Well, vim is problematic for several reasons.
neovim is said to be 'cleaner' code and more collaborative;
Unfortunately, many useful plugins that I need for working with
markdown/ pandoc (e.g. youcompleteme) don't run on all platforms
with neovim, why I'm still stuck with vim (from time to time I need a
manuscript finished..).

Since my hand mobility is limited, I cannot use Emacs, et al. (;-)),
and atom, which was a very versatile editor, is dead.

My point: the tab/intend/space issue is only the tip of the iceberg.
Probably a newly written 'vimish' editor is needed.


Sebastian LaVine

unread,
Jul 5, 2022, 8:22:00 PM7/5/22
to dev mail list
On Tue Jul 5, 2022 at 7:43 PM EDT, Robert Winkler wrote:
> Probably a newly written 'vimish' editor is needed.

I know some of my more minimalistically minded friends use vis[0].

[0]: https://github.com/martanne/vis

NRK

unread,
Jul 6, 2022, 4:52:06 AM7/6/22
to dev mail list
On Tue, Jul 05, 2022 at 06:43:53PM -0500, Robert Winkler wrote:
> Probably a newly written 'vimish' editor is needed.

I see that "vis" has already been mentioned. There's also neatvi, and
kakoune.

But if your problem with neovim is that it isn't compatible with the vim
ecosystem, then neatvi and kakoune; or any other "newly written" vi
clone will suffer from the same problem.

neatvi: https://github.com/aligrudi/neatvi
kakoune: https://github.com/mawww/kakoune

- NRK

Reply all
Reply to author
Forward
0 new messages