You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.4KB

  1. " File: autoload/jalcine/mappings.vim
  2. " Author: Jacky Alcine <yo@jacky.wtf>
  3. " Description: Defines dynamic and static mappings.
  4. " Last Modified: August 25, 2017
  5. " vim: set fdm=marker :
  6. " options {{{
  7. let g:jalcine.mappings = {
  8. \ 'leader': ',',
  9. \ 'localLeader': '\\',
  10. \ 'lang': {}
  11. \ }
  12. " }}}
  13. func! jalcine#mappings#apply_bulk(mappings_list, opts) abort " {{{
  14. for l:a_mapping in a:mappings_list
  15. let l:command = l:a_mapping[0]
  16. let l:map_format = 'map'
  17. if has_key(a:opts, 'prefix')
  18. let l:command = a:opts.prefix . l:command
  19. endif
  20. if has_key(a:opts, 'remap')
  21. let l:map_format = 'noremap'
  22. endif
  23. if has_key(a:opts, 'silent')
  24. let l:map_format .= ' <silent>'
  25. endif
  26. let l:modes = get(l:a_mapping, 2, 'n')
  27. let l:idx = 0
  28. while l:idx < len(l:modes)
  29. let l:mode = l:modes[l:idx : 1]
  30. let l:exc_cmd = l:mode . l:map_format
  31. \ . g:jalcine.mappings.leader . l:command
  32. \ . ' '
  33. \ . get(l:a_mapping, 1)
  34. exec l:exc_cmd
  35. let l:idx += 1
  36. endwhile
  37. endfor
  38. endfunc " }}}
  39. func! jalcine#mappings#setup() abort " {{{
  40. " Define the leader!
  41. exec 'let g:mapleader="' . g:jalcine.mappings.leader . '"'
  42. exec 'let g:maplocalleader="' . g:jalcine.mappings.localLeader. '"'
  43. "
  44. " Ensure that InsertLeave is triggered.
  45. inoremap <c-c> <ESC>
  46. "
  47. " {{{ Terminal
  48. tnoremap <Esc> <C-\><C-n>
  49. tnoremap <A-h> <C-\><C-n><C-w>h
  50. tnoremap <A-j> <C-\><C-n><C-w>j
  51. tnoremap <A-k> <C-\><C-n><C-w>k
  52. tnoremap <A-l> <C-\><C-n><C-w>l
  53. nnoremap <A-h> <C-w>h
  54. nnoremap <A-j> <C-w>j
  55. nnoremap <A-k> <C-w>k
  56. nnoremap <A-l> <C-w>l
  57. " }}}
  58. "
  59. " Moving in popmenu menu.
  60. inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
  61. inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
  62. "
  63. " Rewrite 'vhe' to 'vert help'.
  64. cnoremap vhe vert help
  65. "
  66. " Show me tags.
  67. nnoremap <F8> :TagbarToggle<CR>
  68. "
  69. " Focuses Vim.
  70. nnoremap <silent> <leader><space> :Goyo<CR>
  71. "
  72. " Time & Date Values {{{
  73. inoremap <silent> <leader>pt <C-R>=strftime("%Y-%m-%d")<CR>
  74. "
  75. " Inject the current time with the labeling of the time-zone.
  76. inoremap <silent> <leader>py <C-R>=strftime("%H:%M:%S %Z")<CR>
  77. cnoremap <silent> <leader>py <C-R>=strftime("%H.%M.%S_%Z")<CR>
  78. cnoremap <silent> <leader>pY <C-R>=strftime("%H.%M.%S")<CR>
  79. "
  80. " Inject the current date and time (in Insert or Command mode).
  81. inoremap <silent> <leader>pt <C-R>=strftime("%Y-%m-%d %H:%M:%S %Z")<CR>
  82. cnoremap <silent> <leader>pt <C-R>=strftime("%Y%m%d%H%M%S")<CR>
  83. "
  84. " Inject the current date in Insert or Command mode).
  85. inoremap <silent> <leader>pd <C-R>=strftime("%Y-%m-%d")<CR>
  86. cnoremap <silent> <leader>pd <C-R>=strftime("%Y-%m-%d")<CR>
  87. " }}}
  88. "
  89. " {{{ Bulk Mappings
  90. " quickfix
  91. call jalcine#mappings#apply_bulk([
  92. \ ['e', '<ESC>:cnext<CR>'],
  93. \ ['f', '<ESC>:cfirst<CR>'],
  94. \ ['l', '<ESC>:clast<CR>'],
  95. \ ['o', '<ESC>:Copen<CR>'],
  96. \ ['p', '<ESC>:cprevious<CR>'],
  97. \ ['x', '<ESC>:cclose<CR>'],
  98. \ ['X', '<ESC>:windo cclose<CR>'],
  99. \ ], { 'prefix': 'c' })
  100. "
  101. " loclist
  102. call jalcine#mappings#apply_bulk([
  103. \ ['e', '<ESC>:lnext<CR>'],
  104. \ ['f', '<ESC>:lfirst<CR>'],
  105. \ ['l', '<ESC>:llast<CR>'],
  106. \ ['o', '<ESC>:lwindow<CR>'],
  107. \ ['p', '<ESC>:lprevious<CR>'],
  108. \ ['x', '<ESC>:lclose<CR>'],
  109. \ ['X', '<ESC>:windo lclose<CR>'],
  110. \ ], { 'prefix': 'l' })
  111. " }}}
  112. endfunc " }}}