My Drupal ready VIM config

For some reason I just can’t stop using vim. This article is not ment to get into the debate of pros and cons between using a modern IDE like Eclipse or Netbeans. However I have tried many IDE’s and always find myself back to pecking away at a terminal. VIM is available out of the box on every modern Unix/Linux/Mac computer out there, and with in 20 seconds I am up and running with the configuration that works for me.

So here is the configuration I use incase anyone else would like to try it out. It supports among other things the following features

  • Support for black terminals
  • Auto indenting after {
  • Syntax highlighting
  • Shows line numbers
  • Dictionary auto completion
  • Shows tabs and extra whitespace
  • Ctrl + B for php syntax checking
  • Ctrl + X for svn commit
  • Ctrl + C for git commit
  • Ctrl + A converts tabs to spaces
  • Ctrl + D Hides line numbers (useful for copying text)
  • Ctrl + F Show line numbers (for when your done)
Hopefully you will find this helpful.
" I use a back background in my editors
set background=dark

" I like highlighted search results
set hlsearch
" Use incremental searching
set incsearch

" Set standard setting for PEAR coding standards
set tabstop=4
set shiftwidth=4

" Auto expand tabs to spaces
set expandtab

" Auto indent after a {
set autoindent
set smartindent

" Linewidth to endless
set textwidth=0

" Do not wrap lines automatically
set nowrap

" Show line numbers by default
set number

" Jump 5 lines when running out of the screen
set scrolljump=10

" Indicate jump out of the screen when 3 lines before end of the screen
set scrolloff=3

" Repair wired terminal/vim settings
set backspace=start,eol

" Map <CTRL>-B to run PHP parser check
noremap <C-B> :!php -l %<CR>

" The completion dictionary is provided by Rasmus:
" http://lerdorf.com/funclist.txt
set dictionary-=/home/karnold/funclist.txt dictionary+=/home/karnold/funclist.txt
" Use the dictionary completion
set complete-=k complete+=k

" This function determines, wether we are on the start of the line text (then tab indents) or
" if we want to try autocompletion
function InsertTabWrapper()
    let col = col('.') - 1
    if !col || getline('.')[col - 1] !~ '\k'
        return "\<tab>"
    else
        return "\<c-p>"
    endif
endfunction

" Remap the tab key to select action with InsertTabWrapper
inoremap <tab> <c-r>=InsertTabWrapper()<cr>

" set list
" set listchars=tab:>-,trail:-
" set listchars=tab:>-,trail:-,eol:$
set ignorecase                  " caseinsensitive searches
set showmode                    " always show command or insert mode
set ruler                      " show line and column information
set showmatch                  " show matching brackets
set formatoptions=tcqor
set whichwrap=b,s,<,>,[,]
set paste
syntax on

" CTRL-X = SVN Commit
map <C-X> :w<CR>:!svn commit *<CR>
" CTRL-C = Git Commit
map <C-C> :w<CR>:!git commit *<CR>

" Convert Tabs to spaces 
map <C-A> :set tabstop=4<CR>:set shiftwidth=4<CR>:retab<CR>
" Hide line numbers
map <C-D> :set nonu<CR>
" Show line numbers
map <C-F> :set number<CR>

if has("autocmd")
  augroup module
    " Drupal *.module and *.install files.
    autocmd BufRead,BufNewFile *.module set filetype=php
    autocmd BufRead,BufNewFile *.install set filetype=php
    autocmd BufRead,BufNewFile *.test set filetype=php
    autocmd BufRead *.txt set tw=78
    " When editing a file, always jump to the last cursor position
    autocmd BufReadPost *
    \ if line("'\"") > 0 && line ("'\"") <= line("$") |
    \   exe "normal! g'\"" |
    \ endif
  augroup END
endif
syntax on

Leave a Reply

See also: