One of the features of Sublime Text I used a lot was the snippets, where I could save a portion of text that would be substituted when I typed its trigger (in my case, I used a word followed by tab). The venerable VIM has a number of plugins that support snippets however it’s inbuilt abbreviation support can provide what I need without external dependencies.

To create an abbreviation, use the iabbrev command (can be shortened to ia) - there is also an abbreviate (ab) command but iabbrev makes the abbreviation only apply in insert mode. For example:

iabbrev pydef def method(params):
iabbrev javaclass class name {<CR>}

Note that you can use <CR> for multiline substitutions.

Now, whenever one types pydef followed by any punctuation, in insert mode, VIM will substitute the text specified, the same with javaclass (note that the punctuation you press is retained, so if you press space you get a trailing space - although way to suppress this are in the VIM documenation). To suppress the substitution simply hit Ctrl+V before pressing the punctuation key. You can expand the abbreviation without using punctuation by hitting Ctrl+], which is more convenient for the javaclass example (where one doesn’t want trailing punctuation) but for the pydef example you probably do want a newline so expanding with the return key is more convenient.

Obviously these can be added to your vimrc file to make them persistent and available in all file types.

To remove an abbreviation, use iunabbrev (iuna) (unabbreviate (una) for those defined with abbreviate). E.g. iuna pydef or iuna javaclass to remove the ones defined above. iabclear (iabc) will remove all abbreviations (abclear (abc) for abbreviate).