• +43 660 1453541
  • contact@germaniumhq.com

Creating a Command in Vim


Creating a Command in Vim

I love vim. And one of the reasons that makes it so appealing is customization. One of the coolest things is the ability to create functions. You bind the functions to commands, and you simply call the commands for the execution.

  1. Create the function:

    function! Spaces2()
        set sw=2
        set ts=2
    endfunction
  2. Bind it to a command:

    command Spaces2 call Spaces2()

Now whenever we want to set 2 spaces for indenting, we’re going to call our new command in vim, regardless of the buffer type:

:Spaces2<cr>

It’s that easy.