Monday, March 30, 2009

Toggle Comment in VIM in one line using perl

There are lot of scripts in VIM which can toggle comments for you. But interestingly there is not a one liner which I can execute on systems where I do not have my vimrc file.

try this mapping

:map F2 V:!perl -nle 'if (/^\s*\/\//) { s/\s*\/\/\s*(.*)/$1/g; print } else {print "//".$_}'^Mj

You can map Alt+C or Ctrl+T something which is faster than F2

This mapping will comment and uncomment the C-style comment. I have tried this on Ubuntu and VIM 7.1 and works fine for me

Note: The map command may not work on copying as the VIM may not recognize the Ctrl - M character. You have to Ctrl- V and then Enter to make it work

Friday, March 13, 2009

Singleton versus Static

These are rules which I use to decide where or not my class will be a Singleton or Static:
  1. Control over construction. Timing issues.
  2. Polymorphism.
  3. One versus multiple instances.

Tuesday, March 10, 2009

Formatting XML in VIM - xmllint --format -

XML text can be formatted in VIM by running the xmllint command over the selected text.

!xmllint --format -

Note the hyphen at the last.

Tried searching for sorter options for --format but did not found any.

Monday, March 09, 2009

VNC not working on locked PC

Problem:
---------
I found that the VNC was not working on my PC(Windows XP) when it was locked using Ctrl+Alt+Del. Interestingly it did worked when the PC was not locked.

Solution:
---------
While installing VNC make sure that you select the option to install it as a service so it can be seen in services.msc

On installing VNC, it provides an option to install as a service. If it is not installed as an service, the VNC cannot be done on a locked PC.

Reason:
--------
This is what as told by one of my colleagues. Seems to be logical.

Windows uses API from gina.dll which provides the capabilities for locking/unlocking the workstation. API from gina.dll are accessible only by the windows services and not by other programs.