Tag Archives: vim

Generic vim counters

I needed a way in vim config to use counters and what better way, but to write a function to simultaneously handle all variables and optinally increase or decrease them:

" define and manage counters
" NB! all counters are namespaced globally (g:)
function! Counter(name,...)
" check if this variable already exists or should we initialise it
  if !exists("g:" . a:name)
    exec 'let g:'  . a:name .' = 0'
" if second parameter is given, increase/decrease value
  if a:0 > 0
    exec 'let g:'. a:name .' = g:' . a:name . ' + ' . a:1
  exec 'return g:' . a:name

Usage of the function is as follows:

" Get the current value
echo Counter('mycount')
" Increase value by 1(and return the new value)
echo Counter('mycount', 1)
" Decrease value by 2
echo Counter('mycount', -2)

Vim unindenting comments

I was annoyed that Vim moved all comments to the beginning of the line the moment I entered # sign. Searching around first turned me to smartindent, but I found that was already off.

Then this vimtip shed the light on the monster:

just add to your .vimrc:

set cinkeys-=0#

And you are good to go.