Ways to quit

In Vim you are more than likely to want to close a file at some point after opening it.

If you open a file, have a skim through and want to close it again, you can do so with the :quit command. This can be shortened to :q.

If you make some rubbish changes and want to quit and discard them, force quit with :q!.

If you make some useful changes you can write them with :w but if you want to write and quit, combine the two with :wq. If the file doesn’t currently have a filename, you can specify one with :wq {file}. If the file is read only, you can force it to save with :wq! – this should work as long as the file has a name.

For a short and sweet alternative, you can write changes (only if any exist) and quit using the :xit command or 😡 for short.

If you prefer to avoid ex commands, you can also use ZZ instead which is perhaps the fastest yet as it’s just a double tap of the same key.

See :help :q for more details.

Lovingly typed (in Vim) by Guy Routledge

comments powered by Disqus… Click Here

In Place code execution with Pipe2Eval

A while ago I wrote about executing Ruby code in Vim. That was cool, but I didn’t like only having that functionality available to Vim.

Then I found the Pipe2Eval Vim plugin. Pipe2Eval works similarly but has much improved support, including Ruby, JS, Python, PHP, CoffeeScript and so on.

Installation is straightforward and unlike the other solution there’s no gems to install.

By default, Pipe2Eval tries to store the temporary files it needs to /dev/shm/. On Mac OS X however, the /dev/ folder is well locked down permissions wise, so what I did was create a new folder, and export the environment variable Pipe2Eval looks for:

mkdir /tmp/shm
$ export PIP2EVAL_TMP_FILE_PATH=/tmp/shm

You may wish to add that second line to your zshrc/bashrc or similar.

Once that’s done, the plugin should work just fine. Highlight some lines you want to execute with Visual mode, and then hit the spacebar.

Here’s an example of it working for both Ruby and JavaScript.

comments powered by Disqus… Click Here