Roberto S. wrote:
> Hi sorry for this stupid question, but I'm learning vim.
> I would like to create a "pkg" abbreviation that create the:
> package org.hello.world;
> row in a file found in directory:
> I have added this to my .vimrc:
> autocmd BufRead,BufNew *.java iab pkg <esc>:r!echo "package "%:h:s?src/main/java/??:gs?/?.?";"<CR>
> The problem is: this abbreviation go on next line. I would like to write "package etc..." on the same line.
> I have tried also with register let @a, but I'm unable to obtain a final result.
> Can you help me?
use the expression register and the system() function:
autocmd BufRead,BufNew *.java iab pkg <c-r>=system('package "%:h:s?src/main/java/??:gs?/?.?";')<CR>
The output of the package command is likely to be terminated by a line
feed. This would advance your cursor to the next line. If you don't want
this, you can wrap the call of the system() function with an additional
call of substitute():
autocmd BufRead,BufNew *.java iab pkg <c-r>=substitute(system('package "%:h:s?src/main/java/??:gs?/?.?";'), '\n$', '', 'g')<CR>
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)
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