How to make Vim and Perforce work together in three easy steps

(Vim logo from http://www.vim.org/)

Step 1: Make sure that the perforce client is in your path. Can you open a shell (or command prompt) and type 'p4'? Do you get a help message from Perforce?

Step 2: Open the .vimrc file (on Windows, look for a _vimrc file) in your home directory. If you don't have one, now's the time to make it. Paste in the following and then close Vim:

nnoremap @p4a :!p4 add %:e
nnoremap @p4e :!p4 edit %:e
nnoremap @p4d :!p4 diff %

Step 3: Go to a file that is managed by Perforce (i.e. with the no read permissions). Open it. In Normal mode, type the following:

@p4e

Rejoice as Vim checks the file out for you. How to check it back in again? Do that from your command line or GUI client. There's no such thing as a free lunch ...

DevOps New Zealand