Thursday, May 21, 2009

Example of vimrc

Let's face it,IDEs are fancy and cool, but I sometimes wonder to what extent these tools distract us with the real thing: programming. In this sense, the austerity of vi or vim may be helpful to really focus on the programming tasks. Besides, the fact that is console based makes us aware of the file structure of the application we are developing. I like NetBeans a lot, but frankly speaking, I get a bit lost on the file directory when developing Ruby on Rails applications. I really recommend vim even for this purpose. The learning curve may be daunting at first. But I think that it pays at the end (and not only for RoR, but also for Matlab and IDL programs).

Here I post a small snippet with the vimrc I am using.


" Syntax highlighting
syntax on

" Use spaces instead of tabs
set expandtab

" Set numbering
set numberwidth=5
set number

" Set autoindentation with 4 space indentation
set autoindent
set shiftwidth=4

" Set the ruler
set ruler

" Set the CUDA filetype
au BufNewFile,BufRead *.cu set ft=cu
"au BufNewFile,BufRead *.gnu set ft=gnuplot

" Set the searc highlight
set hlsearch

" Set syntax automatic folding
set foldmethod=syntax

" Set foldcolumns
set foldcolumn=3

" Set colorscheme to desert
colorscheme desert

" Instructions to print
" Courtesy of http://vim.wikia.com/wiki/Print_to_a_Postscript_file
let &printexpr="(v:cmdarg=='' ? ".
\"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice)".
\". ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error".
\" : system('mv '.v:fname_in.' '.v:cmdarg) + v:shell_error)"


2 comments:

  1. In order to paste the date in command or insert mode, simply add the following lines in the .vimrc file:

    " Add command to put timestamp (in command or insert mode)
    " Extracted from http://vim.wikia.com/wiki/Insert_current_date_or_time
    nnoremap "=strftime(" - %a %d %b %Y - ")P
    inoremap =strftime(" - %a %d %b %Y - ")

    ReplyDelete
  2. Hello,

    I was trying to add the syntax highlighting functionality to my vim for CUDA files. I Copied the cu.vim to the dir /usr/share/vim/vim*/syntax and then added the line mentioned in your blog i.e.
    au BufNewFile,BufRead *.cu set ft=cu
    to my ~/.vimrc file in home. When i try to refresh the vimrc using
    $. .vimrc
    it gives me the following error,
    bash: au: command not found

    Can you help me with this ?

    Thanks

    ReplyDelete