Register now and start sharing your code snippets.
-->

A proper vim setup

Shell Script (Bash) posted 6 months ago by marko

Out-of-the-box vim setup is good, but with a few tweaks it gets much better. Install the full version instead of the minimal and also exuberant ctags, which are great for programmers using vim. They let you navigate in the source code like you do in a full fledged IDE .

   1  sudo apt-get install vim exuberant-ctags

Then place the content below into your ~/.vimrc file.

   1  set nocompatible
   2  syntax on
   3  filetype plugin indent on
   4  runtime! macros/matchit.vim
   5  set autoindent          " always set autoindenting on
   6  set smartindent         " smartindent! :)
   7  set nobackup " nobackup
   8  :colorscheme oceandeep
   9  augroup myfiletypes
  10    " Clear old autocmds in group
  11    autocmd!
  12    " autoindent with two spaces, always expand tabs
  13    autocmd FileType ruby,eruby,yaml set ai sw=2 sts=2 et
  14  augroup END
  15  
  16  
  17  " minibufexplorer options
  18  let g:miniBufExplMapWindowNavVim = 1
  19  let g:miniBufExplMapWindowNavArrows = 1
  20  let g:miniBufExplMapCTabSwitchBufs = 1
  21  let g:miniBufExplModSelTarget = 1
  22  
  23  
  24  
  25  
  26  " Add the contents of this file to your ~/.vimrc file
  27  "
  28  " Crucual setting, set to the dir in which your ruby projects reside
  29  
  30  let base_dir = "/work/aktagon/rails" . expand("%")
  31  
  32  " Central additions (also add the functions below)
  33  
  34  :command RTlist call CtagAdder("app/models","app/controllers","app/views","public")
  35  
  36  map <F7> :RTlist<CR>
  37  
  38  " Optional, handy TagList settings
  39  
  40  :nnoremap <silent> <F8> :Tlist<CR>
  41  
  42  let Tlist_Compact_Format = 1
  43  let Tlist_File_Fold_Auto_Close = 1
  44  
  45  let Tlist_Use_Right_Window = 1
  46  let Tlist_Exit_OnlyWindow = 1
  47  
  48  let Tlist_WinWidth = 40
  49  
  50  " Function that gets the dirtrees for the provided dirs and feeds 
  51  " them to the TlAddAddFiles function below
  52  
  53  func CtagAdder(...)
  54  	let index = 1
  55  	let s:dir_list = ''
  56  	while index <= a:0
  57  		let s:dir_list = s:dir_list . TlGetDirs(a:{index})
  58  		let index = index + 1
  59  	endwhile
  60  	call TlAddAddFiles(s:dir_list)
  61  	wincmd p
  62  	exec "normal ="
  63  	wincmd p
  64  endfunc 
  65  
  66  " Adds *.rb, *.rhtml and *.css files to TagList from a given list
  67  " of dirs
  68  
  69  func TlAddAddFiles(dir_list)
  70  	let dirlist = a:dir_list
  71  	let s:olddir = getcwd()
  72  	while strlen(dirlist) > 0
  73  		let curdir = substitute (dirlist, '|.*', "", "")
  74  		let dirlist = substitute (dirlist, '[^|]*|\?', "", "")
  75  		exec "cd " . g:base_dir
  76  		exec "TlistAddFiles " . curdir . "/*.rb"
  77  		exec "TlistAddFiles " . curdir . "/*.rhtml"
  78  		exec "TlistAddFiles " . curdir . "/*.css"
  79  "		exec "TlistAddFiles " . curdir . "/*.js"
  80  	endwhile
  81  	exec "cd " . s:olddir
  82  endfunc
  83  
  84  " Gets all dirs within a given dir, returns them in a string,
  85  " separated by '|''s
  86  
  87  func TlGetDirs(start_dir)
  88  	let s:olddir = getcwd()
  89  	exec "cd " . g:base_dir . '/' . a:start_dir
  90  	let dirlist = a:start_dir . '|'
  91  	let dirlines = glob ('*')
  92  	let dirlines = substitute (dirlines, "\n", '/', "g")
  93  	while strlen(dirlines) > 0
  94  		let curdir = substitute (dirlines, '/.*', "", "")
  95  		let dirlines = substitute (dirlines, '[^/]*/\?', "", "")
  96  		if isdirectory(g:base_dir . '/' . a:start_dir . '/' . curdir)
  97  			let dirlist = dirlist . TlGetDirs(a:start_dir . '/' . curdir)
  98  		endif
  99  	endwhile
 100  	exec "cd " . s:olddir
 101  	return dirlist
 102  endfunc
 103  

Tagged vim