View Single Post
Old 05-12-2007, 05:32 AM   #11
kacir
Wizard
kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.
 
kacir's Avatar
 
Posts: 3,463
Karma: 10684861
Join Date: May 2006
Device: PocketBook 360, before it was Sony Reader, cassiopeia A-20
Quote:
Originally Posted by jimmyzou
Thanks a lot...
Wow, it is really like lot of work... Especailly for a people like me, I really have not been doing programing for many years, so these kinda too complex for me...
Vim has relatively steep learning curve, but it is well worth learning.
Those commands DO look cryptic, I know, but you should give it a try. Download gvim - a gui version of vim.
The most used command in my examples is
:s
That is just a short form of
:substitute
command

For replacing 'foo' with 'bar' on the current line it works like this:
you press <Esc> key to get into command line. Command line is at the bottom of the screen and begins with ':'
then you type
:substitute/foo/bar/

If you want to substitute 'foo' with 'bar' on all lines of file you have to give he substitute command an address.
You could type "apply the substitute command on lines in range from line 1 [represented by number 1] to the last line [you do not know how many lines the file has, so the representation for the last line is $ character]"
Uf. That is a loooong command isn't it?
We would write it like this
press <Esc> to get to the command line and type
:1,$substitute/foo/bar/g
1,$ - means range of all lines and there is a shortcut '%', so you do not have to type three characters '1,$' to write the most commonly used range .
Also substitute can be shortened to just s command so we get:
:%s/foo/bar/g

Now we get to the letter 'g' at the end of the substitute command. g is the "option" and it means "replace all occurences of 'foo' on the line". Without 'g' option the substitute command would only replace the first 'foo' on the line.

Uffff.

And we haven't even scratched the surface yet.
I didn't even get to the 'Regular expressions' yet.
'foo' in our example is a regular expression meaning letters 'f' 'o' 'o'. but regular expressions can be MUCH more ... aehm ... expressive
see http://www.regular-expressions.info/
Regular expressions in vim are even more powerfull than REs on perl. Yes, I can prove it. Just send me a PM ;-)


This all is only a tip of the iceberg.
besides the :substitute command there are another 1152 commands in vim (yes, I have just counted them in the ':help index' built in documentation) and another 211 built-in functions. Combine THAT with thousands of macros, programs, scripts, tips, configurations and syntax definition files on www.vim.org PLUS a very very friendly community on the mailing list and you get THE most powerfull text editor in the world.
vim also has the best documentation I have *ever* seen. And I am quite keen on software manuals ;-)

You do not have to learn all of these commands. Just
:s comand itself makes vim worth learning.
All you really need is about 10 commands and you can manipulate ANY book in text format to suit your taste.

if you learn Vim you will also automaticaly acquire other skills:
- you will be able to use the infamous vi editor. vi is the default editor on just about any Unix out there. There are countless other editors but vi is the one you find installed on ANY Unix out there
- you will be able to use ed editor - a most minimalistic unix editor you get as the last resort when something really, really bad happens to your Unix (like you screw your /etc/fstab file and your Unix (or Linux, FreeBSD) boots into emergency single user mode
- you will be able to write sed scripts
- you will be able to use grep command in Unix
- you will learn 'Regular expressions' - a really powerfull mini language for manipulating (or describing) strings (text objects) Regular expressions are built into most of the Unix tools (vi, ed, ex, sed, grep, more, less and countless others like for example OpenOffice.org). Regular expressions are built into most of modern programming languages like perl, python, ruby, .....

If you are a Windows user and you hesitate to start using such a complicated and intimidating looking tool as gvim try TextPad - a shareware text editor that has very decent Regular expessions support.
Or try EditPad pro http://www.regular-expressions.info/editpadpro.html


Disclaimer: This is not a flamebait to the [X]Emacs users ;-) I am a converted former XEmacs user myself.
kacir is offline   Reply With Quote