VIM, step by step

19 views
Skip to first unread message

Peyman Taher

unread,
Jul 18, 2007, 11:53:52 AM7/18/07
to fit-ca...@googlegroups.com
Being a computer science student, we always need to use an editor to
edit text files, therefore knowing how to use a good editor can be of
extensive use; VIM (Vi Improved) is one of the most powerful and
popular editors one can learn and do a lot in few key strokes but
learning it at the first place needs patience. So here I try to post a
daily tutorial on how to use Vim, so that by simply reading one small
e-mail a day, hopefully you'll learn an editor you'll be happy all your
life time being with. And of course others can contribute and correct my
mistakes, especially Mr. Nazri :-).

Shall we?

Basic Editing:

$ vim <filename>
will open <filename> for editing using vim
$ gvim <filename>
same thing, but this time a graphical user interface for vim, not
ncurses based.

Vim is a modal editor, meaning that depending on which mode you are in,
different commands and keys mean differently.
Modes are: normal, insert, visual; if the bottom of the screen shows the
filename or blank, you're in normal mode, if there's a --INSERT--,
obvious, and if --VISUAL--, you tell me.

Press i to switch from normal to insert, ESC for the other way, and
leave the visual mode for later, but if so curious, try v.

You can insert text only if you're in insert mode.

Commands starting with : must be issued in normal mode.

Some of the basic commands you need for your hello world are:
:w or :write to save the file (buffer actually, but we'll talk about it
later).
:q or :quite to exit

So here is a what a key logger would capture when I write the hello
world:

vim hello.txt<enter>
iHello World<ESC>
:w
:q

And here we have our first file edited by Vim.
$ cat hello.txt
Hello World

Tomorrow on how to move around in Vim way and other commands such as
undo, redo, delete a line, open a new line, help and so on...

--
Peyman Taher.
GC v.3.12
GCS/M/MU/P/SS d- s+:+ a-- C+++ L+++
P+ E- W++ N+ w--- PS 5? X !tv b+ G++

meisam sarabadani

unread,
Jul 18, 2007, 9:28:03 PM7/18/07
to fit-ca...@googlegroups.com
let me appreciate the great job you have started dude.

Peyman Taher

unread,
Jul 19, 2007, 7:34:12 PM7/19/07
to fit-ca...@googlegroups.com
Okeey, I hope you've done enough practice on the first part; here comes
part two of "Daily Vim".

Vim uses an alternative set of key binding for moving around, though the
usuall arrow keys work fine, but what every Vim user would recommend you
is to use the Vim style which is: h -> left, j -> down, k -> up and l ->
right (all in normal mode). I know it might look a bit odd at the first
place, but believe me, the moment you get comfortable with these keys,
you'll start pushing them even for your web browser.

You can use x to delete a character in normal mode, or d.
dd deletes a line, and o opens a new line to insert below the cursor; O
opens a new line to insert above the cursor and D deletes from cursor to
the end of the line.
(note that D means shift + d)

Undo is u and redo is Ctrl+r.

One of the most interesting features of almost every command in Vim is
that you can specify a counter for them, meaning that one would enter
10dd to delete the next 10 lines or 5ix to insert xxxxx. Nice, huh?!

And the last point for today's tutorial is :help.

Try these to learn more:
ZZ to save and quite; equivalent to :wq
:help x
:help :q
:help :w

Squall_Chua

unread,
Jul 20, 2007, 10:02:57 AM7/20/07
to FIT Cafeteria
Here come to give u moral support to keep posting this here.
Gain benefit from it also. ^^

Peyman Taher

unread,
Jul 20, 2007, 12:21:13 PM7/20/07
to fit-ca...@googlegroups.com
Here is the third section of our "Daily Vim":

A week can be divided into three parts, Monday to Thursday that people
work, Saturday and Sunday that people enjoy their holiday and Friday
which casts into void! So, only a few commands for today...

All of the commands below are to be issued in normal and visual mode,
not in insert mode:

w to move one word forward
b to move one word backward
$ to move to the end of the line
^ to move to the beginning of the line
fX forward search until it finds X and stop over the character
FX backward search and the rest just like f
t and T work exactly same as f and F respectively, except that they stop
on one character before X.

That's it, only a few examples to demonstrate:

One would press 5w to move to 5 word next to it's current position, and
10$ will get you the end of a line which is 10 line after where you
currently are located; same goes with b and ^, and suppose in the
following sentence I want to jump from beginning of the line to the
fourth occurrence of t which is the first t in truth, I would press
4ft.

"A lie told often enough becomes the truth."

Peyman Taher

unread,
Jul 20, 2007, 12:21:57 PM7/20/07
to fit-ca...@googlegroups.com


On 7/20/07, Squall_Chua <Squal...@gmail.com> wrote:

Here come to give u moral support to keep posting this here.
Gain benefit from it also. ^^

Thanks :-)

Wong Ya Ping

unread,
Jul 20, 2007, 3:00:52 PM7/20/07
to fit-ca...@googlegroups.com
Great job Peyman... actually Monday is just an initialization.
--
Wong Ya Ping <ypw...@mmu.edu.my>
Lecturer, Faculty of Information Technology,
Multimedia University, Cyberjaya, Malaysia
Tel: +6 03 8312 5393
Loc: http://www.wikimapia.org/#y=2928421&x=101641163&z=18&l=0&m=a&v=2
GCS/ED/M/P/S/SS d+ s+:+ !a C++ U+ P+ L+>+++ E- W++ N+ o+++ w--- PGP t+>++ 5+ X+ tv- b+$ G++ e+++>++++

meisam sarabadani

unread,
Jul 21, 2007, 1:10:09 AM7/21/07
to fit-ca...@googlegroups.com
peyman thats fantastic, please go ahead, i dun let you stop this great job :D

On 7/21/07, Peyman Taher <peyman...@gmail.com > wrote:

Ian Tan

unread,
Jul 21, 2007, 12:18:27 PM7/21/07
to FIT Cafeteria
someone better start and emacs version of this before this whole
newsgroup becomes vi fanatics ... :-P

On Jul 21, 1:10 pm, "meisam sarabadani" <meisam.sarabad...@gmail.com>
wrote:


> peyman thats fantastic, please go ahead, i dun let you stop this great job
> :D
>

Peyman Taher

unread,
Jul 21, 2007, 9:10:03 PM7/21/07
to fit-ca...@googlegroups.com
yeah, good idea, emacs is good too, just that one needs at least 12 fingers to edit as fast as he can edit with 5 fingers in vim. :-p

Peyman Taher

unread,
Jul 21, 2007, 9:31:43 PM7/21/07
to fit-ca...@googlegroups.com
Session 4 of "Daily Vim":

gg goes to the first line of the text
G goes to the last line
23G goes to line 23 and you can do this by 23j too, and also by :23, choose the one you prefer, all are same.
CTRL+g tells you what position are you in what file at the bottom of the screen, so does CTRL+G.
":set number" configures Vim to show you the line number and ":set nonumber" removes them.
Note that ":set" command is to configure some of the environment configurations of Vim, and one can add them to his ~/.vimrc or /etc/vimrc file (in Linux) or (I'm not quite sure if it's the right place but seems like) C:\Program Files\Vim\_vimrc file (in Windows) so that your configurations are saved and will be loaded every time you open Vim.

