Archive for the ‘Vim’ Category


Setting all line endings in a DOS file to UNIX

September 13, 2012

If you have a nasty DOS file and you wish to convert the it from any mixture of CRLF/LF-only line endings, so all lines end with LF only:

Save any changes.

Edit file again, using dos file format (‘fileformats’ is ignored).
:e ++ff=dos

This buffer will use LF-only line endings when written.
:setlocal ff=unix

Write buffer using unix (LF-only) line endings.


Stop vim replicating comments on a new line

July 4, 2011

I use vim for programming on Mac OSX. The version of vim has problem sharing clipboard with the mac so I don’t seem to be able to yank to the system clipboard or paste from the system clipboard.

I can paste using the usual cmd+v in insert mode but this types the contents of the system clipboard into VIM. what this means is that when I paste a line of comment in followed by lines of code, the code is commented out as VIM helpfully continues comments on the next line.

To stop vim doing this before a paste from the system clipboard, first issue the VIM command:

:set fo=cqt

To set Vim back into its previous new line continue commenting state use

:set fo=crqt


Case sensitive find and replace in VIM

February 10, 2011

Had trouble finding this for some reason. Normal find and replace in my vim is case insenstive though must totorials I found claim it to be sensetive by default. The following will replace all case instances of book (i.e. Book and BOOK will be replaced by session as well):


If I only want to replace book, I need to use a capital I option like this:


Another useful option is c, which asks you to confirm every instance it finds before replacing it.



Scala syntax highlighting in VIM

November 2, 2010

To get SCALA syntax highlighting in Vim do the following:

1. Download the scala.vim file from here

2. Save it somewhere you can find it (e.g. your ~/.vim/syntax directory; you may need to create this)

3. Edit your ~/.vimrc file and add the following:

au BufRead,BufNewFile *.scala set filetype=scala
au! Syntax scala source ~/.vim/syntax/scala.vim

4. open a .scala file in vim and you should find some basic syntax highlighting working. Great!


Copying out of Vim

September 29, 2010

Occasionally I need to be able to copy text out of a Vim terminal window into another application. Setting mouse=a in my .vimrc disabled the terminal windows copy and paste functionality. However, Vim does have a key combination which will yank into the global clipboard. The keys are:

"+y (copy)
"+x (cut)
"+p (paste)

Note that you need the quote, the plus and the letter.

Unfortunately, this only works if your vim is compiled with +xterm_clipboard. Run the following to see if it is:

vim --version | grep xterm

If you see +xterm_clipboard in the output you are good to go, if it says -xterm_clipboard or is missing then this will not work.

For those of you without this an alternative is to hold down shift while dragging the mouse which allows the selection to be copied by the terminal.