diff options
| author | jdhao <jdhao@hotmail.com> | 2020-11-12 00:39:24 +0800 |
|---|---|---|
| committer | jdhao <jdhao@hotmail.com> | 2020-11-12 00:39:24 +0800 |
| commit | 49f533b153a6beb3c876be2cf17fbfbe91897ac7 (patch) | |
| tree | 381ab17f2f137cc9c3d1f9d0a50c53fd65c435af /core/mappings.vim | |
| parent | b361fc40532a9808c99f497336239b6fe4b41d5f (diff) | |
Fall back to defaul URL detection if highlighturl not available.
Diffstat (limited to 'core/mappings.vim')
| -rw-r--r-- | core/mappings.vim | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/core/mappings.vim b/core/mappings.vim index 92c3f7d..1e0ac31 100644 --- a/core/mappings.vim +++ b/core/mappings.vim @@ -215,8 +215,17 @@ vnoremap <silent> iu :<C-U>call <SID>URLTextObj()<CR> onoremap <silent> iu :<C-U>call <SID>URLTextObj()<CR> function! s:URLTextObj() abort - " Note that we use https://github.com/itchyny/vim-highlighturl to get the URL pattern. - let url_pattern = highlighturl#default_pattern() + if match(&runtimepath, 'vim-highlighturl') != -1 + " Note that we use https://github.com/itchyny/vim-highlighturl to get the URL pattern. + let url_pattern = highlighturl#default_pattern() + else + let url_pattern = expand('<cfile>') + " Since expand('<cfile>') also works for normal words, we need to check if + " this is really URL using heuristics, e.g., URL length. + if len(url_pattern) <= 10 + return + endif + endif " Note that the index starts at 0, end_idx is index of the character left of " the pattern. let [url, start_idx, end_idx] = matchstrpos(getline('.'), url_pattern) |
