By Vi, most people mean vim though nvi and vim are different from vi.
Anyway let us talk about vi the same way we talk about vim.
I am going to talk only about advanced use. I am thinking that most of
you will know
how to use vi by now. Otherwise you dunno Linux anyway. ;)
Okay how to do simple things that are really cool with vi?
$ vi foo.txt
Now inside vi, the : mode is most interesting. Obviously this only
works under command mode.
If you want to read the output of ifconfig, then
: r !ifconfig
will get you or :r !/sbin/ifconfig
The buffer gets filled with the output.
You can also format a text file by wrapping at 72 characters in which
vi acts as a filtering agent.
: %!fmt -w 72
will do it.
Here, % stands for the whole text file you are editing and !(bang)
escapes to the shell invokes fmt -w 72
and spits back the result into the vi buffer.
Now you can also read files.
:r /etc/passwd
will read the file contents into the buffer.
You can flip the character case using the ~ (tilde) operator.
Just move over the characters pressing it.
You can format the file and indent the loops and conditions by
selecting the region and pressing =
This only works in vim.
:%=
Or if you want to use 'v' for selecting then ggvG=
You can check the man page of a word by pressing K under the word.
You can search and replace with
:%s/search/replace/
Of course searching string is a pattern and replacement is a literal.
-Girish
--
Gayatri Hitech
http://gayatri-hitech.com