Vim中增加ga键的vmap功能

ga是Vim自带的查找光标字符的功能,但是在可视模式也并没有切换功能。

在vimrc中添加以下代码即可实现。

比如选中22909按ga,则显示<22909> 0x597d 好

选中597d或0x597d,则显示<597d> 22909 好

vnoremap ga y:call hy_string#get#GetNumAndChar(@0)<CR>

"获取数字的各种格式及对应的字符
function! hy_string#get#GetNumAndChar(num) abort
    "let n = hy_string#get#Select()
    let n = a:num
    if n =~? '\v^\d+$' "10进制
        let n1 = '0x' . printf('%x', n)
    elseif n =~? '\x' || n =~? '^0x' "16进制
        let n1 = printf('%d', '0x' . n)
    endif
    let @" = '<' . n . '> ' . n1 . ' ' . nr2char(n1)
    echo @"
endfunction

 

猜你喜欢

转载自www.cnblogs.com/hyaray/p/9022085.html
GA