mirror of https://github.com/tLDP/LDP
updated
This commit is contained in:
parent
d3291f3a7d
commit
90f06738a8
|
@ -2,6 +2,8 @@
|
|||
|
||||
<Article id="index">
|
||||
|
||||
<!-- Article Header -->
|
||||
|
||||
<ArtHeader>
|
||||
|
||||
<Title>
|
||||
|
@ -30,15 +32,55 @@
|
|||
|
||||
</Author>
|
||||
|
||||
<PubDate>
|
||||
v0.1, Dec 04 2000
|
||||
</PubDate>
|
||||
<revhistory>
|
||||
|
||||
<revision>
|
||||
|
||||
<revnumber>
|
||||
v1.0
|
||||
</revnumber>
|
||||
|
||||
<date>
|
||||
Jan 14, 2001
|
||||
</date>
|
||||
|
||||
<authorinitials>
|
||||
sh
|
||||
</authorinitials>
|
||||
|
||||
<revremark>
|
||||
Second Revision. Corrected some typos.
|
||||
</revremark>
|
||||
|
||||
</revision>
|
||||
|
||||
<revision>
|
||||
|
||||
<revnumber>
|
||||
v0.1
|
||||
</revnumber>
|
||||
|
||||
<date>
|
||||
Dec 04, 2000
|
||||
</date>
|
||||
|
||||
<authorinitials>
|
||||
sh
|
||||
</authorinitials>
|
||||
|
||||
<revremark>
|
||||
First Revision. I would love to have your feedback
|
||||
</revremark>
|
||||
|
||||
</revision>
|
||||
|
||||
</revhistory>
|
||||
|
||||
<abstract>
|
||||
|
||||
<para>
|
||||
This document gives an introduction to editing C and
|
||||
other language files whose syntax is similar like C++ and
|
||||
other language files, whose syntax is similar, like C++ and
|
||||
Java in vi/VIM.
|
||||
</para>
|
||||
|
||||
|
@ -46,6 +88,8 @@
|
|||
|
||||
</ArtHeader>
|
||||
|
||||
<!-- Section 1: Introduction -->
|
||||
|
||||
<sect1 id="intro">
|
||||
<title>
|
||||
Introduction
|
||||
|
@ -69,6 +113,8 @@
|
|||
|
||||
</sect1>
|
||||
|
||||
<!-- Section 2: Moving Around -->
|
||||
|
||||
<sect1 id="moving">
|
||||
<title>
|
||||
Moving around.
|
||||
|
@ -133,7 +179,7 @@
|
|||
</para>
|
||||
|
||||
<para>
|
||||
<keycap>e</keycap> is similar to <keycap> w</keycap> only
|
||||
<keycap>e</keycap> is similar to <keycap>w</keycap> only
|
||||
that it takes you to the end of the current word and not
|
||||
to the beginning of the next word.
|
||||
</para>
|
||||
|
@ -199,7 +245,7 @@
|
|||
|
||||
<para>
|
||||
The above snippet shows two paragraphs. One can easily
|
||||
move from the beginning of one to the other by using the
|
||||
move from the beginning of one to the other, by using the
|
||||
<keycap>{</keycap> and <keycap>}</keycap>
|
||||
keys. <keycap>{</keycap> will take the cursor to the
|
||||
paragraph above and <keycap>}</keycap> will take the
|
||||
|
@ -207,9 +253,9 @@
|
|||
</para>
|
||||
|
||||
<para>
|
||||
Many people have the coding style where logical set of
|
||||
statements are grouped together and separated from sets by
|
||||
a blank line.
|
||||
Many people have the coding style where a logical set of
|
||||
statements are grouped together and separated by
|
||||
one or more blank lines.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
@ -317,7 +363,7 @@
|
|||
take you to the opening { of the bar() function. The
|
||||
reverse is slightly different. If you were in the middle of bar()
|
||||
and you type <keycap>[[</keycap> the cursor will move to
|
||||
the first { above ie the beginning of bar() itself. One
|
||||
the first { above i.e. the beginning of bar() itself. One
|
||||
has to type <keycap>[[</keycap> again to move to the
|
||||
beginning of foo(). The number of keystrokes can be
|
||||
minimized by typing <keycap>2[[</keycap> to take the
|
||||
|
@ -395,7 +441,7 @@
|
|||
the cursor will jump to the corresponding match.
|
||||
</para>
|
||||
|
||||
<para> Amongst other things the <keycap>%</keycap> keystroke
|
||||
<para> Amongst other things, the <keycap>%</keycap> keystroke
|
||||
can be used to match #if, #ifdef, #else #elif and #endif
|
||||
also.
|
||||
</para>
|
||||
|
@ -434,14 +480,12 @@
|
|||
|
||||
</figure>
|
||||
|
||||
|
||||
|
||||
<para>
|
||||
Checking the above code will involve the correctness of
|
||||
the parenthesis. The <keycap>%</keycap> can be used to
|
||||
jump from one ( to it corresponding ) and vice versa.
|
||||
Thus one can find which parenthesis corresponds to which
|
||||
other closing parenthesis and use the information to
|
||||
Checking the above code will involve checking the correctness
|
||||
of the parenthesis. The <keycap>%</keycap> can be used to
|
||||
jump from one ( to its corresponding ) and vice versa.
|
||||
Thus, one can find which opening parenthesis corresponds to
|
||||
which closing parenthesis and use the information to
|
||||
validate the code.
|
||||
</para>
|
||||
|
||||
|
@ -454,6 +498,8 @@
|
|||
|
||||
</sect1>
|
||||
|
||||
<!-- Section 3: Jumping to Random positions -->
|
||||
|
||||
<sect1 id="Random">
|
||||
<title>
|
||||
Jumping to random positions in C files
|
||||
|
@ -465,11 +511,11 @@
|
|||
</title>
|
||||
|
||||
<para>
|
||||
A Tag are a sort of placeholder. Tags are very useful in
|
||||
understanding and editing C files. Tags are a set of
|
||||
book-marks to each function in the C file. Tags are very
|
||||
A Tag is a sort of placeholder. Tags are very useful in
|
||||
understanding and editing C. Tags are a set of
|
||||
book-marks to each function in a C file. Tags are very
|
||||
useful in jumping to the definition of a function from
|
||||
where it is called and back.
|
||||
where it is called and then jumping back.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
@ -518,23 +564,23 @@
|
|||
<para>
|
||||
Lets say that you are editing the function foo() and you
|
||||
come across the function bar(). Now, to see what bar()
|
||||
does, one makes uses of tags. One can jump to the
|
||||
definition of bar() and then jump back later. If need be
|
||||
does, one makes uses of Tags. One can jump to the
|
||||
definition of bar() and then jump back later. If need be,
|
||||
one can jump to another function called within bar() and back.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
To use tags one must first run the program ctags on all
|
||||
To use Tags one must first run the program ctags on all
|
||||
the source files. This creates a file called tags. This
|
||||
file contains pointers to all the function definitions and
|
||||
is used by VIM to take you to the function definition.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The actual keystrokes for jumping to and back are
|
||||
The actual keystrokes for jumping to and fro are
|
||||
<keycap>CTRL-]</keycap> and <keycap>CTRL-T</keycap>. By
|
||||
hitting <keycap>CTRL-]</keycap> in foo() at the place
|
||||
where bar() is called takes the cursor to the beginning of
|
||||
where bar() is called, takes the cursor to the beginning of
|
||||
bar(). One can jump back from bar() to foo() by just
|
||||
hitting <keycap>CTRL-T</keycap>.
|
||||
</para>
|
||||
|
@ -558,9 +604,9 @@
|
|||
|
||||
<para>
|
||||
In case of a source tree which contains C files in
|
||||
different sub directories one can call ctags in the root
|
||||
different sub directories, one can call ctags in the root
|
||||
directory of the source tree with the -R option and a tags
|
||||
file containing tags to all functions in the source tree
|
||||
file containing Tags to all functions in the source tree
|
||||
will be created. For Example.
|
||||
</para>
|
||||
|
||||
|
@ -581,16 +627,16 @@
|
|||
</title>
|
||||
|
||||
<para>
|
||||
Marks are place-holders like tags. However, marks can be
|
||||
Marks are place-holders like Tags. However, marks can be
|
||||
set at any point in a file and is not limited to only
|
||||
functions, enums etc.. Plus marks have be set manually by
|
||||
the user himself.
|
||||
the user.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
By setting a mark there is no visible indication of the
|
||||
same. A mark is just a position in a file which is
|
||||
remembered. Consider the following code
|
||||
remembered by VIM. Consider the following code
|
||||
</para>
|
||||
|
||||
<figure>
|
||||
|
@ -635,14 +681,14 @@
|
|||
|
||||
<para>
|
||||
Suppose you are editing the line x++; and you want to come
|
||||
back to that line after editing some other line. One can
|
||||
back to that line after editing some other line. You can
|
||||
set a mark on that line with the keystroke
|
||||
<keycap>m'</keycap> and come back to the same line later
|
||||
by hitting <keycap>''</keycap>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
VIM allows you to set multiple marks. These marks are
|
||||
VIM allows you to set more than one mark. These marks are
|
||||
stored in registers a-z, A-Z and 1-0. To set a mark and
|
||||
store the same in a register say j, all one has to hit is
|
||||
<keycap>mj</keycap>. To go back to the mark one has to hit
|
||||
|
@ -658,14 +704,14 @@
|
|||
|
||||
<para>
|
||||
Marks can span across files. To use such marks one has to
|
||||
use upper-case registers ie A-Z. Lower-case registers are
|
||||
use upper-case registers i.e. A-Z. Lower-case registers are
|
||||
used only within files and do not span files. That's to
|
||||
say, if you were to set a mark in a file foo.c in register
|
||||
"a" and then move to another file and hit
|
||||
<keycap>'a</keycap>, there will not change to the cursor
|
||||
location. The cursor will not jump back to the previous
|
||||
<keycap>'a</keycap>,
|
||||
the cursor will not jump back to the previous
|
||||
location. If you want a mark which will take you to a
|
||||
different file then you will need to use upper-case
|
||||
different file then you will need to use an upper-case
|
||||
register. For example, use <keycap>mA</keycap> instead of
|
||||
<keycap>ma</keycap>. I'll talk about editing multiple
|
||||
files in a later section.
|
||||
|
@ -745,6 +791,8 @@
|
|||
|
||||
</sect1>
|
||||
|
||||
<!-- Section 4: Auto-completing words -->
|
||||
|
||||
<sect1 id="Auto-Complete">
|
||||
<Title>
|
||||
Auto-Completing Words
|
||||
|
@ -795,16 +843,16 @@
|
|||
</figure>
|
||||
|
||||
<para>
|
||||
The function AVeryLongFunctionName() can be quite
|
||||
exasparating to type over and over again. While in
|
||||
The function A_Very_Long_Function_Name() can be quite
|
||||
exasperating to type over and over again. While still in
|
||||
insert-mode, one can auto-complete a word by either searching
|
||||
forwards or backwards. In function, AnotherFunction() one can
|
||||
type AVery... and hit <keycap>CTRL-P</keycap>. The first
|
||||
forwards or backwards. In function, Another_Function() one can
|
||||
type A_Very... and hit <keycap>CTRL-P</keycap>. The first
|
||||
matching word will be displayed first. In this case it would
|
||||
be AVeryLongVariableName. To complete it correctly, one can
|
||||
be A_Very_Long_Variable_Name. To complete it correctly, one can
|
||||
hit <keycap>CTRL-P</keycap> again and the search continues
|
||||
upwards to the next matching word, which is
|
||||
AVeryLongFunctionName. As soon as the correct word is matched
|
||||
A_Very_Long_Function_Name. As soon as the correct word is matched
|
||||
you can continue typing. VIM remains in insert-mode during
|
||||
the entire process.
|
||||
</para>
|
||||
|
@ -826,7 +874,7 @@
|
|||
</para>
|
||||
|
||||
<para>
|
||||
CTRL-X mode allows you do autocompletion in a variety of
|
||||
CTRL-X mode allows you do auto-completion in a variety of
|
||||
ways. One can even autocomplete filenames. This is
|
||||
particularly useful when you have to include header
|
||||
files. Using CTRL-X mode you can include a file foo.h using
|
||||
|
@ -834,7 +882,7 @@
|
|||
</para>
|
||||
|
||||
<programlisting>
|
||||
#include "f^X^F"
|
||||
#include "f CTRL-X CTRL-F"
|
||||
</programlisting>
|
||||
|
||||
<para>
|
||||
|
@ -913,11 +961,13 @@
|
|||
<keycap>CTRL-X CTRL-K</keycap>. The completion is similar to
|
||||
the <keycap>CTRL-P</keycap> and <keycap>CTRL-N</keycap>
|
||||
keystrokes. So... to type "typedef" all one needs to do is
|
||||
t^X^K and voila, the name completed.
|
||||
t CTRL-X CTRL-K and poof... the name completed.
|
||||
</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
<!-- Section 5: Auto Formating -->
|
||||
|
||||
<sect1 id="auto-format">
|
||||
<title>
|
||||
Formating automatically
|
||||
|
@ -966,9 +1016,8 @@
|
|||
|
||||
<para>
|
||||
While coding in C, one often indents inner-blocks of
|
||||
code. To do this automatically while coding, VIM has
|
||||
command called cindent. To set this, the following command
|
||||
is used
|
||||
code. To do this automatically while coding, VIM has an
|
||||
option called cindent. To set this, just use the command
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
|
@ -977,7 +1026,7 @@
|
|||
|
||||
<para>
|
||||
By setting cindent, code is automatically beautified. To
|
||||
set this command automatically, just set it in your .vimrc
|
||||
set this command automatically, just add it to your .vimrc
|
||||
</para>
|
||||
|
||||
</sect2>
|
||||
|
@ -1060,6 +1109,8 @@
|
|||
|
||||
</sect1>
|
||||
|
||||
<!-- Section 6: Editing Multiple files -->
|
||||
|
||||
<sect1 id="multi">
|
||||
<title>
|
||||
Multi-file editing
|
||||
|
@ -1068,7 +1119,7 @@
|
|||
<para>
|
||||
One often needs to edit more than one file at a time. For
|
||||
example one maybe editing a header file and a source file at
|
||||
the same time. To editing more than one file at a time,
|
||||
the same time. To edit more than one file at a time,
|
||||
invoke VIM using the following command
|
||||
</para>
|
||||
|
||||
|
@ -1117,14 +1168,16 @@
|
|||
|
||||
<para>
|
||||
After executing that command, you'll find that there are two
|
||||
files visible. One with the first file and the other with the
|
||||
new file. To switch between the files on has to use the
|
||||
files visible. One window shows the first file and the other shows
|
||||
the second file. To switch between the files one has to use the
|
||||
keystroke <keycap>CTRL-W CTRL-W</keycap>. To learn more about
|
||||
split windows, just run help on it.
|
||||
</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
<!-- Section 7: Quickfix -->
|
||||
|
||||
<sect1 id="quickfix">
|
||||
<title>
|
||||
Quickfix
|
||||
|
@ -1136,7 +1189,7 @@
|
|||
I've mentioned earlier, save the file, compile the code and
|
||||
go to the error(s) and start editing again. VIM helps save
|
||||
the cycle time slightly using a mode called
|
||||
quickfix. Basically, one saves the compiler errors in a file
|
||||
quickfix. Basically, one has to save the compiler errors in a file
|
||||
and open the file with VIM using the command
|
||||
</para>
|
||||
|
||||
|
@ -1150,10 +1203,10 @@
|
|||
</para>
|
||||
|
||||
<para>
|
||||
There is a shortcut to the cycle. Using the make command, one
|
||||
There is a shortcut to the cycle. Using the command "make", one
|
||||
can automatically compile code and goto the position where
|
||||
the first error occurs. To invoke the make command use the
|
||||
following command
|
||||
the first error occurs. To invoke the make command type the
|
||||
following
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
|
@ -1258,7 +1311,7 @@
|
|||
<textobject>
|
||||
|
||||
<programlisting>
|
||||
:!gcc test.c 2>&1| tee /tmp/vim9821.err
|
||||
:!gcc test.c 2>&1| tee /tmp/vim9821.err
|
||||
test.c: In function `main':
|
||||
test.c:6: parse error before `}'
|
||||
test.c:4: warning: return type of `main' is not `int'
|
||||
|
@ -1312,7 +1365,7 @@
|
|||
<textobject>
|
||||
|
||||
<programlisting>
|
||||
:!gcc test.c 2>&1| tee /tmp/vim9822.err
|
||||
:!gcc test.c 2>&1| tee /tmp/vim9822.err
|
||||
|
||||
Press RETURN or enter command to continue
|
||||
</programlisting>
|
||||
|
@ -1333,13 +1386,15 @@
|
|||
|
||||
</sect1>
|
||||
|
||||
<!-- Section 8: Copyright -->
|
||||
|
||||
<sect1 id="copying">
|
||||
<title>
|
||||
Copyright
|
||||
</title>
|
||||
|
||||
<para>
|
||||
Copyright (c) 2000 Siddharth Heroor.
|
||||
Copyright (c) 2000,2001 Siddharth Heroor.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
@ -1356,6 +1411,8 @@
|
|||
|
||||
</sect1>
|
||||
|
||||
<!-- Section 9: References -->
|
||||
|
||||
<sect1 id="references">
|
||||
<title>
|
||||
References
|
||||
|
|
Loading…
Reference in New Issue