Skip to content
Bruno Heridet edited this page Oct 4, 2017 · 17 revisions

How to select all occurrences of the main selection?

map global user a '*%s<c-/><ret>' -docstring 'select all'

How to make x select lines downward and X select lines upward?

more here

def -hidden -params 1 extend-line-down %{
  exec "<a-:>%arg{1}X"
}
def -hidden -params 1 extend-line-up %{
  exec "<a-:><a-;>%arg{1}K<a-x>"
}
map global normal x ":extend-line-down %val{count}<ret>"
map global normal X ":extend-line-up %val{count}<ret>"

Also checkout the vertical-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 textobject, more here

def -hidden select-prev-word-part %{
  exec <a-/>[A-Z][a-z]+|[A-Z]+|[a-z]+<ret>
}
def -hidden select-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>
}
map global normal w :select-next-word-part<ret>
map global normal W :extend-next-word-part<ret>

How to convert between common case conventions?

# foo_bar → fooBar
# foo-bar → fooBar
# foo bar → fooBar
def camelcase %{
  exec `s[-_<space>]<ret>d~
}

# fooBar → foo_bar
def snakecase %{
  exec s[A-Z]<ret>`i_<esc>
}

# fooBar → foo-bar
def kebabcase %{
  exec s[A-Z]<ret>`i-<esc>
}

How to keep selections which have more than 10 chars?

First solution using the keep 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 the shell test command [ and the # operator in the var expansion.

Plugins dealing with selections :

  • vertical-selection copy the current selection up and downwards to all lines matching the current selection.
  • interactive-itersel 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