VIM browser plugin to execute commands on files

前端 未结 2 928
粉色の甜心
粉色の甜心 2021-01-07 04:52

I\'m trying NERDtree which is pretty cool, but what I\'d like to do is execute special commands, or scripts, on the selected file.

For example, I\'d like to highligh

2条回答
  •  无人及你
    2021-01-07 05:22

    After research I found a solution that seems to do exactly what I wanted. This piece of code shoud be inserted in a file under ~/.vim/nerdtree_plugin (or equivalent directory under other operating systems):

    call NERDTreeAddKeyMap({
        \ 'key': 'b',
        \ 'callback': 'NERDTreeInsertImage',
        \ 'quickhelpText': 'Insert XHTML tag of image' })
    
    function! NERDTreeInsertImage()
        let n = g:NERDTreeFileNode.GetSelected()
        if n != {}
            let @i = system("~/perl/image.pl " . n.path.str())
            normal ^Wp"ip
        endif
    endfunction
    

    it adds a mapping to key b which runs the function NERDTreeInsertImage() which takes the full path of the selected file in the browser and passes it as an argument to my perl script. Of course ^W is inserted as .

    Hope this can be helpful to some other Vim user :)

    @romainl this is the very simple Perl script (requires ImageMagick module):

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use Image::Magick;
    
    my $source = $ARGV[0];
    
    my $img = Image::Magick->new;
    
    $img->Read($source);
    
    my ( $width, $height ) = $img->Get('width', 'height');
    print qq##;
    

提交回复
热议问题