Frage

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! :)

War es hilfreich?

Lösung

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>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top