Things that would make me a bit happier with Kakoune and things I thin we'd all like

Hello all!

I thought I’d look into Kakoune again. I do recall that there are some things that I wish where improved.

  1. System clipboard

    Dear god. I forgot how this kind of annoys me. So I’m using kitty for my terminal, and I’m using good 'ol xsel:

    # --- Cutting, Yanking, Pasting ---
    
    hook global NormalKey y|d|c %{
    	nop %sh{
    		printf %s "$kak_main_reg_dquote" | xsel --input --clipboard
     }
    }
    
    hook global RegisterModified '"' %{
        nop %sh{
         printf "%s" "$kak_main_reg_dquote" | xsel --input --clipboard
     }
    }
    
    map global normal -docstring "delete to end-of-line"       D     ';<a-l>d'
    map global normal -docstring "delete to beginning-of-line" <a-d> ';<a-h>d'
    
    evaluate-commands %sh{
    	copy="xsel --input --clipboard"
    	paste="xsel --output --clipboard"
    	printf \
    	"map global normal -docstring 'paste (before) from clipboard' p '!%s<ret>'\n" "$paste"
    	printf \
    	"map global normal -docstring 'paste (after) from clipboard' P '<a-!>%s<ret>'\n" "$paste"
    	printf \
    	"map global normal -docstring 'copy to system clipboard' y '<a-|>%s<ret>'\n" "$copy"
    	printf \
    	"map global normal -docstring 'copy to end-of-line to system clipboard' Y '<a-l><a-|>%s<ret> 
     <a-;>;'\n" "$copy"
    	printf \
    	"map global normal -docstring 'replace selection with system clipboard' R '|%s<ret>'" "$paste"
    }
    
    

    And I can get things in to the system clipboard fine, but getting them out is a not possible apparently. Say I’m in the browser, and then I’m trying to paste something I copied from there inot Kakoune. Dones’t happen.

  2. Highlighting with tree-sitter?

    Yea, feel like it’s pretty self explanitory. I’m curious how I’d might use it with Kakoune.

  3. Using Kakoune + Kitty better

    I’m curious how I could go about using Kakoune with Kitty for a better workflow. In Vim/Neovim you can C-w v and you create a split. I would like something that easy with Kakoune. I’d like to have a prompt to open a file in a Kitty split running Kakoune with that file. Not sure how prompts work.

  4. Debug Adapter Protocol?

    Has anyone any interest in this for Kakoune?

For the system clipboard stuff, once you have the RegisterModified hook, the NormalKey hook and the “copy to system clipboard” mappings are redundant. The “copy to end-of-line to system clipboard” isn’t redundant, but it can just be mapped to <semicolon><a-l>y instead of piping anything to xsel. I don’t think that will fix your “can’t paste from other apps” problem, but it should make things simpler and maybe more reliable.

p1. Why so complicated?

map -docstring "paste clipboard content after selection"  global user p "<a-!> xsel --output --clipboard <ret>".

p2. Kak-tree seems to be dead, and semantic highlighting already works with Kak-lsp.
p4. Maybe follow GitHub - jdugan6240/kak-dap: A generic debugger for Kakoune.

I prefer having two different clipboards as I often yank something, but I still want to have the contents of the system clipboard intact. So I use user mode mappings that mirror Kakoune’s default mappings:

map -docstring "copy to system clipboard"                   global user 'y' '<a-|>xsel -b -i<ret>:<space>echo -markup %{{Information}yanked selection to system clipboard}<ret>'
map -docstring "cut to system clipboard"                    global user 'd' '|xsel -b -i<ret>'
map -docstring "cut to system clipboard, enter insert mode" global user 'c' '|xsel -b -i<ret>i'
map -docstring "paste from system clipboard before cursor"  global user 'P' '!xsel --output --clipboard<ret>'
map -docstring "paste from system clipboard after cursor"   global user 'p' '<a-!>xsel --output --clipboard<ret>'
map -docstring "replace selection with system clipboard"    global user 'R' '|xsel --output --clipboard<ret>'