CTRL-d moves half a page down and CTRL-u moves half a page up.

Tips: We already know that d and x can be used to delete in normal mode. Now, something nice about the d command is that you can add a motion command to it, and it will delete from the current position of cursor to where the motion command moves:
Example: in "The shortest distance between two points is under construction." the cursor is on 's' of shortest, if you press 'dw', Vim will delete the next word, and in the same fashion, if you press 'd3w' it will delete up to 'two'. Experiment the following commands yourself:
d10G
dfX
dG
dgg
dj
d$
d^
3dfX
d3fX

Tomorrow, we'll talk about more interesting stuff that not every editor can do.
By the way, for those who write programs in Vim, check this out: ":syntax on" ;-)

Behdad Kh

unread,
Jul 22, 2007, 1:07:30 AM7/22/07
to fit-ca...@googlegroups.com
O N L Y  V I M
As a suggestion , isnt it better if you post each session as a single thread ? then if we had a question regards that
session simply we just post on that specific thread , another thing is just write a short session title then we can refer
to them in future , i think it makes it a good classified VIM tutorial by peyman taher .

You know how much we love you man ;)

Wong Ya Ping

unread,
Jul 22, 2007, 1:37:41 AM7/22/07
to fit-ca...@googlegroups.com
better keep it in a single thread...we got too many emails to manage.....
--
Wong Ya Ping <ypw...@mmu.edu.my>
Lecturer, Faculty of Information Technology,
Multimedia University, Cyberjaya, Malaysia
Tel: +6 03 8312 5393
Loc: http://www.wikimapia.org/#y=2928421&x=101641163&z=18&l=0&m=a&v=2
GCS/ED/M/P/S/SS d+ s+:+ !a C++ U+ P+ L+>+++ E- W++ N+ o+++ w--- PGP t+>++ 5+ X+ tv- b+$ G++ e+++>++++

Peyman Taher

unread,
Jul 22, 2007, 2:37:05 AM7/22/07
to fit-ca...@googlegroups.com
One good suggestion, One good complain! What do I do now?

Btw, Behdad, we're waiting eagerly for your LAMP / WAMP daily tutorial :-)

On 7/22/07, Wong Ya Ping <wongy...@gmail.com> wrote:
better keep it in a single thread...we got too many emails to manage.....


On 7/22/07, Behdad Kh < behd...@gmail.com > wrote:
O N L Y  V I M
As a suggestion , isnt it better if you post each session as a single thread ? then if we had a question regards that
session simply we just post on that specific thread , another thing is just write a short session title then we can refer
to them in future , i think it makes it a good classified VIM tutorial by peyman taher .

You know how much we love you man ;)





--
Wong Ya Ping <ypw...@mmu.edu.my >
Lecturer, Faculty of Information Technology,
Multimedia University, Cyberjaya, Malaysia
Tel: +6 03 8312 5393
Loc: http://www.wikimapia.org/#y=2928421&x=101641163&z=18&l=0&m=a&v=2
GCS/ED/M/P/S/SS d+ s+:+ !a C++ U+ P+ L+>+++ E- W++ N+ o+++ w--- PGP t+>++ 5+ X+ tv- b+$ G++ e+++>++++


Reza Iranmanesh

unread,
Jul 22, 2007, 12:25:50 PM7/22/07
to fit-ca...@googlegroups.com

> someone better start and emacs version of this before this whole
newsgroup becomes vi fanatics ... :-P

Oops could be nice, we'll gonna have a classic little war here :

The Church of Emacs, formed by Richard Stallman, is a joke, and while it refers to vi vi vi (which is 6-6-6 in Roman numerals) as the "editor of the beast", it does not oppose the use of vi; rather, it calls proprietary software an anathema. ("Using a free-software version of vi is not a sin; it is a penance.")

As a poke at Emacs' creeping featurism, vi advocates will describe Emacs as "a great operating system, lacking only a decent editor" :)), or they say Emacs is an acronym for "Escape Meta Alt Control Shift" (a jab at Emacs's reliance on modifier keys), or "Eight Megabytes And Constantly Swapping", in reference to Emacs's high system resource requirements in a time when eight megabytes was a great amount of memory. The more modern humorist uses "Eventually Mallocs All Core Storage"

however, i am one of those who have a vi vi vi on his head so cheers to all beasts! :D



On 7/22/07, Peyman Taher <peyman...@gmail.com> wrote:



--
|2324 ||24/\//\/\4/\/35]-[

Peyman Taher

unread,
Jul 22, 2007, 8:35:12 PM7/22/07
to fit-ca...@googlegroups.com
Daily Vim, Session 5:

In our way to edit a file faster, we can also use the following commands:

c followed by a motion, deletes the text from the current position of the cursor until where the motion ends and enters the insert mode, e.g. use cw to replace a word, c$ to change the text from cursor to the end of line.
C to change a whole line.
dd to delete a whole line. Note that C does exactly what ddi does.
J to join lines, meaning that assuming we have the following lines in a file:

"How can you govern a country which
has 246 varieties of cheese?"

Now if you press J while cursor is on the first line, you'll get something like this:

"How can you govern a country which has 246 varieties of cheese?"

And you know that as always, you can specify a number before command, so that 3J concatenates the following three lines.

gJ does exactly what J does, except that it will not remove the spaces and indentations.

. command, yes "dot", repeats the last delete or change command!!! Use it to learn it, but a small example is this:

iostream
fstream
sstream
vector

Move the cursor to the i in iostream, press i to insert, and type #include < and then press escape, now move th cursor to f in fstream, press . and do the same for all the other lines!

Alright, Monday, and you probably have the energy to hear about one of the most useful and nice features of Vim: macros.
I have the following lines in a file:

iostream
fstream
sstream
vector

And here is exactly the sequence of keys I press:

qa^i#include <ESC$a>ESCjq

Note that ESC is not E S C, but the escape key.

and then press:

3@a

And the result is this:

#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>

Nice, hah?! :-)

q start recording a macro, a after that is the name of the macro, characters after that are a sequence of keys needed to change the iostream to #include <iostream> and then q again will stop recording the macro a, and finally @ executes a macro, so 3@a executes macro a for three times.

Have a good Monday :-).

Reza Iranmanesh

unread,
Jul 23, 2007, 7:54:31 AM7/23/07
to fit-ca...@googlegroups.com
Thanks for Macros bro, i was always in wonder about the recording word which sometimes came down the page and didn't let me do my job :D, so it was not the 007 agent.
You go for 20 chapters and we'll all become vim geeks.

Peyman Taher

unread,
Jul 23, 2007, 8:41:43 PM7/23/07
to fit-ca...@googlegroups.com
Daily Vim, Part 6:

There's something called "digraph", I'm don't really use, if you want, type :digraphs and search in :help for it (basically, for special signs like the copyright sign).

To search for a word in the text, one can issue /X in normal mode, and after you press enter the cursor will be locate on X (if present).
So suppose I have the following piece of text in a file:

"My way of joking is to tell the truth. It is the funniest joke in the world."

Now press /joke and then enter, you'll see that the cursor is located over j from joke.

