vim

18 Mar

Convert DOS to UNIX (and UNIX to DOS) in VIM

in programming, vim

Once upon a time I knew a vi mantra for removing carriage returns from a DOS-formatted text file, thus transforming it into a UNIX file.It was something like :%s/^V^M//g. It has become such an ingrained habit that I can still type it without even thinking about it. Muscle memory.

But VIM knows more about a file than that old clunky version of vi did, and there's an easier and more consistent way of converting between DOS and UNIX in VIM.

To convert from DOS to UNIX:

:e ++ff=dos
:setlocal ff=unix
:w

This basically forces the document into DOS mode, and then tells VIM to switch it to a UNIX file. (That closing :w just writes the change to disk.)

ff is VIM's abbreviation for fileformat. If you want to type that all out, you can. And ++? It tells VIM to effectively reopen the current file. So make sure you save your work before running these commands.

To convert from UNIX to DOS is even easier:

:e ++ff=dos
:w

That forces the file into DOS mode and then saves the change to disk.

Since both of these hook into a deeper level of VIM, they're not as prone to bugs and inconsistencies as relying upon a regular expression.

But wait... I need to do something more complicated...

The above is a great way to do simple conversions, but if your needs are more complex, you might want to take a look at the VIM wiki page in this topic.

10 Dec

Using the Go Syntax for Janus VIM

in go, golang, janus, ubuntu, vim

To add the Go language (golang) plugins to Janus-flavored VIM, it's not enough to install the VIM plugins into your system's default location. So using, for example, Ubuntu's vim-syntax-go package will not work.

The best way to install all of the Go VIM plugins is to do the following:

  • Create a directory in your .janus directory for the go VIM plugin: mkdir ~/.janus/go
  • Download a fresh copy of the Go source: hg clone https://code.google.com/p/go/ (you may need to sudo apt-get install mercurial first)
  • Inside of the go/misc directory, find the vim directory
  • Copy the contents of the vim directory to the .janus/go directory: cp -a vim/* ~/.janus/go.
  • Restart VIM

This will give VIM access to all of the Go plugins. Syntax highlighting should immediately work on all *.go files.

04 Feb

Removing trailing whitespace with VIM regular expressions

in oneliner, textmate, vim

While cleaning up old sourcecode that I wrote with TextMate, I'm finding many cases where TextMate left trailing whitespace. To keep with current coding conventions, I am removing these extra spaces.

Here's a quick way to do this in VIM:

:%s/\s\+$//g

This tells VIM to search the entire document for lines that end with one or more whitespace characters. Any matching spaces will be removed.

26 Jan

(Re)Mapping Command-Shift-Arrow Keys in Janus/MacVIM

in janus, mac, vi, vim

Users of the Janus VIM suite may notice a change in the newest version of Janus. In previous versions, one could navigate around split panes (including to and from the file browser) by holding down COMMAND-SHIFT and then typing one of the arrow keys. This feature has been removed from the latest versions of Janus (I'm guessing because of some other conflict).

Here's how to add that back in.

  1. Open your ~/.vimrc.after file.
  2. Add the code shown below.
  3. Save and restart VIM.
19 Jan

Janus VIM on Linux Mint

in janus, linux, linuxmint, vi, vim

VIM with JanusVIM with JanusLinux Mint claims to be the second most popular Linux distribution after Ubuntu. And it is largely based on Ubuntu/Debian. While there are many subtle differences, though, the main one is that Mint supports a broader range of desktop environments -- most notably, Gnome 3.

Janus is a package of tools that turn vanilla VIM into a powerful development environment. It is targeted at GUI versions (gvim and MacVim), and it comes with a large assortment of VIM plugins and scripts.

This short blog shows how to install Janus on a newly installed Linux Mint desktop. It assumes that you can run commands using sudo in a terminal.

10 Jan

Syntax Checking for Drupal in VIM

in drupal, php, phpcs, programming, vi, vim

SyntasticSyntasticVim (VI Improved) is a powerful text editor that comes standard on most versions of Linux, OS X, BSD, and other UNIXes. With thousands of add-ons, console and GUI versions, and a fully scriptable environment, you can transform a humble text editor into a powerful development tool. In fact, there are several Drupal add-ons for vim.

In this article, I explain how to turn on syntax checking for PHP, adding code style validation along with error checking. We do this with three tools: The Syntastic Vim plugin, the PHP CodeSniffer PEAR package, and the Drupal Code Sniffer project from Drupal.org.

04 Jul

Vim Colorschemes

in mac, os x, vi, vim

Here's a small tip for burgeoning Vim (VI Improved) users. Vim supports various colorschemes in its colorized editing mode. If you don't like the default syntax highlighting colorscheme that Vim uses, you can change it easily by running a command like this (within Vim):

:colorscheme koehler

The :colorscheme command takes one argument: the name of the colorscheme. Above, I am setting the syntax highlighting colorscheme to the koehler scheme. At any point, I can change it back to the default by running:

:colorscheme default