sponsor Vim development Vim logo Vim Book Ad

Abridge : Vim code snippets creation made easy

 script karma  Rating 6/3, Downloaded by 804  Comments, bugs, improvements  Vim wiki

created by
Justin Domingue
script type
Easily create custom snippets automatically expanded when recognized, or use the default ones provided. No need to hit <TAB> or some other key combinations.

See GitHub for most recent version : https://github.com/justindomingue/Abridge
Animated screenshot : https://github.com/justindomingue/Abridge/blob/master/screenshot.gif

= Example Workflow

In a c or c++ file,

      for<space>i = 0,,i < 10,,++i,,

will become

      for(i = 0; i < 10; ++i) {

Once you hit <space>, vim recognized `for` and expands the snippet as defined in abridge.vim (easily modified). ",," selects the next placeholder (you could change it to <TAB> if you wanted, see below).

= Usage

Abridge comes with some default snippets. The goal is not to be exahaustive, but rather to define commonly use snippets.

You can define your own very easily. Add the command in your .vimrc :

call Abridge("to", "from", "filetype")
        from : abbreviation (contains <1> - see note below)
          to : expanded expression
    filetype : file type on which to apply the abbreviation ('*' for all file types)
This command will create an abbreviation for to which will expand to from in file with type filetype.

Note from must contain <1>. This is where the cursor will be positioned after the expansion.

For example,

call Abridge("for","for(<1>; <2>; <3>) {<CR><4><CR>}", "c,cpp")
will expand for<non-keyword character> to

for(<1>; <2>; <3>) {
Note <non-keyword character> helps vim recognize the abbreviation : <ESC>, <CR>, <space>

- Mapping

,, : go to next <\d> and substitute (if not match is found, insert ",,")

-- Disable Mapping

To overwrite the mapping keys, set g:abridge_map_keys to your preferred keys. For example,

let g:abridge_map_keys = "<tab>"

-- Disable Default Snippets

Add let abridge_default_abb = 0 to your vimrc.
install details
Either copy plugin/abridge.vim to ~/.vim/plugin/ or use pathogen :

    cd ~/.vim/bundle/
    git clone https://github.com/justindomingue/Abridge.git

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
abridge.vim 0.4 2014-03-01 7.0 Justin Domingue Added SelectNextIfSage() which selects next only if match found
abridge.vim 0.3 2014-03-01 7.0 Justin Domingue Fixed a bug
abridge.vim 0.2 2014-03-01 7.0 Justin Domingue Initial upload
ip used for rating:

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.