Skip to content

Commit

Permalink
refactor: simplify s:trans_special_key
Browse files Browse the repository at this point in the history
  • Loading branch information
kawarimidoll committed Nov 21, 2023
1 parent 202fe8b commit 72dd18a
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions k.vim
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,9 @@ function! k#toggle() abort
return k#is_enable() ? k#disable() : k#enable()
endfunction

" e.g. <space> -> \<space>
function! s:trans_special_key(str) abort
return a:str->substitute('<space>', "\<space>", 'g')
\ ->substitute('<s-space>', "\<s-space>", 'g')
\ ->substitute('<cr>', "\<cr>", 'g')
\ ->substitute('<bs>', "\<bs>", 'g')
\ ->substitute('<c-a>', "\<c-a>", 'g')
\ ->substitute('<c-b>', "\<c-b>", 'g')
\ ->substitute('<c-d>', "\<c-d>", 'g')
\ ->substitute('<c-e>', "\<c-e>", 'g')
\ ->substitute('<c-f>', "\<c-f>", 'g')
\ ->substitute('<c-g>', "\<c-g>", 'g')
\ ->substitute('<c-h>', "\<c-h>", 'g')
\ ->substitute('<c-i>', "\<c-i>", 'g')
\ ->substitute('<c-j>', "\<c-j>", 'g')
\ ->substitute('<c-k>', "\<c-k>", 'g')
\ ->substitute('<c-l>', "\<c-l>", 'g')
\ ->substitute('<c-m>', "\<c-m>", 'g')
\ ->substitute('<c-n>', "\<c-n>", 'g')
\ ->substitute('<c-o>', "\<c-o>", 'g')
\ ->substitute('<c-p>', "\<c-p>", 'g')
\ ->substitute('<c-q>', "\<c-q>", 'g')
\ ->substitute('<c-r>', "\<c-r>", 'g')
\ ->substitute('<c-s>', "\<c-s>", 'g')
\ ->substitute('<c-t>', "\<c-t>", 'g')
\ ->substitute('<c-u>', "\<c-u>", 'g')
\ ->substitute('<c-v>', "\<c-v>", 'g')
\ ->substitute('<c-w>', "\<c-w>", 'g')
\ ->substitute('<c-x>', "\<c-x>", 'g')
\ ->substitute('<c-y>', "\<c-y>", 'g')
\ ->substitute('<c-z>', "\<c-z>", 'g')
return substitute(a:str, '<[^>]*>', {m -> eval($'"\{m[0]}"')}, 'g')
endfunction

function! k#initialize() abort
Expand Down

0 comments on commit 72dd18a

Please sign in to comment.