#colorscheme catppuccin_latte # Lines numbers and relative numbers add-highlighter global/ number-lines -relative # Highlight matching pair add-highlighter global/ show-matching # Wrap on word boundaries add-highlighter global/ wrap -indent -word # Highlight trailing whitespace add-highlighter global/ regex \h+$ 0:Error set-option global scrolloff 5,5 map global normal ":comment-line" # System clipboard bindings map global user y "cp.sh" -docstring "[Y]ank to system clipboard" map global user p "|put.sh" -docstring "[P]ut from system clipboard" ### A note on the /dev/null black magic ### # %sh is synchronous by design. It will wait for: # 1. The shell process to exit. # 2. All pipes (stdin, stdout, stderr) to close. # # The final `&` forks the process, satisfying the first condition, but all # pipes are left open. So, we need to "close" them: # - `> /dev/null` to close stdout # - `2>&1` redirects stderr to stdout, which in this case is `/dev/null` - closed # - `< /dev/null` closes stdin # Now, as far as kakoune is concerned, the process has finished and all pipes # are closed, so control immediately returns to the client. define-command -docstring "Compile the current document" compile %{ nop %sh{ { compiler $"{kak_buffile}" } > /dev/null 2>&1 < /dev/null & } } map global user c -docstring "[C]ompile the current file" ":compile" map global user = -docstring "Format current buffer with :format" ":format" hook global BufCreate .*\.[Rr]md %{ set-option buffer filetype markdown } # Pattern for communicating with kak via it's session socket define-command sockettest %{ nop %sh{ { sleep 10 echo "eval -client '$kak_client' 'echo sleep ended'" | kak -p ${kak_session} } > /dev/null 2>&1 < /dev/null & } } # fzf file chooser define-command fzf_file %{ nop %sh{ # Create a temporary file for storage foot -T 'foot_tmp' dash -c ' next=$(fzf --height=100% --layout=default --preview "highlight -O ansi {}") printf "eval -client %s %%{ edit %s }\n" "$kak_client" "$next" | kak -p "$kak_session" ' > /dev/null 2>&1 < /dev/null & } } map global user f -docstring "Browse [f]iles with fzf" ":fzf_file" # fzf buffer chooser define-command fzf_buffer %{ nop %sh{ # Create a temporary file for storage foot -T 'foot_tmp' dash -c ' next=$(printf "%s\n" "$kak_buflist" | tr " " "\n" | fzf --height=100% --layout=default --preview "highlight -O ansi {}") printf "eval -client %s %%{ buffer %s }\n" "$kak_client" "$next" | kak -p "$kak_session" ' > /dev/null 2>&1 < /dev/null & } } map global user b -docstring "Browse [b]uffers with fzf" ":fzf_buffer" define-command fifotest %{ evaluate-commands %sh{ # Create a temporary fifo for communication output=$(mktemp -d -t kak-temp-XXXXXXXX)/fifo mkfifo ${output} # run command detached from the shell { fzf > ${output} } > /dev/null 2>&1 < /dev/null & # Open the file in Kakoune and add a hook to remove the fifo echo "edit! -fifo ${output} *buffer-name* hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output})} }" } } # Trick to make compiler run async #hook global BufWritePost .*\.(md|tex|ms)$ %{ # nop %sh{ { # compiler $"{kak_buffile}" # } > /dev/null 2>&1 < /dev/null & } #} # Simpler version # hook global BufWritePost .*\.(md|tex)$ %{ # echo -debug %sh{compiler "${kak_buffile}"} # } # Filetypes with two-space indentation hook global BufCreate .*\.(js|html|ts|tsx|hs)$ %{ # Map tab key to `>` in normal mode -- inserts spaces map global insert '' set-option buffer indentwidth 2 } # Filetypes with four-space indentation hook global BufCreate .*\.(py|json|jsonc)$ %{ map global insert '' set-option buffer indentwidth 4 } eval %sh{kak-lsp} hook global WinSetOption filetype=(haskell|rust|python|go|javascript|typescript|c|cpp) %{ lsp-enable-window } remove-hooks global lsp-filetype-python hook -group lsp-filetype-python global BufSetOption filetype=python %{ # set-option buffer lsp_servers %{ # [pylsp] # root_globs = ["requirements.txt", "setup.py", "pyproject.toml", ".git", ".hg"] # settings_section = "_" # [pylsp.settings._] # # See https://github.com/python-lsp/python-lsp-server#configuration # # pylsp.configurationSources = ["flake8"] # pylsp.plugins.jedi_completion.include_params = true # } set-option buffer lsp_servers %{ [pyright-langserver] root_globs = ["requirements.txt", "setup.py", "pyproject.toml", "pyrightconfig.json", ".git", ".hg"] args = ["--stdio"] } # set-option -add buffer lsp_servers %{ # [ruff] # args = ["server", "--quiet"] # root_globs = ["requirements.txt", "setup.py", "pyproject.toml", ".git", ".hg"] # settings_section = "_" # [ruff.settings._.globalSettings] # organizeImports = true # fixAll = true # } } hook -group lsp-filetype-javascript global BufSetOption filetype=(?:javascript|typescript) %{ set-option buffer lsp_servers %{ [vtsls] root_globs = ["package.json", "tsconfig.json", "jsconfig.json", ".git", ".hg"] args = ["--stdio"] settings_section = "_" [vtsls.settings._] quotePreference = "single" # typescript.format.semicolons = "insert" } #set-option buffer lsp_servers %{ # [typescript-language-server] # root_globs = ["package.json", "tsconfig.json", "jsconfig.json", ".git", ".hg"] # args = ["--stdio"] # settings_section = "_" # [typescript-language-server.settings._] # # quotePreference = "double" # # typescript.format.semicolons = "insert" #} # set-option buffer lsp_servers %{ # [deno] # root_globs = ["package.json", "tsconfig.json", ".git", ".hg"] # args = ["lsp"] # settings_section = "deno" # [deno.settings.deno] # enable = true # lint = true # } # set-option buffer lsp_servers %opt{lsp_server_biome} # set-option buffer lsp_servers %{ # [eslint-language-server] # root_globs = [".eslintrc", ".eslintrc.json"] # args = ["--stdio"] # workaround_eslint = true # [eslint-language-server.settings] # codeActionsOnSave = { mode = "all", "source.fixAll.eslint" = true } # format = { enable = true } # quiet = false # rulesCustomizations = [] # run = "onType" # validate = "on" # experimental = {} # problems = { shortenToSingleLine = false } # codeAction.disableRuleComment = { enable = true, location = "separateLine" } # codeAction.showDocumentation = { enable = false } # } # set-option buffer lsp_servers %{ # [tailwindcss-language-server] # root_globs = ["tailwind.*"] # args = ["--stdio"] # [tailwindcss-language-server.settings.tailwindCSS] # editor = {} # } } map global user l ':enter-user-mode lsp' -docstring 'LSP mode' map global insert ':try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' map global user h ':lsp-hover' -docstring 'LSP hover' map global object a 'lsp-object' -docstring 'LSP any symbol' map global object 'lsp-object' -docstring 'LSP any symbol' map global object f 'lsp-object Function Method' -docstring 'LSP function or method' map global object t 'lsp-object Class Interface Struct' -docstring 'LSP class interface or struct' map global object d 'lsp-diagnostic-object --include-warnings' -docstring 'LSP errors and warnings' map global object D 'lsp-diagnostic-object' -docstring 'LSP errors'