Last active
April 18, 2024 14:39
-
-
Save cipharius/6f5132bfbd447c1e89c33ab9583657ee to your computer and use it in GitHub Desktop.
Sort kakoune selections using GNU sort utility
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
define-command sort-selections -params 0.. -override -docstring ' | |
sort-selections: Sort current selections using GNU sort utility | |
All parameters will be passed to the GNU sort utility | |
' %{ | |
# Copy current selections to a temporary sort buffer | |
execute-keys %{"sy} | |
edit -scratch *sort-selections* | |
execute-keys %{"s<a-p>} | |
# Seperate selections with null characters | |
execute-keys %{<a-!>printf '\000'<ret>ggd} | |
# Sort the buffer | |
# Use `head -c-1` to get rid of leading newline | |
execute-keys "%%|head -c-1|sort -z %arg{@}<ret>" | |
# Yank the sorted candidates | |
execute-keys %{%HS\x00<ret>"sy} | |
# Update the original buffer | |
delete-buffer | |
execute-keys %{"sR} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about this generalized version?