From 49f533b153a6beb3c876be2cf17fbfbe91897ac7 Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 12 Nov 2020 00:39:24 +0800 Subject: [PATCH] Fall back to defaul URL detection if highlighturl not available. --- core/mappings.vim | 13 +++++++++++-- 1 file 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 iu :call URLTextObj() onoremap iu :call URLTextObj() 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('') + " Since expand('') 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)