"***************************************************************************** "** Name: StateExp.vim - expand statements ** "** ** "** Type: global VIM plugin for Vim 7 ** "** ** "** Author: Christian Habermann ** "** christian (at) habermann-net (point) de ** "** ** "** License: GNU General Public License 2 (GPL 2) or later ** "** ** "** This program is free software; you can redistribute it ** "** and/or modify it under the terms of the GNU General Public ** "** License as published by the Free Software Foundation; either ** "** version 2 of the License, or (at your option) any later ** "** version. ** "** ** "** This program is distributed in the hope that it will be ** "** useful, but WITHOUT ANY WARRANTY; without even the implied ** "** warrenty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ** "** PURPOSE. ** "** See the GNU General Public License for more details. ** "** ** "** Version: 1.01.00 ** "** tested under Windows (gvim 7.0) ** "** ** "** History: 1.01.00 27. Oct. 2006 ** "** - better alignment of help page if statements are not all ** "** of the same length ** "** - new statement: 'else { }' ** "** 1.00.00 26. Oct. 2006 ** "** initial version ** "** ** "***************************************************************************** "** Description: ** "** The main point this script targets to is to ease writing code. ** "** Just type sw and you get a complete switch(){case;break;} ** "** statement. But it can also be used to add a header to a letter, etc. ** "** What to expand and how to expand can easily be configured. ** "** ** "** To invoke the statement expansion, type a short form of a ** "** statement and press in insert mode. ** "** Memory aid: s (s)tatement expansion ** "** The statement will be expanded. By default the most important ones ** "** of C are defined: ** "** short form: expanded form: ** "** ** "** 'if' 'if ( ) { }' ** "** 'ie' 'if ( ) { } else { }' ** "** 'el' 'else { }' ** "** 'fo' 'for ( ; ; ) { }' ** "** 'wh' 'while ( ) { }' ** "** 'do' 'do { } while ( )' ** "** 'sw' 'switch ( ) { case 0: break; default: break; }' ** "** 'ca' 'case 0: break;' ** "** 'in' '#include ""' ** "** 'is' '#include <>' ** "** 'de' '#define ' ** "** ** "** Press sh to get a list of defined statements. ** "** Memory aid: sh (s)tatement expansion (h)elp ** "** ** "** ** "** Installation: ** "** ============= ** "** Just copy this script into Vim's plugin directory, for details see ** "** Vim help ':help plugin'. ** "** ** "** Configuration: ** "** ============= ** "** To configure StateExp you may set the following variables in your ** "** vimrc-file. If they are not set, defaults will be taken. ** "** ** "** - Mapping 'sexp_MapStatementExpansion' ** "** Press this key in insert mode when cursor is right to the text ** "** that you want to expand. ** "** default is: , means ctrl-s ** "** imap sexp_MapStatementExpansion ** "** ** "** - Mapping 'sexp_MapViewHelp' ** "** Press this msp to get a list of statements that can be expanded. ** "** default is: \sh ** "** map sh sexp_MapViewHelp ** "** ** "** - Variable g:sexp_shiftWidth ** "** This variable defines how much to indent code when expanding ** "** statements, independent from Vim's option 'shiftwidth'. ** "** Default: use Vim's option 'shiftwidth' ** "** ** "** - Variable g:sexp_stats ** "** This variable defines which short forms of statements are known, ** "** to what to expand them and where the cursor should be placed after ** "** expansion. ** "** g:sexp_stats = [ ** "** [ 'short form', 'expanded form', relx, rely], ** "** .... ** "** [ 'short form', 'expanded form', relx, rely] ** "** ] ** "** 'short form': Can be a string with any characters Vim recognizes ** "** as a word. See ':help ' for more informations. ** "** This is case-sensitive, \n is not allowed. ** "** ** "** 'expanded form': The expanded statement. May contain \n and \t to ** "** get multi-line statements. ** "** ** "** relx, rely: Relative cursor position to first character after ** "** expansion. ** "** ** "** Default: By default C statements are used, see script below. ** "** ** "** ** "** Known Limitations: ** "** ================== ** "** This script uses register 9. If you need this register, please ** "** adapt this script. ** "** ** "** ** "** Module prefix is sexp_ ** "** ** "** Happy viming... ** "***************************************************************************** " before doing anything, check whether vim version is ok if ( v:version < 700 ) echoerr "sorry, need Vim version 7.0 or newer" finish endif " allow user to avoid loading this plugin and prevent loading twice if exists ( "g:loaded_sexp" ) finish endif let g:loaded_sexp = 1 "***************************************************************************** "************************** C O N F I G U R A T I O N ************************ "***************************************************************************** " the mappings: if !hasmapto('sexp_MapStatementExpansion') imap sexp_MapStatementExpansion endif imap