Vimscript: Simple function

Let's make a function in .vimrc and call it with a key mapping.

You start it with function and end it with endfunction. It has a capital letter. This makes it global.

(You use function! if you want to redeclare a function)

Normal mode commands are issued with normal.

function MyFunc()
  normal iHello there
  normal ddPPP

This inserts "Hello there". Then deletes it. Then pastes it three times.

Let's map it to cq. map cq :call MyFunc()^M (You get ^M with ctrl-v <enter>)

And you will get

Hello there
Hello there
Hello there

Edit on github
comments powered by Disqus
Click me