hyaray

这只是个小功能,但在转义符上也被卡了很久,导致打开的网址只有一部分,特此分享,主要步骤有:

  1. 选中网址
  2. 获取选中内容,可以使用如下函数,注释掉的是另一种方法
    "获取visual模式下选中的内容
    " from interestingwords
    " Why is this not a built-in Vim script function?!
    function! hy_string#get#select() abort
      let [lnum1, col1] = getpos("\'<")[1:2]
      let [lnum2, col2] = getpos("\'>")[1:2]
      let lines = getline(lnum1, lnum2)
      let lines[-1] = lines[-1][: col2 - (&selection == \'inclusive\' ? 1 : 2)]
      let lines[0] = lines[0][col1 - 1:]
      return join(lines, "\n")
    "     let temp = @s
    "     normal! gv"sy
    "     let res = @s
    "     let @s = temp
    "     return res
    endfunction

     

  3. 指定浏览器访问选中内容,重点:转义符是 ^,而不是常规的 \,&符要转成^&即可 里面的g:browser 可以自行换成自己的浏览器路径
vnoremap <F3> :call SmartRun(hy_string#get#select())<cr>
function! SmartRun(str)
    if a:str =~? \'^http\'
        execute \'silent! !start /b \'.g:browser.\' \'.escape(substitute(a:str,\'&\',\'^&\',\'g\'), \'#\')
    elseif a:str =~? \'\v^\{\x{8}(-\x{4}){3}-\x{12}\}$\' "clsid
        execute \'!start explorer.exe shell:::\' . a:str
    else
        execute \'silent! !start \' . a:str
    endif
endfunction

分类:

技术点:

相关文章:

  • 2021-09-13
  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
  • 2021-11-02
  • 2021-09-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-02
  • 2021-05-22
  • 2021-09-18
  • 2022-02-21
  • 2021-09-23
相关资源
相似解决方案