? to search backward.
n to repeat the search command, meaning that if it was forward, find next, if it was backward, find previous.
N does exactly opposite of n.

":set hlsearch" will highlight found strings in the text.
":set nohlsearch" turns off the highlighting thing.
":set incsearch" starts the search while you type. (I like it.)

Tomorrow on regular expressions.

johnsee

unread,
Jul 24, 2007, 11:16:31 PM7/24/07
to FIT Cafeteria
Hey Peyman, nice tutorial on VIM.
:-) Keep it up. A worthwhile read.
(I must confess that I don't use VIM or VI really well anyway...)

On Jul 21, 12:21 am, "Peyman Taher" <peyman.ta...@gmail.com> wrote:

Wong Ya Ping

unread,
Jul 24, 2007, 11:46:11 PM7/24/07
to fit-ca...@googlegroups.com
...hmm..as for me, I can't seems to remember things after a long time i don't use it. I used to be really good with vi long long time ago..before most of you people were born, certainly before you guys knew a,b,c.. :)  Now i can only remember a few command. :(

--
Wong Ya Ping <ypw...@mmu.edu.my>
Lecturer, Faculty of Information Technology,
Multimedia University, Cyberjaya, Malaysia
Tel: +6 03 8312 5393
Loc: http://www.wikimapia.org/#y=2928421&x=101641163&z=18&l=0&m=a&v=2
GCS/ED/M/P/S/SS d+ s+:+ !a C++ U+ P+ L+>+++ E- W++ N+ o+++ w--- PGP t+>++ 5+ X+ tv- b+$ G++ e+++>++++

Peyman Taher

unread,
Jul 25, 2007, 1:40:39 AM7/25/07
to fit-ca...@googlegroups.com
Hi :-)
Thanks, I'm trying to geta good mark for my "Co-curricular Activities" assessment this time ;-).

On 7/25/07, johnsee <joh...@gmail.com> wrote:

Peyman Taher

unread,
Jul 25, 2007, 1:44:59 AM7/25/07
to fit-ca...@googlegroups.com


On 7/25/07, Wong Ya Ping <wongy...@gmail.com> wrote:
...hmm..as for me, I can't seems to remember things after a long time i don't use it. I used to be really good with vi long long time ago..before most of you people were born, certainly before you guys knew a,b,c.. :)  Now i can only remember a few command. :(


Definitely :-), actually people like you are why we as students keep up good working so that maybe we also would have something to teach to those not born yet.

meisam sarabadani

unread,
Jul 25, 2007, 1:53:18 AM7/25/07
to fit-ca...@googlegroups.com
lolll :))))

Peyman Taher

unread,
Jul 25, 2007, 2:46:05 AM7/25/07
to fit-ca...@googlegroups.com
Daily Vim, Part 7:

Regular Expressions: As defined in http://en.wikipedia.org/wiki/Regular_expression, in computing, a regular expression is a string that is used to describe or match a set of strings, according to certain syntax rules.
As an example, I think we are all familiar with * which in most shells is substituted by everything matched in the context, so that "cp * foo/" will copy every file in the current directory to foo/.

The syntax used in Vim to represent regular expressions is like the one grep and most of other Unix programs use, so just a small recap for those who already know.

. (dot) can be used to represent any single character
.* (dot-star) matches everything
$ end of line
^ beginning of the line
x the character x
\x changes the meaning of x (not always, but most of the time)

Here are few examples of regular expressions used by '/' (search) to find a string or set of strings:

/^$    will search for empty lines
/^#    will search for all preprocessor definitions in you C/C++ source file
/\\$   will search for every line that is broken into to lines (most of them are macros)
/ .*@.*\.com  will search for email addresses in a file

We have quite a lot more to say about REs, but for now let's practice with these.
Tomorrow on how to copy/cut/paste and marks.

Peyman Taher

unread,
Jul 25, 2007, 2:46:48 AM7/25/07
to fit-ca...@googlegroups.com
What was funny!?

On 7/25/07, meisam sarabadani <meisam.s...@gmail.com> wrote:
lolll :)))) 

Peyman Taher

unread,
Jul 25, 2007, 9:40:54 PM7/25/07
to fit-ca...@googlegroups.com
Daily Vim, Part 8:

When you delete something with x or d command, the text is saved and you can paste with p command. I just told you how to cut!
d<motion> and then go to where you wanna paste and press p. You might find it strange as you've always been using other programs which paste before the character under cursor, but in Vim, p command pastes after the character under the cursor, if you want it other way, use P (capital p: shift+p).
To copy, press y<motion>, it will copy the text from cursor to where motion ends, and paste it as described above; note that y stands for "yank", so you don't copy actually, you yank it out.

yy or Y to copy a line.
dd to cut a line.
p to paste after the cursor
P to paste before the cursor

Marks: You can mark a position in the text and use it just like a bookmark. Mark using m<a-z> (don't use capitals or numbers, we'll talk about them later) to set a mark with the name of the alphabet that comes after it, meaning that if you press ma you've just marked your position (where the cursor is) with letter a, so later on you can return to this position by pressing `a.

m<a-z> to mark a position with the given letter
`<a-z> to go to the given mark
'<a-z> to go to the beginning of the "line" with given mark (not the exact position).

Marks are quite useful if you're dealing with large text file and need to jump from position to position quite frequently, and also can be useful in deleting and copying a large block of text; for doing so, follow these steps:
Go to the first line of the block of text you want to delete or copy.
press ma to mark it with a (assuming you don't already have a "a" mark, which if that's the case, the old mark will be overwritten).
Go the the last line of the block.
press d`a or d'a or y`a or y'a, whichever suits your task.
Note that you can use marks with every command that expects a "motion".

There are a few hard-coded marks you might find interesting:
`] or '] the first character of the previously changed or yanked text.
`[ or '[ the last character of the previously changed or yanked text.
`` or '' the position before the last jump.
follow the convention:
`( or '( and `) or ') for sentence.
`{ or '{ and `} or '} for paragraph.

:marks to see all the marks in your buffer.

Tomorrow is interesting: Filters.

Peyman Taher

unread,
Jul 26, 2007, 9:34:07 PM7/26/07
to fit-ca...@googlegroups.com
Vim Daily, Part 9:

Filters: For those who are not familiar with the word "filter" in Unix jargon, a filter is any program that takes some input, does some specific task on them, and returns some output; a good example would be "grep" program, or the "sort" program, which each of them take some values as input and with respect to the options provided by the user, would return something.

In Vim, you can use these filters to automate some of the tasks:
!<motion><filter>  will use the block of text from cursor up to where the motion ends as the input for the specified filter and substitutes this block with the output of the filter.

Example: Suppose we have a list of names in a file:

Hamm
Slink
Potato
Woody
Sarge
Etch
Lenny

and you want to sort them in ascending order; follow the steps:

move the cursor the beginning of first line (Hamm)
press !
press G to move the last row (Lenny); note that you can use marks to do so.
and now you will be prompted in the last row of the screen to enter the filter name.
enter "sort" follow by enter, and this is what you get:

Etch
Hamm
Lenny
Potato
Sarge
Slink
Woody

