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

Re: What does this function do (why does it throw an error)?

Expand Messages
  • Charles E Campbell Jr
    ... Because, the second or subsequent time its sourced, it already existed. Note that .vimrc is already sourced; by doing it manually, you re sourcing it a
    Message 1 of 3 , May 30, 2008
    View Source
    • 0 Attachment
      703designs wrote:
      > this is from a Yahoo! Vim for PHP presentation. They present this
      > function:
      >
      > 48 “ Insert <Tab> or complete identifier
      > 49 “ if the cursor is after a keyword character
      > 50 function MyTabOrComplete()
      > 51 let col = col('.')-1
      > 52 if !col || getline('.')[col-1] !~ '\k'
      > 53 return "\<tab>"
      > 54 else
      > 55 return "\<C-N>"
      > 56 endif
      > 57 endfunction
      >
      > inoremap <Tab> <C-R>=MyTabOrComplete()<CR>
      >
      > Which throws the following error when I source .vimrc, although it
      > does work fine:
      >
      > Error detected while processing /Users/myusername/.vimrc:
      > line 57:
      > E122: Function MyTabOrComplete already exists, add ! to replace it
      >
      > I've included the line #s for reference. Can someone explain how this
      > script works? I'd actually like to have it tab-complete filenames,
      > Ctrl-X Ctrl-F, instead of keywords. And why am I getting that error?
      >

      Because, the second or subsequent time its sourced, it already existed.

      Note that .vimrc is already sourced; by doing it manually, you're
      sourcing it a second time. What you probably want to have is to have
      function! MytabOrComplete()
      ...
      endfunction
      which tells vim that its ok to overwrite a previously existing version
      of the function.

      Regards,
      Chip Campbell


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.