7

How do I make the Kakoune text editor display line numbers?

0

4 Answers 4

6

On latest Kakoune versions, you can enable line numbers for every buffers by putting the number_lines highlighter inside the global scope, with the following command:

add-highlighter global number_lines

If you want more control, another solution is to use a hook to add the number_lines highlighter on specific windows, for example if you line numbering only on buffers whose names do not contains * (as these are usually internal buffers), you can add a hook that does just that:

hook global WinCreate ^[^*]+$ %{ add-highlighter window number_lines }

4
  • This does not work for the version I installed from the official Ubuntu 17.04 repositories. However, it works if you compile kakoune from source.
    – user142
    Nov 22, 2017 at 14:55
  • It looks like my version is just too old. addhl number_lines works for my version.
    – user142
    Nov 22, 2017 at 15:09
  • 8
    As of 2018 (Kakoune v2018.10.27), I had to type add-highlighter global/ number-lines
    – Nate
    Dec 7, 2018 at 18:59
  • @Nate You should post answers as answers, not comments. Jan 20, 2019 at 17:12
5

As of 2020-11,

Kakoune v2020.09.01

the following is working:

add-highlighter global/ number-lines

Make sure you're typing spaces exactly as in the snippet above.

Originally provided by Nate on Dec 7 '18 at 18:59 for Kakoune v2018.10.27.

1
  • Thanks, finally working :)
    – xeruf
    Nov 22, 2020 at 21:08
1

In addition to answers for absolute line numbers:
add-highlighter global/ number-lines or
hook global WinCreate ^[^*]+$ %{ add-highlighter window/ number-lines }


If you want relative line numbers, put into kakrc:
add-highlighter global/ number-lines -relative or
hook global WinCreate ^[^*]+$ %{ add-highlighter window/ number-lines -relative }


And if you want absolute line numbers with on-demand relative line numbers:

add-highlighter global/ number-lines
def switch-number-line -params .. %{
    try %{ remove-highlighter window/number-lines }
    add-highlighter window/number-lines number-lines %arg{@}
}
hook global NormalKey  0   'switch-number-line -relative'
hook global NormalKey \D.* 'switch-number-line'

This snippet instructs Kakoune to initially show absolute line numbers,
on pressing 0 switch to relative line numbers,
and on pressing non-digit \D.* switch back to absolute line numbers.

Usage e.g. type 03j/03k to see relative numbers and go 3 lines down/up.
Type 03C/03<a-C> to see relative numbers and 3 times copy main selection to next/previous lines.

Taken from https://discuss.kakoune.com/t/type-0-to-show-relative-line-numbers-for-the-next-command/760/6
(also look that discussion for a partial solution for issue with git diff and linters indicators)

0

Expanding on Marek Kowalczyk's wonderful answer, if you want to enable line numbers everytime you launch kakoune, I find that going into your .bashrc and entering:

alias kak="kak -e 'add-highlighter global/ number-lines'"

helps a lot in getting line numbers everytime you go into a file with kakoune. Not only that, but with this method you have immediate access to disabling this command and tweaking it however you desire.

man kak

if you want to learn more about this command.

1
  • 3
    Better just to put add-highlighter global/ number-lines in your kakrc, surely. Apr 27, 2021 at 13:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .