本文介绍了Vim - 扩展 verilog 总线的宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法创建执行以下操作的 vim 宏:

I can't seem to be able to create a vim macro that does the following:

来源:

this_is_a_bus[10:0]
another_bus[2:0]

所需目标:

this_is_a_bus[10]
this_is_a_bus[9]
this_is_a_bus[8]
this_is_a_bus[7]
this_is_a_bus[6]
this_is_a_bus[5]
this_is_a_bus[4]
this_is_a_bus[3]
this_is_a_bus[2]
this_is_a_bus[1]
this_is_a_bus[0]
another_bus[2]
another_bus[1]
another_bus[0]

我尝试做的:我可以搜索 \d\+:\d\+ 并将光标放在第一个数字上,然后用 yw 将其复制到内存中.但是,我似乎无法根据寄存器中的数字告诉 vim 运行粘贴命令.

What I tried to do:I can search for \d\+:\d\+ and put the cursor on the first number, then copy that with yw to the memory. However I can't seem to be able to tell vim to run the paste command on the basis of the number in the register.

我是否以错误的方式接近这个?创建这样的东西的建议方法是什么?

Am I approaching this the wrong way? What's the suggested way to create something like this?

推荐答案

这里有一个函数,可以通过单键自动进行扩展.(在本例中为 )

Here is a function, which could do the expansion automatically by single keystroke. (<F6> in this case)

fun! ExpandIt()
    let pat = '^\([^][]\+\)\[\(\d\+\):\(\d\+\)\]\s*'
    let line = getline('.')
    let lnr = line('.')
    if line !~ pat
        return
    endif
    let exestr = substitute(line,pat,'range(\2,\3,-1)','g')
    let text = substitute(line,pat,'\1','g')
    exec 'let range='.exestr
    let result = []
    for i in range
        call add(result, text.'['.i.']')
    endfor
    call append(lnr, result)
    exec lnr'.d'
endf
nnoremap <F6> :call ExpandIt()<cr>

  • 获取此文件,或将其放入您的 vimrc.
  • 最后一行创建了一个映射,它允许你在该行上按进行扩展
  • 如果该行不是 xxxx[number:number] 格式,则什么都不会发生
  • 我没有检查错误情况,例如 xxx[1:10]xxx[000:000]
    • source this file, or put it in your vimrc.
    • the last line creates a mapping, it allows you to press <F6> on that line to do expansion
    • if the line is not in xxxx[number:number] format, nothing would happen
    • I didn't check error case, like xxx[1:10] or xxx[000:000]
    • 我做了一个小测试,它看起来像:

      I did a little test, and it looks like:

      这篇关于Vim - 扩展 verilog 总线的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 18:43