• Vim 直接打开网址的 map 设置(重点是字符转义)


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

    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, "
      ")
      "     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
  • 相关阅读:
    mysql BETWEEN操作符 语法
    mysql IN操作符 语法
    mysql LIKE通配符 语法
    mysql TOP语句 语法
    mysql DELETE语句 语法
    mysql Update语句 语法
    mysql INSERT语句 语法
    mysql ORDER BY语句 语法
    mysql OR运算符 语法
    mysql AND运算符 语法
  • 原文地址:https://www.cnblogs.com/hyaray/p/14397346.html
Copyright © 2020-2023  润新知