Re: vim help

not really ViEmu specific.
some commands shown in the gif running in the www.viemu.com that I could not found in the vim help:


I wanted to read the manual to learn about them. but I guess I don't know how to use vim help.
I tried:
:help w
:help g
:help )

but did not get the help I needed.
can someone please give me some pointers on how to use vim help.

Last edited by kroiz (2007-07-18 06:25:01)


Re: vim help

Hey kroiz, cool and unexpected question.

:w and :g are 'ex' commands, you need to type ":help :w" and ":help :g" to get vim help on them. Their actual full names are "w[rite]" and "g[lobal]", representing where you can shorten the name to.

":w" just writes the current file to disk. It's similar to "File->Save" in most programs. In vim, but not in ViEmu, you can use ":w filename" to save with a different filename ("Save As"), and you need to add a bang (":w! filename") to overwrite an existing file. Take into account that ViEmu only implements the basic behavior. Many people (including myself) have ":w<return>" burned in their muscle memory.

":g" is one of the most powerful commands in vi/vim. The general syntax is ":g/{re}/{cmd}", where "{re}" stands for a regular expression or search pattern, and "{cmd}" stands for any ex command (without the colon). This is (was) often used with "p" (ex command ":p"), which prints out a line, so the pattern ":g/re/p" is the source of the Unix "grep" utility".

What it does is the following: it searches the whole buffer for the "{re}" pattern, marks all lines where it appears, and then it sets the cursor to each of these lines in turn and executes the given "{cmd}". For example, ":g/hello/p" will print all lines that contain "hello" (in ViEmu, they are printed to the Output pane). ":g/hello/d" uses the ":d" command, which deletes a line, so it deletes all lines containing hello.

The example above uses the ":move 0" command (abbreviated to ":m0". What this command does is it moves the current line to the line give, 0 in this case, meaning "before line 1". Since the regular expression given is "^" (beginning-of-line), the ":m0" command will be run on all lines. If you think a bit about it, this will result in reversing the whole file - actually, ":g/^/m0" is a pretty idiomatic way in vi/vim to reverse the contents of a file.

And finally, I just typed ":)" in the video because I wanted to end it with a smile :)


Re: vim help