René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -

Misc tips for VIM


Search and replace with lower case in VIM

In the command line, enter :%s/\(abc\)/\=tolower(submatch(1))/i

Searching for special characters

com! -nargs=* S exe "let @/='\\V".escape(<q-args>,' \/')."'<bar>norm! n"
This defines a user command (through com!) with the name S.
The command can then be executed with :S some* fancy \string /

Command line editing

The following command makes ctrl-f edit the command line when being in the command line:
:set cedit=^F

Using normal in a script

In order to simulate keystrokes for normal mode in a vim script, one can use normal. For example, the following command deletes the first line:
normal 1Gdd
However, a problem is that this doesn't allow to dynamically specify a line to be deleted. The following wouldn't work
function DelLine(line) 
  normal a:line . "Gdd"
For this to make it work, one has to use execute normal
function DelLine(line) 
  execute "normal " . a:line . "Gdd"

Splitted buffers

Scrolling the top buffer

The following two lines create two maps which can be used to scroll the top split of a window up (by typing ,u) and down (by typing ,d), respectively.
nmap ,u <c-w>t<c-e><c-w>p
nmap ,d <c-w>t<c-y><c-w>p
<c-w>t: This goes to the top window
<c-e>: Moves the buffers content one line up
<c-w>p: Goes to the previous window (the one with the input focus before the top window got it).


Yanking all lines in a buffer that match a pattern

:g/pattern/y A
This command yankes all lines in the buffer that contain 'pattern' into the register a. If there already was something in a, the lines will be appended in the register.
A's content can then be pasted like


View source with gvim instead of notepad in IExplorer





@="c:\\vim\\vim62\\gvim.exe \"%1\""