I’m a new vim user who is looking for a little help with a script that would allow me to call mvn build.
Currently I map this as follows
map <F3> :! mvn build<CR>
but because this tries to do the build in my current working directory (currently java development so I’m deep in a package under src usually)
How might I go up the directory structure so this mvn build command works correctly?
Thank you in advance
The vimscript function
finddir()can be used to find thesrcdirectory. The syntax used in its second argument (path) has some augmentations to basic path specification, one of which is the ability to specify an upward search using the;:This will find the src directory if it’s above the current directory.
To do a build in this directory, you can run
I don’t think this will work under windows. In that case, I think you’d want to change directory temporarily using vim’s
cdcommand, run the command, and then change back using:cd -.You can combine those commands into a function
Running this function will have the side effect of clobbering vim’s previous current directory: in other words, doing
:cd -afterwards won’t necessarily change to the same directory it would have before.You can arrange to have the function invoked by a mapping with
or by a command with