1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:30:05 +08:00

Add: add a new key binding SPC l K (#2628)

This commit is contained in:
Lin Kun 2019-02-28 11:52:45 +08:00 committed by Wang Shidong
parent df741d6ef2
commit e36007c836
3 changed files with 19 additions and 11 deletions

View File

@ -64,8 +64,10 @@ function! SpaceVim#layers#lang#markdown#config() abort
let g:mkdp_browserfunc = 'openbrowser#open'
" }}}
call SpaceVim#mapping#space#regesit_lang_mappings('markdown', function('s:mappings'))
nnoremap <silent> <plug>(markdown-insert-link) :call <SID>markdown_insert_url(0)<Cr>
xnoremap <silent> <plug>(markdown-insert-link) :<C-u> call <SID>markdown_insert_url(1)<Cr>
nnoremap <silent> <plug>(markdown-insert-link) :call <SID>markdown_insert_link(0, 0)<Cr>
xnoremap <silent> <plug>(markdown-insert-link) :<C-u> call <SID>markdown_insert_link(1, 0)<Cr>
nnoremap <silent> <plug>(markdown-insert-picture) :call <SID>markdown_insert_link(0, 1)<Cr>
xnoremap <silent> <plug>(markdown-insert-picture) :<C-u> call <SID>markdown_insert_link(1, 1)<Cr>
augroup spacevim_layer_lang_markdown
autocmd!
autocmd FileType markdown setlocal omnifunc=htmlcomplete#CompleteTags
@ -79,6 +81,7 @@ function! s:mappings() abort
let g:_spacevim_mappings_space.l = {'name' : '+Language Specified'}
call SpaceVim#mapping#space#langSPC('nmap', ['l','p'], 'MarkdownPreview', 'Real-time markdown preview', 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l','k'], '<plug>(markdown-insert-link)', 'add link url', 0, 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l','K'], '<plug>(markdown-insert-picture)', 'add link picture', 0, 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l', 'r'],
\ 'call call('
\ . string(function('s:run_code_in_block'))
@ -106,20 +109,23 @@ function! s:generate_remarkrc() abort
return f
endfunction
function! s:markdown_insert_url(visual) abort
function! s:markdown_insert_link(isVisual, isPicture) abort
if !empty(@+)
let l:save_register_unnamed = @"
let l:save_edge_left = getpos("'<")
let l:save_edge_right = getpos("'>")
if !a:visual
if !a:isVisual
execute "normal! viw\<esc>"
endif
let l:paste = (col("'>") == col("$") - 1 ? 'p' : 'P')
normal! gvx
let @" = '[' . @" . '](' . @+ . ')'
if a:isPicture
let @" = '!' . @"
endif
execute 'normal! ' . l:paste
let @" = l:save_register_unnamed
if a:visual
if a:isVisual
let l:save_edge_left[2] += 1
if l:save_edge_left[1] == l:save_edge_right[1]
let l:save_edge_right[2] += 1

View File

@ -74,5 +74,6 @@ npm install --global prettier
| 快捷键 | 模式 | 按键描述 |
| ---------- | ------------- | -------------------------------------- |
| `SPC b f` | Normal | 格式化当前文件 |
| `SPC l k` | Normal/Visual | 为光标下的单词或者选中文本增加链接 URL |
| `SPC l k` | Normal/Visual | 为光标下的单词或者选中文本增加 URL 链接|
| `SPC l K` | Normal/Visual | 为光标下的单词或者选中文本增加图片链接 |
| `SPC l p` | Normal | 通过浏览器实时预览当前文件 |

View File

@ -70,8 +70,9 @@ Bullet marker to use for list items (`'-'`, `'*'`, or `'+'`, default: `'-'`).
## Key bindings
| Key bindings | mode | Descriptions |
| ------------ | ------------- | --------------------------------------------- |
| `SPC b f` | Normal | Format current buffer |
| `SPC l k` | Normal/Visual | Add URL for word under cursor or slected word |
| `SPC l p` | Normal | Real-time markdown preview |
| Key bindings | mode | Descriptions |
| ------------ | ------------- | ------------------------------------------------------ |
| `SPC b f` | Normal | Format current buffer |
| `SPC l k` | Normal/Visual | Add URL link for word under cursor or slected word |
| `SPC l k` | Normal/Visual | Add picture link for word under cursor or slected word |
| `SPC l p` | Normal | Real-time markdown preview |