Last active
January 21, 2025 10:40
Revisions
-
Konfekt revised this gist
Jan 21, 2025 . 2 changed files with 1 addition and 55 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ This has been included in `:help netrw-handler` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,55 +0,0 @@ -
Konfekt revised this gist
Sep 27, 2024 . No changes.There are no files selected for viewing
-
Konfekt revised this gist
Sep 25, 2024 . 1 changed file with 30 additions and 44 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,69 +1,55 @@ " Better gx to open URLs. " " Adapted from https://github.com/habamax/.vim/blob/d5087779fee4a7372c1dd2c407674997fdb1268d/autoload/os.vim " to use in particular :Open command from https://gist.github.com/Konfekt/8e484af2955a0c7bfe82114df683ce0f " See also https://gist.github.com/AndrewRadev/1ba9eba62df82d616fc8040338c4c4e1 " URL regexes let s:regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}' func! s:GetURL() abort " markdown URL such as [link text](http://ya.ru 'yandex search') try let save_view = winsaveview() if searchpair('\[.\{-}\](', '', ')\zs', 'cbW', '', line('.')) > 0 return matchstr(getline('.')[col('.')-1:], '\[.\{-}\](\zs'..s:regex_url..'\ze\(\s\+.\{-}\)\?)') endif finally call winrestview(save_view) endtry " HTML URL such as <a href='http://www.python.org'>Python is here</a> " <a href="http://www.python.org"/> try let save_view = winsaveview() if searchpair('<a\s\+href=', '', '\%(</a>\|/>\)\zs', 'cbW', '', line('.')) > 0 return matchstr(getline('.')[col('.') - 1 : ], \ 'href=["'.."'"..']\?\zs\S\{-}\ze["'.."'"..']\?/\?>') endif finally call winrestview(save_view) endtry " URL with leading or closing parenthesis (http://google.com) let URL = matchstr(expand("<cWORD>"), '^(\?\zs'..s:regex_url..'\ze)\?$') if !empty(URL) | return URL | endif " Is it a file in the current work dir? let file = expand("<cfile>") if filereadable(file) | return file | endif " .. or that of the current buffer? let path = expand('%') if isdirectory(path) let dir = fnamemodify(path, ':p') elseif filereadable(path) let dir = fnamemodify(path, ':p:h') endif if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif return '' endf func! s:BetterGx() abort let URL = s:GetURL() if !empty(URL) | exe 'Open' escape(URL, '#%') | endif endfunc nnoremap <silent> gx :<c-u>call <SID>BetterGx()<CR> -
Konfekt created this gist
Sep 18, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,69 @@ " Better gx to open URLs in Vim. " " Adapted from https://github.com/habamax/.vim/blob/d5087779fee4a7372c1dd2c407674997fdb1268d/autoload/os.vim " to use in particular :Open command from https://gist.github.com/Konfekt/8e484af2955a0c7bfe82114df683ce0f " See also https://gist.github.com/AndrewRadev/1ba9eba62df82d616fc8040338c4c4e1 func! s:BetterGx() abort " URL regexes let rx_base = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S' let rx_bare = rx_base . '\+' let rx_embd = rx_base . '\{-}' let URL = '' " cursor on " markdown URL such as [link text](http://ya.ru 'yandex search') try let save_view = winsaveview() if searchpair('\[.\{-}\](', '', ')\zs', 'cbW', '', line('.')) > 0 let URL = matchstr(getline('.')[col('.')-1:], '\[.\{-}\](\zs'.rx_embd.'\ze\(\s\+.\{-}\)\?)') endif finally call winrestview(save_view) endtry " asciidoc URL such as http://yandex.ru[yandex search] if empty(URL) try let save_view = winsaveview() if searchpair('\[.\{-}\](', '', ')\zs', 'cbW', '', line('.')) > 0 let URL = matchstr(getline('.')[col('.') - 1 : ], '\[.\{-}\](\zs' . rx_embd . '\ze\(\s\+.\{-}\)\?)') endif finally call winrestview(save_view) endtry endif " HTML URL such as <a href='http://www.python.org'>Python is here</a> " <a href="http://www.python.org"/> if empty(URL) try let save_view = winsaveview() if searchpair('<a\s\+href=', '', '\%(</a>\|/>\)\zs', 'cbW', '', line('.')) > 0 let URL = matchstr(getline('.')[col('.') - 1 : ], \ 'href=["' . "'" . ']\?\zs\S\{-}\ze["' . "'" . ']\?/\?>') endif finally call winrestview(save_view) endtry endif " URL (http://google.com) if empty(URL) let URL = matchstr(expand("<cWORD>"), '^(\zs' . rx_bare . '\ze)$') endif " barebone URL http://google.com if empty(URL) let URL = matchstr(expand("<cWORD>"), rx_bare) endif if empty(URL) return endif exe 'Open! ' . escape(URL, '#%') endfunc nnoremap <silent> gx :<c-u>call <SID>BetterGx()<CR>