!!  will take the whole current line as the input for the filter.
note that if the line is empty, means that the filter can accept no input; This is what I do to insert the exact time and date I've edited a source file in a comment at the top of the source code.

go to a blank line
!!date

that's it!
Expand your experiment by using grep, strings, sed, awk, cut, seq, ...

Tomorrow on multiple files navigation.

P/S: Is anybody actually following this tutorial? If yes, how come you never ask questions?!

meisam sarabadani

unread,
Jul 26, 2007, 9:40:58 PM7/26/07
to fit-ca...@googlegroups.com
when nobody is asking question means the notes are well done structured that is answering any question happen to be appeared in mind. ;) .

Peyman Taher

unread,
Jul 26, 2007, 9:46:23 PM7/26/07
to fit-ca...@googlegroups.com
That was fast reply (7minutes after I posted)! Did you only read the last line? ;-)
Thanks, but questions make us both learn more.

meisam sarabadani

unread,
Jul 26, 2007, 9:53:07 PM7/26/07
to fit-ca...@googlegroups.com
I always skim any tut i want to read then it fully. :D . if any question i dun hesitate to ask.

Ian Tan

unread,
Jul 27, 2007, 6:07:15 AM7/27/07
to FIT Cafeteria
Actually, have you thought of writing a small manual on this? (Of
course, using your own examples).

Also, so far, it's really "vi" and you haven't touched "vim" yet
right?

Ian

Peyman Taher

unread,
Jul 27, 2007, 6:33:54 AM7/27/07
to fit-ca...@googlegroups.com
On 7/27/07, Ian Tan <ikt...@gmail.com> wrote:

Actually, have you thought of writing a small manual on this?  (Of
course, using your own examples).

Yes actually, I'm planning to combine these small pieces into a better structured manual, but I suppose I have to post more than 100 daily Vims to cover almost up to the advanced topics, so maybe I would bundle them after a few more post into an introductory manual on Vim. Do you have any suggestion or recommendation on that?
 

Also, so far, it's really "vi" and you haven't touched "vim" yet
right?

Honestly, I don't really know, cause I've always been using Vim and never used Vi.

Ian

Peyman Taher

unread,
Jul 29, 2007, 2:22:14 AM7/29/07
to fit-ca...@googlegroups.com
Daily Vim, Part 10:

You can use :vi <filename> or :e <filename> to open a new file for editing, and :view <filename> to open a file in read-only mode, which in this case to write possible changes to the file, you need to add a "!" at the end of :w command, resulting in :w!.
One can alternatively open multiple files as command arguments passed to Vim, e.g.: $ vim foo.c foo.h bar.c bar.h

:next     to show the next opened file
:wnext   to write the current file and then show next opened file

In case you've made changes to the current buffer and still haven't saved the changes, you need to write changes to file before moving to next buffer, or skip changes by :next!. In case you want Vim to save every file the moment you close it's buffer, you can set the autowrite option by :set autowrite or for the opposite case use :set noautowrite to turn off this feature.

Just like many other commands, you can use a counter before :next, so that :3next will act like :next :next :next.

:previous  to show the previous opened file
:Next    same as previous
:wprevious   guess what!
:wNext    guess what!
:first   puts you in the first opened file
:last   puts you in the last opened file

Tomorrow on how to manage windows (of course not that product of Microsoft!)...

Peyman Taher

unread,
Jul 30, 2007, 10:00:05 AM7/30/07
to fit-ca...@googlegroups.com
Daily Vim, Part 11:

One point that I left out yesterday, was CTRL-^ to switch to an alternative file, meaning that suppose you've opened Vim with four command line arguments (press :args to see what arguments are passed to Vim), pressing <count>CTRL-^ puts you in the specified file.

OK, "Windows" as I promised:

:split    to split your window to two horizontal separate windows; note that you'll see the same file in both windows
:split <filename>    to split but edit the given file
:vsplit   to split vertically
:vsplit <filename>   obvious!
:<counter>[split|vsplit]  to set the size of the new window to counter
:[vsplit|split] +<command> <filename>  to split and issue the initial <command>;

Example:

:15split +/System\.out\.print foo.java    will split the window to two horizontal windows, open foo.java in the new window, set its height to 15 lines, and searches for System.out.print and so puts the cursor at the first line containing so; note that in case System.out.print is not found, Vim will prompt that is unable to find the string and puts the cursor at the beginning of the file.

CTRL-w w   to switch between windows
CTRL-w [h|j|k|l] to switch to the window in the given direction
CTRL-w q to close a window
CTRL-w s to split
CTRL-w v to vsplit
CTRL-w + to increase the size of the window
CTRL-w - to decrease
CTRL-w = to set all windows sizes equal
CTRL-w o to set the current window as the only active window
CTRL-w _ to minimize the current window

Tomorrow on Buffers...

Reza Iranmanesh

unread,
Jul 31, 2007, 2:14:28 PM7/31/07
to fit-ca...@googlegroups.com
the minimizing feature was cool, :D

the CTRL-w combination is much easier than writing the commands, but can i use CTRL-w combination to open a new file with a given name? i mean something equivalent to: split <filename>

Peyman Taher

unread,
Jul 31, 2007, 7:53:42 PM7/31/07
to fit-ca...@googlegroups.com
there's no [file] option for CTRL-w_s.
By the way, note that in some terminals such as "xterm", CTRL-s will lock the terminal, so don't use CTRL-w CTRL-s, instead use CTRL-w s. And if you locked your terminal, use CTRL-q to unlock it.

Peyman Taher

unread,
Aug 1, 2007, 11:04:52 AM8/1/07
to fit-ca...@googlegroups.com
Daily Vim, Part 12:

The Vim editor, uses the term "buffer" for a file being edited, which is actually a copy of a file that you edit.
A buffer has three states:
Active: Appears on screen
Hidden: A file being edited but not on the screen.
Inactive: The file is not being edited, but Vim keeps the information about it anyway.

:hide  to hide the current active buffer
:buffers to see a list of buffers

In this list:
-  means inactive
h  means hidden
%  current buffer
#  alternative buffer
+  file has been modified

:buffer <number>  to switch to the given buffer
:buffer <filename>  you tell me!
:sbuffer [<number>|<filename>]  to split the window and open the buffer in the new window
:bnext  go to the next buffer
:<count>bnext  go to the next <count> buffer
Try these: sbnext, bprevious, sbprevious, sNext, sbNext, blast, brewind, sblast, sbrewind, bmodified, sbmodified and use your imagination and find it's intersection with Vim programmers' imaginations.

Usually, when the last window of a file is closed, the buffer associated with the file becomes inactive unless the "hidden" option is not set, which if it's set, they automatically become hidden.

:set hidden

Tomorrow on Visual Modes...

Reza Iranmanesh

unread,
Aug 1, 2007, 12:26:35 PM8/1/07
to fit-ca...@googlegroups.com


for heavy vi/vim users the distance between Esc and the alphanumeric keys is a pain. One of the posts was  about the old keyboards, and it inspired me to look for a way to move my Esc back to the place it was a few decades ago :)

What i found was that my "caps lock" key was not much in use, so replacing it with Esc could be a good idea.

here is the little how to for debian/ubuntu users to do so(i suppose it will work for other distros as well)

