Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
Adria Arrufat edited this pageNov 28, 2022 ·17 revisions

How to select all occurrences of the main selection?

mapglobal user a'*%s<ret>' -docstring'select all'

Explanation

  • * puts the content of the main selection in the search register/
  • % selects the whole buffer
  • s opens a prompt waiting for a regex which will be used to make sub-selections. If nothing is entered and the prompt is validated with<ret>, the content of the search register is used by default.

Movements

How to makex select lines downward andX select lines upward?

more here

def -params1 extend-line-down %{exec"<a-:>%arg{1}X"}def -params1 extend-line-up %{exec"<a-:><a-;>%arg{1}K<a-;>"try %{exec -draft';<a-K>\n<ret>'exec X  }exec'<a-;><a-X>'}mapglobal normal x':extend-line-down %val{count}<ret>'mapglobal normal X':extend-line-up %val{count}<ret>'

Also checkout thevertical-selection plugin

How to make word keys discern camelCase or snake_case parts?

so when you want to select the word - you select it like a text-object,more here

def -hiddenselect-prev-word-part %{exec <a-/>[A-Z][a-z]+|[A-Z]+|[a-z]+<ret>}def -hiddenselect-next-word-part %{exec /[A-Z][a-z]+|[A-Z]+|[a-z]+<ret>}def -hidden extend-prev-word-part %{exec <a-?>[A-Z][a-z]+|[A-Z]+|[a-z]+<ret>}def -hidden extend-next-word-part %{exec ?[A-Z][a-z]+|[A-Z]+|[a-z]+<ret>}mapglobal normalw :select-next-word-part<ret>mapglobal normal W :extend-next-word-part<ret>

See:https://github.com/delapouite/kakoune-hump

Mapping (transforming the content of each selection)

How to convert between common case conventions?

# foo_bar → fooBar# foo-bar → fooBar# foo bar → fooBardef camelcase %{exec'`s[-_<space>]<ret>d~<a-i>w'}# fooBar → foo_bar# foo-bar → foo_bar# foo bar → foo_bardef snakecase %{exec'<a-:><a-;>s-|[a-z][A-Z]<ret>;a<space><esc>s[-\s]+<ret>c_<esc><a-i>w`'}# fooBar → foo-bar# foo_bar → foo-bar# foo bar → foo-bardef kebabcase %{exec'<a-:><a-;>s_|[a-z][A-Z]<ret>;a<space><esc>s[_\s]+<ret>c-<esc><a-i>w`'}

Seehttps://gitlab.com/FlyingWombat/case.kak

How to sort lines?

Pipe your selection intosort:|sort<ret>You can also deduplicate with theuniq command or reverse the letters of a word withrev using similar strategies.

How to prepend lines with their number?

To go from

foobarqux

to

1foo2bar3qux

Make one selection per line (with<a-s> for instance), enter insert mode withI to move cursors at the beginning of each line and insert the content of theindex register with<c-r>#.

Filtering (reducing the number of multiple selections)

How to keep selections which have more than 10 chars?

First solution using thekeep regex primitive<a-k>:

<a-k>.{10,}

Second solution using the$ primitive.In this particular case it's longer to type but it's more generic and powerful since you can construct predicates based on any value:

$[ ${#kak_selection} -gt 10 ]<ret>

Here we use a combination of theshell test command[ and the# operator in the var expansion.

How to keep selection based on their index?

The following snippet keeps only "even" selections. So if you have 6 selections, it only keeps selection 2, 4 and 6 :

$[ $((kak_main_reg_hash % 2)) -eq 0 ]<ret>

Here we use a combination of theshell test command[ and the(()) shell arithmetic command.

Design more complex filters by using small wrappers in python or lua:https://discuss.kakoune.com/t/filter-your-selections-more-easily/1296

How to select the smallest single selection containing every selection?

defselection-hull %{eval -save-regs'abc' %{exec'"aZ''<space>"bZ''"az<a-space>"cZ'eval -itersel %{exec'"b<a-Z>u' }exec'"bz'  }}

See Also

Plugins dealing with selections :

  • vertical-selection copy the current selection up and downwards to all lines matching the current selection.
  • phantom-selection interactively iterate over the current selections one by one.
  • select-view select the visible part of a buffer.
  • auto-percent enhance some primitives with bigger selections
Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp