Vim scripting: “let” more powerful than you might think

September 22nd, 2007

Anybody familiar with writing vim scripts will probably be familiar with this syntax:

let foo = 5

Those with slightly more experience may even be familiar with the assignment of local and global variables:

let l:foo = 5
let g:foo = 5

But what you might not know is that you can also assign values directly to registers:

let @a = 5
echo @a
input('Press a key to continue ...')
let @a = 10
echo @a

… and environment variables:

let $JAVA_HOME = "/usr/local/java5"
echo $JAVA_HOME
let $JAVA_HOME = "/usr/local/java6"
echo $JAVA_HOME

Makes for some interesting possibilities in vim scripts!

Categories: Software Development |

2 Comments

  1. rms

    isn’t that something.
    been using for 30 years in emacs.

  2. OJ

    @rms: That’s a typical comment by an emacs fanboy.

    @Tom: I wasn’t aware of the local/global assignments, that’s pretty handy. Haven’t had to write VIM scripts for a while, but I’ll bear this in mind next time I do :) Cheers for the ref!

Leave a comment