I'm using ViM version 7.2 to edit Java files.
In Java I have to frequently type this code: System.out.println("
print something ");
Is there a way to create a shortcut so that , the entire line of code
System.out.println(""); would be typed with just a few keystrokes?
For example, something like sout <tab> , would expand to
System.out.println("");
I also came across a plugin for ViM called VJDE, I'm trying to find
out if this plugin may have this feature to print
System.out.println(""); with a few keystrokes.
I appreciate any help.
-Rashmi
Rashmi <r...@gmail.com> dixit:
> Is there a way to create a shortcut so that , the entire line of code
> System.out.println(""); would be typed with just a few keystrokes?
>
> For example, something like sout <tab> , would expand to
> System.out.println("");
I would use an iabbr:
:iabbr sout System.out.println("");
(remove the ":" at the beginning of the line if you put this command
into your .vimrc)
--
Raúl "DervishD" Núñez de Arenas Coronado
Linux Registered User 88736 | http://www.dervishd.net
It's my PC and I'll cry if I want to... RAmen!
See the list guidelines:
http://groups.google.com/group/vim_use/web/vim-information
I used imap as suggested previously, it works well because it also
allows positioning the cursor to between the double quotes.
Also , if we add this
:imap sout<Press Tab> System.out.println("");<Esc>F"i
to a new file created under
C:\Program Files\Vim\vimfiles\ftplugin\java.vim
the mapping gets set each time ViM is started, so I don't have to set
the mapping each time.
I got this tip from: http://vim.wikia.com/wiki/VimTip1510 (Keep your
vimrc file clean)
I made a newbie mistake by sending this message twice
once to vim...@googlegroups.com and once to v...@vim.org thinking it
might not have reached, so sorry about that.
-Rashmi
2009/7/30 Raúl Núñez de Arenas Coronado <rau...@gmail.com>:
Rashmi <r...@gmail.com> dixit:
> I used imap as suggested previously, it works well because it also
> allows positioning the cursor to between the double quotes.
You can do that with iabbr, too, but since the iabbr will be triggered
mostly using <Space> (I mean, "sout<Space>") you will end up with an
space between the "", which may or may not be what you want. The imap is
better in that sense.
> to a new file created under C:\Program
> Files\Vim\vimfiles\ftplugin\java.vim
>
> the mapping gets set each time ViM is started, so I don't have to set
> the mapping each time. I got this tip from:
> http://vim.wikia.com/wiki/VimTip1510 (Keep your vimrc file clean)
I don't know about Windows, but in UNIX you can put that in
".vim/after/ftplugin/java.vim", just in case you need to.
> I made a newbie mistake by sending this message twice once to
> vim...@googlegroups.com and once to v...@vim.org thinking it might not
> have reached, so sorry about that.
Don't worry about that, it's a normal mistake. On the other hand,
please bottom post on this list, quote a small (relevant) part of the
message you are replying to, and put your text underneath.
See the list guidelines:
http://groups.google.com/group/vim_use/web/vim-information
Thanks :)
unless you add the Eatchar function, as documented in
:help iabbreviation
by adding
function! Eatchar(pat)
let c = nr2char(getchar(0))
return (c =~ a:pat) ? '' : c
endfunction
to your .vimrc, and writing your iabbr like this:
iabbrev ibt #!/usr/bin/tclsh<c-r>=Eatchar('\s')<cr>
then when you hit the space the string is inserted but not with a
trailing space, but if you trigger it with <Enter> a carriage
return is inserted
sc
scott <t...@swbell.net> dixit:
> On Friday 31 July 2009 12:52:19 Raúl Núñez de Arenas Coronado
> wrote:
>> You can do that with iabbr, too, but since the iabbr will be
>> triggered mostly using <Space> (I mean, "sout<Space>") you
>> will end up with an space between the "", which may or may not
>> be what you want. The imap is better in that sense.
>
> unless you add the Eatchar function, as documented in
>
> :help iabbreviation
>
> by adding
>
> function! Eatchar(pat)
> let c = nr2char(getchar(0))
> return (c =~ a:pat) ? '' : c
> endfunction
Yes! Thanks a lot for the advice, this is something I've always missed
in the help for iabbr O:) Very useful, since most of the time I prefer
iabbr over imap for certain things.