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
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#
#;