maven - How to traverse up the directory structure and kick off mvn build in vimscript? -
i'm new vim user looking little script allow me call mvn build.
currently map follows
map <f3> :! mvn build<cr> but because tries build in current working directory (currently java development i'm deep in package under src usually)
how might go directory structure mvn build command works correctly?
thank in advance
the vimscript function finddir() can used find src directory. syntax used in second argument (path) has augmentations basic path specification, 1 of ability specify upward search using ;:
let src_dir = finddir('src', ';') this find src directory if it's above current directory.
to build in directory, can run
exec '!cd' shellescape(src_dir) '&& mvn build' i don't think work under windows. in case, think you'd want change directory temporarily using vim's cd command, run command, , change using :cd -.
you can combine commands function
function! runmaveninsrcdir() let src_dir = finddir('src', ';') exec 'cd' fnameescape(src_dir) !mvn build cd - endfunction running function have side effect of clobbering vim's previous current directory: in other words, doing :cd - afterwards won't change same directory have before.
you can arrange have function invoked mapping with
map <f3> :call runmaveninsrcdir()<cr> or command with
command! runmaveninsrcdir call runmaveninsrcdir()
Comments
Post a Comment