blob: 67b350d865a85e540247d6c20a89fd9d6c2c70ea [file] [log] [blame]
Bram Moolenaar843ee412004-06-30 16:16:41 +00001*vimtips.txt* This file comes from the Vim Online tip database. These tips
2were downloaded on Tue, 24 Sep 2002 15:27:26 -0700 More tips can be found at <A
3HREF="http://vim.sf.net/tip_index.php">http://vim.sf.net/tip_index.php</A><BR>
4A new tip file can be downloaded from <A
5HREF="http://vim.sf.net/tip_download.php">http://vim.sf.net/tip_download.php</A><BR>
6
7Thanks for using vim online.
8
9<Tip category="KVim"> <html><center>the super star</center> <pre> <A
10HREF="http://vim.sf.net/tip_view.php?tip_id=1">http://vim.sf.net/tip_view.php?tip_id=1</A><BR>
11
12When a discussion started about learning vim on the vim list Juergen Salk
13mentioned the "*" key as something that he wished he had know earlier. When
14I read the mail I had to go help on what the heck the "*" did. I also wish
15I had known earlier...
16
17Using the "*" key while in normal mode searches for the word under the cursor.
18
19If 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
22edit of files in the same directory</center> <pre> <A
23HREF="http://vim.sf.net/tip_view.php?tip_id=2">http://vim.sf.net/tip_view.php?tip_id=2</A><BR>
24
25It was often frustrating when I would open a file deep in the code tree and
26then realize I wanted to open another file in that same directory. Douglas
27Potts 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
30expression to extract path from current file's path " (thanks Douglas Potts)
31if has("unix")
32 map ,e :e &lt;C-R&gt;=expand("%:p:h") . "/" &lt;CR&gt;
33else
34 map ,e :e &lt;C-R&gt;=expand("%:p:h") . "\" &lt;CR&gt;
35endif
36
37Then when you type ,e in normal mode you can use tab to complete to the
38file. You can also expand this to allow for spitting, etc. Very very nice.
39
40</pre></tip> </html> <Tip category="KVim"> <html><center>use
41vim to quickly compile java files</center> <pre> <A
42HREF="http://vim.sf.net/tip_view.php?tip_id=3">http://vim.sf.net/tip_view.php?tip_id=3</A><BR>
43
44For a number of years I used vim on an SGI box. When I left my job at SGI
45I went to a company that developed on PCs. For 2 years I used IDEs. I was
46unhappy. I was frustrated. I couldn't figure out why. (Beyond my machine
47crashing twice a day.) Finally I upgraded to windows 2000 (kind of stable!) and
48started using vim as an IDE. All was good. Here is how you use vim to compile
49your java:
50
511. While I'm sure this works with javac, javac is slow slow slow. So download
52the Jikes complier first. (Jikes is from ibm, search on google for jikes
53and you will find it..available on most platforms.)
54
552. Add the following to your vimrc:
56
57set makeprg=jikes -nowarn -Xstdout +E % set
58errorformat=%f:%l:%c:%*\d:%*\d:%*\s%m
59
603. When you are editing a java file type :make and it will compile the
61current file and jump you to the first error in the file (if any). Read
62":help quickfix" for how to move between errors.
63
64To setup your classpath environment either launch gvim from a shell that
65has your classpath/path setup or use the "let" command to configure it in
66your vimrc.
67
68</pre></tip> </html> <Tip category="KVim">
69<html><center>Any word completion</center> <pre> <A
70HREF="http://vim.sf.net/tip_view.php?tip_id=4">http://vim.sf.net/tip_view.php?tip_id=4</A><BR>
71
72Either when programming or writing, I tend to have some identifiers or words
73that I use all the time. By sheer accident, I noticed the 'ctrl-n' command,
74that will attempt to complete the word under the cursor. Hit it once, and it
75will try to complete it with the first match in the current file. If there is
76no match, it will (at least in the case of C code) search through all files
77included from the current one. Repeated invocations will cycle through all
78found matches.
79
80</pre></tip> </html> <Tip category="KVim">
81<html><center>Quickly searching for a word</center> <pre> <A
82HREF="http://vim.sf.net/tip_view.php?tip_id=5">http://vim.sf.net/tip_view.php?tip_id=5</A><BR>
83
84To search for a word under the cursor in the current file you can use either
85the "*" or "#" keys.
86
87The "*" key will search for the word from the current cursor position to
88the end of the file. The "#" key will search for the word from the current
89cursor position to the top of the file.
90
91Note that the above two keys will search for the whole word and not the
92partial word. This is equivalent to using the &lt;word&gt; pattern in the
93search commands (/ and ?).
94
95To search for partial matches, you can use the "g*" and "g#" key sequence.
96
97You can also use the mouse to search for a word. This will only work in
98the GUI version of VIM (gvim) or a console version of VIM in an xterm which
99accepts a mouse. Also, the 'mousemodel' should be set to 'extend'. Add the
100following line to your .vimrc:
101
102set mousemodel=extend
103
104To search for a word under the cursor from the current cursor position to
105the end of the file, press the shift key and click on the word using the
106left mouse button. To search in the opposite direction, press the shift
107key and click on the word using the the right mouse button.
108
109To 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
116HREF="http://vim.sf.net/tip_view.php?tip_id=6">http://vim.sf.net/tip_view.php?tip_id=6</A><BR>
117
118The % key can be used
119
1201. To jump to a matching opening or closing parenthesis, square
121 bracket or a curly brace i.e. ([{}])
1222. To jump to start or end of a C-style comment /* */. 3. To jump to a
123matching #if, #ifdef, #else, #elif, #endif C
124 preprocessor conditionals.
125
126To get more information about this, do
127
128 :help %
129
130The % 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
136to the start and end of a code block</center> <pre> <A
137HREF="http://vim.sf.net/tip_view.php?tip_id=7">http://vim.sf.net/tip_view.php?tip_id=7</A><BR>
138
139To jump to the beginning of a C code block (while, switch, if etc), use the
140[{ command.
141
142To jump to the end of a C code block (while, switch, if etc), use the ]}
143command.
144
145The above two commands will work from anywhere inside the code block.
146
147To jump to the beginning of a parenthesis use the [( command.
148
149To jump to the end of a parenthesis use the ]) command.
150
151To get more help on these commands, do
152
153:help [{ :help ]} :help [( :help ])
154
155</pre></tip> </html> <Tip category="KVim"> <html><center>Jumping
156to the declaration of a local/global variable</center> <pre> <A
157HREF="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,
160position 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,
163position the cursor on the name of the variable and use the gD command.
164
165</pre></tip> </html> <Tip category="KVim"> <html><center>Displaying
166a variable/macro definition</center> <pre> <A
167HREF="http://vim.sf.net/tip_view.php?tip_id=9">http://vim.sf.net/tip_view.php?tip_id=9</A><BR>
168
169To display the definition of a variable, place the cursor on the variable
170and use the [i command. To display a macro definition, place the cursor on
171the macro name and use the [d command. Note that these commands will work
172most 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
177to previosuly visited locations in a file</center> <pre> <A
178HREF="http://vim.sf.net/tip_view.php?tip_id=10">http://vim.sf.net/tip_view.php?tip_id=10</A><BR>
179
180Vim remembers all the locations visited by you in a file in a session.
181You can jump to the older locations by pressing the Ctrl-O key. You can
182jump to the newer locations by pressing the Ctrl-I or the &lt;Tab&gt; key.
183
184To 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
189words quicky in insert mode</center> <pre> <A
190HREF="http://vim.sf.net/tip_view.php?tip_id=11">http://vim.sf.net/tip_view.php?tip_id=11</A><BR>
191
192In Insert mode, press the Ctrl-p or Ctrl-n key to complete part of a word
193that has been typed.
194
195This is useful while typing C programs to complete long variable and
196function names. This also helps in avoiding typing mistakes.
197
198Note that using the 'complete' option, you can complete keywords defined in
199one of the include files, tag file, etc.
200
201To 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
207HREF="http://vim.sf.net/tip_view.php?tip_id=12">http://vim.sf.net/tip_view.php?tip_id=12</A><BR>
208
209To insert space characters whenever the tab key is pressed, set the
210'expandtab' option:
211
212 set expandtab
213
214With this option set, if you want to enter a real tab character use
215Ctrl-V&lt;Tab&gt; key sequence.
216
217To control the number of space characters that will be inserted when the tab
218key is pressed, set the 'tabstop' option. For example, to insert 4 spaces
219for a tab, use:
220
221 set tabstop=4
222
223After the 'expandtab' option is set, all the new tab characters entered will
224be changed to spaces. This will not affect the existing tab characters.
225To change all the existing tab characters to match the current tab settings,
226use
227
228 :retab
229
230To change the number of space characters inserted for indentation, use the
231'shiftwidth' option:
232
233 set shiftwidth=4
234
235For example, to get the following coding style,
236 - No tabs in the source file - All tab characters are 4 space
237 characters
238
239use the following set of options:
240
241 set tabstop=4 set shiftwidth=4 set expandtab
242
243Add the above settings to your .vimrc file.
244
245To get more help on these options, use :help tabstop :help shiftwidth :help
246expandtab
247
248</pre></tip> </html> <Tip category="KVim">
249<html><center>Incremental search</center> <pre> <A
250HREF="http://vim.sf.net/tip_view.php?tip_id=13">http://vim.sf.net/tip_view.php?tip_id=13</A><BR>
251
252To move the cursor to the matched string, while typing the search string,
253set the following option in the .vimrc file:
254
255 set incsearch
256
257You can complete the search by pressing the Enter key. To cancel the search,
258press the escape key.
259
260</pre></tip> </html> <Tip category="KVim"> <html><center>Highlighting
261all the search pattern matches</center> <pre> <A
262HREF="http://vim.sf.net/tip_view.php?tip_id=14">http://vim.sf.net/tip_view.php?tip_id=14</A><BR>
263
264To highlight all the search pattern matches in a file set the following option:
265
266 :set hlsearch
267
268After this option is set, if you search for a pattern, all the matches in
269the file will be highlighted in yellow.
270
271To disable the highlighting temporarily, use the command
272
273 :nohlsearch
274
275This command will remove the highlighting for the current search.
276The highlighting will come back for the next search.
277
278To disable the highlighting completely, set the following option:
279
280 :set nohlsearch
281
282By default, the hlsearch option is turned off.
283
284To 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
290HREF="http://vim.sf.net/tip_view.php?tip_id=15">http://vim.sf.net/tip_view.php?tip_id=15</A><BR>
291
292To display the status line always, set the following option in your .vimrc
293file:
294
295 set laststatus=2
296
297The advantage of having the status line displayed always is, you can see
298the current mode, file name, file status, ruler, etc.
299
300To get more help on this, use
301
302:help laststatus
303
304</pre></tip> </html> <Tip category="KVim"> <html><center>Avoiding
305the "Hit ENTER to continue" prompts</center> <pre> <A
306HREF="http://vim.sf.net/tip_view.php?tip_id=16">http://vim.sf.net/tip_view.php?tip_id=16</A><BR>
307
308To avoid the "Hit ENTER to continue" prompt, use the 'shortmess' option.
309Add the following line to your .vimrc file:
310
311 set shortmess=a
312
313Also, you can increase the height of the command line to 2
314
315 set cmdheight=2
316
317The default command height is 1.
318
319To 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
324previosuly entered characters in insert mode</center> <pre> <A
325HREF="http://vim.sf.net/tip_view.php?tip_id=17">http://vim.sf.net/tip_view.php?tip_id=17</A><BR>
326
327In insert mode, to erase previously entered characters, set the following
328option:
329
330 set backspace=2
331
332By default, this option is empty. If this option is empty, in insert mode,
333you can not erase characters entered before this insert mode started.
334This is the standard Vi behavior.
335
336To 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
342HREF="http://vim.sf.net/tip_view.php?tip_id=18">http://vim.sf.net/tip_view.php?tip_id=18</A><BR>
343
344From Johannes Zellner on the vim list:
345
346You can use vim's makeprg and equalprg to clean up HTML. First download
347html tidy from <A HREF="http://www.w3.org/People/Raggett/tidy/. Then use
348the following commands.">http://www.w3.org/People/Raggett/tidy/. Then use
349the following commands.</A><BR>
350
351vim6? exe 'setlocal equalprg=tidy -quiet -f '.&errorfile setlocal makeprg=tidy
352-quiet -e %
353
354vim5? exe 'set equalprg=tidy -quiet -f '.&errorfile set makeprg=tidy -quiet
355-e %
356
357At this point you can use make to clean up the full file or you can use =
358to 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
364HREF="http://vim.sf.net/tip_view.php?tip_id=19">http://vim.sf.net/tip_view.php?tip_id=19</A><BR>
365
366I have started doing all my code reviews on a laptop because of the number
367command.
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
374and *~ files littering your working directory?</center> <pre> <A
375HREF="http://vim.sf.net/tip_view.php?tip_id=20">http://vim.sf.net/tip_view.php?tip_id=20</A><BR>
376
377Have you ever been frustrated at swap files and backups cluttering up your
378working directory?
379
380Untidy:
381 ons.txt ons.txt~ README README~ tester.py tester.py~
382
383Here are a couple of options that can help:
384
385 set backupdir=./.backup,.,/tmp set directory=.,./.backup,/tmp
386
387This way, if you want your backups to be neatly grouped, just create
388a directory called '.backup' in your working directory. Vim will stash
389backups there. The 'directory' option controls where swap files go. If your
390working directory is not writable, Vim will put the swap file in one of the
391specified places.
392
393</pre></tip> </html> <Tip category="KVim">
394<html><center>easy pasting to windows apps</center> <pre> <A
395HREF="http://vim.sf.net/tip_view.php?tip_id=21">http://vim.sf.net/tip_view.php?tip_id=21</A><BR>
396
397In Vim, the unnamed register is the " register, and the Windows Clipboard is
398the * register. This means that if you yank something, you have to yank it to
399the * register if you want to paste it into a Windows app. If this is too much
400trouble, set the 'clipboard' option to 'unnamed'. Then you always yank to *.
401
402So pasting to windows apps doesn't require prefixing "* :
403
404 set clipboard=unnamed
405
406</pre></tip> </html> <Tip category="KVim"> <html><center>handle
407common typos for :commands</center> <pre> <A
408HREF="http://vim.sf.net/tip_view.php?tip_id=22">http://vim.sf.net/tip_view.php?tip_id=22</A><BR>
409
410I frequently hold the shift key for too long when typing, for instance :wq,
411and end up with :Wq. Vim then whines "Not an editor command: Wq"
412
413In my .vimrc, I have taught vim my common typos: command! Q quit command! W
414write command! Wq wq " this one won't work, because :X is already a built-in
415command command! X xit
416
417</pre></tip> </html> <Tip category="KVim">
418<html><center>Vim xterm title</center> <pre> <A
419HREF="http://vim.sf.net/tip_view.php?tip_id=23">http://vim.sf.net/tip_view.php?tip_id=23</A><BR>
420
421Check out your .vimrc. If 'set notitle' is an entry, comment it out with
422a quotation mark ("). Now your xterm should inherit the title from Vim.
423e.g. 'Vim - ~/.vimrc'. This can be quite nice when programming and editing
424lots of files at the same time. by [jonasbn@wanadoo.dk]
425
426</pre></tip> </html> <Tip category="KVim"> <html><center>changing
427the default syntax highlighting</center> <pre> <A
428HREF="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
4331. I want *.foo files to be highlighted like HTML files.
434
435:help new-filetype <A
436HREF="http://www.vim.org/html/autocmd.html#new-filetype">http://www.vim.org/html/autocmd.html#new-filetype</A><BR>
437
4382. I want to define a syntax file for *.bar files. Read the above and also
439
440:help mysyntaxfile <A
441HREF="http://www.vim.org/html/syntax.html#mysyntaxfile">http://www.vim.org/html/syntax.html#mysyntaxfile</A><BR>
442
4433. I want to make a few changes to the existing syntax highlighting.
444Depending on the x in 5.x, either read the above and page down a few screens,
445or you may be able to skip right to
446
447:help mysyntaxfile-add <A
448HREF="http://www.vim.org/html/syntax.html#mysyntaxfile-add">http://www.vim.org/html/syntax.html#mysyntaxfile-add</A><BR>
449
4504. I want to change some of the colors from their defaults. Again, read
451
452:help mysyntaxfile <A
453HREF="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
456highlighting on telnet (esp w/ SecureCRT)</center> <pre> <A
457HREF="http://vim.sf.net/tip_view.php?tip_id=25">http://vim.sf.net/tip_view.php?tip_id=25</A><BR>
458
459The following settings in .vimrc will enable color highlighting when using
460SecureCRT and may work on other telnet packages. The terminal type should
461be selected as ANSI and color enabled.
462
463if !has("gui_running") set t_Co=8 set t_Sf=^[[3%p1%dm set t_Sb=^[[4%p1%dm endif
464
465The ^[ is entered as "&lt;ctrl-v&gt;&lt;esc&gt;"
466
467</pre></tip> </html> <Tip category="KVim"> <html><center>Getting
468rid of ^M - mixing dos and unix</center> <pre> <A
469HREF="http://vim.sf.net/tip_view.php?tip_id=26">http://vim.sf.net/tip_view.php?tip_id=26</A><BR>
470
471If you work in a mixed environment you will often open files that have ^M's
472in them. An example would be this:
473
474------------------------------------------------------------------
475import java.util.Hashtable; ^M import java.util.Properties; ^Mimport
476java.io.IOException; import org.xml.sax.AttributeList; ^M import
477org.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
485Notice that some programs are not consistent in the way they insert the line
486breaks 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
488one). There are two steps to clean this up.
489
4901. replace all extraneous ^M:
491
492:%s/^M$//g
493
494BE SURE YOU MAKE the ^M USING "CTRL-V CTRL-M" NOT BY TYPING "CARROT M"! This
495expression will replace all the ^M's that have carriage returns after them
496with nothing. (The dollar ties the search to the end of a line)
497
4982. replace all ^M's that need to have carriage returns:
499
500:%s/^M//g
501
502Once 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
504carriage returns after them with a carriage return.
505
506Voila! Clean file. Map this to something if you do it frequently.
507
508:help ffs - for more info on file formats
509
510thanks 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
514HREF="http://vim.sf.net/tip_view.php?tip_id=27">http://vim.sf.net/tip_view.php?tip_id=27</A><BR>
515
516when you check the output of objdump, you'll confused by the $0xFFFFFFc
517operand, 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
524endfunction usage: 5,8call Hex2Dec()
525
526</pre></tip> </html> <Tip category="KVim"> <html><center>add a line-number
527to every line without cat or awk alike utilities.</center> <pre> <A
528HREF="http://vim.sf.net/tip_view.php?tip_id=28">http://vim.sf.net/tip_view.php?tip_id=28</A><BR>
529
530With Unix-like environment, you can use cat or awk to generate a line number
531easily, because vim has a friendly interface with shell, so everything work
532in vim as well as it does in shell. :%!call -n or :%!awk '{print NR,$0}'
533
534But, if you use vim in MS-DOS, of win9x, win2000, you loss these tookit.
535here is a very simple way to archive this only by vim: fu! LineIt()
536 exe ":s/^/".line(".")."/"
537endf
538
539Well, 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
543all the line with only 7 keystroke in vim</center> <pre> <A
544HREF="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)
547from normal-mode(also known as command mode). 2. g means you'll take an
548action through the whole file, generally perform a search, `v' also perform
549a search but it match the line not match the canonical expression. 3. /
550begins the regular express 4. ^ is a special character respect the start
551of a line. 5. the second / ends the regular express and indicate that the
552remains is action to do. 6. m means move, `t` and `co' for copy, `d' for
553delete 7. 0 is the destination line.
554
555you can use :g/regexp/t$ to filter all lines and pick the match line together
556and copy them to the end of the buffer or :g/regexp/y A to put them into a
557register(not eax, ebx...)
558
559</pre></tip> </html> <Tip category="KVim">
560<html><center>Increasing or decreasing numbers</center> <pre> <A
561HREF="http://vim.sf.net/tip_view.php?tip_id=30">http://vim.sf.net/tip_view.php?tip_id=30</A><BR>
562
563To increase a number under or nearest to the right of the cursor, go to
564Normal mode and type:
565 Ctrl-A
566
567To decrease, type:
568 Ctrl-X
569
570Using 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
574HREF="http://vim.sf.net/tip_view.php?tip_id=31">http://vim.sf.net/tip_view.php?tip_id=31</A><BR>
575
576To find and replace one or more occurences of a given text pattern with a
577new text string, use the s[ubstitute] command.
578
579There 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
588occurance 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
596NB: Without the 'g' flag, replacement occurs only for the first occurrence
597in each line.
598
599For a full description and some more interesting examples of the substitute
600command refer to
601
602:help substitute
603
604See also:
605
606:help cmdline-ranges :help pattern :help gdefault
607
608</pre></tip> </html> <Tip category="KVim"> <html><center>Write
609your own vim function(scripts)</center> <pre> <A
610HREF="http://vim.sf.net/tip_view.php?tip_id=32">http://vim.sf.net/tip_view.php?tip_id=32</A><BR>
611
612compare to C and shell(bash), herein is some vim specifics about vim-script:
6131. 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.
6162. 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.
6213. 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
6304. where is the vim-library
631 yes, vim has its own function-library, just like *.a in c :help functions
6325. can I use += or ++ operator?
633 Nop, += and ++ (and -=, -- and so on)operator gone away in vim.
6346. 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
6377. 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 :
6408. Can I call a function recurse?
641 Yes, but use it carefully to avoid infinte call.
6429. Can I call another function in a function?
643 Course, like C does.
64410. 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.
64711. 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.
65112. 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
659off the line-number when enter on-line help</center> <pre> <A
660HREF="http://vim.sf.net/tip_view.php?tip_id=33">http://vim.sf.net/tip_view.php?tip_id=33</A><BR>
661
662I like the line-number for myself editing. But I hate it in on-line help
663page because it force the screen wrapped. :au filetype help :se nonu
664
665</pre></tip> </html> <Tip category="KVim"> <html><center>control
666the position of the new window</center> <pre> <A
667HREF="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
671do a vsplit)
672
673</pre></tip> </html> <Tip category="KVim"> <html><center>translate
674// style comment to /* */and vice vesa</center> <pre> <A
675HREF="http://vim.sf.net/tip_view.php?tip_id=35">http://vim.sf.net/tip_view.php?tip_id=35</A><BR>
676
677the `|' concatenate servals ex-command in one line. It's the key to translate
678// style comments to /* */ style :g#^s{-}//#s##/*# | s#$#*/#
679
680the `|' 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
690HREF="http://vim.sf.net/tip_view.php?tip_id=36">http://vim.sf.net/tip_view.php?tip_id=36</A><BR>
691
692K 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
694while the cursor is hold by a keyword such as printf will bring you to
695Gnu-info help page :h &lt;F1&gt; :h nnoremap
696
697</pre></tip> </html> <Tip category="KVim"> <html><center>The
698basic operation about vim-boolean optionals</center> <pre> <A
699HREF="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
702or :set number! switch it inverse against the current setting :set number&
703get the default value vim assums.
704
705replace number with any legal vim-boolean optionals, they all works well.
706for vim-non-boolean optionals :set optional& also works properly.
707
708</pre></tip> </html> <Tip category="KVim"> <html><center>Cursor
709one line at a time when :set wrap</center> <pre> <A
710HREF="http://vim.sf.net/tip_view.php?tip_id=38">http://vim.sf.net/tip_view.php?tip_id=38</A><BR>
711
712If your tierd of the cursor jumping past 5 lines when :set wrap then add
713these mappings to you vimrc file.
714
715nnoremap j gj nnoremap k gk vnoremap j gj vnoremap k gk nnoremap &lt;Down&gt;
716gj nnoremap &lt;Up&gt; gk vnoremap &lt;Down&gt; gj vnoremap &lt;Up&gt;
717gk inoremap &lt;Down&gt; &lt;C-o&gt;gj inoremap &lt;Up&gt; &lt;C-o&gt;gk
718
719What 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
723HREF="http://vim.sf.net/tip_view.php?tip_id=39">http://vim.sf.net/tip_view.php?tip_id=39</A><BR>
724
725To undo recent changes, use the u[ndo] command:
726
727u undo last change (can be repeated to undo preceding commands)
728U return the line to its original state (undo all changes in
729current line) CTRL-R Redo changes which were undone (undo the undo's).
730
731For 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
737HREF="http://vim.sf.net/tip_view.php?tip_id=40">http://vim.sf.net/tip_view.php?tip_id=40</A><BR>
738
739To insert the contents of a file (or the output of a system command) into
740the current buffer, use the r[ead] command:
741
742Examples:
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
752For more information about the r[ead] command refer to:
753
754:help read
755
756See also:
757
758:help cmdline-ranges :help !cmd
759
760</pre></tip> </html> <Tip category="KVim"> <html><center>Command-history
761facilities for Oracle/sqlplus user</center> <pre> <A
762HREF="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...
765and others in vim@vim.org which spend much time to answer questions,
766sometimes foolish question asked by someone like me. Without their I can't
767get the final solution for my sqlplus work descripted follows.
768 As Oracle user known, sqlplus has a very bad
769command-line edition environment. It has no command-history, don't support
770most of getline facilities. which MySQL and shell does it well. Even Microsoft
771recogonize this point. In Windows2000, doskey is installed by default.
772 Below is my vim-solution to sqlplus, which
773record the command-history when you use edit(sqlplus builtin command) to
774open the editor specified by EDITOR environment variable. It saves the SQL
775statement into a standalone file such as .sqlplus.history
776 Every time you open the file
777afiedt.buf(sqlplus's default command-buffer file), you get two splited windows,
778the buffer above is afiedt.buf, the buffer below is .sqlplus.history, you
779can see every SQL statement in the windows. If you want to use SQL statement
780in 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
795endf au BufEnter afiedt.buf call VimSQL()
796
797</pre></tip> </html> <Tip category="KVim">
798<html><center>Using marks</center> <pre> <A
799HREF="http://vim.sf.net/tip_view.php?tip_id=42">http://vim.sf.net/tip_view.php?tip_id=42</A><BR>
800
801To mark one or more positions in a file, use the m[ark] command.
802
803Examples:
804
805ma - 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
811d'a - delete from current line to line of mark a
812
813d`a - delete from current cursor position to mark a
814
815c'a - change text from current line to line of mark a
816
817y`a - yank text to unnamed buffer from cursor to mark a
818
819:marks - list all the current marks
820
821NB: Lowercase marks (a-z) are valid within one file. Uppercase marks (A-Z),
822also called file marks, are valid between files.
823
824For a detailed description of the m[ark] command refer to
825
826:help mark
827
828See also:
829
830:help various-motions
831
832</pre></tip> </html> <Tip category="KVim">
833<html><center>Using abbreviations</center> <pre> <A
834HREF="http://vim.sf.net/tip_view.php?tip_id=43">http://vim.sf.net/tip_view.php?tip_id=43</A><BR>
835
836To define abbreviations, use the ab[breviate] command.
837
838Examples:
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
850NB: To avoid expansion in insert mode, type CTRL-V after the last character
851of the abbreviation.
852
853For a detailed description of the ab[breviate] command and some more examples
854refer to
855
856:help abbreviations
857
858</pre></tip> </html> <Tip category="KVim">
859<html><center>Repeat last changes</center> <pre> <A
860HREF="http://vim.sf.net/tip_view.php?tip_id=44">http://vim.sf.net/tip_view.php?tip_id=44</A><BR>
861
862Simple text changes in normal mode (e.g. "dw" or "J") can be repeated with
863the "." command. The last command-line change (those invoked with ":",
864e.g. ":s/foo/bar") can be repeated with the "@:" command.
865
866For 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
872HREF="http://vim.sf.net/tip_view.php?tip_id=45">http://vim.sf.net/tip_view.php?tip_id=45</A><BR>
873
874You 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,
876this can be used to find the previous substitute command: Type ":s" and
877then &lt;Up&gt;.
878
879There are separate history tables for the ':' commands and for previous '/'
880or '?' search strings.
881
882To 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
890For a detailed description of the command-line history refer to:
891
892:help cmdline-history
893
894See also:
895
896:help Cmdline-mode
897
898</pre></tip> </html> <Tip category="KVim"> <html><center>Win32
899binaries with perl, python, and tcl</center> <pre> <A
900HREF="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
903and &gt; python support turned on?
904
905<A
906HREF="ftp://vim.sourceforge.net/pub/vim/upload_binaries/">ftp://vim.sourceforge.net/pub/vim/upload_binaries/</A><BR>
907
908<A
909HREF="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
912characters, words and lines</center> <pre> <A
913HREF="http://vim.sf.net/tip_view.php?tip_id=47">http://vim.sf.net/tip_view.php?tip_id=47</A><BR>
914
915To swap two characters or lines, use the following commands:
916
917xp - delete the character under the cursor and put it afterwards.
918 (In other words, it swaps the characters.)
919
920ddp - delete the current line and put it afterwards.
921 (In other words, it swaps the lines.)
922
923Unfortunately there is no universal solution to swap two words. You may
924try the following ones, but don't expect too much of them:
925
926dawwP - 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
930dawbP - 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
936HREF="http://vim.sf.net/tip_view.php?tip_id=48">http://vim.sf.net/tip_view.php?tip_id=48</A><BR>
937
938You can save a lot of time when navigating through the text by using
939appropriate movements commands. In most cases the cursor keys, &lt;PageUp&gt;
940or &lt;PageDown&gt; are NOT the best choice.
941
942Here is a selection of some basic movement commands that hopefully helps
943you to acquire a taste for more:
944
945e - move to the end of a word w - move forward to the beginning of a
946word 3w - move forward three words b - move backward to the beginning of
947a word 3b - move backward three words
948
949$ - move to the end of the line &lt;End&gt; - same as $ 0 -
950move 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
956H - jump to the top of the display M - jump to the middle of the display
957L - 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
960of mark m
961
962G - 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 `` -
965return 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
970For some more interesting movement commands (especially those for programmers)
971refer 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
979HREF="http://vim.sf.net/tip_view.php?tip_id=49">http://vim.sf.net/tip_view.php?tip_id=49</A><BR>
980
981To switch the case of one or more characters use the "~", "gU" or "gu"
982commands.
983
984Examples:
985
986~ - switch case of character under cursor
987 (in visual-mode: switch case of highlighted text)
988
9893~ - switch case of next three characters
990
991g~~ - switch case of current line
992
993U - in visual-mode: make highlighted text uppercase
994
995gUU - make current line uppercase
996
997u - in visual-mode: make highlighted text lowercase
998
999guu - make current line lowercase
1000
1001gUaw - make current word uppercase
1002
1003guaw - make current word lowercase
1004
1005For some more examples refer to
1006
1007:help ~
1008
1009See also:
1010
1011:help simple-change
1012
1013</pre></tip> </html> <Tip category="KVim">
1014<html><center>Recovering files</center> <pre> <A
1015HREF="http://vim.sf.net/tip_view.php?tip_id=50">http://vim.sf.net/tip_view.php?tip_id=50</A><BR>
1016
1017If your computer has crashed while editing a file, you should be able to
1018recover the file by typing
1019
1020 vi -r &lt;filename&gt;
1021
1022where &lt;filename&gt; is the name of the file you were editing at the time
1023of the crash. If you were editing without a file name, give an empty string
1024as argument:
1025
1026 vim -r ""
1027
1028To get a list of recoverable files start vim without arguments:
1029
1030 vim -r
1031
1032For 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
1038HREF="http://vim.sf.net/tip_view.php?tip_id=51">http://vim.sf.net/tip_view.php?tip_id=51</A><BR>
1039
1040To enter german umlauts (or any other of those weired characters) not
1041available on your keyboard use 'digraphs':
1042
1043In insert-mode type for example:
1044
1045 CTRL-K "a
1046
1047 CTRL-K ^e
1048
1049which gives an 'ä' and 'e' with a hat.
1050
1051You can also set the digraph option:
1052
1053 :set digraph (or :set dg)
1054
1055With digraph option set you can enter
1056
1057 " &lt;BS&gt; a
1058
1059 ^ &lt;BS&gt; e
1060
1061which gives the same result.
1062
1063To get a list of currently defined digraphs type
1064
1065 :dig[graphs]
1066
1067For 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
1073HREF="http://vim.sf.net/tip_view.php?tip_id=52">http://vim.sf.net/tip_view.php?tip_id=52</A><BR>
1074
1075If you want to bind two or more windows such that when one window is scrolled,
1076the other windows are scrolled simultaneously, set the 'scrollbind' option
1077for these windows:
1078
1079:set scrollbind
1080
1081When a window that has 'scrollbind' set is scrolled, all other 'scrollbind'
1082windows are scrolled the same amount, if possible.
1083
1084For more information about the 'scrollbind' option refer to
1085
1086:help scoll-binding
1087
1088</pre></tip> </html> <Tip category="KVim"> <html><center>Better
1089colors for syntax highlighting</center> <pre> <A
1090HREF="http://vim.sf.net/tip_view.php?tip_id=53">http://vim.sf.net/tip_view.php?tip_id=53</A><BR>
1091
1092For syntax highlighting there are two sets of default color maps: One for a
1093light and another one for a dark background. If you have a black background,
1094use the following command to get a better color map for syntax highlighting:
1095
1096:set background=dark
1097
1098You have to switch off and on again syntax highlighting to activate the new
1099color map:
1100
1101:syntax off :syntax on
1102
1103For a detailled description of syntax highlighting refer to
1104
1105:help syntax.txt
1106
1107See also the Vim syntax support file: $VIMRUNTIME/syntax/synload.vim
1108
1109</pre></tip> </html> <Tip category="KVim"> <html><center>View
1110a Java Class File Decompiled thru Vim</center> <pre> <A
1111HREF="http://vim.sf.net/tip_view.php?tip_id=54">http://vim.sf.net/tip_view.php?tip_id=54</A><BR>
1112
1113Hi All, Wish u could view a Java Class File using Vim, Well ur query
1114ends here. First of all u will need a Java Decompiler to decompile the
1115Class File. I would suggest the JAD decompiler by Pavel Kouznetsov <A
1116HREF="http://www.geocities.com/SiliconValley/Bridge/8617/jad.html">http://www.geocities.com/SiliconValley/Bridge/8617/jad.html</A><BR>
1117
1118Its a command line decompiler and absolutely free. U can use any command
1119line decompiler of ur choice.
1120
1121Next create a vimscript file called jad.vim as #########################
1122FILE 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
1125bufreadpost,filereadpost *.class normal gg=G au bufreadpost,filereadpost
1126*.class set nomodified augr END ######################## FILE END
1127#####################
1128
1129Note:- Keep the Jad.exe in a directory with out white spaces. The -p options
1130directs JAD to send the output to standard output instead of a .jad file. Other
1131options are described on the JAD site.
1132
1133Next add the following line in the .vimrc file. so jad.vim
1134
1135Next time u do vim abc.class. Viola u have the source code for abc.class.
1136
1137NOTE:- I have written the script so as to open the class file read only,
1138So that u dont accidently modify it. U can also exted this script to unjar
1139a jar file and then view each file in the JAR file. thanks bhaskar Any
1140suggestions are welcome
1141
1142</pre></tip> </html> <Tip category="KVim">
1143<html><center>previous buffer</center> <pre> <A
1144HREF="http://vim.sf.net/tip_view.php?tip_id=55">http://vim.sf.net/tip_view.php?tip_id=55</A><BR>
1145
1146One of the keys to vim is buffer management. If I have to use another IDE
1147that makes me click on a tab every time I want to look at another file I'm
1148going to go postal.
1149
1150So of course you know about :ls which lists all the current open buffers. This
1151gets 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
1153is really nice because you can type any fragment of a file name and it will
1154complete to the matching file. (i.e. RequestManager.java can be completed
1155using "tma"&lt;tab&gt; or "req"&lt;tab&gt; or "r.java"&lt;tab&gt;).
1156
1157Now for awhile I was also using :bn and :bp which jumps you to the next
1158and previous buffer respectively. I found I was often frustrated because I
1159wanted :bp to be the previous buffer I was in, not the previous buffer in
1160the list. So (drum roll) the reason I wrote this tip was because of:
1161
1162:b#
1163
1164jump to the previous buffer you were in. Very very handy. The only thing
1165nicer are tag, but that's a tip for another time.
1166
1167:help buffers :help bn :help bp
1168
1169If anybody knows where to get help on # in this context please add notes.
1170
1171</pre></tip> </html> <Tip category="KVim"> <html><center>how
1172to avoid obliterating window layout</center> <pre> <A
1173HREF="http://vim.sf.net/tip_view.php?tip_id=58">http://vim.sf.net/tip_view.php?tip_id=58</A><BR>
1174
1175If you take the time to lay out several windows with vim (especially vertically
1176in version 6), you may be bummed when you hit an errant key and find that
1177all but what one window disappears.
1178
1179What 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
1181don't follow with a window command. Now hitting 'o' to start insert mode
1182issues a command equivalent to :only, and closes all windows execept for
1183the one you are in (unless some windows have unsaved changes in them).
1184
1185How to avoid this: petition the vim-dev mailing list about how :only is
1186sufficient for the infrequenty use this might get (j/k).
1187
1188Really: use mapping to disable the &lt;C-W&gt;o functionality; put this in
1189your .vimrc:
1190
1191nnoremap &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
1194references:
1195
1196:help :only :help CTRL-W_o
1197
1198That is all. Scott
1199
1200</pre></tip> </html> <Tip category="KVim"> <html><center>Applying
1201substitutes to a visual block</center> <pre> <A
1202HREF="http://vim.sf.net/tip_view.php?tip_id=62">http://vim.sf.net/tip_view.php?tip_id=62</A><BR>
1203
1204If you'd like to apply a substitute, or even any ex command, to a visual-block
1205selected text region (ctrl-v and move), then you'll want Stefan Roemer's <A
1206HREF="http://www.erols.com/astronaut/vim/vimscript/vis.vim . Just source
1207it in,">http://www.erols.com/astronaut/vim/vimscript/vis.vim . Just source
1208it in,</A><BR> and then press ":B". On the command line you'll see
1209
1210:'&lt;,'&gt;BCtrl-V
1211
1212Just continue with the substitute or whatever...
1213
1214:'&lt;,'&gt;B s/abc/ABC/g
1215
1216and the substitute will be applied to just that block of text!
1217
1218Example: Ctrl-V Select..........|......Type ..................just
1219the 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
1228substitutes to a visual block</center> <pre> <A
1229HREF="http://vim.sf.net/tip_view.php?tip_id=63">http://vim.sf.net/tip_view.php?tip_id=63</A><BR>
1230
1231If you'd like to apply a substitute, or even any ex command, to a visual-block
1232selected text region (ctrl-v and move), then you'll want Stefan Roemer's <A
1233HREF="http://www.erols.com/astronaut/vim/vimscript/vis.vim . Just source
1234it in,">http://www.erols.com/astronaut/vim/vimscript/vis.vim . Just source
1235it in,</A><BR> and then press ":B". On the command line you'll see
1236
1237:'&lt;,'&gt;BCtrl-V
1238
1239Just continue with the substitute or whatever...
1240
1241:'&lt;,'&gt;B s/abc/ABC/g
1242
1243and the substitute will be applied to just that block of text!
1244
1245Example: Ctrl-V Select..........|......Type
1246..................just the central.......|......:B
1247s/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
1256your working directory to the file you're editing</center> <pre> <A
1257HREF="http://vim.sf.net/tip_view.php?tip_id=64">http://vim.sf.net/tip_view.php?tip_id=64</A><BR>
1258
1259Sometimes I think it's helpful if your working directory is always the same
1260as the buffer you are editing. You need to put this in your .vimrc:
1261
1262function! CHANGE_CURR_DIR()
1263 let _dir = expand("%:p:h") exec "cd " . _dir unlet _dir
1264endfunction
1265
1266autocmd BufEnter * call CHANGE_CURR_DIR()
1267
1268Doing this will make a "cd" command to your the current buffer each time
1269you switch to it. This is actually similar to vimtip#2 but more automatic.
1270
1271You should see for more details: :help autocmd :help expand :help function
1272
1273Note: This tip was contributed by somebody on the list a while ago (sorry
1274for no reference) and it has been extremely helpful to me. Thanks!
1275
1276</pre></tip> </html> <Tip category="KVim"> <html><center>Insert
1277line number into the actuall text of the file.</center> <pre> <A
1278HREF="http://vim.sf.net/tip_view.php?tip_id=65">http://vim.sf.net/tip_view.php?tip_id=65</A><BR>
1279
1280Although :set number will add nice line number for you At time you may wish
1281to actually place the line numbers into the file. For example on GNU Unix
1282you can acomplish a simular task using cat -n file &gt; new_file
1283
1284In VIM you can use the global command to do this
1285
1286:g/^/exec "s/^/".strpart(line(".")." ", 0, 4)
1287
1288What this does is run the exec comand on every line that matches /^/ (All)
1289The exec command taks a string and executes it as if it were typed in.
1290
1291line(".")." " -&gt; returns the number of the current line plus four spaces.
1292strpart("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
1296text between two Vim 'sessions',</center> <pre> <A
1297HREF="http://vim.sf.net/tip_view.php?tip_id=66">http://vim.sf.net/tip_view.php?tip_id=66</A><BR>
1298
1299This one is a one of my favorites from Dr. Chip, and I haven't seen it come
1300across vim tips yet...
1301
1302Can 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;
1310else
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;
1314endif
1315
1316</pre></tip> </html> <Tip category="KVim">
1317<html><center>Ascii Value</center> <pre> <A
1318HREF="http://vim.sf.net/tip_view.php?tip_id=67">http://vim.sf.net/tip_view.php?tip_id=67</A><BR>
1319
1320Sometimes we, the programmers, need the value of a character, don't we?
1321You can learn the ascii value of a character by pressing g and a keys.(ga)!
1322It displays the value in dec, hex and octal...
1323
1324</pre></tip> </html> <Tip category="KVim">
1325<html><center>Delete key</center> <pre> <A
1326HREF="http://vim.sf.net/tip_view.php?tip_id=68">http://vim.sf.net/tip_view.php?tip_id=68</A><BR>
1327
1328Don'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
1333HREF="http://vim.sf.net/tip_view.php?tip_id=69">http://vim.sf.net/tip_view.php?tip_id=69</A><BR>
1334
1335You can copy and paste the last changes you made in the last insert mode
1336without using y and p by pressing . (just dot). Vim memorizes the keys you
1337pressed and echos them if you hit the dot key. You must be in command mode
1338as 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
1342HREF="http://vim.sf.net/tip_view.php?tip_id=70">http://vim.sf.net/tip_view.php?tip_id=70</A><BR>
1343
1344From Peter Bismuti on the vim list:
1345
1346How to global search and replace in all buffers with one command? You need
1347the 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
1357endfun
1358
1359":call AllBuffers("%s/foo/bar/ge|update")
1360
1361Thanks Peter!
1362
1363</pre></tip> </html> <Tip category="KVim"> <html><center>Transfer
1364text between two gvim sessions using clipboard</center> <pre> <A
1365HREF="http://vim.sf.net/tip_view.php?tip_id=71">http://vim.sf.net/tip_view.php?tip_id=71</A><BR>
1366
1367If you use gvim, you can transfer text from one instance of gvim into another
1368one using clipboard. It is convenient to use * (star) register, like this:
1369
1370In one instance yank two lines into clipboard:
1371 "*2yy
1372Paste it in another instance in normal mode:
1373 "*p
1374or 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
1379HREF="http://vim.sf.net/tip_view.php?tip_id=72">http://vim.sf.net/tip_view.php?tip_id=72</A><BR>
1380
1381Sometimes to improve the readability of the document I insert empty lines,
1382which will be later removed. To get rid off them try: :%g/^$/d This will
1383remove a l l empty line in the document. Some other tipps you can find
1384under www.linuxclass.de/vim.phtml
1385
1386</pre></tip> </html> <Tip category="KVim">
1387<html><center>Using vim as calculator</center> <pre> <A
1388HREF="http://vim.sf.net/tip_view.php?tip_id=73">http://vim.sf.net/tip_view.php?tip_id=73</A><BR>
1389
1390Basic 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
1392will be printed in the document.
1393
1394Some other tipps you can find under www.linuxclass.de/vim.phtml
1395
1396</pre></tip> </html> <Tip category="KVim"> <html><center>Using
1397Vim as an outline processor</center> <pre> <A
1398HREF="http://vim.sf.net/tip_view.php?tip_id=74">http://vim.sf.net/tip_view.php?tip_id=74</A><BR>
1399
1400With the addition of folding, Vim6 can function as a high performance outline
1401processor. Simply :set ai and in insert mode use backspace to promote and
1402tab to demote headlines.
1403
1404In command mode, &lt;&lt; promotes (n&lt;&lt; to promote multiple lines),
1405and &gt;&gt; demotes. Also, highlight several headlines and &lt; or &gt;
1406to promote or demote.
1407
1408:set foldmethod=indent, and then your z commands can expand or collapse
1409headline trees, filewide or by the tree.
1410
1411The VimOutliner GPL distro contains the scripts and configs to easily
1412configure Vim6 as an outliner, including scripts to create tag files enabling
1413interoutline hyperlinking.
1414
1415The VimOutliner project is at <A
1416HREF="http://www.troubleshooters.com/projects/vimoutliner/index.htm.">http://www.troubleshooters.com/projects/vimoutliner/index.htm.</A><BR>
1417
1418Steve (Litt) slitt@troubleshooters.com
1419
1420</pre></tip> </html> <Tip category="KVim"> <html><center>Remap
1421CAPSLOCK key in Windows 2000 Professional and NT4.0</center> <pre> <A
1422HREF="http://vim.sf.net/tip_view.php?tip_id=75">http://vim.sf.net/tip_view.php?tip_id=75</A><BR>
1423
1424If you're Windows 2000 Professional user and got tired to move your hands off
1425basic row when hitting &lt;ESC&gt; key here the solution (not for Windows 9x.):
1426remap CapsLock key as &lt;ESC&gt; key. It's located in useful position. Put
1427this lines into &lt;EscLock.reg&gt; file and start it in explorer.Reboot.Enjoy.
1428
1429REGEDIT4 [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
1432To restore you capslock back just delete this entry from Registry and reboot.
1433And below is remapping &lt;capslock&gt; as &lt;Left Control&gt;:
1434
1435REGEDIT4 [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
1440HREF="http://vim.sf.net/tip_view.php?tip_id=76">http://vim.sf.net/tip_view.php?tip_id=76</A><BR>
1441
1442The 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
1444through the list of errors/matches and the appropriate source code locations
1445with, for instance, the ':cnext' command. Another way to get a quick overview
1446is to use VIMs folding mode, to fold away all the error-free/match-free
1447regions. The script at the end of this message can be used for this
1448purpose. It is at the moment not elaborate enough to put it up as a 'script';
1449but it might give someone inspiration to do so. Big restrictions / bugs are
1450as follows: 1. Vim Perl interface is required, i.e. the output of ':version'
1451must contain '+perl' (People with Vim scripting knowledge might fix this)
14522. Works only for one file, i.e. the current buffer. 3. It's a quick hack.
1453Sample usage: (a) edit a file, (b) do ':grep regexp %' to get a quickfix
1454error list and (c) ':source foldqf.vim' will fold as described Increasing
1455the value of $CONTEXT gives you more context around the error regions.
1456
1457Here comes it, it should be 7 lines: ---foldqf.vim cwindow perl $CONTEXT = 0;
1458perl @A = map { m/\|(\d+)\|/; $1 +0 } $curbuf-&gt;Get(1..$curbuf-&gt;Count());
1459close 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
1465search results using folds</center> <pre> <A
1466HREF="http://vim.sf.net/tip_view.php?tip_id=77">http://vim.sf.net/tip_view.php?tip_id=77</A><BR>
1467
1468A guy I work with told me about a function that an old IBM text editor had
1469that he said was useful, and that is to create folds in the file after a
1470search such that every line that is visible contains the search pattern(except
1471possibly the first). All lines that do not contain the search pattern are
1472folded up to the last occurence of the pattern or the top of the file.
1473
1474One use for such a function is to be able to make a quick and dirty api of
1475a source file. For example, if working in Java, you could run the function
1476using the pattern "public|protected|private" and ithe results would be that
1477only the method headers would be visible (well, close enough).
1478
1479function! 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
1501endfunction
1502
1503" Command is executed as ':Fs pattern'" command! -nargs=+ -complete=command
1504Fs call Foldsearch(&lt;q-args&gt;) " View the methods and variables in a
1505java 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
1509HREF="http://vim.sf.net/tip_view.php?tip_id=78">http://vim.sf.net/tip_view.php?tip_id=78</A><BR>
1510
1511For people using mutt and vim for mail, the following script will allow
1512you to insert a new signature (and again and again if you don\'t like the
1513current one) at the bottom of your mail. This is usefull eg when you don\'t
1514want to send a potentially offensive quote to someone you don\'t know very
1515well (or a mailing list), but are too lazy to delete the quote, open your
1516quotes file, and cut and paste another one in. (I put it here in \'tips\'
1517and 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
1522your sig with '-- ', or adjust the script " -Adjust the last execute to a
1523command that prints a sig to stdout " Known problems: " - You'll get an
1524error message when you're below the last " '^-- $' in your mail (nothing
1525bad though - just an not- " found marker)
1526
1527function! 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
1530endfunction
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
1534HREF="http://vim.sf.net/tip_view.php?tip_id=79">http://vim.sf.net/tip_view.php?tip_id=79</A><BR>
1535
1536The following function will make a :cwindow window with a line per function
1537in the current C source file. NOTE: It writes the file as a side effect.
1538
1539Invoke with ':call ShowFunc()' You may want to do :nmap &lt;somekey&gt;
1540:call ShowFunc()&lt;CR&gt;
1541
1542function! 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
1553endfunc
1554
1555</pre></tip> </html> <Tip category="KVim"> <html><center>Restore
1556cursor to file position in previous editing session</center> <pre> <A
1557HREF="http://vim.sf.net/tip_view.php?tip_id=80">http://vim.sf.net/tip_view.php?tip_id=80</A><BR>
1558
1559Here's something for your &lt;.vimrc&gt; which will allow you to restore
1560your cursor position in a file over several editing sessions. This technique
1561uses the viminfo option:
1562
1563Ex. 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
1567If you're on Unix, the viminfo is probably fine as is (but check up on Vim's
1568help for viminfo to see if you like the settings above). For Windows you'll
1569need to change the "n" suboption to something like
1570
1571Ex. set viminfo='10,\"100,:20,%,nc:\\some\\place\\under\\Windoz\\_viminfo
1572
1573This tip is a somewhat improved version of the example given for :he line()
1574in the Vim on-line documentation.
1575
1576</pre></tip> </html> <Tip category="KVim">
1577<html><center>Substitution of characters and lines in VIM is
1578made far easier with the s and S commands</center> <pre> <A
1579HREF="http://vim.sf.net/tip_view.php?tip_id=81">http://vim.sf.net/tip_view.php?tip_id=81</A><BR>
1580
1581Substitute Characters ----------------------------------- I was just editing
1582a file that contained the same leading string on many lines.
1583
1584example:
1585
1586foo_bar_baz1=a foo_bar_baz1=abc674 foo_bar_baz1=qrs foo_bar_baz1=m1
1587foo_bar_baz1=bz90 foo_bar_baz1=bc ...
1588
1589Needing to only substitute a portion of the string, I referred to a VIM
1590reference card and discovered a command answering my need exactly. The s
1591command is used to subsitute a certain number of characters. In my example
1592file above, if I only needed to subsititute the characters foo_bar, I set
1593the cursor on the first character where I'd like the subsitution to begin
1594and type 7s. VIM drops the characters foo_bar and goes to insert mode,
1595waiting for the substitution text.
1596
1597Substitute Lines ----------------------- After years of using vi and VIM and
1598always deleting multiple lines in order to replace them, I just discovered
1599the S command. If you need to subsitute three lines of text, simply type
16003S. VIM drops the three lines and goes into insert mode, waiting for the
1601subsitution text.
1602
1603</pre></tip> </html> <Tip category="KVim"> <html><center>letting
1604variable values be overwritten in a script</center> <pre> <A
1605HREF="http://vim.sf.net/tip_view.php?tip_id=82">http://vim.sf.net/tip_view.php?tip_id=82</A><BR>
1606
1607this is a simple function i wrote to get the value of a variable from three
1608different places (in that order): the current buffer, the global setting
1609or from the script itself.
1610
1611this allows me to set a default value for a configuration variable inside my
1612script and the user to change it on a global level by setting the same variable
1613with a g: prepended. then, they can further set it on a per-buffer level by
1614the 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
1616characters (// for java, for example) are placed the beginning of the line or
1617just before the first-non-blanks in the text. i set up a default in my script:
1618
1619let s:comments_hug_start_of_line=0 " comments should hug the text
1620
1621that's fine as a default, but if i want to overwrite it for vim scripts,
1622i just put the following in my ftplugin/vim.vim:
1623
1624let b:comments_hug_start_of_line=1 " vim comments should hug the first
1625column, 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 "
1629either, 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
1639endfunction
1640
1641personally, i never let it get to the -1 state by always having an s: set
1642with SOME default value.
1643
1644</pre></tip> </html> <Tip category="KVim"> <html><center>how
1645to indent (useful for source code)</center> <pre> <A
1646HREF="http://vim.sf.net/tip_view.php?tip_id=83">http://vim.sf.net/tip_view.php?tip_id=83</A><BR>
1647
1648Here is the most useful vim command that I know of and I'm surprised that
1649it's not yet in the tips list.
1650
1651I use the indent features of vim all the time. Basically, it lets you indent
1652your source code.
1653
1654SETUP: To make indentation work nicely I have the following in my .vimrc file:
1655set et set sw=4 set smarttab
1656
1657these make vim behave nicely when indenting, giving 4 spaces (not tabs)
1658for each "tabstop".
1659
1660HOW TO USE: in command mode, == will indent the current line selecting a range
1661of lines (with shift-v) then == will indent your selection typing a number
1662then == will indent that many lines, starting from your cursor (you get the
1663idea, there are many other things you can do to select a range of lines)
1664
1665Tell me that isn't great?
1666
1667</pre></tip> </html> <Tip category="KVim"> <html><center>Changing
1668the behaviour of . to include visual mode</center> <pre> <A
1669HREF="http://vim.sf.net/tip_view.php?tip_id=84">http://vim.sf.net/tip_view.php?tip_id=84</A><BR>
1670
1671one of the things i do a lot in vim is to make a change to the beginning or
1672end of the line (such as adding the text '// remove' at the end of java
1673debug code). a quick way of doing this is to use a to append the text to
1674the end of the first line and then move down one, hit . (repeat last edit),
1675move down, hit . etc. etc. the following mapping allows one to simply
1676highlight the region in question and hit . -- it will automatically
1677execute 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
1682another thing i do a lot is to record a quick macro in the "a" register
1683and then play it back a number of times. while @@ can be used to repeat the
1684last register used, my recorded macros sometimes use other registers so @@
1685doesn't necessarily give me the same results as @a. also, i have mapped '
1686to ` because i like to go to the precise location of my marks -- always --
1687and 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
1691then, in keeping with the visual . above, i did the same for the ` -- is
1692thexecutes @a once on each highlighed line.
1693
1694 vnoremap ` :normal @a&lt;CR&gt;
1695
1696as 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
1700and, for some reason, i need to get the following:
1701
1702 "asdf" "lkhj" "hjkhjkh"
1703
1704i record the following into a:
1705
1706 ^cf_"&lt;ESC&gt;$r"
1707
1708the ^ is because my java code is indented and i don't want to go to
1709column 0 and the &lt;esc&gt; is an actual escape i hit to exit insert mode.
1710
1711then, i simply select (visually) the other lines (only two in case --
1712admittedly not an overly useful example) and just hit `.
1713
1714</pre></tip> </html> <Tip category="KVim"> <html><center>How to mimic
1715the vim 6.0 plugin feature with older versions</center> <pre> <A
1716HREF="http://vim.sf.net/tip_view.php?tip_id=85">http://vim.sf.net/tip_view.php?tip_id=85</A><BR>
1717
1718If you do not have vim 6.0, but would like to mimic the plugins directory
1719feature then copy and paste this into your vimrc:
1720
1721exec "source " . substitute(glob($VIM."/plugins/*.vim"), "\n", "\nsource ",
1722"g")
1723
1724It will automatically source every vim script file located in the vim/plugins
1725directory. Now, to add a new plugin, just drop the script in this directory
1726and vim will automatically find it.
1727
1728</pre></tip> </html> <Tip category="KVim"> <html><center>Helps
1729undo 1 line when entered many</center> <pre> <A
1730HREF="http://vim.sf.net/tip_view.php?tip_id=86">http://vim.sf.net/tip_view.php?tip_id=86</A><BR>
1731
1732When U entered text, U cannot undo only 1 line, for example, when U press
1733"u", all entered in last "insert" text removed.
1734
1735If U add this line to .vimrc: inoremap &lt;Return&gt; &lt;Return&gt;^O^[
1736where "^O" or "^[" is 1 char "u" will undo (remove) only 1 line.
1737
1738</pre></tip> </html> <Tip category="KVim"> <html><center>Get
1739vim 5.x window in vim 6.x</center> <pre> <A
1740HREF="http://vim.sf.net/tip_view.php?tip_id=87">http://vim.sf.net/tip_view.php?tip_id=87</A><BR>
1741
1742The format of the window title in vim 5.x (well, at least for 5.7,.8, for
1743Win32) used to be VIM - &lt;full filename with path&gt;. It's not in the
1744win32 binary of 6.0an that I found. I want my old way back.
1745
1746Turns 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
1748to vim 5.x style
1749
1750Oh, however, one thing I did like about the 6.0 style is that it puts the
1751word "help" in the title when the current buffer is a help file; so, I just
1752tacked %h to my titlestring giving:
1753
1754:set title titlestring=VIM\ -\ %F\ %h "make sure that the window caption
1755setting is turned on and set caption to vim 5.x style
1756
1757see also: :he 'titlestring' :he 'statusline' "for the format for titlestring
1758
1759</pre></tip> </html> <Tip category="KVim"> <html><center>How
1760to maximize vim on entry (win32)</center> <pre> <A
1761HREF="http://vim.sf.net/tip_view.php?tip_id=88">http://vim.sf.net/tip_view.php?tip_id=88</A><BR>
1762
1763Maybe it's just because I have far too small of a monitor, because I can
1764get distracted while coding if I have other stuff on the screen, or because I
1765starting using vim on a console, but I definitely like my vim window maximized.
1766Anyway, sticking the following in your vimrc will always maximize your vim
1767window on startup.
1768
1769au GUIEnter * simalt ~x
1770
1771:he win16-maximized
1772
1773</pre></tip> </html> <Tip category="KVim"> <html><center>Get more
1774screen real estate by hidding toolbar and/or menus</center> <pre> <A
1775HREF="http://vim.sf.net/tip_view.php?tip_id=89">http://vim.sf.net/tip_view.php?tip_id=89</A><BR>
1776
1777I use gvim over console vim because gvim is much more readable (under Windows).
1778However, that doesn't mean I want to dedicate screen space to things I'll
1779never use (i.e. the toolbar and the menus).
1780
1781Anyway, you can give the following a try if you'd like.
1782
1783set guioptions-=T "get rid of toolbar set guioptions-=m "get rid of menu
1784
1785Oh, yeah. If you decide that you don't really like being without your the
1786toolbar or menus, issue the following:
1787
1788set guioptions+=T "bring back toolbar set guioptions+=m "bring back menu
1789
1790see also: :he 'guioptions
1791
1792</pre></tip> </html> <Tip category="KVim">
1793<html><center>Encryption</center> <pre> <A
1794HREF="http://vim.sf.net/tip_view.php?tip_id=90">http://vim.sf.net/tip_view.php?tip_id=90</A><BR>
1795
1796You can encrypt your texts by using vim. :X prompts for an encryption key.
1797After writing your key, if you save your document it will be encrypted
1798and no one else (but you and vim) can read your documents. If you reopen
1799the file, VIM will ask for the key. If you want to disable encryption,
1800just type :set key= if you forget your key you will lose your document.
1801So please DO NOT forget your key,
1802
1803
1804</pre></tip> </html> <Tip category="KVim">
1805<html><center>Dictionary completions</center> <pre> <A
1806HREF="http://vim.sf.net/tip_view.php?tip_id=91">http://vim.sf.net/tip_view.php?tip_id=91</A><BR>
1807
1808This tip will will explain how to use the dictionary completion facilities
1809provided by vim. This can be useful if you use vim to type your email,
1810edit code, etc.
1811
1812Dictionary completion is one of many search facilites provided by Insert mode
1813completion. It allows the user to get a list of keywords, based off of the
1814current 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
1816the spelling.
1817
1818To start, we must first tell vim where our dictionary is located. This is done
1819via the 'dictionary' option. Below is an example. Your location may vary.
1820See :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
1825Now, to use this list we have to enter insert mode completion. This is done
1826by hitting CTRL-X while in insert mode. Next, you have to specify what you
1827want to complete. For dictionaries use CTRL-K. Once in this mode the keys
1828CTRL-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
1833It can be cumbersome to type CTRL-X CTRL-K for many different completions.
1834So, vim gives us a shortcut. While in insert mode CTRL-N and CTRL-P
1835will cycle through a predetermined set of completion sources. By default,
1836dictionary 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
1841Now, 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
1845This shortcut may not save a whole lot of typing. However, I find that it
1846requires less hand movement to only worry myself with two key combinations,
1847rather than 4.
1848
1849I find that the completion facilites provided by vim save me a *HUGE* amount
1850of typing. These savings can be realized in only a short amount of time if
1851you are editing some code with functions and variables that have long names
1852with underscores in them.
1853
1854For 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
1860HREF="http://vim.sf.net/tip_view.php?tip_id=92">http://vim.sf.net/tip_view.php?tip_id=92</A><BR>
1861
1862As everyone knows, the $VIMRUNTIME/doc is increasing rapidly in size. The
1863directory contained so many plain-text documents that I often compress
1864them to save my diskspace. With the support of VIM's GZIP plugin,
1865VIM will automatically uncompress the files when we need to read them.
1866Here is my procedure: 1. If you have the source, go to 'runtime/doc'
1867and edit 'doctags.c', change printf("%s\t%s\t/*", p1, argv[0]); to
1868printf("%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.
18712. 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
18743. Copy the new 'tags' to $VIMRNUTIME/doc and run 'gzip *.txt; gunzip help.txt'
1875
1876On VIM 6.0an, we can reduce the original size (3302k) to 1326k. I don't
1877know if this helps, but if someone likes to compress documents... this can
1878be 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
1883HREF="http://vim.sf.net/tip_view.php?tip_id=93">http://vim.sf.net/tip_view.php?tip_id=93</A><BR>
1884
1885It is very convenient to use 'hlsearch' option. However it can be annoying
1886to have the highlight stick longer than you want it. In order to run it
1887off you have to type at least 4 keystrokes, ":noh". So, it's a good idea
1888to map this to a key. I like to map it to control-n. This is the line I
1889use in my .vimrc file to do it:
1890
1891nmap &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
1895HREF="http://vim.sf.net/tip_view.php?tip_id=94">http://vim.sf.net/tip_view.php?tip_id=94</A><BR>
1896
1897Using tags file with Vim ------------------------ This document gives you
1898a idea about the various facilities available in Vim for using a tags file
1899to browse through program source files. You can read the Vim online help,
1900which explains in detail the tags support, using :help tagsearch.txt. You can
1901also use the help keywords mentioned in this document to read more about a
1902particular command or option. To read more about a particular command or
1903option use, :help &lt;helpkeyword&gt; in Vim.
1904
19051. 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
19122. 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
19643. 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
19814. 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
19895. 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
19966. 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
20117. 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
20398. 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
20509. 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
205710. 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
206411. 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
209112. 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
211513. 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
213114. 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
215015. 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
216616. 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
217317. 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
219718. 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
222019. Is it possible to highlight all the tags in the current file?
2221
2222 Yes. Read the Vim online help on "tag-highlight".
2223
222420. 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
223421. 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
2250the output from ex commands into the text buffer?</center> <pre> <A
2251HREF="http://vim.sf.net/tip_view.php?tip_id=95">http://vim.sf.net/tip_view.php?tip_id=95</A><BR>
2252
2253This 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
2255many times for different reasons and could never find a way!
2256
2257I would just love to be able to do :hi --&gt; textBuffer and examine the output
2258at my own leasure scrolling up and down and using vim search commands on it.
2259Same thing for :set all, and other things. Considering that cut and paste
2260is horrible in windows, I can't for example do :set guioptions? then cut
2261and paste! So I have to retype it, or cut and paste from the help manual.
2262I really want to be able to pipe the output of ex commands into the text
2263buffer. Can someone help me?
2264
2265</pre></tip> </html> <Tip category="KVim"> <html><center>Cooperation
2266of Gvim and AutoCad [MTEXT]</center> <pre> <A
2267HREF="http://vim.sf.net/tip_view.php?tip_id=96">http://vim.sf.net/tip_view.php?tip_id=96</A><BR>
2268
2269You can - like me :o) - use gvim, like replacement of internal AutoCad
2270MTEXT editor. You need switch variable MTEXTED to "gvim" (or maybe fullpath,
2271something like "c:\vim\vim60aq\gvim" ), and to your _vimrc you can put line:
2272
2273autocmd BufRead,BufNewFile *.tmp source c:\vim\aacad.vim
2274
2275And 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
2279accustomed vith gvim) or start gvim from gvim.lnk or gvim.bat (I'am using
2280windows95) and automatic skip to INSERT mode -latest word star, on end of
2281script- is without functionality(?) Maybe someone advise me?? ]
2282
2283Well, script aacad.vim is listed here:
2284
2285"VIM menu for AutoCad's MTEXT editation "brz;
2286mailto:brz@centrum.cz; 8. 8. 2001 " Version Mk.I
2287"--------------------------------------------------------------------------
2288
2289imenu &AutoCad.Insert.Space \~ vmenu &AutoCad.Insert.Space
2290&lt;Esc&gt;`&lt;i\~&lt;Esc&gt;% imenu &AutoCad.Insert.Backslash \\
2291vmenu &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
2297imenu &AutoCad.-SEP1- :
2298
2299imenu &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;%
2305imenu &AutoCad.Colour.Cyan \C4; vmenu &AutoCad.Colour.Cyan
2306&lt;Esc&gt;`&gt;a\C7;&lt;Esc&gt;`&lt;i\C4;&lt;Esc&gt;%
2307imenu &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;%
2311imenu &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
2318imenu &AutoCad.Font.Arial \fArial; vmenu &AutoCad.Font.Arial
2319&lt;Esc&gt;`&lt;i\fArial;&lt;Esc&gt;% imenu &AutoCad.Font.Symbol \Fsymbol;
2320vmenu &AutoCad.Font.Symbol &lt;Esc&gt;`&lt;i\Fsymbol;&lt;Esc&gt;%
2321imenu &AutoCad.Font.RomanC \Fromanc; imenu &AutoCad.Font.RomanC
2322&lt;Esc&gt;`&lt;i\Fromanc;&lt;Esc&gt;% imenu &AutoCad.Font.RomanS \Fromans;
2323vmenu &AutoCad.Font.RomanS &lt;Esc&gt;`&lt;i\Fromans;&lt;Esc&gt;%
2324imenu &AutoCad.Font.RomanD \Fromand; vmenu &AutoCad.Font.RomanD
2325&lt;Esc&gt;`&lt;i\Fromand;&lt;Esc&gt;% imenu &AutoCad.Font.RomanT \Fromant;
2326vmenu &AutoCad.Font.RomanT &lt;Esc&gt;`&lt;i\Fromant;&lt;Esc&gt;%
2327
2328imenu &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;%
2332imenu &AutoCad.Size.3x \H3x; vmenu &AutoCad.Size.3x
2333&lt;Esc&gt;`&lt;i\H3x;&lt;Esc&gt;%
2334
2335imenu &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
2340imenu &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
2348imenu &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
2354imenu &AutoCad.Effects.-SEP5- : imenu &AutoCad.Effects.Justify_Down \A0;
2355vmenu &AutoCad.Effects.Justify_Down &lt;Esc&gt;`&lt;i\A0;&lt;Esc&gt;%
2356imenu &AutoCad.Effects.Justify_Middle \A1; vmenu
2357&AutoCad.Effects.Justify_Middle &lt;Esc&gt;`&lt;i\A1;&lt;Esc&gt;%
2358imenu &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
2363vmenu &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
2367imenu &AutoCad.-SEP6- : imenu &AutoCad.Help &lt;CR&gt;&lt;CR&gt;***Quit
2368Editor: press Alt-F4 and 'No' ***&lt;CR&gt;&lt;CR&gt;
2369
2370star
2371
2372</pre></tip> </html> <Tip category="KVim"> <html><center>How
2373do I add a current time string inside Vim?</center> <pre> <A
2374HREF="http://vim.sf.net/tip_view.php?tip_id=97">http://vim.sf.net/tip_view.php?tip_id=97</A><BR>
2375
2376This is a *request* for a tip. Sometimes (eg. editing HTML pages) I need
2377to add a timestamp string to my editing buffer. On UNIX systems, I can use
2378 :r!date
2379to get a localized date time string; but on Windows ('date' on Windows will
2380query 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
2384vim help from mailing lists and newsgroups.</center> <pre> <A
2385HREF="http://vim.sf.net/tip_view.php?tip_id=98">http://vim.sf.net/tip_view.php?tip_id=98</A><BR>
2386
2387There have been a few "requests for tips" entered into the tips database
2388lately. If you have specific questions that aren't answered by the existing
2389tips, there are a couple of resources that may be more appropriate:
2390
2391The mailing list vim@vim.org is for vim users. If you send an email
2392to vim-help@vim.org, you'll get a message back telling you how
2393to subscribe, as well as how to request old messages and contact
2394the list maintainer. This mailing list is also archived at <A
2395HREF="http://groups.yahoo.com/group/vim.">http://groups.yahoo.com/group/vim.</A><BR>
2396
2397The newsgroup comp.editors discusses many different editors, but most of
2398the 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
2400HREF="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
2402Using the tips database for asking questions is not likely to work well.
2403For example, if you ask a question titled "Searching for strings in a file"
2404and I read this site and see that tip, I'm not going to read it if I already
2405know how to search for strings in a file. In comp.editors and vim@vim.org,
2406people expect to find questions from others and are therefore more likely
2407to see your questions.
2408
2409After finding the answer to your question, please consider whether it would
2410make an appropriate tip, and if so, add it to the tips database.
2411
2412</pre></tip> </html> <Tip category="KVim"> <html><center>How to
2413tell what syntax highlighting group *that* is!</center> <pre> <A
2414HREF="http://vim.sf.net/tip_view.php?tip_id=99">http://vim.sf.net/tip_view.php?tip_id=99</A><BR>
2415
2416Here's a (what should be a one-line) map to help you tell just what syntax
2417highlighting groups the item under the cursor actually is:
2418
2419map &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
2424Once known you can override the current highlighting with whatever you want.
2425If you're debugging a syntax highlighting file (a rare occupation), sometimes
2426you'll wish to know the entire chain of syntax highlighting. For that,
2427check out
2428
2429<A
2430HREF="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
2433tag (e.g. help topic) with German keyboard (PC)</center> <pre> <A
2434HREF="http://vim.sf.net/tip_view.php?tip_id=100">http://vim.sf.net/tip_view.php?tip_id=100</A><BR>
2435
2436You'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
2439CTRL-]."
2440
2441Unfortunately 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
2444Kind regards
2445
2446</pre></tip> </html> <Tip category="KVim"> <html><center>Change automatically
2447to the directory the file in the current buffer is in</center> <pre> <A
2448HREF="http://vim.sf.net/tip_view.php?tip_id=101">http://vim.sf.net/tip_view.php?tip_id=101</A><BR>
2449
2450To change automatically to the directory the file in the current buffer is
2451in add a line (below) to the file .vimrc . The file .vimrc should have
2452the 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
2463Add the line above the endif and restart vim/gvim.
2464
2465</pre></tip> </html> <Tip category="KVim"> <html><center>smart
2466mapping for tab completion</center> <pre> <A
2467HREF="http://vim.sf.net/tip_view.php?tip_id=102">http://vim.sf.net/tip_view.php?tip_id=102</A><BR>
2468
2469I'm used to complete words with &lt;tab&gt;, however when editing source
2470I can't just map that to vim keyword completion because I sometime need to
2471insert real tabs, since it mostly happen when at the beginning of the line or
2472after a ; and before a one line comma (java, c++ or perl anyone...) I've come
2473to find the following really usefull This is how you can map the &lt;tab&gt;
2474key in insert mode while still being able to use it when at the start of
2475a line or when the preceding char is not a keyword character. in a script
2476file in a plugin directory or in your .vimrc file: first define a function
2477which returns a &lt;tab&gt; or a &lt;C-N&gt; depending on the context:
2478
2479function 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
2485endfunction
2486
2487then define the appropriate mapping: inoremap &lt;tab&gt;
2488&lt;c-r&gt;=InsertTabWrapper()&lt;cr&gt;
2489
2490the trick here is the use of the &lt;c-r&gt;= in insert mode to be able to
2491call your function without leaving insert mode. :help i_CTRL-R Benoit
2492
2493</pre></tip> </html> <Tip category="KVim"> <html><center>Move
2494to next/previous line with same indentation</center> <pre> <A
2495HREF="http://vim.sf.net/tip_view.php?tip_id=103">http://vim.sf.net/tip_view.php?tip_id=103</A><BR>
2496
2497When working with Python and other languages which don't use braces, it's
2498useful to be able to jump to and from lines which have the same indentation
2499as the line you are currently on.
2500
2501nn &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
2505will map Alt-&lt; and Alt-&gt; in Normal mode to upward and downward searching
2506for lines with the same indent as the current line.
2507
2508</pre></tip> </html> <Tip category="KVim"> <html><center>using
2509vim to complement Perl's DBI::Shell</center> <pre> <A
2510HREF="http://vim.sf.net/tip_view.php?tip_id=104">http://vim.sf.net/tip_view.php?tip_id=104</A><BR>
2511
2512DBI::Shell is a Perl module that is used as a shell interface to Perl's
2513popular DBI (database interface) package. Forget your favorite SQL navigation
2514gui and give this method a shot. This has only been tested in UNIX.
2515
25161. run dbish (runs DBI::Shell; installed with DBI::Shell) and connect to any
2517database 2. in dbish, set /format box 3. enter your query 4. to execute query,
2518type "/ | vim -"
2519
2520This runs the query and pipes the output to the standard input of vim. Here
2521are some follow-up tips: -use gvim instead of vim so a new window will pop
2522up -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
2528HREF="http://vim.sf.net/tip_view.php?tip_id=105">http://vim.sf.net/tip_view.php?tip_id=105</A><BR>
2529
2530I sometimes found myself moving down a few lines with j, then scrolling
2531down about the same number of lines with &lt;C-E&gt; to put the cursor in
2532roughly 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
2537This was pretty good, but behaved funny at the beginning and end of files.
2538Then, I realized that &lt;C-D&gt; already combined move and scroll, so I
2539figured 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
2543Unfortunately, this permanently attaches a count to &lt;C-D&gt; (ugh!),
2544so I have to undo that:
2545
2546 :map &lt;C-J&gt; 1&lt;C-D&gt;:set scroll=0&lt;CR&gt;
2547
2548This has the drawback of not necessarily resetting scroll to its original
2549value, but since I never change scroll, it's good enough for me. It would be
2550nice if there were a version of &lt;C-D&gt; that did not have the side-affect
2551of changing scroll.
2552
2553Happy vimming, Andrew
2554
2555</pre></tip> </html> <Tip category="KVim">
2556<html><center>Supersimple one-line solution</center> <pre> <A
2557HREF="http://vim.sf.net/tip_view.php?tip_id=106">http://vim.sf.net/tip_view.php?tip_id=106</A><BR>
2558
2559Hallo, next solution for _most_simple_ signature rotater: You can
2560only put one line to your .vimrc || _vimrc: map &lt;Leader&gt;ms :e
2561c:\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
2563Must exist file (from eg above) c:\sign.txt, with content: -- first signature
2564-- second signature -- third signature --
2565
2566When You finished mail, only call shortcut \ms and 'first signature' will
2567be insert in your mail. In c:\sign.txt will be first signature pushed
2568to 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. )
2570You can change this and append one part like 'basic' from command and
2571append 'changing' part from .signature file, as you like... Ok, one
2572unpleasant thing is here: your signature must not contain '--' (signature
2573separator)... Anyhow, I find it useful brz* &lt;brz@centrum.cz&gt; <A
2574HREF="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
2578HREF="http://vim.sf.net/tip_view.php?tip_id=107">http://vim.sf.net/tip_view.php?tip_id=107</A><BR>
2579
2580When testing your own C/C++ programs you sometimes wish to have a trace output,
2581which shows you, which enum value is used. You can do this by creating
2582a string table for that enum type, which contains the enum identifyer as
2583a string. e.g. printf ("%s", MyEnumStringTable [ MyEnumVal] );
2584
2585You can create the complete string table by - marking the lines containing
2586the complete typedef enum - select menu C/C++.transform enum2Stringtab
2587
2588You can create string table entries by - marking the lines within the typedef
2589enum - select menu C/C++.transform enum2String
2590
2591This makes it easy to keep the enum (on changes) consistent to the string
2592table.
2593
2594Add the following lines to your _GVIMRC file: 31amenu C/C++.transform\
2595enum2Stringtab :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
2599const char* const Names[] = {&lt;ESC&gt;&lt;CR&gt;/sdfsdf&lt;CR&gt;
2600
260131amenu C/C++.transform\ enum2String :s#[ ]*\\(\\w\\+\\)#/*
2602\\1 */ "\\1"#&lt;CR&gt;o}&lt;ESC&gt;/sdfsdf&lt;CR&gt; 31vmenu
2603C/C++.transform\ enum2String :s#[ ]*\\(\\w\\+\\)#/* \\1 */
2604"\\1"#&lt;CR&gt;o}&lt;ESC&gt;/sdfsdf&lt;CR&gt;
2605
2606hint: '/sdfsdf' is added for deactivating search highlighting, ok, you'll
2607sure find a better way to do this.
2608
2609</pre></tip> </html> <Tip category="KVim"> <html><center>Toggle
2610a fold with a single keystroke</center> <pre> <A
2611HREF="http://vim.sf.net/tip_view.php?tip_id=108">http://vim.sf.net/tip_view.php?tip_id=108</A><BR>
2612
2613When viewing/editing a folded file, it is often needed to inspect/close
2614some 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
2618current line, just moves forward. " If it is present, reverse it's state.
2619fun! 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
2629endfun
2630
2631" Map this function to Space key. noremap &lt;space&gt; :call
2632ToggleFold()&lt;CR&gt;
2633
2634See :help folding for more information about folding.
2635
2636</pre></tip> </html> <Tip category="KVim">
2637<html><center>jump between files</center> <pre> <A
2638HREF="http://vim.sf.net/tip_view.php?tip_id=109">http://vim.sf.net/tip_view.php?tip_id=109</A><BR>
2639
2640Often I know I'm likely to edit many files. I run 'vim *.pl' and get a whole
2641bunch of open files.
2642
2643To make jumping between files to a pleasure, I defined to mapss:
2644
2645map &lt;f1&gt; :previous&lt;cr&gt; map &lt;f2&gt; :next&lt;cr&gt;
2646
2647Press 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
2653HREF="http://vim.sf.net/tip_view.php?tip_id=110">http://vim.sf.net/tip_view.php?tip_id=110</A><BR>
2654
2655Below are two functions and a mapping which will convert lines of plain
2656text into HTML table code. For example, you have several lines like:
2657----------------------------------------------- 1 2 3
2658
26594 5 6 --------------------------------------------------- by visualizing
2660all 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
2666rule is: Every line is a table item, every empty line means starting of a
2667new 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
2671area. Thanks
2672
2673func 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;"
2686endfunc
2687
2688vmap &lt;F5&gt; &lt;ESC&gt;:call Table()&lt;CR&gt;
2689
2690func 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
2697endfunc
2698
2699</pre></tip> </html> <Tip category="KVim"> <html><center>Printing with
2700syntax highlighting independent of your normal highlighting</center> <pre> <A
2701HREF="http://vim.sf.net/tip_view.php?tip_id=111">http://vim.sf.net/tip_view.php?tip_id=111</A><BR>
2702
2703I have found it undesirable to use :hardcopy directly because it uses the
2704current syntax highlighting to determine how to print the text. For example,
2705I like to print comments in italics, but I don't like italic fonts on the
2706screen. This tip will show you how to set up a colorscheme for printing and
2707use it only when you print.
2708
2709I copied an existing colorscheme to ~/.vim/colors/print.vim, and changed
2710all the lines like this:
2711
2712 highlight Normal ctermbg=DarkGrey ctermfg=White guifg=White guibg=grey20
2713to this:
2714 highlight clear Normal
2715
2716Then 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
2721I then defined the following command in my .vimrc file:
2722
2723command! -nargs=* Hardcopy call DoMyPrint("&lt;args&gt;")
2724
2725And, finally, I defined this function in my .vimrc:
2726
2727function DoMyPrint(args)
2728 let colorsave=g:colors_name color print exec "hardcopy ".a:args exec
2729 'color '.colorsave
2730endfunction
2731
2732After this is complete, you can do:
2733 :Hardcopy &gt; /tmp/out.ps
2734or just
2735 :Hardcopy
2736(Note the capital H)
2737
2738</pre></tip> </html> <Tip category="KVim"> <html><center>Back
2739and forth between indented lines again</center> <pre> <A
2740HREF="http://vim.sf.net/tip_view.php?tip_id=112">http://vim.sf.net/tip_view.php?tip_id=112</A><BR>
2741
2742Paul Wright posted a tip which explained how to jump back and forth between
2743lines with the same indentation level. I do this a lot, so I came up with
2744this slightly more comprehensive solution.
2745
2746The example mappings below work as follows:
2747
2748[l and ]l jump to the previous or the next line with the same indentation
2749level as the one you're currently on.
2750
2751[L and ]L jump to the previous or the next line with an indentation level
2752lower than the line you're currently on.
2753
2754These movements also work in visual mode and (only as of one of the 6.0 alpha
2755versions) in operator pending mode, meaning that you can do a d]l. The motion
2756is specified as being exclusive when in operator pending mode.
2757
2758When might you use this? If you're writing programs in Python, Haskell,
2759or editing XML files, they will be very useful. E.g. in XML you can jump to
2760the outer enclosing tag, or the next matching tag. I use it for practically
2761anything I edit, so it's not limited to this.
2762
2763" " NextIndent() " " Jump to the next or previous line that has the same level
2764or a lower " level of indentation than the current line. " " exclusive (bool):
2765true: Motion is exclusive " false: Motion is inclusive "
2766fwd (bool): true: Go to next line " false: Go to
2767previous line " lowerlevel (bool): true: Go to line with lower indentation
2768level " false: Go to line with the same indentation level
2769" skipblanks (bool): true: Skip blank lines " false:
2770Don't skip blank lines
2771
2772function! 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
2788endfunc
2789
2790" Moving back and forth between lines of same or lower indentation.
2791nnoremap &lt;silent&gt; [l :call NextIndent(0, 0, 0, 1)&lt;cr&gt;
2792nnoremap &lt;silent&gt; ]l :call NextIndent(0, 1, 0, 1)&lt;cr&gt;
2793nnoremap &lt;silent&gt; [L :call NextIndent(0, 0, 1, 1)&lt;cr&gt;
2794nnoremap &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''
2796vnoremap &lt;silent&gt; ]l &lt;esc&gt;:call NextIndent(0, 1, 0,
27971)&lt;cr&gt;m'gv'' vnoremap &lt;silent&gt; [L &lt;esc&gt;:call NextIndent(0, 0,
27981, 1)&lt;cr&gt;m'gv'' vnoremap &lt;silent&gt; ]L &lt;esc&gt;:call NextIndent(0,
27991, 1, 1)&lt;cr&gt;m'gv'' onoremap &lt;silent&gt; [l :call NextIndent(0, 0, 0,
28001)&lt;cr&gt; onoremap &lt;silent&gt; ]l :call NextIndent(0, 1, 0, 1)&lt;cr&gt;
2801onoremap &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
2805in vim (Windows solution)</center> <pre> <A
2806HREF="http://vim.sf.net/tip_view.php?tip_id=113">http://vim.sf.net/tip_view.php?tip_id=113</A><BR>
2807
2808Hallo, today I found script "translate.vim", but on Windows this will be
2809probably difficult to run it (maybe with Cygwin is it possible). I've simpler
2810solution of keymap for vim interlacing to dictionary: Must exist file with
2811vocabulary (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
2813under cursor deleted and is insert selected form of word from translantion
2814window (select it by mouse and than press right button: It works fine on
2815W2k). 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
2817HREF="http://www.tgries.de/agrep/index.html">http://www.tgries.de/agrep/index.html</A><BR>
2818
2819map &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;
2823b"*yw&lt;Esc&gt;:! c:/bin/agrep -ih &lt;C-R&gt;* "c:/dict/an-cs.txt"&lt;CR&gt;
2824imap &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
2827brz* &lt;brz@centrum.cz&gt;
2828
2829</pre></tip> </html> <Tip category="KVim">
2830<html><center>Browsing by paragraph</center> <pre> <A
2831HREF="http://vim.sf.net/tip_view.php?tip_id=114">http://vim.sf.net/tip_view.php?tip_id=114</A><BR>
2832
2833It can be done by reaching the blank lines in up and down directions just
2834by pressing
2835
2836{ ---- For going to the blank line above the paragraph } ---- For
2837going to the blank line below the paragraph
2838
2839</pre></tip> </html> <Tip category="KVim">
2840<html><center>Browsing by paragraph</center> <pre> <A
2841HREF="http://vim.sf.net/tip_view.php?tip_id=115">http://vim.sf.net/tip_view.php?tip_id=115</A><BR>
2842
2843It can be done by reaching the blank lines in up and down directions just
2844by pressing
2845
2846{ ---- For going to the blank line above the paragraph } ---- For
2847going to the blank line below the paragraph
2848
2849</pre></tip> </html> <Tip category="KVim"> <html><center>Search all
2850occurances of the word under cursor in all the open files</center> <pre> <A
2851HREF="http://vim.sf.net/tip_view.php?tip_id=116">http://vim.sf.net/tip_view.php?tip_id=116</A><BR>
2852
2853Sometimes it is useful to know all the occurances of the word under cursor in
2854all 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
2858SEARCH ACROSS THE PROJECT</center> <pre> <A
2859HREF="http://vim.sf.net/tip_view.php?tip_id=117">http://vim.sf.net/tip_view.php?tip_id=117</A><BR>
2860
2861Searching for a word across the project wastes most of the
2862developres time, which can be avoided by the use of GNU Id_utils
2863with VIM. The procedure needs to be followed is as follows:
2864download GNU idutils 3.2d (mkid,lid,fid,fnid,xtokid) from <A
2865HREF="http://www.mossbayeng.com/~ron/vim/builds.html">http://www.mossbayeng.com/~ron/vim/builds.html</A><BR>
2866
2867uncompress and store these files in the directory from where vim is running.
2868
2869goto the top level directory of the project, and run mkid, it will create ID
2870file in that directory (As it is time consuming process, so be patient). copy
2871this file ID to the directory from where vim is running.
2872
2873USAGE:
2874
2875Put 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
2886To use it, place the cursor on a word, type "_u" and vim will load the file
2887that contains the word. Search for the next ocurance of the word in the
2888same file with "n". Go to the next file with "_n".
2889
2890The mapping of "_u" and "_n" can be done to some other key as per your
2891preference but I use ^K and ^L for this purpose.
2892
2893</pre></tip> </html> <Tip category="KVim"> <html><center>Configuring
2894gVim as Internet Explorer 'View Source' editor</center> <pre> <A
2895HREF="http://vim.sf.net/tip_view.php?tip_id=118">http://vim.sf.net/tip_view.php?tip_id=118</A><BR>
2896
2897Within the registry, you can specify the source editor to be used by Internet
2898Explorer when {View|Source} is selected. Unfortunately, you can't specify a
2899quoted filename argument here, i.e. "%1". The editor specified is supposed
2900to handle filenames which contain spaces. This will cause problems for
2901Vim because Vim treats each space as an argument separator. If an unquoted
2902filename contains spaces, Vim treats the filename as multiple arguments and
2903will open multiple files instead of one. To workaround this problem a quoted
2904filename has to be passed to Vim. This can be done by creating the following
2905Visual 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
2913option explicit
2914
2915dim oWShell, sArg, sFile
2916
2917 ' Create script object
2918set oWShell = CreateObject("wscript.shell")
2919 ' Loop through arguments
2920for each sArg in wscript.arguments
2921 ' Add argument to filename
2922 sFile = sFile & sArg & " "
2923next
2924 ' Remove excess space
2925sFile = 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.
2929oWShell.Run _
2930 """D:\Programs\Vim\Vim58\gvim.exe """ & _ "-R """ & sFile & """ " & _
2931 "-c ""set syntax=html"""
2932
2933 ' Destroy script object
2934set oWShell = NOTHING
2935
2936The source editor now can be specified by adding the following key to the
2937registry:
2938
2939HKEY_LOCAL_MACHINE |- Software
2940 |- Microsoft
2941 |- Internet Explorer
2942 |- View Source Editor
2943 |- Editor Name (Default) = D:\Programs\Vim\gvim.vbs
2944
2945Freddy Vulto &lt;fvu@fvu.myweb.nl&gt; <A
2946HREF="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
2950HREF="http://vim.sf.net/tip_view.php?tip_id=119">http://vim.sf.net/tip_view.php?tip_id=119</A><BR>
2951
2952I really like the new explorer window, but I wanted it to function a little
2953more seemlessly in the editor. The following code does two things. First,
2954the explorer is started when vim is started. I also noticed and fixed
2955that the explorers size is not equal to the window size, hence the strange
2956behavior when popping between two windows. The other major function of
2957the code is to close the explorer when it's the only window that's left.
2958I'd actually like to take this a step further and close the window if the
2959last _document_ window is closed. I'd prefer that multiple explorers or help
2960windows don't keep the application running - only having a file open keeps the
2961application running. But I didn't see an easy way to do this... anyone else?
2962
2963BTW, thank you Bram for the help figuring this out.
2964
2965Code (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
2978endfunc
2979
2980func 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
2987endfunc
2988
2989if has("autocmd")
2990 if !exists("rudyautocommands")
2991 let rudyautocommands = 1 autocmd VimEnter * call
2992 OpenFileWindow() autocmd WinEnter * call CloseIfLast()
2993
2994 endif
2995endif
2996
2997</pre></tip> </html> <Tip category="KVim"> <html><center>Compiling
2998Java with Sun JDK (javac) within VIM</center> <pre> <A
2999HREF="http://vim.sf.net/tip_view.php?tip_id=120">http://vim.sf.net/tip_view.php?tip_id=120</A><BR>
3000
3001The $VIMRUNTIME/compiler has 'jikes.vim', but there's nothing for traditional
3002Sun JDK(javac), so I tried (Only tested on Win 2000):
3003
3004" Vim Compiler File javac.vim " Compiler: Sun/IBM JDK: Javac
3005
3006if exists("current_compiler")
3007 finish
3008endif let current_compiler = "javac"
3009
3010" Javac defaults to printing output on stderr and no options can convert,
3011so we have to set 'shellpipe' setlocal shellpipe=2&gt; " 2&gt; works on Win
3012NT 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
3016vim as a syntax-highlighting pager</center> <pre> <A
3017HREF="http://vim.sf.net/tip_view.php?tip_id=121">http://vim.sf.net/tip_view.php?tip_id=121</A><BR>
3018
3019If you want to use Vim's syntax highlighting in a "more"-style pager, here's
3020one way to set it up:
3021
3022First, create a vimrc like the following -- I called mine ~/.vimrc.more
3023
3024---8&lt;---cut here---8&lt;--- " No compatibility -- necessary for mappings
3025to work. set nocompatible
3026
3027" Status line set laststatus=0 set cmdheight=1 set nomodifiable "
3028Only 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.
3032if has("terminfo")
3033 set t_Co=16 set t_Sf=[3%p1%dm set t_Sb=[4%p1%dm
3034else
3035 set t_Co=16 set t_Sf=[3%dm set t_Sb=[4%dm
3036endif " My xterms have a navy-blue background, so I need this line too.
3037set 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
3040type the following line, type *two* C-V's followed by two spaces. This "
3041is how you map the spacebar. nmap ^V &lt;C-F&gt;&lt;C-G&gt; ---8&lt;---cut
3042here---8&lt;---
3043
3044Then, to use this .vimrc, add an alias. If you're using tcsh, the syntax
3045will be something like:
3046
3047alias vmore "vim -u ~/.vimrc.more"
3048
3049Then you can type "vmore [filename]" to view a file in this "pager". Spacebar
3050will move down, 'b' will move back up, and 'q' quits. You can add mappings
3051for other keys if you want to, also.
3052
3053</pre></tip> </html> <Tip category="KVim"> <html><center>Skip
3054blank lines when folding text.</center> <pre> <A
3055HREF="http://vim.sf.net/tip_view.php?tip_id=122">http://vim.sf.net/tip_view.php?tip_id=122</A><BR>
3056
3057I love the text folding capabilities of vim. I didn't like that it would
3058display the first line of the range as the "title" for the fold. I like
3059to write my comments with the "/*" on a line by itself. So I wrote this
3060little function that will skip over anything that isn't a character, and
3061then display whatever it finds after that character.
3062
3063Just include this in your ~/.vimrc (or ~/.gvimrc):
3064
3065function 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
3071endfunction set
3072foldtext='+'.v:folddashes.substitute(GetFirstLineWithChars(),'\\\/\\\/\\\|\\*\\\|\\*\\\|{{{\\d\\=','','g')
3073set fillchars=fold: hi folded guibg=black guifg=yellow gui=bold
3074
3075And as an added bonus, for those new to text folding, add this to your .vimrc
3076file too:
3077
3078autocmd BufWinLeave *.* mkview autocmd BufWinEnter *.* silent loadview
3079
3080That way whatever folds you set won't get lost when you quit. I had that
3081happen after spending 15 minutes folding up a 3000+ line file. Happy vimming!
3082
3083</pre></tip> </html> <Tip category="KVim"> <html><center>use
3084functionality similar to the * search on multiple files</center> <pre> <A
3085HREF="http://vim.sf.net/tip_view.php?tip_id=123">http://vim.sf.net/tip_view.php?tip_id=123</A><BR>
3086
3087The use of star as in vimtip#1 and vimtip#5 is great, here is how to use
3088this type of search accross a whole directory: Just add the mappings (or
3089choose different letter combinations): map gr :grep &lt;cword&gt; *&lt;cr&gt;
3090map 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
3093mapping one will search for the word under the cursor (like g*) in any of
3094the files in the current directory mapping two will search for the word
3095under the cursor (like g*) in any of the files in the same directory as the
3096current 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
3098directory 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
3100directory as the current file
3101
3102Benoit
3103
3104</pre></tip> </html> <Tip category="KVim">
3105<html><center>Number a group of lines</center> <pre> <A
3106HREF="http://vim.sf.net/tip_view.php?tip_id=124">http://vim.sf.net/tip_view.php?tip_id=124</A><BR>
3107
3108Below is a way to number a set of lines. Here is an exaple before and
3109after snapshot:
3110
3111apple bob pear tree
3112
31131 apple 2 bob 3 pear 4 tree
3114
3115" Description: " This provides a command and a function. They both can be
3116called with or " without a range. In addition, they can be called with or
3117without " arguments. Without a range they operate on the current line. " "
3118There are two supported arguments. They are described below: " arg1 -&gt;
3119the number to start at. The default is one. This will " number
3120your selected lines sequentially. The start can be a " number,
3121., $, or, 'x (like getline). " arg2 -&gt; Text to append after numbers.
3122The default is a space. " " Examples: " To provide your functionality:
3123" :%Nlist 20 " :%call Nlist(20) " To make a list start at
31241: " :'&lt;,'&gt;Nlist " :'&lt;,'&gt;call Nlist() " To
3125number the whole buffer (with it's actual line number): " :%Nlist "
3126:%call Nlist() " To number a subset of lines with their line number (and
3127put a '] ' in " front of every number): " :'&lt;,'&gt;Nlist . ]\
3128" :'&lt;,'&gt;call Nlist(".", "] ")
3129
3130command! -nargs=* -range Nlist &lt;line1&gt;,&lt;line2&gt;call
3131Nlist(&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/'
3147endfunction
3148
3149</pre></tip> </html> <Tip category="KVim">
3150<html><center>Auto commenting for "}"</center> <pre> <A
3151HREF="http://vim.sf.net/tip_view.php?tip_id=125">http://vim.sf.net/tip_view.php?tip_id=125</A><BR>
3152
3153I always wanted a script that would auto-comment the end of a conditional
3154block. 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
3156is no previous matching "{", it inserts nothing.
3157
3158So...
3159
3160 if (test){
3161
3162will generate:
3163 } // if (test)
3164
3165This is obviously not work if you use a different style. If you use
3166
3167 if (test) {
3168
3169then substituting 'getline(".")', use 'getline(line(".") - 1)' should work.
3170
3171Put the following in your .vimrc: au BufNewFile,BufRead *.c,*.cc,*.C,*.h
3172imap } &lt;ESC&gt;:call CurlyBracket()&lt;CR&gt;a
3173
3174function 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
3181endfunction
3182
3183</pre></tip> </html> <Tip category="KVim"> <html><center>how do
3184I get rid of that bold stuff with my xterm?</center> <pre> <A
3185HREF="http://vim.sf.net/tip_view.php?tip_id=126">http://vim.sf.net/tip_view.php?tip_id=126</A><BR>
3186
3187Having problems setting up your syntax highlighting because everything is
3188coming up in bold?
3189
3190You're probably using an 8 color xterm and setting up highlighting lines such
3191as hi Normal ... ctermfg=green . The solution: use numbers! 0=black, 1=red,
31922=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
3194dim text unless its been made bold).
3195
3196Read 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
3200HREF="http://vim.sf.net/tip_view.php?tip_id=127">http://vim.sf.net/tip_view.php?tip_id=127</A><BR>
3201
3202I've found while writing HTML files that it can become cumbersome when I have
3203to switch to a web browser, load my page, and move back to VIM regularly to
3204preview what I've written. I've come up with the following tricks.
3205
3206The first one requires that you have lynx (the text-based browser) installed
3207on your computer (available from <A HREF="http://lynx.isc.org/release/).
3208If your HTML page is primarily text, with few (if any) images, you can
3209set up the following function and mapping:">http://lynx.isc.org/release/).
3210If your HTML page is primarily text, with few (if any) images, you can set
3211up 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
3220This will open a new window and display your formatted HTML document in
3221that window. Note that bold-face, italics, links, etc. will be lost --
3222all you will see is the text -- but the "-underscore" parameter to Lynx
3223causes any text that would have been bold, italicized, or underlined to be
3224displayed like _this_.
3225
3226The other trick requires that vim be running on your current machine, and that
3227you be running a GUI of some sort (X-Windows, Windows, etc.). You can cause
3228vim 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;
3234If you don't use mozilla, you will need to modify the function to use your
3235preferred browser.
3236
3237Happy vimming!
3238
3239</pre></tip> </html> <Tip category="KVim"> <html><center>grep,
3240diff, patch, idutils, etc. for Windows systems</center> <pre> <A
3241HREF="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,
3245but do not feel like installing all of Cygwin, you
3246can get many of the most-used tools from Ron Aaron's web site: <A
3247HREF="http://www.mossbayeng.com/~ron/vim/builds.html">http://www.mossbayeng.com/~ron/vim/builds.html</A><BR>
3248Since Ron is a big Vim fan (see <A
3249HREF="http://www.mossbayeng.com/~ron/vim/vimrant.html ) you can count
3250on">http://www.mossbayeng.com/~ron/vim/vimrant.html ) you can count on</A><BR>
3251these tools' working well with Vim. For some hints on how to use them,
3252read :help :grep :help lid inside Vim.
3253 Happy Vimming!
3254
3255</pre></tip> </html> <Tip category="KVim"> <html><center>Removing
3256automatic comment leaders</center> <pre> <A
3257HREF="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
3261automatically when you start a new line in a comment. For example, in TeX
3262the "%" 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
3265were generated automatically. % This is the last line of the comment,
3266but Vim will insert the comment leader on the next line. %
3267
3268You can get rid of the comment leader (along with anything you may already
3269have 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)
3274or "&lt;C-T&gt;" (to increase it). In the docs for Vim 6.0, this is described
3275in the users' manual, :help 30.4 .
3276
3277</pre></tip> </html> <Tip category="KVim">
3278<html><center>disabling default ftplugins</center> <pre> <A
3279HREF="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
3285If you want to disable all ftplugins, or disable a particular default
3286ftplugin, see
3287
3288:help :filetype :help ftplugin-overrule
3289
3290If you have your own ftplugins, and you want to disable all the default
3291ones, then do NOT include a check for b:did_ftplugin in your ftplugin files,
3292and add the line
3293
3294:autocmd BufEnter * let b:did_ftplugin = 1
3295
3296to 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
3300HREF="http://vim.sf.net/tip_view.php?tip_id=131">http://vim.sf.net/tip_view.php?tip_id=131</A><BR>
3301
3302This mapping allow you to quickly scroll inactive window when displaying
3303several windows concurrently.
3304
3305nmap &lt;silent&gt; &lt;M-Down&gt; :call ScrollOtherWindow("down")&lt;CR&gt;
3306nmap &lt;silent&gt; &lt;M-Up&gt; :call ScrollOtherWindow("up")&lt;CR&gt;
3307
3308fun! 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"
3314endfun
3315
3316PS: Original idea and discussion of this tip appeared on vim@vim.org mailing
3317list, I'm just prettified it a little.
3318
3319</pre></tip> </html> <Tip category="KVim">
3320<html><center>window zooming convenience</center> <pre> <A
3321HREF="http://vim.sf.net/tip_view.php?tip_id=132">http://vim.sf.net/tip_view.php?tip_id=132</A><BR>
3322
3323i frequently have multiple windows open in vim -- this reduces the number
3324of lines each window displays -- i almost always have my windows either all
3325the same size or the current one as big as possible.
3326
3327the 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
3329something else if you prefer.
3330
3331this causes the current window to be as big as possible (moving into another
3332window causes that one to become big) and all the others get very small.
3333i actually use this ALL the time. turning it off (by typing the hotkey
3334sequence again) will cause all windows to have the same height.
3335
3336"toggles whether or not the current window is automatically zoomed
3337function! 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
3346endfunction 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
3350HREF="http://vim.sf.net/tip_view.php?tip_id=133">http://vim.sf.net/tip_view.php?tip_id=133</A><BR>
3351
3352i like bufdo and windo but i don't like the fact that the commands end in
3353a different window/buffer than from where i executed them. these versions
3354(starts with a capital letter) will restore the current window or buffer
3355when the command's done.
3356
3357for 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
3359where i started.
3360
3361" just like windo but restores the current window when it's done
3362function! WinDo(command)
3363 let currwin=winnr() execute 'windo ' . a:command execute currwin . 'wincmd w'
3364endfunction 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
3367function! BufDo(command)
3368 let currBuff=bufnr("%") execute 'bufdo ' . a:command execute 'buffer '
3369 . currBuff
3370endfunction 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
3374HREF="http://vim.sf.net/tip_view.php?tip_id=134">http://vim.sf.net/tip_view.php?tip_id=134</A><BR>
3375
3376You can change the "View Source" editor of IE6 by adding the following to
3377the Windows Registry. Change the path in case you installed VIM in another
3378location.
3379
3380[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source
3381Editor\Editor Name] @="C:\\vim\\vim60\\gvim.exe"
3382
3383</pre></tip> </html> <Tip category="KVim">
3384<html><center>Vim buffer FAQ</center> <pre> <A
3385HREF="http://vim.sf.net/tip_view.php?tip_id=135">http://vim.sf.net/tip_view.php?tip_id=135</A><BR>
3386
3387Vim provides various commands and options to support editing multiple buffers.
3388This document covers some of the questions asked about using multiple buffers
3389with 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
3391this document to read more about a particular command or option. To read more
3392about a particular command or option use, ":help &lt;helpkeyword&gt;" in Vim.
3393
33941. 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
34012. 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
34093. 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
34144. 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
34255. 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
34346. 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
34527. 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
34708. 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
34809. 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
349710. 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
352111. 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
352712. 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
353413. 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
354114. 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
355015. 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
355716. 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
356617. 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
357118. 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
357919. 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
358920. 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
359921. 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
360522. 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
361823. 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
362224. 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
363025. 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
364226. 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
365427. 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
366228. 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
367929. 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
369230. 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
370331. 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
371232. 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
3722Alt, Ctrl and Caps in Win2k</center> <pre> <A
3723HREF="http://vim.sf.net/tip_view.php?tip_id=136">http://vim.sf.net/tip_view.php?tip_id=136</A><BR>
3724
3725Since I installed Win2K on my laptop, I had been unable to locate a utilitie
3726that would simply enable me to remap my Crtl Alt and Caps the way I think they
3727should be and the way they were until MS kill all competition in computing,
3728that is Crtl on the left of the letter A, Alt to the left bottom of the
3729letter Z and Caps approximately until the C.
3730
3731After some research, I came across a tip posted here by juano@mindspring.com. I
3732tried to make sense of it and then downloaded the MS scan keys map at the
3733URL he mentionned.
3734
3735Extrapolating his tip, I wrote this ASCI file that I named keys2000.reg :
3736
3737Regedit4 [HKey_Local_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard
3738Layout] "Scancode
3739Map"=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
3741Once you have saved this file, left click on it from Explorer and answer
3742yes to the prompt "do you want to enter this into the registry".
3743
3744Reboot and you are done.
3745
3746A few explanations :04 stands for 3 remappings (Caps lock to Control, Control
3747to 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
3749remaps Caps to Left Alt, 38,00,1D remaps Left Alt to Left Ctrl and 1D,00,3A
3750remaps Left Ctrl to Caps Lock since 3A=Caps, 1D=Left Ctrl and 38=Left Alt.
3751
3752Based on Juano tip and on this one, I believe a lot of remapping can be done
3753as long as you keep the separators 00 and remember to add one to the number
3754of remappings. What I do not know is how far you can extend this instruction
3755without getting into trouble with the registry. At worst, if you keyboard does
3756not behave as expected, go into the registry and delete this instruction (be
3757careful here since it is easy to confuse this instruction with the Keyboard
3758LayoutS (S for emphasis) which must not be deleted.
3759
3760Again, thanks to Juano@mindspring.com who got me going and suggested I
3761post my tip. Took me some time to retrieve the VIM Url but fortunately,
3762I had printed his tip.
3763
3764Regards
3765
3766</pre></tip> </html> <Tip category="KVim">
3767<html><center>automatically wrap left and right</center> <pre> <A
3768HREF="http://vim.sf.net/tip_view.php?tip_id=137">http://vim.sf.net/tip_view.php?tip_id=137</A><BR>
3769
3770I hate it when I hit left (or h) and my screen flickers. I want it to go up
3771to the next line. Ditto fir right (or l). Below are two functions / mappings
3772to help with that. I'm pretty sure that if you remove the &lt;silent&gt;,
3773then it will work in 5.x...
3774
3775nnoremap &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
3778nnoremap &lt;silent&gt; h :call WrapLeft()&lt;cr&gt; nnoremap
3779&lt;silent&gt; l :call WrapRight()&lt;cr&gt;
3780
3781function! 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
3791endfunction
3792
3793function! 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
3805endfunction
3806
3807</pre></tip> </html> <Tip category="KVim">
3808<html><center>Getting name of the function</center> <pre> <A
3809HREF="http://vim.sf.net/tip_view.php?tip_id=138">http://vim.sf.net/tip_view.php?tip_id=138</A><BR>
3810
3811Hi All,
3812
3813While browsing code one always needs to know which function you are currently
3814looking. Getting the name is very painful when the functions are lengthy
3815and you are currently browsing NOT near to the start of the function. You
3816can get the function's name by using this simple mapping.
3817
3818Just place this in your .vimrc.
3819
3820map _F ma[[k"xyy`a:echo @x&lt;CR&gt;
3821
3822now _F will display which function you are currently in.
3823
3824Enjoy the power of Vim -Nitin Raut
3825
3826PS: The working is as follows, mark the current line with a, jump to the
3827previous '{' in the first column, go one line up, yank the line in register
3828x, return to the mark a, echo the value of register x, which is the wanted
3829function name.
3830
3831</pre></tip> </html> <Tip category="KVim"> <html><center>=,
3832LaTeX tables, declarations, etc</center> <pre> <A
3833HREF="http://vim.sf.net/tip_view.php?tip_id=139">http://vim.sf.net/tip_view.php?tip_id=139</A><BR>
3834
3835Check out
3836
3837<A
3838HREF="http://www.erols.com/astronaut/vim/textab.html">http://www.erols.com/astronaut/vim/textab.html</A><BR>
3839
3840and see some examples of text alignment (its hopeless to do it here with
3841proportional fonts). You'll be able to download textab source, a Windows-based
3842textab executable, and a scriptfile containing a convenient interface
3843(ttalign.vim). The textab program coupled with &lt;ttalign.vim&gt; lets you:
3844
38451. align C language statements on their = += -= /= etc symbols 2. align C
3846language declararations: separate columns for types, *[, variable
3847 names, initializations (=), and comments (// or /* .. */)
38483. align C/C++ language comments (//, /* .. */) 4. align C/C++ language
3849(ansi) function argument lists 5. align LaTeX tables on their && separators
38506. align HTML tables with &lt;/TD&gt;&lt;TD&gt; separators 7. align on
3851several characters: &lt; ? : | @ ; (or modify them to handle whatever
3852 alignment characters you want)
3853
3854</pre></tip> </html> <Tip category="KVim"> <html><center>tip
3855using embedded perl interpreter</center> <pre> <A
3856HREF="http://vim.sf.net/tip_view.php?tip_id=140">http://vim.sf.net/tip_view.php?tip_id=140</A><BR>
3857
3858When 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
3860language (especially fast compared to vim scripts) there are some gotchas.
3861
3862First: never embed complex perl command in the body of a vim function this
3863will be recompiled and evaled each time for a tremendous loss of time.instead
3864to it like this
3865
3866perl &lt;&lt; EOF sub mySub {
3867 #some usefull perl stuff
3868} EOF
3869
3870function! MyFunction perl mySub "an argument", "another" endfunction
3871
3872to pass computed argument to your perl sub use the vim exec command
3873function! MyFunction exec "perl mySub " . aLocalVar . ", " b:aBufferLocalVar
3874endfunction
3875
3876It may be very hard to debug your perl sub since the output of the perl
3877compiler is somehow lost in the middle of nowhere and the debugger is not
3878available. When a compilation error occurs in your sub definition you'll get
3879an error message when you try to call it saying that the sub does not exists.
3880One thing which I have found very usefull is to write a fake VIM module with
3881stub methods which will allow you to use the command line perl interpretor
3882to at least compile your program. You could make your stub smart enough to
3883fake a vim and use the debugger. Here is a sample for such a fake module
3884defining just those method which I was using.
3885
3886package 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
3911Then you can copy other your perl code in a separate file and add a use VIM;
3912at the top and your set to debug.
3913
3914Good Vimming good perling. Benoit PS: this tips are probably true for other
3915scripting languages
3916
3917</pre></tip> </html> <Tip category="KVim"> <html><center>Add
3918your function heading with a keystroke</center> <pre> <A
3919HREF="http://vim.sf.net/tip_view.php?tip_id=141">http://vim.sf.net/tip_view.php?tip_id=141</A><BR>
3920
3921Below is a tip that the C/C++ Newbies may find interesting and handy to use.
3922The following code will add a function heading and position your cursor just
3923after Description so that one can document as one proceeds with code.
3924
3925function 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
3932endfunction
3933
3934imap &lt;F4&gt; &lt;esc&gt;mz:execute FileHeading()&lt;RET&gt;`zjA
3935
3936Where &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
3939function end commenting for C++ and Java</center> <pre> <A
3940HREF="http://vim.sf.net/tip_view.php?tip_id=142">http://vim.sf.net/tip_view.php?tip_id=142</A><BR>
3941
3942Some people have a habit of adding the function name as a comment to the
3943end 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
3946Use 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
3949If you now end the function with '}//', the follwoing string will be
3950automatically generated: '} //END: functionname'
3951
3952</pre></tip> </html> <Tip category="KVim"> <html><center>Use
3953of Vim folds for javadocs</center> <pre> <A
3954HREF="http://vim.sf.net/tip_view.php?tip_id=143">http://vim.sf.net/tip_view.php?tip_id=143</A><BR>
3955
3956Hi,
3957
3958The fold-method marker can be effectively use to set the folds in your
3959Java source. Define some marker and place it inside HTML comments &lt;!--
3960xx --&gt;. This way, it does not affect the Javadocs generated without the
3961necessity of a seprate comment line. e.g.
3962
3963/**
3964 * &lt;!-- zz.FOLDSTART class AbcClass --&gt; * The class description.
3965 * ... */
3966public 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
3978fmr=zz.FOLDSTART,zz.END fdl=2 fdc=2: */
3979
3980Now, 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
3983Sameer.
3984
3985</pre></tip> </html> <Tip category="KVim"> <html><center>recording
3986keystrokes by "q" for repested jobs</center> <pre> <A
3987HREF="http://vim.sf.net/tip_view.php?tip_id=144">http://vim.sf.net/tip_view.php?tip_id=144</A><BR>
3988
3989The most useful feature that I find in VIM is the "recording" feature (:help
3990recording). I have used this to automatically insert function headers,
3991re-indent lines, and convert some 34 source files into HTML.
3992
3993This feature is most useful when you want to do some repeated jobs, which
3994you cant do easily using ".". You can set about writing a function, define
3995a mapping, etc, but then these things might take time. By recording, you
3996can try out and find the actual keystrokes that does the job.
3997
3998To start recording, press "q" in normal mode followed by any of "0-9a-z".
3999This will start recording the keystrokes to the register you choose. You can
4000also see the word "recording" in the status(?) line. You can start the key
4001sequences that you want to record. You can go to insert mode and type if
4002you want.
4003
4004To stop recording, press "q" in the normal mode.
4005
4006To playback your keystrokes, press "@" followed by the character you choose.
4007Pressing "@@" will repeat the same again.
4008
4009Sameer.
4010
4011</pre></tip> </html> <Tip category="KVim"> <html><center>Changing
4012DOS style end of line to UNIX, or vise-versa</center> <pre> <A
4013HREF="http://vim.sf.net/tip_view.php?tip_id=145">http://vim.sf.net/tip_view.php?tip_id=145</A><BR>
4014
4015Those of us doomed to work in both the Unix and Windows world have many times
4016encountered files that were create/editted on systems other that the one
4017we are on at the time of our edits. We can easily correct the dreaded '^M'
4018at the end of our Unix lines, or make files have more than one line in DOS by:
4019
4020To change from &lt;CR&gt;&lt;LF&gt; (DOS) to just &lt;LF&gt; (Unix): :set
4021fileformat=unix :w
4022
4023Or to change back the other way: :set fileformat=dos :w
4024
4025It also works for Apple land: :set fileformat=mac :w
4026
4027And 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
4031Happy Vimming!
4032
4033</pre></tip> </html> <Tip category="KVim"> <html><center>opening
4034multiple files from a single command-line</center> <pre> <A
4035HREF="http://vim.sf.net/tip_view.php?tip_id=146">http://vim.sf.net/tip_view.php?tip_id=146</A><BR>
4036
4037i use the :split command a lot -- both to open a second window containing
4038the 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
4040one file and calling :sp multiple times is inconvenient. so, i created the
4041following command, function and abbreviation:
4042
4043function! 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
4053endfunction com! -nargs=* -complete=file Sp call Sp(&lt;f-args&gt;) cab sp Sp
4054
4055this retains the behaviour of :sp in that i can still type :sp (the
4056abbreviation takes care of that). :Sp takes any number of files and opens
4057them all up, one after the other.
4058
4059the things i have noticed are that this causes 'sp' to be expanded to 'Sp'
4060everywhere, even in search patterns. also, prepending 'vert' doesn't work.
4061if 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
4065HREF="http://vim.sf.net/tip_view.php?tip_id=147">http://vim.sf.net/tip_view.php?tip_id=147</A><BR>
4066
4067This tip gives a skeleton for writing a plugin; Vim's help files have plenty
4068of 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)
4073if exists("loaded_YourAppName") || &cp
4074 finish
4075endif
4076
4077# Public Interface: # AppFunction: is a function you expect your users to
4078call # PickAMap: some sequence of characters that will run your AppFunction #
4079Repeat these three lines as needed for multiple functions which will # be used
4080to 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
4082endif
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;
4092interface above fu! &lt;SID&gt;AppFunction() ..whatever..
4093
4094# your script function can set up maps to internal functions
4095nmap &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
4099name # 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 #
4106script, and its name won't clash with whatever else the user has loaded
4107fu! &lt;SID&gt;InternalAppFunction(...) ..whatever.. endf
4108
4109#
4110------------------------------------------------------------------------------
4111
4112Plugins are intended to be "drop into &lt;.vim/plugin&gt;" and work.
4113The problem that the &lt;Plug&gt;, &lt;SID&gt;, etc stuff is intended to
4114resolve: what to do about functions that have the same names in different
4115plugins, and what to do about maps that use the same sequence of characters?
4116The first problem is solved with &lt;SID&gt; (a script identifier number)
4117that vim assigns: program with it and your users will be happier when your
4118stuff works with all their other stuff. The second problem: what to about
4119those maps is addressed with &lt;Plug&gt;, &lt;unique&gt;, etc. Basically
4120the idea is: let the user know that there are clashes and don't overwrite
4121previously existing maps. Use the user's preferred map-introducer sequence
4122(I like the backslash, but there are many keyboards which make producing
4123backslashes unpleasant, and those users usually prefer something else).
4124
4125What I like to do is to have a pair of start/stop maps to reduce my impact
4126on the namespace. When the starting map is used, it kicks off a starting
4127function that introduces all the maps needed. When the stopping map is
4128used, it not only removes the maps the starter made but restores any maps
4129the user had had that would have clashed. I also use the start/stop pair
4130of functions to set and restore options that cause my scripts difficulties.
4131
4132Check out DrawIt.vim's SaveMap() function for a way to save user maps.
4133Restoring maps with it is easy:
4134
4135if b:restoremap != ""
4136 exe b:restoremap unlet b:restoremap
4137endif
4138
4139So you can see it sets up a string variable with all the maps that the user
4140had that would have clashed with my application.
4141
4142One final thing: if your application needs to share information between
4143its various functions, see if you can use s:varname (a variable that only
4144your script's functions can access) or b:varname (a variable that anything
4145associated with the buffer your application is running with can access)
4146instead of using global variables.
4147
4148Good luck and happy Vimming!
4149
4150</pre></tip> </html> <Tip category="KVim"> <html><center>Make
4151great use of those homemade menus</center> <pre> <A
4152HREF="http://vim.sf.net/tip_view.php?tip_id=148">http://vim.sf.net/tip_view.php?tip_id=148</A><BR>
4153
4154Accidently 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
4156out in a seperate window. Selecting the menu with the mouse and then hitting
4157enter does not seem to do it.
4158
4159I will have to learn to add hotletters to my menus now so that the mouse
4160can take a break.
4161
4162I am a total newbie with vim, but constantly amazed....
4163
4164</pre></tip> </html> <Tip category="KVim"> <html><center>Automatically
4165update your diff upon writing.</center> <pre> <A
4166HREF="http://vim.sf.net/tip_view.php?tip_id=149">http://vim.sf.net/tip_view.php?tip_id=149</A><BR>
4167
4168When trying to reconcile differences between files, and using the new 'diff'
4169functionality in Vim 6.0 you may want to automatically update the differences
4170as you are working along. A convienent time is when you write out either of
4171the 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
4179a column of increasing numbers</center> <pre> <A
4180HREF="http://vim.sf.net/tip_view.php?tip_id=150">http://vim.sf.net/tip_view.php?tip_id=150</A><BR>
4181
4182You 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
4187to convert a block of numbers selected via ctrl-v (visual block) into a
4188column of increasing integers. Select the column, press :I&lt;CR&gt;, and
4189the first line's number will be used as a starting value. Subsequent lines's
4190numbers will be incremented by one.
4191
4192If the ctrl-v block is "ragged right", which can happen when "$" is used to
4193select the right hand side, the block will have spaces appended as needed
4194to straighten it out. If the strlen of the count exceeds the visual-block
4195allotment of spaces, then additional spaces will be inserted.
4196
4197Example: 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
4203This script works with both vim 5.7 (:so visincr.vim) or vim 6.0 (source it
4204as 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
4208HREF="http://vim.sf.net/tip_view.php?tip_id=151">http://vim.sf.net/tip_view.php?tip_id=151</A><BR>
4209
4210There is an ascii table in the vim-help files, but it's hard to find. Thus,
4211I shall give a pointer to it:
4212
4213:help digraph-table
4214
4215</pre></tip> </html> <Tip category="KVim"> <html><center>Dutch,
4216English, German, Hungarian, and Yiddish</center> <pre> <A
4217HREF="http://vim.sf.net/tip_view.php?tip_id=152">http://vim.sf.net/tip_view.php?tip_id=152</A><BR>
4218
4219Under <A
4220HREF="http://www.erols.com/astronaut/vim/index.html#vimlinks_scripts">http://www.erols.com/astronaut/vim/index.html#vimlinks_scripts</A><BR>
4221are links to spelling checkers for Dutch, English, German, Hungarian,
4222and Yiddish, all based on the original engspchk.vim. The spelling checker
4223provides as-you-type spell checking; with vim6.0 it will avoid checking on
4224partially typed words.
4225
4226Provided 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
4233To 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
4240To use the spell checkers just source it in:
4241
4242 ex. so engspchk.vim
4243
4244To 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
4250Parenthesis And Brackets Handling Easier</center> <pre> <A
4251HREF="http://vim.sf.net/tip_view.php?tip_id=153">http://vim.sf.net/tip_view.php?tip_id=153</A><BR>
4252
42531) ++++++++++++++++++++++++++ "Automatic" bracket setting
4254+++++++++++++++++++++++++++++ 2) +++++++++++++ Further improvement of
4255parenthesis/bracket expanding +++++++++++++++++ 3) ++++++++++++++++++++++++++++
4256"Late" bracketing of text +++++++++++++++++++++++++++++ 4)
4257+++++++++++++++++++++++++++++ Conclusion ++++++++++++++++++++++++++++++++++++++
4258++++
4259
4260=======================================================================================
4261
42621) ++++++++++++++++++++++++++ "Automatic" bracket setting
4263+++++++++++++++++++++++++++++
4264
4265To automatically insert a closing parenthesis when typing an opening
4266parenthesis you can insert the following simple mapping to your vimrc:
4267
4268 :inoremap ( ()&lt;ESC&gt;i
4269
4270This ends up with the cursor between the opening and the closing parenthesis
4271in insert mode.
4272
4273You can apply this and the following tips, of course, with the kind of
4274parenthesis/bracket character you want to, i.e. (, {, [, &lt; ..... and,
4275pretty useful as well, quotation marks ",',.... (to be continued)
4276
42772) +++++++++++++++ Further improvement of parenthesis/bracket expanding
4278++++++++++++++++++
4279
4280I 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
4282comfortable, I invented the following kind of mappings, which get out of
4283the last expanded parenthesis/bracket, regardless of the actual type of it,
4284and enter append mode again. I mapped this kind of "getaway" with CTRL_j,
4285you 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
4293Explanation: The variable "leavechar" contents the actual char which is to
4294"escape" from.
4295
42963) ++++++++++++++++++++++++++++ "Late" bracketing of text
4297+++++++++++++++++++++++++++++
4298
4299Occasionally I later want already written text parts to put in parenthesis.
4300
4301I use the following macro, which brackets previously visually selected text.
4302I mapped it with _(.
4303
4304 :vnoremap _( &lt;ESC&gt;`&gt;a)&lt;ESC&gt;`&lt;i(&lt;ESC&gt;
4305
4306Furthermore, a sort of mapping for bracketing a *single word* is conceivable.
4307Because this is not as general like the kind of visual mode mapping, I use
4308this kind of "word bracketing" only for surrounding the word right behind
4309the cursor in insert mode with **. I use the following macro to "emphasize"
4310the word i just typed, for newsgroup articles.
4311
4312 :imap _* &lt;Esc&gt;bi*&lt;Esc&gt;ea*&lt;Space&gt;
4313
43144) ++++++++++++++++++++++++++++++ Conclusion
4315++++++++++++++++++++++++++++++++++++++++++
4316
4317Since I use these macros, I never caused a syntax error because of missing
4318brackets, and furthermore I can quickly insert parenthesis and qutotes into
4319code- and non-code files.
4320
4321 JH 04.11.2001
4322
4323</pre></tip> </html> <Tip category="KVim"> <html><center>Mappings
4324to facilitate the creation of text</center> <pre> <A
4325HREF="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
4328sgovindachar@yahoo.com " Date: November 5, 2001 " " While typing text to
4329create 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
4331as "i", "O", "s" etc. " " I looked into using "set insertmode" to speed
4332up such actions, but " found that too confusing. " " I have come up with
4333a set of mappings that have speeded up my process " of creating documents.
4334I have saved these mappings in a file, named " FullScreenVI.vim, in vim's
4335plugin 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
4339from 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;
4345imap &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
4351imap &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;*
4355imap &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;~
4365imap &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
4367imap &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
4375Java .class files automatically</center> <pre> <A
4376HREF="http://vim.sf.net/tip_view.php?tip_id=155">http://vim.sf.net/tip_view.php?tip_id=155</A><BR>
4377
4378Here's a plugin to automatically decompile Java .class files as they're
4379read in. Tweak the javap flags for what you want to see. I didn't post
4380this as a script because it's too simple and it's really more useful for
4381demonstrating how to read decompilable files (or other binary files that
4382can be converted to text).
4383
4384function s:ReadClass(dir, classname)
4385 execute "cd " . a:dir execute "0read !javap -c " . a:classname 1 setlocal
4386 readonly setlocal nomodified
4387endfunction
4388
4389autocmd 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
4395HREF="http://vim.sf.net/tip_view.php?tip_id=156">http://vim.sf.net/tip_view.php?tip_id=156</A><BR>
4396
4397i had some trouble with the sqlplus scripts (probably my fault). but it
4398seemed a little heavy for what i need, usually all i want is a listing of
4399the columns for a given table while i'm whipping on some sql inside vim.
4400
4401so i wrote a bash script (describe)...
4402
4403~~~~~~~~~~~~~~~begin describe script #!/usr/bin/bash
4404
4405f=aTempFile.sql u=&lt;uName&gt; p=&lt;pWord&gt; d=&lt;dBase&gt;
4406
4407echo "/* describe for $1" echo "describe $1;" &gt; $f; echo "quit;"
4408&gt;&gt; $f;
4409
4410sqlplus -S $u/$p@$d @$f rm -f $f; echo " end describe for $1 */"
4411~~~~~~~~~~~~~~~end describe script
4412
4413your path needs to include the script (as well as sqlplus), then from vim
4414you can just type....
4415
4416:r !describe &lt;tableName&gt;
4417
4418and you get a listing of the table columns slammed into wherever your cursor
4419was, complete with java/c comments
4420
4421</pre></tip> </html> <Tip category="KVim">
4422<html><center>Incredible new functionality</center> <pre> <A
4423HREF="http://vim.sf.net/tip_view.php?tip_id=157">http://vim.sf.net/tip_view.php?tip_id=157</A><BR>
4424
4425if you get away from vim and get any other editor that was built *after*
44261970....
4427
4428</pre></tip> </html> <Tip category="KVim"> <html><center>Using
4429Computer Modern TT as gvim font (Win32)</center> <pre> <A
4430HREF="http://vim.sf.net/tip_view.php?tip_id=158">http://vim.sf.net/tip_view.php?tip_id=158</A><BR>
4431
4432If you really like the Computer Modern typewriter font (as seen in most TeX
4433distributions) you can use it as the font in gvim! (looks excellent with
4434font smoothing turned on)
4435
4436First, get hold of the free Blue Sky Type 1 PS versions of the CM fonts from
4437your local CTAN mirror. Unpack to a suitable directory.
4438
4439Next locate the cmtt8.pfb file and open it (in Vim, naturally ;) - find the
4440line saying dup 32 /visiblespace put
4441
4442and change it to dup 32 /space put
4443
4444that is, inserting enough spaces to keep the file size exactly the same
4445(IMPORTANT!)
4446
4447Save the file in Mac format (:set fileformat=mac).
4448
4449Now 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
4451Fonts folder.
4452
4453Now 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
4460Saving Substituting and Searching</center> <pre> <A
4461HREF="http://vim.sf.net/tip_view.php?tip_id=159">http://vim.sf.net/tip_view.php?tip_id=159</A><BR>
4462
44631) ++++++++++++++ Saving Keystrokes for common Searching
4464and Substituting +++++++++++ --- a) Searching b) Substituting
4465--------------------------------------------------- 2) ++++ Searching for
4466resp. Substituting of the current word under the cursor ++++++ --- a) Searching
4467b) Substituting ---------------------------------------------------
44683) ++ Searching and Substituting for an arbitrary visually
4469selected part of text ++++ --- a) Searching b) Substituting
4470---------------------------------------------------
44714) ++++++++++++++++++++++++++++++++ Conclusion
4472+++++++++++++++++++++++++++++++++++++
4473
4474=====================================================================================
4475
44761) ++++++++++++++ Saving Keystrokes for common Substituting and Searching
4477+++++++++++
4478
4479a) Searching ............ Sorry, there is not much that can be saved for
4480common Searching. It's just hitting /mypattern&lt;RETURN&gt;
4481
4482b) Substituting ......... I think, common substitution requires pretty many
4483keystrokes. 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
4487This ends up with the cursor after the first '/' in the
4488commandline. To complete it, you only have to enter -&gt;
4489myoldpattern/mynewpattern&lt;RETURN&gt;
4490
4491Remark: I mapped it to &lt;F4&gt; (cause of tribute to the &lt;F4&gt; of
4492the good old Norton Commander editor). You may map it where you want to.
4493
44942) ++++ Searching for resp. Substituting of the current word under the
4495cursor ++++++
4496
4497a) Searching ............ If you don't know how to look for the next
4498occurence 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:
4500To make your pattern more visible, look for :help hls))
4501
4502b) Substituting ......... The following macro extends the one above with
4503automatically inserting the current word under the cursor into the from -
4504pattern 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
4509To complete it, just enter -&gt; mynewpattern&lt;RETURN&gt;
4510
4511I use this i.e. for reliable and quickly renaming a variable in the entire
4512buffer. I mapped it to Shift-&lt;F4&gt;. You may map it to the keystroke
4513you want.
4514
4515Explanation: CTRL-v+CTRL-w expands to the word under the cursor.
4516
45173) ++ Searching and Substituting for an arbitrary visually selected part of
4518text ++++
4519
4520If you want to look or substitute (for) an *arbritary* pattern (which
4521already exists at least once in your text), the following 2 mappings do it
4522for you. The advantage is that you dont have to type again or cut & paste
4523the appropriate text but only have to visually select it.
4524
4525a) Searching ...........
4526
4527:vmap / y:execute "/".escape(@",'[]/\.*')&lt;CR&gt;
4528
4529This immediately finds to the next occurence of the previously visually
4530selected text.
4531
4532b) 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
4537Again, as in the mapping in chapter 2), you just have to complete it by
4538entering -&gt; mynewpattern&lt;RETURN&gt;
4539
4540Explanation/Discussion: What both Substituting and Searching in this way
4541generally does is: - *y*anking the selected text - Inserting the visually
4542selected 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
45534) ++++++++++++++++++++++++++++++++ Conclusion
4554+++++++++++++++++++++++++++++++++++++
4555
4556With the appropriate mappings in your vimrc you can save keystrokes when
4557Searching or Substituting and avoid typing errors. That way, you can take
4558lunch sooner
4559
4560</pre></tip> </html> <Tip category="KVim">
4561<html><center>Dutch spelling checker</center> <pre> <A
4562HREF="http://vim.sf.net/tip_view.php?tip_id=161">http://vim.sf.net/tip_view.php?tip_id=161</A><BR>
4563
4564Download at <A
4565HREF="http://www.thomer.com/thomer/vi/nlspchk.vim.gz.">http://www.thomer.com/thomer/vi/nlspchk.vim.gz.</A><BR>
4566
4567This sciript is based on Charles E. Campbell's English spelling checker script
4568for ViM (<A HREF="http://users.erols.com/astronaut/vim/) and Piet Tutelaers'
4569Dutch word list (http://www.ntg.nl/spell-nl-v5b/) using Thomas Köhler's
4570script (http://jeanluc-picard.de/vim/gerspchk/create). In other words, I
4571didn't do much.">http://users.erols.com/astronaut/vim/) and Piet Tutelaers'
4572Dutch word list (http://www.ntg.nl/spell-nl-v5b/) using Thomas Köhler's
4573script (http://jeanluc-picard.de/vim/gerspchk/create). In other words,
4574I didn't do much.</A><BR>
4575
4576</pre></tip> </html> <Tip category="KVim"> <html><center>write
4577plugin with explorer like interfaces</center> <pre> <A
4578HREF="http://vim.sf.net/tip_view.php?tip_id=162">http://vim.sf.net/tip_view.php?tip_id=162</A><BR>
4579
4580Several plugins use a text base interface based on a special buffer, this
4581is the case of the standard explorer plugin, several bufexplorer plugins,
4582the option buffer and others... Here is a quick guide in how to do this
4583
4584Writing 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
4592Setting 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
4657HREF="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
4663non-ASCII characters displayed on console</center> <pre> <A
4664HREF="http://vim.sf.net/tip_view.php?tip_id=164">http://vim.sf.net/tip_view.php?tip_id=164</A><BR>
4665
4666I had a problem with VIM on the FreeBSD console: it didn't display characters
4667like German umlauts correctly, but escaped them with a tilde. The solution
4668is to teach VIM about printable characters. I use the following on my .vimrc:
4669
4670set isprint=@,128-255
4671
4672</pre></tip> </html> <Tip category="KVim"> <html><center>Deleting
4673a buffer without closing the window</center> <pre> <A
4674HREF="http://vim.sf.net/tip_view.php?tip_id=165">http://vim.sf.net/tip_view.php?tip_id=165</A><BR>
4675
4676I'm not sure if this functionality is already within Vim, but I sometimes I
4677find it useful to keep a split window from closing when deleting a buffer.
4678This has already been discussed on the vim@vim.org mailing list. However,
4679I feel this solution is a little easier to use.
4680
4681" Put this into .vimrc or make it a plugin. " Mapping :Bclose to some
4682keystroke would probably be more useful. " I like the way buflisted()
4683behaves, but some may like the behavior " of other buffer testing functions.
4684
4685command! Bclose call &lt;SID&gt;BufcloseCloseIt()
4686
4687function! &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
4703endfunction
4704
4705</pre></tip> </html> <Tip category="KVim"> <html><center>Mapping
4706caps lock to esc in XWindows</center> <pre> <A
4707HREF="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
4710HREF="http://groups.yahoo.com/group/vim/message/19856)">http://groups.yahoo.com/group/vim/message/19856)</A><BR>
4711
4712If you want to completely swap caps lock and escape, you have to replace
4713the "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;
4715remove Lock = Caps_Lock&lt;br&gt; keysym Escape = Caps_Lock&lt;br&gt;
4716keysym Caps_Lock = Escape&lt;br&gt; add Lock = Caps_Lock&lt;br&gt;
4717------------end-------------&lt;br&gt; and call it ".speedswapper". Then
4718open a terminal and type&lt;br&gt; $ xmodmap .speedswapper&lt;br&gt;
4719and you'll be twice as efficient in vim. Who needs caps lock anyway? The
4720swapping 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,
4722I'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
4725vim as a man-page viewer under Unix</center> <pre> <A
4726HREF="http://vim.sf.net/tip_view.php?tip_id=167">http://vim.sf.net/tip_view.php?tip_id=167</A><BR>
4727
4728To 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
4733Put one of the above two lines into your &lt;.profile&gt; or &lt;.login&gt;
4734file as appropriate for your shell.
4735
4736The man pages will then be displayed with vim called as "view" and
4737will use the &lt;man.vim&gt; syntax highlighting. I myself use some
4738additional 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;
4740colorscheme (also available from this archive); those who use bright
4741backgrounds may find the colors selected for manSubSectionStart and
4742manSubSection something they'll want to change:
4743
4744 ---------------------------------------------------------------------
4745" DrChip's additional &lt;man.vim&gt; stuff
4746
4747syn match manSectionHeading "^\s\+[0-9]\+\.[0-9.]*\s\+[A-Z].*$"
4748contains=manSectionNumber syn match manSectionNumber
4749"^\s\+[0-9]\+\.[0-9]*" contained syn region manDQString
4750start='[^a-zA-Z"]"[^", )]'lc=1 end='"' contains=manSQString
4751syn region manSQString start="[ \t]'[^', )]"lc=1 end="'"
4752syn region manSQString start="^'[^', )]"lc=1 end="'"
4753syn region manBQString start="[^a-zA-Z`]`[^`, )]"lc=1 end="[`']"
4754syn region manBQSQString start="``[^),']" end="''"
4755syn match manBulletZone transparent "^\s\+o\s" contains=manBullet
4756syn case match syn keyword manBullet contained o syn match manBullet
4757contained "\[+*]" syn match manSubSectionStart "^\*" skipwhite
4758nextgroup=manSubSection syn match manSubSection ".*$" contained
4759
4760hi link manSectionNumber Number hi link manDQString String hi
4761link manSQString String hi link manBQString String hi
4762link manBQSQString String hi link manBullet Special hi
4763manSubSectionStart term=NONE cterm=NONE gui=NONE ctermfg=black
4764ctermbg=black guifg=navyblue guibg=navyblue hi manSubSection
4765term=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
4770the actual XPM data in GVIM</center> <pre> <A
4771HREF="http://vim.sf.net/tip_view.php?tip_id=168">http://vim.sf.net/tip_view.php?tip_id=168</A><BR>
4772
4773GVIM has an excellent syntax highlighting for XPM images, but sometimes
4774it's useful to view the actual data. This can be achieved by searching for
4775everything, type in "/." and all characters will be highlighted and therefore
4776the old colouring is lost. To regain the normal highlighting you can search
4777for 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
4781HREF="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;
4785can be mapped to different things. The answer is no. As I understand it,
4786this is a low level issue: &lt;Tab&gt; and &lt;C-I&gt; are different names
4787for the same ASCII code, and there is no way for vim to tell them apart.
4788Similarly, &lt;Esc&gt; and &lt;C-[&gt; are the same thing.
4789
4790</pre></tip> </html> <Tip category="KVim"> <html><center>Repeating
4791a sequence of commands without defining a macro</center> <pre> <A
4792HREF="http://vim.sf.net/tip_view.php?tip_id=170">http://vim.sf.net/tip_view.php?tip_id=170</A><BR>
4793
4794Imagine.
4795
4796You have just finished a complicated modification of a file, involving
4797numerous replace commands :%s/xxx/yyyy/g, and other ex commands.
4798
4799Then you realize, you have done it a little bit wrong, and you have to begin
4800all the operation again, just to change one replace string, or do one more
4801operation "somewhere 10 commands ago".
4802
4803Or you realize, you will have to do the same stuff tomorrow with another file.
4804
4805or you realize, you want to perform the same sequence of commands, you have
4806typed a few days ago
4807
4808You should have made it a macro (normal command q), but you haven't.
4809
4810Nothing is lost yet.
4811
4812You go to the command line (by typing :) and press Ctrl+F. (Ctrl+F in other
4813modes scrolls the screen)
4814
4815You get a temporary window, listing the history of command line.
4816It 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
4819see :help cedit
4820
4821Then you can call the macro using :source something.vim
4822
4823You might want to set variable 'history' to a higher number then default in
4824your vimrc file like :set history=300 see :help history :help vimrc
4825
4826</pre></tip> </html> <Tip category="KVim"> <html><center>Do
4827you know the "g/" and "g?" commands?</center> <pre> <A
4828HREF="http://vim.sf.net/tip_view.php?tip_id=171">http://vim.sf.net/tip_view.php?tip_id=171</A><BR>
4829
4830Directly from the Vim Todo list:
4831
48327 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
4835In other words, a way to search for visually selected text !! :-)
4836
4837"==== vsearch.vim ====
4838
4839" Visual mode search
4840
4841vmap g/ :call VsearchPatternSave()&lt;cr&gt;/&lt;c-r&gt;/&lt;cr&gt; vmap
4842g? :call VsearchPatternSave()&lt;cr&gt;?&lt;c-r&gt;/&lt;cr&gt;
4843
4844function! VsearchPatternSave()
4845 let l:temp = @@ normal gvy let @/ = substitute(escape(@@, '/\'), "\n",
4846 "\\\\n", "g") let @@ = l:temp unlet l:temp
4847endfunction
4848
4849"==== END ====
4850
4851Normally, this file should reside in the plugins directory and be
4852automatically sourced. If not, you must manually source this file using
4853':source vsearch.vim'.
4854
4855In Visual mode, highlight the text for searching. Then you can use the
4856default visual key mappings
4857
4858g/ - search forwards g? - search backwards
4859
4860Visual searches behave like normal searches. The 'n' and 'N' commands
4861work as they should, and the search history correctly records each search.
4862Multi-line searches behave as they should (this corrects the 'yank-only'
4863method mentioned in the Vim help files). Block visual searches do not
4864work yet. Hopefully, someone can figure out a way to do this easily.
4865
4866I've only tested this on Win2000 and Redhat Linux 7.1. I'm not really clear
4867on how the carriage returns are dealt with on other systems.
4868
4869Anyway, enjoy!
4870
4871</pre></tip> </html> <Tip category="KVim"> <html><center>Using
4872Ispell on a highlighted region</center> <pre> <A
4873HREF="http://vim.sf.net/tip_view.php?tip_id=172">http://vim.sf.net/tip_view.php?tip_id=172</A><BR>
4874
4875Suppose you would like to use Ispell to check a word or region that you've
4876visually highlighted. The following macro will do the job. Just type
4877Shift-Insert while in visual mode.
4878
4879vnoremap &lt;S-Insert&gt; &lt;C-C&gt;`&lt;v`&gt;s&lt;Space&gt;&lt;Esc&gt;mq:e
4880ispell.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
4883ispell.tmp*&lt;CR&gt;`q"_s&lt;C-R&gt;"&lt;Esc&gt;
4884
4885This is based on Chip Campbell's macro which uses Ispell on the whole file
4886(in normal mode).
4887
4888noremap &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
4891Carl Mueller
4892
4893</pre></tip> </html> <Tip category="KVim"> <html><center>Switch
4894between splits very fast (for multi-file editing)</center> <pre> <A
4895HREF="http://vim.sf.net/tip_view.php?tip_id=173">http://vim.sf.net/tip_view.php?tip_id=173</A><BR>
4896
4897I am a Web developer and I use Vim as my primary editor.
4898
4899Most programming projects (and Web programming projects, in particular)
4900are spread out over multiple files, which you often want to have open
4901concurrently. If you don't already know, Vim supports this very well! Just use:
4902
4903:sp name-of-another-file-to-edit
4904
4905My problems were that (1) it took too long to move between files, and (2)
4906the 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
4909typing Ctrl-W, Up (move up a window) Ctrl-W, _ (maximize the menu). That's
4910four keystrokes (more if you count Ctrl and Shift), and they are all over
4911the keyboard. To help avoid this problem, I created this mapping in my .vimrc:
4912
4913map &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
4916Now I can hold down Ctrl and move between windows with the standard Vim
4917movement 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
4921line in my .vimrc:
4922
4923set wmh=0
4924
4925This sets the minimum window height to 0, so you can stack many more files
4926before things get crowded. Vim will only display the filename.
4927
4928Hope this helps those of you who are working on projects with large numbers
4929of files you're constantly flipping through. Happy Vimming!
4930
4931</pre></tip> </html> <Tip category="KVim">
4932<html><center>Footnotes</center> <pre> <A
4933HREF="http://vim.sf.net/tip_view.php?tip_id=174">http://vim.sf.net/tip_view.php?tip_id=174</A><BR>
4934
4935ab (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]
4937ab (2 [2]&lt;esc&gt;:/^Footnotes\:/+2/&lt;cr&gt;o&lt;insert&gt;[2]
4938ab (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
4943VIM as ur default editor even without root ac.</center> <pre> <A
4944HREF="http://vim.sf.net/tip_view.php?tip_id=175">http://vim.sf.net/tip_view.php?tip_id=175</A><BR>
4945
4946hi, if u have installed vim in your home directory somewhere and u don't have a
4947root account, and you want to make VIM the default editor for anything u do.
4948i.e if ur using SQLplus and want to edit a sql command. normally typing
4949edit brings up the vi editor and not vim editor. to solve this problem.
4950define these three variables in your .profile VIM=&lt;base directory where
4951vim executable is placed&gt; VIMRUNTIME=&lt;base direcoty where vim runtimes
4952are kept&gt; EDITOR=$VIM/vim
4953
4954note if u have installed vim with another name, say vim.exe then change
4955EDITOR=$VIM/vim to EDITOR=$VIM/vim.exe
4956
4957source the .profile and viola. next time u start an editor from any program
4958u have the vim editor.
4959
4960Njoy.
4961
4962</pre></tip> </html> <Tip category="KVim">
4963<html><center>Autocheckout from perforce</center> <pre> <A
4964HREF="http://vim.sf.net/tip_view.php?tip_id=176">http://vim.sf.net/tip_view.php?tip_id=176</A><BR>
4965
4966The following code automatically checks out files from perforce when the
4967user 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
4970modified for RCS, CVS, etc., but I don't use those.)
4971
4972I'm a vim newbie -- I've used vi since 1984, but just started with vim a couple
4973days ago. Color me impressed! Please excuse any stupidity in the code..
4974
4975Note that this function needs the "P4HOME" environment variable to be set.
4976I could extract it by invoking "p4 client", but I don't want to invoke p4
4977every 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
4980the 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
4986endfunction " Confirm with the user, then checkout a file from perforce.
4987function 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
4996endfunction
4997
4998if !exists("au_p4_cmd")
4999 let au_p4_cmd=1
5000
5001 au BufEnter * call IsUnderPerforce() au FileChangedRO * call P4Checkout()
5002endif
5003
5004</pre></tip> </html> <Tip category="KVim"> <html><center>Highlight
5005matching brackets as one moves in normal mode (plugin)</center> <pre> <A
5006HREF="http://vim.sf.net/tip_view.php?tip_id=177">http://vim.sf.net/tip_view.php?tip_id=177</A><BR>
5007
5008Check out <A HREF="http://www.erols.com/astronaut/vim/index.html#VimFuncs
5009for">http://www.erols.com/astronaut/vim/index.html#VimFuncs for</A><BR>
5010a plugin script which highlights matching brackets. The script has two
5011always-on maps:
5012 \[i : start [HiMtchBrkt] mode \[s : stop [HiMtchBrkt] mode
5013The plugin will save all user maps and options that the plugin uses and will
5014restore them when the mode is stopped.
5015
5016</pre></tip> </html> <Tip category="KVim"> <html><center>Making
5017a "derived" colorscheme without copy & paste</center> <pre> <A
5018HREF="http://vim.sf.net/tip_view.php?tip_id=178">http://vim.sf.net/tip_view.php?tip_id=178</A><BR>
5019
5020Suppose there's a colorscheme that you're pretty fond of, but hate one or
5021two particular aspects about. For example, I love the "blue" colorscheme
5022that ships with vim, but I find it's colors for the non-active status line
5023to be unreadable. Here's how to create a colorscheme which extends "blue"
5024without copying it to a new file and editing it.
5025
5026In 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
5029if exists("syntax_on")
5030 syntax reset
5031endif
5032
5033"Load the 'base' colorscheme - the one you want to alter runtime
5034colors/blue.vim
5035
5036"Override the name of the base colorscheme with the name of this custom one
5037let g:colors_name = "my-blue"
5038
5039"Clear the colors for any items that you don't like hi clear StatusLine hi
5040clear StatusLineNC
5041
5042"Set up your new & improved colors hi StatusLine guifg=black guibg=white hi
5043StatusLineNC guifg=LightCyan guibg=blue gui=bold
5044
5045That's all there is to it.
5046
5047</pre></tip> </html> <Tip category="KVim">
5048<html><center>Simplify help buffer navigation</center> <pre> <A
5049HREF="http://vim.sf.net/tip_view.php?tip_id=179">http://vim.sf.net/tip_view.php?tip_id=179</A><BR>
5050
5051Vim is distributed with comprehensive help system, which has basic hyperlink
5052support - you can press &lt;C-]&gt; over |some subject| or 'some option'
5053to read more about particular term.
5054
5055The following mappings simplify help buffer navigation: pressing s(or S)
5056will find next(previous) subject from cursor position pressing o(or O) will
5057find next(previous) option from cursor position pressing Enter will jump to
5058subject under cursor pressing Backspace will return from the last jump
5059
5060Put them into help filetype plugin (like ~/.vim/ftplugin/help.vim on UNIX).
5061
5062nmap &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;
5064O ?'[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
5068your filetype/syntax plugin</center> <pre> <A
5069HREF="http://vim.sf.net/tip_view.php?tip_id=180">http://vim.sf.net/tip_view.php?tip_id=180</A><BR>
5070
5071Ever tried to write/debug your own filetype/syntax plugin?
5072
5073It's an iterative process which involves editing plugin code and testing it
5074on some sample file. To see changes you made in your plugin simply do :e
5075on sample file. This will force Vim to reload all buffer-specific files,
5076including your plugin.
5077
5078</pre></tip> </html> <Tip category="KVim">
5079<html><center>get the vim patched source</center> <pre> <A
5080HREF="http://vim.sf.net/tip_view.php?tip_id=181">http://vim.sf.net/tip_view.php?tip_id=181</A><BR>
5081
5082Hi, there has been a number of person (including) asking in the vim list how
5083to keep up with Bram's incredible bug correction and patch writing skills, but
5084there is a great way to do this! Use the cvs source which is available at <A
5085HREF="http://sourceforge.net/cvs/?group_id=8">http://sourceforge.net/cvs/?group_id=8</A><BR>
5086it is kept up to date and its a lot easier than applying all the patch
5087in order. Benoit
5088
5089</pre></tip> </html> <Tip category="KVim"> <html><center>Keep
5090your cursor centered vertically on the screen</center> <pre> <A
5091HREF="http://vim.sf.net/tip_view.php?tip_id=182">http://vim.sf.net/tip_view.php?tip_id=182</A><BR>
5092
5093i hope i don't hear a collective 'DUH!' from around the world but i just
5094did this and i think it's kinda cool.
5095
5096in your .vimrc add...
5097
5098map j jzz map k kzz
5099
5100so whenever you go up or down, vim does that and then re-centers. obviously it
5101doesn't work when you page up/ down.
5102
5103</pre></tip> </html> <Tip category="KVim"> <html><center>Select
5104a buffer from those matching a pattern</center> <pre> <A
5105HREF="http://vim.sf.net/tip_view.php?tip_id=183">http://vim.sf.net/tip_view.php?tip_id=183</A><BR>
5106
5107The :bu command will take a pattern as an argument and jump to the matching
5108buffer. However, it's not very helpful if there is more than one buffer
5109matching the pattern. In that case, it will jump to the first match, which
5110may not be what you want. The following function and user-command will
5111print a list of the matching buffers in the command-line area, and allow
5112you to select one of the matching buffers by number.
5113
5114"Select from buffers matching a certain pattern "the 'pattern' argument
5115shouldn't be prepended with a slash
5116
5117function! 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
5129endfunction
5130
5131"Bind the BufSel() function to a user-command command! -nargs=1 Bs :call
5132BufSel("&lt;args&gt;")
5133
5134</pre></tip> </html> <Tip category="KVim"> <html><center>How
5135to obscure text instantaneously</center> <pre> <A
5136HREF="http://vim.sf.net/tip_view.php?tip_id=184">http://vim.sf.net/tip_view.php?tip_id=184</A><BR>
5137
5138Hi, Lets say your writing some imp. doc. and your colleague comes along. you
5139don'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
5141text temporarily, so that u don't have to quit or swith to another application
5142using Alt-tab. (and if u don;t have any other window open u can;t even use
5143alt-tab) well rot-13 comes to help. vim has a built in rot-13 encoder.
5144
5145jut put the follwoing in your .vimrc
5146
5147map &lt;F3&gt; ggVGg?
5148
5149so next time some body comes along just press &lt;F3&gt; and all the buffer
5150will 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
5153editor for files with unregistered extensions in Windows</center> <pre> <A
5154HREF="http://vim.sf.net/tip_view.php?tip_id=185">http://vim.sf.net/tip_view.php?tip_id=185</A><BR>
5155
5156Normally in Windows, if you try to "launch" a file whose extension is not
5157registered with the system, the OS will prompt you for what editor you would
5158like to use to open the file. A much more appealing solution, in my mind,
5159is to make vim the default editor for any unregistered extension.
5160
5161To set vim up as the default editor for unregistered extensions, follow
5162these 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
5165files\\vim\\vim60\\gvim.exe \"%1\"" -------------end
5166unregistered.reg-----------------
5167
51682. Import unregistered into your registry. This can be done in vim by
5169executing the following :!regedit "unregistered.reg"
5170
5171Disclaimer: This has been tested only on NT4.
5172
5173</pre></tip> </html> <Tip category="KVim">
5174<html><center>Making search powerful</center> <pre> <A
5175HREF="http://vim.sf.net/tip_view.php?tip_id=186">http://vim.sf.net/tip_view.php?tip_id=186</A><BR>
5176
5177My 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
5181HREF="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
5185My tip is just a bunch of mappings that can be used while searching.
5186What 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
5192How 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
5196Note:
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
5208Mappings Used / =&gt; regular forward search start ? =&gt;
5209regular backward search start Rest of the mappings are used during search
5210Ctrl-A =&gt; search again forward (In normal mode, search forward with
5211the word under cursor) Ctrl-Q =&gt; search again backward (in normal mode,
5212search backward with the word under cursor) Ctrl-X =&gt; restore cursor (use
5213at 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
5215letters following the search pattern (in current line) Ctrl-T Ctrl-T =&gt;
5216search for the exact Ctrl-T Ctrl-Y =&gt; search partial (just strips \&lt;
5217and \&gt;) Ctrl-E =&gt; scroll up during searching Ctrl-Y =&gt; scroll down
5218during 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
5221screen (like zb in normal)
5222
5223Misc: Ctrl-K during search save the current matching line Ctrl-K in normal
5224mode pastes the saved line
5225
5226C mappings Ctrl-V Ctrl-G search for the global variable of the search
5227pattern/word under cursor Ctrl-V Ctrl-H search for the local variable of
5228the search pattern/word under cursor
5229
5230" --- cut n paste from here to end of document --- se nocp incsearch " core
5231mappings noremap / mg/ noremap ? mg? ounmap / ounmap ? noremap &lt;C-A&gt;
5232mg"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
5240mode cnoremap &lt;C-K&gt; &lt;CR&gt;"hyy?&lt;Up&gt;&lt;CR&gt;/&lt;Up&gt;
5241noremap &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;
5248mgyiw&lt;CR&gt;gg/\&lt;&lt;C-R&gt;"\&gt; noremap &lt;C-V&gt;&lt;C-H&gt;
5249mgyiw?^{&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;
5261vnoremap ? ymg?&lt;C-R&gt;=escape(@",'.*\/?')&lt;CR&gt;
5262
5263</pre></tip> </html> <Tip category="KVim"> <html><center>Searching
5264for more than one word at the same time.</center> <pre> <A
5265HREF="http://vim.sf.net/tip_view.php?tip_id=188">http://vim.sf.net/tip_view.php?tip_id=188</A><BR>
5266
5267Did you know that with VIM u can search for more than one word with a single
5268command. say you want to search all occurances of "bill" or "ted", or "harry"
5269in a text. in normal mode do the following. /\(bill\)\|\(ted\)\|\(harry\)
5270&lt;Enter&gt;
5271
5272this will match all instances of either "bill", or "ted", or "harry" in your
5273text. the key is the \(\) and \| operators. \(\) group characters in a word
5274and \| is for ORing.
5275
5276this is so cool u can even use it for replacing text. to replace all
5277instances 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
5279set the option "gdefault" u don't need the "g" at the end of the above command)
5280
5281I don't know of any other editor which can do this, with so much ease.
5282Rock on VIM Njoy
5283
5284</pre></tip> </html> <Tip category="KVim"> <html><center>Make
5285Ctrl-Backspace delete previous word (like GTK inputs)</center> <pre> <A
5286HREF="http://vim.sf.net/tip_view.php?tip_id=189">http://vim.sf.net/tip_view.php?tip_id=189</A><BR>
5287
5288Stuff this into your ~/.gvimrc and then you'll be able to type
5289Control-Backspace to delete the previous word. I had gotten so used to
5290C-BS working a certain way in all my editors with a ceezy input area (like
5291mozilla/galeon, gabber, etc...), that I wanted the same behaviour when I
5292used gvim.
5293
5294" map control-backspace to delete the previous word :imap &lt;C-BS&gt;
5295&lt;Esc&gt;vBc
5296
5297Simple, I know, but reasonably useful.
5298
5299--Robert
5300
5301</pre></tip> </html> <Tip category="KVim"> <html><center>XP &gt;
5302I-Explorer &gt; HTML Editor &lt; REG files</center> <pre> <A
5303HREF="http://vim.sf.net/tip_view.php?tip_id=190">http://vim.sf.net/tip_view.php?tip_id=190</A><BR>
5304
5305The issue is permitting other programs, besides NOTEPAD, be the HTML editor
5306under Internet Explorer. (Adding "Edit" as a New Action in the publicly
5307exposed Files Types for HTM/L does NOT do the job.)
5308
5309Given below are two REG files for vim. Just cut 'em up where indicated.
5310They have been tested under Windows XP.
5311
5312-------------------------------------------------------CUT HERE---------------
5313Windows Registry Editor Version 5.00
5314
5315; GOAL: Set gvim as HTML editor in Internet Explorer 6.0 ; Vim version :
53166.0 ; Windows version: XP ; EASY USAGE: name this file iex-vim60.reg and
5317double click on it ; Hard Usage: IMPORT this file using REGEDIT.EXE found
5318in c:\WINDOWS ; Last modified date : Dec 16, 2001
5319
5320; gvim is expected in "C:\Program Files\Vim\vim60\gvim.exe" ; Be sure to
5321also reset Explorer&gt;Tools&gt;Internet Options&gt;Programs
5322
5323; Microsoft documentation ; <A
5324HREF="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
5334Files\\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
5351Editor\Editor Name] ;@="C:\\Program Files\\Vim\\vim60\\gvim.exe"
5352
5353; ============================================= EOF
5354
5355-------------------------------------------------------CUT HERE---------------
5356Windows Registry Editor Version 5.00
5357
5358; GOAL: UNINSTALL gvim as HTML editor in Internet Explorer 6.0 ; Vim version :
53596.0 ; Windows version: XP ; EASY USAGE: name this file iex-vim60-uninstall.reg
5360and double click on it ; Hard Usage: IMPORT this file using REGEDIT.EXE
5361found 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
5364also reset Explorer&gt;Tools&gt;Internet Options&gt;Programs
5365
5366; Microsoft documentation ; <A
5367HREF="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
5378Happy Vimming...
5379
5380</pre></tip> </html> <Tip category="KVim">
5381<html><center>Transposing</center> <pre> <A
5382HREF="http://vim.sf.net/tip_view.php?tip_id=191">http://vim.sf.net/tip_view.php?tip_id=191</A><BR>
5383
5384You 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
5386you 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
5389imap &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
5392vmap &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
5400HREF="http://vim.sf.net/tip_view.php?tip_id=192">http://vim.sf.net/tip_view.php?tip_id=192</A><BR>
5401
5402LaTeX Help for aucTeX `translated' as vim help file.
5403
5404Installing
5405
5406:help add-local-help
5407
5408</pre></tip> </html> <Tip category="KVim"> <html><center>Insert
5409the current filename at cursor postion.</center> <pre> <A
5410HREF="http://vim.sf.net/tip_view.php?tip_id=193">http://vim.sf.net/tip_view.php?tip_id=193</A><BR>
5411
5412I found this one good for when I was starting to learn Java, it simply inserts
5413the current filename, at the cursor position, when you are in insert mode.
5414Honestly, its a mish-mash of some other tips I found here, but I thought it
5415might be useful.
5416
5417imap \fn &lt;C-R&gt;=expand("%:t:r")&lt;CR&gt;
5418
5419Enjoy!
5420
5421</pre></tip> </html> <Tip category="KVim">
5422<html><center>Inserting text in multiple lines</center> <pre> <A
5423HREF="http://vim.sf.net/tip_view.php?tip_id=194">http://vim.sf.net/tip_view.php?tip_id=194</A><BR>
5424
5425Do you know the I key in visual-block mode?
5426
5427Suppose you have let a=2 let b=3 let c=4
5428
5429You 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
5431Now enter s:&lt;Esc&gt;, and when you press &lt;Esc&gt;, b and c will have
5432the s: prefix too. See |v_b_I|
5433
5434Happy vimming! Gergely Kontra
5435
5436</pre></tip> </html> <Tip category="KVim">
5437<html><center>Switching between files</center> <pre> <A
5438HREF="http://vim.sf.net/tip_view.php?tip_id=195">http://vim.sf.net/tip_view.php?tip_id=195</A><BR>
5439
5440When you edit multiple files, you often need to change windows. You can set
5441up vim in windows and gvim to switch between windows with the commonly used
5442Ctrl-Tab and Ctrl-Shift-Tab The mappings nmap &lt;C-Tab&gt; &lt;C-w&gt;w
5443nmap &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
5446Completion in Shell Scripts</center> <pre> <A
5447HREF="http://vim.sf.net/tip_view.php?tip_id=196">http://vim.sf.net/tip_view.php?tip_id=196</A><BR>
5448
5449In shell scripts, you often define environment variables for diff directory
5450names. i.e. JAVA_HOME=/opt/java/jdk1.4 PATH=/usr/local/bin:/bin....
5451
5452Normally typing Ctrl-X Ctrl-F is used to complete FileName under cursor.
5453But this does not work if used on lines given above. This is because vim
5454treats "=" sign as a valid filename character. Since the actual possibility
5455of "=" being in any filename is very less, this char can be removed from
5456the list of valid filename char.
5457
5458set isfname-==
5459
5460putting the above line in .vimrc will remove "=" from the list of valid
5461filename 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
5465file in already running vim from elsewhere</center> <pre> <A
5466HREF="http://vim.sf.net/tip_view.php?tip_id=197">http://vim.sf.net/tip_view.php?tip_id=197</A><BR>
5467
5468If you want edit new file, and you want do it in alrady running vim,
5469instead of launching another instance, you may use --remote argument:
5470
5471gvim first_file gvim --remote +split first_file
5472
5473:he --remote It requires X windows (but works in terminal version of vim
5474there too) or MS windows and built-in client-server mechanism. If there are
5475several instances of vim already running, you may choose to which you talk
5476using --servername :help --servername
5477
5478</pre></tip> </html> <Tip category="KVim"> <html><center>Pasting
5479code with syntax coloring in emails</center> <pre> <A
5480HREF="http://vim.sf.net/tip_view.php?tip_id=198">http://vim.sf.net/tip_view.php?tip_id=198</A><BR>
5481
5482When sending code snippets or diffs to your colleagues either for code review
5483or for something else as email, how nice and clear it will be if you can
5484paste it with the Vim syntax highlighting? I am sure they will be impressed
5485and feel much easier to read the code. It is also very easy and fast (once
5486you practice it) to do this.
5487
5488This probably works only on windows and requires you to use Internet Explorer
5489and an email client that understand RTF content coming from clipboard, such
5490as Outlook or Outlook Express. At least that would make the process faster. I
5491haven'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
5494use dark background for GVim (like me), then I would suggest you to change
5495your color scheme temporarily to something else that has a white background
5496or 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
5501prompt 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
5506want 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
5512it with syntax coloring in any application that accepts RTF content from
5513clipboard, including Outlook or Outlook Express mail composing window.
5514
5515</pre></tip> </html> <Tip category="KVim"> <html><center>maximize
5516window and return to previous split structure</center> <pre> <A
5517HREF="http://vim.sf.net/tip_view.php?tip_id=199">http://vim.sf.net/tip_view.php?tip_id=199</A><BR>
5518
5519Say you have layed out a complex window split structure, and want to
5520temporarily open 1 window with max dimensions, but don't want to lose your
5521split structure. The following function and mappings let you toggle between
5522the split windows and on window maximized. The mappings prevent the default
5523behavior of calling :only and losing your finely tuned splits.
5524
5525Put this bit in your vimrc file, change mappings if you don't want to override
5526the defaults:
5527
5528nnoremap &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
5530MaximizeToggle ()&lt;CR&gt;
5531
5532function! 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
5541endfunction
5542
5543</pre></tip> </html> <Tip category="KVim"> <html><center>Bouncing
5544Parentheses (during insertion)</center> <pre> <A
5545HREF="http://vim.sf.net/tip_view.php?tip_id=200">http://vim.sf.net/tip_view.php?tip_id=200</A><BR>
5546
5547When one is inserting parentheses some folks like to see the cursor bounce
5548off 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
5554Adjust 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
5558HREF="http://vim.sf.net/tip_view.php?tip_id=201">http://vim.sf.net/tip_view.php?tip_id=201</A><BR>
5559
5560Use this tip if you need to discover the meaning of life, the universe
5561and everything.
5562
5563Simply do: :h 42
5564
5565</pre></tip> </html> <Tip category="KVim">
5566<html><center>debugging window autocommands</center> <pre> <A
5567HREF="http://vim.sf.net/tip_view.php?tip_id=202">http://vim.sf.net/tip_view.php?tip_id=202</A><BR>
5568
5569Don't know how people debug autocommands, but I just found out that you can
5570debug (at least) those that result due to window close by just doing a debug
5571quit, i.e.,
5572
5573:debug quit
5574
5575Vim 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
5579HREF="http://vim.sf.net/tip_view.php?tip_id=203">http://vim.sf.net/tip_view.php?tip_id=203</A><BR>
5580
5581I find this a very useful command to use. Add the below 4 lines to your vimrc.
5582Then instead of "make" use "Make".
5583
5584" Command Make will call make and then cwindow which " opens a 3 line error
5585window 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
5589mappings for using cscope with vim.</center> <pre> <A
5590HREF="http://vim.sf.net/tip_view.php?tip_id=204">http://vim.sf.net/tip_view.php?tip_id=204</A><BR>
5591
5592These mappings can make using cscope a fun. You can copy the word under the
5593cursor 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
5599find s &lt;C-R&gt;=@m&lt;CR&gt;&lt;CR&gt; map &lt;C-F5&gt; :cscope find
5600c &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
5605HREF="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
5611others. " "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
5625file and put it into your plugin directory, "or write those few commands
5626into a file end issue a command :so %
5627
5628"how to use this little function: "let's suppose you have a simple
5629column 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
5631line 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
5636number, so submatch(0) returns only a number and "the text remains unchanged
5637after 'substitute'
5638
5639"for starter on the wonderfull world of regular expressions see: :help
5640usr_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
5652is the most powerfull command you can find in a text editor. "(with the
5653possible exception of :global command)
5654
5655</pre></tip> </html> <Tip category="KVim"> <html><center>Highlight
5656doubled word errors in text</center> <pre> <A
5657HREF="http://vim.sf.net/tip_view.php?tip_id=206">http://vim.sf.net/tip_view.php?tip_id=206</A><BR>
5658
5659An error I sometimes make while working on a LaTeX file is the repetition of
5660a word as in "the the". Most often, such doubled words come about through
5661a careless edit. Doubled words are hard to spot when the first word of the
5662doubled pair is the last word on one line, and the second word of the pair
5663is the the first word on the next line. There is an example of such an error
5664in the last sentence. Vim's syntax mechanism can be used to highlight doubled
5665words as an error.
5666
5667To obtain this highlighting for TeX and LaTeX files, place the following
5668two lines:
5669
5670 syn match texDoubleWord "\c\&lt;\(\a\+\)\_s\+\1\&gt;" hi def link
5671 texDoubleWord Error
5672
5673in a file called tex.vim in the directory that shows up last in your
5674runtimepath (:set runtimepath? to check). This will often be either
5675~/.vim/after/syntax/tex.vim or $VIM/vimfiles/after/syntax/tex.vim
5676
5677The same effect can be obtained for files of a different filetype, say html,
5678by putting the same lines in a file called html.vim in the same location.
5679
5680For 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
5684databases with Vim/Perl/DBI</center> <pre> <A
5685HREF="http://vim.sf.net/tip_view.php?tip_id=207">http://vim.sf.net/tip_view.php?tip_id=207</A><BR>
5686
5687Perl's Data-Base-Independent (DBI) module provides programming language
5688level access to a lot of databases.
5689
5690Vim hosts an embedded Perl interpreter. So it is only a matter of some key
5691strokes to interactively issue DB commands from within Vim or to search,
5692edit, 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
5694patterns in Vim functions or Perl modules.
5695
5696Prerequisites: 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
5698database driver has to be installed with Perl in order to execute these
5699Vim 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
5708tables;");
5709
5710" insert the list of tables into the current buffer's top: :perl
5711$curbuf-&gt;Append(0, map($_-&gt;[0], @{$result}));
5712
5713In MySql the command "show tables;" results in a list of table names. Inserted
5714into a Vim buffer this results in one line per table.
5715
5716You can find more on my web page <A
5717HREF="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
5720the display of buffers in the buffers menu</center> <pre> <A
5721HREF="http://vim.sf.net/tip_view.php?tip_id=208">http://vim.sf.net/tip_view.php?tip_id=208</A><BR>
5722
5723If you use the buffers menu, here's where you can change how the buffernames
5724are displayed:
5725
5726menu.vim, function s:BMMunge
5727
5728OLD: let name2 = name2 . ' (' . a:bnum . ')'
5729
5730displays:
5731
5732 .vimrc (1) menu.vim (2)
5733
5734NEW: let name2 = '&' . a:bnum . '. ' . name2
5735
5736displays
5737
5738 1. .vimrc 2. menu.vim
5739(with the 1 and the 2 underlined)
5740
5741which is more useful, because you can (almost) always pick the buffer you
5742want with one keystroke, the buffernumber, until you get to buffer 10 anyway.
5743
5744Roger
5745
5746</pre></tip> </html> <Tip category="KVim">
5747<html><center>backtracking your movements in a file</center> <pre> <A
5748HREF="http://vim.sf.net/tip_view.php?tip_id=209">http://vim.sf.net/tip_view.php?tip_id=209</A><BR>
5749
5750If you are jumping from one line to another a lot. You may find the "Ctrl-o"
5751command handy. Usually u can set markers in a buffer to keep track of your
5752movements. but Ctrl-o makes it even easier. it takes you back sequentially
5753to all your previous cursor locations in a buffer. just press ctrl-o in
5754normal mode and u will go to your last cursor position.
5755
5756Njoy
5757
5758</pre></tip> </html> <Tip category="KVim">
5759<html><center>compiling the actual file with gcc</center> <pre> <A
5760HREF="http://vim.sf.net/tip_view.php?tip_id=210">http://vim.sf.net/tip_view.php?tip_id=210</A><BR>
5761
5762if you use set makeprg=gcc\ -o\ %&lt;\ % in your .vimrc, and your actual
5763file is file.c, then :make will compile file.c with the output file. (gcc
5764file.c -o file).
5765
5766</pre></tip> </html> <Tip category="KVim">
5767<html><center>Rotate color themes</center> <pre> <A
5768HREF="http://vim.sf.net/tip_view.php?tip_id=211">http://vim.sf.net/tip_view.php?tip_id=211</A><BR>
5769
5770This tip is for those who like to change their vim color themes pretty often.
5771I like different themes just for a change in my work environment. To achieve
5772this just add the following to your .vimrc or _vimrc file.
5773
5774let 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
5788endfunction
5789
5790Change 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#"
5792You can add your favorite color themes in this string so that you can rotate
5793between them. Just make sure that any string that you add is in between the #
5794as shown above. Just follow the format above and things will work.
5795
5796Then assign a key to roate the theme. map &lt;F8&gt; :execute
5797RotateColorTheme()
5798
5799Dunno if there are better ways to do the same. I just did a "help eval"
5800and wrote the above.
5801
5802</pre></tip> </html> <Tip category="KVim"> <html><center>Setting
5803file attributes without reloading a buffer</center> <pre> <A
5804HREF="http://vim.sf.net/tip_view.php?tip_id=212">http://vim.sf.net/tip_view.php?tip_id=212</A><BR>
5805
5806While creating scripts and others executable files with Vim it is needed to
5807set 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
5809that Vim will notice attribute changes and prompt you to reload a file. If
5810you do this, your undo history for the file will be lost.
5811
5812The following function facilitate changing executable attributes without
5813reloading a buffer. Thanks to Bram for the algorithm for this function.
5814
5815fun! SetExecutableBit()
5816 let fname = expand("%:p") :checktime exec "au FileChangedShell
5817 " . fname . " :echo" :silent !chmod a+x % :checktime exec
5818 "au! FileChangedShell " . fname
5819endfun
5820
5821" Create an EX command that will call the function. command -nargs=0 Xbit
5822call SetExecutableBit()
5823
5824Now 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
5828HREF="http://vim.sf.net/tip_view.php?tip_id=213">http://vim.sf.net/tip_view.php?tip_id=213</A><BR>
5829
5830I needed this one when I was editing an ldif file:
5831
5832I needed to delete all lines containing "profile":
5833
5834:g/profile/d
5835
5836very handydandy
5837
5838</pre></tip> </html> <Tip category="KVim">
5839<html><center>Current buffer based menus</center> <pre> <A
5840HREF="http://vim.sf.net/tip_view.php?tip_id=214">http://vim.sf.net/tip_view.php?tip_id=214</A><BR>
5841
5842If you have different menus for different filetypes, and you want to have
5843only the menu relevant to current buffer displayed, you can use this approach:
5844
5845in .vimrc: au BufEnter * if exists('b:BuffEnter')|exec b:BuffEnter|endif au
5846BufLeave * if exists('b:BuffEnter')|exec b:BuffLeave|endif
5847
5848In appropriate ftplugin/?.vim, there are assigned commands to create or
5849destroy the menus - here typed in directly, may be of course call to a
5850menu-generating function or whatever.
5851
5852let b:BuffEnter='amenu C.added ...' let b:BuffLeave='unmenu! C|unmenu C'
5853
5854</pre></tip> </html> <Tip category="KVim"> <html><center>Edit
5855configuration files for a filetype</center> <pre> <A
5856HREF="http://vim.sf.net/tip_view.php?tip_id=215">http://vim.sf.net/tip_view.php?tip_id=215</A><BR>
5857
5858When you open a file, vim may load several scripts to customize itself for
5859editing the file type the file is associated with (for example a file "test.c"
5860is associated with the filetype "c"). Such configurations include the setting
5861of syntax highlighting colors (:help syntax) and support for indentation
5862(:help filetype-indent-on). When you start to override these files for
5863yourself, it can sometimes be confusing, which file sets a specific option.
5864The following function can be used, to edit the configuration files which
5865are associated with a specific filename. It open a buffer for all files which
5866get loaded. If I invoke it with ':call Edit_ft_conf("test.c")', for example,
5867I 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
5874Here 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
5879windows reflects the order of script loading (but "file" is " the topmost
5880window) 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
5898endfun
5899
5900</pre></tip> </html> <Tip category="KVim"> <html><center>calculate
5901equations from within vim</center> <pre> <A
5902HREF="http://vim.sf.net/tip_view.php?tip_id=216">http://vim.sf.net/tip_view.php?tip_id=216</A><BR>
5903
5904The following map and function calculates equations using the program 'bc'
5905(found on most linux systems, available for most systems). Visually select the
5906equation 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
5908is echoed as a message. The code to put in a vimrc and source is at the end.
5909
5910Equations can span multiple lines, and the full bc syntax is probably
5911supported. Additionally, sin (), cos (), etc, are transformed into the
5912names used by bc (s () c (), etc).
5913
5914Here are some example lines:
5915
59162 * sqrt (2) =
5917
59183 * (2 - 1) + 4.0 ^ 6 =
5919
59204 / 3 =
5921
59223 +
5923 4 -
5924 2 * (1 / (3 + 2)) =
5925
5926define rad (x) {
5927 return (x / 180) * 4 * atan (1)
5928} cos (rad (45)) =
5929
5930Select each of these in turn (continguous non-blank lines, and hit ;bc for
5931each), and this is what you get: 2 * sqrt (2) = 2.82842712474619009760
5932
59333 * (2 - 1) + 4.0 ^ 6 = 4099.000000
5934
59354 / 3 = 1.33333333333333333333
5936
59373 +
5938 4 -
5939 2 * (1 / (3 + 2)) = 6.60000000000000000000
5940
5941define rad (x) {
5942 return (x / 180) * 4 * atan (1)
5943} cos (rad (45)) = .70710678118654752440
5944
5945Fun, no? Here is the code you need to put in your vimrc file:
5946
5947vnoremap ;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
5972endfunction
5973
5974</pre></tip> </html> <Tip category="KVim"> <html><center>Translate
5975&#nnn; in html source to readable ascii</center> <pre> <A
5976HREF="http://vim.sf.net/tip_view.php?tip_id=217">http://vim.sf.net/tip_view.php?tip_id=217</A><BR>
5977
5978I found a website *cough*Tivoli.com*cough* that likes to obfuscate some of
5979its help file web pages using &#nnn; instead of normal ascii. If you load
5980the source with Vim (in Opera you can just designate Vim as your source
5981viewing program), you can :so the following code to make it readable.
5982
5983let 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
5991endwhile
5992
5993Disclaimer: I hacked this together in about 10 minutes (or possibly longer :).
5994It worked suitably for the website I wrote it for (or possibly "against" :).
5995Your Milage May Vary.
5996
5997See :help eval, :help silent, :help exec, :help :s
5998
5999</pre></tip> </html> <Tip category="KVim"> <html><center>Check
6000for comments, independent of the filetype</center> <pre> <A
6001HREF="http://vim.sf.net/tip_view.php?tip_id=218">http://vim.sf.net/tip_view.php?tip_id=218</A><BR>
6002
6003For some scripts it might be useful to detect, whether a specific position
6004in a buffer is inside of a comment or not. Syntax highlighting can save us
6005the work for parsing the comments ourselves.
6006
6007The command
6008 :echo synIDattr(synIDtrans(synID(line("."), col("."), 0)), "name")
6009echoes the group used for *highlighting* the character at the current
6010cursor position, see ':help synIDtrans()'. It will usually be "Comment"
6011if the cursor is inside of a comment, so
6012 synIDattr(synIDtrans(synID(line("."), col("."), 0)), "name") == "Comment"
6013detects, independent of the filetype (which have their own group 'names'
6014for comments), if the cursor is inside a comment or not. The expression
6015 synIDattr(synIDtrans(synID(line("."), col("."), 0)), "name") =~
6016 'Comment\|Constant\|PreProc'
6017will detect additionally, if the cursor is inside of a string or some
6018preprocessor statement.
6019
6020</pre></tip> </html> <Tip category="KVim"> <html><center>make
6021from command line, open vim on errors</center> <pre> <A
6022HREF="http://vim.sf.net/tip_view.php?tip_id=219">http://vim.sf.net/tip_view.php?tip_id=219</A><BR>
6023
6024A simple alias (*csh) or shell function (bash) will let you run make from your
6025shell, then automatically open vim or gvim on the errors (if there were any):
6026
6027csh or tcsh:
6028
6029alias Make 'make \!* |& tee make.errors || gvim -q make.errors -c :copen'
6030
6031bash:
6032
6033Make () { command make "$@" |& tee make.errors || gvim -q make.errors -c
6034:copen ; }
6035
6036If you use vanilla sh or ksh or even cmd.exe, you can probably do the same -
6037add 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
6041HREF="http://vim.sf.net/tip_view.php?tip_id=220">http://vim.sf.net/tip_view.php?tip_id=220</A><BR>
6042
6043This 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
6047atom 'Foo' followed by end-of-word @! Match (with zero length)
6048when the previous atom doesn't match. \k+ Match one or more
6049Keywords &gt; Match end-of-word.
6050
6051This is a kool example of using \@! in the middle of a regexp. The non-magic
6052version is: \&lt;\(foo\&gt;\)\@!\k\+\&gt;
6053
6054</pre></tip> </html> <Tip category="KVim">
6055<html><center>indenting "throws" in java</center> <pre> <A
6056HREF="http://vim.sf.net/tip_view.php?tip_id=221">http://vim.sf.net/tip_view.php?tip_id=221</A><BR>
6057
6058I want to indent java files like this:
6059
6060 int x(int y, int z)
6061 throws Exception
6062 {
6063 [...] return something;
6064 }
6065
6066By default vim will properly indent "throws" line, but following "{" will
6067not be deindented back to the method declaration.
6068
6069The 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
6073It just checks that the current line starts with "{" and the previous line
6074starts with "throws" and if that is the case, it subtracts one shiftwidth
6075from 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
6079HREF="http://vim.sf.net/tip_view.php?tip_id=222">http://vim.sf.net/tip_view.php?tip_id=222</A><BR>
6080
6081Following the normal steps of running "./configure" and "make" to build vim
6082on an HP-UX 10.20 will result in vim being linked with the termlib library.
6083This 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.
6085Consequently, vim will not display colors when used with a color terminal
6086such as a color xterm.
6087
6088One 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
6093This will cause vim to be linked with the HP-UX curses library, which does
6094support the color termcap capability codes.
6095
6096Note that the xterm that comes standard with HP-UX 10.20 does not display color
6097character attributes. To see colors when running vim in a terminal window,
6098you 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
6102HREF="http://vim.sf.net/tip_view.php?tip_id=223">http://vim.sf.net/tip_view.php?tip_id=223</A><BR>
6103
6104Suppose you want to reverse some text - I don't know why you would want to -
6105maybe you're dyslexic. Anyway, I had a need, so this mapping will reverse
6106visually selected text. Put the mapping in your vimrc or otherwise source
6107it, then visually select the word or words, and hit ;rv - really only works
6108with selections on one line:
6109
6110vnoremap ;rv c&lt;C-O&gt;:set revins&lt;cr&gt;&lt;C-R&gt;"&lt;esc&gt;:set
6111norevins&lt;cr&gt;
6112
6113</pre></tip> </html> <Tip category="KVim">
6114<html><center>Shifting blocks visually</center> <pre> <A
6115HREF="http://vim.sf.net/tip_view.php?tip_id=224">http://vim.sf.net/tip_view.php?tip_id=224</A><BR>
6116
6117I use the &lt; and &gt; commands on blocks a lot, and it has always annoyed me
6118that 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
6120with "gv". So I've cooked up two mappings that come in very handy:
6121
6122:vnoremap &lt; &lt;gv :vnoremap &gt; &gt;gv
6123
6124These mappings will reselect the block after shifting, so you'll just have
6125to 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
6128I 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
6132HREF="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
6171file under cursor after a horizontal split</center> <pre> <A
6172HREF="http://vim.sf.net/tip_view.php?tip_id=226">http://vim.sf.net/tip_view.php?tip_id=226</A><BR>
6173
6174I use the command 'gf' quite often. But with this command the current buffer
6175is hidden. To avoid that I use the following mapping :
6176
6177map gw &lt;Esc&gt;:sp %&lt;CR&gt; gf
6178
6179With 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
6183HREF="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
6186illustrate the use of it with some examples. Hope, it will be useful for
6187someone.
6188
6189Brief explanation for ":g" ------------------------- Syntax is:
6190 :[range]:g/&lt;pattern&gt;/[cmd]
6191You can think the working as, for the range (default whole file), execute
6192the colon command(ex) "cmd" for the lines matching &lt;pattern&gt;. Also,
6193for 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
6196Some examples ------------- Display context (5 lines) for all occurences of
6197a 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;
6200Delete all lines matching a pattern
6201 :g/&lt;pattern&gt;/d
6202Delete all blank lines (just an example for above)
6203 :g/^\s*$/d
6204Double space the file
6205 :g/^/pu =\"\n\" :g/^/pu _ &lt;&lt; the above one also works &gt;&gt;
6206Copy all lines matching a pattern to end of file
6207 :g/&lt;pattern&gt;/t$
6208Yank all lines matching a pattern to register 'a'
6209 0"ay0:g/&lt;pattern&gt;/y A
6210Increment the number items from current line to end-of-document by one
6211 :.,$g/^\d/exe "normal! \&lt;c-a&gt;"
6212Comment (C) lines containing "DEBUG" statements
6213 g/^\s*DEBUG/exe "norm! I/* \&lt;Esc&gt;A */\&lt;Esc&gt;"
6214A Reverse lookup for records (eg: An address book, with Name on start-of-line
6215and 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
6220Reverse a file (just to show the power of 'g')
6221 :g/^/m0
6222
6223Foot note 1: use :v to negate the search pattern Foot note 2: Some explanation
6224of 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
6231Foot 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
6236nested reply threads in emails</center> <pre> <A
6237HREF="http://vim.sf.net/tip_view.php?tip_id=228">http://vim.sf.net/tip_view.php?tip_id=228</A><BR>
6238
6239I find the following setting useful when replying to email threads that have
6240lots of lines like the following: &gt; blah &gt; &gt; blah &gt; &gt; &gt; blah
6241
6242autocmd FileType mail map &lt;F8&gt; :%g/^&gt; &gt;/d&lt;CR&gt;
6243
6244When replying to a mail and you want to remove everything except what the
6245person you are directly replying to wrote just press F8. From the example
6246above, you would just be left with &gt; blah
6247
6248What it does is simply match any line starting with &gt; &gt; and deletes it.
6249It's not perfect as sigs and other debris may remain but it takes a lot
6250of the grunt work out of replying to mails. The autocmd only maps F8 when
6251using 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
6256thing to try before asking help</center> <pre> <A
6257HREF="http://vim.sf.net/tip_view.php?tip_id=229">http://vim.sf.net/tip_view.php?tip_id=229</A><BR>
6258
6259I've seen several questions asked in the reflector which is available in the
6260help files. Yeah, I know the help is huge. But, you can try this command
6261to show a list of related topics you are trying:
6262 :he &lt;topic&gt;&lt;c-d&gt;
6263It is "some topic" followed by the key sequence Ctrl-D. For eg:
6264 :he xterm&lt;c-d&gt;
6265will show all the help topics matching xterm. Then you can do
6266completion/copy-n-paste the topic you are searching. Of course you can cycle
6267through all the topics through repeated &lt;TABS&gt;, but if the number of
6268hits are huge, it is cumbersome.
6269
6270Enjoy vimming beginners!!! -Arun
6271
6272</pre></tip> </html> <Tip category="KVim"> <html><center>copy
6273current file to another location from within vim</center> <pre> <A
6274HREF="http://vim.sf.net/tip_view.php?tip_id=230">http://vim.sf.net/tip_view.php?tip_id=230</A><BR>
6275
6276I work on jsp pages in my source tree but I have to copy the jsp files over
6277to the tomcat directory in order to view my changes.The following mapping
6278will copy the file being edited to another location.
6279
6280command Cpage silent !cp '%:p' "c:/Progra~1/Tomcat/webapps/console/pages/%"
6281
6282Explanation:
6283
6284% refers to the current buffer %:p refers to the path to the file silent
6285suppresses the command prompt window.
6286
6287Usage:
6288
6289:Cpage
6290
6291</pre></tip> </html> <Tip category="KVim">
6292<html><center>Localized color schemes</center> <pre> <A
6293HREF="http://vim.sf.net/tip_view.php?tip_id=231">http://vim.sf.net/tip_view.php?tip_id=231</A><BR>
6294
6295i frequently like to edit multiple files in the same vim session. however,
6296if i come into vim from another window i frequently hit 'i' and start typing
6297in 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
6300one way to work around this for me is to use a different color scheme
6301depending on what file i'm working on:
6302
6303au BufEnter * if (exists("b:colors_name")) | let b:current_colors=colors_name
6304| execute "colorscheme " . b:colors_name | endif
6305
6306au BufLeave * if (exists("b:current_colors")) | execute "colorscheme "
6307. b:current_colors | endif
6308
6309if you define b:colors_name with a particular color scheme name, then the
6310above autocommands will switch to that colorscheme when you enter that window
6311and will return to the original color upon departure.
6312
6313inside 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
6317JDK help for keyword at cursor</center> <pre> <A
6318HREF="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.
6322You need the winhlp32 version of the Jdk docs from this URL - <A
6323HREF="http://www.confluent.fr/javadoc/indexe.html.">http://www.confluent.fr/javadoc/indexe.html.</A><BR>
6324It is a 16mb D/L and approx 85mb unzipped!
6325
6326I 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
6329And also made a keymapping map J :!start winhlp32 -k &lt;cword&gt;
6330F:\jdk\winhelp\JDK13.HLP &lt;CR&gt;
6331
6332Trivial yes, but I find it quite useful.
6333
6334</pre></tip> </html> <Tip category="KVim"> <html><center>Some
6335tips for using Vim to write Lisp code</center> <pre> <A
6336HREF="http://vim.sf.net/tip_view.php?tip_id=233">http://vim.sf.net/tip_view.php?tip_id=233</A><BR>
6337
6338For some tips on how to use Vim for writing Lisp code, see <A
6339HREF="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)
6342Command Line tips & tricks</center> <pre> <A
6343HREF="http://vim.sf.net/tip_view.php?tip_id=234">http://vim.sf.net/tip_view.php?tip_id=234</A><BR>
6344
6345Hi VIMMERs
6346
6347These tips save me wearing out my delicate little fingers with unnecessary
6348keystrokes. 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
6353alias -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
6356actually in a little shell script call ed vg where the keyword is passed as
6357parameter $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
6362button) alias -x xew='`l\s -t *.pl | head -1 `'
6363
6364Cheers zzapper
6365
6366</pre></tip> </html> <Tip category="KVim"> <html><center>Toggle
6367highlight word under cursor, to find cursor.</center> <pre> <A
6368HREF="http://vim.sf.net/tip_view.php?tip_id=235">http://vim.sf.net/tip_view.php?tip_id=235</A><BR>
6369
6370When the screen has scrolled such as during a search, it may be difficult to
6371find the cursor. :help %# explains the pattern one can use to highlight the
6372word around the cursor, which gives a bigger target to look for on the screen.
6373I have this in my .vimrc:
6374
6375function 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
6381endfunction map &lt;C-K&gt; :call VIMRCWhere()&lt;CR&gt;
6382
6383This means that in "normal" mode ctrl-k will toggle the highlight. Todo is
6384a hightlight group whch is particularly easy to see. For further information
6385see ":help s:", ":help match", ":help exists()" and ":help funtion".
6386
6387</pre></tip> </html> <Tip category="KVim"> <html><center>Menu
6388for inserting special characters</center> <pre> <A
6389HREF="http://vim.sf.net/tip_view.php?tip_id=236">http://vim.sf.net/tip_view.php?tip_id=236</A><BR>
6390
6391First, thanks for the script printascii.vim.
6392
6393When looking at the ascii table, I found some characters I'd like to have
6394inserted when editing. Add the following lines in your _gvimrc and you
6395can select them via menu. (change the names of the menu if you don't have
6396German installed or don't like my titles). I also made some abbreviations
6397to get separation lines in documentation or code files, e.g. abb dotlin
6398Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…^M
6399abb cdotlin
6400/*Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…Â…*/^M
6401abb fdotlin
6402•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••^M
6403abb cfdotlin
6404/*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/^M abb
6405dlin =======================================================================^M
6406abb cdlin
6407/*===================================================================*/^M abb
6408lin -----------------------------------------------------------------------^M
6409abb clin
6410/*-------------------------------------------------------------------*/^M abb
6411ulin _______________________________________________________________________^M
6412abb culin
6413/*___________________________________________________________________*/^M abb
6414Ulin ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯^M
6415abb cUlin
6416/*¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*/^M
6417
6418(you have to substitute ^M with CTRL_V CTRL_M or delete it)
6419
642020imenu Editieren.Sonderzeichen.open\ angle\ «
6421&lt;C-R&gt;=nr2char(171)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.open\
6422angle\ « a&lt;C-R&gt;=nr2char(171)&lt;CR&gt;&lt;ESC&gt;
642320imenu Editieren.Sonderzeichen.close\ angle\ »
6424&lt;C-R&gt;=nr2char(187)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.close\
6425angle\ » a&lt;C-R&gt;=nr2char(187)&lt;CR&gt;&lt;ESC&gt;
642620imenu Editieren.Sonderzeichen.start\ mark\ „
6427&lt;C-R&gt;=nr2char(132)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.start\
6428mark\ „ a&lt;C-R&gt;=nr2char(132)&lt;CR&gt;&lt;ESC&gt;
642920imenu Editieren.Sonderzeichen.end\ mark\ \ ”
6430&lt;C-R&gt;=nr2char(148)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.end\
6431mark\ \ ” a&lt;C-R&gt;=nr2char(148)&lt;CR&gt;&lt;ESC&gt;
643220imenu Editieren.Sonderzeichen.fat\ dot\ \ •
6433&lt;C-R&gt;=nr2char(149)&lt;CR&gt; 20nmenu Editieren.Sonderzeichen.fat\
6434dot\ \ • a&lt;C-R&gt;=nr2char(149)&lt;CR&gt;&lt;ESC&gt;
643520imenu 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;
643820imenu 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;
644120imenu 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;
644420imenu 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;
644720imenu 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
6452you prefer vertical splits</center> <pre> <A
6453HREF="http://vim.sf.net/tip_view.php?tip_id=237">http://vim.sf.net/tip_view.php?tip_id=237</A><BR>
6454
6455This is just in case there's somebody else who likes to work in a maximized
6456vim window on a high resolution desktop. If you follow good coding practice
6457and make sure your programs use only 80 characters in each row, have you
6458noticed how much space lies unused on the right?
6459
6460I find that the following settings keep me from ever seeing another horizontal
6461split, unless I specifically ask for it.
6462
6463cabbrev split vsplit cabbrev hsplit split cabbrev sta vertical sta cabbrev
6464help 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
6501endfunction 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
6505nosplitbelow&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
6508command with ranges :-) ;noremap : :vertical&lt;Space&gt;
6509
6510; EOF
6511
6512</pre></tip> </html> <Tip category="KVim"> <html><center>Very
6513basic session persistence</center> <pre> <A
6514HREF="http://vim.sf.net/tip_view.php?tip_id=238">http://vim.sf.net/tip_view.php?tip_id=238</A><BR>
6515
6516I use the following code in my plugins dir to ease session persistance. If
6517I want my session to persist I use :mks! and then whenever I open the
6518Session.vim file, my session is restored. If I am working from a restored
6519session and I close VIM, the session is saved automatically. Drawback is
6520that 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
6532HREF="http://vim.sf.net/tip_view.php?tip_id=239">http://vim.sf.net/tip_view.php?tip_id=239</A><BR>
6533
6534You can make Vim scroll the text using the shifted up/down arrows, sort
6535of like your browser (except with shifted keys :), by mapping Shift-Up to
6536Ctrl-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
6540Shift-Down will then scroll down (like moving a scroll-bar down, or like
6541moving a cursor at the bottom of a window down), and Shift-Up will then
6542scroll up (like moving a scroll-bar up, etc).
6543
6544If you'd rather think about the text moving down/up instead of the cursor
6545moving up/down, you can of course swap the mappings.
6546
6547If you normally use j and k for cursor movement, and rarely use the arrow
6548keys, you can map the arrow keys directly, in which case I'd probably map
6549the 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
6554See :help ctrl-e, :help ctrl-y, and :help key-mapping.
6555
6556See also :help i_ctrl-o and :help map-modes for how to set up these mappings
6557for 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
6560visual 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
6565HREF="http://vim.sf.net/tip_view.php?tip_id=240">http://vim.sf.net/tip_view.php?tip_id=240</A><BR>
6566
6567Xemacs has a hide all function which can make all the function in your C file a
6568fold and close them. And here is something small to achieve similiar under Vim.
6569
6570func! HideAll()
6571 syn region myFold start="{" end="}" transparent fold syn sync fromstart
6572 set foldnestmax=1 set foldmethod=syntax
6573endfunc
6574
6575amenu 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
6579HREF="http://vim.sf.net/tip_view.php?tip_id=241">http://vim.sf.net/tip_view.php?tip_id=241</A><BR>
6580
6581I 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
6583make them fade to black....bg=black fg=black
6584
6585au 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
6590au BufRead,BufNewfile * syn match fmrkr '"*{{{\|"*}}}'
6591 \ containedin=vimLineComment contained |
6592 \ hi fmrkr term=NONE guibg=black guifg=black \
6593 ctermbg=black ctermfg=black
6594
6595They both accomplish the same thing, but with different methods, so simply pick
6596one and see those annoying (at least to me) markers fade away. I just tried
6597it out with vim files, but you can easily modify it for any other filetypes.
6598
6599Thanks to Colin's lead with ':help c-syntax' for the 1st au. Thanks to
6600Benji's lead with ':help containedin' for the 2nd au. Understanding most
6601of the syntax.txt document file would also be helpful.
6602
6603To figure out what highlighting group the Marker is in, I would suggest
6604using Chip's vimtip#99.
6605
6606Happy Vimming!
6607
6608</pre></tip> </html> <Tip category="KVim">
6609<html><center>The power of "\_" in reg-ex</center> <pre> <A
6610HREF="http://vim.sf.net/tip_view.php?tip_id=242">http://vim.sf.net/tip_view.php?tip_id=242</A><BR>
6611
6612One of the most uncelebrated feature of vim 6.0 is the ability to span a
6613search across multiple lines.
6614
6615\_^ maps a begining of line anywhere in search pattern. \_$ ---"----- end
6616----------------------"-------------------------. \_s ---"------ space
6617------------"------------------------- .
6618
6619e.g /{\_s will map all white spaces and new-line chars after a "{"
6620
6621The \_ can be appended to other objects as well. such as \_U, \_L, \_. (this
6622one's risky) .
6623
6624See :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
6628HREF="http://vim.sf.net/tip_view.php?tip_id=243">http://vim.sf.net/tip_view.php?tip_id=243</A><BR>
6629
6630We're trying to develop txt2pdf.vim <A
6631HREF="http://vim.sourceforge.net/scripts/script.php?script_id=283 on
6632Win.">http://vim.sourceforge.net/scripts/script.php?script_id=283
6633on Win.</A><BR> It's a very simple module to save the
6634current file and convert it to PDF using our txt2pdf tool <A
6635HREF="http://www.sanface.com/txt2pdf.html">http://www.sanface.com/txt2pdf.html</A><BR>
6636On our Windows 2000 we've developed it. It works good. Today we've tested
6637the module on Linux. Surprise: it doesn't work. Default Win Vim configure
6638save on Win text in Win way: EOL \r\n. A Vim module made in this way can't
6639work on Linux (probably on every Unix OS). If you want to make a Vim module
6640on Win and you want it can work also on Unix (we hope the same rula can work
6641also on different OS) you've to save the Vim module with Unix EOL (\n).
6642
6643Please send us (sanface@sanface.com) your notes about other OS (e.g. OpenVMS).
6644
6645</pre></tip> </html> <Tip category="KVim"> <html><center>Ask
6646vim where an option was set.</center> <pre> <A
6647HREF="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,
6651an option might be set in the system vimrc file, in a personal vimrc file,
6652in a plugin (global or local), or interactively. Vim will tell you where
6653the current value was set if you ask:
6654
6655:verbose set history?
6656
6657will 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
6660with Unicode (platform-independent)</center> <pre> <A
6661HREF="http://vim.sf.net/tip_view.php?tip_id=245">http://vim.sf.net/tip_view.php?tip_id=245</A><BR>
6662
6663Here are the main options you will want to set if you want to work with
6664Unicode files in (g)vim (see at bottom what help tags to look for)
6665
6666if 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
6694else
6695 echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"
6696endif
6697
6698In "replace" mode, one utf character (one or more data bytes) replaces one
6699utf character (which need not use the same number of bytes) In "normal" mode,
6700ga shows the character under the cursor as text, decimal, octal and hex; g8
6701shows 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
6710Unicode can be used to create html "body text", at least for Netscape 6 and
6711probably 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
6714Gvim will display it properly if you have the fonts for it, provided that
6715you set 'guifont' to some fixed-width font which has the glyphs you want
6716to use (Courier New is OK for French, German, Greek, Russian and more,
6717but I'm not sure about Hebrew or Arabic; its glyphs are of a more "fixed"
6718width than those of, e.g. Lucida Console: the latter can be annoying if you
6719need bold Cyrillic writing).
6720
6721see:
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
6726Happy Vimming ! Tony.
6727
6728</pre></tip> </html> <Tip category="KVim"> <html><center>Working
6729with Unicode (the same, rewritten for legibility)</center> <pre> <A
6730HREF="http://vim.sf.net/tip_view.php?tip_id=246">http://vim.sf.net/tip_view.php?tip_id=246</A><BR>
6731
67321. 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
67362. What to do (These are *examples*. Modify them to suit your work
6737environment.) ------------- 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
6741else
6742 echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"
6743endif
6744
67453. What the above does ---------------------- * has("multi_byte") checks if
6746you have the right options compiled-in. If you haven't got what it takes,
6747it's no use trying to use Unicode.
6748
6749* 'encoding' sets how vim shall represent characters internally. Utf-8 is
6750necessary 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
6754to same as 'encoding'. Or you may want to set one of the ucs encodings, It
6755might make the same disk file bigger or smaller depending on your particular
6756mix of characters. Also, IIUC, utf-8 is always big-endian (high bit first)
6757while ucs can be big-endian or little-endian, so if you use it, you will
6758probably need to set 'bomb" (see below).
6759
6760* 'bomb' (boolean): if set, vim will put a "byte order mark" at the start
6761of ucs files. This option is irrelevant for most non-ucs files (utf-8,
6762iso-8859, etc.)
6763
6764* 'termencoding' defines how your keyboard encodes what you type. The value
6765you put there will depend on your locale: iso-8859-15 is Latin1 + Euro currency
6766sign, but you may want something else for, say, an Eastern European keyboard.
6767
6768* 'fileencodings' defines the heuristic to set 'fileencoding' (local to buffer)
6769when reading an existing file. The first one that matches will be used (and,
6770IIUC, if there is no match, Vim falls back on Latin1). Ucs-bom is "ucs with
6771byte-order-mark"; it must not come after utf-8 if you want it to be used.
6772
67734. Additional remarks --------------------- * In "replace" mode, one utf
6774character (one or more data bytes) replaces one utf character (which need
6775not use the same number of bytes)
6776
6777* In "normal" mode, ga shows the character under the cursor as text, decimal,
6778octal 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
6790probably 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
6794that you set 'guifont' to some fixed-width font which has the glyphs you
6795want to use (Courier New is OK for French, German, Greek, Russian and more,
6796but I'm not sure about Hebrew or Arabic; its glyphs are of a more "fixed"
6797width than those of, e.g. Lucida Console: the latter can be awkward if you
6798need bold Cyrillic writing).
6799
6800Happy Vimming ! Tony.
6801
6802</pre></tip> </html> <Tip category="KVim">
6803<html><center>Preexisting code indentation</center> <pre> <A
6804HREF="http://vim.sf.net/tip_view.php?tip_id=247">http://vim.sf.net/tip_view.php?tip_id=247</A><BR>
6805
6806Using tabs as elementary unit in your code indentation has two advantages:
6807first, you may modify 'tabstop' and immediately all the indentations depths
6808are modified according to it; second, your file will be smaller.
6809
6810But how can we change some already-written code in order to convert spaces
6811to tabs. Very simple! Suppose your old code has an indentation unit of
68122 spaces :ret! 2 :x will replace every 2-spaces to one tab, independently
6813from your current tabstop value, and will save the modified file. Then,
6814if you open again the file with tabstop=2, the file will look as before but
6815it will be smaller. If you open the file with tabstop=4, the code vill have
6816a more indented look, and so on...
6817
6818Cheers!
6819
6820</pre></tip> </html> <Tip category="KVim"> <html><center>Auto-save
6821the current buffer periodically.</center> <pre> <A
6822HREF="http://vim.sf.net/tip_view.php?tip_id=248">http://vim.sf.net/tip_view.php?tip_id=248</A><BR>
6823
6824I have no idea if this was implemented in vim 5.3 or not, but you can
6825definitely do the following kludge in 6.x by using CursorHold and
6826localtime:
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
6854Obviously, you should get rid of the else portion once you're certain
6855that this does indeed do what you wanted.
6856
6857The thing to note is that the CursorHold will only fire after
6858'updatetime' milliseconds of inactivity have elapsed. So, if you type
6859rapidly for one and a half minutes non-stop, it won't actually save
6860anything until you STOP activity long enough. This may be what you want
6861anyway because it won't interrupt your activity with a forced save.
6862
6863The actual save-delay can be changed from '60' to another number (in seconds)
6864or a variable or anything like that. This entire functionality can be easily
6865wrapped 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
6869insert #if 0 - #endif around block of code</center> <pre> <A
6870HREF="http://vim.sf.net/tip_view.php?tip_id=249">http://vim.sf.net/tip_view.php?tip_id=249</A><BR>
6871
6872One of my favorite macros that I use in vim (and vi) inserts a #if 0 #endif
6873sandwich around a block of code. I always map this to the 2 key sequence ;'
6874which is the semi-colon followed by the single quote. Look at your keyboard,
6875you will notice these keys are adjacent to one another. I like this mapping
6876because it's very fast, my fingers easily roll from one key to the next,
6877obviously YMMV.
6878
6879To use this mapping, go to the line of code that you want the '#if 0' to be
6880on, type ma to mark this line with the marker a, then move to the line that
6881should 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
6890HREF="http://vim.sf.net/tip_view.php?tip_id=250">http://vim.sf.net/tip_view.php?tip_id=250</A><BR>
6891
6892If you like to see your files in fullscreen, and you have to edit more files,
6893you can do the following. * Use only one window * Open further files with :e *
6894type :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.
6896Now to switch between windows, you can press Alt-Up, and Alt-Down (Just in
6897the GUI, if you use console, don't use Alt key) Another idea is to map them
6898to 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
6902HREF="http://vim.sf.net/tip_view.php?tip_id=251">http://vim.sf.net/tip_view.php?tip_id=251</A><BR>
6903
6904If you try to impose any sort of alignment on your preprocessor directives,
6905rather 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
6907the correct alignment to edit code.
6908
6909inoremap &lt;buffer&gt; #en
6910X&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
6912I am reasonably sure this is insensitive to vim options...
6913
6914</pre></tip> </html> <Tip category="KVim"> <html><center>python
6915script to align statements</center> <pre> <A
6916HREF="http://vim.sf.net/tip_view.php?tip_id=252">http://vim.sf.net/tip_view.php?tip_id=252</A><BR>
6917
6918i know there's some awk scripts out there that do the same thing, and if i
6919were a real trooper i would have written this in vims internal language but...
6920
6921i wrote a python script to align statements.
6922
6923i put this in my .vimrc: map L :!lineUp.py&lt;cr&gt; " of course lineUp.py
6924is somewhere in my path
6925
6926and i have this python file somewhere in my path: <A
6927HREF="http://ophinity.com/res/dotFiles/lineUp.py">http://ophinity.com/res/dotFiles/lineUp.py</A><BR>
6928
6929so now i can just pipe the offending lines thru my code: :5, 10 !lineUp.py
6930or using the mapping above, visually select the lines and press 'L'
6931
6932</pre></tip> </html> <Tip category="KVim"> <html><center>The
6933power of | (v75|r- actually...)</center> <pre> <A
6934HREF="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|"
6937will place your cursor on column 75 of the current line.
6938
6939That in itself is pretty handy at times, but some true power arises when
6940used in conjuction with visual mode and replace. Or you could just say a
6941sneaky trick :)
6942
6943v75|r- will repace from the cursor to the end of line with '-' *breakdown*
6944v to turn on visual mode 75 for the count | *bar* to goto column r to enter
6945repace - to specify the char to replace.
6946
6947A handy and quick way to make a noticable section of your code (or whatever).
6948
6949A 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
6971Have 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
6975HREF="http://vim.sf.net/tip_view.php?tip_id=254">http://vim.sf.net/tip_view.php?tip_id=254</A><BR>
6976
6977This code fragment is suitable to drop into DrChip's CStubs.
6978After much searching I was unable to find a tip nor script
6979number to referance, I believe where I found Dr. Chip's CStubs originally : <A
6980HREF="http://users.erols.com/astronaut/vim/vimscript/drcstubs.vim">http://users.erols.com/astronaut/vim/vimscript/drcstubs.vim</A><BR>
6981Thank you Dr. Chip! (=
6982
6983If you have ever wanted to match parts of a word you may have considered
6984something like: if wrd == "re" || wrd == "ret" || wrd == "retu" || wrd ==
6985"retur"
6986 "do something
6987
6988Althought the above works well enough it is a pain to maintain and add new
6989words (not to mention its just a touch messy ;) )
6990
6991A more elegant (and easier to use I believe) method would be to use \%[]
6992as part of a pattern.
6993
6994For 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
6998require to match \\%[tur] = optionally match chars bewteen the braces,
6999i.e. 't', 'tu' or 'tur' \\&gt; = end of word
7000
7001So, we can use this as a pattern for match like so (In DrChip's CStubs)
7002
7003elseif match(wrd, "\\&lt;re\\%[tur]\\&gt;") &gt; -1
7004 exe "norm! bdWireturn\&lt;Esc&gt;"
7005
7006Which, I think, is a little better than the longer alternative: " vs elseif
7007wrd == "re" || wrd == "ret" || wrd == "retu" || wrd == "retur"
7008 exe "norm! bdWireturn\&lt;Esc&gt;"
7009
7010Just 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
7014HREF="http://vim.sf.net/tip_view.php?tip_id=255">http://vim.sf.net/tip_view.php?tip_id=255</A><BR>
7015
7016This definitely work on linux and there is probably some windows equivalent.
7017I've started working with tomcat and many many .jsp files. I find this
7018trick to be very helpful.
7019
7020find -name '*.jsp' -printf '%f\t%P\t1\n' |sort &gt; jsp.tags
7021
7022This will create a file called jsp.tags with tag entries for each .jsp file.
7023Within Vim I use
7024
7025:set tags+=jsp.tags
7026
7027Now I can to simple :tag file.jsp to quickly switch b/w the many, many
7028.jsp files.
7029
7030One important note. The utility sort will use the value of LC_COLLATE to sort
7031according to your locale. This will give Vim issues. So try "LC_COLLATE=C
7032sort" instead of plain "sort"
7033
7034</pre></tip> </html> <Tip category="KVim"> <html><center>Opening
7035current Vim file in your Windows browser</center> <pre> <A
7036HREF="http://vim.sf.net/tip_view.php?tip_id=256">http://vim.sf.net/tip_view.php?tip_id=256</A><BR>
7037
7038Hi Vimmers
7039
7040open current file in browser
7041
7042map ,f :update&lt;CR&gt;:silent !start c:\progra~1\intern~1\iexplore.exe
7043file://%:p&lt;CR&gt;
7044
7045open http link under cursor in your browser
7046
7047map ,i :update&lt;CR&gt;: !start c:\progra~1\intern~1\iexplore.exe
7048&lt;cWORD&gt;&lt;CR&gt;
7049
7050Note use of cWORD (not cword) meaning OUTER Word
7051
7052Works for me in XP & 98 (Original came from a posting by Ralf Arens)
7053
7054zzapper
7055
7056</pre></tip> </html> <Tip category="KVim">
7057<html><center>fast page up/down.</center> <pre> <A
7058HREF="http://vim.sf.net/tip_view.php?tip_id=257">http://vim.sf.net/tip_view.php?tip_id=257</A><BR>
7059
7060i discovered a cool way to move between pages of the same document in vim
70616.1. press a number in -normal mode- and the page up/down. the document
7062will move with that number of pages up/down.if the number is greater that
7063the nr of pages, document will move to begin/end of file. i didn't test it
7064on other version.
7065
7066</pre></tip> </html> <Tip category="KVim"> <html><center>how
7067long is the current word?</center> <pre> <A
7068HREF="http://vim.sf.net/tip_view.php?tip_id=258">http://vim.sf.net/tip_view.php?tip_id=258</A><BR>
7069
7070ever wondered how long the current word is? this can be quite useful when
7071editing data files. simply add the following to your .vimrc
7072
7073nmap &lt;C-_&gt; :echo 'word' expand("&lt;cword&gt;") ' wordlen ='
7074strlen(expand("&lt;cword&gt;"))&lt;CR&gt;
7075
7076and it will tell you the word under the cursor, and how long it is.
7077
7078and for things that arent words, this addition to your .vimrc works on
7079sections of a line that have been hightligted in visual mode
7080
7081vmap &lt;C-_&gt; "-y:echo 'word' @- ' wordlen =' strlen(@-)&lt;CR&gt;
7082
7083again you see the "word", and its length this may also work on vim 5.x,
7084but i havent checked to make sure.
7085
7086</pre></tip> </html> <Tip category="KVim"> <html><center>removing
7087the toolbar (icons) from gvim</center> <pre> <A
7088HREF="http://vim.sf.net/tip_view.php?tip_id=259">http://vim.sf.net/tip_view.php?tip_id=259</A><BR>
7089
7090Change good or bad usually encounters interia from people in excepting it.
7091gvim 6.0 is the first version that introduced the icons shortcut in shape
7092of a toolbar under the menu. when we upgraded to the new and improved vim
70936.1 from vim 5.7 some of people in our company encountered some problems
7094with their syntax highlighting and some of them objected on the new toolbar
7095which displayed icons for some common tasks for people more used to GUI.
7096
7097I finally figured out how to remove this new feature since I also didn't
7098see much use for it
7099
7100Here is for all those who haven't figured it out yet
7101
7102In your .gvimrc include the following two lines
7103
7104unmenu ToolBar unmenu! ToolBar
7105
7106Doing this from an open gvim does not remove them but grays them out but
7107doing from gvimrc does the job
7108
7109I was also trying to remove the menus at the top and almost succeeded with
7110a similar technique but somehow the Buffer menu item stays there no matter
7111what. IMHO it is a bug but it could very well be a feature ;)
7112
7113I tried this
7114
7115unmenu * unmenu! *
7116
7117even added this line after the above two but didn't help unmenu Buffers
7118
7119I 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
7123HREF="http://vim.sf.net/tip_view.php?tip_id=260">http://vim.sf.net/tip_view.php?tip_id=260</A><BR>
7124
7125This tip is for those who prefer to do some of the common operations like
7126cut/copy/paste etc using mouse. All u have to do is
7127
7128 :set mousemodel=popup
7129
7130by this u get a popup menu on right click of your mouse and u can do all
7131the common operations like undo, cut, copy, paste, select etc using mouse.
7132
7133u can also customise your popup menu by editing $VIMRUNTIME/menu.vim
7134
7135</pre></tip> </html> <Tip category="KVim"> <html><center>Close
7136windows from Gvim poup menu</center> <pre> <A
7137HREF="http://vim.sf.net/tip_view.php?tip_id=261">http://vim.sf.net/tip_view.php?tip_id=261</A><BR>
7138
7139To 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.\
7142Other :confirm only&lt;CR&gt;
7143
7144You obviously need ':set mousemodel=popup' in your .gvimrc as well :=)
7145
7146</pre></tip> </html> <Tip category="KVim"> <html><center>Bored
7147of ur arrow shapped mouseptr?</center> <pre> <A
7148HREF="http://vim.sf.net/tip_view.php?tip_id=262">http://vim.sf.net/tip_view.php?tip_id=262</A><BR>
7149
7150here is how u can change the shape of ur mouseptr in gvim.
7151
7152:set mouseshape=n:pencil
7153
7154this will change the shape of the mouseptr to pencil in normal mode. u can
7155choose different shapes for different modes. see :h mouseshape
7156
7157Want more shapes?
7158
7159Then look for the file cursorfont.h in ur X11/ directory. This file contains
7160lots of cursor shape #define definitions, like . #define XC_heart 62 .
7161now :set mouseshape=n:62 will set the shape of the mouseptr to heart in
7162normal mode.
7163
7164-ncr
7165
7166</pre></tip> </html> <Tip category="KVim">
7167<html><center>color active line</center> <pre> <A
7168HREF="http://vim.sf.net/tip_view.php?tip_id=263">http://vim.sf.net/tip_view.php?tip_id=263</A><BR>
7169
7170This tip shows how to color the active line, the line in which the cursor
7171is, for better reading. You should try possibility 2 before 1, IMHO it is
7172mostly usable.
7173
7174possibility 1:
7175 :au! CursorHold * let @/ = '\%' . line('.') . 'l.*' :set ut=500
7176
7177explanation:
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
7181problem:
7182 Register / holds the search pattern, so you cannot have color the active
7183 line and search. Therefore another solution:
7184
7185possibility 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
7190explanation:
7191 This solution uses 'match' to highlight a string, it does not interface
7192 with the current search pattern.
7193
7194addition:
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
7201references to vim help:
7202 :help Cursorhold :help 'ut' :help /\%l :help "/ :help \%
7203
7204</pre></tip> </html> <Tip category="KVim"> <html><center>F5
7205Compile and Run, F8 Compile (ala Visual Studio)</center> <pre> <A
7206HREF="http://vim.sf.net/tip_view.php?tip_id=264">http://vim.sf.net/tip_view.php?tip_id=264</A><BR>
7207
7208I love vim, it's my default editor on my Sun, Windows, Linux and *BSD boxen.
7209That said, I hate having to flip windows to compile while doing the
7210write-&gt;compile-&gt;debug loop.
7211
7212If you're used to Visual Studio and the ability it has to just hit F5 to
7213compile and run the current file or F8 to compile or step through the code
7214you'll appreciate this...
7215
7216This is my Windows version of this scriplet/tiplet. For other platforms,
7217you'll want to change the IF ELSE loops. You should actually never see
7218the "Unsuccessful" message from the compile/run loop unless the compiler
7219completely bombs out. This is from my _vimrc...
7220
7221map &lt;F5&gt; :call CompileRunGcc()&lt;CR&gt;
7222
7223map &lt;F8&gt; : call CompileGcc()&lt;CR&gt;
7224
7225func! 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
7231endfunc
7232
7233func! 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
7238endfunc
7239
7240</pre></tip> </html> <Tip category="KVim">
7241<html><center>Fast help in full window</center> <pre> <A
7242HREF="http://vim.sf.net/tip_view.php?tip_id=265">http://vim.sf.net/tip_view.php?tip_id=265</A><BR>
7243
7244You can get fast access to help by writing small script
7245
7246#!/bin/bash vim -c "help $1" -c only
7247
7248now 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
7254HREF="http://vim.sf.net/tip_view.php?tip_id=266">http://vim.sf.net/tip_view.php?tip_id=266</A><BR>
7255
7256The -S switch could be used to simplify common idiom: start Vim and source
7257a script file: gvim -c ":so foobar.vim" got translated into gvim -S foobar.vim
7258
7259Yes, this tip is trivial but I still see the -c ":so x" way too often. Time
7260to update your mind!
7261
7262</pre></tip> </html> <Tip category="KVim">
7263<html><center>selectively displaying abbreviations</center> <pre> <A
7264HREF="http://vim.sf.net/tip_view.php?tip_id=267">http://vim.sf.net/tip_view.php?tip_id=267</A><BR>
7265
7266Hi Vimmers, abbreviations have always been one of the most useful parts of
7267vi(m), trouble is when you've got too many you forgot what you called them.
7268
7269You can of course list the whole lot with
7270
7271:ab&lt;cr&gt;
7272
7273But did you know that you can type the first few letters of your abbreviations
7274and 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
7277my perls
7278
7279also try control-D instrad of &lt;cr&gt;
7280
7281zzapper
7282
7283</pre></tip> </html> <Tip category="KVim"> <html><center>Get cursor
7284position as byte percentage instead of line percentage</center> <pre> <A
7285HREF="http://vim.sf.net/tip_view.php?tip_id=268">http://vim.sf.net/tip_view.php?tip_id=268</A><BR>
7286
7287On line 300 of a thousand line file, Vim will show you that you're 30%
7288through the file. But what if most of the lines have one character in them,
7289and some of them have twenty thousand? Sometimes it comes in handy to know
7290your percentage through the file in terms of current-byte / total-bytes.
7291I looked through the Vim docs and couldn't find a way to do this, so I wrote
7292a Vim function to show it.
7293
7294Put this in your .vimrc:
7295
7296function! 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
7300endfunction
7301
7302(Uncomment the first return to see intermediate values.)
7303
7304And put this somewhere in your "set statusline=...":
7305
7306 %{Percent()}%%
7307
7308See "help statusline", "help eval".
7309
7310</pre></tip> </html> <Tip category="KVim"> <html><center>Syntax highlighting
7311is "out of sync", seems to correct itself with refresh ??</center> <pre> <A
7312HREF="http://vim.sf.net/tip_view.php?tip_id=269">http://vim.sf.net/tip_view.php?tip_id=269</A><BR>
7313
7314This one has come across the 'vim' users mailing list many times, and probably
7315comp.editors as well...
7316
7317Summary: see :help :syn-sync and search for 'sync' in your favorite syntax
7318file in $VIMRUNTIME/syntax
7319
7320Long Version: The syntax highlight code utilizes a certain synchronization
7321method to efficiently figure out syntax highlighting, specifically if you
7322aren't at the very beginning or end of a file. The specific setting is 'syntax
7323sync'. For various file types the method is set by default in this is setup
7324in the syntax file and one can vary the degree of trouble which VIM goes to to
7325try and figure this out. As an example for C, from $VIMRUNTIME/syntax/c.vim:
7326
7327if exists("c_minlines")
7328 let b:c_minlines = c_minlines
7329else
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
7335endif exec "syn sync ccomment cComment minlines=" . b:c_minlines
7336
7337Where c_minlines is the minimum number of lines that VIM goes backward to try
7338to find the start of a comment for syntax highlighting. If that line which
7339starts a comment is outside of that range, highlighting will appear wrong.
7340
7341You can easily set up something like this in your .vimrc: let c_minlines=500
7342or even bigger, but realize that it is a performance trade-off and that
7343syntax highlighting will slow things down.
7344
7345</pre></tip> </html> <Tip category="KVim">
7346<html><center>Insert a single character</center> <pre> <A
7347HREF="http://vim.sf.net/tip_view.php?tip_id=270">http://vim.sf.net/tip_view.php?tip_id=270</A><BR>
7348
7349Using Insert mode to insert a single character feels clumsy (you need 3
7350keypresses for one character), so here's a slightly easier way:
7351
7352:nmap &lt;space&gt; i_&lt;esc&gt;r
7353
7354Now, when in Normal mode, just press space followed by what it is you want
7355to insert.
7356
7357BUG: 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
7361HREF="http://vim.sf.net/tip_view.php?tip_id=271">http://vim.sf.net/tip_view.php?tip_id=271</A><BR>
7362
7363Something that I do quite alot is comment out blocks of text, only to uncomment
7364that same block later. The following mappings have proven useful to me. They
7365can 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;
7369map ,! :s/^/!/&lt;CR&gt; map ,; :s/^/;/&lt;CR&gt; map ,- :s/^/--/&lt;CR&gt;
7370map ,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
7377The commands to comment a selection of text are as follows, begining with
7378begining-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
7385Here 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
7391formating pasted text (p=`])</center> <pre> <A
7392HREF="http://vim.sf.net/tip_view.php?tip_id=272">http://vim.sf.net/tip_view.php?tip_id=272</A><BR>
7393
7394In times past I used a nice editor that had the neat feature of automatically
7395setting pasted text to the proper indent level. Recently I've begun to miss
7396this so I went looking in the help and camp up with....
7397
7398=`]
7399
7400which will format to the end of the pasted text... Perfect to call right
7401after you past something as the cursor ends up at the top of the pasted text,
7402thus 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,
7407your mileage will vary no doubt.
7408
7409However 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
7413p to p and = to end of pasted text. :nnoremap p p=`] :nnoremap &lt;c-p&gt; p
7414
7415This simply (as the comment hints at) maps normal mode p to what p did (paste)
7416then = to `] (last character in the previously changed text). While ctrl+p
7417just does what p did. (just in case you find you don't want a bit of text
7418auto formatted.).
7419
7420reference: :h :nnoremap :h p :h = :h `]
7421
7422Whatever the name of this idea is, tis something I find handy :)
7423
7424Happy VIMing
7425
7426</pre></tip> </html> <Tip category="KVim"> <html><center>Fast
7427fixing of email quotations (too long lines)</center> <pre> <A
7428HREF="http://vim.sf.net/tip_view.php?tip_id=273">http://vim.sf.net/tip_view.php?tip_id=273</A><BR>
7429
7430When using VIM as your editor of choice, even for email processing - as I
7431do - it is often unpleasing how some MUA's quote the email body produced by
7432mailers such as Outlook. The lines often span across multiple visual lines
7433and its difficult to reply on certain parts of it.
7434
7435With VIM, you can quickly fix those quotations to maintain a proper 75 char
7436break. For example, when using Mutt, put this line in your .muttrc, or use
7437a custom .vimrc_mail for it:
7438
7439set editor="vim -c 'set fo=tcrq' -c 'set tw=76'"
7440
7441For other MUA's this has to be fitted. However, now, when your quoted email
7442is displayed, you can use this VIM sequence to fix it:
7443
74441. move cursor to first line of broken paragraph 2. press 'V' and move to the
7445last line of the paragraph you want to fix 3. press 'g' and then 'q'. The
7446marked text will wrap around to your specified textwidth (76 in our case)
7447and 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
7451HREF="http://vim.sf.net/tip_view.php?tip_id=274">http://vim.sf.net/tip_view.php?tip_id=274</A><BR>
7452
7453You know, TeX requires a lot of additional formatting code. I'm tired of
7454opening and closing braces, brakets,
7455 \beginning and \ending etc. I particularly hate typing \begin and \end.
7456To help myself and to save a few(not a few) keystrokes I naturaly came up to
7457some solutions, which I wish to share with other TeXnicians and TeXperts whhich
7458use 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
7461environment. " 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
7464desired environment " ht are options " : is delimiter; in fact, you can
7465use whatever delimiter you want " as long it is not in &iskeyword option.
7466inoremap &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
7470inoremap &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
7475line the name of " the desired environment and options (see i_&lt;C-L&gt;)
7476and visual select " (from top to bottom) this and following lines. " After
7477pressing &lt;C-L&gt; the selected lines will be surrounded " with begin/end
7478skeleton 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
7484vnoremap &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,
7491blank or opening brace, " exit the brace block and stay in insert mode. "
7492If 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
7499endfunction 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
7505HREF="http://vim.sf.net/tip_view.php?tip_id=275">http://vim.sf.net/tip_view.php?tip_id=275</A><BR>
7506
7507You know, TeX requires a lot of additional formatting code. I'm tired of
7508opening and closing braces, brakets,
7509 \beginning and \ending etc. I particularly hate typing \begin and \end.
7510To help myself and to save a few(not a few) keystrokes I naturaly came up to
7511some solutions, which I wish to share with other TeXnicians and TeXperts whhich
7512use 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
7515environment. " 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
7518desired environment " ht are options " : is delimiter; in fact, you can
7519use whatever delimiter you want " as long it is not in &iskeyword option.
7520inoremap &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
7524inoremap &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
7529line the name of " the desired environment and options (see i_&lt;C-L&gt;)
7530and visual select " (from top to bottom) this and following lines. " After
7531pressing &lt;C-L&gt; the selected lines will be surrounded " with begin/end
7532skeleton 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
7538vnoremap &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,
7545blank or opening brace, " exit the brace block and stay in insert mode. "
7546If 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
7553endfunction 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
7559HREF="http://vim.sf.net/tip_view.php?tip_id=276">http://vim.sf.net/tip_view.php?tip_id=276</A><BR>
7560
7561Have you ever tried to call a function which parameters you have forgotten?
7562Especially those long named and with long parameter list GTK+ functions
7563like gtk_menu_item_image_from_stock_new(..........) !!! By accident I saw a
7564function in Vim help. It's name was PreviewWord and it allowed one to jump
7565in the preview window to the tag for the word cursor is on. I _slightly_
7566modified this function not to need tags file, but to search included files
7567instead. I wrote another function, which uses the above said one, which
7568triggers PreviewWord when you open the parenthesis after a function name.
7569Here it is: " Note: " This is literally stolen from Vim help. The only
7570changes are: " (1) if w != "" becomes if w =~ "\k" "
7571(2) exe "silent! ptag " . w becomes exe "silent! psearch " . w " *
7572The first change prevents PreviewWord of searching while cursor is on some "
7573non-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
7612endfunction au! CursorHold *.[ch] nested call PreviewWord()
7613
7614" Note: " When you open a parenthesis after a function name, and
7615at the " line end, that function's definition is previewed through
7616PreviewWord(). " This is inspired from Delphi's CodeInsight technology.
7617" Something similar (PreviewClassMembers) could be written for " the C++
7618users, for previewing the class members when you type " a dot after an
7619object name. " If somebody decides to write it, please, mail it to me.
7620function! PreviewFunctionSignature()
7621 let CharOnCursor = strpart( getline('.'), col('.')-2, 1) if col(".") ==
7622 col("$")
7623 call PreviewWord()
7624 endif return "("
7625endfunction 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
7630HREF="http://vim.sf.net/tip_view.php?tip_id=277">http://vim.sf.net/tip_view.php?tip_id=277</A><BR>
7631
7632Have you ever tried to call a function which parameters you have forgotten?
7633Especially those long named and with long parameter list GTK+ functions
7634like gtk_menu_item_image_from_stock_new(..........) !!! By accident I saw a
7635function in Vim help. It's name was PreviewWord and it allowed one to jump
7636in the preview window to the tag for the word cursor is on. I _slightly_
7637modified this function not to need tags file, but to search included files
7638instead. I wrote another function, which uses the above said one, which
7639triggers PreviewWord when you open the parenthesis after a function name.
7640Here it is: " Note: " This is literally stolen from Vim help. The only
7641changes are: " (1) if w != "" becomes if w =~ "\k" "
7642(2) exe "silent! ptag " . w becomes exe "silent! psearch " . w " *
7643The first change prevents PreviewWord of searching while cursor is on some "
7644non-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
7683endfunction au! CursorHold *.[ch] nested call PreviewWord()
7684
7685" Note: " When you open a parenthesis after a function name, and
7686at the " line end, that function's definition is previewed through
7687PreviewWord(). " This is inspired from Delphi's CodeInsight technology.
7688" Something similar (PreviewClassMembers) could be written for " the C++
7689users, for previewing the class members when you type " a dot after an
7690object name. " If somebody decides to write it, please, mail it to me.
7691function! PreviewFunctionSignature()
7692 let CharOnCursor = strpart( getline('.'), col('.')-2, 1) if col(".") ==
7693 col("$")
7694 call PreviewWord()
7695 endif return "("
7696endfunction 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
7701HREF="http://vim.sf.net/tip_view.php?tip_id=278">http://vim.sf.net/tip_view.php?tip_id=278</A><BR>
7702
7703One of the principles of effective text editing is moving around very
7704efficiently. 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'
7714will 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
7735the default action for double-click with "unknown file types"</center> <pre> <A
7736HREF="http://vim.sf.net/tip_view.php?tip_id=279">http://vim.sf.net/tip_view.php?tip_id=279</A><BR>
7737
7738I find myself installing the following registry modification for all my
7739PC's now (even other people's PC's). It applies to Microsoft Windows
7740machines only. The following is also for Windows 9x... NT or XP or 2000
7741may require modifications (which I don't care to understand!).
7742
7743The problem: You double-click on a file that doesn't have a 'registered type'
7744and that pesky "What program should I use?" dialog pops up. Even worse,
7745depending on the installation, the GVim icon may not be listed, and one has
7746to browse to the executable... and then the type becomes forever bonded
7747to being editted with GVim (if that box is checked). The standard Vim 6.1
7748installation does include a "right click to edit" menu item for all files,
7749but a double-click is so much faster!
7750
7751The solution: What if unregistered types would just automatically open up
7752in GVim? Well, they can.. with a little registry trickery.
7753
7754How to Install it:
7755
7756Step 1. Create a text file called "vimalways.reg" and paste the below text
7757into it.
7758
7759Step 2. Important NOTE: You will have to edit the pathname to correspond
7760to the pathname of your GVim.exe. The text below works fine for a GVim 6.1
7761default installation.
7762
7763Step 3: Save the file.
7764
7765Step 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
7772with &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
7779Note 1. This can't be de-installed automatically, and if you want to remove
7780it, you'll have to edit the registry by hand (annoying, but easy).
7781
7782Note 2. Keep this file around, so when you upgrade your GVim, all you have
7783to do is modify the pathname (to say, for example, vim62) and then install
7784it again.
7785
7786Ok, thanks for playing! And thanks to the author(s) of Vim and GVim.
7787If 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
7791with PyUnit testing framework</center> <pre> <A
7792HREF="http://vim.sf.net/tip_view.php?tip_id=280">http://vim.sf.net/tip_view.php?tip_id=280</A><BR>
7793
7794Vim has a wonderful ability to integrate with external tools, like compilers,
7795make, ctags etc. That's one of the reasons we love it.
7796
7797PyUnit can be seen as a "compiler" for the Python test code. To understand
7798it, Vim should be told about the language the PyUnit speaks. This could be
7799done with 'errorformat' option:
7800
7801setlocal efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
7802
7803This magic spell enables Vim to parse unittest.TextRunner's output and to
7804enter 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
7807setlocal makeprg=./alltests.py
7808
7809And contents of the alltests.py (for the sake of completeness):
7810
7811#!/usr/bin/env python2
7812
7813import unittest import sys sys.path.append('unittests')
7814
7815modules_to_test = (
7816 'fooTest', 'barTest', 'bazTest',
7817)
7818
7819def suite():
7820 alltests = unittest.TestSuite() for module in map(__import__,
7821 modules_to_test):
7822 alltests.addTest(unittest.findTestCases(module))
7823 return alltests
7824
7825if __name__ == '__main__':
7826 unittest.main(defaultTest='suite')
7827
7828============== end of the alltests.py file ========================
7829
7830While talking about it, I'd also suggest to add a couple of mappings.
7831In the end, my vim/files/ftplugin/python.vim looks like this:
7832
7833setlocal makeprg=./alltests.py\ -q setlocal efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\
7834line\ %l%.%#,%Z%[%^\ ]%\\@=%m iabbr &lt;buffer&gt; sae self.assertEquals
7835iabbr &lt;buffer&gt; sar self.assertRaises
7836
7837For details see :help quick-fix, :help
7838'efm' and :help 'makeprg'. See also: <A
7839HREF="http://c2.com/cgi/wiki?PythonUnit">http://c2.com/cgi/wiki?PythonUnit</A><BR>
7840
7841Many 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
7846HREF="http://vim.sf.net/tip_view.php?tip_id=281">http://vim.sf.net/tip_view.php?tip_id=281</A><BR>
7847
7848Do you find yourself hitting 'zz' all the time in order to see some context of
7849what you're currently working on? If so, then this tip might be for you. If
7850you 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
7858HREF="http://vim.sf.net/tip_view.php?tip_id=282">http://vim.sf.net/tip_view.php?tip_id=282</A><BR>
7859
7860Well, I've tried to understand some of the folding scripts, but life's too
7861short. Instead, I added the following lines to my vimrc file.
7862
7863set
7864foldexpr=(getline(v:lnum)=~@/)?0:(getline(v:lnum-1)=~@/)\|\|(getline(v:lnum+1)=~@/)?1:2
7865map \z :set foldmethod=expr foldlevel=0 foldcolumn=2&lt;CR&gt;
7866
7867The first line is an extension of foldexpr=(getline(v:lnum)=~@/)?0:1 The
7868second line (re)sets the foldmethod to expr(ession) plus.
7869
7870First search for /regexp/, then fold everything else with \z Use zr to reveal
7871more context (before/after) lines.
7872
7873You could add (getline(v:lnum-2)=~@/)\|\|(getline(v:lnum+2)=~@/)?2:3 but it
7874will take longer as folded lines (the majority) evaluate the full expression.
7875
7876What could be easier?
7877
7878</pre></tip> </html> <Tip category="KVim"> <html><center>Turn
7879on syntax coloring in Mac OS X</center> <pre> <A
7880HREF="http://vim.sf.net/tip_view.php?tip_id=283">http://vim.sf.net/tip_view.php?tip_id=283</A><BR>
7881
7882This tip is actually for vim 6.1. To turn on syntax coloring in Mac OS X
7883enter 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
7888to print syntax highlighted buffer in B&W</center> <pre> <A
7889HREF="http://vim.sf.net/tip_view.php?tip_id=284">http://vim.sf.net/tip_view.php?tip_id=284</A><BR>
7890
7891I use this mapping to print syntax highlighted C++ code in B&W This tip
7892needs vimscript #233 print_bw.
7893
7894The mapping is as follows map &lt;C-p&gt; :color
7895print_bw&lt;CR&gt;:hardcopy&lt;CR&gt;:color sean&lt;CR&gt;:syn on&lt;CR&gt;
7896
7897Change ":color sean" to whatever is your chosen color scheme. Need to
7898change line 7 of print_bw from "syntax reset" to "syntax off" &lt;C-p&gt;
7899on a syntax highlighted buffer turns off syntax highlighting , sets the
7900colors to B&W, prints the buffer, resets the color scheme and turns on syntax
7901highlighting again.
7902
7903</pre></tip> </html> <Tip category="KVim">
7904<html><center>Don't use the escape key!</center> <pre> <A
7905HREF="http://vim.sf.net/tip_view.php?tip_id=285">http://vim.sf.net/tip_view.php?tip_id=285</A><BR>
7906
7907Vim (any vi really) is a dream for touch typists... Until you want to switch
7908from insert mode to normal mode. Then you've got to reach way up to whack
7909the escape key.
7910
7911Or 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
7916That little bit of knowledge, plus mapping my caps lock to another control
7917key, was what turned my fascination with Vim into true love. You never have
7918to lose track of the home row again!
7919
7920For Xfree86 users - you can make the capslock key another control key by adding
7921
7922Option "XkbOptions" "ctrl:nocaps"
7923
7924to the InputDevice section of your XF86Config file.
7925
7926For Windows NT/2000 users - use the following .reg file to do the same thing:
7927
7928REGEDIT4
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
7934after doing something... ugly.</center> <pre> <A
7935HREF="http://vim.sf.net/tip_view.php?tip_id=286">http://vim.sf.net/tip_view.php?tip_id=286</A><BR>
7936
7937I was once editing a file and wanted to test something. The test was meant
7938to add a line at the end of the file, from outside vim. All was fine, but
7939instead of &gt;&gt;, I wrote &gt;. You can imagine what happened... :)
7940
7941If 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
7947HREF="http://vim.sf.net/tip_view.php?tip_id=287">http://vim.sf.net/tip_view.php?tip_id=287</A><BR>
7948
7949In the gvim if you want to decrement any number just put ur curcor on that
7950number in Esc mode and pres &lt;CTRL&gt; X
7951
7952</pre></tip> </html> <Tip category="KVim"> <html><center>A keymapping
7953to generate Java setters and getters automatically</center> <pre> <A
7954HREF="http://vim.sf.net/tip_view.php?tip_id=288">http://vim.sf.net/tip_view.php?tip_id=288</A><BR>
7955
7956This mapping makes it much simpler to write new java classes by simplifying
7957some of the dull repetative coding (ie setters and getters).
7958
7959To use, first write a basic class with the following format:
7960
7961public 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
7972Note the getters/setters comment -- they are important as they are used to
7973place the getters and setters.
7974
7975The mapping is:
7976
7977map 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
7981void &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
7985lines above).
7986
7987To use this to generate a class go to the variable that should have a
7988setter/getter and place the curser at the beginning of the 'private':
7989
7990 private &lt;type&gt; &lt;variable&gt; = &lt;initvalue&gt;' ^
7991
7992Then type:
7993
7994jgs
7995
7996this will create the first getter/setter and then move up to the next
7997variable. You can just keep typing jgs until all the getters/setters have
7998been generated.
7999
8000This should mapping isn't perfect and someone could probably make it a little
8001cleaner. It could also relatively easily be adapted to C++. Please feel free
8002to 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
8006insert" and get out into normal mode</center> <pre> <A
8007HREF="http://vim.sf.net/tip_view.php?tip_id=289">http://vim.sf.net/tip_view.php?tip_id=289</A><BR>
8008
8009This is an alternative key combo for the escape key from the one mentioned
8010by David A. Rogers in vimtip #285.
8011
8012I do a lot of editting in Vim, and I've always found myself in situations where
8013I had to "do a quick insert" - basically (from normal mode), change into insert
8014mode, type in one quick word, then &lt;esc&gt; out, then navigate elsewhere.
8015
8016As has been rightly observed by a lot of people, the &lt;esc&gt; key can
8017sometimes be a little bit out of the way. But that's no problem for ViM, is it?
8018
8019At first, I thought of editting the ViM source code itself, in order to come
8020up with a command that could do things like say "let me jump into insert
8021mode, type a few quick words, then escape out into normal mode when i press
8022something like double &lt;space&gt;".
8023
8024It was only later when reading through the section in
8025Jesse Goerz's "Beginner's Guide to ViM" on remapping (<A
8026HREF="http://newbiedoc.sourceforge.net/tutorials/vim/mapping-vim.html)
8027that I got inspired to retake a look at using remapping as an alternative
8028instead.">http://newbiedoc.sourceforge.net/tutorials/vim/mapping-vim.html)
8029that I got inspired to retake a look at using remapping as an alternative
8030instead.</A><BR>
8031
8032This is what I came up with.. Use whatever is comfortable for you - single
8033or 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
8038With this quick combo ("Shift", + &lt;space&gt;), one can easily (and might
8039I add, intuitively) "do a quick insert" and exit quickly out into normal
8040mode. I guess I always thought the &lt;space&gt; would be a good way to
8041do this sort of thing, since it is after all, so intuitive in the typing
8042process. So why not make it such that it can "escape" you out into normal
8043mode as well? Just type 'i', to go into insert mode, type in your stuff,
8044and once you're done, hit Shift-space!
8045
8046</pre></tip> </html> <Tip category="KVim"> <html><center>Text
8047Processing With Integrated Spell Checking</center> <pre> <A
8048HREF="http://vim.sf.net/tip_view.php?tip_id=290">http://vim.sf.net/tip_view.php?tip_id=290</A><BR>
8049
8050I have written an HTML document to help others use Vim as a basic text
8051processing application. It discusses how to integrate spell checking,
8052dictionary, and thesaurus applications. It also talks about wrapping lines,
8053indentation, justification, and the vim settings that effect the behavior
8054of 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
8058Everything has been tested with UNIX, Linux, Windows, and Windows with
8059Cygwin patforms.
8060
8061</pre></tip> </html> <Tip category="KVim"> <html><center>^P
8062& auto filling of variables and text</center> <pre> <A
8063HREF="http://vim.sf.net/tip_view.php?tip_id=291">http://vim.sf.net/tip_view.php?tip_id=291</A><BR>
8064
8065Do 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
8067variable 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
8073HREF="http://vim.sf.net/tip_view.php?tip_id=292">http://vim.sf.net/tip_view.php?tip_id=292</A><BR>
8074
8075I've found that vim + cscope + cygwin does not work. The problem seems to
8076be that in
8077
8078sprintf(cmd, "exec %s -dl -f %s", prog, csinfo[i].fname);
8079
8080vim execs cscope with the "-dl" options, causing it to fail. It is probably
8081a cscope bug, but a simple workaround is top build vim without thad "d":
8082
8083sprintf(cmd, "exec %s -l -f %s", prog, csinfo[i].fname);
8084
8085seems to work for me!
8086
8087</pre></tip> </html> <Tip category="KVim"> <html><center>remember
8088where you had ended reading help</center> <pre> <A
8089HREF="http://vim.sf.net/tip_view.php?tip_id=293">http://vim.sf.net/tip_view.php?tip_id=293</A><BR>
8090
8091You could jump to the last place you had been while reading Vim help files
8092if you add this to your .vimrc file:
8093
8094au BufLeave * if &ft == "help" | mark H | endif
8095
8096Then use 'H to go to the mark H.
8097
8098To work between Vim runs 'viminfo' option should be setup to save file marks.
8099See :help 'viminfo' and :help file-marks for more information.
8100
8101</pre></tip> </html> <Tip category="KVim"> <html><center>Use
8102Ctrl-S to save current or new files.</center> <pre> <A
8103HREF="http://vim.sf.net/tip_view.php?tip_id=294">http://vim.sf.net/tip_view.php?tip_id=294</A><BR>
8104
8105I wanted to have a single key stroke that would save existing files, or call
8106the file browser. Here's a key map for Ctrl-S to accomplish that (place in
8107vimrc file):
8108
8109if 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;
8114endif
8115
8116Tom Kimpton
8117
8118</pre></tip> </html> <Tip category="KVim">
8119<html><center>Line/word/file/whatever completion</center> <pre> <A
8120HREF="http://vim.sf.net/tip_view.php?tip_id=295">http://vim.sf.net/tip_view.php?tip_id=295</A><BR>
8121
8122In addition to vimtip #291 you can use whole &lt;C-x&gt; completion mode. It
8123can complete whole lines (&lt;C-x&gt;l, then &lt;C-p&gt;, &lt;C-n&gt;),
8124filenames (&lt;C-f&gt;), keywords, words from custom dictionary and many,
8125many others. During coding it usually saves a LOT of key strokes ;) This
8126mode 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
8128with another &lt;C-x&gt;&lt;C-p&gt;. For example, after writing such text:
8129
8130this is first line second line is here
8131
8132Placing cursor at third line and pressing &lt;C-x&gt;l will double last
8133line - &lt;C-n&gt;, &lt;C-p&gt; in this moment can be used to manipulate
8134completed line. Or, instead of completing whole line you can press 'f' and
8135then complete by &lt;C-p&gt; which will result in 'first' word. After that
8136you can &lt;C-x&gt;&lt;C-p&gt; to get 'line' word (since this is next word
8137after 'first'). Try yourself for other powerful combinations.
8138
8139</pre></tip> </html> <Tip category="KVim"> <html><center>Attach
8140the currently open file to email</center> <pre> <A
8141HREF="http://vim.sf.net/tip_view.php?tip_id=296">http://vim.sf.net/tip_view.php?tip_id=296</A><BR>
8142
8143This is very simple, but most people don't seem to take advantage of
8144this. Often you have some file (source code or other text file) already open
8145in an existing vim session and you need to attach it with an email. It is
8146very 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
8154That is all there to it. If you are on windows and your email client doesn't
8155accept 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
8160HTH, Hari
8161
8162</pre></tip> </html> <Tip category="KVim"> <html><center>Start
8163in insert mode without loosing your escape key</center> <pre> <A
8164HREF="http://vim.sf.net/tip_view.php?tip_id=297">http://vim.sf.net/tip_view.php?tip_id=297</A><BR>
8165
8166There are two parts to this, each is fairly simple.
8167
8168First, I want to start in insert mode. Well "set im!" in my vimrc did the
8169job, but I lost the escape key. Second, I have found that often times,
8170when I'm in command mode, I hit escape trying to get back into insert mode.
8171I am always rewarded with a beep, telling me once again I made that mistake.
8172
8173So I mapped esc in command mode to set insert mode (":set im") and I mapped
8174esc in insert mode to unset insert mode (&lt;c-o&gt;:set im) Well then I
8175realized if you hit "i" in command mode, escape woulding work the first time.
8176So here's the code to add to your vimrc:
8177
8178set im! " start in insert mode map &lt;esc&gt; :set
8179im!&lt;cr&gt; " escape in command mode goes to insert mode map
8180i :set im!&lt;cr&gt; " i in command mode goes to insert mode
8181map! &lt;esc&gt; &lt;c-o&gt;:set im!&lt;cr&gt; " escape in insert mode goes
8182to command mode
8183
8184see :help insert
8185
8186</pre></tip> </html> <Tip category="KVim"> <html><center>Changing
8187case with regular expressions</center> <pre> <A
8188HREF="http://vim.sf.net/tip_view.php?tip_id=298">http://vim.sf.net/tip_view.php?tip_id=298</A><BR>
8189
8190I stumbled across this factoid on a website about vi. I haven't been able to
8191locate it in the Vim documentation, but it works in Vim, and it's very handy.
8192
8193There are times that you might like to go through a file and change the case
8194of characters that match some arbitrary criteria. If you understand regular
8195expressions well, you can actually do this fairly easily.
8196
8197It's as simple as placing \U or \L in front of any backreferences in your
8198regular expressions. Vim will make the text in the backreference uppercase
8199or lowercase (respectively).
8200
8201(A "backreference" is a part of a regular expression that refers to a previous
8202part of a regular expression. The most common backrefernces are &, \1, \2,
8203\3, ... , \9).
8204
8205Some examples that demonstrate the power of this technique:
8206
8207Lowercase the entire file - :%s/.*/\L&/g
8208
8209(& is a handy backreference that refers to the complete text of the match.)
8210
8211Uppercase all words that are preceded by a &lt; (i.e. opening HTML tag names):
8212:%s/&lt;\(\w*\)/&lt;\U\1/g
8213
8214Please add a note if you know where this is in the documentation. I have
8215done 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
8219HREF="http://vim.sf.net/tip_view.php?tip_id=299">http://vim.sf.net/tip_view.php?tip_id=299</A><BR>
8220
8221A little thing that I did and found quite useful:
8222
8223function! 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
8226endfunction
8227
8228map! silent &lt;M-e&gt; :call OpenFileUnderCursor()&lt;CR&gt;
8229
8230Then use Alt+E on a filename to open it (relative to the directory the
8231current file resides in).
8232
8233</pre></tip> </html> <Tip category="KVim"> <html><center>Making
8234a tags file for IDL (Interactive Data Language)</center> <pre> <A
8235HREF="http://vim.sf.net/tip_view.php?tip_id=300">http://vim.sf.net/tip_view.php?tip_id=300</A><BR>
8236
8237I have recently began using the tags features of vim (:help tags) with my
8238fortran codes and come to appreciate their power. I also do a lot of coding
8239in IDL (Interactive Data Language), but found that ctags did not have native
8240support for IDL. If you take the time you can learn how to get ctags to
8241support IDL, but I found, after a search of usenet, that someone else has
8242already done this and written a perl script called idltags. It is part
8243of an emacs package (is anyone still reading?) that you need to download,
8244called idlwave, which is located at:
8245 <A HREF="http://idlwave.org/">http://idlwave.org/</A><BR>
8246and 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>
8249In the usenet pages the maintainer, JD Smith, was suggesting that idlwave
8250had outgrown idltags and was not sure it was still needed, so I don't know
8251how long it will be available.
8252
8253</pre></tip> </html> <Tip category="KVim"> <html><center>Edit
8254files in path, or related.</center> <pre> <A
8255HREF="http://vim.sf.net/tip_view.php?tip_id=301">http://vim.sf.net/tip_view.php?tip_id=301</A><BR>
8256
8257You can write a little shell function that will let you easily edit any file
8258that is in the path, or which's location can be retrieved with the whereis
8259tool. This is something similar to what I have in /etc/profile:
8260
8261function vvim() { vim `whereis $1|cut -d: -f2` } function ggvim() { gvim
8262`whereis $1|cut -d: -f2` }
8263
8264Then just type, for example, "vvim ls", and you'll start vim with /bin/ls
8265and /usr/share/man/ls.1.gz loaded :) (it's not very useful to edit /bin/ls,
8266but you get the ideea ;)
8267
8268</pre></tip> </html> <Tip category="KVim">
8269<html><center>Use gvim in kmail</center> <pre> <A
8270HREF="http://vim.sf.net/tip_view.php?tip_id=302">http://vim.sf.net/tip_view.php?tip_id=302</A><BR>
8271
8272To automatically open gvim to edit in kmail, "-f" command line option must
8273be used . In kmail configuration go to the composer settings , and write
8274in the "use external editor" field the following command : "gvim -f %f"
8275Without -f option gvim would work in background and editing would not have
8276any effect on kmail.
8277
8278</pre></tip> </html> <Tip category="KVim"> <html><center>Statusline
8279Tab Level Function Ruler TVIM</center> <pre> <A
8280HREF="http://vim.sf.net/tip_view.php?tip_id=303">http://vim.sf.net/tip_view.php?tip_id=303</A><BR>
8281
8282I use this function to let me know if my cursor is on a TAB column. The t*
8283on 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
8286want to change a tab level you can drag or push the first character of a line
8287to a desired tab level. (more on that later) This ruler replacement will let
8288you know where you are, whether you like to use space tabs (see vimtip #12 )
8289or regular tabs. My function is set to four space tabs stops and only goes
82909 levels but can be easily modified.
8291
8292Actually I just wanted to learn how to use a function in my _vimrc and this
8293was my first attempt. Add this to your _vimrc
8294
8295"--------------------cut------------------ set laststatus=2 "This makes sure
8296the ruler shows. See help laststatus set statusline=%f\ ---------\ My\
8297Ruler\ ----------\ r%l,c%c,t%{ShowTab()} "See help statusline (I toggle
8298between 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
8305return TabLev endf "The ruler (statusline) shows a t* unless you are on
8306col 1,5,9,13,... "-------------------cut-------------------
8307
8308This function ShowTab() gets called and updates the ruler with every cursor
8309move but it does not slow things down as I type. Perhaps a speed typist
8310may complain :-) In case I write something else you may search on the key
8311word 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
8315HREF="http://vim.sf.net/tip_view.php?tip_id=304">http://vim.sf.net/tip_view.php?tip_id=304</A><BR>
8316
8317If 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
8319start=/{/ end=/}/ transparent fold syn region foldJavadoc start=,/\*\*,
8320end=,\*/, 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
8324of VIM Tips (VIM's best Features)</center> <pre> <A
8325HREF="http://vim.sf.net/tip_view.php?tip_id=305">http://vim.sf.net/tip_view.php?tip_id=305</A><BR>
8326
8327Here's a necessarily cryptic list of "MY" Best Vim Tips
8328that I've gleaned from <A HREF="http://vim.sf.net/ &
8329comp.editors ">http://vim.sf.net/ & comp.editors </A><BR> <A
8330HREF="http://groups.google.com/groups?safe=off&group=comp.editors">http://groups.google.com/groups?safe=off&group=comp.editors</A><BR>
8331
8332updated version at <A
8333HREF="http://www.rayninfo.co.uk/vimtips.html">http://www.rayninfo.co.uk/vimtips.html</A><BR>
8334------------------------------------------------------------------------------
8335# Absolutely essential
8336------------------------------------------------------------------------------
8337vim.sf.net : Visit frequently comp.editors : "VIM" dominated
8338newsgroup * # g* g# : find word under cursor (forwards/backwards)
8339% : match brackets {}[]() matchit.vim : % now matches
8340tags &lt;tr&gt;&lt;td&gt;&lt;script&gt; etc &lt;C-N&gt; &lt;C-P&gt; : word
8341completion in insert mode &lt;C-X&gt;&lt;C-L&gt; : Line complete SUPER
8342USEFUL /&lt;C-R&gt;&lt;C-W&gt; : Pull &lt;cword&gt; onto search/command
8343line :set ignorecase # you nearly always want this :syntax on : colour
8344syntax in Perl,HTML,PHP etc :h slash&lt;C-D&gt; : type control-D and get a
8345list 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
8353Text :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
8358following) :cd .. : move to parent directory
8359------------------------------------------------------------------------------
8360# Great guu : lowercase line gUU
8361: uppercase line gf : open file name under
8362cursor (SUPER) ga : display hex,ascii value of
8363character under cursor ggVGg? : rot13 whole file
8364CTRL-A,CTRL-X : increment,decerement number under cursor
8365 win32 users must remap CNTRL-A
8366CTRL-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
8371line (SUPER) `. : jump to exact spot in last modification
8372line &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
8379c:/aaa/xr&lt;CR&gt; :ab php : list of abbreviations beginning
8380php :map , : list of maps beginning , # For use in Maps
8381&lt;CR&gt; : carriage Return for maps &lt;ESC&gt; :
8382Escape &lt;LEADER&gt; : normally \ &lt;BAR&gt; : | pipe
8383------------------------------------------------------------------------------
8384# List your Registers :reg : display contents
8385of all registers "1p.... : retrieve numeric buffers
8386------------------------------------------------------------------------------
8387# Useful trick "ayy@a : execute "Vim command" in a
8388text file yy@" : same thing using unnamed register
8389------------------------------------------------------------------------------
8390# Get output from other commands :r!ls.exe :
8391reads 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
8395next (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
8398unmodified file :w c:/aaa/% : save file elsewhere :e # :
8399edit alternative file :e % :rew : rewwind to first file in
8400ARGS :bn : next file :bp : next file :brew
8401------------------------------------------------------------------------------
8402# Recording (BEST TIP of ALL) qq # record to q your commands
8403q @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
8407but 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
8411file://%:p&lt;CR&gt; :nmap ,i :update&lt;CR&gt;: !start
8412c:\progra~1\intern~1\iexplore.exe &lt;cWORD&gt;&lt;CR&gt;
8413------------------------------------------------------------------------------
8414# FTPing from VIM cmap ,r :Nread <A
8415HREF="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
8417HREF="ftp://209.51.134.122/public_html/index.html">ftp://209.51.134.122/public_html/index.html</A><BR>
8418gvim <A
8419HREF="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
84225 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
8430for lines beginning A-J followed by at leat 1 A-J /forum\(\_.\)*pent
8431search over possible multiple lines /fred\_s*joe/i : any
8432whitespace 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
8437by : :%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
8441substitute "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 :
8446delete lines not containing string :v/^dd/d : delete lines not
8447containing string :g/fred/,/joe/d : not line based :v/./.,/./-1join : compress
8448empty 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
8451END "*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!! #
8459vg.ksh (shell script) # vi all files in directory containing
8460keyword $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
8464web-browser with the URL in the current line</center> <pre> <A
8465HREF="http://vim.sf.net/tip_view.php?tip_id=306">http://vim.sf.net/tip_view.php?tip_id=306</A><BR>
8466
8467function! Browser ()
8468 let line = getline (".") let line = matchstr (line, "http[^ ]*") exec
8469 "!netscape ".line
8470endfunction
8471
8472map &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
8476HREF="http://vim.sf.net/tip_view.php?tip_id=307">http://vim.sf.net/tip_view.php?tip_id=307</A><BR>
8477
8478i use gvim and bash heavily under win98. i have
8479
8480let $HOME = substitute($HOME, '\\', '/', 'g') set shell=bash\ --rcfile\
8481\"$HOME\"_bashrc\ -i
8482
8483in my _vimrc, and something like
8484
8485function br() { if [ $1 ]; then
8486 explorer.exe ${1//\//\\}
8487 else
8488 explorer.exe ${PWD//\//\\}
8489 fi
8490}
8491
8492in my _bashrc. when i finish editing one html file, i simply type :!br %
8493
8494everything works fine now. but when :!br % executes, one console window will
8495bump out and wait me to press some key to contiue. i consider this quiet
8496annoying. i want the console window to disappear automatically if no fault
8497has 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
8501HREF="http://vim.sf.net/tip_view.php?tip_id=308">http://vim.sf.net/tip_view.php?tip_id=308</A><BR>
8502
8503If you don't like the fact that when you press Up and Down on a wrapped line,
8504you get to the next phisical line instead of the next line on the screen,
8505you can do something like this:
8506
8507imap &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
8510nmap &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
8513vim you left open remotely</center> <pre> <A
8514HREF="http://vim.sf.net/tip_view.php?tip_id=309">http://vim.sf.net/tip_view.php?tip_id=309</A><BR>
8515
8516Vim 6 has this cool client-server protocol. I use it all the time to edit
8517a file in an existing gvim, like so $ gvim --remote [filename]
8518
8519Today I left myself logged in at the console at work, and when I got home
8520I realized I had left vim running with files unsaved. I think I even left
8521it in insert mode. I wanted to edit these files at home. So I ssh'd to the
8522machine 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
8527After a lot of failed attempts, I finally succeeded in getting the remote
8528vim to save its buffers and quit.
8529
8530$ DISPLAY=:0 vim --servername GVIM --remote-send '&lt;ESC&gt;:wqa&lt;CR&gt;'
8531
8532A couple of notable things. Then environment variable DISPLAY has to be the
8533display of the remote vim, and you have to be able to open that display. The
8534client-server stuff is done through X.
8535
8536The &lt;CR&gt; is important. This part eluded me for a long time. The {keys}
8537are just like keys you would press if you were editing at the console,
8538and you have to press enter, or vim won't do anything.
8539
8540Check your .swp files to make sure vim really closed the files it was
8541editing. Vim provides little feedback as to the success or failure of what
8542you're trying to do remotely. Nonetheless, it's clearly a useful feature to
8543have available.
8544
8545</pre></tip> </html> <Tip category="KVim"> <html><center>showing ascii
8546value of the current character in decimal, hex, and octal</center> <pre> <A
8547HREF="http://vim.sf.net/tip_view.php?tip_id=310">http://vim.sf.net/tip_view.php?tip_id=310</A><BR>
8548
8549dont 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
8551the decimal, hex, and octal of the char under the cursor... ncie to know.
8552
8553</pre></tip> </html> <Tip category="KVim"> <html><center>Open
8554the folder containing the currently open file</center> <pre> <A
8555HREF="http://vim.sf.net/tip_view.php?tip_id=311">http://vim.sf.net/tip_view.php?tip_id=311</A><BR>
8556
8557Occasionally, on windows, I have files open in gvim, that the folder for that
8558file is not open. This key map opens the folder that contains the currently
8559open file. The expand() is so that we don't try to open the folder of an
8560anonymous buffer, we would get an explorer error dialog in that case.
8561
8562if 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
8570endif
8571
8572Tom.
8573
8574</pre></tip> </html> <Tip category="KVim">
8575<html><center>Copy, Cut, and Paste</center> <pre> <A
8576HREF="http://vim.sf.net/tip_view.php?tip_id=312">http://vim.sf.net/tip_view.php?tip_id=312</A><BR>
8577
8578PS: copy, cut, and paste are the words from (usually) gui editor.
8579
8580Ever try to cut (or copy) some lines and paste to another place? If you
8581need to count the lines first, then try these to eliminate counting task.
8582
8583Cut and Paste:
8584
85851. Place the cursor at the beginning of the block you want to CUT. 2. Mark
8586it with md 3. Go to the end of the block. 4. Cut it with d'd 5. Go to the
8587new location that you want to PASTE those text. 6. Press P.
8588
8589Copy and Paste:
8590
85911. Place the cursor at the beginning of the block you want to COPY. 2. Mark
8592it with my 3. Go to the end of the block. 4. Cut it with y'y 5. Go to the
8593new location that you want to PASTE those text. 6. Press P.
8594
8595The name of the mark used is related to the operation (d:delete or y:yank).
8596I found that those mark names requires minimal movement of my finger. ;)
8597
8598</pre></tip> </html> <Tip category="KVim"> <html><center>printing
8599using kprinter (unix + kde)</center> <pre> <A
8600HREF="http://vim.sf.net/tip_view.php?tip_id=313">http://vim.sf.net/tip_view.php?tip_id=313</A><BR>
8601
8602just add set printexpr=system('kprinter'\ .\ '\ '\ .\ v:fname_in)\ .\
8603delete(v:fname_in)\ +\ v:shell_error to your ~/.vimrc; further on all your
8604printing will be piped through the nice and consistent print-dialog of kde.
8605
8606lg, tomte
8607
8608</pre></tip> </html> <Tip category="KVim">
8609<html><center>Insert and back...</center> <pre> <A
8610HREF="http://vim.sf.net/tip_view.php?tip_id=314">http://vim.sf.net/tip_view.php?tip_id=314</A><BR>
8611
8612this is related to vimtip #289 in terms of programmers (like I) too lazy to
8613move 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
8617here is a small snippet from my mappings file, ready to speed things up: //
8618the 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
8621imap &lt;S-CR&gt; &lt;esc&gt;O
8622
8623nmap &lt;S-Space&gt; i nmap &lt;space&gt;&lt;space&gt; i nnoremap &lt;CR&gt;
8624o nmap &lt;S-CR&gt; O
8625
8626---uncut---
8627
8628Good luck!!
8629
8630</pre></tip> </html> <Tip category="KVim">
8631<html><center>"Smart &lt;home&gt;"</center> <pre> <A
8632HREF="http://vim.sf.net/tip_view.php?tip_id=315">http://vim.sf.net/tip_view.php?tip_id=315</A><BR>
8633
8634to 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
8643endfun 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
8650what this snippet does is make the &lt;home&gt; key behave as it does in
8651such IDEs as PythonWin or MSVisualStudio, and that is first go to the first
8652non 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
8656HREF="http://vim.sf.net/tip_view.php?tip_id=316">http://vim.sf.net/tip_view.php?tip_id=316</A><BR>
8657
8658There are a number of ways you can search for a pattern in a script.
8659The search function is the typical way to search for a pattern. But, it
8660has limited options. In particular, there are no options to control the
8661position of the cursor after it matches the pattern.
8662
8663Instead 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"
8665and move the cursor to the end of the matching pattern issue the command:
8666
8667:normal /pattern/e+1^M
8668
8669where ^M is a real carriage return. It can be entered with
8670&lt;c-v&gt;&lt;c-m&gt;.
8671
8672Another use is when you want to enter a bunch of normal commands together.
8673For example, if you were looking to find a '{' to highlight and delete
8674a C block. The '{' may not be on the same line so you can't use the "f"
8675normal command.
8676
8677:normal V/{/^M%d
8678
8679A drawback to using the normal command is that if the pattern does not
8680match then it is difficult to detect. Also, you can get in trouble with
8681the wrapscan setting.
8682
8683For 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
8689HREF="http://vim.sf.net/tip_view.php?tip_id=317">http://vim.sf.net/tip_view.php?tip_id=317</A><BR>
8690
8691If you use VIM you like the h, j, k, and l movement keys. I found myself
8692annoyed at not having these movement keys available when browsing web pages.
8693Moving to the arrow keys on a laptop is annoying to just scroll the page.
8694
8695Locate your mozilla/res/builtin directory (varies by platform). You could
8696search for htmlBindings.xml to find it. (ie. locate htmlBindings.xml.
8697
8698On Mac OS X it's inside the Mozilla application bundle.
8699/Applications/Mozilla/Mozilla.app/Contents/MacOS/res/builtin.
8700
8701Create a new XML file called userHTMLBindings.xml, making it executable for
8702all users and making sure the CRLF format is the same as htmlBindings.xml.
8703i.e. on Mac OS X most files use \r but Vim writes \n instead. You can either
8704save the file with Vim as a Mac formatted file or use tr '\n' '\r' &lt;
8705input.xml &gt; output.xml to convert the file.
8706
8707Place 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
8727There are many more bindings one could configure to get Vim like keybindings.
8728You can read <A HREF="http://www.mozilla.org/unix/customizing.html#keys for
8729more information.">http://www.mozilla.org/unix/customizing.html#keys for
8730more information.</A><BR>
8731
8732PS. I love the keymaster/gatekeeper xul reference in the xul URL above.
8733It's from the original GhostBusters movie. ;-)
8734
8735
8736
8737</pre></tip> </html> <Tip category="KVim"> <html><center>Extended
8738Bracket and Parenthesis + extras for perl</center> <pre> <A
8739HREF="http://vim.sf.net/tip_view.php?tip_id=318">http://vim.sf.net/tip_view.php?tip_id=318</A><BR>
8740
8741This is an extension of vimtip #153 I found this tip useful, but the jump
8742seemed out of place for me, I couldn't enter just one ' or ", and so I created
8743an improvement Basically, I set it up so that when you're in perl and have
8744a non keyword charcter, (except for @, $ and % for perl) and you type a {
8745you get: {
8746 | &lt;- cursor
8747} Where as, when I have a keyword I get: word{} With the cursor in the middle,
8748for hashes in perl. I can jump out of any block, except the "" or '' blocks,
8749by typing their closing charcter. So } jumps me out past the next } in
8750the file.
8751
8752Warning, this search may wrap around.
8753
8754Finally, 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
8757a &lt; &lt;Alt-.&gt; inserts a &gt;
8758
8759"######################################## " File -
8760matchMe.vim " Date - Wednesday, August 21, 2002
8761"########################################
8762
8763" This code fixes my problem with " does the one format for perl and still
8764keeps 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
8779endfunction
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
8785endfunction
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;
8789inoremap &lt; &lt;&gt;&lt;esc&gt;i&lt;c-o&gt;:echo &lt;cr&gt;
8790inoremap ( ()&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;
8793inoremap ) &lt;c-r&gt;=JumpNext(")")&lt;cr&gt;
8794inoremap ] &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; }
8797inoremap &lt;m-,&gt; &lt; inoremap &lt;m-.&gt; &gt; inoremap &lt;m-'&gt; '
8798
8799"######################################## " End Of File
8800"########################################
8801
8802If you have any other suggestions, drop a note...
8803
8804</pre></tip> </html> <Tip category="KVim"> <html><center>text
8805formatting (lining up ='s,('s etc))</center> <pre> <A
8806HREF="http://vim.sf.net/tip_view.php?tip_id=319">http://vim.sf.net/tip_view.php?tip_id=319</A><BR>
8807
8808some time onw would like to reformat text like a=1; foo=2; longstring=1; c=2
8809
8810to
8811
8812a =1; foo =2; longstring =1; c =2;
8813
8814Note I am not sure wether the code above is displayed properly in your browsers
8815what is basically shows is all the ='s are lined up in a single column
8816and this is how we achive it 0f=20i&lt;space&gt;&lt;esc&gt;020lvf=hx and
8817this is what it does 0 goes to first column f=
8818finds next occurance of = on current line 20i&lt;space&gt;&lt;esc&gt;
8819inserts 20 spaces before = 0 goesback to
8820first column 20l forward 20 column vf=hx
8821deletes everything up to the = sign
8822
8823</pre></tip> </html> <Tip category="KVim">
8824<html><center>Borland pageup/down behavier</center> <pre> <A
8825HREF="http://vim.sf.net/tip_view.php?tip_id=320">http://vim.sf.net/tip_view.php?tip_id=320</A><BR>
8826
8827borlandbehavier = the cursor keeps the same xy position during pageup/down
8828
8829Im new to VIM scripting, im sure it can be done smarter? I read vimtip #105
8830and 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.
8833function 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
8839endfunc
8840
8841" noremap &lt;PageUp&gt; 39&lt;C-U&gt;:set scroll=0&lt;CR&gt;
8842function! MyPageUp()
8843 let visible_lines = GetNumberOfVisibleLines() execute "normal "
8844 . visible_lines . "\&lt;C-U&gt;:set scroll=0\r"
8845endfunction
8846
8847" noremap &lt;PageDown&gt; 39&lt;C-D&gt;:set scroll=0&lt;CR&gt;
8848function! MyPageDown()
8849 let visible_lines = GetNumberOfVisibleLines() execute "normal "
8850 . visible_lines . "\&lt;C-D&gt;:set scroll=0\r"
8851endfunction
8852
8853" BorlandPascal pageup/down behavier! " todo: when hitting top/bottom of file,
8854then restore Y to lastY noremap &lt;PageUp&gt; :call MyPageUp()&lt;CR&gt;
8855noremap &lt;PageDown&gt; :call MyPageDown()&lt;CR&gt;
8856
8857</pre></tip> </html> <Tip category="KVim"> <html><center>Centura
8858swap with upper/lower line behavier</center> <pre> <A
8859HREF="http://vim.sf.net/tip_view.php?tip_id=321">http://vim.sf.net/tip_view.php?tip_id=321</A><BR>
8860
8861I was once forced to use a windows development suite called "Centura".
8862The only good thing i remember was its swap current_line with upper/lower line.
8863
8864function! MySwapUp()
8865 let cur_col = virtcol(".") normal ddkkp execute "normal " . cur_col . "|"
8866endfunction
8867
8868function! MySwapDown()
8869 let cur_col = virtcol(".") normal ddp execute "normal " . cur_col . "|"
8870endfunction
8871
8872" swap lines and preserve cursorx " todo: in visual mode, perform swap with
8873line before/after the selection noremap &lt;S-Up&gt; :call MySwapUp()&lt;CR&gt;
8874noremap &lt;S-Down&gt; :call MySwapDown()&lt;CR&gt;
8875
8876</pre></tip> </html> <Tip category="KVim"> <html><center>text
8877template with placeholders</center> <pre> <A
8878HREF="http://vim.sf.net/tip_view.php?tip_id=322">http://vim.sf.net/tip_view.php?tip_id=322</A><BR>
8879
8880Many scripts/ftplugin provide text or code templates. Sadly none of the
8881marks the places where you are supposed to "fill in the form". My own code
8882templates for C/C++ insert a triple percent (%%%) where you are supposed to
8883enter something. I mapped ;; to find the next %%% and change them. All the
8884template mappings are insert-mode only, while the "skip to next placeholder"
8885is both insert and normal mode enabled.
8886
8887A 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
8892The 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
8897Every time I need a for-loop ;fo produces this ( _ is the cursor position)
8898: for( _; %%% ; %%%) { // %%%
8899 %%%
8900}
8901
8902Now I enter starting value (i=0): for( i=0_; %%% ; %%%) { // %%%
8903 %%%
8904}
8905
8906and go to the condition using ;; for( i=0; _ ; %%%) { // %%%
8907 %%%
8908}
8909
8910and so forth.
8911
8912The choice of %%% proved to be almost universal, it even works in MATLAB or
8913LaTeX where % is the comment character.
8914
8915Even if you forget to replace one %%%, that's not a problem as the compiler
8916flags is as a syntax error (except MATLAB and LaTeX, of course).
8917
8918It 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
8922HREF="http://vim.sf.net/tip_view.php?tip_id=323">http://vim.sf.net/tip_view.php?tip_id=323</A><BR>
8923
8924set foldmarker=\\begin,\\end set foldmethod=marker
8925
8926this is useful with big latex document
8927
8928</pre></tip> </html> <Tip category="KVim"> <html><center>Search
8929and replace in files named NAME</center> <pre> <A
8930HREF="http://vim.sf.net/tip_view.php?tip_id=324">http://vim.sf.net/tip_view.php?tip_id=324</A><BR>
8931
8932I'm not sure if there is a simple way to do this from within Vim, but,
8933I wrote this simple script that does it. It basically searches for files
8934named NAMED (whatever name pass) for a given string and replaces that with
8935a given string: find_replace.sh NAMED "string_to_find" "string_to_replace"
8936
8937This is all done from the command line without opening Vim.
8938
8939Of 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
8948As suggested in the Vim help files :-) but, I wanted to go and find only
8949these 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
8962for java/ant/junit/cygwin/bash</center> <pre> <A
8963HREF="http://vim.sf.net/tip_view.php?tip_id=325">http://vim.sf.net/tip_view.php?tip_id=325</A><BR>
8964
8965If you program in Java and use Jakarta ant for builds *and* if you have the
8966bash shell, this tip will make your development experience a little smoother.
8967
8968This tip will result in a working compile/edit/debug system (in Win32 vim/gvim
8969and in Cygwin vim) that takes you to the exact lines where the build fails,
8970whether the failure is a compilation error or a junit test failure. If you
8971use bash on a linux box, you shouldn't have to change very much to get
8972everything to work.
8973
8974There are 6 sections: 1. set up your build script 2. set up makeprg 3. set
8975up shell options 4. set up path formatting options 5. set up your errorformat
89766. set up key mappings
8977
8978Set up build script ------------------- Add the following script to your path
8979(I use /usr/local/bin/):
8980
8981mymake: #!/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
8984Comment: sed -u is non-standard, use the code at: <A
8985HREF="http://mail.gnu.org/pipermail/bug-gnu-utils/2002-May/000192.html to
8986get">http://mail.gnu.org/pipermail/bug-gnu-utils/2002-May/000192.html to
8987get</A><BR> the -u option for sed (this avoids waiting for the build output
8988to get to the screen)
8989
8990testerrors.sed: # This assumes that all your junit test cases are in a com.*
8991package /^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
9005Set 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
9009Set up shell options -------------------- Add the following lines to your
9010vimrc:
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
9017Also to use this environment in Win32 gvim, you must recompile vimrun so
9018that gvim invokes the shell via bash, not via cmd.exe.
9019
9020Set up path formatting options ------------------------------ Add the
9021following lines to your vimrc:
9022 " allows DOS file names from UNIX (Cygwin) vim set isfname+=\
9023
9024Set up your errorformat ----------------------- Add the following lines to
9025your 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
9044NOTE: Make sure that the character before "at" is an actual Tab character
9045in the three long -Z lines above
9046
9047Here 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
9086Set 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
9090This allows for quick error navigation.
9091
9092NOTES ----- Vim treats the "Entering: /work/src/..." messages in a weird way.
9093If 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
9096since they don't include any line numbers, the cursor position is never moved.
9097
9098I thought that this was strange, but even stranger, it is programmed directly
9099into the vim error handling code to function exactly this way. There were
9100no comments, and nobody responded on the vim mailing list, so I just decided
9101to live with it.
9102
9103The upshot of it all is that if you see an error like "Entering:", chances
9104are that your build succeeded and all the tests ran without a problem.
9105
9106Hope this helps...
9107
9108Mail me with bugs at jdsumsion at earthlink.net.
9109
9110</pre></tip> </html> <Tip category="KVim"> <html><center>Help
9111for VIM Help (VIM QuickRef)</center> <pre> <A
9112HREF="http://vim.sf.net/tip_view.php?tip_id=326">http://vim.sf.net/tip_view.php?tip_id=326</A><BR>
9113
9114Type :help quickref or :h quic
9115
9116And get a VIM Command Quick Reference Page brilliant for beginners &
9117oldtimers alike
9118
9119type :h help to learn how to use help
9120
9121Other Help Tips
9122
9123# help for help :h visual&lt;C-D&gt;&lt;tab&gt; : obtain list of all
9124visual 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;
9129in insert mode :h c_CTRL-R : help for say &lt;C-R&gt; in command
9130mode :h v_CTRL-V : visual mode :h tutor : VIM Tutor
9131
9132These 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
9136HREF="http://vim.sf.net/tip_view.php?tip_id=327">http://vim.sf.net/tip_view.php?tip_id=327</A><BR>
9137
9138I use my left thumb for the alt key and right for the space. Using this
9139combo, you can get some useful key maps for which you don't have to move
9140your hands. I find I have to turn my hand a little to press the left ctrl key.
9141
9142These are some maps i use for C programming.
9143
9144map ' ` 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
9148Tags map &lt;M-c&gt; I/*&lt;Esc&gt;A*/&lt;Esc&gt;
9149Comment current line map &lt;M-d&gt; ^xx$xx
9150Delete comment for a single line map &lt;M-l&gt;
9151[{zf% Fold upto the enclosing brace
9152level map &lt;M-o&gt; zo open fold
9153map &lt;M-i&gt; zc close fold map
9154&lt;M-.&gt; :cn&lt;C-m&gt; Go
9155to next error in list map &lt;M-,&gt; :cp&lt;C-m&gt;
9156previous error in list
9157
9158imap &lt;Tab&gt; &lt;C-p&gt;
9159Complete word inoremap &lt;S-Tab&gt; &lt;Tab&gt;
9160Tab inoremap { &lt;CR&gt;{&lt;CR&gt;
9161Brace and line inoremap } &lt;CR&gt;}
9162brace and line. saves one enter stroke
9163
9164imap &lt;M-j&gt; &lt;Esc&gt;
9165Escape. Don't want to move my hand to esc key. imap &lt;M-k&gt; &lt;C-y&gt;
9166Copy line from above. imap &lt;M-q&gt; /* */&lt;Esc&gt;hhi
9167Comment selected lines
9168
9169noremap &lt;M-r&gt; ddko{&lt;C-m&gt;}&lt;Esc&gt;kpko Convert a
9170simple statement to a compound statement. And place cursor above prev line.
9171noremap &lt;M-k&gt; ddko{&lt;C-m&gt;}&lt;Esc&gt;kpo Same as
9172above but place cursor below old line.
9173
9174vnoremap &lt;M-j&gt; &lt;Esc&gt; vnoremap &lt;M-c&gt;
9175di/*&lt;C-m&gt;/&lt;C-m&gt;&lt;Esc&gt;kkp Commented selected text
9176
9177nmap &lt;M-n&gt; :noh&lt;CR&gt; No hilight
9178
9179Bye,
9180 Nithin.
9181
9182</pre></tip> </html> <Tip category="KVim"> <html><center>Vim
9183in Microsoft Visual Foxpro</center> <pre> <A
9184HREF="http://vim.sf.net/tip_view.php?tip_id=328">http://vim.sf.net/tip_view.php?tip_id=328</A><BR>
9185
9186You can tell MS VFP to use an external editor for editing project files.
9187To tell MS VFP to use Vim:
9188
9189start regedit locate [HKEY_CURRENT_USER
9190 \Software
9191 \Microsoft
9192 \VisualFoxPro
9193 \5.0
9194 \Options]
9195
9196and create a new item TEDIT with string content "/N
9197C:\Progra~1\vim\vim61\gvim.exe" (or whatever your path to Vim happens to be.)
9198
9199This 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,
9201VFP will fire up gvim.
9202
9203Start 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
9207HREF="http://vim.sf.net/tip_view.php?tip_id=329">http://vim.sf.net/tip_view.php?tip_id=329</A><BR>
9208
9209Put 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
9214Then when you put the cursor on or in a word, press "gw", and the word will
9215be swapped with the next word. The words may even be separated by punctuation
9216(such as "abc = def").
9217
9218While we're talking swapping, here's a map for swapping characters:
9219
9220 nmap &lt;silent&gt; gc xph
9221
9222This hint was formed in a collaboration between Chip Campbell - Arun Easi -
9223Benji Fisher
9224
9225</pre></tip> </html> <Tip category="KVim">
9226<html><center>how to stop auto indenting</center> <pre> <A
9227HREF="http://vim.sf.net/tip_view.php?tip_id=330">http://vim.sf.net/tip_view.php?tip_id=330</A><BR>
9228
9229Since VIM 6.0 the indent has been improved so much. But sometimes when
9230we are pasting formated text (source code or HTML etc) into a buffer, VIM
9231indents again so that lines will be padded with too much spaces.
9232
9233Setting nocindent, noautoindent, nosmartindent still cannot stop this. All you
9234need to do is "set paste", then paste your stuff, and then "set nopaste" again.
9235
9236Ref: indentexpr
9237
9238</pre></tip> </html> <Tip category="KVim">
9239<html><center>modline magic...</center> <pre> <A
9240HREF="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
9243useful is that you can store by-file settings... that is each file can
9244contain settings specific to it. this thing is called a modline (:help
9245modline). though this is limited to only the 'set' command arguments, you
9246can do allot of local to file things like the indent type, folding method
9247and so on.
9248
9249the syntax is as follows:
9250
9251// vim:set ts=4 sw=4 nowrap:
9252
9253or
9254
9255/* vim:noai:ts=2:sw=4: */
9256
9257 The modlines can be contained in comments so as to not interfere with
9258the file syntax (shown here for C/C++). these lines are read by vim when
9259it loads the file, and they can either be in the first or last 5 lines
9260(by default).
9261
9262refer 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
9268HREF="http://vim.sf.net/tip_view.php?tip_id=332">http://vim.sf.net/tip_view.php?tip_id=332</A><BR>
9269
9270I found at <A
9271HREF="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>
9272a macro to insert footnotes in vim, but it doesn't work as of vim6.0. so i
9273wrote my own; this macro requires two differents shortcuts, one for entering
9274the first footnote, the other one for all subsequent footnotes.
9275
9276when you hit "K0" (first footnote) or "KK" (all other footnotes) in normal
9277mode, your cursor is positionned at the end of the document, in the footnote &
9278in insert mode. The "a" bookmark is set to the place where you entered the
9279footnote in the text. so a "`a" will bring you back to the location of the
9280footnote in the text.
9281
9282" for now requires entering K0 for the first footnote and then KK
9283nmap K0 i[0]&lt;esc&gt;maG$i&lt;end&gt;&lt;enter&gt;[0] nmap KK
9284maG$?\[[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
9288HREF="http://vim.sf.net/tip_view.php?tip_id=333">http://vim.sf.net/tip_view.php?tip_id=333</A><BR>
9289
9290Here's a function to toggle the use of syntax-based folding for a c/c++/java
9291file. It also handles folding markers.
9292
9293function! 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
9312endfunction
9313
9314</html></tip>