Further Customization Questions

Few things that I would like to figure out (and might be even useful to document somewhere):

  1. Hard wrapping
    I don’t think that’s what it’s called, but what I’m trying to get is Kakoune to wrap text on long lines.

    I have

    hook global WinSetOption filetype=(text|markdown|rst|ms|org) %{
       set window autowrap_column 50 
       autowrap-enable
    }
    

    However that doesn’t wrap any text. If I open a blank text file and hold down a key in insert mode, kakoune doesn’t wrap the line. It keeps going until I press enter, and then I’m just on a newline I just made.

    Doing addhl global/ wrap doesn’t suit my wants, and I don’t see the point in binding a key in order to wrap text.

  2. Using TAB to cycle through completions in insert mode

    Not sure how one would do this.

  3. Creating splits (if possible) in the terminal

    I use Kitty terminal, and one thing that I would like to see if it is possible to create a window of a certain size and run nnn in it.

    I found something from user duncan on here that allows me to open a new terminal window with nnn running in it:

    def nnn -params .. -file-completion %(connect-terminal nnn %args(@)) -docstring "Open with nnn"
    

    Which is really useful, I was just wondering it if were possible to have it like a drawer like kak-tree.

    This is more specific to me, but I think it’d still be helpful to know how to create “splits” like Vim/Neovim, whether it be to run an external program or to split the window to have two separate files. Like Vim and Emacs can.

About hard wrapping: the autowrap script provided by default with Kakoune relies on an external formatter (such as fold or fmt) to do the wrapping. Most of these formatters will break the current line on white space, so if you keep pressing the same key (e.g, x) no wrapping will take place.
Did I misunderstand you? Or did you try to write a regular sentence (with spaces between words) and did wrapping still fail?

I typed out a series of sentences just now and it did not wrap at any point. fold and fmt are on my machine.

Assume you have a text file opened and hard wrapping failed. What happens if you escape to Normal mode and type:

 :set window autowrap_column 50

and then:

:autowrap-enable

manually? Does autowrap still fail when going back to Insert mode? If not, that would suggest there is something wrong with your hook.

(By the way, does the debug buffer show anything?).

  1. Tab to cycle through completions

Have a look at this: https://github.com/mawww/kakoune/issues/1327

  1. Splits

Run kakoune in tmux, then do :new to create a new tmux split with a kakoune client.

1 Like

Nope. Still no wrapping. And debug doesn’t show anything related to wrapping. Does show something related to kak-lsp…I’ll have to look at that later.

Is the issue with this filetype=(text|markdown|rst|ms|org) ?

I haven’t gotten back into using tmux with kitty. I’ll have to look into it again.

Thank you, though!

Yes, I thought that it might be the regex in the hook, but the fact that wrapping fails even when you activate autowrapping manually suggests that the issue is with autowrapping itself.

Once you have activated autowrap manually, just for checking things – what happens if you type in Normal mode:

:echo %opt(autowrap_column) [Enter]

and

:echo %opt(autowrap_fmtcmd) [Enter]

The former should return 50 (the value you just set manually) and the latter,

fold -s -w %c

The autowrap script is supposed to substitute %c by 50 and thus call fold -s -w 50 on your paragraph. So, what happens if you try to run fold manually on a paragraph you wrote in your buffer (text file)? What happens when you select a whole paragraph (in Normal mode) and type:

| fold -s -w 50 [Enter]

Ah, well the first echo command there returns 80 and not the 50 I set. That says something right there. The second one returns the what you specified.

And using fmt and fold manually both work.

So if the regex I have is wrong, how should I enable autowrap for buffers with each of those filetypes?

I thought that formatting did not work even when you set autowrap_column manually to 50? In any case, before checking the regex, is filetype detection working correctly? What happens if you open a text or markdown file (etc) and type:

:echo %opt(filetype)

If this returns the correct filetype, then this would suggest something wrong with the regex. Perhaps removing the outer parentheses will help (I don’t think they are ever needed). What happens when you remove the parentheses? Out of despair, what happens when you use a single filetype in your hook, e.g., filetype=text?

Ah well it might be because a .txt file doing :echo %opt(filetype) returns plain.

Let me change that and see what happens.

Well, changing text to plain in the filetype regex did nothing. I’ll try just 1 filetype.

EDIT: welp. That did nothing either.

About plain-text files: yes, I recall now that they are detected as plain (Kakone detects filetypes based on your system’s file command with the -b and -i switches. So it is no surprise that text didn’t work. Did you try removing the outer parentheses from the regex:

filetype=plain|markdown|rst|ms|org

And what happens if you try to call you hook on any file whatsoever, with:

filetype=.*

? Is autowrap activated correctly?

1 Like

Both of those work. :+1:

  1. Your hook works for me for .txt files once I add plain to the regex.

  2. Already answered. I want to point out to mawww’s kakrc, from where this was taken, in case you wanna take a look: great kakrc’s.

  3. I use kitty too. If you just want to open a new kitty window, checkout the commands :terminal, :terminal-tab and :new. You can do :terminal nnn for your used case. Kakoune will recognize if you are using tmux, kitty or other terminals and map :terminal to the appropriate command (commands for other terminals don’t get sourced). So, basically, in you case :terminal is an alias for :kitty-terminal. To make use of them, you need to enable in kitty's configuration file remote control. And if you are interested in implementing more functionality (like split with special parameters) you could check how the command is implemented.

    By the way, take a look at the plugin connect.kak if you want to open files from nnn to your kakoune window easily.

1 Like

Great! You may want to have a look at:

:doc regex

The examples for alternation (|) make it clear that the surrounding parentheses are not needed in your use case.

I would worry that this would match filetype=plain or markdown or rst, etc. instead of filetype=plain or filetype=markdown or filetype=rst, which are the actual strings the regex needs to match.

That is to say, I think the () are necessary.

1 Like

From what the OP said, I thought that the regex was applied to the right side of filetype=..., but I just checked and you are right, the regex is applied to the whole expression. Therefore, the parentheses are necessary:

filetype=(plain|markdown|rst|ms|org)

So it seems the whole thing was just an issue of having the wrong filetype (“text” instead of “plain”).

I wouldn’t know about the parentheses issue because I never use this type of hook. The hook on filetypes in my kakrc is just filetype=.*. Inside the hook I have generic commands, plus a call to the shell with a case ... esac construction on $kak_opt_filetype. This allows me to have filetype-specific customizations in only one place instead of being spread over several hook declarations.

Credit @robertmeta
roberts kakrc file is worth taking a look at @The-BigDaddy.