Bluhalo IT


Make working via PuTTY and Vim a bit nicer

Posted in linux by Simon Green on the March 17, 2009
Tags: , , ,

If you’re used to working in a nice IDE or some kind of GUI when programming, this may be of interest to you.

The common complaint I hear about when people have to work from the command line such as on remote servers is that there is no nice editor. To me this sounds ludicrous just because I’m used to using Vi all day, but I can see how it would be a problem to those used to a prettier interface :)

Insert the following lines into a .vimrc file in your home directory: ($ vi ~/.vimrc)

:syntax on
:set expandtab
:set tabstop=2
:set shiftwidth=2
:set showtabline=2

This will do the following for you:

  • Enabled coloured syntax highlighting for you while editing, based on language
  • Tell Vi to use the equivalent number of spaces instead of tabs when you hit the Tab key
  • Set the number of spaces inserted to 2
  • Set the number of spaces inserted when indenting to 2
  • Force the tab bar to be shown along the top all the time

Here we use double spacing instead of Tabs in line with the Symfony standards. You can adjust the values above to fit whatever your coding standards are.

You can navigate between tabs by using:
:tabn & :tabp:
open new tabs with:
:tabe
and open files into a new tab with:
:tabe filename
When you’re at the command line, you can open multiple files at once into multiple tabs by doing:
$ vi file1.php file2.php -p

Finally, if you are a windows user and use PuTTY to connect to servers over SSH, you should definitly override the default colors. Right click the task bar of your open PuTTY session, go to the colours section, and check the box for “Use system colours”. This makes the background white instead of black, and stops you having to squint to make out the annoying blue against black you get when working remotely.

Leave a Reply