Can I substitute multiple items in a single regular expression in VIM or Perl?

You can do this in vim using a Dictionary: :%s/quick\|lazy/\={‘quick’:’slow’,’lazy’:’energetic’}[submatch(0)]/g This will change the following text: The quick brown fox ran quickly next to the lazy brook. into: The slow brown fox ran slowly next to the energetic brook. To see how this works, see :help sub-replace-expression and :help Dictionary. In short, \= lets you … Read more

Tabbing visual selection

You can prefix a number, ie. 2> to indent two tab stops. Or, you can use > to indent once, then . to indent again (this works even though the block is no longer highlighted). If you go too far, u will undo one step at a time. Another useful command is gv to restore … Read more

Multiple file types in vim

You can specify to use multiple filetypes at the same time. For example: :setfiletype html.php But most of filetype plugings and syntax files are not designed for such cases. See also :help ‘filetype’

Pathogen does not load plugins

This seems to be common problem caused by the “system” vimrc in some distributions setting filetype on before you set up pathogen. So turning it off and back on again forces plugins to load correctly: call pathogen#runtime_append_all_bundles() filetype off syntax on filetype plugin indent on More info here.

How to launch an EDITOR (e. g. vim) from a python script?

Calling up $EDITOR is easy. I’ve written this kind of code to call up editor: import sys, tempfile, os from subprocess import call EDITOR = os.environ.get(‘EDITOR’, ‘vim’) # that easy! initial_message=”” # if you want to set up the file somehow with tempfile.NamedTemporaryFile(suffix=”.tmp”) as tf: tf.write(initial_message) tf.flush() call([EDITOR, tf.name]) # do the parsing with `tf` … Read more

compiling vim with python support

I’ve also had “… and link flags for Python are sane… no: PYTHON DISABLED” On Ubuntu 10.04 you have to install ‘python2.6-dev‘. The flags for ./configure are: –enable-pythoninterp –with-python-config-dir=/usr/lib/python2.6/config Make sure you got a path to directory, which contains ‘config.c‘ file. Also no ‘/‘ at the end of the path! That caused me problems.