Tip #378: Auto insert Java class template when editing a new Java file
tip karma |
Rating 10/10, Viewed by 523
|
created: |
|
November 27, 2002 8:50 |
|
complexity: |
|
basic |
author: |
|
Pete Kazmier |
|
as of Vim: |
|
6.0 |
If you are lazy like me, tend to use lengthy and verbose Java class names, then this tip is for you. When creating a new Java class file, the first thing that I do after creating it is to add the following block of text:
public class ClassName
{
}
Rather than have to type the ClassName twice (once when you first opened the new file, and then again for this block), you can use this autocmd to insert that text for you automatically:
autocmd BufNewFile *.java
\ exe "normal Opublic class " . expand('%:t:r') . "\n{\n}\<Esc>1G"
<<Microsoft Natural Multimedia Keyboard Scancodes |
1,$ s/^M//g gets rid of control-Ms (windows carriage returns) >>
Additional Notes
|