1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-13 02:05:40 +08:00

Fix: replace the function markdown-insert-URL with a new one. (#2617)

* Fix: replace the function markdown-insert-URL with a new one.

* Doc: update docs for the new markdown_insert_URL.

* Fix: a very very smal promotion.
This commit is contained in:
Lin Kun 2019-02-21 16:19:39 +08:00 committed by Wang Shidong
parent e97974ff35
commit e8d39bea00
3 changed files with 27 additions and 24 deletions

View File

@ -58,8 +58,8 @@ 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()<Cr>
xnoremap <silent> <plug>(markdown-insert-link) :call <SID>markdown_insert_url()<Cr>
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>
augroup spacevim_layer_lang_markdown
autocmd!
autocmd FileType markdown setlocal omnifunc=htmlcomplete#CompleteTags
@ -100,19 +100,22 @@ function! s:generate_remarkrc() abort
return f
endfunction
function! s:markdown_insert_url() abort
let pos1 = getpos("'<")
let pos2 = getpos("'>")
let scope = sort([pos1[2], pos2[2]], 'n')
"FIXME: list scope is not same as string scope index.
let url = @+
if !empty(url)
let line = getline(pos1[1])
let splits = [line[:scope[0]], line[scope[0] : scope[1]], line[scope[1]:]]
let result = splits[0] . '[' . splits[1] . '](' . url . ')' . splits[2]
call setline(pos1[1], result)
function! s:markdown_insert_url(visual) abort
if !empty(@+)
let l:save_register_unnamed = @"
if a:visual
normal! gvx
else
normal! diw
endif
let @" = '[' . @" . '](' . @+ . ')'
if col('.') == col('$') - 1
normal! p
else
normal! P
endif
let @" = l:save_register_unnamed
endif
keepjumps call cursor(pos1[1], scope[0])
endfunction
" this function need context_filetype.vim

View File

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

View File

@ -71,7 +71,7 @@ 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 | Add URL |
| `SPC l k` | Normal/Visual | Add URL for word under cursor or slected word |
| `SPC l p` | Normal | Real-time markdown preview |