You can do it in two ways(actually many ways, but these are two possiblities):

1- First possible way:

i) replace the right click button on your keyboard(which is between right shift and control) witch "caps lock"
ii) duplicate your Esc key So your Esc key is still working and also your original "caps lock" is also another Esc key :)

to do so make a new file in your home folder and copy the following lines into it:

remove Lock    = Caps_Lock
keycode 0x42 =  Escape
keycode 0x75 =  Caps_Lock
add    Lock    = Caps_Lock Caps_Lock

save it and then issue the command:
xmodmap  <filename>

that's it!!
------------

2- the alternative way:  swap Esc and caps lock

write the following in a new file:

remove Lock    = Caps_Lock
keycode 0x09 =  Caps_Lock
keycode 0x42 =  Escape
add    Lock    = Caps_Lock Caps_Lock

and then save it and issue the command:
xmodmap <filename>
-----------

I prefer the first solution, coz it takes a while to get used to my new Esc, and i may press the original Esc up there.

to make your changes permanent you can put the xmodmap <path/filename> into your ".bashrc" file.

you may also like to take a look at this:  xkeycaps

Peyman Taher

unread,
Aug 2, 2007, 1:39:12 AM8/2/07
to fit-ca...@googlegroups.com
Daily Vim, Part 13:

After all, let's talk about "visual mode"; something that can make your vim-life easier or at least more visualized.

There are three different visual modes:
press v for a character by character visual mode
press V (shift-v) for a line by line visual mode
and press CTRL-v for block visual mode
and finally press ESC to exit a visual mode.

You can delete (d) or yank (y) or change (c) or join (J) the selected part just like before.
Actually you can use the visual mode as an alternative to every command that takes a motion argument.

Extra: If you're a programmer and use Vim for your daily programming, you might find the K (shift-k) command pretty useful as it will show you the man page for the word under cursor. (Note that you might need to install the "manpages-dev" package under Debian based distros for a complete set of manpages needed for developers.)

Tomorrow will be a few more command in visual mode.

Ian Tan

unread,
Aug 3, 2007, 5:28:12 AM8/3/07
to FIT Cafeteria
Hmphhh ... interesting. But I prefer the ESC key as it is (maybe over
the years, the fingers have gotten used to it).

/it

On Aug 2, 12:26 am, "Reza Iranmanesh" <reza.iranman...@gmail.com>
wrote:

Wong Ya Ping

unread,
Aug 3, 2007, 2:15:14 PM8/3/07
to fit-ca...@googlegroups.com
Hmm... me too preferred where it is now. ESC is often used as a panic button (escape from some disaster), thus you want to be able to assess it by just feeling the button at the corner of the keyboard rather than trying to aim and end up accidentally pressing the wrong button if it is located else where!

Perhaps like Ian, the fingers have gotten used to it. :)  I suppose you could train your finger to press that button at light speed... :)

GCS/ED/M/P/S/SS d+ s+:+ !a C++ U+ P+ L+>+++ E- W++ N+ o+++ w--- PGP t+>++ 5+ X+ tv- b+$ G++ e+++>++++

Peyman Taher

unread,
Aug 4, 2007, 12:07:24 PM8/4/07
to fit-ca...@googlegroups.com
Daily Vim, Part 14:

Few more commands on Visual Mode:

You can use I/A/C to insert/append/change (respectively) a block of text. Note that at first you will only see it in the first line, but then press ESC and the change will affect the whole selected block.

I  to insert in all the selected lines
A to append to all the selected lines
C to change all the selected lines

r<char> to replace the whole selected block with <char>(s).

> to shift the block one shiftwidth spaces to right
< shift to left

:set shiftwidth?  to see what's the shiftwidth, usually 8
:set shiftwidth=<num>  to set the shiftwidth to <num> spaces

The fun part starts from tomorrow: Vim for Programmers...

Nazri Ramliy

unread,
Aug 6, 2007, 12:54:03 AM8/6/07
to fit-ca...@googlegroups.com
On 8/4/07, Wong Ya Ping <wongy...@gmail.com> wrote:
> Perhaps like Ian, the fingers have gotten used to it. :) I suppose you
> could train your finger to press that button at light speed... :)

