Email: bknpk@hotmail.com Phone: +972-54-7649119
V

 

ASIC/FPGA Design and Verification Out Source Services

VIM running a shell command on a block

  1. This pages show how to mark a block in vim and execute a shell command on it.

  2. First you need to mark the block in your code.
    It is done by putting tags: mt on the top and mb on the bottom.

  3. Second run the shell command:
    :'t,'b !sort
    :'t,'b !uniq

  4. The example, which I selected, sorts the text and removes multiple entries by executing the sort followed uniq shell commands.

  5. Another example, which may be very handy. At work I often need to number vectors in an increment form. So I easily create the following lines:
    signal sig_0 : std_logic;
    signal sig_0 : std_logic;
    signal sig_0 : std_logic;
    signal sig_0 : std_logic;
    signal sig_0 : std_logic;
    signal sig_0 : std_logic;
    signal sig_0 : std_logic;
    signal sig_0 : std_logic;

    begin
    Next I mark my area of work and fire the following perl script on that block:
    :'t,'b !perl vi_inc.pl
    signal sig_0 : std_logic;
    signal sig_1 : std_logic;
    signal sig_2 : std_logic;
    signal sig_3 : std_logic;
    signal sig_4 : std_logic;
    signal sig_5 : std_logic;
    signal sig_6 : std_logic;
    signal sig_7 : std_logic;

    begin
    The script can be easily improved do other functions as well. The increment script is shown below:
    1. #!/bin/perl

    2. $cnt=0;
    3. while (<STDIN>) {
    4.   if($_ =~ /([^\d]*)([0-9]*)(.*)/) {
    5.     $a=$1; $b=$3;
    6.     $out=$a . $cnt . $b;
    7.     print("$out\n");
    8.     $cnt++;
    9.   }
    10. }#while

    Note that for simple renumbering, one can use cat command:
    :'a,'b !cat -n
    In this case the block of text, which is marked by tags a and b, is numbered between 1 to N.

    A complex example for scripting from within vim is shown at the following page.

    To remove all lines from a file except for ones, which start with the word FILE:
    :'a,'b !grep "^FILE"

    For simple increment / decrement operation a MACRO can be created using: ^a and ^x for increment / decrement.

Contact me now at:

  ...


I would be happy to offer my services. Call ASAP !


Home

VIM shift insert to paste data






Search This Site


Feedback This Site




new pages on this site