Skip to content

Vimscript 简单实例

实例 1

实例展示

这是一个快速注释的脚本

function Commentary()
    let ch = strgetchar(getline('.'), 0)
    if ch == 47
        normal 0d3l
    elseif ch == -1
    else
        normal 0i// 
    endif
endfunction

实例收货

1. 获取当前行
2. 从string中获取char
3. vimscript中的if-else
4. 执行normal模式

注意点

1. 函数名一定要大写
2. 可视模式调用: '<,'>call function()

Comments