views:

553

answers:

2

The following is the contents of the Windows System Clipboard

  • :function CurrentLineLength
  • : len = strlen(getline("."))
  • : return len
  • :endfunction

I hit the colon and then control r I then hit shift 8 to paste the contents of the system clipboard.

I hit return and vim comes back with E488: Trailing Characters

I see some ^M characters in there and removing them does not help. I do know that I can paste the functions into a .vim file and read them that way so its not crippling but as I work through some examples of vim script this would be nice to have.

Is there something special about how functions are entered in or is it possible to paste them from the system clipboard?

Thanks!

+1  A: 

Vim should not have any problems with carriage returns in command mode (that's what the ^M characters are). I would guess that there are some other characters in the code you're pasting - this is quite possibly the problem if you're pasting from a web page. Try putting the contents of your clipboard into a file and see if it's really what you expect it to be (including all whitespace characters).

soulmerge
I had some fundamental issues with what was on the clipboard... I feel so dense lately...
ojblass
+3  A: 

I'm not sure about pasting multiple lines to command mode, but you can achieve the same thing by simply putting the function in a register and executing the register (same as a macro).

Also, Vim doesn't seem to like that function as you've pasted it, I've made a couple of changes below. If you copy the below to the system clipboard and then press @* from normal mode, it works.

:function CurrentLineLength()
: let len = strlen(getline("."))
: return len
:endfunction
gravious
Yes it does... probably some issue from windows clipboard into a putty window... thanks a bunch
ojblass