User Tools

Site Tools


en:prog:vim

My experience with Vim

New line symbol in search and replace

  \r
  " this inserts a new line after each 'bla'
  :%s/bla/bla\r/

Matching parentheses

  %

Split configuration

The new split appears on the right of the old window

  set splitright

Useful key shortcuts

  map <C-C> <C-W>c            " to close the actual split
  map <C-left> <C-W><left>    " moving left-right between the splits
  map <C-right> <C-W><right>

Open header file in a new split
It takes actual filename, replaces */src/*.cc to */interface/*.h (or */inc/*.h) and tries to open the header file in a new vertical split.

command! Ehead :call EditHeaderFile()

function EditHeaderFile()
	let s:filename=substitute(bufname(""), "\.cc\s*$", ".h", "")
	let s:filename1=substitute(s:filename, '\([a-zA-Z.,0-9]*\)\/\([a-zA-Z.,0-9]*\)$', 'interface\/\2', "")
	let s:filename2=substitute(s:filename, '\([a-zA-Z.,0-9]*\)\/\([a-zA-Z.,0-9]*\)$', 'inc\/\2', "")
	let s:filesOpen=0
	if filereadable(s:filename1)
		exe "vsplit ".s:filename1
		let s:filesOpen+=1
	endif
	if filereadable(s:filename2)
		exe "vsplit ".s:filename2
		let s:filesOpen+=1
	endif
	if s:filesOpen == 0
		echo 'Sorry, no standard header file for this buffer :-('
	endif
endfunction

Do you need a graphical diff?

Try gvimdiff.

Reverse search from DVI viewer

This is partly based on xdvi documentation.

First, I define alias

alias vt='gvim --servername tex --remote-tab-silent'

so as all tex files are opened as tabs in the same gvim vindow (with server name tex). Second, I configured xdvi to run command

gvim --servername tex --remote-tab-silent +%l %f

when reverse search is done. The %l stands for the line number and %f for the filename. The same configuration works for Okular too.

Indentation with spaces

Here is the full story.

If you want no indetation made of space characters

:set expandtab
:set noexpandtab # to get back indentation with tabs

Modifying an already written code

:%retab    # for tabs to spaces
:%retab!   # for spaces to tabs

Modeline for TOTEM SW style

// vim: ts=4 sw=2 sts=2 et

How to switch off automatic indentation

set indentexpr=

How to set window title

set title
set titlesring=your\ title\ here
en/prog/vim.txt · Last modified: 2009/04/30 15:24 (external edit)