As for windowing, I don’t use Kitty, but to me Tmux seems as the best option here, as it runs almost anywhere, available as a package on all systems I’ve seen so far, and has tons of windowing features that Vim didn’t have at all.

I find Tmux to be kind of slow, and using Tmux inside of Kitty is kinda of redundant and over kill.

There is this bit that I have to create splits in Kitty

# Providing a means to create splits like the tmux module can,
# but with kitty instead.
#
# Thank you user joefiorini:
# https://github.com/joefiorini/joeconf-kakoune-plugins/blob/master/plugins/kitty.kak

provide-module kitty-split %[

# Ensure we don't load built-in kitty module
set-option global windowing_modules

declare-option str kitty_split_default_location "last"
declare-option str kitty_split_default_type "window"

define-command kitty-split -params .. -shell-completion -docstring '
kitty-split [location] [type] [<arguments>]: create a new terminal window as a kitty split
Accepts --horizontal or --vertical for the location of the split
Any extra arguments will be passed to "kitty @ launch"' \
%{
  nop %sh{
    echo "arg: <<${1}>>" 1>&2
    kitty_locations=(vsplit before hsplit after last neighbor first)
    kitty_split_types=(window tab primary clipboard os-window background overlay)

    case "${kitty_locations[@]}" in
      *"${1}"*)
        split_arg=$1
        shift
        ;;
    esac

    case "${kitty_split_types[@]}" in
      *"${1}"*)
        type_arg=$1
        shift
        ;;
    esac

    echo "split_arg: <<${split_arg:-$kak_opt_kitty_split_default_location}>>" 1>&2
    echo "type_arg: <<${type_arg:-$kak_opt_kitty_split_default_type}>>" 1>&2
    echo "shifted: <<${1}>>" 1>&2
    kitty @ launch --no-response --type="${type_arg:-$kak_opt_kitty_split_default_type}" --cwd="$PWD" --location="${split_arg:-$kak_opt_kitty_split_default_location}" "${@}"
  }
}

define-command kitty-split-horizontal -params .. -shell-completion -docstring '
kitty-split-horizontal [<arguments>]: create a new terminal window above or below
the current window.
Any extra arguments will be passed to "kitty @ launch"' \
%{
	kitty-split hsplit %arg{@}
}

define-command kitty-split-vertical -params .. -shell-completion -docstring '
kitty-split-vertical [<arguments>]: create a new terminal window to the left or right of
the current window.
Any extra arguments will be passed to "kitty @ launch"' \
%{
	kitty-split vsplit %arg{@}
}

define-command kitty-overlay -params .. -shell-completion -docstring '
kitty-overlay [<arguments>]: create a new terminal window on top of the current window.
Any extra arguments will be passed to "kitty @ launch"' \
%{
  kitty-split overlay %arg{@}
}

require-module kitty

unalias global terminal kitty
alias global terminal kitty-split
alias global focus kitty-focus

]

Works pretty well, actually. I still run into the issue of that it seems separate Kakoune instances in different splits don’t share a clipboard? Also I can’t seem to use kakoune.cr with the above? It’s says the kcr command doesn’t exist? 0_o

Ah, thank you! That’s allows me to refactor a little.

This clipboard issue I’m having is strange.

There is the clipboard kitten for Kitty. Maybe that has something to do with it?

Sorry if this seems like a somewhat late reply - those who have a look at that repository may notice that it hasn’t been updated in quite a while. I haven’t had a ton of time to work on it lately, but rest assured it is still being worked on :wink: . The goal with this is to have similar (but not identical, due to feature differences between vim and kakoune) features as the popular vimspector plugin for vim/neovim:

Like I said, progress is slow, but a Debug Adapter Protocol plugin for Kakoune will come.

2 Likes