Last active
September 16, 2024 14:42
-
-
Save dojoteef/3ba8d7c9445a0fc80272f8c05b414bfb to your computer and use it in GitHub Desktop.
Enable softwrap in kakoune and fix associated movement issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Softwrap long lines (and correct for improper kakoune movement behavior) | |
add-highlighter global/softwrap wrap -word -indent | |
define-command goto-center -docstring 'Jump to the center of the view' %{ | |
execute-keys %sh{ | |
echo $kak_window_range $kak_cursor_line | ( | |
read y x h w l | |
num_lines=$((l-y-(h+1)/2)) | |
if [ $num_lines -lt 0 ]; then | |
echo "${num_lines##-}j" | |
elif [ $num_lines -gt 0 ]; then | |
echo "${num_lines}k" | |
fi | |
) | |
} | |
} | |
define-command view-center -docstring 'Position view so the cursor is centered vertically' %{ | |
view-bottom | |
execute-keys %sh{ | |
echo $kak_window_range $kak_cursor_line | ( | |
read y x h w l | |
num_lines=$((l-y-(h+1)/2)) | |
if [ $num_lines -lt 0 ]; then | |
echo "${num_lines##-}vk" | |
elif [ $num_lines -gt 0 ]; then | |
echo "${num_lines}vj" | |
fi | |
) | |
} | |
} | |
define-command goto-bottom -docstring 'Jump to the bottom of the view' %{ | |
execute-keys %sh{ | |
echo $kak_window_range $kak_cursor_line | ( | |
read y x h w l | |
num_lines=$((y+h-l)) | |
if [ $num_lines -gt 0 ]; then | |
echo "${num_lines##-}j" | |
fi | |
) | |
} | |
} | |
define-command view-bottom -docstring 'Position view so the cursor is on the last line' %{ | |
evaluate-commands %sh{ | |
echo $kak_window_range $kak_cursor_line $kak_buf_line_count | ( | |
read y x h w l t | |
bottom=$((y+h)) | |
while test $bottom -ge $l; do | |
echo "evaluate-commands %{ | |
execute-keys vk | |
echo -to-file $kak_response_fifo %val{window_range} | |
}" > $kak_command_fifo | |
last="$y $x $h $w" | |
read y x h w < $kak_response_fifo | |
bottom=$((y+h)) | |
if [ "$y $x $h $w" = "$last" ]; then | |
break | |
fi | |
done | |
echo "echo -to-file $kak_response_fifo %val{cursor_line}" > $kak_command_fifo | |
read l2 < $kak_response_fifo | |
if [ $l -ne $l2 ]; then | |
echo "execute-keys j" | |
fi | |
) | |
} | |
} | |
define-command goto-top -docstring 'Jump to the top of the view' %{ | |
execute-keys %sh{ | |
echo $kak_window_range $kak_cursor_line | ( | |
read y x h w l | |
num_lines=$((l-y-1)) | |
if [ $num_lines -gt 0 ]; then | |
echo "${num_lines##-}k" | |
fi | |
) | |
} | |
} | |
define-command view-top -docstring 'Position view so the cursor is on the first line' %{ | |
evaluate-commands %sh{ | |
echo $kak_window_range $kak_cursor_line | ( | |
read y x h w l | |
top=$((y+1)) | |
while test $top -lt $l; do | |
echo "evaluate-commands %{ | |
execute-keys vj | |
echo -to-file $kak_response_fifo %val{window_range} | |
}" > $kak_command_fifo | |
last="$y $x $h $w" | |
read y x h w < $kak_response_fifo | |
top=$((y+1)) | |
if [ "$y $x $h $w" = "$last" ]; then | |
break | |
fi | |
done | |
) | |
} | |
} | |
map -docstring 'window bottom' global goto b '<esc>:goto-bottom<ret>' | |
map -docstring 'window center' global goto c '<esc>:goto-center<ret>' | |
map -docstring 'window top' global goto t '<esc>:goto-top<ret>' | |
map -docstring 'cursor on bottom' global view b '<esc>:view-bottom<ret>' | |
map -docstring 'center cursor (vertically)' global view c '<esc>:view-center<ret>' | |
map -docstring 'cursor on top' global view t '<esc>:view-top<ret>' | |
map global normal <c-b> ':goto-top<ret>kvb' | |
map global normal <c-f> ':goto-bottom<ret>jvt' | |
map global normal <c-u> ':goto-center<ret>vb' | |
map global normal <c-d> 'vt:goto-center<ret>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No worries, I'm happy to implement it too once I get around to.
I think C++ in general has gotten much better. I'm quite happy with kak-lsp + clangd. The Kakoune code is mostly very obvious, there are hardly any surprises.
Not yet sure about the exact behavior of
<c-u>
and<c-d>
. My muscle memory was thrown off a bit, perhaps they should have Vim behavior (always maintain the cursor position if possible). That should make it easier to track the cursor while scrolling. I think I'll try that one as preliminary patch.