Loading ...
Sorry, an error occurred while loading the content.

113515Re: What plugin would do this?

Expand Messages
  • Christian Brabandt
    Apr 2, 2010
    • 0 Attachment
      Hi MK!

      On Do, 01 Apr 2010, MK wrote:

      > I'm positive some of you already do this, and I wanna too ;) so bear
      > with me.
      >
      > I map some F-keys with stuff like
      >
      > :imap <f2> for(i=0;i ;i++)
      > :imap <f3> vector< >::iterator it = xxx.begin(), end = xxx.end()
      > :imap <f4> while (my ($k,$v) = each %
      >
      > I'd have a about a hundred of those if I could use a popup menu, ala
      > completion ctrl-n/p, just a alphebetized list.

      I don't know if there is a plugin that does this kind of stuff. I would
      do it like this:

      ,----[ template.vim ]-
      | let s:template = [
      | \ 'for(i=0;i ;i++)',
      | \ 'vector< >::iterator it = xxx.begin(), end = xxx.end()',
      | \ 'while (my ($k,$v) = each %'
      | \ ]
      |
      | fun! CompleteTemplate(findstart, base)
      | if a:findstart
      | " locate the start of the word
      | let line = getline('.')
      | let start = col('.') - 1
      | while start > 0 && line[start - 1] =~ '\a'
      | let start -= 1
      | endwhile
      | return start
      | else
      | let res = []
      | for item in s:template
      | if item =~# '^' . a:base
      | call add(res, item)
      | endif
      | endfor
      | return res
      | endif
      | endfun
      | set completefunc=CompleteTemplate
      `----

      Define your template stuff in the variable s:template
      Each line has to begin with a \ and end with a comma (except the last
      line) and each template needs to be put in quotes. Linebreaks are
      trickier though. I am not sure right now, how to insert a linebreak. For
      a tab, you could use \t in double quotation marks.

      Source this file (or if you'd like to have this as a plugin, put it in
      your ~/.vim/plugin directory if you are on Unix or $VIM and for Windows
      put it in your $HOME/vimfiles/plugin directory (and create directories
      that do not exist yet). The restart vim and this file should always be
      loaded if your .vimrc contains the line
      :filetype plugin on

      Then you can use <ctrl-x><ctrl-u> to complete your code. All matching
      templates will be put on a completion menu.

      regards,
      Christian

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      To unsubscribe, reply using "remove me" as the subject.
    • Show all 8 messages in this topic