For near-light-speed result, I use the Ctrl+[ combination, and have
gotten used to it:
left pinky on the left ctrl, and right pinky on the [.

Nazri.
--
Cubert: That's impossible. You can't go faster than the speed of light.
Farnsworth: Of course not. That's why scientists increased the speed of
light in 2208.

Peyman Taher

unread,
Aug 7, 2007, 2:09:13 AM8/7/07
to fit-ca...@googlegroups.com
Daily Vim, Part 15:

Try these by yourself:

:syntax on   for syntax highlighting
:set background?   to see what is your background? (dark or light). Did you get the meaning for '?' ? Use it with other options...
:set background=dark
:set background=light

"syntax" highlighting in Vim depends on the file extension or file type (not the file command in *nix) and so in case you're editing a file foo.bar which is actually a ASCII C source code file, Vim will not be able to show his intelligence! Borrow him your own:
:set filetype=c

use >> or << to indent a line one shift-width to right or left respectively.
hint: programmers tend to indent with tab, and tab looks like 8 spaces, and 8 is 8! Don't indent 2 spaces or 4 spaces or rand() % 8 spaces!

Vim is smart enough to indent your source file just like how you're supposed to indent it, check this out:
:set cindent
:set smartindent
:set autoindent

Difference is that cindent has IQ 100, smartindent 50 (just like human being! those who try to be smart are always below average!) and autoindent didn't even get to finish the test! There's another indentation mode: indentexpr (Einstein's class mate) which we'll talk about it later...

autoindent uses the indent from the previous line.
smartindent works just like the autoindent with this this advantage that in some cases recognizes C syntax and increase or decrease the indentation level. This is the indentation mode mainly used in Dev(il)-C++.
cindent is configurable to different indenting styles.

Tomorrow: more programmers' commands...

--
Cheers,
Peyman.

Peyman Taher

unread,
Aug 11, 2007, 12:07:16 AM8/11/07
to fit-ca...@googlegroups.com
I just found something worthy to share here:

Date: Jun 21 1999
From: Chris Cera
To: ask...@oreilly.com
Subject: Editor: vi or emacs?

I want to know what editor Tim O'Reilly uses: vi or emacs? Could you please tell us why?

-- Chris


Chris,

I have to confess that I'm a "vi guy." When I was new to UNIX, I actually started out using emacs (not GNU emacs, but Gosling's Emacs, in the early days of the emacs wars) and loved it. But then one day, I discovered that someone had blown away the custom emacs profile that I had gotten comfortable with. It took about a week for me to get it restored, and in the meantime, I switched to vi, and got hooked.

What I especially liked about vi was precisely that I didn't have to have all these nifty customizations to make it really usable. What really distinguished vi from emacs in my mind was that it was just there on any system I sat down at--tremendously portable. I didn't have to copy my emacs profile around to sit down and do useful work on someone else's machine.

Once you learn vi's admittedly unintuitive style, it is remarkably easy to use and tremendously powerful. Like a lot of things about UNIX, it only *seems* difficult. After a small barrier to entry, it is orders of magnitude more powerful and easy to use than commercial word processors. (But that's true of emacs as well!)

Despite emacs' higher profile as a free software poster child, I think more people actually use vi than emacs. We sell more copies of our vi book than of our emacs book -- almost twice as many each year. This could be because emacs has a free manual that is distributed with it. But I saw a matching statistic at Linux Expo, where O'Reilly sponsors a vi vs. emacs paintball game each year. I happened to check the signup list, and noticed that there were about twice as many people signed up for the vi team as for the emacs team. (Maybe they just like the vi t-shirt -- the team "uniform" -- more than the emacs t-shirt, but I don't think so.)

But I don't want to pour gasoline on this fire, any more than I want to pour gasoline on the perl vs. tcl vs. python fires. Both vi and emacs are great editors, and both are very widely used within O'Reilly. If you went down the list of our editors, you'd get strong partisans of each.

P.S. If you want to read more on why I like vi, you need only turn to the opening pages of our book Learning the vi Editor. While I don't have an author credit on the cover, I actually wrote a large part of the fourth and fifth editions, including the opening paean to the virtues of vi.

--Tim



On 7/22/07, Ian Tan <ikt...@gmail.com> wrote:

someone better start and emacs version of this before this whole
newsgroup becomes vi fanatics ... :-P





--
Cheers,
Peyman.

Ian Tan

unread,
Aug 11, 2007, 12:28:29 PM8/11/07
to FIT Cafeteria
Ha hah hah ... ok, my path to "vi" was very similar to the story as
well. I started out using Emacs, I don't know which version but
remembered that it was called Micro-Emacs, learnt how to customize it
and built a nice profile as well. This is all nice especially at that
time (late 80s / early 90s) since we used shared servers, i.e. we log
on to the server from any dumb terminal and code. I don't really need
to copy my profile from workstation to workstation. (And using Ctrl-
something was natural then due to the popular Wordstar wordprocessor).
Then I moved to another University and we had nice Sun workstations
that firstly did not have Emacs. So, very relunctantly I learnt the
weird press "i" to insert and press "ESC" to whatever they call it.
After a few days of spending more time figuring out how to use the
editor than work (coding) ... it suddenly began to feel quite natural.

The funniest part was then using Windows and editing using notepad. I
kept on pressing "i", "h", "j", "k", "l", etc etc instead of just
typing it out!.

But then, I still think that Emacs should have a following as it is
after all not just an editor, some call it a programming language
whilst some even call the environment an operating system!!

Ok, who's an Emacs person here ... hands up!

On Aug 11, 12:07 pm, "Peyman Taher" <peyman.ta...@gmail.com> wrote:
> I just found something worthy to share here:
>
> Date: Jun 21 1999
> From: Chris Cera

> To: ask_...@oreilly.com


> Subject: Editor: vi or emacs?
>
> I want to know what editor Tim O'Reilly uses: vi or emacs? Could you please
> tell us why?
>
> -- Chris
>

> ------------------------------


>
> Chris,
>
> I have to confess that I'm a "vi guy." When I was new to UNIX, I actually
> started out using emacs (not GNU emacs, but Gosling's Emacs, in the early
> days of the emacs wars) and loved it. But then one day, I discovered that
> someone had blown away the custom emacs profile that I had gotten
> comfortable with. It took about a week for me to get it restored, and in the
> meantime, I switched to vi, and got hooked.
>
> What I especially liked about vi was precisely that I didn't have to have
> all these nifty customizations to make it really usable. What really
> distinguished vi from emacs in my mind was that it was just there on any
> system I sat down at--tremendously portable. I didn't have to copy my emacs
> profile around to sit down and do useful work on someone else's machine.
>
> Once you learn vi's admittedly unintuitive style, it is remarkably easy to
> use and tremendously powerful. Like a lot of things about UNIX, it only
> *seems* difficult. After a small barrier to entry, it is orders of magnitude
> more powerful and easy to use than commercial word processors. (But that's
> true of emacs as well!)
>
> Despite emacs' higher profile as a free software poster child, I think more

> people actually use vi than emacs. We sell more copies of *our vi
> book*<http://www.oreilly.com/catalog/vi6/>than of
> *our emacs book* <http://www.oreilly.com/catalog/gnu2/> -- almost twice as


> many each year. This could be because emacs has a free manual that is
> distributed with it. But I saw a matching statistic at Linux Expo, where
> O'Reilly sponsors a vi vs. emacs paintball game each year. I happened to
> check the signup list, and noticed that there were about twice as many
> people signed up for the vi team as for the emacs team. (Maybe they just
> like the vi t-shirt -- the team "uniform" -- more than the emacs t-shirt,
> but I don't think so.)
>
> But I don't want to pour gasoline on this fire, any more than I want to pour
> gasoline on the perl vs. tcl vs. python fires. Both vi and emacs are great
> editors, and both are very widely used within O'Reilly. If you went down the
> list of our editors, you'd get strong partisans of each.
>
> P.S. If you want to read more on why I like vi, you need only turn to the

> opening pages of our book *Learning the vi
> Editor*<http://www.oreilly.com/catalog/vi6/>.

Peyman Taher

unread,
Aug 12, 2007, 8:47:47 PM8/12/07
to fit-ca...@googlegroups.com
Daily Vim, Part 16:

Long time, no see! :-)
I know I wasn't posting regularly during last two week, but I was quite busy with some stuff. So anyway I'll try to keep it up again.

=<motion> is a command to automatically indent your code.
== to indent the current line.
%  jumps to the matching { [ ( or } ] )

So a combination of these can be =% which if your cursor is currently on the open bracket or close bracket, it will indent all the code inside that block according to the indentation mode specified before.

Example: type in the following dummy program in Vim.

int foo()
{
printf("A wise man can see more from the bottom of a "
"well than a fool can from a mountain top .");
int i;
for (i = 0; i != 10; i++)
if (i == 5)
printf("Politics is the art of looking for trouble, finding it whether it "
"exists or not, diagnosing it incorrectly, and applying the wrong remedy.");
}

Move your cursor to the first line, press =G and here is the result:

int foo()
{
    printf("A wise man can see more from the bottom of a "
            "well than a fool can from a mountain top .");
    int i;
    for (i = 0; i != 10; i++)
        if (i == 5)
            printf("Politics is the art of looking for trouble, finding it whether it "
                    "exists or not, diagnosing it incorrectly, and applying the wrong remedy.");
}

* to search for the word under cursor forward
# do * but backward
[CTRL-I do * in current file + all those brought in by #include
]CTRL-I backward
gd, and gD jump to the definition of a variable
]CTRL-D and [CTRL-D jump to the definition of a macro
]d, [d, ]D, [D to display the macro definition <- I like this one

Tomorrow, more for programmers...

--
Cheers,
Peyman.

Peyman Taher

unread,
Aug 12, 2007, 8:52:16 PM8/12/07
to fit-ca...@googlegroups.com
CORRECTION...


WRONG EXPLANATION ^^
[CTRL-I searches from the beginning of the file.

]CTRL-I backward

]CTRL-I searches from current location of cursor.

gd, and gD jump to the definition of a variable
]CTRL-D and [CTRL-D jump to the definition of a macro
]d, [d, ]D, [D to display the macro definition <- I like this one

Tomorrow, more for programmers...

--
Cheers,
Peyman.



--
Cheers,
Peyman.

Peyman Taher

unread,
Aug 15, 2007, 3:54:56 AM8/15/07
to fit-ca...@googlegroups.com
Daily Vim, Part 17:

Some notes on what we had in last part:

[d, ]d are different from [D, ]D in that the formers display the first definition of a macro while the laters display all definitions found for a macro.
And also, the difference between [ and ] is that [ starts searching for the definition of the macro from the beginning of file, while ] start from the current position of the cursor.

We've already mentioned %, use it in different locations and find out more about it:
() {} [] #ifdef #else #endif ...

i{ i} a{ and a} are motion commands, well not like hjkl but can be used with those commands that accept a motion command, and roughly what they do is to select the block you're currently inside, i{ and i} are for inner block, meaning that { and } of the beginning and end of block will not be included while a{ and a} are "a block" and will include so. To understand, use them combined with v to show the selected block in visual mode: vi{ va{. Note that here again, we can apply a counter, so that v2i{ will include: starting from the current location, two nested blocks...

For tomorrow, try to install "ctags": sudo aptitude install ctags ...

--
Cheers,
Peyman.

Reza Iranmanesh

unread,
Aug 19, 2007, 2:05:49 AM8/19/07
to fit-ca...@googlegroups.com
<Aoi-chan> everyone's first vi session. ^C^C^X^X^X^XquitqQ!qdammit[esc]qwertyuiopasdfghjkl;:xwhat

Peyman Taher

unread,
Aug 20, 2007, 12:47:23 AM8/20/07
to fit-ca...@googlegroups.com
Daily Vim, Part 18:

I think I should change the Daily Vim to Sometimes Vim!

OK, I'm assuming you have already installed "ctags", so proceed with the following commands:

In your terminal, type in "ctags <list of filenames>", this will create a "tags" file, which keeps track of tags in your program.
Now "vim <filename>" and ...
CTRL-] to jump to the declaration or definition of the word under cursor
CTRL-t to jump back
:tag  same as CTRL-]
:tags a list of tags you've visited so far
:tag /<regexp> to search for definition of a set of strings matching the given regular expression

