Vim Tips Wiki
No edit summary
No edit summary
Line 1: Line 1:
 
When editing html, you can copy and insert automatically image height and width into your html code by pressing F4 or whatever key you like.
 
When editing html, you can copy and insert automatically image height and width into your html code by pressing F4 or whatever key you like.
 
   
 
==Copy and insert any image width and height with F4==
 
==Copy and insert any image width and height with F4==
 
First step is to make sure you have perl installed and the perl module Image::Size.
 
First step is to make sure you have perl installed and the perl module Image::Size.
Then all you need is to add this to your vimrc file :
+
Then all you need is to add this to your vimrc file.
   
 
:"get image size with F4 with perl Image::Size module
 
:"get image size with F4 with perl Image::Size module

Revision as of 14:20, 23 August 2010

When editing html, you can copy and insert automatically image height and width into your html code by pressing F4 or whatever key you like.

Copy and insert any image width and height with F4

First step is to make sure you have perl installed and the perl module Image::Size. Then all you need is to add this to your vimrc file.

"get image size with F4 with perl Image::Size module
fun! PerlImageSize()
:g/src
normal $
normal N
normal 2w
perl << EOF
use Image::Size;
$jo = VIM::Eval("expand('<cfile>')");
$size = Image::Size::html_imgsize("$jo");
VIM::Eval("setreg('a', '$size')");
EOF
normal $
normal "ap
endfun
nnoremap <F4> :call PerlImageSize()<CR>


References

Comments