annotate runtime/doc/usr_29.txt @ 46:46d39f2eff86 v7.0027

updated for version 7.0027
author vimboss
date Fri, 31 Dec 2004 21:01:02 +0000
parents 3fc0f57ecb91
children 6beb2c667935
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 *usr_29.txt* For Vim version 7.0aa. Last change: 2004 Feb 12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 VIM USER MANUAL - by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 Moving through programs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 The creator of Vim is a computer programmer. It's no surprise that Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 contains many features to aid in writing programs. Jump around to find where
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 identifiers are defined and used. Preview declarations in a separate window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 There is more in the next chapter.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 |29.1| Using tags
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 |29.2| The preview window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 |29.3| Moving through a program
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 |29.4| Finding global identifiers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 |29.5| Finding local identifiers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 Next chapter: |usr_30.txt| Editing programs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 Previous chapter: |usr_28.txt| Folding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 Table of contents: |usr_toc.txt|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 *29.1* Using tags
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 What is a tag? It is a location where an identifier is defined. An example
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 is a function definition in a C or C++ program. A list of tags is kept in a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 tags file. This can be used by Vim to directly jump from any place to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 tag, the place where an identifier is defined.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 To generate the tags file for all C files in the current directory, use the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 following command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 ctags *.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 "ctags" is a separate program. Most Unix systems already have it installed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 If you do not have it yet, you can find Exuberant ctags here:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 http://ctags.sf.net ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 Now when you are in Vim and you want to go to a function definition, you can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 jump to it by using the following command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 :tag startlist
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 This command will find the function "startlist" even if it is in another file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 The CTRL-] command jumps to the tag of the word that is under the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 This makes it easy to explore a tangle of C code. Suppose, for example, that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 you are in the function "write_block". You can see that it calls
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 "write_line". But what does "write_line" do? By placing the cursor on the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 call to "write_line" and pressing CTRL-], you jump to the definition of this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 function.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 The "write_line" function calls "write_char". You need to figure out what
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 it does. So you position the cursor over the call to "write_char" and press
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 CTRL-]. Now you are at the definition of "write_char".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 +-------------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 |void write_block(char **s; int cnt) |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 |{ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 | int i; |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 | for (i = 0; i < cnt; ++i) |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 | write_line(s[i]); |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 |} | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 +-----------|-------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 CTRL-] |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 | +----------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 +--> |void write_line(char *s) |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 |{ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 | while (*s != 0) |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 | write_char(*s++); |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 |} | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 +--------|-------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 CTRL-] |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 | +------------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 +--> |void write_char(char c) |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 |{ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 | putchar((int)(unsigned char)c); |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 |} |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 +------------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 The ":tags" command shows the list of tags that you traversed through:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 :tags
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 # TO tag FROM line in file/text ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 1 1 write_line 8 write_block.c ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 2 1 write_char 7 write_line.c ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 > ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 Now to go back. The CTRL-T command goes to the preceding tag. In the example
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 above you get back to the "write_line" function, in the call to "write_char".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 This command takes a count argument that indicates how many tags to jump
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 back. You have gone forward, and now back. Let's go forward again. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 following command goes to the tag on top of the list: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 :tag
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 You can prefix it with a count and jump forward that many tags. For example:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 ":3tag". CTRL-T also can be preceded with a count.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 These commands thus allow you to go down a call tree with CTRL-] and back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 up again with CTRL-T. Use ":tags" to find out where you are.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 SPLIT WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 The ":tag" command replaces the file in the current window with the one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 containing the new function. But suppose you want to see not only the old
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 function but also the new one? You can split the window using the ":split"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 command followed by the ":tag" command. Vim has a shorthand command that does
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 both: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 :stag tagname
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 To split the current window and jump to the tag under the cursor use this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 CTRL-W ]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 If a count is specified, the new window will be that many lines high.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 MORE TAGS FILES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 When you have files in many directories, you can create a tags file in each of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 them. Vim will then only be able to jump to tags within that directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 To find more tags files, set the 'tags' option to include all the relevant
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 tags files. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 :set tags=./tags,./../tags,./*/tags
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 This finds a tags file in the same directory as the current file, one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 directory level higher and in all subdirectories.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 This is quite a number of tags files, but it may still not be enough. For
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 example, when editing a file in "~/proj/src", you will not find the tags file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 "~/proj/sub/tags". For this situation Vim offers to search a whole directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 tree for tags files. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 :set tags=~/proj/**/tags
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 ONE TAGS FILE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 When Vim has to search many places for tags files, you can hear the disk
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 rattling. It may get a bit slow. In that case it's better to spend this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 time while generating one big tags file. You might do this overnight.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 This requires the Exuberant ctags program, mentioned above. It offers an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 argument to search a whole directory tree: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 cd ~/proj
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 ctags -R .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 The nice thing about this is that Exuberant ctags recognizes various file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 types. Thus this doesn't work just for C and C++ programs, also for Eiffel
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 and even Vim scripts. See the ctags documentation to tune this.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 Now you only need to tell Vim where your big tags file is: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 :set tags=~/proj/tags
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 MULTIPLE MATCHES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 When a function is defined multiple times (or a method in several classes),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 the ":tag" command will jump to the first one. If there is a match in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 current file, that one is used first.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 You can now jump to other matches for the same tag with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 :tnext
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 Repeat this to find further matches. If there are many, you can select which
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 one to jump to: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 :tselect tagname
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 Vim will present you with a list of choices:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 # pri kind tag file ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 1 F f mch_init os_amiga.c ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 mch_init() ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 2 F f mch_init os_mac.c ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 mch_init() ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 3 F f mch_init os_msdos.c ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 mch_init(void) ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 4 F f mch_init os_riscos.c ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 mch_init() ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 Enter nr of choice (<CR> to abort): ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 You can now enter the number (in the first column) of the match that you would
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 like to jump to. The information in the other columns give you a good idea of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 where the match is defined.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 To move between the matching tags, these commands can be used:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 :tfirst go to first match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 :[count]tprevious go to [count] previous match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 :[count]tnext go to [count] next match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 :tlast go to last match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 If [count] is omitted then one is used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 GUESSING TAG NAMES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 Command line completion is a good way to avoid typing a long tag name. Just
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 type the first bit and press <Tab>: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 :tag write_<Tab>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 You will get the first match. If it's not the one you want, press <Tab> until
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 you find the right one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 Sometimes you only know part of the name of a function. Or you have many
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 tags that start with the same string, but end differently. Then you can tell
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 Vim to use a pattern to find the tag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 Suppose you want to jump to a tag that contains "block". First type
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 :tag /block
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 Now use command line completion: press <Tab>. Vim will find all tags that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 contain "block" and use the first match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 The "/" before a tag name tells Vim that what follows is not a literal tag
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 name, but a pattern. You can use all the items for search patterns here. For
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 example, suppose you want to select a tag that starts with "write_": >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 :tselect /^write_
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 The "^" specifies that the tag starts with "write_". Otherwise it would also
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 be found halfway a tag name. Similarly "$" at the end makes sure the pattern
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 matches until the end of a tag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 A TAGS BROWSER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 Since CTRL-] takes you to the definition of the identifier under the cursor,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 you can use a list of identifier names as a table of contents. Here is an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 example.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 First create a list of identifiers (this requires Exuberant ctags): >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 ctags --c-types=f -f functions *.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 Now start Vim without a file, and edit this file in Vim, in a vertically split
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 window: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 :vsplit functions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 The window contains a list of all the functions. There is some more stuff,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 but you can ignore that. Do ":setlocal ts=99" to clean it up a bit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 In this window, define a mapping: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 :nnoremap <buffer> <CR> 0ye<C-W>w:tag <C-R>"<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 Move the cursor to the line that contains the function you want to go to.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 Now press <Enter>. Vim will go to the other window and jump to the selected
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 function.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 RELATED ITEMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 You can set 'ignorecase' to make case in tag names be ignored.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 The 'tagbsearch' option tells if the tags file is sorted or not. The default
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 is to assume a sorted tags file, which makes a tags search a lot faster, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 doesn't work if the tags file isn't sorted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 The 'taglength' option can be used to tell Vim the number of significant
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 characters in a tag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 When you use the SNiFF+ program, you can use the Vim interface to it |sniff|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 SNiFF+ is a commercial program.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 Cscope is a free program. It does not only find places where an identifier is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 declared, but also where it is used. See |cscope|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 *29.2* The preview window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 When you edit code that contains a function call, you need to use the correct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 arguments. To know what values to pass you can look at how the function is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 defined. The tags mechanism works very well for this. Preferably the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 definition is displayed in another window. For this the preview window can be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 To open a preview window to display the function "write_char": >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 :ptag write_char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 Vim will open a window, and jumps to the tag "write_char". Then it takes you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 back to the original position. Thus you can continue typing without the need
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 to use a CTRL-W command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 If the name of a function appears in the text, you can get its definition
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 in the preview window with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 CTRL-W }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 There is a script that automatically displays the text where the word under
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 the cursor was defined. See |CursorHold-example|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 To close the preview window use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 :pclose
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 To edit a specific file in the preview window, use ":pedit". This can be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 useful to edit a header file, for example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 :pedit defs.h
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 Finally, ":psearch" can be used to find a word in the current file and any
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 included files and display the match in the preview window. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 especially useful when using library functions, for which you do not have a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 tags file. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 :psearch popen
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 This will show the "stdio.h" file in the preview window, with the function
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 prototype for popen():
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 FILE *popen __P((const char *, const char *)); ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 You can specify the height of the preview window, when it is opened, with the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 'previewheight' option.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 *29.3* Moving through a program
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 Since a program is structured, Vim can recognize items in it. Specific
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 commands can be used to move around.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 C programs often contain constructs like this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 #ifdef USE_POPEN ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 fd = popen("ls", "r") ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 #else ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 fd = fopen("tmp", "w") ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 #endif ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 But then much longer, and possibly nested. Position the cursor on the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 "#ifdef" and press %. Vim will jump to the "#else". Pressing % again takes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 you to the "#endif". Another % takes you to the "#ifdef" again.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 When the construct is nested, Vim will find the matching items. This is a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 good way to check if you didn't forget an "#endif".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 When you are somewhere inside a "#if" - "#endif", you can jump to the start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 of it with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 [#
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 If you are not after a "#if" or "#ifdef" Vim will beep. To jump forward to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 the next "#else" or "#endif" use: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 ]#
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 These two commands skip any "#if" - "#endif" blocks that they encounter.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 Example:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 #if defined(HAS_INC_H) ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 a = a + inc(); ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 # ifdef USE_THEME ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 a += 3; ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 # endif ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 set_width(a); ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 With the cursor in the last line, "[#" moves to the first line. The "#ifdef"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 - "#endif" block in the middle is skipped.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 MOVING IN CODE BLOCKS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 In C code blocks are enclosed in {}. These can get pretty long. To move to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 the start of the outer block use the "[[" command. Use "][" to find the end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 This assumes that the "{" and "}" are in the first column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 The "[{" command moves to the start of the current block. It skips over
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 pairs of {} at the same level. "]}" jumps to the end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 An overview:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 function(int a)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 +-> {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 | if (a)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 | +-> {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 [[ | | for (;;) --+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 | | +-> { |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 | [{ | | foo(32); | --+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 | | [{ | if (bar(a)) --+ | ]} |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 +-- | +-- break; | ]} | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 | } <-+ | | ][
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 +-- foobar(a) | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 } <-+ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 } <-+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 When writing C++ or Java, the outer {} block is for the class. The next level
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 of {} is for a method. When somewhere inside a class use "[m" to find the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 previous start of a method. "]m" finds the next end of a method.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 Additionally, "[]" moves backward to the end of a function and "]]" moves
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 forward to the start of the next function. The end of a function is defined
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 by a "}" in the first column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 int func1(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 +----------> }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 [] | int func2(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 | +-> {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 | [[ | if (flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 start +-- +-- return flag;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 | ][ | return 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 | +-> }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 ]] |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 | int func3(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 +----------> {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 return 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 Don't forget you can also use "%" to move between matching (), {} and [].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 That also works when they are many lines apart.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 MOVING IN BRACES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 The "[(" and "])" commands work similar to "[{" and "]}", except that they
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 work on () pairs instead of {} pairs.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 [(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 < <--------------------------------
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 <-------
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 if (a == b && (c == d || (e > f)) && x > y) ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 -------------->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 --------------------------------> >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 ])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 MOVING IN COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 To move back to the start of a comment use "[/". Move forward to the end of a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 comment with "]/". This only works for /* - */ comments.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 +-> +-> /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 | [/ | * A comment about --+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 [/ | +-- * wonderful life. | ]/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 | */ <-+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 +-- foo = bar * 3; --+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 | ]/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 /* a short comment */ <-+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 *29.4* Finding global identifiers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 You are editing a C program and wonder if a variable is declared as "int" or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 "unsigned". A quick way to find this is with the "[I" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 Suppose the cursor is on the word "column". Type: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 [I
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 Vim will list the matching lines it can find. Not only in the current file,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 but also in all included files (and files included in them, etc.). The result
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 looks like this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 structs.h ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 1: 29 unsigned column; /* column number */ ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 The advantage over using tags or the preview window is that included files are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 searched. In most cases this results in the right declaration to be found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 Also when the tags file is out of date. Also when you don't have tags for the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 included files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 However, a few things must be right for "[I" to do its work. First of all,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 the 'include' option must specify how a file is included. The default value
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 works for C and C++. For other languages you will have to change it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 LOCATING INCLUDED FILES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 Vim will find included files in the places specified with the 'path'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 option. If a directory is missing, some include files will not be found. You
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 can discover this with this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 :checkpath
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 It will list the include files that could not be found. Also files included
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 by the files that could be found. An example of the output:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 --- Included files not found in path --- ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 <io.h> ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 vim.h --> ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 <functions.h> ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 <clib/exec_protos.h> ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 The "io.h" file is included by the current file and can't be found. "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 can be found, thus ":checkpath" goes into this file and checks what it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 includes. The "functions.h" and "clib/exec_protos.h" files, included by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 "vim.h" are not found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 Vim is not a compiler. It does not recognize "#ifdef" statements.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 This means every "#include" statement is used, also when it comes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 after "#if NEVER".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 To fix the files that could not be found, add a directory to the 'path'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 option. A good place to find out about this is the Makefile. Look out for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 lines that contain "-I" items, like "-I/usr/local/X11". To add this directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 use: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 :set path+=/usr/local/X11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 When there are many subdirectories, you an use the "*" wildcard. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 :set path+=/usr/*/include
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 This would find files in "/usr/local/include" as well as "/usr/X11/include".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 When working on a project with a whole nested tree of included files, the "**"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 items is useful. This will search down in all subdirectories. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 :set path+=/projects/invent/**/include
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 This will find files in the directories:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 /projects/invent/include ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 /projects/invent/main/include ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 /projects/invent/main/os/include ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 There are even more possibilities. Check out the 'path' option for info.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 If you want to see which included files are actually found, use this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 :checkpath!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 You will get a (very long) list of included files, the files they include, and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 so on. To shorten the list a bit, Vim shows "(Already listed)" for files that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 were found before and doesn't list the included files in there again.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 JUMPING TO A MATCH
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 "[I" produces a list with only one line of text. When you want to have a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 closer look at the first item, you can jump to that line with the command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 [<Tab>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 You can also use "[ CTRL-I", since CTRL-I is the same as pressing <Tab>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 The list that "[I" produces has a number at the start of each line. When you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 want to jump to another item than the first one, type the number first: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 3[<Tab>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 Will jump to the third item in the list. Remember that you can use CTRL-O to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 jump back to where you started from.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 RELATED COMMANDS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 [i only lists the first match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 ]I only lists items below the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 ]i only lists the first item below the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 FINDING DEFINED IDENTIFIERS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 The "[I" command finds any identifier. To find only macros, defined with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 "#define" use: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 [D
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 Again, this searches in included files. The 'define' option specifies what a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 line looks like that defines the items for "[D". You could change it to make
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 it work with other languages than C or C++.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 The commands related to "[D" are:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 [d only lists the first match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 ]D only lists items below the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 ]d only lists the first item below the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 *29.5* Finding local identifiers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 The "[I" command searches included files. To search in the current file only,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 and jump to the first place where the word under the cursor is used: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 gD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 Hint: Goto Definition. This command is very useful to find a variable or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 function that was declared locally ("static", in C terms). Example (cursor on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 "counter"):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 +-> static int counter = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 | int get_counter(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 gD | {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 | ++counter;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 +-- return counter;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 To restrict the search even further, and look only in the current function,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 gd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 This will go back to the start of the current function and find the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 occurrence of the word under the cursor. Actually, it searches backwards to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 an empty line above the a "{" in the first column. From there it searches
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 forward for the identifier. Example (cursor on "idx"):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 int find_entry(char *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 +-> int idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 gd | for (idx = 0; idx < table_len; ++idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 | if (strcmp(table[idx].name, name) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 +-- return idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 Next chapter: |usr_30.txt| Editing programs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 Copyright: see |manual-copyright| vim:tw=78:ts=8:ft=help:norl: