sponsor Vim development Vim logo Vim Book Ad

snippet.vim : Replace a word with any text

 script karma  Rating 34/23, Downloaded by 1907  Comments, bugs, improvements  Vim wiki

created by
Timothy Aldrich
 
script type
utility
 
description
Snippets are fragments of code, usually related to keywords .
For example the C language defines "for" and "do" as keywords,
among others.  Since "for" is usually written
    as :
         for (...;...;...) {
                 //code here
         }
Most users will create an abbreviation for the keyword "for" to add the
parenthesis and curly-braces such as :
         iabb xFor for<space>(<space>;<space>;<space>)<space>{<cr><cr>}

To accomplish this using snippets, create a file with these lines :

for ( <#cursor#>; ; ) {

}

Now when editing a 'c' file, when you type 'for<C-S>' ,for is replaced by the
snippet of code you placed in the file.  Additionally the cursor is placed
between the opening ( and the first ; ... ready for you to begin typing.
 
install details
place plugin/snippet.vim in your ~/.vim/plugin directory
place syntax/snippet.vim in your ~/.vim/syntax directory
place doc/snippet.txt in your ~/.vim/doc
see :he add-local-help for details on adding plugin help.
mkdir ~/.vim/snippets ( read help for alternatives )
mkdir ~/.vim/snippets/<syntax>

to use the snippet syntax file, add :

augroup filetypedetect
  au! BufRead,BufNewFile *.spt setfiletype snippet
augroup END

to your filetype.vim

 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
snippet.zip 1.5 2003-12-19 6.0 Timothy Aldrich Minor fix in the include functionality.
snippet.zip 1.4 2002-08-09 6.0 Timothy Aldrich another Vikas improvement :
changed visual selection from character wise 'v' to line wise 'V'
incorporates all previous fixes see changelog for list
ip used for rating: 3.142.197.198

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github