vim:keys: Rewrite mapping functions to use dicts
Instead of having a long list of `map` commands, define a dictionary for the mappings and take shortcuts were possible.
This commit is contained in:
@@ -226,28 +226,26 @@ imap <C-q> <C-o>Q
|
|||||||
" Swap movement mappings that act on display lines with the normal ones, making
|
" Swap movement mappings that act on display lines with the normal ones, making
|
||||||
" it easier to navigate long wrapped lines.
|
" it easier to navigate long wrapped lines.
|
||||||
function! MapWrapMovement()
|
function! MapWrapMovement()
|
||||||
|
let l:mappings = {
|
||||||
|
\ 'j': 'gj',
|
||||||
|
\ 'k': 'gk',
|
||||||
|
\ '0': 'g0',
|
||||||
|
\ '^': 'g^',
|
||||||
|
\ '$': 'g$',
|
||||||
|
\ 'gj': 'j',
|
||||||
|
\ 'gk': 'k',
|
||||||
|
\ 'g0': '0',
|
||||||
|
\ 'g^': '^',
|
||||||
|
\ 'g$': '$',
|
||||||
|
\ }
|
||||||
if &wrap
|
if &wrap
|
||||||
noremap j gj
|
for [l:from, l:to] in items(l:mappings)
|
||||||
noremap k gk
|
execute 'noremap ' .. l:from .. ' ' .. l:to
|
||||||
noremap 0 g0
|
endfor
|
||||||
noremap ^ g^
|
|
||||||
noremap $ g$
|
|
||||||
noremap gj j
|
|
||||||
noremap gk k
|
|
||||||
noremap g0 0
|
|
||||||
noremap g^ ^
|
|
||||||
noremap g$ $
|
|
||||||
else
|
else
|
||||||
noremap j j
|
for l:key in keys(l:mappings)
|
||||||
noremap k k
|
execute 'silent! unmap ' .. l:key
|
||||||
noremap 0 0
|
endfor
|
||||||
noremap ^ ^
|
|
||||||
noremap $ $
|
|
||||||
noremap gj gj
|
|
||||||
noremap gk gk
|
|
||||||
noremap g0 g0
|
|
||||||
noremap g^ g^
|
|
||||||
noremap g$ g$
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
augroup WrapMovementMappings
|
augroup WrapMovementMappings
|
||||||
@@ -360,6 +358,10 @@ endfunction
|
|||||||
vmap <silent> <leader>j <Cmd>call ExpandVisualSelection(1)<CR>
|
vmap <silent> <leader>j <Cmd>call ExpandVisualSelection(1)<CR>
|
||||||
vmap <silent> <leader>k <Cmd>call ExpandVisualSelection(-1)<CR>
|
vmap <silent> <leader>k <Cmd>call ExpandVisualSelection(-1)<CR>
|
||||||
|
|
||||||
|
let g:macro_type_mappings = {
|
||||||
|
\ '<Space>': '_',
|
||||||
|
\ }
|
||||||
|
|
||||||
function! s:macro_type()
|
function! s:macro_type()
|
||||||
if !exists('s:macro_type')
|
if !exists('s:macro_type')
|
||||||
let s:macro_type = 0
|
let s:macro_type = 0
|
||||||
@@ -371,68 +373,24 @@ function! s:macro_type()
|
|||||||
" Disable on InsertLeave
|
" Disable on InsertLeave
|
||||||
au! macro_type InsertLeave * call s:macro_type()
|
au! macro_type InsertLeave * call s:macro_type()
|
||||||
|
|
||||||
imap <Space> _
|
for [l:from, l:to] in items(g:macro_type_mappings)
|
||||||
imap a A
|
execute 'imap ' .. l:from .. ' ' .. l:to
|
||||||
" {{{
|
endfor
|
||||||
imap b B
|
|
||||||
imap c C
|
for l:key in "abcdefghijklmnopqrstuvwxyz"
|
||||||
imap d D
|
execute 'imap ' .. l:key .. ' ' .. toupper(l:key)
|
||||||
imap e E
|
endfor
|
||||||
imap f F
|
|
||||||
imap g G
|
|
||||||
imap h H
|
|
||||||
imap i I
|
|
||||||
imap j J
|
|
||||||
imap k K
|
|
||||||
imap l L
|
|
||||||
imap m M
|
|
||||||
imap n N
|
|
||||||
imap o O
|
|
||||||
imap p P
|
|
||||||
imap q Q
|
|
||||||
imap r R
|
|
||||||
imap s S
|
|
||||||
imap t T
|
|
||||||
imap u U
|
|
||||||
imap v V
|
|
||||||
imap w W
|
|
||||||
imap x X
|
|
||||||
imap y Y
|
|
||||||
imap z Z
|
|
||||||
" }}}
|
|
||||||
else
|
else
|
||||||
let s:macro_type = 0
|
let s:macro_type = 0
|
||||||
au! macro_type
|
au! macro_type
|
||||||
|
|
||||||
iunmap <Space>
|
for l:key in keys(g:macro_type_mappings)
|
||||||
iunmap a
|
execute 'iunmap ' .. l:key
|
||||||
" {{{
|
endfor
|
||||||
iunmap b
|
|
||||||
iunmap c
|
for l:key in "abcdefghijklmnopqrstuvwxyz"
|
||||||
iunmap d
|
execute 'iunmap ' .. l:key
|
||||||
iunmap e
|
endfor
|
||||||
iunmap f
|
|
||||||
iunmap g
|
|
||||||
iunmap h
|
|
||||||
iunmap i
|
|
||||||
iunmap j
|
|
||||||
iunmap k
|
|
||||||
iunmap l
|
|
||||||
iunmap m
|
|
||||||
iunmap n
|
|
||||||
iunmap o
|
|
||||||
iunmap p
|
|
||||||
iunmap q
|
|
||||||
iunmap r
|
|
||||||
iunmap s
|
|
||||||
iunmap t
|
|
||||||
iunmap u
|
|
||||||
iunmap v
|
|
||||||
iunmap w
|
|
||||||
iunmap x
|
|
||||||
iunmap y
|
|
||||||
iunmap z
|
|
||||||
" }}}
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user