":tag" can be proceeded by a [count] which makes it jump to the [count]th occurrence of expression.

:stag is same as :tag with the only difference that will split window and show the tag in the new one; So does CTRL-w].
:tselect returns a list of all tags matching given expression; so does g]
:help tag-priority if you find the FSC thing in tselect interesting enough.

:tnext
:tprevious
:tNext
:trewind
:tlast
(forward, backward, backward, first and last tag)

:tjump and gCTRL] are merely equal to tselect and g] with a small useless different, you would never remember, trust me.

:stselect is also available (to split)

Next one on Makefile and related stuff...

--
Cheers,
Peyman.

Peyman Taher

unread,
Aug 20, 2007, 10:19:58 PM8/20/07
to fit-ca...@googlegroups.com
Daily Vim, Part 19:

Make is a Unix tool to facilitate program compilation and some related things.
For start, let's say you have a file named foo.c and how do you compile it? gcc foo.c
Now let's do it with "make": create a file in the same directory as foo.c, call it "Makefile" and save the following lines in it:

all:
          gcc foo.c

Note that, "all:" is the first line in Makefile, and gcc foo.c has ONE SINGLE TAB before it. Save it, and in your prompt, type in make and then enter! done!

Now let's do it with Vim:
:make makes the project which it's makefile is in directory you opened vim from. if $PWD == $HOME/bar/, and Vim, then in order to make :make work, Makefile must be saved in $HOME/bar/

Of course there might be some errors and warnings, vim can jump straight to the line that error or warning is reported from which is what exactly it does by default for the first error or warning.

:cc  show the error or warning
:clist  show a list of all errors and warnings
:cn  go to the next error or warning
:cprevious  previous
:crewind
:clast
:cNext

In case you're using Vim for your programming stuff, add the following line to your .vimrc or whatever else the configuration file is called:

:map <F5> :w<CR>:make<CR>

and from this moment onward, when you write a program, create a Makefile in it's own directory, and instead of each time going to shell and gcc blablabla, just press F5... (more about it, and much nicer commands with map, later)

BTW, use :grep just like how you use it as a program outside of vim, with the only difference that :grep will jump to the found occurrence of expression and note that all those c* command up there ^^ still work with :grep

--
Cheers,
Peyman.

Peyman Taher

unread,
Aug 22, 2007, 9:46:56 PM8/22/07
to fit-ca...@googlegroups.com
Daily Vim, Part 20:

A small note on Makefiles: make is a very sensitive program, so if you're Makefile does not follow what exactly make expects, you'll get error, and one of these expectations is that there should be exactly ONE tab before a command line ( e.g. at the beginning of gcc foo.c line) and this tab cannot be expanded (replaced by spaces) so, one can use ":set list" to ask Vim to show you a $ at the end of each line and a ^I in place of a tab, so:
all:
        gcc foo.c

will be like:
all:$
^Igcc foo.c$

BTW, you can set Vim to expand tab or not:

:set expandtab
and
:set noexpandtab

Abbreviations:

:abbreviate <ABBREVIATE> <COMPLETE>

I use this:
:ab #D #define
:ab #I #include<
:ab lng oh my god, this is just so long to type every time, so I just type "lng" and a whitespace!

and Vim will replace the <ABBREVIATE> with the <COMPLETE> if a whitespace (space, tab, enter) is found after it.
:ab  will list all abbreviations

I guess I mentioned the :map command in last tutorial, but a recap:
:map <KEY> <SET OF COMMANDS>
will map a key into a set of commands, so one can have something like this:
:map <F10> :wall<CR>:q<CR>
to map F10 to write all buffers and quit.

Here is a nice one:

:map <F9> :w<CR>:make<CR>:clist<CR>
Just remember to have a Makefile in the directory you used to open vim.
:map <F5> :w<CR>:make -f Makefile.%<<CR>:clist<CR>
and now remember to have a Makefile.<file name with no extension> in that directory, so by pressing F5 in a file named foo.c, Vim tries to make with file Makefile.foo (allows several separate programs in a folder with a Makefile for each).
--
Cheers,
Peyman.

Reza Iranmanesh

unread,
Aug 29, 2007, 12:50:37 PM8/29/07
to fit-ca...@googlegroups.com
Dude, you slowed down when it reached the interesting parts.

this little thing is very handy for me, it might be interesting for others as well:
:map <space> /
-----------------------------------------
we always hear a problem with exponential complexity is almost unsolvable in real world. if you want to see and feel how bad an exponential growth is (in a vim manner), try this:

open vim and write the following line:
i am waiting for next chapter

then in normal mode press:
qaggVGypq

now again in normal mode press
20@a
(repeat 20 times)

exponential growth feels awful, doesn't it?
anyone willing to try 50@a?

Peyman Taher

unread,
Aug 29, 2007, 9:08:51 PM8/29/07
to fit-ca...@googlegroups.com
On 8/30/07, Reza Iranmanesh <reza.ir...@gmail.com> wrote:
> Dude, you slowed down when it reached the interesting parts.
>

