0

I have been trying this now for about an hour and I can't seem to get it to work at all! ha ha

This is what I have:

function! Tabber()
let l2=getline(".")
if l2[:2] == 'To:'
    if len(l2) > 4
        exe "silent! normal 5Gi"
    else
        exe "silent! normal 2Gi"
    endif
endif
startinsert
endfunction

Basically when I'm writing an email in VIM for mutt I want to be able to hit the Tab key when done writing the To: address and I want it to decide if the line I'm on has To: on it, then if it's more than 4 character's that mean's I have an address entered, if not then stay there. If there are more than 4 goto line 5 which is the subject line.

Once done there I want to copy that If for a Subject line to make sure if I'm on the subject line goto line 9 to write the email. So I can just tab my way down ha ha.

For the life of me it won't work. Of course I don't have it connected to tab yet, I am just <Esc>ing out and then:

:call Tabber()

But that should work. :S

Thanks! :)

Conner
  • 30,144
  • 8
  • 52
  • 73
jfreak53
  • 2,239
  • 7
  • 37
  • 53
  • possible duplicate of [VIM check if second line is TO and empty](http://stackoverflow.com/questions/11871748/vim-check-if-second-line-is-to-and-empty) – Conner Aug 08 '12 at 23:19
  • Actually no, that's what started it, that function work's great and is somewhere else in my VimRC. This is a brand new function I am trying to get to work for another use but related to that original since I got my code from it. – jfreak53 Aug 08 '12 at 23:23
  • It just doesn't work, it won't move lines at all. I tried making both line 1 to run like a check to see if it was even doing anything and it's not moving at all. – jfreak53 Aug 08 '12 at 23:28

1 Answers1

1

Your function does work for me, so I'm not sure why you're having trouble with it without some more information. I did modify it though to fit your specifications:

function! Tabber()
   let line=getline(".")
   if line[:2] == 'To:'
      if len(line) > 4 | 5 | endif
   elseif line[:7] == 'Subject:'
      if len(line) > 9 | 9 | endif
   endif
   startinsert!
endfunction
inoremap <Tab> <Esc>:call Tabber()<cr>
Conner
  • 30,144
  • 8
  • 52
  • 73
  • Now that works! What was making mine not work?! The only thing that doesn't work on that one is the in Insert mode, I guess I could use another key combo. – jfreak53 Aug 08 '12 at 23:34
  • It's probably preferable to use a `` key in insert mode. See `:help `. – Conner Aug 08 '12 at 23:37
  • You might check `:imap ` to see if something else is mapped to it. In my case, the snipMate plugin is occupying it. – Conner Aug 08 '12 at 23:45
  • Ohhh yeah, I do use snipMate, I forgot about it :( I'll find another then :) What's the for, I've never found out how to use that? – jfreak53 Aug 08 '12 at 23:56