sponsor Vim development Vim logo Vim Book Ad

smart_cr : Inserting snippets in new line

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

created by
Valentin Valyaeff
script type
Deprecated, use vimscript#1957

Perhaps you editing C file:
  #include <stdlib.h*>
(* - cursor position)
If you hit Enter, new include directive will be inserted:
  #include <stdlib.h>
  #include <*>

You must create new hash g:smart_cr
  let g:smart_cr = {}
Hash must contain arrays for different filetypes:
  let g:smart_cr.c = [['^#include <', '^>$', "#include \<@@@>"],
                     \['^#include "', '^"$', "#include \"@@@\""]]
When you hit Enter, line is divided on two parts - before and above
the cursor. First two strings are regular expressions for left and
right parts of line. If they matched, third string will be inserted in
new line.
"@@@" is marker where to place cursor. You may redefine it by setting
global variable:
  let g:smart_cr_marker = '<here>'

Another example
This for Embedded ruby:
  let g:smart_cr.eruby = [['<%[^=]', '^\s*%>',  "<% @@@ %>"],
                         \['<%[^=]', '^\s*-%>', "<% @@@ -%>"],
                         \['<%=',    '^\s*%>',  "<%= @@@ %>"],
                         \['<%=',    '^\s*-%>', "<%= @@@ -%>"]]
install details
Place file into plugin folder

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
smart_cr.vim 1.0 2007-07-14 6.0 Valentin Valyaeff 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.
OSDN.net Logo