Adding commands to NERDTree

1 view
Skip to first unread message

Matteo Riva

unread,
Nov 7, 2009, 6:19:56 AM11/7/09
to vim...@googlegroups.com
I would like to add custom functions to files in the browser window,
like running a script that inserts the correct XHTML tag when used on an
image, or inserting require() lines on the selected module and so on.

Is it possibile with NERDTree or is there any other browser plugin that
supports this?

Thanks

Matteo Riva

unread,
Nov 8, 2009, 7:28:17 AM11/8/09
to vim...@googlegroups.com

Posting the solution I came up with in case it may be of interest to
other vim users.

file: ~/.vim/nerdtree_plugin/my_plugin.vim

call NERDTreeAddKeyMap({
\ 'key': 'b',
\ 'callback': 'NERDTreeInsertImage',
\ 'quickhelpText': 'Insert XHTML tag of image' })

function! NERDTreeInsertImage()
let n = g:NERDTreeFileNode.GetSelected()
let filepath = n.path.str()
if n != {}
let @i = system("~/perl/image.pl " . filepath)
normal ^W"ip
endif
endfunction

it adds a mapping to key `b` and runs the perl script using the full
file path as argument. Of course ^W is inserted with <C-v><C-w>.

Reply all
Reply to author
Forward
0 new messages