linux命令---vim常用命令

Vim实用技巧汇总
本文介绍了Vim编辑器中的多项实用技巧,包括排序、统计字节数、进行计算等操作方法,还详细讲解了如何使用Vim添加头文件定义,为用户提供了一套全面的Vim编辑器使用指南。

1、vim中的排序

 

|2 | 22 | 111| 2222|
|1 | 11 | 222| 1111|

:sort /|[^|]\+|[^|]\+/    #sort grep

|1 | 11 | 222| 1111|
|2 | 22 | 111| 2222|

 

2、vim中统计字节字符数

g+[ctrl+g]

 

3、vim中的计算

在vim的插入模式下输入:CTRL+R =

 

4、vim中拷贝鼠标下单词到命令行中

ctrl-r-w

 

5、vim中拷贝指定寄存器中的值到命令行

ctrl-r+reg_name

 6、vim添加头文件

function InsertHeadDef(firstLine, lastLine)
    if a:firstLine <1 || a:lastLine> line('$')
        echoerr 'InsertHeadDef : Range overflow !(FirstLine:'.a:firstLine.';LastLine:'.a:lastLine.';ValidRange:1~'.line('$').')'
        return ''
    endif
    let sourcefilename=expand("%:t")
    let definename=substitute(sourcefilename,' ','','g')
    let definename=substitute(definename,'\.','_','g')
    let definename = toupper(definename)
    exe 'normal '.a:firstLine.'GO'
    call setline('.', '#ifndef _'.definename."_")
    normal ==o
    call setline('.', '#define _'.definename."_")
    exe 'normal =='.(a:lastLine-a:firstLine+1).'jo'
    call setline('.', '#endif')
    let goLn = a:firstLine+2
    exe 'normal =='.goLn.'G'
endfunction
function InsertHeadDefN()
    let firstLine = 1
    let lastLine = line('$')
    let n=1
    while n < 20
        let line = getline(n)
        if n==1 
            if line =~ '^\/\*.*$'
                let n = n + 1
                continue
            else
                break
            endif
        endif
        if line =~ '^.*\*\/$'
            let firstLine = n+1
            break
        endif
        let n = n + 1
    endwhile
    call InsertHeadDef(firstLine, lastLine)
endfunction
nmap ,ha :call InsertHeadDefN()<CR>

 

转载于:https://www.cnblogs.com/tianzhiyi/p/5358346.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值