Okey! :-)

> this little thing is very handy for me, it might be interesting for others
> as well:
> :map <space> /
> -----------------------------------------

that was good :->

> we always hear a problem with exponential complexity is almost unsolvable
> in real world. if you want to see and feel how bad an exponential growth is
> (in a vim manner), try this:
>
> open vim and write the following line:
> i am waiting for next chapter
>
> then in normal mode press:
> qaggVGypq
>
> now again in normal mode press
> 20@a
> (repeat 20 times)
>

that was bad! :-))

> exponential growth feels awful, doesn't it?
> anyone willing to try 50@a?
>
>
>
> >
>


--
Cheers,
Peyman.

Peyman Taher

unread,
Aug 29, 2007, 9:47:46 PM8/29/07
to fit-ca...@googlegroups.com
Daily Vim, Part 21:

Did I mention that you can list all the abbreviations by:
:ab
or
:abbreviation

To write your current configuration of Vim on a vimrc file:
:mkvimrc <file>
And to load a vimrc file:
:source <file>

:version gives a list of compile time configurations of your Vim.

I alway use:
:set textwidth=80
since a tty has 80 columns and also, 80 is long enough for up to three
nested loops, which if you have more, you'd better rewrite your
program!
BTW, you might need to:
:set formatoption+=t or c to make it work
and more on this comes later...

Substitute:
One can substitute or replace regexp using :s command, e.g.:
:s/X/Y/ will replace the first occurrence of X in the current line with Y
:1,5s/X/Y/ does the same thing for each line from 1 to 5
:%s/X/Y/ does it for the whole file
:s/X/Y/g replace "every" occurrence of X with Y in the current line

So, basically, the s command has the following form:

:[range]s/<regexp>/<expression>/[flag]

range is mmm, is a range!
regexp is a regular expression like the one we talked few sections back.
flags are as follows:
g for global
p for print
c for confirmation
i for ignore case
I for don't ignore case
:help su for more

--
Cheers,
Peyman.

asyazwan

unread,
Sep 4, 2007, 12:43:36 PM9/4/07
to FIT Cafeteria
Whatever happen to the native Ctrl-c?

It's the best replacement of ESC in ViM in my opinion, since it is
used in terminals as well to cancel/terminate.

On Aug 5, 9:54 pm, "Nazri Ramliy" <ayieh...@gmail.com> wrote:

asyazwan

unread,
Sep 4, 2007, 12:53:23 PM9/4/07
to FIT Cafeteria
Not a question, just something to share about emacs. Apparently Vim
isn't used by all these great programmers:
http://www.stifflog.com/2006/10/16/stiff-asks-great-programmers-answer/

Don't get me wrong, I love ViM, but I am also learning emacs at the
moment, so someone has to defend it. :P

saleh

unread,
Sep 4, 2007, 4:18:34 PM9/4/07
to FIT Cafeteria
2-questions:
1)can we run CL as a subprocess of "Vim"?(part 1)
2)how can we have a the same "Vi" or "Vim" under "Emacs"?(part 2)

part 1)
-Running CL as a subprocess of Emacs:
An even more powerful way of developing with Allegro CL is by running
it within Emacs in conjunction with a special Emacs/Lisp interface
provided by Franz Inc. This technique provides all the benefits of
running in an Emacs shell as outlined above, but is more powerful
because the Emacs-CL interface extends Emacs with several special
commands. These commands interact with the CL process, making the
editor appear to be "Lisp-aware." The combination of Emacs with the
Emacs-CL interface results in a development environment whose utility
approaches that of the vintage Symbolics Lisp Machines, which many
Lisp aficionados still consider to be technology advanced well beyond
anything produced today".
part 2)
-A Note on Emacs and Text Editors:
If you are used to working with the "vi"editor, Emacs comes with
several "vi" emulation modes...


Peyman Taher

unread,
Sep 4, 2007, 10:19:23 PM9/4/07
to fit-ca...@googlegroups.com
On 9/5/07, asyazwan <asya...@gmail.com> wrote:
>
> Not a question, just something to share about emacs. Apparently Vim
> isn't used by all these great programmers:
> http://www.stifflog.com/2006/10/16/stiff-asks-great-programmers-answer/
>

cool link :-), thanks.

> Don't get me wrong, I love ViM, but I am also learning emacs at the
> moment, so someone has to defend it. :P
>
>

hehe! You don't start eating bacon and egg for breakfast, just because
Bijarne Strustroup does that (in case he does!). it's a matter of
taste!

--
Cheers,
Peyman.

asyazwan

unread,
Sep 5, 2007, 5:55:25 AM9/5/07
to FIT Cafeteria
You'd be surprised what Bjarne Stroustoup use as his text editor if
you check that link.

On Sep 4, 7:19 pm, "Peyman Taher" <peyman.ta...@gmail.com> wrote:

Peyman Taher

unread,
Oct 8, 2007, 9:25:02 PM10/8/07
to fit-ca...@googlegroups.com
Dear Vim Users,

I guess so far we have covered almost all the basic and intermediate level commands in Vim and those who have followed this tutorial should be able to use Vim easily and perhaps keep learning more by themselves. So as of now, I will not post anything new in this thread, except answering possible questions and I'm putting my effort on combining this thread as a tutorial to Vim and will post the complete document here for your daily use.

But, this will not be the end of the story. I have two other tutorials in "coming soon" state:
LaTeX2e
"Hello World!" - What a wild greeting!

The former will be an introductory tutorial on LaTeX edition 2 which can certainly serve as an alternative for your Word Processing tool and will help you write shockingly neat and professional reports. I suspect this will start in few days, and will not be a long tutorial.
The later is what I have been dreaming of for few months already, and hopefully will be started after the LaTeX2e and I don't really know how much effort it takes, but definitely should not be easy. In this, I will try to start from a "Hello World!" program in C, and will describe every single important operation this poor PC does to just write a "Hello World!" on the screen and will try to go as deep as the machine instruction level. Well for now, the only thing I can foresee is that it will be a great fun and educative post!

--
Cheers,
Peyman.

Peyman Taher

unread,
Apr 6, 2008, 7:55:36 AM4/6/08
to fit-ca...@googlegroups.com
For those using Vim for Java development, this
http://www.vim.org/scripts/script.php?script_id=1213 might cheer you
up a bit. It simply gives an IDE better and faster than Eclips ;). For
example you can use the code-completion by pressing ^x^u (^ stands for
CTRL) and you can even see the method's signature on the tops the
window.

--
Cheers,
Peyman.

meisam sarabadani

unread,
Apr 6, 2008, 2:13:18 PM4/6/08
to fit-ca...@googlegroups.com
:) Thanks a lot, Nice.
--
Appreciated much,
Meisam Sarabadani

Peyman Taher

unread,
Jun 21, 2008, 10:21:10 PM6/21/08
to fit-ca...@googlegroups.com
I put up the "Vim, Step by Step" posts in a tutorial format here:
http://peyman.taher.googlepages.com/vim%2Cstepbystep
I hope it would be useful.

--
Cheers,
Peyman.

Reply all
Reply to author
Forward
0 new messages