comparison runtime/kde-tips @ 11:4424b47a0797

updated for version 7.0003
author vimboss
date Wed, 30 Jun 2004 16:16:41 +0000
parents
children
comparison
equal deleted inserted replaced
10:4e2284e71352 11:4424b47a0797
1 *vimtips.txt* This file comes from the Vim Online tip database. These tips
2 were downloaded on Tue, 24 Sep 2002 15:27:26 -0700 More tips can be found at <A
3 HREF="http://vim.sf.net/tip_index.php">http://vim.sf.net/tip_index.php</A><BR>
4 A new tip file can be downloaded from <A
5 HREF="http://vim.sf.net/tip_download.php">http://vim.sf.net/tip_download.php</A><BR>
6
7 Thanks for using vim online.
8
9 <Tip category="KVim"> <html><center>the super star</center> <pre> <A
10 HREF="http://vim.sf.net/tip_view.php?tip_id=1">http://vim.sf.net/tip_view.php?tip_id=1</A><BR>
11
12 When a discussion started about learning vim on the vim list Juergen Salk
13 mentioned the "*" key as something that he wished he had know earlier. When
14 I read the mail I had to go help on what the heck the "*" did. I also wish
15 I had known earlier...
16
17 Using the "*" key while in normal mode searches for the word under the cursor.
18
19 If that doesn't save you a lot of typing, I don't know what will.
20
21 </pre></tip> </html> <Tip category="KVim"> <html><center>easy
22 edit of files in the same directory</center> <pre> <A
23 HREF="http://vim.sf.net/tip_view.php?tip_id=2">http://vim.sf.net/tip_view.php?tip_id=2</A><BR>
24
25 It was often frustrating when I would open a file deep in the code tree and
26 then realize I wanted to open another file in that same directory. Douglas
27 Potts taught me a nice way to do this. Add the following snipit to your vimrc:
28
29 " Edit another file in the same directory as the current file " uses
30 expression to extract path from current file's path " (thanks Douglas Potts)
31 if has("unix")
32 map ,e :e &lt;C-R&gt;=expand("%:p:h") . "/" &lt;CR&gt;
33 else
34 map ,e :e &lt;C-R&gt;=expand("%:p:h") . "\" &lt;CR&gt;
35 endif
36
37 Then when you type ,e in normal mode you can use tab to complete to the
38 file. You can also expand this to allow for spitting, etc. Very very nice.
39
40 </pre></tip> </html> <Tip category="KVim"> <html><center>use
41 vim to quickly compile java files</center> <pre> <A
42 HREF="http://vim.sf.net/tip_view.php?tip_id=3">http://vim.sf.net/tip_view.php?tip_id=3</A><BR>
43
44 For a number of years I used vim on an SGI box. When I left my job at SGI
45 I went to a company that developed on PCs. For 2 years I used IDEs. I was
46 unhappy. I was frustrated. I couldn't figure out why. (Beyond my machine
47 crashing twice a day.) Finally I upgraded to windows 2000 (kind of stable!) and
48 started using vim as an IDE. All was good. Here is how you use vim to compile
49 your java:
50
51 1. While I'm sure this works with javac, javac is slow slow slow. So download
52 the Jikes complier first. (Jikes is from ibm, search on google for jikes
53 and you will find it..available on most platforms.)
54
55 2. Add the following to your vimrc:
56
57 set makeprg=jikes -nowarn -Xstdout +E % set
58 errorformat=%f:%l:%c:%*\d:%*\d:%*\s%m
59
60 3. When you are editing a java file type :make and it will compile the
61 current file and jump you to the first error in the file (if any). Read
62 ":help quickfix" for how to move between errors.
63
64 To setup your classpath environment either launch gvim from a shell that
65 has your classpath/path setup or use the "let" command to configure it in
66 your vimrc.
67
68 </pre></tip> </html> <Tip category="KVim">
69 <html><center>Any word completion</center> <pre> <A
70 HREF="http://vim.sf.net/tip_view.php?tip_id=4">http://vim.sf.net/tip_view.php?tip_id=4</A><BR>
71
72 Either when programming or writing, I tend to have some identifiers or words
73 that I use all the time. By sheer accident, I noticed the 'ctrl-n' command,
74 that will attempt to complete the word under the cursor. Hit it once, and it
75 will try to complete it with the first match in the current file. If there is
76 no match, it will (at least in the case of C code) search through all files
77 included from the current one. Repeated invocations will cycle through all
78 found matches.
79
80 </pre></tip> </html> <Tip category="KVim">
81 <html><center>Quickly searching for a word</center> <pre> <A
82 HREF="http://vim.sf.net/tip_view.php?tip_id=5">http://vim.sf.net/tip_view.php?tip_id=5</A><BR>
83
84 To search for a word under the cursor in the current file you can use either
85 the "*" or "#" keys.
86
87 The "*" key will search for the word from the current cursor position to
88 the end of the file. The "#" key will search for the word from the current
89 cursor position to the top of the file.
90
91 Note that the above two keys will search for the whole word and not the
92 partial word. This is equivalent to using the &lt;word&gt; pattern in the
93 search commands (/ and ?).
94
95 To search for partial matches, you can use the "g*" and "g#" key sequence.
96
97 You can also use the mouse to search for a word. This will only work in
98 the GUI version of VIM (gvim) or a console version of VIM in an xterm which
99 accepts a mouse. Also, the 'mousemodel' should be set to 'extend'. Add the
100 following line to your .vimrc:
101
102 set mousemodel=extend
103
104 To search for a word under the cursor from the current cursor position to
105 the end of the file, press the shift key and click on the word using the
106 left mouse button. To search in the opposite direction, press the shift
107 key and click on the word using the the right mouse button.
108
109 To get more help on these, use
110
111 :help * :help # :help g* :help g# :help &lt;S-LeftMouse&gt; :help
112 &lt;S-RightMouse&gt;
113
114 </pre></tip> </html> <Tip category="KVim">
115 <html><center>Using the % key</center> <pre> <A
116 HREF="http://vim.sf.net/tip_view.php?tip_id=6">http://vim.sf.net/tip_view.php?tip_id=6</A><BR>
117
118 The % key can be used
119
120 1. To jump to a matching opening or closing parenthesis, square
121 bracket or a curly brace i.e. ([{}])
122 2. To jump to start or end of a C-style comment /* */. 3. To jump to a
123 matching #if, #ifdef, #else, #elif, #endif C
124 preprocessor conditionals.
125
126 To get more information about this, do
127
128 :help %
129
130 The % key can be extended to support other matching pairs by modifying the
131 "matchpairs" option. Read the help on
132
133 :help matchpairs
134
135 </pre></tip> </html> <Tip category="KVim"> <html><center>Jumping
136 to the start and end of a code block</center> <pre> <A
137 HREF="http://vim.sf.net/tip_view.php?tip_id=7">http://vim.sf.net/tip_view.php?tip_id=7</A><BR>
138
139 To jump to the beginning of a C code block (while, switch, if etc), use the
140 [{ command.
141
142 To jump to the end of a C code block (while, switch, if etc), use the ]}
143 command.
144
145 The above two commands will work from anywhere inside the code block.
146
147 To jump to the beginning of a parenthesis use the [( command.
148
149 To jump to the end of a parenthesis use the ]) command.
150
151 To get more help on these commands, do
152
153 :help [{ :help ]} :help [( :help ])
154
155 </pre></tip> </html> <Tip category="KVim"> <html><center>Jumping
156 to the declaration of a local/global variable</center> <pre> <A
157 HREF="http://vim.sf.net/tip_view.php?tip_id=8">http://vim.sf.net/tip_view.php?tip_id=8</A><BR>
158
159 'gd' command: To jump to the declaration of a local variable in a C program,
160 position the cursor on the name of the variable and use the gd command.
161
162 'gD' command: To jump to the declaration of a global variable in a C program,
163 position the cursor on the name of the variable and use the gD command.
164
165 </pre></tip> </html> <Tip category="KVim"> <html><center>Displaying
166 a variable/macro definition</center> <pre> <A
167 HREF="http://vim.sf.net/tip_view.php?tip_id=9">http://vim.sf.net/tip_view.php?tip_id=9</A><BR>
168
169 To display the definition of a variable, place the cursor on the variable
170 and use the [i command. To display a macro definition, place the cursor on
171 the macro name and use the [d command. Note that these commands will work
172 most of the time (not all the time). To get more help on these commands, use
173
174 :help [i :help [d
175
176 </pre></tip> </html> <Tip category="KVim"> <html><center>Jumping
177 to previosuly visited locations in a file</center> <pre> <A
178 HREF="http://vim.sf.net/tip_view.php?tip_id=10">http://vim.sf.net/tip_view.php?tip_id=10</A><BR>
179
180 Vim remembers all the locations visited by you in a file in a session.
181 You can jump to the older locations by pressing the Ctrl-O key. You can
182 jump to the newer locations by pressing the Ctrl-I or the &lt;Tab&gt; key.
183
184 To get more help on these keys, use
185
186 :help CTRL-O :help CTRL-I :help jump-motions
187
188 </pre></tip> </html> <Tip category="KVim"> <html><center>Completing
189 words quicky in insert mode</center> <pre> <A
190 HREF="http://vim.sf.net/tip_view.php?tip_id=11">http://vim.sf.net/tip_view.php?tip_id=11</A><BR>
191
192 In Insert mode, press the Ctrl-p or Ctrl-n key to complete part of a word
193 that has been typed.
194
195 This is useful while typing C programs to complete long variable and
196 function names. This also helps in avoiding typing mistakes.
197
198 Note that using the 'complete' option, you can complete keywords defined in
199 one of the include files, tag file, etc.
200
201 To get more help on this, use
202
203 :help i_Ctrl-N :help i_Ctrl-P :help ins-completion :help complete
204
205 </pre></tip> </html> <Tip category="KVim">
206 <html><center>Converting tabs to spaces</center> <pre> <A
207 HREF="http://vim.sf.net/tip_view.php?tip_id=12">http://vim.sf.net/tip_view.php?tip_id=12</A><BR>
208
209 To insert space characters whenever the tab key is pressed, set the
210 'expandtab' option:
211
212 set expandtab
213
214 With this option set, if you want to enter a real tab character use
215 Ctrl-V&lt;Tab&gt; key sequence.
216
217 To control the number of space characters that will be inserted when the tab
218 key is pressed, set the 'tabstop' option. For example, to insert 4 spaces
219 for a tab, use:
220
221 set tabstop=4
222
223 After the 'expandtab' option is set, all the new tab characters entered will
224 be changed to spaces. This will not affect the existing tab characters.
225 To change all the existing tab characters to match the current tab settings,
226 use
227
228 :retab
229
230 To change the number of space characters inserted for indentation, use the
231 'shiftwidth' option:
232
233 set shiftwidth=4
234
235 For example, to get the following coding style,
236 - No tabs in the source file - All tab characters are 4 space
237 characters
238
239 use the following set of options:
240
241 set tabstop=4 set shiftwidth=4 set expandtab
242
243 Add the above settings to your .vimrc file.
244
245 To get more help on these options, use :help tabstop :help shiftwidth :help
246 expandtab
247
248 </pre></tip> </html> <Tip category="KVim">
249 <html><center>Incremental search</center> <pre> <A
250 HREF="http://vim.sf.net/tip_view.php?tip_id=13">http://vim.sf.net/tip_view.php?tip_id=13</A><BR>
251
252 To move the cursor to the matched string, while typing the search string,
253 set the following option in the .vimrc file:
254
255 set incsearch
256
257 You can complete the search by pressing the Enter key. To cancel the search,
258 press the escape key.
259
260 </pre></tip> </html> <Tip category="KVim"> <html><center>Highlighting
261 all the search pattern matches</center> <pre> <A
262 HREF="http://vim.sf.net/tip_view.php?tip_id=14">http://vim.sf.net/tip_view.php?tip_id=14</A><BR>
263
264 To highlight all the search pattern matches in a file set the following option:
265
266 :set hlsearch
267
268 After this option is set, if you search for a pattern, all the matches in
269 the file will be highlighted in yellow.
270
271 To disable the highlighting temporarily, use the command
272
273 :nohlsearch
274
275 This command will remove the highlighting for the current search.
276 The highlighting will come back for the next search.
277
278 To disable the highlighting completely, set the following option:
279
280 :set nohlsearch
281
282 By default, the hlsearch option is turned off.
283
284 To get more help on this option, use
285
286 :help 'hlsearch' :help :nohlsearch
287
288 </pre></tip> </html> <Tip category="KVim">
289 <html><center>Displaying status line always</center> <pre> <A
290 HREF="http://vim.sf.net/tip_view.php?tip_id=15">http://vim.sf.net/tip_view.php?tip_id=15</A><BR>
291
292 To display the status line always, set the following option in your .vimrc
293 file:
294
295 set laststatus=2
296
297 The advantage of having the status line displayed always is, you can see
298 the current mode, file name, file status, ruler, etc.
299
300 To get more help on this, use
301
302 :help laststatus
303
304 </pre></tip> </html> <Tip category="KVim"> <html><center>Avoiding
305 the "Hit ENTER to continue" prompts</center> <pre> <A
306 HREF="http://vim.sf.net/tip_view.php?tip_id=16">http://vim.sf.net/tip_view.php?tip_id=16</A><BR>
307
308 To avoid the "Hit ENTER to continue" prompt, use the 'shortmess' option.
309 Add the following line to your .vimrc file:
310
311 set shortmess=a
312
313 Also, you can increase the height of the command line to 2
314
315 set cmdheight=2
316
317 The default command height is 1.
318
319 To get more help on these options, use
320
321 :help hit-enter :help shortmess :help cmdheight
322
323 </pre></tip> </html> <Tip category="KVim"> <html><center>Erasing
324 previosuly entered characters in insert mode</center> <pre> <A
325 HREF="http://vim.sf.net/tip_view.php?tip_id=17">http://vim.sf.net/tip_view.php?tip_id=17</A><BR>
326
327 In insert mode, to erase previously entered characters, set the following
328 option:
329
330 set backspace=2
331
332 By default, this option is empty. If this option is empty, in insert mode,
333 you can not erase characters entered before this insert mode started.
334 This is the standard Vi behavior.
335
336 To get more help on this, use
337
338 :help 'backspace'
339
340 </pre></tip> </html> <Tip category="KVim">
341 <html><center>Cleanup your HTML</center> <pre> <A
342 HREF="http://vim.sf.net/tip_view.php?tip_id=18">http://vim.sf.net/tip_view.php?tip_id=18</A><BR>
343
344 From Johannes Zellner on the vim list:
345
346 You can use vim's makeprg and equalprg to clean up HTML. First download
347 html tidy from <A HREF="http://www.w3.org/People/Raggett/tidy/. Then use
348 the following commands.">http://www.w3.org/People/Raggett/tidy/. Then use
349 the following commands.</A><BR>
350
351 vim6? exe 'setlocal equalprg=tidy -quiet -f '.&errorfile setlocal makeprg=tidy
352 -quiet -e %
353
354 vim5? exe 'set equalprg=tidy -quiet -f '.&errorfile set makeprg=tidy -quiet
355 -e %
356
357 At this point you can use make to clean up the full file or you can use =
358 to clean up sections.
359
360 :help = :help equalprg :help makeprg
361
362 </pre></tip> </html> <Tip category="KVim">
363 <html><center>line numbers...</center> <pre> <A
364 HREF="http://vim.sf.net/tip_view.php?tip_id=19">http://vim.sf.net/tip_view.php?tip_id=19</A><BR>
365
366 I have started doing all my code reviews on a laptop because of the number
367 command.
368
369 :set number will put line numbers along the left side of a window
370
371 :help number
372
373 </pre></tip> </html> <Tip category="KVim"> <html><center>Are *.swp
374 and *~ files littering your working directory?</center> <pre> <A
375 HREF="http://vim.sf.net/tip_view.php?tip_id=20">http://vim.sf.net/tip_view.php?tip_id=20</A><BR>
376
377 Have you ever been frustrated at swap files and backups cluttering up your
378 working directory?
379
380 Untidy:
381 ons.txt ons.txt~ README README~ tester.py tester.py~
382
383 Here are a couple of options that can help:
384
385 set backupdir=./.backup,.,/tmp set directory=.,./.backup,/tmp
386
387 This way, if you want your backups to be neatly grouped, just create
388 a directory called '.backup' in your working directory. Vim will stash
389 backups there. The 'directory' option controls where swap files go. If your
390 working directory is not writable, Vim will put the swap file in one of the
391 specified places.
392
393 </pre></tip> </html> <Tip category="KVim">
394 <html><center>easy pasting to windows apps</center> <pre> <A
395 HREF="http://vim.sf.net/tip_view.php?tip_id=21">http://vim.sf.net/tip_view.php?tip_id=21</A><BR>
396
397 In Vim, the unnamed register is the " register, and the Windows Clipboard is
398 the * register. This means that if you yank something, you have to yank it to
399 the * register if you want to paste it into a Windows app. If this is too much
400 trouble, set the 'clipboard' option to 'unnamed'. Then you always yank to *.
401
402 So pasting to windows apps doesn't require prefixing "* :
403
404 set clipboard=unnamed
405
406 </pre></tip> </html> <Tip category="KVim"> <html><center>handle
407 common typos for :commands</center> <pre> <A
408 HREF="http://vim.sf.net/tip_view.php?tip_id=22">http://vim.sf.net/tip_view.php?tip_id=22</A><BR>
409
410 I frequently hold the shift key for too long when typing, for instance :wq,
411 and end up with :Wq. Vim then whines "Not an editor command: Wq"
412
413 In my .vimrc, I have taught vim my common typos: command! Q quit command! W
414 write command! Wq wq " this one won't work, because :X is already a built-in
415 command command! X xit
416
417 </pre></tip> </html> <Tip category="KVim">
418 <html><center>Vim xterm title</center> <pre> <A
419 HREF="http://vim.sf.net/tip_view.php?tip_id=23">http://vim.sf.net/tip_view.php?tip_id=23</A><BR>
420
421 Check out your .vimrc. If 'set notitle' is an entry, comment it out with
422 a quotation mark ("). Now your xterm should inherit the title from Vim.
423 e.g. 'Vim - ~/.vimrc'. This can be quite nice when programming and editing
424 lots of files at the same time. by [jonasbn@wanadoo.dk]
425
426 </pre></tip> </html> <Tip category="KVim"> <html><center>changing
427 the default syntax highlighting</center> <pre> <A
428 HREF="http://vim.sf.net/tip_view.php?tip_id=24">http://vim.sf.net/tip_view.php?tip_id=24</A><BR>
429
430 Here are some pointers to the vim documentation. Notice that the
431 mechanism is different in vim 6.0 and vim 5.x.
432
433 1. I want *.foo files to be highlighted like HTML files.
434
435 :help new-filetype <A
436 HREF="http://www.vim.org/html/autocmd.html#new-filetype">http://www.vim.org/html/autocmd.html#new-filetype</A><BR>
437
438 2. I want to define a syntax file for *.bar files. Read the above and also
439
440 :help mysyntaxfile <A
441 HREF="http://www.vim.org/html/syntax.html#mysyntaxfile">http://www.vim.org/html/syntax.html#mysyntaxfile</A><BR>
442
443 3. I want to make a few changes to the existing syntax highlighting.
444 Depending on the x in 5.x, either read the above and page down a few screens,
445 or you may be able to skip right to
446
447 :help mysyntaxfile-add <A
448 HREF="http://www.vim.org/html/syntax.html#mysyntaxfile-add">http://www.vim.org/html/syntax.html#mysyntaxfile-add</A><BR>
449
450 4. I want to change some of the colors from their defaults. Again, read
451
452 :help mysyntaxfile <A
453 HREF="http://www.vim.org/html/syntax.html#mysyntaxfile">http://www.vim.org/html/syntax.html#mysyntaxfile</A><BR>
454
455 </pre></tip> </html> <Tip category="KVim"> <html><center>color
456 highlighting on telnet (esp w/ SecureCRT)</center> <pre> <A
457 HREF="http://vim.sf.net/tip_view.php?tip_id=25">http://vim.sf.net/tip_view.php?tip_id=25</A><BR>
458
459 The following settings in .vimrc will enable color highlighting when using
460 SecureCRT and may work on other telnet packages. The terminal type should
461 be selected as ANSI and color enabled.
462
463 if !has("gui_running") set t_Co=8 set t_Sf=^[[3%p1%dm set t_Sb=^[[4%p1%dm endif
464
465 The ^[ is entered as "&lt;ctrl-v&gt;&lt;esc&gt;"
466
467 </pre></tip> </html> <Tip category="KVim"> <html><center>Getting
468 rid of ^M - mixing dos and unix</center> <pre> <A
469 HREF="http://vim.sf.net/tip_view.php?tip_id=26">http://vim.sf.net/tip_view.php?tip_id=26</A><BR>
470
471 If you work in a mixed environment you will often open files that have ^M's
472 in them. An example would be this:
473
474 ------------------------------------------------------------------
475 import java.util.Hashtable; ^M import java.util.Properties; ^Mimport
476 java.io.IOException; import org.xml.sax.AttributeList; ^M import
477 org.xml.sax.HandlerBase; ^Mimport org.xml.sax.SAXException;
478
479 /**^M
480 * XMLHandler: This class parses the elements contained^M * within a XML
481 message and builds a Hashtable^M
482
483 [snip] ------------------------------------------------------------------
484
485 Notice that some programs are not consistent in the way they insert the line
486 breaks so you end up with some lines that have both a carrage return and a
487 ^M and some lines that have a ^M and no carrage return (and so blend into
488 one). There are two steps to clean this up.
489
490 1. replace all extraneous ^M:
491
492 :%s/^M$//g
493
494 BE SURE YOU MAKE the ^M USING "CTRL-V CTRL-M" NOT BY TYPING "CARROT M"! This
495 expression will replace all the ^M's that have carriage returns after them
496 with nothing. (The dollar ties the search to the end of a line)
497
498 2. replace all ^M's that need to have carriage returns:
499
500 :%s/^M//g
501
502 Once again: BE SURE YOU MAKE the ^M USING "CTRL-V CTRL-M" NOT BY TYPING
503 "CARROT M"! This expression will replace all the ^M's that didn't have
504 carriage returns after them with a carriage return.
505
506 Voila! Clean file. Map this to something if you do it frequently.
507
508 :help ffs - for more info on file formats
509
510 thanks to jonathan merz, douglas potts, and benji fisher
511
512 </pre></tip> </html> <Tip category="KVim">
513 <html><center>Convert hex to dec</center> <pre> <A
514 HREF="http://vim.sf.net/tip_view.php?tip_id=27">http://vim.sf.net/tip_view.php?tip_id=27</A><BR>
515
516 when you check the output of objdump, you'll confused by the $0xFFFFFFc
517 operand, this function translate the hexcamal to decimal. function! Hex2Dec()
518 let lstr = getline(".") let hexstr = matchstr(lstr, '0x[a-f0-9]+')
519 while hexstr != ""
520 let hexstr = hexstr + 0 exe 's#0x[a-f0-9]+#'.hexstr."#" let lstr =
521 substitute(lstr, '0x[a-f0-9]+', hexstr, "") let hexstr = matchstr(lstr,
522 '0x[a-f0-9]+')
523 endwhile
524 endfunction usage: 5,8call Hex2Dec()
525
526 </pre></tip> </html> <Tip category="KVim"> <html><center>add a line-number
527 to every line without cat or awk alike utilities.</center> <pre> <A
528 HREF="http://vim.sf.net/tip_view.php?tip_id=28">http://vim.sf.net/tip_view.php?tip_id=28</A><BR>
529
530 With Unix-like environment, you can use cat or awk to generate a line number
531 easily, because vim has a friendly interface with shell, so everything work
532 in vim as well as it does in shell. :%!call -n or :%!awk '{print NR,$0}'
533
534 But, if you use vim in MS-DOS, of win9x, win2000, you loss these tookit.
535 here is a very simple way to archive this only by vim: fu! LineIt()
536 exe ":s/^/".line(".")."/"
537 endf
538
539 Well, a sequence composed with alphabet is as easy as above:
540 exe "s/^/".nr2char(line("."))."/"
541
542 </pre></tip> </html> <Tip category="KVim"> <html><center>reverse
543 all the line with only 7 keystroke in vim</center> <pre> <A
544 HREF="http://vim.sf.net/tip_view.php?tip_id=29">http://vim.sf.net/tip_view.php?tip_id=29</A><BR>
545
546 :g/^/m0 well, 1. : bring you to command-line mode(also known as ex-mode)
547 from normal-mode(also known as command mode). 2. g means you'll take an
548 action through the whole file, generally perform a search, `v' also perform
549 a search but it match the line not match the canonical expression. 3. /
550 begins the regular express 4. ^ is a special character respect the start
551 of a line. 5. the second / ends the regular express and indicate that the
552 remains is action to do. 6. m means move, `t` and `co' for copy, `d' for
553 delete 7. 0 is the destination line.
554
555 you can use :g/regexp/t$ to filter all lines and pick the match line together
556 and copy them to the end of the buffer or :g/regexp/y A to put them into a
557 register(not eax, ebx...)
558
559 </pre></tip> </html> <Tip category="KVim">
560 <html><center>Increasing or decreasing numbers</center> <pre> <A
561 HREF="http://vim.sf.net/tip_view.php?tip_id=30">http://vim.sf.net/tip_view.php?tip_id=30</A><BR>
562
563 To increase a number under or nearest to the right of the cursor, go to
564 Normal mode and type:
565 Ctrl-A
566
567 To decrease, type:
568 Ctrl-X
569
570 Using this in a macro simplifies generating number sequences a lot.
571
572 </pre></tip> </html> <Tip category="KVim">
573 <html><center>Find and Replace</center> <pre> <A
574 HREF="http://vim.sf.net/tip_view.php?tip_id=31">http://vim.sf.net/tip_view.php?tip_id=31</A><BR>
575
576 To find and replace one or more occurences of a given text pattern with a
577 new text string, use the s[ubstitute] command.
578
579 There are a variety of options, but these are what you most probably want:
580
581 :%s/foo/bar/g find each occurance of 'foo' and replace it with
582 'bar' without asking for confirmation
583
584 :%s/foo/bar/gc find each occurance of 'foo' and replace it with
585 'bar' asking for confirmation first
586
587 :%s/&lt;foo&gt;/bar/gc find (match exact word only) and replace each
588 occurance of 'foo' with 'bar'
589
590 :%s/foo/bar/gci find (case insensitive) and replace each occurance of
591 'foo' with 'bar'
592
593 :%s/foo/bar/gcI find (case sensitive) and replace each occurance of
594 'foo' with 'bar'
595
596 NB: Without the 'g' flag, replacement occurs only for the first occurrence
597 in each line.
598
599 For a full description and some more interesting examples of the substitute
600 command refer to
601
602 :help substitute
603
604 See also:
605
606 :help cmdline-ranges :help pattern :help gdefault
607
608 </pre></tip> </html> <Tip category="KVim"> <html><center>Write
609 your own vim function(scripts)</center> <pre> <A
610 HREF="http://vim.sf.net/tip_view.php?tip_id=32">http://vim.sf.net/tip_view.php?tip_id=32</A><BR>
611
612 compare to C and shell(bash), herein is some vim specifics about vim-script:
613 1. A function name must be capitalized.
614 hex2dec is invalid Hex2dec is valid while in c and shell(bash), both
615 lowercase and uppercase is allowed.
616 2. how to reference the parameters
617 fu! Hex2dec(var1, var2)
618 let str=a:var1 let str2=a:var2
619 you must prefix the parameter name with "a:", and a:var1 itself is read-only
620 in c, you reference the parameter directly and the parameter is writable.
621 3. how to implement variable parameter
622 fu! Hex2dec(fixpara, ...)
623 a:0 is the real number of the variable parameter when you invoke the
624 function, with :Hex2dec("asdf", 4,5,6), a:0=3, and a:1=4 a:2=5 a:3=6
625 you can combine "a:" and the number to get the value while i&lt;a:0
626 exe "let num=a:".i let i=i+1
627 endwhile in c, the function get the real number by checking the additional
628 parameter such as printf family, or by checking the special value such
629 as NULL
630 4. where is the vim-library
631 yes, vim has its own function-library, just like *.a in c :help functions
632 5. can I use += or ++ operator?
633 Nop, += and ++ (and -=, -- and so on)operator gone away in vim.
634 6. How can I assign a value to a variables and fetch its value?
635 let var_Name=value let var1=var2 like it does in c, except you must use
636 let keyword
637 7. Can I use any ex-mode command in a function?
638 As I know, yes, just use it directly, as if every line you type appears
639 in the familar :
640 8. Can I call a function recurse?
641 Yes, but use it carefully to avoid infinte call.
642 9. Can I call another function in a function?
643 Course, like C does.
644 10. Must I compile the function?
645 No, you needn't and you can't, just :so script_name, after this you can
646 call the function freely.
647 11. Is it has integer and char or float data type?
648 No, like perl, vim script justify the variable type depend upon the context
649 :let a=1 :let a=a."asdf" :echo a you'll get `1asdf' :let a=1 :let a=a+2
650 :echo a you'll get 3 But it differs from perl.
651 12. Must I append a `;' in every statement?
652 No, never do that. ; is required in C, and optional in shell for each
653 statement in a alone line. But is forbidden in vim. if you want combine
654 servals statement in one single line, use `|'. Take your mind that every
655 statement appears in function should be valid in ex-mode(except for some
656 special statement).
657
658 </pre></tip> </html> <Tip category="KVim"> <html><center>toggle
659 off the line-number when enter on-line help</center> <pre> <A
660 HREF="http://vim.sf.net/tip_view.php?tip_id=33">http://vim.sf.net/tip_view.php?tip_id=33</A><BR>
661
662 I like the line-number for myself editing. But I hate it in on-line help
663 page because it force the screen wrapped. :au filetype help :se nonu
664
665 </pre></tip> </html> <Tip category="KVim"> <html><center>control
666 the position of the new window</center> <pre> <A
667 HREF="http://vim.sf.net/tip_view.php?tip_id=34">http://vim.sf.net/tip_view.php?tip_id=34</A><BR>
668
669 :se splitbelow make the new window appears below the current window.
670 :se splitright make the new window appears in right.(only 6.0 version can
671 do a vsplit)
672
673 </pre></tip> </html> <Tip category="KVim"> <html><center>translate
674 // style comment to /* */and vice vesa</center> <pre> <A
675 HREF="http://vim.sf.net/tip_view.php?tip_id=35">http://vim.sf.net/tip_view.php?tip_id=35</A><BR>
676
677 the `|' concatenate servals ex-command in one line. It's the key to translate
678 // style comments to /* */ style :g#^s{-}//#s##/*# | s#$#*/#
679
680 the `|' keep the current line matchs ^s{-}// to perform s#$#*/
681
682 /* ... */ ---&gt; //style :g#/*(.{-})*/#//1#
683
684 /* ....
685 .... .....
686 */ =====&gt; //...... //...... //...... style: ? Anyone implement it?
687
688 </pre></tip> </html> <Tip category="KVim">
689 <html><center>Using Gnu-info help in vim</center> <pre> <A
690 HREF="http://vim.sf.net/tip_view.php?tip_id=36">http://vim.sf.net/tip_view.php?tip_id=36</A><BR>
691
692 K in normal bring you the man page about the keyword under current cursor.
693 :nnoremap &lt;F1&gt; :exe ":!info ".expand("&lt;cword&gt;") Now press F1
694 while the cursor is hold by a keyword such as printf will bring you to
695 Gnu-info help page :h &lt;F1&gt; :h nnoremap
696
697 </pre></tip> </html> <Tip category="KVim"> <html><center>The
698 basic operation about vim-boolean optionals</center> <pre> <A
699 HREF="http://vim.sf.net/tip_view.php?tip_id=37">http://vim.sf.net/tip_view.php?tip_id=37</A><BR>
700
701 :set number switch the number on :set nonumber switch it off :set invnumber
702 or :set number! switch it inverse against the current setting :set number&
703 get the default value vim assums.
704
705 replace number with any legal vim-boolean optionals, they all works well.
706 for vim-non-boolean optionals :set optional& also works properly.
707
708 </pre></tip> </html> <Tip category="KVim"> <html><center>Cursor
709 one line at a time when :set wrap</center> <pre> <A
710 HREF="http://vim.sf.net/tip_view.php?tip_id=38">http://vim.sf.net/tip_view.php?tip_id=38</A><BR>
711
712 If your tierd of the cursor jumping past 5 lines when :set wrap then add
713 these mappings to you vimrc file.
714
715 nnoremap j gj nnoremap k gk vnoremap j gj vnoremap k gk nnoremap &lt;Down&gt;
716 gj nnoremap &lt;Up&gt; gk vnoremap &lt;Down&gt; gj vnoremap &lt;Up&gt;
717 gk inoremap &lt;Down&gt; &lt;C-o&gt;gj inoremap &lt;Up&gt; &lt;C-o&gt;gk
718
719 What they do is remap the cursor keys to use there `g' equvilant. See :help gj
720
721 </pre></tip> </html> <Tip category="KVim">
722 <html><center>Undo and Redo</center> <pre> <A
723 HREF="http://vim.sf.net/tip_view.php?tip_id=39">http://vim.sf.net/tip_view.php?tip_id=39</A><BR>
724
725 To undo recent changes, use the u[ndo] command:
726
727 u undo last change (can be repeated to undo preceding commands)
728 U return the line to its original state (undo all changes in
729 current line) CTRL-R Redo changes which were undone (undo the undo's).
730
731 For a full description of the undo/redo commands refer to
732
733 :help undo
734
735 </pre></tip> </html> <Tip category="KVim">
736 <html><center>Insert a file</center> <pre> <A
737 HREF="http://vim.sf.net/tip_view.php?tip_id=40">http://vim.sf.net/tip_view.php?tip_id=40</A><BR>
738
739 To insert the contents of a file (or the output of a system command) into
740 the current buffer, use the r[ead] command:
741
742 Examples:
743
744 :r foo.txt inserts the file foo.txt below the cursor
745
746 :0r foo.txt inserts the file foo.txt above the first line
747
748 :r !ls inserts a listing of your directory below the cursor
749
750 :$r !pwd inserts the current working directory below the last line
751
752 For more information about the r[ead] command refer to:
753
754 :help read
755
756 See also:
757
758 :help cmdline-ranges :help !cmd
759
760 </pre></tip> </html> <Tip category="KVim"> <html><center>Command-history
761 facilities for Oracle/sqlplus user</center> <pre> <A
762 HREF="http://vim.sf.net/tip_view.php?tip_id=41">http://vim.sf.net/tip_view.php?tip_id=41</A><BR>
763
764 First of all, thanks Benji fisher, Stefan Roemer...
765 and others in vim@vim.org which spend much time to answer questions,
766 sometimes foolish question asked by someone like me. Without their I can't
767 get the final solution for my sqlplus work descripted follows.
768 As Oracle user known, sqlplus has a very bad
769 command-line edition environment. It has no command-history, don't support
770 most of getline facilities. which MySQL and shell does it well. Even Microsoft
771 recogonize this point. In Windows2000, doskey is installed by default.
772 Below is my vim-solution to sqlplus, which
773 record the command-history when you use edit(sqlplus builtin command) to
774 open the editor specified by EDITOR environment variable. It saves the SQL
775 statement into a standalone file such as .sqlplus.history
776 Every time you open the file
777 afiedt.buf(sqlplus's default command-buffer file), you get two splited windows,
778 the buffer above is afiedt.buf, the buffer below is .sqlplus.history, you
779 can see every SQL statement in the windows. If you want to use SQL statement
780 in line 5 to replace
781 the current command-buffer, just press 5K, then
782 :xa to back to you sqlplus. and use / to repeat the command
783 saved in command-buffer file called afiedt.buf by default.
784 It can't process multi-line SQL statement convinencely.
785 Todo this, just use you favorite vim trick to do that:
786 fu! VimSQL()
787 nnoremap &lt;C-K&gt; :&lt;C-U&gt;
788 exe "let linenum=".v:count&lt;CR&gt;:1,$-1d&lt;CR&gt;&lt;C-W&gt;j:exe
789 lin enum."y"&lt;CR&gt;&lt;C-W&gt;kP
790 let linenum=line("$") 1,$-1w! &gt;&gt; ~/.sqlplus.history e
791 ~/.sqlplus.history execute ":$-".(linenum-1).",$m0" %!uniq if
792 line("$")&gt;100
793 101,$d
794 endif b# set splitbelow sp ~/.sqlplus.history au! BufEnter afiedt.buf
795 endf au BufEnter afiedt.buf call VimSQL()
796
797 </pre></tip> </html> <Tip category="KVim">
798 <html><center>Using marks</center> <pre> <A
799 HREF="http://vim.sf.net/tip_view.php?tip_id=42">http://vim.sf.net/tip_view.php?tip_id=42</A><BR>
800
801 To mark one or more positions in a file, use the m[ark] command.
802
803 Examples:
804
805 ma - set current cursor location as mark a
806
807 'a - jump to beginning of line of mark a
808
809 `a - jump to postition of mark a
810
811 d'a - delete from current line to line of mark a
812
813 d`a - delete from current cursor position to mark a
814
815 c'a - change text from current line to line of mark a
816
817 y`a - yank text to unnamed buffer from cursor to mark a
818
819 :marks - list all the current marks
820
821 NB: Lowercase marks (a-z) are valid within one file. Uppercase marks (A-Z),
822 also called file marks, are valid between files.
823
824 For a detailed description of the m[ark] command refer to
825
826 :help mark
827
828 See also:
829
830 :help various-motions
831
832 </pre></tip> </html> <Tip category="KVim">
833 <html><center>Using abbreviations</center> <pre> <A
834 HREF="http://vim.sf.net/tip_view.php?tip_id=43">http://vim.sf.net/tip_view.php?tip_id=43</A><BR>
835
836 To define abbreviations, use the ab[breviate] command.
837
838 Examples:
839
840 :ab rtfm read the fine manual - Whenever you type 'rtfm' followed by a
841 &lt;space&gt; (or &lt;esc&gt; or &lt;cr&gt;) vim
842 will expand this to 'read the fine manual'.
843
844 :ab - list all defined abbreviations
845
846 :una[bbreviate] rtfm - remove 'rtfm' from the list of abbreviations
847
848 :abc[lear] - remove all abbreviations
849
850 NB: To avoid expansion in insert mode, type CTRL-V after the last character
851 of the abbreviation.
852
853 For a detailed description of the ab[breviate] command and some more examples
854 refer to
855
856 :help abbreviations
857
858 </pre></tip> </html> <Tip category="KVim">
859 <html><center>Repeat last changes</center> <pre> <A
860 HREF="http://vim.sf.net/tip_view.php?tip_id=44">http://vim.sf.net/tip_view.php?tip_id=44</A><BR>
861
862 Simple text changes in normal mode (e.g. "dw" or "J") can be repeated with
863 the "." command. The last command-line change (those invoked with ":",
864 e.g. ":s/foo/bar") can be repeated with the "@:" command.
865
866 For more informations about repeating single changes refer to:
867
868 :help single-repeat
869
870 </pre></tip> </html> <Tip category="KVim">
871 <html><center>Using command-line history</center> <pre> <A
872 HREF="http://vim.sf.net/tip_view.php?tip_id=45">http://vim.sf.net/tip_view.php?tip_id=45</A><BR>
873
874 You can recall previous command lines from a history table by hitting the
875 &lt;Up&gt; and &lt;Down&gt; cursor keys in command-line mode. For example,
876 this can be used to find the previous substitute command: Type ":s" and
877 then &lt;Up&gt;.
878
879 There are separate history tables for the ':' commands and for previous '/'
880 or '?' search strings.
881
882 To display the history of last entered commands or search strings, use the
883 :his[tory] command:
884
885 :his - Display command-line history.
886
887 :his s - Display search string history.
888
889
890 For a detailed description of the command-line history refer to:
891
892 :help cmdline-history
893
894 See also:
895
896 :help Cmdline-mode
897
898 </pre></tip> </html> <Tip category="KVim"> <html><center>Win32
899 binaries with perl, python, and tcl</center> <pre> <A
900 HREF="http://vim.sf.net/tip_view.php?tip_id=46">http://vim.sf.net/tip_view.php?tip_id=46</A><BR>
901
902 &gt; Does anyone know if windows binaries of vim 5.7 are available with perl
903 and &gt; python support turned on?
904
905 <A
906 HREF="ftp://vim.sourceforge.net/pub/vim/upload_binaries/">ftp://vim.sourceforge.net/pub/vim/upload_binaries/</A><BR>
907
908 <A
909 HREF="http://vim.sourceforge.net/bin_download/">http://vim.sourceforge.net/bin_download/</A><BR>
910
911 </pre></tip> </html> <Tip category="KVim"> <html><center>Swapping
912 characters, words and lines</center> <pre> <A
913 HREF="http://vim.sf.net/tip_view.php?tip_id=47">http://vim.sf.net/tip_view.php?tip_id=47</A><BR>
914
915 To swap two characters or lines, use the following commands:
916
917 xp - delete the character under the cursor and put it afterwards.
918 (In other words, it swaps the characters.)
919
920 ddp - delete the current line and put it afterwards.
921 (In other words, it swaps the lines.)
922
923 Unfortunately there is no universal solution to swap two words. You may
924 try the following ones, but don't expect too much of them:
925
926 dawwP - delete the word under the cursor, move forward one word
927 and put it back after the cursor. (In other words, it swaps
928 the current and following word.)
929
930 dawbP - delete the word under the cursor, move backward on word
931 and put it back after the cursor. (In other words, it swaps
932 the current and preceeding word.)
933
934 </pre></tip> </html> <Tip category="KVim">
935 <html><center>Moving around</center> <pre> <A
936 HREF="http://vim.sf.net/tip_view.php?tip_id=48">http://vim.sf.net/tip_view.php?tip_id=48</A><BR>
937
938 You can save a lot of time when navigating through the text by using
939 appropriate movements commands. In most cases the cursor keys, &lt;PageUp&gt;
940 or &lt;PageDown&gt; are NOT the best choice.
941
942 Here is a selection of some basic movement commands that hopefully helps
943 you to acquire a taste for more:
944
945 e - move to the end of a word w - move forward to the beginning of a
946 word 3w - move forward three words b - move backward to the beginning of
947 a word 3b - move backward three words
948
949 $ - move to the end of the line &lt;End&gt; - same as $ 0 -
950 move to the beginning of the line &lt;Home&gt; - same as 0
951
952 ) - jump forward one sentence ( - jump backward one sentence
953
954 } - jump forward one paragraph { - jump backward one paragraph
955
956 H - jump to the top of the display M - jump to the middle of the display
957 L - jump to the bottom of the display
958
959 'm - jump to the beginning of the line of mark m `m - jump to the location
960 of mark m
961
962 G - jump to end of file 1G - jump to beginning of file 50G - jump to line 50
963
964 '' - return to the line where the cursor was before the latest jump `` -
965 return to the cursor position before the latest jump (undo the jump).
966
967 % - jump to corresponding item, e.g. from an open brace to its
968 matching closing brace
969
970 For some more interesting movement commands (especially those for programmers)
971 refer to:
972
973 :help motion.txt
974
975 :help search-commands
976
977 </pre></tip> </html> <Tip category="KVim">
978 <html><center>Switching case of characters</center> <pre> <A
979 HREF="http://vim.sf.net/tip_view.php?tip_id=49">http://vim.sf.net/tip_view.php?tip_id=49</A><BR>
980
981 To switch the case of one or more characters use the "~", "gU" or "gu"
982 commands.
983
984 Examples:
985
986 ~ - switch case of character under cursor
987 (in visual-mode: switch case of highlighted text)
988
989 3~ - switch case of next three characters
990
991 g~~ - switch case of current line
992
993 U - in visual-mode: make highlighted text uppercase
994
995 gUU - make current line uppercase
996
997 u - in visual-mode: make highlighted text lowercase
998
999 guu - make current line lowercase
1000
1001 gUaw - make current word uppercase
1002
1003 guaw - make current word lowercase
1004
1005 For some more examples refer to
1006
1007 :help ~
1008
1009 See also:
1010
1011 :help simple-change
1012
1013 </pre></tip> </html> <Tip category="KVim">
1014 <html><center>Recovering files</center> <pre> <A
1015 HREF="http://vim.sf.net/tip_view.php?tip_id=50">http://vim.sf.net/tip_view.php?tip_id=50</A><BR>
1016
1017 If your computer has crashed while editing a file, you should be able to
1018 recover the file by typing
1019
1020 vi -r &lt;filename&gt;
1021
1022 where &lt;filename&gt; is the name of the file you were editing at the time
1023 of the crash. If you were editing without a file name, give an empty string
1024 as argument:
1025
1026 vim -r ""
1027
1028 To get a list of recoverable files start vim without arguments:
1029
1030 vim -r
1031
1032 For more information about file recovery refer to:
1033
1034 :help recovery
1035
1036 </pre></tip> </html> <Tip category="KVim">
1037 <html><center>Entering german umlauts</center> <pre> <A
1038 HREF="http://vim.sf.net/tip_view.php?tip_id=51">http://vim.sf.net/tip_view.php?tip_id=51</A><BR>
1039
1040 To enter german umlauts (or any other of those weired characters) not
1041 available on your keyboard use 'digraphs':
1042
1043 In insert-mode type for example:
1044
1045 CTRL-K "a
1046
1047 CTRL-K ^e
1048
1049 which gives an 'ä' and 'e' with a hat.
1050
1051 You can also set the digraph option:
1052
1053 :set digraph (or :set dg)
1054
1055 With digraph option set you can enter
1056
1057 " &lt;BS&gt; a
1058
1059 ^ &lt;BS&gt; e
1060
1061 which gives the same result.
1062
1063 To get a list of currently defined digraphs type
1064
1065 :dig[graphs]
1066
1067 For more information about defining and using digraphs refer to:
1068
1069 :help digraph.txt
1070
1071 </pre></tip> </html> <Tip category="KVim">
1072 <html><center>Scrolling synchronously</center> <pre> <A
1073 HREF="http://vim.sf.net/tip_view.php?tip_id=52">http://vim.sf.net/tip_view.php?tip_id=52</A><BR>
1074
1075 If you want to bind two or more windows such that when one window is scrolled,
1076 the other windows are scrolled simultaneously, set the 'scrollbind' option
1077 for these windows:
1078
1079 :set scrollbind
1080
1081 When a window that has 'scrollbind' set is scrolled, all other 'scrollbind'
1082 windows are scrolled the same amount, if possible.
1083
1084 For more information about the 'scrollbind' option refer to
1085
1086 :help scoll-binding
1087
1088 </pre></tip> </html> <Tip category="KVim"> <html><center>Better
1089 colors for syntax highlighting</center> <pre> <A
1090 HREF="http://vim.sf.net/tip_view.php?tip_id=53">http://vim.sf.net/tip_view.php?tip_id=53</A><BR>
1091
1092 For syntax highlighting there are two sets of default color maps: One for a
1093 light and another one for a dark background. If you have a black background,
1094 use the following command to get a better color map for syntax highlighting:
1095
1096 :set background=dark
1097
1098 You have to switch off and on again syntax highlighting to activate the new
1099 color map:
1100
1101 :syntax off :syntax on
1102
1103 For a detailled description of syntax highlighting refer to
1104
1105 :help syntax.txt
1106
1107 See also the Vim syntax support file: $VIMRUNTIME/syntax/synload.vim
1108
1109 </pre></tip> </html> <Tip category="KVim"> <html><center>View
1110 a Java Class File Decompiled thru Vim</center> <pre> <A
1111 HREF="http://vim.sf.net/tip_view.php?tip_id=54">http://vim.sf.net/tip_view.php?tip_id=54</A><BR>
1112
1113 Hi All, Wish u could view a Java Class File using Vim, Well ur query
1114 ends here. First of all u will need a Java Decompiler to decompile the
1115 Class File. I would suggest the JAD decompiler by Pavel Kouznetsov <A
1116 HREF="http://www.geocities.com/SiliconValley/Bridge/8617/jad.html">http://www.geocities.com/SiliconValley/Bridge/8617/jad.html</A><BR>
1117
1118 Its a command line decompiler and absolutely free. U can use any command
1119 line decompiler of ur choice.
1120
1121 Next create a vimscript file called jad.vim as #########################
1122 FILE START ################ augr class au! au bufreadpost,filereadpost
1123 *.class %!d:jad.exe -noctor -ff -i -p % au bufreadpost,filereadpost
1124 *.class set readonly au bufreadpost,filereadpost *.class set ft=java au
1125 bufreadpost,filereadpost *.class normal gg=G au bufreadpost,filereadpost
1126 *.class set nomodified augr END ######################## FILE END
1127 #####################
1128
1129 Note:- Keep the Jad.exe in a directory with out white spaces. The -p options
1130 directs JAD to send the output to standard output instead of a .jad file. Other
1131 options are described on the JAD site.
1132
1133 Next add the following line in the .vimrc file. so jad.vim
1134
1135 Next time u do vim abc.class. Viola u have the source code for abc.class.
1136
1137 NOTE:- I have written the script so as to open the class file read only,
1138 So that u dont accidently modify it. U can also exted this script to unjar
1139 a jar file and then view each file in the JAR file. thanks bhaskar Any
1140 suggestions are welcome
1141
1142 </pre></tip> </html> <Tip category="KVim">
1143 <html><center>previous buffer</center> <pre> <A
1144 HREF="http://vim.sf.net/tip_view.php?tip_id=55">http://vim.sf.net/tip_view.php?tip_id=55</A><BR>
1145
1146 One of the keys to vim is buffer management. If I have to use another IDE
1147 that makes me click on a tab every time I want to look at another file I'm
1148 going to go postal.
1149
1150 So of course you know about :ls which lists all the current open buffers. This
1151 gets a little unweildly once you have a full project open so you can also use
1152 :b &lt;any snipit of text&gt; &lt;tab&gt; to complete to an open buffer. This
1153 is really nice because you can type any fragment of a file name and it will
1154 complete to the matching file. (i.e. RequestManager.java can be completed
1155 using "tma"&lt;tab&gt; or "req"&lt;tab&gt; or "r.java"&lt;tab&gt;).
1156
1157 Now for awhile I was also using :bn and :bp which jumps you to the next
1158 and previous buffer respectively. I found I was often frustrated because I
1159 wanted :bp to be the previous buffer I was in, not the previous buffer in
1160 the list. So (drum roll) the reason I wrote this tip was because of:
1161
1162 :b#
1163
1164 jump to the previous buffer you were in. Very very handy. The only thing
1165 nicer are tag, but that's a tip for another time.
1166
1167 :help buffers :help bn :help bp
1168
1169 If anybody knows where to get help on # in this context please add notes.
1170
1171 </pre></tip> </html> <Tip category="KVim"> <html><center>how
1172 to avoid obliterating window layout</center> <pre> <A
1173 HREF="http://vim.sf.net/tip_view.php?tip_id=58">http://vim.sf.net/tip_view.php?tip_id=58</A><BR>
1174
1175 If you take the time to lay out several windows with vim (especially vertically
1176 in version 6), you may be bummed when you hit an errant key and find that
1177 all but what one window disappears.
1178
1179 What happens: while navigating between windows, you hit &lt;C-W&gt;j,
1180 &lt;C-W&gt;k, etc. At some point you accidently hit &lt;C-W&gt; but then
1181 don't follow with a window command. Now hitting 'o' to start insert mode
1182 issues a command equivalent to :only, and closes all windows execept for
1183 the one you are in (unless some windows have unsaved changes in them).
1184
1185 How to avoid this: petition the vim-dev mailing list about how :only is
1186 sufficient for the infrequenty use this might get (j/k).
1187
1188 Really: use mapping to disable the &lt;C-W&gt;o functionality; put this in
1189 your .vimrc:
1190
1191 nnoremap &lt;C-W&gt;O :echo "sucker"&lt;CR&gt; nnoremap &lt;C-W&gt;o :echo
1192 "sucker"&lt;CR&gt; nnoremap &lt;C-W&gt;&lt;C-O&gt; :echo "sucker"&lt;CR&gt;
1193
1194 references:
1195
1196 :help :only :help CTRL-W_o
1197
1198 That is all. Scott
1199
1200 </pre></tip> </html> <Tip category="KVim"> <html><center>Applying
1201 substitutes to a visual block</center> <pre> <A
1202 HREF="http://vim.sf.net/tip_view.php?tip_id=62">http://vim.sf.net/tip_view.php?tip_id=62</A><BR>
1203
1204 If you'd like to apply a substitute, or even any ex command, to a visual-block
1205 selected text region (ctrl-v and move), then you'll want Stefan Roemer's <A
1206 HREF="http://www.erols.com/astronaut/vim/vimscript/vis.vim . Just source
1207 it in,">http://www.erols.com/astronaut/vim/vimscript/vis.vim . Just source
1208 it in,</A><BR> and then press ":B". On the command line you'll see
1209
1210 :'&lt;,'&gt;BCtrl-V
1211
1212 Just continue with the substitute or whatever...
1213
1214 :'&lt;,'&gt;B s/abc/ABC/g
1215
1216 and the substitute will be applied to just that block of text!
1217
1218 Example: Ctrl-V Select..........|......Type ..................just
1219 the central....|......:B s/abc/ABC/g ..................four
1220 "abc"s..............| ..................----------------....|...-------------
1221 ..................abcabcabcabc............|......abcabcabcabc
1222 ..................abcabcabcabc............|......abcABCABCabc
1223 ..................abcabcabcabc............|......abcABCABCabc
1224 ..................abcabcabcabc............|......abcabcabcabc
1225 (dots inserted to retain tabular format)
1226
1227 </pre></tip> </html> <Tip category="KVim"> <html><center>Applying
1228 substitutes to a visual block</center> <pre> <A
1229 HREF="http://vim.sf.net/tip_view.php?tip_id=63">http://vim.sf.net/tip_view.php?tip_id=63</A><BR>
1230
1231 If you'd like to apply a substitute, or even any ex command, to a visual-block
1232 selected text region (ctrl-v and move), then you'll want Stefan Roemer's <A
1233 HREF="http://www.erols.com/astronaut/vim/vimscript/vis.vim . Just source
1234 it in,">http://www.erols.com/astronaut/vim/vimscript/vis.vim . Just source
1235 it in,</A><BR> and then press ":B". On the command line you'll see
1236
1237 :'&lt;,'&gt;BCtrl-V
1238
1239 Just continue with the substitute or whatever...
1240
1241 :'&lt;,'&gt;B s/abc/ABC/g
1242
1243 and the substitute will be applied to just that block of text!
1244
1245 Example: Ctrl-V Select..........|......Type
1246 ..................just the central.......|......:B
1247 s/abc/ABC/g ..................four "abc"s.................|
1248 ..................---------............|...-------------
1249 ..................abcabcabcabc............|......abcabcabcabc
1250 ..................abcabcabcabc............|......abcABCABCabc
1251 ..................abcabcabcabc............|......abcABCABCabc
1252 ..................abcabcabcabc............|......abcabcabcabc
1253 (dots inserted to retain tabular format)
1254
1255 </pre></tip> </html> <Tip category="KVim"> <html><center>Always set
1256 your working directory to the file you're editing</center> <pre> <A
1257 HREF="http://vim.sf.net/tip_view.php?tip_id=64">http://vim.sf.net/tip_view.php?tip_id=64</A><BR>
1258
1259 Sometimes I think it's helpful if your working directory is always the same
1260 as the buffer you are editing. You need to put this in your .vimrc:
1261
1262 function! CHANGE_CURR_DIR()
1263 let _dir = expand("%:p:h") exec "cd " . _dir unlet _dir
1264 endfunction
1265
1266 autocmd BufEnter * call CHANGE_CURR_DIR()
1267
1268 Doing this will make a "cd" command to your the current buffer each time
1269 you switch to it. This is actually similar to vimtip#2 but more automatic.
1270
1271 You should see for more details: :help autocmd :help expand :help function
1272
1273 Note: This tip was contributed by somebody on the list a while ago (sorry
1274 for no reference) and it has been extremely helpful to me. Thanks!
1275
1276 </pre></tip> </html> <Tip category="KVim"> <html><center>Insert
1277 line number into the actuall text of the file.</center> <pre> <A
1278 HREF="http://vim.sf.net/tip_view.php?tip_id=65">http://vim.sf.net/tip_view.php?tip_id=65</A><BR>
1279
1280 Although :set number will add nice line number for you At time you may wish
1281 to actually place the line numbers into the file. For example on GNU Unix
1282 you can acomplish a simular task using cat -n file &gt; new_file
1283
1284 In VIM you can use the global command to do this
1285
1286 :g/^/exec "s/^/".strpart(line(".")." ", 0, 4)
1287
1288 What this does is run the exec comand on every line that matches /^/ (All)
1289 The exec command taks a string and executes it as if it were typed in.
1290
1291 line(".")." " -&gt; returns the number of the current line plus four spaces.
1292 strpart("123 ", 0, 4) -&gt; returns only the first four characters ("123 ").
1293 "s/^/123 " -&gt; substituts the begining of the line with "123 ".
1294
1295 </pre></tip> </html> <Tip category="KVim"> <html><center>Transfer
1296 text between two Vim 'sessions',</center> <pre> <A
1297 HREF="http://vim.sf.net/tip_view.php?tip_id=66">http://vim.sf.net/tip_view.php?tip_id=66</A><BR>
1298
1299 This one is a one of my favorites from Dr. Chip, and I haven't seen it come
1300 across vim tips yet...
1301
1302 Can use either visual, or marking to denote the text.
1303
1304 " transfer/read and write one block of text between vim sessions " Usage: "
1305 `from' session: " ma " move to end-of-block " xw " " `to' session:
1306 " move to where I want block inserted " xr " if has("unix")
1307 nmap xr :r $HOME/.vimxfer&lt;CR&gt; nmap xw
1308 :'a,.w! $HOME/.vimxfer&lt;CR&gt; vmap xr c&lt;esc&gt;:r
1309 $HOME/.vimxfer&lt;CR&gt; vmap xw :w! $HOME/.vimxfer&lt;CR&gt;
1310 else
1311 nmap xr :r c:/.vimxfer&lt;CR&gt; nmap xw :'a,.w! c:/.vimxfer&lt;CR&gt;
1312 vmap xr c&lt;esc&gt;:r c:/.vimxfer&lt;cr&gt; vmap xw
1313 :w! c:/.vimxfer&lt;CR&gt;
1314 endif
1315
1316 </pre></tip> </html> <Tip category="KVim">
1317 <html><center>Ascii Value</center> <pre> <A
1318 HREF="http://vim.sf.net/tip_view.php?tip_id=67">http://vim.sf.net/tip_view.php?tip_id=67</A><BR>
1319
1320 Sometimes we, the programmers, need the value of a character, don't we?
1321 You can learn the ascii value of a character by pressing g and a keys.(ga)!
1322 It displays the value in dec, hex and octal...
1323
1324 </pre></tip> </html> <Tip category="KVim">
1325 <html><center>Delete key</center> <pre> <A
1326 HREF="http://vim.sf.net/tip_view.php?tip_id=68">http://vim.sf.net/tip_view.php?tip_id=68</A><BR>
1327
1328 Don't worry if your delete key does not work properly. Just press
1329 &lt;CTRL&gt;-Backspace. It works under both mode(insert or normal).
1330
1331 </pre></tip> </html> <Tip category="KVim">
1332 <html><center>dot makes life easier</center> <pre> <A
1333 HREF="http://vim.sf.net/tip_view.php?tip_id=69">http://vim.sf.net/tip_view.php?tip_id=69</A><BR>
1334
1335 You can copy and paste the last changes you made in the last insert mode
1336 without using y and p by pressing . (just dot). Vim memorizes the keys you
1337 pressed and echos them if you hit the dot key. You must be in command mode
1338 as usual. It can be helpful...
1339
1340 </pre></tip> </html> <Tip category="KVim">
1341 <html><center>running a command on all buffers</center> <pre> <A
1342 HREF="http://vim.sf.net/tip_view.php?tip_id=70">http://vim.sf.net/tip_view.php?tip_id=70</A><BR>
1343
1344 From Peter Bismuti on the vim list:
1345
1346 How to global search and replace in all buffers with one command? You need
1347 the AllBuffers command:
1348
1349 :call AllBuffers("%s/string1/string2/g")
1350
1351 "put this in a file and source it function AllBuffers(cmnd)
1352 let cmnd = a:cmnd let i = 1 while (i &lt;= bufnr("$"))
1353 if bufexists(i)
1354 execute "buffer" i execute cmnd
1355 endif let i = i+1
1356 endwhile
1357 endfun
1358
1359 ":call AllBuffers("%s/foo/bar/ge|update")
1360
1361 Thanks Peter!
1362
1363 </pre></tip> </html> <Tip category="KVim"> <html><center>Transfer
1364 text between two gvim sessions using clipboard</center> <pre> <A
1365 HREF="http://vim.sf.net/tip_view.php?tip_id=71">http://vim.sf.net/tip_view.php?tip_id=71</A><BR>
1366
1367 If you use gvim, you can transfer text from one instance of gvim into another
1368 one using clipboard. It is convenient to use * (star) register, like this:
1369
1370 In one instance yank two lines into clipboard:
1371 "*2yy
1372 Paste it in another instance in normal mode:
1373 "*p
1374 or in insert mode:
1375 &lt;Ctrl-R&gt;*
1376
1377 </pre></tip> </html> <Tip category="KVim">
1378 <html><center>Remove unwanted empty lines</center> <pre> <A
1379 HREF="http://vim.sf.net/tip_view.php?tip_id=72">http://vim.sf.net/tip_view.php?tip_id=72</A><BR>
1380
1381 Sometimes to improve the readability of the document I insert empty lines,
1382 which will be later removed. To get rid off them try: :%g/^$/d This will
1383 remove a l l empty line in the document. Some other tipps you can find
1384 under www.linuxclass.de/vim.phtml
1385
1386 </pre></tip> </html> <Tip category="KVim">
1387 <html><center>Using vim as calculator</center> <pre> <A
1388 HREF="http://vim.sf.net/tip_view.php?tip_id=73">http://vim.sf.net/tip_view.php?tip_id=73</A><BR>
1389
1390 Basic calculations can done within vim easily by typing (insert-mode): STRG
1391 (=CTRL) + R followed by = then for example 2+2 and hit RETURN the result 4
1392 will be printed in the document.
1393
1394 Some other tipps you can find under www.linuxclass.de/vim.phtml
1395
1396 </pre></tip> </html> <Tip category="KVim"> <html><center>Using
1397 Vim as an outline processor</center> <pre> <A
1398 HREF="http://vim.sf.net/tip_view.php?tip_id=74">http://vim.sf.net/tip_view.php?tip_id=74</A><BR>
1399
1400 With the addition of folding, Vim6 can function as a high performance outline
1401 processor. Simply :set ai and in insert mode use backspace to promote and
1402 tab to demote headlines.
1403
1404 In command mode, &lt;&lt; promotes (n&lt;&lt; to promote multiple lines),
1405 and &gt;&gt; demotes. Also, highlight several headlines and &lt; or &gt;
1406 to promote or demote.
1407
1408 :set foldmethod=indent, and then your z commands can expand or collapse
1409 headline trees, filewide or by the tree.
1410
1411 The VimOutliner GPL distro contains the scripts and configs to easily
1412 configure Vim6 as an outliner, including scripts to create tag files enabling
1413 interoutline hyperlinking.
1414
1415 The VimOutliner project is at <A
1416 HREF="http://www.troubleshooters.com/projects/vimoutliner/index.htm.">http://www.troubleshooters.com/projects/vimoutliner/index.htm.</A><BR>
1417
1418 Steve (Litt) slitt@troubleshooters.com
1419
1420 </pre></tip> </html> <Tip category="KVim"> <html><center>Remap
1421 CAPSLOCK key in Windows 2000 Professional and NT4.0</center> <pre> <A
1422 HREF="http://vim.sf.net/tip_view.php?tip_id=75">http://vim.sf.net/tip_view.php?tip_id=75</A><BR>
1423
1424 If you're Windows 2000 Professional user and got tired to move your hands off
1425 basic row when hitting &lt;ESC&gt; key here the solution (not for Windows 9x.):
1426 remap CapsLock key as &lt;ESC&gt; key. It's located in useful position. Put
1427 this lines into &lt;EscLock.reg&gt; file and start it in explorer.Reboot.Enjoy.
1428
1429 REGEDIT4 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
1430 "Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00
1431
1432 To restore you capslock back just delete this entry from Registry and reboot.
1433 And below is remapping &lt;capslock&gt; as &lt;Left Control&gt;:
1434
1435 REGEDIT4 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
1436 "Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
1437
1438 </pre></tip> </html> <Tip category="KVim">
1439 <html><center>Folding for Quickfix</center> <pre> <A
1440 HREF="http://vim.sf.net/tip_view.php?tip_id=76">http://vim.sf.net/tip_view.php?tip_id=76</A><BR>
1441
1442 The Quickfix mode aims to "speed up the edit-compile-edit cycle" according to
1443 ':help quickfix'. After executing ':make' or ':grep' it is possible to skim
1444 through the list of errors/matches and the appropriate source code locations
1445 with, for instance, the ':cnext' command. Another way to get a quick overview
1446 is to use VIMs folding mode, to fold away all the error-free/match-free
1447 regions. The script at the end of this message can be used for this
1448 purpose. It is at the moment not elaborate enough to put it up as a 'script';
1449 but it might give someone inspiration to do so. Big restrictions / bugs are
1450 as follows: 1. Vim Perl interface is required, i.e. the output of ':version'
1451 must contain '+perl' (People with Vim scripting knowledge might fix this)
1452 2. Works only for one file, i.e. the current buffer. 3. It's a quick hack.
1453 Sample usage: (a) edit a file, (b) do ':grep regexp %' to get a quickfix
1454 error list and (c) ':source foldqf.vim' will fold as described Increasing
1455 the value of $CONTEXT gives you more context around the error regions.
1456
1457 Here comes it, it should be 7 lines: ---foldqf.vim cwindow perl $CONTEXT = 0;
1458 perl @A = map { m/\|(\d+)\|/; $1 +0 } $curbuf-&gt;Get(1..$curbuf-&gt;Count());
1459 close normal zD perl sub fold { VIM::DoCommand( $_[0] . ',' . ($_[1]) . "fold"
1460 ) if( $_[0] &lt; $_[1] ); } perl $last = 0; for (@A) { fold( $last+1+$CONTEXT,
1461 $_-1-$CONTEXT ); $last = $_; }; VIM::DoCommand(($A[-1]+1+$CONTEXT )
1462 . ',$fold' );
1463
1464 </pre></tip> </html> <Tip category="KVim"> <html><center>Displaying
1465 search results using folds</center> <pre> <A
1466 HREF="http://vim.sf.net/tip_view.php?tip_id=77">http://vim.sf.net/tip_view.php?tip_id=77</A><BR>
1467
1468 A guy I work with told me about a function that an old IBM text editor had
1469 that he said was useful, and that is to create folds in the file after a
1470 search such that every line that is visible contains the search pattern(except
1471 possibly the first). All lines that do not contain the search pattern are
1472 folded up to the last occurence of the pattern or the top of the file.
1473
1474 One use for such a function is to be able to make a quick and dirty api of
1475 a source file. For example, if working in Java, you could run the function
1476 using the pattern "public|protected|private" and ithe results would be that
1477 only the method headers would be visible (well, close enough).
1478
1479 function! Foldsearch(search)
1480 normal zE "erase all folds to begin with normal G$
1481 "move to the end of the file let folded = 0 "flag to set when
1482 a fold is found let flags = "w" "allow wrapping in the search let
1483 line1 = 0 "set marker for beginning of fold while search(a:search,
1484 flags) &gt; 0
1485 let line2 = line(".") "echo "pattern found at line #
1486 " line2 if (line2 -1 &gt; line1)
1487 "echo line1 . ":" . (line2-1) "echo "A fold goes here."
1488 execute ":" . line1 . "," . (line2-1) . "fold"
1489 let folded = 1 "at
1490 least one fold has been found
1491 endif let line1 = line2 "update marker let flags = "W"
1492 "turn off wrapping
1493 endwhile
1494 " Now create the last fold which goes to the end of the file.
1495 normal $G let line2 = line(".")
1496 "echo "end of file found at line # " line2
1497 if (line2 &gt; line1 && folded == 1)
1498 "echo line1 . ":" . line2 "echo "A fold goes here."
1499 execute ":". line1 . "," . line2 . "fold"
1500 endif
1501 endfunction
1502
1503 " Command is executed as ':Fs pattern'" command! -nargs=+ -complete=command
1504 Fs call Foldsearch(&lt;q-args&gt;) " View the methods and variables in a
1505 java source file." command! Japi Fs public\|protected\|private
1506
1507 </pre></tip> </html> <Tip category="KVim">
1508 <html><center>rotating mail signatures</center> <pre> <A
1509 HREF="http://vim.sf.net/tip_view.php?tip_id=78">http://vim.sf.net/tip_view.php?tip_id=78</A><BR>
1510
1511 For people using mutt and vim for mail, the following script will allow
1512 you to insert a new signature (and again and again if you don\'t like the
1513 current one) at the bottom of your mail. This is usefull eg when you don\'t
1514 want to send a potentially offensive quote to someone you don\'t know very
1515 well (or a mailing list), but are too lazy to delete the quote, open your
1516 quotes file, and cut and paste another one in. (I put it here in \'tips\'
1517 and not in \'scripts\' because it is imo too short to be a \'real\' script)
1518
1519 " rotate_sig.vim " Maintainer: Roel Vanhout &lt;roel@2e-systems.com&gt;
1520 " Version: 0.1 " Last Change: Tuesday, June 12, 2001 " Mapping I use:
1521 " nmap ,r :call RotateSig()&lt;CR&gt; " Usage: " -Make sure you delimit
1522 your sig with '-- ', or adjust the script " -Adjust the last execute to a
1523 command that prints a sig to stdout " Known problems: " - You'll get an
1524 error message when you're below the last " '^-- $' in your mail (nothing
1525 bad though - just an not- " found marker)
1526
1527 function! RotateSig()
1528 normal mQG execute '?^-- $' execute ':nohl' normal o&lt;ESC&gt; normal
1529 dG normal &lt;CR&gt; execute 'r !~/bin/autosig ~/.quotes \%' normal `Q
1530 endfunction
1531
1532 </pre></tip> </html> <Tip category="KVim"> <html><center>How to use
1533 :grep to get a clickable list of function names</center> <pre> <A
1534 HREF="http://vim.sf.net/tip_view.php?tip_id=79">http://vim.sf.net/tip_view.php?tip_id=79</A><BR>
1535
1536 The following function will make a :cwindow window with a line per function
1537 in the current C source file. NOTE: It writes the file as a side effect.
1538
1539 Invoke with ':call ShowFunc()' You may want to do :nmap &lt;somekey&gt;
1540 :call ShowFunc()&lt;CR&gt;
1541
1542 function! ShowFunc()
1543
1544 let gf_s = &grepformat let gp_s = &grepprg
1545
1546 let &grepformat = '%*\k%*\sfunction%*\s%l%*\s%f %*\s%m' let &grepprg =
1547 'ctags -x --c-types=f --sort=no -o -'
1548
1549 write silent! grep % cwindow
1550
1551 let &grepformat = gf_s let &grepprg = gp_s
1552
1553 endfunc
1554
1555 </pre></tip> </html> <Tip category="KVim"> <html><center>Restore
1556 cursor to file position in previous editing session</center> <pre> <A
1557 HREF="http://vim.sf.net/tip_view.php?tip_id=80">http://vim.sf.net/tip_view.php?tip_id=80</A><BR>
1558
1559 Here's something for your &lt;.vimrc&gt; which will allow you to restore
1560 your cursor position in a file over several editing sessions. This technique
1561 uses the viminfo option:
1562
1563 Ex. set viminfo='10,\"100,:20,%,n~/.viminfo
1564 au BufReadPost * if line("'\"") &gt; 0|if line("'\"") &lt;=
1565 line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
1566
1567 If you're on Unix, the viminfo is probably fine as is (but check up on Vim's
1568 help for viminfo to see if you like the settings above). For Windows you'll
1569 need to change the "n" suboption to something like
1570
1571 Ex. set viminfo='10,\"100,:20,%,nc:\\some\\place\\under\\Windoz\\_viminfo
1572
1573 This tip is a somewhat improved version of the example given for :he line()
1574 in the Vim on-line documentation.
1575
1576 </pre></tip> </html> <Tip category="KVim">
1577 <html><center>Substitution of characters and lines in VIM is
1578 made far easier with the s and S commands</center> <pre> <A
1579 HREF="http://vim.sf.net/tip_view.php?tip_id=81">http://vim.sf.net/tip_view.php?tip_id=81</A><BR>
1580
1581 Substitute Characters ----------------------------------- I was just editing
1582 a file that contained the same leading string on many lines.
1583
1584 example:
1585
1586 foo_bar_baz1=a foo_bar_baz1=abc674 foo_bar_baz1=qrs foo_bar_baz1=m1
1587 foo_bar_baz1=bz90 foo_bar_baz1=bc ...
1588
1589 Needing to only substitute a portion of the string, I referred to a VIM
1590 reference card and discovered a command answering my need exactly. The s
1591 command is used to subsitute a certain number of characters. In my example
1592 file above, if I only needed to subsititute the characters foo_bar, I set
1593 the cursor on the first character where I'd like the subsitution to begin
1594 and type 7s. VIM drops the characters foo_bar and goes to insert mode,
1595 waiting for the substitution text.
1596
1597 Substitute Lines ----------------------- After years of using vi and VIM and
1598 always deleting multiple lines in order to replace them, I just discovered
1599 the S command. If you need to subsitute three lines of text, simply type
1600 3S. VIM drops the three lines and goes into insert mode, waiting for the
1601 subsitution text.
1602
1603 </pre></tip> </html> <Tip category="KVim"> <html><center>letting
1604 variable values be overwritten in a script</center> <pre> <A
1605 HREF="http://vim.sf.net/tip_view.php?tip_id=82">http://vim.sf.net/tip_view.php?tip_id=82</A><BR>
1606
1607 this is a simple function i wrote to get the value of a variable from three
1608 different places (in that order): the current buffer, the global setting
1609 or from the script itself.
1610
1611 this allows me to set a default value for a configuration variable inside my
1612 script and the user to change it on a global level by setting the same variable
1613 with a g: prepended. then, they can further set it on a per-buffer level by
1614 the the b: mechanism. one of the examples for this might be my comments script
1615 (not uploaded). i have a variable in there that determines whether comment
1616 characters (// for java, for example) are placed the beginning of the line or
1617 just before the first-non-blanks in the text. i set up a default in my script:
1618
1619 let s:comments_hug_start_of_line=0 " comments should hug the text
1620
1621 that's fine as a default, but if i want to overwrite it for vim scripts,
1622 i just put the following in my ftplugin/vim.vim:
1623
1624 let b:comments_hug_start_of_line=1 " vim comments should hug the first
1625 column, always
1626
1627 " tries to return the buffer-specific value of a variable; if not
1628 " found, tries to return the global value -- if that's not found "
1629 either, returns the value set in the script itself function! GetVar(varName)
1630 if (exists ("b:" . a:varName))
1631 exe "let retVal=b:" . a:varName
1632 elseif (exists ("g:" . a:varName))
1633 exe "let retVal=g:" . a:varName
1634 elseif (exists ("s:" . a:varName))
1635 exe "let retVal=s:" . a:varName
1636 else
1637 retVal=-1
1638 endif return retVal
1639 endfunction
1640
1641 personally, i never let it get to the -1 state by always having an s: set
1642 with SOME default value.
1643
1644 </pre></tip> </html> <Tip category="KVim"> <html><center>how
1645 to indent (useful for source code)</center> <pre> <A
1646 HREF="http://vim.sf.net/tip_view.php?tip_id=83">http://vim.sf.net/tip_view.php?tip_id=83</A><BR>
1647
1648 Here is the most useful vim command that I know of and I'm surprised that
1649 it's not yet in the tips list.
1650
1651 I use the indent features of vim all the time. Basically, it lets you indent
1652 your source code.
1653
1654 SETUP: To make indentation work nicely I have the following in my .vimrc file:
1655 set et set sw=4 set smarttab
1656
1657 these make vim behave nicely when indenting, giving 4 spaces (not tabs)
1658 for each "tabstop".
1659
1660 HOW TO USE: in command mode, == will indent the current line selecting a range
1661 of lines (with shift-v) then == will indent your selection typing a number
1662 then == will indent that many lines, starting from your cursor (you get the
1663 idea, there are many other things you can do to select a range of lines)
1664
1665 Tell me that isn't great?
1666
1667 </pre></tip> </html> <Tip category="KVim"> <html><center>Changing
1668 the behaviour of . to include visual mode</center> <pre> <A
1669 HREF="http://vim.sf.net/tip_view.php?tip_id=84">http://vim.sf.net/tip_view.php?tip_id=84</A><BR>
1670
1671 one of the things i do a lot in vim is to make a change to the beginning or
1672 end of the line (such as adding the text '// remove' at the end of java
1673 debug code). a quick way of doing this is to use a to append the text to
1674 the end of the first line and then move down one, hit . (repeat last edit),
1675 move down, hit . etc. etc. the following mapping allows one to simply
1676 highlight the region in question and hit . -- it will automatically
1677 execute the . once on each line:
1678
1679 " allow the . to execute once for each line of a visual selection vnoremap
1680 . :normal .&lt;CR&gt;
1681
1682 another thing i do a lot is to record a quick macro in the "a" register
1683 and then play it back a number of times. while @@ can be used to repeat the
1684 last register used, my recorded macros sometimes use other registers so @@
1685 doesn't necessarily give me the same results as @a. also, i have mapped '
1686 to ` because i like to go to the precise location of my marks -- always --
1687 and never to the beginning of the line. this leaves my ` key unused. so:
1688
1689 " make ` execute the contents of the a register nnoremap ` @a
1690
1691 then, in keeping with the visual . above, i did the same for the ` -- is
1692 thexecutes @a once on each highlighed line.
1693
1694 vnoremap ` :normal @a&lt;CR&gt;
1695
1696 as an example, say i have the following lines of java code:
1697
1698 public String m_asdf; public String m_lkhj; public int m_hjkhjkh;
1699
1700 and, for some reason, i need to get the following:
1701
1702 "asdf" "lkhj" "hjkhjkh"
1703
1704 i record the following into a:
1705
1706 ^cf_"&lt;ESC&gt;$r"
1707
1708 the ^ is because my java code is indented and i don't want to go to
1709 column 0 and the &lt;esc&gt; is an actual escape i hit to exit insert mode.
1710
1711 then, i simply select (visually) the other lines (only two in case --
1712 admittedly not an overly useful example) and just hit `.
1713
1714 </pre></tip> </html> <Tip category="KVim"> <html><center>How to mimic
1715 the vim 6.0 plugin feature with older versions</center> <pre> <A
1716 HREF="http://vim.sf.net/tip_view.php?tip_id=85">http://vim.sf.net/tip_view.php?tip_id=85</A><BR>
1717
1718 If you do not have vim 6.0, but would like to mimic the plugins directory
1719 feature then copy and paste this into your vimrc:
1720
1721 exec "source " . substitute(glob($VIM."/plugins/*.vim"), "\n", "\nsource ",
1722 "g")
1723
1724 It will automatically source every vim script file located in the vim/plugins
1725 directory. Now, to add a new plugin, just drop the script in this directory
1726 and vim will automatically find it.
1727
1728 </pre></tip> </html> <Tip category="KVim"> <html><center>Helps
1729 undo 1 line when entered many</center> <pre> <A
1730 HREF="http://vim.sf.net/tip_view.php?tip_id=86">http://vim.sf.net/tip_view.php?tip_id=86</A><BR>
1731
1732 When U entered text, U cannot undo only 1 line, for example, when U press
1733 "u", all entered in last "insert" text removed.
1734
1735 If U add this line to .vimrc: inoremap &lt;Return&gt; &lt;Return&gt;^O^[
1736 where "^O" or "^[" is 1 char "u" will undo (remove) only 1 line.
1737
1738 </pre></tip> </html> <Tip category="KVim"> <html><center>Get
1739 vim 5.x window in vim 6.x</center> <pre> <A
1740 HREF="http://vim.sf.net/tip_view.php?tip_id=87">http://vim.sf.net/tip_view.php?tip_id=87</A><BR>
1741
1742 The format of the window title in vim 5.x (well, at least for 5.7,.8, for
1743 Win32) used to be VIM - &lt;full filename with path&gt;. It's not in the
1744 win32 binary of 6.0an that I found. I want my old way back.
1745
1746 Turns out, all that it takes to get it back is :set title titlestring=VIM\
1747 -\ %F "make sure that the window caption setting is turned on and set caption
1748 to vim 5.x style
1749
1750 Oh, however, one thing I did like about the 6.0 style is that it puts the
1751 word "help" in the title when the current buffer is a help file; so, I just
1752 tacked %h to my titlestring giving:
1753
1754 :set title titlestring=VIM\ -\ %F\ %h "make sure that the window caption
1755 setting is turned on and set caption to vim 5.x style
1756
1757 see also: :he 'titlestring' :he 'statusline' "for the format for titlestring
1758
1759 </pre></tip> </html> <Tip category="KVim"> <html><center>How
1760 to maximize vim on entry (win32)</center> <pre> <A
1761 HREF="http://vim.sf.net/tip_view.php?tip_id=88">http://vim.sf.net/tip_view.php?tip_id=88</A><BR>
1762
1763 Maybe it's just because I have far too small of a monitor, because I can
1764 get distracted while coding if I have other stuff on the screen, or because I
1765 starting using vim on a console, but I definitely like my vim window maximized.
1766 Anyway, sticking the following in your vimrc will always maximize your vim
1767 window on startup.
1768
1769 au GUIEnter * simalt ~x
1770
1771 :he win16-maximized
1772
1773 </pre></tip> </html> <Tip category="KVim"> <html><center>Get more
1774 screen real estate by hidding toolbar and/or menus</center> <pre> <A
1775 HREF="http://vim.sf.net/tip_view.php?tip_id=89">http://vim.sf.net/tip_view.php?tip_id=89</A><BR>
1776
1777 I use gvim over console vim because gvim is much more readable (under Windows).
1778 However, that doesn't mean I want to dedicate screen space to things I'll
1779 never use (i.e. the toolbar and the menus).
1780
1781 Anyway, you can give the following a try if you'd like.
1782
1783 set guioptions-=T "get rid of toolbar set guioptions-=m "get rid of menu
1784
1785 Oh, yeah. If you decide that you don't really like being without your the
1786 toolbar or menus, issue the following:
1787
1788 set guioptions+=T "bring back toolbar set guioptions+=m "bring back menu
1789
1790 see also: :he 'guioptions
1791
1792 </pre></tip> </html> <Tip category="KVim">
1793 <html><center>Encryption</center> <pre> <A
1794 HREF="http://vim.sf.net/tip_view.php?tip_id=90">http://vim.sf.net/tip_view.php?tip_id=90</A><BR>
1795
1796 You can encrypt your texts by using vim. :X prompts for an encryption key.
1797 After writing your key, if you save your document it will be encrypted
1798 and no one else (but you and vim) can read your documents. If you reopen
1799 the file, VIM will ask for the key. If you want to disable encryption,
1800 just type :set key= if you forget your key you will lose your document.
1801 So please DO NOT forget your key,
1802
1803
1804 </pre></tip> </html> <Tip category="KVim">
1805 <html><center>Dictionary completions</center> <pre> <A
1806 HREF="http://vim.sf.net/tip_view.php?tip_id=91">http://vim.sf.net/tip_view.php?tip_id=91</A><BR>
1807
1808 This tip will will explain how to use the dictionary completion facilities
1809 provided by vim. This can be useful if you use vim to type your email,
1810 edit code, etc.
1811
1812 Dictionary completion is one of many search facilites provided by Insert mode
1813 completion. It allows the user to get a list of keywords, based off of the
1814 current word at the cursor. This is useful if you are typing a long word
1815 (e.g. acknowledgeable) and don't want to finish typing or don't remember
1816 the spelling.
1817
1818 To start, we must first tell vim where our dictionary is located. This is done
1819 via the 'dictionary' option. Below is an example. Your location may vary.
1820 See :help 'dictionary' for hints as to where you should look.
1821
1822 :set dictionary-=/usr/share/dict/words
1823 dictionary+=/usr/share/dict/words
1824
1825 Now, to use this list we have to enter insert mode completion. This is done
1826 by hitting CTRL-X while in insert mode. Next, you have to specify what you
1827 want to complete. For dictionaries use CTRL-K. Once in this mode the keys
1828 CTRL-N and CTRL-P will cycle through the matches. So, to complete the word
1829 "acknowledgeable" I would do the following in insert mode:
1830
1831 acknow&lt;CTRL-X&gt;&lt;CTRL-K&gt;&lt;CTRL-N&gt;
1832
1833 It can be cumbersome to type CTRL-X CTRL-K for many different completions.
1834 So, vim gives us a shortcut. While in insert mode CTRL-N and CTRL-P
1835 will cycle through a predetermined set of completion sources. By default,
1836 dictionary completion is not a part of this set. This set is defined by the
1837 'complete' option. Therefore, we must add dictionary to this as shown below:
1838
1839 :set complete-=k complete+=k
1840
1841 Now, while in insert mode we can type the following to complete our example:
1842
1843 acknow&lt;CTRL-N&gt;&lt;CTRL-N&gt;
1844
1845 This shortcut may not save a whole lot of typing. However, I find that it
1846 requires less hand movement to only worry myself with two key combinations,
1847 rather than 4.
1848
1849 I find that the completion facilites provided by vim save me a *HUGE* amount
1850 of typing. These savings can be realized in only a short amount of time if
1851 you are editing some code with functions and variables that have long names
1852 with underscores in them.
1853
1854 For more help:
1855 help ins-completion help compl-dictionary help 'complete' help
1856 'dictionary' help :set+=
1857
1858 </pre></tip> </html> <Tip category="KVim">
1859 <html><center>Reducing 'doc' directory size</center> <pre> <A
1860 HREF="http://vim.sf.net/tip_view.php?tip_id=92">http://vim.sf.net/tip_view.php?tip_id=92</A><BR>
1861
1862 As everyone knows, the $VIMRUNTIME/doc is increasing rapidly in size. The
1863 directory contained so many plain-text documents that I often compress
1864 them to save my diskspace. With the support of VIM's GZIP plugin,
1865 VIM will automatically uncompress the files when we need to read them.
1866 Here is my procedure: 1. If you have the source, go to 'runtime/doc'
1867 and edit 'doctags.c', change printf("%s\t%s\t/*", p1, argv[0]); to
1868 printf("%s\t%s.gz\t/*", p1, argv[0]);
1869 then make. This is to modify the tag, or you'll have to change the
1870 'tags' file by hand if you don't have doctags.c.
1871 2. Edit the new generated 'tags' file to rename 'help.txt.gz' back to
1872 'help.txt' because it's hard-written in VIM executable binary.
1873 :% s/help\.txt\.gz/help\.txt/g
1874 3. Copy the new 'tags' to $VIMRNUTIME/doc and run 'gzip *.txt; gunzip help.txt'
1875
1876 On VIM 6.0an, we can reduce the original size (3302k) to 1326k. I don't
1877 know if this helps, but if someone likes to compress documents... this can
1878 be reffered :)
1879
1880
1881 </pre></tip> </html> <Tip category="KVim"> <html><center>if you use
1882 'highlight search' feature, map a key to :noh</center> <pre> <A
1883 HREF="http://vim.sf.net/tip_view.php?tip_id=93">http://vim.sf.net/tip_view.php?tip_id=93</A><BR>
1884
1885 It is very convenient to use 'hlsearch' option. However it can be annoying
1886 to have the highlight stick longer than you want it. In order to run it
1887 off you have to type at least 4 keystrokes, ":noh". So, it's a good idea
1888 to map this to a key. I like to map it to control-n. This is the line I
1889 use in my .vimrc file to do it:
1890
1891 nmap &lt;silent&gt; &lt;C-N&gt; :silent noh&lt;CR&gt;
1892
1893 </pre></tip> </html> <Tip category="KVim"> <html><center>Questions
1894 & Answers about using tags with Vim</center> <pre> <A
1895 HREF="http://vim.sf.net/tip_view.php?tip_id=94">http://vim.sf.net/tip_view.php?tip_id=94</A><BR>
1896
1897 Using tags file with Vim ------------------------ This document gives you
1898 a idea about the various facilities available in Vim for using a tags file
1899 to browse through program source files. You can read the Vim online help,
1900 which explains in detail the tags support, using :help tagsearch.txt. You can
1901 also use the help keywords mentioned in this document to read more about a
1902 particular command or option. To read more about a particular command or
1903 option use, :help &lt;helpkeyword&gt; in Vim.
1904
1905 1. How do I create a tags file?
1906
1907 You can create a tags file either using the ctags utility or using a
1908 custom script or utility.
1909
1910 Help keyword(s): tag
1911
1912 2. Where can I download the tools to generate the tags file?
1913
1914 There are several utilities available to generate the tags file.
1915 Depending on the programming language, you can use any one of them.
1916
1917 1. Exuberant ctags generates tags for the following programming
1918 language files:
1919
1920 Assembler, AWK, ASP, BETA, Bourne/Korn/Zsh Shell, C, C++, COBOL,
1921 Eiffel, Fortran, Java, Lisp, Make, Pascal, Perl, PHP, Python, REXX,
1922 Ruby, S-Lang, Scheme, Tcl, and Vim.
1923
1924 You can download exuberant ctags from <A
1925 HREF="http://ctags.sourceforge.net/">http://ctags.sourceforge.net/</A><BR>
1926
1927 2. On Unix, you can use the /usr/bin/ctags utility. This utility
1928 is present in most of the Unix installations.
1929
1930 3. You can use jtags for generating tags file for java programs.
1931 You can download jtags from: <A
1932 HREF="http://www.fleiner.com/jtags/">http://www.fleiner.com/jtags/</A><BR>
1933
1934 4. You can use ptags for generating tags file for perl programs.
1935 You can download ptags from: <A
1936 HREF="http://www.eleves.ens.fr:8080/home/nthiery/Tags/">http://www.eleves.ens.fr:8080/home/nthiery/Tags/</A><BR>
1937
1938 5. You can download scripts from the following links for
1939 generating tags file for verilog files:
1940
1941 <A
1942 HREF="http://www.probo.com/vtags.htm">http://www.probo.com/vtags.htm</A><BR>
1943 <A
1944 HREF="http://www.cs.albany.edu/~mosh/Perl/veri-tags">http://www.cs.albany.edu/~mosh/Perl/veri-tags</A><BR>
1945 <A
1946 HREF="http://www.verilog.net/vrtags.txt">http://www.verilog.net/vrtags.txt</A><BR>
1947
1948 6. You can download Hdrtag from the following linke:
1949
1950 <A
1951 HREF="http://www.erols.com/astronaut/vim/index.html#Tags">http://www.erols.com/astronaut/vim/index.html#Tags</A><BR>
1952
1953 This utility generates tags file for the following programming languages:
1954 assembly, c/c++, header files, lex, yacc,LaTeX, vim, and Maple V.
1955
1956 7. You can also use the following scripts which are part of the Vim
1957 runtime files:
1958
1959 pltags.pl - Create tags file for perl code tcltags - Create tags
1960 file for TCL code shtags.pl - Create tags file for shell script
1961
1962 Help keyword(s): ctags
1963
1964 3. How do I generate a tags file using ctags?
1965
1966 You can generate a tags file for all the C files in the current directory
1967 using the following command:
1968
1969 $ ctags *.c
1970
1971 You can generate tags file for all the files in the current directory
1972 and all the sub-directories using (this applies only to exuberant ctags):
1973
1974 $ ctags -R .
1975
1976 You can generate tags file for all the files listed in a text file named
1977 flist using (this applies only to exuberant ctags)
1978
1979 $ ctags -L flist
1980
1981 4. How do I configure Vim to locate a tags file?
1982
1983 You can set the 'tags' option in Vim to specify a particular tags file.
1984
1985 set tags=/my/dir/tags
1986
1987 Help keyword(s): 'tags', tags-option
1988
1989 5. How do I configure Vim to use multiple tags files?
1990
1991 The 'tags' option can specify more than one tags file. The tag filenames
1992 are separated using either comma or spaces.
1993
1994 set tags=/my/dir1/tags, /my/dir2/tags
1995
1996 6. How do I configure Vim to locate a tags file in a directory tree?
1997
1998 Note that the following will work only in Vim 6.0 and above. You can set
1999 the 'tags' option to make Vim search for the tags file in a directory tree.
2000 For example, if the 'tags' option is set like this:
2001
2002 set tags=tags;/
2003
2004 Vim will search for the file named 'tags', starting with the current
2005 directory and then going to the parent directory and then recursively to
2006 the directory one level above, till it either locates the 'tags' file or
2007 reaches the root '/' directory.
2008
2009 Help keyword(s): file-searching
2010
2011 7. How do I jump to a tag?
2012
2013 There are several ways to jump to a tag location.
2014 1. You can use the 'tag' ex command. For example,
2015
2016 :tag &lt;tagname&gt;
2017
2018 will jump to the tag named &lt;tagname&gt;.
2019 2. You can position the cursor over a tag name and then press
2020 Ctrl-].
2021 3. You can visually select a text and then press Ctrl-] to
2022 jump to the tag matching the selected text.
2023 4. You can click on the tag name using the left mouse button,
2024 while pressing the &lt;Ctrl&gt; key.
2025 5. You can press the g key and then click on the tag name
2026 using the left mouse button.
2027 6. You can use the 'stag' ex command, to open the tag in a new
2028 window. For example,
2029
2030 :stag func1
2031
2032 will open the func1 definition in a new window.
2033 7. You can position the cursor over a tag name and then press
2034 Ctrl-W ]. This will open the tag location in a new window.
2035
2036 Help keyword(s): :tag, Ctrl-], v_CTRL_], &lt;C-LeftMouse&gt;,
2037 g&lt;LeftMouse&gt;, :stag, Ctrl-W_]
2038
2039 8. How do I come back from a tag jump?
2040
2041 There are several ways to come back to the old location from a tag jump.
2042 1. You can use the 'pop' ex command. 2. You can press Ctrl-t.
2043 3. You can click the right mouse button, while pressing the
2044 &lt;Ctrl&gt; key.
2045 4. You can press the g key and then click the right mouse
2046 button.
2047
2048 Help keyword(s): :pop, Ctrl-T, &lt;C-RightMouse&gt;, g&lt;RightMouse&gt;
2049
2050 9. How do I jump again to a previously jumped tag location?
2051
2052 You can use the 'tag' ex command to jump to a previously jumped tag
2053 location, which is stored in the tag stack.
2054
2055 Help keyword(s): tag
2056
2057 10. How do I list the contents of the tag stack?
2058
2059 Vim remembers the location from which you jumped to a tag in the tag stack.
2060 You can list the current tag stack using the 'tags' ex command.
2061
2062 Help keyword(s): :tags, tagstack
2063
2064 11. How do I jump to a particular tag match, if there are multiple
2065 matching tags?
2066
2067 In some situations, there can be more than one match for a tag.
2068 For example, a C function or definition may be present in more than one
2069 file in a source tree. There are several ways to jump to a specific
2070 tag from a list of matching tags.
2071
2072 1. You can use the 'tselect' ex command to list all the tag
2073 matches. For example,
2074
2075 :tselect func1
2076
2077 will list all the locations where func1 is defined. You can then
2078 enter the number of a tag match to jump to that location.
2079 2. You can position the cursor over the tag name and press g]
2080 to get a list of matching tags.
2081 3. You can visually select a text and press g] to get a list
2082 of matching tags.
2083 4. You can use the 'stselect' ex command. This will open the
2084 selected tag from the tag list in a new window.
2085 5. You can position the cursor over the tag name and press
2086 Ctrl-W g] to do a :stselect.
2087
2088 Help keyword(s): tag-matchlist, :tselect, g], v_g], :stselect,
2089 Ctrl-W_g]
2090
2091 12. I want to jump to a tag, if there is only one matching tag,
2092 otherwise a list of matching tags should be displayed. How do I do this?
2093
2094 There are several ways to make Vim to jump to a tag directly, if there
2095 is only one tag match, otherwise present a list of tag matches.
2096
2097 1. You can use the 'tjump' ex command. For example,
2098
2099 :tjump func1
2100
2101 will jump to the definition func1, if it is defined only once.
2102 If func1 is defined multiple times, a list of matching tags will
2103 be presented.
2104 2. You can position the cursor over the tag and press g
2105 Ctrl-].
2106 3. You can visually select a text and press g Ctrl-] to jump
2107 or list the matching tags.
2108 4. You can use the 'stjump' ex command. This will open the
2109 matching or selected tag from the tag list in a new window.
2110 5. You can press Ctrl-W g Ctrl-] to do a :stjump.
2111
2112 Help keyword(s): :tjump, g_Ctrl-], v_g_CTRL-], :stjump,
2113 Ctrl-W_g_Ctrl-]
2114
2115 13. How do browse through a list of multiple tag matches?
2116
2117 If there are multiple tag matches, you can browse through all of them
2118 using several of the Vim ex commands.
2119
2120 1. To go to the first tag in the list, use the 'tfirst' or
2121 'trewind' ex command.
2122 2. To go to the last tag in the list, use the 'tlast' ex command.
2123 3. To go to the next matching tag in the list, use the 'tnext' ex
2124 command.
2125 4. To go to the previous matching tag in the list, use the
2126 'tprevious' or 'tNext' ex command.
2127
2128 Help keyword(s): :tfirst, :trewind, :tlast, :tnext, :tprevious,
2129 :tNext
2130
2131 14. How do I preview a tag?
2132
2133 You can use the preview window to preview a tag, without leaving the
2134 original window. There are several ways to preview a tag:
2135
2136 1. You can use the 'ptag' ex command to open a tag in the
2137 preview window.
2138 2. You can position the cursor on a tag name and press Ctrl-W
2139 } to open the tag in the preview window.
2140 3. You can use the 'ptselect' ex command to do the equivalent
2141 of the 'tselect' ex command in the preview window.
2142 4. You can use the 'ptjump' ex command to do the equivalent of
2143 the 'tjump' ex command in the preview window.
2144 5. You can position the cursor on the tag and press Ctrl-W g}
2145 to do a :ptjump on the tag.
2146
2147 Help keyword(s): :preview-window, :ptag, Ctrl-W_}, :ptselect,
2148 :ptjump, Ctrl-W_g}
2149
2150 15. How do I browse through the tag list in a preview window?
2151
2152 If there are multiple tag matches, you can browse through all of them
2153 in the preview window using several of the Vim ex commands.
2154
2155 1. To go to the first tag in the list, use the 'ptfirst' or
2156 'ptrewind' ex command.
2157 2. To go to the last tag in the list, use the 'ptlast' ex command.
2158 3. To go to the next matching tag in the list, use the 'ptnext' ex
2159 command.
2160 4. To go to the previous matching tag in the list, use the
2161 'ptprevious' or 'ptNext' ex command.
2162
2163 Help keyword(s): :ptfirst, :ptrewind, :ptlast, :ptnext,
2164 :ptprevious, :ptNext
2165
2166 16. How do I start Vim to start editing a file at a given tag match?
2167
2168 While starting Vim, you can use the command line option '-t' to supply
2169 a tag name. Vim will directly jump to the supplied tag location.
2170
2171 Help keyword(s): -t
2172
2173 17. How do I list all the tags matching a search pattern?
2174
2175 There are several ways to go through a list of all tags matching a pattern.
2176
2177 1. You can list all the tags matching a particular regular
2178 expression pattern by prepending the tag name with the '/'
2179 search character. For example,
2180
2181 :tag /&lt;pattern&gt; :stag /&lt;pattern&gt; :ptag
2182 /&lt;pattern&gt; :tselect /&lt;pattern&gt; :tjump
2183 /&lt;pattern&gt; :ptselect /&lt;pattern&gt; :ptjump
2184 /&lt;pattern&gt;
2185
2186 2. If you have the 'wildmenu' option set, then you can press
2187 the &lt;Tab&gt; key to display a list of all the matching tags
2188 in the status bar. You can use the arrow keys to move between
2189 the tags and then use the &lt;Enter&gt; key to select a tag.
2190
2191 3. If you don't have the 'wildmenu' option set, you can still
2192 use the &lt;Tab&gt; key to browse through the list of matching
2193 tags.
2194
2195 Help keyword(s): tag-regexp, wildmenu
2196
2197 18. What options are available to control how Vim handles the tags
2198 file?
2199
2200 You can use the following options to control the handling of tags file
2201 by Vim:
2202
2203 1. 'tagrelative' - Controls how the file names in the tags file
2204 are treated. When on, the filenames are relative to
2205 the directory where the tags file is present.
2206
2207 2. 'taglength' - Controls the number of significant characters
2208 used for recognizing a tag.
2209
2210 3. 'tagbsearch' - Controls the method used to search the tags file
2211 for a tag. If this option is on, binary search is
2212 used to search the tags file. Otherwise, linear search
2213 is used.
2214
2215 4. 'tagstack' - Controls how the tag stack is used.
2216
2217 Help keyword(s): 'tagrelative', 'taglength', 'tagbsearch',
2218 'tagstack'
2219
2220 19. Is it possible to highlight all the tags in the current file?
2221
2222 Yes. Read the Vim online help on "tag-highlight".
2223
2224 20. Is it possible to create a menu with all the tags in the current
2225 file?
2226
2227 Yes. It is possible to create a menu with all the tags in the current
2228 file using a Vim script. Download the TagsMenu.vim script from the
2229 following link:
2230
2231 <A
2232 HREF="http://members.home.net/jayglanville/tagsmenu/TagsMenu.html">http://members.home.net/jayglanville/tagsmenu/TagsMenu.html</A><BR>
2233
2234 21. Is there a workaround to make the Ctrl-] key not to be treated as
2235 the telnet escape character?
2236
2237 The default escape characters for telnet in Unix systems is Ctrl-].
2238 While using Vim in a telnet session, if you use Ctrl-] to jump to a tag,
2239 you will get the telnet prompt. There are two ways to avoid this problem:
2240
2241 1. Map the telnet escape character to some other character using
2242 the "-e &lt;escape character&gt;" telnet command line option
2243
2244 2. Disable the telnet escape character using the "-E" telnet
2245 command line option.
2246
2247 Help keyword(s): telnet-CTRL-]
2248
2249 </pre></tip> </html> <Tip category="KVim"> <html><center>How do I pipe
2250 the output from ex commands into the text buffer?</center> <pre> <A
2251 HREF="http://vim.sf.net/tip_view.php?tip_id=95">http://vim.sf.net/tip_view.php?tip_id=95</A><BR>
2252
2253 This is a *request* for a tip. I need to be able to pipe the output of a
2254 :blah ex command into the vim text buffer for editing. I wanted to do this
2255 many times for different reasons and could never find a way!
2256
2257 I would just love to be able to do :hi --&gt; textBuffer and examine the output
2258 at my own leasure scrolling up and down and using vim search commands on it.
2259 Same thing for :set all, and other things. Considering that cut and paste
2260 is horrible in windows, I can't for example do :set guioptions? then cut
2261 and paste! So I have to retype it, or cut and paste from the help manual.
2262 I really want to be able to pipe the output of ex commands into the text
2263 buffer. Can someone help me?
2264
2265 </pre></tip> </html> <Tip category="KVim"> <html><center>Cooperation
2266 of Gvim and AutoCad [MTEXT]</center> <pre> <A
2267 HREF="http://vim.sf.net/tip_view.php?tip_id=96">http://vim.sf.net/tip_view.php?tip_id=96</A><BR>
2268
2269 You can - like me :o) - use gvim, like replacement of internal AutoCad
2270 MTEXT editor. You need switch variable MTEXTED to "gvim" (or maybe fullpath,
2271 something like "c:\vim\vim60aq\gvim" ), and to your _vimrc you can put line:
2272
2273 autocmd BufRead,BufNewFile *.tmp source c:\vim\aacad.vim
2274
2275 And when you edit MTEXT in acad, menu AutoCad will be for your use in gvim
2276 (only in INSERT and VISUAL mode)
2277
2278 [NOTE: Only I can't start gvim like gvim -y (for any other person, not so
2279 accustomed vith gvim) or start gvim from gvim.lnk or gvim.bat (I'am using
2280 windows95) and automatic skip to INSERT mode -latest word star, on end of
2281 script- is without functionality(?) Maybe someone advise me?? ]
2282
2283 Well, script aacad.vim is listed here:
2284
2285 "VIM menu for AutoCad's MTEXT editation "brz;
2286 mailto:brz@centrum.cz; 8. 8. 2001 " Version Mk.I
2287 "--------------------------------------------------------------------------
2288
2289 imenu &AutoCad.Insert.Space \~ vmenu &AutoCad.Insert.Space
2290 &lt;Esc&gt;`&lt;i\~&lt;Esc&gt;% imenu &AutoCad.Insert.Backslash \\
2291 vmenu &AutoCad.Insert.Backslash &lt;Esc&gt;`&lt;i\\&lt;Esc&gt;% imenu
2292 &AutoCad.Insert.Brackets \{\}&lt;Esc&gt;F\i vmenu &AutoCad.Insert.Brackets
2293 &lt;Esc&gt;`&gt;a\}&lt;Esc&gt;`&lt;i\{&lt;Esc&gt;% imenu
2294 &AutoCad.Insert.Paragraph \P vmenu &AutoCad.Insert.Paragraph
2295 &lt;Esc&gt;`&gt;a\P&lt;Esc&gt;%
2296
2297 imenu &AutoCad.-SEP1- :
2298
2299 imenu &AutoCad.Colour.Red \C1; vmenu &AutoCad.Colour.Red
2300 &lt;Esc&gt;`&gt;a\C7;&lt;Esc&gt;`&lt;i\C1;&lt;Esc&gt;% imenu
2301 &AutoCad.Colour.Yellow \C2; vmenu &AutoCad.Colour.Yellow
2302 &lt;Esc&gt;`&gt;a\C7;&lt;Esc&gt;`&lt;i\C2;&lt;Esc&gt;% imenu
2303 &AutoCad.Colour.Green \C3; vmenu &AutoCad.Colour.Green
2304 &lt;Esc&gt;`&gt;a\C7;&lt;Esc&gt;`&lt;i\C3;&lt;Esc&gt;%
2305 imenu &AutoCad.Colour.Cyan \C4; vmenu &AutoCad.Colour.Cyan
2306 &lt;Esc&gt;`&gt;a\C7;&lt;Esc&gt;`&lt;i\C4;&lt;Esc&gt;%
2307 imenu &AutoCad.Colour.Blue \C5; vmenu &AutoCad.Colour.Blue
2308 &lt;Esc&gt;`&gt;a\C7;&lt;Esc&gt;`&lt;i\C5;&lt;Esc&gt;% imenu
2309 &AutoCad.Colour.Violet \C6; vmenu &AutoCad.Colour.Violet
2310 &lt;Esc&gt;`&gt;a\C7;&lt;Esc&gt;`&lt;i\C6;&lt;Esc&gt;%
2311 imenu &AutoCad.Colour.Black \C7; vmenu &AutoCad.Colour.Black
2312 &lt;Esc&gt;`&gt;a\C7;&lt;Esc&gt;`&lt;i\C7;&lt;Esc&gt;% imenu
2313 &AutoCad.Colour.D_Grey \C8; vmenu &AutoCad.Colour.D_Grey
2314 &lt;Esc&gt;`&gt;a\C7;&lt;Esc&gt;`&lt;i\C8;&lt;Esc&gt;% imenu
2315 &AutoCad.Colour.L_Grey \C9; vmenu &AutoCad.Colour.L_Grey
2316 &lt;Esc&gt;`&gt;a\C7;&lt;Esc&gt;`&lt;i\C9;&lt;Esc&gt;%
2317
2318 imenu &AutoCad.Font.Arial \fArial; vmenu &AutoCad.Font.Arial
2319 &lt;Esc&gt;`&lt;i\fArial;&lt;Esc&gt;% imenu &AutoCad.Font.Symbol \Fsymbol;
2320 vmenu &AutoCad.Font.Symbol &lt;Esc&gt;`&lt;i\Fsymbol;&lt;Esc&gt;%
2321 imenu &AutoCad.Font.RomanC \Fromanc; imenu &AutoCad.Font.RomanC
2322 &lt;Esc&gt;`&lt;i\Fromanc;&lt;Esc&gt;% imenu &AutoCad.Font.RomanS \Fromans;
2323 vmenu &AutoCad.Font.RomanS &lt;Esc&gt;`&lt;i\Fromans;&lt;Esc&gt;%
2324 imenu &AutoCad.Font.RomanD \Fromand; vmenu &AutoCad.Font.RomanD
2325 &lt;Esc&gt;`&lt;i\Fromand;&lt;Esc&gt;% imenu &AutoCad.Font.RomanT \Fromant;
2326 vmenu &AutoCad.Font.RomanT &lt;Esc&gt;`&lt;i\Fromant;&lt;Esc&gt;%
2327
2328 imenu &AutoCad.Size.0_5x \H0.5x; vmenu &AutoCad.Size.0_5x
2329 &lt;Esc&gt;`&lt;i\H0.5x;&lt;Esc&gt;% imenu &AutoCad.Size.1_5x \H1.5x; vmenu
2330 &AutoCad.Size.1_5x &lt;Esc&gt;`&lt;i\H1.5x;&lt;Esc&gt;% imenu &AutoCad.Size.2x
2331 \H2x; vmenu &AutoCad.Size.2x &lt;Esc&gt;`&lt;i\H2x;&lt;Esc&gt;%
2332 imenu &AutoCad.Size.3x \H3x; vmenu &AutoCad.Size.3x
2333 &lt;Esc&gt;`&lt;i\H3x;&lt;Esc&gt;%
2334
2335 imenu &AutoCad.Effects.Set_Out_1_5 \T1.5; vmenu &AutoCad.Effects.Set_Out_1_5
2336 &lt;Esc&gt;`&gt;a\T1;&lt;Esc&gt;`&lt;i\T1.5;&lt;Esc&gt;% imenu
2337 &AutoCad.Effects.Set_Out_2 \T2; vmenu &AutoCad.Effects.Set_Out_2
2338 &lt;Esc&gt;`&gt;a\T1;&lt;Esc&gt;`&lt;i\T2;&lt;Esc&gt;%
2339
2340 imenu &AutoCad.Effects.-SEP3- : imenu
2341 &AutoCad.Effects.Tilt_15deg \Q15; vmenu &AutoCad.Effects.Tilt_15deg
2342 &lt;Esc&gt;`&gt;a\Q0;&lt;Esc&gt;`&lt;i\Q10;&lt;Esc&gt;% imenu
2343 &AutoCad.Effects.Tilt_20deg \Q20; vmenu &AutoCad.Effects.Tilt_20deg
2344 &lt;Esc&gt;`&gt;a\Q0;&lt;Esc&gt;`&lt;i\Q20;&lt;Esc&gt;% imenu
2345 &AutoCad.Effects.Tilt_30deg \Q30; vmenu &AutoCad.Effects.Tilt_30deg
2346 &lt;Esc&gt;`&gt;a\Q0;&lt;Esc&gt;`&lt;i\Q30;&lt;Esc&gt;%
2347
2348 imenu &AutoCad.Effects.-SEP4- : imenu &AutoCad.Effects.Change_Width_0_5x
2349 \W0.5; vmenu &AutoCad.Effects.Change_Width_0_5x
2350 &lt;Esc&gt;`&gt;a\W1;&lt;Esc&gt;`&lt;i\W0.5;&lt;Esc&gt;% imenu
2351 &AutoCad.Effects.Change_Width_2x \W2; vmenu &AutoCad.Effects.Change_Width_2x
2352 &lt;Esc&gt;`&gt;a\W1;&lt;Esc&gt;`&lt;i\W2;&lt;Esc&gt;%
2353
2354 imenu &AutoCad.Effects.-SEP5- : imenu &AutoCad.Effects.Justify_Down \A0;
2355 vmenu &AutoCad.Effects.Justify_Down &lt;Esc&gt;`&lt;i\A0;&lt;Esc&gt;%
2356 imenu &AutoCad.Effects.Justify_Middle \A1; vmenu
2357 &AutoCad.Effects.Justify_Middle &lt;Esc&gt;`&lt;i\A1;&lt;Esc&gt;%
2358 imenu &AutoCad.Effects.Justify_Up \A2; vmenu &AutoCad.Effects.Justify_Up
2359 &lt;Esc&gt;`&lt;i\A2;&lt;Esc&gt;% imenu &AutoCad.Effects.Overlined_Characters
2360 \O\o&lt;Esc&gt;F\i vmenu &AutoCad.Effects.Overlined_Characters
2361 &lt;Esc&gt;`&gt;a\O&lt;Esc&gt;`&lt;i\o&lt;Esc&gt;% imenu
2362 &AutoCad.Effects.Underlined_Characters \L\l&lt;Esc&gt;F\i
2363 vmenu &AutoCad.Effects.Underlined_Characters
2364 &lt;Esc&gt;`&gt;a\l&lt;Esc&gt;`&lt;i\L&lt;Esc&gt;% imenu
2365 &AutoCad.Effects.Index_Top \S^;
2366
2367 imenu &AutoCad.-SEP6- : imenu &AutoCad.Help &lt;CR&gt;&lt;CR&gt;***Quit
2368 Editor: press Alt-F4 and 'No' ***&lt;CR&gt;&lt;CR&gt;
2369
2370 star
2371
2372 </pre></tip> </html> <Tip category="KVim"> <html><center>How
2373 do I add a current time string inside Vim?</center> <pre> <A
2374 HREF="http://vim.sf.net/tip_view.php?tip_id=97">http://vim.sf.net/tip_view.php?tip_id=97</A><BR>
2375
2376 This is a *request* for a tip. Sometimes (eg. editing HTML pages) I need
2377 to add a timestamp string to my editing buffer. On UNIX systems, I can use
2378 :r!date
2379 to get a localized date time string; but on Windows ('date' on Windows will
2380 query the user to input new date) or other platforms which does not have
2381 'date' command, how do I get a timestamp easily?
2382
2383 </pre></tip> </html> <Tip category="KVim"> <html><center>Getting
2384 vim help from mailing lists and newsgroups.</center> <pre> <A
2385 HREF="http://vim.sf.net/tip_view.php?tip_id=98">http://vim.sf.net/tip_view.php?tip_id=98</A><BR>
2386
2387 There have been a few "requests for tips" entered into the tips database
2388 lately. If you have specific questions that aren't answered by the existing
2389 tips, there are a couple of resources that may be more appropriate:
2390
2391 The mailing list vim@vim.org is for vim users. If you send an email
2392 to vim-help@vim.org, you'll get a message back telling you how
2393 to subscribe, as well as how to request old messages and contact
2394 the list maintainer. This mailing list is also archived at <A
2395 HREF="http://groups.yahoo.com/group/vim.">http://groups.yahoo.com/group/vim.</A><BR>
2396
2397 The newsgroup comp.editors discusses many different editors, but most of
2398 the traffic is about vim. When posting, it is appreciated if you include
2399 "vim" in the subject line. The comp.editors newsgroup is archived at <A
2400 HREF="http://groups.google.com/groups?hl=en&safe=off&group=comp.editors.">http://groups.google.com/groups?hl=en&safe=off&group=comp.editors.</A><BR>
2401
2402 Using the tips database for asking questions is not likely to work well.
2403 For example, if you ask a question titled "Searching for strings in a file"
2404 and I read this site and see that tip, I'm not going to read it if I already
2405 know how to search for strings in a file. In comp.editors and vim@vim.org,
2406 people expect to find questions from others and are therefore more likely
2407 to see your questions.
2408
2409 After finding the answer to your question, please consider whether it would
2410 make an appropriate tip, and if so, add it to the tips database.
2411
2412 </pre></tip> </html> <Tip category="KVim"> <html><center>How to
2413 tell what syntax highlighting group *that* is!</center> <pre> <A
2414 HREF="http://vim.sf.net/tip_view.php?tip_id=99">http://vim.sf.net/tip_view.php?tip_id=99</A><BR>
2415
2416 Here's a (what should be a one-line) map to help you tell just what syntax
2417 highlighting groups the item under the cursor actually is:
2418
2419 map &lt;F10&gt; :echo "hi&lt;"
2420 . synIDattr(synID(line("."),col("."),1),"name") . '&gt; trans&lt;'
2421 . synIDattr(synID(line("."),col("."),0),"name") . "&gt; lo&lt;"
2422 . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . "&gt;"&lt;CR&gt;
2423
2424 Once known you can override the current highlighting with whatever you want.
2425 If you're debugging a syntax highlighting file (a rare occupation), sometimes
2426 you'll wish to know the entire chain of syntax highlighting. For that,
2427 check out
2428
2429 <A
2430 HREF="http://www.erols.com/astronaut/vim/vimscript/hilinks.vim">http://www.erols.com/astronaut/vim/vimscript/hilinks.vim</A><BR>
2431
2432 </pre></tip> </html> <Tip category="KVim"> <html><center>Jump to
2433 tag (e.g. help topic) with German keyboard (PC)</center> <pre> <A
2434 HREF="http://vim.sf.net/tip_view.php?tip_id=100">http://vim.sf.net/tip_view.php?tip_id=100</A><BR>
2435
2436 You're a newbie in vim and need some ":help"? Well, help.txt reads:
2437
2438 "Jump to a subject: Position the cursor on a tag between |bars| and hit
2439 CTRL-]."
2440
2441 Unfortunately there is no "]" key on German keyboards. On Win32 try CTRL-+
2442 (Strg-+), on Linux console I use CTRL-AltGr-9 (Strg-AltGr-9).
2443
2444 Kind regards
2445
2446 </pre></tip> </html> <Tip category="KVim"> <html><center>Change automatically
2447 to the directory the file in the current buffer is in</center> <pre> <A
2448 HREF="http://vim.sf.net/tip_view.php?tip_id=101">http://vim.sf.net/tip_view.php?tip_id=101</A><BR>
2449
2450 To change automatically to the directory the file in the current buffer is
2451 in add a line (below) to the file .vimrc . The file .vimrc should have
2452 the following if-statement to control the autocmd feature:
2453
2454 if has("autocmd")
2455
2456 &lt; ... lot of autocmd stuff ... &gt;
2457
2458 " Change to the directory the file in your current buffer is in autocmd
2459 BufEnter * :cd %:p:h
2460
2461 endif " has("autocmd")
2462
2463 Add the line above the endif and restart vim/gvim.
2464
2465 </pre></tip> </html> <Tip category="KVim"> <html><center>smart
2466 mapping for tab completion</center> <pre> <A
2467 HREF="http://vim.sf.net/tip_view.php?tip_id=102">http://vim.sf.net/tip_view.php?tip_id=102</A><BR>
2468
2469 I'm used to complete words with &lt;tab&gt;, however when editing source
2470 I can't just map that to vim keyword completion because I sometime need to
2471 insert real tabs, since it mostly happen when at the beginning of the line or
2472 after a ; and before a one line comma (java, c++ or perl anyone...) I've come
2473 to find the following really usefull This is how you can map the &lt;tab&gt;
2474 key in insert mode while still being able to use it when at the start of
2475 a line or when the preceding char is not a keyword character. in a script
2476 file in a plugin directory or in your .vimrc file: first define a function
2477 which returns a &lt;tab&gt; or a &lt;C-N&gt; depending on the context:
2478
2479 function InsertTabWrapper()
2480 let col = col('.') - 1 if !col || getline('.')[col - 1] !~ '\k'
2481 return "\&lt;tab&gt;"
2482 else
2483 return "\&lt;c-p&gt;"
2484 endif
2485 endfunction
2486
2487 then define the appropriate mapping: inoremap &lt;tab&gt;
2488 &lt;c-r&gt;=InsertTabWrapper()&lt;cr&gt;
2489
2490 the trick here is the use of the &lt;c-r&gt;= in insert mode to be able to
2491 call your function without leaving insert mode. :help i_CTRL-R Benoit
2492
2493 </pre></tip> </html> <Tip category="KVim"> <html><center>Move
2494 to next/previous line with same indentation</center> <pre> <A
2495 HREF="http://vim.sf.net/tip_view.php?tip_id=103">http://vim.sf.net/tip_view.php?tip_id=103</A><BR>
2496
2497 When working with Python and other languages which don't use braces, it's
2498 useful to be able to jump to and from lines which have the same indentation
2499 as the line you are currently on.
2500
2501 nn &lt;M-,&gt; k:call search ("^". matchstr (getline (line (".")+ 1),
2502 '\(\s*\)') ."\\S", 'b')&lt;CR&gt;^ nn &lt;M-.&gt; :call search ("^". matchstr
2503 (getline (line (".")), '\(\s*\)') ."\\S")&lt;CR&gt;^
2504
2505 will map Alt-&lt; and Alt-&gt; in Normal mode to upward and downward searching
2506 for lines with the same indent as the current line.
2507
2508 </pre></tip> </html> <Tip category="KVim"> <html><center>using
2509 vim to complement Perl's DBI::Shell</center> <pre> <A
2510 HREF="http://vim.sf.net/tip_view.php?tip_id=104">http://vim.sf.net/tip_view.php?tip_id=104</A><BR>
2511
2512 DBI::Shell is a Perl module that is used as a shell interface to Perl's
2513 popular DBI (database interface) package. Forget your favorite SQL navigation
2514 gui and give this method a shot. This has only been tested in UNIX.
2515
2516 1. run dbish (runs DBI::Shell; installed with DBI::Shell) and connect to any
2517 database 2. in dbish, set /format box 3. enter your query 4. to execute query,
2518 type "/ | vim -"
2519
2520 This runs the query and pipes the output to the standard input of vim. Here
2521 are some follow-up tips: -use gvim instead of vim so a new window will pop
2522 up -set nowrap once in vim -make a syntax highlighting file for me!
2523
2524 -Adam Monsen
2525
2526 </pre></tip> </html> <Tip category="KVim">
2527 <html><center>combining move and scroll</center> <pre> <A
2528 HREF="http://vim.sf.net/tip_view.php?tip_id=105">http://vim.sf.net/tip_view.php?tip_id=105</A><BR>
2529
2530 I sometimes found myself moving down a few lines with j, then scrolling
2531 down about the same number of lines with &lt;C-E&gt; to put the cursor in
2532 roughly the same place as it started. I decided I wanted to map &lt;C-J&gt;
2533 (and &lt;C-K&gt;, respectively) to the move-and-scroll operation. First, I did
2534
2535 :map &lt;C-J&gt; &lt;C-E&gt;j
2536
2537 This was pretty good, but behaved funny at the beginning and end of files.
2538 Then, I realized that &lt;C-D&gt; already combined move and scroll, so I
2539 figured that giving &lt;C-D&gt; a count of 1 would do it:
2540
2541 :map &lt;C-J&gt; 1&lt;C-D&gt;
2542
2543 Unfortunately, this permanently attaches a count to &lt;C-D&gt; (ugh!),
2544 so I have to undo that:
2545
2546 :map &lt;C-J&gt; 1&lt;C-D&gt;:set scroll=0&lt;CR&gt;
2547
2548 This has the drawback of not necessarily resetting scroll to its original
2549 value, but since I never change scroll, it's good enough for me. It would be
2550 nice if there were a version of &lt;C-D&gt; that did not have the side-affect
2551 of changing scroll.
2552
2553 Happy vimming, Andrew
2554
2555 </pre></tip> </html> <Tip category="KVim">
2556 <html><center>Supersimple one-line solution</center> <pre> <A
2557 HREF="http://vim.sf.net/tip_view.php?tip_id=106">http://vim.sf.net/tip_view.php?tip_id=106</A><BR>
2558
2559 Hallo, next solution for _most_simple_ signature rotater: You can
2560 only put one line to your .vimrc || _vimrc: map &lt;Leader&gt;ms :e
2561 c:\sign.txt&lt;CR&gt;ggV/--&lt;CR&gt;k"*xG$a&lt;C-R&gt;&lt;C-O&gt;*&lt;Esc&gt;:w&lt;CR&gt;:bd&lt;CR&gt;G$a&lt;C-M&gt;&lt;Esc&gt;"*P
2562
2563 Must exist file (from eg above) c:\sign.txt, with content: -- first signature
2564 -- second signature -- third signature --
2565
2566 When You finished mail, only call shortcut \ms and 'first signature' will
2567 be insert in your mail. In c:\sign.txt will be first signature pushed
2568 to the end of this file. When You want use other signature, only press
2569 'u' and \ms again (Or You can change \ms to e.g. &lt;F12&gt;, indeed. )
2570 You can change this and append one part like 'basic' from command and
2571 append 'changing' part from .signature file, as you like... Ok, one
2572 unpleasant thing is here: your signature must not contain '--' (signature
2573 separator)... Anyhow, I find it useful brz* &lt;brz@centrum.cz&gt; <A
2574 HREF="http://brz.d2.cz/">http://brz.d2.cz/</A><BR>
2575
2576 </pre></tip> </html> <Tip category="KVim">
2577 <html><center>convert enum to string table</center> <pre> <A
2578 HREF="http://vim.sf.net/tip_view.php?tip_id=107">http://vim.sf.net/tip_view.php?tip_id=107</A><BR>
2579
2580 When testing your own C/C++ programs you sometimes wish to have a trace output,
2581 which shows you, which enum value is used. You can do this by creating
2582 a string table for that enum type, which contains the enum identifyer as
2583 a string. e.g. printf ("%s", MyEnumStringTable [ MyEnumVal] );
2584
2585 You can create the complete string table by - marking the lines containing
2586 the complete typedef enum - select menu C/C++.transform enum2Stringtab
2587
2588 You can create string table entries by - marking the lines within the typedef
2589 enum - select menu C/C++.transform enum2String
2590
2591 This makes it easy to keep the enum (on changes) consistent to the string
2592 table.
2593
2594 Add the following lines to your _GVIMRC file: 31amenu C/C++.transform\
2595 enum2Stringtab :s#[ ]*\\(\\w\\+\\)#/* \\1 */
2596 "\\1"#&lt;CR&gt;o};&lt;ESC&gt;uOstatic const char* const Names[] =
2597 {&lt;ESC&gt;&lt;CR&gt;/sdfsdf&lt;CR&gt; 31vmenu C/C++.transform\ enum2Stringtab
2598 :s#[ ]*\\(\\w\\+\\)#/* \\1 */ "\\1"#&lt;CR&gt;o};&lt;ESC&gt;uOstatic
2599 const char* const Names[] = {&lt;ESC&gt;&lt;CR&gt;/sdfsdf&lt;CR&gt;
2600
2601 31amenu C/C++.transform\ enum2String :s#[ ]*\\(\\w\\+\\)#/*
2602 \\1 */ "\\1"#&lt;CR&gt;o}&lt;ESC&gt;/sdfsdf&lt;CR&gt; 31vmenu
2603 C/C++.transform\ enum2String :s#[ ]*\\(\\w\\+\\)#/* \\1 */
2604 "\\1"#&lt;CR&gt;o}&lt;ESC&gt;/sdfsdf&lt;CR&gt;
2605
2606 hint: '/sdfsdf' is added for deactivating search highlighting, ok, you'll
2607 sure find a better way to do this.
2608
2609 </pre></tip> </html> <Tip category="KVim"> <html><center>Toggle
2610 a fold with a single keystroke</center> <pre> <A
2611 HREF="http://vim.sf.net/tip_view.php?tip_id=108">http://vim.sf.net/tip_view.php?tip_id=108</A><BR>
2612
2613 When viewing/editing a folded file, it is often needed to inspect/close
2614 some fold. To speed up these operation use the following (put in your
2615 $HOME/.vimrc):
2616
2617 " Toggle fold state between closed and opened. " " If there is no fold at
2618 current line, just moves forward. " If it is present, reverse it's state.
2619 fun! ToggleFold()
2620 if foldlevel('.') == 0
2621 normal! l
2622 else
2623 if foldclosed('.') &lt; 0
2624 . foldclose
2625 else
2626 . foldopen
2627 endif
2628 endif " Clear status line echo
2629 endfun
2630
2631 " Map this function to Space key. noremap &lt;space&gt; :call
2632 ToggleFold()&lt;CR&gt;
2633
2634 See :help folding for more information about folding.
2635
2636 </pre></tip> </html> <Tip category="KVim">
2637 <html><center>jump between files</center> <pre> <A
2638 HREF="http://vim.sf.net/tip_view.php?tip_id=109">http://vim.sf.net/tip_view.php?tip_id=109</A><BR>
2639
2640 Often I know I'm likely to edit many files. I run 'vim *.pl' and get a whole
2641 bunch of open files.
2642
2643 To make jumping between files to a pleasure, I defined to mapss:
2644
2645 map &lt;f1&gt; :previous&lt;cr&gt; map &lt;f2&gt; :next&lt;cr&gt;
2646
2647 Press F1 to go back and F2 to go forward.
2648
2649 -- Kirill
2650
2651 </pre></tip> </html> <Tip category="KVim">
2652 <html><center>text-&gt;html table converter.</center> <pre> <A
2653 HREF="http://vim.sf.net/tip_view.php?tip_id=110">http://vim.sf.net/tip_view.php?tip_id=110</A><BR>
2654
2655 Below are two functions and a mapping which will convert lines of plain
2656 text into HTML table code. For example, you have several lines like:
2657 ----------------------------------------------- 1 2 3
2658
2659 4 5 6 --------------------------------------------------- by visualizing
2660 all the 7 lines and press &lt;F5&gt;, you can change the text into
2661 &lt;table&gt;&lt;tr&gt;
2662 &lt;td&gt;1&lt;/td&gt; &lt;td&gt;2&lt;/td&gt; &lt;td&gt;3&lt;/td&gt;
2663 &lt;/tr&gt;&lt;tr&gt;
2664 &lt;td&gt;4&lt;/td&gt; &lt;td&gt;5&lt;/td&gt; &lt;td&gt;6&lt;/td&gt;
2665 &lt;/tr&gt;&lt;/table&gt; which will eventually render into a table. So the
2666 rule is: Every line is a table item, every empty line means starting of a
2667 new table row.
2668
2669 "A text-&gt;html table code converter "By: Wenzhi Liang wzhliang@yahoo.com
2670 "You can distribute/change this file freely as long as you keep the title
2671 area. Thanks
2672
2673 func Table()
2674 let end=line("'&gt;") let start=line("'&lt;") let i=start
2675
2676 wh i &lt;= end
2677 exe ":" . i let e=Empty() if e == 1
2678 exe "normal I&lt;/tr&gt;&lt;tr&gt;"
2679 else
2680 exe "normal I&lt;td&gt;A&lt;/td&gt;&gt;&gt;"
2681 endif let i=i+1
2682 endwh
2683
2684 exe "normal o&lt;/tr&gt;&lt;/table&gt;&lt;&lt;" exe ":" . start exe
2685 "normal O&lt;table&gt;&lt;tr&gt;&lt;&lt;"
2686 endfunc
2687
2688 vmap &lt;F5&gt; &lt;ESC&gt;:call Table()&lt;CR&gt;
2689
2690 func Empty()
2691 let line_nr= line (".") let a=getline ( line_nr ) let m=match(a,
2692 "\\S") if m == -1
2693 return 1
2694 else
2695 return 0
2696 endif
2697 endfunc
2698
2699 </pre></tip> </html> <Tip category="KVim"> <html><center>Printing with
2700 syntax highlighting independent of your normal highlighting</center> <pre> <A
2701 HREF="http://vim.sf.net/tip_view.php?tip_id=111">http://vim.sf.net/tip_view.php?tip_id=111</A><BR>
2702
2703 I have found it undesirable to use :hardcopy directly because it uses the
2704 current syntax highlighting to determine how to print the text. For example,
2705 I like to print comments in italics, but I don't like italic fonts on the
2706 screen. This tip will show you how to set up a colorscheme for printing and
2707 use it only when you print.
2708
2709 I copied an existing colorscheme to ~/.vim/colors/print.vim, and changed
2710 all the lines like this:
2711
2712 highlight Normal ctermbg=DarkGrey ctermfg=White guifg=White guibg=grey20
2713 to this:
2714 highlight clear Normal
2715
2716 Then I set the syntax groups how I wanted them to be printed on the printer:
2717
2718 highlight Comment term=italic cterm=italic gui=italic highlight
2719 Constant term=bold cterm=bold gui=bold etc....
2720
2721 I then defined the following command in my .vimrc file:
2722
2723 command! -nargs=* Hardcopy call DoMyPrint("&lt;args&gt;")
2724
2725 And, finally, I defined this function in my .vimrc:
2726
2727 function DoMyPrint(args)
2728 let colorsave=g:colors_name color print exec "hardcopy ".a:args exec
2729 'color '.colorsave
2730 endfunction
2731
2732 After this is complete, you can do:
2733 :Hardcopy &gt; /tmp/out.ps
2734 or just
2735 :Hardcopy
2736 (Note the capital H)
2737
2738 </pre></tip> </html> <Tip category="KVim"> <html><center>Back
2739 and forth between indented lines again</center> <pre> <A
2740 HREF="http://vim.sf.net/tip_view.php?tip_id=112">http://vim.sf.net/tip_view.php?tip_id=112</A><BR>
2741
2742 Paul Wright posted a tip which explained how to jump back and forth between
2743 lines with the same indentation level. I do this a lot, so I came up with
2744 this slightly more comprehensive solution.
2745
2746 The example mappings below work as follows:
2747
2748 [l and ]l jump to the previous or the next line with the same indentation
2749 level as the one you're currently on.
2750
2751 [L and ]L jump to the previous or the next line with an indentation level
2752 lower than the line you're currently on.
2753
2754 These movements also work in visual mode and (only as of one of the 6.0 alpha
2755 versions) in operator pending mode, meaning that you can do a d]l. The motion
2756 is specified as being exclusive when in operator pending mode.
2757
2758 When might you use this? If you're writing programs in Python, Haskell,
2759 or editing XML files, they will be very useful. E.g. in XML you can jump to
2760 the outer enclosing tag, or the next matching tag. I use it for practically
2761 anything I edit, so it's not limited to this.
2762
2763 " " NextIndent() " " Jump to the next or previous line that has the same level
2764 or a lower " level of indentation than the current line. " " exclusive (bool):
2765 true: Motion is exclusive " false: Motion is inclusive "
2766 fwd (bool): true: Go to next line " false: Go to
2767 previous line " lowerlevel (bool): true: Go to line with lower indentation
2768 level " false: Go to line with the same indentation level
2769 " skipblanks (bool): true: Skip blank lines " false:
2770 Don't skip blank lines
2771
2772 function! NextIndent(exclusive, fwd, lowerlevel, skipblanks)
2773 let line = line('.') let column = col('.') let lastline = line('$')
2774 let indent = indent(line) let stepvalue = a:fwd ? 1 : -1
2775
2776 while (line &gt; 0 && line &lt;= lastline)
2777 let line = line + stepvalue if ( ! a:lowerlevel &&
2778 indent(line) == indent ||
2779 \ a:lowerlevel && indent(line) &lt; indent)
2780 if (! a:skipblanks || strlen(getline(line)) &gt; 0)
2781 if (a:exclusive)
2782 let line = line - stepvalue
2783 endif exe line exe "normal " column . "|"
2784 return
2785 endif
2786 endif
2787 endwhile
2788 endfunc
2789
2790 " Moving back and forth between lines of same or lower indentation.
2791 nnoremap &lt;silent&gt; [l :call NextIndent(0, 0, 0, 1)&lt;cr&gt;
2792 nnoremap &lt;silent&gt; ]l :call NextIndent(0, 1, 0, 1)&lt;cr&gt;
2793 nnoremap &lt;silent&gt; [L :call NextIndent(0, 0, 1, 1)&lt;cr&gt;
2794 nnoremap &lt;silent&gt; ]L :call NextIndent(0, 1, 1, 1)&lt;cr&gt; vnoremap
2795 &lt;silent&gt; [l &lt;esc&gt;:call NextIndent(0, 0, 0, 1)&lt;cr&gt;m'gv''
2796 vnoremap &lt;silent&gt; ]l &lt;esc&gt;:call NextIndent(0, 1, 0,
2797 1)&lt;cr&gt;m'gv'' vnoremap &lt;silent&gt; [L &lt;esc&gt;:call NextIndent(0, 0,
2798 1, 1)&lt;cr&gt;m'gv'' vnoremap &lt;silent&gt; ]L &lt;esc&gt;:call NextIndent(0,
2799 1, 1, 1)&lt;cr&gt;m'gv'' onoremap &lt;silent&gt; [l :call NextIndent(0, 0, 0,
2800 1)&lt;cr&gt; onoremap &lt;silent&gt; ]l :call NextIndent(0, 1, 0, 1)&lt;cr&gt;
2801 onoremap &lt;silent&gt; [L :call NextIndent(1, 0, 1, 1)&lt;cr&gt; onoremap
2802 &lt;silent&gt; ]L :call NextIndent(1, 1, 1, 1)&lt;cr&gt;
2803
2804 </pre></tip> </html> <Tip category="KVim"> <html><center>Translator
2805 in vim (Windows solution)</center> <pre> <A
2806 HREF="http://vim.sf.net/tip_view.php?tip_id=113">http://vim.sf.net/tip_view.php?tip_id=113</A><BR>
2807
2808 Hallo, today I found script "translate.vim", but on Windows this will be
2809 probably difficult to run it (maybe with Cygwin is it possible). I've simpler
2810 solution of keymap for vim interlacing to dictionary: Must exist file with
2811 vocabulary (e.g. "an-cs.txt"), which is called for word under cursor. In
2812 'normal' is only displayed window with translations, in 'insert' is word
2813 under cursor deleted and is insert selected form of word from translantion
2814 window (select it by mouse and than press right button: It works fine on
2815 W2k). Key _F12_ is looking for "word", shifted _S-F12_ is looking for
2816 "pattern". For windows is needed agrep, which is localy placed on <A
2817 HREF="http://www.tgries.de/agrep/index.html">http://www.tgries.de/agrep/index.html</A><BR>
2818
2819 map &lt;F12&gt; b"*yw&lt;Esc&gt;:! c:/bin/agrep -wih
2820 &lt;C-R&gt;* "c:/dict/an-cs.txt"&lt;CR&gt; imap &lt;F12&gt;
2821 &lt;Esc&gt;b"*yw&lt;Esc&gt;:! c:/bin/agrep -wih &lt;C-R&gt;*
2822 "c:/dict/an-cs.txt"&lt;CR&gt;dwi &lt;C-R&gt;* map &lt;S-F12&gt;
2823 b"*yw&lt;Esc&gt;:! c:/bin/agrep -ih &lt;C-R&gt;* "c:/dict/an-cs.txt"&lt;CR&gt;
2824 imap &lt;S-F12&gt; &lt;Esc&gt;b"*yw&lt;Esc&gt;:! c:/bin/agrep -ih &lt;C-R&gt;*
2825 "c:/dict/an-cs.txt"&lt;CR&gt;dwi &lt;C-R&gt;*
2826
2827 brz* &lt;brz@centrum.cz&gt;
2828
2829 </pre></tip> </html> <Tip category="KVim">
2830 <html><center>Browsing by paragraph</center> <pre> <A
2831 HREF="http://vim.sf.net/tip_view.php?tip_id=114">http://vim.sf.net/tip_view.php?tip_id=114</A><BR>
2832
2833 It can be done by reaching the blank lines in up and down directions just
2834 by pressing
2835
2836 { ---- For going to the blank line above the paragraph } ---- For
2837 going to the blank line below the paragraph
2838
2839 </pre></tip> </html> <Tip category="KVim">
2840 <html><center>Browsing by paragraph</center> <pre> <A
2841 HREF="http://vim.sf.net/tip_view.php?tip_id=115">http://vim.sf.net/tip_view.php?tip_id=115</A><BR>
2842
2843 It can be done by reaching the blank lines in up and down directions just
2844 by pressing
2845
2846 { ---- For going to the blank line above the paragraph } ---- For
2847 going to the blank line below the paragraph
2848
2849 </pre></tip> </html> <Tip category="KVim"> <html><center>Search all
2850 occurances of the word under cursor in all the open files</center> <pre> <A
2851 HREF="http://vim.sf.net/tip_view.php?tip_id=116">http://vim.sf.net/tip_view.php?tip_id=116</A><BR>
2852
2853 Sometimes it is useful to know all the occurances of the word under cursor in
2854 all the open files. This can be done by pressing [I ( bracket and capital I )
2855 . it shows the results found in the command window.
2856
2857 </pre></tip> </html> <Tip category="KVim"> <html><center>FAST
2858 SEARCH ACROSS THE PROJECT</center> <pre> <A
2859 HREF="http://vim.sf.net/tip_view.php?tip_id=117">http://vim.sf.net/tip_view.php?tip_id=117</A><BR>
2860
2861 Searching for a word across the project wastes most of the
2862 developres time, which can be avoided by the use of GNU Id_utils
2863 with VIM. The procedure needs to be followed is as follows:
2864 download GNU idutils 3.2d (mkid,lid,fid,fnid,xtokid) from <A
2865 HREF="http://www.mossbayeng.com/~ron/vim/builds.html">http://www.mossbayeng.com/~ron/vim/builds.html</A><BR>
2866
2867 uncompress and store these files in the directory from where vim is running.
2868
2869 goto the top level directory of the project, and run mkid, it will create ID
2870 file in that directory (As it is time consuming process, so be patient). copy
2871 this file ID to the directory from where vim is running.
2872
2873 USAGE:
2874
2875 Put these lines in your .vimrc:
2876
2877 map _u :call ID_search()&lt;Bar&gt;execute "/\\&lt;" . g:word
2878 . "\\&gt;"&lt;CR&gt; map _n :n&lt;Bar&gt;execute "/\\&lt;" . g:word
2879 . "\\&gt;"&lt;CR&gt;
2880
2881 function ID_search()
2882 let g:word = expand("&lt;cword&gt;") let x = system("lid --key=none
2883 ". g:word) let x = substitute(x, "\n", " ", "g") execute "next " . x
2884 endfun
2885
2886 To use it, place the cursor on a word, type "_u" and vim will load the file
2887 that contains the word. Search for the next ocurance of the word in the
2888 same file with "n". Go to the next file with "_n".
2889
2890 The mapping of "_u" and "_n" can be done to some other key as per your
2891 preference but I use ^K and ^L for this purpose.
2892
2893 </pre></tip> </html> <Tip category="KVim"> <html><center>Configuring
2894 gVim as Internet Explorer 'View Source' editor</center> <pre> <A
2895 HREF="http://vim.sf.net/tip_view.php?tip_id=118">http://vim.sf.net/tip_view.php?tip_id=118</A><BR>
2896
2897 Within the registry, you can specify the source editor to be used by Internet
2898 Explorer when {View|Source} is selected. Unfortunately, you can't specify a
2899 quoted filename argument here, i.e. "%1". The editor specified is supposed
2900 to handle filenames which contain spaces. This will cause problems for
2901 Vim because Vim treats each space as an argument separator. If an unquoted
2902 filename contains spaces, Vim treats the filename as multiple arguments and
2903 will open multiple files instead of one. To workaround this problem a quoted
2904 filename has to be passed to Vim. This can be done by creating the following
2905 Visual Basic Script file gVim.vbs:
2906
2907 '--- gVim.vbs -----------------------------------------------------------------
2908 'function: Start gvim, combining multiple arguments to single file argument.
2909 'changes: 20010905: Quoted 'oWShell.Run' filename argument, allowing spaces.
2910 ' 20010518: Created. 'author: Freddy Vulto &lt;fvu@fvu.myweb.nl&gt;
2911
2912 ' Making variable declaration mandatory
2913 option explicit
2914
2915 dim oWShell, sArg, sFile
2916
2917 ' Create script object
2918 set oWShell = CreateObject("wscript.shell")
2919 ' Loop through arguments
2920 for each sArg in wscript.arguments
2921 ' Add argument to filename
2922 sFile = sFile & sArg & " "
2923 next
2924 ' Remove excess space
2925 sFile = Trim(sFile)
2926 ' Run Vim with file argument. Additional arguments: ' -R: View file
2927 readonly ' -c "set syntax=html": Use HTML syntax-highlighting ' NOTE:
2928 Use "-c ""set ft=html""" to make it work for Vim v6.
2929 oWShell.Run _
2930 """D:\Programs\Vim\Vim58\gvim.exe """ & _ "-R """ & sFile & """ " & _
2931 "-c ""set syntax=html"""
2932
2933 ' Destroy script object
2934 set oWShell = NOTHING
2935
2936 The source editor now can be specified by adding the following key to the
2937 registry:
2938
2939 HKEY_LOCAL_MACHINE |- Software
2940 |- Microsoft
2941 |- Internet Explorer
2942 |- View Source Editor
2943 |- Editor Name (Default) = D:\Programs\Vim\gvim.vbs
2944
2945 Freddy Vulto &lt;fvu@fvu.myweb.nl&gt; <A
2946 HREF="http://fvu.myweb.nl/Projects/Vim/Web/vim.htm">http://fvu.myweb.nl/Projects/Vim/Web/vim.htm</A><BR>
2947
2948 </pre></tip> </html> <Tip category="KVim">
2949 <html><center>Explorer startup and shutdown</center> <pre> <A
2950 HREF="http://vim.sf.net/tip_view.php?tip_id=119">http://vim.sf.net/tip_view.php?tip_id=119</A><BR>
2951
2952 I really like the new explorer window, but I wanted it to function a little
2953 more seemlessly in the editor. The following code does two things. First,
2954 the explorer is started when vim is started. I also noticed and fixed
2955 that the explorers size is not equal to the window size, hence the strange
2956 behavior when popping between two windows. The other major function of
2957 the code is to close the explorer when it's the only window that's left.
2958 I'd actually like to take this a step further and close the window if the
2959 last _document_ window is closed. I'd prefer that multiple explorers or help
2960 windows don't keep the application running - only having a file open keeps the
2961 application running. But I didn't see an easy way to do this... anyone else?
2962
2963 BTW, thank you Bram for the help figuring this out.
2964
2965 Code (which currently lives in my _vimrc):
2966
2967 " FILE BROWSER STARTUP func OpenFileWindow()
2968 " :runtime plugin/*.vim " this would be useful if you were
2969 calling this
2970 " function from the .vimrc directly
2971 let g:explDetailedList=1 " show size and date by default let
2972 g:explVertical=1 " Split vertically let g:explStartRight=0
2973 " Put new explorer window to the left of the current window :Sexplore
2974 set nonu set winwidth=15 " Make the width of the window match
2975 the explorer setting "let g:explVertical=0 " Split vertically
2976 doautocmd fileExplorer BufEnter " Forces the directory refresh to
2977 occur :winc l " change to the document window
2978 endfunc
2979
2980 func CloseIfLast()
2981 if exists("b:completePath") " this is how I determine that I'm
2982 in an explorer window
2983 let n = winnr() wincmd p if n == winnr()
2984 quit " quit the window
2985 endif wincmd p
2986 endif
2987 endfunc
2988
2989 if has("autocmd")
2990 if !exists("rudyautocommands")
2991 let rudyautocommands = 1 autocmd VimEnter * call
2992 OpenFileWindow() autocmd WinEnter * call CloseIfLast()
2993
2994 endif
2995 endif
2996
2997 </pre></tip> </html> <Tip category="KVim"> <html><center>Compiling
2998 Java with Sun JDK (javac) within VIM</center> <pre> <A
2999 HREF="http://vim.sf.net/tip_view.php?tip_id=120">http://vim.sf.net/tip_view.php?tip_id=120</A><BR>
3000
3001 The $VIMRUNTIME/compiler has 'jikes.vim', but there's nothing for traditional
3002 Sun JDK(javac), so I tried (Only tested on Win 2000):
3003
3004 " Vim Compiler File javac.vim " Compiler: Sun/IBM JDK: Javac
3005
3006 if exists("current_compiler")
3007 finish
3008 endif let current_compiler = "javac"
3009
3010 " Javac defaults to printing output on stderr and no options can convert,
3011 so we have to set 'shellpipe' setlocal shellpipe=2&gt; " 2&gt; works on Win
3012 NT and UNIX setlocal makeprg=javac\ #&lt;.java setlocal errorformat=%f:%l:%m
3013 " Sorry I'm not familiar with 'errorformat', so I set it very simple.
3014
3015 </pre></tip> </html> <Tip category="KVim"> <html><center>Using
3016 vim as a syntax-highlighting pager</center> <pre> <A
3017 HREF="http://vim.sf.net/tip_view.php?tip_id=121">http://vim.sf.net/tip_view.php?tip_id=121</A><BR>
3018
3019 If you want to use Vim's syntax highlighting in a "more"-style pager, here's
3020 one way to set it up:
3021
3022 First, create a vimrc like the following -- I called mine ~/.vimrc.more
3023
3024 ---8&lt;---cut here---8&lt;--- " No compatibility -- necessary for mappings
3025 to work. set nocompatible
3026
3027 " Status line set laststatus=0 set cmdheight=1 set nomodifiable "
3028 Only in version 6.0 set readonly
3029
3030 " Syntax colouring -- lines taken from syntax.txt discussion on colour xterms.
3031 " See ':help color-xterm'. Use appropriate lines for your own set-up.
3032 if has("terminfo")
3033 set t_Co=16 set t_Sf=[3%p1%dm set t_Sb=[4%p1%dm
3034 else
3035 set t_Co=16 set t_Sf=[3%dm set t_Sb=[4%dm
3036 endif " My xterms have a navy-blue background, so I need this line too.
3037 set background=dark " Turn syntax on syntax on
3038
3039 " Key bindings. nmap b &lt;C-B&gt;&lt;C-G&gt; nmap q :q&lt;CR&gt; " To
3040 type the following line, type *two* C-V's followed by two spaces. This "
3041 is how you map the spacebar. nmap ^V &lt;C-F&gt;&lt;C-G&gt; ---8&lt;---cut
3042 here---8&lt;---
3043
3044 Then, to use this .vimrc, add an alias. If you're using tcsh, the syntax
3045 will be something like:
3046
3047 alias vmore "vim -u ~/.vimrc.more"
3048
3049 Then you can type "vmore [filename]" to view a file in this "pager". Spacebar
3050 will move down, 'b' will move back up, and 'q' quits. You can add mappings
3051 for other keys if you want to, also.
3052
3053 </pre></tip> </html> <Tip category="KVim"> <html><center>Skip
3054 blank lines when folding text.</center> <pre> <A
3055 HREF="http://vim.sf.net/tip_view.php?tip_id=122">http://vim.sf.net/tip_view.php?tip_id=122</A><BR>
3056
3057 I love the text folding capabilities of vim. I didn't like that it would
3058 display the first line of the range as the "title" for the fold. I like
3059 to write my comments with the "/*" on a line by itself. So I wrote this
3060 little function that will skip over anything that isn't a character, and
3061 then display whatever it finds after that character.
3062
3063 Just include this in your ~/.vimrc (or ~/.gvimrc):
3064
3065 function GetFirstLineWithChars()
3066 let line_num = 0 let charline = matchstr(getline(v:foldstart),
3067 '[a-zA-Z][a-zA-Z ]*') while strlen(charline) == 0
3068 let line_num = line_num + 1 let charline =
3069 matchstr(getline(v:foldstart + line_num), '[a-zA-Z][a-zA-Z ]*')
3070 endw return charline
3071 endfunction set
3072 foldtext='+'.v:folddashes.substitute(GetFirstLineWithChars(),'\\\/\\\/\\\|\\*\\\|\\*\\\|{{{\\d\\=','','g')
3073 set fillchars=fold: hi folded guibg=black guifg=yellow gui=bold
3074
3075 And as an added bonus, for those new to text folding, add this to your .vimrc
3076 file too:
3077
3078 autocmd BufWinLeave *.* mkview autocmd BufWinEnter *.* silent loadview
3079
3080 That way whatever folds you set won't get lost when you quit. I had that
3081 happen after spending 15 minutes folding up a 3000+ line file. Happy vimming!
3082
3083 </pre></tip> </html> <Tip category="KVim"> <html><center>use
3084 functionality similar to the * search on multiple files</center> <pre> <A
3085 HREF="http://vim.sf.net/tip_view.php?tip_id=123">http://vim.sf.net/tip_view.php?tip_id=123</A><BR>
3086
3087 The use of star as in vimtip#1 and vimtip#5 is great, here is how to use
3088 this type of search accross a whole directory: Just add the mappings (or
3089 choose different letter combinations): map gr :grep &lt;cword&gt; *&lt;cr&gt;
3090 map gr :grep &lt;cword&gt; %:p:h/*&lt;cr&gt; map gR :grep \b&lt;cword&gt;\b
3091 *&lt;cr&gt; map GR :grep \b&lt;cword&gt;\b %:p:h/*&lt;cr&gt;
3092
3093 mapping one will search for the word under the cursor (like g*) in any of
3094 the files in the current directory mapping two will search for the word
3095 under the cursor (like g*) in any of the files in the same directory as the
3096 current file mapping three will search for the word under the cursor by itself
3097 (i.e. surrounded by word boundary like *) in any of the files in the current
3098 directory mapping four will search for the word under the cursor by itself
3099 (i.e. surrounded by word boundary like *) in any of the files in the same
3100 directory as the current file
3101
3102 Benoit
3103
3104 </pre></tip> </html> <Tip category="KVim">
3105 <html><center>Number a group of lines</center> <pre> <A
3106 HREF="http://vim.sf.net/tip_view.php?tip_id=124">http://vim.sf.net/tip_view.php?tip_id=124</A><BR>
3107
3108 Below is a way to number a set of lines. Here is an exaple before and
3109 after snapshot:
3110
3111 apple bob pear tree
3112
3113 1 apple 2 bob 3 pear 4 tree
3114
3115 " Description: " This provides a command and a function. They both can be
3116 called with or " without a range. In addition, they can be called with or
3117 without " arguments. Without a range they operate on the current line. " "
3118 There are two supported arguments. They are described below: " arg1 -&gt;
3119 the number to start at. The default is one. This will " number
3120 your selected lines sequentially. The start can be a " number,
3121 ., $, or, 'x (like getline). " arg2 -&gt; Text to append after numbers.
3122 The default is a space. " " Examples: " To provide your functionality:
3123 " :%Nlist 20 " :%call Nlist(20) " To make a list start at
3124 1: " :'&lt;,'&gt;Nlist " :'&lt;,'&gt;call Nlist() " To
3125 number the whole buffer (with it's actual line number): " :%Nlist "
3126 :%call Nlist() " To number a subset of lines with their line number (and
3127 put a '] ' in " front of every number): " :'&lt;,'&gt;Nlist . ]\
3128 " :'&lt;,'&gt;call Nlist(".", "] ")
3129
3130 command! -nargs=* -range Nlist &lt;line1&gt;,&lt;line2&gt;call
3131 Nlist(&lt;f-args&gt;) function! Nlist(...) range
3132 if 2 == a:0
3133 let start = a:1 let append = a:2
3134 elseif 1 == a:0
3135 let start = a:1 let append = " "
3136 else
3137 let start = 1 let append = " "
3138 endif
3139
3140 " try to work like getline (i.e. allow the user to pass in . $ or 'x)
3141 if 0 == (start + 0)
3142 let start = line(start)
3143 endif
3144
3145 exe a:firstline . "," . a:lastline
3146 . 's/^/\=line(".")-a:firstline+start.append/'
3147 endfunction
3148
3149 </pre></tip> </html> <Tip category="KVim">
3150 <html><center>Auto commenting for "}"</center> <pre> <A
3151 HREF="http://vim.sf.net/tip_view.php?tip_id=125">http://vim.sf.net/tip_view.php?tip_id=125</A><BR>
3152
3153 I always wanted a script that would auto-comment the end of a conditional
3154 block. So, I wrote one. This function searches for the previous matching
3155 "{", grabs the line, and inserts it as a comment after the "}". If there
3156 is no previous matching "{", it inserts nothing.
3157
3158 So...
3159
3160 if (test){
3161
3162 will generate:
3163 } // if (test)
3164
3165 This is obviously not work if you use a different style. If you use
3166
3167 if (test) {
3168
3169 then substituting 'getline(".")', use 'getline(line(".") - 1)' should work.
3170
3171 Put the following in your .vimrc: au BufNewFile,BufRead *.c,*.cc,*.C,*.h
3172 imap } &lt;ESC&gt;:call CurlyBracket()&lt;CR&gt;a
3173
3174 function CurlyBracket()
3175 let l:my_linenum = line(".") iunmap } sil exe "normal i}" imap }
3176 &lt;ESC&gt;:call CurlyBracket()&lt;CR&gt; let l:result1 = searchpair('{',
3177 '', '}', 'bW') if (result1 &gt; 0)
3178 let l:my_string = substitute(getline("."), '^\s*\(.*\){', '\1', "")
3179 sil exe ":" . l:my_linenum sil exe "normal a //" . l:my_string
3180 endif
3181 endfunction
3182
3183 </pre></tip> </html> <Tip category="KVim"> <html><center>how do
3184 I get rid of that bold stuff with my xterm?</center> <pre> <A
3185 HREF="http://vim.sf.net/tip_view.php?tip_id=126">http://vim.sf.net/tip_view.php?tip_id=126</A><BR>
3186
3187 Having problems setting up your syntax highlighting because everything is
3188 coming up in bold?
3189
3190 You're probably using an 8 color xterm and setting up highlighting lines such
3191 as hi Normal ... ctermfg=green . The solution: use numbers! 0=black, 1=red,
3192 2=green, 3=yellow, 4=blue, 5=magenta, 6=cyan, and 7=white. Vim tries to use
3193 "bright" colors when its given names (because Windoz machines prefer to use
3194 dim text unless its been made bold).
3195
3196 Read more about it under :help highlight-ctermfg .
3197
3198 </pre></tip> </html> <Tip category="KVim">
3199 <html><center>Preview HTML files quickly</center> <pre> <A
3200 HREF="http://vim.sf.net/tip_view.php?tip_id=127">http://vim.sf.net/tip_view.php?tip_id=127</A><BR>
3201
3202 I've found while writing HTML files that it can become cumbersome when I have
3203 to switch to a web browser, load my page, and move back to VIM regularly to
3204 preview what I've written. I've come up with the following tricks.
3205
3206 The first one requires that you have lynx (the text-based browser) installed
3207 on your computer (available from <A HREF="http://lynx.isc.org/release/).
3208 If your HTML page is primarily text, with few (if any) images, you can
3209 set up the following function and mapping:">http://lynx.isc.org/release/).
3210 If your HTML page is primarily text, with few (if any) images, you can set
3211 up the following function and mapping:</A><BR>
3212
3213 function PreviewHTML_TextOnly()
3214 let l:fname = expand("%:p" ) new set buftype=nofile nonumber exe "%!lynx
3215 " . l:fname . " -dump -nolist -underscore -width " . winwidth( 0 )
3216 endfunction
3217
3218 map &lt;Leader&gt;pt :call PreviewHTML_TextOnly()&lt;CR&gt;
3219
3220 This will open a new window and display your formatted HTML document in
3221 that window. Note that bold-face, italics, links, etc. will be lost --
3222 all you will see is the text -- but the "-underscore" parameter to Lynx
3223 causes any text that would have been bold, italicized, or underlined to be
3224 displayed like _this_.
3225
3226 The other trick requires that vim be running on your current machine, and that
3227 you be running a GUI of some sort (X-Windows, Windows, etc.). You can cause
3228 vim to invoke your favorite browser and have it display the file, like this:
3229 function PreviewHTML_External()
3230 exe "silent !mozilla -remote \"openurl(file://" . expand( "%:p" ) . ")\""
3231 endfunction
3232
3233 map &lt;Leader&gt;pp :call PreviewHTML_External()&lt;CR&gt;
3234 If you don't use mozilla, you will need to modify the function to use your
3235 preferred browser.
3236
3237 Happy vimming!
3238
3239 </pre></tip> </html> <Tip category="KVim"> <html><center>grep,
3240 diff, patch, idutils, etc. for Windows systems</center> <pre> <A
3241 HREF="http://vim.sf.net/tip_view.php?tip_id=128">http://vim.sf.net/tip_view.php?tip_id=128</A><BR>
3242
3243 If you use Vim on Windows, and you wish you had some of those nifty
3244 UNIX command-line tools,
3245 but do not feel like installing all of Cygwin, you
3246 can get many of the most-used tools from Ron Aaron's web site: <A
3247 HREF="http://www.mossbayeng.com/~ron/vim/builds.html">http://www.mossbayeng.com/~ron/vim/builds.html</A><BR>
3248 Since Ron is a big Vim fan (see <A
3249 HREF="http://www.mossbayeng.com/~ron/vim/vimrant.html ) you can count
3250 on">http://www.mossbayeng.com/~ron/vim/vimrant.html ) you can count on</A><BR>
3251 these tools' working well with Vim. For some hints on how to use them,
3252 read :help :grep :help lid inside Vim.
3253 Happy Vimming!
3254
3255 </pre></tip> </html> <Tip category="KVim"> <html><center>Removing
3256 automatic comment leaders</center> <pre> <A
3257 HREF="http://vim.sf.net/tip_view.php?tip_id=129">http://vim.sf.net/tip_view.php?tip_id=129</A><BR>
3258
3259 If you include the "r" flag in the 'formatoptions' option (:help 'fo'
3260 , :help fo-table ) then the comment leader is inserted
3261 automatically when you start a new line in a comment. For example, in TeX
3262 the "%" character is the comment leader, and you might type
3263
3264 % This is a tex file. % The comment leaders on all lines but the first
3265 were generated automatically. % This is the last line of the comment,
3266 but Vim will insert the comment leader on the next line. %
3267
3268 You can get rid of the comment leader (along with anything you may already
3269 have typed on the line) without affecting the indent, if any, by typing
3270 "&lt;C-U&gt;" while in Insert mode.
3271
3272 Related point: if you want to adjust the indent while in Insert mode,
3273 you can use "&lt;C-D&gt;" (to Decrease the indent)
3274 or "&lt;C-T&gt;" (to increase it). In the docs for Vim 6.0, this is described
3275 in the users' manual, :help 30.4 .
3276
3277 </pre></tip> </html> <Tip category="KVim">
3278 <html><center>disabling default ftplugins</center> <pre> <A
3279 HREF="http://vim.sf.net/tip_view.php?tip_id=130">http://vim.sf.net/tip_view.php?tip_id=130</A><BR>
3280
3281 For an overview of ftplugins (filetype plugins) see
3282
3283 :help ftplugins
3284
3285 If you want to disable all ftplugins, or disable a particular default
3286 ftplugin, see
3287
3288 :help :filetype :help ftplugin-overrule
3289
3290 If you have your own ftplugins, and you want to disable all the default
3291 ones, then do NOT include a check for b:did_ftplugin in your ftplugin files,
3292 and add the line
3293
3294 :autocmd BufEnter * let b:did_ftplugin = 1
3295
3296 to your VIMRC file, BEFORE the ":filetype ftplugin on" line.
3297
3298 </pre></tip> </html> <Tip category="KVim">
3299 <html><center>Scroll alternate window</center> <pre> <A
3300 HREF="http://vim.sf.net/tip_view.php?tip_id=131">http://vim.sf.net/tip_view.php?tip_id=131</A><BR>
3301
3302 This mapping allow you to quickly scroll inactive window when displaying
3303 several windows concurrently.
3304
3305 nmap &lt;silent&gt; &lt;M-Down&gt; :call ScrollOtherWindow("down")&lt;CR&gt;
3306 nmap &lt;silent&gt; &lt;M-Up&gt; :call ScrollOtherWindow("up")&lt;CR&gt;
3307
3308 fun! ScrollOtherWindow(dir)
3309 if a:dir == "down"
3310 let move = "\&lt;C-E&gt;"
3311 elseif a:dir == "up"
3312 let move = "\&lt;C-Y&gt;"
3313 endif exec "normal \&lt;C-W&gt;p" . move . "\&lt;C-W&gt;p"
3314 endfun
3315
3316 PS: Original idea and discussion of this tip appeared on vim@vim.org mailing
3317 list, I'm just prettified it a little.
3318
3319 </pre></tip> </html> <Tip category="KVim">
3320 <html><center>window zooming convenience</center> <pre> <A
3321 HREF="http://vim.sf.net/tip_view.php?tip_id=132">http://vim.sf.net/tip_view.php?tip_id=132</A><BR>
3322
3323 i frequently have multiple windows open in vim -- this reduces the number
3324 of lines each window displays -- i almost always have my windows either all
3325 the same size or the current one as big as possible.
3326
3327 the following function can be toggled on or off by typing &lt;Leader&gt;max
3328 (i can do this quite quickly); just change the mapping at the bottom to
3329 something else if you prefer.
3330
3331 this causes the current window to be as big as possible (moving into another
3332 window causes that one to become big) and all the others get very small.
3333 i actually use this ALL the time. turning it off (by typing the hotkey
3334 sequence again) will cause all windows to have the same height.
3335
3336 "toggles whether or not the current window is automatically zoomed
3337 function! ToggleMaxWins ()
3338 if exists ('g:windowMax')
3339 au! maxCurrWin exe "normal \&lt;c-w&gt;=" unlet g:windowMax
3340 else
3341 augroup maxCurrWin " au BufEnter * exe "normal
3342 \&lt;c-w&gt;_\&lt;c-w&gt;\&lt;bar&gt;" " " only max it vertically
3343 au! BufEnter * exe "normal \&lt;c-w&gt;_" augroup END do maxCurrWin
3344 BufEnter let g:windowMax=1
3345 endif
3346 endfunction map &lt;Leader&gt;max :call ToggleMaxWins ()&lt;CR&gt;
3347
3348 </pre></tip> </html> <Tip category="KVim">
3349 <html><center>Windo and Bufdo</center> <pre> <A
3350 HREF="http://vim.sf.net/tip_view.php?tip_id=133">http://vim.sf.net/tip_view.php?tip_id=133</A><BR>
3351
3352 i like bufdo and windo but i don't like the fact that the commands end in
3353 a different window/buffer than from where i executed them. these versions
3354 (starts with a capital letter) will restore the current window or buffer
3355 when the command's done.
3356
3357 for example, to turn on line numbers everywhere, i use :Windo set nu --
3358 :windo set nu does the trick also but leaves me in a different window than
3359 where i started.
3360
3361 " just like windo but restores the current window when it's done
3362 function! WinDo(command)
3363 let currwin=winnr() execute 'windo ' . a:command execute currwin . 'wincmd w'
3364 endfunction com! -nargs=+ -complete=command Windo call WinDo(&lt;q-args&gt;)
3365
3366 " just like bufdo but restores the current buffer when it's done
3367 function! BufDo(command)
3368 let currBuff=bufnr("%") execute 'bufdo ' . a:command execute 'buffer '
3369 . currBuff
3370 endfunction com! -nargs=+ -complete=command Bufdo call BufDo(&lt;q-args&gt;)
3371
3372 </pre></tip> </html> <Tip category="KVim">
3373 <html><center>View Source in IE6 using VIM</center> <pre> <A
3374 HREF="http://vim.sf.net/tip_view.php?tip_id=134">http://vim.sf.net/tip_view.php?tip_id=134</A><BR>
3375
3376 You can change the "View Source" editor of IE6 by adding the following to
3377 the Windows Registry. Change the path in case you installed VIM in another
3378 location.
3379
3380 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source
3381 Editor\Editor Name] @="C:\\vim\\vim60\\gvim.exe"
3382
3383 </pre></tip> </html> <Tip category="KVim">
3384 <html><center>Vim buffer FAQ</center> <pre> <A
3385 HREF="http://vim.sf.net/tip_view.php?tip_id=135">http://vim.sf.net/tip_view.php?tip_id=135</A><BR>
3386
3387 Vim provides various commands and options to support editing multiple buffers.
3388 This document covers some of the questions asked about using multiple buffers
3389 with Vim. You can get more detailed information about Vim buffer support using
3390 ":help windows.txt" in Vim. You can also use the help keywords mentioned in
3391 this document to read more about a particular command or option. To read more
3392 about a particular command or option use, ":help &lt;helpkeyword&gt;" in Vim.
3393
3394 1. What is a Vim buffer?
3395 A buffer is a file loaded into memory for editing. All opened files
3396 are associated with a buffer. There are also buffers not associated with
3397 any file.
3398
3399 Help keyword(s): windows-intro
3400
3401 2. How do I identify a buffer?
3402 Vim buffers are identified using a name and a number. The name of the
3403 buffer is the name of the file associated with that buffer. The buffer
3404 number is a unique sequential number assigned by Vim. This buffer number
3405 will not change in a single Vim session.
3406
3407 Help keyword(s): :buffers
3408
3409 3. How do I create a buffer?
3410 When you open a file using any of the Vim commands, a buffer is
3411 automatically created. For example, if you use the ":edit file" command
3412 to edit a file, a new buffer is automatically created.
3413
3414 4. How do I add a new buffer for a file to the buffer list without opening
3415 the file? You can add a new buffer for a file without opening it, using
3416 the ":badd" ex command. For example,
3417
3418 :badd f1.txt :badd f2.txt
3419
3420 The above commands will add two new buffers for the files f1.txt and
3421 f2.txt to the buffer list.
3422
3423 Help keyword(s): :badd
3424
3425 5. How do I get a list of all the existing buffers?
3426 You can get a list of all the existing buffers using the ":buffers" or
3427 ":ls" or ":files" ex command. This list is called the 'buffer list'.
3428
3429 In Vim 6.0, to display all the buffers including unlisted buffers, use the
3430 ":buffers!" or ":ls!" or ":files!" ex command.
3431
3432 Help keyword(s): :buffers, :ls, :files
3433
3434 6. How do I delete a buffer?
3435 You can delete a buffer using the ":bdelete" ex command. You can use either
3436 the buffer name or the buffer number to specify a buffer. For example,
3437
3438 :bdelete f1.txt :bdelete 4
3439
3440 The above commands will delete the buffer named "f1.txt" and the fourth
3441 buffer in the buffer list. The ":bdelete" command will remove the buffer
3442 from the buffer list.
3443
3444 In Vim 6.0, when a buffer is deleted, the buffer becomes an unlisted-buffer
3445 and is no longer included in the buffer list. But the buffer name and other
3446 information associated with the buffer is still remembered. To completely
3447 delete the buffer, use the ":bwipeout" ex command. This command will remove
3448 the buffer completely (i.e. the buffer will not become a unlisted buffer).
3449
3450 Help keyword(s): :bdelete, :bwipeout
3451
3452 7. How do I delete multiple buffers?
3453 You can delete multiple buffers in several ways:
3454
3455 1. Pass a range argument to the ":bdelete" command. For example,
3456
3457 :3,5bdelete
3458
3459 This command will delete the buffers 3, 4 and 5.
3460 2. Pass multiple buffer names to the ":bdelete" command. For example,
3461
3462 :bdelete buf1.txt buf2.c buf3.h
3463
3464 This command will delete buf1.txt, buf2.c and buf3.h buffers. In this
3465 example, after typing ":bdelete buf", you can press &lt;Ctrl-A&gt;
3466 to expand all the buffer names starting with 'buf'.
3467
3468 Help keyword(s): :bdelete, :bwipeout
3469
3470 8. How do I remove a buffer from a window?
3471 You can remove a buffer displayed in a window in several ways:
3472
3473 1. Close the window or edit another buffer/file in that window. 2. Use
3474 the ":bunload" ex command. This command will remove the buffer
3475 from the window and unload the buffer contents from memory. The buffer
3476 will not be removed from the buffer list.
3477
3478 Help keyword(s): :bunload
3479
3480 9. How do I edit an existing buffer from the buffer list?
3481 You can edit or jump to a buffer in the buffer list in several ways:
3482
3483 1. Use the ":buffer" ex command passing the name of an existing buffer
3484 or the buffer number. Note that buffer name completion can be used
3485 here by pressing the &lt;Tab&gt; key.
3486 2. You can enter the buffer number you want to jump/edit and press the
3487 Ctrl-^ key.
3488 3. Use the ":sbuffer" ex command passing the name of the buffer or the
3489 buffer number. Vim will split open a new window and open the specified
3490 buffer in that window.
3491 4. You can enter the buffer number you want to jump/edit and press the
3492 Ctrl-W ^ or Ctrl-W Ctrl-^ keys. This will open the specified buffer
3493 in a new window.
3494
3495 Help keyword(s): :buffer, :sbuffer, CTRL-W_^, CTRL-^
3496
3497 10. How do I browse through all the available buffers?
3498 You can browse through the buffers in the buffer list in several ways:
3499
3500 1. To jump to the first buffer in the buffer list, use the ":bfirst" or
3501 ":brewind" ex command.
3502 2. To jump to the first buffer in the buffer list in a new window, use
3503 the ":sbfirst" or ":sbrewind" ex command.
3504 3. To edit the next buffer in the buffer list, use the ":bnext" ex
3505 command.
3506 4. To open the next buffer in the buffer list in a new window, use the
3507 ":sbnext" ex command.
3508 5. To edit the previous buffer in the buffer list, use the ":bprevious"
3509 or ":bNext" ex command.
3510 6. To open the previous buffer in the buffer list in a new window, use
3511 the ":sbprevious" or ":sbNext" ex command.
3512 7. To open the last buffer in the buffer list, use the ":blast" ex
3513 command.
3514 8. To open the last buffer in the buffer list in a new window, use the
3515 ":sblast" ex command.
3516
3517 Help keyword(s): :bfirst, :brewind, :sbfirst, :sbrewind, :bnext,
3518 :sbnext, :bprevious, :bNext, :sbprevious, :sbNext,
3519 :blast, :sblast
3520
3521 11. How do I open all the buffers in the buffer list?
3522 You can open all the buffers present in the buffer list using the ":ball"
3523 or ":sball" ex commands.
3524
3525 Help keyword(s): :ball, :sball
3526
3527 12. How do I open all the loaded buffers?
3528 You can open all the loaded buffers in the buffer list using the ":unhide"
3529 or ":sunhide" ex commands. Each buffer will be loaded in a separate
3530 new window.
3531
3532 Help keyword(s): :unhide, :sunhide
3533
3534 13. How do I open the next modified buffer?
3535 You can open the next or a specific modified buffer using the ":bmodified"
3536 ex command. You can open the next or a specific modified buffer in a
3537 new window using the ":sbmodified" ex command.
3538
3539 Help keyword(s): :bmodified, :sbmodified
3540
3541 14. I am using the GUI version of Vim (gvim), is there a simpler way for
3542 using the buffers instead of the ex commands? Yes. In the GUI version of
3543 Vim, you can use the 'Buffers' menu, which simplifies the use of buffers.
3544 All the buffers in the buffer list are listed in this menu. You can
3545 select a buffer name from this menu to edit the buffer. You can also
3546 delete a buffer or browse the buffer list.
3547
3548 Help keyword(s): buffers-menu
3549
3550 15. Is there a Vim script that simplifies using buffers with Vim?
3551 Yes. You can use the bufexplorer.vim script to simplify the process of
3552 using buffers. You can download the bufexplorer script from:
3553
3554 <A
3555 HREF="http://lanzarotta.tripod.com/vim.html">http://lanzarotta.tripod.com/vim.html</A><BR>
3556
3557 16. Is it possible to save and restore the buffer list across Vim sessions?
3558 Yes. To save and restore the buffer list across Vim session, include the
3559 '%' flag in the 'viminfo' option. Note that if Vim is invoked with a
3560 filename argument, then the buffer list will not be restored from the
3561 last session. To use buffer lists across sessions, invoke Vim without
3562 passing filename arguments.
3563
3564 Help keyword(s): 'viminfo', viminfo
3565
3566 17. How do I remove all the entries from the buffer list?
3567 You can remove all the entries in the buffer list by starting Vim with
3568 a file argument. You can also manually remove all the buffers using the
3569 ":bdelete" ex command.
3570
3571 18. What is a hidden buffer?
3572 A hidden buffer is a buffer with some unsaved modifications and is not
3573 displayed in a window. Hidden buffers are useful, if you want to edit
3574 multiple buffers without saving the modifications made to a buffer while
3575 loading other buffers.
3576
3577 Help keyword(s): :buffer-!, 'hidden', hidden-buffer, buffer-hidden
3578
3579 19. How do I load buffers in a window, which currently has a buffer with
3580 unsaved modifications? By setting the option 'hidden', you can load
3581 buffers in a window that currently has a modified buffer. Vim will
3582 remember your modifications to the buffer. When you quit Vim, you will be
3583 asked to save the modified buffers. It is important to note that, if you
3584 have the 'hidden' option set, and you quit Vim forcibly, for example using
3585 ":quit!", then you will lose all your modifications to the hidden buffers.
3586
3587 Help keyword(s): 'hidden'
3588
3589 20. Is it possible to unload or delete a buffer when it becomes hidden?
3590 The following works only in Vim 6.0 and above. By setting the 'bufhidden'
3591 option to either 'hide' or 'unload' or 'delete', you can control what
3592 happens to a buffer when it becomes hidden. When 'bufhidden' is set to
3593 'delete', the buffer is deleted when it becomes hidden. When 'bufhidden'
3594 is set to 'unload', the buffer is unloaded when it becomes hidden.
3595 When 'bufhidden' is set to 'hide', the buffer is hidden.
3596
3597 Help keyword(s): 'bufhidden'
3598
3599 21. How do I execute a command on all the buffers in the buffer list?
3600 In Vim 6.0, you can use the ":bufdo" ex command to execute an ex command
3601 on all the buffers in the buffer list.
3602
3603 Help keyword(s): :bufdo
3604
3605 22. When I open an existing buffer from the buffer list, if the buffer is
3606 already displayed in one of the existing windows, I want Vim to jump to
3607 that window instead of creating a new window for this buffer. How do I
3608 do this? When opening a buffer using one of the split open buffer commands
3609 (:sbuffer, :sbnext), Vim will open the specified buffer in a new window.
3610 If the buffer is already opened in one of the existing windows, then
3611 you will have two windows containing the same buffer. You can change
3612 this behavior by setting the 'switchbuf' option to 'useopen'. With this
3613 setting, if a buffer is already opened in one of the windows, Vim will
3614 jump to that window, instead of creating a new window.
3615
3616 Help keyword(s): 'switchbuf'
3617
3618 23. What information is stored as part of a buffer?
3619 Every buffer in the buffer list contains information about the last
3620 cursor position, marks, jump list, etc.
3621
3622 24. What is the difference between deleting a buffer and unloading a
3623 buffer? When a buffer is unloaded, it is not removed from the buffer list.
3624 Only the file contents associated with the buffer are removed from memory.
3625 When a buffer is deleted, it is unloaded and removed from the buffer list.
3626 In Vim 6, a deleted buffer becomes an 'unlisted' buffer.
3627
3628 Help keyword(s): :bunload, :bdelete, :bwipeout, unlisted-buffer
3629
3630 25. Is it possible to configure Vim, by setting some option, to re-use the
3631 number of a deleted buffer for a new buffer? No. Vim will not re-use the
3632 buffer number of a deleted buffer for a new buffer. Vim will always assign
3633 the next sequential number for a new buffer. The buffer number assignment
3634 is implemented this way, so that you can always jump to a buffer using the
3635 same buffer number. One method to achieve buffer number reordering is to
3636 restart Vim. If you restart Vim, it will re-assign numbers sequentially
3637 to all the buffers in the buffer list (assuming you have properly set
3638 'viminfo' to save and restore the buffer list across vim sessions).
3639
3640 Help keyword(s): :buffers
3641
3642 26. What options do I need to set for a scratch (temporary) buffer?
3643 The following works only in Vim 6.0 and above. You can set the the
3644 following options to create a scratch (temporary) buffer:
3645
3646 :set buftype=nofile :set bufhidden=hide :setlocal noswapfile
3647
3648 This will create a buffer which is not associated with a file, which
3649 does not have a associated swap file and will be hidden when removed
3650 from a window.
3651
3652 Help keyword(s): special-buffers, 'buftype'
3653
3654 27. How do I prevent a buffer from being added to the buffer list?
3655 The following works only in Vim 6.0 and above. You can prevent a buffer
3656 from being added to the buffer list by resetting the 'buflisted' option.
3657
3658 :set nobuflisted
3659
3660 Help keyword(s): 'buflisted'
3661
3662 28. How do I determine whether a buffer is modified or not?
3663 There are several ways to find out whether a buffer is modified or not.
3664 The simplest way is to look at the status line or the title bar. If the
3665 displayed string contains a '+' character, then the buffer is modified.
3666 Another way is to check whether the 'modified' option is set or not.
3667 If 'modified' is set, then the buffer is modified. To check the value
3668 of modified, use
3669
3670 :set modified?
3671
3672 You can also explicitly set the 'modified' option to mark the buffer as
3673 modified like this:
3674
3675 :set modified
3676
3677 Help keyword(s): 'modified'
3678
3679 29. How can I prevent modifications to a buffer?
3680 The following works only in Vim 6.0 and above. You can prevent any
3681 modification to a buffer by re-setting the 'modifiable' option. To reset
3682 this option, use
3683
3684 :set nomodifiable
3685
3686 To again allow modifications to the buffer, use:
3687
3688 :set modifiable
3689
3690 Help keyword(s): 'modifiable'
3691
3692 30. How do I set options specific to the current buffer?
3693 The following works only in Vim 6.0 and above. You can set Vim options
3694 which are specific to a buffer using the "setlocal" command. For example,
3695
3696 :setlocal textwidth=70
3697
3698 This will set the 'textwidth' option to 70 only for the current buffer.
3699 All other buffers will have the default or the previous 'textwidth' value.
3700
3701 Help keyword(s): 'setlocal', local-options
3702
3703 31. How do I define mappings specific to the current buffer?
3704 The following works only in Vim 6.0 and above. You can define mappings
3705 specific to the current buffer by using the keyword "&lt;buffer&gt;"
3706 in the map command. For example,
3707
3708 :map &lt;buffer&gt; ,w /[.,;]&lt;CR&gt;
3709
3710 Help keyword(s): :map-local
3711
3712 32. How do I define abbreviations specific to the current buffer?
3713 The following works only in Vim 6.0 and above. You can define
3714 abbreviations specific to the current buffer by using the keyword
3715 "&lt;buffer&gt;" in the :abbreviate command. For example,
3716
3717 :abb &lt;buffer&gt; FF for (i = 0; i &lt; ; ++i)
3718
3719 Help keyword(s): :abbreviate-local
3720
3721 </pre></tip> </html> <Tip category="KVim"> <html><center>Remapping
3722 Alt, Ctrl and Caps in Win2k</center> <pre> <A
3723 HREF="http://vim.sf.net/tip_view.php?tip_id=136">http://vim.sf.net/tip_view.php?tip_id=136</A><BR>
3724
3725 Since I installed Win2K on my laptop, I had been unable to locate a utilitie
3726 that would simply enable me to remap my Crtl Alt and Caps the way I think they
3727 should be and the way they were until MS kill all competition in computing,
3728 that is Crtl on the left of the letter A, Alt to the left bottom of the
3729 letter Z and Caps approximately until the C.
3730
3731 After some research, I came across a tip posted here by juano@mindspring.com. I
3732 tried to make sense of it and then downloaded the MS scan keys map at the
3733 URL he mentionned.
3734
3735 Extrapolating his tip, I wrote this ASCI file that I named keys2000.reg :
3736
3737 Regedit4 [HKey_Local_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard
3738 Layout] "Scancode
3739 Map"=hex:00,00,00,00,00,00,00,00,04,00,00,00,3A,00,38,00,38,00,1D,00,1D,00,3A,00,00,00,00
3740
3741 Once you have saved this file, left click on it from Explorer and answer
3742 yes to the prompt "do you want to enter this into the registry".
3743
3744 Reboot and you are done.
3745
3746 A few explanations :04 stands for 3 remappings (Caps lock to Control, Control
3747 to Alt and Alt to Caps Lock) plus the closing one which is always required
3748 (1 remapping would require 02, 2 would require 03, and so on). 3A,00,38
3749 remaps Caps to Left Alt, 38,00,1D remaps Left Alt to Left Ctrl and 1D,00,3A
3750 remaps Left Ctrl to Caps Lock since 3A=Caps, 1D=Left Ctrl and 38=Left Alt.
3751
3752 Based on Juano tip and on this one, I believe a lot of remapping can be done
3753 as long as you keep the separators 00 and remember to add one to the number
3754 of remappings. What I do not know is how far you can extend this instruction
3755 without getting into trouble with the registry. At worst, if you keyboard does
3756 not behave as expected, go into the registry and delete this instruction (be
3757 careful here since it is easy to confuse this instruction with the Keyboard
3758 LayoutS (S for emphasis) which must not be deleted.
3759
3760 Again, thanks to Juano@mindspring.com who got me going and suggested I
3761 post my tip. Took me some time to retrieve the VIM Url but fortunately,
3762 I had printed his tip.
3763
3764 Regards
3765
3766 </pre></tip> </html> <Tip category="KVim">
3767 <html><center>automatically wrap left and right</center> <pre> <A
3768 HREF="http://vim.sf.net/tip_view.php?tip_id=137">http://vim.sf.net/tip_view.php?tip_id=137</A><BR>
3769
3770 I hate it when I hit left (or h) and my screen flickers. I want it to go up
3771 to the next line. Ditto fir right (or l). Below are two functions / mappings
3772 to help with that. I'm pretty sure that if you remove the &lt;silent&gt;,
3773 then it will work in 5.x...
3774
3775 nnoremap &lt;silent&gt; &lt;Left&gt; :call WrapLeft()&lt;cr&gt; nnoremap
3776 &lt;silent&gt; &lt;Right&gt; :call WrapRight()&lt;cr&gt;
3777
3778 nnoremap &lt;silent&gt; h :call WrapLeft()&lt;cr&gt; nnoremap
3779 &lt;silent&gt; l :call WrapRight()&lt;cr&gt;
3780
3781 function! WrapLeft()
3782 let col = col(".")
3783
3784 if 1 == col
3785 " don't wrap if we're on the first line if 1 == line(".")
3786 return
3787 endif normal! k$
3788 else
3789 normal! h
3790 endif
3791 endfunction
3792
3793 function! WrapRight()
3794 let col = col(".") if 1 != col("$")
3795 let col = col + 1
3796 endif
3797
3798 if col("$") == col
3799 " don't wrap if we're on the last line if line("$") == line(".")
3800 return
3801 endif normal! j1|
3802 else
3803 normal! l
3804 endif
3805 endfunction
3806
3807 </pre></tip> </html> <Tip category="KVim">
3808 <html><center>Getting name of the function</center> <pre> <A
3809 HREF="http://vim.sf.net/tip_view.php?tip_id=138">http://vim.sf.net/tip_view.php?tip_id=138</A><BR>
3810
3811 Hi All,
3812
3813 While browsing code one always needs to know which function you are currently
3814 looking. Getting the name is very painful when the functions are lengthy
3815 and you are currently browsing NOT near to the start of the function. You
3816 can get the function's name by using this simple mapping.
3817
3818 Just place this in your .vimrc.
3819
3820 map _F ma[[k"xyy`a:echo @x&lt;CR&gt;
3821
3822 now _F will display which function you are currently in.
3823
3824 Enjoy the power of Vim -Nitin Raut
3825
3826 PS: The working is as follows, mark the current line with a, jump to the
3827 previous '{' in the first column, go one line up, yank the line in register
3828 x, return to the mark a, echo the value of register x, which is the wanted
3829 function name.
3830
3831 </pre></tip> </html> <Tip category="KVim"> <html><center>=,
3832 LaTeX tables, declarations, etc</center> <pre> <A
3833 HREF="http://vim.sf.net/tip_view.php?tip_id=139">http://vim.sf.net/tip_view.php?tip_id=139</A><BR>
3834
3835 Check out
3836
3837 <A
3838 HREF="http://www.erols.com/astronaut/vim/textab.html">http://www.erols.com/astronaut/vim/textab.html</A><BR>
3839
3840 and see some examples of text alignment (its hopeless to do it here with
3841 proportional fonts). You'll be able to download textab source, a Windows-based
3842 textab executable, and a scriptfile containing a convenient interface
3843 (ttalign.vim). The textab program coupled with &lt;ttalign.vim&gt; lets you:
3844
3845 1. align C language statements on their = += -= /= etc symbols 2. align C
3846 language declararations: separate columns for types, *[, variable
3847 names, initializations (=), and comments (// or /* .. */)
3848 3. align C/C++ language comments (//, /* .. */) 4. align C/C++ language
3849 (ansi) function argument lists 5. align LaTeX tables on their && separators
3850 6. align HTML tables with &lt;/TD&gt;&lt;TD&gt; separators 7. align on
3851 several characters: &lt; ? : | @ ; (or modify them to handle whatever
3852 alignment characters you want)
3853
3854 </pre></tip> </html> <Tip category="KVim"> <html><center>tip
3855 using embedded perl interpreter</center> <pre> <A
3856 HREF="http://vim.sf.net/tip_view.php?tip_id=140">http://vim.sf.net/tip_view.php?tip_id=140</A><BR>
3857
3858 When writing scripts using the embedded interpreter available if vim has the
3859 +perl ore +perl/dyn on gives you access to this powerfull and FAST scripting
3860 language (especially fast compared to vim scripts) there are some gotchas.
3861
3862 First: never embed complex perl command in the body of a vim function this
3863 will be recompiled and evaled each time for a tremendous loss of time.instead
3864 to it like this
3865
3866 perl &lt;&lt; EOF sub mySub {
3867 #some usefull perl stuff
3868 } EOF
3869
3870 function! MyFunction perl mySub "an argument", "another" endfunction
3871
3872 to pass computed argument to your perl sub use the vim exec command
3873 function! MyFunction exec "perl mySub " . aLocalVar . ", " b:aBufferLocalVar
3874 endfunction
3875
3876 It may be very hard to debug your perl sub since the output of the perl
3877 compiler is somehow lost in the middle of nowhere and the debugger is not
3878 available. When a compilation error occurs in your sub definition you'll get
3879 an error message when you try to call it saying that the sub does not exists.
3880 One thing which I have found very usefull is to write a fake VIM module with
3881 stub methods which will allow you to use the command line perl interpretor
3882 to at least compile your program. You could make your stub smart enough to
3883 fake a vim and use the debugger. Here is a sample for such a fake module
3884 defining just those method which I was using.
3885
3886 package VIM; use diagnostics; use strict; sub VIM::Eval {
3887 $_ = shift;
3888
3889 print "Eval $_\n";
3890
3891 {
3892 return
3893 '^(?!!)([^\t]*)\t[^\t]*\t(.*);"\t([^\t]*)\tline:(\d*).*$'
3894 if (/g:TagsBase_pattern/); return $ARGV[0] if
3895 (/b:fileName/); return '$3' if (/g:TagsBase_typePar/);
3896 return '$1' if (/g:TagsBase_namePar/); return '$4' if
3897 (/g:TagsBase_linePar/); return 'Ta&gs' if (/s:menu_name/);
3898 return $ARGV[1] if (/g:TagsBase_groupByType/);
3899 die "unknown eval $_";
3900 }
3901 } sub VIM::Msg {
3902 my $msg = shift; print "MSG $msg\n";
3903 } sub VIM::DoCommand {
3904 my $package; my $filename; my $line;
3905 ($package, $filename, $line) = caller;
3906
3907 my $command = shift; print "at $filename $line\n"; print "DoCommand
3908 $command\n";
3909 } 1;
3910
3911 Then you can copy other your perl code in a separate file and add a use VIM;
3912 at the top and your set to debug.
3913
3914 Good Vimming good perling. Benoit PS: this tips are probably true for other
3915 scripting languages
3916
3917 </pre></tip> </html> <Tip category="KVim"> <html><center>Add
3918 your function heading with a keystroke</center> <pre> <A
3919 HREF="http://vim.sf.net/tip_view.php?tip_id=141">http://vim.sf.net/tip_view.php?tip_id=141</A><BR>
3920
3921 Below is a tip that the C/C++ Newbies may find interesting and handy to use.
3922 The following code will add a function heading and position your cursor just
3923 after Description so that one can document as one proceeds with code.
3924
3925 function FileHeading()
3926 let s:line=line(".") call
3927 setline(s:line,"/***************************************************")
3928 call append(s:line,"* Description - ") call append(s:line+1,"*
3929 Author - Mohit Kalra") call append(s:line+2,"* Date
3930 - ".strftime("%b %d %Y")) call append(s:line+3,"*
3931 *************************************************/") unlet s:line
3932 endfunction
3933
3934 imap &lt;F4&gt; &lt;esc&gt;mz:execute FileHeading()&lt;RET&gt;`zjA
3935
3936 Where &lt;esc&gt; stands for ^V+ESC and &lt;RET&gt; for ^V+ENTER
3937
3938 </pre></tip> </html> <Tip category="KVim"> <html><center>Automatic
3939 function end commenting for C++ and Java</center> <pre> <A
3940 HREF="http://vim.sf.net/tip_view.php?tip_id=142">http://vim.sf.net/tip_view.php?tip_id=142</A><BR>
3941
3942 Some people have a habit of adding the function name as a comment to the
3943 end of that function, if it is long, so that he/she knows which function the
3944 '}' ends. Here's a way to automate the process.
3945
3946 Use the following abbreviation: iab }// } // END:
3947 &lt;esc&gt;10h%$?\w\+\s*(&lt;cr&gt;"xy/\s*(&lt;cr&gt;/{&lt;cr&gt;:nohl&lt;cr&gt;%$"xpa
3948
3949 If you now end the function with '}//', the follwoing string will be
3950 automatically generated: '} //END: functionname'
3951
3952 </pre></tip> </html> <Tip category="KVim"> <html><center>Use
3953 of Vim folds for javadocs</center> <pre> <A
3954 HREF="http://vim.sf.net/tip_view.php?tip_id=143">http://vim.sf.net/tip_view.php?tip_id=143</A><BR>
3955
3956 Hi,
3957
3958 The fold-method marker can be effectively use to set the folds in your
3959 Java source. Define some marker and place it inside HTML comments &lt;!--
3960 xx --&gt;. This way, it does not affect the Javadocs generated without the
3961 necessity of a seprate comment line. e.g.
3962
3963 /**
3964 * &lt;!-- zz.FOLDSTART class AbcClass --&gt; * The class description.
3965 * ... */
3966 public class AbcClass {
3967
3968 /**
3969 * &lt;!-- method zz.FOLDSTART someMethod() --&gt; * Method description.
3970 */
3971 public void someMethod();
3972
3973 ...
3974
3975 } /* zz.END: AbcClass */
3976
3977 /* Put this at the end of your file */ /* vim:fdm=marker
3978 fmr=zz.FOLDSTART,zz.END fdl=2 fdc=2: */
3979
3980 Now, the files will be opened with the methods neatly folded. You can use
3981 "zR" to open all folds (or click on the "+" at the left column).
3982
3983 Sameer.
3984
3985 </pre></tip> </html> <Tip category="KVim"> <html><center>recording
3986 keystrokes by "q" for repested jobs</center> <pre> <A
3987 HREF="http://vim.sf.net/tip_view.php?tip_id=144">http://vim.sf.net/tip_view.php?tip_id=144</A><BR>
3988
3989 The most useful feature that I find in VIM is the "recording" feature (:help
3990 recording). I have used this to automatically insert function headers,
3991 re-indent lines, and convert some 34 source files into HTML.
3992
3993 This feature is most useful when you want to do some repeated jobs, which
3994 you cant do easily using ".". You can set about writing a function, define
3995 a mapping, etc, but then these things might take time. By recording, you
3996 can try out and find the actual keystrokes that does the job.
3997
3998 To start recording, press "q" in normal mode followed by any of "0-9a-z".
3999 This will start recording the keystrokes to the register you choose. You can
4000 also see the word "recording" in the status(?) line. You can start the key
4001 sequences that you want to record. You can go to insert mode and type if
4002 you want.
4003
4004 To stop recording, press "q" in the normal mode.
4005
4006 To playback your keystrokes, press "@" followed by the character you choose.
4007 Pressing "@@" will repeat the same again.
4008
4009 Sameer.
4010
4011 </pre></tip> </html> <Tip category="KVim"> <html><center>Changing
4012 DOS style end of line to UNIX, or vise-versa</center> <pre> <A
4013 HREF="http://vim.sf.net/tip_view.php?tip_id=145">http://vim.sf.net/tip_view.php?tip_id=145</A><BR>
4014
4015 Those of us doomed to work in both the Unix and Windows world have many times
4016 encountered files that were create/editted on systems other that the one
4017 we are on at the time of our edits. We can easily correct the dreaded '^M'
4018 at the end of our Unix lines, or make files have more than one line in DOS by:
4019
4020 To change from &lt;CR&gt;&lt;LF&gt; (DOS) to just &lt;LF&gt; (Unix): :set
4021 fileformat=unix :w
4022
4023 Or to change back the other way: :set fileformat=dos :w
4024
4025 It also works for Apple land: :set fileformat=mac :w
4026
4027 And to tell the difference: set statusline=%&lt;%f%h%m%r%=%{&ff}\ %l,%c%V\ %P
4028 ^^^^^ This shows what the
4029 current file's format is.
4030
4031 Happy Vimming!
4032
4033 </pre></tip> </html> <Tip category="KVim"> <html><center>opening
4034 multiple files from a single command-line</center> <pre> <A
4035 HREF="http://vim.sf.net/tip_view.php?tip_id=146">http://vim.sf.net/tip_view.php?tip_id=146</A><BR>
4036
4037 i use the :split command a lot -- both to open a second window containing
4038 the currently edited file and to edit a new file altogether (with the :split
4039 &lt;filename&gt; option). however, i also like to be able to edit more than
4040 one file and calling :sp multiple times is inconvenient. so, i created the
4041 following command, function and abbreviation:
4042
4043 function! Sp(...)
4044 if(a:0 == 0)
4045 sp
4046 else
4047 let i = a:0 while(i &gt; 0)
4048 execute 'let file = a:' . i execute 'sp ' . file
4049
4050 let i = i - 1
4051 endwhile
4052 endif
4053 endfunction com! -nargs=* -complete=file Sp call Sp(&lt;f-args&gt;) cab sp Sp
4054
4055 this retains the behaviour of :sp in that i can still type :sp (the
4056 abbreviation takes care of that). :Sp takes any number of files and opens
4057 them all up, one after the other.
4058
4059 the things i have noticed are that this causes 'sp' to be expanded to 'Sp'
4060 everywhere, even in search patterns. also, prepending 'vert' doesn't work.
4061 if there is interest, i'll do that.
4062
4063 </pre></tip> </html> <Tip category="KVim">
4064 <html><center>How to write a plugin</center> <pre> <A
4065 HREF="http://vim.sf.net/tip_view.php?tip_id=147">http://vim.sf.net/tip_view.php?tip_id=147</A><BR>
4066
4067 This tip gives a skeleton for writing a plugin; Vim's help files have plenty
4068 of details (:he plugin, :he write-plugin, :he plugin-details).
4069
4070 #
4071 ------------------------------------------------------------------------------
4072 # Exit when your app has already been loaded (or "compatible" mode set)
4073 if exists("loaded_YourAppName") || &cp
4074 finish
4075 endif
4076
4077 # Public Interface: # AppFunction: is a function you expect your users to
4078 call # PickAMap: some sequence of characters that will run your AppFunction #
4079 Repeat these three lines as needed for multiple functions which will # be used
4080 to provide an interface for the user if !hasmapto('&lt;Plug&gt;AppFunction')
4081 map &lt;unique&gt; &lt;Leader&gt;PickAMap &lt;Plug&gt;AppFunction
4082 endif
4083
4084 # Global Maps: # map &lt;silent&gt; &lt;unique&gt;
4085 &lt;script&gt; &lt;Plug&gt;AppFunction \ :set lz&lt;CR&gt;:call
4086 &lt;SID&gt;AppFunc&lt;CR&gt;:set nolz&lt;CR&gt;
4087
4088 #
4089 ------------------------------------------------------------------------------
4090
4091 # AppFunction: this function is available vi the &lt;Plug&gt;/&lt;script&gt;
4092 interface above fu! &lt;SID&gt;AppFunction() ..whatever..
4093
4094 # your script function can set up maps to internal functions
4095 nmap &lt;silent&gt; &lt;left&gt; :set lz&lt;CR&gt;:silent! call
4096 &lt;SID&gt;AppFunction2&lt;CR&gt;:set nolz&lt;CR&gt;
4097
4098 # your app can call functions in its own script and not worry about
4099 name # clashes by preceding those function names with &lt;SID&gt; call
4100 &lt;SID&gt;InternalAppFunction(...)
4101
4102 # or you could call it with call s:InternalAppFunction(...) endf #
4103 ------------------------------------------------------------------------------
4104
4105 # InternalAppFunction: this function cannot be called from outside the #
4106 script, and its name won't clash with whatever else the user has loaded
4107 fu! &lt;SID&gt;InternalAppFunction(...) ..whatever.. endf
4108
4109 #
4110 ------------------------------------------------------------------------------
4111
4112 Plugins are intended to be "drop into &lt;.vim/plugin&gt;" and work.
4113 The problem that the &lt;Plug&gt;, &lt;SID&gt;, etc stuff is intended to
4114 resolve: what to do about functions that have the same names in different
4115 plugins, and what to do about maps that use the same sequence of characters?
4116 The first problem is solved with &lt;SID&gt; (a script identifier number)
4117 that vim assigns: program with it and your users will be happier when your
4118 stuff works with all their other stuff. The second problem: what to about
4119 those maps is addressed with &lt;Plug&gt;, &lt;unique&gt;, etc. Basically
4120 the idea is: let the user know that there are clashes and don't overwrite
4121 previously existing maps. Use the user's preferred map-introducer sequence
4122 (I like the backslash, but there are many keyboards which make producing
4123 backslashes unpleasant, and those users usually prefer something else).
4124
4125 What I like to do is to have a pair of start/stop maps to reduce my impact
4126 on the namespace. When the starting map is used, it kicks off a starting
4127 function that introduces all the maps needed. When the stopping map is
4128 used, it not only removes the maps the starter made but restores any maps
4129 the user had had that would have clashed. I also use the start/stop pair
4130 of functions to set and restore options that cause my scripts difficulties.
4131
4132 Check out DrawIt.vim's SaveMap() function for a way to save user maps.
4133 Restoring maps with it is easy:
4134
4135 if b:restoremap != ""
4136 exe b:restoremap unlet b:restoremap
4137 endif
4138
4139 So you can see it sets up a string variable with all the maps that the user
4140 had that would have clashed with my application.
4141
4142 One final thing: if your application needs to share information between
4143 its various functions, see if you can use s:varname (a variable that only
4144 your script's functions can access) or b:varname (a variable that anything
4145 associated with the buffer your application is running with can access)
4146 instead of using global variables.
4147
4148 Good luck and happy Vimming!
4149
4150 </pre></tip> </html> <Tip category="KVim"> <html><center>Make
4151 great use of those homemade menus</center> <pre> <A
4152 HREF="http://vim.sf.net/tip_view.php?tip_id=148">http://vim.sf.net/tip_view.php?tip_id=148</A><BR>
4153
4154 Accidently discovered that using &lt;alt&gt;&lt;Menu Hotletter&gt;&lt;cr&gt;
4155 (e.g &lt;alt&gt;b&lt;cr&gt; - for the buffer menu) causes the menu to break
4156 out in a seperate window. Selecting the menu with the mouse and then hitting
4157 enter does not seem to do it.
4158
4159 I will have to learn to add hotletters to my menus now so that the mouse
4160 can take a break.
4161
4162 I am a total newbie with vim, but constantly amazed....
4163
4164 </pre></tip> </html> <Tip category="KVim"> <html><center>Automatically
4165 update your diff upon writing.</center> <pre> <A
4166 HREF="http://vim.sf.net/tip_view.php?tip_id=149">http://vim.sf.net/tip_view.php?tip_id=149</A><BR>
4167
4168 When trying to reconcile differences between files, and using the new 'diff'
4169 functionality in Vim 6.0 you may want to automatically update the differences
4170 as you are working along. A convienent time is when you write out either of
4171 the files you are diff'ing. This autocmd will take care of doing that for you.
4172
4173 " If doing a diff. Upon writing changes to file, automatically update the
4174 " differences au BufWritePost * if &diff ==
4175 1 au BufWritePost * :diffupdate au BufWritePost
4176 * endif
4177
4178 </pre></tip> </html> <Tip category="KVim"> <html><center>Generating
4179 a column of increasing numbers</center> <pre> <A
4180 HREF="http://vim.sf.net/tip_view.php?tip_id=150">http://vim.sf.net/tip_view.php?tip_id=150</A><BR>
4181
4182 You can use the "Visual Incrementing" script from
4183
4184 <A
4185 HREF="http://www.erols.com/astronaut/vim/index.html#VimFuncs">http://www.erols.com/astronaut/vim/index.html#VimFuncs</A><BR>
4186
4187 to convert a block of numbers selected via ctrl-v (visual block) into a
4188 column of increasing integers. Select the column, press :I&lt;CR&gt;, and
4189 the first line's number will be used as a starting value. Subsequent lines's
4190 numbers will be incremented by one.
4191
4192 If the ctrl-v block is "ragged right", which can happen when "$" is used to
4193 select the right hand side, the block will have spaces appended as needed
4194 to straighten it out. If the strlen of the count exceeds the visual-block
4195 allotment of spaces, then additional spaces will be inserted.
4196
4197 Example: Put cursor on topmost zero, select column with ctrl-v, then :I
4198
4199 vector[0]= 1; vector[0]= 1; vector[0]= 1; vector[1]= 1;
4200 vector[0]= 1; --&gt; vector[2]= 1; vector[0]= 1; vector[3]= 1;
4201 vector[0]= 1; vector[4]= 1;
4202
4203 This script works with both vim 5.7 (:so visincr.vim) or vim 6.0 (source it
4204 as for vim 5.7 or drop it into the .vim/plugin directory).
4205
4206 </pre></tip> </html> <Tip category="KVim">
4207 <html><center>an ascii table</center> <pre> <A
4208 HREF="http://vim.sf.net/tip_view.php?tip_id=151">http://vim.sf.net/tip_view.php?tip_id=151</A><BR>
4209
4210 There is an ascii table in the vim-help files, but it's hard to find. Thus,
4211 I shall give a pointer to it:
4212
4213 :help digraph-table
4214
4215 </pre></tip> </html> <Tip category="KVim"> <html><center>Dutch,
4216 English, German, Hungarian, and Yiddish</center> <pre> <A
4217 HREF="http://vim.sf.net/tip_view.php?tip_id=152">http://vim.sf.net/tip_view.php?tip_id=152</A><BR>
4218
4219 Under <A
4220 HREF="http://www.erols.com/astronaut/vim/index.html#vimlinks_scripts">http://www.erols.com/astronaut/vim/index.html#vimlinks_scripts</A><BR>
4221 are links to spelling checkers for Dutch, English, German, Hungarian,
4222 and Yiddish, all based on the original engspchk.vim. The spelling checker
4223 provides as-you-type spell checking; with vim6.0 it will avoid checking on
4224 partially typed words.
4225
4226 Provided are several maps:
4227
4228 \et : add word under cursor into database for just this file \es : save
4229 word under cursor into database (permanently) \en : move cursor to the
4230 next spelling error \ep : move cursor to the previous spelling error
4231 \ea : look for alternative spellings of word under cursor
4232
4233 To use \ea you will need agrep:
4234
4235 agrep source: <A
4236 HREF="ftp://sunsite.unc.edu/pub/Linux/utils/text/agrep-2.04.tar.Z">ftp://sunsite.unc.edu/pub/Linux/utils/text/agrep-2.04.tar.Z</A><BR>
4237 agrep Win exe: <A
4238 HREF="http://www.tgries.de/agrep">http://www.tgries.de/agrep</A><BR>
4239
4240 To use the spell checkers just source it in:
4241
4242 ex. so engspchk.vim
4243
4244 To read more about it see
4245
4246 <A
4247 HREF="http://www.erols.com/astronaut/vim/index.html#Spelling">http://www.erols.com/astronaut/vim/index.html#Spelling</A><BR>
4248
4249 </pre></tip> </html> <Tip category="KVim"> <html><center>Making
4250 Parenthesis And Brackets Handling Easier</center> <pre> <A
4251 HREF="http://vim.sf.net/tip_view.php?tip_id=153">http://vim.sf.net/tip_view.php?tip_id=153</A><BR>
4252
4253 1) ++++++++++++++++++++++++++ "Automatic" bracket setting
4254 +++++++++++++++++++++++++++++ 2) +++++++++++++ Further improvement of
4255 parenthesis/bracket expanding +++++++++++++++++ 3) ++++++++++++++++++++++++++++
4256 "Late" bracketing of text +++++++++++++++++++++++++++++ 4)
4257 +++++++++++++++++++++++++++++ Conclusion ++++++++++++++++++++++++++++++++++++++
4258 ++++
4259
4260 =======================================================================================
4261
4262 1) ++++++++++++++++++++++++++ "Automatic" bracket setting
4263 +++++++++++++++++++++++++++++
4264
4265 To automatically insert a closing parenthesis when typing an opening
4266 parenthesis you can insert the following simple mapping to your vimrc:
4267
4268 :inoremap ( ()&lt;ESC&gt;i
4269
4270 This ends up with the cursor between the opening and the closing parenthesis
4271 in insert mode.
4272
4273 You can apply this and the following tips, of course, with the kind of
4274 parenthesis/bracket character you want to, i.e. (, {, [, &lt; ..... and,
4275 pretty useful as well, quotation marks ",',.... (to be continued)
4276
4277 2) +++++++++++++++ Further improvement of parenthesis/bracket expanding
4278 ++++++++++++++++++
4279
4280 I you are ready with filling the parenthesis/brackets, you likely want to
4281 "escape" from the brackets again to continue coding. To make this pretty
4282 comfortable, I invented the following kind of mappings, which get out of
4283 the last expanded parenthesis/bracket, regardless of the actual type of it,
4284 and enter append mode again. I mapped this kind of "getaway" with CTRL_j,
4285 you may use your favorite keystroke with it.
4286
4287 ...
4288 :inoremap ( ()&lt;ESC&gt;:let leavechar=")"&lt;CR&gt;i :inoremap [
4289 []&lt;ESC&gt;:let leavechar="]"&lt;CR&gt;i
4290 ...
4291 :imap &lt;C-j&gt; &lt;ESC&gt;:exec "normal f" . leavechar&lt;CR&gt;a
4292
4293 Explanation: The variable "leavechar" contents the actual char which is to
4294 "escape" from.
4295
4296 3) ++++++++++++++++++++++++++++ "Late" bracketing of text
4297 +++++++++++++++++++++++++++++
4298
4299 Occasionally I later want already written text parts to put in parenthesis.
4300
4301 I use the following macro, which brackets previously visually selected text.
4302 I mapped it with _(.
4303
4304 :vnoremap _( &lt;ESC&gt;`&gt;a)&lt;ESC&gt;`&lt;i(&lt;ESC&gt;
4305
4306 Furthermore, a sort of mapping for bracketing a *single word* is conceivable.
4307 Because this is not as general like the kind of visual mode mapping, I use
4308 this kind of "word bracketing" only for surrounding the word right behind
4309 the cursor in insert mode with **. I use the following macro to "emphasize"
4310 the word i just typed, for newsgroup articles.
4311
4312 :imap _* &lt;Esc&gt;bi*&lt;Esc&gt;ea*&lt;Space&gt;
4313
4314 4) ++++++++++++++++++++++++++++++ Conclusion
4315 ++++++++++++++++++++++++++++++++++++++++++
4316
4317 Since I use these macros, I never caused a syntax error because of missing
4318 brackets, and furthermore I can quickly insert parenthesis and qutotes into
4319 code- and non-code files.
4320
4321 JH 04.11.2001
4322
4323 </pre></tip> </html> <Tip category="KVim"> <html><center>Mappings
4324 to facilitate the creation of text</center> <pre> <A
4325 HREF="http://vim.sf.net/tip_view.php?tip_id=154">http://vim.sf.net/tip_view.php?tip_id=154</A><BR>
4326
4327 " " Mappings to facilitate the creation of text " " Author: Suresh Govindachar
4328 sgovindachar@yahoo.com " Date: November 5, 2001 " " While typing text to
4329 create a document, I often end up hitting " &lt;Esc&gt;, issuing some commands
4330 (with or without ":") and getting back " to typing by issuing a command such
4331 as "i", "O", "s" etc. " " I looked into using "set insertmode" to speed
4332 up such actions, but " found that too confusing. " " I have come up with
4333 a set of mappings that have speeded up my process " of creating documents.
4334 I have saved these mappings in a file, named " FullScreenVI.vim, in vim's
4335 plugin directory. " " Perhaps you will find these mappings helpful too.
4336 " " Please send me feedback. "
4337
4338 "To allow overriding the Alt key set winaltkeys=no "To enable viewing messages
4339 from commands issued using the mappings presented here set cmdheight=2
4340
4341 "The fundamental mapping that makes full-screen editing possible imap
4342 &lt;A-o&gt; &lt;C-o&gt; imap &lt;A-;&gt; &lt;C-o&gt;:
4343
4344 "Basic motions imap &lt;A-h&gt; &lt;Left&gt; imap &lt;A-j&gt; &lt;Down&gt;
4345 imap &lt;A-k&gt; &lt;Up&gt; imap &lt;A-l&gt; &lt;Right&gt; imap &lt;A-f&gt;
4346 &lt;PageDown&gt; imap &lt;A-b&gt; &lt;PageUp&gt; imap &lt;A-^&gt;
4347 &lt;Home&gt; imap &lt;A-$&gt; &lt;End&gt;
4348
4349 "Numbers for repeats imap &lt;A-1&gt; &lt;C-o&gt;1 imap &lt;A-2&gt;
4350 &lt;C-o&gt;2 imap &lt;A-3&gt; &lt;C-o&gt;3 imap &lt;A-4&gt; &lt;C-o&gt;4
4351 imap &lt;A-5&gt; &lt;C-o&gt;5 imap &lt;A-6&gt; &lt;C-o&gt;6 imap &lt;A-7&gt;
4352 &lt;C-o&gt;7 imap &lt;A-8&gt; &lt;C-o&gt;8 imap &lt;A-9&gt; &lt;C-o&gt;9
4353
4354 "Basic searches imap &lt;A-/&gt; &lt;C-o&gt;/ imap &lt;A-*&gt; &lt;C-o&gt;*
4355 imap &lt;A-#&gt; &lt;C-o&gt;# imap &lt;A-n&gt; &lt;C-o&gt;n imap &lt;A-N&gt;
4356 &lt;C-o&gt;N
4357
4358 "Deleting imap &lt;A-x&gt; &lt;C-o&gt;x imap &lt;A-d&gt; &lt;C-o&gt;d imap
4359 &lt;A-D&gt; &lt;C-o&gt;D
4360
4361 "Yanking and putting imap &lt;A-y&gt; &lt;C-o&gt;y imap &lt;A-Y&gt;
4362 &lt;C-o&gt;Y imap &lt;A-p&gt; &lt;C-o&gt;p imap &lt;A-P&gt; &lt;C-o&gt;P
4363
4364 "Common prefixes: marking, matching etc. imap &lt;A-~&gt; &lt;C-o&gt;~
4365 imap &lt;A-m&gt; &lt;C-o&gt;m imap &lt;A-`&gt; &lt;C-o&gt;` imap &lt;A-"&gt;
4366 &lt;C-o&gt;" imap &lt;A-%&gt; &lt;C-o&gt;% imap &lt;A-h&gt; &lt;C-o&gt;:h
4367 imap &lt;A-s&gt; &lt;C-o&gt;:s
4368
4369 "Interacting with the 'outside' imap &lt;A-!&gt; &lt;C-o&gt;:! imap
4370 &lt;A-w&gt; &lt;C-o&gt;:w&lt;CR&gt; imap &lt;A-e&gt; &lt;C-o&gt;:e
4371
4372 "Other commands imap &lt;A-u&gt; &lt;C-o&gt;u imap &lt;A-.&gt; &lt;C-o&gt;.
4373
4374 </pre></tip> </html> <Tip category="KVim"> <html><center>Decompile
4375 Java .class files automatically</center> <pre> <A
4376 HREF="http://vim.sf.net/tip_view.php?tip_id=155">http://vim.sf.net/tip_view.php?tip_id=155</A><BR>
4377
4378 Here's a plugin to automatically decompile Java .class files as they're
4379 read in. Tweak the javap flags for what you want to see. I didn't post
4380 this as a script because it's too simple and it's really more useful for
4381 demonstrating how to read decompilable files (or other binary files that
4382 can be converted to text).
4383
4384 function s:ReadClass(dir, classname)
4385 execute "cd " . a:dir execute "0read !javap -c " . a:classname 1 setlocal
4386 readonly setlocal nomodified
4387 endfunction
4388
4389 autocmd BufReadCmd *.class
4390 \ call &lt;SID&gt;ReadClass(expand("&lt;afile&gt;:p:h"),
4391 expand("&lt;afile&gt;:t:r"))
4392
4393 </pre></tip> </html> <Tip category="KVim"> <html><center>describe
4394 &lt;table name&gt; from vim</center> <pre> <A
4395 HREF="http://vim.sf.net/tip_view.php?tip_id=156">http://vim.sf.net/tip_view.php?tip_id=156</A><BR>
4396
4397 i had some trouble with the sqlplus scripts (probably my fault). but it
4398 seemed a little heavy for what i need, usually all i want is a listing of
4399 the columns for a given table while i'm whipping on some sql inside vim.
4400
4401 so i wrote a bash script (describe)...
4402
4403 ~~~~~~~~~~~~~~~begin describe script #!/usr/bin/bash
4404
4405 f=aTempFile.sql u=&lt;uName&gt; p=&lt;pWord&gt; d=&lt;dBase&gt;
4406
4407 echo "/* describe for $1" echo "describe $1;" &gt; $f; echo "quit;"
4408 &gt;&gt; $f;
4409
4410 sqlplus -S $u/$p@$d @$f rm -f $f; echo " end describe for $1 */"
4411 ~~~~~~~~~~~~~~~end describe script
4412
4413 your path needs to include the script (as well as sqlplus), then from vim
4414 you can just type....
4415
4416 :r !describe &lt;tableName&gt;
4417
4418 and you get a listing of the table columns slammed into wherever your cursor
4419 was, complete with java/c comments
4420
4421 </pre></tip> </html> <Tip category="KVim">
4422 <html><center>Incredible new functionality</center> <pre> <A
4423 HREF="http://vim.sf.net/tip_view.php?tip_id=157">http://vim.sf.net/tip_view.php?tip_id=157</A><BR>
4424
4425 if you get away from vim and get any other editor that was built *after*
4426 1970....
4427
4428 </pre></tip> </html> <Tip category="KVim"> <html><center>Using
4429 Computer Modern TT as gvim font (Win32)</center> <pre> <A
4430 HREF="http://vim.sf.net/tip_view.php?tip_id=158">http://vim.sf.net/tip_view.php?tip_id=158</A><BR>
4431
4432 If you really like the Computer Modern typewriter font (as seen in most TeX
4433 distributions) you can use it as the font in gvim! (looks excellent with
4434 font smoothing turned on)
4435
4436 First, get hold of the free Blue Sky Type 1 PS versions of the CM fonts from
4437 your local CTAN mirror. Unpack to a suitable directory.
4438
4439 Next locate the cmtt8.pfb file and open it (in Vim, naturally ;) - find the
4440 line saying dup 32 /visiblespace put
4441
4442 and change it to dup 32 /space put
4443
4444 that is, inserting enough spaces to keep the file size exactly the same
4445 (IMPORTANT!)
4446
4447 Save the file in Mac format (:set fileformat=mac).
4448
4449 Now install the cmtt.pfm file - in Win9x/NT4, you'll need Adobe Type Manager
4450 (free download), but in Win2k, you can just drop the .pfm file into the
4451 Fonts folder.
4452
4453 Now in your _gvimrc: set guifont=CMTT8:h11:cSYMBOL
4454
4455 (use whatever height you like instead of h11)
4456
4457 ..and enjoy! It's the first scalable font I can bear to edit code in... %-)
4458
4459 </pre></tip> </html> <Tip category="KVim"> <html><center>Keystroke
4460 Saving Substituting and Searching</center> <pre> <A
4461 HREF="http://vim.sf.net/tip_view.php?tip_id=159">http://vim.sf.net/tip_view.php?tip_id=159</A><BR>
4462
4463 1) ++++++++++++++ Saving Keystrokes for common Searching
4464 and Substituting +++++++++++ --- a) Searching b) Substituting
4465 --------------------------------------------------- 2) ++++ Searching for
4466 resp. Substituting of the current word under the cursor ++++++ --- a) Searching
4467 b) Substituting ---------------------------------------------------
4468 3) ++ Searching and Substituting for an arbitrary visually
4469 selected part of text ++++ --- a) Searching b) Substituting
4470 ---------------------------------------------------
4471 4) ++++++++++++++++++++++++++++++++ Conclusion
4472 +++++++++++++++++++++++++++++++++++++
4473
4474 =====================================================================================
4475
4476 1) ++++++++++++++ Saving Keystrokes for common Substituting and Searching
4477 +++++++++++
4478
4479 a) Searching ............ Sorry, there is not much that can be saved for
4480 common Searching. It's just hitting /mypattern&lt;RETURN&gt;
4481
4482 b) Substituting ......... I think, common substitution requires pretty many
4483 keystrokes. So I use the following macro with my favorite substitution options:
4484
4485 :map &lt;F4&gt; :%s//gc&lt;Left&gt;&lt;Left&gt;&lt;Left&gt;
4486
4487 This ends up with the cursor after the first '/' in the
4488 commandline. To complete it, you only have to enter -&gt;
4489 myoldpattern/mynewpattern&lt;RETURN&gt;
4490
4491 Remark: I mapped it to &lt;F4&gt; (cause of tribute to the &lt;F4&gt; of
4492 the good old Norton Commander editor). You may map it where you want to.
4493
4494 2) ++++ Searching for resp. Substituting of the current word under the
4495 cursor ++++++
4496
4497 a) Searching ............ If you don't know how to look for the next
4498 occurence of the word under the cursor, you should *now* type :help * or
4499 :help star or refer to the tips vimtip #1 or vimtip #5 ((Tip within tip:
4500 To make your pattern more visible, look for :help hls))
4501
4502 b) Substituting ......... The following macro extends the one above with
4503 automatically inserting the current word under the cursor into the from -
4504 pattern of the :s command.
4505
4506 :map &lt;S-F4&gt;
4507 :%s/&lt;C-r&gt;&lt;C-w&gt;//gc&lt;Left&gt;&lt;Left&gt;&lt;Left&gt;
4508
4509 To complete it, just enter -&gt; mynewpattern&lt;RETURN&gt;
4510
4511 I use this i.e. for reliable and quickly renaming a variable in the entire
4512 buffer. I mapped it to Shift-&lt;F4&gt;. You may map it to the keystroke
4513 you want.
4514
4515 Explanation: CTRL-v+CTRL-w expands to the word under the cursor.
4516
4517 3) ++ Searching and Substituting for an arbitrary visually selected part of
4518 text ++++
4519
4520 If you want to look or substitute (for) an *arbritary* pattern (which
4521 already exists at least once in your text), the following 2 mappings do it
4522 for you. The advantage is that you dont have to type again or cut & paste
4523 the appropriate text but only have to visually select it.
4524
4525 a) Searching ...........
4526
4527 :vmap / y:execute "/".escape(@",'[]/\.*')&lt;CR&gt;
4528
4529 This immediately finds to the next occurence of the previously visually
4530 selected text.
4531
4532 b) Substituting .........
4533
4534 :vmap &lt;F4&gt; y:execute
4535 "%s/".escape(@",'[]/\')."//gc"&lt;Left&gt;&lt;Left&gt;&lt;Left&gt;&lt;Left&gt;
4536
4537 Again, as in the mapping in chapter 2), you just have to complete it by
4538 entering -&gt; mynewpattern&lt;RETURN&gt;
4539
4540 Explanation/Discussion: What both Substituting and Searching in this way
4541 generally does is: - *y*anking the selected text - Inserting the visually
4542 selected via adressing the '"' register with '@"' as a
4543 parameter of the escape() function going finally into the 'myoldpattern'
4544 part. The trickery problem is, if you have characters in your myoldpattern,
4545 which are regular expression chars, they are recognized and threated
4546 accordingly. That is most likely not what you wanted. To escape them, these
4547 chars have to be declared by the second parameter of the excape() function,
4548 which then escapes them with a backslash. The few characters above work
4549 for me. If you run into problems, you should check for additional regexp
4550 chars in your text, and try to escape them by adding them to the escape()
4551 function parameter.
4552
4553 4) ++++++++++++++++++++++++++++++++ Conclusion
4554 +++++++++++++++++++++++++++++++++++++
4555
4556 With the appropriate mappings in your vimrc you can save keystrokes when
4557 Searching or Substituting and avoid typing errors. That way, you can take
4558 lunch sooner
4559
4560 </pre></tip> </html> <Tip category="KVim">
4561 <html><center>Dutch spelling checker</center> <pre> <A
4562 HREF="http://vim.sf.net/tip_view.php?tip_id=161">http://vim.sf.net/tip_view.php?tip_id=161</A><BR>
4563
4564 Download at <A
4565 HREF="http://www.thomer.com/thomer/vi/nlspchk.vim.gz.">http://www.thomer.com/thomer/vi/nlspchk.vim.gz.</A><BR>
4566
4567 This sciript is based on Charles E. Campbell's English spelling checker script
4568 for ViM (<A HREF="http://users.erols.com/astronaut/vim/) and Piet Tutelaers'
4569 Dutch word list (http://www.ntg.nl/spell-nl-v5b/) using Thomas Köhler's
4570 script (http://jeanluc-picard.de/vim/gerspchk/create). In other words, I
4571 didn't do much.">http://users.erols.com/astronaut/vim/) and Piet Tutelaers'
4572 Dutch word list (http://www.ntg.nl/spell-nl-v5b/) using Thomas Köhler's
4573 script (http://jeanluc-picard.de/vim/gerspchk/create). In other words,
4574 I didn't do much.</A><BR>
4575
4576 </pre></tip> </html> <Tip category="KVim"> <html><center>write
4577 plugin with explorer like interfaces</center> <pre> <A
4578 HREF="http://vim.sf.net/tip_view.php?tip_id=162">http://vim.sf.net/tip_view.php?tip_id=162</A><BR>
4579
4580 Several plugins use a text base interface based on a special buffer, this
4581 is the case of the standard explorer plugin, several bufexplorer plugins,
4582 the option buffer and others... Here is a quick guide in how to do this
4583
4584 Writing a special buf script
4585 | using a special buffer is a common technic when writing
4586 Vim scripts, it is used by | explorer, bufexplorer,
4587 DirDiff... | I'm currently writing one for TagsBase.vim | <A
4588 HREF="http://vim.sourceforge.net/scripts/script.php?script_id=100
4589 ">http://vim.sourceforge.net/scripts/script.php?script_id=100 </A><BR>
4590 | and I'll use this document to take notes on how to do it. |
4591
4592 Setting up the buffer
4593 Opening the window TODO
4594
4595 Using a setup function
4596 Principle
4597 | we can use a specific function to open and setup
4598 the special buffer. s:SetupBuf()
4599 Setup Function advantage
4600 | since the command will be defined in the main
4601 script you | can use script local functions
4602 Using a special filetype
4603 Principle
4604 | we can also use a new filetype and distribute a
4605 syntax and an ftplugin for this | filetype, the only
4606 thing needed in this case is to set the | filetype
4607 after creating the buffer
4608 Filetype advantage
4609 | better separations of different parts of your
4610 script. If | the main function of your plugin is
4611 not to have this | special buffer then it is nice
4612 to avoid clutering it.
4613 Things which needs to be done to setup the buffer
4614 The buffer should not be listed and does not correspond to
4615 a file
4616 * setlocal buftype=nofile - options always local
4617 to buffer * set nobuflisted * set bufhidden=delete *
4618 set nomodifiable
4619 Setup the syntax for this buffer
4620 | see :help syntax | This is usually done in two
4621 steps, first describe the | syntax groups using :syn
4622 commands then setup the | hilighting using :hi def
4623 link commands. Usually it is | best to link the
4624 newly defined groups to predefine ones in | order
4625 to make the coloring work fine with colorschemes.
4626 | You'll find the list of predefined group by doing:
4627 | :help group-name
4628 Setup the special mappings
4629 | since we have chosen to use the set nomodifiable
4630 option | our buffer will never be in insert mode. All
4631 our mapping | are in Normal, Visual or operator
4632 pending, they should | therefore use the map, nmap,
4633 vmap and omap mapping command | plus the associated
4634 'nore' version. I usually find it | better to use the
4635 'nore' version to avoid surprises due to | mapping
4636 in the user configuration. | | We also want our
4637 mappings to be local to the special | buffer so all
4638 the commands will use the &lt;buffer&gt; modifier.
4639 | | Finally we want our mappings not to polute the
4640 status bar | so we use the &lt;silent&gt; modifier |
4641 | Putting all this together we end up with mapping
4642 commands | which look like: | noremap &lt;buffer&gt;
4643 &lt;silent&gt; {lhs} {rhs}
4644 Setup the special command
4645 | we will then setup special commands for this buffer.
4646 Like | for the mapping there are some precautions to
4647 take: | we don't want an error message if the command
4648 is defined | twice so we use the command! variant. |
4649 We want a command local to our buffer wo we use the |
4650 -buffer attribute. The rests of the command attributes
4651 | and options depend on the actual command. | So
4652 our commands look like: | command! -buffer {attr}
4653 {cmd} {rep} | where attr is optional.
4654
4655 </pre></tip> </html> <Tip category="KVim">
4656 <html><center>Toggle Search Highlighting</center> <pre> <A
4657 HREF="http://vim.sf.net/tip_view.php?tip_id=163">http://vim.sf.net/tip_view.php?tip_id=163</A><BR>
4658
4659 " Map H to toggle search highlighting map H :let &hlsearch =
4660 !&hlsearch&lt;CR&gt;
4661
4662 </pre></tip> </html> <Tip category="KVim"> <html><center>Make
4663 non-ASCII characters displayed on console</center> <pre> <A
4664 HREF="http://vim.sf.net/tip_view.php?tip_id=164">http://vim.sf.net/tip_view.php?tip_id=164</A><BR>
4665
4666 I had a problem with VIM on the FreeBSD console: it didn't display characters
4667 like German umlauts correctly, but escaped them with a tilde. The solution
4668 is to teach VIM about printable characters. I use the following on my .vimrc:
4669
4670 set isprint=@,128-255
4671
4672 </pre></tip> </html> <Tip category="KVim"> <html><center>Deleting
4673 a buffer without closing the window</center> <pre> <A
4674 HREF="http://vim.sf.net/tip_view.php?tip_id=165">http://vim.sf.net/tip_view.php?tip_id=165</A><BR>
4675
4676 I'm not sure if this functionality is already within Vim, but I sometimes I
4677 find it useful to keep a split window from closing when deleting a buffer.
4678 This has already been discussed on the vim@vim.org mailing list. However,
4679 I feel this solution is a little easier to use.
4680
4681 " Put this into .vimrc or make it a plugin. " Mapping :Bclose to some
4682 keystroke would probably be more useful. " I like the way buflisted()
4683 behaves, but some may like the behavior " of other buffer testing functions.
4684
4685 command! Bclose call &lt;SID&gt;BufcloseCloseIt()
4686
4687 function! &lt;SID&gt;BufcloseCloseIt()
4688 let l:currentBufNum = bufnr("%") let l:alternateBufNum = bufnr("#")
4689
4690 if buflisted(l:alternateBufNum)
4691 buffer #
4692 else
4693 bnext
4694 endif
4695
4696 if bufnr("%") == l:currentBufNum
4697 new
4698 endif
4699
4700 if buflisted(l:currentBufNum)
4701 execute("bdelete ".l:currentBufNum)
4702 endif
4703 endfunction
4704
4705 </pre></tip> </html> <Tip category="KVim"> <html><center>Mapping
4706 caps lock to esc in XWindows</center> <pre> <A
4707 HREF="http://vim.sf.net/tip_view.php?tip_id=166">http://vim.sf.net/tip_view.php?tip_id=166</A><BR>
4708
4709 (This originally appeared on the vim mailing list as post by Adam Monsen <A
4710 HREF="http://groups.yahoo.com/group/vim/message/19856)">http://groups.yahoo.com/group/vim/message/19856)</A><BR>
4711
4712 If you want to completely swap caps lock and escape, you have to replace
4713 the "Lock" on caps lock. Drop this file in your home dir:&lt;br&gt;
4714 -----------start------------&lt;br&gt; ! Swap caps lock and escape&lt;br&gt;
4715 remove Lock = Caps_Lock&lt;br&gt; keysym Escape = Caps_Lock&lt;br&gt;
4716 keysym Caps_Lock = Escape&lt;br&gt; add Lock = Caps_Lock&lt;br&gt;
4717 ------------end-------------&lt;br&gt; and call it ".speedswapper". Then
4718 open a terminal and type&lt;br&gt; $ xmodmap .speedswapper&lt;br&gt;
4719 and you'll be twice as efficient in vim. Who needs caps lock anyway? The
4720 swapping lasts for the duration of the X session, so you can put it in a
4721 .xinitrc or similar startup file. As far as other people using my laptop,
4722 I'd rather they didn't! Using a Dvorak layout might protect me even more... :)
4723
4724 </pre></tip> </html> <Tip category="KVim"> <html><center>Using
4725 vim as a man-page viewer under Unix</center> <pre> <A
4726 HREF="http://vim.sf.net/tip_view.php?tip_id=167">http://vim.sf.net/tip_view.php?tip_id=167</A><BR>
4727
4728 To use vim as a man-page viewer involves setting an environment variable:
4729
4730 sh, ksh: export MANPAGER="col -b | view -c 'set ft=man nomod nolist'
4731 -" csh : setenv MANPAGER "col -b | view -c 'set ft=man nomod nolist' -"
4732
4733 Put one of the above two lines into your &lt;.profile&gt; or &lt;.login&gt;
4734 file as appropriate for your shell.
4735
4736 The man pages will then be displayed with vim called as "view" and
4737 will use the &lt;man.vim&gt; syntax highlighting. I myself use some
4738 additional highlighting which is enabled by putting the following file into
4739 &lt;.vim/after/syntax/man.vim&gt;. I usually use the &lt;astronaut&gt;
4740 colorscheme (also available from this archive); those who use bright
4741 backgrounds may find the colors selected for manSubSectionStart and
4742 manSubSection something they'll want to change:
4743
4744 ---------------------------------------------------------------------
4745 " DrChip's additional &lt;man.vim&gt; stuff
4746
4747 syn match manSectionHeading "^\s\+[0-9]\+\.[0-9.]*\s\+[A-Z].*$"
4748 contains=manSectionNumber syn match manSectionNumber
4749 "^\s\+[0-9]\+\.[0-9]*" contained syn region manDQString
4750 start='[^a-zA-Z"]"[^", )]'lc=1 end='"' contains=manSQString
4751 syn region manSQString start="[ \t]'[^', )]"lc=1 end="'"
4752 syn region manSQString start="^'[^', )]"lc=1 end="'"
4753 syn region manBQString start="[^a-zA-Z`]`[^`, )]"lc=1 end="[`']"
4754 syn region manBQSQString start="``[^),']" end="''"
4755 syn match manBulletZone transparent "^\s\+o\s" contains=manBullet
4756 syn case match syn keyword manBullet contained o syn match manBullet
4757 contained "\[+*]" syn match manSubSectionStart "^\*" skipwhite
4758 nextgroup=manSubSection syn match manSubSection ".*$" contained
4759
4760 hi link manSectionNumber Number hi link manDQString String hi
4761 link manSQString String hi link manBQString String hi
4762 link manBQSQString String hi link manBullet Special hi
4763 manSubSectionStart term=NONE cterm=NONE gui=NONE ctermfg=black
4764 ctermbg=black guifg=navyblue guibg=navyblue hi manSubSection
4765 term=underline cterm=underline gui=underline ctermfg=green guifg=green set ts=8
4766 ---------------------------------------------------------------------
4767
4768
4769 </pre></tip> </html> <Tip category="KVim"> <html><center>Viewing
4770 the actual XPM data in GVIM</center> <pre> <A
4771 HREF="http://vim.sf.net/tip_view.php?tip_id=168">http://vim.sf.net/tip_view.php?tip_id=168</A><BR>
4772
4773 GVIM has an excellent syntax highlighting for XPM images, but sometimes
4774 it's useful to view the actual data. This can be achieved by searching for
4775 everything, type in "/." and all characters will be highlighted and therefore
4776 the old colouring is lost. To regain the normal highlighting you can search
4777 for a non-existent sequence, like "/foo".
4778
4779 </pre></tip> </html> <Tip category="KVim"> <html><center>&lt;Tab&gt;
4780 = &lt;C-I&gt; and &lt;Esc&gt; = &lt;C-[&gt;</center> <pre> <A
4781 HREF="http://vim.sf.net/tip_view.php?tip_id=169">http://vim.sf.net/tip_view.php?tip_id=169</A><BR>
4782
4783 An FAQ on the vim users' mailing list is whether &lt;Tab&gt; and
4784 &lt;C-I&gt;
4785 can be mapped to different things. The answer is no. As I understand it,
4786 this is a low level issue: &lt;Tab&gt; and &lt;C-I&gt; are different names
4787 for the same ASCII code, and there is no way for vim to tell them apart.
4788 Similarly, &lt;Esc&gt; and &lt;C-[&gt; are the same thing.
4789
4790 </pre></tip> </html> <Tip category="KVim"> <html><center>Repeating
4791 a sequence of commands without defining a macro</center> <pre> <A
4792 HREF="http://vim.sf.net/tip_view.php?tip_id=170">http://vim.sf.net/tip_view.php?tip_id=170</A><BR>
4793
4794 Imagine.
4795
4796 You have just finished a complicated modification of a file, involving
4797 numerous replace commands :%s/xxx/yyyy/g, and other ex commands.
4798
4799 Then you realize, you have done it a little bit wrong, and you have to begin
4800 all the operation again, just to change one replace string, or do one more
4801 operation "somewhere 10 commands ago".
4802
4803 Or you realize, you will have to do the same stuff tomorrow with another file.
4804
4805 or you realize, you want to perform the same sequence of commands, you have
4806 typed a few days ago
4807
4808 You should have made it a macro (normal command q), but you haven't.
4809
4810 Nothing is lost yet.
4811
4812 You go to the command line (by typing :) and press Ctrl+F. (Ctrl+F in other
4813 modes scrolls the screen)
4814
4815 You get a temporary window, listing the history of command line.
4816 It is possible to yank appropriate lines here, make a new file called
4817 $VIMRUNTIME/macros/something.vim put those lines here, edit them and save
4818
4819 see :help cedit
4820
4821 Then you can call the macro using :source something.vim
4822
4823 You might want to set variable 'history' to a higher number then default in
4824 your vimrc file like :set history=300 see :help history :help vimrc
4825
4826 </pre></tip> </html> <Tip category="KVim"> <html><center>Do
4827 you know the "g/" and "g?" commands?</center> <pre> <A
4828 HREF="http://vim.sf.net/tip_view.php?tip_id=171">http://vim.sf.net/tip_view.php?tip_id=171</A><BR>
4829
4830 Directly from the Vim Todo list:
4831
4832 7 For Visual mode: Command to do a search for the string in the marked area.
4833 Only when less than two lines. Use "g/" and "g?".
4834
4835 In other words, a way to search for visually selected text !! :-)
4836
4837 "==== vsearch.vim ====
4838
4839 " Visual mode search
4840
4841 vmap g/ :call VsearchPatternSave()&lt;cr&gt;/&lt;c-r&gt;/&lt;cr&gt; vmap
4842 g? :call VsearchPatternSave()&lt;cr&gt;?&lt;c-r&gt;/&lt;cr&gt;
4843
4844 function! VsearchPatternSave()
4845 let l:temp = @@ normal gvy let @/ = substitute(escape(@@, '/\'), "\n",
4846 "\\\\n", "g") let @@ = l:temp unlet l:temp
4847 endfunction
4848
4849 "==== END ====
4850
4851 Normally, this file should reside in the plugins directory and be
4852 automatically sourced. If not, you must manually source this file using
4853 ':source vsearch.vim'.
4854
4855 In Visual mode, highlight the text for searching. Then you can use the
4856 default visual key mappings
4857
4858 g/ - search forwards g? - search backwards
4859
4860 Visual searches behave like normal searches. The 'n' and 'N' commands
4861 work as they should, and the search history correctly records each search.
4862 Multi-line searches behave as they should (this corrects the 'yank-only'
4863 method mentioned in the Vim help files). Block visual searches do not
4864 work yet. Hopefully, someone can figure out a way to do this easily.
4865
4866 I've only tested this on Win2000 and Redhat Linux 7.1. I'm not really clear
4867 on how the carriage returns are dealt with on other systems.
4868
4869 Anyway, enjoy!
4870
4871 </pre></tip> </html> <Tip category="KVim"> <html><center>Using
4872 Ispell on a highlighted region</center> <pre> <A
4873 HREF="http://vim.sf.net/tip_view.php?tip_id=172">http://vim.sf.net/tip_view.php?tip_id=172</A><BR>
4874
4875 Suppose you would like to use Ispell to check a word or region that you've
4876 visually highlighted. The following macro will do the job. Just type
4877 Shift-Insert while in visual mode.
4878
4879 vnoremap &lt;S-Insert&gt; &lt;C-C&gt;`&lt;v`&gt;s&lt;Space&gt;&lt;Esc&gt;mq:e
4880 ispell.tmp&lt;CR&gt;i&lt;C-R&gt;"&lt;Esc&gt;:w&lt;CR&gt;:! xterm
4881 -bg ivory -fn 10x20 -e ispell %&lt;CR&gt;&lt;CR&gt;:e
4882 %&lt;CR&gt;&lt;CR&gt;ggVG&lt;Esc&gt;`&lt;v`&gt;s&lt;Esc&gt;:bwipeout!&lt;CR&gt;:!rm
4883 ispell.tmp*&lt;CR&gt;`q"_s&lt;C-R&gt;"&lt;Esc&gt;
4884
4885 This is based on Chip Campbell's macro which uses Ispell on the whole file
4886 (in normal mode).
4887
4888 noremap &lt;S-Insert&gt; :w&lt;CR&gt;:! xterm -bg ivory -fn 10x20 -e ispell
4889 %&lt;CR&gt;&lt;Space&gt;:e %&lt;CR&gt;&lt;Space&gt;
4890
4891 Carl Mueller
4892
4893 </pre></tip> </html> <Tip category="KVim"> <html><center>Switch
4894 between splits very fast (for multi-file editing)</center> <pre> <A
4895 HREF="http://vim.sf.net/tip_view.php?tip_id=173">http://vim.sf.net/tip_view.php?tip_id=173</A><BR>
4896
4897 I am a Web developer and I use Vim as my primary editor.
4898
4899 Most programming projects (and Web programming projects, in particular)
4900 are spread out over multiple files, which you often want to have open
4901 concurrently. If you don't already know, Vim supports this very well! Just use:
4902
4903 :sp name-of-another-file-to-edit
4904
4905 My problems were that (1) it took too long to move between files, and (2)
4906 the files were taking up too much room on the screen.
4907
4908 (1) In order to move to the file in the split above my current window, I was
4909 typing Ctrl-W, Up (move up a window) Ctrl-W, _ (maximize the menu). That's
4910 four keystrokes (more if you count Ctrl and Shift), and they are all over
4911 the keyboard. To help avoid this problem, I created this mapping in my .vimrc:
4912
4913 map &lt;C-J&gt; &lt;C-W&gt;j&lt;C-W&gt;_ map &lt;C-K&gt;
4914 &lt;C-W&gt;k&lt;C-W&gt;_
4915
4916 Now I can hold down Ctrl and move between windows with the standard Vim
4917 movement keys. Much, much quicker!
4918
4919 (2) By default, Vim displays the current line of each minimized file, which
4920 (to me) isn't much help and takes up too much screen real estate. I use this
4921 line in my .vimrc:
4922
4923 set wmh=0
4924
4925 This sets the minimum window height to 0, so you can stack many more files
4926 before things get crowded. Vim will only display the filename.
4927
4928 Hope this helps those of you who are working on projects with large numbers
4929 of files you're constantly flipping through. Happy Vimming!
4930
4931 </pre></tip> </html> <Tip category="KVim">
4932 <html><center>Footnotes</center> <pre> <A
4933 HREF="http://vim.sf.net/tip_view.php?tip_id=174">http://vim.sf.net/tip_view.php?tip_id=174</A><BR>
4934
4935 ab (1
4936 [1]&lt;esc&gt;:/^--\s/-1/&lt;cr&gt;o&lt;insert&gt;&lt;cr&gt;Footnotes:&lt;cr&gt;----------&lt;cr&gt;[1]
4937 ab (2 [2]&lt;esc&gt;:/^Footnotes\:/+2/&lt;cr&gt;o&lt;insert&gt;[2]
4938 ab (3 [3]&lt;esc&gt;:/^Footnotes\:/+3/&lt;cr&gt;o&lt;insert&gt;[3] ab
4939 (4 [4]&lt;esc&gt;:/^Footnotes\:/+4/&lt;cr&gt;o&lt;insert&gt;[4] ab (5
4940 [5]&lt;esc&gt;:/^Footnotes\:/+5/&lt;cr&gt;o&lt;insert&gt;[5]
4941
4942 </pre></tip> </html> <Tip category="KVim"> <html><center>how to make
4943 VIM as ur default editor even without root ac.</center> <pre> <A
4944 HREF="http://vim.sf.net/tip_view.php?tip_id=175">http://vim.sf.net/tip_view.php?tip_id=175</A><BR>
4945
4946 hi, if u have installed vim in your home directory somewhere and u don't have a
4947 root account, and you want to make VIM the default editor for anything u do.
4948 i.e if ur using SQLplus and want to edit a sql command. normally typing
4949 edit brings up the vi editor and not vim editor. to solve this problem.
4950 define these three variables in your .profile VIM=&lt;base directory where
4951 vim executable is placed&gt; VIMRUNTIME=&lt;base direcoty where vim runtimes
4952 are kept&gt; EDITOR=$VIM/vim
4953
4954 note if u have installed vim with another name, say vim.exe then change
4955 EDITOR=$VIM/vim to EDITOR=$VIM/vim.exe
4956
4957 source the .profile and viola. next time u start an editor from any program
4958 u have the vim editor.
4959
4960 Njoy.
4961
4962 </pre></tip> </html> <Tip category="KVim">
4963 <html><center>Autocheckout from perforce</center> <pre> <A
4964 HREF="http://vim.sf.net/tip_view.php?tip_id=176">http://vim.sf.net/tip_view.php?tip_id=176</A><BR>
4965
4966 The following code automatically checks out files from perforce when the
4967 user modifies them. It first confirms the check-out with the user.
4968
4969 (Perforce is a commercial version control system. I imagine this could be
4970 modified for RCS, CVS, etc., but I don't use those.)
4971
4972 I'm a vim newbie -- I've used vi since 1984, but just started with vim a couple
4973 days ago. Color me impressed! Please excuse any stupidity in the code..
4974
4975 Note that this function needs the "P4HOME" environment variable to be set.
4976 I could extract it by invoking "p4 client", but I don't want to invoke p4
4977 every time I start vim. So I assume the user sets it in the environment.
4978
4979 " Set a buffer-local variable to the perforce path, if this file is under
4980 the perforce root. function IsUnderPerforce()
4981 if exists("$P4HOME")
4982 if expand("%:p") =~ ("^" . $P4HOME)
4983 let b:p4path = substitute(expand("%:p"), $P4HOME, "//depot", "")
4984 endif
4985 endif
4986 endfunction " Confirm with the user, then checkout a file from perforce.
4987 function P4Checkout()
4988 if exists("b:p4path")
4989 if (confirm("Checkout from Perforce?", "&Yes\n&No", 1) == 1)
4990 call system("p4 edit " . b:p4path . " &gt; /dev/null") if
4991 v:shell_error == 0
4992 set noreadonly
4993 endif
4994 endif
4995 endif
4996 endfunction
4997
4998 if !exists("au_p4_cmd")
4999 let au_p4_cmd=1
5000
5001 au BufEnter * call IsUnderPerforce() au FileChangedRO * call P4Checkout()
5002 endif
5003
5004 </pre></tip> </html> <Tip category="KVim"> <html><center>Highlight
5005 matching brackets as one moves in normal mode (plugin)</center> <pre> <A
5006 HREF="http://vim.sf.net/tip_view.php?tip_id=177">http://vim.sf.net/tip_view.php?tip_id=177</A><BR>
5007
5008 Check out <A HREF="http://www.erols.com/astronaut/vim/index.html#VimFuncs
5009 for">http://www.erols.com/astronaut/vim/index.html#VimFuncs for</A><BR>
5010 a plugin script which highlights matching brackets. The script has two
5011 always-on maps:
5012 \[i : start [HiMtchBrkt] mode \[s : stop [HiMtchBrkt] mode
5013 The plugin will save all user maps and options that the plugin uses and will
5014 restore them when the mode is stopped.
5015
5016 </pre></tip> </html> <Tip category="KVim"> <html><center>Making
5017 a "derived" colorscheme without copy & paste</center> <pre> <A
5018 HREF="http://vim.sf.net/tip_view.php?tip_id=178">http://vim.sf.net/tip_view.php?tip_id=178</A><BR>
5019
5020 Suppose there's a colorscheme that you're pretty fond of, but hate one or
5021 two particular aspects about. For example, I love the "blue" colorscheme
5022 that ships with vim, but I find it's colors for the non-active status line
5023 to be unreadable. Here's how to create a colorscheme which extends "blue"
5024 without copying it to a new file and editing it.
5025
5026 In my ~/.vim/colors, I created a "my-blue.vim" file with these contents:
5027
5028 "these lines are suggested to be at the top of every colorscheme hi clear
5029 if exists("syntax_on")
5030 syntax reset
5031 endif
5032
5033 "Load the 'base' colorscheme - the one you want to alter runtime
5034 colors/blue.vim
5035
5036 "Override the name of the base colorscheme with the name of this custom one
5037 let g:colors_name = "my-blue"
5038
5039 "Clear the colors for any items that you don't like hi clear StatusLine hi
5040 clear StatusLineNC
5041
5042 "Set up your new & improved colors hi StatusLine guifg=black guibg=white hi
5043 StatusLineNC guifg=LightCyan guibg=blue gui=bold
5044
5045 That's all there is to it.
5046
5047 </pre></tip> </html> <Tip category="KVim">
5048 <html><center>Simplify help buffer navigation</center> <pre> <A
5049 HREF="http://vim.sf.net/tip_view.php?tip_id=179">http://vim.sf.net/tip_view.php?tip_id=179</A><BR>
5050
5051 Vim is distributed with comprehensive help system, which has basic hyperlink
5052 support - you can press &lt;C-]&gt; over |some subject| or 'some option'
5053 to read more about particular term.
5054
5055 The following mappings simplify help buffer navigation: pressing s(or S)
5056 will find next(previous) subject from cursor position pressing o(or O) will
5057 find next(previous) option from cursor position pressing Enter will jump to
5058 subject under cursor pressing Backspace will return from the last jump
5059
5060 Put them into help filetype plugin (like ~/.vim/ftplugin/help.vim on UNIX).
5061
5062 nmap &lt;buffer&gt; &lt;CR&gt; &lt;C-]&gt; nmap &lt;buffer&gt; &lt;BS&gt;
5063 &lt;C-T&gt; nmap &lt;buffer&gt; o /'[a-z]\{2,\}'&lt;CR&gt; nmap &lt;buffer&gt;
5064 O ?'[a-z]\{2,\}'&lt;CR&gt; nmap &lt;buffer&gt; s /\|\S\+\|&lt;CR&gt; nmap
5065 &lt;buffer&gt; S ?\|\S\+\|&lt;CR&gt;
5066
5067 </pre></tip> </html> <Tip category="KVim"> <html><center>Reload
5068 your filetype/syntax plugin</center> <pre> <A
5069 HREF="http://vim.sf.net/tip_view.php?tip_id=180">http://vim.sf.net/tip_view.php?tip_id=180</A><BR>
5070
5071 Ever tried to write/debug your own filetype/syntax plugin?
5072
5073 It's an iterative process which involves editing plugin code and testing it
5074 on some sample file. To see changes you made in your plugin simply do :e
5075 on sample file. This will force Vim to reload all buffer-specific files,
5076 including your plugin.
5077
5078 </pre></tip> </html> <Tip category="KVim">
5079 <html><center>get the vim patched source</center> <pre> <A
5080 HREF="http://vim.sf.net/tip_view.php?tip_id=181">http://vim.sf.net/tip_view.php?tip_id=181</A><BR>
5081
5082 Hi, there has been a number of person (including) asking in the vim list how
5083 to keep up with Bram's incredible bug correction and patch writing skills, but
5084 there is a great way to do this! Use the cvs source which is available at <A
5085 HREF="http://sourceforge.net/cvs/?group_id=8">http://sourceforge.net/cvs/?group_id=8</A><BR>
5086 it is kept up to date and its a lot easier than applying all the patch
5087 in order. Benoit
5088
5089 </pre></tip> </html> <Tip category="KVim"> <html><center>Keep
5090 your cursor centered vertically on the screen</center> <pre> <A
5091 HREF="http://vim.sf.net/tip_view.php?tip_id=182">http://vim.sf.net/tip_view.php?tip_id=182</A><BR>
5092
5093 i hope i don't hear a collective 'DUH!' from around the world but i just
5094 did this and i think it's kinda cool.
5095
5096 in your .vimrc add...
5097
5098 map j jzz map k kzz
5099
5100 so whenever you go up or down, vim does that and then re-centers. obviously it
5101 doesn't work when you page up/ down.
5102
5103 </pre></tip> </html> <Tip category="KVim"> <html><center>Select
5104 a buffer from those matching a pattern</center> <pre> <A
5105 HREF="http://vim.sf.net/tip_view.php?tip_id=183">http://vim.sf.net/tip_view.php?tip_id=183</A><BR>
5106
5107 The :bu command will take a pattern as an argument and jump to the matching
5108 buffer. However, it's not very helpful if there is more than one buffer
5109 matching the pattern. In that case, it will jump to the first match, which
5110 may not be what you want. The following function and user-command will
5111 print a list of the matching buffers in the command-line area, and allow
5112 you to select one of the matching buffers by number.
5113
5114 "Select from buffers matching a certain pattern "the 'pattern' argument
5115 shouldn't be prepended with a slash
5116
5117 function! BufSel(pattern)
5118 let bufcount = bufnr("$") let currbufnr = 1 while currbufnr &lt;= bufcount
5119 if(bufexists(currbufnr))
5120 let currbufname = bufname(currbufnr) if(match(currbufname, a:pattern)
5121 &gt; -1)
5122 echo currbufnr . ": ". bufname(currbufnr)
5123 endif
5124 endif let currbufnr = currbufnr + 1
5125 endwhile let desiredbufnr = input("Enter buffer number: ")
5126 if(strlen(desiredbufnr) != 0)
5127 exe ":bu ". desiredbufnr
5128 endif
5129 endfunction
5130
5131 "Bind the BufSel() function to a user-command command! -nargs=1 Bs :call
5132 BufSel("&lt;args&gt;")
5133
5134 </pre></tip> </html> <Tip category="KVim"> <html><center>How
5135 to obscure text instantaneously</center> <pre> <A
5136 HREF="http://vim.sf.net/tip_view.php?tip_id=184">http://vim.sf.net/tip_view.php?tip_id=184</A><BR>
5137
5138 Hi, Lets say your writing some imp. doc. and your colleague comes along. you
5139 don't wan't him to see what you are typing. so u start fumbling to type
5140 :wq! or switch with Alt-TAB. etc. but wouldn't it be nice to just obsucre the
5141 text temporarily, so that u don't have to quit or swith to another application
5142 using Alt-tab. (and if u don;t have any other window open u can;t even use
5143 alt-tab) well rot-13 comes to help. vim has a built in rot-13 encoder.
5144
5145 jut put the follwoing in your .vimrc
5146
5147 map &lt;F3&gt; ggVGg?
5148
5149 so next time some body comes along just press &lt;F3&gt; and all the buffer
5150 will be rot-13 encoded. to decode just press &lt;f3&gt; again. Njoy
5151
5152 </pre></tip> </html> <Tip category="KVim"> <html><center>Make vim the
5153 editor for files with unregistered extensions in Windows</center> <pre> <A
5154 HREF="http://vim.sf.net/tip_view.php?tip_id=185">http://vim.sf.net/tip_view.php?tip_id=185</A><BR>
5155
5156 Normally in Windows, if you try to "launch" a file whose extension is not
5157 registered with the system, the OS will prompt you for what editor you would
5158 like to use to open the file. A much more appealing solution, in my mind,
5159 is to make vim the default editor for any unregistered extension.
5160
5161 To set vim up as the default editor for unregistered extensions, follow
5162 these steps: 1. Copy the following into a file named unregistered.reg
5163 -------------begin unregistered.reg----------------- REGEDIT4
5164 [HKEY_CLASSES_ROOT\Unknown\shell\Open\Command] @="d:\\program
5165 files\\vim\\vim60\\gvim.exe \"%1\"" -------------end
5166 unregistered.reg-----------------
5167
5168 2. Import unregistered into your registry. This can be done in vim by
5169 executing the following :!regedit "unregistered.reg"
5170
5171 Disclaimer: This has been tested only on NT4.
5172
5173 </pre></tip> </html> <Tip category="KVim">
5174 <html><center>Making search powerful</center> <pre> <A
5175 HREF="http://vim.sf.net/tip_view.php?tip_id=186">http://vim.sf.net/tip_view.php?tip_id=186</A><BR>
5176
5177 My tip is just a bunch of mappings that can be used while searching.
5178
5179 </pre></tip> </html> <Tip category="KVim">
5180 <html><center>Making search powerful</center> <pre> <A
5181 HREF="http://vim.sf.net/tip_view.php?tip_id=187">http://vim.sf.net/tip_view.php?tip_id=187</A><BR>
5182
5183 (Sorry, I think I accidentally added an incomplete tip)
5184
5185 My tip is just a bunch of mappings that can be used while searching.
5186 What it does?
5187 o. Extend your current search. (kinda emacs search where you can search
5188 each occurences
5189 one by one and go back to the cursor position.
5190 o. Scroll/position during mapping. o. Other miscellaneous stuffs ;) read on
5191
5192 How to use?
5193 o. copy and paste the mappings into a file o. open vim (like vim .profile)
5194 o. :so &lt;saved-file&gt; o. start using the mappings
5195
5196 Note:
5197 In case these mappings dont work run like, 'vim -u NONE -U NONE -c
5198 "so the-saved-file.vim"'
5199
5200 Some of my mappings override the default vim bindings. (like Ctrl-A,
5201 Ctrl-Q). I selected those because, I feel by taking those I can do all
5202 the search stuff with my left hand.
5203
5204 One thing I did not like with this is, I usually miss the "search hit
5205 bottom" message. I could have handled that by complicating the current
5206 mappings, but I preferred to make it simple
5207
5208 Mappings Used / =&gt; regular forward search start ? =&gt;
5209 regular backward search start Rest of the mappings are used during search
5210 Ctrl-A =&gt; search again forward (In normal mode, search forward with
5211 the word under cursor) Ctrl-Q =&gt; search again backward (in normal mode,
5212 search backward with the word under cursor) Ctrl-X =&gt; restore cursor (use
5213 at any point of time/during-any-operation mentioned during searching) Ctrl-F
5214 =&gt; search with the word under cursor Ctrl-G =&gt; incrementally add the
5215 letters following the search pattern (in current line) Ctrl-T Ctrl-T =&gt;
5216 search for the exact Ctrl-T Ctrl-Y =&gt; search partial (just strips \&lt;
5217 and \&gt;) Ctrl-E =&gt; scroll up during searching Ctrl-Y =&gt; scroll down
5218 during searching Ctrl-Z Ctrl-Z =&gt; position the cursor to mid of screen
5219 (like zz in normal) Ctrl-Z Ctrl-A =&gt; position the cursor to top of screen
5220 (like zt in normal) Ctrl-Z Ctrl-X =&gt; position the cursor to bottom of
5221 screen (like zb in normal)
5222
5223 Misc: Ctrl-K during search save the current matching line Ctrl-K in normal
5224 mode pastes the saved line
5225
5226 C mappings Ctrl-V Ctrl-G search for the global variable of the search
5227 pattern/word under cursor Ctrl-V Ctrl-H search for the local variable of
5228 the search pattern/word under cursor
5229
5230 " --- cut n paste from here to end of document --- se nocp incsearch " core
5231 mappings noremap / mg/ noremap ? mg? ounmap / ounmap ? noremap &lt;C-A&gt;
5232 mg"gyiw/&lt;C-R&gt;g cnoremap &lt;C-A&gt; &lt;CR&gt;/&lt;Up&gt; cnoremap
5233 &lt;C-X&gt; &lt;CR&gt;`g cnoremap &lt;C-Q&gt; &lt;CR&gt;?&lt;Up&gt;
5234
5235 " extending current search mappings cnoremap &lt;C-F&gt;
5236 &lt;CR&gt;yiw&lt;BS&gt;/&lt;C-R&gt;" cnoremap &lt;C-G&gt;
5237 &lt;CR&gt;y/&lt;Up&gt;/e+1&lt;CR&gt;&lt;BS&gt;/&lt;C-R&gt;=escape(@",'.*\/?')&lt;CR&gt;
5238
5239 " miscellaneous: copy current line during search and later paste in NORMAL
5240 mode cnoremap &lt;C-K&gt; &lt;CR&gt;"hyy?&lt;Up&gt;&lt;CR&gt;/&lt;Up&gt;
5241 noremap &lt;C-K&gt; "hp
5242
5243 " exact/partial search mappings cnoremap &lt;C-T&gt;&lt;C-T&gt;
5244 &lt;Home&gt;\&lt;&lt;C-End&gt;\&gt; cnoremap &lt;C-T&gt;&lt;C-Y&gt;
5245 &lt;Home&gt;&lt;Del&gt;&lt;Del&gt;&lt;End&gt;&lt;Del&gt;&lt;Del&gt;
5246
5247 " C global/local variable search mappings noremap &lt;C-V&gt;&lt;C-G&gt;
5248 mgyiw&lt;CR&gt;gg/\&lt;&lt;C-R&gt;"\&gt; noremap &lt;C-V&gt;&lt;C-H&gt;
5249 mgyiw?^{&lt;CR&gt;/\&lt;&lt;C-R&gt;"\&gt; cnoremap &lt;C-V&gt;&lt;C-G&gt;
5250 &lt;CR&gt;yiwgg/\&lt;&lt;C-R&gt;"\&gt; cnoremap &lt;C-V&gt;&lt;C-H&gt;
5251 &lt;CR&gt;yiw?^{&lt;CR&gt;/\&lt;&lt;C-R&gt;"\&gt;
5252
5253 " positioning/scrolling during search mappings cnoremap &lt;C-E&gt;
5254 &lt;CR&gt;mt&lt;C-E&gt;`t&lt;BS&gt;/&lt;Up&gt; cnoremap &lt;C-Y&gt;
5255 &lt;CR&gt;&lt;C-Y&gt;&lt;BS&gt;/&lt;Up&gt; cnoremap &lt;C-Z&gt;&lt;C-A&gt;
5256 &lt;CR&gt;zt&lt;BS&gt;/&lt;Up&gt; cnoremap &lt;C-Z&gt;&lt;C-X&gt;
5257 &lt;CR&gt;zb&lt;BS&gt;/&lt;Up&gt; cnoremap &lt;C-Z&gt;&lt;C-Z&gt;
5258 &lt;CR&gt;zz&lt;BS&gt;/&lt;Up&gt;
5259
5260 " VISUAL mappings vnoremap / ymg/&lt;C-R&gt;=escape(@",'.*\/?')&lt;CR&gt;
5261 vnoremap ? ymg?&lt;C-R&gt;=escape(@",'.*\/?')&lt;CR&gt;
5262
5263 </pre></tip> </html> <Tip category="KVim"> <html><center>Searching
5264 for more than one word at the same time.</center> <pre> <A
5265 HREF="http://vim.sf.net/tip_view.php?tip_id=188">http://vim.sf.net/tip_view.php?tip_id=188</A><BR>
5266
5267 Did you know that with VIM u can search for more than one word with a single
5268 command. say you want to search all occurances of "bill" or "ted", or "harry"
5269 in a text. in normal mode do the following. /\(bill\)\|\(ted\)\|\(harry\)
5270 &lt;Enter&gt;
5271
5272 this will match all instances of either "bill", or "ted", or "harry" in your
5273 text. the key is the \(\) and \| operators. \(\) group characters in a word
5274 and \| is for ORing.
5275
5276 this is so cool u can even use it for replacing text. to replace all
5277 instances of "bill" or "ted" or "harry" with "greg" do the following
5278 :%s/\(bill\)\|\(ted\)\|\(harry\)/greg/g &lt;enter&gt; (note :- if u have
5279 set the option "gdefault" u don't need the "g" at the end of the above command)
5280
5281 I don't know of any other editor which can do this, with so much ease.
5282 Rock on VIM Njoy
5283
5284 </pre></tip> </html> <Tip category="KVim"> <html><center>Make
5285 Ctrl-Backspace delete previous word (like GTK inputs)</center> <pre> <A
5286 HREF="http://vim.sf.net/tip_view.php?tip_id=189">http://vim.sf.net/tip_view.php?tip_id=189</A><BR>
5287
5288 Stuff this into your ~/.gvimrc and then you'll be able to type
5289 Control-Backspace to delete the previous word. I had gotten so used to
5290 C-BS working a certain way in all my editors with a ceezy input area (like
5291 mozilla/galeon, gabber, etc...), that I wanted the same behaviour when I
5292 used gvim.
5293
5294 " map control-backspace to delete the previous word :imap &lt;C-BS&gt;
5295 &lt;Esc&gt;vBc
5296
5297 Simple, I know, but reasonably useful.
5298
5299 --Robert
5300
5301 </pre></tip> </html> <Tip category="KVim"> <html><center>XP &gt;
5302 I-Explorer &gt; HTML Editor &lt; REG files</center> <pre> <A
5303 HREF="http://vim.sf.net/tip_view.php?tip_id=190">http://vim.sf.net/tip_view.php?tip_id=190</A><BR>
5304
5305 The issue is permitting other programs, besides NOTEPAD, be the HTML editor
5306 under Internet Explorer. (Adding "Edit" as a New Action in the publicly
5307 exposed Files Types for HTM/L does NOT do the job.)
5308
5309 Given below are two REG files for vim. Just cut 'em up where indicated.
5310 They have been tested under Windows XP.
5311
5312 -------------------------------------------------------CUT HERE---------------
5313 Windows Registry Editor Version 5.00
5314
5315 ; GOAL: Set gvim as HTML editor in Internet Explorer 6.0 ; Vim version :
5316 6.0 ; Windows version: XP ; EASY USAGE: name this file iex-vim60.reg and
5317 double click on it ; Hard Usage: IMPORT this file using REGEDIT.EXE found
5318 in c:\WINDOWS ; Last modified date : Dec 16, 2001
5319
5320 ; gvim is expected in "C:\Program Files\Vim\vim60\gvim.exe" ; Be sure to
5321 also reset Explorer&gt;Tools&gt;Internet Options&gt;Programs
5322
5323 ; Microsoft documentation ; <A
5324 HREF="http://msdn.microsoft.com/workshop/browser/configuration/clientreg/clientregistrylayout.asp">http://msdn.microsoft.com/workshop/browser/configuration/clientreg/clientregistrylayout.asp</A><BR>
5325
5326 ; Add Vim in the list of supported HTML editors
5327 [HKEY_CLASSES_ROOT\.htm\OpenWithList\Vim]
5328
5329 [HKEY_CLASSES_ROOT\.htm\OpenWithList\Vim\shell]
5330
5331 [HKEY_CLASSES_ROOT\.htm\OpenWithList\Vim\shell\edit]
5332
5333 [HKEY_CLASSES_ROOT\.htm\OpenWithList\Vim\shell\edit\command] @="\"C:\\Program
5334 Files\\Vim\\vim60\\gvim.exe\" \"%1\""
5335
5336 ; Do NOT add to .html, registry for .htm type suffices
5337 ;[HKEY_CLASSES_ROOT\.html\OpenWithList\Vim]
5338
5339 ;[HKEY_CLASSES_ROOT\.html\OpenWithList\Vim\shell]
5340
5341 ;[HKEY_CLASSES_ROOT\.html\OpenWithList\Vim\shell\edit]
5342
5343 ;[HKEY_CLASSES_ROOT\.html\OpenWithList\Vim\shell\edit\command]
5344 ;@="\"C:\\Program Files\\Vim\\vim60\\gvim.exe\" \"%1\""
5345
5346 ; OPTIONAL: Within Internet Explorer "View Source" with gvim
5347 ; but prefer to use Edit button (got to add this) on Toolbar
5348 ;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source Editor]
5349
5350 ;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source
5351 Editor\Editor Name] ;@="C:\\Program Files\\Vim\\vim60\\gvim.exe"
5352
5353 ; ============================================= EOF
5354
5355 -------------------------------------------------------CUT HERE---------------
5356 Windows Registry Editor Version 5.00
5357
5358 ; GOAL: UNINSTALL gvim as HTML editor in Internet Explorer 6.0 ; Vim version :
5359 6.0 ; Windows version: XP ; EASY USAGE: name this file iex-vim60-uninstall.reg
5360 and double click on it ; Hard Usage: IMPORT this file using REGEDIT.EXE
5361 found in c:\WINDOWS ; Last modified date : Dec 16, 2001
5362
5363 ; gvim is expected in "C:\Program Files\Vim\vim60\gvim.exe" ; Be sure to
5364 also reset Explorer&gt;Tools&gt;Internet Options&gt;Programs
5365
5366 ; Microsoft documentation ; <A
5367 HREF="http://msdn.microsoft.com/workshop/browser/configuration/clientreg/clientregistrylayout.asp">http://msdn.microsoft.com/workshop/browser/configuration/clientreg/clientregistrylayout.asp</A><BR>
5368
5369 [-HKEY_CLASSES_ROOT\.htm\OpenWithList\Vim]
5370
5371 [-HKEY_CLASSES_ROOT\.html\OpenWithList\Vim]
5372
5373 [-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source Editor]
5374
5375 ; ============================================= EOF
5376 -------------------------------------------------------CUT HERE---------------
5377
5378 Happy Vimming...
5379
5380 </pre></tip> </html> <Tip category="KVim">
5381 <html><center>Transposing</center> <pre> <A
5382 HREF="http://vim.sf.net/tip_view.php?tip_id=191">http://vim.sf.net/tip_view.php?tip_id=191</A><BR>
5383
5384 You can easily move lines with these maps using &lt;C-Up&gt; and &lt;C-Down&gt;
5385 (only in GUI version :( ) (Works in normal, insert, and visual mode, but
5386 you can't add a count to them) " Transposing lines nmap &lt;C-Down&gt;
5387 :&lt;C-u&gt;move .+1&lt;CR&gt; nmap &lt;C-Up&gt; :&lt;C-u&gt;move .-2&lt;CR&gt;
5388
5389 imap &lt;C-Down&gt; &lt;C-o&gt;:&lt;C-u&gt;move .+1&lt;CR&gt; imap &lt;C-Up&gt;
5390 &lt;C-o&gt;:&lt;C-u&gt;move .-2&lt;CR&gt;
5391
5392 vmap &lt;C-Down&gt; :move '&gt;+1&lt;CR&gt;gv vmap &lt;C-Up&gt; :move
5393 '&lt;-2&lt;CR&gt;gv
5394
5395 " Transpose chars (like Ctrl-T in emacs, shell...) imap &lt;C-F&gt;
5396 &lt;Esc&gt;Xpa
5397
5398 </pre></tip> </html> <Tip category="KVim">
5399 <html><center>Latex Help for VIM</center> <pre> <A
5400 HREF="http://vim.sf.net/tip_view.php?tip_id=192">http://vim.sf.net/tip_view.php?tip_id=192</A><BR>
5401
5402 LaTeX Help for aucTeX `translated' as vim help file.
5403
5404 Installing
5405
5406 :help add-local-help
5407
5408 </pre></tip> </html> <Tip category="KVim"> <html><center>Insert
5409 the current filename at cursor postion.</center> <pre> <A
5410 HREF="http://vim.sf.net/tip_view.php?tip_id=193">http://vim.sf.net/tip_view.php?tip_id=193</A><BR>
5411
5412 I found this one good for when I was starting to learn Java, it simply inserts
5413 the current filename, at the cursor position, when you are in insert mode.
5414 Honestly, its a mish-mash of some other tips I found here, but I thought it
5415 might be useful.
5416
5417 imap \fn &lt;C-R&gt;=expand("%:t:r")&lt;CR&gt;
5418
5419 Enjoy!
5420
5421 </pre></tip> </html> <Tip category="KVim">
5422 <html><center>Inserting text in multiple lines</center> <pre> <A
5423 HREF="http://vim.sf.net/tip_view.php?tip_id=194">http://vim.sf.net/tip_view.php?tip_id=194</A><BR>
5424
5425 Do you know the I key in visual-block mode?
5426
5427 Suppose you have let a=2 let b=3 let c=4
5428
5429 You want to make these variables script-wise. Then you move to over a, hit
5430 &lt;C-v&gt;, press jj and now press I. You will be in insert mode before a
5431 Now enter s:&lt;Esc&gt;, and when you press &lt;Esc&gt;, b and c will have
5432 the s: prefix too. See |v_b_I|
5433
5434 Happy vimming! Gergely Kontra
5435
5436 </pre></tip> </html> <Tip category="KVim">
5437 <html><center>Switching between files</center> <pre> <A
5438 HREF="http://vim.sf.net/tip_view.php?tip_id=195">http://vim.sf.net/tip_view.php?tip_id=195</A><BR>
5439
5440 When you edit multiple files, you often need to change windows. You can set
5441 up vim in windows and gvim to switch between windows with the commonly used
5442 Ctrl-Tab and Ctrl-Shift-Tab The mappings nmap &lt;C-Tab&gt; &lt;C-w&gt;w
5443 nmap &lt;C-S-Tab&gt;&lt;C-w&gt;W (They wrap around) See also |Ctrl-w|
5444
5445 </pre></tip> </html> <Tip category="KVim"> <html><center>FileName
5446 Completion in Shell Scripts</center> <pre> <A
5447 HREF="http://vim.sf.net/tip_view.php?tip_id=196">http://vim.sf.net/tip_view.php?tip_id=196</A><BR>
5448
5449 In shell scripts, you often define environment variables for diff directory
5450 names. i.e. JAVA_HOME=/opt/java/jdk1.4 PATH=/usr/local/bin:/bin....
5451
5452 Normally typing Ctrl-X Ctrl-F is used to complete FileName under cursor.
5453 But this does not work if used on lines given above. This is because vim
5454 treats "=" sign as a valid filename character. Since the actual possibility
5455 of "=" being in any filename is very less, this char can be removed from
5456 the list of valid filename char.
5457
5458 set isfname-==
5459
5460 putting the above line in .vimrc will remove "=" from the list of valid
5461 filename chars. thus u can easyly complete filenames using &lt;Ctrl-X&gt;
5462 &lt;Ctrl-F&gt; Njoy
5463
5464 </pre></tip> </html> <Tip category="KVim"> <html><center>Open
5465 file in already running vim from elsewhere</center> <pre> <A
5466 HREF="http://vim.sf.net/tip_view.php?tip_id=197">http://vim.sf.net/tip_view.php?tip_id=197</A><BR>
5467
5468 If you want edit new file, and you want do it in alrady running vim,
5469 instead of launching another instance, you may use --remote argument:
5470
5471 gvim first_file gvim --remote +split first_file
5472
5473 :he --remote It requires X windows (but works in terminal version of vim
5474 there too) or MS windows and built-in client-server mechanism. If there are
5475 several instances of vim already running, you may choose to which you talk
5476 using --servername :help --servername
5477
5478 </pre></tip> </html> <Tip category="KVim"> <html><center>Pasting
5479 code with syntax coloring in emails</center> <pre> <A
5480 HREF="http://vim.sf.net/tip_view.php?tip_id=198">http://vim.sf.net/tip_view.php?tip_id=198</A><BR>
5481
5482 When sending code snippets or diffs to your colleagues either for code review
5483 or for something else as email, how nice and clear it will be if you can
5484 paste it with the Vim syntax highlighting? I am sure they will be impressed
5485 and feel much easier to read the code. It is also very easy and fast (once
5486 you practice it) to do this.
5487
5488 This probably works only on windows and requires you to use Internet Explorer
5489 and an email client that understand RTF content coming from clipboard, such
5490 as Outlook or Outlook Express. At least that would make the process faster. I
5491 haven't tried on any other combination though. This is what you need to do:
5492
5493 - Open the file containing the code/code snippet/diff etc. in gvim. If you
5494 use dark background for GVim (like me), then I would suggest you to change
5495 your color scheme temporarily to something else that has a white background
5496 or just use the "-U NONE" as below:
5497
5498 gvim -U NONE &lt;file&gt;
5499
5500 - Convert the file into HTML by using the following command at the colon
5501 prompt as below:
5502
5503 :runtime syntax/2html.vim
5504
5505 - The above step will open a new window with the HTML content in it. You might
5506 want to just save it with the suggested name or write into a temporary file as:
5507
5508 :w! c:/tmp/t.html
5509
5510 - Open the IE browser window and open the above temp file "c:/tmp/t.html".
5511 - Now you select all (press ^A) and copy it (^C). - You are ready to paste
5512 it with syntax coloring in any application that accepts RTF content from
5513 clipboard, including Outlook or Outlook Express mail composing window.
5514
5515 </pre></tip> </html> <Tip category="KVim"> <html><center>maximize
5516 window and return to previous split structure</center> <pre> <A
5517 HREF="http://vim.sf.net/tip_view.php?tip_id=199">http://vim.sf.net/tip_view.php?tip_id=199</A><BR>
5518
5519 Say you have layed out a complex window split structure, and want to
5520 temporarily open 1 window with max dimensions, but don't want to lose your
5521 split structure. The following function and mappings let you toggle between
5522 the split windows and on window maximized. The mappings prevent the default
5523 behavior of calling :only and losing your finely tuned splits.
5524
5525 Put this bit in your vimrc file, change mappings if you don't want to override
5526 the defaults:
5527
5528 nnoremap &lt;C-W&gt;O :call MaximizeToggle ()&lt;CR&gt; nnoremap &lt;C-W&gt;o
5529 :call MaximizeToggle ()&lt;CR&gt; nnoremap &lt;C-W&gt;&lt;C-O&gt; :call
5530 MaximizeToggle ()&lt;CR&gt;
5531
5532 function! MaximizeToggle()
5533 if exists("s:maximize_session")
5534 source s:maximize_session call delete(s:maximize_session)
5535 unlet s:maximize_session let &hidden=s:maximize_hidden_save
5536 unlet s:maximize_hidden_save
5537 else
5538 let s:maximize_hidden_save = &hidden let s:maximize_session =
5539 tempname() set hidden mksession! s:maximize_session only
5540 endif
5541 endfunction
5542
5543 </pre></tip> </html> <Tip category="KVim"> <html><center>Bouncing
5544 Parentheses (during insertion)</center> <pre> <A
5545 HREF="http://vim.sf.net/tip_view.php?tip_id=200">http://vim.sf.net/tip_view.php?tip_id=200</A><BR>
5546
5547 When one is inserting parentheses some folks like to see the cursor bounce
5548 off the matching parenthesis. To do that, put the following map into your
5549 &lt;.vimrc&gt; file:
5550
5551 inoremap ) )&lt;c-o&gt;%&lt;c-o&gt;:sleep
5552 500m&lt;CR&gt;&lt;c-o&gt;%&lt;c-o&gt;a
5553
5554 Adjust the time delay (its 500 milliseconds above) to suit your needs.
5555
5556 </pre></tip> </html> <Tip category="KVim">
5557 <html><center>The meaning of life</center> <pre> <A
5558 HREF="http://vim.sf.net/tip_view.php?tip_id=201">http://vim.sf.net/tip_view.php?tip_id=201</A><BR>
5559
5560 Use this tip if you need to discover the meaning of life, the universe
5561 and everything.
5562
5563 Simply do: :h 42
5564
5565 </pre></tip> </html> <Tip category="KVim">
5566 <html><center>debugging window autocommands</center> <pre> <A
5567 HREF="http://vim.sf.net/tip_view.php?tip_id=202">http://vim.sf.net/tip_view.php?tip_id=202</A><BR>
5568
5569 Don't know how people debug autocommands, but I just found out that you can
5570 debug (at least) those that result due to window close by just doing a debug
5571 quit, i.e.,
5572
5573 :debug quit
5574
5575 Vim will let you step into the autocommands. Try it to believe.
5576
5577 </pre></tip> </html> <Tip category="KVim">
5578 <html><center>Make make more helpful</center> <pre> <A
5579 HREF="http://vim.sf.net/tip_view.php?tip_id=203">http://vim.sf.net/tip_view.php?tip_id=203</A><BR>
5580
5581 I find this a very useful command to use. Add the below 4 lines to your vimrc.
5582 Then instead of "make" use "Make".
5583
5584 " Command Make will call make and then cwindow which " opens a 3 line error
5585 window if any errors are found. " if no errors, it closes any open cwindow.
5586 :command -nargs=* Make make &lt;args&gt; | cwindow 3
5587
5588 </pre></tip> </html> <Tip category="KVim"> <html><center>Some
5589 mappings for using cscope with vim.</center> <pre> <A
5590 HREF="http://vim.sf.net/tip_view.php?tip_id=204">http://vim.sf.net/tip_view.php?tip_id=204</A><BR>
5591
5592 These mappings can make using cscope a fun. You can copy the word under the
5593 cursor in one window, and search for it from other window.
5594
5595 " Copy and paste the word under cursor map &lt;silent&gt; &lt;C-Space&gt;
5596 :let@m=expand("&lt;cword&gt;")&lt;CR&gt;
5597
5598 " Use the C-Space word as the search criterion map &lt;C-F6&gt; :cscope
5599 find s &lt;C-R&gt;=@m&lt;CR&gt;&lt;CR&gt; map &lt;C-F5&gt; :cscope find
5600 c &lt;C-R&gt;=@m&lt;CR&gt;&lt;CR&gt; map &lt;C-F7&gt; :cscope find g
5601 &lt;C-R&gt;=@m&lt;CR&gt;&lt;CR&gt;
5602
5603 </pre></tip> </html> <Tip category="KVim">
5604 <html><center>Computing a sum of numbers in vim</center> <pre> <A
5605 HREF="http://vim.sf.net/tip_view.php?tip_id=205">http://vim.sf.net/tip_view.php?tip_id=205</A><BR>
5606
5607 "Sometimes you need to sum a some numbers in vim. There *are* some plugins
5608 "that can do the job. But what if the numbers are not in a columns or are on
5609 "the same line or are sacttered all across the file? You might also need to
5610 "sum all the numbers in file that look like '1234$', or '54565 Eu' ignoring
5611 others. " "There is a very simple trick, using (my favourite) command ":s "
5612 "First you define following function
5613
5614 :let g:S=0 "In global variable S we later find the result
5615
5616 :function! Sum(number) "The function is defined with a '!',
5617 "so it does not complain during debugging
5618 "when you are redefining the function
5619 :let g:S=g:S+a:number "we accumulate the result in global variable
5620 S :return a:number "function returns the argument, so after a :s
5621 "command the text remains the same
5622 :endfunction
5623
5624 "you can do issue those few commands from a command line, "or create a small
5625 file and put it into your plugin directory, "or write those few commands
5626 into a file end issue a command :so %
5627
5628 "how to use this little function: "let's suppose you have a simple
5629 column of numbers like " "10 "20 "30 " "you issue command like: :let S=0
5630 :%s/[0-9]\+/\=Sum(submatch(0))/ "the command finds the first number on the
5631 line and adds it to the S " "the result is displayed :echo $S
5632
5633 "!!!! don't forget to do :let g:S=0 "before use.
5634
5635 "you can also use \zs and \ze atoms in a regular expression to "delimit the
5636 number, so submatch(0) returns only a number and "the text remains unchanged
5637 after 'substitute'
5638
5639 "for starter on the wonderfull world of regular expressions see: :help
5640 usr_27.txt
5641
5642 "for the definition of the search pattern see :help :s :help pattern
5643
5644 "for replacement strings begining with \= and special function submatch(0)see
5645 :help sub-replace-special
5646
5647 "for the *ultimate* guide through the world of regular expressions see book:
5648 "Mastering Regular Expressions "Powerful Techniques for Perl and Other Tools
5649 "by Jeffrey E.F. Friedl "from O'REILLY
5650
5651 "the book does not write about vim, yet here you can learn that ":s command
5652 is the most powerfull command you can find in a text editor. "(with the
5653 possible exception of :global command)
5654
5655 </pre></tip> </html> <Tip category="KVim"> <html><center>Highlight
5656 doubled word errors in text</center> <pre> <A
5657 HREF="http://vim.sf.net/tip_view.php?tip_id=206">http://vim.sf.net/tip_view.php?tip_id=206</A><BR>
5658
5659 An error I sometimes make while working on a LaTeX file is the repetition of
5660 a word as in "the the". Most often, such doubled words come about through
5661 a careless edit. Doubled words are hard to spot when the first word of the
5662 doubled pair is the last word on one line, and the second word of the pair
5663 is the the first word on the next line. There is an example of such an error
5664 in the last sentence. Vim's syntax mechanism can be used to highlight doubled
5665 words as an error.
5666
5667 To obtain this highlighting for TeX and LaTeX files, place the following
5668 two lines:
5669
5670 syn match texDoubleWord "\c\&lt;\(\a\+\)\_s\+\1\&gt;" hi def link
5671 texDoubleWord Error
5672
5673 in a file called tex.vim in the directory that shows up last in your
5674 runtimepath (:set runtimepath? to check). This will often be either
5675 ~/.vim/after/syntax/tex.vim or $VIM/vimfiles/after/syntax/tex.vim
5676
5677 The same effect can be obtained for files of a different filetype, say html,
5678 by putting the same lines in a file called html.vim in the same location.
5679
5680 For more on the runtimepath, :he runtimepath. For more on syntax highlighting,
5681 :he syntax
5682
5683 </pre></tip> </html> <Tip category="KVim"> <html><center>editing
5684 databases with Vim/Perl/DBI</center> <pre> <A
5685 HREF="http://vim.sf.net/tip_view.php?tip_id=207">http://vim.sf.net/tip_view.php?tip_id=207</A><BR>
5686
5687 Perl's Data-Base-Independent (DBI) module provides programming language
5688 level access to a lot of databases.
5689
5690 Vim hosts an embedded Perl interpreter. So it is only a matter of some key
5691 strokes to interactively issue DB commands from within Vim or to search,
5692 edit, and replace database contents including retrieval and storage. Of course
5693 "create table" scripts can be worked upon in Vim as well as storing recurring
5694 patterns in Vim functions or Perl modules.
5695
5696 Prerequisites: Vim needs to be compiled with Perl support enabled. See the
5697 |if_perl.txt| manual page! The CPAN module DBI as well as an appropriate
5698 database driver has to be installed with Perl in order to execute these
5699 Vim commands:
5700
5701 " connect to perl's dbi module: :perl use dbi;
5702
5703 " connect to the database: :perl $dbh = dbi-&gt;connect(
5704 "DBI:mysql:$DBNAME:$HOST",$USER,$PASSWORD,
5705 { raiseerror =&gt; 1});
5706
5707 " perform a simple query: :perl $result = $dbh-&gt;selectall_arrayref("show
5708 tables;");
5709
5710 " insert the list of tables into the current buffer's top: :perl
5711 $curbuf-&gt;Append(0, map($_-&gt;[0], @{$result}));
5712
5713 In MySql the command "show tables;" results in a list of table names. Inserted
5714 into a Vim buffer this results in one line per table.
5715
5716 You can find more on my web page <A
5717 HREF="http://members.chello.at/intelliware/dbEdit">http://members.chello.at/intelliware/dbEdit</A><BR>
5718
5719 </pre></tip> </html> <Tip category="KVim"> <html><center>Alter
5720 the display of buffers in the buffers menu</center> <pre> <A
5721 HREF="http://vim.sf.net/tip_view.php?tip_id=208">http://vim.sf.net/tip_view.php?tip_id=208</A><BR>
5722
5723 If you use the buffers menu, here's where you can change how the buffernames
5724 are displayed:
5725
5726 menu.vim, function s:BMMunge
5727
5728 OLD: let name2 = name2 . ' (' . a:bnum . ')'
5729
5730 displays:
5731
5732 .vimrc (1) menu.vim (2)
5733
5734 NEW: let name2 = '&' . a:bnum . '. ' . name2
5735
5736 displays
5737
5738 1. .vimrc 2. menu.vim
5739 (with the 1 and the 2 underlined)
5740
5741 which is more useful, because you can (almost) always pick the buffer you
5742 want with one keystroke, the buffernumber, until you get to buffer 10 anyway.
5743
5744 Roger
5745
5746 </pre></tip> </html> <Tip category="KVim">
5747 <html><center>backtracking your movements in a file</center> <pre> <A
5748 HREF="http://vim.sf.net/tip_view.php?tip_id=209">http://vim.sf.net/tip_view.php?tip_id=209</A><BR>
5749
5750 If you are jumping from one line to another a lot. You may find the "Ctrl-o"
5751 command handy. Usually u can set markers in a buffer to keep track of your
5752 movements. but Ctrl-o makes it even easier. it takes you back sequentially
5753 to all your previous cursor locations in a buffer. just press ctrl-o in
5754 normal mode and u will go to your last cursor position.
5755
5756 Njoy
5757
5758 </pre></tip> </html> <Tip category="KVim">
5759 <html><center>compiling the actual file with gcc</center> <pre> <A
5760 HREF="http://vim.sf.net/tip_view.php?tip_id=210">http://vim.sf.net/tip_view.php?tip_id=210</A><BR>
5761
5762 if you use set makeprg=gcc\ -o\ %&lt;\ % in your .vimrc, and your actual
5763 file is file.c, then :make will compile file.c with the output file. (gcc
5764 file.c -o file).
5765
5766 </pre></tip> </html> <Tip category="KVim">
5767 <html><center>Rotate color themes</center> <pre> <A
5768 HREF="http://vim.sf.net/tip_view.php?tip_id=211">http://vim.sf.net/tip_view.php?tip_id=211</A><BR>
5769
5770 This tip is for those who like to change their vim color themes pretty often.
5771 I like different themes just for a change in my work environment. To achieve
5772 this just add the following to your .vimrc or _vimrc file.
5773
5774 let themeindex=0 function! RotateColorTheme()
5775 let y = -1 while y == -1
5776 let colorstring =
5777 "#blue.vim#elflord.vim#evening.vim#koehler.vim#murphy.vim#pablo.vim#ron.vim#"
5778 let x = match(colorstring,"#",g:themeindex) let y =
5779 match(colorstring,"#",x+1) let g:themeindex = x+1 ":echo x
5780 y g:themeindex if y == -1
5781 let g:themeindex = 0
5782 else
5783 let themestring = strpart(colorstring,x+1,y-x-1)
5784 echo("Setting Theme to-&gt; ".themestring) return
5785 ":so $VIMRUNTIME/colors/".themestring
5786 endif
5787 endwhile
5788 endfunction
5789
5790 Change the value of colorstring above by changing the line let colorstring =
5791 "#blue.vim#elflord.vim#evening.vim#koehler.vim#murphy.vim#pablo.vim#ron.vim#"
5792 You can add your favorite color themes in this string so that you can rotate
5793 between them. Just make sure that any string that you add is in between the #
5794 as shown above. Just follow the format above and things will work.
5795
5796 Then assign a key to roate the theme. map &lt;F8&gt; :execute
5797 RotateColorTheme()
5798
5799 Dunno if there are better ways to do the same. I just did a "help eval"
5800 and wrote the above.
5801
5802 </pre></tip> </html> <Tip category="KVim"> <html><center>Setting
5803 file attributes without reloading a buffer</center> <pre> <A
5804 HREF="http://vim.sf.net/tip_view.php?tip_id=212">http://vim.sf.net/tip_view.php?tip_id=212</A><BR>
5805
5806 While creating scripts and others executable files with Vim it is needed to
5807 set UNIX executable bit on the file. You can do this from inside Vim with
5808 :!chmod a+x %. The % represents current buffer's filename. The problem is
5809 that Vim will notice attribute changes and prompt you to reload a file. If
5810 you do this, your undo history for the file will be lost.
5811
5812 The following function facilitate changing executable attributes without
5813 reloading a buffer. Thanks to Bram for the algorithm for this function.
5814
5815 fun! SetExecutableBit()
5816 let fname = expand("%:p") :checktime exec "au FileChangedShell
5817 " . fname . " :echo" :silent !chmod a+x % :checktime exec
5818 "au! FileChangedShell " . fname
5819 endfun
5820
5821 " Create an EX command that will call the function. command -nargs=0 Xbit
5822 call SetExecutableBit()
5823
5824 Now you can type :Xbit to make the file executable!
5825
5826 </pre></tip> </html> <Tip category="KVim">
5827 <html><center>delet all lines containt TXT</center> <pre> <A
5828 HREF="http://vim.sf.net/tip_view.php?tip_id=213">http://vim.sf.net/tip_view.php?tip_id=213</A><BR>
5829
5830 I needed this one when I was editing an ldif file:
5831
5832 I needed to delete all lines containing "profile":
5833
5834 :g/profile/d
5835
5836 very handydandy
5837
5838 </pre></tip> </html> <Tip category="KVim">
5839 <html><center>Current buffer based menus</center> <pre> <A
5840 HREF="http://vim.sf.net/tip_view.php?tip_id=214">http://vim.sf.net/tip_view.php?tip_id=214</A><BR>
5841
5842 If you have different menus for different filetypes, and you want to have
5843 only the menu relevant to current buffer displayed, you can use this approach:
5844
5845 in .vimrc: au BufEnter * if exists('b:BuffEnter')|exec b:BuffEnter|endif au
5846 BufLeave * if exists('b:BuffEnter')|exec b:BuffLeave|endif
5847
5848 In appropriate ftplugin/?.vim, there are assigned commands to create or
5849 destroy the menus - here typed in directly, may be of course call to a
5850 menu-generating function or whatever.
5851
5852 let b:BuffEnter='amenu C.added ...' let b:BuffLeave='unmenu! C|unmenu C'
5853
5854 </pre></tip> </html> <Tip category="KVim"> <html><center>Edit
5855 configuration files for a filetype</center> <pre> <A
5856 HREF="http://vim.sf.net/tip_view.php?tip_id=215">http://vim.sf.net/tip_view.php?tip_id=215</A><BR>
5857
5858 When you open a file, vim may load several scripts to customize itself for
5859 editing the file type the file is associated with (for example a file "test.c"
5860 is associated with the filetype "c"). Such configurations include the setting
5861 of syntax highlighting colors (:help syntax) and support for indentation
5862 (:help filetype-indent-on). When you start to override these files for
5863 yourself, it can sometimes be confusing, which file sets a specific option.
5864 The following function can be used, to edit the configuration files which
5865 are associated with a specific filename. It open a buffer for all files which
5866 get loaded. If I invoke it with ':call Edit_ft_conf("test.c")', for example,
5867 I end up with the following buffers / windows:
5868 1 a "[No File]" line 1 2 a "test.c"
5869 line 1 3 a= "/usr/local/share/vim/vim60/syntax/c.vim"
5870 line 1 4 a "~/.vim/after/syntax/c.vim" line 1 5 #a=
5871 "/usr/local/share/vim/vim60/indent/c.vim" line 1 6 %a=
5872 "/usr/local/share/vim/vim60/ftplugin/c.vim" line 1
5873
5874 Here comes the function:
5875
5876 " Edit filetype configuration files " Usage: ':call Edit_ft_conf("file")'
5877 " Purpose: open all scripts which get loaded implicitly by opening "file" "
5878 (syntax highlighting, indentation, filetype plugins, ..) " The order of
5879 windows reflects the order of script loading (but "file" is " the topmost
5880 window) fun! Edit_ft_conf(name)
5881 " we may not do this with a loaded file, since this won't trigger the
5882 " configuration file loading as desired. " try calling with 'call
5883 Edit_ft_conf("nonexistingfile.&lt;EXT&gt;")' if this " gives you troubles
5884 if bufexists(a:name) && bufloaded(a:name)
5885 echo "!Attention: buffer for " . a:name . " is loaded, unload first."
5886 return
5887 endif " split-open the file with verbose set, grab the output into a
5888 register " (without clobbering) let safereg = @u redir @u " redirect
5889 command output to register @u exec "silent 2verbose split " . a:name
5890 " verbose level 2 suffices to catch all scripts which get opened
5891 redir END " Parse register @u, looking for smth like:
5892 'sourcing"/usr/local/share/vim/vim60/syntax/c.vim"' let pos = 0 let
5893 regexp = 'sourcing "[^"]\+"' while match(@u,regexp,pos) &gt;= 0
5894 let file = matchstr(@u,regexp,pos) let pos = matchend (@u,regexp,pos)
5895 let file = strpart(file,10,strlen(file)-11) exec "silent below split
5896 " . file
5897 endwhile " restore the register let @u = safereg
5898 endfun
5899
5900 </pre></tip> </html> <Tip category="KVim"> <html><center>calculate
5901 equations from within vim</center> <pre> <A
5902 HREF="http://vim.sf.net/tip_view.php?tip_id=216">http://vim.sf.net/tip_view.php?tip_id=216</A><BR>
5903
5904 The following map and function calculates equations using the program 'bc'
5905 (found on most linux systems, available for most systems). Visually select the
5906 equation you want to calculate, then hit ;bc - if the selection ends with an
5907 '=' sign, the answer will be appended after the equal, otherwise, the answer
5908 is echoed as a message. The code to put in a vimrc and source is at the end.
5909
5910 Equations can span multiple lines, and the full bc syntax is probably
5911 supported. Additionally, sin (), cos (), etc, are transformed into the
5912 names used by bc (s () c (), etc).
5913
5914 Here are some example lines:
5915
5916 2 * sqrt (2) =
5917
5918 3 * (2 - 1) + 4.0 ^ 6 =
5919
5920 4 / 3 =
5921
5922 3 +
5923 4 -
5924 2 * (1 / (3 + 2)) =
5925
5926 define rad (x) {
5927 return (x / 180) * 4 * atan (1)
5928 } cos (rad (45)) =
5929
5930 Select each of these in turn (continguous non-blank lines, and hit ;bc for
5931 each), and this is what you get: 2 * sqrt (2) = 2.82842712474619009760
5932
5933 3 * (2 - 1) + 4.0 ^ 6 = 4099.000000
5934
5935 4 / 3 = 1.33333333333333333333
5936
5937 3 +
5938 4 -
5939 2 * (1 / (3 + 2)) = 6.60000000000000000000
5940
5941 define rad (x) {
5942 return (x / 180) * 4 * atan (1)
5943 } cos (rad (45)) = .70710678118654752440
5944
5945 Fun, no? Here is the code you need to put in your vimrc file:
5946
5947 vnoremap ;bc "ey:call CalcBC()&lt;CR&gt; function! CalcBC()
5948 let has_equal = 0
5949
5950 " remove newlines and trailing spaces let @e = substitute (@e, "\n",
5951 "", "g") let @e = substitute (@e, '\s*$', "", "g")
5952
5953 " if we end with an equal, strip, and remember for output if @e =~ "=$"
5954 let @e = substitute (@e, '=$', "", "") let has_equal = 1
5955 endif
5956
5957 " sub common func names for bc equivalent let @e = substitute (@e,
5958 '\csin\s*(', "s (", "") let @e = substitute (@e, '\ccos\s*(', "c
5959 (", "") let @e = substitute (@e, '\catan\s*(', "a (", "") let @e =
5960 substitute (@e, "\cln\s*(", "l (", "")
5961
5962 " escape chars for shell let @e = escape (@e, '*()')
5963
5964 " run bc, strip newline let answer = substitute (system ("echo "
5965 . @e . " \| bc -l"), "\n", "", "")
5966
5967 " append answer or echo if has_equal == 1
5968 normal `&gt; exec "normal a" . answer
5969 else
5970 echo "answer = " . answer
5971 endif
5972 endfunction
5973
5974 </pre></tip> </html> <Tip category="KVim"> <html><center>Translate
5975 &#nnn; in html source to readable ascii</center> <pre> <A
5976 HREF="http://vim.sf.net/tip_view.php?tip_id=217">http://vim.sf.net/tip_view.php?tip_id=217</A><BR>
5977
5978 I found a website *cough*Tivoli.com*cough* that likes to obfuscate some of
5979 its help file web pages using &#nnn; instead of normal ascii. If you load
5980 the source with Vim (in Opera you can just designate Vim as your source
5981 viewing program), you can :so the following code to make it readable.
5982
5983 let n = 32 while n &lt; 127
5984 if n == 38
5985 silent! exec '%s/&#38;/\&amp;/g'
5986 elseif n == 47
5987 silent! exec '%s/&#47;/\//g'
5988 else
5989 silent! exec '%s/&#' . n . ';/' . nr2char(n) . '/g'
5990 endif let n = n + 1
5991 endwhile
5992
5993 Disclaimer: I hacked this together in about 10 minutes (or possibly longer :).
5994 It worked suitably for the website I wrote it for (or possibly "against" :).
5995 Your Milage May Vary.
5996
5997 See :help eval, :help silent, :help exec, :help :s
5998
5999 </pre></tip> </html> <Tip category="KVim"> <html><center>Check
6000 for comments, independent of the filetype</center> <pre> <A
6001 HREF="http://vim.sf.net/tip_view.php?tip_id=218">http://vim.sf.net/tip_view.php?tip_id=218</A><BR>
6002
6003 For some scripts it might be useful to detect, whether a specific position
6004 in a buffer is inside of a comment or not. Syntax highlighting can save us
6005 the work for parsing the comments ourselves.
6006
6007 The command
6008 :echo synIDattr(synIDtrans(synID(line("."), col("."), 0)), "name")
6009 echoes the group used for *highlighting* the character at the current
6010 cursor position, see ':help synIDtrans()'. It will usually be "Comment"
6011 if the cursor is inside of a comment, so
6012 synIDattr(synIDtrans(synID(line("."), col("."), 0)), "name") == "Comment"
6013 detects, independent of the filetype (which have their own group 'names'
6014 for comments), if the cursor is inside a comment or not. The expression
6015 synIDattr(synIDtrans(synID(line("."), col("."), 0)), "name") =~
6016 'Comment\|Constant\|PreProc'
6017 will detect additionally, if the cursor is inside of a string or some
6018 preprocessor statement.
6019
6020 </pre></tip> </html> <Tip category="KVim"> <html><center>make
6021 from command line, open vim on errors</center> <pre> <A
6022 HREF="http://vim.sf.net/tip_view.php?tip_id=219">http://vim.sf.net/tip_view.php?tip_id=219</A><BR>
6023
6024 A simple alias (*csh) or shell function (bash) will let you run make from your
6025 shell, then automatically open vim or gvim on the errors (if there were any):
6026
6027 csh or tcsh:
6028
6029 alias Make 'make \!* |& tee make.errors || gvim -q make.errors -c :copen'
6030
6031 bash:
6032
6033 Make () { command make "$@" |& tee make.errors || gvim -q make.errors -c
6034 :copen ; }
6035
6036 If you use vanilla sh or ksh or even cmd.exe, you can probably do the same -
6037 add a not if you have ideas.
6038
6039 </pre></tip> </html> <Tip category="KVim">
6040 <html><center>Match every word except 'foo'</center> <pre> <A
6041 HREF="http://vim.sf.net/tip_view.php?tip_id=220">http://vim.sf.net/tip_view.php?tip_id=220</A><BR>
6042
6043 This is a regular expression that matches all words except 'foo'
6044 \v&lt;(foo&gt;)@!\k+&gt;
6045
6046 \v Very magic &lt; Start-of-word (Foo&gt;) The
6047 atom 'Foo' followed by end-of-word @! Match (with zero length)
6048 when the previous atom doesn't match. \k+ Match one or more
6049 Keywords &gt; Match end-of-word.
6050
6051 This is a kool example of using \@! in the middle of a regexp. The non-magic
6052 version is: \&lt;\(foo\&gt;\)\@!\k\+\&gt;
6053
6054 </pre></tip> </html> <Tip category="KVim">
6055 <html><center>indenting "throws" in java</center> <pre> <A
6056 HREF="http://vim.sf.net/tip_view.php?tip_id=221">http://vim.sf.net/tip_view.php?tip_id=221</A><BR>
6057
6058 I want to indent java files like this:
6059
6060 int x(int y, int z)
6061 throws Exception
6062 {
6063 [...] return something;
6064 }
6065
6066 By default vim will properly indent "throws" line, but following "{" will
6067 not be deindented back to the method declaration.
6068
6069 The following indentexpr does the trick: let
6070 &indentexpr='getline(v:lnum)=~"^\\s*{" && getline(v:lnum-1)=~"^\\s*throws\\s"
6071 ? cindent(v:lnum)-&sw : cindent(v:lnum)'
6072
6073 It just checks that the current line starts with "{" and the previous line
6074 starts with "throws" and if that is the case, it subtracts one shiftwidth
6075 from the number returned by cindent.
6076
6077 </pre></tip> </html> <Tip category="KVim">
6078 <html><center>Building vim with color on HP-UX</center> <pre> <A
6079 HREF="http://vim.sf.net/tip_view.php?tip_id=222">http://vim.sf.net/tip_view.php?tip_id=222</A><BR>
6080
6081 Following the normal steps of running "./configure" and "make" to build vim
6082 on an HP-UX 10.20 will result in vim being linked with the termlib library.
6083 This library does not support certain termcap capability codes, such as the
6084 "Co" code used to query the number of colors supported by the terminal.
6085 Consequently, vim will not display colors when used with a color terminal
6086 such as a color xterm.
6087
6088 One solution to this is to run the configure script with the
6089 "--with-tlib=curses" option, like this:
6090
6091 ./configure --with-tlib=curses
6092
6093 This will cause vim to be linked with the HP-UX curses library, which does
6094 support the color termcap capability codes.
6095
6096 Note that the xterm that comes standard with HP-UX 10.20 does not display color
6097 character attributes. To see colors when running vim in a terminal window,
6098 you will also need to install a color terminal emulator such as a recent xterm.
6099
6100 </pre></tip> </html> <Tip category="KVim">
6101 <html><center>Reverse Selected Text</center> <pre> <A
6102 HREF="http://vim.sf.net/tip_view.php?tip_id=223">http://vim.sf.net/tip_view.php?tip_id=223</A><BR>
6103
6104 Suppose you want to reverse some text - I don't know why you would want to -
6105 maybe you're dyslexic. Anyway, I had a need, so this mapping will reverse
6106 visually selected text. Put the mapping in your vimrc or otherwise source
6107 it, then visually select the word or words, and hit ;rv - really only works
6108 with selections on one line:
6109
6110 vnoremap ;rv c&lt;C-O&gt;:set revins&lt;cr&gt;&lt;C-R&gt;"&lt;esc&gt;:set
6111 norevins&lt;cr&gt;
6112
6113 </pre></tip> </html> <Tip category="KVim">
6114 <html><center>Shifting blocks visually</center> <pre> <A
6115 HREF="http://vim.sf.net/tip_view.php?tip_id=224">http://vim.sf.net/tip_view.php?tip_id=224</A><BR>
6116
6117 I use the &lt; and &gt; commands on blocks a lot, and it has always annoyed me
6118 that if you want to shift more than one 'shiftwidth', you have count how many
6119 'shiftwidth's you want to enter the '[count]&gt;', or restore the selection
6120 with "gv". So I've cooked up two mappings that come in very handy:
6121
6122 :vnoremap &lt; &lt;gv :vnoremap &gt; &gt;gv
6123
6124 These mappings will reselect the block after shifting, so you'll just have
6125 to select a block, press &lt; or &gt; as many times as you like, and press
6126 &lt;ESC&gt; when you're done to unselect the block.
6127
6128 I know it's not rocket science, but it sure has helped me a lot.
6129
6130 </pre></tip> </html> <Tip category="KVim">
6131 <html><center>vim can interact with xdvi</center> <pre> <A
6132 HREF="http://vim.sf.net/tip_view.php?tip_id=225">http://vim.sf.net/tip_view.php?tip_id=225</A><BR>
6133
6134 vim can interact with the tricks that the latest xdvi does:
6135
6136 * If one clicks at some place in xdvi, vim automatically jumps to the
6137 corresponding line in the LaTeX source file ("reverse search")
6138 * Also, from inside vim, one can jump to the corresponding line in xdvi
6139 which becomes highlighted ("forward search").
6140
6141 Here is how to do it:
6142
6143 * Reverse search:
6144 We start a vim server by: vim --servername xdvi We start xdvi(k) on
6145 file.dvi by:
6146 xdvik -editor "vim --servername xdvi --remote +%l %f" file.dvi
6147 At the desired location in xdvi, we press: &lt;ctrl&gt;&lt;left_mouse&gt;
6148 Then, vim will jump to the corresponding line in the source file.
6149
6150 * Forward search:
6151 Inside vim, we type, for example, _g which is the following mapping:
6152 (the following should be a single line)
6153
6154 map _g :execute "!xdvik -name xdvi -sourceposition "
6155 . line(".") . expand("%") . " " . expand("%:r") . ".dvi"
6156 &lt;cr&gt;&lt;cr&gt;
6157
6158 [the command to go to the point of xdvi that corresponds to line, eg, 77
6159 of the source file is (no space after 77)
6160 xdvik -name xdvi -sourceposition 77file.tex file.dvi ]
6161
6162 For the above to work one needs: 1) A recent version of xdvi or xdvik
6163 (&gt;22.39 I think) 2) The package srcltx.sty and \usepackage{srcltx}
6164 (which should be
6165 commented out when one finishes and is ready for printing etc).
6166 3) Our version of vim should have been compiled with +clientserver
6167 (however, my vim doesn't have it and still works, so try it before
6168 Bram finds out what is happening and fixes it)
6169
6170 </pre></tip> </html> <Tip category="KVim"> <html><center>Edit
6171 file under cursor after a horizontal split</center> <pre> <A
6172 HREF="http://vim.sf.net/tip_view.php?tip_id=226">http://vim.sf.net/tip_view.php?tip_id=226</A><BR>
6173
6174 I use the command 'gf' quite often. But with this command the current buffer
6175 is hidden. To avoid that I use the following mapping :
6176
6177 map gw &lt;Esc&gt;:sp %&lt;CR&gt; gf
6178
6179 With this mapping the file under the cursor is opened after a horizontal split.
6180
6181 </pre></tip> </html> <Tip category="KVim">
6182 <html><center>Power of :g</center> <pre> <A
6183 HREF="http://vim.sf.net/tip_view.php?tip_id=227">http://vim.sf.net/tip_view.php?tip_id=227</A><BR>
6184
6185 :g is something very old and which is very powerful. I just wanted to
6186 illustrate the use of it with some examples. Hope, it will be useful for
6187 someone.
6188
6189 Brief explanation for ":g" ------------------------- Syntax is:
6190 :[range]:g/&lt;pattern&gt;/[cmd]
6191 You can think the working as, for the range (default whole file), execute
6192 the colon command(ex) "cmd" for the lines matching &lt;pattern&gt;. Also,
6193 for all lines that matched the pattern, "." is set to that particular line
6194 (for certain commands if line is not specified "." (current line) is assumed).
6195
6196 Some examples ------------- Display context (5 lines) for all occurences of
6197 a pattern
6198 :g/&lt;pattern&gt;/z#.5 :g/&lt;pattern&gt;/z#.5|echo "==========" &lt;&lt;
6199 same as first, but with some beautification &gt;&gt;
6200 Delete all lines matching a pattern
6201 :g/&lt;pattern&gt;/d
6202 Delete all blank lines (just an example for above)
6203 :g/^\s*$/d
6204 Double space the file
6205 :g/^/pu =\"\n\" :g/^/pu _ &lt;&lt; the above one also works &gt;&gt;
6206 Copy all lines matching a pattern to end of file
6207 :g/&lt;pattern&gt;/t$
6208 Yank all lines matching a pattern to register 'a'
6209 0"ay0:g/&lt;pattern&gt;/y A
6210 Increment the number items from current line to end-of-document by one
6211 :.,$g/^\d/exe "normal! \&lt;c-a&gt;"
6212 Comment (C) lines containing "DEBUG" statements
6213 g/^\s*DEBUG/exe "norm! I/* \&lt;Esc&gt;A */\&lt;Esc&gt;"
6214 A Reverse lookup for records (eg: An address book, with Name on start-of-line
6215 and fields after a space)
6216 :g/&lt;patern&gt;?^\w?p "if only name is interested
6217 :g/&lt;patern&gt;/ka|?^\w?p|'ap "if name and the lookup-line
6218 is interested :g/&lt;patern&gt;/?^\w?|+,/^[^ ]/-1p "if entire record
6219 is interested
6220 Reverse a file (just to show the power of 'g')
6221 :g/^/m0
6222
6223 Foot note 1: use :v to negate the search pattern Foot note 2: Some explanation
6224 of commonly used commands with :g
6225 :2,8co15 =&gt; Copy lines 2 through 8 after line 15 :4,15t$ =&gt; Copy
6226 linesa 4 through 15 towards end of document (t == co)
6227 :-t$ =&gt; Copy previous line to end of document
6228 :m0 =&gt; Move current line to the top of the document
6229 :.,+3m$-1 =&gt; Move current line through cur-line+3 to the last but one line
6230 of the document
6231 Foot note 3: Commands used with :g are ex commands, so a help search should
6232 be,
6233 :help :&lt;help-topic&gt; eg. :help :k
6234
6235 </pre></tip> </html> <Tip category="KVim"> <html><center>Deleting
6236 nested reply threads in emails</center> <pre> <A
6237 HREF="http://vim.sf.net/tip_view.php?tip_id=228">http://vim.sf.net/tip_view.php?tip_id=228</A><BR>
6238
6239 I find the following setting useful when replying to email threads that have
6240 lots of lines like the following: &gt; blah &gt; &gt; blah &gt; &gt; &gt; blah
6241
6242 autocmd FileType mail map &lt;F8&gt; :%g/^&gt; &gt;/d&lt;CR&gt;
6243
6244 When replying to a mail and you want to remove everything except what the
6245 person you are directly replying to wrote just press F8. From the example
6246 above, you would just be left with &gt; blah
6247
6248 What it does is simply match any line starting with &gt; &gt; and deletes it.
6249 It's not perfect as sigs and other debris may remain but it takes a lot
6250 of the grunt work out of replying to mails. The autocmd only maps F8 when
6251 using mails, this is handy if you use F8 for other things as I do.
6252
6253 :help autocmd :help map :help :g
6254
6255 </pre></tip> </html> <Tip category="KVim"> <html><center>First
6256 thing to try before asking help</center> <pre> <A
6257 HREF="http://vim.sf.net/tip_view.php?tip_id=229">http://vim.sf.net/tip_view.php?tip_id=229</A><BR>
6258
6259 I've seen several questions asked in the reflector which is available in the
6260 help files. Yeah, I know the help is huge. But, you can try this command
6261 to show a list of related topics you are trying:
6262 :he &lt;topic&gt;&lt;c-d&gt;
6263 It is "some topic" followed by the key sequence Ctrl-D. For eg:
6264 :he xterm&lt;c-d&gt;
6265 will show all the help topics matching xterm. Then you can do
6266 completion/copy-n-paste the topic you are searching. Of course you can cycle
6267 through all the topics through repeated &lt;TABS&gt;, but if the number of
6268 hits are huge, it is cumbersome.
6269
6270 Enjoy vimming beginners!!! -Arun
6271
6272 </pre></tip> </html> <Tip category="KVim"> <html><center>copy
6273 current file to another location from within vim</center> <pre> <A
6274 HREF="http://vim.sf.net/tip_view.php?tip_id=230">http://vim.sf.net/tip_view.php?tip_id=230</A><BR>
6275
6276 I work on jsp pages in my source tree but I have to copy the jsp files over
6277 to the tomcat directory in order to view my changes.The following mapping
6278 will copy the file being edited to another location.
6279
6280 command Cpage silent !cp '%:p' "c:/Progra~1/Tomcat/webapps/console/pages/%"
6281
6282 Explanation:
6283
6284 % refers to the current buffer %:p refers to the path to the file silent
6285 suppresses the command prompt window.
6286
6287 Usage:
6288
6289 :Cpage
6290
6291 </pre></tip> </html> <Tip category="KVim">
6292 <html><center>Localized color schemes</center> <pre> <A
6293 HREF="http://vim.sf.net/tip_view.php?tip_id=231">http://vim.sf.net/tip_view.php?tip_id=231</A><BR>
6294
6295 i frequently like to edit multiple files in the same vim session. however,
6296 if i come into vim from another window i frequently hit 'i' and start typing
6297 in whatever buffer is currently being used -- this is often the wrong one
6298 (requires &lt;esc&gt;, undo, go the other buffer and . to redo).
6299
6300 one way to work around this for me is to use a different color scheme
6301 depending on what file i'm working on:
6302
6303 au BufEnter * if (exists("b:colors_name")) | let b:current_colors=colors_name
6304 | execute "colorscheme " . b:colors_name | endif
6305
6306 au BufLeave * if (exists("b:current_colors")) | execute "colorscheme "
6307 . b:current_colors | endif
6308
6309 if you define b:colors_name with a particular color scheme name, then the
6310 above autocommands will switch to that colorscheme when you enter that window
6311 and will return to the original color upon departure.
6312
6313 inside ftplugin/java.vim, for example, i might have b:colors_name set to
6314 'morning', causing all java files to have a distinguishing color scheme.
6315
6316 </pre></tip> </html> <Tip category="KVim"> <html><center>Search
6317 JDK help for keyword at cursor</center> <pre> <A
6318 HREF="http://vim.sf.net/tip_view.php?tip_id=232">http://vim.sf.net/tip_view.php?tip_id=232</A><BR>
6319
6320 If you are using the Win32 version of Vim you can use this tip to search
6321 the Jdk help for the keyword under the cursor.
6322 You need the winhlp32 version of the Jdk docs from this URL - <A
6323 HREF="http://www.confluent.fr/javadoc/indexe.html.">http://www.confluent.fr/javadoc/indexe.html.</A><BR>
6324 It is a 16mb D/L and approx 85mb unzipped!
6325
6326 I added a command to the popup menu :amenu PopUp.JavaHelp :!start winhlp32
6327 -k &lt;cword&gt; F:\jdk\winhelp\JDK13.HLP &lt;CR
6328
6329 And also made a keymapping map J :!start winhlp32 -k &lt;cword&gt;
6330 F:\jdk\winhelp\JDK13.HLP &lt;CR&gt;
6331
6332 Trivial yes, but I find it quite useful.
6333
6334 </pre></tip> </html> <Tip category="KVim"> <html><center>Some
6335 tips for using Vim to write Lisp code</center> <pre> <A
6336 HREF="http://vim.sf.net/tip_view.php?tip_id=233">http://vim.sf.net/tip_view.php?tip_id=233</A><BR>
6337
6338 For some tips on how to use Vim for writing Lisp code, see <A
6339 HREF="http://www.lisp-p.org/i000/15-vim.">http://www.lisp-p.org/i000/15-vim.</A><BR>
6340
6341 </pre></tip> </html> <Tip category="KVim"> <html><center>Vi(M)
6342 Command Line tips & tricks</center> <pre> <A
6343 HREF="http://vim.sf.net/tip_view.php?tip_id=234">http://vim.sf.net/tip_view.php?tip_id=234</A><BR>
6344
6345 Hi VIMMERs
6346
6347 These tips save me wearing out my delicate little fingers with unnecessary
6348 keystrokes. They assume Unix, but I also use them on a Windows Unix Shell
6349 (MKS) as well
6350
6351 # When I know the file i want to edit is the most recent file in a directory
6352
6353 alias -x vew='vi `l\s -t * | head -1 `'
6354
6355 #When I know the file I want to edit contains a unique keyword #this is
6356 actually in a little shell script call ed vg where the keyword is passed as
6357 parameter $1 #/bin/sh #name vg vi.exe $(grep -isl $1 *) &
6358
6359 # some variations alias -x vp='vi `l\s -t *.@(pl|cgi)| head -1 `'
6360
6361 #execute the most recent script (I call this from within VIM with a mapped
6362 button) alias -x xew='`l\s -t *.pl | head -1 `'
6363
6364 Cheers zzapper
6365
6366 </pre></tip> </html> <Tip category="KVim"> <html><center>Toggle
6367 highlight word under cursor, to find cursor.</center> <pre> <A
6368 HREF="http://vim.sf.net/tip_view.php?tip_id=235">http://vim.sf.net/tip_view.php?tip_id=235</A><BR>
6369
6370 When the screen has scrolled such as during a search, it may be difficult to
6371 find the cursor. :help %# explains the pattern one can use to highlight the
6372 word around the cursor, which gives a bigger target to look for on the screen.
6373 I have this in my .vimrc:
6374
6375 function VIMRCWhere()
6376 if !exists("s:highlightcursor")
6377 match Todo /\k*\%#\k*/ let s:highlightcursor=1
6378 else
6379 match None unlet s:highlightcursor
6380 endif
6381 endfunction map &lt;C-K&gt; :call VIMRCWhere()&lt;CR&gt;
6382
6383 This means that in "normal" mode ctrl-k will toggle the highlight. Todo is
6384 a hightlight group whch is particularly easy to see. For further information
6385 see ":help s:", ":help match", ":help exists()" and ":help funtion".
6386
6387 </pre></tip> </html> <Tip category="KVim"> <html><center>Menu
6388 for inserting special characters</center> <pre> <A
6389 HREF="http://vim.sf.net/tip_view.php?tip_id=236">http://vim.sf.net/tip_view.php?tip_id=236</A><BR>
6390
6391 First, thanks for the script printascii.vim.
6392
6393 When looking at the ascii table, I found some characters I'd like to have
6394 inserted when editing. Add the following lines in your _gvimrc and you
6395 can select them via menu. (change the names of the menu if you don't have
6396 German installed or don't like my titles). I also made some abbreviations
6397 to get separation lines in documentation or code files, e.g. abb dotlin
6398 ……………………………………………………………………………………………………………………………………………………………………………………………^M
6399 abb cdotlin
6400 /*…………………………………………………………………………………………………………………………………………………………………………………*/^M
6401 abb fdotlin
6402 •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••^M
6403 abb cfdotlin
6404 /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/^M abb
6405 dlin =======================================================================^M
6406 abb cdlin
6407 /*===================================================================*/^M abb
6408 lin -----------------------------------------------------------------------^M
6409 abb clin
6410 /*-------------------------------------------------------------------*/^M abb
6411 ulin _______________________________________________________________________^M
6412 abb culin
6413 /*___________________________________________________________________*/^M abb
6414 Ulin ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯^M
6415 abb cUlin
6416 /*¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*/^M
6417
6418 (you have to substitute ^M with CTRL_V CTRL_M or delete it)
6419
6420 20imenu Editieren.Sonderzeichen.open\ angle\ «
6421 &lt;C-R&gt;=nr2char(171)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.open\
6422 angle\ « a&lt;C-R&gt;=nr2char(171)&lt;CR&gt;&lt;ESC&gt;
6423 20imenu Editieren.Sonderzeichen.close\ angle\ »
6424 &lt;C-R&gt;=nr2char(187)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.close\
6425 angle\ » a&lt;C-R&gt;=nr2char(187)&lt;CR&gt;&lt;ESC&gt;
6426 20imenu Editieren.Sonderzeichen.start\ mark\ „
6427 &lt;C-R&gt;=nr2char(132)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.start\
6428 mark\ „ a&lt;C-R&gt;=nr2char(132)&lt;CR&gt;&lt;ESC&gt;
6429 20imenu Editieren.Sonderzeichen.end\ mark\ \ ”
6430 &lt;C-R&gt;=nr2char(148)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.end\
6431 mark\ \ ” a&lt;C-R&gt;=nr2char(148)&lt;CR&gt;&lt;ESC&gt;
6432 20imenu Editieren.Sonderzeichen.fat\ dot\ \ •
6433 &lt;C-R&gt;=nr2char(149)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.fat\
6434 dot\ \ • a&lt;C-R&gt;=nr2char(149)&lt;CR&gt;&lt;ESC&gt;
6435 20imenu Editieren.Sonderzeichen.etc\ \ \ …
6436 &lt;C-R&gt;=nr2char(133)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.etc\
6437 \ \ … a&lt;C-R&gt;=nr2char(133)&lt;CR&gt;&lt;ESC&gt;
6438 20imenu Editieren.Sonderzeichen.!underscore\ \ ¯
6439 &lt;C-R&gt;=nr2char(175)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.!underscore\
6440 \ ¯ a&lt;C-R&gt;=nr2char(175)&lt;CR&gt;&lt;ESC&gt;
6441 20imenu Editieren.Sonderzeichen.copyright\ \ ©
6442 &lt;C-R&gt;=nr2char(169)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.copyright\
6443 \ © a&lt;C-R&gt;=nr2char(169)&lt;CR&gt;&lt;ESC&gt;
6444 20imenu Editieren.Sonderzeichen.paragraph\ \ §
6445 &lt;C-R&gt;=nr2char(167)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.paragraph\
6446 \ § a&lt;C-R&gt;=nr2char(167)&lt;CR&gt;&lt;ESC&gt;
6447 20imenu Editieren.Sonderzeichen.noitamalcxe\ ¡
6448 &lt;C-R&gt;=nr2char(161)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.noitamalcxe\
6449 ¡ a&lt;C-R&gt;=nr2char(161)&lt;CR&gt;&lt;ESC&gt;
6450
6451 </pre></tip> </html> <Tip category="KVim"> <html><center>If
6452 you prefer vertical splits</center> <pre> <A
6453 HREF="http://vim.sf.net/tip_view.php?tip_id=237">http://vim.sf.net/tip_view.php?tip_id=237</A><BR>
6454
6455 This is just in case there's somebody else who likes to work in a maximized
6456 vim window on a high resolution desktop. If you follow good coding practice
6457 and make sure your programs use only 80 characters in each row, have you
6458 noticed how much space lies unused on the right?
6459
6460 I find that the following settings keep me from ever seeing another horizontal
6461 split, unless I specifically ask for it.
6462
6463 cabbrev split vsplit cabbrev hsplit split cabbrev sta vertical sta cabbrev
6464 help vertical help cabbrev new vnew cabbrev right botright
6465
6466 ; A more heavyweight solution for ^W^] function! ToggleSplit (dir)
6467 let currFname = bufname ("%") let old = winnr ()
6468
6469 " Window navigation to ensure the correct window is 'last'. if (a:dir ==
6470 "u")
6471 wincmd k let back="j"
6472 elseif (a:dir == "d")
6473 wincmd j let back="k"
6474 elseif (a:dir == "l")
6475 wincmd h let back="l"
6476 elseif (a:dir == "r")
6477 wincmd l let back="h"
6478 endif
6479
6480 if (winnr () == old)
6481 echo "Ouch" return
6482 endif
6483
6484 exec "wincmd " . back
6485
6486 quit
6487
6488 if (back == "j" || back == "k")
6489 let orientation = "vsplit"
6490 else
6491 let orientation = "split"
6492 endif
6493
6494 if (back == "j" || back == "l")
6495 let dir = "below"
6496 else
6497 let dir = "above"
6498 endif
6499
6500 exec dir . " " . orientation " " . currFname
6501 endfunction noremap ^W^] ^W^]:silent call ToggleSplit ("d")&lt;CR&gt;
6502
6503 ; Optional. set splitright ; In which case the above mapping becomes: noremap
6504 ^W^] :set splitbelow&lt;CR&gt;^W^]:silent call ToggleSplit ("u")&lt;CR&gt;:set
6505 nosplitbelow&lt;CR&gt; ; Or you could just set splitbelow ; :-)
6506
6507 ; Very elegant and almost perfect, but it screws up if you want to run a
6508 command with ranges :-) ;noremap : :vertical&lt;Space&gt;
6509
6510 ; EOF
6511
6512 </pre></tip> </html> <Tip category="KVim"> <html><center>Very
6513 basic session persistence</center> <pre> <A
6514 HREF="http://vim.sf.net/tip_view.php?tip_id=238">http://vim.sf.net/tip_view.php?tip_id=238</A><BR>
6515
6516 I use the following code in my plugins dir to ease session persistance. If
6517 I want my session to persist I use :mks! and then whenever I open the
6518 Session.vim file, my session is restored. If I am working from a restored
6519 session and I close VIM, the session is saved automatically. Drawback is
6520 that it makes editing the Session.vim file a bit cumbersome ;)
6521
6522 au BufRead Session.vim so % au VimLeave * call SaveCurrentSession()
6523
6524 function! SaveCurrentSession()
6525 if v:this_session != ""
6526 exe "mksession! " . v:this_session
6527 endif
6528 endfunction
6529
6530 </pre></tip> </html> <Tip category="KVim">
6531 <html><center>map shift-up and shift-down</center> <pre> <A
6532 HREF="http://vim.sf.net/tip_view.php?tip_id=239">http://vim.sf.net/tip_view.php?tip_id=239</A><BR>
6533
6534 You can make Vim scroll the text using the shifted up/down arrows, sort
6535 of like your browser (except with shifted keys :), by mapping Shift-Up to
6536 Ctrl-Y and Shift-Down to Ctrl-E.
6537
6538 map &lt;s-Down&gt; &lt;C-E&gt; map &lt;s-Up&gt; &lt;C-Y&gt;
6539
6540 Shift-Down will then scroll down (like moving a scroll-bar down, or like
6541 moving a cursor at the bottom of a window down), and Shift-Up will then
6542 scroll up (like moving a scroll-bar up, etc).
6543
6544 If you'd rather think about the text moving down/up instead of the cursor
6545 moving up/down, you can of course swap the mappings.
6546
6547 If you normally use j and k for cursor movement, and rarely use the arrow
6548 keys, you can map the arrow keys directly, in which case I'd probably map
6549 the shifted arrow keys back to cursor movement:
6550
6551 map &lt;down&gt; &lt;c-e&gt; map &lt;up&gt; &lt;c-y&gt; map &lt;s-down&gt;
6552 j map &lt;s-up&gt; k
6553
6554 See :help ctrl-e, :help ctrl-y, and :help key-mapping.
6555
6556 See also :help i_ctrl-o and :help map-modes for how to set up these mappings
6557 for use in other modes (like insert mode :).
6558
6559 (Vim by default maps s-Down and s-Up to Ctrl-F and Ctrl-B, for both normal and
6560 visual mode. Keep this in mind if you change some of the above mappings to
6561 "nmap", 'cause you'll probably also want to look in to "vmap".)
6562
6563 </pre></tip> </html> <Tip category="KVim">
6564 <html><center>Hideall for Vim</center> <pre> <A
6565 HREF="http://vim.sf.net/tip_view.php?tip_id=240">http://vim.sf.net/tip_view.php?tip_id=240</A><BR>
6566
6567 Xemacs has a hide all function which can make all the function in your C file a
6568 fold and close them. And here is something small to achieve similiar under Vim.
6569
6570 func! HideAll()
6571 syn region myFold start="{" end="}" transparent fold syn sync fromstart
6572 set foldnestmax=1 set foldmethod=syntax
6573 endfunc
6574
6575 amenu Whatever.Hide\ all :call HideAll()&lt;CR&gt;
6576
6577 </pre></tip> </html> <Tip category="KVim">
6578 <html><center>"Hide" Folding Markers</center> <pre> <A
6579 HREF="http://vim.sf.net/tip_view.php?tip_id=241">http://vim.sf.net/tip_view.php?tip_id=241</A><BR>
6580
6581 I wanted to start using folding without having to get used to seeing the
6582 (default) markers, a.k.a {{{ and }}}. So, here are 2 autocmd's that will
6583 make them fade to black....bg=black fg=black
6584
6585 au BufRead,BufNewfile * syn match fmrkr '"*{{{\|"*}}}' |
6586 \ syn cluster vimCommentGroup contains=fmrkr |
6587 \ hi fmrkr term=NONE guibg=black guifg=black \
6588 ctermbg=black ctermfg=black
6589
6590 au BufRead,BufNewfile * syn match fmrkr '"*{{{\|"*}}}'
6591 \ containedin=vimLineComment contained |
6592 \ hi fmrkr term=NONE guibg=black guifg=black \
6593 ctermbg=black ctermfg=black
6594
6595 They both accomplish the same thing, but with different methods, so simply pick
6596 one and see those annoying (at least to me) markers fade away. I just tried
6597 it out with vim files, but you can easily modify it for any other filetypes.
6598
6599 Thanks to Colin's lead with ':help c-syntax' for the 1st au. Thanks to
6600 Benji's lead with ':help containedin' for the 2nd au. Understanding most
6601 of the syntax.txt document file would also be helpful.
6602
6603 To figure out what highlighting group the Marker is in, I would suggest
6604 using Chip's vimtip#99.
6605
6606 Happy Vimming!
6607
6608 </pre></tip> </html> <Tip category="KVim">
6609 <html><center>The power of "\_" in reg-ex</center> <pre> <A
6610 HREF="http://vim.sf.net/tip_view.php?tip_id=242">http://vim.sf.net/tip_view.php?tip_id=242</A><BR>
6611
6612 One of the most uncelebrated feature of vim 6.0 is the ability to span a
6613 search across multiple lines.
6614
6615 \_^ maps a begining of line anywhere in search pattern. \_$ ---"----- end
6616 ----------------------"-------------------------. \_s ---"------ space
6617 ------------"------------------------- .
6618
6619 e.g /{\_s will map all white spaces and new-line chars after a "{"
6620
6621 The \_ can be appended to other objects as well. such as \_U, \_L, \_. (this
6622 one's risky) .
6623
6624 See :help pattern for more details. Njoy
6625
6626 </pre></tip> </html> <Tip category="KVim">
6627 <html><center>Develop vim modules on Win</center> <pre> <A
6628 HREF="http://vim.sf.net/tip_view.php?tip_id=243">http://vim.sf.net/tip_view.php?tip_id=243</A><BR>
6629
6630 We're trying to develop txt2pdf.vim <A
6631 HREF="http://vim.sourceforge.net/scripts/script.php?script_id=283 on
6632 Win.">http://vim.sourceforge.net/scripts/script.php?script_id=283
6633 on Win.</A><BR> It's a very simple module to save the
6634 current file and convert it to PDF using our txt2pdf tool <A
6635 HREF="http://www.sanface.com/txt2pdf.html">http://www.sanface.com/txt2pdf.html</A><BR>
6636 On our Windows 2000 we've developed it. It works good. Today we've tested
6637 the module on Linux. Surprise: it doesn't work. Default Win Vim configure
6638 save on Win text in Win way: EOL \r\n. A Vim module made in this way can't
6639 work on Linux (probably on every Unix OS). If you want to make a Vim module
6640 on Win and you want it can work also on Unix (we hope the same rula can work
6641 also on different OS) you've to save the Vim module with Unix EOL (\n).
6642
6643 Please send us (sanface@sanface.com) your notes about other OS (e.g. OpenVMS).
6644
6645 </pre></tip> </html> <Tip category="KVim"> <html><center>Ask
6646 vim where an option was set.</center> <pre> <A
6647 HREF="http://vim.sf.net/tip_view.php?tip_id=244">http://vim.sf.net/tip_view.php?tip_id=244</A><BR>
6648
6649 When things go wrong, it is sometimes hard to figure out why.
6650 For example,
6651 an option might be set in the system vimrc file, in a personal vimrc file,
6652 in a plugin (global or local), or interactively. Vim will tell you where
6653 the current value was set if you ask:
6654
6655 :verbose set history?
6656
6657 will tell you the current value of the 'history' option, and where it was set.
6658
6659 </pre></tip> </html> <Tip category="KVim"> <html><center>Working
6660 with Unicode (platform-independent)</center> <pre> <A
6661 HREF="http://vim.sf.net/tip_view.php?tip_id=245">http://vim.sf.net/tip_view.php?tip_id=245</A><BR>
6662
6663 Here are the main options you will want to set if you want to work with
6664 Unicode files in (g)vim (see at bottom what help tags to look for)
6665
6666 if has("multi_byte")
6667 set encoding=utf-8 " how vim shall represent
6668 characters internally setglobal fileencoding=utf-8 " empty is
6669 also OK (defaults to same as 'encoding'). Or you may want to set one
6670 of the ucs encodings (which
6671 " may use less disk
6672 space if you use
6673 only "alphabetic"
6674 scripts such as
6675 Latin, Greek,
6676 Cyrillic, Hebrew
6677 or Arabic, and "
6678 not "ideographic"
6679 scripts like
6680 Chinese, Japanese
6681 or Korean. With
6682 the ucs encodings
6683 it is usually better
6684 set bomb " to also set 'bomb'
6685 on ('byte-order-mark" option, irrelevant for utf-8 but not for
6686 ucs) set termencoding=iso-8859-15 " or whatever is appropriate
6687 to your locale (iso-8859-15 is Latin1 + Euro currency sign) set
6688 fileencodings=ucs-bom,iso-8859-15,iso-8859-3,utf-8
6689 " or whatever is appropriate to the kinds of files you want to
6690 edit " 'fileencodings' defines the heuristic to set 'fillencoding'
6691 (local to buffer) when reading an existing file. The first one that
6692 matches will be used. " ucs-bom is "ucs with byte-order-mark";
6693 it must not come after ucs-8 if you want it to be used
6694 else
6695 echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"
6696 endif
6697
6698 In "replace" mode, one utf character (one or more data bytes) replaces one
6699 utf character (which need not use the same number of bytes) In "normal" mode,
6700 ga shows the character under the cursor as text, decimal, octal and hex; g8
6701 shows which byte(s) is/are used to represent it In "insert" or "replace" mode,
6702 - any character defined on your keyboard can be entered the usual way (even
6703 with dead keys if you have them, e.g. âêîôû äëïöü) - any character which
6704 has a "digraph" (there are a huge lot of them, see :dig after setting
6705 enc=utf-8) can be entered with a Ctrl-K prefix - any utf character at
6706 all can be entered with a Ctrl-V prefix, either &lt;Ctrl-V&gt; u aaaa
6707 or &lt;Ctrl-V&gt; U bbbbbbbb, with 0 &lt;= aaaa &lt;= FFFF, or 0 &lt;=
6708 bbbbbbbb &lt;= 7FFFFFFF
6709
6710 Unicode can be used to create html "body text", at least for Netscape 6 and
6711 probably for IE; but on my machine it doesn't display properly as "title text"
6712 (i.e., between &lt;title&gt;&lt;/title&gt; tags in the &lt;head&gt; part).
6713
6714 Gvim will display it properly if you have the fonts for it, provided that
6715 you set 'guifont' to some fixed-width font which has the glyphs you want
6716 to use (Courier New is OK for French, German, Greek, Russian and more,
6717 but I'm not sure about Hebrew or Arabic; its glyphs are of a more "fixed"
6718 width than those of, e.g. Lucida Console: the latter can be annoying if you
6719 need bold Cyrillic writing).
6720
6721 see:
6722
6723 :h utf8 :h 'enc' :h 'fenc' :h 'fencs' :h 'tenc' :h 'bomb' :h 'guifont'
6724 :h ga :h g8 :h i_Ctrl-V_digit
6725
6726 Happy Vimming ! Tony.
6727
6728 </pre></tip> </html> <Tip category="KVim"> <html><center>Working
6729 with Unicode (the same, rewritten for legibility)</center> <pre> <A
6730 HREF="http://vim.sf.net/tip_view.php?tip_id=246">http://vim.sf.net/tip_view.php?tip_id=246</A><BR>
6731
6732 1. Where to look for help ------------------------- :h utf8 :h encoding-values
6733 :h 'enc' :h 'fenc' :h 'fencs' :h 'tenc' :h 'bomb' :h 'guifont' :h ga :h g8
6734 :h :dig :h i_Ctrl-V_digit :h has()
6735
6736 2. What to do (These are *examples*. Modify them to suit your work
6737 environment.) ------------- if has("multi_byte")
6738 set encoding=utf-8 setglobal fileencoding=utf-8
6739 set bomb set termencoding=iso-8859-15 set
6740 fileencodings=ucs-bom,iso-8859-15,iso-8859-3,utf-8
6741 else
6742 echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"
6743 endif
6744
6745 3. What the above does ---------------------- * has("multi_byte") checks if
6746 you have the right options compiled-in. If you haven't got what it takes,
6747 it's no use trying to use Unicode.
6748
6749 * 'encoding' sets how vim shall represent characters internally. Utf-8 is
6750 necessary for most flavors of Unicode.
6751
6752 * 'fileencoding' sets the encoding for a particular file (local to buffer);
6753 :setglobal sets the default value. An empty value can also be used: it defaults
6754 to same as 'encoding'. Or you may want to set one of the ucs encodings, It
6755 might make the same disk file bigger or smaller depending on your particular
6756 mix of characters. Also, IIUC, utf-8 is always big-endian (high bit first)
6757 while ucs can be big-endian or little-endian, so if you use it, you will
6758 probably need to set 'bomb" (see below).
6759
6760 * 'bomb' (boolean): if set, vim will put a "byte order mark" at the start
6761 of ucs files. This option is irrelevant for most non-ucs files (utf-8,
6762 iso-8859, etc.)
6763
6764 * 'termencoding' defines how your keyboard encodes what you type. The value
6765 you put there will depend on your locale: iso-8859-15 is Latin1 + Euro currency
6766 sign, but you may want something else for, say, an Eastern European keyboard.
6767
6768 * 'fileencodings' defines the heuristic to set 'fileencoding' (local to buffer)
6769 when reading an existing file. The first one that matches will be used (and,
6770 IIUC, if there is no match, Vim falls back on Latin1). Ucs-bom is "ucs with
6771 byte-order-mark"; it must not come after utf-8 if you want it to be used.
6772
6773 4. Additional remarks --------------------- * In "replace" mode, one utf
6774 character (one or more data bytes) replaces one utf character (which need
6775 not use the same number of bytes)
6776
6777 * In "normal" mode, ga shows the character under the cursor as text, decimal,
6778 octal and hex; g8 shows which byte(s) is/are used to represent it.
6779
6780 * In "insert" or "replace" mode,
6781 - any character defined on your keyboard can be entered the usual way
6782 (even with dead keys if you have them, e.g. French circumflex, German
6783 umlaut, etc.); - any character which has a "digraph" (there are a huge lot
6784 of them, see :dig after setting enc=utf-8) can be entered with a Ctrl-K
6785 prefix; - any utf character at all can be entered with a Ctrl-V prefix,
6786 either &lt;Ctrl-V&gt; u aaaa or &lt;Ctrl-V&gt; U bbbbbbbb, with 0 &lt;=
6787 aaaa &lt;= FFFF, or 0 &lt;= bbbbbbbb &lt;= 7FFFFFFF.
6788
6789 * Unicode can be used to create html "body text", at least for Netscape 6 and
6790 probably for IE; but on my machine it doesn't display properly as "title text"
6791 (i.e., between &lt;title&gt;&lt;/title&gt; tags in the &lt;head&gt; part).
6792
6793 * Gvim will display it properly if you have the fonts for it, provided
6794 that you set 'guifont' to some fixed-width font which has the glyphs you
6795 want to use (Courier New is OK for French, German, Greek, Russian and more,
6796 but I'm not sure about Hebrew or Arabic; its glyphs are of a more "fixed"
6797 width than those of, e.g. Lucida Console: the latter can be awkward if you
6798 need bold Cyrillic writing).
6799
6800 Happy Vimming ! Tony.
6801
6802 </pre></tip> </html> <Tip category="KVim">
6803 <html><center>Preexisting code indentation</center> <pre> <A
6804 HREF="http://vim.sf.net/tip_view.php?tip_id=247">http://vim.sf.net/tip_view.php?tip_id=247</A><BR>
6805
6806 Using tabs as elementary unit in your code indentation has two advantages:
6807 first, you may modify 'tabstop' and immediately all the indentations depths
6808 are modified according to it; second, your file will be smaller.
6809
6810 But how can we change some already-written code in order to convert spaces
6811 to tabs. Very simple! Suppose your old code has an indentation unit of
6812 2 spaces :ret! 2 :x will replace every 2-spaces to one tab, independently
6813 from your current tabstop value, and will save the modified file. Then,
6814 if you open again the file with tabstop=2, the file will look as before but
6815 it will be smaller. If you open the file with tabstop=4, the code vill have
6816 a more indented look, and so on...
6817
6818 Cheers!
6819
6820 </pre></tip> </html> <Tip category="KVim"> <html><center>Auto-save
6821 the current buffer periodically.</center> <pre> <A
6822 HREF="http://vim.sf.net/tip_view.php?tip_id=248">http://vim.sf.net/tip_view.php?tip_id=248</A><BR>
6823
6824 I have no idea if this was implemented in vim 5.3 or not, but you can
6825 definitely do the following kludge in 6.x by using CursorHold and
6826 localtime:
6827
6828 - When you start reading a file, set a buffer variable to the current
6829 time:
6830
6831 au BufRead,BufNewFile * let b:start_time=localtime()
6832
6833 - Set a CursorHold event to check to see if enough time has elapsed
6834 since the last save and save if not:
6835
6836 au CursorHold * call UpdateFile()
6837
6838 - Define a function to save the file if needed:
6839
6840 " only write if needed and update the start time after the save
6841 function! UpdateFile()
6842 if ((localtime() - b:start_time) &gt;= 60)
6843 update let b:start_time=localtime()
6844 else
6845 echo "Only " . (localtime() - b:start_time) . " seconds have elapsed
6846 so far."
6847 endif
6848 endfunction
6849
6850 - Reset the start time explicitly after each save.
6851
6852 au BufWritePre * let b:start_time=localtime()
6853
6854 Obviously, you should get rid of the else portion once you're certain
6855 that this does indeed do what you wanted.
6856
6857 The thing to note is that the CursorHold will only fire after
6858 'updatetime' milliseconds of inactivity have elapsed. So, if you type
6859 rapidly for one and a half minutes non-stop, it won't actually save
6860 anything until you STOP activity long enough. This may be what you want
6861 anyway because it won't interrupt your activity with a forced save.
6862
6863 The actual save-delay can be changed from '60' to another number (in seconds)
6864 or a variable or anything like that. This entire functionality can be easily
6865 wrapped inside a nice script which enables/disables this on a per-buffer basis
6866 (maybe with maps etc.). If desired, I can provide that also.
6867
6868 </pre></tip> </html> <Tip category="KVim"> <html><center>Quickly
6869 insert #if 0 - #endif around block of code</center> <pre> <A
6870 HREF="http://vim.sf.net/tip_view.php?tip_id=249">http://vim.sf.net/tip_view.php?tip_id=249</A><BR>
6871
6872 One of my favorite macros that I use in vim (and vi) inserts a #if 0 #endif
6873 sandwich around a block of code. I always map this to the 2 key sequence ;'
6874 which is the semi-colon followed by the single quote. Look at your keyboard,
6875 you will notice these keys are adjacent to one another. I like this mapping
6876 because it's very fast, my fingers easily roll from one key to the next,
6877 obviously YMMV.
6878
6879 To use this mapping, go to the line of code that you want the '#if 0' to be
6880 on, type ma to mark this line with the marker a, then move to the line that
6881 should be last line just above the '#endif' and press ;'
6882
6883 " insert #if 0 - #endif around block of code map ;' mz'aO&lt;Esc&gt;i#if
6884 0&lt;Esc&gt;'zo&lt;Esc&gt;i#endif&lt;Esc&gt;
6885
6886 -- David Thompson dat1965@yahoo.com
6887
6888 </pre></tip> </html> <Tip category="KVim">
6889 <html><center>One big window</center> <pre> <A
6890 HREF="http://vim.sf.net/tip_view.php?tip_id=250">http://vim.sf.net/tip_view.php?tip_id=250</A><BR>
6891
6892 If you like to see your files in fullscreen, and you have to edit more files,
6893 you can do the following. * Use only one window * Open further files with :e *
6894 type :nm &lt;A-Up&gt; :bp!&lt;CR&gt; * type :nm &lt;A-Down&gt; :bn!&lt;CR&gt;
6895 * type :nm &lt;C-F4&gt; :bd!&lt;CR&gt; You can of course change the keys.
6896 Now to switch between windows, you can press Alt-Up, and Alt-Down (Just in
6897 the GUI, if you use console, don't use Alt key) Another idea is to map them
6898 to Ctrl-Tab, and Ctrl-Shift-Tab To close the current file you can press Ctrl-F4
6899
6900 </pre></tip> </html> <Tip category="KVim"> <html><center>align
6901 #endif with corresponding #if/#ifdef</center> <pre> <A
6902 HREF="http://vim.sf.net/tip_view.php?tip_id=251">http://vim.sf.net/tip_view.php?tip_id=251</A><BR>
6903
6904 If you try to impose any sort of alignment on your preprocessor directives,
6905 rather than just starting them on column 0, this mapping will align the #endif
6906 'correctly' when you type '#en', start a new line, and bring you back to
6907 the correct alignment to edit code.
6908
6909 inoremap &lt;buffer&gt; #en
6910 X&lt;BS&gt;&lt;Esc&gt;?#if&lt;CR&gt;"zy0^Og0"zpDa#endif&lt;CR&gt;X&lt;BS&gt;&lt;Esc&gt;?#end?-1&lt;CR&gt;^"zy0^O0"zpDa
6911
6912 I am reasonably sure this is insensitive to vim options...
6913
6914 </pre></tip> </html> <Tip category="KVim"> <html><center>python
6915 script to align statements</center> <pre> <A
6916 HREF="http://vim.sf.net/tip_view.php?tip_id=252">http://vim.sf.net/tip_view.php?tip_id=252</A><BR>
6917
6918 i know there's some awk scripts out there that do the same thing, and if i
6919 were a real trooper i would have written this in vims internal language but...
6920
6921 i wrote a python script to align statements.
6922
6923 i put this in my .vimrc: map L :!lineUp.py&lt;cr&gt; " of course lineUp.py
6924 is somewhere in my path
6925
6926 and i have this python file somewhere in my path: <A
6927 HREF="http://ophinity.com/res/dotFiles/lineUp.py">http://ophinity.com/res/dotFiles/lineUp.py</A><BR>
6928
6929 so now i can just pipe the offending lines thru my code: :5, 10 !lineUp.py
6930 or using the mapping above, visually select the lines and press 'L'
6931
6932 </pre></tip> </html> <Tip category="KVim"> <html><center>The
6933 power of | (v75|r- actually...)</center> <pre> <A
6934 HREF="http://vim.sf.net/tip_view.php?tip_id=253">http://vim.sf.net/tip_view.php?tip_id=253</A><BR>
6935
6936 '|' as you may well be aware is the goto column motion, and that "75|"
6937 will place your cursor on column 75 of the current line.
6938
6939 That in itself is pretty handy at times, but some true power arises when
6940 used in conjuction with visual mode and replace. Or you could just say a
6941 sneaky trick :)
6942
6943 v75|r- will repace from the cursor to the end of line with '-' *breakdown*
6944 v to turn on visual mode 75 for the count | *bar* to goto column r to enter
6945 repace - to specify the char to replace.
6946
6947 A handy and quick way to make a noticable section of your code (or whatever).
6948
6949 A handy way to use this (formated to just drop into DrChip's CStubs): "//
6950 -[Feral]---------------------------------------------------------------
6951 "// &lt;cursor&gt;
6952 elseif wrd == "//"
6953 exe "norm! a
6954 -[AuthorId]\&lt;esc&gt;$lv75|r-$a\&lt;cr&gt;\&lt;esc&gt;$a "
6955
6956 "// -[Feral:146/02@08:31]--------------------------------------------------
6957 "// &lt;cursor&gt;
6958 elseif wrd == "///"
6959 exe "norm! s
6960 -[AuthorId:\&lt;C-R&gt;=strftime('%j/%y@%H:%M')\&lt;CR&gt;]\&lt;esc&gt;$lv75|r-$a\&lt;cr&gt;\&lt;esc&gt;$a
6961 "
6962
6963 "/* -[Feral:146/02@08:31]--------------------------------------------------
6964 " * &lt;cursor&gt; " *
6965 -------------------------------------------------------------------- */
6966 elseif wrd == "/*"
6967 exe "norm! a
6968 -[AuthorId:\&lt;C-R&gt;=strftime('%j/%y@%H:%M')\&lt;CR&gt;]\&lt;esc&gt;$lv75|r-$a\&lt;cr&gt;\&lt;cr&gt;\&lt;esc&gt;2lv72|r-$a
6969 */\&lt;esc&gt;k$a "
6970
6971 Have to love VIM!
6972
6973 </pre></tip> </html> <Tip category="KVim"> <html><center>Using
6974 \%[] to easily match parts of a word.</center> <pre> <A
6975 HREF="http://vim.sf.net/tip_view.php?tip_id=254">http://vim.sf.net/tip_view.php?tip_id=254</A><BR>
6976
6977 This code fragment is suitable to drop into DrChip's CStubs.
6978 After much searching I was unable to find a tip nor script
6979 number to referance, I believe where I found Dr. Chip's CStubs originally : <A
6980 HREF="http://users.erols.com/astronaut/vim/vimscript/drcstubs.vim">http://users.erols.com/astronaut/vim/vimscript/drcstubs.vim</A><BR>
6981 Thank you Dr. Chip! (=
6982
6983 If you have ever wanted to match parts of a word you may have considered
6984 something like: if wrd == "re" || wrd == "ret" || wrd == "retu" || wrd ==
6985 "retur"
6986 "do something
6987
6988 Althought the above works well enough it is a pain to maintain and add new
6989 words (not to mention its just a touch messy ;) )
6990
6991 A more elegant (and easier to use I believe) method would be to use \%[]
6992 as part of a pattern.
6993
6994 For instance, "\\&lt;re\\%[tur]\\&gt;" will match "re", "ret", "retu" or
6995 "retur"
6996
6997 *breakdown* \\&lt; = start of word re = first letters of word we want to
6998 require to match \\%[tur] = optionally match chars bewteen the braces,
6999 i.e. 't', 'tu' or 'tur' \\&gt; = end of word
7000
7001 So, we can use this as a pattern for match like so (In DrChip's CStubs)
7002
7003 elseif match(wrd, "\\&lt;re\\%[tur]\\&gt;") &gt; -1
7004 exe "norm! bdWireturn\&lt;Esc&gt;"
7005
7006 Which, I think, is a little better than the longer alternative: " vs elseif
7007 wrd == "re" || wrd == "ret" || wrd == "retu" || wrd == "retur"
7008 exe "norm! bdWireturn\&lt;Esc&gt;"
7009
7010 Just another one of those VIM things that made me smile :)
7011
7012 </pre></tip> </html> <Tip category="KVim">
7013 <html><center>arbitrary tags for file names</center> <pre> <A
7014 HREF="http://vim.sf.net/tip_view.php?tip_id=255">http://vim.sf.net/tip_view.php?tip_id=255</A><BR>
7015
7016 This definitely work on linux and there is probably some windows equivalent.
7017 I've started working with tomcat and many many .jsp files. I find this
7018 trick to be very helpful.
7019
7020 find -name '*.jsp' -printf '%f\t%P\t1\n' |sort &gt; jsp.tags
7021
7022 This will create a file called jsp.tags with tag entries for each .jsp file.
7023 Within Vim I use
7024
7025 :set tags+=jsp.tags
7026
7027 Now I can to simple :tag file.jsp to quickly switch b/w the many, many
7028 .jsp files.
7029
7030 One important note. The utility sort will use the value of LC_COLLATE to sort
7031 according to your locale. This will give Vim issues. So try "LC_COLLATE=C
7032 sort" instead of plain "sort"
7033
7034 </pre></tip> </html> <Tip category="KVim"> <html><center>Opening
7035 current Vim file in your Windows browser</center> <pre> <A
7036 HREF="http://vim.sf.net/tip_view.php?tip_id=256">http://vim.sf.net/tip_view.php?tip_id=256</A><BR>
7037
7038 Hi Vimmers
7039
7040 open current file in browser
7041
7042 map ,f :update&lt;CR&gt;:silent !start c:\progra~1\intern~1\iexplore.exe
7043 file://%:p&lt;CR&gt;
7044
7045 open http link under cursor in your browser
7046
7047 map ,i :update&lt;CR&gt;: !start c:\progra~1\intern~1\iexplore.exe
7048 &lt;cWORD&gt;&lt;CR&gt;
7049
7050 Note use of cWORD (not cword) meaning OUTER Word
7051
7052 Works for me in XP & 98 (Original came from a posting by Ralf Arens)
7053
7054 zzapper
7055
7056 </pre></tip> </html> <Tip category="KVim">
7057 <html><center>fast page up/down.</center> <pre> <A
7058 HREF="http://vim.sf.net/tip_view.php?tip_id=257">http://vim.sf.net/tip_view.php?tip_id=257</A><BR>
7059
7060 i discovered a cool way to move between pages of the same document in vim
7061 6.1. press a number in -normal mode- and the page up/down. the document
7062 will move with that number of pages up/down.if the number is greater that
7063 the nr of pages, document will move to begin/end of file. i didn't test it
7064 on other version.
7065
7066 </pre></tip> </html> <Tip category="KVim"> <html><center>how
7067 long is the current word?</center> <pre> <A
7068 HREF="http://vim.sf.net/tip_view.php?tip_id=258">http://vim.sf.net/tip_view.php?tip_id=258</A><BR>
7069
7070 ever wondered how long the current word is? this can be quite useful when
7071 editing data files. simply add the following to your .vimrc
7072
7073 nmap &lt;C-_&gt; :echo 'word' expand("&lt;cword&gt;") ' wordlen ='
7074 strlen(expand("&lt;cword&gt;"))&lt;CR&gt;
7075
7076 and it will tell you the word under the cursor, and how long it is.
7077
7078 and for things that arent words, this addition to your .vimrc works on
7079 sections of a line that have been hightligted in visual mode
7080
7081 vmap &lt;C-_&gt; "-y:echo 'word' @- ' wordlen =' strlen(@-)&lt;CR&gt;
7082
7083 again you see the "word", and its length this may also work on vim 5.x,
7084 but i havent checked to make sure.
7085
7086 </pre></tip> </html> <Tip category="KVim"> <html><center>removing
7087 the toolbar (icons) from gvim</center> <pre> <A
7088 HREF="http://vim.sf.net/tip_view.php?tip_id=259">http://vim.sf.net/tip_view.php?tip_id=259</A><BR>
7089
7090 Change good or bad usually encounters interia from people in excepting it.
7091 gvim 6.0 is the first version that introduced the icons shortcut in shape
7092 of a toolbar under the menu. when we upgraded to the new and improved vim
7093 6.1 from vim 5.7 some of people in our company encountered some problems
7094 with their syntax highlighting and some of them objected on the new toolbar
7095 which displayed icons for some common tasks for people more used to GUI.
7096
7097 I finally figured out how to remove this new feature since I also didn't
7098 see much use for it
7099
7100 Here is for all those who haven't figured it out yet
7101
7102 In your .gvimrc include the following two lines
7103
7104 unmenu ToolBar unmenu! ToolBar
7105
7106 Doing this from an open gvim does not remove them but grays them out but
7107 doing from gvimrc does the job
7108
7109 I was also trying to remove the menus at the top and almost succeeded with
7110 a similar technique but somehow the Buffer menu item stays there no matter
7111 what. IMHO it is a bug but it could very well be a feature ;)
7112
7113 I tried this
7114
7115 unmenu * unmenu! *
7116
7117 even added this line after the above two but didn't help unmenu Buffers
7118
7119 I hope this benefits you all as much as I have benefitted from all your tips
7120
7121 </pre></tip> </html> <Tip category="KVim">
7122 <html><center>gvim--&gt;mouse--&gt;popup menu</center> <pre> <A
7123 HREF="http://vim.sf.net/tip_view.php?tip_id=260">http://vim.sf.net/tip_view.php?tip_id=260</A><BR>
7124
7125 This tip is for those who prefer to do some of the common operations like
7126 cut/copy/paste etc using mouse. All u have to do is
7127
7128 :set mousemodel=popup
7129
7130 by this u get a popup menu on right click of your mouse and u can do all
7131 the common operations like undo, cut, copy, paste, select etc using mouse.
7132
7133 u can also customise your popup menu by editing $VIMRUNTIME/menu.vim
7134
7135 </pre></tip> </html> <Tip category="KVim"> <html><center>Close
7136 windows from Gvim poup menu</center> <pre> <A
7137 HREF="http://vim.sf.net/tip_view.php?tip_id=261">http://vim.sf.net/tip_view.php?tip_id=261</A><BR>
7138
7139 To close windows from the popup menu add these lines to your .gvimrc
7140
7141 :amenu PopUp.Close.\ Window :confirm close&lt;CR&gt; :amenu PopUp.Close.\
7142 Other :confirm only&lt;CR&gt;
7143
7144 You obviously need ':set mousemodel=popup' in your .gvimrc as well :=)
7145
7146 </pre></tip> </html> <Tip category="KVim"> <html><center>Bored
7147 of ur arrow shapped mouseptr?</center> <pre> <A
7148 HREF="http://vim.sf.net/tip_view.php?tip_id=262">http://vim.sf.net/tip_view.php?tip_id=262</A><BR>
7149
7150 here is how u can change the shape of ur mouseptr in gvim.
7151
7152 :set mouseshape=n:pencil
7153
7154 this will change the shape of the mouseptr to pencil in normal mode. u can
7155 choose different shapes for different modes. see :h mouseshape
7156
7157 Want more shapes?
7158
7159 Then look for the file cursorfont.h in ur X11/ directory. This file contains
7160 lots of cursor shape #define definitions, like . #define XC_heart 62 .
7161 now :set mouseshape=n:62 will set the shape of the mouseptr to heart in
7162 normal mode.
7163
7164 -ncr
7165
7166 </pre></tip> </html> <Tip category="KVim">
7167 <html><center>color active line</center> <pre> <A
7168 HREF="http://vim.sf.net/tip_view.php?tip_id=263">http://vim.sf.net/tip_view.php?tip_id=263</A><BR>
7169
7170 This tip shows how to color the active line, the line in which the cursor
7171 is, for better reading. You should try possibility 2 before 1, IMHO it is
7172 mostly usable.
7173
7174 possibility 1:
7175 :au! CursorHold * let @/ = '\%' . line('.') . 'l.*' :set ut=500
7176
7177 explanation:
7178 After 500 ms of waiting for you to hit a key, vim sets the search
7179 register to a pattern that matches the current line.
7180
7181 problem:
7182 Register / holds the search pattern, so you cannot have color the active
7183 line and search. Therefore another solution:
7184
7185 possibility 2:
7186 :highlight CurrentLine guibg=darkgrey guifg=white (or whatever
7187 colors you want) :au! Cursorhold * exe 'match CurrentLine /\%'
7188 . line('.') . 'l.*/' :set ut=100
7189
7190 explanation:
7191 This solution uses 'match' to highlight a string, it does not interface
7192 with the current search pattern.
7193
7194 addition:
7195 Turning the highlighning off:
7196 :au! Cursorhold :match none
7197 The order of these commands are important. If :match none is executed
7198 first, the autocommand would almost immediately execute another match
7199 command.
7200
7201 references to vim help:
7202 :help Cursorhold :help 'ut' :help /\%l :help "/ :help \%
7203
7204 </pre></tip> </html> <Tip category="KVim"> <html><center>F5
7205 Compile and Run, F8 Compile (ala Visual Studio)</center> <pre> <A
7206 HREF="http://vim.sf.net/tip_view.php?tip_id=264">http://vim.sf.net/tip_view.php?tip_id=264</A><BR>
7207
7208 I love vim, it's my default editor on my Sun, Windows, Linux and *BSD boxen.
7209 That said, I hate having to flip windows to compile while doing the
7210 write-&gt;compile-&gt;debug loop.
7211
7212 If you're used to Visual Studio and the ability it has to just hit F5 to
7213 compile and run the current file or F8 to compile or step through the code
7214 you'll appreciate this...
7215
7216 This is my Windows version of this scriplet/tiplet. For other platforms,
7217 you'll want to change the IF ELSE loops. You should actually never see
7218 the "Unsuccessful" message from the compile/run loop unless the compiler
7219 completely bombs out. This is from my _vimrc...
7220
7221 map &lt;F5&gt; :call CompileRunGcc()&lt;CR&gt;
7222
7223 map &lt;F8&gt; : call CompileGcc()&lt;CR&gt;
7224
7225 func! CompileRunGcc()
7226 exec "w" "Save the file exec "!gcc % -o %&lt; && cr 10 && IF
7227 EXIST %&lt;.exe (%&lt;) ELSE banner -c = Compile Unsuccessful
7228 " exec "i" "jump back where we were
7229
7230
7231 endfunc
7232
7233 func! CompileGcc()
7234 exec "w" exec "!gcc % -o %&lt; && IF EXIST %&lt;.exe (cr 5 &&
7235 banner -c # Success) ELSE banner -c # Compile Unsuccessful
7236 " exec "i"
7237
7238 endfunc
7239
7240 </pre></tip> </html> <Tip category="KVim">
7241 <html><center>Fast help in full window</center> <pre> <A
7242 HREF="http://vim.sf.net/tip_view.php?tip_id=265">http://vim.sf.net/tip_view.php?tip_id=265</A><BR>
7243
7244 You can get fast access to help by writing small script
7245
7246 #!/bin/bash vim -c "help $1" -c only
7247
7248 now name it eg. vih and from cl
7249
7250 $ vih makeprg
7251
7252 </pre></tip> </html> <Tip category="KVim">
7253 <html><center>use -S command line switch</center> <pre> <A
7254 HREF="http://vim.sf.net/tip_view.php?tip_id=266">http://vim.sf.net/tip_view.php?tip_id=266</A><BR>
7255
7256 The -S switch could be used to simplify common idiom: start Vim and source
7257 a script file: gvim -c ":so foobar.vim" got translated into gvim -S foobar.vim
7258
7259 Yes, this tip is trivial but I still see the -c ":so x" way too often. Time
7260 to update your mind!
7261
7262 </pre></tip> </html> <Tip category="KVim">
7263 <html><center>selectively displaying abbreviations</center> <pre> <A
7264 HREF="http://vim.sf.net/tip_view.php?tip_id=267">http://vim.sf.net/tip_view.php?tip_id=267</A><BR>
7265
7266 Hi Vimmers, abbreviations have always been one of the most useful parts of
7267 vi(m), trouble is when you've got too many you forgot what you called them.
7268
7269 You can of course list the whole lot with
7270
7271 :ab&lt;cr&gt;
7272
7273 But did you know that you can type the first few letters of your abbreviations
7274 and get a list of just thos abs eg
7275
7276 :ab php&lt;cr&gt; gives me all my php abs & :ab perl&lt;cr&gt; gives me all
7277 my perls
7278
7279 also try control-D instrad of &lt;cr&gt;
7280
7281 zzapper
7282
7283 </pre></tip> </html> <Tip category="KVim"> <html><center>Get cursor
7284 position as byte percentage instead of line percentage</center> <pre> <A
7285 HREF="http://vim.sf.net/tip_view.php?tip_id=268">http://vim.sf.net/tip_view.php?tip_id=268</A><BR>
7286
7287 On line 300 of a thousand line file, Vim will show you that you're 30%
7288 through the file. But what if most of the lines have one character in them,
7289 and some of them have twenty thousand? Sometimes it comes in handy to know
7290 your percentage through the file in terms of current-byte / total-bytes.
7291 I looked through the Vim docs and couldn't find a way to do this, so I wrote
7292 a Vim function to show it.
7293
7294 Put this in your .vimrc:
7295
7296 function! Percent()
7297 let byte = line2byte( line( "." ) ) + col( "." ) - 1 let size = (line2byte(
7298 line( "$" ) + 1 ) - 1) " return byte . " " . size . " " . (byte * 100)
7299 / size return (byte * 100) / size
7300 endfunction
7301
7302 (Uncomment the first return to see intermediate values.)
7303
7304 And put this somewhere in your "set statusline=...":
7305
7306 %{Percent()}%%
7307
7308 See "help statusline", "help eval".
7309
7310 </pre></tip> </html> <Tip category="KVim"> <html><center>Syntax highlighting
7311 is "out of sync", seems to correct itself with refresh ??</center> <pre> <A
7312 HREF="http://vim.sf.net/tip_view.php?tip_id=269">http://vim.sf.net/tip_view.php?tip_id=269</A><BR>
7313
7314 This one has come across the 'vim' users mailing list many times, and probably
7315 comp.editors as well...
7316
7317 Summary: see :help :syn-sync and search for 'sync' in your favorite syntax
7318 file in $VIMRUNTIME/syntax
7319
7320 Long Version: The syntax highlight code utilizes a certain synchronization
7321 method to efficiently figure out syntax highlighting, specifically if you
7322 aren't at the very beginning or end of a file. The specific setting is 'syntax
7323 sync'. For various file types the method is set by default in this is setup
7324 in the syntax file and one can vary the degree of trouble which VIM goes to to
7325 try and figure this out. As an example for C, from $VIMRUNTIME/syntax/c.vim:
7326
7327 if exists("c_minlines")
7328 let b:c_minlines = c_minlines
7329 else
7330 if !exists("c_no_if0")
7331 let b:c_minlines = 50 " #if 0 constructs can be long
7332 else
7333 let b:c_minlines = 15 " mostly for () constructs
7334 endif
7335 endif exec "syn sync ccomment cComment minlines=" . b:c_minlines
7336
7337 Where c_minlines is the minimum number of lines that VIM goes backward to try
7338 to find the start of a comment for syntax highlighting. If that line which
7339 starts a comment is outside of that range, highlighting will appear wrong.
7340
7341 You can easily set up something like this in your .vimrc: let c_minlines=500
7342 or even bigger, but realize that it is a performance trade-off and that
7343 syntax highlighting will slow things down.
7344
7345 </pre></tip> </html> <Tip category="KVim">
7346 <html><center>Insert a single character</center> <pre> <A
7347 HREF="http://vim.sf.net/tip_view.php?tip_id=270">http://vim.sf.net/tip_view.php?tip_id=270</A><BR>
7348
7349 Using Insert mode to insert a single character feels clumsy (you need 3
7350 keypresses for one character), so here's a slightly easier way:
7351
7352 :nmap &lt;space&gt; i_&lt;esc&gt;r
7353
7354 Now, when in Normal mode, just press space followed by what it is you want
7355 to insert.
7356
7357 BUG: Repeating the insertion with . doesn't work.
7358
7359 </pre></tip> </html> <Tip category="KVim"> <html><center>easy
7360 (un)commenting out of source code</center> <pre> <A
7361 HREF="http://vim.sf.net/tip_view.php?tip_id=271">http://vim.sf.net/tip_view.php?tip_id=271</A><BR>
7362
7363 Something that I do quite alot is comment out blocks of text, only to uncomment
7364 that same block later. The following mappings have proven useful to me. They
7365 can be applied using visually selected blocks, or with motion keys.
7366
7367 " lhs comments map ,# :s/^/#/&lt;CR&gt; map ,/ :s/^/\/\//&lt;CR&gt; map ,&gt;
7368 :s/^/&gt; /&lt;CR&gt; map ," :s/^/\"/&lt;CR&gt; map ,% :s/^/%/&lt;CR&gt;
7369 map ,! :s/^/!/&lt;CR&gt; map ,; :s/^/;/&lt;CR&gt; map ,- :s/^/--/&lt;CR&gt;
7370 map ,c :s/^\/\/\\|^--\\|^&gt; \\|^[#"%!;]//&lt;CR&gt;
7371
7372 " wrapping comments map ,* :s/^\(.*\)$/\/\* \1 \*\//&lt;CR&gt; map ,(
7373 :s/^\(.*\)$/\(\* \1 \*\)/&lt;CR&gt; map ,&lt; :s/^\(.*\)$/&lt;!--
7374 \1 --&gt;/&lt;CR&gt; map ,d :s/^\([/(]\*\\|&lt;!--\) \(.*\)
7375 \(\*[/)]\\|--&gt;\)$/\2/&lt;CR&gt;
7376
7377 The commands to comment a selection of text are as follows, begining with
7378 begining-of-line comments:
7379
7380 ,# shell, perl, etc ,/ c++ ,&gt; email quote ," vim ,%
7381 latex, prolog ,! assembly?... add single ! ,; scheme ,-
7382 don't remember this one... add -- ,c clears any of the previous
7383 comments
7384
7385 Here are the wrapping comments, each line wrapped individually:
7386
7387 ,* c ,( Standard ML ,&lt; html ,d clears any of
7388 the wrapping comments
7389
7390 </pre></tip> </html> <Tip category="KVim"> <html><center>automaticaly
7391 formating pasted text (p=`])</center> <pre> <A
7392 HREF="http://vim.sf.net/tip_view.php?tip_id=272">http://vim.sf.net/tip_view.php?tip_id=272</A><BR>
7393
7394 In times past I used a nice editor that had the neat feature of automatically
7395 setting pasted text to the proper indent level. Recently I've begun to miss
7396 this so I went looking in the help and camp up with....
7397
7398 =`]
7399
7400 which will format to the end of the pasted text... Perfect to call right
7401 after you past something as the cursor ends up at the top of the pasted text,
7402 thus the mapping:
7403
7404 :map &lt;c-p&gt; =`]
7405
7406 " by the by the above may should be nmap and I am pretty sure c-p is unused,
7407 your mileage will vary no doubt.
7408
7409 However I wanted the formatting to automatically be done so it was two simple
7410 (once I figured out how!) nnoremap:
7411
7412 " [Feral:185/02@14:27] map c-p to what p was (past with no formatting), map
7413 p to p and = to end of pasted text. :nnoremap p p=`] :nnoremap &lt;c-p&gt; p
7414
7415 This simply (as the comment hints at) maps normal mode p to what p did (paste)
7416 then = to `] (last character in the previously changed text). While ctrl+p
7417 just does what p did. (just in case you find you don't want a bit of text
7418 auto formatted.).
7419
7420 reference: :h :nnoremap :h p :h = :h `]
7421
7422 Whatever the name of this idea is, tis something I find handy :)
7423
7424 Happy VIMing
7425
7426 </pre></tip> </html> <Tip category="KVim"> <html><center>Fast
7427 fixing of email quotations (too long lines)</center> <pre> <A
7428 HREF="http://vim.sf.net/tip_view.php?tip_id=273">http://vim.sf.net/tip_view.php?tip_id=273</A><BR>
7429
7430 When using VIM as your editor of choice, even for email processing - as I
7431 do - it is often unpleasing how some MUA's quote the email body produced by
7432 mailers such as Outlook. The lines often span across multiple visual lines
7433 and its difficult to reply on certain parts of it.
7434
7435 With VIM, you can quickly fix those quotations to maintain a proper 75 char
7436 break. For example, when using Mutt, put this line in your .muttrc, or use
7437 a custom .vimrc_mail for it:
7438
7439 set editor="vim -c 'set fo=tcrq' -c 'set tw=76'"
7440
7441 For other MUA's this has to be fitted. However, now, when your quoted email
7442 is displayed, you can use this VIM sequence to fix it:
7443
7444 1. move cursor to first line of broken paragraph 2. press 'V' and move to the
7445 last line of the paragraph you want to fix 3. press 'g' and then 'q'. The
7446 marked text will wrap around to your specified textwidth (76 in our case)
7447 and the quotations will be preserved across the lines
7448
7449 </pre></tip> </html> <Tip category="KVim">
7450 <html><center>Some useful mappings for TeX</center> <pre> <A
7451 HREF="http://vim.sf.net/tip_view.php?tip_id=274">http://vim.sf.net/tip_view.php?tip_id=274</A><BR>
7452
7453 You know, TeX requires a lot of additional formatting code. I'm tired of
7454 opening and closing braces, brakets,
7455 \beginning and \ending etc. I particularly hate typing \begin and \end.
7456 To help myself and to save a few(not a few) keystrokes I naturaly came up to
7457 some solutions, which I wish to share with other TeXnicians and TeXperts whhich
7458 use Vim. "===============================cut here=========================
7459 "=============== you can put it in ~/.vim/after/ftplugin/tex.vim
7460 =============== " " Note: i_&lt;C-L&gt; " This constructs a skeleton of a TeX
7461 environment. " You write a line like this: " floatingfigure:ht&lt;C-L&gt;
7462 " and after you press &lt;C-L&gt;, you get: " " \begin[ht]{floatingfigure}
7463 " " \end{floatingfigure} " -- INSERT -- " " where floatingfigure is the
7464 desired environment " ht are options " : is delimiter; in fact, you can
7465 use whatever delimiter you want " as long it is not in &iskeyword option.
7466 inoremap &lt;buffer&gt; &lt;C-L&gt; 
7467 \:s/[^][:alnum:]&lt;bar&gt;]\+/,/eg
7468 \I\begin{ea}[A]%d%%P \:s/\[,/[/e \:s/,]/]/e
7469 \:s/\[]//e \0f{y%o\endpO
7470 inoremap &lt;buffer&gt; { {}i inoremap &lt;buffer&gt; [ []i inoremap
7471 &lt;buffer&gt; ^ ^{}i inoremap &lt;buffer&gt; _ _{}i inoremap &lt;buffer&gt;
7472 \( \(\)hi inoremap &lt;buffer&gt; \[ \[\]hi
7473
7474 " Note: v_&lt;C-L&gt; " For this to work, you have to write on a blank
7475 line the name of " the desired environment and options (see i_&lt;C-L&gt;)
7476 and visual select " (from top to bottom) this and following lines. " After
7477 pressing &lt;C-L&gt; the selected lines will be surrounded " with begin/end
7478 skeleton of the environment. vnoremap &lt;buffer&gt; &lt;C-L&gt; o
7479 \:s/[^][:alnum:]&lt;bar&gt;]\+/,/eg
7480 \I\begin{ea}[A]%d%%P \:s/\[,/[/e \:s/,]/]/e
7481 \:s/\[]//e \0f{y%gvoo\endp
7482 " vnoremap &lt;buffer&gt; { di{}P " vnoremap &lt;buffer&gt;
7483 [ di[]P vnoremap &lt;buffer&gt;  di^{}P vnoremap &lt;buffer&gt;  di_{}P
7484 vnoremap &lt;buffer&gt; \( di\(\)hP vnoremap &lt;buffer&gt; \[ di\[\]hP
7485
7486 " This makes "two spaces after a comma" before every :write au BufWritePre
7487 *.tex %s/,\(\S\)/, \1/ge
7488
7489 "==================== You can put this in your ~/.vimrc
7490 ======================== " If cursor is inside braces and not before comma,
7491 blank or opening brace, " exit the brace block and stay in insert mode. "
7492 If cursor is outside braces, it inserts a space or perform an abbreviation
7493 " as normal. function! CleverSpace()
7494 let CharOnCursor = strpart( getline('.'), col('.')-2, 1) let
7495 CharAfterCursor = strpart( getline('.'), col('.'), 1) if CharOnCursor
7496 !~ ',\|\s\|(' && CharAfterCursor =~ ')\|]\|}'
7497 normal x
7498 endif
7499 endfunction inoremap &lt;Space&gt; &lt;Space&gt;:call CleverSpace()&lt;LF&gt;a
7500
7501 " I use the last function not only for LaTeX but also in C sources.
7502
7503 </pre></tip> </html> <Tip category="KVim">
7504 <html><center>Some useful mappings for TeX</center> <pre> <A
7505 HREF="http://vim.sf.net/tip_view.php?tip_id=275">http://vim.sf.net/tip_view.php?tip_id=275</A><BR>
7506
7507 You know, TeX requires a lot of additional formatting code. I'm tired of
7508 opening and closing braces, brakets,
7509 \beginning and \ending etc. I particularly hate typing \begin and \end.
7510 To help myself and to save a few(not a few) keystrokes I naturaly came up to
7511 some solutions, which I wish to share with other TeXnicians and TeXperts whhich
7512 use Vim. "===============================cut here=========================
7513 "=============== you can put it in ~/.vim/after/ftplugin/tex.vim
7514 =============== " " Note: i_&lt;C-L&gt; " This constructs a skeleton of a TeX
7515 environment. " You write a line like this: " floatingfigure:ht&lt;C-L&gt;
7516 " and after you press &lt;C-L&gt;, you get: " " \begin[ht]{floatingfigure}
7517 " " \end{floatingfigure} " -- INSERT -- " " where floatingfigure is the
7518 desired environment " ht are options " : is delimiter; in fact, you can
7519 use whatever delimiter you want " as long it is not in &iskeyword option.
7520 inoremap &lt;buffer&gt; &lt;C-L&gt; 
7521 \:s/[^][:alnum:]&lt;bar&gt;]\+/,/eg
7522 \I\begin{ea}[A]%d%%P \:s/\[,/[/e \:s/,]/]/e
7523 \:s/\[]//e \0f{y%o\endpO
7524 inoremap &lt;buffer&gt; { {}i inoremap &lt;buffer&gt; [ []i inoremap
7525 &lt;buffer&gt; ^ ^{}i inoremap &lt;buffer&gt; _ _{}i inoremap &lt;buffer&gt;
7526 \( \(\)hi inoremap &lt;buffer&gt; \[ \[\]hi
7527
7528 " Note: v_&lt;C-L&gt; " For this to work, you have to write on a blank
7529 line the name of " the desired environment and options (see i_&lt;C-L&gt;)
7530 and visual select " (from top to bottom) this and following lines. " After
7531 pressing &lt;C-L&gt; the selected lines will be surrounded " with begin/end
7532 skeleton of the environment. vnoremap &lt;buffer&gt; &lt;C-L&gt; o
7533 \:s/[^][:alnum:]&lt;bar&gt;]\+/,/eg
7534 \I\begin{ea}[A]%d%%P \:s/\[,/[/e \:s/,]/]/e
7535 \:s/\[]//e \0f{y%gvoo\endp
7536 " vnoremap &lt;buffer&gt; { di{}P " vnoremap &lt;buffer&gt;
7537 [ di[]P vnoremap &lt;buffer&gt;  di^{}P vnoremap &lt;buffer&gt;  di_{}P
7538 vnoremap &lt;buffer&gt; \( di\(\)hP vnoremap &lt;buffer&gt; \[ di\[\]hP
7539
7540 " This makes "two spaces after a comma" before every :write au BufWritePre
7541 *.tex %s/,\(\S\)/, \1/ge
7542
7543 "==================== You can put this in your ~/.vimrc
7544 ======================== " If cursor is inside braces and not before comma,
7545 blank or opening brace, " exit the brace block and stay in insert mode. "
7546 If cursor is outside braces, it inserts a space or perform an abbreviation
7547 " as normal. function! CleverSpace()
7548 let CharOnCursor = strpart( getline('.'), col('.')-2, 1) let
7549 CharAfterCursor = strpart( getline('.'), col('.'), 1) if CharOnCursor
7550 !~ ',\|\s\|(' && CharAfterCursor =~ ')\|]\|}'
7551 normal x
7552 endif
7553 endfunction inoremap &lt;Space&gt; &lt;Space&gt;:call CleverSpace()&lt;LF&gt;a
7554
7555 " I use the last function not only for LaTeX but also in C sources.
7556
7557 </pre></tip> </html> <Tip category="KVim">
7558 <html><center>Function signature previewer</center> <pre> <A
7559 HREF="http://vim.sf.net/tip_view.php?tip_id=276">http://vim.sf.net/tip_view.php?tip_id=276</A><BR>
7560
7561 Have you ever tried to call a function which parameters you have forgotten?
7562 Especially those long named and with long parameter list GTK+ functions
7563 like gtk_menu_item_image_from_stock_new(..........) !!! By accident I saw a
7564 function in Vim help. It's name was PreviewWord and it allowed one to jump
7565 in the preview window to the tag for the word cursor is on. I _slightly_
7566 modified this function not to need tags file, but to search included files
7567 instead. I wrote another function, which uses the above said one, which
7568 triggers PreviewWord when you open the parenthesis after a function name.
7569 Here it is: " Note: " This is literally stolen from Vim help. The only
7570 changes are: " (1) if w != "" becomes if w =~ "\k" "
7571 (2) exe "silent! ptag " . w becomes exe "silent! psearch " . w " *
7572 The first change prevents PreviewWord of searching while cursor is on some "
7573 non-keyword characters, e.g. braces, asterisks, etc. function! PreviewWord()
7574 if &previewwindow " don't do this in the
7575 preview window
7576 return
7577 endif let w = expand("&lt;cword&gt;") " get the word under
7578 cursor if w =~ "\k" " if there is one
7579 ":ptag" to it
7580
7581 " Delete any existing highlight before showing another tag
7582 silent! wincmd P " jump to preview
7583 window if &previewwindow " if we really
7584 get there...
7585 match none " delete existing
7586 highlight wincmd p " back to
7587 old window
7588 endif
7589
7590 " Try displaying a matching tag for the word under the cursor
7591 let v:errmsg = "" exe "silent! psearch " . w if v:errmsg =~
7592 "tag not found"
7593 return
7594 endif
7595
7596 silent! wincmd P " jump to preview
7597 window if &previewwindow " if we really get
7598 there...
7599 if has("folding")
7600 silent! .foldopen " don't want
7601 a closed fold
7602 endif call search("$", "b") " to end of
7603 previous line let w = substitute(w, '\\', '\\\\',
7604 "") call search('\&lt;\V' . w . '\&gt;') "
7605 position cursor on match " Add a match highlight to
7606 the word at this position hi previewWord term=bold
7607 ctermbg=green guibg=green exe 'match previewWord "\%'
7608 . line(".") . 'l\%' . col(".") . 'c\k*"' wincmd p
7609 " back to old window
7610 endif
7611 endif
7612 endfunction au! CursorHold *.[ch] nested call PreviewWord()
7613
7614 " Note: " When you open a parenthesis after a function name, and
7615 at the " line end, that function's definition is previewed through
7616 PreviewWord(). " This is inspired from Delphi's CodeInsight technology.
7617 " Something similar (PreviewClassMembers) could be written for " the C++
7618 users, for previewing the class members when you type " a dot after an
7619 object name. " If somebody decides to write it, please, mail it to me.
7620 function! PreviewFunctionSignature()
7621 let CharOnCursor = strpart( getline('.'), col('.')-2, 1) if col(".") ==
7622 col("$")
7623 call PreviewWord()
7624 endif return "("
7625 endfunction inoremap &lt;buffer&gt; (
7626 &lt;C-R&gt;=PreviewFunctionSignature()&lt;LF&gt;
7627
7628 </pre></tip> </html> <Tip category="KVim">
7629 <html><center>Function signature previewer</center> <pre> <A
7630 HREF="http://vim.sf.net/tip_view.php?tip_id=277">http://vim.sf.net/tip_view.php?tip_id=277</A><BR>
7631
7632 Have you ever tried to call a function which parameters you have forgotten?
7633 Especially those long named and with long parameter list GTK+ functions
7634 like gtk_menu_item_image_from_stock_new(..........) !!! By accident I saw a
7635 function in Vim help. It's name was PreviewWord and it allowed one to jump
7636 in the preview window to the tag for the word cursor is on. I _slightly_
7637 modified this function not to need tags file, but to search included files
7638 instead. I wrote another function, which uses the above said one, which
7639 triggers PreviewWord when you open the parenthesis after a function name.
7640 Here it is: " Note: " This is literally stolen from Vim help. The only
7641 changes are: " (1) if w != "" becomes if w =~ "\k" "
7642 (2) exe "silent! ptag " . w becomes exe "silent! psearch " . w " *
7643 The first change prevents PreviewWord of searching while cursor is on some "
7644 non-keyword characters, e.g. braces, asterisks, etc. function! PreviewWord()
7645 if &previewwindow " don't do this in the
7646 preview window
7647 return
7648 endif let w = expand("&lt;cword&gt;") " get the word under
7649 cursor if w =~ "\k" " if there is one
7650 ":ptag" to it
7651
7652 " Delete any existing highlight before showing another tag
7653 silent! wincmd P " jump to preview
7654 window if &previewwindow " if we really
7655 get there...
7656 match none " delete existing
7657 highlight wincmd p " back to
7658 old window
7659 endif
7660
7661 " Try displaying a matching tag for the word under the cursor
7662 let v:errmsg = "" exe "silent! psearch " . w if v:errmsg =~
7663 "tag not found"
7664 return
7665 endif
7666
7667 silent! wincmd P " jump to preview
7668 window if &previewwindow " if we really get
7669 there...
7670 if has("folding")
7671 silent! .foldopen " don't want
7672 a closed fold
7673 endif call search("$", "b") " to end of
7674 previous line let w = substitute(w, '\\', '\\\\',
7675 "") call search('\&lt;\V' . w . '\&gt;') "
7676 position cursor on match " Add a match highlight to
7677 the word at this position hi previewWord term=bold
7678 ctermbg=green guibg=green exe 'match previewWord "\%'
7679 . line(".") . 'l\%' . col(".") . 'c\k*"' wincmd p
7680 " back to old window
7681 endif
7682 endif
7683 endfunction au! CursorHold *.[ch] nested call PreviewWord()
7684
7685 " Note: " When you open a parenthesis after a function name, and
7686 at the " line end, that function's definition is previewed through
7687 PreviewWord(). " This is inspired from Delphi's CodeInsight technology.
7688 " Something similar (PreviewClassMembers) could be written for " the C++
7689 users, for previewing the class members when you type " a dot after an
7690 object name. " If somebody decides to write it, please, mail it to me.
7691 function! PreviewFunctionSignature()
7692 let CharOnCursor = strpart( getline('.'), col('.')-2, 1) if col(".") ==
7693 col("$")
7694 call PreviewWord()
7695 endif return "("
7696 endfunction inoremap &lt;buffer&gt; (
7697 &lt;C-R&gt;=PreviewFunctionSignature()&lt;LF&gt;
7698
7699 </pre></tip> </html> <Tip category="KVim">
7700 <html><center>all the right moves</center> <pre> <A
7701 HREF="http://vim.sf.net/tip_view.php?tip_id=278">http://vim.sf.net/tip_view.php?tip_id=278</A><BR>
7702
7703 One of the principles of effective text editing is moving around very
7704 efficiently. Following are some pointers which may help u do that.
7705
7706 h move one character left j move one row down
7707 k move one row up l move one char. right. w move
7708 to begining of next word b move to begining of previous word
7709 e move to end of word W move to begining of next word after a
7710 whitespace B move to begining of pervious word before a whitespace
7711 E move to end of word before a whitespace.
7712
7713 (All the above movements can be preceeded by a numeric value . i.e '4j'
7714 will move 4 rows down )
7715
7716 ^ move to first non blank char of the line. g_ move to last non
7717 blank char of the line. 0 moev to begining of line $ move
7718 to end of line. gg move to first line. G move to last line.
7719 nG move to "n"th line. H top of screen.
7720 M middle of screen
7721 L bottom of screen
7722 Ctrl-D move half page down Ctrl-U move half page up. Ctrl-B page-up
7723 Ctrl-F page down.
7724
7725 Ctrl-o last cursor position. '[a-z,0-9,A-Z] jump to the marker. (u
7726 can set a marker on line by :- m[a-zA-Z,0-9] and then jump back to
7727 it by '[a-z,A-Z0-9]
7728
7729 n next matching search pattern N previous matching search pattern *
7730 next word under cursor
7731 # previous word under cursor. g* next matching search pattern
7732 under cursor. g# previous matching search pattern under cursor.
7733
7734 </pre></tip> </html> <Tip category="KVim"> <html><center>On Windows, make GVim
7735 the default action for double-click with "unknown file types"</center> <pre> <A
7736 HREF="http://vim.sf.net/tip_view.php?tip_id=279">http://vim.sf.net/tip_view.php?tip_id=279</A><BR>
7737
7738 I find myself installing the following registry modification for all my
7739 PC's now (even other people's PC's). It applies to Microsoft Windows
7740 machines only. The following is also for Windows 9x... NT or XP or 2000
7741 may require modifications (which I don't care to understand!).
7742
7743 The problem: You double-click on a file that doesn't have a 'registered type'
7744 and that pesky "What program should I use?" dialog pops up. Even worse,
7745 depending on the installation, the GVim icon may not be listed, and one has
7746 to browse to the executable... and then the type becomes forever bonded
7747 to being editted with GVim (if that box is checked). The standard Vim 6.1
7748 installation does include a "right click to edit" menu item for all files,
7749 but a double-click is so much faster!
7750
7751 The solution: What if unregistered types would just automatically open up
7752 in GVim? Well, they can.. with a little registry trickery.
7753
7754 How to Install it:
7755
7756 Step 1. Create a text file called "vimalways.reg" and paste the below text
7757 into it.
7758
7759 Step 2. Important NOTE: You will have to edit the pathname to correspond
7760 to the pathname of your GVim.exe. The text below works fine for a GVim 6.1
7761 default installation.
7762
7763 Step 3: Save the file.
7764
7765 Step 4: Right-click on the file and select "install". Then you are done!
7766
7767 ------ vimalways.reg ------- cut here ------snip---snip--- REGEDIT4
7768
7769 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell]
7770
7771 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Open with &GVim] @="Open
7772 with &GVim"
7773
7774 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Open with &GVim\command]
7775 @="\"C:\\vim\\vim61\\gvim.exe\" \"%1\""
7776
7777 ----end of file---- cut here----- snip---snip----
7778
7779 Note 1. This can't be de-installed automatically, and if you want to remove
7780 it, you'll have to edit the registry by hand (annoying, but easy).
7781
7782 Note 2. Keep this file around, so when you upgrade your GVim, all you have
7783 to do is modify the pathname (to say, for example, vim62) and then install
7784 it again.
7785
7786 Ok, thanks for playing! And thanks to the author(s) of Vim and GVim.
7787 If it weren't for them, I'd still be using elvis or stevie!
7788
7789
7790 </pre></tip> </html> <Tip category="KVim"> <html><center>Integration
7791 with PyUnit testing framework</center> <pre> <A
7792 HREF="http://vim.sf.net/tip_view.php?tip_id=280">http://vim.sf.net/tip_view.php?tip_id=280</A><BR>
7793
7794 Vim has a wonderful ability to integrate with external tools, like compilers,
7795 make, ctags etc. That's one of the reasons we love it.
7796
7797 PyUnit can be seen as a "compiler" for the Python test code. To understand
7798 it, Vim should be told about the language the PyUnit speaks. This could be
7799 done with 'errorformat' option:
7800
7801 setlocal efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
7802
7803 This magic spell enables Vim to parse unittest.TextRunner's output and to
7804 enter quick-fix mode. To run all your unit tests at once you'll need to setup
7805 'makeprg' option and provide a runner. I'm using this setup:
7806
7807 setlocal makeprg=./alltests.py
7808
7809 And contents of the alltests.py (for the sake of completeness):
7810
7811 #!/usr/bin/env python2
7812
7813 import unittest import sys sys.path.append('unittests')
7814
7815 modules_to_test = (
7816 'fooTest', 'barTest', 'bazTest',
7817 )
7818
7819 def suite():
7820 alltests = unittest.TestSuite() for module in map(__import__,
7821 modules_to_test):
7822 alltests.addTest(unittest.findTestCases(module))
7823 return alltests
7824
7825 if __name__ == '__main__':
7826 unittest.main(defaultTest='suite')
7827
7828 ============== end of the alltests.py file ========================
7829
7830 While talking about it, I'd also suggest to add a couple of mappings.
7831 In the end, my vim/files/ftplugin/python.vim looks like this:
7832
7833 setlocal makeprg=./alltests.py\ -q setlocal efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\
7834 line\ %l%.%#,%Z%[%^\ ]%\\@=%m iabbr &lt;buffer&gt; sae self.assertEquals
7835 iabbr &lt;buffer&gt; sar self.assertRaises
7836
7837 For details see :help quick-fix, :help
7838 'efm' and :help 'makeprg'. See also: <A
7839 HREF="http://c2.com/cgi/wiki?PythonUnit">http://c2.com/cgi/wiki?PythonUnit</A><BR>
7840
7841 Many thanks to Stefan Roemer who patiently spent quite some time to build
7842 'efm' for me.
7843
7844 </pre></tip> </html> <Tip category="KVim">
7845 <html><center>Stateful zz</center> <pre> <A
7846 HREF="http://vim.sf.net/tip_view.php?tip_id=281">http://vim.sf.net/tip_view.php?tip_id=281</A><BR>
7847
7848 Do you find yourself hitting 'zz' all the time in order to see some context of
7849 what you're currently working on? If so, then this tip might be for you. If
7850 you add the following line in your vimrc, you can toggle zz mode by pressing
7851 &lt;Leader&gt;zz.
7852
7853 " maintain a constant zz state, second call will toggle it back off map
7854 &lt;Leader&gt;zz :let &scrolloff=999-&scrolloff&lt;CR&gt;
7855
7856 </pre></tip> </html> <Tip category="KVim">
7857 <html><center>Folding with Regular Expression</center> <pre> <A
7858 HREF="http://vim.sf.net/tip_view.php?tip_id=282">http://vim.sf.net/tip_view.php?tip_id=282</A><BR>
7859
7860 Well, I've tried to understand some of the folding scripts, but life's too
7861 short. Instead, I added the following lines to my vimrc file.
7862
7863 set
7864 foldexpr=(getline(v:lnum)=~@/)?0:(getline(v:lnum-1)=~@/)\|\|(getline(v:lnum+1)=~@/)?1:2
7865 map \z :set foldmethod=expr foldlevel=0 foldcolumn=2&lt;CR&gt;
7866
7867 The first line is an extension of foldexpr=(getline(v:lnum)=~@/)?0:1 The
7868 second line (re)sets the foldmethod to expr(ession) plus.
7869
7870 First search for /regexp/, then fold everything else with \z Use zr to reveal
7871 more context (before/after) lines.
7872
7873 You could add (getline(v:lnum-2)=~@/)\|\|(getline(v:lnum+2)=~@/)?2:3 but it
7874 will take longer as folded lines (the majority) evaluate the full expression.
7875
7876 What could be easier?
7877
7878 </pre></tip> </html> <Tip category="KVim"> <html><center>Turn
7879 on syntax coloring in Mac OS X</center> <pre> <A
7880 HREF="http://vim.sf.net/tip_view.php?tip_id=283">http://vim.sf.net/tip_view.php?tip_id=283</A><BR>
7881
7882 This tip is actually for vim 6.1. To turn on syntax coloring in Mac OS X
7883 enter the following commands, or place them in your $HOME/.vimrc file.
7884
7885 :set term=builtin_beos-ansi :syntax on
7886
7887 </pre></tip> </html> <Tip category="KVim"> <html><center>Mapping
7888 to print syntax highlighted buffer in B&W</center> <pre> <A
7889 HREF="http://vim.sf.net/tip_view.php?tip_id=284">http://vim.sf.net/tip_view.php?tip_id=284</A><BR>
7890
7891 I use this mapping to print syntax highlighted C++ code in B&W This tip
7892 needs vimscript #233 print_bw.
7893
7894 The mapping is as follows map &lt;C-p&gt; :color
7895 print_bw&lt;CR&gt;:hardcopy&lt;CR&gt;:color sean&lt;CR&gt;:syn on&lt;CR&gt;
7896
7897 Change ":color sean" to whatever is your chosen color scheme. Need to
7898 change line 7 of print_bw from "syntax reset" to "syntax off" &lt;C-p&gt;
7899 on a syntax highlighted buffer turns off syntax highlighting , sets the
7900 colors to B&W, prints the buffer, resets the color scheme and turns on syntax
7901 highlighting again.
7902
7903 </pre></tip> </html> <Tip category="KVim">
7904 <html><center>Don't use the escape key!</center> <pre> <A
7905 HREF="http://vim.sf.net/tip_view.php?tip_id=285">http://vim.sf.net/tip_view.php?tip_id=285</A><BR>
7906
7907 Vim (any vi really) is a dream for touch typists... Until you want to switch
7908 from insert mode to normal mode. Then you've got to reach way up to whack
7909 the escape key.
7910
7911 Or at least that's what I was doing until I realized that (drum roll please)
7912
7913 Esc is exactly equivalent to control-[ (that's the
7914 control key plus the left square bracket key)
7915
7916 That little bit of knowledge, plus mapping my caps lock to another control
7917 key, was what turned my fascination with Vim into true love. You never have
7918 to lose track of the home row again!
7919
7920 For Xfree86 users - you can make the capslock key another control key by adding
7921
7922 Option "XkbOptions" "ctrl:nocaps"
7923
7924 to the InputDevice section of your XF86Config file.
7925
7926 For Windows NT/2000 users - use the following .reg file to do the same thing:
7927
7928 REGEDIT4
7929
7930 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
7931 "Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
7932
7933 </pre></tip> </html> <Tip category="KVim"> <html><center>Recover
7934 after doing something... ugly.</center> <pre> <A
7935 HREF="http://vim.sf.net/tip_view.php?tip_id=286">http://vim.sf.net/tip_view.php?tip_id=286</A><BR>
7936
7937 I was once editing a file and wanted to test something. The test was meant
7938 to add a line at the end of the file, from outside vim. All was fine, but
7939 instead of &gt;&gt;, I wrote &gt;. You can imagine what happened... :)
7940
7941 If you happen to do something like that, the solution is:
7942
7943 :recover
7944
7945 </pre></tip> </html> <Tip category="KVim">
7946 <html><center>Cool trick to change numbers</center> <pre> <A
7947 HREF="http://vim.sf.net/tip_view.php?tip_id=287">http://vim.sf.net/tip_view.php?tip_id=287</A><BR>
7948
7949 In the gvim if you want to decrement any number just put ur curcor on that
7950 number in Esc mode and pres &lt;CTRL&gt; X
7951
7952 </pre></tip> </html> <Tip category="KVim"> <html><center>A keymapping
7953 to generate Java setters and getters automatically</center> <pre> <A
7954 HREF="http://vim.sf.net/tip_view.php?tip_id=288">http://vim.sf.net/tip_view.php?tip_id=288</A><BR>
7955
7956 This mapping makes it much simpler to write new java classes by simplifying
7957 some of the dull repetative coding (ie setters and getters).
7958
7959 To use, first write a basic class with the following format:
7960
7961 public class MyClass {
7962
7963 private &lt;type&gt; &lt;varname&gt; = &lt;initvalue&gt;; private
7964 &lt;type&gt; &lt;varname&gt; = initvalue&gt;;
7965
7966 // getters
7967
7968 // setters
7969
7970 }
7971
7972 Note the getters/setters comment -- they are important as they are used to
7973 place the getters and setters.
7974
7975 The mapping is:
7976
7977 map jgs mawv/ &lt;Enter&gt;"ty/
7978 &lt;Enter&gt;wvwh"ny/getters&lt;Enter&gt;$a&lt;Enter&gt;&lt;Enter&gt;public
7979 &lt;Esc&gt;"tpa&lt;Esc&gt;"npbiget&lt;Esc&gt;l~ea()&lt;Enter&gt;{&lt;Enter&gt;&lt;Tab&gt;return
7980 &lt;Esc&gt;"npa;&lt;Enter&gt;}&lt;Esc&gt;=&lt;Enter&gt;&lt;Esc&gt;/setters&lt;Enter&gt;$a&lt;Enter&gt;&lt;Enter&gt;public
7981 void &lt;Esc&gt;"npbiset&lt;Esc&gt;l~ea(&lt;Esc&gt;"tpa
7982 &lt;Esc&gt;"npa)&lt;Enter&gt;{&lt;Enter&gt;&lt;Tab&gt;this.&lt;Esc&gt;"npa=&lt;Esc&gt;"npa;&lt;Enter&gt;}&lt;Esc&gt;=&lt;Enter&gt;`ak
7983
7984 (the above should be one long line with no spaces between the end of the
7985 lines above).
7986
7987 To use this to generate a class go to the variable that should have a
7988 setter/getter and place the curser at the beginning of the 'private':
7989
7990 private &lt;type&gt; &lt;variable&gt; = &lt;initvalue&gt;' ^
7991
7992 Then type:
7993
7994 jgs
7995
7996 this will create the first getter/setter and then move up to the next
7997 variable. You can just keep typing jgs until all the getters/setters have
7998 been generated.
7999
8000 This should mapping isn't perfect and someone could probably make it a little
8001 cleaner. It could also relatively easily be adapted to C++. Please feel free
8002 to send me any feedback/enhancements as I am trying to compile a list of these.
8003
8004 </pre></tip> </html> <Tip category="KVim"> <html><center>Alternative
8005 &lt;escape&gt; that allows you to do a "quick and dirty
8006 insert" and get out into normal mode</center> <pre> <A
8007 HREF="http://vim.sf.net/tip_view.php?tip_id=289">http://vim.sf.net/tip_view.php?tip_id=289</A><BR>
8008
8009 This is an alternative key combo for the escape key from the one mentioned
8010 by David A. Rogers in vimtip #285.
8011
8012 I do a lot of editting in Vim, and I've always found myself in situations where
8013 I had to "do a quick insert" - basically (from normal mode), change into insert
8014 mode, type in one quick word, then &lt;esc&gt; out, then navigate elsewhere.
8015
8016 As has been rightly observed by a lot of people, the &lt;esc&gt; key can
8017 sometimes be a little bit out of the way. But that's no problem for ViM, is it?
8018
8019 At first, I thought of editting the ViM source code itself, in order to come
8020 up with a command that could do things like say "let me jump into insert
8021 mode, type a few quick words, then escape out into normal mode when i press
8022 something like double &lt;space&gt;".
8023
8024 It was only later when reading through the section in
8025 Jesse Goerz's "Beginner's Guide to ViM" on remapping (<A
8026 HREF="http://newbiedoc.sourceforge.net/tutorials/vim/mapping-vim.html)
8027 that I got inspired to retake a look at using remapping as an alternative
8028 instead.">http://newbiedoc.sourceforge.net/tutorials/vim/mapping-vim.html)
8029 that I got inspired to retake a look at using remapping as an alternative
8030 instead.</A><BR>
8031
8032 This is what I came up with.. Use whatever is comfortable for you - single
8033 or double &lt;Shift-space&gt;
8034
8035 :map! &lt;S-space&gt; &lt;esc&gt; :map! &lt;S-space&gt;&lt;S-space&gt;
8036 &lt;esc&gt;
8037
8038 With this quick combo ("Shift", + &lt;space&gt;), one can easily (and might
8039 I add, intuitively) "do a quick insert" and exit quickly out into normal
8040 mode. I guess I always thought the &lt;space&gt; would be a good way to
8041 do this sort of thing, since it is after all, so intuitive in the typing
8042 process. So why not make it such that it can "escape" you out into normal
8043 mode as well? Just type 'i', to go into insert mode, type in your stuff,
8044 and once you're done, hit Shift-space!
8045
8046 </pre></tip> </html> <Tip category="KVim"> <html><center>Text
8047 Processing With Integrated Spell Checking</center> <pre> <A
8048 HREF="http://vim.sf.net/tip_view.php?tip_id=290">http://vim.sf.net/tip_view.php?tip_id=290</A><BR>
8049
8050 I have written an HTML document to help others use Vim as a basic text
8051 processing application. It discusses how to integrate spell checking,
8052 dictionary, and thesaurus applications. It also talks about wrapping lines,
8053 indentation, justification, and the vim settings that effect the behavior
8054 of these operations. The document can be found at:
8055 <A
8056 HREF="http://www.highley-recommended.com/text-processing.html">http://www.highley-recommended.com/text-processing.html</A><BR>
8057
8058 Everything has been tested with UNIX, Linux, Windows, and Windows with
8059 Cygwin patforms.
8060
8061 </pre></tip> </html> <Tip category="KVim"> <html><center>^P
8062 & auto filling of variables and text</center> <pre> <A
8063 HREF="http://vim.sf.net/tip_view.php?tip_id=291">http://vim.sf.net/tip_view.php?tip_id=291</A><BR>
8064
8065 Do you know you can auto fill the variable and names as you type your code
8066 ? This will help most of the programmers, who always try hard to remember the
8067 variable names and browse through all the files to find out the variable name.
8068 Use Ctrl+P and Ctrl+N to autofill the variables names etc. Just practice,
8069 you will feel the ease of using vim
8070
8071 </pre></tip> </html> <Tip category="KVim">
8072 <html><center>vim + cscope + cygwin</center> <pre> <A
8073 HREF="http://vim.sf.net/tip_view.php?tip_id=292">http://vim.sf.net/tip_view.php?tip_id=292</A><BR>
8074
8075 I've found that vim + cscope + cygwin does not work. The problem seems to
8076 be that in
8077
8078 sprintf(cmd, "exec %s -dl -f %s", prog, csinfo[i].fname);
8079
8080 vim execs cscope with the "-dl" options, causing it to fail. It is probably
8081 a cscope bug, but a simple workaround is top build vim without thad "d":
8082
8083 sprintf(cmd, "exec %s -l -f %s", prog, csinfo[i].fname);
8084
8085 seems to work for me!
8086
8087 </pre></tip> </html> <Tip category="KVim"> <html><center>remember
8088 where you had ended reading help</center> <pre> <A
8089 HREF="http://vim.sf.net/tip_view.php?tip_id=293">http://vim.sf.net/tip_view.php?tip_id=293</A><BR>
8090
8091 You could jump to the last place you had been while reading Vim help files
8092 if you add this to your .vimrc file:
8093
8094 au BufLeave * if &ft == "help" | mark H | endif
8095
8096 Then use 'H to go to the mark H.
8097
8098 To work between Vim runs 'viminfo' option should be setup to save file marks.
8099 See :help 'viminfo' and :help file-marks for more information.
8100
8101 </pre></tip> </html> <Tip category="KVim"> <html><center>Use
8102 Ctrl-S to save current or new files.</center> <pre> <A
8103 HREF="http://vim.sf.net/tip_view.php?tip_id=294">http://vim.sf.net/tip_view.php?tip_id=294</A><BR>
8104
8105 I wanted to have a single key stroke that would save existing files, or call
8106 the file browser. Here's a key map for Ctrl-S to accomplish that (place in
8107 vimrc file):
8108
8109 if has("gui_running")
8110 " If the current buffer has never been saved, it will have no name,
8111 " call the file browser to save it, otherwise just save it. :map
8112 &lt;silent&gt; &lt;C-S&gt; :if expand("%") == ""&lt;CR&gt;:browse confirm
8113 w&lt;CR&gt;:else&lt;CR&gt;:confirm w&lt;CR&gt;:endif&lt;CR&gt;
8114 endif
8115
8116 Tom Kimpton
8117
8118 </pre></tip> </html> <Tip category="KVim">
8119 <html><center>Line/word/file/whatever completion</center> <pre> <A
8120 HREF="http://vim.sf.net/tip_view.php?tip_id=295">http://vim.sf.net/tip_view.php?tip_id=295</A><BR>
8121
8122 In addition to vimtip #291 you can use whole &lt;C-x&gt; completion mode. It
8123 can complete whole lines (&lt;C-x&gt;l, then &lt;C-p&gt;, &lt;C-n&gt;),
8124 filenames (&lt;C-f&gt;), keywords, words from custom dictionary and many,
8125 many others. During coding it usually saves a LOT of key strokes ;) This
8126 mode has many other powerful features, for example when completing word (by
8127 &lt;C-x&gt;&lt;C-p&gt; or just by &lt;C-p&gt;) you can continue completion
8128 with another &lt;C-x&gt;&lt;C-p&gt;. For example, after writing such text:
8129
8130 this is first line second line is here
8131
8132 Placing cursor at third line and pressing &lt;C-x&gt;l will double last
8133 line - &lt;C-n&gt;, &lt;C-p&gt; in this moment can be used to manipulate
8134 completed line. Or, instead of completing whole line you can press 'f' and
8135 then complete by &lt;C-p&gt; which will result in 'first' word. After that
8136 you can &lt;C-x&gt;&lt;C-p&gt; to get 'line' word (since this is next word
8137 after 'first'). Try yourself for other powerful combinations.
8138
8139 </pre></tip> </html> <Tip category="KVim"> <html><center>Attach
8140 the currently open file to email</center> <pre> <A
8141 HREF="http://vim.sf.net/tip_view.php?tip_id=296">http://vim.sf.net/tip_view.php?tip_id=296</A><BR>
8142
8143 This is very simple, but most people don't seem to take advantage of
8144 this. Often you have some file (source code or other text file) already open
8145 in an existing vim session and you need to attach it with an email. It is
8146 very simple.
8147 - First copy the filename into clipboard. For this I put the following
8148 mapping in vimrc and press &lt;F2&gt;:
8149 nnoremap &lt;F2&gt; :let @*=expand("%:p")&lt;cr&gt;
8150 - Go to your email compose window and use your regular file attachment
8151 menu (Insert-&gt;File in outlook) and press ^V (or whatever key to paste
8152 clipboard) and press Enter.
8153
8154 That is all there to it. If you are on windows and your email client doesn't
8155 accept forward-slashes, then you might want to change the map to:
8156
8157 nnoremap &lt;F2&gt; :let @*=substitute(expand("%:p"), "/", "\\",
8158 "g")&lt;cr&gt;
8159
8160 HTH, Hari
8161
8162 </pre></tip> </html> <Tip category="KVim"> <html><center>Start
8163 in insert mode without loosing your escape key</center> <pre> <A
8164 HREF="http://vim.sf.net/tip_view.php?tip_id=297">http://vim.sf.net/tip_view.php?tip_id=297</A><BR>
8165
8166 There are two parts to this, each is fairly simple.
8167
8168 First, I want to start in insert mode. Well "set im!" in my vimrc did the
8169 job, but I lost the escape key. Second, I have found that often times,
8170 when I'm in command mode, I hit escape trying to get back into insert mode.
8171 I am always rewarded with a beep, telling me once again I made that mistake.
8172
8173 So I mapped esc in command mode to set insert mode (":set im") and I mapped
8174 esc in insert mode to unset insert mode (&lt;c-o&gt;:set im) Well then I
8175 realized if you hit "i" in command mode, escape woulding work the first time.
8176 So here's the code to add to your vimrc:
8177
8178 set im! " start in insert mode map &lt;esc&gt; :set
8179 im!&lt;cr&gt; " escape in command mode goes to insert mode map
8180 i :set im!&lt;cr&gt; " i in command mode goes to insert mode
8181 map! &lt;esc&gt; &lt;c-o&gt;:set im!&lt;cr&gt; " escape in insert mode goes
8182 to command mode
8183
8184 see :help insert
8185
8186 </pre></tip> </html> <Tip category="KVim"> <html><center>Changing
8187 case with regular expressions</center> <pre> <A
8188 HREF="http://vim.sf.net/tip_view.php?tip_id=298">http://vim.sf.net/tip_view.php?tip_id=298</A><BR>
8189
8190 I stumbled across this factoid on a website about vi. I haven't been able to
8191 locate it in the Vim documentation, but it works in Vim, and it's very handy.
8192
8193 There are times that you might like to go through a file and change the case
8194 of characters that match some arbitrary criteria. If you understand regular
8195 expressions well, you can actually do this fairly easily.
8196
8197 It's as simple as placing \U or \L in front of any backreferences in your
8198 regular expressions. Vim will make the text in the backreference uppercase
8199 or lowercase (respectively).
8200
8201 (A "backreference" is a part of a regular expression that refers to a previous
8202 part of a regular expression. The most common backrefernces are &, \1, \2,
8203 \3, ... , \9).
8204
8205 Some examples that demonstrate the power of this technique:
8206
8207 Lowercase the entire file - :%s/.*/\L&/g
8208
8209 (& is a handy backreference that refers to the complete text of the match.)
8210
8211 Uppercase all words that are preceded by a &lt; (i.e. opening HTML tag names):
8212 :%s/&lt;\(\w*\)/&lt;\U\1/g
8213
8214 Please add a note if you know where this is in the documentation. I have
8215 done Ctrl-D searches on upper, lower, \U, and \L with no luck.
8216
8217 </pre></tip> </html> <Tip category="KVim">
8218 <html><center>Open file under cursor.</center> <pre> <A
8219 HREF="http://vim.sf.net/tip_view.php?tip_id=299">http://vim.sf.net/tip_view.php?tip_id=299</A><BR>
8220
8221 A little thing that I did and found quite useful:
8222
8223 function! OpenFileUnderCursor()
8224 let FileName = expand("&lt;cfile&gt;") let OldPath = getcwd() silent cd
8225 %:p:h execute "silent sp +e " . FileName execute "silent cd " . OldPath
8226 endfunction
8227
8228 map! silent &lt;M-e&gt; :call OpenFileUnderCursor()&lt;CR&gt;
8229
8230 Then use Alt+E on a filename to open it (relative to the directory the
8231 current file resides in).
8232
8233 </pre></tip> </html> <Tip category="KVim"> <html><center>Making
8234 a tags file for IDL (Interactive Data Language)</center> <pre> <A
8235 HREF="http://vim.sf.net/tip_view.php?tip_id=300">http://vim.sf.net/tip_view.php?tip_id=300</A><BR>
8236
8237 I have recently began using the tags features of vim (:help tags) with my
8238 fortran codes and come to appreciate their power. I also do a lot of coding
8239 in IDL (Interactive Data Language), but found that ctags did not have native
8240 support for IDL. If you take the time you can learn how to get ctags to
8241 support IDL, but I found, after a search of usenet, that someone else has
8242 already done this and written a perl script called idltags. It is part
8243 of an emacs package (is anyone still reading?) that you need to download,
8244 called idlwave, which is located at:
8245 <A HREF="http://idlwave.org/">http://idlwave.org/</A><BR>
8246 and currently (I don't know if this will change) the direct download link is
8247 <A
8248 HREF="http://idlwave.org/download/idlwave.tar.gz">http://idlwave.org/download/idlwave.tar.gz</A><BR>
8249 In the usenet pages the maintainer, JD Smith, was suggesting that idlwave
8250 had outgrown idltags and was not sure it was still needed, so I don't know
8251 how long it will be available.
8252
8253 </pre></tip> </html> <Tip category="KVim"> <html><center>Edit
8254 files in path, or related.</center> <pre> <A
8255 HREF="http://vim.sf.net/tip_view.php?tip_id=301">http://vim.sf.net/tip_view.php?tip_id=301</A><BR>
8256
8257 You can write a little shell function that will let you easily edit any file
8258 that is in the path, or which's location can be retrieved with the whereis
8259 tool. This is something similar to what I have in /etc/profile:
8260
8261 function vvim() { vim `whereis $1|cut -d: -f2` } function ggvim() { gvim
8262 `whereis $1|cut -d: -f2` }
8263
8264 Then just type, for example, "vvim ls", and you'll start vim with /bin/ls
8265 and /usr/share/man/ls.1.gz loaded :) (it's not very useful to edit /bin/ls,
8266 but you get the ideea ;)
8267
8268 </pre></tip> </html> <Tip category="KVim">
8269 <html><center>Use gvim in kmail</center> <pre> <A
8270 HREF="http://vim.sf.net/tip_view.php?tip_id=302">http://vim.sf.net/tip_view.php?tip_id=302</A><BR>
8271
8272 To automatically open gvim to edit in kmail, "-f" command line option must
8273 be used . In kmail configuration go to the composer settings , and write
8274 in the "use external editor" field the following command : "gvim -f %f"
8275 Without -f option gvim would work in background and editing would not have
8276 any effect on kmail.
8277
8278 </pre></tip> </html> <Tip category="KVim"> <html><center>Statusline
8279 Tab Level Function Ruler TVIM</center> <pre> <A
8280 HREF="http://vim.sf.net/tip_view.php?tip_id=303">http://vim.sf.net/tip_view.php?tip_id=303</A><BR>
8281
8282 I use this function to let me know if my cursor is on a TAB column. The t*
8283 on the ruler means I am not. But t3 means the cursor is on tablevel 3 ~vimrc
8284 ----------------------- My Ruler ------------------------ r4,c13,t3 ~vimrc
8285 ----------------------- My Ruler ------------------------ r4,c14,t* If you
8286 want to change a tab level you can drag or push the first character of a line
8287 to a desired tab level. (more on that later) This ruler replacement will let
8288 you know where you are, whether you like to use space tabs (see vimtip #12 )
8289 or regular tabs. My function is set to four space tabs stops and only goes
8290 9 levels but can be easily modified.
8291
8292 Actually I just wanted to learn how to use a function in my _vimrc and this
8293 was my first attempt. Add this to your _vimrc
8294
8295 "--------------------cut------------------ set laststatus=2 "This makes sure
8296 the ruler shows. See help laststatus set statusline=%f\ ---------\ My\
8297 Ruler\ ----------\ r%l,c%c,t%{ShowTab()} "See help statusline (I toggle
8298 between 12 helpful rulers -- more on that later) fu ShowTab()
8299 let TabLev='*' let Col=(col(".")) if Col == 1 | let TabLev='0' |
8300 en if Col == 5 | let TabLev='1' | en if Col == 9 | let TabLev='2' |
8301 en if Col ==13 | let TabLev='3' | en if Col ==17 | let TabLev='4' |
8302 en if Col ==21 | let TabLev='5' | en if Col ==25 | let TabLev='6' |
8303 en if Col ==29 | let TabLev='7' | en if Col ==33 | let TabLev='8' |
8304 en if Col ==37 | let TabLev='9' | en
8305 return TabLev endf "The ruler (statusline) shows a t* unless you are on
8306 col 1,5,9,13,... "-------------------cut-------------------
8307
8308 This function ShowTab() gets called and updates the ruler with every cursor
8309 move but it does not slow things down as I type. Perhaps a speed typist
8310 may complain :-) In case I write something else you may search on the key
8311 word TVIM Best Wishes TVIM Tamed Vim paradocs@frontiernet.net
8312
8313 </pre></tip> </html> <Tip category="KVim">
8314 <html><center>fold braces and javadoc</center> <pre> <A
8315 HREF="http://vim.sf.net/tip_view.php?tip_id=304">http://vim.sf.net/tip_view.php?tip_id=304</A><BR>
8316
8317 If you'd like to have javadoc folded together with areas in braces try that
8318 &lt;pre&gt; set foldmethod=syntax set foldenable syn region foldBraces
8319 start=/{/ end=/}/ transparent fold syn region foldJavadoc start=,/\*\*,
8320 end=,\*/, transparent fold keepend &lt;/pre&gt; and play a bit with:
8321 &lt;pre&gt; set foldlevel=0 set foldnestmax=10 &lt;/pre&gt; parameters
8322
8323 </pre></tip> </html> <Tip category="KVim"> <html><center>Best
8324 of VIM Tips (VIM's best Features)</center> <pre> <A
8325 HREF="http://vim.sf.net/tip_view.php?tip_id=305">http://vim.sf.net/tip_view.php?tip_id=305</A><BR>
8326
8327 Here's a necessarily cryptic list of "MY" Best Vim Tips
8328 that I've gleaned from <A HREF="http://vim.sf.net/ &
8329 comp.editors ">http://vim.sf.net/ & comp.editors </A><BR> <A
8330 HREF="http://groups.google.com/groups?safe=off&group=comp.editors">http://groups.google.com/groups?safe=off&group=comp.editors</A><BR>
8331
8332 updated version at <A
8333 HREF="http://www.rayninfo.co.uk/vimtips.html">http://www.rayninfo.co.uk/vimtips.html</A><BR>
8334 ------------------------------------------------------------------------------
8335 # Absolutely essential
8336 ------------------------------------------------------------------------------
8337 vim.sf.net : Visit frequently comp.editors : "VIM" dominated
8338 newsgroup * # g* g# : find word under cursor (forwards/backwards)
8339 % : match brackets {}[]() matchit.vim : % now matches
8340 tags &lt;tr&gt;&lt;td&gt;&lt;script&gt; etc &lt;C-N&gt; &lt;C-P&gt; : word
8341 completion in insert mode &lt;C-X&gt;&lt;C-L&gt; : Line complete SUPER
8342 USEFUL /&lt;C-R&gt;&lt;C-W&gt; : Pull &lt;cword&gt; onto search/command
8343 line :set ignorecase # you nearly always want this :syntax on : colour
8344 syntax in Perl,HTML,PHP etc :h slash&lt;C-D&gt; : type control-D and get a
8345 list all help topics containing
8346 slash (plus use TAB for Help completion)
8347 ------------------------------------------------------------------------------
8348 # MAKE IT EASY TO UPDATE/RELOAD_vimrc :nmap
8349 ,s :source $VIM/_vimrc :nmap ,v :e $VIM/_vimrc
8350 ------------------------------------------------------------------------------
8351 #VISUAL MODE Mappings :vmap sb "zdi&lt;b&gt;&lt;C-R&gt;z&lt;/b&gt;&lt;ESC&gt;
8352 : wrap &lt;b&gt;&lt;/b&gt; around VISUALLY selected
8353 Text :vmap st "zdi&lt;?= &lt;C-R&gt;z ?&gt;&lt;ESC&gt;
8354 : wrap &lt;?= ?&gt; around VISUALLY selected Text
8355 ------------------------------------------------------------------------------
8356 # Exploring :Ex : file explorer note capital Ex \be
8357 : builtin buffer explorer :ls : list of buffers(eg
8358 following) :cd .. : move to parent directory
8359 ------------------------------------------------------------------------------
8360 # Great guu : lowercase line gUU
8361 : uppercase line gf : open file name under
8362 cursor (SUPER) ga : display hex,ascii value of
8363 character under cursor ggVGg? : rot13 whole file
8364 CTRL-A,CTRL-X : increment,decerement number under cursor
8365 win32 users must remap CNTRL-A
8366 CTRL-R=5*5 : insert 25 into text
8367 ------------------------------------------------------------------------------
8368 # Makes all other tips superfluous :h 42 :h holy-grail :help!
8369 ------------------------------------------------------------------------------
8370 # Markers & moving about '. : jump to last modification
8371 line (SUPER) `. : jump to exact spot in last modification
8372 line &lt;C-O&gt; : retrace your movements in file
8373 (old) &lt;C-I&gt; : retrace your movements in file (new)
8374 :ju(mps) :help jump-motions :history : list of all your commands
8375 ------------------------------------------------------------------------------
8376 # Abbreviations & maps :map &lt;f7&gt; :'a,'bw! c:/aaa/x :map &lt;f8&gt;
8377 :r c:/aaa/x :map &lt;f9&gt; :w&lt;CR&gt;:!c:/php/php.exe %&lt;CR&gt;
8378 :map &lt;f11&gt; :.w! c:/aaa/xr&lt;CR&gt; :map &lt;f12&gt; :r
8379 c:/aaa/xr&lt;CR&gt; :ab php : list of abbreviations beginning
8380 php :map , : list of maps beginning , # For use in Maps
8381 &lt;CR&gt; : carriage Return for maps &lt;ESC&gt; :
8382 Escape &lt;LEADER&gt; : normally \ &lt;BAR&gt; : | pipe
8383 ------------------------------------------------------------------------------
8384 # List your Registers :reg : display contents
8385 of all registers "1p.... : retrieve numeric buffers
8386 ------------------------------------------------------------------------------
8387 # Useful trick "ayy@a : execute "Vim command" in a
8388 text file yy@" : same thing using unnamed register
8389 ------------------------------------------------------------------------------
8390 # Get output from other commands :r!ls.exe :
8391 reads in output of ls !!date : same thing
8392 :%!sort -u : use an external program to filter content
8393 ------------------------------------------------------------------------------
8394 # Multiple Files Management :wn : write file and move to
8395 next (SUPER) :bd : remove file from buffer list (SUPER)
8396 :sav php.html : Save current file as php.html and "move" to php.html
8397 :sp fred.txt : open fred.txt into a split :e! : return to
8398 unmodified file :w c:/aaa/% : save file elsewhere :e # :
8399 edit alternative file :e % :rew : rewwind to first file in
8400 ARGS :bn : next file :bp : next file :brew
8401 ------------------------------------------------------------------------------
8402 # Recording (BEST TIP of ALL) qq # record to q your commands
8403 q @q to execute @@ to Repeat # editing a register/recording "ap
8404 &lt;you can now see register contents, edit as required&gt; "add @a
8405 ------------------------------------------------------------------------------
8406 # _vimrc essentials :set incsearch : jumps to search word as you type (annoying
8407 but excellent) :set wildignore=*.o,*.obj,*.bak,*.exe :set shiftwidth=3
8408 ------------------------------------------------------------------------------
8409 # launching Win IE :nmap ,f :update&lt;CR&gt;:silent
8410 !start c:\progra~1\intern~1\iexplore.exe
8411 file://%:p&lt;CR&gt; :nmap ,i :update&lt;CR&gt;: !start
8412 c:\progra~1\intern~1\iexplore.exe &lt;cWORD&gt;&lt;CR&gt;
8413 ------------------------------------------------------------------------------
8414 # FTPing from VIM cmap ,r :Nread <A
8415 HREF="ftp://209.51.134.122/public_html/index.html
8416 ">ftp://209.51.134.122/public_html/index.html </A><BR> cmap ,w :Nwrite <A
8417 HREF="ftp://209.51.134.122/public_html/index.html">ftp://209.51.134.122/public_html/index.html</A><BR>
8418 gvim <A
8419 HREF="ftp://209.51.134.122/public_html/index.html">ftp://209.51.134.122/public_html/index.html</A><BR>
8420 ------------------------------------------------------------------------------
8421 # appending to registers (use CAPITAL) # yank
8422 5 lines into "a" then add a further 5 "a5yy 10j "A5yy
8423 ------------------------------------------------------------------------------
8424 [I : show lines matching word under cursor &lt;cword&gt;
8425 ------------------------------------------------------------------------------
8426 #Conventional Shifting :'a,'b&gt;&gt; # visual shifting
8427 (builtin-repeat) :vnoremap &lt; &lt;gv :vnoremap &gt; &gt;gv
8428 ------------------------------------------------------------------------------
8429 # searching /^joe.*fred.*bill/ : normal /^[A-J]\+/ : search
8430 for lines beginning A-J followed by at leat 1 A-J /forum\(\_.\)*pent
8431 search over possible multiple lines /fred\_s*joe/i : any
8432 whitespace including newline /fred\|joe : Search for FRED OR JOE
8433 ------------------------------------------------------------------------------
8434 #substitution :%s/fred/joe/igc : general substitute command
8435 :%s/\r//g : Delete DOS returns ^M :'a,'bg/fred/s/dick/joe/gc
8436 : VERY USEFUL :s/\(.*\):\(.*\)/\2 : \1/ : reverse fields separated
8437 by : :%s/^.\{-}pdf/new.pdf/ non greedy matching (ie to first pdf)
8438 :s/fred/&lt;c-r&gt;a/g substitute "fred" with contents of register "a"
8439 :%s/^\(.*\)\n\1/\1$/ delete duplicate lines # non-greedy matching
8440 \{-} :%s/^.\{-}pdf/new.pdf/ :help /\{-} :s/fred/&lt;c-r&gt;a/g
8441 substitute "fred" with contents of register "a" # multiple commands
8442 :%s/\f\+\.gif\&gt;/\r&\r/g | v/\.gif$/d | %s/gif/jpg/ :%s/suck\|buck/loopy/gc
8443 : ORing :s/__date__/\=strftime("%c")/ : insert datestring
8444 ------------------------------------------------------------------------------
8445 # global command :g/^\s*$/d :delete all blank lines :g!/^dd/d :
8446 delete lines not containing string :v/^dd/d : delete lines not
8447 containing string :g/fred/,/joe/d : not line based :v/./.,/./-1join : compress
8448 empty lines :'a,'b g/^Error/ . w &gt;&gt; errors.txt :g/cmap\|form/p : ORing
8449 ------------------------------------------------------------------------------
8450 # Paste register * :redir @* : redirect commands to paste :redir
8451 END "*yy : yank to paste "*p : insert paste buffer
8452 ------------------------------------------------------------------------------
8453 # Formatting text gq&lt;CR&gt; gqap (a is motion p paragraph (visual mode))
8454 ------------------------------------------------------------------------------
8455 # Operate command over multiple files :argdo
8456 %s/foo/bar/ :bufdo %s/foo/bar/ :windo %s/foo/bar/
8457 ------------------------------------------------------------------------------
8458 # Command line tricks gvim -h ls | gvim - : edit a PIPE!! #
8459 vg.ksh (shell script) # vi all files in directory containing
8460 keyword $1 and jump to $1 gvim.exe -c "/$1" $(grep -isl "$1" *) &
8461 ------------------------------------------------------------------------------
8462
8463 </pre></tip> </html> <Tip category="KVim"> <html><center>Open a
8464 web-browser with the URL in the current line</center> <pre> <A
8465 HREF="http://vim.sf.net/tip_view.php?tip_id=306">http://vim.sf.net/tip_view.php?tip_id=306</A><BR>
8466
8467 function! Browser ()
8468 let line = getline (".") let line = matchstr (line, "http[^ ]*") exec
8469 "!netscape ".line
8470 endfunction
8471
8472 map &lt;Leader&gt;w :call Browser ()&lt;CR&gt;
8473
8474 </pre></tip> </html> <Tip category="KVim"> <html><center>annoying
8475 "Hit any key to close this window..."</center> <pre> <A
8476 HREF="http://vim.sf.net/tip_view.php?tip_id=307">http://vim.sf.net/tip_view.php?tip_id=307</A><BR>
8477
8478 i use gvim and bash heavily under win98. i have
8479
8480 let $HOME = substitute($HOME, '\\', '/', 'g') set shell=bash\ --rcfile\
8481 \"$HOME\"_bashrc\ -i
8482
8483 in my _vimrc, and something like
8484
8485 function br() { if [ $1 ]; then
8486 explorer.exe ${1//\//\\}
8487 else
8488 explorer.exe ${PWD//\//\\}
8489 fi
8490 }
8491
8492 in my _bashrc. when i finish editing one html file, i simply type :!br %
8493
8494 everything works fine now. but when :!br % executes, one console window will
8495 bump out and wait me to press some key to contiue. i consider this quiet
8496 annoying. i want the console window to disappear automatically if no fault
8497 has happened. does anyone know how to achieve this? thanks.
8498
8499 </pre></tip> </html> <Tip category="KVim">
8500 <html><center>Move through wrapped lines.</center> <pre> <A
8501 HREF="http://vim.sf.net/tip_view.php?tip_id=308">http://vim.sf.net/tip_view.php?tip_id=308</A><BR>
8502
8503 If you don't like the fact that when you press Up and Down on a wrapped line,
8504 you get to the next phisical line instead of the next line on the screen,
8505 you can do something like this:
8506
8507 imap &lt;silent&gt; &lt;Down&gt; &lt;C-o&gt;gj imap &lt;silent&gt; &lt;Up&gt;
8508 &lt;C-o&gt;gk
8509
8510 nmap &lt;silent&gt; &lt;Down&gt; gj nmap &lt;silent&gt; &lt;Up&gt; gk
8511
8512 </pre></tip> </html> <Tip category="KVim"> <html><center>close
8513 vim you left open remotely</center> <pre> <A
8514 HREF="http://vim.sf.net/tip_view.php?tip_id=309">http://vim.sf.net/tip_view.php?tip_id=309</A><BR>
8515
8516 Vim 6 has this cool client-server protocol. I use it all the time to edit
8517 a file in an existing gvim, like so $ gvim --remote [filename]
8518
8519 Today I left myself logged in at the console at work, and when I got home
8520 I realized I had left vim running with files unsaved. I think I even left
8521 it in insert mode. I wanted to edit these files at home. So I ssh'd to the
8522 machine and started playing with the --remote commands.
8523
8524 :help was a bit cryptic
8525 --remote-send {keys} Send {keys} to server and exit.
8526
8527 After a lot of failed attempts, I finally succeeded in getting the remote
8528 vim to save its buffers and quit.
8529
8530 $ DISPLAY=:0 vim --servername GVIM --remote-send '&lt;ESC&gt;:wqa&lt;CR&gt;'
8531
8532 A couple of notable things. Then environment variable DISPLAY has to be the
8533 display of the remote vim, and you have to be able to open that display. The
8534 client-server stuff is done through X.
8535
8536 The &lt;CR&gt; is important. This part eluded me for a long time. The {keys}
8537 are just like keys you would press if you were editing at the console,
8538 and you have to press enter, or vim won't do anything.
8539
8540 Check your .swp files to make sure vim really closed the files it was
8541 editing. Vim provides little feedback as to the success or failure of what
8542 you're trying to do remotely. Nonetheless, it's clearly a useful feature to
8543 have available.
8544
8545 </pre></tip> </html> <Tip category="KVim"> <html><center>showing ascii
8546 value of the current character in decimal, hex, and octal</center> <pre> <A
8547 HREF="http://vim.sf.net/tip_view.php?tip_id=310">http://vim.sf.net/tip_view.php?tip_id=310</A><BR>
8548
8549 dont know if you guys know this or not, but i was trying to make the word
8550 "hello" to upper case by trying "gaUw" (= which didnt work but it showed
8551 the decimal, hex, and octal of the char under the cursor... ncie to know.
8552
8553 </pre></tip> </html> <Tip category="KVim"> <html><center>Open
8554 the folder containing the currently open file</center> <pre> <A
8555 HREF="http://vim.sf.net/tip_view.php?tip_id=311">http://vim.sf.net/tip_view.php?tip_id=311</A><BR>
8556
8557 Occasionally, on windows, I have files open in gvim, that the folder for that
8558 file is not open. This key map opens the folder that contains the currently
8559 open file. The expand() is so that we don't try to open the folder of an
8560 anonymous buffer, we would get an explorer error dialog in that case.
8561
8562 if has("gui_running")
8563 if has("win32")
8564 " Open the folder containing the currently open file. Double &lt;CR&gt; at
8565 end " is so you don't have to hit return after command. Double quotes are
8566 " not necessary in the 'explorer.exe %:p:h' section. :map &lt;silent&gt;
8567 &lt;C-F5&gt; :if expand("%:p:h") != ""&lt;CR&gt;:!start explorer.exe
8568 %:p:h&lt;CR&gt;:endif&lt;CR&gt;&lt;CR&gt;
8569 endif
8570 endif
8571
8572 Tom.
8573
8574 </pre></tip> </html> <Tip category="KVim">
8575 <html><center>Copy, Cut, and Paste</center> <pre> <A
8576 HREF="http://vim.sf.net/tip_view.php?tip_id=312">http://vim.sf.net/tip_view.php?tip_id=312</A><BR>
8577
8578 PS: copy, cut, and paste are the words from (usually) gui editor.
8579
8580 Ever try to cut (or copy) some lines and paste to another place? If you
8581 need to count the lines first, then try these to eliminate counting task.
8582
8583 Cut and Paste:
8584
8585 1. Place the cursor at the beginning of the block you want to CUT. 2. Mark
8586 it with md 3. Go to the end of the block. 4. Cut it with d'd 5. Go to the
8587 new location that you want to PASTE those text. 6. Press P.
8588
8589 Copy and Paste:
8590
8591 1. Place the cursor at the beginning of the block you want to COPY. 2. Mark
8592 it with my 3. Go to the end of the block. 4. Cut it with y'y 5. Go to the
8593 new location that you want to PASTE those text. 6. Press P.
8594
8595 The name of the mark used is related to the operation (d:delete or y:yank).
8596 I found that those mark names requires minimal movement of my finger. ;)
8597
8598 </pre></tip> </html> <Tip category="KVim"> <html><center>printing
8599 using kprinter (unix + kde)</center> <pre> <A
8600 HREF="http://vim.sf.net/tip_view.php?tip_id=313">http://vim.sf.net/tip_view.php?tip_id=313</A><BR>
8601
8602 just add set printexpr=system('kprinter'\ .\ '\ '\ .\ v:fname_in)\ .\
8603 delete(v:fname_in)\ +\ v:shell_error to your ~/.vimrc; further on all your
8604 printing will be piped through the nice and consistent print-dialog of kde.
8605
8606 lg, tomte
8607
8608 </pre></tip> </html> <Tip category="KVim">
8609 <html><center>Insert and back...</center> <pre> <A
8610 HREF="http://vim.sf.net/tip_view.php?tip_id=314">http://vim.sf.net/tip_view.php?tip_id=314</A><BR>
8611
8612 this is related to vimtip #289 in terms of programmers (like I) too lazy to
8613 move their hands to reach the far far away &lt;esc&gt; key.... joking! :)
8614 actually the less your hands move around the faster you type, and the fester
8615 you type the more time you have on your hands to think of "what" you type...
8616
8617 here is a small snippet from my mappings file, ready to speed things up: //
8618 the key overloading might be a somewhat confusing at first....
8619
8620 --cut--- imap &lt;S-Space&gt; &lt;esc&gt;l imap &lt;C-CR&gt; &lt;esc&gt;o
8621 imap &lt;S-CR&gt; &lt;esc&gt;O
8622
8623 nmap &lt;S-Space&gt; i nmap &lt;space&gt;&lt;space&gt; i nnoremap &lt;CR&gt;
8624 o nmap &lt;S-CR&gt; O
8625
8626 ---uncut---
8627
8628 Good luck!!
8629
8630 </pre></tip> </html> <Tip category="KVim">
8631 <html><center>"Smart &lt;home&gt;"</center> <pre> <A
8632 HREF="http://vim.sf.net/tip_view.php?tip_id=315">http://vim.sf.net/tip_view.php?tip_id=315</A><BR>
8633
8634 to make it faster to navigate through indented code here is a common way to
8635 "go home"...
8636
8637 ---cut--- fun! s:SmartHome()
8638 if col('.') != match(getline('.'), '\S')+1
8639 norm ^
8640 else
8641 :call cursor(line('.'),2) norm h
8642 endif
8643 endfun inoremap &lt;silent&gt;&lt;home&gt; &lt;C-O&gt;:call
8644 &lt;SID&gt;SmartHome()&lt;CR&gt; nnoremap &lt;silent&gt;&lt;home&gt; :call
8645 &lt;SID&gt;SmartHome()&lt;CR&gt; vnoremap &lt;silent&gt;&lt;home&gt; :call
8646 &lt;SID&gt;SmartHome()&lt;CR&gt;
8647
8648 ---uncut---
8649
8650 what this snippet does is make the &lt;home&gt; key behave as it does in
8651 such IDEs as PythonWin or MSVisualStudio, and that is first go to the first
8652 non whitespace, and then to the first char on the line.
8653
8654 </pre></tip> </html> <Tip category="KVim"> <html><center>Using
8655 /pattern/ search in a script</center> <pre> <A
8656 HREF="http://vim.sf.net/tip_view.php?tip_id=316">http://vim.sf.net/tip_view.php?tip_id=316</A><BR>
8657
8658 There are a number of ways you can search for a pattern in a script.
8659 The search function is the typical way to search for a pattern. But, it
8660 has limited options. In particular, there are no options to control the
8661 position of the cursor after it matches the pattern.
8662
8663 Instead you can use :normal command. The secret is to add a &lt;CR&gt;
8664 (^M) on the end of the command. For example, to search for "pattern"
8665 and move the cursor to the end of the matching pattern issue the command:
8666
8667 :normal /pattern/e+1^M
8668
8669 where ^M is a real carriage return. It can be entered with
8670 &lt;c-v&gt;&lt;c-m&gt;.
8671
8672 Another use is when you want to enter a bunch of normal commands together.
8673 For example, if you were looking to find a '{' to highlight and delete
8674 a C block. The '{' may not be on the same line so you can't use the "f"
8675 normal command.
8676
8677 :normal V/{/^M%d
8678
8679 A drawback to using the normal command is that if the pattern does not
8680 match then it is difficult to detect. Also, you can get in trouble with
8681 the wrapscan setting.
8682
8683 For more information about these commands look at
8684
8685 :help / :help normal :help search()
8686
8687 </pre></tip> </html> <Tip category="KVim">
8688 <html><center>Mozilla Vim Keybindings</center> <pre> <A
8689 HREF="http://vim.sf.net/tip_view.php?tip_id=317">http://vim.sf.net/tip_view.php?tip_id=317</A><BR>
8690
8691 If you use VIM you like the h, j, k, and l movement keys. I found myself
8692 annoyed at not having these movement keys available when browsing web pages.
8693 Moving to the arrow keys on a laptop is annoying to just scroll the page.
8694
8695 Locate your mozilla/res/builtin directory (varies by platform). You could
8696 search for htmlBindings.xml to find it. (ie. locate htmlBindings.xml.
8697
8698 On Mac OS X it's inside the Mozilla application bundle.
8699 /Applications/Mozilla/Mozilla.app/Contents/MacOS/res/builtin.
8700
8701 Create a new XML file called userHTMLBindings.xml, making it executable for
8702 all users and making sure the CRLF format is the same as htmlBindings.xml.
8703 i.e. on Mac OS X most files use \r but Vim writes \n instead. You can either
8704 save the file with Vim as a Mac formatted file or use tr '\n' '\r' &lt;
8705 input.xml &gt; output.xml to convert the file.
8706
8707 Place the following XML into the userHTMLBindings.xml file.
8708
8709 &lt;?xml version="1.0"?&gt;
8710
8711 &lt;bindings id="htmlBindings"
8712 xmlns="<A
8713 HREF="http://www.mozilla.org/xbl"">http://www.mozilla.org/xbl"</A><BR>
8714 xmlns:xul="<A
8715 HREF="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt;">http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt;</A><BR>
8716
8717 &lt;binding id="browserUser"&gt;
8718 &lt;handlers&gt;
8719 &lt;handler event="keypress" key="h" command="cmd_scrollLeft"/&gt;
8720 &lt;handler event="keypress" key="j" command="cmd_scrollLineDown"/&gt;
8721 &lt;handler event="keypress" key="k" command="cmd_scrollLineUp"/&gt;
8722 &lt;handler event="keypress" key="l" command="cmd_scrollRight"/&gt;
8723 &lt;/handlers&gt;
8724 &lt;/binding&gt;
8725 &lt;/bindings&gt;
8726
8727 There are many more bindings one could configure to get Vim like keybindings.
8728 You can read <A HREF="http://www.mozilla.org/unix/customizing.html#keys for
8729 more information.">http://www.mozilla.org/unix/customizing.html#keys for
8730 more information.</A><BR>
8731
8732 PS. I love the keymaster/gatekeeper xul reference in the xul URL above.
8733 It's from the original GhostBusters movie. ;-)
8734
8735
8736
8737 </pre></tip> </html> <Tip category="KVim"> <html><center>Extended
8738 Bracket and Parenthesis + extras for perl</center> <pre> <A
8739 HREF="http://vim.sf.net/tip_view.php?tip_id=318">http://vim.sf.net/tip_view.php?tip_id=318</A><BR>
8740
8741 This is an extension of vimtip #153 I found this tip useful, but the jump
8742 seemed out of place for me, I couldn't enter just one ' or ", and so I created
8743 an improvement Basically, I set it up so that when you're in perl and have
8744 a non keyword charcter, (except for @, $ and % for perl) and you type a {
8745 you get: {
8746 | &lt;- cursor
8747 } Where as, when I have a keyword I get: word{} With the cursor in the middle,
8748 for hashes in perl. I can jump out of any block, except the "" or '' blocks,
8749 by typing their closing charcter. So } jumps me out past the next } in
8750 the file.
8751
8752 Warning, this search may wrap around.
8753
8754 Finally, I made it so that, using the alt key, &lt;Alt-'&gt; inserts a '
8755 &lt;Alt-/&gt; inserts a " &lt;Alt-[&gt; inserts a [ &lt;Alt-]&gt; inserts a
8756 ] &lt;Alt--&gt; inserts a { &lt;Alt-=&gt; inserts a } &lt;Alt-,&gt; inserts
8757 a &lt; &lt;Alt-.&gt; inserts a &gt;
8758
8759 "######################################## " File -
8760 matchMe.vim " Date - Wednesday, August 21, 2002
8761 "########################################
8762
8763 " This code fixes my problem with " does the one format for perl and still
8764 keeps hashes function! InsertBrackets()
8765 let fileType = &ft
8766
8767 if fileType == 'perl'
8768 let col = col('.') - 1 if !col || getline('.')[col - 1] !~
8769 '\k' && getline('.')[col - 1] !~ '\$' && getline('.')[col - 1]
8770 !~ '@' && getline('.')[col - 1] !~ '%' && getline('.')[col -
8771 1] !~ '#'
8772 return "{\&lt;cr&gt;\&lt;bs&gt;}\&lt;esc&gt;ko"
8773 else
8774 return "{}\&lt;esc&gt;i\&lt;c-o&gt;:echo \&lt;cr&gt;"
8775 endif
8776 else
8777 return "{\&lt;cr&gt;\&lt;bs&gt;}\&lt;esc&gt;ko"
8778 endif
8779 endfunction
8780
8781 " This code jumps out of the brackets function! JumpNext(normChar)
8782 let ret =
8783 "\&lt;space&gt;\&lt;esc&gt;ma\&lt;left&gt;/\\".a:normChar."\&lt;cr&gt;mb`ai\&lt;del&gt;\&lt;esc&gt;`bi\&lt;right&gt;"
8784 return ret
8785 endfunction
8786
8787 " mappings inoremap " ""&lt;esc&gt;i&lt;c-o&gt;:echo
8788 &lt;cr&gt; inoremap ' ''&lt;esc&gt;i&lt;c-o&gt;:echo &lt;cr&gt;
8789 inoremap &lt; &lt;&gt;&lt;esc&gt;i&lt;c-o&gt;:echo &lt;cr&gt;
8790 inoremap ( ()&lt;esc&gt;i&lt;c-o&gt;:echo &lt;cr&gt; inoremap [
8791 []&lt;esc&gt;i&lt;c-o&gt;:echo &lt;cr&gt; inoremap { &lt;c-r&gt;=InsertBrackets
8792 ()&lt;cr&gt; inoremap &gt; &lt;c-r&gt;=JumpNext("&gt;")&lt;cr&gt;
8793 inoremap ) &lt;c-r&gt;=JumpNext(")")&lt;cr&gt;
8794 inoremap ] &lt;c-r&gt;=JumpNext("]")&lt;cr&gt; inoremap }
8795 &lt;c-r&gt;=JumpNext("}")&lt;cr&gt; inoremap &lt;m-[&gt; [ inoremap &lt;m-]&gt;
8796 ] inoremap &lt;m-/&gt; " inoremap &lt;m--&gt; { inoremap &lt;m-=&gt; }
8797 inoremap &lt;m-,&gt; &lt; inoremap &lt;m-.&gt; &gt; inoremap &lt;m-'&gt; '
8798
8799 "######################################## " End Of File
8800 "########################################
8801
8802 If you have any other suggestions, drop a note...
8803
8804 </pre></tip> </html> <Tip category="KVim"> <html><center>text
8805 formatting (lining up ='s,('s etc))</center> <pre> <A
8806 HREF="http://vim.sf.net/tip_view.php?tip_id=319">http://vim.sf.net/tip_view.php?tip_id=319</A><BR>
8807
8808 some time onw would like to reformat text like a=1; foo=2; longstring=1; c=2
8809
8810 to
8811
8812 a =1; foo =2; longstring =1; c =2;
8813
8814 Note I am not sure wether the code above is displayed properly in your browsers
8815 what is basically shows is all the ='s are lined up in a single column
8816 and this is how we achive it 0f=20i&lt;space&gt;&lt;esc&gt;020lvf=hx and
8817 this is what it does 0 goes to first column f=
8818 finds next occurance of = on current line 20i&lt;space&gt;&lt;esc&gt;
8819 inserts 20 spaces before = 0 goesback to
8820 first column 20l forward 20 column vf=hx
8821 deletes everything up to the = sign
8822
8823 </pre></tip> </html> <Tip category="KVim">
8824 <html><center>Borland pageup/down behavier</center> <pre> <A
8825 HREF="http://vim.sf.net/tip_view.php?tip_id=320">http://vim.sf.net/tip_view.php?tip_id=320</A><BR>
8826
8827 borlandbehavier = the cursor keeps the same xy position during pageup/down
8828
8829 Im new to VIM scripting, im sure it can be done smarter? I read vimtip #105
8830 and it gave me a clue of how BorlandPageUp/Down could be done.
8831
8832 " i could'nt find any get_number_of_visible_lines function, so i made my own.
8833 function GetNumberOfVisibleLines()
8834 let cur_line = line(".") let cur_col = virtcol(".") normal H let
8835 top_line = line(".") normal L let bot_line = line(".")
8836
8837 execute "normal " . cur_line . "G" execute "normal " . cur_col . "|"
8838 return bot_line - top_line
8839 endfunc
8840
8841 " noremap &lt;PageUp&gt; 39&lt;C-U&gt;:set scroll=0&lt;CR&gt;
8842 function! MyPageUp()
8843 let visible_lines = GetNumberOfVisibleLines() execute "normal "
8844 . visible_lines . "\&lt;C-U&gt;:set scroll=0\r"
8845 endfunction
8846
8847 " noremap &lt;PageDown&gt; 39&lt;C-D&gt;:set scroll=0&lt;CR&gt;
8848 function! MyPageDown()
8849 let visible_lines = GetNumberOfVisibleLines() execute "normal "
8850 . visible_lines . "\&lt;C-D&gt;:set scroll=0\r"
8851 endfunction
8852
8853 " BorlandPascal pageup/down behavier! " todo: when hitting top/bottom of file,
8854 then restore Y to lastY noremap &lt;PageUp&gt; :call MyPageUp()&lt;CR&gt;
8855 noremap &lt;PageDown&gt; :call MyPageDown()&lt;CR&gt;
8856
8857 </pre></tip> </html> <Tip category="KVim"> <html><center>Centura
8858 swap with upper/lower line behavier</center> <pre> <A
8859 HREF="http://vim.sf.net/tip_view.php?tip_id=321">http://vim.sf.net/tip_view.php?tip_id=321</A><BR>
8860
8861 I was once forced to use a windows development suite called "Centura".
8862 The only good thing i remember was its swap current_line with upper/lower line.
8863
8864 function! MySwapUp()
8865 let cur_col = virtcol(".") normal ddkkp execute "normal " . cur_col . "|"
8866 endfunction
8867
8868 function! MySwapDown()
8869 let cur_col = virtcol(".") normal ddp execute "normal " . cur_col . "|"
8870 endfunction
8871
8872 " swap lines and preserve cursorx " todo: in visual mode, perform swap with
8873 line before/after the selection noremap &lt;S-Up&gt; :call MySwapUp()&lt;CR&gt;
8874 noremap &lt;S-Down&gt; :call MySwapDown()&lt;CR&gt;
8875
8876 </pre></tip> </html> <Tip category="KVim"> <html><center>text
8877 template with placeholders</center> <pre> <A
8878 HREF="http://vim.sf.net/tip_view.php?tip_id=322">http://vim.sf.net/tip_view.php?tip_id=322</A><BR>
8879
8880 Many scripts/ftplugin provide text or code templates. Sadly none of the
8881 marks the places where you are supposed to "fill in the form". My own code
8882 templates for C/C++ insert a triple percent (%%%) where you are supposed to
8883 enter something. I mapped ;; to find the next %%% and change them. All the
8884 template mappings are insert-mode only, while the "skip to next placeholder"
8885 is both insert and normal mode enabled.
8886
8887 A complete for-loop template for C++ looks like:
8888
8889 :imap &lt;buffer&gt; ;fo &lt;C-O&gt;mzfor( %%%; %%%; %%%)&lt;CR&gt;{ //
8890 %%%&lt;CR&gt;%%%&lt;CR&gt;}&lt;CR&gt;&lt;C-O&gt;'z;;
8891
8892 The command to go to the next placeholder is this:
8893
8894 :imap &lt;buffer&gt; ;; &lt;C-O&gt;/%%%&lt;CR&gt;&lt;C-O&gt;c3l :nmap
8895 &lt;buffer&gt; ;; /%%%&lt;CR&gt;c3l
8896
8897 Every time I need a for-loop ;fo produces this ( _ is the cursor position)
8898 : for( _; %%% ; %%%) { // %%%
8899 %%%
8900 }
8901
8902 Now I enter starting value (i=0): for( i=0_; %%% ; %%%) { // %%%
8903 %%%
8904 }
8905
8906 and go to the condition using ;; for( i=0; _ ; %%%) { // %%%
8907 %%%
8908 }
8909
8910 and so forth.
8911
8912 The choice of %%% proved to be almost universal, it even works in MATLAB or
8913 LaTeX where % is the comment character.
8914
8915 Even if you forget to replace one %%%, that's not a problem as the compiler
8916 flags is as a syntax error (except MATLAB and LaTeX, of course).
8917
8918 It made my life easier, maybe it works for you.
8919
8920 </pre></tip> </html> <Tip category="KVim">
8921 <html><center>using folders with latex</center> <pre> <A
8922 HREF="http://vim.sf.net/tip_view.php?tip_id=323">http://vim.sf.net/tip_view.php?tip_id=323</A><BR>
8923
8924 set foldmarker=\\begin,\\end set foldmethod=marker
8925
8926 this is useful with big latex document
8927
8928 </pre></tip> </html> <Tip category="KVim"> <html><center>Search
8929 and replace in files named NAME</center> <pre> <A
8930 HREF="http://vim.sf.net/tip_view.php?tip_id=324">http://vim.sf.net/tip_view.php?tip_id=324</A><BR>
8931
8932 I'm not sure if there is a simple way to do this from within Vim, but,
8933 I wrote this simple script that does it. It basically searches for files
8934 named NAMED (whatever name pass) for a given string and replaces that with
8935 a given string: find_replace.sh NAMED "string_to_find" "string_to_replace"
8936
8937 This is all done from the command line without opening Vim.
8938
8939 Of course one could do things like:
8940 :let n = 1 :while n &lt;= argc() " loop over all
8941 files in arglist : exe "argument " . n : " start at
8942 the last char in the file and wrap for the : " first
8943 search to find match at start of file : normal G$ :
8944 let flags = "w" : while search("foo", flags) &gt; 0 :
8945 s/foo/bar/g : let flags = "W" : endwhile : update
8946 " write the file if modified : let n = n + 1 :endwhile
8947
8948 As suggested in the Vim help files :-) but, I wanted to go and find only
8949 these files... here is the script:
8950 1 #!/bin/sh 2 # Luis Mondesi &lt; lemsx1@hotmail.com &gt; 3 #
8951 DESCRIPTION: 4 # it uses vim to replace a given string for 5 #
8952 another in a number of files 6 # 7 # usage: 8 # find_replace.sh file
8953 "string" "replace" 9 #
8954 10 if [ $1 -a $2 -a $3 ]; then 11 for i in `find . -name "$1"
8955 -type f | xargs grep -l $2`; do 12 # how do search and replace
8956 13 # the screen might flicker... vim opening and closing...
8957 14 vim -c ":%s/$2/$3/g" -c ":wq" $i 15 done 16 exit 0
8958 17 fi 18 # I should never reach here 19 echo -e "USAGE: find_replace.sh
8959 file 'string' 'replace' \n\n" 20 exit 1
8960
8961 </pre></tip> </html> <Tip category="KVim"> <html><center>Errorformat
8962 for java/ant/junit/cygwin/bash</center> <pre> <A
8963 HREF="http://vim.sf.net/tip_view.php?tip_id=325">http://vim.sf.net/tip_view.php?tip_id=325</A><BR>
8964
8965 If you program in Java and use Jakarta ant for builds *and* if you have the
8966 bash shell, this tip will make your development experience a little smoother.
8967
8968 This tip will result in a working compile/edit/debug system (in Win32 vim/gvim
8969 and in Cygwin vim) that takes you to the exact lines where the build fails,
8970 whether the failure is a compilation error or a junit test failure. If you
8971 use bash on a linux box, you shouldn't have to change very much to get
8972 everything to work.
8973
8974 There are 6 sections: 1. set up your build script 2. set up makeprg 3. set
8975 up shell options 4. set up path formatting options 5. set up your errorformat
8976 6. set up key mappings
8977
8978 Set up build script ------------------- Add the following script to your path
8979 (I use /usr/local/bin/):
8980
8981 mymake: #!/bin/bash cd /work/ ant -emacs $* 2&gt;&1 | tr '\\' / | tr ^M '
8982 ' | sed -u -n -f /usr/local/bin/testerrors.sed | tee /tmp/errors
8983
8984 Comment: sed -u is non-standard, use the code at: <A
8985 HREF="http://mail.gnu.org/pipermail/bug-gnu-utils/2002-May/000192.html to
8986 get">http://mail.gnu.org/pipermail/bug-gnu-utils/2002-May/000192.html to
8987 get</A><BR> the -u option for sed (this avoids waiting for the build output
8988 to get to the screen)
8989
8990 testerrors.sed: # This assumes that all your junit test cases are in a com.*
8991 package /^Running com\./ {
8992 # duplicate the line s!\(.*\)!\1\
8993 \1!
8994 P
8995
8996 # turn the test package into a directory path for %D errorformat
8997 s!.*\(com\..*\)\.[A-Za-z_][A-Za-z0-9_]*!\1! s!\.!/!g s!.*!Entering:
8998 /work/src/&!
8999
9000 # print the line and go on p n
9001 }
9002
9003 # just pass any unmatched lines through p
9004
9005 Set up makeprg -------------- Add the following lines to your vimrc:
9006 autocmd BufNewFile,BufRead /work/*.java set makeprg=mymake autocmd
9007 BufNewFile,BufRead ?:/work/*.java set makeprg=mymake
9008
9009 Set up shell options -------------------- Add the following lines to your
9010 vimrc:
9011 " in order to have bash as the shell for win32 vi.exe and gvim.exe,
9012 you have " to set these options, and also build vimrun.exe in the cygwin
9013 environment " so that the system() call is executed via bash, not cmd.exe
9014 -- the command " to build vimrun.exe is "make -f Make_cyg.mak vimrun.exe"
9015 set shell=bash.exe set shellcmdflag=-c set shellslash
9016
9017 Also to use this environment in Win32 gvim, you must recompile vimrun so
9018 that gvim invokes the shell via bash, not via cmd.exe.
9019
9020 Set up path formatting options ------------------------------ Add the
9021 following lines to your vimrc:
9022 " allows DOS file names from UNIX (Cygwin) vim set isfname+=\
9023
9024 Set up your errorformat ----------------------- Add the following lines to
9025 your vimrc:
9026 " the "\%DEntering:\ %f," rule relies on a sed script which generates "
9027 "Entering: " messages for each test class run (the directory name is "
9028 generated from the test class package and a hard-coded src root)
9029
9030 " the "%\\C" at the start of the exception matching line tells to match
9031 " case-exact (the exception mathching lines rely on the %D rule that sets
9032 " up the correct directory from the package structure)
9033
9034 " ant/junit/javac errorformat set errorformat=
9035 \%-G%.%#build.xml:%.%#, \%-G%.%#warning:\ %.%#, \%-G%\\C%.%#EXPECTED%.%#,
9036 \%f:%l:\ %#%m, \C:%f:%l:\ %m, \%DEntering:\ %f\ %\\=, \%ECaused\
9037 by:%[%^:]%#:%\\=\ %\\=%m, \%ERoot\ cause:%[%^:]%#:%\\=\ %\\=%m,
9038 \%Ecom.%[%^:]%#:%\\=\ %\\=%m, \%Eorg.%[%^:]%#:%\\=\ %\\=%m,
9039 \%Ejava.%[%^:]%#:%\\=\ %\\=%m, \%Ejunit.%[%^:]%#:%\\=\ %\\=%m,
9040 \%-Z%\\C\ at\ com.mypkg.%.%#.test%[A-Z]%.%#(%f:%l)\ %\\=,
9041 \%-Z%\\C\ at\ com.mypkg.%.%#.setUp(%f:%l)\ %\\=, \%-Z%\\C\ at\
9042 com.mypkg.%.%#.tearDown(%f:%l)\ %\\=, \%-Z%^\ %#%$, \%-C%.%#, \%-G%.%#
9043
9044 NOTE: Make sure that the character before "at" is an actual Tab character
9045 in the three long -Z lines above
9046
9047 Here is an annotated version:
9048 set errorformat=
9049 " don't treat the build.xml diagnostic as an error
9050 \%-G%.%#build.xml:%.%#,
9051
9052 " don't treat warning lines as errors \%-G%.%#warning:\ %.%#,
9053
9054 " don't treat lines containing "EXPECTED" as errors
9055 \%-G%\\C%.%#EXPECTED%.%#,
9056
9057 " look for this standard error format \%f:%l:\ %#%m,
9058
9059 " look for this standard error format (with C: on front) \C:%f:%l:\ %m,
9060
9061 " look for special sed-generated "Entering" lines while running tests
9062 \%DEntering:\ %f\ %\\=,
9063
9064 " look for exceptions that were thrown in the tests, use the exception
9065 " description as the error message (don't know how to also include the
9066 " exception name in the error message) \%ECaused\ by:%[%^:]%#:%\\=\
9067 %\\=%m, \%ERoot\ cause:%[%^:]%#:%\\=\ %\\=%m, \%Ecom.%[%^:]%#:%\\=\
9068 %\\=%m, \%Eorg.%[%^:]%#:%\\=\ %\\=%m, \%Ejava.%[%^:]%#:%\\=\ %\\=%m,
9069 \%Ejunit.%[%^:]%#:%\\=\ %\\=%m,
9070
9071 " using the "Entering" directory and the filename/line number provided
9072 " in the exception trace, go to the test method where the exception
9073 " was thrown \%-Z%\\C\ at\ com.mypkg.%.%#.test%[A-Z]%.%#(%f:%l)\
9074 %\\=, \%-Z%\\C\ at\ com.mypkg.%.%#.setUp(%f:%l)\ %\\=, \%-Z%\\C\ at\
9075 com.mypkg.%.%#.tearDown(%f:%l)\ %\\=,
9076
9077 " empty lines terminate searching for further exception lines \%-Z%^\
9078 %#%$,
9079
9080 " any line can intervene between the start of an exception printout
9081 " and the line where it ends (last in list so that it is matched if
9082 " none of the other exception trace patterns match) \%-C%.%#,
9083
9084 " all other lines are not errors \%-G%.%#
9085
9086 Set up key mappings ------------------- Add the following lines to your vimrc:
9087 nmap &lt;F10&gt; :clist&lt;CR&gt; nmap &lt;F11&gt; :cprev&lt;CR&gt; nmap
9088 &lt;F12&gt; :cnext&lt;CR&gt;
9089
9090 This allows for quick error navigation.
9091
9092 NOTES ----- Vim treats the "Entering: /work/src/..." messages in a weird way.
9093 If there are any actual errors, then these error lines are ignored by the
9094 :cnext and :cprev commands, but if there are no real errors, then :cnext and
9095 :cprev roll through these "Entering:" messages as if they were errors, but
9096 since they don't include any line numbers, the cursor position is never moved.
9097
9098 I thought that this was strange, but even stranger, it is programmed directly
9099 into the vim error handling code to function exactly this way. There were
9100 no comments, and nobody responded on the vim mailing list, so I just decided
9101 to live with it.
9102
9103 The upshot of it all is that if you see an error like "Entering:", chances
9104 are that your build succeeded and all the tests ran without a problem.
9105
9106 Hope this helps...
9107
9108 Mail me with bugs at jdsumsion at earthlink.net.
9109
9110 </pre></tip> </html> <Tip category="KVim"> <html><center>Help
9111 for VIM Help (VIM QuickRef)</center> <pre> <A
9112 HREF="http://vim.sf.net/tip_view.php?tip_id=326">http://vim.sf.net/tip_view.php?tip_id=326</A><BR>
9113
9114 Type :help quickref or :h quic
9115
9116 And get a VIM Command Quick Reference Page brilliant for beginners &
9117 oldtimers alike
9118
9119 type :h help to learn how to use help
9120
9121 Other Help Tips
9122
9123 # help for help :h visual&lt;C-D&gt;&lt;tab&gt; : obtain list of all
9124 visual help topics
9125 : Then use tab to step thru them
9126 :h ctrl&lt;C-D&gt; : list help of all control keys :h :r
9127 : help for :ex command :h CTRL-R : normal mode :h \r
9128 : what's \r in a regexp :h i_CTRL-R : help for say &lt;C-R&gt;
9129 in insert mode :h c_CTRL-R : help for say &lt;C-R&gt; in command
9130 mode :h v_CTRL-V : visual mode :h tutor : VIM Tutor
9131
9132 These are also listed in my Best Of VIM Tips vimtip #305
9133
9134 </pre></tip> </html> <Tip category="KVim">
9135 <html><center>key mappings</center> <pre> <A
9136 HREF="http://vim.sf.net/tip_view.php?tip_id=327">http://vim.sf.net/tip_view.php?tip_id=327</A><BR>
9137
9138 I use my left thumb for the alt key and right for the space. Using this
9139 combo, you can get some useful key maps for which you don't have to move
9140 your hands. I find I have to turn my hand a little to press the left ctrl key.
9141
9142 These are some maps i use for C programming.
9143
9144 map ' ` map &lt;C-f&gt; :w&lt;C-m&gt;:!make&lt;C-m&gt; map &lt;M-]&gt;
9145 &lt;C-]&gt; Tags map &lt;M-[&gt;
9146 &lt;C-t&gt; Tags map &lt;M-u&gt;
9147 :!ctags -R *&lt;C-m&gt; Build
9148 Tags map &lt;M-c&gt; I/*&lt;Esc&gt;A*/&lt;Esc&gt;
9149 Comment current line map &lt;M-d&gt; ^xx$xx
9150 Delete comment for a single line map &lt;M-l&gt;
9151 [{zf% Fold upto the enclosing brace
9152 level map &lt;M-o&gt; zo open fold
9153 map &lt;M-i&gt; zc close fold map
9154 &lt;M-.&gt; :cn&lt;C-m&gt; Go
9155 to next error in list map &lt;M-,&gt; :cp&lt;C-m&gt;
9156 previous error in list
9157
9158 imap &lt;Tab&gt; &lt;C-p&gt;
9159 Complete word inoremap &lt;S-Tab&gt; &lt;Tab&gt;
9160 Tab inoremap { &lt;CR&gt;{&lt;CR&gt;
9161 Brace and line inoremap } &lt;CR&gt;}
9162 brace and line. saves one enter stroke
9163
9164 imap &lt;M-j&gt; &lt;Esc&gt;
9165 Escape. Don't want to move my hand to esc key. imap &lt;M-k&gt; &lt;C-y&gt;
9166 Copy line from above. imap &lt;M-q&gt; /* */&lt;Esc&gt;hhi
9167 Comment selected lines
9168
9169 noremap &lt;M-r&gt; ddko{&lt;C-m&gt;}&lt;Esc&gt;kpko Convert a
9170 simple statement to a compound statement. And place cursor above prev line.
9171 noremap &lt;M-k&gt; ddko{&lt;C-m&gt;}&lt;Esc&gt;kpo Same as
9172 above but place cursor below old line.
9173
9174 vnoremap &lt;M-j&gt; &lt;Esc&gt; vnoremap &lt;M-c&gt;
9175 di/*&lt;C-m&gt;/&lt;C-m&gt;&lt;Esc&gt;kkp Commented selected text
9176
9177 nmap &lt;M-n&gt; :noh&lt;CR&gt; No hilight
9178
9179 Bye,
9180 Nithin.
9181
9182 </pre></tip> </html> <Tip category="KVim"> <html><center>Vim
9183 in Microsoft Visual Foxpro</center> <pre> <A
9184 HREF="http://vim.sf.net/tip_view.php?tip_id=328">http://vim.sf.net/tip_view.php?tip_id=328</A><BR>
9185
9186 You can tell MS VFP to use an external editor for editing project files.
9187 To tell MS VFP to use Vim:
9188
9189 start regedit locate [HKEY_CURRENT_USER
9190 \Software
9191 \Microsoft
9192 \VisualFoxPro
9193 \5.0
9194 \Options]
9195
9196 and create a new item TEDIT with string content "/N
9197 C:\Progra~1\vim\vim61\gvim.exe" (or whatever your path to Vim happens to be.)
9198
9199 This will not replace the internal VFP editor for such things as modifying the
9200 "click method" for a button (unfortunately), but when you modify a program,
9201 VFP will fire up gvim.
9202
9203 Start MS VFP, start Help and look for TEDIT. ;-)
9204
9205 </pre></tip> </html> <Tip category="KVim">
9206 <html><center>A map for swapping words</center> <pre> <A
9207 HREF="http://vim.sf.net/tip_view.php?tip_id=329">http://vim.sf.net/tip_view.php?tip_id=329</A><BR>
9208
9209 Put the following map into your &lt;.vimrc&gt;:
9210
9211 nmap &lt;silent&gt; gw
9212 "_yiw:s/\(\%#\w\+\)\(\W\+\)\(\w\+\)/\3\2\1/&lt;cr&gt;&lt;c-o&gt;&lt;c-l&gt;
9213
9214 Then when you put the cursor on or in a word, press "gw", and the word will
9215 be swapped with the next word. The words may even be separated by punctuation
9216 (such as "abc = def").
9217
9218 While we're talking swapping, here's a map for swapping characters:
9219
9220 nmap &lt;silent&gt; gc xph
9221
9222 This hint was formed in a collaboration between Chip Campbell - Arun Easi -
9223 Benji Fisher
9224
9225 </pre></tip> </html> <Tip category="KVim">
9226 <html><center>how to stop auto indenting</center> <pre> <A
9227 HREF="http://vim.sf.net/tip_view.php?tip_id=330">http://vim.sf.net/tip_view.php?tip_id=330</A><BR>
9228
9229 Since VIM 6.0 the indent has been improved so much. But sometimes when
9230 we are pasting formated text (source code or HTML etc) into a buffer, VIM
9231 indents again so that lines will be padded with too much spaces.
9232
9233 Setting nocindent, noautoindent, nosmartindent still cannot stop this. All you
9234 need to do is "set paste", then paste your stuff, and then "set nopaste" again.
9235
9236 Ref: indentexpr
9237
9238 </pre></tip> </html> <Tip category="KVim">
9239 <html><center>modline magic...</center> <pre> <A
9240 HREF="http://vim.sf.net/tip_view.php?tip_id=331">http://vim.sf.net/tip_view.php?tip_id=331</A><BR>
9241
9242 One of the things about vim that are both quite simple yet very
9243 useful is that you can store by-file settings... that is each file can
9244 contain settings specific to it. this thing is called a modline (:help
9245 modline). though this is limited to only the 'set' command arguments, you
9246 can do allot of local to file things like the indent type, folding method
9247 and so on.
9248
9249 the syntax is as follows:
9250
9251 // vim:set ts=4 sw=4 nowrap:
9252
9253 or
9254
9255 /* vim:noai:ts=2:sw=4: */
9256
9257 The modlines can be contained in comments so as to not interfere with
9258 the file syntax (shown here for C/C++). these lines are read by vim when
9259 it loads the file, and they can either be in the first or last 5 lines
9260 (by default).
9261
9262 refer to ':help modline'
9263
9264 //and a happy 20th birthday to the good old smiley!! :-)
9265
9266 </pre></tip> </html> <Tip category="KVim">
9267 <html><center>make footnotes in vim</center> <pre> <A
9268 HREF="http://vim.sf.net/tip_view.php?tip_id=332">http://vim.sf.net/tip_view.php?tip_id=332</A><BR>
9269
9270 I found at <A
9271 HREF="http://groups.google.com/groups?q=vim+changing+shell+to+zsh&hl=en&lr=&ie=UTF-8&selm=S_Rh9.716%24a5.124150%40news.uchicago.edu&rnum=4">http://groups.google.com/groups?q=vim+changing+shell+to+zsh&hl=en&lr=&ie=UTF-8&selm=S_Rh9.716%24a5.124150%40news.uchicago.edu&rnum=4</A><BR>
9272 a macro to insert footnotes in vim, but it doesn't work as of vim6.0. so i
9273 wrote my own; this macro requires two differents shortcuts, one for entering
9274 the first footnote, the other one for all subsequent footnotes.
9275
9276 when you hit "K0" (first footnote) or "KK" (all other footnotes) in normal
9277 mode, your cursor is positionned at the end of the document, in the footnote &
9278 in insert mode. The "a" bookmark is set to the place where you entered the
9279 footnote in the text. so a "`a" will bring you back to the location of the
9280 footnote in the text.
9281
9282 " for now requires entering K0 for the first footnote and then KK
9283 nmap K0 i[0]&lt;esc&gt;maG$i&lt;end&gt;&lt;enter&gt;[0] nmap KK
9284 maG$?\[[0-9]*\]&lt;enter&gt;yt]G$i&lt;end&gt;&lt;enter&gt;&lt;esc&gt;p&lt;C-a&gt;i&lt;end&gt;]&lt;esc&gt;`aP&lt;C-a&gt;&lt;right&gt;i]&lt;esc&gt;maG$i&lt;end&gt;&lt;end&gt;
9285
9286 </pre></tip> </html> <Tip category="KVim">
9287 <html><center>Syntax-based folding for c/c++/java</center> <pre> <A
9288 HREF="http://vim.sf.net/tip_view.php?tip_id=333">http://vim.sf.net/tip_view.php?tip_id=333</A><BR>
9289
9290 Here's a function to toggle the use of syntax-based folding for a c/c++/java
9291 file. It also handles folding markers.
9292
9293 function! OutlineToggle()
9294 if (! exists ("b:outline_mode"))
9295 let b:outline_mode = 0
9296 endif
9297
9298 if (b:outline_mode == 0)
9299 syn region myFold start="{" end="}" transparent fold syn sync
9300 fromstart set foldmethod=syntax
9301
9302 silent! exec "%s/{{{/&lt;&lt;&lt;/" silent! exec "%s/}}}/&gt;&gt;&gt;/"
9303
9304 let b:outline_mode = 1
9305 else
9306 set foldmethod=marker
9307
9308 silent! exec "%s/&lt;&lt;&lt;/{{{/" silent! exec "%s/&gt;&gt;&gt;/}}}/"
9309
9310 let b:outline_mode = 0
9311 endif
9312 endfunction
9313
9314 </html></tip>