References to URIs in email with VIM

Replies:

Parents:

  • None.
Gerald once managed to convert me to VIM[1] for email writing, and
that was definitely a good thing. This editor kicks ass. It's light
and deleting and adding text in emails is really quick and powerful.

So here is my contribution to the VIM world, and something which is
going to make my life much easier. When I write emails, I like to put
URIs at the end because it doesn't obscure the text around it.
However, I always felt that it was a waste of time to:
1) put a number between bracket (that you have to remember).
2) go at the bottom of the message.
3) insert your URI.
4) go back to where you were.
5) resume editing.

I have managed to do steps 1 to 4 in two keystrokes. Here is how it
works.

I type my text:

] I found a cool new site
]
] --
] This is my signature.

I want to add a URI, so I type it between angle brackets:

] I found a cool new site<http://larve.net/people/hugo/>
]    
] --                  
] This is my signature.

I then press ESC and F11:

] I found a cool new site[1]
]
]   1. http://larve.net/people/hugo/
] --                  
] This is my signature.

And I can continue typing:

] I found a cool new site[1]! Yes, I know, it's free advertising for
] my home page.
]
]   1. http://larve.net/people/hugo/
] --                  
] This is my signature.

And I then press F12 to add a blank line before my signature:

] I found a cool new site[1]! Yes, I know, it's free advertising for
] my home page.
]
]   1. http://larve.net/people/hugo/
]
] --                  
] This is my signature.

The link number is increased automatically, so you just forget about
it.

If you are replying to somebody who used up to reference #3, you type
":let @r = 3" before adding your text and your references will be
numbered starting from 4.

Here are the macros:

map <F11> <ESC>:let @r = @r + 1<CR>F<df>maG?^-- $<CR>O<ESC>:set paste<CR>px0x>>i<C-R>r. <ESC>`aa[<C-R>r]<ESC>:set nopaste<CR>a
map <F12> G?^-- $<CR>O<ESC>

Enjoy!

 1. http://www.vim.org/

--
Hugo Haas <[email protected]> - http://larve.net/people/hugo/
Hard work will pay off later. Laziness pays off now!

Re: References to URIs in email with VIM

Replies:

Parents:

On Tue, Feb 20, 2001, Hugo Haas wrote:
> Gerald once managed to convert me to VIM[1] for email writing, and
> that was definitely a good thing. This editor kicks ass. It's light
> and deleting and adding text in emails is really quick and powerful.
>
> So here is my contribution to the VIM world, and something which is
> going to make my life much easier. When I write emails, I like to put
> URIs at the end because it doesn't obscure the text around it.
> However, I always felt that it was a waste of time to:
> 1) put a number between bracket (that you have to remember).
> 2) go at the bottom of the message.
> 3) insert your URI.
> 4) go back to where you were.
> 5) resume editing.
>
> I have managed to do steps 1 to 4 in two keystrokes.

I have actually rewritten it and I managed to do it in only one key
stroke and it now uses a prompt:
1. In insert mode, press <F5>. (F11 was not convenient)
2. Enter the URI at the "Reference: " prompt.
3. Enter the reference numver at the "Reference number: " prompt (or
just enter, to accept the default).
4. Continue typing stuff.

Press <F6> at the end for cosmetic purposes.

Here is the code:

 function InsertRef()
   let @r = @r + 1
   let ref = input("Reference: ")
   let number = input("Reference number (" . @r . "): ")
   if ( number != "" )
     let @r = number
   endif
   execute "normal a[\<C-R>r]\<ESC>G"
   set paste
   ?^-- $
   execute "normal O  " . @r . ". " . ref . "\<ESC>`rf]"
   set nopaste
   let a = col(".")
   normal $
   let b = col(".")
   if ( a == b )
     startinsert!
   else
     normal `rf]l
     startinsert
   endif
 endfuntion

 map! <F5> <ESC>mr:call InsertRef()<CR>
 map <F6> G?^-- $<CR>O<ESC>

--
Hugo Haas <[email protected]> - http://larve.net/people/hugo/
Me fail English? That's unpossible. -- Ralph Wiggum

Re: References to URIs in email with VIM

Replies:

  • None.

Parents:

I became obsessed with this (mainly because Philippe[3] tried to do a
better one for Emacs) and I ended up doing something that works fine
and I documented it at [1]. The code is at [2].

I removed the empty line before the signature cosmetic fix because it
makes it difficult to continue the editing (well, I had found other
solutions but I am happy with this one).

Do send comments/bugs if you have/find any.

 1. http://larve.net/people/hugo/2001/02/email-uri-refs/
 2. http://larve.net/people/hugo/2001/02/email-uri-refs/uri-ref-20010223.vim
 3. http://www.w3.org/People/LeHegaret/
--
Hugo Haas <[email protected]> - http://larve.net/people/hugo/
I would kill everyone in this room for a drop of sweet beer. -- Homer
J. Simpson

HURL: fogo mailing list archives, maintained by Gerald Oskoboiny