On Wed, 4 Jul 2012, Roberto S. wrote:

Hi, I'm configuring a variable called $CLASSPATH in order to have javacomplete 
plugin running well.
I'm using a software called "maven" to build the project and I have found that 
executing this command:
  mvn dependency:build-classpath | grep -v "^\["
gives me exactly the classpath it use to compile the project... so using this 
to generate $CLASSPATH seems to be the better way.

To assign that output to $CLASSPATH using <Leader>cp, I have done:
function! ReadMvnClasspath()
 let $CLASSPATH=system('echo \"`mvn dependency:build-classpath | grep -v 
"^\["`\"')

Your command is needlessly complex. Wrapping the `mvn` command in backticks tells the shell to capture the output as a string. Wrapping the backticks in double-quotes prevents the shell treating spaces specially. But then you just echo the output that you captured as a string. So, it's easier to just not capture the output with backticks. This part of the command is all you need:

mvn dependency:build-classpath | grep -v "^\["

(Full command:)
let $CLASSPATH=system('mvn dependency:build-classpath | grep -v "^\["')


endfunction
au BufRead,BufNew *.java nmap <Leader>cp :call ReadMvnClasspath()<CR>

and this run well.
The question is: can you explaing why if I try to avoid the function with next 
command, I obtain an error at startup?
au BufRead,BufNew *.java nmap <Leader>cp :let $CLASSPATH=system('echo \"`mvn 
dependency:build-classpath | grep -v "^\["`\"')

Doing this I obtain at startup:
:!grep -n -v "^\["`\"') /dev/null 2>&1| tee /tmp/<afile>
/bin/bash: -c line 0: unexpected EOF while looking for matching ``'

I'm not sure precisely. Best guess is that Vim treats '|' specially in different contexts. It might work if you replace '|' with '<bar>' in your command. (Can't seem to find the relevant help text.)

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to