Вы находитесь на странице: 1из 1643

tips : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
Browse all
Download all
Karma
My Account

Vim Tips (add tip)


"...Can you imagine how many keystrokes could have been saved, if I only
had known the "*" command in time?" - Juergen Salk, 1/19/2001

Recent Tip Additions (browse all | search | download all)


[2004-02-18] tip #659 - Collect filenames of current subtree (Siegfried Bublitz)
[2004-02-18] tip #658 - Switching to unit test module for python (Max

Ischenko)
[2004-02-17] tip #657 - have a question about vim? (Adam Wolff)
[2004-02-16] tip #656 - Recursive mappings - (2 examples to learn from)

Site Help

(Mohit Kalra)

What are tips?

[2004-02-16] tip #655 - search with one key (vim_user)

This is a place where users of


the vim editor can add their
favorite commands, macros and
other assorted tips to a common
database. While the vim
distribution comes with a rich
set of documentation it is often
hard to find a place to start
when trying to incrementally
learn how to use the editor.

[2004-02-15] tip #654 - special characters in VIM substitution (Hyouck Kim)


[2004-02-10] tip #653 - doxygen '///' :comments setting (Michael Brailsford)
[2004-02-06] tip #652 - save all open buffers at once (Andreas Berg)
[2004-02-05] tip #651 - Edit gnupg-encrypted files. (Frank Price)
[2004-02-04] tip #650 - abbreviation that prompts whether to expand it or not

Why tips?

(Yakov Lerner)

When I realized how much I


was learning from the vim list
alone I thought it would be great
to have a place that the
community could maintain a list
of their favorite vim gems. The
overall goal is to have a place
you can visit when you are in a
vim learning mood or when you
"discover" something
particularly powerful and want
to share it with other vim users.

Displaying 10 of 653 (more)

http://www.vim.org/tips/ (1 of 2) [18/02/2004 14:39:54]

tips : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/ (2 of 2) [18/02/2004 14:39:54]

SourceForge
Logo

search results : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
Browse all
Download all
Karma
My Account

search results
Showing 1 to 20 of 653
results

Searched tips for ""


tip

author

rating views

created

summary

659

Siegfried Bublitz

49 2004-02-18

Collect filenames of
current subtree

658

Max Ischenko

50 2004-02-18

Switching to unit test


module for python

657

Adam Wolff

191 2004-02-17

have a question about


vim?

656

Mohit Kalra

14

202 2004-02-16

Recursive mappings - (2
examples to learn from)

655

vim_user

-4

259 2004-02-16 search with one key

654

Hyouck Kim

240 2004-02-15

special characters in
VIM substitution

653 Michael Brailsford

383 2004-02-10

doxygen '///' :comments


setting

652

Andreas Berg

594 2004-02-06

save all open buffers at


once

651

Frank Price

11

461 2004-02-05

Edit gnupg-encrypted
files.

Site Help

650

Yakov Lerner

abbreviation that
391 2004-02-04 prompts whether to
expand it or not

649

Yakov Lerner

293 2004-02-04

expand existing
abbreviation

648

Michael Geddes

11

634 2004-02-01

Uniq - Removing
duplicate lines

647

Astrobe

-1

777 2004-01-30 Single letter insert

646

Frank Butler

37

927 2004-01-28

645

Girish Gajwani

http://www.vim.org/tips/tip_search_results.php (1 of 2) [18/02/2004 14:40:02]

moving lines up/down in


a file

Enabling Windows
shortcuts (eg alt+space,
589 2004-01-28
F10 etc) for gvim
window

search results : vim online

644

stsi

16

643

Alfvaen

642

641

640

David Risner

Olivier Teuliere

Mark Fernandes

510 2004-01-27 restoring indent for '#'


307 2004-01-26

Disable built-in
command

13

Windows: Get K to not


493 2004-01-21 display a DOS box that
needs closing

17

Highlighting of method
727 2004-01-21 names in the definition
(C++)

See your vim templates


532 2004-01-20 in Windows Explorer's
New context menu
Showing 1 to 20 of 653
results

prev | next

keywords
sort by

Rating

Descending

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip_search_results.php (2 of 2) [18/02/2004 14:40:02]

search

cancel

SourceForge
Logo

download tips : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Tip Download
You can download the vim tip database as a text file for easy reading offline. Benji Fisher has also written a vim script (vimtips.zip) that will emulate
"tip of the day" functionality.
download

Scripts
Tips
Browse all
Download all
Karma
My Account
Site Help

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip_download.php [18/02/2004 14:40:06]

SourceForge
Logo

add a tip : vim online

not logged in (login)

Home
Search

Add a Tip
author

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

as of

5.7

complexity basic

summary
Your tip should include some context to why one might want to use the tip and
references to vim help for additional reading. All HTML in descriptions will be escaped for
security reasons. If you want to use links, just enter "http://...." and it will be turned into a
link. Spaces and returns will be maintained so the general structure of your tip will be as
you entered it. If you want to refer to other tips or scripts you should use the syntax
"keyword #id" and it will be linked to the correct place. For example: vimtip #6 or
vimscript #10.

add

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/add_tip.php [18/02/2004 14:40:08]

cancel

SourceForge
Logo

Tip #1 - the super star : vim online

not logged in (login)

Home
Search

Tip #1: the super star


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2592/868, Viewed by 25211

created: February 24, 2001 14:47


author: scott at kintana.com

complexity: basic
as of Vim: 5.7

When a discussion started about learning vim on the vim list Juergen
Salk mentioned the "*" key as something that he wished he had know
earlier. When I read the mail I had to go help on what the heck the
"*" did. I also wish I had known earlier...
Using the "*" key while in normal mode searches for the word under
the cursor.
If that doesn't save you a lot of typing, I don't know what will.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

easy edit of files in the same directory >>

Additional Notes
kunzem@optimiz.com, March 8, 2001 14:51
see vimtip #5 for more detail
jorge@paises.com, August 17, 2001 9:22
Oh boy! What a great discovery! I too wish I knew it earlier...but
better late than never.
dontsendjunk@mailcity.com, September 12, 2001 4:44
if you find "*" useful check out '#' does the same thing but in
reverse order ;-)
Regards
Jags
Anonymous, January 4, 2002 14:00
Jags, you're my hero!!! That was my next question...
matthew.krauski@mu.edu, March 1, 2002 12:44
if you like "#" and "*", and you do lots of nested loops, try using
"%"
sachinnb@rediffmail.com, March 3, 2002 9:27
U can also search patterns by just left clicking the mouse on the
word U want to search while keeping the shift button pressed !!!
--- sachin
http://www.vim.org/tips/tip.php?tip_id=1 (1 of 7) [18/02/2004 14:40:13]

Tip #1 - the super star : vim online

gsinclair@soyabean.com.au, April 4, 2002 20:44


Another thing worth knowing that is related to this: when entering
a search, hit <C-R><C-W> and the word under the cursor will appear
in your search. This is very useful if you want to search for some
variation of the word under the cursor.
--Gavin
Thomas.Ramming@gmx.de, April 19, 2002 3:59
If you have already searched anything, type '/' or '?' and use arrow
up/down to get the last search patterns/commands.
hennylieuw@hotmail.com, May 3, 2002 6:57
In addition to / and arrow keys you can also just type "n" to search
(again) for the next instance.
vvauzi@yahoo.com, May 14, 2002 3:36
Here's a mapping that lets */# search for the selected text in
VISUAL MODE. Put this into your .vimrc file:
" Search for selected text in visual mode with */#
" effect: overrides unnamed register
" Simplest version: vnoremap * y/<C-R>"<CR>
" Better one: vnoremap * y/\V<C-R>=escape(@@,"/\\")<CR><CR>
" This is so far the best, allowing all selected characters and
multiline selection:
" Atom \V sets following pattern to "very nomagic", i.e. only the
backslash has special meaning.
" As a search pattern we insert an expression (= register) that
" calls the 'escape()' function on the unnamed register content
'@@',
" and escapes the backslash and the character that still has a
special
" meaning in the search command (/|?, respectively).
" This works well even with <Tab> (no need to change ^I into \t),
" but not with a linebreak, which must be changed from ^M to \n.
" This is done with the substitute() function.
vnoremap * y/\V<CR>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>
vnoremap # y?\V<CR>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>
dpscr@yahoo.com, July 12, 2002 19:05
I discovered the "#" and "*" commands after forgetting to go to
insert mode at the beginning of a new c source file about seventy
times. I'd start to type "#include", and get the error message: "No
string under cursor." I finally decided to look it up.
vdhingra@hss.hns.com, July 26, 2002 2:42
This is really great.
I feel I've entered into a new world of VIm
Thx
iskoryh@ukr.net, August 13, 2002 4:12

http://www.vim.org/tips/tip.php?tip_id=1 (2 of 7) [18/02/2004 14:40:13]

Tip #1 - the super star : vim online

Please pardon me, but I can't understand how on earth "*" command
can save me typing. Could somebody provide example scenarios where
it may be helpful?
juddkenneth@yahoo.com.hk, August 19, 2002 2:25
You normally would search for the occurence of a word by typing
"/_Your_Very_Big_And_Untidy_Word_That_Has_A_Lot_Of_UnderScores_<CR>"
followed by 'n's and 'p's. If you have the word you want to search
for under the cursor, you can just press '*' or '#' to go to the
next or previous occurence of that word.
milindacharya_2000@yahoo.com, September 4, 2002 3:27
That is just great. Thanks for giving this tip.
laloo@rabri.com, September 10, 2002 4:37
bahut aacha hai bhaiya .
koi ghotala nahi
Anonymous, September 12, 2002 22:43
stated using, looking at VIM today...good tip to start out with!
Anonymous, October 15, 2002 7:32
...and for those n00bs out there (like myself...) it's NOT the mouse
cursor we're talking about here! duh...
maylward@iprimus.com.au, October 15, 2002 19:21
Oh, now I see, always wondered how to do that. What is it 2002, I
started using vim exclusively in 1995, quick learner aren't I!!!
That is an exceptional tip, it should be kept back from newer vim
users to avoid them gaining an unfair advantage over old coots like
me.
Cheers and many thanks,
Matt
Anonymous, October 23, 2002 14:19
Ha! I started using vim a few days ago and I just learned this. :P
Anonymous, November 8, 2002 4:57
To heck with "*", in reading this thread I just found out how to put
comments in my _vimrc file for all those cryptic commands I'm
assigning to F-keys. RTFM? Hah! A real engineer only resorts to
documentation when the keyboard dents on the forehead get too
noticeable.
arnarbi@hi.is, November 24, 2002 10:42
Brilliant.. nothing but brilliant!
ssepiro@hotmail.com, January 11, 2003 0:43
fortunately..I have known #,*... ...I just say.that you do "gD" on
the word. :)
I think this is also great!
Anonymous, January 19, 2003 8:46
The fingers usually are closer to the gd combination than the '*',
that's why I don't find '*' to be such a great enhancment...

http://www.vim.org/tips/tip.php?tip_id=1 (3 of 7) [18/02/2004 14:40:13]

Tip #1 - the super star : vim online

narayanpavgi@hotmail.com, January 22, 2003 1:36


I use "*" for to find out where a particular variable has been used
down the file. But when I have done through its occurences, I want
to get back to the line where I first used "*" and continue with the
source. I usually just keep hitting "*" a many more times so that it
cycles around the file and comes to the line where I left off. How
can I shorten this ?
mkantor@dcs.wisc.edu, January 23, 2003 0:00
Set a mark before you start roaming with *. Press m[a-zA-Z]. That
is, m followed by any letter. To return to the mark, press
backquote ( ` ) followed by the same letter. Single quote takes you
to the start of the line containing the mark. Capital letters work
across different files, too.
:marks lets you see the lines on which marks are set.
vim@geert.triple-it.nl, January 24, 2003 2:44
About going back after you've moved to the first '#' or '*'-hit:
typ `` (2 times a backtick) to go back to the last place.
This always works after every jump you make.
In this discussion it works only when you don't move around all #or *-hits of course.
analogue@glop.org, February 5, 2003 7:26
this thing is *huge* !)
Anonymous, April 23, 2003 11:53
>> I
used
want
with

use "*" for to find out where a particular variable has been
down the file. But when I have done through its occurences, I
to get back to the line where I first used "*" and continue
the source. I usually just keep hitting "*" a many more times.

As a side comment: You can simply press 'n' instead of pressing '*'
to continue your search and move on to the next hit. '*' involves
holding down shift, while 'n' does not.
Anonymous, April 23, 2003 11:54
>> gsinclair@soyabean.com.au, Another thing worth knowing that is
related to this: when entering a search, hit <C-R><C-W> and the
word under the cursor will appear in your search. This is very
useful if you want to search for some variation of the word under
the cursor.
This is just about as phenomenal (if not more) as the '*' and '#'
commands themselves !! Thanks dude!
Anonymous, April 27, 2003 16:58
can anybody please tell me what <C-R><C-W> means?
thanks
vario uneseny
Anonymous, April 30, 2003 3:12

http://www.vim.org/tips/tip.php?tip_id=1 (4 of 7) [18/02/2004 14:40:13]

Tip #1 - the super star : vim online

<C-R><C-W> means 'Hold down CTRL, press R, press W, release


CTRL'. Or, verbally, Control R, Control W.
anon, May 24, 2003 2:26
Regarding getting back to where you first pressed * from.. I good
idea is to press (capital) N which does the search in reverse. Might
be quicker and easier than pressing n several times until you wrap.
Setting hlsearch is good too.
Also, * is just one keypress on most keyboards... on the numeric
keypad.
Anonymous, June 15, 2003 10:04
thanks for reminding that * is one stroke
Anonymous, July 3, 2003 15:51
err... someone knows how to unmark words previously marked with '*'
, '#' or '/' ?
My way is /~ (not always works of course)
BIG THX
Anonymous, July 3, 2003 19:12
i found vimtip #14 about it.
slemansadi@hotmail.com, July 7, 2003 0:54
hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

slemansadi@hotmail.com
fozemohammed@yahoo.com, July 25, 2003 11:41

vimbigot at fastmail.fm, August 5, 2003 23:29


you can also jump backwards after a * by using <C-o> as in controlo. control-i will let you jump forward again. You guessed it, it is
a jump stack.
also I toggle highlighting when doing a search, and turn it off when
I have stopped searching. The next search turns it back on again.
from my _vimrc
" don't leave highlighting on for ever, but turn back when a new
search
" starts or the last one is repeated
http://www.vim.org/tips/tip.php?tip_id=1 (5 of 7) [18/02/2004 14:40:13]

Tip #1 - the super star : vim online

nnoremap
nnoremap
nnoremap
nnoremap
nnoremap
nnoremap
nnoremap

<F7> :se nohls<cr>


n :set hls<CR>n
N :set hls<CR>N
* :set hls<CR>*
# :set hls<CR>#
/ :set hls<CR>/
? :set hls<CR>?

Anonymous, August 8, 2003 2:52


Your mapping is not necessary, except F7. Instead of using ":set
noh" use ":noh". Rest is done automaticaly.
Anonymous, September 29, 2003 15:59
many thanks to
this.

vvauzi@yahoo.com for the visual mode version of

here's a tweak of that which works in --SELECT-- mode:


vnoremap <M-/> y/\V<CR>=substitute(escape(@@,"/\\"),"\n","\\\\n","ge")<CR><CR>gV
vnoremap <M-?> y?\V<CR>=substitute(escape(@@,"?\\"),"\n","\\\\n","ge")<CR><CR>gV
(note that i map the commands to META-/ and META-? instead of * and
# because i want to keep the option of replacing the selection with
*/#.)
tha_code_buster@hotmail.com, October 13, 2003 10:47
COME ON PEOPLE !!!! It's just another command! Don't have an orgasm
over it! Ooooooh! That's what it's all about!!!???
Rodge
jimk@hotmail.com, December 1, 2003 12:52
"tha_code_buster" Rodge's juvenile comment notwithstanding, thanks
to all for the great tips!
no-social-life-on-friday-evening@hothotmail.com., December 12, 2003 19:32
Go get a life without a #nerds*, stop worshipping vim
and start using it.
Guido@VanHoecke.org, January 15, 2004 15:14
From my .vimrc :
" Clears search highlighting by just hitting a return.
" The <BS> clears the command line.
" (From Zdenek Sekera [zs@sgi.com] on the vim list.)
" I added the final <cr> to restore the standard behaviour of
" <cr> to go to the next line
:nnoremap <CR> :nohlsearch<CR>/<BS><CR>
I like this approach: <CR> is more likely than most other keys, at
least when in normal mode, and you don't loose any key with this
approach. (Thanks Zdenek).
Add Note

http://www.vim.org/tips/tip.php?tip_id=1 (6 of 7) [18/02/2004 14:40:13]

Tip #1 - the super star : vim online


If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=1 (7 of 7) [18/02/2004 14:40:13]

SourceForge
Logo

Tip #2 - easy edit of files in the same directory : vim online

not logged in (login)

Home
Search

Tip #2: easy edit of files in the same directory


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 79/47, Viewed by 3363

created: February 24, 2001 14:57


author: scott at kintana.com

complexity: intermediate
as of Vim: 5.7

It was often frustrating when I would open a file deep


in the code tree and then realize I wanted to open
another file in that same directory. Douglas Potts
taught me a nice way to do this. Add the following
snipit to your vimrc:
"
Edit another file in the same directory as the
current file
"
uses expression to extract path from current file's
path
" (thanks Douglas Potts)
if has("unix")
map ,e :e <C-R>=expand("%:p:h") . "/" <CR>
else
map ,e :e <C-R>=expand("%:p:h") . "\" <CR>
endif
Then when you type ,e in normal mode you can use tab to
complete to the file. You can also expand this to allow
for spitting, etc. Very very nice.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<the super star | use vim to quickly compile java files >>

Additional Notes
bstrohhaecker@hueller-hille.com, May 30, 2001 2:08
For not-unix-systems you need two backslashes, so use:
map ,e :e <C-R>=expand("%:p:h") . "\\" <CR>
Sometimes it may also be useful to change to the file's
directory.
map ,cd :cd %:p:h<CR>

http://www.vim.org/tips/tip.php?tip_id=2 (1 of 3) [18/02/2004 14:40:15]

Tip #2 - easy edit of files in the same directory : vim online

desert_storm2001@hotmail.com, July 6, 2001 3:26


map ,e :e <C-R>=expand("%:p:h") . "\\" <CR>
Will leave a space after printing the directory name.
Use this, if you don't want the leave space after the
directory name.
map ,e :e <C-R>=expand("%:p:h") . "\\"<CR>
Remove the space after "\\".
Jim Hill <jthill@users.sf.net>, March 20, 2002 9:22
Do `:help path` for the vim-6 builtin way to do this.
Anonymous, August 28, 2003 18:44
Jim Hill, could you point out how to use the Vim6 builtin function to do that?
Run the command
:help path
under Vim6.2 I got this:
This is a list of directories which will be searched
when using the
|gf|, [f, ]f, ^Wf, |:find| and other commands,
provided that the file
being searched for has a relative path (not
starting with '/'). The
directories in the 'path' option may be
relative or absolute.
I don't know how to fulfill the goal of this tip.
huzhipeng@hotmail.com, December 8, 2003 23:22
You can use vim 6 built-in command:
:cd %:h
It's really excellent.
--Zhipeng Hu
yulya@vdcom.ru, January 15, 2004 4:21
To expand current file directory in the command line
you may also do something like
cmap %/ <C-R>=expand("%:p:h")."/"<cr>
in your .vimrc and use this mapping with :e, :w and any
other command.
Add Note

http://www.vim.org/tips/tip.php?tip_id=2 (2 of 3) [18/02/2004 14:40:15]

Tip #2 - easy edit of files in the same directory : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=2 (3 of 3) [18/02/2004 14:40:15]

SourceForge
Logo

Tip #3 - use vim to quickly compile java files : vim online

not logged in (login)

Home
Search

Tip #3: use vim to quickly compile java files


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 215/84, Viewed by 9846

created: February 24, 2001 15:05


author: scott at kintana.com

complexity: advanced
as of Vim: 5.7

For a number of years I used vim on an SGI box. When I


left my job at SGI I went to a company that developed on
PCs. For 2 years I used IDEs. I was unhappy. I was
frustrated. I couldn't figure out why. (Beyond my
machine crashing twice a day.) Finally I upgraded to
windows 2000 (kind of stable!) and started using vim as
an IDE. All was good. Here is how you use vim to compile
your java:
1. While I'm sure this works with javac, javac is slow
slow slow. So download the Jikes complier first. (Jikes
is from ibm, search on google for jikes and you will
find it..available on most platforms.)
2. Add the following to your vimrc:
set makeprg=jikes -nowarn -Xstdout +E %
set errorformat=%f:%l:%c:%*\d:%*\d:%*\s%m
3. When you are editing a java file type :make and it
will compile the current file and jump you to the first
error in the file (if any). Read ":help quickfix" for
how to move between errors.
To setup your classpath environment either launch gvim
from a shell that has your classpath/path setup or use
the "let" command to configure it in your vimrc.
rate this tip

Life Changing

Helpful

Unfulfilling

<<easy edit of files in the same directory | Any word completion >>

Additional Notes
slabounty@netaphor.com, April 20, 2001 13:17
http://www.vim.org/tips/tip.php?tip_id=3 (1 of 8) [18/02/2004 14:40:18]

rate

Tip #3 - use vim to quickly compile java files : vim online

You also may want to try using ant as your makeprg as


follows:
set makeprg=ant.bat " Use ant as the makefile (remove
.bat on *nix machines) you can get ant from reference
below.
and setting your errorformat to:
"For ant (http://jakarta.apache.org/) the above
errorformat has to be modified
"to honour the leading [javac] in front of each javac
output line:
:set errorformat=%A%*\s%[javac%\] %f:%l:
%m,%Z%*\s%[javac%\] symbol%*\s: %m
Put both of these in your .vimrc, use the :cn and :cp
commands and have fun.
Scott
vimonline@lonsky.com, June 27, 2001 7:05
Another quick way of getting :make to work with ant is
to add the following line to your .vimrc file
makeprg=ant\ -emacs
The -emacs option converts Java formatted error
messages to C-like error messages. This way you don't
have to mess with the errorformat (efm) string (which I
was never able to get to work).
leifw@bigfoot.com, July 13, 2001 21:55
Step 2 of the original comment should probably have the
spaces escaped with whacks, such as
set makeprg=jikes\ -nowarn\ -Xstdout\ +E\ %
set errorformat=%f:%l:%c:%*\d:%*\d:%*\s%m
It works much better for me that way, anyhow.
leifw@bigfoot.com, August 31, 2001 16:25
Oops. Let me revise that. It should've been:
set makeprg=jikes\ -nowarn\ -Xstdout\ +E\ %
set errorformat=%f:%l:%c:%*\\d:%*\\d:%*\\s%m
jeff@socialchange.net.au, November 12, 2001 21:55

http://www.vim.org/tips/tip.php?tip_id=3 (2 of 8) [18/02/2004 14:40:18]

Tip #3 - use vim to quickly compile java files : vim online

Hmm.. none of the solutions above let you specify a


classpath for jikes. I currently have the following in
my .vimrc:
set makeprg=jikes\ -nowarn\ -Xstdout\ +E\ -classpath\
$CLASSPATH\ %
set errorformat=%f:%l:%c:%*\\d:%*\\d:%*\\s%m
However, the $CLASSPATH isn't expanded. Is there some
trick to this?
thanks,
--Jeff
maxiangjiang@hotmail, January 8, 2002 10:24
use the following to expand $CLASSPATH
<C-R>=$CLASSPATH<CR>
thane777@yahoo.com, May 31, 2002 21:56
Whenever I try to use jikes it never gets off the
ground. I get:
:!jikes -nowarn -Xstdout +E -classpath $CLASSPATH
\Java\Blah_Blah\Blah\filename.java >
C:\DOCUME~1\Owner\LOCALS~1\TEMP\VIe49.tmp
shell returned 1
Any help would be a Godsend!
Thanks!
thane
glenwagley@myrealbox.com, June 24, 2002 22:52
So what if I want to use javac. I know it is slow :). What lines would I add to my .vimrc?
emdot@atlas.cz, August 1, 2002 8:22

http://www.vim.org/tips/tip.php?tip_id=3 (3 of 8) [18/02/2004 14:40:18]

Tip #3 - use vim to quickly compile java files : vim online

I'm using "slow" ;) javac too. I have only this in my


.vimrc:
linux:
set makeprg=javac\ %
set errorformat=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
win:
set makeprg=cmd\ /c\ \"cmd\ \/c\ javac\ %\ 2>&1\"
errorformat is the same
It works fine for me.
I hope it helps....
stevenutt@hotmail.com, September 9, 2002 21:49
How do I add files to my .vimrc?
I am trying to add the javac as well.
stevenutt@hotmail.com, September 9, 2002 21:51
I mean how to I add LINES to my .vimrc?
lists@goecs.net, October 3, 2002 14:02
> how do I add lines to my .vimrc
Open the text file .vimrc with a text editor such as
Vim...
rvijay2001@hotmail.com, December 3, 2002 11:40
On the windows machine... the following works
Download stderr from
http://www.teaser.fr/~amajorel/stderr/ and add it to
your path
set shell=cmd
set makeprg=stderr\ javac\ %
set errorformat=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
To browse through the errors use
:cl
:cn
:cp
dhazel@senatr.com, February 26, 2003 8:09

http://www.vim.org/tips/tip.php?tip_id=3 (4 of 8) [18/02/2004 14:40:18]

Tip #3 - use vim to quickly compile java files : vim online

I am running Win2K and have the following in my vimrc:


set shell=tcsh
if executable("jikes") || executable("jikes.exe")
let&l:errorformat='%f:%l:%v:%*\d:%*\d:%*\s%m'
nn<silent><buffer> [1
\:let&l:mp='jikes -nowarn -d <C-R>=$cp<CR> -Xstdout
+E %:t'<CR>
elseif executable("javac") || executable("javac.exe")
let&l:errorformat='%A%f:%l:%m,%-Z%p^,%-C%.%#'
nn<silent><buffer> [1 :let&l:mp='javac -d <CR>=$cp<CR> %:t'<CR>
endif
when I do :make I get:
:!jikes +E aka.java >
C:/DOCUM~1/dhazel/LOCALS~1/Temp/VIe31f.tmp 2>&1
shell returned 1
E40: Can't open error file ...
When I look in the temp directory the file is not
there. What's wrong?
dhazel@sentar.com, February 26, 2003 9:11
I fat fingered my email address on the last
post. Please send replies to this one.
left0s@hotmail.com, March 14, 2003 8:47
Hi.
Is the -quiet option necessary in ant to make it work
with this errorformat?
set makeprg=ant
set errorformat=%A\ %#[javac]\ %f:%l:\ %m,%-Z\
%#[javac]\ %p^,%-C%.%#
I got this errorformat from the documentation in gvim
v.6.1 but I cant't get it to work.
I have also tried anything else you sugested here but
still...
The version of ant I am using is 1.5.1
do you know if different versions of ant have
differencies in the output format?
Thanks
hiker_51@yahoo.com, April 29, 2003 22:52

http://www.vim.org/tips/tip.php?tip_id=3 (5 of 8) [18/02/2004 14:40:18]

Tip #3 - use vim to quickly compile java files : vim online

I use ant for full builds, but when I am refactoring,


and thus compiling small changes frequently, ant is way
too slow. When compiling frequently I want to use jikes
directly, so I have this in my .vimrc (note that
makejhess is simply a script that executes ant with the
right command line options for me for me):
nmap <F6> :set makeprg=jikes\ -d\ $JHESS_HOME/build\ deprecation\ -Xstdout\ +E\ % <cr> :make <cr> :set
makeprg=makejhess <cr> :cc <cr>
Thus hitting F6 changes my makeprg to jikes, executes
jikes, and then switches makeprg back to ant. It takes
less than a second to build my project with jikes. It
take roughly 4 seconds to build it with ant, so I get a
huge speed up!
lech.ambrzykowski at wp.pl, May 8, 2003 4:08
Some of you might have had problems setting up SUN's
software to work with VIM correctly with WIN32. As far
as compilation is concerned, most of the problems have
been solved (mentioned above). However, I had problems
whenever I tried to create a mapping allowing me to
"execute" my new classes. Typing:
java c:\somejavaprojectsdir\MyCompiledClass
would return an error. However, using
java -cp c:\somejavaprojectsdir MyCompiledClass
would be okay.
I realized it was good enough, if I changed the working
path of the file. One of the tips I found:
cd %:p:h
So, the final thing was to add something like:
augroup filetypedetect
au BufNewFile,BufRead,BufEnter *.java
\ cd %:p:h |
\ map <F9> :w<CR>:!javac "%"<CR> |
\ map <F6> :!java %:t:r<CR>
augroup END
lech.ambrzykowski at wp.pl, May 8, 2003 4:30

http://www.vim.org/tips/tip.php?tip_id=3 (6 of 8) [18/02/2004 14:40:18]

Tip #3 - use vim to quickly compile java files : vim online

Safer:
augroup filetypedetect
au BufNewFile,BufRead,BufEnter *.java
\ map <F9> :w<CR>:!javac "%"<CR> |
\ map <F6> :!java -cp %:p:h %:t:r<CR>
augroup END
Anonymous, September 20, 2003 9:52
Reading this tips, I've just found out that Windows XP
supports redirecting stderr.
Just do:
:set shellpipe=>\ %s\ 2>&1
Then, :make will be expanded to {makeprg} > {errorfile}
2>&1 and you'll see all the output from the make
program!
graziosi.fabio@tiscali.it, September 23, 2003 6:24
Also Win2K supports redirecting stderr. You can use tip
for Win Xp.
khulick@varco.com, October 15, 2003 21:30
I am a java developer forced to use Windows on occasion
and use Vim as my primary editing tool. I use the
shell redirection (on Win XP) and the output and
quickfix work fine, but what I really miss in the win
gui version is the "live" feed as the compile is
happening, like you get out of tail -ing the temp
output in a Unix system.
Anyone have suggestions?
zlhg@hotmail.com, October 23, 2003 19:34
how do I set java's classpath in vim just like batach
file in Win2k.
I do it with batch file in ultraEdit while build java
file in it ?
I'm a newbie. I don't know how to set envirorment in
Win2k.
Thank u in advance!
schloman@msu.edu, January 20, 2004 12:15

http://www.vim.org/tips/tip.php?tip_id=3 (7 of 8) [18/02/2004 14:40:18]

Tip #3 - use vim to quickly compile java files : vim online

FYI if you are getting an e40 error (remember, ':help


e40' to get the vim help):
:!jikes +E aka.java >
C:/DOCUM~1/dhazel/LOCALS~1/Temp/VIe31f.tmp 2>&1
shell returned 1
E40: Can't open error file ...
do what the help doc says and check to make sure your
mkprg, sh, etc. are all set correctly. This is
probably due to a path issue (like to where your shell
is).
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=3 (8 of 8) [18/02/2004 14:40:18]

SourceForge
Logo

Tip #4 - Any word completion : vim online

not logged in (login)

Home
Search

Tip #4: Any word completion


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 450/134, Viewed by 5667

created: February 24, 2001 15:48


author: Jamo.sp@lorenz.lucs.lu.se

complexity: basic
as of Vim: 5.7

Either when programming or writing, I tend to have some


identifiers or words that I use all the time. By sheer
accident, I noticed the 'ctrl-n' command, that will
attempt to complete the word under the cursor. Hit it
once, and it will try to complete it with the first
match in the current file. If there is no match, it will
(at least in the case of C code) search through all
files included from the current one. Repeated
invocations will cycle through all found matches.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<use vim to quickly compile java files | Quickly searching for a word >>

Additional Notes
scrott@users.sourceforge.net, February 25, 2001 12:10
See vimtip #11 for more details...
harry@slaughters.com, October 12, 2002 2:17
that is definitely a life changing tip.
especially when programming and trying to recal
variable names and so on. wow. i had no idea.
ajglist@izzy.net, February 2, 2003 1:38

http://www.vim.org/tips/tip.php?tip_id=4 (1 of 2) [18/02/2004 14:40:21]

Tip #4 - Any word completion : vim online

Outstanding! I've been following std/boost guidelines


for C++ code which specify
longish_variable_names_with_lots_of_underbars, since
everything is lowercase, you have fewer identifiers to
choose from, so your identifiers can get quite long,
(i.e. return_temporary_buffer from std). With this
feature, it all makes sense. Typos are on the decline.
Life altering, indeed.
hjaramillo@geocenter.com, February 7, 2003 13:10
Great tip!
thanks a lot.

Yes, I agree, life changing!.

Herman.
Anonymous, June 15, 2003 15:14
Damn, this saves me about 1000 keystrokes a day.
Anonymous, July 3, 2003 17:33
I love vim ;-p
spam@sukria.net, August 11, 2003 4:34
Of course this tip is a life changing one :)
Note that you can ask vim for a previous word
compeltion with <Ctrl>P
Yo ucan also, for use facilities, map this combo on a
not-often-used key such as the '' one.
But, does anyone know how to make Vim read the Pel
modules inculded for compeltion on function names ?
Such as it did when editing C code ?
Thanks a lot.
Anonymous, January 17, 2004 18:31
I wish I had known this earlier. Thank for the tip!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=4 (2 of 2) [18/02/2004 14:40:21]

SourceForge
Logo

Tip #5 - Quickly searching for a word : vim online

not logged in (login)

Home
Search

Tip #5: Quickly searching for a word


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 442/159, Viewed by 9434

created: February 24, 2001 17:57


author: yega@cisco.com

complexity: basic
as of Vim: 5.7

To search for a word under the cursor in the current


file you
can use either the "*" or "#" keys.
The "*" key will search for the word from the current
cursor
position to the end of the file. The "#" key will search
for the
word from the current cursor position to the top of the
file.
Note that the above two keys will search for the whole
word and not
the partial word. This is equivalent to using the
<word> pattern
in the search commands (/ and ?).
To search for partial matches, you can use the "g*" and
"g#" key
sequence.
You can also use the mouse to search for a word. This
will only
work in the GUI version of VIM (gvim) or a console
version
of VIM in an xterm which accepts a mouse. Also, the
'mousemodel'
should be set to 'extend'. Add the following line to
your .vimrc:
set mousemodel=extend
To search for a word under the cursor from the current
cursor
position to the end of the file, press the shift key and
click
on the word using the left mouse button. To search in

http://www.vim.org/tips/tip.php?tip_id=5 (1 of 2) [18/02/2004 14:40:23]

Tip #5 - Quickly searching for a word : vim online

the opposite
direction, press the shift key and click on the word
using the
the right mouse button.
To get more help on these, use
:help
:help
:help
:help
:help
:help

*
#
g*
g#
<S-LeftMouse>
<S-RightMouse>

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Any word completion | Using the % key >>

Additional Notes
atheeban@yahoo.com, October 8, 2002 11:28
Very good tip!.
kubieziel@gmx.de, November 2, 2002 14:28
I'm quite happy to find that tip now. I'm start using
vim. So it will save lot of time. :-)
scherkas@tx.technion.ac.il, December 8, 2002 8:22
By default on Windows version <S-RightMouse> works [as
backwards search], but <S-LeftMouse> does not.
This is because mousemodel is set to
"popup". (somebody knows why?)
If you want to use this nice feature [<S-LeftMouse> as
forward word search], add
this line to _vimrc file, which is located in VIM
installation directory:
set mousemodel=extend
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=5 (2 of 2) [18/02/2004 14:40:23]

SourceForge
Logo

Tip #6 - Using the % key : vim online

not logged in (login)

Home
Search

Tip #6: Using the % key


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 95/44, Viewed by 3571

created: February 24, 2001 17:59


author: Yegappan

complexity: basic
as of Vim: 5.7

The % key can be used


1. To jump to a matching opening or closing parenthesis,
square
bracket or a curly brace i.e. ([{}])
2. To jump to start or end of a C-style comment /* */.
3. To jump to a matching #if, #ifdef, #else, #elif,
#endif C
preprocessor conditionals.
To get more information about this, do
:help %
The % key can be extended to support other matching
pairs by
modifying the "matchpairs" option. Read the help on
:help matchpairs
rate this tip

Life Changing

Helpful

Unfulfilling

<<Quickly searching for a word | Jumping to the start and end of a code block >>

Additional Notes
Anonymous, February 28, 2001 11:00

http://www.vim.org/tips/tip.php?tip_id=6 (1 of 3) [18/02/2004 14:40:25]

rate

Tip #6 - Using the % key : vim online

Also check out Benji Fisher's matchit.vim set of


functions to give
'%' type toggling for a multitude of language
constructs, like:
if,else,elseif,endif
http://sites.netscape.net/BBenjiF/vim
lacaprara@pd.infn.it, April 12, 2001 9:52
I also find very useful the following map:
noremap % v%
This way, whenever you type "%" you jump to the
matching object AND you visually select all the text in
between.
It's useful f.i. for indenting a C or C++ method/class:
go to opening/closing {/}, hit % and then hit = That's
it!
benji@member.AMS.org, May 7, 2002 8:16
The matchit script mentioned in the first note is now a
plugin,
and it is included in the macros/ directory of the
standard
distribution of vim 6.x. See
:help add-local-help
for installation details.
vimonline@dangercat.net, September 21, 2002 15:53
the link to the matchit script apparently is no longer
valid -- neither IE nor Netscape can find the
server. Is there a newer link for those of us whose
institutions (Univ. of Michigan....) are still stuck on
v5.7?
thanks
benji@member.AMS.org, December 5, 2002 11:05
If you are stuck with vim 5.7, you can use matchit.vim
1.0, available from the scripts section of this site:
http://www.vim.org/script.php?script_id=39
Anonymous, December 14, 2003 17:40

http://www.vim.org/tips/tip.php?tip_id=6 (2 of 3) [18/02/2004 14:40:25]

Tip #6 - Using the % key : vim online

Don't forget 'showmatch', it can reduce the need for


%. I like to speed things up a bit so I also set
'matchtime'. In .vimrc:
set showmatch
set matchtime=3
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=6 (3 of 3) [18/02/2004 14:40:25]

SourceForge
Logo

Tip #7 - Jumping to the start and end of a code block : vim online

not logged in (login)

Home
Search

Tip #7: Jumping to the start and end of a code block


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 26/16, Viewed by 1505

created: February 24, 2001 17:59


author: Yegappan

complexity: basic
as of Vim: 5.7

To jump to the beginning of a C code block (while,


switch, if etc),
use the [{ command.
To jump to the end of a C code block (while, switch, if
etc),
use the ]} command.
The above two commands will work from anywhere inside
the code
block.
To jump to the beginning of a parenthesis use the [(
command.
To jump to the end of a parenthesis use the ]) command.
To get more help on these commands, do
:help
:help
:help
:help

[{
]}
[(
])

rate this tip

Life Changing

Helpful

Unfulfilling

<<Using the % key | Jumping to the declaration of a local/global variable >>

Additional Notes
alinets@yahoo.com, June 14, 2002 17:55

http://www.vim.org/tips/tip.php?tip_id=7 (1 of 2) [18/02/2004 14:40:28]

rate

Tip #7 - Jumping to the start and end of a code block : vim online

related to these motion command are

[[ and ]]

[[
sections backward or to the previous '{' in the first
column.
]]
sections backward or to the previous '{' in the first
column.
[]
sections backward or to the previous '}' in the first
column.
This has specially help me in jumping to the top of the
functions and jumping from one function to the next
function.
May be our coding convention played a part in this
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=7 (2 of 2) [18/02/2004 14:40:28]

SourceForge
Logo

Tip #8 - Jumping to the declaration of a local/global variable : vim online

not logged in (login)

Home
Search

Tip #8: Jumping to the declaration of a local/global variable


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 43/22, Viewed by 1349

created: February 24, 2001 18:00


author: Yegappan

complexity: basic
as of Vim: 5.7

'gd' command:
To jump to the declaration of a local variable in a C
program,
position the cursor on the name of the variable and use
the
gd command.
'gD' command:
To jump to the declaration of a global variable in a C
program,
position the cursor on the name of the variable and use
the
gD command.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Jumping to the start and end of a code block | Displaying a variable/macro definition >>

Additional Notes
scrott@users.sourceforge.net, February 25, 2001 12:06
This works in java, perl and a number of other
languages as well!
vinayns@hotmail.com, December 10, 2003 14:02
to jump back use `` (backquote backquote)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=8 [18/02/2004 14:40:30]

SourceForge
Logo

Tip #9 - Displaying a variable/macro definition : vim online

not logged in (login)

Home
Search

Tip #9: Displaying a variable/macro definition


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 20/13, Viewed by 1310

created: February 24, 2001 18:00


author: Yegappan

complexity: basic
as of Vim: 5.7

To display the definition of a variable, place the


cursor on the
variable and use the [i command. To display a macro
definition,
place the cursor on the macro name and use the [d
command.
Note that these commands will work most of the time (not
all the
time). To get more help on these commands, use
:help [i
:help [d
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Jumping to the declaration of a local/global variable | Jumping to previosuly visited locations in a file
>>

Additional Notes
maneesh@india.hp.com, February 25, 2001 2:31
Use [I on a variable display all the lines having that
variable with line numbers. This is very useful for
browsing some C Code.
dp@orion.spectral-sys.com, February 28, 2001 10:58
You can also do ]<c-i> do JUMP to the place where it is
defined
bindu@wavell.net, November 11, 2001 14:28

http://www.vim.org/tips/tip.php?tip_id=9 (1 of 2) [18/02/2004 14:40:32]

Tip #9 - Displaying a variable/macro definition : vim online

gd
will also take you to where it is defined (unless it is
global, in which case gD works)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=9 (2 of 2) [18/02/2004 14:40:32]

SourceForge
Logo

Tip #10 - Jumping to previosuly visited locations in a file : vim online

not logged in (login)

Home
Search

Tip #10: Jumping to previosuly visited locations in a file


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 77/29, Viewed by 1640

created: February 24, 2001 18:01


author: Yegappan

complexity: basic
as of Vim: 5.7

Vim remembers all the locations visited by you in a file


in a session.
You can jump to the older locations by pressing the CtrlO key. You
can jump to the newer locations by pressing the Ctrl-I
or the <Tab>
key.
To get more help on these keys, use
:help CTRL-O
:help CTRL-I
:help jump-motions
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Displaying a variable/macro definition | Completing words quicky in insert mode >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=10 [18/02/2004 14:40:35]

SourceForge
Logo

Tip #11 - Completing words quicky in insert mode : vim online

not logged in (login)

Home
Search

Tip #11: Completing words quicky in insert mode


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating 367/120, Viewed by 6801

created: February 24, 2001 18:01


author: Yegappan

complexity: basic
as of Vim: 5.7

In Insert mode, press the Ctrl-p or Ctrl-n key to complete part of


a word that has been typed.

Scripts
Tips
My Account

This is useful while typing C programs to complete long variable and


function names. This also helps in avoiding typing mistakes.

Site Help

Note that using the 'complete' option, you can complete keywords
defined in one of the include files, tag file, etc.
To get more help on this, use
:help
:help
:help
:help

i_Ctrl-N
i_Ctrl-P
ins-completion
complete

rate this tip

Life Changing

Helpful

Unfulfilling

<<Jumping to previosuly visited locations in a file | Converting tabs to spaces >>

Additional Notes
jmcpherson@bigfoot.com, August 17, 2001 14:26

http://www.vim.org/tips/tip.php?tip_id=11 (1 of 4) [18/02/2004 14:40:38]

rate

Tip #11 - Completing words quicky in insert mode : vim online

Unfortunately, this can also propagate errors, so use it carefully. I've had times when I've
misspelled a keyword or variable somewhere and then CTRL-P/N completed it five times before I
noticed what I was doing. (-: Of course, at least that gives you a consistent misspelling that's
easy to fix with :%s...
I have found myself performing a lot of CTRL-P/N commands on the same strings, and when this
happens, I generally add an abbreviation, which saves me a keystroke or two. I do a lot of
programming in ColdFusion, and I have these lines in my .vimrc:
ab Attr Attributes
ab Appl Application
ab Vari Variables
ab Req Request
ab CFQ CFQUERY
ab CFO CFOUTPUT
...
VIM will finish the word as soon as you type a character after the abbreviation. This is a lot of
fun, especially when you have non-VIM-using co-workers who think you're controlling the editor
with your mind as well as your keyboard. (-;
michael.garriss@abacus-direct.com, September 19, 2002 13:08
I shook with excitement after reading this......
dof@spamsocks-codepoets-foo-co-dot-uk, November 8, 2002 7:52
excitement ? is that all ? I've been using vim for a couple fo years now and have only just found
out about this... clearly I need to RTFM more.
ritesh_j_patel@indiatimes.com, November 28, 2002 5:52
It's great and making life easier.
Balu, January 17, 2003 15:12
How would I add multiline abbrevs? I've tried to edit them using ^V with no luck
salloum@computer.org, February 13, 2003 4:27
Awesome !!!!
Anon, March 13, 2003 22:41
Balu asked about multiline abbreviations?
ab mul Mult^V<Enter>iple lines
the above will probably look like "ab mul Mult^Miple lines".
Anonymous, March 15, 2003 5:08
http://www.vim.org/tips/tip.php?tip_id=11 (2 of 4) [18/02/2004 14:40:38]

Tip #11 - Completing words quicky in insert mode : vim online

If you've several words you'd like to complete, you can use CTRL-X CTRL-P to extend the match.
e.g.
a line exists in your file:
$res = mysql_query($q) or die(mysql_error());
you want to type the line:
$result = mysql_query($q) or die(mysql_error());
but don't want to have to type it in again. (BTW if you wanted the same line use CTRL-X CTRL-L to
complete whole lines)
type
$result = my
keep pressing CTRL-P until you get to mysql_query
then CTRL-X CTRL-P
will give you
$result = mysql_query($q
then keep pressing CTRL-X CTRL-P to complete all the words.
Have a play.
see:
:h i_CTRL-X_CTRL-P
:h i_CTRL-X_CTRL-N

Anonymous, April 28, 2003 11:30


If you want to complete the entire line:
$result = mysql_query($q) or die(mysql_error());
just type:
$result = mys<C-X><C-L>
Snoopy_The_Fish@gmx.net, June 4, 2003 2:09
is it possible to set the cursor position in ab ?
i think of:
ab fu (#cursorPos)<Enter>{<Enter>
gaita@uv.es, July 4, 2003 8:16

http://www.vim.org/tips/tip.php?tip_id=11 (3 of 4) [18/02/2004 14:40:38]

return 0;<Enter>}

Tip #11 - Completing words quicky in insert mode : vim online

The autocompletion is great (I i-mapped it to <Tab>), but the abbreviation "ab" is at least as
good!
Thanks!
clamey@infonow.com, October 30, 2003 11:59
Well, cursor position can be done like this:
ab ff for (Iterator i =; i.hasNext())
{<LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT>
I've tried added a [count] before the <LEFT> but it doesn't seem to work.
Anyone else have an idea?
baitisj@yahoo.com, January 9, 2004 11:23
It would be great if we could have something like wildmode=longest,list in insert mode:
A lot of my friends think that the way VIM rotates through possible completions is annoying. We
would prefer the behavior to act like the default tab-completion in BASH, where you type <tab>
once, and if it can complete with only one match, the completion is performed. If there are other
possible completions, then an alphabetical list of completions is listed, giving you an
opportunity to type the next letter to further narrow your completion list.
Can anyone suggest how to do this?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=11 (4 of 4) [18/02/2004 14:40:38]

SourceForge
Logo

Tip #12 - Converting tabs to spaces : vim online

not logged in (login)

Home
Search

Tip #12: Converting tabs to spaces


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 414/167, Viewed by 7132

created: February 24, 2001 18:02


author: Yegappan

complexity: basic
as of Vim: 5.7

To insert space characters whenever the tab key is


pressed, set the
'expandtab' option:
set expandtab
With this option set, if you want to enter a real tab
character use
Ctrl-V<Tab> key sequence.
To control the number of space characters that will be
inserted when
the tab key is pressed, set the 'tabstop' option. For
example, to
insert 4 spaces for a tab, use:
set tabstop=4
After the 'expandtab' option is set, all the new tab
characters entered
will be changed to spaces. This will not affect the
existing tab
characters. To change all the existing tab characters
to match the
current tab settings, use
:retab
To change the number of space characters inserted for
indentation, use
the 'shiftwidth' option:
set shiftwidth=4
For example, to get the following coding style,
- No tabs in the source file
- All tab characters are 4 space characters

http://www.vim.org/tips/tip.php?tip_id=12 (1 of 4) [18/02/2004 14:40:41]

Tip #12 - Converting tabs to spaces : vim online

use the following set of options:


set tabstop=4
set shiftwidth=4
set expandtab
Add the above settings to your .vimrc file.
To get more help on these options, use
:help tabstop
:help shiftwidth
:help expandtab
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Completing words quicky in insert mode | Incremental search >>

Additional Notes
glennj@canada.com, February 27, 2001 7:05
Also, see the :help smarttab option
jason@katzbrown.com, February 27, 2001 8:42
but tabs are better :-)
Dirk Ruediger <druediger@gmx.net>, March 6, 2001 3:57
I'm also using
set list listchars=tab:,trail:
to "highlight" any tabs and all trailing spaces -- to
catch them :).
peach@avaya.com, August 14, 2001 20:47
To turn off expandtab for editing makefiles, I put the
following in my .vimrc:
au FileType make setlocal noexpandtab
jzgoda@o2.pl, December 13, 2002 1:45
This feature is a "life preserver", when you edit
Python code.
smceligot@despammed.com, May 15, 2003 15:40

http://www.vim.org/tips/tip.php?tip_id=12 (2 of 4) [18/02/2004 14:40:41]

Tip #12 - Converting tabs to spaces : vim online

To use this mode only for python add the following to


~/.vimrc
autocmd FileType * set tabstop=2|set shiftwidth=2|set
noexpandtab
autocmd FileType python set tabstop=4|set
shiftwidth=4|set expandtab
wongi@wongi.pe.kr, June 30, 2003 19:48
:retab
This is what I've been looking for!
I use spaces... for printing only ;-)
rausse@hotmail.com, July 10, 2003 15:07
I also add the following line:
set softtabstop=4
tabs

" makes the spaces feel like real

This makes the backspace key treat the four spaces like
a tab (so one backspace goes back a full 4 spaces).
I love vim.
iebnn@hotmail.com, December 3, 2003 10:25
Read this if you're interested in this tip. It explains
how tabs are actually much better than spaces, contrary
to many's opinion.
http://derkarl.org/why_to_tabs.html
misof, December 16, 2003 14:54
:!man expand
:%!expand
why shouldn't you use an external tool made especially
for this purpose?
d_ayles@telus.net, December 28, 2003 8:41

http://www.vim.org/tips/tip.php?tip_id=12 (3 of 4) [18/02/2004 14:40:41]

Tip #12 - Converting tabs to spaces : vim online

I was just about to give up on Vim,


because of backspacing in insert mode.
Wow, thanks.
Also, check "Vi Improved- Vim" (Steve Oualline); I've
just used the index.
page 94 - a nice clear explanation on "backspace"
He says: use ":set
backspace=indent,eol,start",
instead of ":set
backspace=2.
pages 265-268 - a story on tab/retab/space/etc.;
I got somewhat confused here over
softtabstop/tabstop/shiftwidth.
micah@micahgorrell.com, January 21, 2004 21:40
Is there any way to make vim treat spaces as tabs when
not in insert mode? My co-workers prefer code to be
saved with spaces (which makes no sense to me) so I
would like to use these options. The problem is that
when I position my cursor on a line, and hit insert, it
begins at that space, which may not line up with the
tab stop. I want cursor movement on whitespace to act
like there are tabs there.
Is that possible?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=12 (4 of 4) [18/02/2004 14:40:41]

SourceForge
Logo

Tip #13 - Incremental search : vim online

not logged in (login)

Home
Search

Tip #13: Incremental search


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 120/50, Viewed by 1940

created: February 24, 2001 18:02


author: Yegappan

complexity: basic
as of Vim: 5.7

To move the cursor to the matched string, while typing


the search
string, set the following option in the .vimrc file:
set incsearch
You can complete the search by pressing the Enter
key. To cancel
the search, press the escape key.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Converting tabs to spaces | Highlighting all the search pattern matches >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=13 [18/02/2004 14:40:44]

SourceForge
Logo

Tip #14 - Highlighting all the search pattern matches : vim online

not logged in (login)

Home
Search

Tip #14: Highlighting all the search pattern matches


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 55/34, Viewed by 2450

created: February 24, 2001 18:03


author: Yegappan

complexity: basic
as of Vim: 5.7

To highlight all the search pattern matches in a file


set the
following option:
:set hlsearch
After this option is set, if you search for a pattern,
all the
matches in the file will be highlighted in yellow.
To disable the highlighting temporarily, use the command
:nohlsearch
This command will remove the highlighting for the
current search.
The highlighting will come back for the next search.
To disable the highlighting completely, set the
following option:
:set nohlsearch
By default, the hlsearch option is turned off.
To get more help on this option, use
:help 'hlsearch'
:help :nohlsearch
rate this tip

Life Changing

Helpful

<<Incremental search | Displaying status line always >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=14 (1 of 3) [18/02/2004 14:40:46]

Unfulfilling

rate

Tip #14 - Highlighting all the search pattern matches : vim online

jsuntheimer@neo.rr.com, May 26, 2001 23:09


Another quick way to remove the highlighting of the
last search without disabling highlighting is to do a
search for a nonsense string
/asdfasdf
When vim cant find the search string in the current
buffer, all highlighting is removed. It's ugly, quick,
and easily remembered.
harshad.joglekar@wipro.com, August 19, 2001 9:25
I have found that the default hi-light color for search
matches is rather flagrant (Yellow for gvim). If you
set it to some pleasant color, you don't have to turn
off "hlsearch" all the time, or search for an empty
string.
Try this,
:hi Search guibg=LightGreen
or
:hi Search guibg=LightBlue
regards,
Harshad
Anonymous, April 25, 2003 7:28
I have this mapping in my .vimrc:
map <F1> :let &hlsearch=!&hlsearch<CR>
Very handy.
Anonymous, June 15, 2003 10:58
is there any way so that
current curser position
is highlighted ,

while only the word on under

nivas@vsnl.net, October 16, 2003 22:22


add following line to the _vimrc file :
hi search guibg=LightBlue
that should take care of using pleasant colours as
opposed to 'bright yellow' (?!? I mean seriously...)
gene.rmspam.smith@sea.rmspam.siemens.com, November 20, 2003 16:18

http://www.vim.org/tips/tip.php?tip_id=14 (2 of 3) [18/02/2004 14:40:46]

Tip #14 - Highlighting all the search pattern matches : vim online

The tip:
map <F1> :let &hlsearch=!&hlsearch<CR>
Is good, but watch out for a invisible space at end
after <CR> which makes the cursor move right on each
F1 hit. I guess this is possible because vim does not
trim spaces at end of lines. (How do you keep this from
calling help in insert mode?)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=14 (3 of 3) [18/02/2004 14:40:46]

SourceForge
Logo

Tip #15 - Displaying status line always : vim online

not logged in (login)

Home
Search

Tip #15: Displaying status line always


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 41/26, Viewed by 1467

created: February 24, 2001 18:03


author: Yegappan

complexity: basic
as of Vim: 5.7

To display the status line always, set the following


option in
your .vimrc file:
set laststatus=2
The advantage of having the status line displayed always
is, you
can see the current mode, file name, file status, ruler,
etc.
To get more help on this, use
:help laststatus
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Highlighting all the search pattern matches | Avoiding the "Hit ENTER to continue" prompts >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=15 [18/02/2004 14:40:48]

SourceForge
Logo

Tip #16 - Avoiding the "Hit ENTER to continue" prompts : vim online

not logged in (login)

Home
Search

Tip #16: Avoiding the "Hit ENTER to continue" prompts


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 19/15, Viewed by 1600

created: February 24, 2001 18:04


author: Yegappan

complexity: basic
as of Vim: 5.7

To avoid the "Hit ENTER to continue" prompt, use the


'shortmess'
option. Add the following line to your .vimrc file:
set shortmess=a
Also, you can increase the height of the command line to
2
set cmdheight=2
The default command height is 1.
To get more help on these options, use
:help hit-enter
:help shortmess
:help cmdheight
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Displaying status line always | Erasing previosuly entered characters in insert mode >>

Additional Notes
michael@endbracket.net, October 23, 2003 18:33
The "Hit ENTER to continue" commands that I find most
annoying are actually disabled by setting
shortmess="oO" rather than "a". shortmess is set to
"filnxtToO" by default, so these messages should not
appear by default anyhow.
Add Note

http://www.vim.org/tips/tip.php?tip_id=16 (1 of 2) [18/02/2004 14:40:50]

Tip #16 - Avoiding the "Hit ENTER to continue" prompts : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=16 (2 of 2) [18/02/2004 14:40:50]

SourceForge
Logo

Tip #17 - Erasing previosuly entered characters in insert mode : vim online

not logged in (login)

Home
Search

Tip #17: Erasing previosuly entered characters in insert mode


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 35/16, Viewed by 1132

created: February 24, 2001 18:04


author: Yegappan

complexity: basic
as of Vim: 5.7

In insert mode, to erase previously entered characters,


set the
following option:
set backspace=2
By default, this option is empty. If this option is
empty, in
insert mode, you can not erase characters entered before
this
insert mode started. This is the standard Vi behavior.
To get more help on this, use
:help 'backspace'
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Avoiding the "Hit ENTER to continue" prompts | Cleanup your HTML >>

Additional Notes
jsuntheimer@neo.rr.com, May 26, 2001 22:59
a convenient and oldly memorable abbreviation is
:set bs=2
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=17 [18/02/2004 14:40:52]

SourceForge
Logo

Tip #18 - Cleanup your HTML : vim online

not logged in (login)

Home
Search

Tip #18: Cleanup your HTML


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 33/20, Viewed by 3118

created: February 25, 2001 19:59


author: scrott@users.sourceforge.net

complexity: advanced
as of Vim: 5.7

From Johannes Zellner on the vim list:


You can use vim's makeprg and equalprg to clean up HTML.
First download html tidy from
http://www.w3.org/People/Raggett/tidy/. Then use the
following commands.
vim6?
exe 'setlocal equalprg=tidy -quiet -f '.&errorfile
setlocal makeprg=tidy -quiet -e %
vim5?
exe 'set equalprg=tidy -quiet -f '.&errorfile
set makeprg=tidy -quiet -e %
At this point you can use make to clean up the full file
or you can use = to clean up sections.
:help =
:help equalprg
:help makeprg

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Erasing previosuly entered characters in insert mode | line numbers... >>

Additional Notes
scrott@users.sourceforge.net, May 2, 2001 23:05
There is also Jtidy (Java implementation of tidy):
http://sourceforge.net/projects/jtidy/
djkea2@mugca.cc.monash.edu.au, January 11, 2002 5:01
http://www.vim.org/tips/tip.php?tip_id=18 (1 of 2) [18/02/2004 14:40:54]

Tip #18 - Cleanup your HTML : vim online

Vim 6.0 comes with a Tidy compiler plugin for use in


quickfix mode - $VIMRUNTIME/compiler/tidy.vim
andy_todd@yahoo.com, April 23, 2002 19:11
Any hints or tips on how to use the tidy.vim plugin?
creitzel@rcn.com, July 4, 2002 12:02
The current version of C Tidy is now at
http://tidy.sourceforge.net/ ;
creitzel@rcn.com, July 4, 2002 12:03
Make that http://tidy.sourceforge.net/
william@knowmad.com, August 15, 2002 6:25
To use the included compiler script, run `:compiler
tidy`. For more info, see :h quickfix and :h compilerselect.
If you are using tidy.vim under WinNT (not sure about
9x), you need to set your shellpipe=2> or else Vim
won't see the output from tidy. Apparently these Unix
tools write output to stderr instead of stdout and Vim
isn't configured by default to handle this situation.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=18 (2 of 2) [18/02/2004 14:40:54]

SourceForge
Logo

Tip #19 - line numbers... : vim online

not logged in (login)

Home
Search

Tip #19: line numbers...


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 72/29, Viewed by 2208

created: February 25, 2001 22:17


author: scrott@users.sourceforge.net

complexity: basic
as of Vim: 5.7

I have started doing all my code reviews on a laptop


because of the number command.
:set number will put line numbers along the left side of
a window
:help number

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Cleanup your HTML | Are *.swp and *~ files littering your working directory? >>

Additional Notes
the_voice666@hotmail.com, August 19, 2001 17:00
A faster way to do this is
:set nu
bindu@wavell, November 11, 2001 13:48
An even faster way to do this :) is
:se nu
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=19 [18/02/2004 14:41:00]

SourceForge
Logo

Tip #20 - Are *.swp and *~ files littering your working directory? : vim online

not logged in (login)

Home
Search

Tip #20: Are *.swp and *~ files littering your working directory?
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 192/74, Viewed by 3394

created: February 25, 2001 22:27


author: jean@mosaicsoftware.com

complexity: basic
as of Vim: 5.7

Have you ever been frustrated at swap files and backups


cluttering
up your working directory?
Untidy:
ons.txt
ons.txt~
README
README~
tester.py
tester.py~
Here are a couple of options that can help:
set
set

backupdir=./.backup,.,/tmp
directory=.,./.backup,/tmp

This way, if you want your backups to be neatly grouped,


just
create a directory called '.backup' in your working
directory.
Vim will stash backups there. The 'directory' option
controls
where swap files go. If your working directory is not
writable,
Vim will put the swap file in one of the specified
places.
rate this tip

Life Changing

Helpful

Unfulfilling

<<line numbers... | easy pasting to windows apps >>

Additional Notes
christophe.badoit@free.fr, December 28, 2001 2:20
http://www.vim.org/tips/tip.php?tip_id=20 (1 of 3) [18/02/2004 14:41:07]

rate

Tip #20 - Are *.swp and *~ files littering your working directory? : vim online

Yes but remind that the swp files are very useful when
many users are working on the same directory, to
prevent you loosing datas...
Anonymous, July 25, 2002 8:13
I love you
Anonymous, November 25, 2002 7:24
I too, love you.
Anonymous, December 22, 2002 21:22
I dont love you, but the tip is great. Thank you.
Anonymous, January 7, 2003 5:40
I was not able to use it in Windows. Is there some
difference on how to properly write paths?
Anonymous, January 10, 2003 10:05
Yes it is. Use \\ instead of / in your path.
It should look like:
set
set

backupdir=.\\.backup,.,c:\\tmp
directory=.,.\\.backup,c:\\tmp

Anonymous, January 23, 2003 9:55


To use it in Windows, I replaced .backup by _backup:
set
set

backupdir=./_backup,.,/tmp
directory=.,./_backup,/tmp

humsuplau@hotmail.com, June 6, 2003 2:25


You're a legend mate! I spent freakin ages trying to
find the solution for this (most of the time not
knowing if it was a VIM problem or something else). No
more annoying backup files... yeeeehhhaaaaaa!!
Anonymous, September 2, 2003 17:24
That's "losing" data.
(What is it with people confusing "loosing"/"losing"
and "loose"/"lose" these days? It's a fairly recent
phenomenon, AFAIK. I first started seeing it only a
few years ago - mostly on Slashdot.)
Anonymous, November 3, 2003 5:46
Don't start. You're going to loose this discussion
Anonymous, November 3, 2003 5:56
http://www.vim.org/tips/tip.php?tip_id=20 (2 of 3) [18/02/2004 14:41:07]

Tip #20 - Are *.swp and *~ files littering your working directory? : vim online

Sorry, couldn't help it.


'lose' is a verb: something you do (or rather not)
'loose' is an adjective: it describes a quality of
something (or lack of it)
Example: men with loose canons usually lose their
lives.
Anonymous, November 12, 2003 3:40
Jeebus, stay on the darn topic, willya?! who cares!
re: tip - great one - I personally hate ~ files, as I
use CVS to protect and avoid "losing" data.
emallove@yahoo.com, December 9, 2003 17:15
This is huge! ~ files have been the bane of my vim
existence for years I thought for sure I had found the
answer here:
http://vim.sourceforge.net/htmldoc/recover.html
... but no dice - it didn't work until I set the
backupdir oprtion as explained in this tip.
Thanks!
Ethan
gk@charter.net, January 8, 2004 19:13
I guess I'm just dense. I'm using vim 6.2, and I've
tried all the settings in this thread, in the _vimrc
where my gvim.exe resides, and nothing changes.
Apparently I'm missing something...
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=20 (3 of 3) [18/02/2004 14:41:07]

SourceForge
Logo

Tip #21 - easy pasting to windows apps : vim online

not logged in (login)

Home
Search

Tip #21: easy pasting to windows apps


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 131/53, Viewed by 2566

created: February 25, 2001 22:31


author: jean@mosaicsoftware.com

complexity: basic
as of Vim: 5.7

In Vim, the unnamed register is the " register, and the


Windows
Clipboard is the * register. This means that if you yank
something,
you have to yank it to the * register if you want to
paste it into
a Windows app. If this is too much trouble, set the
'clipboard'
option to 'unnamed'. Then you always yank to *.
So pasting to windows apps doesn't require prefixing "*
:
set

clipboard=unnamed

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Are *.swp and *~ files littering your working directory? | handle common typos for :commands >>

Additional Notes
benji@member.AMS.org, March 4, 2001 11:27
You can also have the Visual selection automatically
copied to the clipboard. If you
:set go+=a
and then make a Visual selection, you can switch to
another application (such as your mail reader) and
paste.
:help guioptions
:help quotestar
slabounty@netaphor.com, October 28, 2001 17:34
http://www.vim.org/tips/tip.php?tip_id=21 (1 of 2) [18/02/2004 14:41:09]

Tip #21 - easy pasting to windows apps : vim online

Since the * buffer won't allow (as far as I know


anyway) appending to it, you also do something like:
"aY
to grab a line then move somewhere else
"AY
to append another line to the a buffer and then
finally:
:let @*=@a
This puts both lines into the * buffer for pasting. I
picked this up on the vim email list I think from
Benji.
Scott LaBounty
Netaphor Software, Inc.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=21 (2 of 2) [18/02/2004 14:41:09]

SourceForge
Logo

Tip #22 - handle common typos for :commands : vim online

not logged in (login)

Home
Search

Tip #22: handle common typos for :commands


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/9, Viewed by 976

created: February 27, 2001 7:11


author: glennj@canada.com

complexity: basic
as of Vim: 5.7

I frequently hold the shift key for too long when


typing, for instance :wq, and end up with :Wq. Vim then
whines "Not an editor command: Wq"
In my .vimrc, I have taught vim my common typos:
command! Q quit
command! W write
command! Wq wq
" this one won't work, because :X is already a built-in
command
command! X xit
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<easy pasting to windows apps | Vim xterm title >>

Additional Notes
dp@orion.spectral-sys.com, February 28, 2001 10:54
Or you can also do a cabbrev to change
:Wq to :wq.
Would be done like this:
cabbrev Wq wq
glennj@canada.com, March 21, 2001 14:31
I like that cabbrev tip. That lets you get away with:
cabbrev X x
The drawback is that it becomes tricky to use "X" as a
work in any
command. For example, with "cabbrev X x", you cannot
perform the
search "/X" --> the abbrev changes it to "/x"
http://www.vim.org/tips/tip.php?tip_id=22 (1 of 2) [18/02/2004 14:41:11]

Tip #22 - handle common typos for :commands : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=22 (2 of 2) [18/02/2004 14:41:11]

SourceForge
Logo

Tip #23 - Vim xterm title : vim online

not logged in (login)

Home
Search

Tip #23: Vim xterm title


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 24/19, Viewed by 1387

created: March 1, 2001 6:40


author: stone at snok dot org

complexity: basic
as of Vim: 5.7

Check out your .vimrc. If 'set notitle' is an entry,


comment it out with a quotation mark ("). Now your xterm
should inherit the title from Vim.
e.g. 'Vim ~/.vimrc'. This can be quite nice when programming and
editing lots of files at the same time.
by [jonasbn@wanadoo.dk]
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<handle common typos for :commands | changing the default syntax highlighting >>

Additional Notes
Anonymous, October 15, 2002 14:25
Merely commenting out "set notitle" will not do
it. Vim has the xterm title off by default. You need
to put "set title" in your .vimrc. Alternately, you
could just type ":set title" from within vim.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=23 [18/02/2004 14:41:13]

SourceForge
Logo

Tip #24 - changing the default syntax highlighting : vim online

not logged in (login)

Home
Search

Tip #24: changing the default syntax highlighting


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 15/15, Viewed by 1800

created: March 4, 2001 11:57


author: benji@member.AMS.org

complexity: intermediate
as of Vim: 5.7

Here are some pointers to the vim documentation. Notice


that the mechanism is different in vim 6.0 and vim 5.x.
1. I want *.foo files to be highlighted like HTML files.
:help new-filetype
filetype

http://www.vim.org/html/autocmd.html#new-

2. I want to define a syntax file for *.bar files.


above and also
:help
mysyntaxfile

Read the

http://www.vim.org/html/syntax.html#mysyntaxfile

3. I want to make a few changes to the existing syntax


highlighting. Depending on the x in 5.x, either read the
above and page down a few screens, or you may be able to skip
right to
:help mysyntaxfileadd http://www.vim.org/html/syntax.html#mysyntaxfile-add
4. I want to change some of the colors from their
defaults. Again, read
:help
mysyntaxfile

rate this tip

http://www.vim.org/html/syntax.html#mysyntaxfile

Life Changing

Helpful

Unfulfilling

<<Vim xterm title | color highlighting on telnet (esp w/ SecureCRT) >>

Additional Notes
Anonymous, February 17, 2003 22:52
it says page not found
Anonymous, August 6, 2003 15:28
http://www.vim.org/tips/tip.php?tip_id=24 (1 of 2) [18/02/2004 14:41:15]

rate

Tip #24 - changing the default syntax highlighting : vim online

none of these pages are there


Anonymous, September 17, 2003 18:22
in vim, type :help mysyntaxfile
cthom@nortelNetworks.com, October 17, 2003 11:28
Simple yet elegant - of course
Anonymous, November 3, 2003 1:47
None of these links work anymore!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=24 (2 of 2) [18/02/2004 14:41:15]

SourceForge
Logo

Tip #25 - color highlighting on telnet (esp w/ SecureCRT) : vim online

not logged in (login)

Home
Search

Tip #25: color highlighting on telnet (esp w/ SecureCRT)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 74/22, Viewed by 2159

created: March 4, 2001 13:13


author: stephen@morley.net

complexity: basic
as of Vim: 5.7

The following settings in .vimrc will enable color


highlighting when using SecureCRT and may work on other
telnet packages. The terminal type should be selected as
ANSI and color enabled.
if !has("gui_running")
set t_Co=8
set t_Sf=^[[3%p1%dm
set t_Sb=^[[4%p1%dm
endif
The ^[ is entered as "<ctrl-v><esc>"

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<changing the default syntax highlighting | Getting rid of ^M - mixing dos and unix >>

Additional Notes
Anonymous, July 17, 2002 18:30

Of course this isn't what I wanted to do .... I wanted


to get rid of the stupid syntax colors by default.
but by extension:
t_Co=1
does this perfectly;
just put it in my system wide vimrc file.
Anonymous, April 15, 2003 6:18

http://www.vim.org/tips/tip.php?tip_id=25 (1 of 2) [18/02/2004 14:41:17]

Tip #25 - color highlighting on telnet (esp w/ SecureCRT) : vim online

I think you can enable color via SecureCRT Session


Options :
Emulation/Terminal : Linux + Ansi Color
Appearance/Current Color Scheme : Windows
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=25 (2 of 2) [18/02/2004 14:41:17]

SourceForge
Logo

Tip #26 - Getting rid of ^M - mixing dos and unix : vim online

not logged in (login)

Home
Search

Tip #26: Getting rid of ^M - mixing dos and unix


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 166/71, Viewed by 7504

created: March 5, 2001 17:00


author: scrott@users.sourceforge.net

complexity: basic
as of Vim: 5.7

If you work in a mixed environment you will often open


files that have ^M's in them. An example would be this:
----------------------------------------------------------------import java.util.Hashtable; ^M
import java.util.Properties; ^Mimport
java.io.IOException;
import org.xml.sax.AttributeList; ^M
import org.xml.sax.HandlerBase; ^Mimport
org.xml.sax.SAXException;
/**^M
* XMLHandler: This class parses the elements
contained^M
* within a XML message and builds a Hashtable^M
[snip]
----------------------------------------------------------------Notice that some programs are not consistent in the way
they insert the line breaks so you end up with some
lines that have both a carrage return and a ^M and some
lines that have a ^M and no carrage return (and so blend
into one). There are two steps to clean this up.
1. replace all extraneous ^M:
:%s/^M$//g
BE SURE YOU MAKE the ^M USING "CTRL-V CTRL-M" NOT BY
TYPING "CARROT M"! This expression will replace all the
^M's that have carriage returns after them with nothing.
(The dollar ties the search to the end of a line)
2. replace all ^M's that need to have carriage returns:
:%s/^M/ /g

http://www.vim.org/tips/tip.php?tip_id=26 (1 of 6) [18/02/2004 14:41:21]

Tip #26 - Getting rid of ^M - mixing dos and unix : vim online

Once again: BE SURE YOU MAKE the ^M USING "CTRL-V CTRLM" NOT BY TYPING "CARROT M"! This expression will
replace all the ^M's that didn't have carriage returns
after them with a carriage return.
Voila! Clean file. Map this to something if you do it
frequently.
:help ffs - for more info on file formats
thanks to jonathan merz, douglas potts, and benji fisher
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<color highlighting on telnet (esp w/ SecureCRT) | Convert hex to dec >>

Additional Notes
wiwo@dcon.at, October 22, 2001 8:51
It also works with
:%s/\r//g
rpilkey@hotmail.com, January 29, 2002 9:01
If you want to put a map of this in your _vimrc file,
then you have to double the ^V character so that it
looks like this:
map M :%s/^V^V^M$//g^M
note: if you cut and paste this line, it won't
work. You have to type the control characters as
explained above.
It has something to do with it being interpreted
multiple times, I think.
Roger

mwithers@one.net, March 10, 2002 17:41

http://www.vim.org/tips/tip.php?tip_id=26 (2 of 6) [18/02/2004 14:41:21]

Tip #26 - Getting rid of ^M - mixing dos and unix : vim online

:g/^M$/s///g - will get rid of every instance of a line


ending with the carriage returns as well.
You can map this to a key, but you need to use ^V to
"quote" the carriage return and not by simply copying
and pasting the above regular expression.
Mark
kbgaddis@hotmail.com, April 1, 2002 0:15
yet another way of doing this without the search is
':set fileformat=unix<cr>:w<cr>'... converts the crlfs
to just lfs
hello_ben@yahoo.com, October 31, 2002 12:31
I think using this command is easier.
:set ff=unix //to unix file
:set ff=dos
//to windows file
arnovenner@yahoo.com, January 22, 2003 19:00
Hi,
yet another way to do this in a fine manner is made by
2 steps:
first:
%s/\r\r/\r/g
second
%s/\r//g
It seems useless to do the first step on the first
sight, but so it keeps your linebreaks as the document
originally had - might be usefull.
Arno
winfree@gmx.de, February 26, 2003 15:31
hello_ben@yahoo.com mentioned
:set ff=unix //to unix file
:set ff=dos
//to windows file
to change linebreaks.
I experienced that this will only work on correct
unix/dos files.
If you have a mixture of linebreak types (if you see
this ^M at
then end of several lines), ":set ff" (fileformat) will
not help you.

http://www.vim.org/tips/tip.php?tip_id=26 (3 of 6) [18/02/2004 14:41:21]

Tip #26 - Getting rid of ^M - mixing dos and unix : vim online

avis@excite.com, May 28, 2003 9:06


This is more of a question than additional tips.
How (if possible) can one remove the newline character
from the LAST line?
Anonymous, June 19, 2003 15:36
You should be able to do:
:$,$s/^M//
But I have not tested that.
ramgarden@aol.com, June 25, 2003 6:46
When editing files on my Mac (OS X 10.2) then moving
those to my Windows box, I get the crazy control M
characters as well. I found out through trial and error
the best way for me to get rid of them (and keep the
original line breaks) is to use this command:
:%s/\r/\r/g
Basically says to get rid of the linefeeds you have,
and put in linefeeds this system understands.
Hope this helps someone out!
Anonymous, November 18, 2003 18:11
I am editing the same file under Linux, and Windows.
I want just to hide the ^M, not actually erase them
from the file. All the solutions that you suggested
actually erase the ^M. It means that when I reopen the
file under Windows, it's all messed up. If I don't
change the ^M, it's painful to watch them in Vi 6.2.
under Linux. Any solutions to this?
Anonymous, November 26, 2003 15:31
Note that, when using Vim on Windows, you will need to
use CTRL-Q instead of CTRL-V to escape the special
character on the ex command line.
From the documentation (usr_24.txt):
Note:
On MS-Windows CTRL-V is used to paste text. Use
CTRL-Q instead of
CTRL-V. On Unix, on the other hand, CTRL-Q does
not work on some
terminals, because it has a special meaning.
Anonymous, February 3, 2004 12:30
http://www.vim.org/tips/tip.php?tip_id=26 (4 of 6) [18/02/2004 14:41:21]

Tip #26 - Getting rid of ^M - mixing dos and unix : vim online

To the poster who is editing files on multiple


OSs: Try reading up on :help ffs. If your files truly
are correct "DOS" (carriage return+newline) format when
you open them in linux, VIM should be able to autodetect the newline scheme and hide the actual control
characters from you. Make sure the autodetection is
enabled, or try forcing the file format from the
command line when opening the file.
If you still get ^M's, then the files you are opening
have a mix of newline schemes and VIM is very
inflexible when it comes to mixing newline schemes.
This mixture often happens in log/data files and
rolling files which sometimes never have a carriage
return on the last line or silly things like that which
break VIM's autodetection routine. Again try forcing
the filetype from the command line. If this fails,
your only option is to strip out the ^M's using the
tips in this section.
Anonymous, February 3, 2004 12:32
To the poster who is editing files on multiple
OSs: Try reading up on :help ffs. If your files truly
are correct "DOS" (carriage return+newline) format when
you open them in linux, VIM should be able to autodetect the newline scheme and hide the actual control
characters from you. Make sure the autodetection is
enabled, or try forcing the file format from the
command line when opening the file.
If you still get ^M's, then the files you are opening
have a mix of newline schemes and VIM is very
inflexible when it comes to mixing newline schemes.
This mixture often happens in log/data files and
rolling files which sometimes never have a carriage
return on the last line or silly things like that which
break VIM's autodetection routine. Again try forcing
the filetype from the command line. If this fails,
your only option is to strip out the ^M's using the
tips in this section.
pagarcia@slcolombia.org, February 7, 2004 19:07
with:
:%s/^M/\r/g
works perfectly !!!
Add Note

http://www.vim.org/tips/tip.php?tip_id=26 (5 of 6) [18/02/2004 14:41:21]

Tip #26 - Getting rid of ^M - mixing dos and unix : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=26 (6 of 6) [18/02/2004 14:41:21]

SourceForge
Logo

Tip #27 - Convert hex to dec : vim online

not logged in (login)

Home
Search

Tip #27: Convert hex to dec


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 8/6, Viewed by 4255

created: March 7, 2001 4:59


author: vimer@21cn.com

complexity: advanced
as of Vim: 6.0

when you check the output of objdump, you'll confused by


the $0xFFFFFFc operand, this function translate the
hexcamal to decimal.
function! Hex2Dec()
let lstr = getline(".")
let hexstr = matchstr(lstr, '0x[a-f0-9]+')
while hexstr != ""
let hexstr = hexstr + 0
exe 's#0x[a-f0-9]+#'.hexstr."#"
let lstr = substitute(lstr, '0x[a-f0-9]+',
hexstr, "")
let hexstr = matchstr(lstr, '0x[a-f0-9]+')
endwhile
endfunction
usage:
5,8call Hex2Dec()
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Getting rid of ^M - mixing dos and unix | add a line-number to every line without cat or awk alike
utilities. >>

Additional Notes
o.wegner@gmx.de, June 6, 2001 0:42

http://www.vim.org/tips/tip.php?tip_id=27 (1 of 2) [18/02/2004 14:41:23]

Tip #27 - Convert hex to dec : vim online

This did not work for me unless I escaped the '+' in


the regular expressions. I also added handling of
hexadecimal numbers with upper case letters:
function! Hex2Dec()
let lstr = getline(".")
let hexstr = matchstr(lstr, '0x[a-fA-F0-9]\+')
while hexstr != ""
let hexstr = hexstr + 0
exe 's#0x[a-fA-F0-9]\+#'.hexstr."#"
let lstr = substitute(lstr, '0x[a-fA-F0-9]\+',
hexstr, "")
let hexstr = matchstr(lstr, '0x[a-fA-F0-9]\+')
endwhile
endfunction
Anonymous, June 4, 2003 14:56
63 6F 6E 74 72 6F 6C
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=27 (2 of 2) [18/02/2004 14:41:23]

SourceForge
Logo

Tip #28 - add a line-number to every line without cat or awk alike utilities. : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #28: add a line-number to every line without cat or awk alike
utilities.
tip karma

Rating 8/10, Viewed by 1314

created: March 7, 2001 5:08


author: slimzhao@21cn.com

complexity: intermediate
as of Vim: 5.7

With Unix-like environment, you can use cat or awk to


generate a line number easily, because vim has a
friendly interface with shell, so everything work in vim
as well as it does in shell.
:%!call -n
or
:%!awk '{print NR,$0}'
But, if you use vim in MS-DOS, of win9x, win2000, you
loss these tookit.
here is a very simple way to archive this only by vim:
fu! LineIt()
exe ":s/^/".line(".")."/"
endf
Well, a sequence composed with alphabet is as easy as
above:
exe "s/^/".nr2char(line("."))."/"
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Convert hex to dec | reverse all the line with only 7 keystroke in vim >>

Additional Notes
darren chamberlain <dlc@users.sourceforge.net>, July 2, 2001 4:50

http://www.vim.org/tips/tip.php?tip_id=28 (1 of 2) [18/02/2004 14:41:25]

Tip #28 - add a line-number to every line without cat or awk alike utilities. : vim online

The original awk line gave me entries like:


8 my $foo = Foo->new();
9 my $bar = Bar->new();
10 my $baz = Baz->new();
Turning awk's print to a printf and adding a size the
line number format gave me better results:
8 my $foo = Foo->new();
9 my $bar = Bar->new();
10 my $baz = Baz->new();
:%!awk '{printf "\%3d \%s\n", NR, $0}'
skrishna23@hotmail.com, October 12, 2001 16:52
When I used this, the syntax highlighting for some
terms went OFF,
(for example, #include, #define....those that are meant
to be in col.1)
anyways to fix that ?
tia,
krishna.
daniel@brot.t0c.de, October 18, 2002 7:51
:set number
uws@xs4all.invalid, July 8, 2003 2:49
One could also use unix's `nl` command to add numbers
to all lines.
Example usage: :%nl -ba
micklweiss@gmx.net, November 28, 2003 16:59
:se nu
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=28 (2 of 2) [18/02/2004 14:41:25]

SourceForge
Logo

Tip #29 - reverse all the line with only 7 keystroke in vim : vim online

not logged in (login)

Home
Search

Tip #29: reverse all the line with only 7 keystroke in vim
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/6, Viewed by 1014

created: March 7, 2001 5:21


author: slimzhao@21cn.com

complexity: intermediate
as of Vim: 5.7

:g/^/m0
well,
1. : bring you to command-line mode(also known as exmode) from normal-mode(also known as command mode).
2. g means you'll take an action through the whole file,
generally perform a search, `v' also perform a search
but it match the line not match the canonical
expression.
3. / begins the regular express
4. ^ is a special character respect the start of a line.
5. the second / ends the regular express and indicate
that the remains is action to do.
6. m means move, `t` and `co' for copy, `d' for delete
7. 0 is the destination line.
you can use
:g/regexp/t$
to filter all lines and pick the match line together and
copy them to the end of the buffer or
:g/regexp/y A
to put them into a register(not eax, ebx...)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<add a line-number to every line without cat or awk alike utilities. | Increasing or decreasing numbers
>>

Additional Notes
rufus@o-town.de, April 16, 2002 6:12
You can drop the '^' in the regexp, an empty regexp it
will match any line, too:
:g//m0

http://www.vim.org/tips/tip.php?tip_id=29 (1 of 2) [18/02/2004 14:41:28]

Tip #29 - reverse all the line with only 7 keystroke in vim : vim online

Anonymous, August 16, 2003 13:54


actually an empty regex just matches the same thing as
the previous regex, which will not necessarily match
all lines.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=29 (2 of 2) [18/02/2004 14:41:28]

SourceForge
Logo

Tip #30 - Increasing or decreasing numbers : vim online

not logged in (login)

Home
Search

Tip #30: Increasing or decreasing numbers


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating 51/21, Viewed by 1109

created: March 7, 2001 5:25


author: neuron

complexity: basic
as of Vim: 5.7

To increase a number under or nearest to the right of


the cursor, go to Normal mode and type:
Ctrl-A

Scripts
Tips
My Account

To decrease, type:
Ctrl-X

Site Help

Using this in a macro simplifies generating number


sequences a lot.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<reverse all the line with only 7 keystroke in vim | Find and Replace >>

Additional Notes
vim@suijsmail.com, October 10, 2001 0:30
I always looked for a possbility to create multiple
lines with the same content only differing by an
increasing or decreasing number. Probably haven't
searched hard enough:
Create the first line with the number.
Set the cursor on the number.
Do: mnYP`n^A
Or create a macro with this and call it multiple times.
The single quote must be the back quote ` not ',
because ' goes to the beginning of the line in the mark
and ` goes to the proper column/character-position.
Furthermore the ^A = <CTRL>-A (see this page). You can
as easily change to decreasing numbers.
Herman Suijs

http://www.vim.org/tips/tip.php?tip_id=30 (1 of 2) [18/02/2004 14:41:31]

Tip #30 - Increasing or decreasing numbers : vim online

vim@suijsmail.com, October 10, 2001 0:31


I didn't even read properly, because the nearest number
to the right is increased or decreased. If there is
only 1 number on the line it doesn't matter if you use
` or '.
Sorry ;-)
Herman Suijs
franklin@goodhorse.idv.tw, February 18, 2003 0:57
Hi all
CTRL-A is used to add a number.
However, in gvim for win32, it became "select all".
Is there any way to change it back to increase a number
instead of select all text in file?
Thanks
seibpoirier@free.fr, May 15, 2003 7:01
you just have to put
nunmap <C-A>
in your _vimrc file
Seib
micklweiss@gmx.net, November 30, 2003 6:05
Actually, that last comment won't work on win32. (at
least when I tried it)
The correct version of that is:
:unmap <c-a>
Hope this helps someone else.

:-)

- Mick
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=30 (2 of 2) [18/02/2004 14:41:31]

SourceForge
Logo

Tip #31 - Find and Replace : vim online

not logged in (login)

Home
Search

Tip #31: Find and Replace


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating 59/31, Viewed by 2268

created: March 7, 2001 5:49


author: Anonymous

complexity: basic
as of Vim: 5.7

To find and replace one or more occurences of a given


text pattern with a
new text string, use the s[ubstitute] command.

Scripts
Tips
My Account

There are a variety of options, but these are what you


most probably want:

Site Help

:%s/foo/bar/g
find each occurance of 'foo' and
replace it with 'bar' without asking for confirmation
:%s/foo/bar/gc
find each occurance of 'foo' and
replace it with 'bar' asking for confirmation first
:%s/<foo>/bar/gc
find (match exact word only) and
replace each occurance of 'foo' with 'bar'
:%s/foo/bar/gci
find (case insensitive) and
replace each occurance of 'foo' with 'bar'
:%s/foo/bar/gcI
find (case sensitive) and
replace each occurance of 'foo' with 'bar'
NB: Without the 'g' flag, replacement occurs only for
the first occurrence in each line.
For a full description and some more interesting
examples of the substitute command refer to
:help substitute
See also:
:help cmdline-ranges
:help pattern
:help gdefault
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=31 (1 of 2) [18/02/2004 14:41:33]

Helpful

Unfulfilling

rate

Tip #31 - Find and Replace : vim online

<<Increasing or decreasing numbers | Write your own vim function(scripts) >>

Additional Notes
bstrohhaecker@hueller-hille.com, May 30, 2001 1:57
To match exact words only you need \<foo\>, not <foo>.
Anonymous, November 25, 2002 5:22
To find or replace line breaks or tab characters, use
Ctrl-v followed by the enter or tab key.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=31 (2 of 2) [18/02/2004 14:41:33]

SourceForge
Logo

Tip #32 - Write your own vim function(scripts) : vim online

not logged in (login)

Home
Search

Tip #32: Write your own vim function(scripts)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 17/13, Viewed by 1991

created: March 7, 2001 6:01


author: slimzhao@21cn.com

complexity: advanced
as of Vim: 5.7

compare to C and shell(bash), herein is some vim


specifics about vim-script:
1. A function name must be capitalized.
hex2dec is invalid
Hex2dec is valid
while in c and shell(bash), both lowercase and
uppercase is allowed.
2. how to reference the parameters
fu! Hex2dec(var1, var2)
let str=a:var1
let str2=a:var2
you must prefix the parameter name with "a:", and
a:var1 itself is read-only
in c, you reference the parameter directly and the
parameter is writable.
3. how to implement variable parameter
fu! Hex2dec(fixpara, ...)
a:0 is the real number of the variable parameter
when you invoke the function, with :Hex2dec("asdf",
4,5,6), a:0=3, and a:1=4 a:2=5 a:3=6
you can combine "a:" and the number to get the value
while i<a:0
exe "let num=a:".i
let i=i+1
endwhile
in c, the function get the real number by checking
the additional parameter such as printf family, or by
checking the special value such as NULL
4. where is the vim-library
yes, vim has its own function-library, just like *.a
in c
:help functions
5. can I use += or ++ operator?
Nop, += and ++ (and -=, -- and so on)operator gone
away in vim.
6. How can I assign a value to a variables and fetch its
value?

http://www.vim.org/tips/tip.php?tip_id=32 (1 of 3) [18/02/2004 14:41:35]

Tip #32 - Write your own vim function(scripts) : vim online

let var_Name=value
let var1=var2
like it does in c, except you must use let keyword
7. Can I use any ex-mode command in a function?
As I know, yes, just use it directly, as if every line
you type appears in the familar :
8. Can I call a function recurse?
Yes, but use it carefully to avoid infinte call.
9. Can I call another function in a function?
Course, like C does.
10. Must I compile the function?
No, you needn't and you can't, just :so script_name,
after this you can call the function freely.
11. Is it has integer and char or float data type?
No, like perl, vim script justify the variable type
depend upon the context
:let a=1
:let a=a."asdf"
:echo a
you'll get `1asdf'
:let a=1
:let a=a+2
:echo a
you'll get 3
But it differs from perl.
12. Must I append a `;' in every statement?
No, never do that.
; is required in C, and optional in shell for each
statement in a alone line.
But is forbidden in vim.
if you want combine servals statement in one single
line, use `|'.
Take your mind that every statement appears in
function should be valid in ex-mode(except for some
special statement).
rate this tip

Life Changing

Helpful

Unfulfilling

<<Find and Replace | toggle off the line-number when enter on-line help >>

Additional Notes
dp@orion.spectral-sys.com, March 14, 2001 13:29

http://www.vim.org/tips/tip.php?tip_id=32 (2 of 3) [18/02/2004 14:41:35]

rate

Tip #32 - Write your own vim function(scripts) : vim online

Additional clarification for #10, you do


:so filename_where_function_is_located
Not to be confused with the function name itself.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=32 (3 of 3) [18/02/2004 14:41:35]

SourceForge
Logo

Tip #33 - toggle off the line-number when enter on-line help : vim online

not logged in (login)

Home
Search

Tip #33: toggle off the line-number when enter on-line help
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 5/2, Viewed by 622

created: March 7, 2001 6:06


author: slimzhao@21cn.com

complexity: intermediate
as of Vim: 5.7

I like the line-number for myself editing. But I hate it


in on-line help page because it force the screen
wrapped.
:au filetype help :se nonu
rate this tip

Life Changing

Helpful

Unfulfilling

rate

Site Help
<<Write your own vim function(scripts) | control the position of the new window >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=33 [18/02/2004 14:41:37]

SourceForge
Logo

Tip #34 - control the position of the new window : vim online

not logged in (login)

Home
Search

Tip #34: control the position of the new window


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/2, Viewed by 596

created: March 7, 2001 6:09


author: slimzhao@21cn.com

complexity: intermediate
as of Vim: 5.7

:se splitbelow
make the new window appears below the current window.
:se splitright
make the new window appears in right.(only 6.0 version
can do a vsplit)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<toggle off the line-number when enter on-line help | For programmer: translate // style comment to
/* */and vice vesa >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=34 [18/02/2004 14:41:39]

SourceForge
Logo

Tip #35 - For programmer: translate // style comment to /* */and vice vesa : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #35: For programmer: translate // style comment to /* */and vice


vesa
tip karma

Rating -6/6, Viewed by 1059

created: March 7, 2001 6:25


author: slimzhao@21cn.com

complexity: intermediate
as of Vim: 5.7

the `|' concatenate servals ex-command in one line.


It's the key to translate // style comments to /* */
style
:g#^s{-}//#s##/*# | s#$#*/#
the `|' keep the current line matchs ^s{-}// to perform
s#$#*/
/* ... */ ---> //style
:g#/*(.{-})*/#//1#
/* ....
....
.....
*/
=====>
//......
//......
//......
style:
? Anyone implement it?
rate this tip

Life Changing

Helpful

Unfulfilling

<<control the position of the new window | Using Gnu-info help in vim >>

Additional Notes
leinfidel@netscape.net, August 31, 2003 14:29
wanted to, doesn't appear to work?
perhaps I'm no using it properly

http://www.vim.org/tips/tip.php?tip_id=35 (1 of 2) [18/02/2004 14:41:42]

rate

Tip #35 - For programmer: translate // style comment to /* */and vice vesa : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=35 (2 of 2) [18/02/2004 14:41:42]

SourceForge
Logo

Tip #36 - Using Gnu-info help in vim : vim online

not logged in (login)

Home
Search

Tip #36: Using Gnu-info help in vim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 2/4, Viewed by 691

created: March 7, 2001 6:41


author: vimer@21cn.com

complexity: basic
as of Vim: 5.7

K in normal bring you the man page about the keyword


under current cursor.
:nnoremap <F1> :exe ":!info ".expand("<cword>")
Now press F1 while the cursor is hold by a keyword such
as printf will bring you to Gnu-info help page
:h <F1>
:h nnoremap

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<For programmer: translate // style comment to /* */and vice vesa | The basic operation about vimboolean optionals >>

Additional Notes
Anonymous, January 14, 2004 1:36
Far better to use vimscript#21 - Info browsing within
vim.
Then e.g. :nnoremap <F1> :exe ":Info
".expand("<cword>")<CR>
Also, set your shell to alias info to use vim: (bash)
function viminfo () { vim -c "Info $1" -c "bdelete 1";
}
alias info=viminfo
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=36 [18/02/2004 14:41:44]

SourceForge
Logo

Tip #37 - The basic operation about vim-boolean optionals : vim online

not logged in (login)

Home
Search

Tip #37: The basic operation about vim-boolean optionals


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 8/5, Viewed by 534

created: March 7, 2001 6:47


author: slimzhao@21cn.com

complexity: basic
as of Vim: 5.7

:set number
switch the number on
:set nonumber
switch it off
:set invnumber
or
:set number!
switch it inverse against the current setting
:set number&
get the default value vim assums.
replace number with any legal vim-boolean optionals,
they all works well.
for vim-non-boolean optionals
:set optional&
also works properly.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using Gnu-info help in vim | Cursor one line at a time when :set wrap >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=37 [18/02/2004 14:41:46]

SourceForge
Logo

Tip #38 - Cursor one line at a time when :set wrap : vim online

not logged in (login)

Home
Search

Tip #38: Cursor one line at a time when :set wrap


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 18/11, Viewed by 707

created: March 7, 2001 8:41


author: ktohg@tritarget.com

complexity: basic
as of Vim: 5.7

If your tierd of the cursor jumping past 5 lines when


:set wrap then add these mappings to you vimrc file.
nnoremap
nnoremap
vnoremap
vnoremap
nnoremap
nnoremap
vnoremap
vnoremap
inoremap
inoremap

j gj
k gk
j gj
k gk
<Down> gj
<Up> gk
<Down> gj
<Up> gk
<Down> <C-o>gj
<Up> <C-o>gk

What they do is remap the cursor keys to use there `g'


equvilant. See :help gj
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<The basic operation about vim-boolean optionals | Undo and Redo >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=38 [18/02/2004 14:41:48]

SourceForge
Logo

Tip #39 - Undo and Redo : vim online

not logged in (login)

Home
Search

Tip #39: Undo and Redo


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 38/19, Viewed by 891

created: March 7, 2001 14:52


author: Anonymous

complexity: basic
as of Vim: 5.7

To undo recent changes, use the u[ndo] command:


u
undo last change (can be repeated to undo
preceding commands)
U
return the line to its original state
(undo all changes in current line)
CTRL-R
Redo changes which were undone (undo the
undo's).
For a full description of the undo/redo commands refer
to
:help undo
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Cursor one line at a time when :set wrap | Insert a file >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=39 [18/02/2004 14:41:50]

SourceForge
Logo

Tip #40 - Insert a file : vim online

not logged in (login)

Home
Search

Tip #40: Insert a file


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 26/11, Viewed by 841

created: March 8, 2001 7:25


author: Anonymous

complexity: basic
as of Vim: 5.7

To insert the contents of a file (or the output of a


system command)
into the current buffer, use the r[ead] command:
Examples:
:r foo.txt
cursor

inserts the file foo.txt below the

:0r foo.txt
first line

inserts the file foo.txt above the

:r !ls
below the cursor

inserts a listing of your directory

:$r !pwd
inserts the current working directory
below the last line
For more information about the r[ead] command refer to:
:help read
See also:
:help cmdline-ranges
:help !cmd

rate this tip

Life Changing

Helpful

Unfulfilling

<<Undo and Redo | Command-history facilities for Oracle/sqlplus user >>

Additional Notes
andy@edespot.com, July 16, 2002 19:05
http://www.vim.org/tips/tip.php?tip_id=40 (1 of 2) [18/02/2004 14:41:52]

rate

Tip #40 - Insert a file : vim online

Don't know the path to perl (for #!/.../perl)?


:r!which perl
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=40 (2 of 2) [18/02/2004 14:41:52]

SourceForge
Logo

Tip #41 - Command-history facilities for Oracle/sqlplus user : vim online

not logged in (login)

Home
Search

Tip #41: Command-history facilities for Oracle/sqlplus user


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/2, Viewed by 741

created: March 8, 2001 21:26


author: vimer@21cn.com

complexity: advanced
as of Vim: 5.7

First of all, thanks Benji fisher, Stefan Roemer...


and others in vim@vim.org which spend much time to
answer questions, sometimes foolish question asked by
someone like me. Without their I can't get the final
solution for my sqlplus work descripted follows.
As Oracle user known, sqlplus has a very bad
command-line edition environment. It has no
command-history, don't support most of getline
facilities. which MySQL and shell does it well.
Even Microsoft recogonize this point. In Windows2000,
doskey is installed by default.
Below is my vim-solution to sqlplus, which
record the command-history when you use
edit(sqlplus builtin command) to open the editor
specified by EDITOR environment variable. It saves
the SQL statement into a standalone file such as
.sqlplus.history
Every time you open the file
afiedt.buf(sqlplus's default command-buffer file),
you get two splited windows, the buffer above is
afiedt.buf, the buffer below is .sqlplus.history,
you can see every SQL statement in the windows.
If you want to use SQL statement in line 5 to replace
the current command-buffer, just press 5K, then
:xa
to back to you sqlplus. and use / to repeat the command
saved in command-buffer file called afiedt.buf by
default.
It can't process multi-line SQL statement convinencely.
Todo this, just use you favorite vim trick to do that:
fu! VimSQL()
nnoremap <C-K> :<C-U>
exe "let linenum=".v:count<CR>:1,$-1d<CR><C-W>j:exe lin
enum."y"<CR><C-W>kP
let linenum=line("$")
1,$-1w! >> ~/.sqlplus.history
e ~/.sqlplus.history

http://www.vim.org/tips/tip.php?tip_id=41 (1 of 3) [18/02/2004 14:41:55]

Tip #41 - Command-history facilities for Oracle/sqlplus user : vim online

execute ":$-".(linenum-1).",$m0"
%!uniq
if line("$")>100
101,$d
endif
b#
set splitbelow
sp ~/.sqlplus.history
au! BufEnter afiedt.buf
endf
au BufEnter afiedt.buf call VimSQL()
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Insert a file | Using marks >>

Additional Notes
stephen@morley.net, April 19, 2001 5:59
I added the following:
set syntax=sql
at the start of the function and after loading the
history file, this way the files will be shown with
syntax highlighting.
Also the following map
map ZZ :close<cr>:b afiedt.buf<cr>:xit<cr>
will let the ZZ function close the second window and
save the afiedt.buf file and then exit (if the user has
no other dirty buffers).
Stephen
makoml@msn.com, October 19, 2002 11:39
Another solution (but not olny for vim editor) :
If your operating system is HP-UX, try below.
$ ied sqlplus <user>/<pass>@<db>
SQL> [Escape-Key]
SQL> [K-Key] or [J-Key]
ied is a utility command that is intended to act as an
interface
between the user and an interactive program such as bc,
sqlplus,
providing most of the line editing and history
functionality found in the Korn shell.
http://www.vim.org/tips/tip.php?tip_id=41 (2 of 3) [18/02/2004 14:41:55]

Tip #41 - Command-history facilities for Oracle/sqlplus user : vim online

mako
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=41 (3 of 3) [18/02/2004 14:41:55]

SourceForge
Logo

Tip #42 - Using marks : vim online

not logged in (login)

Tip #42: Using marks

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 35/17, Viewed by 1131

created: March 9, 2001 2:20


author: Anonymous

complexity: basic
as of Vim: 5.7

To mark one or more positions in a file, use the m[ark]


command.
Examples:
ma

set current cursor location as mark a

'a

jump to beginning of line of mark a

`a

jump to postition of mark a

d'a

delete from current line to line of mark a

d`a
mark a

delete from current cursor position to

c'a
mark a

change text from current line to line of

y`a
mark a

yank text to unnamed buffer from cursor to

:marks

list all the current marks

Site Help

NB: Lowercase marks (a-z) are valid within one file.


Uppercase marks
(A-Z), also called file marks, are valid between files.
For a detailed description of the m[ark] command refer
to
:help mark
See also:
:help various-motions
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=42 (1 of 2) [18/02/2004 14:41:57]

Helpful

Unfulfilling

rate

Tip #42 - Using marks : vim online

<<Command-history facilities for Oracle/sqlplus user | Using abbreviations >>

Additional Notes
mbrubeck@cs.hmc.edu, December 10, 2001 14:41
I find that the most useful command is '' (that's a
pair of single quotes). This jumps to the special mark
' which is set automatically after every jump. This
allows you to easily return to your starting point
after a search, for example. This is similar to using
the jump stack (vimtip #10 or :help jump-motions).
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=42 (2 of 2) [18/02/2004 14:41:57]

SourceForge
Logo

Tip #43 - Using abbreviations : vim online

not logged in (login)

Home
Search

Tip #43: Using abbreviations


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/8, Viewed by 811

created: March 9, 2001 4:27


author: Anonymous

complexity: basic
as of Vim: 5.7

To define abbreviations, use the ab[breviate] command.


Examples:
:ab rtfm read the fine manual - Whenever you type
'rtfm' followed by a <space> (or <esc> or <cr>) vim
will expand this to
'read the fine manual'.
:ab
abbreviations

list all defined

:una[bbreviate] rtfm
list of abbreviations

remove 'rtfm' from the

:abc[lear]
abbreviations

remove all

NB: To avoid expansion in insert mode, type CTRL-V after


the last character of the abbreviation.
For a detailed description of the ab[breviate] command
and some more examples refer to
:help abbreviations
rate this tip

Life Changing

Helpful

<<Using marks | Repeat last changes >>

Additional Notes
berdim99@hotmail.com, March 13, 2001 8:22

http://www.vim.org/tips/tip.php?tip_id=43 (1 of 2) [18/02/2004 14:41:59]

Unfulfilling

rate

Tip #43 - Using abbreviations : vim online

Abbreviations can also be used to correct spelling, for


example:
ab teh the
jamesb@panmatrix.net, January 4, 2002 15:45
I don't know why you would, but this is interesting.
If you have abbreviations set up like this:
!
g1
hello
!
g2
howdy
!
g3
hello
!
g4
greetings
and you do a :una g3 it will expand g3 to hello and
delete both g1 and g3.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=43 (2 of 2) [18/02/2004 14:41:59]

SourceForge
Logo

Tip #44 - Repeat last changes : vim online

not logged in (login)

Home
Search

Tip #44: Repeat last changes


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/4, Viewed by 632

created: March 12, 2001 8:45


author: Anonymous

complexity: basic
as of Vim: 5.7

Simple text changes in normal mode (e.g. "dw" or "J")


can be repeated with the "." command.
The last command-line change (those invoked with ":",
e.g. ":s/foo/bar") can be
repeated with the "@:" command.
For more informations about repeating single changes
refer to:
:help single-repeat
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using abbreviations | Using command-line history >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=44 [18/02/2004 14:42:01]

SourceForge
Logo

Tip #45 - Using command-line history : vim online

not logged in (login)

Home
Search

Tip #45: Using command-line history


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/6, Viewed by 896

created: March 12, 2001 9:27


author: Anonymous

complexity: basic
as of Vim: 5.7

You can recall previous command lines from a history


table by hitting
the <Up> and <Down> cursor keys in command-line mode.
For example, this can be used to find the previous
substitute command:
Type ":s" and then <Up>.
There are separate history tables for the ':' commands
and for
previous '/' or '?' search strings.
To display the history of last entered commands or
search strings,
use the :his[tory] command:
:his

Display command-line history.

:his s

Display search string history.

For a detailed description of the command-line history


refer to:
:help cmdline-history
See also:
:help Cmdline-mode
rate this tip

Life Changing

Helpful

Unfulfilling

<<Repeat last changes | Win32 binaries with perl, python, and tcl >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=45 (1 of 2) [18/02/2004 14:42:03]

rate

Tip #45 - Using command-line history : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=45 (2 of 2) [18/02/2004 14:42:03]

SourceForge
Logo

Tip #46 - Win32 binaries with perl, python, and tcl : vim online

not logged in (login)

Home
Search

Tip #46: Win32 binaries with perl, python, and tcl


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 8/6, Viewed by 1380

created: March 12, 2001 12:33


author: benji@member.AMS.org

complexity: basic
as of Vim: 5.7

> Does anyone know if windows binaries of vim 5.7 are


available with perl and
> python support turned on?
ftp://vim.sourceforge.net/pub/vim/upload_binaries/
http://vim.sourceforge.net/bin_download/

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using command-line history | Swapping characters, words and lines >>

Additional Notes
Robert Bogomip <bob.bogo@milohedge.com>, June 6, 2001 1:38
If you have VisualC++ 6.0, then you are well
recommended to use the really cool delay loading
feature to delay-load the perl DLLs. The advantage of
this is that if your machine doesn't have a suitable
perl DLL available, then gvim will still run fine (so
long as you don't try to use any perl inside the vim
session of course). Oh, and since the Perl DLL uses the
C runtime in DLL form (msvcrt.dll), then gvim/vim
should also do this (that's "/MD" in uSoft speak). In
Makefile,w32 I use:
CFLAGS = $(CFLAGS) -DNDEBUG /Ox /G6 /Ob1 /Os /MD /Gy
PERL_LIB = /DelayLoad:perl56.dll
$(PERL)\Lib\Core\perl56.lib DelayImp.lib
(i.e., the link line has "/DelayLoad:perl56.dll" added.
Some stub code is required to support delay loading,
and uSoft supply this in DelayImp.lib). I also find
that I need to append "/I $(PERL)\Lib\MSWin32-x86\Core"
http://www.vim.org/tips/tip.php?tip_id=46 (1 of 2) [18/02/2004 14:42:05]

Tip #46 - Win32 binaries with perl, python, and tcl : vim online

to PERL_INC too.
gerhard@bigfoot.de, February 4, 2002 11:53
http://www.cs.fhm.edu/~ifw00065/vim/
The current CVS version of Vim (post 6.0.158) compiled
for Windows with the Python interface enabled (Python
2.2) plus VisVim and OLE. IOW, everything like the
standard 6.0.0 release from the Vim folks, just newer
and with Python 2.2 support. Using the latest NSIS
installer with bip2 compression, it's also much smaller
than the original. It's only 2.3 megs :-)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=46 (2 of 2) [18/02/2004 14:42:05]

SourceForge
Logo

Tip #47 - Swapping characters, words and lines : vim online

not logged in (login)

Home
Search

Tip #47: Swapping characters, words and lines


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 7/12, Viewed by 1032

created: March 13, 2001 13:08


author: Anonymous

complexity: basic
as of Vim: 5.7

To swap two characters or lines, use the following


commands:
xp
delete the character under the cursor and
put it afterwards.
(In other words, it swaps the
characters.)
ddp
afterwards.

delete the current line and put it


(In other words, it swaps the lines.)

Unfortunately there is no universal solution to swap two


words.
You may try the following ones, but don't expect too
much of them:
dawwP
delete the word under the cursor, move
forward one word
and put it back after the cursor. (In
other words, it
swaps the current and following word.)
dawbP
delete the word under the cursor, move
backward on word
and put it back after the cursor. (In
other words, it
swaps the current and preceeding word.)

rate this tip

Life Changing

Helpful

<<Win32 binaries with perl, python, and tcl | Moving around >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=47 (1 of 2) [18/02/2004 14:42:08]

Unfulfilling

rate

Tip #47 - Swapping characters, words and lines : vim online

Anonymous, August 27, 2001 4:54


I prefer to use dawelp.
cec@NgrOyphSon.gPsfAc.nMasa.gov, October 15, 2002 12:12
The tip
http://vim.sourceforge.net/tips/tip.php?tip_id=329
shows how
to swap a pair of adjacent words, potentially separated
by punctuation.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=47 (2 of 2) [18/02/2004 14:42:08]

SourceForge
Logo

Tip #48 - Moving around : vim online

not logged in (login)

Tip #48: Moving around

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 27/15, Viewed by 1314

created: March 14, 2001 8:36


author: Anonymous

complexity: basic
as of Vim: 5.7

You can save a lot of time when navigating through the


text by using
appropriate movements commands. In most cases the cursor
keys,
<PageUp> or <PageDown> are NOT the best choice.
Here is a selection of some basic movement commands that
hopefully helps you to acquire a taste for more:
e
w
3w
b
3b

$
<End>
0
<Home>

move
move
move
move
move
-

to the end of a word


forward to the beginning of a word
forward three words
backward to the beginning of a word
backward three words
move
same
move
same

to
as
to
as

the end of the line


$
the beginning of the line
0

)
(

- jump forward one sentence


- jump backward one sentence

}
{

- jump forward one paragraph


- jump backward one paragraph

H
M
L

- jump to the top of the display


- jump to the middle of the display
- jump to the bottom of the display

'm
`m

- jump to the beginning of the line of mark m


- jump to the location of mark m

G
- jump to end of file
1G - jump to beginning of file
50G - jump to line 50
'' - return to the line where the cursor was before the
latest jump
http://www.vim.org/tips/tip.php?tip_id=48 (1 of 2) [18/02/2004 14:42:10]

Tip #48 - Moving around : vim online

`` - return to the cursor position before the latest


jump (undo the jump).
% - jump to corresponding item, e.g. from an open brace
to its
matching closing brace
For some more interesting movement commands (especially
those
for programmers) refer to:
:help motion.txt
:help search-commands
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Swapping characters, words and lines | Switching case of characters >>

Additional Notes
pevans@lehman.com, June 19, 2002 4:51
^
g_

move to first non-blank character of the line.


move to last non-blank character of the line.

Anonymous, May 22, 2003 17:54


>1G - jump to beginning of file
gg is faster
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=48 (2 of 2) [18/02/2004 14:42:10]

SourceForge
Logo

Tip #49 - Switching case of characters : vim online

not logged in (login)

Tip #49: Switching case of characters

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 66/33, Viewed by 1587

created: March 14, 2001 9:24


author: Anonymous

complexity: basic
as of Vim: 5.7

To switch the case of one or more characters use the


"~", "gU" or
"gu" commands.
Examples:
~

switch case of character under cursor


(in visual-mode: switch case of highlighted

3~

switch case of next three characters

g~~

switch case of current line

text)

U
uppercase

in visual-mode: make highlighted text

gUU

make current line uppercase

u
lowercase

in visual-mode: make highlighted text

guu

make current line lowercase

gUaw

make current word uppercase

guaw

make current word lowercase

For some more examples refer to


:help ~
See also:
:help simple-change
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=49 (1 of 2) [18/02/2004 14:42:12]

Helpful

Unfulfilling

rate

Tip #49 - Switching case of characters : vim online

<<Moving around | Recovering files >>

Additional Notes
harri.haataja@cs.helsinki.fi, May 7, 2002 6:40
Not exactly case related but something I really like.
g?

does rot13 "encryption"

uws@xs4all.invalid, July 8, 2003 4:25


Instead of g~~, i prefer V~
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=49 (2 of 2) [18/02/2004 14:42:12]

SourceForge
Logo

Tip #50 - Recovering files : vim online

not logged in (login)

Home
Search

Tip #50: Recovering files


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 20/8, Viewed by 896

created: March 14, 2001 14:27


author: Anonymous

complexity: basic
as of Vim: 5.7

If your computer has crashed while editing a file, you


should be able
to recover the file by typing
vi -r <filename>
where <filename> is the name of the file you were
editing at the time
of the crash.
If you were editing without a file name, give an empty
string as argument:
vim -r ""
To get a list of recoverable files start vim without
arguments:
vim -r
For more information about file recovery refer to:
:help recovery
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Switching case of characters | Entering german umlauts >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=50 [18/02/2004 14:42:14]

SourceForge
Logo

Tip #51 - Entering german umlauts : vim online

not logged in (login)

Home
Search

Tip #51: Entering german umlauts


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 25/13, Viewed by 1026

created: March 15, 2001 1:52


author: Anonymous

complexity: basic
as of Vim: 5.7

To enter german umlauts (or any other of those weired


characters) not available on your keyboard use
'digraphs':
In insert-mode type for example:
CTRL-K "a
CTRL-K ^e
which gives an '' and 'e' with a hat.
You can also set the digraph option:
:set digraph (or :set dg)
With digraph option set you can enter
" <BS> a
^ <BS> e
which gives the same result.
To get a list of currently defined digraphs type
:dig[graphs]
For more information about defining and using digraphs
refer to:
:help digraph.txt
rate this tip

Life Changing

<<Recovering files | Scrolling synchronously >>

http://www.vim.org/tips/tip.php?tip_id=51 (1 of 2) [18/02/2004 14:42:16]

Helpful

Unfulfilling

rate

Tip #51 - Entering german umlauts : vim online

Additional Notes
joachim.hof@gmx.de, August 4, 2002 14:13
A little supplement:
German umlauts are: /, /, / , and moreover there
is ''.
These are CTRL-K plus:
a" resp A"
o" resp O"
u" resp U"
ss
-- Examples: -hnlich = similar
Rhre = tube
mde = tired
Strae = street
-- Some french words: -Ren - popular first name
Caf - coffee house
Ampre - French physicist, 1775 - 1836
The 'e' with a hat () is not german, it's french.
l in Danish is beer.
Joachim Hofmann (Schuttberg)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=51 (2 of 2) [18/02/2004 14:42:16]

SourceForge
Logo

Tip #52 - Scrolling synchronously : vim online

not logged in (login)

Home
Search

Tip #52: Scrolling synchronously


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 17/8, Viewed by 1329

created: March 18, 2001 12:27


author: Anonymous

complexity: basic
as of Vim: 5.7

If you want to bind two or more windows such that when


one
window is scrolled, the other windows are scrolled
simultaneously,
set the 'scrollbind' option for these windows:
:set scrollbind
When a window that has 'scrollbind' set is scrolled, all
other
'scrollbind' windows are scrolled the same amount, if
possible.
For more information about the 'scrollbind' option refer
to
:help scoll-binding
rate this tip

Life Changing

Helpful

Unfulfilling

<<Entering german umlauts | Better colors for syntax highlighting >>

Additional Notes
dp@orion.spectral-sys.com, April 20, 2001 13:43

http://www.vim.org/tips/tip.php?tip_id=52 (1 of 2) [18/02/2004 14:42:18]

rate

Tip #52 - Scrolling synchronously : vim online

And for those who are in versions prior to the


scrollbind
days, these maps help. They are intented for use with
2
windows open for scrolling. (I believe this was lifted
from
Dr. Campbell).
"
nmap
imap
nmap
imap

j
j
k
k

{ Scroll two windows up and down in parallel. }


<C-E><C-W>W<C-E><C-W>w
<Esc><C-E><C-W>W<C-E><C-W>wa
<C-Y><C-W>W<C-Y><C-W>w
<Esc><C-Y><C-W>W<C-Y><C-W>wa

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=52 (2 of 2) [18/02/2004 14:42:18]

SourceForge
Logo

Tip #53 - Better colors for syntax highlighting : vim online

not logged in (login)

Home
Search

Tip #53: Better colors for syntax highlighting


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 270/115, Viewed by 10078

created: March 18, 2001 12:59


author: Anonymous

complexity: basic
as of Vim: 5.7

For syntax highlighting there are two sets of default


color
maps: One for a light and another one for a dark
background.
If you have a black background, use the following
command to
get a better color map for syntax highlighting:
:set background=dark
You have to switch off and on again syntax highlighting
to
activate the new color map:
:syntax off
:syntax on
For a detailled description of syntax highlighting refer
to
:help syntax.txt
See also the Vim syntax support file:
$VIMRUNTIME/syntax/synload.vim
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Scrolling synchronously | View a Java Class File Decompiled thru Vim >>

Additional Notes
bindu@wavell.net, November 10, 2001 23:52
I just checked this in 6.0 and you no longer have to
turn syntax off and then back on.

http://www.vim.org/tips/tip.php?tip_id=53 (1 of 3) [18/02/2004 14:42:21]

Tip #53 - Better colors for syntax highlighting : vim online

Anonymous, August 10, 2002 5:00


Love is in the air...
dillon.jones@disney.com, November 26, 2002 11:53
This function reverses background setting so you can
quickly toggle between light and dark . I use it
because I'm often changing my desktop background and
use transparent terminals.
:function! ReverseBackground()
:
let Mysyn=&syntax
:
if &bg=="light"
:
se bg=dark
:
else
:
se bg=light
:
endif
:
syn on
:
exe "set syntax=" . Mysyn
":
echo "now syntax is "&syntax
:endfunction
:command! Invbg call ReverseBackground()
:noremap <F11> :Invbg<CR>
"
Anonymous, July 10, 2003 20:47
You may also need to change the highlighting to match
the new background. Here's the same macro as before,
but toggling the bacground colour of the window as
well:
:function! ReverseBackground()
:
let Mysyn=&syntax
:
if &bg=="light"
:
se bg=dark
:
highlight Normal guibg=black guifg=white
:
else
:
se bg=light
:
highlight Normal guibg=white guifg=black
:
endif
:
syn on
:
exe "set syntax=" . Mysyn
":
echo "now syntax is "&syntax
:endfunction
:command! Invbg call ReverseBackground()
:noremap <F11> :Invbg<CR>
Anonymous, August 21, 2003 15:31

http://www.vim.org/tips/tip.php?tip_id=53 (2 of 3) [18/02/2004 14:42:21]

Tip #53 - Better colors for syntax highlighting : vim online

Mmm... desert... I like that! :-)


http://www.vim.org/scripts/script.php?script_id=105
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=53 (3 of 3) [18/02/2004 14:42:21]

SourceForge
Logo

Tip #54 - View a Java Class File Decompiled thru Vim : vim online

not logged in (login)

Home
Search

Tip #54: View a Java Class File Decompiled thru Vim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 46/18, Viewed by 6460

created: March 22, 2001 18:21


author: bhaskar_v_k@hotmail.com

complexity: intermediate
as of Vim: 5.7

Hi All,
Wish u could view a Java Class File using Vim,
Well ur query ends here.
First of all u will need a Java Decompiler to decompile
the Class File.
I would suggest the JAD decompiler by Pavel Kouznetsov
http://www.geocities.com/SiliconValley/Bridge/8617/jad.html

Site Help

Its a command line decompiler and absolutely free.


U can use any command line decompiler of ur choice.
Next create a vimscript file called jad.vim as
######################### FILE START ################
augr class
au!
au bufreadpost,filereadpost *.class %!d:jad.exe -noctor -ff
-i -p %
au bufreadpost,filereadpost *.class set readonly
au bufreadpost,filereadpost *.class set ft=java
au bufreadpost,filereadpost *.class normal gg=G
au bufreadpost,filereadpost *.class set nomodified
augr END
######################## FILE END #####################
Note:- Keep the Jad.exe in a directory with out white
spaces.
The -p options directs JAD to send the output to standard
output
instead of a .jad file. Other options are described on the
JAD site.
Next add the following line in the .vimrc file.
so jad.vim
Next time u do vim abc.class. Viola u have the source code
for abc.class.
NOTE:- I have written the script so as to open the class
file

http://www.vim.org/tips/tip.php?tip_id=54 (1 of 2) [18/02/2004 14:42:23]

Tip #54 - View a Java Class File Decompiled thru Vim : vim online

read only, So that u dont accidently modify it.


U can also exted this script to unjar a jar file and then
view each
file in the JAR file.
thanks
bhaskar
Any suggestions are welcome
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Better colors for syntax highlighting | previous buffer >>

Additional Notes
b.cerrina@wanadoo.fr, August 21, 2001 13:54
Hi,
first I love this script
I modified this a little bit to use the improved file
runtime organisation of vim60, I don't know if other will
like it better but here it is:
I added to filetype.vim:
augroup filetypedetect
au! BufRead,BufNewFile *.jad setfiletype java
au! BufRead,BufNewFile *.class setfiletype class
augroup END
and created in ftplugin a class.vim with
%!jad.exe -noctor -ff -i -p %
set readonly
set ft=java
normal gg=G
set nomodified
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=54 (2 of 2) [18/02/2004 14:42:23]

SourceForge
Logo

Tip #55 - previous buffer : vim online

not logged in (login)

Home
Search

Tip #55: previous buffer


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 59/23, Viewed by 1464

created: March 27, 2001 21:33


author: scrott@users.sourceforge.net

complexity: basic
as of Vim: 5.7

One of the keys to vim is buffer management. If I have


to use another IDE that makes me click on a tab every
time I want to look at another file I'm going to go
postal.
So of course you know about :ls which lists all the
current open buffers. This gets a little unweildly once
you have a full project open so you can also use :b <any
snipit of text> <tab> to complete to an open buffer.
This is really nice because you can type any fragment of
a file name and it will complete to the matching file.
(i.e. RequestManager.java can be completed using
"tma"<tab> or "req"<tab> or "r.java"<tab>).
Now for awhile I was also using :bn and :bp which jumps
you to the next and previous buffer respectively. I
found I was often frustrated because I wanted :bp to be
the previous buffer I was in, not the previous buffer in
the list. So (drum roll) the reason I wrote this tip was
because of:
:b#
jump to the previous buffer you were in. Very very
handy. The only thing nicer are tag, but that's a tip
for another time.
:help buffers
:help bn
:help bp
If anybody knows where to get help on # in this context
please add notes.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<View a Java Class File Decompiled thru Vim | how to avoid obliterating window layout >>

http://www.vim.org/tips/tip.php?tip_id=55 (1 of 2) [18/02/2004 14:42:25]

Tip #55 - previous buffer : vim online

Additional Notes
max@malva.com.ua, April 6, 2001 6:26
For explanaition of # magic see :help expand
Btw, see :help CTRL-^ to toggle buffers
fma to be found at cci.dk, June 14, 2001 6:42
This is roughly the same as :e# except for completion
See also help for :_# and CTRL-^
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=55 (2 of 2) [18/02/2004 14:42:25]

SourceForge
Logo

Tip #58 - how to avoid obliterating window layout : vim online

not logged in (login)

Home
Search

Tip #58: how to avoid obliterating window layout


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/3, Viewed by 785

created: March 28, 2001 8:00


author: scotch

complexity: intermediate
as of Vim: 5.7

If you take the time to lay out several windows


with vim (especially vertically in version 6), you may
be bummed when
you hit an errant key and find that all but what one
window
disappears.
What happens: while navigating between windows, you
hit <C-W>j, <C-W>k, etc. At some point you accidently
hit <C-W> but then don't follow with a window command.
Now hitting 'o' to start insert mode issues a command
equivalent to :only, and closes all windows execept
for the one you are in (unless some windows have unsaved
changes in them).
How to avoid this: petition the vim-dev mailing list
about
how :only is sufficient for the infrequenty use this
might
get (j/k).
Really: use mapping to disable the <C-W>o functionality;
put
this in your .vimrc:
nnoremap <C-W>O :echo "sucker"<CR>
nnoremap <C-W>o :echo "sucker"<CR>
nnoremap <C-W><C-O> :echo "sucker"<CR>
references:
:help :only
:help CTRL-W_o
That is all.
Scott

http://www.vim.org/tips/tip.php?tip_id=58 (1 of 2) [18/02/2004 14:42:27]

Tip #58 - how to avoid obliterating window layout : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<previous buffer | Applying substitutes to a visual block >>

Additional Notes
scottu@apptechsys.com, January 16, 2002 15:15
See tip vimtip #199 for a way to map these keys to a
maximize window - return to split structure function.
drchipN@OcampbellSfamilyP.AbizM, December 4, 2003 12:18
Another solution is given by ZoomWin (vimscript#508)
which makes <c-w>o
toggle between the multi-window display and a single
window.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=58 (2 of 2) [18/02/2004 14:42:27]

SourceForge
Logo

Tip #62 - Applying substitutes to a visual block : vim online

not logged in (login)

Home
Search

Tip #62: Applying substitutes to a visual block


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 8/4, Viewed by 774

created: March 28, 2001 8:22


author: Chip Campbell

complexity: basic
as of Vim: 5.7

If you'd like to apply a substitute, or even any ex command,


to a visual-block
selected text region (ctrl-v and move), then you'll want
Stefan Roemer's
http://www.erols.com/astronaut/vim/vimscript/vis.vim . Just
source it in,
and then press ":B". On the command line you'll see

Site Help

:'<,'>BCtrl-V
Just continue with the substitute or whatever...
:'<,'>B s/abc/ABC/g
and the substitute will be applied to just that block of
text!
Example: Ctrl-V Select..........|......Type
..................just the central....|......:B s/abc/ABC/g
..................four "abc"s..............|
..................----------------....|...------------..................abcabcabcabc............|......abcabcabcabc
..................abcabcabcabc............|......abcABCABCabc
..................abcabcabcabc............|......abcABCABCabc
..................abcabcabcabc............|......abcabcabcabc
(dots inserted to retain tabular format)

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<how to avoid obliterating window layout | Applying substitutes to a visual block >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=62 (1 of 2) [18/02/2004 14:42:29]

Tip #62 - Applying substitutes to a visual block : vim online


If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=62 (2 of 2) [18/02/2004 14:42:29]

SourceForge
Logo

Tip #63 - Applying substitutes to a visual block : vim online

not logged in (login)

Home
Search

Tip #63: Applying substitutes to a visual block


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 76/23, Viewed by 2786

created: March 28, 2001 8:26


author: Chip Campbell

complexity: intermediate
as of Vim: 5.7

If you'd like to apply a substitute, or even any ex command,


to a visual-block
selected text region (ctrl-v and move), then you'll want
Stefan Roemer's
http://www.erols.com/astronaut/vim/vimscript/vis.vim . Just
source it in,
and then press ":B". On the command line you'll see

Site Help

:'<,'>BCtrl-V
Just continue with the substitute or whatever...
:'<,'>B s/abc/ABC/g
and the substitute will be applied to just that block of
text!
Example: Ctrl-V Select..........|......Type
..................just the central.......|......:B
s/abc/ABC/g
..................four "abc"s.................|
..................---------............|...------------..................abcabcabcabc............|......abcabcabcabc
..................abcabcabcabc............|......abcABCABCabc
..................abcabcabcabc............|......abcABCABCabc
..................abcabcabcabc............|......abcabcabcabc
(dots inserted to retain tabular format)

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Applying substitutes to a visual block | Always set your working directory to the file you're editing >>

Additional Notes
Anonymous, June 15, 2001 6:51

http://www.vim.org/tips/tip.php?tip_id=63 (1 of 3) [18/02/2004 14:42:32]

Tip #63 - Applying substitutes to a visual block : vim online

Sorry about the "Ctrl-V" in :'<,'>BCtrl-V, it shouldn't be


there.
Also I tried to get the dots to line up, but proportional
fonts won out.
--Chip Campbell
hsinclai@speakeasy.net, February 15, 2002 20:59
I use the following pretty much the same, but no need to
import a file...
Just the :g/ command after using V, Shift-V, or CTRL-V to
select.
For example:
to change this line:
word one word two word three
to a vertical list, put the cursor at the start of the
line, then
Shift-V
:g/ /s//CTRL-vCTRL-m/g <CR>
It's a global replace command. :g/
The first pattern to find is a space :g/ /
Now start a substitution :g/ /s//
Use CTRL-v followed by CTRL-m to compose a carriage return
(<CR>)
Now finish the regex with a slash and 'g' for global :g/
/s//CTRL-vCTRL-m/g
and press enter.
Seems like a ridiculously large amount of stuff to remember
but it's been 2nd nature for years now :)
I use it mostly to comment blocks when writing scripts
until I found the b_v_I
try
:g/^/s//# /g
after selecting a block of text to comment out in a script.
OH MY GOD I JUST REMEMBERED THIS IS PART OF VI NOT VIM.
hari kari

cec@NgrOyphSon.gPsfAc.nMasa.gov, February 28, 2002 7:41

http://www.vim.org/tips/tip.php?tip_id=63 (2 of 3) [18/02/2004 14:42:32]

Tip #63 - Applying substitutes to a visual block : vim online

I fear I may not have conveyed the idea properly. Its not
referring
merely to a block of lines but to a visual-block (ie. a
subset of the
characters) and restricting the substitute to refer only to
that visual
block.
I want to convert just the some of the central "cab"
strings to CAB;
use ctrl-v and motion (hjkl or cursor keys) to select the
"cab" strings
to be transformed via a visual-block selection:
to
---->
abcabcabcabcabc
abcabcabcabcabc
abcabcabcabcabc
abcabcabcabcabc
abcabcabcabcabc

abcabcabcabcabc
abcabCABcabcabc
abcabCABcabcabc
abcabCABcabcabc
abcabcabcabcabc

This operation has nothing much to do with converting a


line to a
vertical list. Often it is used to change a variable:
to
---->
printf("...",
abc[0],def[0],ghi[0],
abc[1],def[1],ghi[1],
abc[2],def[2],ghi[2],
abc[3],def[3],ghi[3],

printf("...",
abc[0],DEF[0],ghi[0],
abc[1],DEF[1],ghi[1],
abc[2],DEF[2],ghi[2],
abc[3],DEF[3],ghi[3],

One could break this on the commas, [range]s/def/DEF/,


and rejoin, but that's a lot more work and less intuitive
than simply using ctrl-v to select a visual block and
doing the substitute just on that visual block.
cec@NgrOyphSon.gPsfAc.nMasa.gov, June 19, 2002 7:13
Vis.vim has been improved as of 6/19/2002 -- it is now
immune to tabs and
is considerably faster. Its a complete internal re-write,
although its
interface has been retained.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=63 (3 of 3) [18/02/2004 14:42:32]

SourceForge
Logo

Tip #64 - Always set your working directory to the file you're editing : vim online

not logged in (login)

Home
Search

Tip #64: Always set your working directory to the file you're editing
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 73/31, Viewed by 2044

created: March 28, 2001 9:12


author: William Lee

complexity: intermediate
as of Vim: 5.7

Sometimes I think it's helpful if your working directory


is always the same as the buffer you are editing. You
need to put this in your .vimrc:
function! CHANGE_CURR_DIR()
let _dir = expand("%:p:h")
exec "cd " . _dir
unlet _dir
endfunction
autocmd BufEnter * call CHANGE_CURR_DIR()
Doing this will make a "cd" command to your the current
buffer each time you switch to it. This is actually
similar to vimtip#2 but more automatic.
You should see for more details:
:help autocmd
:help expand
:help function
Note: This tip was contributed by somebody on the list a
while ago (sorry for no reference) and it has been
extremely helpful to me. Thanks!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Applying substitutes to a visual block | Insert line number into the actuall text of the file. >>

Additional Notes
Alexey Marinichev, June 5, 2001 10:54

http://www.vim.org/tips/tip.php?tip_id=64 (1 of 2) [18/02/2004 14:42:34]

Tip #64 - Always set your working directory to the file you're editing : vim online

Autocommand that calls CHANGE_CURR_DIR can be rewritten


like this:
autocmd BufEnter * cd %:p:h
Anonymous, July 19, 2001 12:19
Another approach is to keep VIM's starting directory,
but have the capability to easily change directory to
the file being edited. The mapping below does that.
map ,cd :exe 'cd ' . expand ("%:p:h")<CR>
ict@eh.org, September 29, 2001 10:39
I've found it useful to not change the directory if one
is editing in /tmp (useful for things like editing CVS
commit entries). Suitable modification is thus:
function! CHANGE_CURR_DIR()
let _dir = expand("%:p:h")
if _dir !~ '^/tmp'
exec "cd " . _dir
endif
unlet _dir
endfunction
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=64 (2 of 2) [18/02/2004 14:42:34]

SourceForge
Logo

Tip #65 - Insert line number into the actuall text of the file. : vim online

not logged in (login)

Home
Search

Tip #65: Insert line number into the actuall text of the file.
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 66/33, Viewed by 2160

created: April 5, 2001 16:59


author: Devin Weaver

complexity: basic
as of Vim: 5.7

Although :set number will add nice line number for you
At time you may wish to actually place the line numbers
into the file. For example on GNU Unix you can acomplish
a simular task using cat -n file > new_file
In VIM you can use the global command to do this
:g/^/exec "s/^/".strpart(line(".")."

", 0, 4)

What this does is run the exec comand on every line that
matches /^/ (All)
The exec command taks a string and executes it as if it
were typed in.
line(".")."
" -> returns the number of the current
line plus four spaces.
strpart("123
", 0, 4) -> returns only the first four
characters ("123 ").
"s/^/123 " -> substituts the begining of the line with
"123 ".
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Always set your working directory to the file you're editing | Transfer text between two Vim
'sessions', >>

Additional Notes
ktohg@tritarget.com, April 5, 2001 17:02

http://www.vim.org/tips/tip.php?tip_id=65 (1 of 3) [18/02/2004 14:42:36]

Tip #65 - Insert line number into the actuall text of the file. : vim online

Hmmm. Silly me I forgot HTML contracts spaces. Perhaps


a pre comand would be usefull.
<pre>
:g/^/exec "s/^/".strpart(line(".")."
</pre>

",0,4)

michaelrgeddes@optushome.com.au, June 4, 2001 23:13


In Vim6, this is even easier. For more
information, :help :s and look at the line about \=
:%s/^/\=strpart(line('.')."

",0,&ts)

maxiangjiang@yahoo.com, July 25, 2001 16:38


How about in visual mode, type
:s/^/\\=strpart((line('.')-line("'<")+1).'

',0,5)

Then you will get visual selection numbered


as expected
vimlist@thechases.com, August 29, 2002 13:01
I've found that to number a selection (or even the
whole document) piping it through grep (available now
for your favorite platform, operators are standing by
to take your orders) can be much faster and usually
offers the results I want.
:'<,'>!grep -n -h ^
This numbers (-n) the lines it's piped through and
strips the file-name headers (-h) that grep puts
in. You can even select certain lines to number by
changing the pattern to match (^ is just the beginning
of the line, but it could be a more complex formula)
It's a bit faster than the other suggestions for a
quick down-n-dirty numbering of lines. Small
variations I've noted include:
-The other versions here have a fixed-width column-this could be a good thing or a bad thing
-This one (at least with the version of grep I used)
places a colon after the line numbers, which again
could be good or bad
-This *does* need grep to be around...not a problem for
most folks, but it might be an issue
-tim

http://www.vim.org/tips/tip.php?tip_id=65 (2 of 3) [18/02/2004 14:42:36]

Tip #65 - Insert line number into the actuall text of the file. : vim online

docelic@linux.hr, January 5, 2003 6:46


You might as well add numbers in the file by simply
typing
:%!cat -n
-docelic
Anonymous, December 15, 2003 12:00
If you have the version with Python scripting, you can
use the following :
:py << EOF
from vim import *
cb = current.buffer
for i in range(len(cb)):
cb[i] = str(i) + ' ' + cb[i]
EOF
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=65 (3 of 3) [18/02/2004 14:42:36]

SourceForge
Logo

Tip #66 - Transfer text between two Vim 'sessions', : vim online

not logged in (login)

Home
Search

Tip #66: Transfer text between two Vim 'sessions',


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 21/9, Viewed by 1525

created: April 20, 2001 13:46


author: Douglas Potts

complexity: basic
as of Vim: 5.7

This one is a one of my favorites from Dr. Chip, and I


haven't seen it come
across vim tips yet...
Can use either visual, or marking to denote the text.
" transfer/read and write one block of text between vim
sessions
" Usage:
" `from' session:
"
ma
"
move to end-of-block
"
xw
"
" `to' session:
"
move to where I want block inserted
"
xr
"
if has("unix")
nmap xr
:r $HOME/.vimxfer<CR>
nmap xw
:'a,.w! $HOME/.vimxfer<CR>
vmap xr
c<esc>:r $HOME/.vimxfer<CR>
vmap xw
:w! $HOME/.vimxfer<CR>
else
nmap xr
:r c:/.vimxfer<CR>
nmap xw
:'a,.w! c:/.vimxfer<CR>
vmap xr
c<esc>:r c:/.vimxfer<cr>
vmap xw
:w! c:/.vimxfer<CR>
endif
rate this tip

Life Changing

Helpful

Unfulfilling

<<Insert line number into the actuall text of the file. | Ascii Value >>

Additional Notes
http://www.vim.org/tips/tip.php?tip_id=66 (1 of 2) [18/02/2004 14:42:39]

rate

Tip #66 - Transfer text between two Vim 'sessions', : vim online

Alexey Marinichev, June 4, 2001 11:17


See also Tip #71.
peoter_veliki@hotmail.com, June 4, 2001 21:56

It would be good if this could include a command to


remove the .vimxfer file from the buffer list,
otherwise it polutes the list and alternative
file. This perhaps negates the benefit since you could
just the * buffer as well with only a few extra
keystrokes:
(highlight text)
"*y
Then to paste in another file or application:
"*p

supergrass@gmx.net, February 9, 2002 5:43


here is much simple version of it.. however tested on
*nix only
"copy and paste
nmap
_Y
~/.vi_tmp<CR>
vmap
_Y
nmap
_P

betweeen different vim sessions


:!echo ""> ~/.vi_tmp<CR><CR>:w!
:w! ~/.vi_tmp<CR>
:r ~/.vi_tmp<CR>

select your text, press CTRL+_Y to copy, then in


another (or even the same) vim session press CTRL+_P to
paste
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=66 (2 of 2) [18/02/2004 14:42:39]

SourceForge
Logo

Tip #67 - Ascii Value : vim online

not logged in (login)

Home
Search

Tip #67: Ascii Value


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 173/83, Viewed by 4582

created: May 7, 2001 5:56


author: Erhan

complexity: intermediate
as of Vim: 5.7

Sometimes we, the programmers, need the value of a


character, don't we?
You can learn the ascii value of a character by pressing
g and a keys.(ga)!
It displays the value in dec, hex and octal...
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Transfer text between two Vim 'sessions', | Delete key >>

Additional Notes
dp@orion.spectral-sys.com, May 9, 2001 6:35
You can also add options to the statusline option to
show what the
ascii value of the character under the cursor is.
set statusline=%<%f%h%m%r%=%b 0x%B %l,%c%V %P
^^^^^^^^
The underlined part is what does it.
scrott@users.sourceforge.net, May 9, 2001 22:29
The mnemonic I use to remember ga is "get ascii" but I
guess that is an obvious one...
stephane@tuxfinder.org, June 5, 2001 5:00
doesn't work with multibyte editing :-(
Alexey Marinichev, June 7, 2001 14:57
For multibyte use g8.
Add Note

http://www.vim.org/tips/tip.php?tip_id=67 (1 of 2) [18/02/2004 14:42:41]

Tip #67 - Ascii Value : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=67 (2 of 2) [18/02/2004 14:42:41]

SourceForge
Logo

Tip #68 - Delete key : vim online

not logged in (login)

Home
Search

Tip #68: Delete key


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 7/21, Viewed by 1576

created: May 7, 2001 5:59


author: Erhan

complexity: basic
as of Vim: 5.7

Don't worry if your delete key does not work properly.


Just press <CTRL>-Backspace.
It works under both mode(insert or normal).
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Ascii Value | dot makes life easier >>

Additional Notes
Anonymous, May 16, 2001 3:14
Does not work!
Try mapping.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=68 [18/02/2004 14:42:43]

SourceForge
Logo

Tip #69 - dot makes life easier : vim online

not logged in (login)

Home
Search

Tip #69: dot makes life easier


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 58/32, Viewed by 2707

created: May 30, 2001 3:13


author: Erhan

complexity: basic
as of Vim: 5.7

You can copy and paste the last changes you made in the
last insert mode
without using y and p by pressing . (just dot).
Vim memorizes the keys you pressed and echos them if you
hit the dot key.
You must be in command mode as usual.
It can be helpful...

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Delete key | running a command on all buffers >>

Additional Notes
erhan@aybim.com.tr, May 30, 2001 23:22
You can also repeat the last command you write by
pressing dot.
So, it makes it easier to repeat 2-3 character long
commands.
Anonymous, June 4, 2001 13:23
duh.
Anonymous, September 10, 2001 1:11
You can insert last change with C-A in Insert mode too.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=69 [18/02/2004 14:42:45]

SourceForge
Logo

Tip #70 - running a command on all buffers : vim online

not logged in (login)

Home
Search

Tip #70: running a command on all buffers


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 38/13, Viewed by 1620

created: May 30, 2001 12:09


author: Scott Johnston

complexity: basic
as of Vim: 5.7

From Peter Bismuti on the vim list:


How to global search and replace in all buffers with one
command?
You need the AllBuffers command:
:call AllBuffers("%s/string1/string2/g")
"put this in a file and source it
function AllBuffers(cmnd)
let cmnd = a:cmnd
let i = 1
while (i <= bufnr("$"))
if bufexists(i)
execute "buffer" i
execute cmnd
endif
let i = i+1
endwhile
endfun
":call AllBuffers("%s/foo/bar/ge|update")
Thanks Peter!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<dot makes life easier | Transfer text between two gvim sessions using clipboard >>

Additional Notes
amackay@s.gusnet.cx, June 4, 2001 19:07

http://www.vim.org/tips/tip.php?tip_id=70 (1 of 3) [18/02/2004 14:42:48]

Tip #70 - running a command on all buffers : vim online

I like this one better as you know exactly what is


getting changed and it doesn't require writing any
buffers, it just modifies them.
" execute a command for all buffers ther are shown in
windows
fun! AllWindows(cmnd)
let cmnd = a:cmnd
let origw = winnr()
let i = 1
while (i <= bufnr("$"))
if bufexists(i)
let w = bufwinnr(i)
if w != -1
echo "=== window: " . w . " file: " .
bufname(i)
execute "normal \<c-w>" . w . "w"
execute cmnd
endif
endif
let i = i+1
endwhile
execute "normal \<c-w>" . origw . "w"
endfun
peoter_veliki@hotmail.com, June 4, 2001 22:43

From Janakiraman .S:


Addiing those quotes is pretty boring. That is easy to
fix. Just make a
command like
command! -nargs=+ -complete=command AllBuf call
AllBuffers(<q-args>)
You could then replace across multiple files with
:AllBuf %s/foo/bar/ge
kgergely@mcl.hu, January 9, 2002 6:33
What about the |argdo| and |bufdo| and |windo|
commands?
Gergely Kontra
vincent.virgilio@itt.com, September 13, 2002 13:47
bufdo works for me.

http://www.vim.org/tips/tip.php?tip_id=70 (2 of 3) [18/02/2004 14:42:48]

Perhaps it's a new feature.

Tip #70 - running a command on all buffers : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=70 (3 of 3) [18/02/2004 14:42:48]

SourceForge
Logo

Tip #71 - Transfer text between two gvim sessions using clipboard : vim online

not logged in (login)

Home
Search

Tip #71: Transfer text between two gvim sessions using clipboard
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 23/14, Viewed by 1471

created: June 4, 2001 11:14


author: Alexey Marinichev

complexity: basic
as of Vim: 5.7

If you use gvim, you can transfer text from one instance
of gvim into another one using clipboard. It is
convenient to use * (star) register, like this:
In one instance yank two lines into clipboard:
"*2yy
Paste it in another instance in normal mode:
"*p
or in insert mode:
<Ctrl-R>*
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<running a command on all buffers | Remove unwanted empty lines >>

Additional Notes
benfranklin@sortonce.com, May 31, 2002 20:10
In gvim, for the "copy to clipboard" command, Ctrl+C
works just as well on highlighted text as "*p.
This works for both text in the edit buffer and
characters on the command line.
-- Ben
benfranklin@sortonce.com, May 31, 2002 20:11
Oops, I meant Ctrl+C works like "*y.
-- Ben
anthony, September 22, 2002 18:32
Now if you can only do the same between two vim's
runing in xterms!

http://www.vim.org/tips/tip.php?tip_id=71 (1 of 2) [18/02/2004 14:42:50]

Tip #71 - Transfer text between two gvim sessions using clipboard : vim online

anthony@cit.gu.edu.au, September 22, 2002 18:33


Now if you can only do the same between two vim's
runing in xterms!
Pete Zaitcev <zaitcev@yahoo.com>, May 1, 2003 11:50
Definitely life-changing, because I really hate pasting
with the middle button
into gvim. It pastes under X cursor instead of text
cursor, so I always hit
wrong place. And you cannot paste into partially
obscured windows,
while you can do it when running vim under xterm.
Clipboard does not
have this problem. Clipboard also works well with
Mozilla and gnome-terminal.
I only wish gvim adopted Shift-Ctrl-V shortcut as an
alternative to "*p.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=71 (2 of 2) [18/02/2004 14:42:50]

SourceForge
Logo

Tip #72 - Remove unwanted empty lines : vim online

not logged in (login)

Home
Search

Tip #72: Remove unwanted empty lines


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 26/17, Viewed by 1358

created: June 5, 2001 11:11


author: Volker Duetsch

complexity: basic
as of Vim: 5.7

Sometimes to improve the readability of the document I


insert empty lines, which will be later removed.
To get rid off them try:
:%g/^$/d
This will remove a l l empty line in the document.
Some other tipps you can find under
www.linuxclass.de/vim.phtml

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Transfer text between two gvim sessions using clipboard | Using vim as calculator >>

Additional Notes
Anonymous, July 13, 2001 20:42
I know this may sound like trolling, but this makes me
wonder why there's not an option to rate suggestions
"Detremental".
Anonymous, January 13, 2004 1:00
Detrimental? In my opinion tips like these are useful
since they show up nicely when you for example
google for this little hint you just needed.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=72 [18/02/2004 14:42:52]

SourceForge
Logo

Tip #73 - Using vim as calculator : vim online

not logged in (login)

Home
Search

Tip #73: Using vim as calculator


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 65/42, Viewed by 3169

created: June 5, 2001 11:14


author: Volker Duetsch

complexity: basic
as of Vim: 5.7

Basic calculations can done within vim easily by typing (insertmode):


STRG (=CTRL) + R followed by =
then for example 2+2 and hit RETURN
the result 4 will be printed in the document.
Some other tipps you can find under www.linuxclass.de/vim.phtml

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Remove unwanted empty lines | Using Vim as an outline processor >>

Additional Notes
maxiangjiang@yahoo.com, July 25, 2001 16:20

Adding the following map to your vimrc


ino <C-A> <C-O>yiW<End>=<C-R>=<C-R>0<CR>
Then, just type 8*8<C-A>
you will get 8*8=64
jmcpherson@bigfoot.com, December 18, 2001 11:03
For simple arithmitic, you can often get away with just using
repeats of the Ctrl-A (increment) and Ctrl-X (decrement)
commands.
For instance, to calculate 453-244, insert the text "453" and
then, in Command mode, type 244 and press Ctrl-X (answer: 209).
To calculate 4024+3322, insert the text "4024" and then, in
Command mode, type 3322 and press Ctrl-A (answer: 7346).
modnar_uk@yahoo.co.uk, January 2, 2002 10:53
Is there any way that I can calculate with real numbers (as
opposed to integers only)?
antti@_NOSPAM_kuntsi.com, January 26, 2002 7:52

http://www.vim.org/tips/tip.php?tip_id=73 (1 of 2) [18/02/2004 14:42:56]

Tip #73 - Using vim as calculator : vim online

I have a mapping for passing a line to bc:


map gbc yypkA =<ESC>jOscale=2<ESC>:.,+1!bc<CR>kJ
I guess it could be made a bit better. Another 'useful' mapping
I once needed was summing numbers on multiple lines:
vmap gs y'>p:'[,']1s/$/+/\|'[,']+1j!<CR>'[0"wy$:.s.*\=w<CR>'[yyP:.s/./=/g<CR>_j
So, having
10
20
30
in a file would result in two new lines:
==
60
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=73 (2 of 2) [18/02/2004 14:42:56]

SourceForge
Logo

Tip #74 - Using Vim as an outline processor : vim online

not logged in (login)

Home
Search

Tip #74: Using Vim as an outline processor


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 45/15, Viewed by 2286

created: June 5, 2001 12:01


author: Steve Litt

complexity: intermediate
as of Vim: 6.0

With the addition of folding, Vim6 can function as a high


performance outline processor. Simply :set ai and in insert
mode use backspace to promote and tab to demote headlines.
In command mode, << promotes (n<< to promote multiple lines),
and >> demotes. Also, highlight several headlines and < or >
to promote or demote.
:set foldmethod=indent, and then your z commands can expand or
collapse headline trees, filewide or by the tree.
The VimOutliner GPL distro contains the scripts and configs to
easily configure Vim6 as an outliner, including scripts to
create tag files enabling interoutline hyperlinking.
The VimOutliner project is at
http://www.troubleshooters.com/projects/vimoutliner/index.htm.
Steve (Litt)
slitt@troubleshooters.com
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using vim as calculator | Remap CAPSLOCK key in Windows 2000 Professional and NT4.0 >>

Additional Notes
Anonymous, June 9, 2001 20:15
Awesome.... just what I needed!
ned@bike-nomad.com, September 8, 2003 10:23
If you're interested in outlining in Vim, you should also
check out my TVO
http://www.vim.org/script.php?script_id=517
Add Note

http://www.vim.org/tips/tip.php?tip_id=74 (1 of 2) [18/02/2004 14:42:59]

Tip #74 - Using Vim as an outline processor : vim online


If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=74 (2 of 2) [18/02/2004 14:42:59]

SourceForge
Logo

Tip #75 - Remap CAPSLOCK key in Windows 2000 Professional and NT4.0 : vim online

not logged in (login)

Home
Search

Tip #75: Remap CAPSLOCK key in Windows 2000 Professional and NT4.0
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 89/36, Viewed by 3876

created: June 7, 2001 5:54


author: Igor Prischepoff

complexity: basic
as of Vim: 5.7

If you're Windows 2000 Professional user and got tired to move your hands off
basic row when hitting <ESC> key
here the solution (not for Windows 9x.):
remap CapsLock key as <ESC> key. It's located in useful position.
Put this lines into <EscLock.reg> file and start it in explorer.Reboot.Enjoy.
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00
To restore you capslock back just delete this entry from Registry and reboot.
And below is remapping <capslock> as <Left Control>:
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00

rate this tip

Life Changing

Helpful

<<Using Vim as an outline processor | Folding for Quickfix >>

Additional Notes
gmargo@yahoo.com, July 15, 2001 10:15

http://www.vim.org/tips/tip.php?tip_id=75 (1 of 3) [18/02/2004 14:43:08]

Unfulfilling

rate

Tip #75 - Remap CAPSLOCK key in Windows 2000 Professional and NT4.0 : vim online

Windows:
There is an excellent free tool available to remap the capslock to control ,
thereby putting a control key in "the right place"(tm).
I think the source code is included too.
There are versions for both WinNT/2000 and Win98/95/Me.
Look on http://www.sysinternals.com/.
While they are easy to find, here are the direct links:
http://www.sysinternals.com/ntw2k/source/ctrl2cap.shtml
http://www.sysinternals.com/win9x/utilities/ctrl2cap95.shtml
Linux/Unix:
Here's how to map the caps lock key to a control under X windows,
at least under xfree86-3.x and 4.x:
Add a file named ".Xkbmap" in your home directory with this content:
-option ctrl:nocaps
hans@fugal.net, July 19, 2001 7:01
It would be useful to remap caps lock to some other out-of-the-way key.
linux I map it to F4, but how would I do that in w2k?

In

juano@mindspring.com, July 20, 2001 13:21


Here's what I use to remap the caps lock key to ctrl and the left-ctrl to capslock on a win2k machine:
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode
Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,3A,00,1D,00,1D,00,3A,00,00,00,00,00
This is a little cleaner than the example at the sysinternals site. It's a combo
of the original information in the tip plus info that I found at the following
MS site:
http://www.microsoft.com/HWDEV/input/W2kscan-map.htm
note that their scan key maps are a little off.
-- Juan
Jim_Crockett@go.com, August 21, 2001 11:16
http://www.vim.org/tips/tip.php?tip_id=75 (2 of 3) [18/02/2004 14:43:08]

Tip #75 - Remap CAPSLOCK key in Windows 2000 Professional and NT4.0 : vim online

Personally, I just hit ctrl-[ (that's holding the control key and the left angle
bracket down at the same time), which creates the escape key almost
anywhere. I'm so used to touch typing it I don't even think about it any more.
niczero@yahoo.com, August 15, 2002 9:31
Having such a large part of my UI for functionality as obscure as capslock is
strange indeed.
My ideal setup would be to have <CapsLock> do nothing at all so accidental hits
don't mess
up my blind typing, and to have it effective if I'm also holding down <Shift>
(for those rare
occasions when I feel like SHOUTING).
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=75 (3 of 3) [18/02/2004 14:43:08]

SourceForge
Logo

Tip #76 - Folding for Quickfix : vim online

not logged in (login)

Home
Search

Tip #76: Folding for Quickfix


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/3, Viewed by 1427

created: June 8, 2001 5:27


author: Mark A. Hillebrand

complexity: intermediate
as of Vim: 6.0

The Quickfix mode aims to "speed up the edit-compileedit cycle" according to ':help quickfix'. After
executing ':make' or ':grep' it is possible to skim
through the list of errors/matches and the appropriate
source code locations with, for instance, the ':cnext'
command.
Another way to get a quick overview is to use VIMs
folding mode, to fold away all the error-free/match-free
regions.
The script at the end of this message can be used for
this purpose. It is at the moment not elaborate enough
to put it up as a 'script'; but it might give someone
inspiration to do so.
Big restrictions / bugs are as follows:
1. Vim Perl interface is required, i.e. the output of
':version' must contain '+perl' (People with Vim
scripting knowledge might fix this)
2. Works only for one file, i.e. the current buffer.
3. It's a quick hack.
Sample usage: (a) edit a file, (b) do ':grep regexp %'
to get a quickfix error list and (c) ':source
foldqf.vim' will fold as described
Increasing the value of $CONTEXT gives you more context
around the error regions.
Here comes it, it should be 7 lines:
---foldqf.vim
cwindow
perl $CONTEXT = 0;
perl @A = map { m/\|(\d+)\|/; $1 +0 } $curbuf>Get(1..$curbuf->Count());
close
normal zD
perl sub fold { VIM::DoCommand( $_[0] . ',' . ($_[1]) .
"fold" ) if( $_[0] < $_[1] ); }
perl $last = 0; for (@A) { fold( $last+1+$CONTEXT, $_-1$CONTEXT ); $last = $_; }; VIM::DoCommand(($A[-

http://www.vim.org/tips/tip.php?tip_id=76 (1 of 2) [18/02/2004 14:43:10]

Tip #76 - Folding for Quickfix : vim online

1]+1+$CONTEXT ) . ',$fold' );
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Remap CAPSLOCK key in Windows 2000 Professional and NT4.0 | Displaying search results using
folds >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=76 (2 of 2) [18/02/2004 14:43:10]

SourceForge
Logo

Tip #77 - Displaying search results using folds : vim online

not logged in (login)

Home
Search

Tip #77: Displaying search results using folds


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 18/9, Viewed by 1660

created: June 11, 2001 15:33


author: Peter Bismuti

complexity: intermediate
as of Vim: 6.0

A guy I work with told me about a function that an old


IBM text editor had that he said was useful, and that is
to create folds in the file after a search such that
every line that is visible contains the search
pattern(except possibly the first). All lines that do
not contain the search pattern are folded up to the last
occurence of the pattern or the top of the file.
One use for such a function is to be able to make a
quick and dirty api of a source file. For example, if
working in Java, you could run the function using the
pattern "public|protected|private" and ithe results
would be that only the method headers would be visible
(well, close enough).
function! Foldsearch(search)
normal zE
"erase all folds to begin
with
normal G$
"move to the end of the file
let folded = 0
"flag to set when a fold is found
let flags = "w"
"allow wrapping in the search
let line1 = 0
"set marker for beginning of
fold
while search(a:search, flags) > 0
let line2 = line(".")
"echo "pattern found at line # " line2
if (line2 -1 > line1)
"echo line1 . ":" . (line2-1)
"echo "A fold goes here."
execute ":" . line1 . "," .
(line2-1) . "fold"
let folded = 1
"at least one fold has been found
endif
let line1 = line2
"update marker
let flags = "W"
"turn off wrapping
endwhile

http://www.vim.org/tips/tip.php?tip_id=77 (1 of 3) [18/02/2004 14:43:12]

Tip #77 - Displaying search results using folds : vim online

" Now create the last fold which goes to the end of the
file.
normal $G
let line2 = line(".")
"echo "end of file found at line # " line2
if (line2 > line1 && folded == 1)
"echo line1 . ":" . line2
"echo "A fold goes here."
execute ":". line1 . "," . line2 .
"fold"
endif
endfunction
" Command is executed as ':Fs pattern'"
command! -nargs=+ -complete=command Fs call
Foldsearch(<q-args>)
" View the methods and variables in a java source file."
command! Japi Fs public\|protected\|private

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Folding for Quickfix | rotating mail signatures >>

Additional Notes
bismuti@cs.fsu.edu, June 11, 2001 15:38
The comments I added broke the script, just delete
before trying to run.
bismuti@cs.fsu.edu, June 11, 2001 15:41
This pattern works better to create a Java API, it
enforces white space
at the end of the word.
public\s\|protected\s\|private\s
igor@tyumbit.ru, June 20, 2001 21:18
If foldmethod=syntax then VIM complains " E352: Cannot
erase folds with current 'foldmethod' "
Need to check if foldmethod = syntax then normal zR
cz_butler@yahoo,com, June 16, 2002 20:50

http://www.vim.org/tips/tip.php?tip_id=77 (2 of 3) [18/02/2004 14:43:12]

Tip #77 - Displaying search results using folds : vim online

The original commands were something like


x all
s string
Every line with "string" was displayed, the rest were
folded.
I'm new to folding, but I placed the following in my
vimrc
set foldexpr=getline(v:lnum1)!~@/&&getline(v:lnum)!~@/&&getline(v:lnum+1)!~@/
map \z :set foldmethod=expr foldcolumn=2 foldlevel=0
The foldexpr uses @/ (the last search pattern)
The lnum-1,lnum+1 makes line before/after visible
(context)
To invoke /string/, then \z - can it be any easier?
erichbox@yahoo.com, July 21, 2002 11:23
This kind of expression based folding is very similar
to XEDITs HIDE macro--with an important
difference. HIDE would temporarily "remove" all lines
containing /string/ from the buffer. You could then
edit the file as if these lines were truly gone, and
SHOW ALL to replace the HIDden lines at their original
locations. This was true horizontal slicing.
Is there a way to fold up text in this manner and then
make a vertical slice through the text (for instance:
<C-v>jjjjI"inserted text"<esc> ) that does *not* affect
the folded text? Can buffers be employed to this end
somehow?
kgergely@mcl.dontspam.hu, August 21, 2002 9:05
What I need is to leave some lines around matches. Is
it possible?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=77 (3 of 3) [18/02/2004 14:43:12]

SourceForge
Logo

Tip #78 - rotating mail signatures : vim online

not logged in (login)

Home
Search

Tip #78: rotating mail signatures


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/4, Viewed by 998

created: June 12, 2001 13:36


author: Roel Vanhout

complexity: intermediate
as of Vim: 5.7

For people using mutt and vim for mail, the following
script will allow you to insert a new signature (and
again and again if you don't like the current one) at
the bottom of your mail. This is usefull eg when you
don't want to send a potentially offensive quote to
someone you don't know very well (or a mailing list),
but are too lazy to delete the quote, open your quotes
file, and cut and paste another one in. (I put it here
in 'tips' and not in 'scripts' because it is imo too
short to be a 'real' script)
" rotate_sig.vim
" Maintainer: Roel Vanhout <roel@2e-systems.com>
" Version:
0.1
" Last Change: Tuesday, June 12, 2001
" Mapping I use:
" nmap ,r :call RotateSig()<CR>
" Usage:
" -Make sure you delimit your sig with '-- ', or adjust
the script
" -Adjust the last execute to a command that prints a
sig to stdout
" Known problems:
"
- You'll get an error message when you're below the
last
"
'^-- $' in your mail (nothing bad though - just an
not"
found marker)
function! RotateSig()
normal mQG
execute '?^-- $'
execute ':nohl'
normal o<ESC>
normal dG
normal <CR>
execute 'r !~/bin/autosig ~/.quotes \%'

http://www.vim.org/tips/tip.php?tip_id=78 (1 of 2) [18/02/2004 14:43:15]

Tip #78 - rotating mail signatures : vim online

normal `Q
endfunction

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Displaying search results using folds | How to use :grep to get a clickable list of function names >>

Additional Notes
roel@2e-systems.com, June 13, 2001 0:55
...and ofcourse, tonight I had an idea that this could
be done better & shorter:
:nmap ,t mQG:?^-- $<CR>:nohl<CR>o<ESC>dG:r
!~/bin/autosig ~/.quotes \%<CR>`Q
heh :-)
harri.haataja@cs.helsinki.fi, May 7, 2002 8:34
Mutt has an extensive hooks system that allows things
like this.
set signature="fortune $HOME/.fortunes/other
$HOME/.fortunes/computer |"
send-hook
'~t @networksolutions' 'unset
signature'
send-hook
'~t @orkplace'
'set
signature=~/.signature_official'
etc.
Now what I'd like to see is a thing that does a light
keyword analysis on the message and select an
appropriate quote emulating an extremely kind
sigmonster :-)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=78 (2 of 2) [18/02/2004 14:43:15]

SourceForge
Logo

Tip #79 - How to use :grep to get a clickable list of function names : vim online

not logged in (login)

Home
Search

Tip #79: How to use :grep to get a clickable list of function names
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 43/17, Viewed by 3378

created: June 14, 2001 2:13


author: Flemming Madsen

complexity: basic
as of Vim: 6.0

The following function will make a :cwindow window with


a line per function
in the current C source file. NOTE: It writes the file
as a side effect.
Invoke with ':call ShowFunc()'
You may want to do :nmap <somekey> :call ShowFunc()<CR>
function! ShowFunc()
let gf_s = &grepformat
let gp_s = &grepprg
let &grepformat = '%*\k%*\sfunction%*\s%l%*\s%f
%*\s%m'
let &grepprg = 'ctags -x --c-types=f --sort=no -o -'
write
silent! grep %
cwindow
let &grepformat = gf_s
let &grepprg = gp_s
endfunc
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<rotating mail signatures | Restore cursor to file position in previous editing session >>

Additional Notes
tim@johnsons-web.com, June 14, 2001 9:11

http://www.vim.org/tips/tip.php?tip_id=79 (1 of 6) [18/02/2004 14:43:18]

Tip #79 - How to use :grep to get a clickable list of function names : vim online

When I try this from a .c source file:


I get the following error message:
Error detected while processing function ShowFunc:
Regular expressions can't be delimited by letters
Not an editor command:
cwindow
parth.malwankar@usa.net, June 15, 2001 6:38
I guess this works only with vim 6.0 so cwindow isnt
recognized in the above node.
This is a really useful functions. But somehow when I
use it on a file opened using explorer.vim it doesnt
work as expected. It does list the functions in cwindow
but somehow the links dont work. Does anyone know how
to fix this.
It the file is opened normally using :e then things
work just fine. Very useful, especially with big files.
Thanks.
Parth
Flemming, June 18, 2001 0:14
Some enhancements courtesy of Bill McCarthy:
>
let &grepprg = 'ctags -x --c-types=f --sort=no -o
-'
or just: let &grepprg = 'ctags -x --c-types=f -sort=no'
since the '-o -' is redundant with '-x'.
>
write
or better yet: update
which will not change the filedate on a file that
hasn't changed.
leifw at bigfoot , com, July 19, 2001 11:16
I'd suggest that the call to write or update (as noted
in the note above) be changed to:
if (&readonly == 0) | update | endif
so that you don't get an error message when attempting
this on a read only file.
feline3344@yahoo.com, September 10, 2001 3:38

http://www.vim.org/tips/tip.php?tip_id=79 (2 of 6) [18/02/2004 14:43:18]

Tip #79 - How to use :grep to get a clickable list of function names : vim online

for some reason this failes in vim6.0au under unix with


file names longer than about 14 characters. however,
if you change
let &grepformat = '%*\k%*\sfunction%*\s%l%*\s%f
%*\s%m'
to
let &grepformat = '%*\k%*\sfunction%*\s%l%*\s%f %m'
then it works fine regardless of file name length.
running on a terminal, if there are a lot of functions
in a file then the screen tends to get messed up, which
can be fixed by insering a call to redraw after the
cwindow call, so you get:
silent! grep %
cwindow
redraw
let &grepformat = gf_s
supergrass@gmx.net, February 9, 2002 4:50
WOW! this is absolutely kewl!! thx!!
davev@ziplip.com, February 25, 2002 20:07
Ok, after installing Exuberant Ctags
(ctags.sourceforge.net), and tweaking it a little
while, this version of the function works with C, Perl,
PHP, Python, Shell and Vim filetypes.
if !exists("*ShowFunc")
function! ShowFunc()
let gf_s = &grepformat
let gp_s = &grepprg
if ( &filetype == "c" )
let &grepformat='%*\k%*\sfunction%*\s%l%*\s%f %m'
let &grepprg = 'ctags -x --c-types=f --sort=no'
elseif ( &filetype == "perl" )
let &grepformat='%*\k%*\ssubroutine%*\s%l%*\s%f
%m'
let &grepprg = 'ctags -x --perl-types=s -sort=no'
elseif ( &filetype == "php" )
let &grepformat='%*\k%*\sfunction%*\s%l%*\s%f %m'
let &grepprg = 'ctags -x --php-types=f --sort=no'
elseif ( &filetype == "python" )
let &grepformat='%*\k%*\sfunction%*\s%l%*\s%f %m'
let &grepprg = 'ctags -x --python-types=f -sort=no'
elseif ( &filetype == "sh" )
let &grepformat='%*\k%*\sfunction%*\s%l%*\s%f %m'
http://www.vim.org/tips/tip.php?tip_id=79 (3 of 6) [18/02/2004 14:43:18]

Tip #79 - How to use :grep to get a clickable list of function names : vim online

let &grepprg = 'ctags -x --sh-types=f --sort=no'


elseif ( &filetype == "vim" )
let &grepformat='%*\k%*\sfunction!%*\s%l%*\s%f
%m'
let &grepprg = 'ctags -x --vim-types=f --sort=no'
endif
if (&readonly == 0) | update | endif
silent! grep %
cwindow
redraw
let &grepformat = gf_s
let &grepprg = gp_s
endfunc
endif
Dave V.
kkm9@cornell.edu, March 7, 2002 6:22
It doesn't seem to work or do anything at all for me.
Anyone have any ideas?
davev@ziplip.com, March 16, 2002 19:56
Ok, couple of small bugs and mistakes fixed.
version:

Try this

function! ShowFunc(sort)
let gf_s = &grepformat
let gp_s = &grepprg
if ( &filetype == "c" || &filetype == "php" ||
&filetype == "python" ||
\ &filetype == "sh" )
let &grepformat='%*\k%*\sfunction%*\s%l%*\s%f %m'
let &grepprg = 'ctags -x --'.&filetype.'-types=f -sort='.a:sort
elseif ( &filetype == "perl" )
let &grepformat='%*\k%*\ssubroutine%*\s%l%*\s%f %m'
let &grepprg = 'ctags -x --perl-types=s -sort='.a:sort
elseif ( &filetype == "vim" )
let &grepformat='%*\k%*\sfunction%*\s%l%*\s%f %m'
let &grepprg = 'ctags -x --vim-types=f --languageforce=vim --sort='.a:sort
endif
if (&readonly == 0) | update | endif
silent! grep %
cwindow 10
redraw
let &grepformat = gf_s
http://www.vim.org/tips/tip.php?tip_id=79 (4 of 6) [18/02/2004 14:43:18]

Tip #79 - How to use :grep to get a clickable list of function names : vim online

let &grepprg = gp_s


endfunc
I map this function to F3 to produce a list in the
order the functions appear in the file or Shift-F3 to
list them in alphabetical order.
noremap <F3>
<ESC>:call ShowFunc("no")<CR><ESC>
noremap <S-F3> <ESC>:call ShowFunc("yes")<CR><ESC>
And last be sure you have Exuberant CTags installed or
it won't work.
Dave V.
himanshu_patel@hotmail.com, April 17, 2002 6:08
I am using vim 6.1 on Unix, it's seems like not working
at all. When I do F3 or Shift F3, VIM screen refreshes
but nothing else
Himanshu
davev@ziplip.com, April 27, 2002 21:34
Do you have filetype detection enabled?
If not, add "filetype on" to your .vimrc.
Dave V.
bmonnahan@subdimension.com, July 19, 2002 0:21
This is really cool! Is there any chance someone could
add a java case as well. I don't really understand
whats happening here but adding it to the c et al case
doesn't work.
davev@ziplip.com, August 3, 2002 21:50
Try this:
elseif ( &filetype == "java" )
let &grepformat='%*\k%*\sclass%*\s%l%*\s%f %m'
let &grepprg = 'ctags -x --java-types=c -sort='.a:sort
If this produces blank results, then you can try
changing the last line to:
let &grepprg = 'ctags -x --java-types=c --languageforce=java --sort='.a:sort
Good luck,
Dave

http://www.vim.org/tips/tip.php?tip_id=79 (5 of 6) [18/02/2004 14:43:18]

Tip #79 - How to use :grep to get a clickable list of function names : vim online

davev@ziplip.com, August 24, 2002 16:57


I increased the number of file types supported to 19.
You can now search for
1. Classes - Java
2. Functions - Awk, C, C++, Fortran, Lisp, Pascal, PHP,
Python, Ruby, Shell Scripts, Scheme, Slang, and Vim
3. Macros - Makefiles
4. Procedures - Expect, and Tcl
5. Subroutines - Perl and Rexx
C, Shell Scripts, Vim, Expect, Tcl and Perl are well
tested. The rest work on the few tests that I have
given them. Let me know of any bugs and I'll work them
out.
Additionally, I changed it so that it opens a
dynamically sized cwindow based on the height of the
window it was called from and/or the number of links in
the results. An empty search returns a cwindow a
single line tall.
Last, I packaged this function as a script (vimscript
#397) to make it easier to install, and to get it out
of my vimrc file.
Dave Vehrs
montagne@boora.com, August 27, 2002 8:17
I installed the exuberant-ctags deb file from unstable
(after having the same error from testing) and all I
get is this error:
ctags: unrecognized option `--c-types=f'
It seems the problem is with ctags but it also seems to
be version 5.3 and I can see that line referenced as an
example in the man page.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=79 (6 of 6) [18/02/2004 14:43:18]

SourceForge
Logo

Tip #80 - Restore cursor to file position in previous editing session : vim online

not logged in (login)

Home
Search

Tip #80: Restore cursor to file position in previous editing session


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 112/39, Viewed by 2145

created: June 15, 2001 6:47


author: Charles E Campbell

complexity: intermediate
as of Vim: 6.0

Here's something for your <.vimrc> which will allow you to


restore your cursor position in a file over several editing
sessions. This technique uses the viminfo option:
Ex. set viminfo='10,\"100,:20,%,n~/.viminfo
au BufReadPost * if line("'\"") > 0|if line("'\"") <=
line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
If you're on Unix, the viminfo is probably fine as is (but check
up on Vim's help for viminfo to see if you like the settings
above). For Windows you'll need to change the "n" suboption to
something like
Ex. set
viminfo='10,\"100,:20,%,nc:\\some\\place\\under\\Windoz\\_viminfo
This tip is a somewhat improved version of the example given for
:he line()
in the Vim on-line documentation.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<How to use :grep to get a clickable list of function names | Substitution of characters and lines in VIM is made far
easier with the s and S commands >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=80 [18/02/2004 14:43:20]

SourceForge
Logo

Tip #81 - Substitution of characters and lines in VIM is made far easier with the s and S commands : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #81: Substitution of characters and lines in VIM is made far


easier with the s and S commands
tip karma

Rating 20/24, Viewed by 1865

created: June 21, 2001 14:41


author: Substitue characters and lines

complexity: basic
as of Vim: 5.7

Substitute Characters
----------------------------------I was just editing a file that contained the same
leading string on many lines.
example:
foo_bar_baz1=a
foo_bar_baz1=abc674
foo_bar_baz1=qrs
foo_bar_baz1=m1
foo_bar_baz1=bz90
foo_bar_baz1=bc
...
Needing to only substitute a portion of the string, I
referred to a VIM reference card and discovered a
command answering my need exactly. The s command is used
to subsitute a certain number of characters. In my
example file above, if I only needed to subsititute the
characters foo_bar, I set the cursor on the first
character where I'd like the subsitution to begin and
type 7s. VIM drops the characters foo_bar and goes to
insert mode, waiting for the substitution text.
Substitute Lines
----------------------After years of using vi and VIM and always deleting
multiple lines in order to replace them, I just
discovered the S command. If you need to subsitute three
lines of text, simply type 3S. VIM drops the three lines
and goes into insert mode, waiting for the subsitution
text.
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=81 (1 of 2) [18/02/2004 14:43:26]

Helpful

Unfulfilling

rate

Tip #81 - Substitution of characters and lines in VIM is made far easier with the s and S commands : vim online

<<Restore cursor to file position in previous editing session | letting variable values be overwritten in a
script >>

Additional Notes
leifw at bigfoot dot com, July 11, 2001 14:12
Of course, if you're lazy like me and you don't want to
count that there are 7 characters that you want to
replace, you could use the c command and use a motion
to specify how much to kill. For example, in the
previous example, I'd type c2t_ to kill foo_bar and to
be left in insert mode.
bdr at users.sourceforge.net, August 29, 2001 8:11
You could have selected the "foo_bar" characters with
Ctrl+V (Visual Block), pressed "c" to change the block,
made your change to the first line, press ESC and,
voil, all the lines you selected will be changed the
same way.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=81 (2 of 2) [18/02/2004 14:43:26]

SourceForge
Logo

Tip #82 - letting variable values be overwritten in a script : vim online

not logged in (login)

Home
Search

Tip #82: letting variable values be overwritten in a script


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/1, Viewed by 935

created: June 22, 2001 9:11


author: Salman Halim

complexity: basic
as of Vim: 6.0

this is a simple function i wrote to get the value of a


variable from three different places (in that
order): the current buffer, the global setting or from
the script itself.
this allows me to set a default value for a
configuration variable inside my script and the user to
change it on a global level by setting the same variable
with a g: prepended. then, they can further set it on a
per-buffer level by the the b: mechanism. one of the
examples for this might be my comments script (not
uploaded). i have a variable in there that determines
whether comment characters (// for java, for example)
are placed the beginning of the line or just before the
first-non-blanks in the text. i set up a default in my
script:
let s:comments_hug_start_of_line=0
hug the text

" comments should

that's fine as a default, but if i want to overwrite it


for vim scripts, i just put the following in my
ftplugin/vim.vim:
let b:comments_hug_start_of_line=1
should hug the first column, always

" vim comments

" tries to return the buffer-specific value of a


variable; if not
" found, tries to return the global value -if that's not found
" either, returns the value set in the script itself
function! GetVar(varName)
if (exists ("b:" . a:varName))
exe "let retVal=b:" . a:varName
elseif (exists ("g:" . a:varName))
exe "let retVal=g:" . a:varName
elseif (exists ("s:" . a:varName))
http://www.vim.org/tips/tip.php?tip_id=82 (1 of 3) [18/02/2004 14:43:28]

Tip #82 - letting variable values be overwritten in a script : vim online

exe "let retVal=s:" . a:varName


else
retVal=-1
endif
return retVal
endfunction
personally, i never let it get to the -1 state by always
having an s: set with SOME default value.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Substitution of characters and lines in VIM is made far easier with the s and S commands | how to
indent (useful for source code) >>

Additional Notes
salmanhalim@hotmail.com, June 22, 2001 9:19
it seems as if the s: bit only works if the function is
defined as part of a script (using the s:GetVar)
notation (this is how i had it initially before
deciding it might be useful in general).
my apologies for the premature post.
salman.
salmanhalim@hotmail.com, July 18, 2001 13:51
i tweaked GetVar to no longer look for a script
variable (since i couldn't get it to work
anyway). instead, i have added an optional second
parameter which becomes the value returned if neither a
buffer or a global variable is found -- -1 is still
returned if the second parameter is unspecified:
function! GetVar(...)
let varName=a:1
if (exists("a:2"))
let retVal=a:2
else
let retVal=-1
endif
if (exists ("b:" . varName))
exe "let retVal=b:" . varName
elseif (exists ("g:" . varName))
http://www.vim.org/tips/tip.php?tip_id=82 (2 of 3) [18/02/2004 14:43:28]

Tip #82 - letting variable values be overwritten in a script : vim online

exe "let retVal=g:" . varName


endif
return retVal
endfunction
so, to specify the default scope for java bean
properties (used inside javabean.vim, though i chose
not to put this mechanism in there to avoid the
dependency on this function), i just use
GetVar("javabean_scope", "protected"). if there is a
buffer or global variable set, it uses that; otherwise,
it defaults to protected scope.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=82 (3 of 3) [18/02/2004 14:43:28]

SourceForge
Logo

Tip #83 - how to indent (useful for source code) : vim online

not logged in (login)

Home
Search

Tip #83: how to indent (useful for source code)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 502/183, Viewed by 11708

created: June 22, 2001 14:51


author: Eugene Huang

complexity: basic
as of Vim: 5.7

Here is the most useful vim command that I know of and


I'm surprised that it's not yet in the tips list.
I use the indent features of vim all the time.
Basically, it lets you indent your source code.
SETUP: To make indentation work nicely I have the
following in my .vimrc file:
set et
set sw=4
set smarttab
these make vim behave nicely when indenting, giving 4
spaces (not tabs) for each "tabstop".
HOW TO USE:
in command mode, == will indent the current line
selecting a range of lines (with shift-v) then == will
indent your selection
typing a number then == will indent that many lines,
starting from your cursor
(you get the idea, there are many other things you can
do to select a range of lines)
Tell me that isn't great?
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<letting variable values be overwritten in a script | Changing the behaviour of . to include visual mode
>>

Additional Notes
Debian@austin dot rr dot com, June 26, 2001 16:51

http://www.vim.org/tips/tip.php?tip_id=83 (1 of 5) [18/02/2004 14:43:31]

Tip #83 - how to indent (useful for source code) : vim online

The "=" command operates on lines ranges in the same


way as "d", "y", ">". This duplicates the
functionality of typing your code in the first place
after using the ":set autoindent" command. HOWEVER, it
is far preferrable to use ":set noexpandtab tabstop=4
shiftwidth=4" rather than ":set expandtab" since it
gives others editing the same code the options of
setting the indentation level to 2, 3, 5, 8, ... per
personal taste rather than forcing everyone to live
with your particular choice. If you prefer your cursor
motion to behave as if tabs were actually spaces you
can use the virtual edit mode instead. Fortunately the
"=" command will allow you to reformat code to include
proper tab formatting if someone has made the mistake
of using ":set expandtab".
roel@stack.be, June 28, 2001 0:39
Not to get into a holy way about tabs vs spaces to
indent, but I think it's a bit blunt to say 'if someone
made the mistake to set :expandtab'. Please read
http://www.jwz.org/doc/tabs-vs-spaces.html for a whole
discussion on why spaces are better.
jason@katzbrown.com, July 14, 2001 18:07
Well...
Go tabs!
http://derkarl.org/why_to_tabs.html !!!

rah! :))
soren.edzen@frontec.se, July 24, 2001 6:14
How do you unindent?
--se
eugenehuang @ canada.com, July 24, 2001 18:33

http://www.vim.org/tips/tip.php?tip_id=83 (2 of 5) [18/02/2004 14:43:31]

Tip #83 - how to indent (useful for source code) : vim online

To unindent you can do this:


Select (in any way you choose) the lines you want to
unindent, and then
type <<. You can do this repeatedly until everything is
unindented.
(Also >> indents manually one tab stop)
Hope that helps.
Eug
slow@cscience.org, August 8, 2001 8:31
To indent all your code, you can type 'gg=G'; 'gg' to
go to the top of the file and '=G' to indent from the
current line to the last. 'G=gg' also works...
benoit.cerrina@writeme.com, September 25, 2001 1:22
to indent the whole file without having the cursor move
to the beginning or the end I have the following
function and mapping:
fun BenIndent()
let oldLine=line('.')
normal(gg=G)
execute ':' . oldLine
endfun
map -- :call BenIndent()<cr>
just hit -- (conveniently close to ==) in normal mode
to indent the whole file
mbrubeck@cs.hmc.edu, December 10, 2001 14:24
Vim 6.0 has a new "flexible indenting" feature so that
indenting works in many different programming languages
and filetypes. To turn it on automatically for builtin filetypes, just add:
filetype indent on
to your vimrc. See ":help new-indent-flex" and ":help
indentexpr" for more details.
vihar_rai@agilent.com, May 14, 2002 18:18

http://www.vim.org/tips/tip.php?tip_id=83 (3 of 5) [18/02/2004 14:43:31]

Tip #83 - how to indent (useful for source code) : vim online

You can use pretty much any selection method for indent
"="
1. To indent within braces do " =%"
2. To indent a block
select the beginning of the block by placing a
bookmark
e.g.
" ma" where a is the name of the
buffer (any character)
scroll to the end of the block and do " ='a "
3. multiple lines
"n==" where n is the number of lines
michael.wardle@adacel.com, May 16, 2002 19:54
It is possible to add a line to a source file that says
how Emacs should display a file such as:
/* -*- Mode: C; tab-width:8 -*- */
Is this possible in vi/vim (and if so, then how?)?
michael.wardle@adacel.com, May 20, 2002 0:39
It seems possible by adding this near the top:
ex: set (options):
So to set tabstops to 8 spaces in a C source file, you
would do something like this:
/* ex: set ts=8: */
On my system, this causes vim to automatically use this
option as if it were specified
in my .vimrc, but you may also need to do ":set
modeline" for your editor to look for
these options in the source file.
ser at germane dash software dot com, September 8, 2002 18:18
All of these diverse ways of doing the same
thing. That is very cool.
Another way of cleaning the indentation of the entire
file:
:%=
seanahern@llnl.gov, June 20, 2003 21:25

http://www.vim.org/tips/tip.php?tip_id=83 (4 of 5) [18/02/2004 14:43:31]

Tip #83 - how to indent (useful for source code) : vim online

I have to put in a plug for a script someone submitted


that helps with the whole tabs/spaces indenting thing.
http://www.vim.org/scripts/script.php?script_id=513
Upon loading a buffer, a python script looks through
the file, determines what indent style was used, then
adjusts your settings so that new modifications use
that same style.
Pretty cool!
jko@mdsi.ca, October 10, 2003 13:49
This isn't great. This is fantastic! I've been trying
to get this done for a while now to better indent some
older code that has a mix of tabs and spaces and is
inconsistent in the indentlevel.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=83 (5 of 5) [18/02/2004 14:43:31]

SourceForge
Logo

Tip #84 - Changing the behaviour of . to include visual mode : vim online

not logged in (login)

Home
Search

Tip #84: Changing the behaviour of . to include visual mode


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 47/20, Viewed by 1564

created: June 29, 2001 14:21


author: Salman Halim

complexity: basic
as of Vim: 5.7

one of the things i do a lot in vim is to make a change


to the beginning
or end of the line (such as adding the text '//
remove' at the end of
java debug code). a quick way of doing this is to use
a to append the
text to the end of the first line and then move down
one, hit . (repeat
last edit), move down, hit . etc. etc. the following
mapping allows one
to simply highlight the region in question
and hit . -- it will
automatically execute the . once on each line:
" allow the . to execute once for each line of a
visual selection
vnoremap . :normal .<CR>
another thing i do a lot is to record a quick macro in
the "a" register
and then play it back a number of times. while @@ can
be used to repeat
the last register used, my recorded macros sometimes use
other registers
so @@ doesn't necessarily give me the same results
as @a. also, i have
mapped ' to ` because i like to go to the
precise location of my marks
-- always -- and never to the beginning of the line.
this leaves my `
key unused. so:
" make ` execute the contents of the a register
nnoremap ` @a
then, in keeping with the visual . above, i did the same
for the ` -- is
thexecutes @a once on each highlighed line.

http://www.vim.org/tips/tip.php?tip_id=84 (1 of 3) [18/02/2004 14:43:33]

Tip #84 - Changing the behaviour of . to include visual mode : vim online

vnoremap ` :normal @a<CR>


as an example, say i have the following lines of java
code:
public String m_asdf;
public String m_lkhj;
public int m_hjkhjkh;
and, for some reason, i need to get the following:
"asdf"
"lkhj"
"hjkhjkh"
i record the following into a:
^cf_"<ESC>$r"
the ^ is because my java code is indented and
i don't want to go to
column 0 and the <esc> is an actual escape i hit to exit
insert mode.
then, i simply select (visually) the other lines (only
two in case -admittedly not an overly useful example) and just hit `.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<how to indent (useful for source code) | How to mimic the vim 6.0 plugin feature with older versions
>>

Additional Notes
fatty@aol.com, July 10, 2001 20:32
Wow!

Is this guy good or what?!

salmanhalim@hotmail.com, July 18, 2001 13:52


i found that a few plugin scripts that i use regularly
depended on ` having default functionality, so i
switched the ` key to ~ for my use (i couldn't be
bothered to change all the scripts to use noremap
instead of just map).
salmanhalim@hotmail.com, July 22, 2001 9:24

http://www.vim.org/tips/tip.php?tip_id=84 (2 of 3) [18/02/2004 14:43:33]

Tip #84 - Changing the behaviour of . to include visual mode : vim online

as a side note, i have the following mapping in my


vimrc:
noremap v ~
since i find the v easier to hit than the tilde anyway - and i don't have any plugins that fiddle about with
the case of my text so i don't break anything this way.
kgergely@mcl.hu, January 8, 2002 7:53
If action is just inserting at a given column, also see
vimtip #194
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=84 (3 of 3) [18/02/2004 14:43:33]

SourceForge
Logo

Tip #85 - How to mimic the vim 6.0 plugin feature with older versions : vim online

not logged in (login)

Home
Search

Tip #85: How to mimic the vim 6.0 plugin feature with older versions
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/4, Viewed by 854

created: July 5, 2001 17:20


author: bubbleboy

complexity: intermediate
as of Vim: 5.7

If you do not have vim 6.0, but would like to mimic the
plugins directory feature then copy and paste this into
your vimrc:
exec "source " . substitute(glob($VIM."/plugins/*.vim"),
"\n", "\nsource ", "g")
It will automatically source every vim script file
located in the vim/plugins directory.
Now, to add a new plugin, just drop the script in this
directory and vim will automatically find it.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Changing the behaviour of . to include visual mode | Helps undo 1 line when entered many >>

Additional Notes
mankin@yahoo.no.com.spam, July 8, 2001 10:15
Does anybody know how to have vim look in your home
directory for the plugins directory?
-David Mankin
Anonymous, August 14, 2001 9:35
Use $HOME, or ~ (tilde), instead of $VIM. If you use
tilde, it must be inside the quotes. The $VIM (or
$HOME) may be placed inside the quotes as well glob("$VIM/plugins/*.vim") works just fine.
Add Note

http://www.vim.org/tips/tip.php?tip_id=85 (1 of 2) [18/02/2004 14:43:35]

Tip #85 - How to mimic the vim 6.0 plugin feature with older versions : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=85 (2 of 2) [18/02/2004 14:43:35]

SourceForge
Logo

Tip #86 - Helps undo 1 line when entered many : vim online

not logged in (login)

Home
Search

Tip #86: Helps undo 1 line when entered many


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/6, Viewed by 674

created: July 9, 2001 9:38


author: Stepan Koltsov

complexity: basic
as of Vim: 5.7

When U entered text, U cannot undo only 1 line, for


example, when U press "u", all entered in last "insert"
text removed.
If U add this line to .vimrc:
inoremap <Return> <Return>^O^[
where "^O" or "^[" is 1 char
"u" will undo (remove) only 1 line.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<How to mimic the vim 6.0 plugin feature with older versions | Get vim 5.x window in vim 6.x >>

Additional Notes
rnd@softhome.net, July 9, 2001 14:26
nice tip. but U definitely should improve your English
:)
yozh@mx1.ru, July 13, 2001 11:17
Thanks for advice (about English :) Anywhen I'll learn
it :)
I saw 1 bug of this tip: autoindent don't work. How to
correct this?
Yozh.
yozh@mx1.ru, July 13, 2001 11:22

http://www.vim.org/tips/tip.php?tip_id=86 (1 of 2) [18/02/2004 14:43:37]

Tip #86 - Helps undo 1 line when entered many : vim online

Sorry my English again :)


First idea -- write:
:inoremap <return> <return>a^Ox
it works, but it looks not nice :(
I know vim too bad...
Yozh.
kgergely@mcl.hu, January 9, 2002 6:36
And Yozh solution is not causes a beep
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=86 (2 of 2) [18/02/2004 14:43:37]

SourceForge
Logo

Tip #87 - Get vim 5.x window in vim 6.x : vim online

not logged in (login)

Home
Search

Tip #87: Get vim 5.x window in vim 6.x


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 6/3, Viewed by 806

created: July 14, 2001 18:35


author: Leif Wickland (leifw at bigfoot , com)

complexity: basic
as of Vim: 6.0

The format of the window title in vim 5.x (well, at


least for 5.7,.8, for Win32) used to be VIM - <full
filename with path>. It's not in the win32 binary of
6.0an that I found. I want my old way back.
Turns out, all that it takes to get it back is
:set title titlestring=VIM\ -\ %F "make sure that the
window caption setting is turned on and set caption to
vim 5.x style
Oh, however, one thing I did like about the 6.0 style is
that it puts the word "help" in the title when the
current buffer is a help file; so, I just tacked %h to
my titlestring giving:
:set title titlestring=VIM\ -\ %F\ %h "make sure that
the window caption setting is turned on and set caption
to vim 5.x style
see also:
:he 'titlestring'
:he 'statusline'
rate this tip

"for the format for titlestring

Life Changing

Helpful

Unfulfilling

rate

<<Helps undo 1 line when entered many | How to maximize vim on entry (win32) >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=87 [18/02/2004 14:43:39]

SourceForge
Logo

Tip #88 - How to maximize vim on entry (win32) : vim online

not logged in (login)

Home
Search

Tip #88: How to maximize vim on entry (win32)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 70/28, Viewed by 1671

created: July 14, 2001 19:01


author: Leif Wickland (leifw at bigfoot , com)

complexity: basic
as of Vim: 5.7

Maybe it's just because I have far too small of a


monitor, because I can get distracted while coding if I
have other stuff on the screen, or because I starting
using vim on a console, but I definitely like my vim
window maximized. Anyway, sticking the following in
your vimrc will always maximize your vim window on
startup.
au GUIEnter * simalt ~x
:he win16-maximized

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Get vim 5.x window in vim 6.x | Get more screen real estate by hidding toolbar and/or menus >>

Additional Notes
bindu@wavell.net, November 11, 2001 13:20
In Windows, you can control this from your VIM shortcut
(and even add a keyboard shortcut that will bring up
VIM from anywhere.) Right click on your Icon select
properties and fiddle with the Run and Short cut key
entries. I use Shift-Control-Alt-V to start VIM from
anywhere. If VIM is already running this will switch to
the most recently used instance of VIM.
kbgaddis@hotmail.com, January 10, 2002 21:59
anyone know how to get this functionality to work in X
with gvim? please email me if so...
libberspam@atlaswebmail.com, February 8, 2003 11:36

http://www.vim.org/tips/tip.php?tip_id=88 (1 of 2) [18/02/2004 14:43:42]

Tip #88 - How to maximize vim on entry (win32) : vim online

i dont know how to do this from vimrc. but it is a


function of many windowmanagers, i am using windowmaker
and i minimize vim, right click on vim icon, goto
attributes, and click start maximized. i would guess
many other windowmanagers can do this same thing.
mkruszec@mops.uci.agh.edu.pl, March 17, 2003 5:42
Use for example:
start /MAX "C:\Program Files\vim\vim61\gvim.exe"
Anonymous, October 7, 2003 1:25
In the same vein, you can specific a starting window
size with:
set lines=50 columns=100
I have a 21" monitor at 1600x1200, and with a medium-tosmall font I can fit 4 gvim windows side by side at
100x50 each and still have room for IM client, music
player, etc., yet still have enough room in each window
to actually do stuff. (I'm one of those "prefers a
busy screen" freaks).
see :help winsize (which is depreciated, but the help's
still there)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=88 (2 of 2) [18/02/2004 14:43:42]

SourceForge
Logo

Tip #89 - Get more screen real estate by hidding toolbar and/or menus : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #89: Get more screen real estate by hidding toolbar and/or
menus
tip karma

Rating 45/29, Viewed by 1321

created: July 14, 2001 19:14


author: Leif Wickland (leifw at bigfoot , com)

complexity: basic
as of Vim: 5.7

I use gvim over console vim because gvim is much more


readable (under Windows). However, that doesn't mean I
want to dedicate screen space to things I'll never use
(i.e. the toolbar and the menus).
Anyway, you can give the following a try if you'd like.
set guioptions-=T "get rid of toolbar
set guioptions-=m "get rid of menu
Oh, yeah. If you decide that you don't really like
being without your the toolbar or menus, issue the
following:
set guioptions+=T "bring back toolbar
set guioptions+=m "bring back menu
see also:
:he 'guioptions
rate this tip

Life Changing

Helpful

<<How to maximize vim on entry (win32) | Encryption >>

Additional Notes
tomk@emcity.net, July 29, 2002 12:17

http://www.vim.org/tips/tip.php?tip_id=89 (1 of 2) [18/02/2004 14:43:45]

Unfulfilling

rate

Tip #89 - Get more screen real estate by hidding toolbar and/or menus : vim online

Using a key map makes this toggleable:


set guioptions-=T "get rid of toolbar
:let g:toggleTool = 0
map <silent> <S-F1> :if g:toggleTool == 1<CR>:set
guioptions-=T<CR>:let g:toggleTool = 0<CR>:else<CR>:set
guioptions+=T<CR>:let g:toggleTool = 1<CR>:endif<CR>
set guioptions-=m "get rid of menu
:let g:toggleMenu = 0
map <silent> <S-F2> :if g:toggleMenu == 1<CR>:set
guioptions-=m<CR>:let g:toggleMenu = 0<CR>:else<CR>:set
guioptions+=m<CR>:let g:toggleMenu = 1<CR>:endif<CR>
Tom Kimpton
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=89 (2 of 2) [18/02/2004 14:43:45]

SourceForge
Logo

Tip #90 - Encryption : vim online

not logged in (login)

Home
Search

Tip #90: Encryption


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 58/33, Viewed by 2007

created: July 17, 2001 2:53


author: Erhan

complexity: intermediate
as of Vim: 5.7

You can encrypt your texts by using vim.


:X prompts for an encryption key.
After writing your key, if you save your document
it will be encrypted and no one else (but you and vim)
can read your documents.
If you reopen the file, VIM will ask for the key.
If you want to disable encryption, just type
:set key=
if you forget your key you will lose your document.
So please DO NOT forget your key,
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Get more screen real estate by hidding toolbar and/or menus | Dictionary completions >>

Additional Notes
rolando@extended.de, August 6, 2001 16:02
carefull!
vim asks only ONCE for the password -- if you happen to
misstype it -- then good luck finding out what you
misstyped.
Was that fixed in newer releases?
aloah Roland
charles.e.campbell.1@gsfc.nasa.gov, August 14, 2001 8:18

http://www.vim.org/tips/tip.php?tip_id=90 (1 of 3) [18/02/2004 14:43:47]

Tip #90 - Encryption : vim online

You can also use external encryption software. I use


some autocmds with
pgp version 2.6.2 (because source is available and I'm
in the US of A).
The pgp call for writing uses PGP's "conventional"
cryptography; to use
its public key cryptography, use
pgp -fe userid
instead.
augroup PGP
au!
au BufReadPost *.pgp
au BufWritePre *.pgp
au BufWritePost *.pgp
augroup END

:%!pgp -f
:%!pgp -fc
u

jmcpherson@bigfoot.com, August 17, 2001 14:31


Be aware that Vim's encryption system is not very
strong. From the help files for Vim6.0-ar:
"The algorithm used is breakable. A 4 character key in
about one hour, a 6
character key in one day (on a Pentium 133 PC). This
requires that you know
some text that must appear in the file. An expert can
break it for any key.
When the text has been decrypted, this also means that
the key can be
revealed, and other files encrypted with the same key
can be decrypted."
Probably will keep your files safe from most hackers,
but look elsewhere (see prev. post on external
programs) if your information is extremely valuable.
erhan, April 9, 2002 6:07
the password is asked twice in 6.0 release
so it becomes a little less dangerous
furlan (AT) telocity dot com, June 15, 2002 23:39
I read somewhere that .swp files ARE NOT encrypted
....
Is this true ?
Anonymous, July 26, 2002 6:49
After I encrypt a file vim will always save it as
encrypted. How can I save it again in plane text short
of cut-and-paste to a new window?
http://www.vim.org/tips/tip.php?tip_id=90 (2 of 3) [18/02/2004 14:43:47]

Tip #90 - Encryption : vim online

Anonymous, September 22, 2002 3:57


Encrypt your document with an empty password to remove
the encryption.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=90 (3 of 3) [18/02/2004 14:43:47]

SourceForge
Logo

Tip #91 - Dictionary completions : vim online

not logged in (login)

Home
Search

Tip #91: Dictionary completions


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 126/54, Viewed by 4219

created: July 19, 2001 8:45


author: Brian Medley

complexity: basic
as of Vim: 5.7

This tip will will explain how to use the dictionary


completion facilities provided by vim. This can be
useful if you use vim to type your email, edit code,
etc.
Dictionary completion is one of many search facilites
provided by Insert mode completion. It allows the user
to get a list of keywords, based off of the current word
at the cursor. This is useful if you are typing a long
word (e.g. acknowledgeable) and don't want to finish
typing or don't remember the spelling.
To start, we must first tell vim where our dictionary is
located. This is done via the
'dictionary' option. Below is an example. Your
location may vary. See :help 'dictionary' for hints as
to where you should look.
:set dictionary-=/usr/share/dict/words
dictionary+=/usr/share/dict/words
Now, to use this list we have to enter insert mode
completion. This is done by hitting CTRL-X while in
insert mode. Next, you have to specify what you want to
complete. For dictionaries use CTRL-K. Once in this
mode the keys CTRL-N and CTRL-P will cycle through the
matches. So, to complete the word "acknowledgeable" I
would do the following in insert mode:
acknow<CTRL-X><CTRL-K><CTRL-N>
It can be cumbersome to type CTRL-X CTRL-K for many
different completions. So, vim gives us a
shortcut. While in insert mode CTRL-N and CTRL-P will
cycle through a predetermined set of completion
sources. By default, dictionary completion is not a
part of this set. This set is defined by the 'complete'
option. Therefore, we must add dictionary to this as

http://www.vim.org/tips/tip.php?tip_id=91 (1 of 4) [18/02/2004 14:43:49]

Tip #91 - Dictionary completions : vim online

shown below:
:set complete-=k complete+=k
Now, while in insert mode we can type the following to
complete our example:
acknow<CTRL-N><CTRL-N>
This shortcut may not save a whole lot of
typing. However, I find that it requires less hand
movement to only worry myself with two key combinations,
rather than 4.
I find that the completion facilites provided by vim
save me a *HUGE* amount of typing. These savings can be
realized in only a short amount of time if you are
editing some code with functions and variables that have
long names with underscores in them.
For more help:
help ins-completion
help compl-dictionary
help 'complete'
help 'dictionary'
help :set+=
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Encryption | Reducing 'doc' directory size >>

Additional Notes
mayureshk@aftek.com, January 25, 2002 0:23
thats really cool. Any idea how i can get to do the
same for Java/Perl/php/etc Key-words ? Lovely tip
though .. :)
Larry Clapp <vim@theclapp.org>, February 20, 2002 7:56

http://www.vim.org/tips/tip.php?tip_id=91 (2 of 4) [18/02/2004 14:43:49]

Tip #91 - Dictionary completions : vim online

re: above question


The syntax files often have lists of keywords. Cut 'em
out, put 'em in a separate file (sorted, one per line),
add the file to the front of your 'dictionary'
setting. (If you add it to the back of your
'dictionary' setting, you'll have to go though all the
other completions from the previous files before you
get to your language keywords. Or use "setlocal
dict=<whatever>" to set a value local to the current
buffer. Put this in your .vimrc to set dict
appropriately whenever you load *.c, *.java, etc.)
Also search the scripts section
'completion'.

for 'complete' and

amusikal@yahoo.co.uk, March 17, 2002 18:13


Many thanks for this tip. This one is a keeper!
nicolas.grosjean@dve.be, October 2, 2002 3:23
when programming I use tags on
filed:\vim\TagFolder\tags, AND I set on my gvimrc file
set dict+=d:\vim\TagFolder\tags
Very useful for completing purpose...
Nico
david_han@yahoo.com, February 25, 2003 0:35
Since windows doesn't come with word lists like linux,
I found word lists from the scowl archives
http://wordlist.sourceforge.net.
jrhines@despammed.com, August 7, 2003 9:03
Tag files can be also searched for completion by adding
"]" to the end of your "complete" setting. (e.g. "set
complete=.,w,b,u,t,i,]")
anonymous@example.com, January 20, 2004 5:30

http://www.vim.org/tips/tip.php?tip_id=91 (3 of 4) [18/02/2004 14:43:49]

Tip #91 - Dictionary completions : vim online

Very helpful.
I'm an emacs user, emacs has the same sort of thing
(via ESC-/)
I was wondering how vi does this. I was searching on vi
+ dabbrev with little success.
For anyone else doing a search, I'll add the words
'dabbrev' 'dabbrev mode' 'auto completion' 'dynamic
abbreviation'
'dynamic completion' META-/ in this post. 'dabbrev for
vi', as those were the words I was googling for.
One thing about vi that always impressed me was it's
fast startup time though. It runs a lot cleaner.
So, M-/ is ^X-I - ^X-N - ^X -P in vi. Vi does seem a
bit harder in that way, but, as far as I've seen, emacs
doesn't have the
dictionary functionality (emacs just uses M-/, after
the first time it considers additional M-/'s as VI
considers ^X-N's until you edit.)
I've been trying to learn vi so I can poke fun at vi
users properly. :-)
Well, that and so I'm not lost when the only editor in
town is /bin/vi.
<rant>
My dislike for vi started in the old days when internet
cost big $ to use ( I mean, long distance + hourly rate
+ terminal server) and.. I got dumped into vi w/out
knowing how to get out of it. Knowing ESC-:q! would
have saved me some cash. :-/ I do think editors (or at
least people who implement menu systems that dump new
users into editors) should show some place on the
status line how to exit.
</rant>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=91 (4 of 4) [18/02/2004 14:43:49]

SourceForge
Logo

Tip #92 - Reducing 'doc' directory size : vim online

not logged in (login)

Home
Search

Tip #92: Reducing 'doc' directory size


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/9, Viewed by 1087

created: July 20, 2001 3:10


author: Francis

complexity: intermediate
as of Vim: 6.0

As everyone knows, the $VIMRUNTIME/doc is increasing


rapidly in size. The directory contained so many plaintext documents that I often compress them to save my
diskspace. With the support of VIM's GZIP plugin, VIM
will automatically uncompress the files when we need to
read them.
Here is my procedure:
1. If you have the source, go to 'runtime/doc' and edit
'doctags.c', change
printf("%s\t%s\t/*", p1,
argv[0]); to printf("%s\t%s.gz\t/*", p1, argv[0]);
then make. This is to modify the tag, or you'll
have to change the 'tags' file by hand if you don't have
doctags.c.
2. Edit the new generated 'tags' file to rename
'help.txt.gz' back to 'help.txt' because it's hardwritten in VIM executable binary.
:% s/help\.txt\.gz/help\.txt/g
3. Copy the new 'tags' to $VIMRNUTIME/doc and run 'gzip
*.txt; gunzip help.txt'
On VIM 6.0an, we can reduce the original size (3302k) to
1326k.
I don't know if this helps, but if someone likes to
compress documents... this can be reffered :)

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Dictionary completions | if you use 'highlight search' feature, map a key to :noh >>

Additional Notes
rnd@softhome.net, July 23, 2001 5:48

http://www.vim.org/tips/tip.php?tip_id=92 (1 of 2) [18/02/2004 14:43:51]

Tip #92 - Reducing 'doc' directory size : vim online

it is possible to compress help.txt, too.


'helpfile' option in vim:

there is a

set helpfile=/usr/share/vim/vim60u/doc/help.txt.gz
wichert@wiggy.net, July 30, 2001 3:43
For a demonstration of how this works you can look at
the Debian packages for
vim since, well, before the changelog starts at least
(which is september 1999).
wichert@wiggy.net, August 1, 2001 4:02
Silly typo, that should be 1997.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=92 (2 of 2) [18/02/2004 14:43:51]

SourceForge
Logo

Tip #93 - if you use 'highlight search' feature, map a key to :noh : vim online

not logged in (login)

Home
Search

Tip #93: if you use 'highlight search' feature, map a key to :noh
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 146/61, Viewed by 2889

created: August 3, 2001 9:50


author: Leo Lipelis

complexity: basic
as of Vim: 6.0

It is very convenient to use 'hlsearch' option. However


it can be annoying to have the highlight stick longer
than you want it. In order to run it off you have to
type at least 4 keystrokes, ":noh". So, it's a good
idea to map this to a key. I like to map it to controln. This is the line I use in my .vimrc file to do it:
nmap <silent> <C-N> :silent noh<CR>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Reducing 'doc' directory size | Questions & Answers about using tags with Vim >>

Additional Notes
Anonymous, August 3, 2001 9:56
"In order to run it off..." should read "In order to
turn it off...". And just in case it's not obvious
from my explanation, after you add the mapping to your
.vimrc file, you can turn off search highlights by
hitting control-n, or whatever other key you mapped
":noh" to.
Brandels_Mikesh@web.de, August 4, 2001 15:10

http://www.vim.org/tips/tip.php?tip_id=93 (1 of 4) [18/02/2004 14:43:54]

Tip #93 - if you use 'highlight search' feature, map a key to :noh : vim online

Or you could add a simple function to toggle Search


highlighting on or off and map to that instead:
function ToggleHLSearch()
if &hls
set nohls
else
set hls
endif
endfunction
nmap <silent> <C-n> :silent call ToggleHLSearch()<CR>
dominique.pelle@free.fr, August 4, 2001 19:10
Instead of a function, how about toggling settings
with:
map <F4> :set nohls!<CR>:set nohls?<CR>
wookie@pill.com, August 7, 2001 0:21
I always search for nonsense to get rid of the
highlights, ergo:
/sldkjfz<CR>
Now it's dark...
Marcel.van.der.Laan@ict.nl, September 17, 2001 0:08
Just to be pedantic:
map <F4> :set hls!<CR>:set hls?<CR>
(Uhuh, it's 4 characters shorter... It can be even
shorter by using ":se" instead of ":set", but that's
pushing it...)
bindu@wavell.net, November 11, 2001 13:56
Since we seem to have a competition going here, check
this out:
:map <F4> :let &hls=!&hls<CR>
It 7 characters shorter than the last one :)
bindu@wavell.net, November 11, 2001 14:00
You can nix 6 more characters with the following:
:map <F4> :set hls!<CR>
lifeburst@hotmail.com, February 20, 2002 15:57

http://www.vim.org/tips/tip.php?tip_id=93 (2 of 4) [18/02/2004 14:43:54]

Tip #93 - if you use 'highlight search' feature, map a key to :noh : vim online

Which is the same as the previous version except it


doesn't tell the user which status the toggle has..
Anonymous, March 27, 2002 7:03
How would you change these scripts to automatically
turn highlighting back on when you do another search?
Anonymous, March 27, 2002 7:56
Oh wait... that's what :noh does... my bad!
ncr, June 14, 2002 5:11
For ppl who don't like to toggle :hls but want to get
rid of highlighting can do this
map <F4> :let @/ = ""<CR>
-ncr
bgins@hotmail.com, October 20, 2002 11:55
:map <silent> <C-N> :se invhlsearch<CR>
will toggle the feature on and off. I like this since
n is used anyway to find the next occurrence.
Mohit Kalra @nothanks.com, March 6, 2003 0:59
I have modified this mapping to:
map <F12> :let @/=""<CR>
Cleared"<CR>

:echo "Highlights

(Added the extra message after cleaning the screen.)


arunrecw@yahoo.com, March 15, 2003 12:02
what I do is very simple, press "/" and put a new
search of a word that is certainly to be not there. in
that case the highlighted search of earlier item will
be removed to nothing. Do it when you have idea of
content of file. the new search string must not be
there, in order to remain at the same place and
removing the highlighted portion. cheerios!!!
alienmind@gmx.net, June 8, 2003 16:24
wookie@pill.com: i always search for nonsense too :)
mails@anand76.ind.in, June 23, 2003 0:50

http://www.vim.org/tips/tip.php?tip_id=93 (3 of 4) [18/02/2004 14:43:54]

Tip #93 - if you use 'highlight search' feature, map a key to :noh : vim online

If you people want to turn this irritating feature


(atleast for me!) off, then put set nohls in your
.vimrc and forget about it.
Anonymous, November 15, 2003 12:22
I am tired of searching for nonsense to clear the
results... this tip
was very helpful. :)
My new .vimrc:
map <silent> \ :let @/=""<cr>
map <silent> H :set !hls<cr>
So, I can type \ and "undo" the highlighting caused by
/,
or I can say "screw that" and type H to disable
highlighting.
Anonymous, November 15, 2003 12:24
Whoops, that exclamation mark should go on the other
side.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=93 (4 of 4) [18/02/2004 14:43:54]

SourceForge
Logo

Tip #94 - Questions & Answers about using tags with Vim : vim online

not logged in (login)

Home
Search

Tip #94: Questions & Answers about using tags with Vim
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 269/111, Viewed by 8650

created: August 3, 2001 11:18


author: Yegappan Lakshmanan

complexity: basic
as of Vim: 5.7

Using tags file with Vim


-----------------------This document gives you a idea about the various facilities
available
in Vim for using a tags file to browse through program source
files.
You can read the Vim online help, which explains in detail the
tags
support, using :help tagsearch.txt. You can also use the help
keywords mentioned in this document to read more about a
particular
command or option. To read more about a particular command or
option
use, :help <helpkeyword> in Vim.
1. How do I create a tags file?
You can create a tags file either using the ctags utility or
using
a custom script or utility.
Help keyword(s): tag
2. Where can I download the tools to generate the tags file?
There are several utilities available to generate the tags
file.
Depending on the programming language, you can use any one
of them.
1. Exuberant ctags generates tags for the following
programming
language files:
Assembler, AWK, ASP, BETA, Bourne/Korn/Zsh Shell, C, C++,
COBOL,
Eiffel, Fortran, Java, Lisp, Make, Pascal, Perl, PHP,
Python,
REXX, Ruby, S-Lang, Scheme, Tcl, and Vim.
You can download exuberant ctags from
http://ctags.sourceforge.net/

http://www.vim.org/tips/tip.php?tip_id=94 (1 of 11) [18/02/2004 14:43:57]

Tip #94 - Questions & Answers about using tags with Vim : vim online

2. On Unix, you can use the /usr/bin/ctags utility.


utility
is present in most of the Unix installations.

This

3. You can use jtags for generating tags file for java
programs.
You can download jtags from:
http://www.fleiner.com/jtags/
4. You can use ptags for generating tags file for perl
programs.
You can download ptags from:
http://www.eleves.ens.fr:8080/home/nthiery/Tags/
5. You can download scripts from the following links for
generating tags file for verilog files:
http://www.probo.com/vtags.htm
http://www.cs.albany.edu/~mosh/Perl/veri-tags
http://www.verilog.net/vrtags.txt
6. You can download Hdrtag from the following linke:
http://www.erols.com/astronaut/vim/index.html#Tags
This utility generates tags file for the following
programming
languages: assembly, c/c++, header files, lex,
yacc,LaTeX, vim,
and Maple V.
7. You can also use the following scripts which are part of
the Vim
runtime files:
pltags.pl - Create tags file for perl code
tcltags - Create tags file for TCL code
shtags.pl - Create tags file for shell script
Help keyword(s): ctags
3. How do I generate a tags file using ctags?
You can generate a tags file for all the C files in the
current
directory using the following command:
$ ctags *.c
You can generate tags file for all the files in the current
directory and all the sub-directories using (this applies
only to
exuberant ctags):

http://www.vim.org/tips/tip.php?tip_id=94 (2 of 11) [18/02/2004 14:43:57]

Tip #94 - Questions & Answers about using tags with Vim : vim online

$ ctags -R .
You can generate tags file for all the files listed in a
text file
named flist using (this applies only to exuberant ctags)
$ ctags -L flist
4. How do I configure Vim to locate a tags file?
You can set the 'tags' option in Vim to specify a particular
tags
file.
set tags=/my/dir/tags
Help keyword(s): 'tags', tags-option
5. How do I configure Vim to use multiple tags files?
The 'tags' option can specify more than one tags file.

The

tag
filenames are separated using either comma or spaces.
set tags=/my/dir1/tags, /my/dir2/tags
6. How do I configure Vim to locate a tags file in a directory
tree?
Note that the following will work only in Vim 6.0 and
above. You
can set the 'tags' option to make Vim search for the tags
file in a
directory tree. For example, if the 'tags' option is set
like
this:
set tags=tags;/
Vim will search for the file named 'tags', starting with the
current directory and then going to the parent directory and
then
recursively to the directory one level above, till it either
locates the 'tags' file or reaches the root '/' directory.
Help keyword(s): file-searching
7. How do I jump to a tag?
There are several ways to jump to a tag location.
1. You can use the 'tag' ex command. For example,
:tag <tagname>
will jump to the tag named <tagname>.
2. You can position the cursor over a tag name and then

http://www.vim.org/tips/tip.php?tip_id=94 (3 of 11) [18/02/2004 14:43:57]

Tip #94 - Questions & Answers about using tags with Vim : vim online

press
Ctrl-].
3. You can visually select a text and then press Ctrl-]
to
jump to the tag matching the selected text.
4. You can click on the tag name using the left mouse
button,
while pressing the <Ctrl> key.
5. You can press the g key and then click on the tag
name
using the left mouse button.
6. You can use the 'stag' ex command, to open the tag
in a new
window.

For example,

:stag func1
will open the func1 definition in a new window.
7. You can position the cursor over a tag name and then
press
Ctrl-W ].

This will open the tag location in a new

window.
Help keyword(s): :tag, Ctrl-], v_CTRL_], <C-LeftMouse>,
g<LeftMouse>, :stag, Ctrl-W_]
8. How do I come back from a tag jump?
There are several ways to come back to the old location from
a tag
jump.
1. You can use the 'pop' ex command.
2. You can press Ctrl-t.
3. You can click the right mouse button, while pressing
the
<Ctrl> key.
4. You can press the g key and then click the right
mouse
button.
Help keyword(s): :pop, Ctrl-T, <C-RightMouse>, g<RightMouse>
9. How do I jump again to a previously jumped tag location?
You can use the 'tag' ex command to jump to a previously
jumped tag
location, which is stored in the tag stack.
Help keyword(s): tag
10. How do I list the contents of the tag stack?
Vim remembers the location from which you jumped to a tag in
the
tag stack.

You can list the current tag stack using the

http://www.vim.org/tips/tip.php?tip_id=94 (4 of 11) [18/02/2004 14:43:57]

Tip #94 - Questions & Answers about using tags with Vim : vim online

'tags' ex
command.
Help keyword(s): :tags, tagstack
11. How do I jump to a particular tag match, if there are
multiple
matching tags?
In some situations, there can be more than one match for a
tag.
For example, a C function or definition may be present in
more
than one file in a source tree. There are several ways to
jump to
a specific tag from a list of matching tags.
1. You can use the 'tselect' ex command to list all the
tag
matches.

For example,

:tselect func1
will list all the locations where func1 is
You can
then enter the number of a tag match to jump to that
location.
2. You can position the cursor over the tag name and

defined.

press g]
to get a list of matching tags.
3. You can visually select a text and press g] to get a
list
of matching tags.
4. You can use the 'stselect' ex command.

This will

open the
selected tag from the tag list in a new window.
5. You can position the cursor over the tag name and
press
Ctrl-W g] to do a :stselect.
Help keyword(s): tag-matchlist, :tselect, g], v_g],
:stselect,
Ctrl-W_g]
12. I want to jump to a tag, if there is only one matching tag,
otherwise a list of matching tags should be displayed. How
do I
do this?
There are several ways to make Vim to jump to a tag
directly, if
there is only one tag match, otherwise present a list of
tag
matches.

http://www.vim.org/tips/tip.php?tip_id=94 (5 of 11) [18/02/2004 14:43:57]

Tip #94 - Questions & Answers about using tags with Vim : vim online

1. You can use the 'tjump' ex command.

For example,

:tjump func1
will jump to the definition func1, if it is defined
only
once. If func1 is defined multiple times, a list of
matching tags will be presented.
2. You can position the cursor over the tag and press g
Ctrl-].
3. You can visually select a text and press g Ctrl-] to
jump
or list the matching tags.
4. You can use the 'stjump' ex command.

This will open

the
matching or selected tag from the tag list in a new
window.
5. You can press Ctrl-W g Ctrl-] to do a :stjump.
Help keyword(s): :tjump, g_Ctrl-], v_g_CTRL-], :stjump,
Ctrl-W_g_Ctrl-]
13. How do browse through a list of multiple tag matches?
If there are multiple tag matches, you can browse through
all of
them using several of the Vim ex commands.
1. To go to the first tag in the list, use the 'tfirst' or
'trewind' ex command.
2. To go to the last tag in the list, use the 'tlast' ex
command.
3. To go to the next matching tag in the list, use the
'tnext' ex
command.
4. To go to the previous matching tag in the list, use the
'tprevious' or 'tNext' ex command.
Help keyword(s): :tfirst, :trewind, :tlast, :tnext,
:tprevious,
:tNext
14. How do I preview a tag?
You can use the preview window to preview a tag, without
leaving
the original window. There are several ways to preview a
tag:
1. You can use the 'ptag' ex command to open a tag in
the
preview window.
2. You can position the cursor on a tag name and press
Ctrl-W
} to open the tag in the preview window.
http://www.vim.org/tips/tip.php?tip_id=94 (6 of 11) [18/02/2004 14:43:57]

Tip #94 - Questions & Answers about using tags with Vim : vim online

3. You can use the 'ptselect' ex command to do the


equivalent
of the 'tselect' ex command in the preview window.
4. You can use the 'ptjump' ex command to do the
equivalent of
the 'tjump' ex command in the preview window.
5. You can position the cursor on the tag and press
Ctrl-W g}
to do a :ptjump on the tag.
Help keyword(s): :preview-window, :ptag, Ctrl-W_},
:ptselect,
:ptjump, Ctrl-W_g}
15. How do I browse through the tag list in a preview window?
If there are multiple tag matches, you can browse through
all of
them in the preview window using several of the Vim ex
commands.
1. To go to the first tag in the list, use the 'ptfirst' or
'ptrewind' ex command.
2. To go to the last tag in the list, use the 'ptlast' ex
command.
3. To go to the next matching tag in the list, use the
'ptnext' ex
command.
4. To go to the previous matching tag in the list, use the
'ptprevious' or 'ptNext' ex command.
Help keyword(s): :ptfirst, :ptrewind, :ptlast, :ptnext,
:ptprevious, :ptNext
16. How do I start Vim to start editing a file at a given tag
match?
While starting Vim, you can use the command line option 't' to
supply a tag name. Vim will directly jump to the supplied
tag
location.
Help keyword(s): -t
17. How do I list all the tags matching a search pattern?
There are several ways to go through a list of all tags
matching a
pattern.
1. You can list all the tags matching a particular
regular
expression pattern by prepending the tag name with
the '/'

http://www.vim.org/tips/tip.php?tip_id=94 (7 of 11) [18/02/2004 14:43:57]

Tip #94 - Questions & Answers about using tags with Vim : vim online

search character.

For example,

:tag /<pattern>
:stag /<pattern>
:ptag /<pattern>
:tselect /<pattern>
:tjump /<pattern>
:ptselect /<pattern>
:ptjump /<pattern>
2. If you have the 'wildmenu' option set, then you can
press
the <Tab> key to display a list of all the matching
tags
in the status bar.

You can use the arrow keys to

move
between the tags and then use the <Enter> key to
select a
tag.
3. If you don't have the 'wildmenu' option set, you
can still
use the <Tab> key to browse through the list of
matching
tags.
Help keyword(s): tag-regexp, wildmenu
18. What options are available to control how Vim handles the
tags
file?
You can use the following options to control the handling
of tags
file by Vim:
1. 'tagrelative' - Controls how the file names in the tags
file
are treated. When on, the filenames are
relative to the directory where the tags
file
is present.
2. 'taglength' characters

Controls the number of significant


used for recognizing a tag.

3. 'tagbsearch' - Controls the method used to search the


tags file
for a tag. If this option is on, binary
search
is used to search the tags
file. Otherwise,
linear search is used.

http://www.vim.org/tips/tip.php?tip_id=94 (8 of 11) [18/02/2004 14:43:57]

Tip #94 - Questions & Answers about using tags with Vim : vim online

4. 'tagstack' - Controls how the tag stack is used.


Help keyword(s): 'tagrelative', 'taglength', 'tagbsearch',
'tagstack'
19. Is it possible to highlight all the tags in the current
file?
Yes.

Read the Vim online help on "tag-highlight".

20. Is it possible to create a menu with all the tags in the


current
file?
Yes.

It is possible to create a menu with all the tags in

the
current file using a Vim script.
script
from the following link:

Download the TagsMenu.vim

http://members.home.net/jayglanville/tagsmenu/TagsMenu.html
21. Is there a workaround to make the Ctrl-] key not to be
treated as
the telnet escape character?
The default escape characters for telnet in Unix systems is
Ctrl-]. While using Vim in a telnet session, if you use
Ctrl-] to
jump to a tag, you will get the telnet prompt. There are
two ways
to avoid this problem:
1. Map the telnet escape character to some other character
using
the "-e <escape character>" telnet command line option
2. Disable the telnet escape character using the "-E"
telnet
command line option.
Help keyword(s): telnet-CTRL-]

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<if you use 'highlight search' feature, map a key to :noh | How do I pipe the output from ex commands into the
text buffer? >>

Additional Notes
sunda4u@yahoo.com, March 29, 2002 4:32

http://www.vim.org/tips/tip.php?tip_id=94 (9 of 11) [18/02/2004 14:43:57]

Tip #94 - Questions & Answers about using tags with Vim : vim online

ctags is a great tool..I'm wondering how I havent come across


like these tools earlier
Anonymous, February 27, 2003 12:21
How do I list where all the tags referenced. All the tag
commands in vim are designed
to search for a tag but not find the references to it. If any
one knows the trick, could
you please share it.
asdf@asdf.com, April 27, 2003 11:07
You are looking for cscope.
:he cscope
http://cscope.sourceforge.net
kallumama, July 24, 2003 11:30
Heres an excellent tutorial on using cscope with vim ; right
from installing to becoming an expert.
http://cscope.sourceforge.net/cscope_vim_tutorial.html
ryan@trigger.co.za, October 22, 2003 2:35
Um, for some reason - I couldn't get recursive lookup of tags
to work with just the
set tags=tags;/
line - changing it to
set tags=./tags;/
works just fine - the only time I've EVER come across the
need to use the ./ thing...
molotov1134@hotmail.com, October 31, 2003 11:42
Howabout for support of C++ tags? Specificly, if I have a
function named foo() in class A and class B, vim goes to the
first match of foo(), it could be A::foo() or B::foo(). Is
there any way to resolve the C++ (or java) class name as part
of jumping to a tag? This would be supremely helpful. I
sometimes have tag lists of 20 possible matches, and its
annoying.
Thanks.
vlb@cfcl.com, November 10, 2003 14:27
The TagsMenu link is no longer correct
seth, January 15, 2004 10:36
TagMenu has been moved to
http://members.rogers.com/jayglanville/tagsmenu/

http://www.vim.org/tips/tip.php?tip_id=94 (10 of 11) [18/02/2004 14:43:57]

Tip #94 - Questions & Answers about using tags with Vim : vim online

tomgun6@charter.net, February 10, 2004 20:25


How do I configure Vim to load tags files automagically so
that I don't have to explicitly enter set tags=/yadda/yadda,
/blah/blah every time I'm viewing/editing a source file?
tomgun6, February 10, 2004 21:44
Note to self: next time, RTFM! vimrc, duh!
wasted post. Just delete it if you want.

Sorry about the

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=94 (11 of 11) [18/02/2004 14:43:57]

SourceForge
Logo

Tip #95 - How do I pipe the output from ex commands into the text buffer? : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #95: How do I pipe the output from ex commands into the text
buffer?
tip karma

Rating 33/15, Viewed by 1847

created: August 7, 2001 10:56


author: Anonymous

complexity: intermediate
as of Vim: 6.0

This is a *request* for a tip. I need to be able to


pipe the output of a :blah ex command into the vim text
buffer for editing. I wanted to do this many times for
different reasons and could never find a way!
I would just love to be able to do :hi --> textBuffer
and examine the output at my own leasure scrolling up
and down and using vim search commands on it. Same
thing for :set all, and other things. Considering that
cut and paste is horrible in windows, I can't for
example do :set guioptions? then cut and paste! So I
have to retype it, or cut and paste from the help
manual. I really want to be able to pipe the output of
ex commands into the text buffer. Can someone help me?
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Questions & Answers about using tags with Vim | Cooperation of Gvim and AutoCad [MTEXT] >>

Additional Notes
Yegappan, August 7, 2001 11:45

http://www.vim.org/tips/tip.php?tip_id=95 (1 of 2) [18/02/2004 14:44:00]

Tip #95 - How do I pipe the output from ex commands into the text buffer? : vim online

You can use the :redir command to redirect the output


of an ex command to
a register and then paste the contents of the register
into a Vim buffer.
For example:
:redir @a
:set all
:redir END
Now, register 'a' will have the output of the "set all"
ex command. You
can paste this into a Vim buffer. You can also write a
Vim function
to do the above.
For more information, read :help redir
Anonymous, August 7, 2001 14:13
Wow!!!

That's awesome!!

Exactly what I want!

mark@zieg.com, July 25, 2002 11:28


This may be obvious to experts, but it took me a very
long time to figure it out, because Google searches on
terms like 'pipe', 'buffer', 'shell', etc never brought
it to my attention. However, you can pipe the contents
of the file currently being edited (the current buffer)
to a shell command, and replace the current file/buffer
with the _output_ of that command, using this:
:%! [cmd]
ie, if you didn't know the :retab command (as for a
long time I didn't), you could expand tabs using basic
unix commands like ":%! expand -t 4". Wish I'd known
this a long time ago, so I'm posting it here in the
hopes that others might find it :-)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=95 (2 of 2) [18/02/2004 14:44:00]

SourceForge
Logo

Tip #96 - Cooperation of Gvim and AutoCad [MTEXT] : vim online

not logged in (login)

Home
Search

Tip #96: Cooperation of Gvim and AutoCad [MTEXT]


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 6/3, Viewed by 1198

created: August 8, 2001 6:51


author: brz@centrum.cz

complexity: intermediate
as of Vim: 5.7

You can - like me :o) - use gvim, like replacement of


internal AutoCad MTEXT editor. You need switch variable
MTEXTED to "gvim" (or maybe fullpath, something like
"c:\vim\vim60aq\gvim" ), and to your _vimrc you can put
line:
autocmd BufRead,BufNewFile *.tmp source c:\vim\aacad.vim
And when you edit MTEXT in acad, menu AutoCad will be
for your use in gvim (only in INSERT and VISUAL mode)
[NOTE: Only I can't start gvim like gvim -y (for any
other person, not so accustomed vith gvim) or start gvim
from gvim.lnk or gvim.bat (I'am using windows95) and
automatic skip to INSERT mode -latest word star, on end
of script- is without functionality(?) Maybe someone
advise me?? ]
Well, script aacad.vim is listed here:
"VIM menu for AutoCad's MTEXT editation
"brz; mailto:brz@centrum.cz; 8. 8. 2001
" Version Mk.I
"------------------------------------------------------------------------imenu &AutoCad.Insert.Space \~
vmenu &AutoCad.Insert.Space <Esc>`<i\~<Esc>%
imenu &AutoCad.Insert.Backslash \\
vmenu &AutoCad.Insert.Backslash <Esc>`<i\\<Esc>%
imenu &AutoCad.Insert.Brackets \{\}<Esc>F\i
vmenu &AutoCad.Insert.Brackets
<Esc>`>a\}<Esc>`<i\{<Esc>%
imenu &AutoCad.Insert.Paragraph \P
vmenu &AutoCad.Insert.Paragraph <Esc>`>a\P<Esc>%
imenu &AutoCad.-SEP1- :

http://www.vim.org/tips/tip.php?tip_id=96 (1 of 4) [18/02/2004 14:44:02]

Tip #96 - Cooperation of Gvim and AutoCad [MTEXT] : vim online

imenu &AutoCad.Colour.Red \C1;


vmenu &AutoCad.Colour.Red <Esc>`>a\C7;<Esc>`<i\C1;<Esc>%
imenu &AutoCad.Colour.Yellow \C2;
vmenu &AutoCad.Colour.Yellow
<Esc>`>a\C7;<Esc>`<i\C2;<Esc>%
imenu &AutoCad.Colour.Green \C3;
vmenu &AutoCad.Colour.Green
<Esc>`>a\C7;<Esc>`<i\C3;<Esc>%
imenu &AutoCad.Colour.Cyan \C4;
vmenu &AutoCad.Colour.Cyan
<Esc>`>a\C7;<Esc>`<i\C4;<Esc>%
imenu &AutoCad.Colour.Blue \C5;
vmenu &AutoCad.Colour.Blue
<Esc>`>a\C7;<Esc>`<i\C5;<Esc>%
imenu &AutoCad.Colour.Violet \C6;
vmenu &AutoCad.Colour.Violet
<Esc>`>a\C7;<Esc>`<i\C6;<Esc>%
imenu &AutoCad.Colour.Black \C7;
vmenu &AutoCad.Colour.Black
<Esc>`>a\C7;<Esc>`<i\C7;<Esc>%
imenu &AutoCad.Colour.D_Grey \C8;
vmenu &AutoCad.Colour.D_Grey
<Esc>`>a\C7;<Esc>`<i\C8;<Esc>%
imenu &AutoCad.Colour.L_Grey \C9;
vmenu &AutoCad.Colour.L_Grey
<Esc>`>a\C7;<Esc>`<i\C9;<Esc>%
imenu
vmenu
imenu
vmenu
imenu
imenu
imenu
vmenu
imenu
vmenu
imenu
vmenu

&AutoCad.Font.Arial \fArial;
&AutoCad.Font.Arial <Esc>`<i\fArial;<Esc>%
&AutoCad.Font.Symbol \Fsymbol;
&AutoCad.Font.Symbol <Esc>`<i\Fsymbol;<Esc>%
&AutoCad.Font.RomanC \Fromanc;
&AutoCad.Font.RomanC <Esc>`<i\Fromanc;<Esc>%
&AutoCad.Font.RomanS \Fromans;
&AutoCad.Font.RomanS <Esc>`<i\Fromans;<Esc>%
&AutoCad.Font.RomanD \Fromand;
&AutoCad.Font.RomanD <Esc>`<i\Fromand;<Esc>%
&AutoCad.Font.RomanT \Fromant;
&AutoCad.Font.RomanT <Esc>`<i\Fromant;<Esc>%

imenu
vmenu
imenu
vmenu
imenu
vmenu
imenu
vmenu

&AutoCad.Size.0_5x \H0.5x;
&AutoCad.Size.0_5x <Esc>`<i\H0.5x;<Esc>%
&AutoCad.Size.1_5x \H1.5x;
&AutoCad.Size.1_5x <Esc>`<i\H1.5x;<Esc>%
&AutoCad.Size.2x \H2x;
&AutoCad.Size.2x <Esc>`<i\H2x;<Esc>%
&AutoCad.Size.3x \H3x;
&AutoCad.Size.3x <Esc>`<i\H3x;<Esc>%

imenu &AutoCad.Effects.Set_Out_1_5 \T1.5;


http://www.vim.org/tips/tip.php?tip_id=96 (2 of 4) [18/02/2004 14:44:02]

Tip #96 - Cooperation of Gvim and AutoCad [MTEXT] : vim online

vmenu &AutoCad.Effects.Set_Out_1_5
<Esc>`>a\T1;<Esc>`<i\T1.5;<Esc>%
imenu &AutoCad.Effects.Set_Out_2 \T2;
vmenu &AutoCad.Effects.Set_Out_2
<Esc>`>a\T1;<Esc>`<i\T2;<Esc>%
imenu &AutoCad.Effects.-SEP3- :
imenu &AutoCad.Effects.Tilt_15deg \Q15;
vmenu &AutoCad.Effects.Tilt_15deg
<Esc>`>a\Q0;<Esc>`<i\Q10;<Esc>%
imenu &AutoCad.Effects.Tilt_20deg \Q20;
vmenu &AutoCad.Effects.Tilt_20deg
<Esc>`>a\Q0;<Esc>`<i\Q20;<Esc>%
imenu &AutoCad.Effects.Tilt_30deg \Q30;
vmenu &AutoCad.Effects.Tilt_30deg
<Esc>`>a\Q0;<Esc>`<i\Q30;<Esc>%
imenu &AutoCad.Effects.-SEP4- :
imenu &AutoCad.Effects.Change_Width_0_5x \W0.5;
vmenu &AutoCad.Effects.Change_Width_0_5x
<Esc>`>a\W1;<Esc>`<i\W0.5;<Esc>%
imenu &AutoCad.Effects.Change_Width_2x \W2;
vmenu &AutoCad.Effects.Change_Width_2x
<Esc>`>a\W1;<Esc>`<i\W2;<Esc>%
imenu &AutoCad.Effects.-SEP5- :
imenu &AutoCad.Effects.Justify_Down \A0;
vmenu &AutoCad.Effects.Justify_Down <Esc>`<i\A0;<Esc>%
imenu &AutoCad.Effects.Justify_Middle \A1;
vmenu &AutoCad.Effects.Justify_Middle <Esc>`<i\A1;<Esc>%
imenu &AutoCad.Effects.Justify_Up \A2;
vmenu &AutoCad.Effects.Justify_Up <Esc>`<i\A2;<Esc>%
imenu &AutoCad.Effects.Overlined_Characters \O\o<Esc>F\i
vmenu &AutoCad.Effects.Overlined_Characters
<Esc>`>a\O<Esc>`<i\o<Esc>%
imenu &AutoCad.Effects.Underlined_Characters
\L\l<Esc>F\i
vmenu &AutoCad.Effects.Underlined_Characters
<Esc>`>a\l<Esc>`<i\L<Esc>%
imenu &AutoCad.Effects.Index_Top \S^;
imenu &AutoCad.-SEP6- :
imenu &AutoCad.Help <CR><CR>***Quit Editor: press Alt-F4
and 'No' ***<CR><CR>
star
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=96 (3 of 4) [18/02/2004 14:44:02]

Helpful

Unfulfilling

rate

Tip #96 - Cooperation of Gvim and AutoCad [MTEXT] : vim online

<<How do I pipe the output from ex commands into the text buffer? | How do I add a current time
string inside Vim? >>

Additional Notes
markst@gte.net, August 9, 2001 8:38
Thanks for the tip. Here I thought I was the only
person to use AutoCAD and Vim. Does anybody use Vim to
write there Autolisp programs? It beats the heck out of
the Vlisp editor.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=96 (4 of 4) [18/02/2004 14:44:02]

SourceForge
Logo

Tip #97 - How do I add a current time string inside Vim? : vim online

not logged in (login)

Home
Search

Tip #97: How do I add a current time string inside Vim?


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 30/17, Viewed by 2618

created: August 9, 2001 1:06


author: newbie

complexity: basic
as of Vim: 6.0

This is a *request* for a tip.


Sometimes (eg. editing HTML pages) I need to add a
timestamp string to my editing buffer.
On UNIX systems, I can use
:r!date
to get a localized date time string; but on Windows
('date' on Windows will query the user to input new
date)
or other platforms which does not have 'date' command,
how do I get a timestamp easily?
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Cooperation of Gvim and AutoCad [MTEXT] | Getting vim help from mailing lists and newsgroups.
>>

Additional Notes
none, August 9, 2001 4:27
The best thing to do is install cygwin from
http://sources.redhat.com/cygwin.
This will give you 'date' and a host of other UNIX
utilities under windows.
salmanhalim@hotmail.com, August 9, 2001 5:54

http://www.vim.org/tips/tip.php?tip_id=97 (1 of 4) [18/02/2004 14:44:05]

Tip #97 - How do I add a current time string inside Vim? : vim online

vim has a function to help with this called strftime


(do :help on it); these abbreviations work, but they
aren't my own (i fear i forget whose file i got these
from):
"date/time
iab mdyl
iab mdys
iab mdyc
iab hml
iab hms

abbreviations
<c-r>=strftime("%a %d %b %Y")<cr>
<c-r>=strftime("%y%m%d")<cr>
<c-r>=strftime("%c")<cr>
<c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>
<c-r>=strftime("%H:%M:%S")<cr>

SBrueggemann@gmx.net, August 9, 2001 9:03


You might want to automatically update existing time
stamps when writing a file:
That's what's in my _vimrc:
--- CUT HERE --" first add a function that returns a time stamp in the
desired format
if !exists("*TimeStamp")
fun TimeStamp()
return "Time-stamp: <" . strftime("%d %b %Y
%X") . " My Name>"
endfun
endif
" this function searches for an existing time stamp and
updates it using the
" function declared above
if !exists("*UpdateTimeStamp")
fun UpdateTimeStamp()
if (match(getline(1),"Time-stamp: <.*>")) > 1
exe "1,1 s/Time-stamp: <.*>/" . TimeStamp()
endif
endfun
endif
" abbreviation to manually enter a timestamp. Just type
YTS in insert mode
iab YTS <C-R>=TimeStamp()<CR>
" add an autocommand to update an existing time stamp
when writing the file
" It uses the functions above to replace the time stamp
and restores cursor
" position afterwards (this is from the FAQ)
autocmd BufWritePre,FileWritePre *
ks|call
http://www.vim.org/tips/tip.php?tip_id=97 (2 of 4) [18/02/2004 14:44:05]

Tip #97 - How do I add a current time string inside Vim? : vim online

UpdateTimeStamp()|'s
--- CHAINSAW OFF --My time stamp has the format
Time-stamp: <09 Aug 2001 02:32:42 Editors Name>
It is searched for in the first line of the file only
(you can certainly change that) in columns > 1. I did
that mainly for security reasons (in source code, there
will be almost always a comment start, e.g. /* in c,
preceding the time stamp).
Kind regards
Sven
charles.e.campbell.1@gsfc.nasa.gov, August 14, 2001 8:12
I use the following insert-maps in my <.vimrc>:
" Dates/Times
imap \ymd
<C-R>=strftime("%y%m%d")<CR>
imap \mdy
<C-R>=strftime("%m/%d/%y")<CR>
imap \Mdy
<C-R>=strftime("%b %d, %Y")<CR>
imap \hms
<C-R>=strftime("%T")<CR>
So, while in insert mode, a \ymd will insert the year,
month, and day in
the form 010814.
For html I have an autocmd that I use which fires on
write:
au BufWritePre *.html exe "norm mz"|exe '%s/\(<!-- DATE
-->\).\{-}\d\d:\d\d:\d\d/\1'.strftime("%b %d, %Y
%X")."/e"|norm `z
That way a string of the form <!-- DATE -->Aug 13, 2001
14:19:50
embedded in the text which will be updated to the
current date
(using Vim's built-in strftime() function) and time
automatically -every time I save the file (the ...DATE... stuff is an
HTML comment
which won't appear).

http://www.vim.org/tips/tip.php?tip_id=97 (3 of 4) [18/02/2004 14:44:05]

Tip #97 - How do I add a current time string inside Vim? : vim online

bhilverdink@hotmail.com, January 1, 2002 10:43


try:
r!date /T
antoine.mechelynck@belgacom.net, February 1, 2004 16:45
to add the current date and time at the cursor (on any
platform):
"=strftime("%c")<Enter>p
Vary the format string, i.e. the argument to
strftime(), to get the time and/or date in a different
format. Depending on the format string used, the result
may depend on your locale.
see
:help quote=
:help strftime()
:help :language
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=97 (4 of 4) [18/02/2004 14:44:05]

SourceForge
Logo

Tip #98 - Getting vim help from mailing lists and newsgroups. : vim online

not logged in (login)

Home
Search

Tip #98: Getting vim help from mailing lists and newsgroups.
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 17/10, Viewed by 944

created: August 9, 2001 4:41


author: Cory T. Echols

complexity: basic
as of Vim: 5.7

There have been a few "requests for tips" entered into the tips
database lately. If you have specific questions that aren't
answered by the existing tips, there are a couple of resources
that may be more appropriate:
The mailing list vim@vim.org is for vim users.
email to vim-help@vim.org, you'll get a message
how to subscribe, as well as how to request old
contact the list maintainer. This mailing list
at http://groups.yahoo.com/group/vim.

If you send an
back telling you
messages and
is also archived

The newsgroup comp.editors discusses many different editors, but


most of the traffic is about vim. When posting, it is appreciated
if you include "vim" in the subject line. The comp.editors
newsgroup is archived at
http://groups.google.com/groups?hl=en&safe=off&group=comp.editors.
Using the tips database for asking questions is not likely to work
well. For example, if you ask a question titled "Searching for
strings in a file" and I read this site and see that tip, I'm not
going to read it if I already know how to search for strings in a
file. In comp.editors and vim@vim.org, people expect to find
questions from others and are therefore more likely to see your
questions.
After finding the answer to your question, please consider whether
it would make an appropriate tip, and if so, add it to the tips
database.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<How do I add a current time string inside Vim? | How to tell what syntax highlighting group *that* is! >>

Additional Notes
Anonymous, August 10, 2001 9:51

http://www.vim.org/tips/tip.php?tip_id=98 (1 of 2) [18/02/2004 14:44:07]

Tip #98 - Getting vim help from mailing lists and newsgroups. : vim online

I disagree with this. I see requests for tips become very handy
tips once the requests are answered.
If this is not desired, then it's a good idea to create
"requests for tips" location in addition to "tips". Then people
can post requests, and the answers can go into "Tips" place.
Cory T. Echols, August 10, 2001 10:44
I did not mean for this tip to be a policy statement (I can't
make policy for this site), or a troll, or an admonishment of
anyone for anything.
The fact that questions were being posted in the tips database
implied to me that there were people who weren't aware of the
newsgroup or mailing list, so I entered a tip to help them
out. That's all it meant. Nothing more, nothing less.
Anonymous, August 19, 2001 14:01
Further, as Cory pointed out, a request for a tip could very
well be misconstrued as a tip on a subject and therefore be
ignored by people who can help. One stands a better chance of
having questions answered when they are put up using the avenues
suggested by Cory.
iain-vim@dellah.anu.edu.au, May 20, 2002 14:19
See also http://groups.yahoo.com/group/vimtips/ - a regular
mailing of the tips from this database,
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=98 (2 of 2) [18/02/2004 14:44:07]

SourceForge
Logo

Tip #99 - How to tell what syntax highlighting group *that* is! : vim online

not logged in (login)

Home
Search

Tip #99: How to tell what syntax highlighting group *that* is!
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 48/22, Viewed by 2274

created: August 14, 2001 8:57


author: Charles E. Campbell, Jr.

complexity: intermediate
as of Vim: 5.7

Here's a (what should be a one-line) map to help you tell


just what
syntax highlighting groups the item under the cursor
actually is:
map <F10> :echo "hi<" .
synIDattr(synID(line("."),col("."),1),"name") . '>
trans<' . synIDattr(synID(line("."),col("."),0),"name") .
"> lo<" .
synIDattr(synIDtrans(synID(line("."),col("."),1)),"name")
. ">"<CR>
Once known you can override the current highlighting with
whatever you want.
If you're debugging a syntax highlighting file (a rare
occupation), sometimes
you'll wish to know the entire chain of syntax
highlighting. For that,
check out
http://www.erols.com/astronaut/vim/vimscript/hilinks.vim

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Getting vim help from mailing lists and newsgroups. | Jump to tag (e.g. help topic) with German
keyboard (PC) >>

Additional Notes
cec@NgrOyphSon.gPsfAc.nMasa.gov, December 19, 2001 7:33

http://www.vim.org/tips/tip.php?tip_id=99 (1 of 2) [18/02/2004 14:44:10]

Tip #99 - How to tell what syntax highlighting group *that* is! : vim online

Example: Looking at the syntax/vim.vim file's


syn match vimSpecFile "<c\(word\|WORD\)>" nextgroup=...
Put the cursor on the "\(" in the string, hit <F10>:
hi<vimPatSep> trans<vimPatSep> lo<Special>
will show up on the status line. You may envisage the
highlighting
as a push-down stack of highlighting groups. The
"highest" one is
the most limited in scope, and is the name of the
syntax keyword, match,
or region. Generally such a syntax group is linked to
a highlighting
group. The "lowest" one is the basic highlighting
specification, and
probably has a broad reach -- in this case, "Special"
is a default
highlighting group used in 179 syntax highlighting
files (vim 6.0) for
a variety of purposes.
Syntax groups can be specified as being transparent, so
that whatever
group they're in is what is used for highlighting. If
that's the case,
the group mentioned in "trans<>" will be the name of
that group, else
it is a repeat of the "hi<>" group name.
With the highlighting script (hilinks.vim), you'll get
(via \hlt):
vimPatSep -> SpecialChar -> Special
which shows the entire highlighting chain. Thus, a
"\(" is identified as
being highlighted as a vimPatSep, which is a link to
SpecialChar, which
itself is a link to Special. Actually a "\(" is a
vimPatSepZone region
which has vimPatSep as its "matchgroup".
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=99 (2 of 2) [18/02/2004 14:44:10]

SourceForge
Logo

Tip #100 - Jump to tag (e.g. help topic) with German keyboard (PC) : vim online

not logged in (login)

Home
Search

Tip #100: Jump to tag (e.g. help topic) with German keyboard (PC)
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 32/19, Viewed by 880

created: August 20, 2001 1:51


author: SBrueggemann@gmx.net

complexity: basic
as of Vim: 5.7

You're a newbie in vim and need some ":help"? Well,


help.txt reads:
"Jump to a subject: Position the cursor on a tag
between |bars| and hit CTRL-]."
Unfortunately there is no "]" key on German keyboards.
On Win32 try CTRL-+ (Strg-+), on Linux console I use
CTRL-AltGr-9 (Strg-AltGr-9).
Kind regards
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<How to tell what syntax highlighting group *that* is! | Change automatically to the directory the file in
the current buffer is in >>

Additional Notes
salmanhalim@hotmail.com, August 20, 2001 6:13
if you know the ascii code of the ] (93 or 0x5d), you
could create a mapping to it to guarantee your
combination would work -- the german keyboard might
have some other character thereupon that could be used:
noremap <c-theChar> <c-]>
you can get the ] by typeing a control-v followed by
93<space> or control-v followed by x5d.
hope this helps,
salman.
Add Note

http://www.vim.org/tips/tip.php?tip_id=100 (1 of 2) [18/02/2004 14:44:16]

Tip #100 - Jump to tag (e.g. help topic) with German keyboard (PC) : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=100 (2 of 2) [18/02/2004 14:44:16]

SourceForge
Logo

Tip #101 - Change automatically to the directory the file in the current buffer is in : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #101: Change automatically to the directory the file in the current
buffer is in
tip karma

Rating 48/23, Viewed by 1268

created: August 21, 2001 1:59


author: Fritz Mehner

complexity: basic
as of Vim: 5.7

To change automatically to the directory the file in the


current buffer is in
add a line (below) to the file .vimrc .
The file .vimrc should have the following if-statement
to control the autocmd feature:
if has("autocmd")
< ... lot of autocmd stuff ... >
" Change to the directory the file in your current
buffer is in
autocmd BufEnter * :cd %:p:h
endif " has("autocmd")
Add the line above the endif and restart vim/gvim.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Jump to tag (e.g. help topic) with German keyboard (PC) | smart mapping for tab completion >>

Additional Notes
sf@vikas.mailshell.com, September 24, 2001 11:03
As of Vim 6.0, I would recommend using the "lcd"
instead of "cd" since using ":cd: sometimes messes up
the :mkview / :mksession commands
Anonymous, November 28, 2003 0:42

http://www.vim.org/tips/tip.php?tip_id=101 (1 of 2) [18/02/2004 14:44:18]

Tip #101 - Change automatically to the directory the file in the current buffer is in : vim online

This is very helpful if you have many locations/many


source files for which you want to maintain separate
tag files. You can "set tag=tag" in your vimrc and
then whenever you edit a file you also automatically
use the relevant tag file. (See also ctags at
http://ctags.sourceforge.net/)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=101 (2 of 2) [18/02/2004 14:44:18]

SourceForge
Logo

Tip #102 - smart mapping for tab completion : vim online

not logged in (login)

Home
Search

Tip #102: smart mapping for tab completion


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 699/213, Viewed by 12298

created: August 21, 2001 12:17


author: benoit.cerrina@writeme.com

complexity: basic
as of Vim: 6.0

I'm used to complete words with <tab>, however when


editing source I can't just map that to vim keyword
completion because I sometime need to insert real tabs,
since it mostly happen when at the beginning of the line
or after a ; and before a one line comma (java, c++ or
perl anyone...) I've come to find the following really
usefull
This is how you can map the <tab> key in insert mode
while still being able to use it when at the start of a
line or when the preceding char is not a keyword
character.
in a script file in a plugin directory or in your .vimrc
file:
first define a function which returns a <tab> or a <C-N>
depending on the context:
function InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
then define the appropriate mapping:
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
the trick here is the use of the <c-r>= in insert mode
to be able to call your function without leaving insert
mode.
:help i_CTRL-R
Benoit
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=102 (1 of 11) [18/02/2004 14:44:21]

Helpful

Unfulfilling

rate

Tip #102 - smart mapping for tab completion : vim online

<<Change automatically to the directory the file in the current buffer is in | Move to next/previous line
with same indentation >>

Additional Notes
igor@tyumbit.ru, August 26, 2001 2:01
WOW!
I've wanted this for year and now i've got it!
Thanks for the tip!
anon@xyz.com, September 2, 2001 1:23
This is pretty cool. How would we simulate ^X^N, I
wonder...
octorock@doubtful.com, September 5, 2001 17:56
this is wonderful. however it would be helpful if it
could be made to cycle through all completions like a
proper ctrl-p would.
octorock@doubtful.com, September 5, 2001 20:33
i'm a giant fool. nevermind. (when i copied and
pasted the snippet, it left trailing whitespace
characters.)
thank you for such a killer tip.
Anonymous, September 6, 2001 10:50
With a minor addition you can also go in either
direction:
function! InsertTabWrapper(direction)
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
elseif "backward" == a:direction
return "\<c-p>"
else
return "\<c-n>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper ("forward")<cr>
inoremap <s-tab> <c-r>=InsertTabWrapper
("backward")<cr>

benoit.cerrina@writeme.com, September 25, 2001 19:42


http://www.vim.org/tips/tip.php?tip_id=102 (2 of 11) [18/02/2004 14:44:21]

Tip #102 - smart mapping for tab completion : vim online

Anonymous,
Good, actually in my setting I had define two wrappers
for tab and shift tab effectively achieving the same
effect.
By the way I made a mistake in my orginal e-mail, it is
.com not .fr
Benoit
Anonymous, December 9, 2001 23:52
This tip is great. But, when type in 'tab' , it will
have a additional space. How to fix it ? thanks.
lee@dashf.com, January 16, 2002 9:45
this tip truly does kick ass.
mayureshk@aftek.com, January 24, 2002 23:38
This is freaking fabulous. Thankx man !! Its way too
cool. i too, have been searching for this for quite
some time now. Kudos !
kgergely@mcl.hu, April 9, 2002 10:30
See also vimscript#182.
It is a complete system, and the completion remembers
the completion mode!
anon, April 29, 2002 22:10
This tip is absolutely fantastic. In response to the
problem of a space after hitting tab, there is most
likely a
space after the line
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
In your vimscript, remove this and you should be fine
anon, May 22, 2002 10:17
Darned space!
Vim user, July 9, 2002 6:52
shift-tab always gives me a 'I', whether I'm in insert
mode or not.
Something wrong with my termcap?
AK, August 23, 2002 12:50
This tip is truly kickass..!
luca-vim@llucax.hn.org, September 6, 2002 7:50

http://www.vim.org/tips/tip.php?tip_id=102 (3 of 11) [18/02/2004 14:44:21]

Tip #102 - smart mapping for tab completion : vim online

Anyone knows how to use a list of keywords for the


completion??? I've searched the help but couldn't find
anything. This is the great tip ever!!!
timothy.aldrich@csfb.com, September 13, 2002 6:48
for those of us that would like to use dictionary files
for filetypes ( in order to use function prototypes
et. al.) you can modify the 'iskeyword' option
temporarily to complete function names for example :
given a dictionary with
abs(VALUE)
.
.
.
i could type :
ab<TAB>
and it would expand to abs(VALUE)

function! InsertTabWrapper(direction)
let oldisk=&isk "save the iskeyword options
set isk+=(,),, "add '(' ')' and ',' character
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
elseif "backward" == a:direction
return "\<c-n>"
else
return "\<c-p>"
endif
set &isk=oldisk "restore the iskeyword options
endfunction
timothy.aldrich@csfb.com, September 13, 2002 7:06
actually Mikolaj Machowski suggested the function :
fun! Iskcompletion()
let oldisk=&isk
set isk+=(,)
normal <C-P>
set &isk=oldisk
endfun
I just merged it with the Tab completion function Thank You Mikolaj
Anonymous, October 11, 2002 10:38

http://www.vim.org/tips/tip.php?tip_id=102 (4 of 11) [18/02/2004 14:44:21]

Tip #102 - smart mapping for tab completion : vim online

I am trying to map <F6> to toggle whether this function


is enabled or not. In other words, I want it to toggle
the mapping between the default and this one. More
specifically, I actually have two functions--this one
and <S-Tab> that completes the whole line, and I would
like the <F6> to enable/disable both
mappings. Suggestions? Thanks :).
angus-vim@revahertz.com, October 31, 2002 11:22
If you want to use keywords in completion, you'll need
to make dictionary files for each of the languages
whose keywords you want to use.
e.g.
cat /usr/share/vim/vim61/syntax/sh.vim | grep keyword |
grep -v nextgroup | awk '{ $1=""; $2=""; $3=""; print}'
| perl -pe 's/\s+/\n/g' | grep -v contained | grep -v
'^$' | sort | uniq > /home/user/.vim/dict/sh.dict
the above command will probably need tweaking depending
on the syntax file.
and in your .vimrc:
" tell complete to look in the dictionary
set complete-=k complete+=k
" load the dictionary according to syntax
:au BufReadPost * if exists("b:current_syntax")
:au BufReadPost *
let &dictionary =
substitute("~/.vim/dict/FT.dict", "FT",
b:current_syntax, "")
:au BufReadPost * endif
It would be nice if there was a built in way to add
words to the dictionary from the syntax files. Is
there?
Dean Hougen <hougen@ou.edu>, November 26, 2002 17:31
Very nice!
Daniel Shields <vim@aegis.mailshell.com>, January 15, 2003 7:48

http://www.vim.org/tips/tip.php?tip_id=102 (5 of 11) [18/02/2004 14:44:21]

Tip #102 - smart mapping for tab completion : vim online

I prefer to be able to toggle tab completion manually.


The following function
works for me:
" toggle tab completion
function! TabCompletion()
if mapcheck("\<tab>", "i") != ""
:iunmap <tab>
:iunmap <s-tab>
:iunmap <c-tab>
echo "tab completion off"
else
:imap <tab> <c-n>
:imap <s-tab> <c-p>
:imap <c-tab> <c-x><c-l>
echo "tab completion on"
endif
endfunction
map <Leader>tc :call TabCompletion()<cr>
brentkucera@juno.com, February 2, 2003 1:10
Does anyone know how to map Ctrl+Spacebar to do the
same thing as Ctrl+N while in insert mode? I've tried
these with no luck:
_ represents space
:map!
which
:map!
:map!
:map!

^V__ ^N <-- this maps JUST the spacebar to ^N,


is seriously annoying
^V<Space> ^N <-- this does nothing
<C-SPACE> ^N
<C-Space> ^N

I'm using vim 6.1 on Cygwin. Please e-mail me if you


know how to do this.
daniel.elstner@gmx.net, February 12, 2003 11:25

http://www.vim.org/tips/tip.php?tip_id=102 (6 of 11) [18/02/2004 14:44:21]

Tip #102 - smart mapping for tab completion : vim online

Have to chime in... here's my silly attempt at making


the Tab key more
intelligent. The function below (derived work of
course) allows one to get
the original effect of <Tab> if the previous character
is a space. I.e.,
you can type:
foo<Space><Tab>
and it'll end up as foo<Tab> with the space
deleted. This is *not* the same
as <C-v><Tab>, which would always insert a real Tab
character rather than
honoring 'softtabstop'.
" Intelligent tab completion
inoremap <silent> <Tab> <Cr>=<SID>InsertTabWrapper(1)<CR>
inoremap <silent> <S-Tab> <C-r>=<SID>InsertTabWrapper(1)<CR>
function! <SID>InsertTabWrapper(direction)
let idx = col('.') - 1
let str = getline('.')
if a:direction > 0 && idx >= 2 && str[idx - 1] == '
'
\&& str[idx - 2] =~? '[a-z]'
if &softtabstop && idx % &softtabstop == 0
return "\<BS>\<Tab>\<Tab>"
else
return "\<BS>\<Tab>"
endif
elseif idx == 0 || str[idx - 1] !~? '[a-z]'
return "\<Tab>"
elseif a:direction > 0
return "\<C-p>"
else
return "\<C-n>"
endif
endfunction
Anonymous, May 18, 2003 16:02

http://www.vim.org/tips/tip.php?tip_id=102 (7 of 11) [18/02/2004 14:44:21]

Tip #102 - smart mapping for tab completion : vim online

what about this to dump all the syntax files into


properly formatted dict files
for i in /usr/share/vim/syntax/*;do cat $i | grep
keyword | grep -v nextgroup | awk '{ $1=""; $2="";
$3=""; print}' | perl -pe 's/\s+/\n/g' | grep -v
contained | grep -v '^$' | sort |
uniq>~/.vim/dict/`basename $i .vim`.dict;done
bigdog@hotmail.com, June 17, 2003 23:23
One small suggestion for daniel elstner's script:
replace '[a-z]' with '[^<space><tab>]'.
Sreny@SverGbc.Pbz (Rot13ed), August 1, 2003 5:08
My derivation of this wonderful tip: (aimed at C++ //
comments)
This as it happens has nothing to do with <tab> nor
completion.
function! SpecialCR()
" [Feral:213/03@04:21] This is inspired by how
multi-edit does things.
" Wonderfull VIMTIP#102 clued me in on how to
properly wrap a key like
" this.
(http://vim.sourceforge.net/tips/tip.php?tip_id=102)
let DaLine = getline('.')
if match(DaLine, '\c^\s*//$') > -1
" [Feral:213/03@04:59] Just eat the // chars
"
return "\<bs>\<bs>"
"
"This method:
"
// -[Feral:213/03@04:59]--------------------------------------------"
//
" 75 is the column we wish to not go beyond.
" 2 = ' -'
" 20 = my time stamp: [Feral:213/03@04:52]
" 1 = '-'
let AmountForFiller = 75 (virtcol('.')+2+20+1)
let Filler = ""
while strlen(Filler) < AmountForFiller
let Filler = Filler.'-'
endwhile
let DaLine = " -

http://www.vim.org/tips/tip.php?tip_id=102 (8 of 11) [18/02/2004 14:44:21]

Tip #102 - smart mapping for tab completion : vim online

[Feral:".strftime('%j/%y@%H:%M')."]-".Filler."\<cr>"
return DaLine
elseif match(DaLine, '\c^\s*//\s$') > -1
return "\<bs>\<bs>\<bs>"
else
return "\<cr>"
endif
endfunction
inoremap

<cr>

<c-r>=SpecialCR()<cr>

This will make <cr> eat C++ line comments when they are
the only think on the line, or more precisely:
"//\s" will be get 3 backspaces which should erase it
and "//" will get a simple timestamp separator.
Modify to your hearts content of course.
Happy VIMing!
anders@trolltech.com, September 18, 2003 6:41
Hi
Cool function(s)
Would it be possible to extend InsertTabWrapper to make
a tab pressed at col('.') >= (indent '.') reindent the
line as with a == ? I could not find a simple way to do
this but I am very much a novice with vim.
Anders Bakken
ericzbeard@yahoo.com, October 8, 2003 9:48
Good Stuff!
Here's the section of my vimrc that has all this wired
up (this is on a windows box, I jumped on a unix
machine to run the shell script that makes all the dict
files). My addition is Ctrl-TAB to begin a keyword
search instead of hitting Ctrl-X Ctrl-K, then I can
regular TAB through the entries.
Watch out for those dang spaces at the end of the
lines!
Thanks to everybody who contributed, this is great.
" Remap TAB to keyword completion
function! InsertTabWrapper(direction)
let col = col('.') - 1
http://www.vim.org/tips/tip.php?tip_id=102 (9 of 11) [18/02/2004 14:44:21]

Tip #102 - smart mapping for tab completion : vim online

if !col || getline('.')[col - 1] !~ '\k'


return "\<tab>"
elseif "backward" == a:direction
return "\<c-p>"
elseif "forward" == a:direction
return "\<c-n>"
else
return "\<c-x>\<c-k>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper ("forward")<cr>
inoremap <s-tab> <c-r>=InsertTabWrapper
("backward")<cr>
inoremap <c-tab> <c-r>=InsertTabWrapper
("startkey")<cr>
" toggle tab completion
function! ToggleTabCompletion()
if mapcheck("\<tab>", "i") != ""
:iunmap <tab>
:iunmap <s-tab>
:iunmap <c-tab>
echo "tab completion off"
else
:imap <tab> <c-n>
:imap <s-tab> <c-p>
:imap <c-tab> <c-x><c-l>
echo "tab completion on"
endif
endfunction
map <Leader>tc :call ToggleTabCompletion()<cr>
" tell complete to look in the dictionary
set complete-=k complete+=k
" load the dictionary according to syntax
:au BufReadPost * if exists("b:current_syntax")
:au BufReadPost *
let &dictionary =
substitute("C:\\vim\\vimfiles\\dict\\FT.dict", "FT",
b:current_syntax, "")
:au BufReadPost * endif
EZB
kalita_at_iiprg.cz, October 27, 2003 7:39
This script doesn't work with multibyte (utf-8 chars)

http://www.vim.org/tips/tip.php?tip_id=102 (10 of 11) [18/02/2004 14:44:21]

Tip #102 - smart mapping for tab completion : vim online

kalita_at_iiprg.cz, October 27, 2003 8:04


Try replace condition with
!col || strpart(getline('.'), col-1, col) =~ '\s'
Enjoy
dev.null@gmx.net, January 25, 2004 13:12
is there a way to make tab complete like bash does, ie.
complete only the characters that are unique and then
let me type another one and press tab again to comlete
the rest.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=102 (11 of 11) [18/02/2004 14:44:21]

SourceForge
Logo

Tip #103 - Move to next/previous line with same indentation : vim online

not logged in (login)

Home
Search

Tip #103: Move to next/previous line with same indentation


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 15/9, Viewed by 1591

created: August 22, 2001 6:06


author: Paul Wright

complexity: intermediate
as of Vim: 6.0

When working with Python and other languages which don't


use braces, it's useful to be able to jump to and from
lines which have the same indentation as the line you
are currently on.
nn <M-,> k:call search ("^". matchstr (getline (line
(".")+ 1), '\(\s*\)') ."\\S", 'b')<CR>^
nn <M-.> :call search ("^". matchstr (getline (line
(".")), '\(\s*\)') ."\\S")<CR>^
will map Alt-< and Alt-> in Normal mode to upward and
downward searching for lines with the same indent as the
current line.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<smart mapping for tab completion | using vim to complement Perl's DBI::Shell >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=103 [18/02/2004 14:44:24]

SourceForge
Logo

Tip #104 - using vim to complement Perl's DBI::Shell : vim online

not logged in (login)

Home
Search

Tip #104: using vim to complement Perl's DBI::Shell


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/3, Viewed by 942

created: September 3, 2001 10:02


author: meonkeys

complexity: advanced
as of Vim: 5.7

DBI::Shell is a Perl module that is used as a shell


interface to Perl's popular DBI (database interface)
package. Forget your favorite SQL navigation gui and
give this method a shot. This has only been tested in
UNIX.
1. run dbish (runs DBI::Shell; installed with
DBI::Shell) and connect to any database
2. in dbish, set /format box
3. enter your query
4. to execute query, type "/ | vim -"
This runs the query and pipes the output to the standard
input of vim. Here are some follow-up tips:
-use gvim instead of vim so a new window will pop up
-set nowrap once in vim
-make a syntax highlighting file for me!
-Adam Monsen
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Move to next/previous line with same indentation | combining move and scroll >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=104 [18/02/2004 14:44:26]

SourceForge
Logo

Tip #105 - combining move and scroll : vim online

not logged in (login)

Home
Search

Tip #105: combining move and scroll


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/2, Viewed by 909

created: September 3, 2001 17:22


author: Andrew Pimlott

complexity: basic
as of Vim: 5.7

I sometimes found myself moving down a few lines


then scrolling down
about the same number of lines with <C-E> to put
cursor in roughly the
same place as it started. I decided I wanted to
J> (and <C-K>,
respectively) to the move-and-scroll operation.
I did

with j,
the
map <CFirst,

:map <C-J> <C-E>j


This was pretty good, but behaved funny at the beginning
and end of files.
Then, I realized that <C-D> already combined move and
scroll, so I figured
that giving <C-D> a count of 1 would do it:
:map <C-J> 1<C-D>
Unfortunately, this permanently attaches a count to <CD> (ugh!), so I have
to undo that:
:map <C-J> 1<C-D>:set scroll=0<CR>
This has the drawback of not necessarily resetting
scroll to its original
value, but since I never change scroll, it's good enough
for me. It would
be nice if there were a version of <C-D> that did not
have the side-affect
of changing scroll.
Happy vimming,
Andrew
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=105 (1 of 2) [18/02/2004 14:44:29]

Helpful

Unfulfilling

rate

Tip #105 - combining move and scroll : vim online

<<using vim to complement Perl's DBI::Shell | Mail signature rotation: Supersimple one-line solution
>>

Additional Notes
vdvo@seznam.cz, February 2, 2003 12:45
And for Page-Up/Page-Down, see vimtip #320. My
solution:
map <PageDown> :set scroll=0<CR>:set scroll^=2<CR>:set
scroll-=1<CR><C-D>:set scroll=0<CR>
map <PageUp> :set scroll=0<CR>:set scroll^=2<CR>:set
scroll-=1<CR><C-U>:set scroll=0<CR>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=105 (2 of 2) [18/02/2004 14:44:29]

SourceForge
Logo

Tip #106 - Mail signature rotation: Supersimple one-line solution : vim online

not logged in (login)

Home
Search

Tip #106: Mail signature rotation: Supersimple one-line solution


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/4, Viewed by 784

created: September 3, 2001 22:21


author: brz*

complexity: basic
as of Vim: 6.0

Hallo,
next solution for _most_simple_ signature rotater:
You can only put one line to your .vimrc || _vimrc:
map <Leader>ms :e c:\sign.txt<CR>ggV/--<CR>k"*xG$a<CR><C-O>*<Esc>:w<CR>:bd<CR>G$a<C-M><Esc>"*P
Must exist file (from eg above) c:\sign.txt, with
content:
-first signature
-second signature
-third signature
-When You finished mail, only call shortcut \ms and
'first signature' will be insert in your mail. In
c:\sign.txt will be first signature pushed to the end of
this file. When You want use other signature, only press
'u' and \ms again
(Or You can change \ms to e.g. <F12>, indeed. ) You can
change this and append one part like 'basic' from
command and append 'changing' part from .signature file,
as you like...
Ok, one unpleasant thing is here: your signature must
not contain '--' (signature separator)...
Anyhow, I find it useful
brz* <brz@centrum.cz>
http://brz.d2.cz/

rate this tip

Life Changing

Helpful

Unfulfilling

<<combining move and scroll | C/C++: convert enum to string table >>

http://www.vim.org/tips/tip.php?tip_id=106 (1 of 2) [18/02/2004 14:44:31]

rate

Tip #106 - Mail signature rotation: Supersimple one-line solution : vim online

Additional Notes
dion@erebus.demon.nl, September 5, 2001 6:59
The official signature separator is '-- ' (i.e. dash
dash space.) It would be better to use that in the
expression and the signature file.
kgergely@mcl.hu, January 9, 2002 6:41
And also a patch could be not to search --, but ^--$,
then you can have -- in your signature.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=106 (2 of 2) [18/02/2004 14:44:31]

SourceForge
Logo

Tip #107 - C/C++: convert enum to string table : vim online

not logged in (login)

Home
Search

Tip #107: C/C++: convert enum to string table


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/3, Viewed by 1681

created: September 5, 2001 0:01


author: Thomas Ramming

complexity: basic
as of Vim: 5.7

When testing your own C/C++ programs you sometimes wish


to have a trace output,
which shows you, which enum value is used.
You can do this by creating a string table for that enum
type,
which contains the enum identifyer as a string.
e.g.
printf ("%s", MyEnumStringTable [ MyEnumVal] );
You can create the complete string table by
- marking the lines containing the complete typedef enum
- select menu C/C++.transform enum2Stringtab
You can create string table entries by
- marking the lines within the typedef enum
- select menu C/C++.transform enum2String
This makes it easy to keep the enum (on changes)
consistent to the string table.
Add the following lines to your _GVIMRC file:
31amenu C/C++.transform\ enum2Stringtab :s#[
]*\\(\\w\\+\\)#/* \\1 */ "\\1"#<CR>o};<ESC>u Ostatic
const char* const Names[] = {<ESC><CR>/sdfsdf<CR>
31vmenu C/C++.transform\ enum2Stringtab :s#[
]*\\(\\w\\+\\)#/* \\1 */ "\\1"#<CR>o};<ESC>u Ostatic
const char* const Names[] = {<ESC><CR>/sdfsdf<CR>
31amenu C/C++.transform\
]*\\(\\w\\+\\)#/* \\1 */
31vmenu C/C++.transform\
]*\\(\\w\\+\\)#/* \\1 */

enum2String :s#[
"\\1"#<CR>o}<ESC>/sdfsdf<CR>
enum2String :s#[
"\\1"#<CR>o}<ESC>/sdfsdf<CR>

hint: '/sdfsdf' is added for deactivating search


highlighting,
ok, you'll sure find a better way to do this.

http://www.vim.org/tips/tip.php?tip_id=107 (1 of 2) [18/02/2004 14:44:33]

Tip #107 - C/C++: convert enum to string table : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Mail signature rotation: Supersimple one-line solution | Toggle a fold with a single keystroke >>

Additional Notes
dion@erebus.demon.nl, September 5, 2001 6:56
You can use :noh to reset highlighting.
erwjjjsudu@eufguweguh.com, January 20, 2004 7:07
ilrhgodgfnhioergwergod doesnt exist anymore
boobies, January 20, 2004 7:07
ftvggyBlank note? Not much of a note eh?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=107 (2 of 2) [18/02/2004 14:44:33]

SourceForge
Logo

Tip #108 - Toggle a fold with a single keystroke : vim online

not logged in (login)

Home
Search

Tip #108: Toggle a fold with a single keystroke


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 79/36, Viewed by 2894

created: September 6, 2001 2:51


author: Max Ischenko

complexity: intermediate
as of Vim: 6.0

When viewing/editing a folded file, it is often needed


to inspect/close some fold.
To speed up these operation use the following (put in
your $HOME/.vimrc):
" Toggle fold state between closed and opened.
"
" If there is no fold at current line, just moves
forward.
" If it is present, reverse it's state.
fun! ToggleFold()
if foldlevel('.') == 0
normal! l
else
if foldclosed('.') < 0
. foldclose
else
. foldopen
endif
endif
" Clear status line
echo
endfun
" Map this function to Space key.
noremap <space> :call ToggleFold()<CR>
See :help folding for more information about folding.
rate this tip

Life Changing

Helpful

<<C/C++: convert enum to string table | jump between files >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=108 (1 of 3) [18/02/2004 14:44:36]

Unfulfilling

rate

Tip #108 - Toggle a fold with a single keystroke : vim online

danny@spesh.com, September 22, 2001 0:10


isn't this what 'za' does? would it be better to just
map space to za?
click66@hotmail.com, December 16, 2001 14:42
The problem with just maping space to za is that it
wont function as space if it isnt on the folded line.
brederek@tzi.de, May 21, 2002 13:18
This command breaks the behavior of <Space> outside
folds: it moves the
cursor 3 columns instead of 1, at least for me. Fix: I
use
normal! "
instead of
normal! l
Anonymous, July 7, 2002 9:16
Check and make sure you didn't paste in any extra
spaces at the end of the "normal" line. It was moving
too far for me, too, but now moves one space since I
deleted the space after the "l" which I had pasted in
there.
David Fishburn, May 31, 2003 18:25
This line:
noremap <space> :call ToggleFold()<CR>
Should be changed to:
nnoremap <space> :call ToggleFold()<CR>
Without doing that, you cannot use the <space> to
represent characters, for example:
4c<space>
Would mean change the next 4 characters.
ppa-nsu@mail.ru, June 2, 2003 23:09

http://www.vim.org/tips/tip.php?tip_id=108 (2 of 3) [18/02/2004 14:44:36]

Tip #108 - Toggle a fold with a single keystroke : vim online

There is more shorter way to do the same:


nnoremap <silent> <space> :exe 'silent! normal!
za'.(foldlevel('.')?'':'l')<cr>
Explanation:
- 'normal! za' toggles folds.
- 'silent!' allows to avoid error message when current
line doesn't
delong to fold.
- (foldlevel('.')?'':'l') adds forward moving only if
current line
doesn't delong to fold.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=108 (3 of 3) [18/02/2004 14:44:36]

SourceForge
Logo

Tip #109 - jump between files : vim online

not logged in (login)

Home
Search

Tip #109: jump between files


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 27/21, Viewed by 1346

created: September 6, 2001 2:53


author: kirillm

complexity: basic
as of Vim: 5.7

Often I know I'm likely to edit many files. I run 'vim


*.pl' and get a whole bunch of open files.
To make jumping between files to a pleasure, I defined
to mapss:
map <f1> :previous<cr>
map <f2> :next<cr>
Press F1 to go back and F2 to go forward.
-Kirill
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Toggle a fold with a single keystroke | text->html table converter. >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=109 [18/02/2004 14:44:38]

SourceForge
Logo

Tip #110 - text->html table converter. : vim online

not logged in (login)

Home
Search

Tip #110: text->html table converter.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/3, Viewed by 910

created: September 7, 2001 2:40


author: Wenzhi Liang

complexity: intermediate
as of Vim: 5.7

Below are two functions and a mapping which will convert lines of plain text into
HTML table code.
For example, you have several lines like:
----------------------------------------------1
2
3
4
5
6
--------------------------------------------------by visualizing all the 7 lines and press <F5>, you can change the text into
<table><tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr><tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr></table>
which will eventually render into a table.
So the rule is:
Every line is a table item, every empty line means starting of a new table row.

"A text->html table code converter


"By: Wenzhi Liang wzhliang@yahoo.com
"You can distribute/change this file freely as long as you keep the title area. Thanks
func Table()
let end=line("'>")
let start=line("'<")
http://www.vim.org/tips/tip.php?tip_id=110 (1 of 3) [18/02/2004 14:44:40]

Tip #110 - text->html table converter. : vim online

let i=start
wh i <= end
exe ":" . i
let e=Empty()
if e == 1
exe "normal I</tr><tr> "
else
exe "normal I<td> A</td> >>"
endif
let i=i+1
endwh
exe "normal o</tr></table> <<"
exe ":" . start
exe "normal O<table><tr> <<"
endfunc
vmap <F5> <ESC>:call Table()<CR>
func Empty()
let line_nr= line (".")
let a=getline ( line_nr )
let m=match(a, "\\S")
if m == -1
return 1
else
return 0
endif
endfunc
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<jump between files | Printing with syntax highlighting independent of your normal highlighting >>

Additional Notes
wzhliang@yahoo.com, September 7, 2001 2:48
Sorry. The character not properly displayed should be <CTL-[>
meezer@mailandnews.com, September 12, 2001 2:24

http://www.vim.org/tips/tip.php?tip_id=110 (2 of 3) [18/02/2004 14:44:40]

Tip #110 - text->html table converter. : vim online

or
:s/\(\S\+\)/<TD>\1<\/TD><CR>:'<,'>s/^\s*$/<\/TR><TR><CR>'>o</TR></TABLE><ESC>'<O<TABLE><TR><ESC>
.. for those that like compact but unreadable
Anonymous, September 12, 2001 2:25
make that
:map <F5>
:s/\(\S\+\)/<TD>\1<\/TD><CR>:'<,'>s/^\s*$/<\/TR><TR><CR>'>o</TR></TABLE><ESC>'<O<TABLE><TR><ESC>
to work in the same manner as the original posting
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=110 (3 of 3) [18/02/2004 14:44:40]

SourceForge
Logo

Tip #111 - Printing with syntax highlighting independent of your normal highlighting : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #111: Printing with syntax highlighting independent of your


normal highlighting
tip karma

Rating 8/5, Viewed by 1125

created: September 7, 2001 9:50


author: Aric Blumer

complexity: intermediate
as of Vim: 6.0

I have found it undesirable to use :hardcopy directly


because it uses the current syntax highlighting to
determine how to print the text. For example, I like to
print comments in italics, but I don't like italic fonts
on the screen. This tip will show you how to set up a
colorscheme for printing and use it only when you print.
I copied an existing colorscheme to
~/.vim/colors/print.vim, and changed all the lines like
this:
highlight Normal ctermbg=DarkGrey ctermfg=White
guifg=White guibg=grey20
to this:
highlight clear Normal
Then I set the syntax groups how I wanted them to be
printed on the printer:
highlight
Comment
term=italic
highlight Constant
term=bold
cterm=bold
etc....

cterm=italic

gui=italic

gui=bold

I then defined the following command in my .vimrc file:


command! -nargs=* Hardcopy call DoMyPrint("<args>")
And, finally, I defined this function in my .vimrc:
function DoMyPrint(args)
let colorsave=g:colors_name
color print
exec "hardcopy ".a:args
exec 'color '.colorsave
endfunction

http://www.vim.org/tips/tip.php?tip_id=111 (1 of 2) [18/02/2004 14:44:43]

Tip #111 - Printing with syntax highlighting independent of your normal highlighting : vim online

After this is complete, you can do:


:Hardcopy > /tmp/out.ps
or just
:Hardcopy
(Note the capital H)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<text->html table converter. | Back and forth between indented lines again >>

Additional Notes
Anonymous, September 7, 2001 14:06
This does, BTW, assume that you are already using a
colorscheme.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=111 (2 of 2) [18/02/2004 14:44:43]

SourceForge
Logo

Tip #112 - Back and forth between indented lines again : vim online

not logged in (login)

Home
Search

Tip #112: Back and forth between indented lines again


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 19/7, Viewed by 1179

created: September 11, 2001 17:48


author: Thore Karlsen

complexity: intermediate
as of Vim: 5.7

Paul Wright posted a tip which explained how to jump


back and forth between lines with the same indentation
level. I do this a lot, so I came up with this slightly
more comprehensive solution.
The example mappings below work as follows:
[l and ]l jump to the previous or the next line with the
same indentation level as the one you're currently on.
[L and ]L jump to the previous or the next line with an
indentation level lower than the line you're currently
on.
These movements also work in visual mode and (only as of
one of the 6.0 alpha versions) in operator pending mode,
meaning that you can do a d]l. The motion is specified
as being exclusive when in operator pending mode.
When might you use this? If you're writing programs in
Python, Haskell, or editing XML files, they will be very
useful. E.g. in XML you can jump to the outer enclosing
tag, or the next matching tag. I use it for practically
anything I edit, so it's not limited to this.

"
" NextIndent()
"
" Jump to the next or previous line that has the same
level or a lower
" level of indentation than the current line.
"
" exclusive (bool):
true: Motion is exclusive
"
false: Motion is inclusive
" fwd (bool):
true: Go to next line
"
false: Go to previous line
http://www.vim.org/tips/tip.php?tip_id=112 (1 of 3) [18/02/2004 14:44:48]

Tip #112 - Back and forth between indented lines again : vim online

" lowerlevel (bool):


indentation level
"
indentation level
" skipblanks (bool):
"

true:

Go to line with lower

false: Go to line with the same


true: Skip blank lines
false: Don't skip blank lines

function! NextIndent(exclusive, fwd, lowerlevel,


skipblanks)
let line = line('.')
let column = col('.')
let lastline = line('$')
let indent = indent(line)
let stepvalue = a:fwd ? 1 : -1
while (line > 0 && line <= lastline)
let line = line + stepvalue
if ( ! a:lowerlevel && indent(line) == indent ||
\ a:lowerlevel && indent(line) < indent)
if (! a:skipblanks || strlen(getline(line)) > 0)
if (a:exclusive)
let line = line - stepvalue
endif
exe line
exe "normal " column . "|"
return
endif
endif
endwhile
endfunc
" Moving back and
indentation.
nnoremap <silent>
nnoremap <silent>
nnoremap <silent>
nnoremap <silent>
vnoremap <silent>
1)<cr>m'gv''
vnoremap <silent>
1)<cr>m'gv''
vnoremap <silent>
1)<cr>m'gv''
vnoremap <silent>
1)<cr>m'gv''
onoremap <silent>
onoremap <silent>
onoremap <silent>
onoremap <silent>
http://www.vim.org/tips/tip.php?tip_id=112 (2 of 3) [18/02/2004 14:44:48]

forth between lines of same or lower


[l
]l
[L
]L
[l

:call NextIndent(0, 0, 0, 1)<cr>


:call NextIndent(0, 1, 0, 1)<cr>
:call NextIndent(0, 0, 1, 1)<cr>
:call NextIndent(0, 1, 1, 1)<cr>
<esc>:call NextIndent(0, 0, 0,

]l <esc>:call NextIndent(0, 1, 0,
[L <esc>:call NextIndent(0, 0, 1,
]L <esc>:call NextIndent(0, 1, 1,
[l
]l
[L
]L

:call
:call
:call
:call

NextIndent(0,
NextIndent(0,
NextIndent(1,
NextIndent(1,

0,
1,
0,
1,

0,
0,
1,
1,

1)<cr>
1)<cr>
1)<cr>
1)<cr>

Tip #112 - Back and forth between indented lines again : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Printing with syntax highlighting independent of your normal highlighting | Translator in vim
(Windows solution) >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=112 (3 of 3) [18/02/2004 14:44:48]

SourceForge
Logo

Tip #113 - Translator in vim (Windows solution) : vim online

not logged in (login)

Home
Search

Tip #113: Translator in vim (Windows solution)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/1, Viewed by 1076

created: September 12, 2001 1:00


author: brz*

complexity: basic
as of Vim: 5.7

Hallo, today I found script "translate.vim", but on


Windows this will be probably difficult to run it (maybe
with Cygwin is it possible). I've simpler solution of
keymap for vim interlacing to dictionary:
Must exist file with vocabulary (e.g. "an-cs.txt"),
which is called for word under cursor. In 'normal' is
only displayed window with translations, in 'insert' is
word under cursor deleted and is insert selected form of
word from translantion window (select it by mouse and
than press right button: It works fine on W2k). Key
_F12_ is looking for "word", shifted _S-F12_ is looking
for "pattern".
For windows is needed agrep, which is localy placed on
http://www.tgries.de/agrep/index.html
map <F12> b"*yw<Esc>:! c:/bin/agrep -wih <C-R>*
"c:/dict/an-cs.txt"<CR>
imap <F12> <Esc>b"*yw<Esc>:! c:/bin/agrep -wih <C-R>*
"c:/dict/an-cs.txt"<CR>dwi <C-R>*
map <S-F12> b"*yw<Esc>:! c:/bin/agrep -ih <C-R>*
"c:/dict/an-cs.txt"<CR>
imap <S-F12> <Esc>b"*yw<Esc>:! c:/bin/agrep -ih <C-R>*
"c:/dict/an-cs.txt"<CR>dwi <C-R>*
brz* <brz@centrum.cz>
rate this tip

Life Changing

Helpful

Unfulfilling

<<Back and forth between indented lines again | Browsing by paragraph >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=113 (1 of 2) [18/02/2004 14:44:50]

rate

Tip #113 - Translator in vim (Windows solution) : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=113 (2 of 2) [18/02/2004 14:44:50]

SourceForge
Logo

Tip #114 - Browsing by paragraph : vim online

not logged in (login)

Home
Search

Tip #114: Browsing by paragraph


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 6/5, Viewed by 539

created: September 13, 2001 6:46


author: Manish Tehanguria

complexity: intermediate
as of Vim: 6.0

It can be done by reaching the blank lines in up and


down directions just by pressing
{
---paragraph
}
---paragraph

For going to the blank line above the


For going to the blank line below the

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Translator in vim (Windows solution) | Browsing by paragraph >>

Additional Notes
uws@xs4all.invalid, July 11, 2003 2:51
Also look at the ( and ) movements, which will take
jump to the next (or previous) sentence.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=114 [18/02/2004 14:44:52]

SourceForge
Logo

Tip #115 - Browsing by paragraph : vim online

not logged in (login)

Home
Search

Tip #115: Browsing by paragraph


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating -6/12, Viewed by 821

created: September 13, 2001 6:46


author: Manish Tehanguria

complexity: basic
as of Vim: 6.0

It can be done by reaching the blank lines in up and


down directions just by pressing
{
---paragraph
}
---paragraph

For going to the blank line above the


For going to the blank line below the

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Browsing by paragraph | Search all occurances of the word under cursor in all the open files >>

Additional Notes
pnwms@themail.com, September 18, 2001 2:38
Documented in the quick ref...
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=115 [18/02/2004 14:44:55]

SourceForge
Logo

Tip #116 - Search all occurances of the word under cursor in all the open files : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #116: Search all occurances of the word under cursor in all the
open files
tip karma

Rating 74/45, Viewed by 1712

created: September 13, 2001 6:53


author: Manish Tehanguria

complexity: intermediate
as of Vim: 6.0

Sometimes it is useful to know all the occurances of the


word under cursor in all the open files. This can be
done by pressing [I ( bracket and capital I ) . it shows
the results found in the command window.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Browsing by paragraph | FAST SEARCH ACROSS THE PROJECT >>

Additional Notes
zellerin@volny.cz, September 21, 2001 6:19
Is this right? I always thought (and docs :he [I seems
to say) it shows occurences in current file and files
it includes (omitting comments), not in all open
files...
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=116 [18/02/2004 14:44:57]

SourceForge
Logo

Tip #117 - FAST SEARCH ACROSS THE PROJECT : vim online

not logged in (login)

Home
Search

Tip #117: FAST SEARCH ACROSS THE PROJECT


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 32/11, Viewed by 1754

created: September 13, 2001 7:00


author: Manish Tehanguria

complexity: intermediate
as of Vim: 6.0

Searching for a word across the project wastes most of


the developres time, which can be avoided by the use of
GNU Id_utils with VIM.
The procedure needs to be followed is as follows:
download GNU idutils 3.2d (mkid,lid,fid,fnid,xtokid)
from http://www.mossbayeng.com/~ron/vim/builds.html
uncompress and store these files in the directory from
where vim is running.
goto the top level directory of the project, and run
mkid, it will create ID file in that directory (As it is
time consuming process, so be patient). copy this file
ID to the directory from where vim is running.
USAGE:
Put these lines in your .vimrc:
map _u :call ID_search()<Bar>execute "/\\<" . g:word .
"\\>"<CR>
map _n :n<Bar>execute "/\\<" . g:word . "\\>"<CR>
function ID_search()
let g:word = expand("<cword>")
let x = system("lid --key=none ". g:word)
let x = substitute(x, "\n", " ", "g")
execute "next " . x
endfun
To use it, place the cursor on a word, type "_u" and vim
will load the file
that contains the word. Search for the next ocurance of
the word in the same
file with "n". Go to the next file with "_n".
The mapping of "_u" and "_n" can be done to some other
key as per your preference but I use ^K and ^L for this

http://www.vim.org/tips/tip.php?tip_id=117 (1 of 2) [18/02/2004 14:44:59]

Tip #117 - FAST SEARCH ACROSS THE PROJECT : vim online

purpose.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Search all occurances of the word under cursor in all the open files | Configuring gVim as Internet
Explorer 'View Source' editor >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=117 (2 of 2) [18/02/2004 14:44:59]

SourceForge
Logo

Tip #118 - Configuring gVim as Internet Explorer 'View Source' editor : vim online

not logged in (login)

Home
Search

Tip #118: Configuring gVim as Internet Explorer 'View Source' editor


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 342/115, Viewed by 16728

created: September 16, 2001 12:59


author: Freddy Vulto

complexity: basic
as of Vim: 5.7

Within the registry, you can specify the source editor to


be used by Internet Explorer when {View|Source} is
selected. Unfortunately, you can't specify a quoted
filename argument here, i.e. "%1". The editor specified is
supposed to handle filenames which contain spaces. This
will cause problems for Vim because Vim treats each space
as an argument separator. If an unquoted filename contains
spaces, Vim treats the filename as multiple arguments and
will open multiple files instead of one. To workaround this
problem a quoted filename has to be passed to Vim. This can
be done by creating the following Visual Basic Script file
gVim.vbs:
'--- gVim.vbs ---------------------------------------------------------------'function: Start gvim, combining multiple arguments to
single file argument.
'changes: 20010905: Quoted 'oWShell.Run' filename
argument, allowing spaces.
'
20010518: Created.
'author:
Freddy Vulto <fvu@fvu.myweb.nl>
' Making variable declaration mandatory
option explicit
dim oWShell, sArg, sFile
'
set
'
for

Create script object


oWShell = CreateObject("wscript.shell")
Loop through arguments
each sArg in wscript.arguments
' Add argument to filename
sFile = sFile & sArg & " "
next
' Remove excess space
sFile = Trim(sFile)
' Run Vim with file argument. Additional arguments:
' -R: View file readonly
' -c "set syntax=html": Use HTML syntax-highlighting
'
NOTE: Use "-c ""set ft=html""" to make it work for
http://www.vim.org/tips/tip.php?tip_id=118 (1 of 10) [18/02/2004 14:45:02]

Tip #118 - Configuring gVim as Internet Explorer 'View Source' editor : vim online

Vim v6.
oWShell.Run _
"""D:\Programs\Vim\Vim58\gvim.exe """ & _
"-R """ & sFile & """ " & _
"-c ""set syntax=html"""
' Destroy script object
set oWShell = NOTHING
The source editor now can be specified by adding the
following key to the registry:
HKEY_LOCAL_MACHINE
|- Software
|- Microsoft
|- Internet Explorer
|- View Source Editor
|- Editor Name
D:\Programs\Vim\gvim.vbs

(Default) =

Freddy Vulto <fvu@fvu.myweb.nl>


http://fvu.myweb.nl/Projects/Vim/Web/vim.htm

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<FAST SEARCH ACROSS THE PROJECT | Explorer startup and shutdown >>

Additional Notes
jake.howlett@ebone.com, September 19, 2001 7:09
Great tip! Thanks....
Any ideas why this would work in IE 5.5 but not in IE 5.01
? Strange....
Jake
jake.howlett@ebone.com, September 19, 2001 7:19

http://www.vim.org/tips/tip.php?tip_id=118 (2 of 10) [18/02/2004 14:45:02]

Tip #118 - Configuring gVim as Internet Explorer 'View Source' editor : vim online

Ignore that last note. Solved.


Was trying to do the same with TextPad. There is an option
in there to "Allow multiple files on the command line". I
needed to turn this off.
Sorry to polute this forum with non-Vim stuff ;)
Jake
revscat@swbell.net, September 19, 2001 7:45
The registry key given towards the end of this tip doesn't
exist on my Win2K/IE6 system. A search for "notepad" in
the registry turned up nothing relating to IE. Looks like
M$ might have disabled this customization feature.
revscat@swbell.net, September 19, 2001 7:54
Please disregard my last comment. Serves me right for not
reading the instructions carefully. This *does* work on
Win2K/IE6.
piaip@csie.ntu.edu.tw, September 20, 2001 20:01
How about adding a 'Install as default source editor of
InternetExplore' option to the nsis win32-installer?
sf@vikas.mailshell.com, September 24, 2001 10:54
How to use this VBS script exactly?
sf@vikas.mailshell.com, September 24, 2001 10:55
Disregard my previous comment. Just saw the note about the
registry change later.
piaip@csie.ntu.edu.tw, September 24, 2001 18:12
I made a Win32 executable stub loader to do the same as
the VBS:
http://www.csie.ntu.edu.tw/~b7506051/vim/VimThis0924.zip
(It'll query the registry for GVIM instead of hard-coded
like the VBS above)
Just unzip and get the VimThis.exe, point your registry to
its path.
rekcah@ecad.org, September 25, 2001 13:02
Excellent, been trying to do this forever. Hated it when
the file was "Too big for notepad" :)
thanx
alan
scrott@users.sf.net, November 8, 2001 18:30

http://www.vim.org/tips/tip.php?tip_id=118 (3 of 10) [18/02/2004 14:45:02]

Tip #118 - Configuring gVim as Internet Explorer 'View Source' editor : vim online

This tip kicks ass. As a minor modification I found it was


nice to use the command:
oWShell.Run _
"""gvim.exe """ & _
"-R """ & sFile & """ " & _
"-c ""set syntax=html""" & _
"-c ""set filetype=html"""
By setting the filetype you can use advanced matching
functionality (see vimscript #39) so you can match html
tags.
robertx2@speakeasy.net, November 11, 2001 9:06
This is terrific! NotePad is so-o-o clunky. However, I
would like to be able to select a portion or all of the
source and save it off as a file. I see in the gvim.vbs
that there is a line that makes the file Read-only. My
scripting skills are limited to learning PHP so far. If I
remove the -R argument, will I be able to write the file
to a directory or the desktop? And, while I'm thinking of
it, can the script be adjusted to accomodate saving to a
particular directory? I don't want to mess up the entire
script. Thanks. Robert Roberts
robertx2@speakeasy.net, November 11, 2001 9:25
Disregard the above except as an exercise, or just to
know.
I've found a workaround in tip no. 71 ..."Transfer text
between two gvim sessions using clipboard",
http://vim.sourceforge.net/tips/tip.php?tip_id=71
AND --- it works.
Thanks to all. Vim Rocks!
Robert Roberts
leifw @(at)@ bigfoot .(dot). com, December 13, 2001 6:57
To summarize the improvements given above and to simplify
the installation procedure, here's my rendition of this
tip:
1. Copy the following into a filenamed gvim.vbs. A good
place to put it is the root of your vim tree (e.g.,
c:\program files\vim\).
-------------Begin File: gvim.vbs----------------'--- gVim.vbs ---------------------------------------------------------------'function: Start gvim, combining multiple arguments to
single file argument.
'changes: 20010905: Quoted 'oWShell.Run' filename
argument, allowing spaces.
'
20010518: Created.

http://www.vim.org/tips/tip.php?tip_id=118 (4 of 10) [18/02/2004 14:45:02]

Tip #118 - Configuring gVim as Internet Explorer 'View Source' editor : vim online

'author:

Freddy Vulto <fvu@fvu.myweb.nl>

' Making variable declaration mandatory


option explicit
dim oWShell, sArg, sFile
'
set
'
for

Create script object


oWShell = CreateObject("wscript.shell")
Loop through arguments
each sArg in wscript.arguments
' Add argument to filename
sFile = sFile & sArg & " "
next
' Remove excess space
sFile = Trim(sFile)
' Run Vim with file argument. Additional arguments:
' -R: View file readonly
' -c "set syntax=html": Use HTML syntax-highlighting
'
NOTE: Use "-c ""set ft=html""" to make it work for
Vim v6.
oWShell.Run _
"""d:\program files\vim\vim60\gvim.exe """ & _
"-R """ & sFile & """ " & _
"-c ""set syntax=html""" & _
"-c ""set filetype=html"""
' Destroy script object
set oWShell = NOTHING
-------------End File: gvim.vbs----------------2. Change the path in gvim.vbs to point to your copy of
gvim.
3. Save the following as a file named gvim.ie.vbs.reg (or
something like that):
-------------Begin File: gvim.ie.vbs.reg----------------REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet
Explorer\View Source Editor\Editor Name]
@="c:\\Program Files\\vim\\gvim.vbs"
-------------End File: gvim.ie.vbs.reg----------------4. Change the path in gvim.ie.vbs.reg to point to your
copy of gvim.
5. Double click on the file gvim.ie.vbs.reg, or if you're
already editing it in vim, execute the command line
:!start regedit "c:\program files\vim\gvim.ie.vbs.reg"
Of course, you can produce the file name by hitting
control-r %.
digitect@mindspring.com, January 4, 2002 19:29
http://www.vim.org/tips/tip.php?tip_id=118 (5 of 10) [18/02/2004 14:45:02]

Tip #118 - Configuring gVim as Internet Explorer 'View Source' editor : vim online

Hmm... guess this doesn't work for Windows 95 (IE5.5). I


get "Error: ActiveX component can't create object:
'wscript.shell'", "Source: Microsoft VBScript runtime
error".
Any ideas?
john_mcdonnell.shift2.yahoo.company, January 8, 2002 13:48
The person who reported a problem with Win95 should
probably update their Windows Scripting Host. Try
http://www.microsoft.com/msdownload/vbscript/scripting.asp
fcmensa@hotmail.com, February 26, 2002 13:36
I added the registry entry for my Internet Explorer 6 and
it works, although I only used Editorname=gvim.exe. So it
looks like that IE 6 automatically puts quotes around
filenames (and vim therefore can read \winnt\temporary
internet files\... without any issues).
Or am I missing something?
Best regards, fcmensa!

icewalker_au@yahoo.com.au, March 27, 2002 15:51


Thank you very much. I now have a real editor to work with
html files, not that excuse of an editor called Notepad!
Keep up the good work.
amohamed@mail.totalemed.com, May 14, 2002 13:41
umm... What this does for me is to open gvim.vbs instead
of the actual source. Anyone know what I'm doing wrong?
Thanks.
amohamed@mail.totalemed.com, May 14, 2002 13:48
Ignore that last one. I figured out what I was doing wrong
(set the default for *.vbs to edit with Vim instead of
execute).
gcauthon@hotmail.com, September 12, 2002 11:17
I added this by just specifying gvim.exe and it works on
filenames with spaces on IE6.
piaip@csie.ntu.edu.tw, September 25, 2002 10:08

http://www.vim.org/tips/tip.php?tip_id=118 (6 of 10) [18/02/2004 14:45:02]

Tip #118 - Configuring gVim as Internet Explorer 'View Source' editor : vim online

For people who hates VB scripts or does not want to have


an extra .vbs file,
Look at: http://radio.weblogs.com/0100529/WinXp/#ie_editor
1. Open regedit, go to HKEY_LOCAL_MACHINE
2. Expand the key "Software"
3. Expand the key "Microsoft "
4. Expand the key "Internet Explorer"
5. Create key "View Source Editor" under "Internet
Explorer"
6. Create key "Editor Name" under "View Source Editor"
7. Change the default value of key "Editor Name" to
something named after the view you wish to use, in this
example "vi.exe"
8. Close things up and expand HKEY_CLASSES_ROOT
9. Expand the key "applications"
10. Create a new subkey under "applications" with the
same name from above. Ex "vi.exe"
11. Create a new subkey under the key created in the
last step called shell.
12. Create a new subkey under shell called open.
13. Create a new subkey under edit called command.
14. Change the default value under the key command to
the full path to your editor in quotes plus "%1" (with the
quotes) Ex: "c:\vi\vi.exe" "%1"
Anonymous, February 1, 2003 10:14
An alternative (quick and dirty) solution is to rename
notepad.exe (e.g. to _notepad.exe), and create a batch
file called notepad.bat that runs vim instead. It works
for me!
tbellitta@aol.com, February 10, 2003 21:09
This site is amazing. Collectively the ideas in here, used
in combination, made it possible for IE 6 to view the
source again.
I tried everything, or at least I had thought. Nothing
worked. After reading the second to last post on this
board, and following its info, the ever so awful text
editor, notepad, reappeared for the first time in months.
So much for 'cleaning out the cache.'
Riddle me this; why did the creating of some registry
strings cause my View Source option to work again? The
keys I created seemed like legitimate key names, why
weren't they in my registry to start with? With the new
keys, View Source Editor, Editor Name and the value
Notepad.exe, will the view source issue ever arise, or has
it been forced into the backbone of IE6 for good?
Oh, btw, what is Vim? J/k!
Thanks guys, and girls

http://www.vim.org/tips/tip.php?tip_id=118 (7 of 10) [18/02/2004 14:45:02]

Tip #118 - Configuring gVim as Internet Explorer 'View Source' editor : vim online

flash@atttglobal.neet, March 19, 2003 22:49


Fantastic - I got my notepad working again after 2 months
without it! - just by making the keys..
Thanks!
shiloh at rvglug dot org, May 6, 2003 10:36
Just to take this great tip one step farther. Here's how I
added syntax highlighting to my source code.
" Open html files from Internet Explorer with certain
commands
autocmd BufRead *\[[0-9]] runtime! syntax/html.vim
richard@encounterit.co.uk, June 6, 2003 5:20
Here's how I added syntax colouring to the sourcecode.
Create a file scripts.vim in your user directory with the
following code in. See :help filetype for more details.
This also allows you to start creating an html file and
type :filetype detect to get syntax highlighting as well.
I'm sure the detection code can be improved, but it works
for a first pass!
if did_filetype() " filetype already set..
finish " ..don't do these checks
endif
"Automatic detection of html files.
let s:line1 = getline(1)
let s:line2 = getline(2)
if s:line1 =~ '^<html*' || s:line2 =~ '^<html*'
set ft=html
endif
hashstat at eudoramail dot com, July 14, 2003 9:37
You can avoid VBScript and EXEs by using a shortcut to
Vim. This is especially useful on corporate computers
where, for security reasons, scripting may be disabled.
1. Right-click gvim.exe in Windows Explorer and click
'Create Shortcut'.
2. Rename the shortcut to 'gvim_ie'. Running a directory
listing (dir) at a command prompt reveals the real name of
the shortcut as 'gvim_ie.lnk'.
3. Right-click the shortcut and click 'Properties'. Add
the desired command-line parameters to the 'Target' field
(i.e. '"C:\Program Files\vim\vim62\gvim.exe" -M -c "set
syntax=html" -c "set ft=html"').
4. Point the 'Editor Name' registry key to the link.
http://www.vim.org/tips/tip.php?tip_id=118 (8 of 10) [18/02/2004 14:45:02]

Tip #118 - Configuring gVim as Internet Explorer 'View Source' editor : vim online

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet
Explorer\View Source Editor\Editor Name]
@="C:\\Program Files\\vim\\vim62\\gvim_ie.lnk"
This method was tested using Vim 6.2 on Win2K and Vim 6.1
on Win98.
yongbing@hotmail.com, August 7, 2003 17:07
Instead of using regedit to change "View Source Editor"
directly, we can also use TweakUI for Windows XP (one of
the "Powertoys for Windows XP").
Navigate to "Internet Explorer->View Source". Click
"Change Program".
It changes the registry for you. (Exactly the same effect
as using regedit.)
Regards.
rweaver at austin dot rr dot com, September 12, 2003 11:27
Love it! I've set up IE to do this (via the "shortcut"
method). Does anyone know how to do this for Mozilla
and/or Netscape 7.x?
Regards.
zzapper@ntlworld.com, September 26, 2003 9:14
I vote for the shortcut method! (simplest)
mrgrier at yahoo dot com, January 6, 2004 1:34
The easiest way to get rid of this spaces problem is to
rename your
Temporary Internet Files
folder to something without any spaces, i.e.
TempInetFiles
Windows will complain you're changing a system file folder
name, but it works great, at least on my Win98se.
molivieri@yahoo.com, February 11, 2004 13:47

http://www.vim.org/tips/tip.php?tip_id=118 (9 of 10) [18/02/2004 14:45:02]

Tip #118 - Configuring gVim as Internet Explorer 'View Source' editor : vim online

When I set this up, I had to create the keys for the View
Source Editor, and its subkey "Editor Name".
In regedit:
1. Right Click on
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer
and select "New" -> "Key".
2. Name the new key "View Source Editor"
3. Right click on the new key, select "New" -> "Key"
4. Name that new key "Editor Name"
5. In the right pane of regedit, double click "(Default)".
This will open a pop-up to edit the value.
6. Enter the name of the shortcut, as in C:\Program
Files\Vim\vim62\vim_ie.lnk
Right away I was able to View Source with VIM. If you have
tried to View Source before making these changes, I
suspect you would have to restart IE or even reboot.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=118 (10 of 10) [18/02/2004 14:45:02]

SourceForge
Logo

Tip #119 - Explorer startup and shutdown : vim online

not logged in (login)

Home
Search

Tip #119: Explorer startup and shutdown


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/5, Viewed by 2467

created: September 22, 2001 8:42


author: Rudy Moore

complexity: intermediate
as of Vim: 6.0

I really like the new explorer window, but I wanted it


to function a little more seemlessly in the editor. The
following code does two things. First, the explorer is
started when vim is started.
I also noticed and fixed
that the explorers size is not equal to the window size,
hence the strange behavior when popping between two
windows. The other major function of the code is to
close the explorer when it's the only window that's
left. I'd actually like to take this a step further and
close the window if the last _document_ window is
closed. I'd prefer that multiple explorers or help
windows don't keep the application running - only having
a file open keeps the application running. But I didn't
see an easy way to do this... anyone else?
BTW, thank you Bram for the help figuring this out.
Code (which currently lives in my _vimrc):
" FILE BROWSER STARTUP
func OpenFileWindow()
" :runtime plugin/*.vim " this would be useful if you
were calling this
"
function from the .vimrc directly
let g:explDetailedList=1 " show size and date by default
let g:explVertical=1 " Split vertically
let g:explStartRight=0
" Put new explorer window to
the left of the current window
:Sexplore
set nonu
set winwidth=15 " Make the width of the window match the
explorer setting
"let g:explVertical=0 " Split vertically
doautocmd fileExplorer BufEnter " Forces the directory
refresh to occur
:winc l " change to the document window
endfunc

http://www.vim.org/tips/tip.php?tip_id=119 (1 of 3) [18/02/2004 14:45:05]

Tip #119 - Explorer startup and shutdown : vim online

func CloseIfLast()
if exists("b:completePath") " this is how I determine
that I'm in an explorer window
let n = winnr()
wincmd p
if n == winnr()
quit " quit the window
endif
wincmd p
endif
endfunc
if has("autocmd")
if !exists("rudyautocommands")
let rudyautocommands = 1
autocmd VimEnter * call OpenFileWindow()
autocmd WinEnter * call CloseIfLast()
endif
endif

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Configuring gVim as Internet Explorer 'View Source' editor | Compiling Java with Sun JDK (javac)
within VIM >>

Additional Notes
the_orn@yahoo.com, September 22, 2001 8:49
Ack.

All my tabs disappeared.

" FILE BROWSER STARTUP


func OpenFileWindow()
" :runtime plugin/*.vim
if you were calling this

This one uses spaces...

" this would be useful


"

.vimrc directly
let g:explDetailedList=1
"
default
let g:explVertical=1
"
let g:explStartRight=0
"
window to the left of the current
:Sexplore
set nonu

http://www.vim.org/tips/tip.php?tip_id=119 (2 of 3) [18/02/2004 14:45:05]

function from the


show size and date by
Split vertically
Put new explorer
window

Tip #119 - Explorer startup and shutdown : vim online

set winwidth=15
" Make the width of the
window match the explorer setting
"let g:explVertical=0
" Split vertically
doautocmd fileExplorer BufEnter " Forces the
directory refresh to occur
:winc l
" change to the
document window
endfunc
func CloseIfLast()
if exists("b:completePath") "
determine that I'm in an explorer
let n = winnr()
"
if the window number is the same
wincmd p
"
same window.
if n == winnr()
quit
"
endif
wincmd p
endif
endfunc

this is how I
window
pop between windows,
then they're the

quit the window

if has("autocmd")
if !exists("rudyautocommands")
let rudyautocommands = 1
autocmd VimEnter * call OpenFileWindow()
autocmd WinEnter * call CloseIfLast()
endif
endif
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=119 (3 of 3) [18/02/2004 14:45:05]

SourceForge
Logo

Tip #120 - Compiling Java with Sun JDK (javac) within VIM : vim online

not logged in (login)

Home
Search

Tip #120: Compiling Java with Sun JDK (javac) within VIM
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 50/23, Viewed by 4448

created: September 24, 2001 0:44


author: a jdk user :)

complexity: basic
as of Vim: 6.0

The $VIMRUNTIME/compiler has 'jikes.vim', but there's


nothing for traditional Sun JDK(javac),
so I tried (Only tested on Win 2000):
" Vim Compiler File
javac.vim
" Compiler: Sun/IBM JDK: Javac
if exists("current_compiler")
finish
endif
let current_compiler = "javac"
" Javac defaults to printing output on stderr and no
options can convert, so we have to set 'shellpipe'
setlocal shellpipe=2>
" 2> works on Win NT and UNIX
setlocal makeprg=javac\ #<.java
setlocal errorformat=%f:%l:%m
" Sorry I'm not familiar with 'errorformat', so I set it
very simple.
rate this tip

Life Changing

Helpful

Unfulfilling

<<Explorer startup and shutdown | Using vim as a syntax-highlighting pager >>

Additional Notes
bjorklid at jyu.fi, October 19, 2001 10:13

http://www.vim.org/tips/tip.php?tip_id=120 (1 of 4) [18/02/2004 14:45:08]

rate

Tip #120 - Compiling Java with Sun JDK (javac) within VIM : vim online

If you have a Win 9x or ME, you might want to try a


handy little utility called stderr, which will direct
errorsteram to stdout. can be found at
http://www.teaser.fr/~amajorel/stderr/
The errorformat I'm using (copied it from somewhere):
%A%f:%l:\ %m,%-Z%p^,%-C%.%#
no alternative filename to substitute for '#', January 25, 2002 0:40
i am running VIM 6 on Redhat Linux 7.0, i get this
error on using the above said. Any solutions ?
rickziegler@attbi.com, February 13, 2002 10:57
I also got the same error.
To make it work, I
replaced the alternate file name ( # ) with the real
file name ( % ) on the makeprg line:
setlocal makeprg=javac\ %
laugh@starpower.net, July 21, 2002 10:26
The version of javac I have (JDK1.4) now has an option
to send compiler messages to a file instead of to
stderr:
javac -Xstdout jerrors.txt ...
Note that any -X option is nonstandard. However, since
I'm on Win98 and its DOS shell is so flaky (no way to
redirect stderr?!?), -Xstdout was a boon. I very
nearly had to write a Java class to run javac for me
and do useful stuff with the error messages!
thane777@yahoo.com, July 25, 2002 23:34
I am running on XP. Is there a way to redirect stderr
in XP? I want mine to display on the bottom of my gvim
window.
Thanx.
thane
Koenraad Heijlen <vipie AD ulyssis DOT org>, July 30, 2002 7:24

http://www.vim.org/tips/tip.php?tip_id=120 (2 of 4) [18/02/2004 14:45:08]

Tip #120 - Compiling Java with Sun JDK (javac) within VIM : vim online

I made a small adjustment to the errorformat listed in


the vim documentation,
it shows the symbol in the 'symbol: blabla' line as
part of the error message (%m).
There is still one problem with %p, don't know if it
can be fixed easily:
the javac compiler outputs the line with the error and
uses the caret (^) to
indicate the correct location of the error.
BUT it uses spaces, not tabs. Since I use tabs for my
intendation, the column
number is wrong.
--cut-:setlocal errorformat=%A%f:%l:\ %m,%-Z%p^,%Csymbol\ \
:\ %m,%-C%.%#
--end-and it should output something like this :
Composition.java|10 col 34| cannot resolve symbol class
ClassNameHere
...
mohamed1999@free.fr, December 20, 2002 10:08
Hi,
Try these commands (compiler\ant.vim) to fix the
problem when using quickFix with ant and windows
(standard error cannot be redirect).
setlocal makeprg=ant\ -l\ .ant.log
set makeef=.ant.log
set shellpipe=
have fun,
Mohamed,
shive_x1@yahoo.com.tw, December 25, 2002 8:00

http://www.vim.org/tips/tip.php?tip_id=120 (3 of 4) [18/02/2004 14:45:08]

Tip #120 - Compiling Java with Sun JDK (javac) within VIM : vim online

i can javac my file


ex:
but

:!javac c:\xxx.java

<===it's can work!

ican't java my file

ex:
:!java c:\xxx(xxx.class)
<===Exception in
thread "main" java.lang.NoClassDefFoundError: c:\xxx
shell returned 1
Hit any key to close this window...
how can i use java in vim
please tell me and send to my email because my english
is very bad!
thanks!
Anonymous, September 20, 2003 9:56
Yes, XP can redirect stderr.
Just do:
:set shellpipe=>\ %s\ 2>&1
Then, :make will be expanded to {makeprg} > {errorfile}
2>&1
hadding (at) remove_mailandnews.com, November 7, 2003 2:44
If you have foo.java after you run javac you do java
foo NOT java foo.class else you get the exception in
thread main message
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=120 (4 of 4) [18/02/2004 14:45:08]

SourceForge
Logo

Tip #121 - Using vim as a syntax-highlighting pager : vim online

not logged in (login)

Home
Search

Tip #121: Using vim as a syntax-highlighting pager


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 70/38, Viewed by 5895

created: September 24, 2001 3:51


author: Mary Ellen Foster

complexity: intermediate
as of Vim: 5.7

If you want to use Vim's syntax highlighting in a "more"style pager, here's


one way to set it up:
First, create a vimrc like the following -- I called
mine ~/.vimrc.more
---8<---cut here---8<--" No compatibility -- necessary for mappings to work.
set nocompatible
" Status line
set laststatus=0
set cmdheight=1
set nomodifiable " Only in version 6.0
set readonly
" Syntax colouring -- lines taken from syntax.txt
discussion on colour xterms.
" See ':help color-xterm'. Use appropriate lines for
your own set-up.
if has("terminfo")
set t_Co=16
set t_Sf= [3%p1%dm
set t_Sb= [4%p1%dm
else
set t_Co=16
set t_Sf= [3%dm
set t_Sb= [4%dm
endif
" My xterms have a navy-blue background, so I need this
line too.
set background=dark
" Turn syntax on
syntax on
" Key bindings.
nmap b <C-B><C-G>

http://www.vim.org/tips/tip.php?tip_id=121 (1 of 6) [18/02/2004 14:45:10]

Tip #121 - Using vim as a syntax-highlighting pager : vim online

nmap q :q<CR>
" To type the following line, type *two* C-V's followed
by two spaces. This
" is how you map the spacebar.
nmap ^V <C-F><C-G>
---8<---cut here---8<--Then, to use this .vimrc, add an alias. If you're using
tcsh, the syntax will
be something like:
alias vmore "vim -u ~/.vimrc.more"
Then you can type "vmore [filename]" to view a file in
this "pager". Spacebar
will move down, 'b' will move back up, and 'q' quits.
You can add mappings for
other keys if you want to, also.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Compiling Java with Sun JDK (javac) within VIM | Skip blank lines when folding text. >>

Additional Notes
Anonymous, September 24, 2001 19:41
If you are using vim 6, there is already something like
this - a shell script installed as
$VIMRUNTIME/macros/less.sh. It sets up keybindings as
if you were using the common pager "less".
For more information, ":help less" from vim.
ivo@mentation.nl, September 29, 2001 10:20
I don't have vim 6.0 yet, but I added this to
~/.vimrc.pager:
" No menu bar and tool bar
set guioptions=aiMr
nmap <Up> <C-Y>
nmap <Down> <C-E>
Cursor key scrolling and no menu/tool bar.
Sanjay Aiyagari <saiyaga1881@earthlink.net>, October 2, 2001 1:20

http://www.vim.org/tips/tip.php?tip_id=121 (2 of 6) [18/02/2004 14:45:10]

Tip #121 - Using vim as a syntax-highlighting pager : vim online

This is a great idea! I adjusted it for "less" since I


like to use that. Well, first of all,
I made a little script called "vless" so that I can use
it as my $PAGER. This means
that it has to pass "-" to vim when no command-line
arguments are present:
----#!/bin/sh
vim -u $HOME/.vim.less "${@:--}"
----And here's my .vim.less file. I had to make all the <CX> notation lower-case for it to work
on vim 5.6.
I removed the syntax terminfo stuff, because for me (on
RedHat 6.2) it was in the termcap
for "ansi" and I didn't need anything more. I just
mapped the keys I use most often.
-----" No compatibility -- necessary for mappings to work.
set nocompatible
" Status line
set laststatus=0
set cmdheight=1
"set nomodifiable " Only in version 6.0
set readonly
set is ic hls
set background=dark
" Turn syntax on
syntax on
:hi comment cterm=bold ctermfg=2
:hi PreProc cterm=bold ctermfg=5
:hi Constant cterm=bold ctermfg=6
:hi Special cterm=bold ctermfg=7
:hi Search ctermfg=7 ctermbg=6
:hi IncSearch cterm=bold ctermfg=7 ctermbg=6
:hi Type cterm=bold ctermfg=7
" Key bindings.
nmap b <C-b>H<C-g>
nmap q :q!<CR>
nmap g 1G<C-g>
nmap j <C-e>
nnoremap k <C-y>k
nmap e <C-e>
nnoremap y <C-y>k
nmap d <C-d>z<CR>
nmap u <C-u>H

http://www.vim.org/tips/tip.php?tip_id=121 (3 of 6) [18/02/2004 14:45:10]

Tip #121 - Using vim as a syntax-highlighting pager : vim online

nmap <CR> <C-e>


nmap = <C-g>
nmap <Esc>u :noh<CR>
nmap E :e!<Space>
" To type the following line, type *two* C-V's followed
by two spaces. This
" is how you map the spacebar.
nmap ^V <C-f><C-g>
-------cec@NgrOyphSon.gPsfAc.nMasa.gov, January 14, 2002 14:16
Those who like to use vim as a viewer might want to
check out
vimtip#167 "Using vim as a man-page viewer under Unix".
thehaas@binary.net, June 12, 2002 7:49
I have quite a few plugins that get weird with a page,
so I added the '--noplugins' option to the vim command
in the shell script.
But it's a wonderful thing . . .
dawnsnow@bemail.org, July 19, 2002 0:42
Only function of less that I like most is use space to
scroll a page at a time.
If you are not in Vi's inseart mode, space only move
the cursor to the next character.
Which is not so important feature, so I map space to
page down
map <Space> <PageDown>
map <S-Space> <PageUp>
While shift-space is not page-up in less, I found it a
reasonable mapping.
matt@mc-c.net, November 20, 2002 5:35
For whatever reason (probably the moron user), the nmap
of the space bar in the orginal tip would end up paging
down and printing the status line until EOF. But when
I added <C-G> to the space mapping from dawnsnow, it
worked like a champ.
Brandon D. Valentine <vim_tips@geekpunk.net>, March 15, 2003 0:51

http://www.vim.org/tips/tip.php?tip_id=121 (4 of 6) [18/02/2004 14:45:10]

Tip #121 - Using vim as a syntax-highlighting pager : vim online

I have done the following to make vim 6.1 work as my


PAGER and it works really well. man(1) uses PAGER to
display manpages and I had trouble with vim's filetype
autodetection picking up that it was indeed a manpage
coming in over the pipe. To counter this I've written
a scripts.vim to match manpages by regex and set the
filetype accordingly. Otherwise, I got no syntax
highlighting. The shell I quote is tcsh-specific, but
easily portable to another shell. Also, I assume you
already have a ~/bin and that it is in your path and
that you already have a ~/.vim. If not, you will need
to do these things.
% ln -s /path/to/VIMRUNTIME/macros/less.sh ~/bin/vless
% cat >> ~/.vim/scripts.vim
if did_filetype()
finish
endif
if getline(1) =~ '^\(.\+\)(\d\{1}).\+\1(\d\{1})$'
set filetype=man
endif
^D
% cat >> .cshrc
# config pager
if (-X vless && -X col) then
setenv PAGER 'col -b | vless'
alias less vless
alias more vless
else if (-X less) then
setenv PAGER less
setenv LESS "-e"
alias more less
else if (-X more) then
setenv PAGER more
else
echo "WARNING: No pager found, PAGER not set."
endif
^D
Brandon D. Valentine <vim_tips@geekpunk.net>, March 15, 2003 1:00

http://www.vim.org/tips/tip.php?tip_id=121 (5 of 6) [18/02/2004 14:45:10]

Tip #121 - Using vim as a syntax-highlighting pager : vim online

Actually, here's a smarter way to do that scripts.vim


(the original was taken from the vim manual |newfiletypes-scripts|):
if did_filetype()
" filetype already
set..
elseif getline(1) =~ '^\(.\+\)(\d\{1}).\+\1(\d\{1})$'
set filetype=man
endif
The previous example works but wouldn't allow you to
add anything else to your scripts.vim.
Anonymous, November 10, 2003 15:44
Why not use Bram's less.vim that ships with the
product?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=121 (6 of 6) [18/02/2004 14:45:10]

SourceForge
Logo

Tip #122 - Skip blank lines when folding text. : vim online

not logged in (login)

Home
Search

Tip #122: Skip blank lines when folding text.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 15/6, Viewed by 1497

created: September 27, 2001 0:53


author: Michael Brailsford

complexity: intermediate
as of Vim: 6.0

I love the text folding capabilities of vim. I didn't like that it would display the first line of the
range as the "title" for the fold. I like to write my comments with the "/*" on a line by itself. So I
wrote this little function that will skip over anything that isn't a character, and then display whatever
it finds after that character.
Just include this in your ~/.vimrc (or ~/.gvimrc):
function GetFirstLineWithChars()
let line_num = 0
let charline = matchstr(getline(v:foldstart), '[a-zA-Z][a-zA-Z ]*')
while strlen(charline) == 0
let line_num = line_num + 1
let charline = matchstr(getline(v:foldstart + line_num), '[a-zA-Z][a-zA-Z ]*')
endw
return charline
endfunction
set
foldtext='+'.v:folddashes.substitute(GetFirstLineWithChars(),'\\\/\\\/\\\|\\*\\\|\\*\\\|{{{\\d\\=','','g')
set fillchars=fold:
hi folded guibg=black guifg=yellow gui=bold
And as an added bonus, for those new to text folding, add this to your .vimrc file too:
autocmd BufWinLeave *.* mkview
autocmd BufWinEnter *.* silent loadview
That way whatever folds you set won't get lost when you quit.
folding up a 3000+ line file. Happy vimming!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using vim as a syntax-highlighting pager | use functionality similar to the * search on multiple files >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=122 (1 of 2) [18/02/2004 14:45:12]

I had that happen after spending 15 minutes

Tip #122 - Skip blank lines when folding text. : vim online

brailsmt at users.sourceforge.net, September 27, 2001 0:58


Email me if you need any help. BTW, the line that looks like this "set fillchars=fold:". It actually
has a character at the end. Simply type <C-k><space><space> to reproduce it. It's just a space.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=122 (2 of 2) [18/02/2004 14:45:12]

SourceForge
Logo

Tip #123 - use functionality similar to the * search on multiple files : vim online

not logged in (login)

Home
Search

Tip #123: use functionality similar to the * search on multiple files


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 8/5, Viewed by 1008

created: September 28, 2001 17:22


author: * type grep

complexity: basic
as of Vim: 6.0

The use of star as in vimtip#1 and vimtip#5 is great,


here is how to use this type of search accross a
whole directory:
Just add the mappings (or choose different letter
combinations):
map gr :grep <cword> *<cr>
map gr :grep <cword> %:p:h/*<cr>
map gR :grep \b<cword>\b *<cr>
map GR :grep \b<cword>\b %:p:h/*<cr>
mapping one will search for the word under the cursor
(like g*) in any of the files in the current directory
mapping two will search for the word under the cursor
(like g*) in any of the files in the same directory as
the current file
mapping three will search for the word under the cursor
by itself (i.e. surrounded by word boundary like *) in
any of the files in the current directory
mapping four will search for the word under the cursor
by itself (i.e. surrounded by word boundary like *) in
any of the files in the same directory as the current
file
Benoit
rate this tip

Life Changing

Helpful

Unfulfilling

<<Skip blank lines when folding text. | Number a group of lines >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=123 (1 of 2) [18/02/2004 14:45:14]

rate

Tip #123 - use functionality similar to the * search on multiple files : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=123 (2 of 2) [18/02/2004 14:45:14]

SourceForge
Logo

Tip #124 - Number a group of lines : vim online

not logged in (login)

Tip #124: Number a group of lines

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/2, Viewed by 829

created: October 1, 2001 16:37


author: Brian Medley

complexity: basic
as of Vim: 5.7

Below is a way to number a set of lines.


exaple before and after snapshot:

Here is an

apple
bob
pear
tree
1
2
3
4

apple
bob
pear
tree

" Description:
" This provides a command and a function. They both can
be called with or
" without a range. In addition, they can be called with
or without
" arguments. Without a range they operate on the
current line.
"
" There are two supported arguments. They are described
below:
"
arg1 -> the number to start at. The default is
one. This will
"
number your selected lines
sequentially. The start can be a
"
number, ., $, or, 'x (like getline).
"
arg2 -> Text to append after numbers. The default
is a space.
"
" Examples:
"
To provide your functionality:
"
:%Nlist 20
"
:%call Nlist(20)
"
To make a list start at 1:
"
:'<,'>Nlist
"
:'<,'>call Nlist()
http://www.vim.org/tips/tip.php?tip_id=124 (1 of 3) [18/02/2004 14:45:17]

Tip #124 - Number a group of lines : vim online

"
To number the whole buffer (with it's actual line
number):
"
:%Nlist
"
:%call Nlist()
"
To number a subset of lines with their line number
(and put a '] ' in
"
front of every number):
"
:'<,'>Nlist . ]\
"
:'<,'>call Nlist(".", "] ")
command! -nargs=* -range Nlist <line1>,<line2>call
Nlist(<f-args>)
function! Nlist(...) range
if 2 == a:0
let start = a:1
let append = a:2
elseif 1 == a:0
let start = a:1
let append = " "
else
let start = 1
let append = " "
endif
" try to work like getline (i.e. allow the user to
pass in . $ or 'x)
if 0 == (start + 0)
let start = line(start)
endif
exe a:firstline . "," . a:lastline .
's/^/\=line(".")-a:firstline+start.append/'
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<use functionality similar to the * search on multiple files | Auto commenting for "}" >>

Additional Notes
Brian Medley, October 1, 2001 22:25
There is now a plugin (nlist.vim) in the "scripts"
section that does this. The plugin also handles
justifying the numbers. I probably should have waited
and not made this tip...

http://www.vim.org/tips/tip.php?tip_id=124 (2 of 3) [18/02/2004 14:45:17]

Tip #124 - Number a group of lines : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=124 (3 of 3) [18/02/2004 14:45:17]

SourceForge
Logo

Tip #125 - Auto commenting for "}" : vim online

not logged in (login)

Home
Search

Tip #125: Auto commenting for "}"


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 32/14, Viewed by 2272

created: October 2, 2001 6:48


author: Long Truong

complexity: basic
as of Vim: 6.0

I always wanted a script that would auto-comment the end of a conditional block. So, I wrote one. This
function searches for the previous matching "{", grabs the line, and inserts it as a comment after the "}".
there is no previous matching "{", it inserts nothing.
So...
if (test){

Site Help

will generate:
} // if (test)
This is obviously not work if you use a different style.

If you use

if (test)
{
then substituting 'getline(".")', use

'getline(line(".") - 1)' should work.

Put the following in your .vimrc:


au BufNewFile,BufRead *.c,*.cc,*.C,*.h imap } <ESC>:call CurlyBracket()<CR>a
function CurlyBracket()
let l:my_linenum = line(".")
iunmap }
sil exe "normal i}"
imap } <ESC>:call CurlyBracket()<CR>
let l:result1 = searchpair('{', '', '}', 'bW')
if (result1 > 0)
let l:my_string = substitute(getline("."), '^\s*\(.*\){', '\1', "")
sil exe ":" . l:my_linenum
sil exe "normal a //" . l:my_string
endif
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

<<Number a group of lines | how do I get rid of that bold stuff with my xterm? >>

http://www.vim.org/tips/tip.php?tip_id=125 (1 of 8) [18/02/2004 14:45:20]

rate

If

Tip #125 - Auto commenting for "}" : vim online

Additional Notes
octorock@doubtful.com, October 2, 2001 8:34
sweet!

thanks for a great tip!

Anonymous, October 3, 2001 10:36


Thanks for the cool script. I had some problems getting it working, but I've bodged it for now. Don't know if
you're interested, but I've made a few modifications.
[1] Works for
if (x ==1 )
{
.....
}
(the substitution appeared to be going awry for lines with braces on their own)
[2] Won't comment lines that are within 10 lines of each other. I find this script great for big huge
functions, but for short if statements it can quickly clog up the code with obvious comments.
[3] Won't copy the entire line, but truncates at 30 characters. Prepended spaces are removed.
[4] I've added the line
au BufNewFile,BufRead *.java,*.c,*.cc,*.C,*.h map <A-F1> :call CurlyBracket()<CR>
to my .vimrc for those times when you started with a small if statement, and ended up with a mammoth one.
Simply calls CurleyBracket to comment it.
Hope you don't mind my additions to such a useful script
N.
function! CurlyBracket()
let l:my_linenum=line(".")
iunmap }
sil exe "normal i}"
imap } <ESC>:sil call CurlyBracket()<CR>a
let result1=searchpair('{', '', '}', 'bW')
let goline=""
let appendstr=""
if (result1 > 0)
let l:my_startline=line(".")
if (l:my_linenum - l:my_startline > 10)
let l:my_string=substitute(getline(line(".")-1),"^ *","","g")
let l:shortstring=strpart(l:my_string,0,30)."..."
let appendstr="normal a // ".shortstring
endif
let goline=":".l:my_linenum
endif
sil exe goline
sil exe appendstr
endfunction
http://www.vim.org/tips/tip.php?tip_id=125 (2 of 8) [18/02/2004 14:45:20]

Tip #125 - Auto commenting for "}" : vim online

Long Truong, October 3, 2001 11:49


Okay.
1.
2.
3.
4.

I have changed this script.

It takes into account the last note and some other things I noticed.

This was annoying when I had a short if(){}else{} statement, so I changed the mapping to }<CR>.
If there is an else statement, the comment inserted is the if statement. followed by an else {
>10 lines check put in.
< 30 char check put in

Notes:
This will not indent correctly unless you're using cindent. For some reason, a friend of mine with
smartindent and it didn't work
If your style is to put the curly bracket on it's own line after the "if", add "-1" to all the getline
calls.
au BufNewFile,BufRead *.c,*.cc,*.C,*.h imap }<CR> <ESC>:call CurlyBracket()<CR>a
function CurlyBracket()
let l:startline = line(".")
let l:result1 = searchpair('{', '', '}', 'bW', '')
if (result1 > 0)
let l:linenum = line(".")
let l:string1 = getline(l:linenum)
if (l:string1 =~ ".*}.*{.*")
sil exe "normal 0"
let l:result2 = searchpair('{', '', '}', 'bW', '')
if (l:result2 > 0)
let l:string1 = getline(".") . l:string1
endif
endif
let l:my_string = substitute(l:string1, '^\s*\(.*\){', '\1', "")
let l:my_string = strpart(l:my_string,0,30)."..."
sil exe ":" . l:startline
sil exe "normal i}"
if ((l:startline - l:linenum) > 10)
sil exe "normal a //" . l:my_string
endif
endif
endfunction
jhm@gmx.net, October 4, 2001 10:46

http://www.vim.org/tips/tip.php?tip_id=125 (3 of 8) [18/02/2004 14:45:20]

Tip #125 - Auto commenting for "}" : vim online

Hi!
I tried this script (and also the second) and get the following errors when entering a }. Seems like it's
stuck in recursion... :-( This happens with Vim 6.0final on Linux and Windoze...
Any Ideas?
Jrg
Error detected while processing function CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..Curly
Bracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..Curly
Bracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..Curly
Bracket..CurlyBracket..CurlyBracket:
line
2:
E31: No such mapping
http://www.vim.org/tips/tip.php?tip_id=125 (4 of 8) [18/02/2004 14:45:20]

Tip #125 - Auto commenting for "}" : vim online

schabungbam@hss.hns.REMOVEME.com, October 20, 2001 1:34


Hi,
Just 3 modifications:
[1]. Now, supports both styles of
if (..) {
..
}
and
if (...)
{
...
} else
{
...
}
but,
if ()
{
}
else
{
}
still does not work!!
[2] The number of lines is taken form the start of the "if" (in case of if-else)
[3] The "..." is added only if the length of the stringis > 30.
regards
Sameer.
=======
" curlyC.vim
" From Long Truong : Vim Tip #125.
" Automatically comments {} in C/C++/Java.
au BufNewFile,BufRead *.c,*.cc,*.h imap }<CR> <ESC>:call CurlyBracket()<CR>a
au BufNewFile,BufRead *.cpp,*.C imap }<CR> <ESC>:call CurlyBracket()<CR>a
au BufNewFile,BufRead *.java,*.idl imap }<CR> <ESC>:call CurlyBracket()<CR>a
function CurlyBracket()
let l:startline = line(".")
let l:result1 = searchpair('{', '', '}', 'bW')
if (result1 > 0)
let l:linenum = line(".")
let l:string1 = substitute(getline(l:linenum), '^\s*\(.*\)\s*$', '\1', "")
if (l:string1 =~ '^{')
http://www.vim.org/tips/tip.php?tip_id=125 (5 of 8) [18/02/2004 14:45:20]

Tip #125 - Auto commenting for "}" : vim online

let l:string1 = substitute(getline(l:linenum - 1), '^\s*\(.*\)\s*$', '\1', "") . " " . l:string1
sil exe "normal k"
endif
" get else part if necessary
if (l:string1 =~ "^}")
sil exe "normal 0"
let l:result2 = searchpair('{', '', '}', 'bW')
if (l:result2 > 0)
let l:linenum = line(".")
let l:string2 = substitute(getline(l:linenum), '^\s*\(.*\)\s*$', '\1', "")
if (l:string2 =~ '^{')
let l:string2 = substitute(getline(l:linenum - 1), '^\s*\(.*\)\s*$', '\1', "") . " " .
l:string2
endif
let l:string1 = l:string2 . " ... " . l:string1
endif
endif
" remove trailing whitespaces and curly brace
let l:my_string = substitute(l:string1, '\s*{[^{]*$', '', "")
let l:my_strlen = strlen(l:my_string)
if (l:my_strlen > 30)
let l:my_string = strpart(l:my_string,0,30)."..."
endif
sil exe ":" . l:startline
sil exe "normal i}"
if ((l:startline - l:linenum) > 10)
sil exe "normal a /* " . l:my_string . " */"
endif
endif
endfunction
pacman@huji.ac.il, June 26, 2002 3:42
I use: vim6.1.74 - Linux
Nice tip but it doesn't work for me!
Error detected while processing function
line
2:
Error detected while
line
2:
Error detected while
line
2:
Error detected while
acket:
line
2:
Error detected while
acket..CurlyBracket:
line
2:
Error detected while
http://www.vim.org/tips/tip.php?tip_id=125 (6 of 8) [18/02/2004 14:45:20]

CurlyBracket:
processing function CurlyBracket..CurlyBracket:
processing function CurlyBracket..CurlyBracket..CurlyBracket:
processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr

processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr

processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr

Tip #125 - Auto commenting for "}" : vim online

acket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..Curly
Bracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..Curly
Bracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..Curly
Bracket..CurlyBracket..CurlyBracket:
line
2:
E31: No such mapping
pacman@huji.ac.il, June 26, 2002 3:44
I use: vim6.1.74 - Linux
Nice tip but it doesn't work for me!
Error detected while processing function CurlyBracket:
line
2:
Error detected while processing function
line
2:
Error detected while processing function
line
2:
Error detected while processing function
acket:
line
2:
Error detected while processing function
acket..CurlyBracket:
line
2:
Error detected while processing function
acket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function
acket..CurlyBracket..CurlyBracket..CurlyBracket:
http://www.vim.org/tips/tip.php?tip_id=125 (7 of 8) [18/02/2004 14:45:20]

CurlyBracket..CurlyBracket:
CurlyBracket..CurlyBracket..CurlyBracket:
CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr

CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr

CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr

CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr

Tip #125 - Auto commenting for "}" : vim online

line

2:

Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr


acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..Curly
Bracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..Curly
Bracket..CurlyBracket:
line
2:
Error detected while processing function CurlyBracket..CurlyBracket..CurlyBracket..CurlyBr
acket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..CurlyBracket..Curly
Bracket..CurlyBracket..CurlyBracket:
line
2:
E31: No such mapping
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=125 (8 of 8) [18/02/2004 14:45:20]

SourceForge
Logo

Tip #126 - how do I get rid of that bold stuff with my xterm? : vim online

not logged in (login)

Home
Search

Tip #126: how do I get rid of that bold stuff with my xterm?
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 13/6, Viewed by 1696

created: October 3, 2001 8:26


author: Charles E. Campbell, Jr.

complexity: basic
as of Vim: 6.0

Having problems setting up your syntax highlighting


because
everything is coming up in bold?
You're probably using an 8 color xterm and setting up
highlighting
lines such as hi Normal ... ctermfg=green . The
solution: use
numbers! 0=black, 1=red, 2=green, 3=yellow, 4=blue,
5=magenta,
6=cyan, and 7=white. Vim tries to use "bright" colors
when its
given names (because Windoz machines prefer to use dim
text unless
its been made bold).
Read more about it under :help highlight-ctermfg .

rate this tip

Life Changing

Helpful

<<Auto commenting for "}" | Preview HTML files quickly >>

Additional Notes
hans@fugal.net, October 10, 2001 7:37

http://www.vim.org/tips/tip.php?tip_id=126 (1 of 2) [18/02/2004 14:45:22]

Unfulfilling

rate

Tip #126 - how do I get rid of that bold stuff with my xterm? : vim online

This works ok, but a more portable (and more


predictable) way is to use the dark color names. i.e.
use DarkBlue instead of Blue, Gray instead of White,
etc. See :help cterm-colors.
If you are using a recent xterm
your .vimrc:
if &term =~ "xterm"
" don't do this if you have
set term=xterm-16color
endif
And you will get the non-bolded
colors (which means you have 16

try putting this in

8-color xterms

versions of those
colors to work with)

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=126 (2 of 2) [18/02/2004 14:45:22]

SourceForge
Logo

Tip #127 - Preview HTML files quickly : vim online

not logged in (login)

Home
Search

Tip #127: Preview HTML files quickly


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/10, Viewed by 1957

created: October 4, 2001 8:28


author: Jamis Buck

complexity: basic
as of Vim: 6.0

I've found while writing HTML files that it can become


cumbersome when I have to switch to a web browser, load
my page, and move back to VIM regularly to preview what
I've written. I've come up with the following tricks.
The first one requires that you have lynx (the textbased browser) installed on your computer (available
from http://lynx.isc.org/release/). If your HTML page
is primarily text, with few (if any) images, you can set
up the following function and mapping:
function PreviewHTML_TextOnly()
let l:fname = expand("%:p" )
new
set buftype=nofile nonumber
exe "%!lynx " . l:fname . " -dump -nolist underscore -width " . winwidth( 0 )
endfunction
map <Leader>pt

:call PreviewHTML_TextOnly()<CR>

This will open a new window and display your formatted


HTML document in that window. Note that bold-face,
italics, links, etc. will be lost -- all you will see is
the text -- but the "-underscore" parameter to Lynx
causes any text that would have been bold, italicized,
or underlined to be displayed like _this_.
The other trick requires that vim be running on your
current machine, and that you be running a GUI of some
sort (X-Windows, Windows, etc.). You can cause vim to
invoke your favorite browser and have it display the
file, like this:
function PreviewHTML_External()
exe "silent !mozilla -remote \"openurl(file://"; .
expand( "%:p" ) . ")\""
endfunction

http://www.vim.org/tips/tip.php?tip_id=127 (1 of 2) [18/02/2004 14:45:25]

Tip #127 - Preview HTML files quickly : vim online

map <Leader>pp :call PreviewHTML_External()<CR>


If you don't use mozilla, you will need to modify the
function to use your preferred browser.
Happy vimming!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<how do I get rid of that bold stuff with my xterm? | grep, diff, patch, idutils, etc. for Windows systems
>>

Additional Notes
christophe.badoit@free.frNOSPAM, February 9, 2002 15:40
Better with dillo, a really fast an light browser... a
graphical lynx in some sort.
See http://dillo.sourceforge.net ; or "apt-get
install dillo" for debian users.
Anonymous, July 26, 2002 6:18
It gives me an error when I try it:
E15:

Invalid expression: ; . expand( "%:p") . ")\""

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=127 (2 of 2) [18/02/2004 14:45:25]

SourceForge
Logo

Tip #128 - grep, diff, patch, idutils, etc. for Windows systems : vim online

not logged in (login)

Home
Search

Tip #128: grep, diff, patch, idutils, etc. for Windows systems
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 24/11, Viewed by 2588

created: October 7, 2001 17:36


author: Benji Fisher

complexity: basic
as of Vim: 5.7

If you use Vim on Windows, and you wish you had


some of those nifty UNIX command-line tools,
but do not feel like installing all of Cygwin, you can
get many of the most-used tools from Ron Aaron's
web site:
http://www.mossbayeng.com/~ron/vim/builds.html
Since Ron is a big Vim fan (see
http://www.mossbayeng.com/~ron/vim/vimrant.html ) you
can count on
these tools' working well with Vim. For some hints on
how to use them, read
:help :grep
:help lid
inside Vim.
Happy Vimming!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Preview HTML files quickly | Removing automatic comment leaders >>

Additional Notes
benji@member.AMS.org, December 1, 2001 5:09
Another suggestion from the vim users' list is
http://sourceforge.net/projects/gnuwin32
I have not tried this myself.
zzapper@ntlworld.com, February 7, 2003 10:27
However if you do wish to try Cygwin
http://www.cygwin.com/

http://www.vim.org/tips/tip.php?tip_id=128 (1 of 2) [18/02/2004 14:45:27]

Tip #128 - grep, diff, patch, idutils, etc. for Windows systems : vim online

2003@karpfenteich.net, February 22, 2003 5:38


another resource of the unixtools for windows are:
http://unxutils.sourceforge.net/
or
http://www.openetwork.com/berk.html
Anonymous, July 8, 2003 17:22
It appears that the link:
http://www.mossbayeng.com/~ron/vim/builds.html
is dead. Does anybody have an alternate?
Thanks
benji@member.AMS.org, February 7, 2004 5:41
Ron Aaron just announced that his new website is at
http://ronware.gotdns.com/vim.html
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=128 (2 of 2) [18/02/2004 14:45:27]

SourceForge
Logo

Tip #129 - Removing automatic comment leaders : vim online

not logged in (login)

Home
Search

Tip #129: Removing automatic comment leaders


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/11, Viewed by 868

created: October 7, 2001 19:16


author: Benji Fisher

complexity: basic
as of Vim: 5.7

If you include the "r" flag in the 'formatoptions'


option (:help 'fo' , :help fo-table ) then the comment
leader is inserted
automatically when you start a new line in a
comment. For example, in TeX the "%" character is the
comment leader,
and you might type
% This is a tex file.
% The comment leaders on all lines but the first were
generated automatically.
% This is the last line of the comment, but Vim will
insert the comment leader on the next line.
%
You can get rid of the comment leader (along with
anything you may already have typed on the line) without
affecting
the indent, if any, by typing "<C-U>" while in Insert
mode.
Related point: if you want to adjust the indent
while in Insert mode, you can use "<C-D>" (to Decrease
the indent)
or "<C-T>" (to increase it). In the docs for Vim 6.0,
this is described in the users' manual, :help 30.4 .
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<grep, diff, patch, idutils, etc. for Windows systems | disabling default ftplugins >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=129 (1 of 2) [18/02/2004 14:45:29]

Tip #129 - Removing automatic comment leaders : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=129 (2 of 2) [18/02/2004 14:45:29]

SourceForge
Logo

Tip #130 - disabling default ftplugins : vim online

not logged in (login)

Home
Search

Tip #130: disabling default ftplugins


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating 2/2, Viewed by 560

created: October 8, 2001 5:05


author: Benji Fisher

complexity: intermediate
as of Vim: 5.7

For an overview of ftplugins (filetype plugins) see


:help ftplugins

Scripts
Tips
My Account

If you want to disable all ftplugins, or disable a


particular default ftplugin, see

Site Help

:help :filetype
:help ftplugin-overrule
If you have your own ftplugins, and you want to disable
all the default ones, then
do NOT include a check for b:did_ftplugin in your
ftplugin files, and add the line
:autocmd BufEnter * let b:did_ftplugin = 1
to your VIMRC file, BEFORE the ":filetype ftplugin on"
line.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Removing automatic comment leaders | Scroll alternate window >>

Additional Notes
benji@member.AMS.org, October 8, 2001 5:06
Oops:

that should have been "as of Vim 6.0"!

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=130 [18/02/2004 14:45:32]

SourceForge
Logo

Tip #131 - Scroll alternate window : vim online

not logged in (login)

Home
Search

Tip #131: Scroll alternate window


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating 3/3, Viewed by 609

created: October 11, 2001 7:53


author: Max Ischenko

complexity: basic
as of Vim: 6.0

This mapping allow you to quickly scroll inactive window


when displaying several windows concurrently.

Scripts
Tips
My Account

nmap <silent> <M-Down> :call


ScrollOtherWindow("down")<CR>
nmap <silent> <M-Up> :call ScrollOtherWindow("up")<CR>

Site Help

fun! ScrollOtherWindow(dir)
if a:dir == "down"
let move = "\<C-E>"
elseif a:dir == "up"
let move = "\<C-Y>"
endif
exec "normal \<C-W>p" . move . "\<C-W>p"
endfun
PS: Original idea and discussion of this tip appeared on
vim@vim.org mailing list, I'm just prettified it a
little.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<disabling default ftplugins | window zooming convenience >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=131 [18/02/2004 14:45:33]

SourceForge
Logo

Tip #132 - window zooming convenience : vim online

not logged in (login)

Home
Search

Tip #132: window zooming convenience


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/9, Viewed by 1044

created: October 11, 2001 13:38


author: Salman Halim

complexity: basic
as of Vim: 6.0

i frequently have multiple windows open in vim -- this


reduces the number of lines each window displays -- i
almost always have my windows either all the same size
or the current one as big as possible.
the following function can be toggled on or off by
typing <Leader>max (i can do this quite quickly); just
change the mapping at the bottom to something else if
you prefer.
this causes the current window to be as big as possible
(moving into another window causes that one to become
big) and all the others get very small. i actually use
this ALL the time. turning it off (by typing the hotkey
sequence again) will cause all windows to have the same
height.
"toggles whether or not the current window is
automatically zoomed
function! ToggleMaxWins ()
if exists ('g:windowMax')
au! maxCurrWin
exe "normal \<c-w>="
unlet g:windowMax
else
augroup maxCurrWin
" au BufEnter * exe "normal \<c-w>_\<c-w>\<bar>"
"
" only max it vertically
au! BufEnter * exe "normal \<c-w>_"
augroup END
do maxCurrWin BufEnter
let g:windowMax=1
endif
endfunction
map <Leader>max :call ToggleMaxWins ()<CR>

http://www.vim.org/tips/tip.php?tip_id=132 (1 of 2) [18/02/2004 14:45:37]

Tip #132 - window zooming convenience : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Scroll alternate window | Windo and Bufdo >>

Additional Notes
pottsdl@yahoo.com, October 12, 2001 5:27
Note that the essential Vim commands are <c-_> which
maximizes the current
window by making all of the other windows 1-line
high. And <c-=> which makes
all window sizes the same.
The script just makes it easier to toggle.
salmanhalim@hotmail.com, October 12, 2001 6:21
i just like not having to explicitly maximize the
current window every time. i never said it couldn't be
done by hand at will. i just frequently have four or
five source windows open and it's easier to just have
them become bigger automatically.
salmanhalim@hotmail.com, October 13, 2001 12:42
i noticed that the bufenter commands only happen when
moving from one buffer to another (in a different
window) -- if you have two windows with the same
buffer, the bufenter commands don't get triggered and
the zooming doesn't happen. to make it happen for all
WINDOWS, change all the above BufEnter occurrences to
WinEnter.
glennj@canada.com, October 14, 2001 14:20
what is "<Leader>"?
tvon@etria.org, October 14, 2001 19:21
for info on <leader> see
:help mapleader
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=132 (2 of 2) [18/02/2004 14:45:37]

SourceForge
Logo

Tip #133 - Windo and Bufdo : vim online

not logged in (login)

Home
Search

Tip #133: Windo and Bufdo


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 8/5, Viewed by 888

created: October 11, 2001 13:41


author: Salman Halim

complexity: basic
as of Vim: 6.0

i like bufdo and windo but i don't like the fact that
the commands end in a different window/buffer than from
where i executed them. these versions (starts with a
capital letter) will restore the current window or
buffer when the command's done.
for example, to turn on line numbers everywhere, i use
:Windo set nu -- :windo set nu does the trick also but
leaves me in a different window than where i started.
" just like windo but restores the current window when
it's done
function! WinDo(command)
let currwin=winnr()
execute 'windo ' . a:command
execute currwin . 'wincmd w'
endfunction
com! -nargs=+ -complete=command Windo call WinDo(<qargs>)
" just like bufdo but restores the current buffer when
it's done
function! BufDo(command)
let currBuff=bufnr("%")
execute 'bufdo ' . a:command
execute 'buffer ' . currBuff
endfunction
com! -nargs=+ -complete=command Bufdo call BufDo(<qargs>)
rate this tip

Life Changing

Helpful

Unfulfilling

<<window zooming convenience | View Source in IE6 using VIM >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=133 (1 of 2) [18/02/2004 14:45:39]

rate

Tip #133 - Windo and Bufdo : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=133 (2 of 2) [18/02/2004 14:45:39]

SourceForge
Logo

Tip #134 - View Source in IE6 using VIM : vim online

not logged in (login)

Home
Search

Tip #134: View Source in IE6 using VIM


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 60/29, Viewed by 2288

created: October 12, 2001 0:05


author: Eric Lee

complexity: basic
as of Vim: 6.0

You can change the "View Source" editor of IE6 by adding


the following to the Windows Registry. Change the path
in case you installed VIM in another location.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet
Explorer\View Source Editor\Editor Name]
@="C:\\vim\\vim60\\gvim.exe"

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Windo and Bufdo | Vim buffer FAQ >>

Additional Notes
scrott@users.sourceforge.net, October 12, 2001 8:11
Also worth looking at vimtip #118 which deals with
defaulting the syntax to html and eating extra spaces.
webmaster@wltx.com, May 7, 2002 8:48
I wanted to use wordpad when i choose "view source" in
ie 6. this tip made it possible. just follow tip #134
and you can do this also.
wordpad lets you use your most common keyboard commands
such as ctrl-s, ctrl-a etc. basically all the ones that
notepad does not. no need for any extra script file if
you use wordpad. THANKS VIM !
json
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=134 [18/02/2004 14:45:41]

SourceForge
Logo

Tip #135 - Vim buffer FAQ : vim online

not logged in (login)

Home
Search

Tip #135: Vim buffer FAQ


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 192/85, Viewed by 7115

created: October 12, 2001 10:20


author: Yegappan

complexity: basic
as of Vim: 6.0

Vim provides various commands and options to support


editing multiple
buffers. This document covers some of the questions
asked about using
multiple buffers with Vim. You can get more detailed
information about Vim
buffer support using ":help windows.txt" in Vim. You
can also use the help
keywords mentioned in this document to read more about a
particular command
or option. To read more about a particular command or
option use, ":help
<helpkeyword>" in Vim.
1. What is a Vim buffer?
A buffer is a file loaded into memory for
editing. All opened files are
associated with a buffer. There are also buffers not
associated with any
file.
Help keyword(s): windows-intro
2. How do I identify a buffer?
Vim buffers are identified using a name and a
number. The name of the
buffer is the name of the file associated with that
buffer. The buffer
number is a unique sequential number assigned by
Vim. This buffer
number will not change in a single Vim session.
Help keyword(s): :buffers
3. How do I create a buffer?
When you open a file using any of the Vim commands, a
buffer is

http://www.vim.org/tips/tip.php?tip_id=135 (1 of 11) [18/02/2004 14:45:45]

Tip #135 - Vim buffer FAQ : vim online

automatically created. For example, if you use the


":edit file" command
to edit a file, a new buffer is automatically
created.
4. How do I add a new buffer for a file to the buffer
list without opening
the file?
You can add a new buffer for a file without opening
it, using the
":badd" ex command. For example,
:badd f1.txt
:badd f2.txt
The above commands will add two new buffers for the
files f1.txt and
f2.txt to the buffer list.
Help keyword(s): :badd
5. How do I get a list of all the existing buffers?
You can get a list of all the existing buffers using
the ":buffers" or
":ls" or ":files" ex command. This list is called
the 'buffer list'.
In Vim 6.0, to display all the buffers including
unlisted buffers, use
the ":buffers!" or ":ls!" or ":files!" ex command.
Help keyword(s): :buffers, :ls, :files
6. How do I delete a buffer?
You can delete a buffer using the ":bdelete" ex
command. You can use
either the buffer name or the buffer number to
specify a buffer. For
example,
:bdelete f1.txt
:bdelete 4
The above commands will delete the buffer named
"f1.txt" and the fourth
buffer in the buffer list. The ":bdelete" command
will remove the buffer
from the buffer list.
In Vim 6.0, when a buffer is deleted, the buffer
becomes an

http://www.vim.org/tips/tip.php?tip_id=135 (2 of 11) [18/02/2004 14:45:45]

Tip #135 - Vim buffer FAQ : vim online

unlisted-buffer and is no longer included in the


buffer list. But the
buffer name and other information associated with the
buffer is still
remembered. To completely delete the buffer, use the
":bwipeout" ex
command. This command will remove the buffer
completely (i.e. the
buffer will not become a unlisted buffer).
Help keyword(s): :bdelete, :bwipeout
7. How do I delete multiple buffers?
You can delete multiple buffers in several ways:
1. Pass a range argument to the ":bdelete" command.
For example,
:3,5bdelete
This command will delete the buffers 3, 4 and 5.
2. Pass multiple buffer names to the ":bdelete"
command. For example,
:bdelete buf1.txt buf2.c buf3.h
This command will delete buf1.txt, buf2.c and
buf3.h buffers. In
this example, after typing ":bdelete buf", you can
press <Ctrl-A> to
expand all the buffer names starting with 'buf'.
Help keyword(s): :bdelete, :bwipeout
8. How do I remove a buffer from a window?
You can remove a buffer displayed in a window in
several ways:
1. Close the window or edit another buffer/file in
that window.
2. Use the ":bunload" ex command. This command will
remove the buffer
from the window and unload the buffer contents
from memory. The
buffer will not be removed from the buffer list.
Help keyword(s): :bunload
9. How do I edit an existing buffer from the buffer
list?
You can edit or jump to a buffer in the buffer list

http://www.vim.org/tips/tip.php?tip_id=135 (3 of 11) [18/02/2004 14:45:45]

Tip #135 - Vim buffer FAQ : vim online

in several ways:
1. Use the ":buffer" ex command passing the name of
an existing buffer
or the buffer number. Note that buffer name
completion can be used
here by pressing the <Tab> key.
2. You can enter the buffer number you want to
jump/edit and press the
Ctrl-^ key.
3. Use the ":sbuffer" ex command passing the name of
the buffer or the
buffer number. Vim will split open a new window
and open the
specified buffer in that window.
4. You can enter the buffer number you want to
jump/edit and press the
Ctrl-W ^ or Ctrl-W Ctrl-^ keys. This will open
the specified buffer
in a new window.
Help keyword(s): :buffer, :sbuffer, CTRL-W_^, CTRL-^
10. How do I browse through all the available buffers?
You can browse through the buffers in the buffer
list in several ways:
1. To jump to the first buffer in the buffer list,
use the ":bfirst" or
":brewind" ex command.
2. To jump to the first buffer in the buffer list in
a new window, use
the ":sbfirst" or ":sbrewind" ex command.
3. To edit the next buffer in the buffer list, use
the ":bnext" ex
command.
4. To open the next buffer in the buffer list in a
new window, use the
":sbnext" ex command.
5. To edit the previous buffer in the buffer list,
use the ":bprevious"
or ":bNext" ex command.
6. To open the previous buffer in the buffer list in
a new window, use
the ":sbprevious" or ":sbNext" ex command.
7. To open the last buffer in the buffer list, use
the ":blast" ex
command.
8. To open the last buffer in the buffer list in a
new window, use the
http://www.vim.org/tips/tip.php?tip_id=135 (4 of 11) [18/02/2004 14:45:45]

Tip #135 - Vim buffer FAQ : vim online

":sblast" ex command.
Help keyword(s): :bfirst, :brewind, :sbfirst,
:sbrewind, :bnext,
:sbnext, :bprevious, :bNext,
:sbprevious, :sbNext,
:blast, :sblast
11. How do I open all the buffers in the buffer list?
You can open all the buffers present in the buffer
list using the
":ball" or ":sball" ex commands.
Help keyword(s): :ball, :sball
12. How do I open all the loaded buffers?
You can open all the loaded buffers in the buffer
list using the
":unhide" or ":sunhide" ex commands. Each buffer
will be loaded in a
separate new window.
Help keyword(s): :unhide, :sunhide
13. How do I open the next modified buffer?
You can open the next or a specific modified buffer
using the
":bmodified" ex command. You can open the next or a
specific modified
buffer in a new window using the ":sbmodified" ex
command.
Help keyword(s): :bmodified, :sbmodified
14. I am using the GUI version of Vim (gvim), is there a
simpler way for
using the buffers instead of the ex commands?
Yes. In the GUI version of Vim, you can use the
'Buffers' menu, which
simplifies the use of buffers. All the buffers in
the buffer list are
listed in this menu. You can select a buffer name
from this menu to
edit the buffer. You can also delete a buffer or
browse the buffer
list.
Help keyword(s): buffers-menu
15. Is there a Vim script that simplifies using buffers
with Vim?
http://www.vim.org/tips/tip.php?tip_id=135 (5 of 11) [18/02/2004 14:45:45]

Tip #135 - Vim buffer FAQ : vim online

Yes. You can use the bufexplorer.vim script to


simplify the process of
using buffers. You can download the bufexplorer
script from:
http://lanzarotta.tripod.com/vim.html
16. Is it possible to save and restore the buffer list
across Vim sessions?
Yes. To save and restore the buffer list across Vim
session, include
the '%' flag in the 'viminfo' option. Note that if
Vim is invoked with
a filename argument, then the buffer list will not
be restored from the
last session. To use buffer lists across sessions,
invoke Vim without
passing filename arguments.
Help keyword(s): 'viminfo', viminfo
17. How do I remove all the entries from the buffer
list?
You can remove all the entries in the buffer list by
starting Vim with
a file argument. You can also manually remove all
the buffers using
the ":bdelete" ex command.
18. What is a hidden buffer?
A hidden buffer is a buffer with some unsaved
modifications and is not
displayed in a window. Hidden buffers are useful,
if you want to edit
multiple buffers without saving the modifications
made to a buffer
while loading other buffers.
Help keyword(s): :buffer-!, 'hidden', hidden-buffer,
buffer-hidden
19. How do I load buffers in a window, which currently
has a buffer with
unsaved modifications?
By setting the option 'hidden', you can load buffers
in a window that
currently has a modified buffer. Vim will remember
your modifications
to the buffer. When you quit Vim, you will be asked
to save the

http://www.vim.org/tips/tip.php?tip_id=135 (6 of 11) [18/02/2004 14:45:45]

Tip #135 - Vim buffer FAQ : vim online

modified buffers. It is important to note that, if


you have the
'hidden' option set, and you quit Vim forcibly, for
example using
":quit!", then you will lose all your modifications
to the hidden
buffers.
Help keyword(s): 'hidden'
20. Is it possible to unload or delete a buffer when it
becomes hidden?
The following works only in Vim 6.0 and above. By
setting the
'bufhidden' option to either 'hide' or 'unload' or
'delete', you can
control what happens to a buffer when it becomes
hidden. When
'bufhidden' is set to 'delete', the buffer is
deleted when it becomes
hidden. When 'bufhidden' is set to 'unload', the
buffer is unloaded
when it becomes hidden. When 'bufhidden' is set to
'hide', the buffer
is hidden.
Help keyword(s): 'bufhidden'
21. How do I execute a command on all the buffers in the
buffer list?
In Vim 6.0, you can use the ":bufdo" ex command to
execute an ex
command on all the buffers in the buffer list.
Help keyword(s): :bufdo
22. When I open an existing buffer from the buffer list,
if the buffer is
already displayed in one of the existing windows, I
want Vim to jump to
that window instead of creating a new window for
this buffer. How do I
do this?
When opening a buffer using one of the split open
buffer commands
(:sbuffer, :sbnext), Vim will open the specified
buffer in a new
window. If the buffer is already opened in one of
the existing
windows, then you will have two windows containing

http://www.vim.org/tips/tip.php?tip_id=135 (7 of 11) [18/02/2004 14:45:45]

Tip #135 - Vim buffer FAQ : vim online

the same buffer.


You can change this behavior by setting the
'switchbuf' option to
'useopen'. With this setting, if a buffer is
already opened in one of
the windows, Vim will jump to that window, instead
of creating a new
window.
Help keyword(s): 'switchbuf'
23. What information is stored as part of a buffer?
Every buffer in the buffer list contains information
about the last
cursor position, marks, jump list, etc.
24. What is the difference between deleting a buffer and
unloading a
buffer?
When a buffer is unloaded, it is not removed from
the buffer list.
Only the file contents associated with the buffer
are removed from
memory. When a buffer is deleted, it is unloaded
and removed from the
buffer list. In Vim 6, a deleted buffer becomes an
'unlisted' buffer.
Help keyword(s): :bunload, :bdelete, :bwipeout,
unlisted-buffer
25. Is it possible to configure Vim, by setting some
option, to re-use the
number of a deleted buffer for a new buffer?
No. Vim will not re-use the buffer number of a
deleted buffer for a
new buffer. Vim will always assign the next
sequential number for a
new buffer. The buffer number assignment is
implemented this way, so
that you can always jump to a buffer using the same
buffer number. One
method to achieve buffer number reordering is to
restart Vim. If you
restart Vim, it will re-assign numbers sequentially
to all the buffers
in the buffer list (assuming you have properly set
'viminfo' to save
and restore the buffer list across vim sessions).

http://www.vim.org/tips/tip.php?tip_id=135 (8 of 11) [18/02/2004 14:45:45]

Tip #135 - Vim buffer FAQ : vim online

Help keyword(s): :buffers


26. What options do I need to set for a scratch
(temporary) buffer?
The following works only in Vim 6.0 and above. You
can set the the
following options to create a scratch (temporary)
buffer:
:set buftype=nofile
:set bufhidden=hide
:setlocal noswapfile
This will create a buffer which is not associated
with a file, which
does not have a associated swap file and will be
hidden when removed
from a window.
Help keyword(s): special-buffers, 'buftype'
27. How do I prevent a buffer from being added to the
buffer list?
The following works only in Vim 6.0 and above. You
can prevent a buffer
from being added to the buffer list by resetting the
'buflisted'
option.
:set nobuflisted
Help keyword(s): 'buflisted'
28. How do I determine whether a buffer is modified or
not?
There are several ways to find out whether a buffer
is modified or not.
The simplest way is to look at the status line or
the title bar. If
the displayed string contains a '+' character, then
the buffer is
modified. Another way is to check whether the
'modified' option is set
or not. If 'modified' is set, then the buffer is
modified. To check
the value of modified, use
:set modified?
You can also explicitly set the 'modified' option to
mark the buffer as
http://www.vim.org/tips/tip.php?tip_id=135 (9 of 11) [18/02/2004 14:45:45]

Tip #135 - Vim buffer FAQ : vim online

modified like this:


:set modified
Help keyword(s): 'modified'
29. How can I prevent modifications to a buffer?
The following works only in Vim 6.0 and above. You
can prevent any
modification to a buffer by re-setting the
'modifiable' option. To
reset this option, use
:set nomodifiable
To again allow modifications to the buffer, use:
:set modifiable
Help keyword(s): 'modifiable'
30. How do I set options specific to the current buffer?
The following works only in Vim 6.0 and above. You
can set Vim options
which are specific to a buffer using the "setlocal"
command. For
example,
:setlocal textwidth=70
This will set the 'textwidth' option to 70 only for
the current buffer.
All other buffers will have the default or the
previous 'textwidth'
value.
Help keyword(s): 'setlocal', local-options
31. How do I define mappings specific to the current
buffer?
The following works only in Vim 6.0 and above. You
can define mappings
specific to the current buffer by using the keyword
"<buffer>" in the
map command. For example,
:map <buffer>

,w

/[.,;]<CR>

Help keyword(s): :map-local


32. How do I define abbreviations specific to the
current buffer?
http://www.vim.org/tips/tip.php?tip_id=135 (10 of 11) [18/02/2004 14:45:45]

Tip #135 - Vim buffer FAQ : vim online

The following works only in Vim 6.0 and above. You


can define
abbreviations specific to the current buffer by
using the keyword
"<buffer>" in the :abbreviate command. For example,
:abb <buffer> FF

for (i = 0; i < ; ++i)

Help keyword(s): :abbreviate-local

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<View Source in IE6 using VIM | Remapping Alt, Ctrl and Caps in Win2k >>

Additional Notes
Anonymous, March 25, 2003 16:22
Something simple, using gvim
just detach the buffer menu and place it on the right
hand side of the screen.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=135 (11 of 11) [18/02/2004 14:45:45]

SourceForge
Logo

Tip #136 - Remapping Alt, Ctrl and Caps in Win2k : vim online

not logged in (login)

Home
Search

Tip #136: Remapping Alt, Ctrl and Caps in Win2k


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 6/9, Viewed by 1502

created: October 12, 2001 19:04


author: Jean-Paul Darcis

complexity: basic
as of Vim: 5.7

Since I installed Win2K on my laptop, I had been unable to locate a utilitie that
simply enable me to remap my Crtl Alt and Caps the way I think they should be and
they were until MS kill all competition in computing, that is Crtl on the left of
letter A, Alt to the left bottom of the letter Z and Caps approximately until the

would
the way
the
C.

After some research, I came across a tip posted here by juano@mindspring.com. I tried to
make sense of it and then downloaded the MS scan keys map at the URL he mentionned.
Extrapolating his tip, I wrote this ASCI file that I named keys2000.reg :
Regedit4
[HKey_Local_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode
Map"=hex:00,00,00,00,00,00,00,00,04,00,00,00,3A,00,38,00,38,00,1D,00,1D,00,3A,00,00,00,00
Once you have saved this file, left click on it from Explorer and answer yes to the
prompt "do you want to enter this into the registry".
Reboot and you are done.
A few explanations :04 stands for 3 remappings (Caps lock to Control, Control to Alt and
Alt to Caps Lock) plus the closing one which is always required (1 remapping would
require 02, 2 would require 03, and so on). 3A,00,38 remaps Caps to Left Alt, 38,00,1D
remaps Left Alt to Left Ctrl and 1D,00,3A remaps Left Ctrl to Caps Lock since 3A=Caps,
1D=Left Ctrl and 38=Left Alt.
Based on Juano tip and on this one, I believe a lot of remapping can be done as long as
you keep the separators 00 and remember to add one to the number of remappings. What I do
not know is how far you can extend this instruction without getting into trouble with the
registry. At worst, if you keyboard does not behave as expected, go into the registry and
delete this instruction (be careful here since it is easy to confuse this instruction

http://www.vim.org/tips/tip.php?tip_id=136 (1 of 2) [18/02/2004 14:45:48]

Tip #136 - Remapping Alt, Ctrl and Caps in Win2k : vim online

with the Keyboard LayoutS (S for emphasis) which must not be deleted.
Again, thanks to Juano@mindspring.com who got me going and suggested I post my tip. Took
me some time to retrieve the VIM Url but fortunately, I had printed his tip.
Regards
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Vim buffer FAQ | automatically wrap left and right >>

Additional Notes
leifw @(at)@ bigfoot .(dot). com, December 13, 2001 6:40
I had to make the "Regedit4" at the beginning of the registry entry all caps for this
to work on NT4.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=136 (2 of 2) [18/02/2004 14:45:48]

SourceForge
Logo

Tip #137 - automatically wrap left and right : vim online

not logged in (login)

Home
Search

Tip #137: automatically wrap left and right


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/3, Viewed by 1160

created: October 14, 2001 21:15


author: Brian Medley
I hate it
flickers.
fir right
help with
<silent>,

complexity: basic
as of Vim: 5.7

when I hit left (or h) and my screen


I want it to go up to the next line. Ditto
(or l). Below are two functions / mappings to
that. I'm pretty sure that if you remove the
then it will work in 5.x...

nnoremap <silent> <Left> :call WrapLeft()<cr>


nnoremap <silent> <Right> :call WrapRight()<cr>
nnoremap <silent> h
nnoremap <silent> l

:call WrapLeft()<cr>
:call WrapRight()<cr>

function! WrapLeft()
let col = col(".")
if 1 == col
" don't wrap if we're on the first line
if 1 == line(".")
return
endif
normal! k$
else
normal! h
endif
endfunction
function! WrapRight()
let col = col(".")
if 1 != col("$")
let col = col + 1
endif
if col("$") == col
" don't wrap if we're on the last line
if line("$") == line(".")
return
endif
normal! j1|
http://www.vim.org/tips/tip.php?tip_id=137 (1 of 2) [18/02/2004 14:45:50]

Tip #137 - automatically wrap left and right : vim online

else
normal! l
endif
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Remapping Alt, Ctrl and Caps in Win2k | Getting name of the function >>

Additional Notes
vimonline@geert.triple-it.nl, October 15, 2001 0:45
There is an existing feature for this in Vim:
"set whichwrap=<,>,h,l,[,]"
this causes the cursorkeys, as well as h and l, to wrap
when used at beginning and end of lines.
(the <> and [] differ in that <> are the cursorkeys
used in normal and visual mode, and the [] are the
cursorkeys in insert mode)
See :help whichwrap
So imho no complex scripting needed.
grtz,
Geert van der Ploeg
vschum1 at towson dot edu, November 30, 2003 9:20
I love you for this tip!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=137 (2 of 2) [18/02/2004 14:45:50]

SourceForge
Logo

Tip #138 - Getting name of the function : vim online

not logged in (login)

Home
Search

Tip #138: Getting name of the function


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 15/13, Viewed by 1213

created: October 15, 2001 15:29


author: Nitin Raut

complexity: intermediate
as of Vim: 5.7

Hi All,
While browsing code one always needs to know which
function you are currently looking. Getting the name is
very painful when the functions are lengthy and you are
currently browsing NOT near to the start of the
function. You can get the function's name by using this
simple mapping.
Just place this in your .vimrc.
map _F ma[[k"xyy`a:echo @x<CR>
now _F will display which function you are currently in.
Enjoy the power of Vim
-Nitin Raut
PS: The working is as follows, mark the current line
with a, jump to the previous '{' in the first column, go
one line up, yank the line in register x, return to the
mark a, echo the value of register x, which is the
wanted function name.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<automatically wrap left and right | Alignment: =, LaTeX tables, declarations, etc >>

Additional Notes
Anonymous, October 16, 2001 3:53

http://www.vim.org/tips/tip.php?tip_id=138 (1 of 3) [18/02/2004 14:45:52]

Tip #138 - Getting name of the function : vim online

using vim 6.0 (running on a terminal emulator) i found


this to be quite useful, but ugly, since the function
name is being displayed 2 lines above the bottom of the
screen, along with the message "Hit ENTER or type
command to continue" on the bottom line of the screen.
after a bit of investigation, i found that this is
because the line being copied has a carage return at
the end of the line, which is then being echoed. so,
if instead you use:
map _F ma[[k"xy$`a:echo @x<CR>
the line without the carage return is copied, so now
the function name is displayed on the bottom line of
the screen, and there is no additional message, or key
press required.
i am still getting the message when the function name
is longer than the width of the screen, but this is
quite rare in my code. converting this into a funciton
should allow more complex processing of the line to fix
that problem also. i may have a go at some point.
Anonymous, October 16, 2001 18:20
I used to use a macro like this , but I find a more
'vi' way to this is as follows:
press [[ to get to the start of the function and look
around if you want.
then type '' (that's two single ' ) to return you to
where you were.
It's more keystrokes, but it lets you not have to deal
with functions that aren't formated as you'd expect.
Anonymous, October 18, 2001 2:20
interesting, i didnt know about that command.
this does suggest the further incrimental improvement
to the macro:
map _F [[k"xy$``:echo @x<CR>
which saves playing around with the users markers.
personally i prefer the macro because i can see the
code and the function name all at once, which means i
dont have to remember quite so much <g>
benoit.cerrina@writeme.com, October 18, 2001 2:59

http://www.vim.org/tips/tip.php?tip_id=138 (2 of 3) [18/02/2004 14:45:52]

Tip #138 - Getting name of the function : vim online

using a plugin like TagsBase vimscript #100 will allow


you to do this for many more languages
jw3@gyral.com, October 18, 2001 6:32
Hi.
If you are using the old formatting style ("the one
true formatting style"), i.e.
int something() {
}
...then this won't work. You can use the following
instead:
map _F ma][%0"xy$`a:echo @x<CR>
][ finds the next '}' on the first column, % finds the
complementary '{',
'0' goes to the beginning of line.
Regards,
j.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=138 (3 of 3) [18/02/2004 14:45:52]

SourceForge
Logo

Tip #139 - Alignment: =, LaTeX tables, declarations, etc : vim online

not logged in (login)

Home
Search

Tip #139: Alignment: =, LaTeX tables, declarations, etc


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 46/15, Viewed by 3597

created: October 16, 2001 8:05


author: Charles E. Campbell, Jr.

complexity: basic
as of Vim: 5.7

Check out
http://www.erols.com/astronaut/vim/textab.html
and see some examples of text alignment (its hopeless to
do it here with
proportional fonts). You'll be able to download textab
source, a Windows-based
textab executable, and a scriptfile containing a
convenient interface (ttalign.vim). The textab program
coupled with <ttalign.vim> lets you:
1. align C language statements on their = += -= /= etc
symbols
2. align C language declararations: separate columns for
types, *[, variable
names, initializations (=), and comments (// or /* ..
*/)
3. align C/C++ language comments (//, /* .. */)
4. align C/C++ language (ansi) function argument lists
5. align LaTeX tables on their && separators
6. align HTML tables with </TD><TD> separators
7. align on several characters: < ? : | @ ; (or modify
them to handle whatever
alignment characters you want)
rate this tip

Life Changing

Helpful

Unfulfilling

<<Getting name of the function | tip using embedded perl interpreter >>

Additional Notes
cec@NgrOyphSon.gPsfAc.nMasa.gov, May 7, 2002 11:14

http://www.vim.org/tips/tip.php?tip_id=139 (1 of 2) [18/02/2004 14:45:55]

rate

Tip #139 - Alignment: =, LaTeX tables, declarations, etc : vim online

Textab and <ttalign.vim> have been superceded by


<Align.vim> and <AlignMaps.vim>. Thus alignment
is now done completely by Vim scripts, so no more
compiling and worrying with filter options. The
new Align() function is more powerful, too:
* cyclic left, right, and centering justification
* cyclic or equivalent multiple regular-expression
separators
* improved initial white space control
* specifiable separator padding
* visual range specified alignment, including via
visual-block
* a <Align.txt> help file is now available
These new tools are available at the same page
indicated above.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=139 (2 of 2) [18/02/2004 14:45:55]

SourceForge
Logo

Tip #140 - tip using embedded perl interpreter : vim online

not logged in (login)

Home
Search

Tip #140: tip using embedded perl interpreter


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 20/8, Viewed by 3216

created: October 17, 2001 13:47


author: Benoit Cerrina

complexity: advanced
as of Vim: 6.0

When writing scripts using the embedded interpreter


available if vim has the +perl ore +perl/dyn on
gives you access to this powerfull and FAST scripting
language (especially fast compared to vim
scripts) there are some gotchas.
First:
never embed complex perl command in the body of a vim
function this will be recompiled and evaled
each time for a tremendous loss of time.instead to it
like this
perl << EOF
sub mySub
{
#some usefull perl stuff
}
EOF
function! MyFunction
perl mySub "an argument", "another"
endfunction
to pass computed argument to your perl sub use the vim
exec command
function! MyFunction
exec "perl mySub " . aLocalVar . ", " b:aBufferLocalVar
endfunction
It may be very hard to debug your perl sub since the
output of the perl compiler is
somehow lost in the middle of nowhere and the debugger is
not available.
When a compilation error occurs in your sub definition
you'll get an error message
when you try to call it saying that the sub does not
exists.
One thing which I have found very usefull is to write a

http://www.vim.org/tips/tip.php?tip_id=140 (1 of 4) [18/02/2004 14:45:57]

Tip #140 - tip using embedded perl interpreter : vim online

fake VIM module with stub


methods which will allow you to use the command line perl
interpretor to at least
compile your program. You could make your stub smart
enough to fake a vim
and use the debugger. Here is a sample for such a fake
module defining just
those method which I was using.
package VIM;
use diagnostics;
use strict;
sub VIM::Eval
{
$_ = shift;
print "Eval $_\n";
{
return
'^(?!!)([^\t]*)\t[^\t]*\t(.*);"\t([^\t]*)\tline:(\d*).*$'
if (/g:TagsBase_pattern/);
return $ARGV[0] if (/b:fileName/);
return '$3' if (/g:TagsBase_typePar/);
return '$1' if (/g:TagsBase_namePar/);
return '$4' if (/g:TagsBase_linePar/);
return 'Ta&gs' if (/s:menu_name/);
return $ARGV[1] if (/g:TagsBase_groupByType/);
die "unknown eval $_";
}
}
sub VIM::Msg
{
my $msg = shift;
print "MSG $msg\n";
}
sub VIM::DoCommand
{
my $package;
my $filename;
my $line;
($package, $filename, $line) = caller;
my $command = shift;
print "at $filename $line\n";
print "DoCommand $command\n";
}
1;
Then you can copy other your perl code in a separate file
http://www.vim.org/tips/tip.php?tip_id=140 (2 of 4) [18/02/2004 14:45:57]

Tip #140 - tip using embedded perl interpreter : vim online

and add a use VIM; at the top


and your set to debug.
Good Vimming good perling.
Benoit
PS:
this tips are probably true for other scripting languages
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Alignment: =, LaTeX tables, declarations, etc | Add your function heading with a keystroke >>

Additional Notes
benoit.cerrina@writeme.com, October 19, 2001 14:27
For an example of the technics described see vimscript
#100,
it is while developping this script that I found most
of this.
benoit.cerrina@writeme.com, October 29, 2001 23:02
little changes to the tip
perl << EOF
sub mySub
{
#some usefull perl stuff
}
EOF
function! MyFunction()
perl mySub "an argument", "another"
endfunction
to pass computed argument to your perl sub use the vim
exec command
function! MyFunction()
exec "perl mySub " . aLocalVar . ", " b:aBufferLocalVar
endfunction
another way to do this is to get the arguments from
within the perl function
perl << EOF
sub mySub
{
my $anArg=VIM::Eval("a:anArg");
#some usefull perl stuff
http://www.vim.org/tips/tip.php?tip_id=140 (3 of 4) [18/02/2004 14:45:57]

Tip #140 - tip using embedded perl interpreter : vim online

}
EOF
function! MyFunction(anArg)
perl mySub
endfunction
finaly to be able to return something from perl
perl << EOF
sub mySub
{
my $anArg=VIM::Eval("a:anArg");
#some usefull perl stuff
VIM::DoCmd "let retVal=". aMeaningfullThingToReturn;
}
EOF
function! MyFunction(anArg)
perl mySub
if exists('retVal')
return retVal
endif
endfunction
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=140 (4 of 4) [18/02/2004 14:45:57]

SourceForge
Logo

Tip #141 - Add your function heading with a keystroke : vim online

not logged in (login)

Home
Search

Tip #141: Add your function heading with a keystroke


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 60/23, Viewed by 1466

created: October 18, 2001 22:36


author: Mohit Kalra kmohit@in.ibm.com

complexity: basic
as of Vim: 5.7

Below is a tip that the C/C++ Newbies may find interesting and handy
to use. The following code will add a function heading and position
your cursor just after Description so that one can document as one
proceeds with code.
function FileHeading()
let s:line=line(".")
call
setline(s:line,"/***************************************************")
call append(s:line,"* Description - ")
call append(s:line+1,"* Author Mohit Kalra")
call append(s:line+2,"* Date ".strftime("%b %d %Y"))
call append(s:line+3,"*
*************************************************/")
unlet s:line
endfunction
imap <F4>

<esc>mz:execute FileHeading()<RET>`zjA

Where <esc> stands for ^V+ESC and <RET> for ^V+ENTER


rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<tip using embedded perl interpreter | Automatic function end commenting for C++ and Java >>

Additional Notes
indiaguru100@yahoo.com, November 6, 2002 11:39
Hi:
What key has to be typed for this to be working. I am fairly new to
this board.
imap <F4> mz:execute FileHeading()`zjA
The last 3 chars (zjA) is it typo ? or I have to include in file?
mohit kalra, November 8, 2002 6:23

http://www.vim.org/tips/tip.php?tip_id=141 (1 of 2) [18/02/2004 14:45:59]

Tip #141 - Add your function heading with a keystroke : vim online

to get this working type F4 in insert mode.


the `zja is not a typo. Observe that :
1. mz is actually marking the first line that is inserted becoz of
this macro. That is, it remembers the position of /******
2. `z actually takes the cursor to that marker.
3. j will take you one line below that marked line.
4. A will put you in Append mode at the end of the line where the
cursor is.
Effectively, you have a cursor that is in insert mode and is
positioned right after "Description" so that you can type it then
and there itself.
HTH
Filip K., November 4, 2003 14:44
Very nice tip - it can be used generally everywhere you need some
one-stroke-large-block-of-text-inserting. This includes all
programming languages and much more.
I was wondering however if you can insert some block of text as a
header for a newly created file? I am thinking about inserting a
header like the one show in the tip every time I create a ".java"
file.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=141 (2 of 2) [18/02/2004 14:45:59]

SourceForge
Logo

Tip #142 - Automatic function end commenting for C++ and Java : vim online

not logged in (login)

Home
Search

Tip #142: Automatic function end commenting for C++ and Java
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/9, Viewed by 1417

created: October 19, 2001 9:44


author: Kalle Bjrklid

complexity: intermediate
as of Vim: 6.0

Some people have a habit of adding the function name as


a comment to the end of that function, if it is long, so
that he/she knows which function the '}' ends. Here's a
way to automate the process.
Use the following abbreviation:
iab }// } // END:
<esc>10h%$?\w\+\s*(<cr>"xy/\s*(<cr>/{<cr>:nohl<cr>%$"xpa
If you now end the function with '}//', the follwoing
string will be automatically generated: '} //END:
functionname'
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Add your function heading with a keystroke | Use of Vim folds for javadocs >>

Additional Notes
bjorklid at jyu.fi, October 19, 2001 10:05
Whoops. It seems that a tip like this has allready been
sent here (see vimscript #125). Sorry about that.
bjorklid at jyu.fi, October 19, 2001 10:07
and of course I meant vimtip #125 (not script). I begin
to feel a little foolish here ;-)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=142 [18/02/2004 14:46:06]

SourceForge
Logo

Tip #143 - Use of Vim folds for javadocs : vim online

not logged in (login)

Home
Search

Tip #143: Use of Vim folds for javadocs


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/6, Viewed by 1178

created: October 20, 2001 6:18


author: sameer chabungbam

complexity: basic
as of Vim: 6.0

Hi,
The fold-method marker can be effectively use to set the folds
in your Java source. Define some marker and place it inside
HTML comments <!-- xx -->. This way, it does not affect the
Javadocs generated without the necessity of a seprate comment
line.
e.g.
/**
* <!-- zz.FOLDSTART class AbcClass -->
* The class description.
* ...
*/
public class AbcClass {
/**
* <!-- method zz.FOLDSTART someMethod() -->
* Method description.
*/
public void someMethod();
...
} /* zz.END: AbcClass */
/* Put this at the end of your file */
/* vim:fdm=marker fmr=zz.FOLDSTART,zz.END fdl=2 fdc=2: */
Now, the files will be opened with the methods neatly folded.
You can use "zR" to open all folds (or click on the "+" at the
left column).
Sameer.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Automatic function end commenting for C++ and Java | recording keystrokes by "q" for repested jobs >>

http://www.vim.org/tips/tip.php?tip_id=143 (1 of 2) [18/02/2004 14:46:09]

Tip #143 - Use of Vim folds for javadocs : vim online

Additional Notes
dsummersl@yahoo.com, July 11, 2002 6:43
Another thing you might try, if you don't feel like mucking up
your code by adding markers everywhere(I really love folding
but I don't like the idea of having to modify my sources to get
it to work just right) is to set your foldmarker to the javadoc
comment blocks:
fdm=/**,*/
Seems to work pretty well, doesn't interfere with normal /* */
chunks anyway.
Koenraad Heijlen, July 26, 2002 13:28
Really nice folding on /** */ if you are editing source that's
overcommented....
I use these settings to autoload java files :
autocmd FileType java :set fmr=/**,*/ fdm=marker fdc=1
Eric Bowman, July 30, 2002 14:38
It seems like the last idea is a bit buggy. Not all javadoc
comments fold automatically, and some really weird behavior
results. But the following works like a charm:
In java.vim, change the javaDocComment line to:
syn region javaDocComment
start="/\*\*" end="\*/"
transparent fold keepend
contains=javaCommentTitle,@javaHtml,javaDocTags,javaTodo,@Spell
(added "transparent fold").
Then in my .vimrc I added:
set foldmethod=syntax
Voila!

No more annoying javadoc comments everywhere...

Eric Bowman, July 30, 2002 14:48


Oops, you probably want to leave the "transparent" out...it
changes your javadoc colors to white! I misunderstood the very
:help syn-fold.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=143 (2 of 2) [18/02/2004 14:46:09]

SourceForge
Logo

Tip #144 - recording keystrokes by "q" for repested jobs : vim online

not logged in (login)

Home
Search

Tip #144: recording keystrokes by "q" for repested jobs


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 88/37, Viewed by 1505

created: October 21, 2001 9:43


author: Sameer Chabungbam

complexity: basic
as of Vim: 5.7

The most useful feature that I find in VIM is the


"recording" feature (:help recording). I have used this
to automatically insert function headers, re-indent
lines, and convert some 34 source files into HTML.
This feature is most useful when you want to do some
repeated jobs, which you cant do easily using ".". You
can set about writing a function, define a mapping, etc,
but then these things might take time. By recording,
you can try out and find the actual keystrokes that does
the job.
To start recording, press "q" in normal mode followed by
any of "0-9a-z". This will start recording the
keystrokes to the register you choose. You can also see
the word "recording" in the status(?) line. You can
start the key sequences that you want to record. You
can go to insert mode and type if you want.
To stop recording, press "q" in the normal mode.
To playback your keystrokes, press "@" followed by the
character you choose. Pressing "@@" will repeat the
same again.
Sameer.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Use of Vim folds for javadocs | Changing DOS style end of line to UNIX, or vise-versa >>

Additional Notes
revscat@swbell.net, November 1, 2002 12:56

http://www.vim.org/tips/tip.php?tip_id=144 (1 of 2) [18/02/2004 14:46:12]

Tip #144 - recording keystrokes by "q" for repested jobs : vim online

This is well and good, but how do you make macros work
across buffers or a split-screen? I frequently compare
two files in split-screen mode, and can't get recorded
macros to work it I have to move between screens. Any
ideas?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=144 (2 of 2) [18/02/2004 14:46:12]

SourceForge
Logo

Tip #145 - Changing DOS style end of line to UNIX, or vise-versa : vim online

not logged in (login)

Home
Search

Tip #145: Changing DOS style end of line to UNIX, or vise-versa


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 113/49, Viewed by 3537

created: October 22, 2001 12:06


author: Douglas Potts

complexity: basic
as of Vim: 5.7

Those of us doomed to work in both the Unix and Windows


world have many times encountered
files that were create/editted on systems other that the
one we are on at the time of our edits. We
can easily correct the dreaded '^M' at the end of our
Unix lines, or make files have more than one
line in DOS by:
To change from <CR><LF> (DOS) to just <LF> (Unix):
:set fileformat=unix
:w
Or to change back the other way:
:set fileformat=dos
:w
It also works for Apple land:
:set fileformat=mac
:w
And to tell the difference:
set statusline=%<%f%h%m%r%=%{&ff}\ %l,%c%V\ %P
^^^^^

This

shows what the current file's format is.


Happy Vimming!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<recording keystrokes by "q" for repested jobs | opening multiple files from a single command-line >>

Additional Notes
Anonymous, October 22, 2001 13:27

http://www.vim.org/tips/tip.php?tip_id=145 (1 of 5) [18/02/2004 14:46:16]

Tip #145 - Changing DOS style end of line to UNIX, or vise-versa : vim online

I unfortunately do not find this to be true.


have ^M in my files after doing this.

I still

pottsdl@yahoo.com, October 23, 2001 4:50


This may be the case if an extra set of ctrl-m (^M)
were at the end of
line.
That being the case:
:%s/^M$//
will take care of that.
and that is ctrl-m not caret-M.
Or if there are more than one ^M at the end:
:%s/^M\+$//
HTH
cec@NgrOyphSon.gPsfAc.nMasa.gov, October 23, 2001 7:16
In order to process a bunch of files I usually
qb
:%s/^M$//
:set ff=unix
:w
:n
q
(then use the number of files)@b
To speed things up I also
:set lz
:set ul=-1
This converts dos->unix. To go the other way, remove
the substitute
and :set ff=dos . I haven't ever used a mac, but :set
ff=mac is
also supported in case you need to do that.
pottsdl@yahoo.com, October 25, 2001 5:20

http://www.vim.org/tips/tip.php?tip_id=145 (2 of 5) [18/02/2004 14:46:16]

Tip #145 - Changing DOS style end of line to UNIX, or vise-versa : vim online

Yet another way to do it for multiple files, if in Vim


6.0+ is to use the
:bufdo or :windo commands.
See
:h bufdo
and
:h windo
respectively
eferna1@platea.pntic.mec.es, October 25, 2001 10:19
Hmm, Vim automagically detects the format of a text
file (DO$, UNIX, MAC) and it tells that at the command
line. To change the format issue the command :set
fileformat=<format> and save the file. ;-)). Anyway,
update to the 6.0 version now!
-It is illegal for anyone to give lighted cigars to
dogs, cats, and other
domesticated animal kept as pets.
[real standing law in Illinois, United
States of America]
drini@br.crashed.net, November 14, 2001 19:39
yet another way to check
:set ff?

the file kind:

anonymous, September 26, 2002 14:59


None of this really works. I still get the ^M... I
think I try lemmy which autodetects UNIX files and does
the conversions...
area51@braintransplants.com.nospam, October 20, 2002 2:01
None of these tips worked for me either. I still have
^M all over the place in my file.
area51@braintransplants.com.nospam, October 20, 2002 2:02
None of these tips worked for me either. I still have
^M all over the place in my file.
mperry4@mail.lesley.edu, January 2, 2003 8:57
Umm, I try to use the replace option but how do you
enter ctrl-M? What to you type before it so it will
write the character and not execute a ctrl-M ?
raxxy@nospam.shaw.ca, January 10, 2003 17:30

http://www.vim.org/tips/tip.php?tip_id=145 (3 of 5) [18/02/2004 14:46:16]

Tip #145 - Changing DOS style end of line to UNIX, or vise-versa : vim online

The proper substitution (worked for me) is:


:%s/[^M]$//
and the fileformat change;
:set fileformat=unix
Anonymous, March 17, 2003 15:09
I has the same problems with ^M at the end of a line in
a Windows install. After some fiddling I found out
that:
1. If you have a _vimrc file (even if it's empty) you
won't be in vi compatible mode.
2. If you are not in vi compatible mode and you don't
have the vimrc set up correctly vim always thinks you
are in Unix mode even when open a DOS file on a Windows
machine
3. An easy way to see this is to type :help fileformats
to see the ^M chars at the ends of the line in help.
4. To fix this you need to add
:set fileformats=dos,unix
to your _vimrc. Your platform default file should
be first (if you did this on a mac you would say :set
fileformats=mac,dos,unix
5. Close vim and reopen it.
Problem should be solved. (Worked for me :-)
Of course now you need to add more commands to your
_vimrc :-)
Anonymous, July 14, 2003 18:48
fantastic tip.

simple and useful.

a.lacey@man.ac.uk, September 22, 2003 8:28


One addition that might help some people. There are
two ways to get a ^M symbol. One is doing
CTRL-V CTRL-M - generate
dos file read on Unix

^M as might

be present in a

the other is
CTRL-V CTRL-RETURN - generate the ^M representation of
a Unix carriage-return
So you might find that you want to replace CTRL-V CTRLM with CTRL-V CTRL-RETURN
i.e.
http://www.vim.org/tips/tip.php?tip_id=145 (4 of 5) [18/02/2004 14:46:16]

Tip #145 - Changing DOS style end of line to UNIX, or vise-versa : vim online

:%s/CTRL-V CTRL-M/CTRL-V CTRL-RETURN/


Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=145 (5 of 5) [18/02/2004 14:46:16]

SourceForge
Logo

Tip #146 - opening multiple files from a single command-line : vim online

not logged in (login)

Home
Search

Tip #146: opening multiple files from a single command-line


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/5, Viewed by 1287

created: October 23, 2001 13:29


author: salmanhalim@hotmail.com

complexity: basic
as of Vim: 5.7

i use the :split command a lot -- both to open a second


window containing the currently edited file and to edit
a new file altogether (with the :split <filename>
option). however, i also like to be able to edit more
than one file and calling :sp multiple times is
inconvenient. so, i created the following command,
function and abbreviation:
function! Sp(...)
if(a:0 == 0)
sp
else
let i = a:0
while(i > 0)
execute 'let file = a:' . i
execute 'sp ' . file
let i = i - 1
endwhile
endif
endfunction
com! -nargs=* -complete=file Sp call Sp(<f-args>)
cab sp Sp
this retains the behaviour of :sp in that i can still
type :sp (the abbreviation takes care of that). :Sp
takes any number of files and opens them all up, one
after the other.
the things i have noticed are that this causes 'sp' to
be expanded to 'Sp' everywhere, even in search
patterns. also, prepending 'vert' doesn't work. if
there is interest, i'll do that.
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=146 (1 of 2) [18/02/2004 14:46:18]

Helpful

Unfulfilling

rate

Tip #146 - opening multiple files from a single command-line : vim online

<<Changing DOS style end of line to UNIX, or vise-versa | How to write a plugin >>

Additional Notes
warlocky@pchome.com.tw, June 26, 2003 0:50
This is great! It saves the effort of typing multiple
:sp under vim. I have 2 suggestions
1. If I use
vim
:Sp a b c
It results in 4 windows in vim. One is empty. Is
this could be improved?
2. Is there a way to make a new_cmd that splits a
window to 3, each one for a file specified in the
command line?
For example,
vim a b c
:new_cmd
then I could see 3 windows in vim. One for a, one
for b, and one for c.
Anyway, still thanks for your :Sp.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=146 (2 of 2) [18/02/2004 14:46:18]

SourceForge
Logo

Tip #147 - How to write a plugin : vim online

not logged in (login)

Home
Search

Tip #147: How to write a plugin


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 50/17, Viewed by 2747

created: October 24, 2001 7:42


author: Charles E. Campbell, Jr.

complexity: advanced
as of Vim: 6.0

This tip gives a skeleton for writing a plugin; Vim's


help files have plenty
of details (:he plugin, :he write-plugin, :he plugindetails).
# ----------------------------------------------------------------------------# Exit when your app has already been loaded (or
"compatible" mode set)
if exists("loaded_YourAppName") || &cp
finish
endif
# Public Interface:
# AppFunction: is a function you expect your users to
call
# PickAMap: some sequence of characters that will run
your AppFunction
# Repeat these three lines as needed for multiple
functions which will
# be used to provide an interface for the user
if !hasmapto('<Plug>AppFunction')
map <unique> <Leader>PickAMap <Plug>AppFunction
endif
# Global Maps:
#
map <silent> <unique> <script> <Plug>AppFunction
\ :set lz<CR>:call <SID>AppFunc<CR>:set nolz<CR>
# ----------------------------------------------------------------------------# AppFunction: this function is available vi the
<Plug>/<script> interface above
fu! <SID>AppFunction()
..whatever..

http://www.vim.org/tips/tip.php?tip_id=147 (1 of 4) [18/02/2004 14:46:20]

Tip #147 - How to write a plugin : vim online

# your script function can set up maps to internal


functions
nmap <silent> <left> :set lz<CR>:silent! call
<SID>AppFunction2<CR>:set nolz<CR>
# your app can call functions in its own script and not
worry about name
# clashes by preceding those function names with <SID>
call <SID>InternalAppFunction(...)
# or you could call it with
call s:InternalAppFunction(...)
endf
# ----------------------------------------------------------------------------# InternalAppFunction: this function cannot be called
from outside the
# script, and its name won't clash with whatever else
the user has loaded
fu! <SID>InternalAppFunction(...)
..whatever..
endf
# ----------------------------------------------------------------------------Plugins are intended to be "drop into <.vim/plugin>" and
work. The problem
that the <Plug>, <SID>, etc stuff is intended to
resolve: what to do about
functions that have the same names in different plugins,
and what to do about
maps that use the same sequence of characters? The
first problem is solved
with <SID> (a script identifier number) that vim
assigns: program with it and
your users will be happier when your stuff works with
all their other stuff.
The second problem: what to about those maps is
addressed with <Plug>, <unique>,
etc. Basically the idea is: let the user know that
there are clashes and don't
overwrite previously existing maps. Use the user's
preferred map-introducer
sequence (I like the backslash, but there are many
keyboards which make
producing backslashes unpleasant, and those users
usually prefer something
else).

http://www.vim.org/tips/tip.php?tip_id=147 (2 of 4) [18/02/2004 14:46:20]

Tip #147 - How to write a plugin : vim online

What I like to do is to have a pair of start/stop maps


to reduce my impact on
the namespace. When the starting map is used, it kicks
off a starting function
that introduces all the maps needed. When the stopping
map is used, it not
only removes the maps the starter made but restores any
maps the user had had
that would have clashed. I also use the start/stop pair
of functions to set
and restore options that cause my scripts difficulties.
Check out DrawIt.vim's SaveMap() function for a way to
save user maps.
Restoring maps with it is easy:
if b:restoremap != ""
exe b:restoremap
unlet b:restoremap
endif
So you can see it sets up a string variable with all the
maps that the user
had that would have clashed with my application.
One final thing: if your application needs to share
information between its
various functions, see if you can use s:varname (a
variable that only your
script's functions can access) or b:varname (a variable
that anything associated
with the buffer your application is running with can
access) instead of using
global variables.
Good luck and happy Vimming!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<opening multiple files from a single command-line | Make great use of those homemade menus >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=147 (3 of 4) [18/02/2004 14:46:20]

Tip #147 - How to write a plugin : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=147 (4 of 4) [18/02/2004 14:46:20]

SourceForge
Logo

Tip #148 - Make great use of those homemade menus : vim online

not logged in (login)

Home
Search

Tip #148: Make great use of those homemade menus


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/7, Viewed by 1233

created: October 24, 2001 14:13


author: Rex Byrns

complexity: basic
as of Vim: 6.0

Accidently discovered that using <alt><Menu


Hotletter><cr> (e.g <alt>b<cr> - for the buffer menu)
causes the menu to break out in a seperate window.
Selecting the menu with the mouse and then hitting enter
does not seem to do it.
I will have to learn to add hotletters to my menus now
so that the mouse can take a break.
I am a total newbie with vim, but constantly amazed....
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<How to write a plugin | Automatically update your diff upon writing. >>

Additional Notes
salmanhalim@hotmail.com, October 24, 2001 18:39
i suspect you're referring to the tearoff capability of
the gui menus. your 'guioptions' must include a 't' in
the value for them to be enabled. they are the very
first thing (looks like a small pair of scissors
surrounded by hyphens) in each menu and CAN be clicked
with the mouse also.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=148 [18/02/2004 14:46:23]

SourceForge
Logo

Tip #149 - Automatically update your diff upon writing. : vim online

not logged in (login)

Home
Search

Tip #149: Automatically update your diff upon writing.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 17/8, Viewed by 852

created: October 29, 2001 12:00


author: Douglas Potts

complexity: intermediate
as of Vim: 6.0

When trying to reconcile differences between files, and


using the new
'diff' functionality in Vim 6.0 you may want to
automatically update
the differences as you are working along. A convienent
time is when you
write out either of the files you are diff'ing. This
autocmd will take
care of doing that for you.
" If doing a diff. Upon writing changes to file,
automatically update the
" differences
au BufWritePost
*
if
&diff == 1
au
BufWritePost
*
:diffupdate
au BufWritePost
*
endif
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Make great use of those homemade menus | Generating a column of increasing numbers >>

Additional Notes
jaldri1 at gl dot umbc dot edu, June 16, 2003 15:05
Just knowing that :diffupdate exists is
useful. Thanks.
Add Note

http://www.vim.org/tips/tip.php?tip_id=149 (1 of 2) [18/02/2004 14:46:25]

Tip #149 - Automatically update your diff upon writing. : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=149 (2 of 2) [18/02/2004 14:46:25]

SourceForge
Logo

Tip #150 - Generating a column of increasing numbers : vim online

not logged in (login)

Home
Search

Tip #150: Generating a column of increasing numbers


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 49/18, Viewed by 2171

created: October 31, 2001 9:03


author: Charles E. Campbell, Jr.

complexity: intermediate
as of Vim: 5.7

You can use the "Visual Incrementing" script from


http://www.erols.com/astronaut/vim/index.html#VimFuncs
to convert a block of numbers selected via ctrl-v (visual block)
into a column of increasing integers. Select the column, press :I<CR>,
and the first line's number will be used as a starting value. Subsequent
lines's numbers will be incremented by one.
If the ctrl-v block is "ragged right", which can happen when "$" is used
to select the right hand side, the block will have spaces appended as
needed to straighten it out. If the strlen of the count exceeds the
visual-block allotment of spaces, then additional spaces will be inserted.
Example:

Put cursor on topmost zero, select column with ctrl-v, then :I

vector[0]=
vector[0]=
vector[0]=
vector[0]=
vector[0]=

1;
1;
1;
1;
1;

-->

vector[0]=
vector[1]=
vector[2]=
vector[3]=
vector[4]=

1;
1;
1;
1;
1;

This script works with both vim 5.7 (:so visincr.vim) or vim 6.0 (source it
as for vim 5.7 or drop it into the .vim/plugin directory).

rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=150 (1 of 4) [18/02/2004 14:46:27]

Helpful

Unfulfilling

rate

Tip #150 - Generating a column of increasing numbers : vim online


<<Automatically update your diff upon writing. | an ascii table >>

Additional Notes
sitar@procaut.sk, November 21, 2001 3:26
" another way of generating incremented numbers
"=============================================================================
" File: increment.vim
" Author: Stanislav Sitar (sitar@procaut.sk)
" Help:
" Put increment.vim into a plugin directory.
" Use in replacement strings
" :let I=0
" :%s/my_token_word_to_be_replaced_by_the_auto_incremented_numbers/\=INC(1)/
" or
" :let I=95
" :%s/@/\=INC(5)/
" to replace each occurence of character @ with numbers starting with 100 and
" growing by 5 (100, 105, 110, ...)
"
" Instalation: save this text as increment.vim in your plugins directory
"=========================================================================
let g:I=0
function INC(increment)
let g:I =g:I + a:increment
return g:I
endfunction
cec@NgrOyphSon.gPsfAc.nMasa.gov, November 28, 2001 13:04
Visincr.vim has been improved -- it now uses virtual column calculations
which avoid problems with leading tabs -- you may even mix leading
tabs and spaces, incrementing only the visually selected column.

http://www.vim.org/tips/tip.php?tip_id=150 (2 of 4) [18/02/2004 14:46:27]

Tip #150 - Generating a column of increasing numbers : vim online

cec@NgrOyphSon.gPsfAc.nMasa.gov, December 3, 2001 7:06


Other methods/scripts for incrementing scripts are available as:
Srinath Avadhanula vimscript#156
vimscript#145
Stanislav Sitar
If you're interested in using substitute based approaches, you
might wish to consider Stefan Roemer's <vis.vim>, which allows
one to apply a substitute to just a visual-block. You can get
a copy of his script at
http://www.erols.com/astronaut/vim/index.html#VimVuncs
-- see "Visual Block Commands"
cec@NgrOyphSon.gPsfAc.nMasa.gov, November 1, 2002 7:29
<visincr.vim> supports:
:I<CR> will use the first line's number as a starting point, incrementing by 1
:I #<CR> like :I, but will increment by given number; negative numbers work
fine
:II<CR> will pad on left as needed, otherwise like :I
:II #<CR> like :II, but will increment by given number
cec@NgrOyphSon.gPsfAc.nMasa.gov, May 28, 2003 13:00
More features for <visincr.vim>! There's now an additional script,
<calutil.vim>,
which adds some calendrical dates <-> Julian day conversion functions.
those, <visincr.vim> now has new commands:
IMDY [incr] : makes a column of month/day/year dates
IYMD [incr] : makes a column of year/month/day dates
IDMY [incr] : makes a column of day/month/year dates
ID [incr]
: makes a column of daynames
Of course, the optional incr (default value is 1) can be positive or
negative. Both
scripts are available at
http://www.erols.com/astronaut/vim/index.html#VimFuncs.
http://www.vim.org/tips/tip.php?tip_id=150 (3 of 4) [18/02/2004 14:46:27]

With

Tip #150 - Generating a column of increasing numbers : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=150 (4 of 4) [18/02/2004 14:46:27]

SourceForge
Logo

Tip #151 - an ascii table : vim online

not logged in (login)

Home
Search

Tip #151: an ascii table


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 14/15, Viewed by 1692

created: October 31, 2001 11:43


author: Adam Seyfarth

complexity: basic
as of Vim: 6.0

There is an ascii table in the vim-help files, but it's hard


to find. Thus, I shall give a pointer to it:
:help digraph-table
rate this tip

Life Changing

Helpful

Unfulfilling

rate

Site Help
<<Generating a column of increasing numbers | Spelling checkers for: Dutch, English, German, Hungarian, and
Yiddish >>

Additional Notes
Anonymous, November 1, 2001 7:13
The table does not list all ascii characters, for instance [az], [A-Z] and [0-9] are missing....
shlompi@hotmail.com, November 1, 2001 17:43
In fact it's not an ASCII table at all.
ASCII is 7-bit, codes 0x00 to 0x7F.
This table lists the C0, C1 and G1 ranges of ISO-8859-1 (ISOLatin1).
C0 - lower control codes, 0x00 to 0x1F (and 0x7F, DEL)
C1 - higher control codes, 0x80 to 0x9F
G1 - ISO-8859 extension range, 0xA0 to 0xFF
What is referred to as ASCII characters is the G0 range, 0x20
to 0x7E.
Anonymous, November 7, 2001 3:22
Note that you can get the ascii value (or whatever-value ;-)
of the character under cursor with 'ga' (think of it as "Get
Ascii" to remember it)
digitect@mindspring.com, March 24, 2002 18:55

http://www.vim.org/tips/tip.php?tip_id=151 (1 of 2) [18/02/2004 14:46:29]

Tip #151 - an ascii table : vim online

You can also use the cream-ascii routines


(http://vim.sourceforge.net/scripts/script.php?script_id=247)
to insert a specific ascii code with a dialog.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=151 (2 of 2) [18/02/2004 14:46:29]

SourceForge
Logo

Tip #152 - Spelling checkers for: Dutch, English, German, Hungarian, and Yiddish : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #152: Spelling checkers for: Dutch, English, German, Hungarian, and
Yiddish
tip karma

Rating 18/8, Viewed by 1841

created: November 2, 2001 7:10


author: Charles E. Campbell, Jr.

complexity: intermediate
as of Vim: 5.7

Under
http://www.erols.com/astronaut/vim/index.html#vimlinks_scripts
are links to spelling checkers for Dutch, English, German,
Hungarian,
and Yiddish, all based on the original engspchk.vim. The
spelling
checker provides as-you-type spell checking; with vim6.0 it
will avoid
checking on partially typed words.
Provided are several maps:
\et
file
\es
\en
\ep
\ea

: add

word under cursor into database for just this

:
:
:
:

word under cursor into database (permanently)


cursor to the next
spelling error
cursor to the previous spelling error
for alternative spellings of word under cursor

save
move
move
look

To use \ea you will need agrep:


agrep source:
ftp://sunsite.unc.edu/pub/Linux/utils/text/agrep-2.04.tar.Z
agrep Win exe: http://www.tgries.de/agrep
To use the spell checkers just source it in:
ex.

so engspchk.vim

To read more about it see


http://www.erols.com/astronaut/vim/index.html#Spelling

rate this tip

Life Changing

Helpful

Unfulfilling

<<an ascii table | Making Parenthesis And Brackets Handling Easier >>

Additional Notes
http://www.vim.org/tips/tip.php?tip_id=152 (1 of 2) [18/02/2004 14:46:31]

rate

Tip #152 - Spelling checkers for: Dutch, English, German, Hungarian, and Yiddish : vim online

cec@NgrOyphSon.gPsfAc.nMasa.gov, November 2, 2001 7:14


Thomas Koehler has provided
shell) which
takes a dictionary (list of
<engspchk.vim>
to create spelling checkers
this and
post it, please let me know
links! Also,
remove the NOSPAM hidden in
email address.

a script (using the Bourne


words) and merges it with
for other languages.

If you do

and I'll add it to my list of


the email above to get my real

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=152 (2 of 2) [18/02/2004 14:46:31]

SourceForge
Logo

Tip #153 - Making Parenthesis And Brackets Handling Easier : vim online

not logged in (login)

Tip #153: Making Parenthesis And Brackets Handling Easier

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 107/46, Viewed by 3041

created: November 4, 2001 11:56


author: Joachhim Hofmann (Schuttberg)
1)
2)
3)
4)

complexity: basic
as of Vim: 5.7

++++++++++++++++++++++++++ "Automatic" bracket setting +++++++++++++++++++++++++++++


+++++++++++++ Further improvement of parenthesis/bracket expanding +++++++++++++++++
++++++++++++++++++++++++++++ "Late" bracketing of text +++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++ Conclusion ++++++++++++++++++++++++++++++++++++++ ++++

=======================================================================================
1) ++++++++++++++++++++++++++ "Automatic" bracket setting +++++++++++++++++++++++++++++
To automatically insert a closing parenthesis when typing an opening
parenthesis you can insert the following simple mapping to your vimrc:
:inoremap ( ()<ESC>i
This ends up with the cursor between the opening and the closing parenthesis
in insert mode.
You can apply this and the following tips, of course, with the kind of
parenthesis/bracket
character you want to, i.e. (, {, [, < ..... and, pretty useful as well,
quotation marks ",',.... (to be continued)
2) +++++++++++++++ Further improvement of parenthesis/bracket expanding
++++++++++++++++++
I you are ready with filling the parenthesis/brackets, you likely want to
"escape" from the brackets again to continue coding.
To make this pretty comfortable, I invented the following kind of mappings, which get
out
of the last expanded parenthesis/bracket, regardless of the actual type of it, and
enter append mode again.
I mapped this kind of "getaway" with CTRL_j, you may use your favorite keystroke with

http://www.vim.org/tips/tip.php?tip_id=153 (1 of 7) [18/02/2004 14:46:35]

Tip #153 - Making Parenthesis And Brackets Handling Easier : vim online

it.
...
:inoremap ( ()<ESC>:let leavechar=")"<CR>i
:inoremap [ []<ESC>:let leavechar="]"<CR>i
...
:imap <C-j> <ESC>:exec "normal f" . leavechar<CR>a
Explanation: The variable "leavechar" contents the actual char which is to "escape"
from.
3) ++++++++++++++++++++++++++++ "Late" bracketing of text +++++++++++++++++++++++++++++
Occasionally I later want already written text parts to put in parenthesis.
I use the following macro, which brackets previously visually selected text.
I mapped it with _(.
:vnoremap _( <ESC>`>a)<ESC>`<i(<ESC>
Furthermore, a sort of mapping for bracketing a *single word* is conceivable.
Because this is not as general like the kind of visual mode mapping, I use
this kind of "word bracketing" only for surrounding the word right behind the cursor in
insert mode with **. I use the following macro to "emphasize" the word i just typed,
for newsgroup articles.
:imap _* <Esc>bi*<Esc>ea*<Space>
4) ++++++++++++++++++++++++++++++ Conclusion ++++++++++++++++++++++++++++++++++++++++++
Since I use these macros, I never caused a syntax error because of missing
brackets, and furthermore I can quickly insert parenthesis and qutotes into codeand non-code files.
JH 04.11.2001
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Spelling checkers for: Dutch, English, German, Hungarian, and Yiddish | Mappings to facilitate the creation of text >>

Additional Notes
http://www.vim.org/tips/tip.php?tip_id=153 (2 of 7) [18/02/2004 14:46:35]

Tip #153 - Making Parenthesis And Brackets Handling Easier : vim online

james_sandoz@yahoo.com, July 31, 2002 12:12


Great tip!

Led me to create this mapping:

inoremap { {<CR><BS>}<ESC>ko
to be used in conjunction with my autoindent setup:
set
set
set
set
set

expandtab
shiftwidth=4
smarttab
autoindent
smartindent

Now, any time i type a '{', this is what i get:


{
<cursor here ready for coding>
}
Great time saver and it ensures that i don't ever miss a brace. And it even works
for you crazy people who put the open brace on the same line as the
for/while/function name ;)
atkinssc AT engr orst edu, August 6, 2002 7:31
Well in the last note, someone suggested a mapping that created:
{
| <= Cursor
}
Although this is fine and dandy, f will not search anything but the current line; so
I remapped it to use:
imap <c-j> <esc>:exec "/" . leavechar . "/"<cr>A
Now what would be great is if, when you hit ) or ] or } when you've already filled in
the end charcter, to seek to the end and place your cursor outside of the block.
Any ideas?
rich_unger@alum.wustl.edu, October 1, 2002 17:17
I think I'm missing something. When I try to use the first tip, :inoremap (
()<ESC>i, I get the text "()<ESC>i" when I type "(".
http://www.vim.org/tips/tip.php?tip_id=153 (3 of 7) [18/02/2004 14:46:35]

Tip #153 - Making Parenthesis And Brackets Handling Easier : vim online

schuttberg@aol.com, November 9, 2002 11:53


You probably run vim in 'compatible' mode. (not recommended).
This happens usually when you have no _vimrc created.
Try renaming the file vimrc_example to .vimrc (UNIX) or _vimrc (Windows/DOS),
or set the option nocompatible: ":set nocompatible".
Achim
rwchin @ @ foxtrot . homeip . net, February 24, 2003 16:55
I modified this tip a bit to support different types of parenthisis better.
will remember the list of parenthesis you typed.
inoremap ( ()<esc>:call BC_AddChar(")")<cr>i
inoremap { {<cr>}<esc>:call BC_AddChar("}")<cr><esc>kA<cr>
inoremap [ []<esc>:call BC_AddChar("]")<cr>i
inoremap " ""<esc>:call BC_AddChar("\"")<cr>i
" jump out of parenthesis
inoremap <C-j> <esc>:call search(BC_GetChar(), "W")<cr>a
function! BC_AddChar(schar)
if exists("b:robstack")
let b:robstack = b:robstack . a:schar
else
let b:robstack = a:schar
endif
endfunction
function! BC_GetChar()
let l:char = b:robstack[strlen(b:robstack)-1]
let b:robstack = strpart(b:robstack, 0, strlen(b:robstack)-1)
return l:char
endfunction
seanahern@llnl.gov, June 20, 2003 20:41
Very impressive! As I was reading through the tip and trying the various
incantations, the thought in the back of my mind was that this should use a
stack. And the final tip did it for me! Thanks for the help, guys!
grojas@strategiinc.com, July 3, 2003 9:39

http://www.vim.org/tips/tip.php?tip_id=153 (4 of 7) [18/02/2004 14:46:35]

This one

Tip #153 - Making Parenthesis And Brackets Handling Easier : vim online

I really like the last implementationl, but I noticed a slight problem. The spacing
inside the curly braces is not a single tab, it also includes spaces. How do we get
a single tab inside the curly braces.
grojas@strategicinc.com, July 3, 2003 9:39
Sorry, wrong email address
drennalls@canada.com, July 7, 2003 7:32
I ran into this too. If there's actually a space in the mapping in your .vimrc file
it will get added to the mapping. So just make sure to remove the space.
If you check the current mapping by doing a
:inoremap {
if you did have that trailing whitespace it would show the mapping as
{ {<cr>}<esc>:call BC_AddChar("}")<cr><esc>kA<cr><Space>
Vim shouldn't interpret the whitespace as part of the mapping, perhaps this is a bug
?
maksimkim@mail.ru, July 17, 2003 0:14
And what about abbreviations?
for example:
iab psvm public static void main(String[] args) {<CR><CR>}
with all of those mappings it produce :
public static void main(String[] args){
} }])
How to avoid this?
Anonymous, July 21, 2003 17:17
Use inorea instead of iab
This won't trigger the autobracketing.
Anonymous, July 24, 2003 22:22
Thanks!
breadman@byu.edu, July 31, 2003 16:07

http://www.vim.org/tips/tip.php?tip_id=153 (5 of 7) [18/02/2004 14:46:35]

Tip #153 - Making Parenthesis And Brackets Handling Easier : vim online

The following may be a little more complex than it needs to be, but allows me to type
the closing character to get out of the delimiter, if I'm already at the end.
inoremap ( ()<ESC>i
inoremap [ []<ESC>i
inoremap { {<CR>}<ESC>O
autocmd Syntax html,vim inoremap < <lt>><ESC>i| inoremap > <c-r>=ClosePair('>')<CR>
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap } <c-r>=CloseBracket()<CR>
inoremap " <c-r>=QuoteDelim('"')<CR>
inoremap ' <c-r>=QuoteDelim("'")<CR>
function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
function CloseBracket()
if match(getline(line('.') + 1), '\s*}') < 0
return "\<CR>}"
else
return "\<ESC>j0f}a"
endif
endf
function QuoteDelim(char)
let line = getline('.')
let col = col('.')
if line[col - 2] == "\\"
"Inserting a quoted quotation mark into the string
return a:char
elseif line[col - 1] == a:char
"Escaping out of the string
return "\<Right>"
else
"Starting a string
return a:char.a:char."\<ESC>i"
endif
endf
http://www.vim.org/tips/tip.php?tip_id=153 (6 of 7) [18/02/2004 14:46:35]

Tip #153 - Making Parenthesis And Brackets Handling Easier : vim online
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=153 (7 of 7) [18/02/2004 14:46:35]

SourceForge
Logo

Tip #154 - Mappings to facilitate the creation of text : vim online

not logged in (login)

Home
Search

Tip #154: Mappings to facilitate the creation of text


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 6/3, Viewed by 920

created: November 5, 2001 12:38


author: Suresh Govindachar

complexity: basic
as of Vim: 6.0

"
" Mappings to facilitate the creation of text
"
" Author: Suresh Govindachar sgovindachar@yahoo.com
" Date:
November 5, 2001
"
" While typing text to create a document, I often end up
hitting
" <Esc>, issuing some commands (with or without ":") and
getting back
" to typing by issuing a command such as "i", "O", "s"
etc.
"
" I looked into using "set insertmode" to speed up such
actions, but
" found that too confusing.
"
" I have come up with a set of mappings that have
speeded up my process
" of creating documents. I have saved these mappings in
a file, named
" FullScreenVI.vim, in vim's plugin directory.
"
" Perhaps you will find these mappings helpful too.
"
" Please send me feedback.
"
"To
set
"To
the
set

allow overriding the Alt key


winaltkeys=no
enable viewing messages from commands issued using
mappings presented here
cmdheight=2

"The fundamental mapping that makes full-screen editing


possible
imap <A-o> <C-o>

http://www.vim.org/tips/tip.php?tip_id=154 (1 of 3) [18/02/2004 14:46:38]

Tip #154 - Mappings to facilitate the creation of text : vim online

imap <A-;>

<C-o>:

"Basic motions
imap <A-h> <Left>
imap <A-j> <Down>
imap <A-k> <Up>
imap <A-l> <Right>
imap <A-f> <PageDown>
imap <A-b> <PageUp>
imap <A-^> <Home>
imap <A-$> <End>
"Numbers for repeats
imap <A-1> <C-o>1
imap <A-2> <C-o>2
imap <A-3> <C-o>3
imap <A-4> <C-o>4
imap <A-5> <C-o>5
imap <A-6> <C-o>6
imap <A-7> <C-o>7
imap <A-8> <C-o>8
imap <A-9> <C-o>9
"Basic searches
imap <A-/> <C-o>/
imap <A-*> <C-o>*
imap <A-#> <C-o>#
imap <A-n> <C-o>n
imap <A-N> <C-o>N
"Deleting
imap <A-x>
imap <A-d>
imap <A-D>

<C-o>x
<C-o>d
<C-o>D

"Yanking and putting


imap <A-y> <C-o>y
imap <A-Y> <C-o>Y
imap <A-p> <C-o>p
imap <A-P> <C-o>P
"Common prefixes: marking, matching etc.
imap <A-~> <C-o>~
imap <A-m> <C-o>m
imap <A-`> <C-o>`
imap <A-"> <C-o>"
imap <A-%> <C-o>%
imap <A-h> <C-o>:h
imap <A-s> <C-o>:s
"Interacting with the 'outside'
http://www.vim.org/tips/tip.php?tip_id=154 (2 of 3) [18/02/2004 14:46:38]

Tip #154 - Mappings to facilitate the creation of text : vim online

imap <A-!>
imap <A-w>
imap <A-e>

<C-o>:!
<C-o>:w<CR>
<C-o>:e

"Other commands
imap <A-u> <C-o>u
imap <A-.> <C-o>.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Making Parenthesis And Brackets Handling Easier | Decompile Java .class files automatically >>

Additional Notes
Anonymous, November 7, 2001 4:07
BUG:
In the section "Common prefixes: marking, matching
etc.":
imap <A-h> <C-o>:h
conflicts with the "move to left" command; the
preceding
could be changed to:
imap <A-H> <C-o>:h
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=154 (3 of 3) [18/02/2004 14:46:38]

SourceForge
Logo

Tip #155 - Decompile Java .class files automatically : vim online

not logged in (login)

Home
Search

Tip #155: Decompile Java .class files automatically


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/6, Viewed by 2253

created: November 7, 2001 3:16


author: Lawrence Kesteloot

complexity: intermediate
as of Vim: 6.0

Here's a plugin to automatically decompile Java .class


files as they're read in. Tweak the javap flags for
what you want to see. I didn't post this as a script
because it's too simple and it's really more useful for
demonstrating how to read decompilable files (or other
binary files that can be converted to text).
function s:ReadClass(dir, classname)
execute "cd " . a:dir
execute "0read !javap -c " . a:classname
1
setlocal readonly
setlocal nomodified
endfunction
autocmd BufReadCmd *.class
\ call <SID>ReadClass(expand("<afile>:p:h"),
expand("<afile>:t:r"))

rate this tip

Life Changing

Helpful

Unfulfilling

<<Mappings to facilitate the creation of text | describe <table name> from vim >>

Additional Notes
maxiangjiang@hotmail.com, November 7, 2001 10:14

http://www.vim.org/tips/tip.php?tip_id=155 (1 of 2) [18/02/2004 14:46:40]

rate

Tip #155 - Decompile Java .class files automatically : vim online

It doesn't work when package is used in java code.


Foo.java
package com.foo.test;
class Foo
{
}
The question is how to save package information?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=155 (2 of 2) [18/02/2004 14:46:40]

SourceForge
Logo

Tip #156 - describe <table name> from vim : vim online

not logged in (login)

Home
Search

Tip #156: describe <table name> from vim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 15/8, Viewed by 1126

created: November 7, 2001 10:41


author: Demian L. Neidetcher

complexity: basic
as of Vim: 5.7

i had some trouble with the sqlplus scripts (probably my


fault). but it seemed a little heavy for what i need,
usually all i want is a listing of the columns for a
given table while i'm whipping on some sql inside vim.
so i wrote a bash script (describe)...
~~~~~~~~~~~~~~~begin describe script
#!/usr/bin/bash
f=aTempFile.sql
u=<uName>
p=<pWord>
d=<dBase>
echo "/* describe for $1"
echo "describe $1;" > $f;
echo "quit;" >> $f;
sqlplus -S $u/$p@$d @$f
rm -f $f;
echo " end describe for $1 */"
~~~~~~~~~~~~~~~end describe script
your path needs to include the script (as well as
sqlplus), then from vim you can just type....
:r !describe <tableName>
and you get a listing of the table columns slammed into
wherever your cursor was, complete with java/c comments
rate this tip

Life Changing

Helpful

Unfulfilling

<<Decompile Java .class files automatically | Incredible new functionality >>

http://www.vim.org/tips/tip.php?tip_id=156 (1 of 2) [18/02/2004 14:46:42]

rate

Tip #156 - describe <table name> from vim : vim online

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=156 (2 of 2) [18/02/2004 14:46:42]

SourceForge
Logo

Tip #157 - Incredible new functionality : vim online

not logged in (login)

Home
Search

Tip #157: Incredible new functionality


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating -339/376, Viewed by 3301

created: November 7, 2001 10:51


author: Mike W

complexity: basic
as of Vim: 5.7

if you get away from vim and get any other editor that
was built *after* 1970....
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<describe <table name> from vim | Using Computer Modern TT as gvim font (Win32) >>

Site Help

Additional Notes
demian0311@yahoo.com, November 7, 2001 10:53
my note is the Truth.
kbgaddis@hotmail.com, November 8, 2001 10:16
go away troll...
champion@equuleus.com, November 8, 2001 11:31
Dude, know you are a loser, get a life. Want some
publicity do something more fulfilling
Anonymous, November 8, 2001 15:41
go back to slashdot, please.
Anonymous, November 10, 2001 11:59
maybe its time to introduce some sort of moderation?
this forum has been my favourite since it was started
and it feels bad that its been
defiled like this...
on the other hand, i do get some kind of morbid
satisfaction giving him a -ve rating for once :)
Anonymous, November 10, 2001 12:03

http://www.vim.org/tips/tip.php?tip_id=157 (1 of 3) [18/02/2004 14:46:44]

Tip #157 - Incredible new functionality : vim online

a quick technical question:


each "unfulfilling" vote adds -1 to the karma... so how
can this chap have managed to earn a karma of -60 in 57
votes?
is there any even lower vote you can give?!
scrott@users.sourceforge.net, November 11, 2001 9:04
> how can this chap have managed to earn a karma of -60
in 57 votes?
Bad math on my part. I had a bug in the karma
calculations. I just fixed the problem and
recalculated. Feel free to contact me directly when you
notice something like that. Onward,
sj
java4ever@hotmail.com, February 11, 2002 19:25
Let me guess! You work for Microsoft and you want me to
use the joke called Notepad!
Anonymous, March 15, 2002 13:43
After 1970?
2001.

The version of vim I use was made in late

Also, I would like to know WHAT new functionality you


are talking about? I honestly have never thought "Gee,
I wish vim had -this-". It does far more than any
other editor that I have ever used.
amusikal@yahoo.co.uk, March 17, 2002 17:21
Dunno about you folks, but I _hate_ to use software
that isn't old enough to shave. You never know when
it'll throw a tantrum and mess up something important.
david@tvis.co.uk, August 3, 2002 4:09
How many people try vi(m) fumble with i x <esc> decide
than vi(m) is hopeless, and give up. We all have a duty
care to help vi newbies get over the initial learning
curve!!
zzapper
comicBookGuy, August 26, 2002 15:23
worst...tip...ever!
gab@brainlex.com, September 12, 2002 3:03

http://www.vim.org/tips/tip.php?tip_id=157 (2 of 3) [18/02/2004 14:46:44]

Tip #157 - Incredible new functionality : vim online

I tried this one, it doesn't seem to work for me ;)


Anonymous, September 19, 2002 12:01
Get thee gone before I break out my ggdG style on your
sorry hide...
merzky@zib.de, December 1, 2002 8:29
Thank you sooo much!
more productive!

Since I use notepad I am so much

porcy@porcupine.uklinux.net, January 30, 2003 15:48


bollox
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=157 (3 of 3) [18/02/2004 14:46:44]

SourceForge
Logo

Tip #158 - Using Computer Modern TT as gvim font (Win32) : vim online

not logged in (login)

Home
Search

Tip #158: Using Computer Modern TT as gvim font (Win32)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 22/12, Viewed by 2506

created: November 8, 2001 12:59


author: Vince Negri

complexity: intermediate
as of Vim: 5.7

If you really like the Computer Modern typewriter font


(as seen in most TeX distributions) you can use it as
the font in gvim! (looks excellent with font smoothing
turned on)
First, get hold of the free Blue Sky Type 1 PS versions
of the CM fonts from your local CTAN mirror. Unpack to a
suitable directory.
Next locate the cmtt8.pfb file and open it (in Vim,
naturally ;) - find the line
saying
dup 32 /visiblespace put
and change it to
dup 32 /space

put

that is, inserting enough spaces to keep the file size


exactly the same
(IMPORTANT!)
Save the file in Mac format (:set fileformat=mac).
Now install the cmtt.pfm file - in Win9x/NT4, you'll
need Adobe Type Manager
(free download), but in Win2k, you can just drop the
.pfm file into the Fonts folder.
Now in your _gvimrc:
set guifont=CMTT8:h11:cSYMBOL
(use whatever height you like instead of h11)
..and enjoy! It's the first scalable font I can bear to
edit code in... %-)
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=158 (1 of 3) [18/02/2004 14:46:47]

Helpful

Unfulfilling

rate

Tip #158 - Using Computer Modern TT as gvim font (Win32) : vim online

<<Incredible new functionality | Keystroke Saving Substituting and Searching >>

Additional Notes
Anonymous, November 8, 2001 13:00
grr typo!
"Now install the cmtt.pfm file" should of course be
"Now install the cmtt8.pfm file"
bobnotbob@byu.edu, November 9, 2001 8:43
I couldn't get the font to install on my win2k
box. What exactly should the name of the file
be? Should I change the cmtt8.pfb to cmtt8.pfm? I
tried making the modifications as per the instructions,
and when I tried copying it to my fonts directory,
windows told me that it was an invalid font. I kept
the right number of spaces, and I set fineformat=mac,
but it didn't work. Maybe somebody could post a
version of the font that works OK?
Vince, November 9, 2001 12:42
If you have downloaded the full bluesky package, you
will have *both* .pfb and .pfm files. Do not rename the
.pfb file to .pfm! The .pfm file will appear with a red
'a' as its icon in Win2k.
(Thinking I should have marked this tip as advanced, as
messing with Type 1 fonts even in Win2k is fairly nonintuitive....)
pdwalker@quagmyre.com, November 11, 2001 8:57
One of the nicest mono spaced fonts that I have found
has come from Microsoft.
They have a nice selection of screen legible fonts
located at http://www.microsoft.com/typography.
The monospaced font is called Andale Mono and can be
downloaded as a self installing executable (ugh.) under
Windows.
Take a look if you need a good font.
- Paul
argherna@core.com, November 12, 2001 5:05

http://www.vim.org/tips/tip.php?tip_id=158 (2 of 3) [18/02/2004 14:46:47]

Tip #158 - Using Computer Modern TT as gvim font (Win32) : vim online

Agreed. Andale Mono is what I use. It's a fine


computer type font. In fact, I've set up my CMD prompt
to use it and the IE Browser to use it for the
monospaced fonts. Looks better than Courier new.
steveo@dimensional.com, January 2, 2002 16:27
Nice tip! Computer modern is a beautiful font - my
source code is much more elegant now ;-)
One note - doing 'set ff=mac' and saving my edits to
the .pfb file did not work (for me, using
Win98, Adobe Type Manager, and Vim 6.0). Leaving the
file format alone did work.
pascoedj@spamcop.net, June 4, 2002 19:13
Any chance the resultant file, usable under win32 can
be put up somewhere for ftp/http ?
davidp.
dontmailme@thanks.org, August 20, 2002 7:11
Ohhhhh!!!! Just orgasmic! BTW. If vim shows you the
file as "unix" with a lot of "^M", there's no need to
set filetype.
My, oh my!, September 19, 2002 16:37
I was convinced I'd never find a decent font. I was
using Fixedsys for want of something legible! CTT8 is
so pretty it makes my eyes water. Or maybe my eyes are
watering because I've been oggling it for too long.
*blink* *blink*
Mike
Anonymous, September 11, 2003 21:33
I have started using the Bitstream vera fonts on linux,
and I really like them. The bitstream-vera-sans-mono
is an excellent terminal font. I use it in both
terminals and gvim. I have not tried it on Windows yet,
but since it is a TT font, it shoudl work.
Mike
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=158 (3 of 3) [18/02/2004 14:46:47]

SourceForge
Logo

Tip #159 - Keystroke Saving Substituting and Searching : vim online

not logged in (login)

Home
Search

Tip #159: Keystroke Saving Substituting and Searching


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 29/11, Viewed by 1193

created: November 9, 2001 10:41


author: Joachim Hofmann (Schuttberg)

complexity: basic
as of Vim: 5.7

1) ++++++++++++++ Saving Keystrokes for common Searching and Substituting +++++++++++


--- a) Searching b) Substituting --------------------------------------------------2) ++++ Searching for resp. Substituting of the current word under the cursor ++++++
--- a) Searching b) Substituting --------------------------------------------------3) ++ Searching and Substituting for an arbitrary visually selected part of text ++++
--- a) Searching b) Substituting --------------------------------------------------4) ++++++++++++++++++++++++++++++++ Conclusion +++++++++++++++++++++++++++++++++++++
=====================================================================================
1) ++++++++++++++ Saving Keystrokes for common Substituting and Searching +++++++++++
a) Searching ............
Sorry, there is not much that can be saved for common Searching. It's just hitting
/mypattern<RETURN>
b) Substituting .........
I think, common substitution requires pretty many keystrokes. So I use the
following macro with my favorite substitution options:
:map <F4> :%s//gc<Left><Left><Left>
This ends up with the cursor after the first '/' in the commandline. To complete it,
you only have to enter
-> myoldpattern/mynewpattern<RETURN>
Remark: I mapped it to <F4> (cause of tribute to the <F4> of the good old Norton
Commander editor). You may map it where you want to.
2) ++++

Searching for resp. Substituting of the current word under the cursor ++++++

http://www.vim.org/tips/tip.php?tip_id=159 (1 of 4) [18/02/2004 14:46:49]

Tip #159 - Keystroke Saving Substituting and Searching : vim online

a) Searching ............
If you don't know how to look for the next occurence of the word under the cursor,
you
should *now* type
:help * or
:help star
or refer to the tips vimtip #1 or vimtip #5
((Tip within tip: To make your pattern more visible, look for :help hls))
b) Substituting .........
The following macro extends the one above with automatically inserting the current
word
under the cursor into the from - pattern of the :s command.
:map <S-F4> :%s/<C-r><C-w>//gc<Left><Left><Left>
To complete it, just enter
-> mynewpattern<RETURN>
I use this i.e. for reliable and quickly renaming a variable in the entire buffer.
I mapped it to Shift-<F4>. You may map it to the keystroke you want.
Explanation: CTRL-v+CTRL-w expands to the word under the cursor.
3) ++ Searching and Substituting for an arbitrary visually selected part of text ++++
If you want to look or substitute (for) an *arbritary* pattern (which already exists
at
least once in your text), the following 2 mappings do it for you.
The advantage is that you dont have to type again or cut & paste the appropriate text
but only have to visually select it.
a) Searching ...........
:vmap / y:execute "/".escape(@",'[]/\.*')<CR>
This immediately finds to the next occurence of the previously visually selected
text.
b) Substituting .........

http://www.vim.org/tips/tip.php?tip_id=159 (2 of 4) [18/02/2004 14:46:49]

Tip #159 - Keystroke Saving Substituting and Searching : vim online

:vmap <F4> y:execute "%s/".escape(@",'[]/')."//gc"<Left><Left><Left><Left>


Again, as in the mapping in chapter 2), you just have to complete it by entering
-> mynewpattern<RETURN>
Explanation/Discussion:
What both Substituting and Searching in this way generally does is:
- *y*anking the selected text
- Inserting the visually selected via adressing the '"' register with '@"' as a
parameter of the escape() function going finally into the 'myoldpattern' part.
The trickery problem is, if you have characters in your myoldpattern, which are
regular expression chars, they are recognized and threated accordingly. That
is most likely not what you wanted. To escape them, these chars have to be
declared by the second parameter of the excape() function, which then escapes them
with a backslash. The few characters above work for me. If you run into problems,
you should check for additional regexp chars in your text, and try to escape them
by adding them to the escape() function parameter.
4) ++++++++++++++++++++++++++++++++

Conclusion +++++++++++++++++++++++++++++++++++++

With the appropriate mappings in your vimrc you can save keystrokes when Searching or
Substituting and avoid typing errors. That way, you can take lunch sooner
rate this tip

Life Changing

Helpful

Unfulfilling

<<Using Computer Modern TT as gvim font (Win32) | Dutch spelling checker >>

Additional Notes
maxiangjiang@hotmail.com, November 12, 2001 10:43

http://www.vim.org/tips/tip.php?tip_id=159 (3 of 4) [18/02/2004 14:46:49]

rate

Tip #159 - Keystroke Saving Substituting and Searching : vim online

Thanks
Great to find escape()
I have the following map, as a consequence:
cm <C-A> <C-R>=escape(@",'[]/\.*')<CR>
vm * y/<C-A><CR>| vm / y:%s/<C-A>/
vm # y?<C-A><CR>| vm ? y:g/<C-A>/t$<CR>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=159 (4 of 4) [18/02/2004 14:46:49]

SourceForge
Logo

Tip #161 - Dutch spelling checker : vim online

not logged in (login)

Home
Search

Tip #161: Dutch spelling checker


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/5, Viewed by 524

created: November 11, 2001 0:02


author: Thomer M. Gil

complexity: basic
as of Vim: 6.0

Download at
http://www.thomer.com/thomer/vi/nlspchk.vim.gz.
This sciript is based on Charles E. Campbell's English
spelling checker script for ViM
(http://users.erols.com/astronaut/vim/) and Piet
Tutelaers' Dutch word list (http://www.ntg.nl/spell-nlv5b/) using Thomas Khler's script (http://jeanlucpicard.de/vim/gerspchk/create). In other words, I didn't
do much.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Keystroke Saving Substituting and Searching | write plugin with explorer like interfaces >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=161 [18/02/2004 14:46:51]

SourceForge
Logo

Tip #162 - write plugin with explorer like interfaces : vim online

not logged in (login)

Home
Search

Tip #162: write plugin with explorer like interfaces


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 6/3, Viewed by 1049

created: November 11, 2001 9:02


author: benoit.cerrina@writeme.fr
Several plugins
special buffer,
plugin, several
others...
Here is a quick

complexity: basic
as of Vim: 6.0

use a text base interface based on a


this is the case of the standard explorer
bufexplorer plugins, the option buffer and
guide in how to do this

Writing a special buf script


| using a special buffer is a common technic when writing
Vim scripts, it is used by
| explorer, bufexplorer, DirDiff...
| I'm currently writing one for TagsBase.vim
|
http://vim.sourceforge.net/scripts/script.php?script_id=100
| and I'll use this document to take notes on how to do it.
|
Setting up the buffer
Opening the window TODO
Using a setup function
Principle
| we can use a specific function to open and setup the
special buffer. s:SetupBuf()
Setup Function advantage
| since the command will be defined in the main script you
| can use script local functions
Using a special filetype
Principle
| we can also use a new filetype and distribute a syntax
and an ftplugin for this
| filetype, the only thing needed in this case is to set
the
| filetype after creating the buffer
Filetype advantage
| better separations of different parts of your script. If
| the main function of your plugin is not to have this
| special buffer then it is nice to avoid clutering it.
Things which needs to be done to setup the buffer

http://www.vim.org/tips/tip.php?tip_id=162 (1 of 3) [18/02/2004 14:46:53]

Tip #162 - write plugin with explorer like interfaces : vim online

The buffer should not be listed and does not correspond to


a file
* setlocal buftype=nofile
- options always local to buffer
* set nobuflisted
* set bufhidden=delete
* set nomodifiable
Setup the syntax for this buffer
| see :help syntax
| This is usually done in two steps, first describe the
| syntax groups using :syn commands then setup the
| hilighting using :hi def link commands. Usually it is
| best to link the newly defined groups to predefine ones
in
| order to make the coloring work fine with colorschemes.
| You'll find the list of predefined group by doing:
| :help group-name
Setup the special mappings
| since we have chosen to use the set nomodifiable option
| our buffer will never be in insert mode. All our mapping
| are in Normal, Visual or operator pending, they should
| therefore use the map, nmap, vmap and omap mapping
command
| plus the associated 'nore' version. I usually find it
| better to use the 'nore' version to avoid surprises due
to
| mapping in the user configuration.
|
| We also want our mappings to be local to the special
| buffer so all the commands will use the <buffer>
modifier.
|
| Finally we want our mappings not to polute the status bar
| so we use the <silent> modifier
|
| Putting all this together we end up with mapping commands
| which look like:
| noremap <buffer> <silent> {lhs} {rhs}
Setup the special command
| we will then setup special commands for this
buffer. Like
| for the mapping there are some precautions to take:
| we don't want an error message if the command is defined
| twice so we use the command! variant.
| We want a command local to our buffer wo we use the
| -buffer attribute. The rests of the command attributes
| and options depend on the actual command.
| So our commands look like:
| command! -buffer {attr} {cmd} {rep}
| where attr is optional.

http://www.vim.org/tips/tip.php?tip_id=162 (2 of 3) [18/02/2004 14:46:53]

Tip #162 - write plugin with explorer like interfaces : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Dutch spelling checker | Toggle Search Highlighting >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=162 (3 of 3) [18/02/2004 14:46:53]

SourceForge
Logo

Tip #163 - Toggle Search Highlighting : vim online

not logged in (login)

Home
Search

Tip #163: Toggle Search Highlighting


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 26/22, Viewed by 1259

created: November 11, 2001 13:11


author: Bindu Wavell

complexity: basic
as of Vim: 6.0

" Map H to toggle search highlighting


map H :let &hlsearch = !&hlsearch<CR>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<write plugin with explorer like interfaces | Make non-ASCII characters displayed on console >>

Site Help

Additional Notes
hermitte@free.fr, November 12, 2001 7:07
You can also do something like :
noremap XX :set hlsearch!<cr>:set hlsearch?<cr>
<advertize>
And take a look at
http://vim.sourceforge.net/scripts/script.php?script_id=48
for more complex toggle actions.
</adv>
coryechols@yahoo.com, November 14, 2001 4:52
I think the simplest way to do this is :noremap XX :set
invhlsearch<CR>
For options which have only "on" or "off" settings, giving
the 'inv' prefix to the option causes it to be toggled.
hermitte@free.fr, November 15, 2001 5:07
The "inv" prefix only works with versions 6.x of VIM. It
seems to do strictly the same
thing '!' does. But it does not echoes the value of the
option.
Hence, 'set option?<cr>' is still useful if you want to
know its new current state.

http://www.vim.org/tips/tip.php?tip_id=163 (1 of 2) [18/02/2004 14:46:55]

Tip #163 - Toggle Search Highlighting : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=163 (2 of 2) [18/02/2004 14:46:55]

SourceForge
Logo

Tip #164 - Make non-ASCII characters displayed on console : vim online

not logged in (login)

Home
Search

Tip #164: Make non-ASCII characters displayed on console


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 7/4, Viewed by 975

created: November 14, 2001 21:48


author: Gerhard Hring

complexity: basic
as of Vim: 5.7

I had a problem with VIM on the FreeBSD console: it


didn't display characters like German umlauts correctly,
but escaped them with a tilde. The solution is to teach
VIM about printable characters. I use the following on
my .vimrc:
set isprint=@,128-255

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Toggle Search Highlighting | Deleting a buffer without closing the window >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=164 [18/02/2004 14:46:58]

SourceForge
Logo

Tip #165 - Deleting a buffer without closing the window : vim online

not logged in (login)

Home
Search

Tip #165: Deleting a buffer without closing the window


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/9, Viewed by 1012

created: November 16, 2001 11:50


author: Raymond Li

complexity: intermediate
as of Vim: 6.0

I'm not sure if this functionality is already within


Vim, but I sometimes I find it useful to keep a split
window from closing when deleting a buffer. This has
already been discussed on the vim@vim.org mailing
list. However, I feel this solution is a little easier
to use.
" Put this into .vimrc or make it a plugin.
" Mapping :Bclose to some keystroke would probably be
more useful.
" I like the way buflisted() behaves, but some may like
the behavior
" of other buffer testing functions.
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete ".l:currentBufNum)
endif
endfunction
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=165 (1 of 3) [18/02/2004 14:47:00]

Helpful

Unfulfilling

rate

Tip #165 - Deleting a buffer without closing the window : vim online

<<Make non-ASCII characters displayed on console | Mapping caps lock to esc in XWindows >>

Additional Notes
bindu@wavell.net, December 19, 2001 0:09
The MiniBufExplorer.vim plugin (in the scripts area)
provides this capability with a really simple and small
user interface...
Anonymous, June 24, 2002 22:58
This tip didn't seem to work in gvim 6, I placed it in
my _vimrc file as instructed, but deleting buffers
still closes the windows they are in, as before ;-(.
Anonymous, November 16, 2002 6:16
I didn't try the tip, but this is the solution I came
up with:
You can use the :BufClose command with or without an
argument. The argument can be the filename associated
with a buffer, or a buffer number. You don't have to
be in the window that has the buffer open if you use an
argument.
command! -nargs=? -complete=buffer -bang BufClose
\ :call BufClose(expand('<args>'),
expand('<bang>'))
function! BufClose(buffer, bang)
if a:buffer == ''
let buffer = bufnr('%')
else
let buffer = bufnr(a:buffer)
endif
if buffer == -1
echohl ErrorMsg
echomsg "No matching buffer for" a:buffer
echohl None
return
endif
let current_window = winnr()
let buffer_window = bufwinnr(buffer)
if buffer_window == -1
echohl ErrorMsg
http://www.vim.org/tips/tip.php?tip_id=165 (2 of 3) [18/02/2004 14:47:00]

Tip #165 - Deleting a buffer without closing the window : vim online

echomsg "Buffer" buffer "isn't open in any


windows."
echohl None
return
endif
if a:bang == '' && getbufvar(buffer, '&modified')
echohl ErrorMsg
echomsg 'No write since last change for buffer'
\ buffer '(add ! to override)'
echohl None
return
endif
if buffer_window >= 0
exe 'norm ' . buffer_window . "\<C-w>w"
exe 'enew' . a:bang
exe 'norm ' . current_window . "\<C-w>w"
endif
silent exe 'bdel' . a:bang . ' ' . buffer
endfunction
bush@whitehouse.gov, November 25, 2002 6:08
I dunno how old this tip is, but :bd <bufferName> works
fine for me!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=165 (3 of 3) [18/02/2004 14:47:00]

SourceForge
Logo

Tip #166 - Mapping caps lock to esc in XWindows : vim online

not logged in (login)

Home
Search

Tip #166: Mapping caps lock to esc in XWindows


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 133/40, Viewed by 2028

created: November 19, 2001 11:19


author: Leif Wickland

complexity: basic
as of Vim: 5.7

(This originally appeared on the vim mailing list as post by Adam


Monsen http://groups.yahoo.com/group/vim/message/19856)
If you want to completely swap caps lock and escape, you have to
replace the
"Lock" on caps lock. Drop this file in your home dir:<br>
-----------start------------<br>
! Swap caps lock and escape<br>
remove Lock = Caps_Lock<br>
keysym Escape = Caps_Lock<br>
keysym Caps_Lock = Escape<br>
add Lock = Caps_Lock<br>
------------end-------------<br>
and call it ".speedswapper". Then open a terminal and type<br>
$ xmodmap .speedswapper<br>
and you'll be twice as efficient in vim. Who needs caps lock anyway?
The swapping lasts for the duration of the X session, so you can put
it in a .xinitrc or similar startup file. As far as other people
using my laptop, I'd rather they didn't! Using a Dvorak layout might
protect me even more... :)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Deleting a buffer without closing the window | Using vim as a man-page viewer under Unix >>

Additional Notes
leifw @at@ bigfoot dot.dot com, November 19, 2001 11:21
Oh, and I really didn't mean for those <br>'s to show up in the
file. It should look like
-----------start-----------! Swap caps lock and escape
remove Lock = Caps_Lock
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_Lock
------------end------------jani@turkia.com, July 2, 2002 21:06
Great tip!!! And I might try the other tip on the Dvorak mappings :)

http://www.vim.org/tips/tip.php?tip_id=166 (1 of 3) [18/02/2004 14:47:03]

Tip #166 - Mapping caps lock to esc in XWindows : vim online

ajw@nova.hn.org, October 3, 2002 23:38


If you want to use the capslock as escape on the console as opposed
to just in X, try:
loadkeys ~/keymap
where ~/keymap contains:
---------->8---------keycode 58 = Escape
----------8<---------Or, if you want to completely swap them:
---------->8---------keycode 1 = Caps_Lock
keycode 58 = Escape
----------8<---------see 'man 5 keymaps', and verify with 'dumpkeys' that keycode 1 is
Escape and keycode 58 is Caps_Lock beforehand :)
interfac@hotmail.com, October 12, 2002 11:05
hehe, nice, very nice... but i'm living in a torture right now,
because i DO wanna change <esc> to another key closer, *** but i'm
so used to <esc> that i can't !!!! ***
damn. :P
erik@arbat.com, January 22, 2003 3:23
How to do this in windows:
capstoesc.reg:

Create the following file, calling it

-------start
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard
Layout]
"Scancode
Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00
--------end
Then double-click on it and reboot.
The syntax is explained in
http://www.vim.org/tip_view.php?tip_id=285
gtg947a@<nospam>mail.gatech.edu, September 13, 2003 18:05
I had this script working nicely before, but now it gives me this
error:
xmodmap: .speedswapper:1: bad keysym in remove modifier list
'Caps_Lock', no corresponding keycodes
xmodmap: .speedswapper:3: bad keysym target keysym 'Caps_Lock', no
corresponding keycodes
xmodmap: 2 errors encountered, aborting.
Anybody know what's up?
http://www.vim.org/tips/tip.php?tip_id=166 (2 of 3) [18/02/2004 14:47:03]

Tip #166 - Mapping caps lock to esc in XWindows : vim online

gtg947a@<nospam>mail.gatech.edu, September 13, 2003 18:13


Nevermind, I forgot to delete a line from my XF86Config
file. Disregard.
adityam at inbox dot lv, September 17, 2003 12:29
I connect to a X-server through ssh, and though the script runs
correctly I can not get the desired effect. Can not change the
keysettings in the windows machine that I use since I am not a
administrator :(
Anyway to overcome this?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=166 (3 of 3) [18/02/2004 14:47:03]

SourceForge
Logo

Tip #167 - Using vim as a man-page viewer under Unix : vim online

not logged in (login)

Home
Search

Tip #167: Using vim as a man-page viewer under Unix


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 85/35, Viewed by 4587

created: November 21, 2001 7:29


author: Charles E. Campbell, Jr.

complexity: intermediate
as of Vim: 6.0

To use vim as a man-page viewer involves setting an environment


variable:
sh, ksh:
nolist' -"
csh
:
nolist' -"

export MANPAGER="col -b | view -c 'set ft=man nomod


setenv MANPAGER "col -b | view -c 'set ft=man nomod

Put one of the above two lines into your <.profile> or <.login>
file as
appropriate for your shell.
The man pages will then be displayed with vim called as "view"
and will use
the <man.vim> syntax highlighting. I myself use some additional
highlighting
which is enabled by putting the following file into
<.vim/after/syntax/man.vim>.
I usually use the <astronaut> colorscheme (also available from
this archive);
those who use bright backgrounds may find the colors selected for
manSubSectionStart and manSubSection something they'll want to
change:
-------------------------------------------------------------------" DrChip's additional <man.vim> stuff
syn match manSectionHeading
"^\s\+[0-9]\+\.[0-9.]*\s\+[AZ].*$" contains=manSectionNumber
syn match manSectionNumber
"^\s\+[0-9]\+\.[09]*"
contained
syn region manDQString
start='[^a-zA-Z"]"[^",
)]'lc=1
end='"'
contains=manSQString
syn region manSQString
start="[ \t]'[^',
)]"lc=1
end="'"
syn region manSQString
start="^'[^',
)]"lc=1
end="'"
syn region manBQString
start="[^a-zA-Z`]`[^`,
)]"lc=1
end="[`']"
syn region
manBQSQString
start="``[^),']"
end="''"
syn match manBulletZone
transparent "^\s\+o\s"

http://www.vim.org/tips/tip.php?tip_id=167 (1 of 9) [18/02/2004 14:47:07]

Tip #167 - Using vim as a man-page viewer under Unix : vim online

contains=manBullet
syn case
match
syn keyword manBullet contained
syn match
manBullet contained
syn match
manSubSectionStart
nextgroup=manSubSection
syn match
manSubSection

o
"\[+*]"
"^\*"
skipwhite
".*$"

contained

hi link manSectionNumber
Number
hi link manDQString
String
hi link manSQString
String
hi link manBQString
String
hi link manBQSQString
String
hi link manBullet
Special
hi manSubSectionStart
term=NONE cterm=NONE gui=NONE
ctermfg=black ctermbg=black guifg=navyblue guibg=navyblue
hi manSubSection
term=underline cterm=underline
gui=underline ctermfg=green guifg=green
set ts=8
--------------------------------------------------------------------

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Mapping caps lock to esc in XWindows | Viewing the actual XPM data in GVIM >>

Additional Notes
Douglas Potts <pottsdl@bigfoot.com>, November 26, 2001 6:10
As part of the man filetype plugin delivered in Vim 6.0, the
user command :Man
is setup to view man pages in a similar fashion. (On Unix)
I've sym-linked the
man.vim filetype plugin from the distribution into the plugin
directory. That
was the :Man command is available whenever you need it.
Hope that was useful.
Alper Ersoy <aersoy@tfz.net>, December 1, 2001 0:38
I had to use PAGER variable instead of MANPAGER. Version of
the man tool I use is 2.3.10. People who would like to try
this may like to check tip #121 too.
scottu@apptechsys.com, January 30, 2002 11:24

http://www.vim.org/tips/tip.php?tip_id=167 (2 of 9) [18/02/2004 14:47:07]

Tip #167 - Using vim as a man-page viewer under Unix : vim online

Two things:
1. Some versions of sh don't support setting environment
variables and exporting on the same line. In that case, you'd
have to do:
> MANPAGER="col -b | view -c 'set ft=man nomod nolist' -"
> export MANPAGER
2. Another comment mentioned that their man doesn't support
the MANPAGER env var, so they had to use PAGER. You probably
don't want to do that on a permanent basis, since PAGER is used
for many other things besides man. Instead, you might create a
small script in your $HOME/bin that sets it in a subshell, for
example (vman.sh):
#!/bin/sh
PAGER="col -b | view -c 'set ft=man nomod nolist' - "
export PAGER
man $*
and then do 'vman ls' or whatever. Replace PAGER with MANPAGER
if your man supports it and you want to use the script.
3. You might want to add ignorecase to the list of settings
passed to vim (view) to more closely match the searching of
most man pagers (less and more).
Ok, I lied - 3 things.
supergrass@gmx.net, February 9, 2002 3:36
even simpler way
what I did was:
1) renamed my less to less.orig
2) edited the less.sh script :
if test $# = 0; then
vim -c 'so $VIMRUNTIME/macros/less.vim' elif test $* = "-is"; then
less.orig $*
else
vim -c 'so $VIMRUNTIME/macros/less.vim' $*
fi
3) symlinked $VIMRUNTIME/macros/less.sh to /usb/bin/less
so as you can see when the man is called it just passes the
parameters to less.orig
simple, fast works
have phun :)

http://www.vim.org/tips/tip.php?tip_id=167 (3 of 9) [18/02/2004 14:47:07]

Tip #167 - Using vim as a man-page viewer under Unix : vim online

michael.wardle@adacel.com, May 16, 2002 20:00


On my Red Hat 7.2 system, view invokes vi (vim in vi
compatibility mode), so extra vim features such as syntax
highlighting are not available.
To use vim instead of vi for the pager, either manipulate the
/bin/view link, or set substitute "vim -R" for "view".
happy99999992000@yahoo.com, August 14, 2002 9:00
Replace view with less.sh of vim will maintain the same
keystrokes as less. The following set the MANPAGER for sh, ksh
and bash:
export MANPAGER="col -b | /usr/share/vim/vim61/macros/less.sh c 'set ft=man nomod nolist' -"

ajw@nova.hn.org, October 3, 2002 19:19


The original tip works great for me (export MANPAGER="col -b |
view -c 'set ft=man nomod nolist' -"), however, if I then try
':Man some-man-page' inside vim after executing man from the
shell, I get the following in the window:
Vim: Warning: Input is not from a terminal
^M
Error executing formatting or display command.
System command (cd /usr/man && (echo ".pl 11i"; /bin/gunzip -c
'/usr/man/man3/puts.3.gz') | /usr/bin/gtbl | /usr/bin/nroff -S mandoc | col -b | view -c 'set ft=man nomod nolist' -) exited
with status 256.
No manual entry for fputc
?47h?1hmH2J24;1H"-stdin-" [RO] 64L,
1791C1;24rmH2J24;1H?1l2J?47lVim: Error reading input,
exiting...
Vim: Finished.
24;1HVim: Reading from stdin...
[Somewhat paradoxically, this occurs only if the man page
*does* exist, teehee; if it doesn't, I just get a line telling
me 'Cannot find a 'foo'.' in the command-line area.]
I assume it's because :Man doesn't like vim/view being in the
MANPAGER, so my current messy workaround is 'let
$MANPAGER="/usr/bin/less"' in ~/.vimrc; does anyone have a
better solution? Being able to use K to jump around the
manpages is the major reason why I want to use vim as the
manpager ;)
Anonymous, November 7, 2002 22:41

http://www.vim.org/tips/tip.php?tip_id=167 (4 of 9) [18/02/2004 14:47:07]

Tip #167 - Using vim as a man-page viewer under Unix : vim online

I'm having the same problem as ajw. Seems that it's either
":Man", or vim as pager for man from the command line. Making
sure that MANPAGER is only set for interactive shells, and then
doing "let $MANPAGER='/usr/bin/less'" in .vimrc does help some,
as ajw suggests, but it means that you're stuck with less once
you've jumped out of the first man page via K. Anybody know how
to make vim as MANPAGER and ":Man" from man.vim play nice
together?
cec@NgrOyphSon.gPsfAc.nMasa.gov, November 27, 2002 6:56
There's now a while-you're-in-vim solution -- check out
vimscript#489 for <Manpageview.vim> for a new :Man command
and support for the K normal-mode command.
Anonymous, December 18, 2002 3:04
Great!
cec@NgrOyphSon.gPsfAc.nMasa.gov, December 27, 2002 7:25
Using MANPAGER doesn't work so well with vimscript#489;
instead, I now use a Korn shell function. Similar
functions could be developed for other shells (bash, zsh),
I'm sure:
# man:
function man
{
/usr/bin/man $* | col -b | /usr/local/bin/view -c 'set ft=man
nomod nolist' }
jhf.remmelzwaal at europe.com, January 2, 2003 3:06
Reading man pages on NT, Win2000 etc.
Windows NT, etc has remote shell client support. This can be
used to read the man pages on a unix system. I changed script
vimscript#489 in the following way:
----------------------------------------------*** manpageview.vim~ Thu Jan 2 11:42:14 2003
--- manpageview.vim Thu Jan 2 11:44:48 2003
***************
*** 87,94 ****
enew!
set mod
" call Decho("manpagebook<".manpagebook.">
topic<".manpagetopic.">")
!
exe "r!man ".manpagebook." ".manpagetopic
!
%!col -b
setlocal ft=man nomod nolist
set nolz
endfunction
--- 87,98 ---enew!
set mod

http://www.vim.org/tips/tip.php?tip_id=167 (5 of 9) [18/02/2004 14:47:07]

Tip #167 - Using vim as a man-page viewer under Unix : vim online

" call Decho("manpagebook<".manpagebook.">


topic<".manpagetopic.">")
!
if has('win32')
!
exe "r!rsh g:manpageview_server -l g:manpageview_user man
".manpagebook." ".manpagetopic." | col -b"
!
1
!
else
!
exe "r!man ".manpagebook." ".manpagetopic
!
%!col -b
!
endif
setlocal ft=man nomod nolist
set nolz
endfunction
----------------------------------------------Set your unix system (g:manpageview_server) and user account
(g:manpageview_user) in your _vimrc.
Set your NT system name and user account in your ~/.rhosts on
your unix system.
vim_tips@geekpunk.net, March 15, 2003 0:48
I have done the following to make vim work as my PAGER and it
works really well. Like other people in this thread my man(1)
doesn't use MANPAGER, it uses PAGER. I had trouble with vim's
filetype autodetection picking up that it was indeed a manpage
coming in over the pipe, so I've written a scripts.vim to match
manpages by regex and set the filetype accordingly. Otherwise,
I got no syntax highlighting. The shell I quote is tcshspecific, but easily portable to another shell. Also, I assume
you already have a ~/bin and that it is in your path and that
you already have a ~/.vim. If not, you will need to do these
things.
% ln -s /path/to/VIMRUNTIME/macros/less.sh ~/bin/vless
% cat >> ~/.vim/scripts.vim
if did_filetype()
finish
endif
if getline(1) =~ '^\(.\+\)(\d\{1}).\+\1(\d\{1})$'
set filetype=man
endif
^D
% cat >> .cshrc
# config pager
if (-X vless && -X col) then
setenv PAGER 'col -b | vless'
alias less vless
alias more vless
else if (-X less) then
setenv PAGER less
setenv LESS "-e"
alias more less
else if (-X more) then
setenv PAGER more
else

http://www.vim.org/tips/tip.php?tip_id=167 (6 of 9) [18/02/2004 14:47:07]

Tip #167 - Using vim as a man-page viewer under Unix : vim online

echo "WARNING: No pager found, PAGER not set."


endif
^D
Brandon D. Valentine <vim_tips@geekpunk.net>, March 15, 2003 1:01
Actually, here's a smarter way to do that scripts.vim (the
original was taken from the vim manual |new-filetypesscripts|):
if did_filetype()
" filetype already set..
elseif getline(1) =~ '^\(.\+\)(\d\{1}).\+\1(\d\{1})$'
set filetype=man
endif
The previous example works but wouldn't allow you to add
anything else to your scripts.vim.
agriffis@gentoo.org, April 2, 2003 19:07
Does anybody have trouble searching when using less.vim? I
find that if I do "man perlvar" then search for perl, hit 'n' a
few times, and it will stop finding new matches. However if I
page down a couple times, there are more matches to be
found. I'm using:
export MANPAGER="col -b | vim -u NONE -U NONE -f -c 'so
\$VIMRUNTIME/macros/less.vim | set ft=man nomod nolist
laststatus=0 noruler | syn on' -"
Aron
timball at tux dot org, May 20, 2003 7:51
I've been using brandon's little script for a while but I
modified it with the help of this little sh script:
#!/bin/bash
#
#
-- timball @ tux . org
MAN=/usr/bin/man
{
if [ $1 = "-k" ]; then
$MAN -k $2
exit
else
if [ $TERM = "screen" ]; then
screen $MAN -P "col -b | view -R --noplugin -u
~/lib/vim/vman.vim -" $1
exit
else
$MAN -P "col -b | view -R --noplugin -u ~/lib/vim/vman.vim -"
$1
exit
fi
fi
http://www.vim.org/tips/tip.php?tip_id=167 (7 of 9) [18/02/2004 14:47:07]

Tip #167 - Using vim as a man-page viewer under Unix : vim online

}
kerosin at gmx dot de, June 25, 2003 3:25
To avoid the problems with vim in the PAGER or MANPAGER
variable, use the following bash-function:
vman() { man $* | col -b | vim -c 'set ft=man nomod nolist' -;
}
If you view a manpage within vim now, the K-button will work
right.
Anonymous, July 26, 2003 15:16
In bash, adding:
alias man='vman'
... after the vman function, in your .bashrc file, will let you
use the man command again. Simply renaming the vman function to
'man' gave me a string of errors.
vilover@thomer.com, August 21, 2003 23:15
When using UTF-8 as your locale, bad things happen.
how to make it work:

So this is

function man {
/usr/bin/man $* | col -bp | iconv -c | view -c 'set ft=man
nomod nolist' }
westphal@informatik.uni-oldenburg.de, October 29, 2003 12:23
If MANPAGER does not work and PAGER should not be used for the
aforementioned good reasons then the lucky ones with GNU man
simply write (csh)
alias man
'/usr/bin/man -P "col -bp | iconv -c | view -c '"'"'set ft=man
nomod nolist'"'"' -" \!*'
(this is tick-quotes-tick-quotes-tick in the middle) resp. (sh)
alias man="/usr/bin/man -P \"col -bp | iconv -c | view -c
'set ft=man nomod nolist' -\""
and the ones without write (csh)
alias man 'env PAGER="col -bp | iconv -c | view -c '"'"'set
ft=man nomod nolist'"'"' -" man \!*'
resp. (sh)
alias man="env PAGER=\"col -bp | iconv -c | view -c 'set
ft=man nomod nolist' -\" /usr/bin/man"
and are done.
westphal@informatik.uni-oldenburg.de, October 29, 2003 14:42

http://www.vim.org/tips/tip.php?tip_id=167 (8 of 9) [18/02/2004 14:47:07]

Tip #167 - Using vim as a man-page viewer under Unix : vim online

And with the SunOS 5 man(1) from SunOS 5 it is


alias man 'env PAGER="( col -bp | view -c '"'"'set ft=man
nomod nolist'"'"' - ) < " /usr/bin/man \!*'
(and analogously for sh)
since this man(1) calls PAGER with the name of a temporary
file...
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=167 (9 of 9) [18/02/2004 14:47:07]

SourceForge
Logo

Tip #168 - Viewing the actual XPM data in GVIM : vim online

not logged in (login)

Home
Search

Tip #168: Viewing the actual XPM data in GVIM


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 0/2, Viewed by 767

created: November 21, 2001 10:06


author: Carl Lunde

complexity: basic
as of Vim: 6.0

GVIM has an excellent syntax highlighting for XPM


images, but sometimes it's useful to view the actual
data. This can be achieved by searching for everything,
type in "/." and all characters will be highlighted and
therefore the old colouring is lost. To regain the
normal highlighting you can search for a non-existent
sequence, like "/foo".

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using vim as a man-page viewer under Unix | <Tab> = <C-I> and <Esc> = <C-[> >>

Additional Notes
carll@online.no, November 21, 2001 10:28
This requires search highlighting to be turned on, see
vimtip #14 (or just type :set hlsearch). It should also
work with 5.7
Anonymous, November 29, 2001 5:28
instead of searching for something nonexistant like
/foo, just type :noh (for no highlighting)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=168 [18/02/2004 14:47:09]

SourceForge
Logo

Tip #169 - <Tab> = <C-I> and <Esc> = <C-[> : vim online

not logged in (login)

Home
Search

Tip #169: <Tab> = <C-I> and <Esc> = <C-[>


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/6, Viewed by 1005

created: November 24, 2001 18:42


author: Benji Fisher

complexity: basic
as of Vim: 5.7

An FAQ on the vim users' mailing list is whether


<Tab> and <C-I>
can be mapped to different things. The answer is
no. As I understand
it, this is a low level issue: <Tab> and <C-I> are
different names
for the same ASCII code, and there is no way for vim to
tell them
apart. Similarly, <Esc> and <C-[> are the same thing.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Viewing the actual XPM data in GVIM | Repeating a sequence of commands without defining a
macro >>

Additional Notes
realblades@yahoo.com, August 15, 2002 23:11
If you mean the piece of plastic, it might just send
something other than the two other pieces of plastic.
Depending on the operating environment, it may be
possible to change them though the change is most
likely going to be system-wide.
I'm pretty sure that for example X allows very easy
reconfiguration. I'm also quite sure that this is a
very bad idea to be thinking about at all.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=169 [18/02/2004 14:47:11]

SourceForge
Logo

Tip #170 - Repeating a sequence of commands without defining a macro : vim online

not logged in (login)

Home
Search

Tip #170: Repeating a sequence of commands without defining a


macro
tip karma

Rating 44/26, Viewed by 1808

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

created: November 27, 2001 23:45


author: Stanislav Sitar

Scripts
Tips
My Account

You have just finished a complicated modification of a


file,
involving numerous replace commands :%s/xxx/yyyy/g,
and other ex commands.

Site Help

complexity: intermediate
as of Vim: 6.0

Imagine.

Then you realize, you have done it a little bit wrong,


and you have to begin all the operation again,
just to change one replace string, or do one more
operation
"somewhere 10 commands ago".
Or you realize, you will have to do the same stuff
tomorrow
with another file.
or you realize, you want to perform the same sequence
of commands, you have typed a few days ago
You should have made it a macro (normal command q),
but you haven't.
Nothing is lost yet.
You go to the command line (by typing :)
and press Ctrl+F.
(Ctrl+F in other modes scrolls the screen)
You get a temporary window, listing the history of
command line.
It is possible to yank appropriate lines here,
make a new file called $VIMRUNTIME/macros/something.vim
put those lines here, edit them and save
see
:help cedit

http://www.vim.org/tips/tip.php?tip_id=170 (1 of 3) [18/02/2004 14:47:14]

Tip #170 - Repeating a sequence of commands without defining a macro : vim online

Then you can call the macro using


:source something.vim
You might want to set variable 'history' to a higher
number then default in your vimrc file
like
:set history=300
see
:help history
:help vimrc

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<<Tab> = <C-I> and <Esc> = <C-[> | Do you know the "g/" and "g?" commands? >>

Additional Notes
jmcpherson@bigfoot.com, December 5, 2001 11:38
You can also bring up the command line history while in
Normal mode by typing:
q:
which is just a touch faster than :<Ctrl-F>. (-:
(Actually, I didn't even know about Ctrl-F in : mode
until I read this tip. Neat!)
sathishvj@yahoo.com.__spam_stop, May 2, 2003 14:48
Lemme add a note that I saw elsewhere.
Once you execute a command line or search command you
can retrieve the text thus:
i<C-R>:
command line command
i<C-R>/
command

- for pasting the recent


- for pasting the recent search

* I wish every editor had an in built VIM *


Add Note

http://www.vim.org/tips/tip.php?tip_id=170 (2 of 3) [18/02/2004 14:47:14]

Tip #170 - Repeating a sequence of commands without defining a macro : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=170 (3 of 3) [18/02/2004 14:47:14]

SourceForge
Logo

Tip #171 - Do you know the "g/" and "g?" commands? : vim online

not logged in (login)

Home
Search

Tip #171: Do you know the "g/" and "g?" commands?


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 50/19, Viewed by 4066

created: December 2, 2001 11:11


author: Raymond Li (rayli@rayli.net)

complexity: basic
as of Vim: 5.7

Directly from the Vim Todo list:


7
For Visual mode: Command to do a search for the
string in the marked area.
Only when less than two lines. Use "g/" and "g?".
In other words, a way to search for visually selected
text !! :-)
"==== vsearch.vim ====
" Visual mode search
vmap g/ :call VsearchPatternSave()<cr>/<c-r>/<cr>
vmap g? :call VsearchPatternSave()<cr>?<c-r>/<cr>
function! VsearchPatternSave()
let l:temp = @@
normal gvy
let @/ = substitute(escape(@@, '/'), "\n", "\\\\n",
"g")
let @@ = l:temp
unlet l:temp
endfunction
"==== END ====
Normally, this file should reside in the plugins
directory and be automatically
sourced. If not, you must manually source this file
using ':source vsearch.vim'.
In Visual mode, highlight the text for searching.
you can use the
default visual key mappings
g/ - search forwards

http://www.vim.org/tips/tip.php?tip_id=171 (1 of 2) [18/02/2004 14:47:16]

Then

Tip #171 - Do you know the "g/" and "g?" commands? : vim online

g? - search backwards
Visual searches behave like normal searches. The 'n'
and 'N' commands
work as they should, and the search history correctly
records each search.
Multi-line searches behave as they should (this corrects
the 'yank-only'
method mentioned in the Vim help files). Block visual
searches do not work
yet. Hopefully, someone can figure out a way to do this
easily.
I've only tested this on Win2000 and Redhat Linux
7.1. I'm not really clear
on how the carriage returns are dealt with on other
systems.
Anyway, enjoy!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Repeating a sequence of commands without defining a macro | Using Ispell on a highlighted region
>>

Additional Notes
cec@NdjOinnSi.gPsfAc.nMasa.gov, August 26, 2003 7:59
Here's YAW (Yet Another Way): put the following lines
into your <.vimrc>:
vnoremap <silent> g/
'\\/.*$^~[]')<CR><CR>
vnoremap <silent> g?
'\\/.*$^~[]')<CR><CR>

y/<C-R>=escape(@",
y?<C-R>=escape(@",

Use n and N to repeat searches and


previous visual highlighting.

gv to restore the

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=171 (2 of 2) [18/02/2004 14:47:16]

SourceForge
Logo

Tip #172 - Using Ispell on a highlighted region : vim online

not logged in (login)

Home
Search

Tip #172: Using Ispell on a highlighted region


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 7/5, Viewed by 1261

created: December 3, 2001 8:25


author: Carl Mueller

complexity: basic
as of Vim: 6.0

Suppose you would like to use Ispell to check a word or


region that you've
visually highlighted. The following macro will do the
job. Just type
Shift-Insert while in visual mode.
vnoremap <S-Insert> <C-C>`<v`>s<Space><Esc>mq:e
ispell.tmp<CR>i<C-R>"<Esc>:w<CR>:! xterm -bg ivory -fn
10x20 -e ispell %<CR><CR>:e
%<CR><CR>ggVG<Esc>`<v`>s<Esc>:bwipeout!<CR>:!rm
ispell.tmp*<CR>`q"_s<C-R>"<Esc>
This is based on Chip Campbell's macro which uses Ispell
on the whole file
(in normal mode).
noremap <S-Insert> :w<CR>:! xterm -bg ivory -fn 10x20 -e
ispell %<CR><Space>:e %<CR><Space>
Carl Mueller
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Do you know the "g/" and "g?" commands? | Switch between splits very fast (for multi-file editing)
>>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=172 [18/02/2004 14:47:18]

SourceForge
Logo

Tip #173 - Switch between splits very fast (for multi-file editing) : vim online

not logged in (login)

Home
Search

Tip #173: Switch between splits very fast (for multi-file editing)
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 485/202, Viewed by 7810

created: December 4, 2001 11:48


author: Jonathan McPherson

complexity: intermediate
as of Vim: 5.7

I am a Web developer and I use Vim as my primary editor.


Most programming projects (and Web programming projects,
in particular) are spread out over multiple files, which
you often want to have open concurrently. If you don't
already know, Vim supports this very well! Just use:
:sp name-of-another-file-to-edit
My problems were that (1) it took too long to move
between files, and (2) the files were taking up too much
room on the screen.
(1) In order to move to the file in the split above my
current window, I was typing Ctrl-W, Up (move up a
window) Ctrl-W, _ (maximize the menu). That's four
keystrokes (more if you count Ctrl and Shift), and they
are all over the keyboard. To help avoid this problem, I
created this mapping in my .vimrc:
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
Now I can hold down Ctrl and move between windows with
the standard Vim movement keys. Much, much quicker!
(2) By default, Vim displays the current line of each
minimized file, which (to me) isn't much help and takes
up too much screen real estate. I use this line in my
.vimrc:
set wmh=0
This sets the minimum window height to 0, so you can
stack many more files before things get crowded. Vim
will only display the filename.
Hope this helps those of you who are working on projects
with large numbers of files you're constantly flipping

http://www.vim.org/tips/tip.php?tip_id=173 (1 of 4) [18/02/2004 14:47:20]

Tip #173 - Switch between splits very fast (for multi-file editing) : vim online

through. Happy Vimming!


rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using Ispell on a highlighted region | Footnotes >>

Additional Notes
cec@NgrOyphSon.gPsfAc.nMasa.gov - NOSPAM, December 14, 2001 13:25
One may also do the dual thing for vertical
splits/window changes:
set wmw=0
nmap <c-h> <c-w>h<c-w><bar>
nmap <c-l> <c-w>l<c->w<bar>
fallman@jpl.se, February 11, 2002 7:35
It should be
nmap <c-l> <c-w>l<c-w><bar>
of course...
slyphon@example.net, May 14, 2002 17:51
wonderful wonderful wonderful wonderful....
thanks so much, great tip!
Anonymous, August 26, 2002 14:36
This is so useful, perhaps it can be made part of
"standard" VIM! (Although I would probably leave out
the "maximize" portion: <c-w>_)
rosta@coware.be, September 2, 2002 0:38
I have solved the same problem by setting:
set winminheight=0
set winheight=999
winheight is always bigger than my window so
the current window is maximized.
I do not have to set mapping and I can use other
commands to change buffer, fi C-W C-W, mouse click
on status line of the buffer etc.
jerome.bosch@netcourrier.com, September 10, 2002 6:46
very useful tip, thanks

http://www.vim.org/tips/tip.php?tip_id=173 (2 of 4) [18/02/2004 14:47:20]

Tip #173 - Switch between splits very fast (for multi-file editing) : vim online

Mohit Kalra, October 6, 2002 7:19


Damn neat trick. Thanks for the one on vertical splits
too. (I prefer the vertical split tip without the
<bar>.)
npavgi@vxindia.veritas.com, January 22, 2003 1:16
I use gvim *.cpp at the dos prompt to open-up all
source files in a project and I have to use ":n" and
":prev" to roll over them. How can I map ":n" and
":prev" on the CTRL-foo or the ALT-foo ?
pganesa@ncsu.edu, February 21, 2003 9:09
This should do the trick
map <C-N> <ESC>:n <CR>
map <C-P> <ESC>:prev <CR>
yijun@cs.toronto.edu, May 23, 2003 12:07
I would like to use
map <C-N> <ESC>:bn <CR>
map <C-P> <ESC>:bp <CR>
instead to switch between previous and next buffers.
fishburn@ianywhere.com, November 11, 2003 13:59
I created the SwitchWindow function which uses the ALT
left/right/up/down cursor keys to easily move between
windows.
" Switch window mappings /*{{{*/
nnoremap <A-Up>
:normal <cr>=SwitchWindow('+')<cr><cr>
nnoremap <A-Down>
:normal <c-r>=SwitchWindow('')<cr><cr>
nnoremap <A-Left>
:normal <cr>=SwitchWindow('<')<cr><cr>
nnoremap <A-Right> :normal <cr>=SwitchWindow('>')<cr><cr>
function! SwitchWindow(dir)
let this = winnr()
if '+' == a:dir
execute "normal
elseif '-' == a:dir
execute "normal
elseif '>' == a:dir
execute "normal
elseif '<' == a:dir
execute "normal
http://www.vim.org/tips/tip.php?tip_id=173 (3 of 4) [18/02/2004 14:47:20]

\<c-w>k"
\<c-w>j"
\<c-w>l"
\<c-w>h"

Tip #173 - Switch between splits very fast (for multi-file editing) : vim online

else
echo "oops. check your ~/.vimrc"
return ""
endif
endfunction
" /*}}}*/
This was an easy extension to the function I use for
resizing windows:
See the note I added to:
Tip #427: Fast window resizing with +/- keys
http://www.vim.org/tips/tip.php?tip_id=427
michael.denio@morganstanley.com, November 12, 2003 5:31
Why have a whole function when you can simply:
nmap
nmap
nmap
nmap

<silent>
<silent>
<silent>
<silent>

<A-Up> :wincmd k<CR>


<A-Down> :wincmd j<CR>
<A-Left> :wincmd h<CR>
<A-Right> :wincmd l<CR>

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=173 (4 of 4) [18/02/2004 14:47:20]

SourceForge
Logo

Tip #174 - Footnotes : vim online

not logged in (login)

Home
Search

Tip #174: Footnotes


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -1/8, Viewed by 1086

created: December 6, 2001 5:25


author: Klaus Fischer

complexity: basic
as of Vim: 6.0

ab (1 [1]<esc>:/^--\s/-1/<cr>o<insert><cr>Footnotes:<cr>---------<cr>[1]
ab (2 [2]<esc>:/^Footnotes\:/+2/<cr>o<insert>[2]
ab (3 [3]<esc>:/^Footnotes\:/+3/<cr>o<insert>[3]
ab (4 [4]<esc>:/^Footnotes\:/+4/<cr>o<insert>[4]
ab (5 [5]<esc>:/^Footnotes\:/+5/<cr>o<insert>[5]
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Switch between splits very fast (for multi-file editing) | how to make VIM as ur default editor even
without root ac. >>

Additional Notes
rjbs, April 5, 2002 4:50
Although I can tell what these does, I imagine that
much of the intended audience ('basic' tips users)
can't just tell by looking. Perhaps some annotation is
in order.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=174 [18/02/2004 14:47:26]

SourceForge
Logo

Tip #175 - how to make VIM as ur default editor even without root ac. : vim online

not logged in (login)

Home
Search

Tip #175: how to make VIM as ur default editor even without root ac.
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -1/19, Viewed by 1221

created: December 6, 2001 10:53


author: bhaskar

complexity: basic
as of Vim: 5.7

hi,
if u have installed vim in your home directory somewhere
and u don't have a root account, and you want to
make VIM the default editor for anything u do.
i.e if ur using SQLplus and want to edit a sql command.
normally typing edit brings up the vi editor and not vim
editor.
to solve this problem.
define these three variables in your .profile
VIM=<base directory where vim executable is placed>
VIMRUNTIME=<base direcoty where vim runtimes are kept>
EDITOR=$VIM/vim
note if u have installed vim with another name, say
vim.exe then
change EDITOR=$VIM/vim to EDITOR=$VIM/vim.exe
source the .profile and viola. next time u start an
editor from any
program u have the vim editor.
Njoy.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Footnotes | Autocheckout from perforce >>

Additional Notes
none@none.com, December 9, 2001 6:41
This tip might be more useful if translated into
English.
Anonymous, December 10, 2001 14:17

http://www.vim.org/tips/tip.php?tip_id=175 (1 of 2) [18/02/2004 14:47:29]

Tip #175 - how to make VIM as ur default editor even without root ac. : vim online

Notable programs which use the $EDITOR variable include


CVS and Mutt. Anyone care to add to the list?
realblades@yahoo.com, August 15, 2002 23:35
$EDITOR is The place to have your editor defined.
There's also $VISUAL to define a non-line oriented
editor (which is actually vi's place).
All programs on unixlikes spawning editors should
support these. Some have reasons not to and some are
just stupidly made and others stupidly configured.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=175 (2 of 2) [18/02/2004 14:47:29]

SourceForge
Logo

Tip #176 - Autocheckout from perforce : vim online

not logged in (login)

Home
Search

Tip #176: Autocheckout from perforce


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/5, Viewed by 918

created: December 8, 2001 12:05


author: Steven Grady

complexity: intermediate
as of Vim: 6.0

The following code automatically checks out files from


perforce when the user modifies them. It first confirms
the check-out with the user.
(Perforce is a commercial version control system. I
imagine this could be modified for RCS, CVS, etc., but I
don't use those.)
I'm a vim newbie -- I've used vi since 1984, but just
started with vim a couple days ago. Color me
impressed! Please excuse any stupidity in the code..
Note that this
variable to be
client", but I
start vim. So
environment.

function needs the "P4HOME" environment


set. I could extract it by invoking "p4
don't want to invoke p4 every time I
I assume the user sets it in the

" Set a buffer-local variable to the perforce path, if


this file is under the perforce root.
function IsUnderPerforce()
if exists("$P4HOME")
if expand("%:p") =~ ("^" . $P4HOME)
let b:p4path = substitute(expand("%:p"),
$P4HOME, "//depot", "")
endif
endif
endfunction
" Confirm with the user, then checkout a file from
perforce.
function P4Checkout()
if exists("b:p4path")
if (confirm("Checkout from Perforce?",
"&Yes\n&No", 1) == 1)
call system("p4 edit " . b:p4path . " >
/dev/null")
if v:shell_error == 0
set noreadonly
http://www.vim.org/tips/tip.php?tip_id=176 (1 of 2) [18/02/2004 14:47:31]

Tip #176 - Autocheckout from perforce : vim online

endif
endif
endif
endfunction
if !exists("au_p4_cmd")
let au_p4_cmd=1
au BufEnter * call IsUnderPerforce()
au FileChangedRO * call P4Checkout()
endif
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<how to make VIM as ur default editor even without root ac. | Highlight matching brackets as one
moves in normal mode (plugin) >>

Additional Notes
joseph@plaxo.com, August 18, 2003 15:37
Great tip!! However, I think it only works if you've
checked out the entire depot. I only have one branch
checked out (//depot/main/...) and it doesn't work
because the substitution just puts in //depot and not
//depot/main. I just fixed that in my version of the
code and it works now, but I think in addition to
$P4HOME one needs a $P4ROOT or some such for the root
of what you checked out. Of course you could get both
of these from p4client, but it sounds like in the
original tip this was undesirable...just something to
be aware of for other users of this excellent tip.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=176 (2 of 2) [18/02/2004 14:47:31]

SourceForge
Logo

Tip #177 - Highlight matching brackets as one moves in normal mode (plugin) : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #177: Highlight matching brackets as one moves in normal mode


(plugin)
tip karma

Rating 47/22, Viewed by 3860

created: December 12, 2001 8:19


author: Charles E. Campbell, Jr.

complexity: intermediate
as of Vim: 6.0

Check out
http://www.erols.com/astronaut/vim/index.html#VimFuncs
for
a plugin script which highlights matching brackets. The
script has
two always-on maps:
\[i
: start [HiMtchBrkt] mode
\[s
: stop [HiMtchBrkt] mode
The plugin will save all user maps and options that the
plugin uses and
will restore them when the mode is stopped.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Autocheckout from perforce | Making a "derived" colorscheme without copy & paste >>

Additional Notes
cec@NgrOyphSon.gPsfAc.nMasa.gov - NOSPAM, December 12, 2001 8:21
The script is under the title "Highlighting Matching
Brackets"
parlorinventor@hotmail.com, December 27, 2001 2:46
Nice script, but the 'Special' highlighting of most
color-schemes isn't very bright, so I changed the
'Special' in line 158 of the script to 'Search',
because the 'Search' highlighting is much brighter in
most colorschemes, like the one I use (asu1dark). Now
the other bracket really 'flashes' on, and I don't have
to hurt my eyes searching for a somewhat different
coloured bracket.....

http://www.vim.org/tips/tip.php?tip_id=177 (1 of 4) [18/02/2004 14:47:33]

Tip #177 - Highlight matching brackets as one moves in normal mode (plugin) : vim online

cec@NgrOyphSon.gPsfAc.nMasa.gov, February 8, 2002 7:38


The highlighting group change sounds ok to me! The
latest version
now incorporates "Search" instead of "Special" for
highlighting of
the corresponding curly brace.
cec@NgrOyphSon.gPsfAc.nMasa.gov, February 28, 2002 7:10
<himtchbrkt.vim> now supports highlighting the matching
bracket with
cursor keys (<up> <down> <right> <left>) in insert
mode.
cec@NgrOyphSon.gPsfAc.nMasa.gov, March 14, 2002 12:15
HiMtchBrkt now supports the highlighting of matching
brackets with
<home> <end> b w ; ,
and upon termination, unmaps <left> <right> <up> <down>
<home> and <end>.
A variable "g:DrChipTopLvlMenu" has the default value
"DrChip" which
controls where the menu items go.
alan.schmitt@inria.fr, March 14, 2002 14:08
How about saying in the docs that the keybinding to
start highlighting is <leader>[i
instead of \[i.
I_hat3_s_pamers@hotmail.com, June 29, 2002 14:07
Some note to vim newbies (i am one of them) :
1) I downloaded and compiled vim 6.1 in my home
directory and soon realized that if i put
HiMtchBrkt.vim in my runtime/plugins dir it is not
loaded at all
instead you should create in your homedir (~/)
subdirectory "~/.vim/plugins" and put it there.
2) also I ralized that I can't start it running neither
by ":\[i" or :<leader>[i
All the time vim reports error: "E10: \ should be
followed by /, ? or &"
instead I made very rude and at least working for me
"hack" :
opened ~/.vim/plugins/HiMtchBrkt.vim and added two
stupid functions just before line "fu! <SID>HMBStart()"
==========two stupid functions==========
fu! BStart()
http://www.vim.org/tips/tip.php?tip_id=177 (2 of 4) [18/02/2004 14:47:33]

Tip #177 - Highlight matching brackets as one moves in normal mode (plugin) : vim online

call <SID>HMBStart()
endfunction
fu! BStop()
call <SID>HMBStop()
endfunction
===========original continues...============
" HMBStart:
fu! <SID>HMBStart()
if exists("b:dohimtchbrkt") && b:dohimtchbrkt == 1
" already in HiMtchBrkt mode
echo "[HiMtchBrkt]"
return
endif
.........
....etc.....
....etc.....
=====================================
Now (as I am real newbie) I can easy and "reliable"
start and stop breackets highlighting by executing
commands:
:call BStart()
and
:call BStop()
-----------------------This comment was intended only for real vim newbies who
just want it to put in work (no more).
I need no credits because hack is very rude and stupid.
Thanks for attention.
--vim newbie.
I_hat3_s_pamers@hotmail.com, June 29, 2002 14:18
Sorry for misleading a bit: at homedir must be created
"~/.vim/plugin"
NOT "~/.vim/plugins"
Anonymous, July 13, 2002 21:20
I-hat...: did you ever realize that \[i should be typed
from normal mode?
The colon puts you into command mode, and admittedly
\[i is not defined
there.
maxiangjiang@hotmail.com, February 10, 2003 23:09

http://www.vim.org/tips/tip.php?tip_id=177 (3 of 4) [18/02/2004 14:47:33]

Tip #177 - Highlight matching brackets as one moves in normal mode (plugin) : vim online

This is the simplest form of this map:


nn <silent> K mk:exe 'match Search
/\\%'.line(".").'l/'<CR>
Anonymous, March 18, 2003 12:03
Hmm, the map maxiangjiang provided highlights the
entire line whenever a K is pressed. Doesn't seem to
help with highlighting matching braces any.
maoz@windax.com, August 5, 2003 1:00
Hi,
I have downloaded the plugin and i would like to
enable it by default.
The start mapping is '<Leader>[i', what do i have to
do so when I vim a file it will automatically enable
it.
Regards,
Maoz.
cec@NgrOyphSon.gPsfAc.nMasa.gov, August 5, 2003 13:07
To enable it by default, see vimtip#411 !
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=177 (4 of 4) [18/02/2004 14:47:33]

SourceForge
Logo

Tip #178 - Making a "derived" colorscheme without copy & paste : vim online

not logged in (login)

Home
Search

Tip #178: Making a "derived" colorscheme without copy & paste


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/7, Viewed by 955

created: December 13, 2001 5:29


author: Cory T. Echols

complexity: intermediate
as of Vim: 6.0

Suppose there's a colorscheme that you're pretty fond


of, but hate one or two particular aspects about. For
example, I love the "blue" colorscheme that ships with
vim, but I find it's colors for the non-active status
line to be unreadable. Here's how to create a
colorscheme which extends "blue" without copying it to a
new file and editing it.
In my ~/.vim/colors, I created a "my-blue.vim" file with
these contents:
"these lines are suggested to be at the top of every
colorscheme
hi clear
if exists("syntax_on")
syntax reset
endif
"Load the 'base' colorscheme - the one you want to alter
runtime colors/blue.vim
"Override the name of the base colorscheme with the name
of this custom one
let g:colors_name = "my-blue"
"Clear the colors for any items that you don't like
hi clear StatusLine
hi clear StatusLineNC
"Set up your new & improved colors
hi StatusLine guifg=black guibg=white
hi StatusLineNC guifg=LightCyan guibg=blue gui=bold
That's all there is to it.
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=178 (1 of 2) [18/02/2004 14:47:35]

Helpful

Unfulfilling

rate

Tip #178 - Making a "derived" colorscheme without copy & paste : vim online

<<Highlight matching brackets as one moves in normal mode (plugin) | Simplify help buffer navigation
>>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=178 (2 of 2) [18/02/2004 14:47:35]

SourceForge
Logo

Tip #179 - Simplify help buffer navigation : vim online

not logged in (login)

Home
Search

Tip #179: Simplify help buffer navigation


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/6, Viewed by 757

created: December 14, 2001 3:24


author: Max Ischenko

complexity: intermediate
as of Vim: 6.0

Vim is distributed with comprehensive help system, which


has basic hyperlink support you can press <C-]> over |some subject| or 'some option'
to read more about particular term.
The following mappings simplify help buffer navigation:
pressing s(or S) will find next(previous) subject from
cursor position
pressing o(or O) will find next(previous) option from
cursor position
pressing Enter will jump to subject under cursor
pressing Backspace will return from the last jump
Put them into help filetype plugin (like
~/.vim/ftplugin/help.vim on UNIX).
nmap
nmap
nmap
nmap
nmap
nmap

<buffer>
<buffer>
<buffer>
<buffer>
<buffer>
<buffer>

rate this tip

<CR> <C-]>
<BS> <C-T>
o /'[a-z]\{2,\}'<CR>
O ?'[a-z]\{2,\}'<CR>
s /\|\S\+\|<CR>
S ?\|\S\+\|<CR>

Life Changing

Helpful

Unfulfilling

rate

<<Making a "derived" colorscheme without copy & paste | Reload your filetype/syntax plugin >>

Additional Notes
Add Note

http://www.vim.org/tips/tip.php?tip_id=179 (1 of 2) [18/02/2004 14:47:37]

Tip #179 - Simplify help buffer navigation : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=179 (2 of 2) [18/02/2004 14:47:37]

SourceForge
Logo

Tip #180 - Reload your filetype/syntax plugin : vim online

not logged in (login)

Home
Search

Tip #180: Reload your filetype/syntax plugin


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -2/2, Viewed by 1000

created: December 14, 2001 3:33


author: Max Ischenko

complexity: advanced
as of Vim: 6.0

Ever tried to write/debug your own


plugin?

filetype/syntax

It's an iterative process which involves editing plugin


code and testing it on some
sample file. To see changes you made in your plugin
simply do :e on sample file.
This will force Vim to reload all buffer-specific files,
including your plugin.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Simplify help buffer navigation | get the vim patched source >>

Additional Notes
Cory T. Echols, December 14, 2001 4:40
This tip really oversimplifies the issue.
Your plugin may be designed to only run once per
buffer, no matter how many times that buffer has ":e"
run on it. Also, if you remove a mapping or option
setting from your plugin, and then just call ":e" on
your sample buffer, the mapping will still be there, as
no commands were run to clear it out.
The absolutely most effective way I can think of to
test your plugin is to edit it in one instance of vim,
and another instance of vim for testing the plugin. As
you save changes to your plugin, you'll need to exit
and restart the "test" instance of vim. Luckily, vim
has a very fast startup time :)
There may be other less brute-force methods of doing
http://www.vim.org/tips/tip.php?tip_id=180 (1 of 3) [18/02/2004 14:47:40]

Tip #180 - Reload your filetype/syntax plugin : vim online

this.

If anyone has any suggestions, please add them.

pottsdl@bigfoot.com, December 14, 2001 4:55


Another issue to keep in mind, especially if ever plan
on sharing your
plugin with others is the convention of having a:
if exists("loaded_typecorr")
finish
endif
let loaded_typecorr = 1
as is suggested by ':h write-plugin' an searching for
'NOT LOADING'.
And I quote:
"This also avoids that when the script is loaded twice
it would cause error
messages for redefining functions and cause trouble for
autocommands that are
added twice."
scottu@apptechsys.com, January 23, 2002 20:21
What I do to reduce the number of times I have to
restart vim when debugging is use the recommended
multiple loading check with the additional check of a
global debug variable specific to your plugin. For
example:
if exists ("plugin_name_loaded") && !exists
("g:plugin_name_debug_mode")
finish
endif
let plugin_name_loaded = 1
---This works as long as you are only adding new
functions/mapping or changing existing
functions/mappings (defined with the ! method). But
that's the case most of the time, so while debugging,
you can just :so plugin_file without quitting the vim
you are testing with. If you delete functions/maps,
you'll have to restart as the previous note mentioned.
Add Note

http://www.vim.org/tips/tip.php?tip_id=180 (2 of 3) [18/02/2004 14:47:40]

Tip #180 - Reload your filetype/syntax plugin : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=180 (3 of 3) [18/02/2004 14:47:40]

SourceForge
Logo

Tip #181 - get the vim patched source : vim online

not logged in (login)

Home
Search

Tip #181: get the vim patched source


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 13/9, Viewed by 1117

created: December 14, 2001 13:07


author: benoit.cerrina@writeme.fr

complexity: basic
as of Vim: 6.0

Hi,
there has been a number of person (including) asking in
the vim list how to keep up with Bram's incredible bug
correction
and patch writing skills, but there is a great way to do
this!
Use the cvs source which is available at
http://sourceforge.net/cvs/?group_id=8
it is kept up to date and its a lot easier than applying
all the patch in order.
Benoit
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Reload your filetype/syntax plugin | Keep your cursor centered vertically on the screen >>

Additional Notes
quesadaj@psych.colorado.edu, August 31, 2003 21:20
but cvs.sourceforge is down most of the time (for me at
least). I haven't been able to download the whole
source tree in the whole weekend...
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=181 [18/02/2004 14:47:42]

SourceForge
Logo

Tip #182 - Keep your cursor centered vertically on the screen : vim online

not logged in (login)

Home
Search

Tip #182: Keep your cursor centered vertically on the screen


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 19/16, Viewed by 985

created: December 17, 2001 14:16


author: Demian L. Neidetcher

complexity: basic
as of Vim: 5.7

i hope i don't hear a collective 'DUH!' from around the


world but i just did this and i think it's kinda cool.
in your .vimrc add...
map j jzz
map k kzz
so whenever you go up or down, vim does that and then recenters.
obviously it doesn't work when you page up/ down.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<get the vim patched source | Select a buffer from those matching a pattern >>

Additional Notes
jmcpherson@bigfoot.com, December 17, 2001 18:00
This might work, but it isn't necessary to remap your
keys to get this effect. Vim has a built-in option for
this called 'scrolloff' (or 'so' for short). This sets
how many lines of context are maintained above and
below the cursor. If you set this to a very big number,
your cursor will stay in the center of the screen when
it can.
set so=9999
Try it and see what happens. (-: It's also compatible
with PgUp/Down, arrow keys, ^B/^F, and other scrolling
commands.
feline, January 2, 2002 8:40

http://www.vim.org/tips/tip.php?tip_id=182 (1 of 2) [18/02/2004 14:47:44]

Tip #182 - Keep your cursor centered vertically on the screen : vim online

doh!
i didnt know about the scrolloff setting. i love it
so many settings, not enough hours in the day to find
out what they all do
pedro, April 29, 2002 23:21
The "set so=9999" setting works better, but it renders
"H", "M", "L" useless which is a pain
none., July 26, 2002 10:24
absolutely not, not in vim 6.1 atleast... haven't tried
others, don't bother neither :)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=182 (2 of 2) [18/02/2004 14:47:44]

SourceForge
Logo

Tip #183 - Select a buffer from those matching a pattern : vim online

not logged in (login)

Home
Search

Tip #183: Select a buffer from those matching a pattern


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/1, Viewed by 785

created: December 18, 2001 7:42


author: Cory T. Echols

complexity: intermediate
as of Vim: 6.0

The :bu command will take a pattern as an argument and


jump to the matching buffer. However, it's not very
helpful if there is more than one buffer matching the
pattern. In that case, it will jump to the first match,
which may not be what you want. The following function
and user-command will print a list of the matching
buffers in the command-line area, and allow you to
select one of the matching buffers by number.
"Select from buffers matching a certain pattern
"the 'pattern' argument shouldn't be prepended with a
slash
function! BufSel(pattern)
let bufcount = bufnr("$")
let currbufnr = 1
while currbufnr <= bufcount
if(bufexists(currbufnr))
let currbufname = bufname(currbufnr)
if(match(currbufname, a:pattern) > -1)
echo currbufnr . ":
".
bufname(currbufnr)
endif
endif
let currbufnr = currbufnr + 1
endwhile
let desiredbufnr = input("Enter buffer number: ")
if(strlen(desiredbufnr) != 0)
exe ":bu ". desiredbufnr
endif
endfunction
"Bind the BufSel() function to a user-command
command! -nargs=1 Bs :call BufSel("<args>")

http://www.vim.org/tips/tip.php?tip_id=183 (1 of 3) [18/02/2004 14:47:48]

Tip #183 - Select a buffer from those matching a pattern : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Keep your cursor centered vertically on the screen | How to obscure text instantaneously >>

Additional Notes
Cory T. Echols, December 18, 2001 8:02
I guess I should test my stuff more rigorously before
posting.
The above function doesn't take into account the
situation where no buffers match the supplied
pattern. The function below corrects the problem.
"Select from buffers matching a certain pattern
function! s:BufSel(pattern)
let bufcount = bufnr("$")
let currbufnr = 1
"flag to determine if matches are found
let foundmatch = 0
while currbufnr <= bufcount
if(bufexists(currbufnr))
let currbufname = bufname(currbufnr)
if(match(currbufname, a:pattern) > -1)
echo currbufnr . ":
".
bufname(currbufnr)
let foundmatch = 1
endif
endif
let currbufnr = currbufnr + 1
endwhile
if(foundmatch > 0)
let desiredbufnr = input("Enter buffer number: ")
if(strlen(desiredbufnr) != 0)
exe ":bu ". desiredbufnr
endif
else
echo "No matching buffers"
endif
endfunction
salmanhalim@hotmail.com, December 18, 2001 12:19

http://www.vim.org/tips/tip.php?tip_id=183 (2 of 3) [18/02/2004 14:47:48]

Tip #183 - Select a buffer from those matching a pattern : vim online

if precisely one match is found you needn't prompt the


user -- just go to the one buffer that matched. to
accomplish this, use 'numMatches' instead of foundmatch
and increment it instead of using it as a boolean.
also, if you do implement the above then, in the simple
case, the behaviour is identical to that of :bu -- so
you could completely replace :bu with yours:
:cab bu Bs
of course, this will affect all command-line/search
etc. places where you have to search for or otherwise
type 'bu' as a single word (i do this for 'sp' where i
use 'Sp', a version i wrote that allows entering
multiple filenames and opens them all -- the default
behaviour is identical to 'sp' so i can replace 'sp'
safely).
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=183 (3 of 3) [18/02/2004 14:47:48]

SourceForge
Logo

Tip #184 - How to obscure text instantaneously : vim online

not logged in (login)

Home
Search

Tip #184: How to obscure text instantaneously


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 79/47, Viewed by 3474

created: December 18, 2001 12:05


author: vim user

complexity: basic
as of Vim: 5.7

Hi,
Lets say your writing some imp. doc. and your colleague
comes along. you don't wan't him to see what you are
typing.
so u start fumbling to type :wq! or switch with Alt-TAB.
etc.
but wouldn't it be nice to just obsucre the text
temporarily,
so that u don't have to quit or swith to another
application using Alt-tab.
(and if u don;t have any other window open u can;t even
use alt-tab)
well rot-13 comes to help. vim has a built in rot-13
encoder.
jut put the follwoing in your .vimrc
map <F3> ggVGg?
so next time some body comes along just press <F3> and
all the buffer will
be rot-13 encoded. to decode just press <f3> again.
Njoy
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Select a buffer from those matching a pattern | Make vim the editor for files with unregistered
extensions in Windows >>

Additional Notes
salmanhalim@hotmail.com, December 18, 2001 12:27

http://www.vim.org/tips/tip.php?tip_id=184 (1 of 3) [18/02/2004 14:47:51]

Tip #184 - How to obscure text instantaneously : vim online

a faster (though potentially riskier -- see below)


alternative might be to rot13 just the visible
screen. this might save some time in the case of a big
file:
map <f3> HVLg?
i also like restoring the cursor position:
map <f3> mzHVLg?`z
the risk this incurs is that if precisely the same set
of screen lines isn't visible, the redoing the
operation will NOT restore everything correctly (it may
rot13 some other lines while only restoring the
previously rot13'd lines partially). of course, i
don't like the 'modified +' sign so i DON'T re-rot13
the lines -- i hit 'u' to undo the changes, which will
work irrespective of how the cursor has moved.
Anonymous, January 4, 2002 9:06
I would also :se rl!<CR> to make punctuations
Anonymous, February 11, 2002 4:02
Or may be
map <F3> ggdG
and then use u to restore text? ;-)
Anonymous, March 4, 2002 11:32
Why change file at all?
map <f3> Gz<Enter>
It will keep the last line on the screen though...
frankipank@netscape.net, April 23, 2002 12:16
... and if the document is short Gz will leave the
whole text on the screen:-(
frankipank@netscape.net, April 23, 2002 12:17
Oops, sorry, i left out the Enter;-)
carlos@laviola.org, April 26, 2002 8:26
There is no need to enter visual mode. You can just
use ggg?G to rot13 the whole file. If you're a fast
typist, maybe you won't even need a mapping with this
easy key sequence.
-- carlos
http://www.vim.org/tips/tip.php?tip_id=184 (2 of 3) [18/02/2004 14:47:51]

Tip #184 - How to obscure text instantaneously : vim online

realblades@yahoo.com, August 16, 2002 0:06


If you have multitasking and job control, you can just
suspend the editor with ^Z (or whatever susp is set
to). If you have a terminal that supports it, ^L may
also be a fast way to clear the terminal. Then you can
type something like ps -ef or jobs or ls or pwd or
whatever spinal reflex commands that make it look like
you're busy with the shell :-)
fun, January 6, 2003 22:52

:se rl
Or nn K :se rightleft<CR>
it is fun
Anonymous, October 14, 2003 16:28
The beauty of rot13 is that you don't have to
"undo". When you rot13 again, it is the reverse
operation, because there are 26 letters in the
alphabet. It's a symmetric cypher.
Anonymous, December 11, 2003 22:22
Some other options:(1)
ZZ

- to save changes and exit VIM

(2)
:%d " to blank the VIM window by deleting all
lines and then press
u
- to restore all of the deleted lines
(3) Don't edit things when you should be doing
something else -- like working. ;-)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=184 (3 of 3) [18/02/2004 14:47:51]

SourceForge
Logo

Tip #185 - Make vim the editor for files with unregistered extensions in Windows : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #185: Make vim the editor for files with unregistered extensions
in Windows
tip karma

Rating 57/23, Viewed by 1658

created: December 19, 2001 6:51


author: Leif Wickland

complexity: basic
as of Vim: 6.0

Normally in Windows, if you try to "launch" a file whose


extension is not registered with the system, the OS will
prompt you for what editor you would like to use to open
the file. A much more appealing solution, in my mind,
is to make vim the default editor for any unregistered
extension.
To set vim up as the default editor for unregistered
extensions, follow these steps:
1. Copy the following into a file named unregistered.reg
-------------begin unregistered.reg----------------REGEDIT4
[HKEY_CLASSES_ROOT\Unknown\shell\Open\Command]
@="d:\\program files\\vim\\vim60\\gvim.exe \"%1\""
-------------end unregistered.reg----------------2. Import unregistered into your registry.
done in vim by executing the following
:!regedit "unregistered.reg"

This can be

Disclaimer: This has been tested only on NT4.


rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<How to obscure text instantaneously | Making search powerful >>

Additional Notes
ilan@pointer.co.il, January 1, 2002 23:49
It doesn't work for Windows 2000.
abraund@writeme.com, January 2, 2002 0:43

http://www.vim.org/tips/tip.php?tip_id=185 (1 of 2) [18/02/2004 14:47:53]

Too bad...

Tip #185 - Make vim the editor for files with unregistered extensions in Windows : vim online

My install of Win2K had an "openas" key defined;


HKEY_CLASSES_ROOT\Unknown\shell\openas
I renamed it to
HKEY_CLASSES_ROOT\Unknown\shell\openasBak
and imported the unregistered.reg (adjusted for my gvim
install) and
now unregistered files open with gvim.
shadewizard@hotmail.com, April 15, 2002 4:06
doesn't work with win98se.
too bad.
mfg
mg
Klaus Horsten <email.5@gmx.net>, January 13, 2003 12:31
Windows 2000 NT
This works:
Registry-Path:
[HKEY_CLASSES_ROOT\Unknown\shell\openas\command]
I changed this:
%SystemRoot%\system32\rundll32.exe
%SystemRoot%\system32\shell32.dll,OpenAs_RunDLL %1
to
"D:/vim/vim60/gvim.exe" "%1"
and it works.
Klaus
Anonymous, September 8, 2003 15:30
Same as Tip #279: On Windows, make GVim the default
action for double-click with "unknown file types"
http://www.vim.org/tips/tip.php?tip_id=279
Works on Win9x, WinME, WinNT, Win2k, WinXP.

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=185 (2 of 2) [18/02/2004 14:47:53]

SourceForge
Logo

Tip #186 - Making search powerful : vim online

not logged in (login)

Home
Search

Tip #186: Making search powerful


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -44/44, Viewed by 923

created: December 20, 2001 14:01


author: Arun

complexity: basic
as of Vim: 5.7

My tip is just a bunch of mappings that can be used


while searching.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Make vim the editor for files with unregistered extensions in Windows | Making search powerful >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=186 [18/02/2004 14:47:55]

SourceForge
Logo

Tip #187 - Making search powerful : vim online

not logged in (login)

Home
Search

Tip #187: Making search powerful


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/20, Viewed by 1978

created: December 20, 2001 14:28


author: Arun

complexity: basic
as of Vim: 5.7

(Sorry, I think I accidentally added an incomplete tip)


My tip is just a bunch of mappings that can be used
while searching.
What it does?
o. Extend your current search. (kinda emacs search
where you can search each occurences
one by one and go back to the cursor position.
o. Scroll/position during mapping.
o. Other miscellaneous stuffs ;) read on
How to use?
o. copy and paste the mappings into a file
o. open vim (like vim .profile)
o. :so <saved-file>
o. start using the mappings
Note:
In case these mappings dont work run like, 'vim -u
NONE -U NONE -c "so the-saved-file.vim"'
Some of my mappings override the default vim
bindings. (like Ctrl-A, Ctrl-Q). I
selected those because, I feel by taking those I can
do all the search stuff with
my left hand.
One thing I did not like with this is, I usually miss
the "search hit bottom" message. I could have
handled that by complicating the current mappings,
but I preferred to make it simple
Mappings Used
/
=> regular forward search start
?
=> regular backward search start
Rest of the mappings are used during search
Ctrl-A => search again forward (In normal mode, search
forward with the word under cursor)

http://www.vim.org/tips/tip.php?tip_id=187 (1 of 4) [18/02/2004 14:47:58]

Tip #187 - Making search powerful : vim online

Ctrl-Q => search again backward (in normal mode, search


backward with the word under cursor)
Ctrl-X => restore cursor (use at any point of
time/during-any-operation mentioned during searching)
Ctrl-F => search with the word under cursor
Ctrl-G => incrementally add the letters following the
search pattern (in current line)
Ctrl-T Ctrl-T => search for the exact
Ctrl-T Ctrl-Y => search partial (just strips \< and \>)
Ctrl-E => scroll up during searching
Ctrl-Y => scroll down during searching
Ctrl-Z Ctrl-Z => position the cursor to mid of screen
(like zz in normal)
Ctrl-Z Ctrl-A => position the cursor to top of screen
(like zt in normal)
Ctrl-Z Ctrl-X => position the cursor to bottom of screen
(like zb in normal)
Misc:
Ctrl-K during search save the current matching line
Ctrl-K in normal mode pastes the saved line
C mappings
Ctrl-V Ctrl-G search for the global variable of the
search pattern/word under cursor
Ctrl-V Ctrl-H search for the local variable of the
search pattern/word under cursor
" --- cut n paste from here to end of document --se nocp incsearch
" core mappings
noremap / mg/
noremap ? mg?
ounmap /
ounmap ?
noremap <C-A> mg"gyiw/<C-R>g
cnoremap <C-A> <CR>/<Up>
cnoremap <C-X> <CR>`g
cnoremap <C-Q> <CR>?<Up>
" extending current search mappings
cnoremap <C-F> <CR>yiw<BS>/<C-R>"
cnoremap <C-G> <CR>y/<Up>/e+1<CR><BS>/<CR>=escape(@",'.*\/?')<CR>
" miscellaneous: copy current line during search and
later paste in NORMAL mode
cnoremap <C-K> <CR>"hyy?<Up><CR>/<Up>
noremap <C-K> "hp

http://www.vim.org/tips/tip.php?tip_id=187 (2 of 4) [18/02/2004 14:47:58]

Tip #187 - Making search powerful : vim online

" exact/partial search mappings


cnoremap <C-T><C-T> <Home>\<<C-End>\>
cnoremap <C-T><C-Y> <Home><Del><Del><End><Del><Del>
" C global/local variable search mappings
noremap <C-V><C-G> mgyiw<CR>gg/\<<C-R>"\>
noremap <C-V><C-H> mgyiw?^{<CR>/\<<C-R>"\>
cnoremap <C-V><C-G> <CR>yiwgg/\<<C-R>"\>
cnoremap <C-V><C-H> <CR>yiw?^{<CR>/\<<C-R>"\>
" positioning/scrolling during search mappings
cnoremap <C-E> <CR>mt<C-E>`t<BS>/<Up>
cnoremap <C-Y> <CR><C-Y><BS>/<Up>
cnoremap <C-Z><C-A> <CR>zt<BS>/<Up>
cnoremap <C-Z><C-X> <CR>zb<BS>/<Up>
cnoremap <C-Z><C-Z> <CR>zz<BS>/<Up>
" VISUAL mappings
vnoremap / ymg/<C-R>=escape(@",'.*\/?')<CR>
vnoremap ? ymg?<C-R>=escape(@",'.*\/?')<CR>

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Making search powerful | Searching for more than one word at the same time. >>

Additional Notes
kgergely@mcl.hu, January 15, 2002 9:48
Some of your mapping is needless.
Eg. you can search for the word under the cursor with *
and #.
See vimtp#1
arunke@yahoo.com, February 7, 2002 21:15
In response to kgergely's comment.
It is not redundant. If you are using regular
expression for search, you can still continue search
with my mappings, but not with */#
arunke@yahoo.com, February 7, 2002 21:18
sorry I did not read your comment properly. Yeah, its
kinda redundant. But if you wish to restore your cursor
position after a lot of searches, it might be useful.
(with */#, you have to do that many <c-o>s)

http://www.vim.org/tips/tip.php?tip_id=187 (3 of 4) [18/02/2004 14:47:58]

Tip #187 - Making search powerful : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=187 (4 of 4) [18/02/2004 14:47:58]

SourceForge
Logo

Tip #188 - Searching for more than one word at the same time. : vim online

not logged in (login)

Home
Search

Tip #188: Searching for more than one word at the same time.
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 58/37, Viewed by 1899

created: December 24, 2001 9:29


author: vim_power

complexity: basic
as of Vim: 5.7

Did you know that with VIM u can search for more
than one word with a single command.
say you want to search all occurances of "bill" or
"ted", or
"harry" in a text.
in normal mode do the following.
/\(bill\)\|\(ted\)\|\(harry\) <Enter>
this will match all instances of either "bill", or
"ted", or "harry" in your
text. the key is the \(\) and \| operators.
\(\) group characters in a word and \| is for ORing.
this is so cool u can even use it for replacing text.
to replace all instances of "bill" or "ted" or "harry"
with "greg"
do the following
:%s/\(bill\)\|\(ted\)\|\(harry\)/greg/g <enter>
(note :- if u have set the option "gdefault" u don't
need the "g" at the
end of the above command)
I don't know of any other editor which can do this, with
so much ease.
Rock on VIM
Njoy
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Making search powerful | Make Ctrl-Backspace delete previous word (like GTK inputs) >>

Additional Notes
davidi@msn.com, December 28, 2001 15:36

http://www.vim.org/tips/tip.php?tip_id=188 (1 of 3) [18/02/2004 14:48:02]

Tip #188 - Searching for more than one word at the same time. : vim online

1) Simplified Search
If you don't want to do replaces with captured text you
can simplify eliminating the escaped parentheses, thus
/\(bill\)\|\(ted\)\|\(harry\) <Enter>
becomes
/bill\|ted\|harry <Enter>
Note that you do still have to escape the pipe symbol
2) Simplified Replace
In the example given you don't need the escaped parens
to replace the text 'bill' 'ted' or 'harry' with the
word 'greg,' thus
:%s/\(bill\)\|\(ted\)\|\(harry\)/greg/g <enter>
becomes
:%s/bill\|ted\|harry/greg/g <enter>
3) Capturing the enclosed text
If you do want to capture the enclosed text for
replacement it's still simpler to enclose the whole
statement in one set of parens, thus
/\(bill\)\|\(ted\)\|\(harry\) <Enter>
becomes
/\(bill\|ted\|harry\) <Enter>
4) The full monty
Since using escaped parens -- as in \(bill\|...\) -captures the enclosed text in a regex \1 variable you
can do replacements that would otherwise be sick and
wrong, like put every instance of 'bill' 'ted' or
'harry' in quotes, thus
:%s/\(bill\|ted\|harry\)/"\1"/g
Note: These tricks may work in other versions of vi as
well (for instance it works in vile). I never realized
you had to escape the pipe to do the 'or' trick before
and assumed regexes just weren't fully implemented.
sitar@procaut.txt, January 14, 2002 5:34
There are a few other editors that can do the trick.
Like TextPad for windows,
or Emacs or ..... . Any editor that uses Regular
expressions.
duvell@beer.com, January 25, 2002 21:30

http://www.vim.org/tips/tip.php?tip_id=188 (2 of 3) [18/02/2004 14:48:02]

Tip #188 - Searching for more than one word at the same time. : vim online

If you are using the entire matched text as part of


your replace pattern, it is easier to use & instead of
enclosing the entire search pattern in \( ...\) and
referencing it as \1. Using this, the following
substitute command:
:%s/\(bill\|ted\|harry\)/"\1"/g
can be simplified to this:
:%s/bill\|ted\|harry/"&"/g
The & will be replaced with the entire matching text.
eagsalazar@hotmail.com, November 25, 2003 16:40
Ok, that is cool but in Emacs I heard you can have a
different highlighting color for each of the matched
regexp (not using this regexp syntax obviously). That
would be cool to highlight a RE in one color then leave
it around while you do most of your normal search
highlighting using another color.
Is this possible in vim?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=188 (3 of 3) [18/02/2004 14:48:02]

SourceForge
Logo

Tip #189 - Make Ctrl-Backspace delete previous word (like GTK inputs) : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #189: Make Ctrl-Backspace delete previous word (like GTK


inputs)
tip karma

Rating 8/10, Viewed by 919

created: January 2, 2002 10:03


author: Robert Ames

complexity: basic
as of Vim: 5.7

Stuff this into your ~/.gvimrc and then you'll be able


to type Control-Backspace to delete the previous
word. I had gotten so used to C-BS working a certain
way in all my editors with a ceezy input area (like
mozilla/galeon, gabber, etc...), that I wanted the same
behaviour when I used gvim.
" map control-backspace to delete the previous word
:imap <C-BS>
<Esc>vBc
Simple, I know, but reasonably useful.
--Robert
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Searching for more than one word at the same time. | XP > I-Explorer > HTML Editor < REG files
>>

Additional Notes
jmcpherson@bigfoot.com, January 2, 2002 10:50
Vim has a built-in keyboard command for deleting the
previous word while in Insert mode: Ctrl-W, which works
the same way it does on the command line of your
favorite shell (bash, right? (-;)
So this also works:
:imap <C-BS> <C-W>
Anonymous, January 7, 2002 13:23

http://www.vim.org/tips/tip.php?tip_id=189 (1 of 2) [18/02/2004 14:48:04]

Tip #189 - Make Ctrl-Backspace delete previous word (like GTK inputs) : vim online

C-W is the prefix for window commands - the previous


note might be incorrect.
Debian@austin.rr.co, January 7, 2002 15:37
In INSERT mode only <ctrl-w> will backword delete one
word at a time in insert mode until the cursor reaches
the beginning of the inserted text for the current <cr>
terminated line. Also in INSERT <c-d> will backtab
autoindents and <c-u> will delete all inserted text on
the current line. However, nobody uses these vi
feature in VIM since VIM has more general solutions for
these needs.
--Jonathan-kgergely@mcl.hu, January 9, 2002 6:44
Tell me more about these solutions!
But emacs or bash-like keys will be good enough, won't
be?
But perhaps they can hide nice vim features, if applied
:-(
realblades@yahoo.com, August 16, 2002 2:21
Why add emacs and windos crap :-)
Move to zsh, put to ~/.zshrc:
export INPUTRC=$HOME/.inputrc
export EDITOR="vim" VISUAL="vim"
bindkey -v
and to .inputrc
set editing-mode vi
And be happy.
(or you can always use ksh if you want less bloat)
Now if only browsers had vi editing in these
$DEITYdamned input fields...
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=189 (2 of 2) [18/02/2004 14:48:04]

SourceForge
Logo

Tip #190 - XP > I-Explorer > HTML Editor < REG files : vim online

not logged in (login)

Tip #190: XP > I-Explorer > HTML Editor < REG files

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 55/16, Viewed by 2774

created: January 2, 2002 16:09


author: Hal Atherton

complexity: intermediate
as of Vim: 6.0

The issue is permitting other programs, besides NOTEPAD,


be the HTML editor under Internet Explorer.
(Adding "Edit" as a New Action in the publicly exposed
Files Types for HTM/L does NOT do the job.)
Given below are two REG files for vim.
Just cut 'em up where indicated.
They have been tested under Windows XP.
-------------------------------------------------------CUT HERE--------------Windows Registry Editor Version 5.00
;
;
;
;
;
;

GOAL: Set gvim as HTML editor in Internet Explorer 6.0


Vim version : 6.0
Windows version: XP
EASY USAGE: name this file iex-vim60.reg and double click on it
Hard Usage: IMPORT this file using REGEDIT.EXE found in c:\WINDOWS
Last modified date : Dec 16, 2001

; gvim is expected in "C:\Program Files\Vim\vim60\gvim.exe"


; Be sure to also reset Explorer>Tools>Internet Options>Programs
; Microsoft documentation
;
http://msdn.microsoft.com/workshop/browser/configuration/clientreg/clientregistrylayout.asp
; Add Vim in the list of supported HTML editors
[HKEY_CLASSES_ROOT\.htm\OpenWithList\Vim]
[HKEY_CLASSES_ROOT\.htm\OpenWithList\Vim\shell]
[HKEY_CLASSES_ROOT\.htm\OpenWithList\Vim\shell\edit]
http://www.vim.org/tips/tip.php?tip_id=190 (1 of 3) [18/02/2004 14:48:06]

Tip #190 - XP > I-Explorer > HTML Editor < REG files : vim online

[HKEY_CLASSES_ROOT\.htm\OpenWithList\Vim\shell\edit\command]
@="\"C:\\Program Files\\Vim\\vim60\\gvim.exe\" \"%1\""
; Do NOT add to .html, registry for .htm type suffices
;[HKEY_CLASSES_ROOT\.html\OpenWithList\Vim]
;[HKEY_CLASSES_ROOT\.html\OpenWithList\Vim\shell]
;[HKEY_CLASSES_ROOT\.html\OpenWithList\Vim\shell\edit]
;[HKEY_CLASSES_ROOT\.html\OpenWithList\Vim\shell\edit\command]
;@="\"C:\\Program Files\\Vim\\vim60\\gvim.exe\" \"%1\""
; OPTIONAL: Within Internet Explorer "View Source" with gvim
; but prefer to use Edit button (got to add this) on Toolbar
;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source Editor]
;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source Editor\Editor Name]
;@="C:\\Program Files\\Vim\\vim60\\gvim.exe"
; ============================================= EOF
-------------------------------------------------------CUT HERE--------------Windows Registry Editor Version 5.00
;
;
;
;
;
;

GOAL: UNINSTALL gvim as HTML editor in Internet Explorer 6.0


Vim version : 6.0
Windows version: XP
EASY USAGE: name this file iex-vim60-uninstall.reg and double click on it
Hard Usage: IMPORT this file using REGEDIT.EXE found in c:\WINDOWS
Last modified date : Dec 16, 2001

; gvim is expected in "C:\Program Files\Vim\vim60\gvim.exe"


; Be sure to also reset Explorer>Tools>Internet Options>Programs
; Microsoft documentation
;
http://msdn.microsoft.com/workshop/browser/configuration/clientreg/clientregistrylayout.asp

[-HKEY_CLASSES_ROOT\.htm\OpenWithList\Vim]
[-HKEY_CLASSES_ROOT\.html\OpenWithList\Vim]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source Editor]
http://www.vim.org/tips/tip.php?tip_id=190 (2 of 3) [18/02/2004 14:48:06]

Tip #190 - XP > I-Explorer > HTML Editor < REG files : vim online

; ============================================= EOF
-------------------------------------------------------CUT HERE--------------Happy Vimming...
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Make Ctrl-Backspace delete previous word (like GTK inputs) | Transposing >>

Additional Notes
Anonymous, January 2, 2002 17:52
When using vim to 'view source' from IE, you need to wrap it.
IE requires an editor that can open files with embedded spaces - see vimtip #118 for a
windows scripting solution.
doug@polands.org, July 16, 2002 6:16
Can this be done in the Mozilla as well?
liuch@alum.rpi.edu, September 25, 2002 11:06
I am using opera as my web browser.

You can setup you source viewer program from opera.

www.opera.com
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=190 (3 of 3) [18/02/2004 14:48:06]

SourceForge
Logo

Tip #191 - Transposing : vim online

not logged in (login)

Home
Search

Tip #191: Transposing


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 22/12, Viewed by 1065

created: January 3, 2002 10:34


author: Kontra Gergely

complexity: intermediate
as of Vim: 5.7

You can easily move lines with these maps using <C-Up>
and <C-Down> (only in GUI version :( )
(Works in normal, insert, and visual mode, but you can't
add a count to them)
" Transposing lines
nmap <C-Down> :<C-u>move .+1<CR>
nmap <C-Up> :<C-u>move .-2<CR>
imap <C-Down> <C-o>:<C-u>move .+1<CR>
imap <C-Up> <C-o>:<C-u>move .-2<CR>
vmap <C-Down> :move '>+1<CR>gv
vmap <C-Up> :move '<-2<CR>gv
" Transpose chars (like Ctrl-T in emacs, shell...)
imap <C-F> <Esc>Xpa
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<XP > I-Explorer > HTML Editor < REG files | Latex Help for VIM >>

Additional Notes
Anonymous, January 6, 2002 20:50
There is another way to transpose chars.
Simply type xp in command mode.
Douglas Potts <pottsdl@yahoo.com>, January 7, 2002 5:04
Nice touch using the ex move commands.
'polluting' registers
with the text you are transposing.
Add Note

http://www.vim.org/tips/tip.php?tip_id=191 (1 of 2) [18/02/2004 14:48:08]

Keeps from

Tip #191 - Transposing : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=191 (2 of 2) [18/02/2004 14:48:08]

SourceForge
Logo

Tip #192 - Latex Help for VIM : vim online

not logged in (login)

Home
Search

Tip #192: Latex Help for VIM


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 10/5, Viewed by 1126

created: January 7, 2002 12:32


author: Mikolaj Machowski

complexity: basic
as of Vim: 6.0

LaTeX Help for aucTeX `translated' as vim help file.


Installing
:help add-local-help
rate this tip

Site Help

Life Changing

Helpful

Unfulfilling

rate

<<Transposing | Insert the current filename at cursor postion. >>

Additional Notes
mikmach@wp.pl, January 7, 2002 14:38
Sorry all :(((((((((((((((((((
http://www.vim.phg.pl/latexhelp.zip
mikmach@wp.pl, January 7, 2002 14:39
Sorry all :(((((((((((((((((((
http://www.vim.phg.pl/latexhelp.zip
maxiangjiang@hotmail.com, January 8, 2002 8:46
Thanks.
Any tools to get the job done?
Hopefully, all applications will have a help file in
vim format shipped out.
maxiangjiang@hotmail.com, January 8, 2002 8:50

http://www.vim.org/tips/tip.php?tip_id=192 (1 of 2) [18/02/2004 14:48:11]

Tip #192 - Latex Help for VIM : vim online

One more thing.


When I searched "latex" on this site, I could not find
this tip.
What is trick to "help" vim.sourceforge.net to add this
tip
to its search engin?
Anonymous, February 13, 2003 18:19
Oops...
The link seems broken! HTTP 401! Any mirrors?
Mikolaj Machowski, September 21, 2003 5:54
Sorry, I should post this earlier (much earlier :)
latexhelp.txt is now a script on this page:
http://www.vim.org/scripts/script.php?script_id=206
also is part of vim-latexSuite
http://vim-latex.sourceforge.net
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=192 (2 of 2) [18/02/2004 14:48:11]

SourceForge
Logo

Tip #193 - Insert the current filename at cursor postion. : vim online

not logged in (login)

Home
Search

Tip #193: Insert the current filename at cursor postion.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/10, Viewed by 1248

created: January 7, 2002 16:00


author: Steve Downing

complexity: basic
as of Vim: 5.7

I found this one good for when I was starting to learn


Java, it simply inserts the current filename, at the
cursor position, when you are in insert mode. Honestly,
its a mish-mash of some other tips I found here, but I
thought it might be useful.
imap \fn

<C-R>=expand("%:t:r")<CR>

Enjoy!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Latex Help for VIM | Inserting text in multiple lines >>

Additional Notes
bindu@wavell.net, January 22, 2002 17:38
I often use <C-R>% when in insert mode... It does the
same thing, except you also get your file extension.
isaac.sparrow@engineer.com, March 1, 2002 14:44
Cool tip. I find myself needing to do this whenever I
create a new Java file.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=193 [18/02/2004 14:48:13]

SourceForge
Logo

Tip #194 - Inserting text in multiple lines : vim online

not logged in (login)

Home
Search

Tip #194: Inserting text in multiple lines


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 300/95, Viewed by 3671

created: January 8, 2002 7:52


author: Gergely Kontra

complexity: basic
as of Vim: 5.7

Do you know the I key in visual-block mode?


Suppose you have
let a=2
let b=3
let c=4
You want to make these variables script-wise. Then you
move to over a, hit <C-v>, press jj and now press I.
You will be in insert mode before a
Now enter s:<Esc>, and when you press <Esc>, b and c
will have the s: prefix too.
See |v_b_I|
Happy vimming!
Gergely Kontra
rate this tip

Life Changing

Helpful

Unfulfilling

<<Insert the current filename at cursor postion. | Switching between files >>

Additional Notes
jmcpherson@softhome.net, January 8, 2002 15:17

http://www.vim.org/tips/tip.php?tip_id=194 (1 of 3) [18/02/2004 14:48:16]

rate

Tip #194 - Inserting text in multiple lines : vim online

The above tip represents a concept that has saved me


TONS of time over the past year or so. I use it daily.
There are lots of other neat things you can do with
block selects. One of my favorites is adding a string
to the end of each line... like so:
1. Press Ctrl+V and then j to extend the selection to
all the lines you want
2. Press $. This will create a 'ragged edge' selection
that extends to the right end of each line in your
selection.
3. Press A. I inserts text at the beginning of a block
selection, A appends text at the end of a block
selection.
4. Type your text and press Esc.
Presto! You could also do something like this with
:.,+10s/$/newtext ... but I've become a big fan of
visual selections because they avoid line counting.
Also, the usual "c," "d," "y," and "r" commands work as
you'd expect to change/delete/yank/replace stuff in
blocks. So cool.
david@tvis.co.uk, August 2, 2002 8:18
Thanx
Remember Win32 users you probably need to use <C-Q> as
you've probably mapped <C-V> to Paste
Anonymous, April 23, 2003 12:16
Holy @#$# !! I've been using vim for years, and there's
infinite stuff to learn. This tip is phenomenal !! Both
the smart way to insert comments at the beginning, and
the one to append something to the end of every
line. When you edit a config file that has 2 or more
columns, and you want to append a new column, the
second tip comes in very handy. Thanks!
Anonymous, May 6, 2003 13:49
Hoooo Raah! Very nice indeed!
Add Note

http://www.vim.org/tips/tip.php?tip_id=194 (2 of 3) [18/02/2004 14:48:16]

Tip #194 - Inserting text in multiple lines : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=194 (3 of 3) [18/02/2004 14:48:16]

SourceForge
Logo

Tip #195 - Switching between files : vim online

not logged in (login)

Home
Search

Tip #195: Switching between files


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 25/13, Viewed by 2084

created: January 9, 2002 7:45


author: Kontra, Gergely

complexity: basic
as of Vim: 5.7

When you edit multiple files, you often need to change


windows.
You can set up vim in windows and gvim to switch between
windows with the commonly used Ctrl-Tab and Ctrl-ShiftTab
The mappings
nmap <C-Tab> <C-w>w
nmap <C-S-Tab><C-w>W
(They wrap around)
See also |Ctrl-w|
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Inserting text in multiple lines | FileName Completion in Shell Scripts >>

Additional Notes
glen_ap@yahoo.com, September 6, 2002 16:34
I don't know which way is better, but I couldn't get
that way to work. So I use this instead.
:map <C-Tab> :bn<CR>
:map <C-S-Tab> :bp<CR>
(Reminds me of Perl, TMTOWTDI)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=195 [18/02/2004 14:48:18]

SourceForge
Logo

Tip #196 - FileName Completion in Shell Scripts : vim online

not logged in (login)

Home
Search

Tip #196: FileName Completion in Shell Scripts


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 22/13, Viewed by 1279

created: January 10, 2002 10:10


author: vim_power

complexity: basic
as of Vim: 5.7

In shell scripts, you often define environment variables


for diff directory names.
i.e.
JAVA_HOME=/opt/java/jdk1.4
PATH=/usr/local/bin:/bin....
Normally typing Ctrl-X Ctrl-F is used to complete
FileName under cursor.
But this does not work if used on lines given above.
This is because vim treats "=" sign as a valid filename
character.
Since the actual possibility of "=" being in any
filename is very less, this
char can be removed from the list of valid filename
char.
set isfname-==
putting the above line in .vimrc will remove "=" from
the list of valid filename chars.
thus u can easyly complete filenames using <Ctrl-X>
<Ctrl-F>
Njoy
rate this tip

Life Changing

Helpful

Unfulfilling

<<Switching between files | Open file in already running vim from elsewhere >>

Additional Notes
Anonymous, September 17, 2002 7:41

http://www.vim.org/tips/tip.php?tip_id=196 (1 of 2) [18/02/2004 14:48:20]

rate

Tip #196 - FileName Completion in Shell Scripts : vim online

For source code editors of Progress, based on this tip,


I used
set isfname-={,}
and now my include files are pulled in automatically
with gf when they are in the format {myinclude.i}
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=196 (2 of 2) [18/02/2004 14:48:20]

SourceForge
Logo

Tip #197 - Open file in already running vim from elsewhere : vim online

not logged in (login)

Home
Search

Tip #197: Open file in already running vim from elsewhere


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 51/18, Viewed by 1674

created: January 10, 2002 23:59


author: T. Zellerin

complexity: basic
as of Vim: 6.0

If you want edit new file, and you want do it in alrady


running vim, instead of launching another instance, you may
use --remote argument:
gvim first_file
gvim --remote +split first_file
:he --remote
It requires X windows (but works in terminal version of vim
there too) or MS windows and built-in client-server
mechanism. If there are several instances of vim already
running, you may choose to which you talk using --servername
:help --servername
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<FileName Completion in Shell Scripts | Pasting code with syntax coloring in emails >>

Additional Notes
hari_vim@yahoo.com, January 15, 2002 16:11
Just wanted to add to this that there are builtin functions
available that let you do the same thing from within
running Vim session. It is cool, if you want some sample
code, see the following script:
http://vim.sourceforge.net/scripts/script.php?script_id=180
schabungbam@hss.hns.com, January 24, 2002 4:02

http://www.vim.org/tips/tip.php?tip_id=197 (1 of 2) [18/02/2004 14:48:23]

Tip #197 - Open file in already running vim from elsewhere : vim online

I have the following alias in shell initialization script


file (~/.bashrc)
alias gvir="gvim --remote"
Then, it is very convinient for me to open a file in an
existing gvim window.
$ gvir new_file
dholmes@jccc.net, January 24, 2003 8:17
If you are using some buffer manager like vimscript #159
you mind find the following bash alias commands useful to
start vim:
alias gvdev=" gvim --servername foo --remote"
alias gvlib=" gvim --servername bar --remote"
You can use different names, etc...but the gist of it is
that you can open different files into one or many
windows. Use gvdev to open your actual scripts and gvlib
to open config, headers, libraries, etc.
You don't have to worry about pre-starting a server...if
it's not found, gvim will start with that name anyway.

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=197 (2 of 2) [18/02/2004 14:48:23]

SourceForge
Logo

Tip #198 - Pasting code with syntax coloring in emails : vim online

not logged in (login)

Home
Search

Tip #198: Pasting code with syntax coloring in emails


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 42/22, Viewed by 2445

created: January 15, 2002 12:34


author: Hari Krishna Dara

complexity: basic
as of Vim: 5.7

When sending code snippets or diffs to your colleagues


either for code review or for something else as email,
how nice and clear it will be if you can paste it with
the Vim syntax highlighting? I am sure they will be
impressed and feel much easier to read the code. It is
also very easy and fast (once you practice it) to do
this.
This probably works only on windows and requires you to
use Internet Explorer and an email client that
understand RTF content coming from clipboard, such as
Outlook or Outlook Express. At least that would make the
process faster. I haven't tried on any other combination
though. This is what you need to do:
- Open the file containing the code/code snippet/diff
etc. in gvim. If you use dark background for GVim (like
me), then I would suggest you to change your color
scheme temporarily to something else that has a white
background or just use the "-U NONE" as below:
gvim -U NONE <file>
- Convert the file into HTML by using the following
command at the colon prompt as below:
:runtime syntax/2html.vim
- The above step will open a new window with the HTML
content in it. You might want to just save it with the
suggested name or write into a temporary file as:
:w! c:/tmp/t.html
- Open the IE browser window and open the above temp
file "c:/tmp/t.html".
- Now you select all (press ^A) and copy it (^C).
- You are ready to paste it with syntax coloring in any

http://www.vim.org/tips/tip.php?tip_id=198 (1 of 3) [18/02/2004 14:48:25]

Tip #198 - Pasting code with syntax coloring in emails : vim online

application that accepts RTF content from clipboard,


including Outlook or Outlook Express mail composing
window.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Open file in already running vim from elsewhere | maximize window and return to previous split
structure >>

Additional Notes
benji@member.AMS.org, January 15, 2002 20:16
1. If you are using gvim then you can convert to HTML
from the Syntax menu, so you do not have to remember
the right file to source.
2. I got it to work using Netscape. I converted to
HTML, saved the file, opened the file in Netscape, and
chose "Send Page..."
from the file menu. This sends the HTML as an
attachment. When I got the message, the attachment was
displayed in-line;
this depends on how preferences are set. It would
probably also work to simply save the file and then
attach it.
raycast@hotmail.com, February 21, 2002 11:59
Internet Explorer??? What the heck is that? I don't
have that... :-P
hari_vim@yahoo.com, February 23, 2002 13:40
Well, you can always send HTML mail, but it will
probably not easy to send some inlines snippets that
way. More over, I use this to include sample code while
writing design documents in MS word too.
"Soren Andersen" <perlspinr@att.net>, May 1, 2002 14:22

http://www.vim.org/tips/tip.php?tip_id=198 (2 of 3) [18/02/2004 14:48:25]

Tip #198 - Pasting code with syntax coloring in emails : vim online

This is a pretty interesting tip. I haven't tried it


yet but I get the theory. A point of apparent
misunderstanding, tho, was:
RTF != HTML
One poster at least thought he was getting the same
thing by using Netscape, but in fact that's not what
the original tip was about. The RTF format for
exchanging formatted text is a M$ invention and part of
their OLE system. It could be called "markup" for text
but it sure isn't HTML ("HyperText Markup Language") as
anyone can see for themselves by opening a .RTF file
(assuming they can find one -- ask an M$ Word user to
create one for you) in a hex editor.
For those who don't want to use IE but might want to
send formatted email (the person at the other end has
to be known to be using a client that handles "Rich
email") there is probably another way to do this. I am
pretty sure that there exists a Perl module that will
convert HTML to RTF for you (search.cpan.org). A short
Perl script could probably be integrated into gvim to
get that working easily.
Anon, May 7, 2002 15:32
for novice users (or those who don't seem to remeber
all those tricks) gVim 6.x has menu item under "syntax>ConvertToHtml"
it will produce a filename.html with coloring..
use this html as you hearts desire!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=198 (3 of 3) [18/02/2004 14:48:25]

SourceForge
Logo

Tip #199 - maximize window and return to previous split structure : vim online

not logged in (login)

Home
Search

Tip #199: maximize window and return to previous split structure


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/6, Viewed by 1161

created: January 15, 2002 16:32


author: scotch2

complexity: intermediate
as of Vim: 6.0

Say you have layed out a complex window split structure,


and want to temporarily open 1 window with max
dimensions, but don't want to lose your split
structure. The following function and mappings let you
toggle between the split windows and on window
maximized. The mappings prevent the default behavior of
calling :only and losing your finely tuned splits.
Put this bit in your vimrc file, change mappings if you
don't want to override the defaults:
nnoremap <C-W>O :call MaximizeToggle ()<CR>
nnoremap <C-W>o :call MaximizeToggle ()<CR>
nnoremap <C-W><C-O> :call MaximizeToggle ()<CR>
function! MaximizeToggle()
if exists("s:maximize_session")
source s:maximize_session
call delete(s:maximize_session)
unlet s:maximize_session
let &hidden=s:maximize_hidden_save
unlet s:maximize_hidden_save
else
let s:maximize_hidden_save = &hidden
let s:maximize_session = tempname()
set hidden
mksession! s:maximize_session
only
endif
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Pasting code with syntax coloring in emails | Bouncing Parentheses (during insertion) >>

http://www.vim.org/tips/tip.php?tip_id=199 (1 of 2) [18/02/2004 14:48:27]

Tip #199 - maximize window and return to previous split structure : vim online

Additional Notes
scottu@apptechsys.com, January 16, 2002 17:34
There is a bug in the function such that the session
file used is "s:maximize_session" in the current
directory rather than the temp file created with
tempname (). Replace the function with this:
function! MaximizeToggle()
if exists("s:maximize_session")
exec "source " . s:maximize_session
call delete(s:maximize_session)
unlet s:maximize_session
let &hidden=s:maximize_hidden_save
unlet s:maximize_hidden_save
else
let s:maximize_hidden_save = &hidden
let s:maximize_session = tempname()
set hidden
exec "mksession! " . s:maximize_session
only
endif
endfunction
bhoang99@yahoo.com, April 24, 2003 8:25
perhalf you can leave that complex window alone and
open another gvim session...
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=199 (2 of 2) [18/02/2004 14:48:27]

SourceForge
Logo

Tip #200 - Bouncing Parentheses (during insertion) : vim online

not logged in (login)

Home
Search

Tip #200: Bouncing Parentheses (during insertion)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 40/19, Viewed by 2704

created: January 17, 2002 11:51


author: Charles E. Campbell, Jr.

complexity: basic
as of Vim: 5.7

When one is inserting parentheses some folks like to see


the cursor
bounce off the matching parenthesis. To do that, put
the following
map into your <.vimrc> file:
inoremap ) )<c-o>%<c-o>:sleep 500m<CR><c-o>%<c-o>a
Adjust the time delay (its 500 milliseconds above) to
suit your needs.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<maximize window and return to previous split structure | The meaning of life >>

Additional Notes
cec@NgrOyphSon.gPsfAc.nMasa.gov, January 17, 2002 12:58
Somewhat better map:
inoremap ) )<left><c-o>%<c-o>:sleep 500m<CR><c-o>%<co>a
There was a problem when inserting parentheses into
previously
existing text which the <left> handles.
mbrubeck@hmc.edu, January 17, 2002 14:58
Vim 6 has this functionality built-in.
'showmatch' and 'matchtime' options.
salmanhalim@hotmail.com, January 17, 2002 20:07

http://www.vim.org/tips/tip.php?tip_id=200 (1 of 2) [18/02/2004 14:48:29]

See the

Tip #200 - Bouncing Parentheses (during insertion) : vim online

I think the difference between the built-in


functionality and this mapping is that this mapping
works even if the matching bracket isn't currently
visible on-screen. The documentation stipulates that
the 'showmatch' option only highlights the match if
it's actually on-screen.
kgergely@mcl.hu, January 22, 2002 10:22
Matching a paren not on-screen can be scroll your
screen unwantedly...
foo@bar.com, January 22, 2002 12:36
How about a tip on how to add tips? Where's the link?
Anonymous, January 24, 2002 3:53
why don't you just click on 'Add tip' on the tips main
page ?
cec@NgrOyphSon.gPsfAc.nMasa.gov - NOSPAM, February 11, 2002 7:18
If you'd like to have the corresponding parenthesis,
brace, or curly brace
highlighted, check out vimtip#177.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=200 (2 of 2) [18/02/2004 14:48:29]

SourceForge
Logo

Tip #201 - The meaning of life : vim online

not logged in (login)

Home
Search

Tip #201: The meaning of life


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 443/167, Viewed by 7832

created: January 19, 2002 9:51


author: Steve Halpin

complexity: basic
as of Vim: 6.0

Use this tip if you need to discover the meaning of


life, the universe and everything.
Simply do:
:h 42
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Bouncing Parentheses (during insertion) | debugging window autocommands >>

Additional Notes
(Based on a posting at comp.editors), January 25, 2002 9:53
Also check out
:help!
and
:help holy-grail
horsch@cs.usask.ca, November 10, 2002 12:30
But the question is wrong!
The right question is:
"What is the answer to the ultimate
question of life the universe and everything?"
Anonymous, August 27, 2003 4:12
seems to be a serious VIM bug!
;-)) Thomas
Michael-o-mendolsohn@vsnl.com, December 12, 2003 19:39

http://www.vim.org/tips/tip.php?tip_id=201 (1 of 2) [18/02/2004 14:48:32]

Tip #201 - The meaning of life : vim online

The meaning of life is to find the meaning of life,


and if you have found it, go onto find the right
question.
- The Holy Vimapada
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=201 (2 of 2) [18/02/2004 14:48:32]

SourceForge
Logo

Tip #202 - debugging window autocommands : vim online

not logged in (login)

Home
Search

Tip #202: debugging window autocommands


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 17/5, Viewed by 1120

created: January 21, 2002 16:24


author: Hari Krishna Dara

complexity: advanced
as of Vim: 6.0

Don't know how people debug autocommands, but I just


found out that you can debug (at least) those that
result due to window close by just doing a debug quit,
i.e.,
:debug quit
Vim will let you step into the autocommands. Try it to
believe.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<The meaning of life | Make make more helpful >>

Additional Notes
hari_vim at yahoo.com, January 21, 2002 19:04
While going through the help pages, I figured this
feature is documented with the following example:
:debug edit <file>
This should let you debug autocommands that get
triggered by loading a new buffer.
Hari
Mark Hillebrand, February 19, 2002 6:31

http://www.vim.org/tips/tip.php?tip_id=202 (1 of 2) [18/02/2004 14:48:34]

Tip #202 - debugging window autocommands : vim online

There's also the :verbose command, with which you can


specify the verbosity level for one command only:
:9verbose edit somefile.txt.gz
The possible verbose levels are also documented
in :help 'verbose'
(The 'verbose' option variable sets verbosity
permamently, not just for one command only)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=202 (2 of 2) [18/02/2004 14:48:34]

SourceForge
Logo

Tip #203 - Make make more helpful : vim online

not logged in (login)

Home
Search

Tip #203: Make make more helpful


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 60/18, Viewed by 1690

created: January 27, 2002 6:34


author: Padraic Renaghan

complexity: basic
as of Vim: 6.0

I find this a very useful command to use.


Add the below 4 lines to your vimrc.
Then instead of "make" use "Make".
" Command Make will call make and then cwindow which
" opens a 3 line error window if any errors are found.
" if no errors, it closes any open cwindow.
:command -nargs=* Make make <args> | cwindow 3
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<debugging window autocommands | Some mappings for using cscope with vim. >>

Additional Notes
Anonymous, January 27, 2002 20:21
great
salmanhalim@hotmail.com, January 29, 2002 6:01
since typing :Make is a bit troublesome compared to
:make (which i also find a bit tiresome :)) i have a
mapping:
:map <Leader>j :Make<cr>
then, just hit \j and away you go.
Chad, June 17, 2002 13:59
Great tip. I came to this site looking exactly for
this information (like I can remember the errors w/out
seeing them :-)). Thanks alot.
daniel@brot.t0c.de, October 18, 2002 6:17

http://www.vim.org/tips/tip.php?tip_id=203 (1 of 2) [18/02/2004 14:48:39]

Tip #203 - Make make more helpful : vim online

Chad: with :cc you can see the current error and with
:cn and :cp you can switch between the errors.
vim even goes to the position in sourcecode where they
occured.
ezaydens@optonline.net, January 13, 2003 10:14
Does anybody know how to display a complete error
message that is too long for the line? By default it
inserts ellipsys in the middle of it and only displays
the beginning and the end...
Thanks a bunch.
EZ
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=203 (2 of 2) [18/02/2004 14:48:39]

SourceForge
Logo

Tip #204 - Some mappings for using cscope with vim. : vim online

not logged in (login)

Home
Search

Tip #204: Some mappings for using cscope with vim.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/3, Viewed by 959

created: January 28, 2002 10:38


author: Rahul Agrawal

complexity: basic
as of Vim: 6.0

These mappings can make using cscope a fun. You can copy
the word under the cursor in one window, and search for
it from other window.
" Copy and paste the word under cursor
map <silent> <C-Space> :let@m=expand("<cword>")<CR>
" Use the C-Space word as
map <C-F6> :cscope find s
map <C-F5> :cscope find c
map <C-F7> :cscope find g
rate this tip

Life Changing

the search criterion


<C-R>=@m<CR><CR>
<C-R>=@m<CR><CR>
<C-R>=@m<CR><CR>

Helpful

Unfulfilling

rate

<<Make make more helpful | Computing a sum of numbers in vim >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=204 [18/02/2004 14:48:41]

SourceForge
Logo

Tip #205 - Computing a sum of numbers in vim : vim online

not logged in (login)

Home
Search

Tip #205: Computing a sum of numbers in vim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/8, Viewed by 1077

created: January 30, 2002 3:05


author: Stanislav Sitar

complexity: advanced
as of Vim: 6.0

"Sometimes you need to sum a some numbers in vim. There


*are* some plugins
"that can do the job. But what if the numbers are not
in a columns or are on
"the same line or are sacttered all across the file? You
might also need to
"sum all the numbers in file that look like '1234$', or
'54565 Eu' ignoring others.
"
"There is a very simple trick, using (my favourite)
command
":s
"
"First you define following function
:let g:S=0 "In global variable S we later find the
result
:function! Sum(number) "The function is defined with a
'!',
"so it does not complain during debugging
"when you are redefining the function
:let g:S=g:S+a:number "we accumulate the result in
global variable S
:return a:number "function returns the argument, so
after a :s
"command the text remains the same
:endfunction
"you can do issue those few commands from a command
line,
"or create a small file and put it into your plugin
directory,
"or write those few commands into a file end issue a
command :so %

http://www.vim.org/tips/tip.php?tip_id=205 (1 of 3) [18/02/2004 14:48:44]

Tip #205 - Computing a sum of numbers in vim : vim online

"how to use this little function:


"let's suppose you have a simple column of numbers like
"
"10
"20
"30
"
"you issue command like:
:let S=0
:%s/[0-9]\+/\=Sum(submatch(0))/
"the command finds the first number on the line and adds
it to the S
"
"the result is displayed
:echo $S
"!!!! don't forget to do
:let g:S=0
"before use.
"you can also use \zs and \ze atoms in a regular
expression to
"delimit the number, so submatch(0) returns only a
number and
"the text remains unchanged after 'substitute'
"for starter on the wonderfull world of regular
expressions see:
:help usr_27.txt
"for the definition of the search pattern see
:help :s
:help pattern
"for replacement strings begining with \= and special
function submatch(0)see
:help sub-replace-special
"for the *ultimate* guide through the world of regular
expressions see book:
"Mastering Regular Expressions
"Powerful Techniques for Perl and Other Tools
"by Jeffrey E.F. Friedl
"from O'REILLY
"the book does not write about vim, yet here you can
learn that
":s command is the most powerfull command you can find
in a text editor.
"(with the possible exception of :global command)
http://www.vim.org/tips/tip.php?tip_id=205 (2 of 3) [18/02/2004 14:48:44]

Tip #205 - Computing a sum of numbers in vim : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Some mappings for using cscope with vim. | Highlight doubled word errors in text >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=205 (3 of 3) [18/02/2004 14:48:44]

SourceForge
Logo

Tip #206 - Highlight doubled word errors in text : vim online

not logged in (login)

Home
Search

Tip #206: Highlight doubled word errors in text


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/10, Viewed by 791

created: January 31, 2002 4:32


author: Ajit Thakkar

complexity: intermediate
as of Vim: 6.0

An error I sometimes make while working on a LaTeX file


is the repetition of a
word as in "the the". Most often, such doubled words
come about through a
careless edit. Doubled words are hard to spot when the
first word of the
doubled pair is the last word on one line, and the
second word of the pair is the
the first word on the next line. There is an example of
such an error in the last
sentence. Vim's syntax mechanism can be used to
highlight doubled words as an error.
To obtain this highlighting for TeX and LaTeX files,
place the following two lines:
syn match texDoubleWord "\c\<\(\a\+\)\_s\+\1\>"
hi def link texDoubleWord Error
in a file called tex.vim in the directory that shows up
last in your
runtimepath (:set runtimepath? to check). This will
often be
either ~/.vim/after/syntax/tex.vim or
$VIM/vimfiles/after/syntax/tex.vim
The same effect can be obtained for files of a different
filetype, say html,
by putting the same lines in a file called html.vim in
the same location.
For more on the runtimepath, :he runtimepath.
For more on syntax highlighting, :he syntax
rate this tip

Life Changing

Helpful

Unfulfilling

<<Computing a sum of numbers in vim | editing databases with Vim/Perl/DBI >>

http://www.vim.org/tips/tip.php?tip_id=206 (1 of 2) [18/02/2004 14:48:46]

rate

Tip #206 - Highlight doubled word errors in text : vim online

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=206 (2 of 2) [18/02/2004 14:48:46]

SourceForge
Logo

Tip #207 - editing databases with Vim/Perl/DBI : vim online

not logged in (login)

Home
Search

Tip #207: editing databases with Vim/Perl/DBI


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 20/12, Viewed by 1505

created: January 31, 2002 7:29


author: Wolfgang Stroh

complexity: intermediate
as of Vim: 6.0

Perl's Data-Base-Independent (DBI) module provides


programming language level
access to a lot of databases.
Vim hosts an embedded Perl interpreter. So it is only a
matter of some key
strokes to interactively issue DB commands from within
Vim or to search, edit,
and replace database contents including retrieval and
storage. Of course
"create table" scripts can be worked upon in Vim as well
as storing recurring
patterns in Vim functions or Perl modules.
Prerequisites: Vim needs to be compiled with Perl
support enabled. See the
|if_perl.txt| manual page! The CPAN module DBI as well
as an appropriate
database driver has to be installed with Perl in order
to execute these Vim
commands:
" connect to perl's dbi module:
:perl use dbi;
" connect to the database:
:perl $dbh = dbi->connect(
"DBI:mysql:$DBNAME:$HOST",$USER,$PASSWORD,
{ raiseerror =>
1});
" perform a simple query:
:perl $result = $dbh->selectall_arrayref("show
tables;");
" insert the list of tables into the current buffer's
top:

http://www.vim.org/tips/tip.php?tip_id=207 (1 of 3) [18/02/2004 14:48:49]

Tip #207 - editing databases with Vim/Perl/DBI : vim online

:perl $curbuf->Append(0, map($_->[0], @{$result}));


In MySql the command "show tables;" results in a list of
table names. Inserted
into a Vim buffer this results in one line per table.
You can find more on my web page
http://members.chello.at/intelliware/dbEdit

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Highlight doubled word errors in text | Alter the display of buffers in the buffers menu >>

Additional Notes
mark@summersault.com, January 31, 2002 10:28
When I have a some SQL in vim that I want to see the
results of, I use this simple technique to send it to
Postgres:
1. Highlight the the SQL.
2. :!psql -d my _database
(for Postgres)
Vim will filter my lines through that command replace
them with the result set. When I'm done reviewing the
results, I use "u" to undo the change.
If I repeat this cycle, I can use use :CTRL-P to get
back the previous command to use, and instead of typing
it again.
For larger pieces of SQL, I put it in a file and use:
:!psql -d my_db -f %
to send the whole script to Postgres.
Wolfgang.Stroh@chello.at, February 1, 2002 2:41

http://www.vim.org/tips/tip.php?tip_id=207 (2 of 3) [18/02/2004 14:48:49]

Tip #207 - editing databases with Vim/Perl/DBI : vim online

Running an external process is the way Emacs handles


database queries as well.
Cursors and other database programming are not possible
this way.
Perl's DBI module provides the Vim user with full
interactive access to the
database in the same way as used by graphical user
interfaces and application
programs. Also the single process solution (editor +
database access in one
process) opens only a single permanent database
connection which is much
quicker and allows bigger transactions.
Similar motivations led to the programming language
Tcl: Why should one embed a
command interpreter into application programs? The
answer after many years of
Tcl is given by a lot of scripts weaving together all
kinds of programs as well
as Tcl's graphical user interface library Tk which is
also used for Perl.
For example Linux consists on one hand of many (text)
files, which can be
edited by Vim, and on the other hand of many complex
relations between them,
which can be handled effectively by a relational
database. Merging Vim's many
facilities with those of databases makes it possible to
build a simple yet
effective digital library with only the means at hand.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=207 (3 of 3) [18/02/2004 14:48:49]

SourceForge
Logo

Tip #208 - Alter the display of buffers in the buffers menu : vim online

not logged in (login)

Home
Search

Tip #208: Alter the display of buffers in the buffers menu


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 9/3, Viewed by 654

created: January 31, 2002 9:51


author: Roger Pilkey

complexity: basic
as of Vim: 6.0

If you use the buffers menu, here's where you can change
how the buffernames are displayed:
menu.vim, function s:BMMunge
OLD:

let name2 = name2 . ' (' . a:bnum . ')'

displays:
Site Help

.vimrc (1)
menu.vim (2)
NEW:

let name2 = '&' . a:bnum . '. ' . name2

displays
1. .vimrc
2. menu.vim
(with the 1 and the 2 underlined)
which is more useful, because you can (almost) always
pick the buffer you want with one keystroke, the
buffernumber, until you get to buffer 10 anyway.
Roger
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<editing databases with Vim/Perl/DBI | backtracking your movements in a file >>

Additional Notes
Anonymous, October 15, 2002 10:12

http://www.vim.org/tips/tip.php?tip_id=208 (1 of 2) [18/02/2004 14:48:51]

Tip #208 - Alter the display of buffers in the buffers menu : vim online

Great tip. I changed it so that if you have more than


9 buffers, you get the numbers for 1-9, and for the
others you can type the first letter of the filename
(which still may not be unique, of course, in which
case it will take more keystrokes to select it).
if a:bnum >= 10
let name2 = name2 . ' (' . a:bnum . ')'
else
let name2 = '&' . a:bnum . '. ' . name2
endif
Dana
rpilkey at magma.ca, June 24, 2003 9:24
This tip didn't work in the vim 6.2 menu.vim. Someone
added this line a couple of lines down (line 702):
let name = substitute(name, "&", "&&", "g")
so to make this tip work again, comment out this line.
Rog

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=208 (2 of 2) [18/02/2004 14:48:51]

SourceForge
Logo

Tip #209 - backtracking your movements in a file : vim online

not logged in (login)

Home
Search

Tip #209: backtracking your movements in a file


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 127/49, Viewed by 1849

created: February 1, 2002 10:35


author: vim_power

complexity: basic
as of Vim: 6.0

If you are jumping from one line to another a lot.


You may find the "Ctrl-o" command handy.
Usually u can set markers in a buffer to keep track of
your
movements.
but Ctrl-o makes it even easier. it takes you back
sequentially to
all your previous cursor locations in a buffer.
just press ctrl-o in normal mode and u will go to your
last cursor position.
Njoy
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Alter the display of buffers in the buffers menu | compiling the actual file with gcc >>

Additional Notes
rmadhu@cisco.com, February 1, 2002 12:20
Similarly Ctrl-I in the reverse order. Ctrl-I is also
as useful as Ctrl-o. Try it for yourself.
saisanthosh@yahoo.com, August 21, 2002 15:06
type u<char> bookmarks the current position.
'<char> to return to that
position
vim@campbell-lange.net, January 9, 2003 14:49

http://www.vim.org/tips/tip.php?tip_id=209 (1 of 2) [18/02/2004 14:48:53]

Type

Tip #209 - backtracking your movements in a file : vim online

This is a wonderful tip. Of course you can see the jump


list with :jump, and set markers to allow one to jump
between files (not just within a buffer) with '[A-Z],
but this is tip is great because it just follows your
history. Wonderful!
anonymous, February 13, 2003 22:36
Perhaps a goofy comment, but I use the mnemonic device
of jumping "In" and "Out" of the jump list (<c-i>, <co>).
yuchung at ma il dot c om, June 1, 2003 13:51
sir, u (and vim) changed my life ... horey!!!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=209 (2 of 2) [18/02/2004 14:48:53]

SourceForge
Logo

Tip #210 - compiling the actual file with gcc : vim online

not logged in (login)

Home
Search

Tip #210: compiling the actual file with gcc


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 50/30, Viewed by 1808

created: February 3, 2002 6:37


author: elian

complexity: basic
as of Vim: 6.0

if you use set makeprg=gcc\ -o\ %<\ % in your .vimrc,


and your actual file is file.c, then :make will compile
file.c with the output file. (gcc file.c -o file).
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<backtracking your movements in a file | Rotate color themes >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=210 [18/02/2004 14:48:56]

SourceForge
Logo

Tip #211 - Rotate color themes : vim online

not logged in (login)

Home
Search

Tip #211: Rotate color themes


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 46/22, Viewed by 2259

created: February 6, 2002 4:48


author: Mohit Kalra (kmohit@in.ibm.com)

complexity: intermediate
as of Vim: 6.0

This tip is for those who like to change their vim color themes pretty
often. I like different themes just for a change in my work environment.
achieve this just add the following to your .vimrc or _vimrc file.

To

let themeindex=0
function! RotateColorTheme()
let y = -1
while y == -1
let colorstring =
"#blue.vim#elflord.vim#evening.vim#koehler.vim#murphy.vim#pablo.vim#ron.vim#"
let x = match(colorstring,"#",g:themeindex)
let y = match(colorstring,"#",x+1)
let g:themeindex = x+1
":echo x y g:themeindex
if y == -1
let g:themeindex = 0
else
let themestring = strpart(colorstring,x+1,y-x-1)
echo("Setting Theme to-> ".themestring)
return ":so $VIMRUNTIME/colors/".themestring
endif
endwhile
endfunction
Change the value of colorstring above by changing the line
let colorstring =
"#blue.vim#elflord.vim#evening.vim#koehler.vim#murphy.vim#pablo.vim#ron.vim#"
You can add your favorite color themes in this string so that you can rotate
between them. Just make sure that any string that you add is in between the
# as shown above. Just follow the format above and things will work.
Then assign a key to roate the theme.
map <F8> :execute RotateColorTheme()
Dunno if there are better ways to do the same.
wrote the above.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<compiling the actual file with gcc | Setting file attributes without reloading a buffer >>

Additional Notes
Anonymous, February 7, 2002 1:15

http://www.vim.org/tips/tip.php?tip_id=211 (1 of 2) [18/02/2004 14:48:58]

I just did a "help eval" and

Tip #211 - Rotate color themes : vim online

note that its usually much better to put things like this
in your $HOME/vimfiles or $HOME/.vim directory instead of
or ~/_vimrc.
that makes the vimrc nice and simple and also portable to
of vim which might not have some of the things which this
instance.

as a script file
in the ~/.vimrc
earlier versions
function uses for

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=211 (2 of 2) [18/02/2004 14:48:58]

SourceForge
Logo

Tip #212 - Setting file attributes without reloading a buffer : vim online

not logged in (login)

Home
Search

Tip #212: Setting file attributes without reloading a buffer


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/8, Viewed by 699

created: February 7, 2002 6:14


author: Max Ischenko

complexity: intermediate
as of Vim: 6.0

While creating scripts and others executable files with


Vim it is needed to set UNIX executable bit on the file.
You can do this from inside Vim with :!chmod a+x %. The
% represents current buffer's filename.
The problem is that Vim will notice attribute changes
and prompt you to reload a file. If you do this, your
undo history for the file will be lost.
The following function facilitate changing executable
attributes without reloading a buffer.
Thanks to Bram for the algorithm for this function.
fun! SetExecutableBit()
let fname = expand("%:p")
:checktime
exec "au FileChangedShell " . fname . " :echo"
:silent !chmod a+x %
:checktime
exec "au! FileChangedShell " . fname
endfun
" Create an EX command that will call the function.
command -nargs=0 Xbit call SetExecutableBit()
Now you can type :Xbit to make the file executable!
rate this tip

Life Changing

Helpful

<<Rotate color themes | delet all lines containt TXT >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=212 (1 of 2) [18/02/2004 14:49:01]

Unfulfilling

rate

Tip #212 - Setting file attributes without reloading a buffer : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=212 (2 of 2) [18/02/2004 14:49:01]

SourceForge
Logo

Tip #213 - delet all lines containt TXT : vim online

not logged in (login)

Home
Search

Tip #213: delet all lines containt TXT


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 26/32, Viewed by 1023

created: February 10, 2002 10:43


author: tarjei

complexity: basic
as of Vim: 5.7

I needed this one when I was editing an ldif file:


I needed to delete all lines containing "profile":
:g/profile/d
very handydandy

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Setting file attributes without reloading a buffer | Current buffer based menus >>

Additional Notes
seenutn@cdotb.ernet.in, February 18, 2002 22:53
Can I get this tips in my INBOX??
Regards,
Seenu.
pdwalker@usa.net, August 17, 2003 22:36
use g/^$/d to delete all the blank lines in your file.
(I think there is an easier/faster way to do this, but
I forget how)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=213 [18/02/2004 14:49:04]

SourceForge
Logo

Tip #214 - Current buffer based menus : vim online

not logged in (login)

Home
Search

Tip #214: Current buffer based menus


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/2, Viewed by 661

created: February 14, 2002 3:45


author: Tomas Zellerin

complexity: intermediate
as of Vim: 6.0

If you have different menus for different filetypes, and


you want to have only the menu relevant to current
buffer displayed, you can use this approach:
in .vimrc:
au BufEnter * if exists('b:BuffEnter')|exec
b:BuffEnter|endif
au BufLeave * if exists('b:BuffEnter')|exec
b:BuffLeave|endif
In appropriate ftplugin/?.vim, there are assigned
commands to create or destroy the menus - here typed in
directly, may be of course call to a menu-generating
function or whatever.
let b:BuffEnter='amenu C.added ...'
let b:BuffLeave='unmenu! C|unmenu C'

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<delet all lines containt TXT | Edit configuration files for a filetype >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=214 [18/02/2004 14:49:06]

SourceForge
Logo

Tip #215 - Edit configuration files for a filetype : vim online

not logged in (login)

Home
Search

Tip #215: Edit configuration files for a filetype


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/7, Viewed by 1172

created: February 14, 2002 8:02


author: Mark A. Hillebrand

complexity: intermediate
as of Vim: 6.0

When you open a file, vim may load several scripts to


customize itself for editing the file type the file is
associated with (for example a file "test.c" is
associated with the filetype "c").
Such configurations include the setting of syntax
highlighting colors (:help syntax) and support for
indentation (:help filetype-indent-on).
When you start to override these files for yourself, it
can sometimes be confusing, which file sets a specific
option.
The following function can be used, to edit the
configuration files which are associated with a specific
filename. It open a buffer for all files which get
loaded.
If I invoke it with ':call Edit_ft_conf("test.c")', for
example, I end up with the following buffers / windows:
1 a
"[No File]"
line 1
2 a
"test.c"
line 1
3 a= "/usr/local/share/vim/vim60/syntax/c.vim" line
1
4 a
"~/.vim/after/syntax/c.vim"
line 1
5 #a= "/usr/local/share/vim/vim60/indent/c.vim" line
1
6 %a= "/usr/local/share/vim/vim60/ftplugin/c.vim"
line 1
Here comes the function:
" Edit filetype configuration files
" Usage: ':call Edit_ft_conf("file")'
" Purpose: open all scripts which get loaded implicitly
by opening "file"
"
(syntax highlighting, indentation, filetype plugins,
..)
"
The order of windows reflects the order of script
loading (but "file" is
"
the topmost window)

http://www.vim.org/tips/tip.php?tip_id=215 (1 of 3) [18/02/2004 14:49:08]

Tip #215 - Edit configuration files for a filetype : vim online

fun! Edit_ft_conf(name)
" we may not do this with a loaded file, since this
won't trigger the
" configuration file loading as desired.
" try calling with 'call
Edit_ft_conf("nonexistingfile.<EXT>")' if this
" gives you troubles
if bufexists(a:name) && bufloaded(a:name)
echo "!Attention: buffer for " . a:name . " is
loaded, unload first."
return
endif
" split-open the file with verbose set, grab the
output into a register
" (without clobbering)
let safereg = @u
redir @u " redirect command output to register @u
exec "silent 2verbose split " . a:name
" verbose level 2 suffices to catch all scripts
which get opened
redir END
" Parse register @u, looking for smth like:
'sourcing"/usr/local/share/vim/vim60/syntax/c.vim"'
let pos = 0
let regexp = 'sourcing "[^"]\+"'
while match(@u,regexp,pos) >= 0
let file = matchstr(@u,regexp,pos)
let pos = matchend (@u,regexp,pos)
let file = strpart(file,10,strlen(file)-11)
exec "silent below split " . file
endwhile
" restore the register
let @u = safereg
endfun

rate this tip

Life Changing

Helpful

Unfulfilling

<<Current buffer based menus | calculate equations from within vim >>

Additional Notes
billG@megasoft.com, February 15, 2002 10:55
this is supposed to be a tip section.
so submit a TIP not a PhD thesis

http://www.vim.org/tips/tip.php?tip_id=215 (2 of 3) [18/02/2004 14:49:08]

rate

Tip #215 - Edit configuration files for a filetype : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=215 (3 of 3) [18/02/2004 14:49:08]

SourceForge
Logo

Tip #216 - calculate equations from within vim : vim online

not logged in (login)

Home
Search

Tip #216: calculate equations from within vim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/7, Viewed by 1399

created: February 16, 2002 13:07


author: scotch2

complexity: basic
as of Vim: 5.7

The following map and function calculates equations


using the program 'bc' (found on most linux systems,
available for most systems). Visually select the
equation you want to calculate, then hit ;bc - if the
selection ends with an '=' sign, the answer will be
appended after the equal, otherwise, the answer is
echoed as a message. The code to put in a vimrc and
source is at the end.
Equations can span multiple lines, and the full bc
syntax is probably supported. Additionally, sin (), cos
(), etc, are transformed into the names used by bc (s ()
c (), etc).
Here are some example lines:
2 * sqrt (2) =
3 * (2 - 1) + 4.0 ^ 6 =
4 / 3 =
3 +
4 2 * (1 / (3 + 2)) =
define rad (x) {
return (x / 180) * 4 * atan (1)
}
cos (rad (45)) =
Select each of these in turn (continguous non-blank
lines, and hit ;bc for each), and this is what you get:
2 * sqrt (2) = 2.82842712474619009760
3 * (2 - 1) + 4.0 ^ 6 = 4099.000000
4 / 3 = 1.33333333333333333333

http://www.vim.org/tips/tip.php?tip_id=216 (1 of 5) [18/02/2004 14:49:11]

Tip #216 - calculate equations from within vim : vim online

3 +
4 2 * (1 / (3 + 2)) = 6.60000000000000000000
define rad (x) {
return (x / 180) * 4 * atan (1)
}
cos (rad (45)) = .70710678118654752440
Fun, no?
file:

Here is the code you need to put in your vimrc

vnoremap ;bc "ey:call CalcBC()<CR>


function! CalcBC()
let has_equal = 0
" remove newlines and trailing spaces
let @e = substitute (@e, "\n", "", "g")
let @e = substitute (@e, '\s*$', "", "g")
" if we end with an equal, strip, and remember for
output
if @e =~ "=$"
let @e = substitute (@e, '=$', "", "")
let has_equal = 1
endif
" sub common func names for bc equivalent
let @e = substitute (@e, '\csin\s*(', "s (", "")
let @e = substitute (@e, '\ccos\s*(', "c (", "")
let @e = substitute (@e, '\catan\s*(', "a (", "")
let @e = substitute (@e, "\cln\s*(", "l (", "")
" escape chars for shell
let @e = escape (@e, '*()')
" run bc, strip newline
let answer = substitute (system ("echo " . @e . " \| bc l"), "\n", "", "")
" append answer or echo
if has_equal == 1
normal `>
exec "normal a" . answer
else
echo "answer = " . answer
endif
endfunction

http://www.vim.org/tips/tip.php?tip_id=216 (2 of 5) [18/02/2004 14:49:11]

Tip #216 - calculate equations from within vim : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Edit configuration files for a filetype | Translate &#nnn; in html source to readable ascii >>

Additional Notes
Anonymous, February 16, 2002 15:22
PLEASE do not give such things as tips! make this as a
script and put this in the scripts section. starting
from version 6.0 (which is hopefully what most people
are using),
vim provides the ability to have "plugins". (:he
plugin). imho, its bad practice to keep extending your
~/.vimrc. the rc file should be used for tweaking vim's
settings and such.
it is not a good place to put functions etc. this make
the .vimrc very bloated.
also it ofcourse makes it just a bit harder for users
of vim.sf.net :) now one has to cut and paste the file
into a new file, save it as a file and in most browsers
strip trailing
blanks and stuff which might screw the maps. and if you
care about aesthetics, then you will often have to
repair the indentation. (my browser makes this tip not
have absolutely
any indentation). when you provide a simple
downloadable file, it becomes plug-and-play.
btw, nice tip!
i am not quite sure what others think of this.
personally i prefer functions etc to be in the scripts
section.
tsurban@attbi.com, February 16, 2002 15:56
Good points - I've uploaded it as vimscript #219 - with
a fix that escapes ";" chars.

Larry Clapp <vim@theclapp.org>, February 20, 2002 8:44

http://www.vim.org/tips/tip.php?tip_id=216 (3 of 5) [18/02/2004 14:49:11]

Tip #216 - calculate equations from within vim : vim online

See also ":help quote=" about the expression


register. E.g., in command mode, type
"=10+15<enter>p
(where <enter> means press the Enter key) will put 25
into your file at the current cursor position. See
":help functions" for the list of functions Vim
supports (no math functions).
Anonymous, February 21, 2002 3:23
good idea
I downloaded the plugin, but I have troubles on windows
2000 with cygnus 'bc'.
The DOS echo command appends a 'ctrl-M' character,
about which bc complains and refuses to calc.
Also the backslashes (to mask parenthesis etc.) are
damaging the command for bc.
Thomas
Anonymous, February 21, 2002 4:11
I found a bc.exe which does at least some of the
calculations on windows2000
(http://unxutils.sourceforge.net/).
Thomas
Anonymous, February 25, 2002 7:36
Adaptions for Windows 2000 (and probably NT) using
bc.exe from sourgeforge:
change the lines in the script as:
" escape chars for shell
"not for NT: let @e = escape (@e, '*();&><|')
" windows echo must escape the caret with the caret,
repeat if piped
" backslashes needed to supress
evaluation within vim
let @e = substitute (@e, "\\\^", "\\\^\\\^\\\^\\\^",
"")
Thomas
Add Note

http://www.vim.org/tips/tip.php?tip_id=216 (4 of 5) [18/02/2004 14:49:11]

Tip #216 - calculate equations from within vim : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=216 (5 of 5) [18/02/2004 14:49:11]

SourceForge
Logo

Tip #217 - Translate &#nnn; in html source to readable ascii : vim online

not logged in (login)

Home
Search

Tip #217: Translate &#nnn; in html source to readable ascii


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/2, Viewed by 641

created: February 21, 2002 12:39


author: Larry Clapp
I found a website
obfuscate some of
instead of normal
Vim (in Opera you
viewing program),
it readable.
let n = 32
while n < 127
if n == 38
silent!
elseif n ==
silent!
else
silent!
'/g'
endif
let n = n +
endwhile

complexity: intermediate
as of Vim: 5.7

*cough*Tivoli.com*cough* that likes to


its help file web pages using &#nnn;
ascii. If you load the source with
can just designate Vim as your source
you can :so the following code to make

exec '%s/&/\&/g'
47
exec '%s///\//g'
exec '%s/&#' . n . ';/' . nr2char(n) .

Disclaimer: I hacked this together in about 10 minutes


(or possibly longer :). It worked suitably for the
website I wrote it for (or possibly "against" :). Your
Milage May Vary.
See :help eval, :help silent, :help exec, :help :s
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<calculate equations from within vim | Check for comments, independent of the filetype >>

Additional Notes
Larry, again, February 21, 2002 12:53

http://www.vim.org/tips/tip.php?tip_id=217 (1 of 2) [18/02/2004 14:49:13]

Tip #217 - Translate &#nnn; in html source to readable ascii : vim online

This tip would benefit from a "preview" function. I'll


upload the code as a script, instead. See vimscript
#223.
Larry, again <vim at theclapp.org>, February 21, 2002 14:45
"silent!" requires vim 6.0.
Larry. :(

Yet Another Oops from

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=217 (2 of 2) [18/02/2004 14:49:13]

SourceForge
Logo

Tip #218 - Check for comments, independent of the filetype : vim online

not logged in (login)

Home
Search

Tip #218: Check for comments, independent of the filetype


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 15/5, Viewed by 620

created: February 22, 2002 8:52


author: Mark A. Hillebrand

complexity: advanced
as of Vim: 6.0

For some scripts it might be useful to detect, whether a


specific position in a buffer is inside
of a comment or not. Syntax highlighting can save us the
work for parsing the comments ourselves.
The command
:echo synIDattr(synIDtrans(synID(line("."), col("."),
0)), "name")
echoes the group used for *highlighting* the character
at the current cursor position, see ':help
synIDtrans()'. It will usually be "Comment" if the
cursor is inside of a comment, so
synIDattr(synIDtrans(synID(line("."), col("."), 0)),
"name") == "Comment"
detects, independent of the filetype (which have their
own group 'names' for comments), if the cursor is inside
a comment or not.
The expression
synIDattr(synIDtrans(synID(line("."), col("."), 0)),
"name") =~ 'Comment\|Constant\|PreProc'
will detect additionally, if the cursor is inside of a
string or some preprocessor statement.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Translate &#nnn; in html source to readable ascii | make from command line, open vim on errors >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=218 (1 of 2) [18/02/2004 14:49:18]

Tip #218 - Check for comments, independent of the filetype : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=218 (2 of 2) [18/02/2004 14:49:18]

SourceForge
Logo

Tip #219 - make from command line, open vim on errors : vim online

not logged in (login)

Home
Search

Tip #219: make from command line, open vim on errors


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 7/4, Viewed by 1162

created: February 22, 2002 14:27


author: scott urban

complexity: basic
as of Vim: 5.7

A simple alias (*csh) or shell function (bash) will let


you run make from your shell, then automatically open
vim or gvim on the errors (if there were any):
csh or tcsh:
alias Make 'make \!* |& tee make.errors || gvim -q
make.errors -c :copen'
bash:
Make () { command make "$@" |& tee make.errors || gvim q make.errors -c :copen ; }
If you use vanilla sh or ksh or even cmd.exe, you can
probably do the same - add a not if you have ideas.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Check for comments, independent of the filetype | Regexp: Match every word except 'foo' >>

Additional Notes
Anonymous, February 22, 2002 15:57
err,
:%s/add a not/add a note/
Anonymous, February 25, 2002 13:20
faster (is there a tip for this yet?):
:%s/add a not/&e/
davef@tetsubo.com, February 27, 2002 14:33
http://www.vim.org/tips/tip.php?tip_id=219 (1 of 2) [18/02/2004 14:49:24]

Tip #219 - make from command line, open vim on errors : vim online

dang. That's a sweet comment. Someone should add this


as a tip (%s/not/&e/)
:-), September 12, 2002 15:45
%s/ot/&e/
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=219 (2 of 2) [18/02/2004 14:49:24]

SourceForge
Logo

Tip #220 - Regexp: Match every word except 'foo' : vim online

not logged in (login)

Home
Search

Tip #220: Regexp: Match every word except 'foo'


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 45/22, Viewed by 1258

created: February 25, 2002 22:28


author: Michael Geddes

complexity: intermediate
as of Vim: 6.0

This is a regular expression that matches all words


except 'foo'
\v<(foo>)@!\k+>
\v Very magic
< Start-of-word
(Foo>) The atom 'Foo' followed by end-of-word
@! Match (with zero length) when the previous atom
doesn't
match.
\k+ Match one or more Keywords
> Match end-of-word.
This is a kool example of using \@! in the middle of a
regexp.
The non-magic version is:
\<\(foo\>\)\@!\k\+\>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<make from command line, open vim on errors | indenting "throws" in java >>

Additional Notes
david@tvis.co.uk, March 30, 2002 10:04
Very good explanation of difficult to grasp features,
zero-width matching, keyword matching and very magic.
very magic \v appears to save a lot of backslashing!!!
ben.leighton@wizardis.com.au, May 2, 2002 17:08

http://www.vim.org/tips/tip.php?tip_id=220 (1 of 2) [18/02/2004 14:49:29]

Tip #220 - Regexp: Match every word except 'foo' : vim online

How many times have I wanted to exclude somestring from


my search.
Now (I think) Ill be able to use this regexp or a
variation.
thanks heaps.
jeromeguigue@yahoo.fr, August 29, 2003 9:20
Well... I have been looking a part of the last night
how to search 'everything but this patern' with the
regexpr with no succes ( /\(patern\)\zs[^\1] , to give
an example, doesnt work).
Why must it so complicated?
Why are regexpr so irregular?
We will never know... Thanks a lot anway.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=220 (2 of 2) [18/02/2004 14:49:29]

SourceForge
Logo

Tip #221 - indenting "throws" in java : vim online

not logged in (login)

Home
Search

Tip #221: indenting "throws" in java


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 13/7, Viewed by 1368

created: February 26, 2002 13:35


author: Alexey Marinichev

complexity: intermediate
as of Vim: 6.0

I want to indent java files like this:


int x(int y, int z)
throws Exception
{
[...]
return something;
}
By default vim will properly indent "throws" line, but
following "{" will not be deindented back to the method
declaration.
The following indentexpr does the trick:
let &indentexpr='getline(v:lnum)=~"^\\s*{" &&
getline(v:lnum-1)=~"^\\s*throws\\s" ? cindent(v:lnum)&sw : cindent(v:lnum)'
It just checks that the current line starts with "{" and
the previous line starts with "throws" and if that is
the case, it subtracts one shiftwidth from the number
returned by cindent.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Regexp: Match every word except 'foo' | Building vim with color on HP-UX >>

Additional Notes
Alexey Marinichev, March 4, 2002 12:03
Patch 6.1a.026 adds a more general solution to java
indent file.
jmcnair@guarded.net, November 13, 2003 10:35

http://www.vim.org/tips/tip.php?tip_id=221 (1 of 2) [18/02/2004 14:49:32]

Tip #221 - indenting "throws" in java : vim online

Thank you much for the tip. I have a function key


mapping to reformat the entire file, fixing tab-space
discrepancies, wrong indentation, trailing whitespace,
etc. Needless to say, the default indentation screws
up my methods where 'throws' didn't fit. This is
wonderful!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=221 (2 of 2) [18/02/2004 14:49:32]

SourceForge
Logo

Tip #222 - Building vim with color on HP-UX : vim online

not logged in (login)

Home
Search

Tip #222: Building vim with color on HP-UX


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 29/17, Viewed by 1199

created: February 28, 2002 11:48


author: Gary Johnson

complexity: intermediate
as of Vim: 5.7

Following the normal steps of running "./configure" and


"make" to build
vim on an HP-UX 10.20 will result in vim being linked
with the termlib
library. This library does not support certain termcap
capability
codes, such as the "Co" code used to query the number of
colors
supported by the terminal. Consequently, vim will not
display colors
when used with a color terminal such as a color xterm.
One solution to this is to run the configure script with
the
"--with-tlib=curses" option, like this:
./configure --with-tlib=curses
This will cause vim to be linked with the HP-UX curses
library, which
does support the color termcap capability codes.
Note that the xterm that comes standard with HP-UX 10.20
does not
display color character attributes. To see colors when
running vim in a
terminal window, you will also need to install a color
terminal emulator
such as a recent xterm.
rate this tip

Life Changing

Helpful

<<indenting "throws" in java | Reverse Selected Text >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=222 (1 of 2) [18/02/2004 14:49:34]

Unfulfilling

rate

Tip #222 - Building vim with color on HP-UX : vim online

jerome.bosch@netcourrier.com, September 11, 2002 6:35


I'm running HP B.11.00 A on my machine and launch vim
from a dtterm, after reinstalling vim61 it still
doesn't work. Any idea or extra tips?
timlewis_atlanta@yahoo.removethisbitunlessyouareaspammer.com,
September 8, 2003 20:02

Color vim (6.2) with HP-UX and Putty :


Compile vim with this option:
./configure --with-tlib=curses
In your Putty settings go to "Connection" and set the
"Terminal-type string" to "dtterm".
Edit your .profile, and add
export TERM=dtterm
Edit your .vimrc and add the line
syntax on
You should now be have full color editing in vim.
philippe.andro@eau-loire-bretagne.fr, October 16, 2003 5:42
Hello,
I had the same problem with aix 4.3.3 maintenance level
11 and the tip works!!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=222 (2 of 2) [18/02/2004 14:49:34]

SourceForge
Logo

Tip #223 - Reverse Selected Text : vim online

not logged in (login)

Home
Search

Tip #223: Reverse Selected Text


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 8/5, Viewed by 1072

created: March 11, 2002 21:36


author: scott urban

complexity: basic
as of Vim: 5.7

Suppose you want to reverse some text - I don't know why


you would want to - maybe you're dyslexic. Anyway, I
had a need, so this mapping will reverse visually
selected text. Put the mapping in your vimrc or
otherwise source it, then visually select the word or
words, and hit ;rv - really only works with selections
on one line:
vnoremap ;rv c<C-O>:set revins<cr><C-R>"<esc>:set
norevins<cr>

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Building vim with color on HP-UX | Shifting blocks visually >>

Additional Notes
cec@NgrOyphSon.gPsfAc.nMasa.gov, March 12, 2002 12:49
Interesting idea, but it will only work for those whose
vim has the
+rightleft option. For those who don't have such a
vim, use "ma" to
(mark a) and move the cursor to the last line to be
affected, and:
\fr: will reverse the order of lines (vertical mirror)
nmap \fr
:set lz<CR>o<Esc>mz'aO<Esc>ma:'a+1,'z-1g/^/m
'a<CR>'addma'zdd:set nolz<CR>
\fR: will mirror image the lines (horizontal mirror)
nmap \fR
:set
lz<CR>o<Esc>mzkO<Esc>maj:s/./&\r/g<CR>:'a+1,'z-1g/^/m
'a<CR>:'a+1,'z-1j!<CR>'add'zddk:set nolz<CR>
http://www.vim.org/tips/tip.php?tip_id=223 (1 of 2) [18/02/2004 14:49:37]

Tip #223 - Reverse Selected Text : vim online

Regards,
Charles Campbell

Thomas.Ramming@gmx.de, March 24, 2002 23:24


I really like cryptic commands.
It might be easier to get a full/fitting powered vim ?
Thomas
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=223 (2 of 2) [18/02/2004 14:49:37]

SourceForge
Logo

Tip #224 - Shifting blocks visually : vim online

not logged in (login)

Home
Search

Tip #224: Shifting blocks visually


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 104/58, Viewed by 2294

created: March 13, 2002 7:22


author: niboan

complexity: basic
as of Vim: 5.7

I use the < and > commands on blocks a lot, and it has
always annoyed me that if you want to shift more than
one 'shiftwidth', you have count how many 'shiftwidth's
you want to enter the '[count]>', or restore the
selection with "gv". So I've cooked up two mappings that
come in very handy:
:vnoremap < <gv
:vnoremap > >gv
These mappings will reselect the block after shifting,
so you'll just have to select a block, press < or > as
many times as you like, and press <ESC> when you're done
to unselect the block.
I know it's not rocket science, but it sure has helped
me a lot.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Reverse Selected Text | vim can interact with xdvi >>

Additional Notes
Anonymous, March 13, 2002 9:35
I use "." (repeat previous command) to shift the block
again
Anonymous, March 18, 2002 19:44
"." is nice, but it only moves in the same
direction. It's not the same thing as the tip.
Anonymous, March 19, 2002 1:46

http://www.vim.org/tips/tip.php?tip_id=224 (1 of 2) [18/02/2004 14:49:42]

Tip #224 - Shifting blocks visually : vim online

Ah, but 'u' will undo the last action.


So do the shift, '.' to repeat in the same direction,
'u' to essentially shift back in the other if you go
too far.
I actually prefer '=' after setting indentprg and
options appropriately.
Anonymous, May 7, 2003 14:26
Please note that if you use this mapping, that you
can't just cut-and-paste it off this web page, because
that results in a space after the mapping. The space
will cause all sorts of strange behavior (such as the
visual selection changing shape as you shift). Other
than that, it works great.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=224 (2 of 2) [18/02/2004 14:49:42]

SourceForge
Logo

Tip #225 - vim can interact with xdvi : vim online

not logged in (login)

Home
Search

Tip #225: vim can interact with xdvi


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 98/31, Viewed by 2306

created: March 20, 2002 11:48


author: Dimitri Antoniou

complexity: basic
as of Vim: 6.0

vim can interact with the tricks that the latest xdvi
does:
* If one clicks at some place in xdvi, vim automatically
jumps to the
corresponding line in the LaTeX source file ("reverse
search")
* Also, from inside vim, one can jump to the
corresponding line in xdvi
which becomes highlighted ("forward search").
Here is how to do it:
* Reverse search:
We start a vim server by: vim --servername xdvi
We start xdvi(k) on file.dvi by:
xdvik -editor "vim --servername xdvi --remote +%l
%f" file.dvi
At the desired location in xdvi, we press:
<ctrl><left_mouse>
Then, vim will jump to the corresponding line in the
source file.
* Forward search:
Inside vim, we type, for example, _g which is the
following mapping:
(the following should be a single line)
map _g :execute "!xdvik -name xdvi -sourceposition "
. line(".") . expand("%") . " " . expand("%:r") . ".dvi"
<cr><cr>
[the command to go to the point of xdvi that
corresponds to line, eg, 77
of the source file is (no space after 77)
xdvik -name xdvi -sourceposition 77file.tex
file.dvi ]

http://www.vim.org/tips/tip.php?tip_id=225 (1 of 3) [18/02/2004 14:49:45]

Tip #225 - vim can interact with xdvi : vim online

For the above to work one needs:


1) A recent version of xdvi or xdvik (>22.39 I think)
2) The package srcltx.sty and \usepackage{srcltx}
(which should be
commented out when one finishes and is ready for
printing etc).
3) Our version of vim should have been compiled with
+clientserver
(however, my vim doesn't have it and still works,
so try it before
Bram finds out what is happening and fixes it)

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Shifting blocks visually | Edit file under cursor after a horizontal split >>

Additional Notes
benji@member.AMS.org, March 20, 2002 20:09
If you use the MikTeX distribution on Win32, you
can play the same game with vim and yap.
I use the following with vim 6.0 and (old) MikTeX 1.20b
.
From my vim script for tex files:
execute '!start yap -1 -s' line(".") . expand("%:t")
expand("%:p:r")
(Of course, I have a :map and :menu to do this.)
expands to something like
!start yap -1 -s 1353foo.tex c:\path\to\foo
In yap, from the View/Options panel, choose the
"Inverse Search" tab and enter
D:\vim\vim60\gvim.exe --remote +%l %f
in the "Command line" box. This can probably be
improved: doesn't the installer put a .bat file
somewhere? ...
Mark A. Hillebrand, March 21, 2002 4:02

http://www.vim.org/tips/tip.php?tip_id=225 (2 of 3) [18/02/2004 14:49:45]

This

Tip #225 - vim can interact with xdvi : vim online

The following mapping may also be useful (in one line):


map _g :exe 'silent !xdvi -editor "vim --servername ' .
v:servername . ' --remote +\%l \%f" -sourceposition ' .
line (".") . expand("%") . " " . expand("%:r") . ".dvi
&" \| redraw!<cr>
It starts up an xdvi (if necessary) and does forward
search.
Reverse search will jump to the location in the same
vim.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=225 (3 of 3) [18/02/2004 14:49:45]

SourceForge
Logo

Tip #226 - Edit file under cursor after a horizontal split : vim online

not logged in (login)

Home
Search

Tip #226: Edit file under cursor after a horizontal split


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/6, Viewed by 1133

created: March 23, 2002 18:24


author: Shakti

complexity: basic
as of Vim: 6.0

I use the command 'gf' quite often. But with this command the current buffer is
hidden. To avoid that I use the following mapping :
map gw <Esc>:sp %<CR> gf
With this mapping the file under the cursor is opened after a horizontal split.
rate this tip

Life Changing

<<vim can interact with xdvi | Power of :g >>

Additional Notes
shakti@ti.com, March 23, 2002 22:12

http://www.vim.org/tips/tip.php?tip_id=226 (1 of 2) [18/02/2004 14:49:47]

Helpful

Unfulfilling

rate

Tip #226 - Edit file under cursor after a horizontal split : vim online

The same operation can be done more reliably by


:function! SplitOpen()
:let v:errmsg = ""
:normal gf
:if v:errmsg == ""
:sbp
:endif
:endf
map gw <Esc>:call SplitOpen()<CR>
-Shakti
garyjohn@spk.agilent.com, March 24, 2002 21:38
Or even more simply by "CTRL-W f".
milan@ucw.cz, July 19, 2002 7:29
Yes, CTRL-W f does this, bu with the original idea you have a chance to make a
little change, for example I prefer vertical split very often, but there is no
hotkey for it in vim, so I use this idea and map:
:nn ^W^F :vsplit<CR>gf
Milan
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=226 (2 of 2) [18/02/2004 14:49:47]

SourceForge
Logo

Tip #227 - Power of :g : vim online

not logged in (login)

Home
Search

Tip #227: Power of :g


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 345/138, Viewed by 9639

created: March 24, 2002 3:15


author: Arun Easi

complexity: intermediate
as of Vim: 5.7

:g is something very old and which is very powerful. I


just wanted to illustrate the use of it
with some examples. Hope, it will be useful for someone.
Brief explanation for ":g"
------------------------Syntax is:
:[range]:g/<pattern>/[cmd]
You can think the working as, for the range (default
whole file), execute
the colon command(ex) "cmd" for the lines matching
<pattern>. Also, for all
lines that matched the pattern, "." is set to that
particular line (for
certain commands if line is not specified "." (current
line) is assumed).
Some examples
------------Display context (5 lines) for all occurences of a
pattern
:g/<pattern>/z#.5
:g/<pattern>/z#.5|echo "=========="
<< same as first, but with some beautification >>
Delete all lines matching a pattern
:g/<pattern>/d
Delete all blank lines (just an example for above)
:g/^\s*$/d
Double space the file
:g/^/pu =\"\n\"
:g/^/pu _
<< the above one also works >>
Copy all lines matching a pattern to end of file
:g/<pattern>/t$
Yank all lines matching a pattern to register 'a'
0"ay0:g/<pattern>/y A
Increment the number items from current line to end-of-

http://www.vim.org/tips/tip.php?tip_id=227 (1 of 6) [18/02/2004 14:49:49]

Tip #227 - Power of :g : vim online

document by one
:.,$g/^\d/exe "normal! \<c-a>"
Comment (C) lines containing "DEBUG" statements
g/^\s*DEBUG/exe "norm! I/* \<Esc>A */\<Esc>"
A Reverse lookup for records
(eg: An address book, with Name on start-of-line and
fields after a space)
:g/<patern>?^\w?p
"if only name is
interested
:g/<patern>/ka|?^\w?p|'ap
"if name and the
lookup-line is interested
:g/<patern>/?^\w?|+,/^[^ ]/-1p "if entire record is
interested
Reverse a file (just to show the power of 'g')
:g/^/m0
Foot note 1: use :v to negate the search pattern
Foot note 2: Some explanation of commonly used commands
with :g
:2,8co15 => Copy lines 2 through 8 after line 15
:4,15t$ => Copy linesa 4 through 15 towards end of
document (t == co)
:-t$ => Copy previous line to end of document
:m0 => Move current line to the top of the
document
:.,+3m$-1 => Move current line through cur-line+3 to the
last but one line
of the document
Foot note 3: Commands used with :g are ex commands, so a
help search should
be,
:help :<help-topic>
eg. :help :k
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Edit file under cursor after a horizontal split | Deleting nested reply threads in emails >>

Additional Notes
david@tvis.co.uk, March 28, 2002 7:10

http://www.vim.org/tips/tip.php?tip_id=227 (2 of 6) [18/02/2004 14:49:49]

Tip #227 - Power of :g : vim online

Thanx Karma for extending my g// knowledge


Here's a very useful g// for day to day use
:'a,'bg/pattern/s/pattern2/string3/gi
zzapper
Hal Atherton, April 23, 2002 10:12
g WITH CONFIRM c
Here's something very curious:
:%s/foo/bar/gc
is of course a substitution effective for the entire
file
with confirm on each occurrence of "foo"
with the option of quitting at any point.
However, using something similar,
:g/foo/s//bar/gc
using the global g to effect the entire file -does NOT allow quitting at any point
(even with the use of <ESC>).
If there are hundreds of "foo" -- it's an important
fine point...
Invite further comments...
Arun Easi, April 23, 2002 23:33
g/foo/s//bar/gc => run the command s//bar/gc for each
of the line
matching foo. It is like running multiple "s//"
commands (Hence
you have to press q for each of the invocation). The
g in "s///gc" does not imply entire file, it just
implies all occurence
on a line (or else, it would have substituted only the
first)
dyang@entropia.com, May 30, 2002 9:04
Here is one that deletes every other line (adjusting
double spaced files):
:g/.*/norm jdd
pagaltzis()gmx_de, August 6, 2002 15:12

http://www.vim.org/tips/tip.php?tip_id=227 (3 of 6) [18/02/2004 14:49:49]

Tip #227 - Power of :g : vim online

This can be done much simpler:


:%norm jdd
mra@frogne.dk, February 10, 2003 4:49
Another cool g feature is to count the number of lines
matching /regexp/
let x=0 | g/regexp/let x=x+1
echo x
Great, if you are editing data files.
Regards
Mike
setanta5@excite.com, March 27, 2003 2:14
Reverse all the lines in a file:
:g/^/m0
I have found that useful . . . honest!
PK
kkgahlot@yahoo.com, September 3, 2003 5:06
Can I do something like this using ":g" (or anything
else)
I have a file which contains following kind of lines
abc123=1,2,3
bcd123=100,200,300
abcb123=1,3,4
I want to convert this to following
abc123=1,abc,2,abc,3,abc
bcd123=100,bcd,200,bcd,300,bcd
abcb123=1,abcb,3,abcb,4,abcb
Basically I want to replace each comma in a line with
first few letters, which are coming before 123, of that
line surrounded by 2 commas.
Anonymous, September 3, 2003 12:45

http://www.vim.org/tips/tip.php?tip_id=227 (4 of 6) [18/02/2004 14:49:49]

Tip #227 - Power of :g : vim online

To answer

kkgahlot's question:

global // execute "s/\\([=,][^,]*\\)/\\1, " . matchstr


(getline ("."), "^.\\{-}\\(123\\)\\@=") . "/g"
To make the whole thing a little more transparent some
explanations (from the inside out):
We want to execute on each line a command like
s/\([=,][^,]*\)/\1, abc/g
for each line, but abc gets changed on each line.
The function
matchstr (getline ("."), "^.\\{-}\\(123\\)\\@=")
returns the string that matches the pattern /^.\{}\(123)\@=/ on the current line. In the given examples
this is the text preceding 123= at the beginning of the
line. Depending on the actual requierements, a simpler
expression like /^[a-z]*/ could work too.
The command
execute "s/\\([=,][^,]*\\)/\\1, " . matchstr (getline
("."), "^.\\{-}\\(123\\)\\@=") . "/g"
assembles the desired substitute command for the
current line by joining some static text with the
return value of the matchstr function and then executes
it.
As execute works only on the current line, the command
global // execute ...
applies it to all line. If only certain lines should be
proecessed replace // with some other pattern.
utzb@gmx.de, November 21, 2003 10:39
Reverting lines in a file can also be done via
:%!tac
instead of tac, you can also use sort, xxd, xxd -r,
cut, your-own-filter
Add Note

http://www.vim.org/tips/tip.php?tip_id=227 (5 of 6) [18/02/2004 14:49:49]

Tip #227 - Power of :g : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=227 (6 of 6) [18/02/2004 14:49:49]

SourceForge
Logo

Tip #228 - Deleting nested reply threads in emails : vim online

not logged in (login)

Home
Search

Tip #228: Deleting nested reply threads in emails


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/4, Viewed by 1044

created: March 24, 2002 16:39


author: Darren Greaves

complexity: intermediate
as of Vim: 6.0

I find the following setting useful when replying to


email threads that have lots of lines like the
following:
> blah
> > blah
> > > blah
autocmd FileType mail map <F8> :%g/^> >/d<CR>
When replying to a mail and you want to remove
everything except what the person you are directly
replying to wrote just press F8.
From the example above, you would just be left with
> blah
What it does is simply match any line starting with > >
and deletes it. It's not perfect as sigs and other
debris may remain but it takes a lot of the grunt work
out of replying to mails.
The autocmd only maps F8 when using mails, this is handy
if you use F8 for other things as I do.
:help autocmd
:help map
:help :g
rate this tip

Life Changing

Helpful

<<Power of :g | First thing to try before asking help >>

Additional Notes
salmanhalim@hotmail.com, March 25, 2002 6:15

http://www.vim.org/tips/tip.php?tip_id=228 (1 of 2) [18/02/2004 14:49:51]

Unfulfilling

rate

Tip #228 - Deleting nested reply threads in emails : vim online

why not just put the mapping in the ftplugin/mail.vim


file?
map <buffer> <f8> :g/. . .
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=228 (2 of 2) [18/02/2004 14:49:51]

SourceForge
Logo

Tip #229 - First thing to try before asking help : vim online

not logged in (login)

Home
Search

Tip #229: First thing to try before asking help


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 128/49, Viewed by 2959

created: March 27, 2002 19:17


author: Arun Easi

complexity: basic
as of Vim: 5.7

I've seen several questions asked in the reflector which


is available in the help files.
Yeah, I know the help is huge. But, you can try this
command to show a list of related
topics you are trying:
:he <topic><c-d>
It is "some topic" followed by the key sequence Ctrl-D.
For eg:
:he xterm<c-d>
will show all the help topics matching xterm. Then you
can do completion/copy-n-paste
the topic you are searching. Of course you can cycle
through all the topics through
repeated <TABS>, but if the number of hits are huge, it
is cumbersome.
Enjoy vimming beginners!!!
-Arun
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Deleting nested reply threads in emails | copy current file to another location from within vim >>

Additional Notes
Anonymous, March 27, 2002 19:20
Forgot to add that <c-d> can be used for listing other
matches also.
For eg:
:e <c-d> "to show list of files matching the pattern
:buf <c-d> "to show list of open buffers etc.
-Arun

http://www.vim.org/tips/tip.php?tip_id=229 (1 of 2) [18/02/2004 14:49:53]

Tip #229 - First thing to try before asking help : vim online

kgergely@mclRE.MOVEhu, April 3, 2002 6:16


Also see the widemenu.
My settings:
set wildmenu wildmode=longest:full,full
What it does:
First tab: longest match, list in the statusbar.
Next tabs: cycle through matches. (Like in the shell)
jaldripublic at comcast dot net, November 17, 2003 8:15
Also
:helpgrep {pattern}
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=229 (2 of 2) [18/02/2004 14:49:53]

SourceForge
Logo

Tip #230 - copy current file to another location from within vim : vim online

not logged in (login)

Home
Search

Tip #230: copy current file to another location from within vim
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/1, Viewed by 1030

created: April 2, 2002 7:26


author: Tabrez Syed

complexity: basic
as of Vim: 5.7

I work on jsp pages in my source tree but I have to copy


the jsp files over to the tomcat directory in order to
view my changes.The following mapping will copy the file
being edited to another location.
command Cpage silent !cp '%:p'
"c:/Progra~1/Tomcat/webapps/console/pages/%"
Explanation:
% refers to the current buffer
%:p refers to the path to the file
silent suppresses the command prompt window.
Usage:
:Cpage
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<First thing to try before asking help | Localized color schemes >>

Additional Notes
maxiangjiang@homail.com, April 2, 2002 15:11
Why not
:w %:t c:/Progra~1/Tomcat/webapps/console/pages/
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=230 [18/02/2004 14:49:55]

SourceForge
Logo

Tip #231 - Localized color schemes : vim online

not logged in (login)

Home
Search

Tip #231: Localized color schemes


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/1, Viewed by 1967

created: April 5, 2002 7:23


author: Salman Halim

complexity: basic
as of Vim: 6.0

i frequently like to edit multiple files in the same vim


session. however, if i come into vim from another
window i frequently hit 'i' and start typing in whatever
buffer is currently being used -- this is often the
wrong one (requires <esc>, undo, go the other buffer and
. to redo).
one way to work around this for me is to use a different
color scheme depending on what file i'm working on:
au BufEnter * if (exists("b:colors_name")) | let
b:current_colors=colors_name | execute "colorscheme " .
b:colors_name | endif
au BufLeave * if (exists("b:current_colors")) | execute
"colorscheme " . b:current_colors | endif
if you define b:colors_name with a particular color
scheme name, then the above autocommands will switch to
that colorscheme when you enter that window and will
return to the original color upon departure.
inside ftplugin/java.vim, for example, i might have
b:colors_name set to 'morning', causing all java files
to have a distinguishing color scheme.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<copy current file to another location from within vim | Search JDK help for keyword at cursor >>

Additional Notes
@, April 8, 2002 5:28

http://www.vim.org/tips/tip.php?tip_id=231 (1 of 2) [18/02/2004 14:49:58]

Tip #231 - Localized color schemes : vim online

it'd be nice, set colorscheme through 'modeline' !


Who will make a patch? :)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=231 (2 of 2) [18/02/2004 14:49:58]

SourceForge
Logo

Tip #232 - Search JDK help for keyword at cursor : vim online

not logged in (login)

Home
Search

Tip #232: Search JDK help for keyword at cursor


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 61/26, Viewed by 1812

created: April 5, 2002 23:48


author: Sean Richards

complexity: basic
as of Vim: 6.0

If you are using the Win32 version of Vim you can use this tip to
search the Jdk help for the keyword under the cursor.
You need the winhlp32 version of the Jdk docs from this URL http://www.confluent.fr/javadoc/indexe.html.
It is a 16mb D/L and approx 85mb unzipped!
I added a command to the popup menu
:amenu PopUp.JavaHelp :!start winhlp32 -k <cword>
F:\jdk\winhelp\JDK13.HLP <CR
And also made a keymapping
map J :!start winhlp32 -k <cword> F:\jdk\winhelp\JDK13.HLP <CR>
Trivial yes, but I find it quite useful.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Localized color schemes | Some tips for using Vim to write Lisp code >>

Additional Notes
jmcpherson@softhome.net, April 9, 2002 9:29
Not a bad idea. Here is one for ColdFusion programmers on
Windows:
map K :!"C:\Program Files\Internet Explorer\iexplore.exe"
http://servername/cfdocs/searchmain.cfm?searchstring=<cword><CR>;
where "servername" is the name of a server that has the
ColdFusion documentation installed.
By the way, I mapped it to K because K is Vim's default "help on
keyword under cursor" function, which (traditionally) calls up
the Unix 'man' program. Vim on Windows doesn't use man, though,
so it makes sense to map that to something specific to the
language I use most. (If you work with multiple languages, why
not add language-specific K mappings for each to filetype.vim?
You could get the right help program for whichever language you
were working with.)
In a standard Vim install, J is used in command-mode to join
http://www.vim.org/tips/tip.php?tip_id=232 (1 of 2) [18/02/2004 14:50:03]

Tip #232 - Search JDK help for keyword at cursor : vim online

together two lines of text. I find it very useful -- it allows me


to bring the next line up without moving my cursor around.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=232 (2 of 2) [18/02/2004 14:50:03]

SourceForge
Logo

Tip #233 - Some tips for using Vim to write Lisp code : vim online

not logged in (login)

Home
Search

Tip #233: Some tips for using Vim to write Lisp code
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 6/10, Viewed by 1117

created: April 9, 2002 14:05


author: Larry Clapp

complexity: basic
as of Vim: 6.0

For some tips on how to use Vim for writing Lisp code,
see http://www.lisp-p.org/i000/15-vim.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Search JDK help for keyword at cursor | Vi(M) Command Line tips & tricks >>

Site Help

Additional Notes
srinathava at yahoo dot com, April 9, 2002 18:19
The link above doesnt work (as of April 9, 2002).
since tip editing doesnt work, add the correct link as
a comment below...
Anonymous, April 10, 2002 4:38
Try adding a / to the end.
find from www.lisp-p.org

It is also pretty easy to

http://www.lisp-p.org/i000/15-vim/
Anonymous, April 14, 2002 11:23
Beware! The correction (10 April) *still* doesn't
include the trailing "/" if you attempt to click on it.
Typing in the full URL (including the trailing "/")
works fine.
Once you get past the pain of *getting* to it, the
article is actually an interesting discussion on
writing Lisp using Vim 6.x. (Never thought of "set
foldmethod=indent shiftwidth=1" !!)
I'll attempt to correct the URL one more time:
http://www.lisp-p.org/i000/15-vim/

http://www.vim.org/tips/tip.php?tip_id=233 (1 of 2) [18/02/2004 14:50:05]

Tip #233 - Some tips for using Vim to write Lisp code : vim online

Larry Clapp <vim at theclapp.org>, April 30, 2002 18:01


I goofed.

Thanks, y'all.

Anonymous, September 24, 2002 2:10


Now, the link should read http://www.lispp.org/htdocs/15-vim/index.html
Anonymous, May 19, 2003 21:54
it changed.....
http://www.lisp-p.org/15-vim/
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=233 (2 of 2) [18/02/2004 14:50:05]

SourceForge
Logo

Tip #234 - Vi(M) Command Line tips & tricks : vim online

not logged in (login)

Home
Search

Tip #234: Vi(M) Command Line tips & tricks


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 48/27, Viewed by 7475

created: April 11, 2002 3:18


author: David Rayner (zzapper)

complexity: basic
as of Vim: 6.0

Hi VIMMERs
These tips save me wearing out my delicate little
fingers with unnecessary keystrokes.
They assume Unix, but I also use them on a Windows Unix
Shell (MKS) as well
# When I know the file i want to edit is the most recent
file in a directory
alias -x vew='vi `l\s -t * | head -1 `'
#When I know the file I want to edit contains a unique
keyword
#this is actually in a little shell script call ed vg
where the keyword is passed as parameter $1
#/bin/sh
#name vg
vi.exe $(grep -isl $1 *) &
# some variations
alias -x vp='vi `l\s -t *.@(pl|cgi)| head -1 `'
#execute the most recent script (I call this from within
VIM with a mapped button)
alias -x xew='`l\s -t *.pl | head -1 `'
Cheers zzapper

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Some tips for using Vim to write Lisp code | Toggle highlight word under cursor, to find cursor. >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=234 (1 of 5) [18/02/2004 14:50:07]

Tip #234 - Vi(M) Command Line tips & tricks : vim online

david@tvis.co.uk, April 13, 2002 2:54


Hi
I forgot my best script v.ksh this allows me to edit a
file(s) containing any particular substring
such say I know that a file in a directory is the only
one that contains the letter z I just need to type
> v z
# v.ksh
# description : vi all files containing $1 in name
#
but excluding binaries
#set -x
filenum=0
for x in *$1*
do
if [[ "$x" != *.@(xls|exe|mdb) ]] && [ -f "$x" ]
then
filelst[$filenum]=$x
let filenum=filenum+1
fi
done
vim ${filelst[*]} &
# end script
If your shell (ef csh) allows you alias parameters this
can also be done with
something like (sorry I forget)
alias v=''vi.exe *\($1\)*'
demian0311@yahoo.com, April 18, 2002 11:56
that 'vew' thing is very cool. i _always_ want to do
that, very useful... i had to have it like this under
cygwin...
alias vnew='vim `ls -t | head -1 `'
alias vold='vim `ls -t | tail -1 `'
vold is cool when you want to edit each file in a
directory but don't want to deal with buffers inside
vim.
david@tvis.co.uk, April 20, 2002 15:12

http://www.vim.org/tips/tip.php?tip_id=234 (2 of 5) [18/02/2004 14:50:07]

Tip #234 - Vi(M) Command Line tips & tricks : vim online

Hi I've just remembered he syntax


A Csh alias (for shells that allow parameters)
alias v 'vi *\!*\*'
You can now edit a file in a directory that is say the
only one with a filename containing say "bank"
just by typing
> v bank
alsp don't forget the wonderfull fact that vim will
edit a pipe
> ls -1 fred*.c | vim will result in VIm opening an unnamed file containing a
list of files fred* r
david@tvis.co.uk, May 29, 2002 11:16
Open a file with vi(m) and jump to a particular place
defined by "searchstr"
vi -c "/searchstr" main.c
turn this into a script
#vis.ksh
#vi with search
vi -c "/$1" $2

david@tvis.co.uk, May 29, 2002 11:22


how many times you decided to use one file as a basis
for a new file, started editting the original, and then
absently minded saved it, rather than saving as!!
this shell script simplifies and avoids this problem
# vcp.ksh
# description : copy file $1 to $2 then edit $2
#set -x
cp $1 $2
vi $2
david@tvis.co.uk, July 22, 2002 8:53

http://www.vim.org/tips/tip.php?tip_id=234 (3 of 5) [18/02/2004 14:50:07]

Tip #234 - Vi(M) Command Line tips & tricks : vim online

View Gvim Command Line help by typing


gvim -h
Notables
gvim -u local_vimrc
gvim --noplugin
gvim -v (Vi compatible)
gvim + fred.php (jump to End of file)
gvim +10 fred.php (jump to 10th line)
gvim -w hist.txt fred.php (append all typed commands to
hist.txt)
gvim -c "/searchstr" main.c (jump to string when main.c
opened)(note quotes)
gvim -R important.txt (open read only)
david@tvis.co.uk, July 29, 2002 9:42
To summarise
# the following is an alias to edit the most recent
file in a directory
> vew
# the following script v.ksh , edits any file in
current directory whose name contains say "main"
>v main
# the following script vg.ksh (see below) , edits any
file containing the specified keyword and jumps to 1st
occurrence
>vg fn_main
# vg.ksh
gvim.exe -c "/$1"

$(grep -isl "$1" *)

# gvim can edit a pipe


ls -1 *.php | gvim These should run with adaptions on Unix, and on Windows
with CYGWin,MKS etc
david@tvis.co.uk, August 10, 2002 2:01
Ftping via VIM
gvim ftp://ftp.yoursite.co.uk/public_html/index.html
david@tvis.co.uk, September 2, 2002 6:32
Open file1 & file2 into a split window
gvim -o file1 file2
david@tvis.co.uk, September 8, 2002 2:04
http://www.vim.org/tips/tip.php?tip_id=234 (4 of 5) [18/02/2004 14:50:07]

Tip #234 - Vi(M) Command Line tips & tricks : vim online

# compare differences in 2 files (vimdiff)


# see :h vimdiff
gvim -d file1 file1
david@tvis.co.uk, September 18, 2002 2:47
# performing edits on multiple files (pipe separates
commands)
vim -c "argdo %s/ABC/DEF/g | w" *.txt
yijun@cs.toronto.edu, July 29, 2003 12:45
vim -c "argdo %s/FOO/BAR/g | update" `grep -l FOO *`
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=234 (5 of 5) [18/02/2004 14:50:07]

SourceForge
Logo

Tip #235 - Toggle highlight word under cursor, to find cursor. : vim online

not logged in (login)

Home
Search

Tip #235: Toggle highlight word under cursor, to find cursor.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/12, Viewed by 1742

created: April 11, 2002 7:27


author: HughSasse

complexity: basic
as of Vim: 6.0

When the screen has scrolled such as during a search, it


may be difficult to find the cursor. :help %# explains
the pattern one can use to highlight the word around the
cursor, which gives a bigger target to look for on the
screen. I have this in my .vimrc:
function VIMRCWhere()
if !exists("s:highlightcursor")
match Todo /\k*\%#\k*/
let s:highlightcursor=1
else
match None
unlet s:highlightcursor
endif
endfunction
map <C-K> :call VIMRCWhere()<CR>
This means that in "normal" mode ctrl-k will toggle the
highlight. Todo is a hightlight group whch is
particularly easy to see.
For further information see ":help s:", ":help
match", ":help exists()" and ":help funtion".
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Vi(M) Command Line tips & tricks | Menu for inserting special characters >>

Additional Notes
gsinclair@soyabean.com.au, April 12, 2002 20:44
Good trick. Another way to find the cursor is to hit
zz, which moves the current line to the center of the
screen.

http://www.vim.org/tips/tip.php?tip_id=235 (1 of 2) [18/02/2004 14:50:10]

Tip #235 - Toggle highlight word under cursor, to find cursor. : vim online

gsinclair@soyabean.com.au, April 12, 2002 23:43


I found that often the highlighting didn't help,
because the cursor was either not on a word or on a
single-letter word. Therefore, I chaged the function
to make it highlight the entire line. To do this,
change the appropriate line in the function to "match
Todo /^.*\%#.*$/".
gsinclair@soyabean.com.au, April 12, 2002 23:43
I found that often the highlighting didn't help,
because the cursor was either not on a word or on a
single-letter word. Therefore, I changed the function
to make it highlight the entire line. To do this,
change the appropriate line in the function to "match
Todo /^.*\%#.*$/".
Anonymous, April 13, 2002 2:15
jk
Do this quickly, you'll see the cursor because it's
moving.
Anonymous, April 11, 2003 2:38
As well as hitting zz, you can ":set scrolloff=999" (or
so=999) to leave it permanently in the centre.
Takes a bit of getting used to, but you never lose the
cursor and you don't have to spend as much time
scrolling
because you're always editing in the middlle of the
action.
patrick@neuralyte.org, October 2, 2003 20:14
<Space> followed by <Backspace> moves the cursor in
both Command and Insert modes, without altering the
buffer.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=235 (2 of 2) [18/02/2004 14:50:10]

SourceForge
Logo

Tip #236 - Menu for inserting special characters : vim online

not logged in (login)

Home
Search

Tip #236: Menu for inserting special characters


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/7, Viewed by 1533

created: April 19, 2002 6:30


author: Th. Ramming

complexity: basic
as of Vim: 5.7

First, thanks for the script printascii.vim.


When looking at the ascii table, I found some characters I'd like to have
inserted when editing.
Add the following lines in your _gvimrc and you can select them via menu.
(change the names of the menu if you don't have German installed or don't
like my titles).
I also made some abbreviations to get separation lines in documentation
or code files,
e.g.
abb dotlin
^M
abb cdotlin
/**/^M
abb fdotlin
^M
abb cfdotlin
/**/^M
abb dlin
=======================================================================^M
abb cdlin
/*===================================================================*/^M
abb lin ----------------------------------------------------------------------^M
abb clin /*------------------------------------------------------------------*/^M
abb ulin
_______________________________________________________________________^M
abb culin
/*___________________________________________________________________*/^M
abb Ulin
^M
abb cUlin
/**/^M
(you have to substitute ^M with CTRL_V CTRL_M or delete it)
20imenu Editieren.Sonderzeichen.open\ angle\ <C-R>=nr2char(171)<CR>
20nmenu Editieren.Sonderzeichen.open\ angle\ a<CR>=nr2char(171)<CR><ESC>
20imenu Editieren.Sonderzeichen.close\ angle\ <C-R>=nr2char(187)<CR>
20nmenu Editieren.Sonderzeichen.close\ angle\ a<CR>=nr2char(187)<CR><ESC>
20imenu Editieren.Sonderzeichen.start\ mark\ <C-R>=nr2char(132)<CR>
20nmenu Editieren.Sonderzeichen.start\ mark\ a<CR>=nr2char(132)<CR><ESC>
20imenu Editieren.Sonderzeichen.end\ mark\ \ <C-R>=nr2char(148)<CR>
20nmenu Editieren.Sonderzeichen.end\ mark\ \ a<C-

http://www.vim.org/tips/tip.php?tip_id=236 (1 of 2) [18/02/2004 14:50:12]

Tip #236 - Menu for inserting special characters : vim online

R>=nr2char(148)<CR><ESC>
20imenu Editieren.Sonderzeichen.fat\ dot\ \ <C-R>=nr2char(149)<CR>
20nmenu Editieren.Sonderzeichen.fat\ dot\ \ a<CR>=nr2char(149)<CR><ESC>
20imenu Editieren.Sonderzeichen.etc\ \ \ <C-R>=nr2char(133)<CR>
20nmenu Editieren.Sonderzeichen.etc\ \ \ a<C-R>=nr2char(133)<CR><ESC>
20imenu Editieren.Sonderzeichen.!underscore\ \ <C-R>=nr2char(175)<CR>
20nmenu Editieren.Sonderzeichen.!underscore\ \ a<CR>=nr2char(175)<CR><ESC>
20imenu Editieren.Sonderzeichen.copyright\ \ <C-R>=nr2char(169)<CR>
20nmenu Editieren.Sonderzeichen.copyright\ \ a<CR>=nr2char(169)<CR><ESC>
20imenu Editieren.Sonderzeichen.paragraph\ \ <C-R>=nr2char(167)<CR>
20nmenu Editieren.Sonderzeichen.paragraph\ \ a<CR>=nr2char(167)<CR><ESC>
20imenu Editieren.Sonderzeichen.noitamalcxe\ <C-R>=nr2char(161)<CR>
20nmenu Editieren.Sonderzeichen.noitamalcxe\ a<CR>=nr2char(161)<CR><ESC>

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Toggle highlight word under cursor, to find cursor. | If you prefer vertical splits >>

Additional Notes
Thomas.Ramming@gmx.de, April 23, 2002 7:38
Thanks for rating.
Should I mention that you can insert lines (if you know the length)
e.g. by typing
'40'<select special char from menu>
in normal mode ?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=236 (2 of 2) [18/02/2004 14:50:12]

SourceForge
Logo

Tip #237 - If you prefer vertical splits : vim online

not logged in (login)

Home
Search

Tip #237: If you prefer vertical splits


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/2, Viewed by 1623

created: April 23, 2002 21:59


author: Kartik Agaram

complexity: intermediate
as of Vim: 6.0

This is just in case there's somebody else who likes to


work in a maximized vim window on a high resolution
desktop. If you follow good coding practice and make
sure your programs use only 80 characters in each row,
have you noticed how much space lies unused on the
right?
I find that the following settings keep me from ever
seeing another horizontal split, unless I specifically
ask for it.
cabbrev
cabbrev
cabbrev
cabbrev
cabbrev
cabbrev

split vsplit
hsplit split
sta vertical sta
help vertical help
new vnew
right botright

; A more heavyweight solution for ^W^]


function! ToggleSplit (dir)
let currFname = bufname ("%")
let old = winnr ()
" Window navigation to ensure the correct window is
'last'.
if (a:dir == "u")
wincmd k
let back="j"
elseif (a:dir == "d")
wincmd j
let back="k"
elseif (a:dir == "l")
wincmd h
let back="l"
elseif (a:dir == "r")
wincmd l
let back="h"
endif
http://www.vim.org/tips/tip.php?tip_id=237 (1 of 3) [18/02/2004 14:50:14]

Tip #237 - If you prefer vertical splits : vim online

if (winnr () == old)
echo "Ouch"
return
endif
exec "wincmd " . back
quit
if (back == "j" || back == "k")
let orientation = "vsplit"
else
let orientation = "split"
endif
if (back == "j" || back == "l")
let dir = "below"
else
let dir = "above"
endif
exec dir . " " . orientation " " . currFname
endfunction
noremap ^W^] ^W^]:silent call ToggleSplit ("d")<CR>
; Optional.
set splitright
; In which case the above mapping becomes:
noremap ^W^] :set splitbelow<CR>^W^]:silent call
ToggleSplit ("u")<CR>:set nosplitbelow<CR>
; Or you could just
set splitbelow
; :-)
; Very elegant and almost perfect, but it screws up if
you want to run a command with ranges :-)
;noremap : :vertical<Space>
; EOF
rate this tip

Life Changing

Helpful

Unfulfilling

<<Menu for inserting special characters | Very basic session persistence >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=237 (2 of 3) [18/02/2004 14:50:14]

rate

Tip #237 - If you prefer vertical splits : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=237 (3 of 3) [18/02/2004 14:50:14]

SourceForge
Logo

Tip #238 - Very basic session persistence : vim online

not logged in (login)

Home
Search

Tip #238: Very basic session persistence


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/2, Viewed by 984

created: April 25, 2002 4:54


author: Michel de Bree

complexity: basic
as of Vim: 6.0

I use the following code in my plugins dir to ease


session persistance. If I want my session to persist I
use :mks! and then whenever I open the Session.vim file,
my session is restored. If I am working from a restored
session and I close VIM, the session is saved
automatically. Drawback is that it makes editing the
Session.vim file a bit cumbersome ;)
au BufRead Session.vim so %
au VimLeave * call SaveCurrentSession()
function! SaveCurrentSession()
if v:this_session != ""
exe "mksession! " . v:this_session
endif
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<If you prefer vertical splits | Scroll using arrow keys like browser: map shift-up and shift-down >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=238 [18/02/2004 14:50:16]

SourceForge
Logo

Tip #239 - Scroll using arrow keys like browser: map shift-up and shift-down : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #239: Scroll using arrow keys like browser: map shift-up and
shift-down
tip karma

Rating 6/5, Viewed by 974

created: May 2, 2002 7:05


author: Larry Clapp
You can
up/down
shifted
Down to

complexity: basic
as of Vim: 5.7

make Vim scroll the text using the shifted


arrows, sort of like your browser (except with
keys :), by mapping Shift-Up to Ctrl-Y and ShiftCtrl-E.

map <s-Down> <C-E>


map <s-Up> <C-Y>
Shift-Down will then scroll down (like moving a scrollbar down, or like moving a cursor at the bottom of a
window down), and Shift-Up will then scroll up (like
moving a scroll-bar up, etc).
If you'd rather think about the text moving down/up
instead of the cursor moving up/down, you can of course
swap the mappings.
If you normally use j and k for cursor movement, and
rarely use the arrow keys, you can map the arrow keys
directly, in which case I'd probably map the shifted
arrow keys back to cursor movement:
map
map
map
map

<down> <c-e>
<up> <c-y>
<s-down> j
<s-up> k

See :help ctrl-e, :help ctrl-y, and :help key-mapping.


See also :help i_ctrl-o and :help map-modes for how to
set up these mappings for use in other modes (like
insert mode :).
(Vim by default maps s-Down and s-Up to Ctrl-F and CtrlB, for both normal and visual mode. Keep this in mind
if you change some of the above mappings to "nmap",
'cause you'll probably also want to look in to "vmap".)

http://www.vim.org/tips/tip.php?tip_id=239 (1 of 2) [18/02/2004 14:50:19]

Tip #239 - Scroll using arrow keys like browser: map shift-up and shift-down : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Very basic session persistence | Hideall for Vim >>

Additional Notes
quesadaj@psych.colorado.edu, August 13, 2003 11:56
This would be great, but doesn't work with my
combination of secure F SSH (windows) and TERM=xterm.
The arrows cannot be mapped as <up>, etc, nor the
<home> key. Any idea about why?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=239 (2 of 2) [18/02/2004 14:50:19]

SourceForge
Logo

Tip #240 - Hideall for Vim : vim online

not logged in (login)

Home
Search

Tip #240: Hideall for Vim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 15/8, Viewed by 1003

created: May 2, 2002 8:28


author: Wenzhi Liang

complexity: intermediate
as of Vim: 6.0

Xemacs has a hide all function which can make all the
function in your C file a fold and close them. And here
is something small to achieve similiar under Vim.
func! HideAll()
syn region myFold start="{" end="}" transparent fold
syn sync fromstart
set foldnestmax=1
set foldmethod=syntax
endfunc
amenu Whatever.Hide\ all :call HideAll()<CR>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Scroll using arrow keys like browser: map shift-up and shift-down | "Hide" Folding Markers >>

Additional Notes
zhichao_h@yahoo.com, May 2, 2002 13:06
It works fine in version 6.0. But in version 6.1, it
is really ugly.
Suppose, you have the following Java
public class Hello {
zhichao_h@yahoo.com, May 2, 2002 13:09

http://www.vim.org/tips/tip.php?tip_id=240 (1 of 2) [18/02/2004 14:50:21]

Tip #240 - Hideall for Vim : vim online

I accidently cancel last note. Sorry about this.


Suppose, you have the following java file:
public class Hello {
public void setter() {
// do something ...
}
}
In 6.0, you will the indivisual method name (i.e., you
will see the Hello and setter. So you can unfold the
level you want. But in 6.1, you only see only big
level that is the Hello. If you want to the method
name -- setter, you have to unfold the Hello
first. This is really inconvenient. I am not sure
this is a "new feature" or simply a bad bug.
wzhliang@yahoo.com, May 3, 2002 3:19
No they both work for me. I hav 6.0 and 6.1 running
side by side and doing exactly the same thing.
Maybe you forgot :set foldnestmax=2 ???
zhichao_h@yahoo.com, May 3, 2002 14:44
Yes, it works fine after I set the
foldnestmax=2. Thanks a lot.
jmayo@rm-f.net, September 10, 2002 18:33
That's really neat. Now how do I get it to
automatically apply to any .c .C .cc .cpp file I open?
And is doing that a good idea?
krishna@labautomate.com, June 26, 2003 9:42
add the following after your autocmd for c files (and
after you define the function)
autocmd FileType c,cxx,cpp call HideAll()
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=240 (2 of 2) [18/02/2004 14:50:21]

SourceForge
Logo

Tip #241 - "Hide" Folding Markers : vim online

not logged in (login)

Home
Search

Tip #241: "Hide" Folding Markers


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/3, Viewed by 987

created: May 2, 2002 19:34


author: Edwin-

complexity: intermediate
as of Vim: 6.0

I wanted to start using folding without having to get used


to
seeing the (default) markers, a.k.a {{{ and }}}. So, here
are
2 autocmd's that will make them fade to black....bg=black
fg=black
au BufRead,BufNewfile
'"*{{{\|"*}}}'
contains=fmrkr

* syn match fmrkr


|
\ syn cluster vimCommentGroup

|
\ hi fmrkr term=NONE guibg=black

guifg=black
\

ctermbg=black

ctermfg=black
au BufRead,BufNewfile
contained

* syn match fmrkr '"*{{{\|"*}}}'


\ containedin=vimLineComment

|
\ hi fmrkr term=NONE guibg=black

guifg=black
\

ctermbg=black

ctermfg=black
They both accomplish the same thing, but with different
methods, so
simply pick one and see those annoying (at least to me)
markers fade away.
I just tried it out with vim files, but you can easily
modify it for
any other filetypes.
Thanks to Colin's lead with ':help c-syntax'
for the
1st au.
Thanks to Benji's lead with ':help containedin' for the
2nd au.
Understanding most of the syntax.txt document file would
also be helpful.
http://www.vim.org/tips/tip.php?tip_id=241 (1 of 2) [18/02/2004 14:50:23]

Tip #241 - "Hide" Folding Markers : vim online

To figure out what highlighting group the Marker is in, I


would suggest
using Chip's vimtip#99.
Happy Vimming!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Hideall for Vim | The power of "\_" in reg-ex >>

Additional Notes
kgergely@mcl_remove.hu, May 23, 2002 6:29
Instead of using black color, consider using the Ignore
highlighting group!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=241 (2 of 2) [18/02/2004 14:50:23]

SourceForge
Logo

Tip #242 - The power of "\_" in reg-ex : vim online

not logged in (login)

Home
Search

Tip #242: The power of "\_" in reg-ex


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 23/14, Viewed by 1506

created: May 6, 2002 11:32


author: vim_power

complexity: intermediate
as of Vim: 6.0

One of the most uncelebrated feature of vim 6.0 is the


ability to span a search across multiple lines.
\_^
maps a begining of line anywhere in search
pattern.
\_$
---"----- end
----------------------"------------------------.
\_s ---"------ space
------------"------------------------ .
e.g /{\_s will map all white spaces and new-line chars
after a "{"
The \_ can be appended to other objects as well. such as
\_U, \_L, \_. (this one's risky) .
See :help pattern for more details.
Njoy
rate this tip

Life Changing

Helpful

<<"Hide" Folding Markers | Develop vim modules on Win >>

Additional Notes
Hal Atherton, May 7, 2002 22:58

http://www.vim.org/tips/tip.php?tip_id=242 (1 of 3) [18/02/2004 14:50:25]

Unfulfilling

rate

Tip #242 - The power of "\_" in reg-ex : vim online

This feature is absolutely great...


eg. to seek out HTML
<!-- foobar does
not exit -->
comments over MULTIPLE LINES
/<!--\_p\{-}-->
does the trick.
We used \{-} the "few as possible"
operator
rather than * which is too greedy when there are many
such comments in the file.
The key is of course \_p which is printable characters
including EOL
end-of-lines.
VIM BUG:
the highlighting is very erratic when the span over
number of lines
exceeds, say, 30.
And highlighting is rather spotty
when there are
shifts in screen views.
In other words: HIGHLIGHTING
UNRELIABLE.
FIX?
(some simple option we can reset?)
jaldripublic at comcast dot vim, November 17, 2003 8:08
No this is not a bug, this is -- honest -- a
feature! Specifically, this is a default that improves
highlighting performance.
If you want to ensure the most accurate highlighting,
try:
:syntax sync fromstart
But, be warned! This can slow things down on large
files with complex highlighting
For more info:
:h syn-sync
Add Note

http://www.vim.org/tips/tip.php?tip_id=242 (2 of 3) [18/02/2004 14:50:25]

Tip #242 - The power of "\_" in reg-ex : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=242 (3 of 3) [18/02/2004 14:50:25]

SourceForge
Logo

Tip #243 - Develop vim modules on Win : vim online

not logged in (login)

Home
Search

Tip #243: Develop vim modules on Win


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -1/5, Viewed by 1164

created: May 7, 2002 5:00


author: SANFACE Software

complexity: basic
as of Vim: 6.0

We're trying to develop txt2pdf.vim


http://vim.sourceforge.net/scripts/script.php?script_id=283
on Win.
It's a very simple module to save the current file and
convert it to PDF using our txt2pdf tool
http://www.sanface.com/txt2pdf.html
On our Windows 2000 we've developed it. It works good.
Today we've tested the module on Linux. Surprise: it
doesn't work.
Default Win Vim configure save on Win text in Win way: EOL
\r\n.
A Vim module made in this way can't work on Linux (probably
on every Unix OS).
If you want to make a Vim module on Win and you want it can
work also on Unix (we hope the same rula can work also on
different OS) you've to save the Vim module with Unix EOL
(\n).
Please send us (sanface@sanface.com) your notes about other
OS (e.g. OpenVMS).
rate this tip

Life Changing

Helpful

Unfulfilling

<<The power of "\_" in reg-ex | Ask vim where an option was set. >>

Additional Notes
benji@member.AMS.org, May 12, 2002 8:15

http://www.vim.org/tips/tip.php?tip_id=243 (1 of 2) [18/02/2004 14:50:27]

rate

Tip #243 - Develop vim modules on Win : vim online

I believe that Vim scripts saved with UNIX-style EOL


characters can run on any platform.
Probably the easiest way to make sure they stay this way
is to add a modeline at the top
or bottom of the file, for example
" vim:ff=unix
:help modeline
:help :source_crnl
:help 'fileformat'
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=243 (2 of 2) [18/02/2004 14:50:27]

SourceForge
Logo

Tip #244 - Ask vim where an option was set. : vim online

not logged in (login)

Home
Search

Tip #244: Ask vim where an option was set.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 196/84, Viewed by 2768

created: May 7, 2002 8:22


author: Benji Fisher

complexity: intermediate
as of Vim: 6.0

When things go wrong, it is sometimes hard to


figure out why. For example,
an option might be set in the system vimrc file, in a
personal vimrc file, in a
plugin (global or local), or interactively. Vim will
tell you where the current
value was set if you ask:
:verbose set history?
will tell you the current value of the 'history' option,
and where it was set.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Develop vim modules on Win | Working with Unicode (platform-independent) >>

Additional Notes
atheeban@yahoo.com, October 8, 2002 11:34
I was looking for this quite sometime. I have installed
RH7.1 on my pc and was wondering how the default
settings for vim were set. Good one!.
lk1@teamten.com, February 12, 2003 15:52
Is there a similar feature for mappings? RedHat ships
with a modified vim that sources their own set of maps,
and it took me forever to track them down and disable
them. This feature for maps would have saved me a lot
of trouble.
zzapper@ntlworld.com, August 28, 2003 3:23

http://www.vim.org/tips/tip.php?tip_id=244 (1 of 2) [18/02/2004 14:50:30]

Tip #244 - Ask vim where an option was set. : vim online

:scriptnames
location
:map
:functions
:ab

# list all loaded scripts & their


# list maps
# list functions
# list abbreviations

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=244 (2 of 2) [18/02/2004 14:50:30]

SourceForge
Logo

Tip #245 - Working with Unicode (platform-independent) : vim online

not logged in (login)

Home
Search

Tip #245: Working with Unicode (platform-independent)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 43/15, Viewed by 2333

created: May 10, 2002 12:21


author: Tony Mechelynck

complexity: basic
as of Vim: 6.0

Here are the main options you will want to set if you want
to work with Unicode files in (g)vim (see at bottom what
help tags to look for)
if has("multi_byte")
set encoding=utf-8
" how vim
shall represent characters internally
setglobal fileencoding=utf-8
" empty is also
OK (defaults to same as 'encoding'). Or you may want to set
one of the ucs encodings (which
"
may use less disk space if you use only "alphabetic"
scripts such as Latin, Greek, Cyrillic, Hebrew or Arabic,
and
"
not "ideographic" scripts like Chinese, Japanese or Korean.
With the ucs encodings it is usually better
set bomb
" to
also set 'bomb' on ('byte-order-mark" option, irrelevant
for utf-8 but not for ucs)
set termencoding=iso-8859-15
" or whatever is
appropriate to your locale (iso-8859-15 is Latin1 + Euro
currency sign)
set fileencodings=ucs-bom,iso-8859-15,iso-8859-3,utf-8
" or whatever is appropriate to the kinds of files
you want to edit
" 'fileencodings' defines the heuristic to set
'fillencoding' (local to buffer) when reading an existing
file. The first one that matches will be used.
" ucs-bom is "ucs with byte-order-mark"; it must
not come after ucs-8 if you want it to be used
else
echoerr "Sorry, this version of (g)vim was not
compiled with +multi_byte"
endif
In "replace" mode, one utf character (one or more data
bytes) replaces one utf character (which need not use the
same number of bytes)

http://www.vim.org/tips/tip.php?tip_id=245 (1 of 3) [18/02/2004 14:50:32]

Tip #245 - Working with Unicode (platform-independent) : vim online

In "normal" mode, ga shows the character under the cursor


as text, decimal, octal and hex; g8 shows which byte(s)
is/are used to represent it
In "insert" or "replace" mode,
- any character defined on your keyboard can be entered
the usual way (even with dead keys if you have them, e.g.
)
- any character which has a "digraph" (there are a huge
lot of them, see :dig after setting enc=utf-8) can be
entered with a Ctrl-K prefix
- any utf character at all can be entered with a Ctrl-V
prefix, either <Ctrl-V> u aaaa or <Ctrl-V> U bbbbbbbb, with
0 <= aaaa <= FFFF, or 0 <= bbbbbbbb <= 7FFFFFFF
Unicode can be used to create html "body text", at least
for Netscape 6 and probably for IE; but on my machine it
doesn't display properly as "title text" (i.e., between
<title></title> tags in the <head> part).
Gvim will display it properly if you have the fonts for it,
provided that you set 'guifont' to some fixed-width font
which has the glyphs you want to use (Courier New is OK for
French, German, Greek, Russian and more, but I'm not sure
about Hebrew or Arabic; its glyphs are of a more "fixed"
width than those of, e.g. Lucida Console: the latter can be
annoying if you need bold Cyrillic writing).
see:
:h
:h
:h
:h
:h
:h
:h
:h
:h
:h

utf8
'enc'
'fenc'
'fencs'
'tenc'
'bomb'
'guifont'
ga
g8
i_Ctrl-V_digit

Happy Vimming !
Tony.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Ask vim where an option was set. | Working with Unicode (the same, rewritten for legibility) >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=245 (2 of 3) [18/02/2004 14:50:32]

Tip #245 - Working with Unicode (platform-independent) : vim online

Anonymous, November 17, 2003 21:37


Also see here:
http://wiki.debian.org.tw/index.php?page=vim
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=245 (3 of 3) [18/02/2004 14:50:32]

SourceForge
Logo

Tip #246 - Working with Unicode (the same, rewritten for legibility) : vim online

not logged in (login)

Home
Search

Tip #246: Working with Unicode (the same, rewritten for legibility)
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 124/48, Viewed by 3656

created: May 10, 2002 16:19


author: Tony Mechelynck

complexity: basic
as of Vim: 6.0

1. Where to look for help


------------------------:h utf8
:h encoding-values
:h 'enc'
:h 'fenc'
:h 'fencs'
:h 'tenc'
:h 'bomb'
:h 'guifont'
:h ga
:h g8
:h :dig
:h i_Ctrl-V_digit
:h has()
2. What to do (These are *examples*. Modify them to suit your work
environment.)
------------if has("multi_byte")
set encoding=utf-8
setglobal fileencoding=utf-8
set bomb
set termencoding=iso-8859-15
set fileencodings=ucs-bom,iso-8859-15,iso-8859-3,utf-8
else
echoerr "Sorry, this version of (g)vim was not compiled with
+multi_byte"
endif
3. What the above does
---------------------* has("multi_byte") checks if you have the right options compiledin. If you haven't got what it takes, it's no use trying to use
Unicode.
* 'encoding' sets how vim shall represent characters internally. Utf8 is necessary for most flavors of Unicode.
* 'fileencoding' sets the encoding for a particular file (local to
buffer); :setglobal sets the default value. An empty value can also
be used: it defaults to same as 'encoding'. Or you may want to set
one of the ucs encodings, It might make the same disk file bigger or
smaller depending on your particular mix of characters. Also, IIUC,
utf-8 is always big-endian (high bit first) while ucs can be big-

http://www.vim.org/tips/tip.php?tip_id=246 (1 of 4) [18/02/2004 14:50:34]

Tip #246 - Working with Unicode (the same, rewritten for legibility) : vim online

endian or little-endian, so if you use it, you will probably need to


set 'bomb" (see below).
* 'bomb' (boolean): if set, vim will put a "byte order mark" at the
start of ucs files. This option is irrelevant for most non-ucs files
(utf-8, iso-8859, etc.)
* 'termencoding' defines how your keyboard encodes what you type.
The value you put there will depend on your locale: iso-8859-15 is
Latin1 + Euro currency sign, but you may want something else for,
say, an Eastern European keyboard.
* 'fileencodings' defines the heuristic to set 'fileencoding' (local
to buffer) when reading an existing file. The first one that matches
will be used (and, IIUC, if there is no match, Vim falls back on
Latin1). Ucs-bom is "ucs with byte-order-mark"; it must not come
after utf-8 if you want it to be used.
4. Additional remarks
--------------------* In "replace" mode, one utf character (one or more data bytes)
replaces one utf character (which need not use the same number of
bytes)
* In "normal" mode, ga shows the character under the cursor as text,
decimal, octal and hex; g8 shows which byte(s) is/are used to
represent it.
* In "insert" or "replace" mode,
- any character defined on your keyboard can be entered the usual
way (even with dead keys if you have them, e.g. French circumflex,
German umlaut, etc.);
- any character which has a "digraph" (there are a huge lot of
them, see :dig after setting enc=utf-8) can be entered with a Ctrl-K
prefix;
- any utf character at all can be entered with a Ctrl-V prefix,
either <Ctrl-V> u aaaa or <Ctrl-V> U bbbbbbbb, with 0 <= aaaa <=
FFFF, or 0 <= bbbbbbbb <= 7FFFFFFF.
* Unicode can be used to create html "body text", at least for
Netscape 6 and probably for IE; but on my machine it doesn't display
properly as "title text" (i.e., between <title></title> tags in the
<head> part).
* Gvim will display it properly if you have the fonts for it,
provided that you set 'guifont' to some fixed-width font which has
the glyphs you want to use (Courier New is OK for French, German,
Greek, Russian and more, but I'm not sure about Hebrew or Arabic;
its glyphs are of a more "fixed" width than those of, e.g. Lucida
Console: the latter can be awkward if you need bold Cyrillic
writing).
Happy Vimming !
Tony.
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=246 (2 of 4) [18/02/2004 14:50:34]

Helpful

Unfulfilling

rate

Tip #246 - Working with Unicode (the same, rewritten for legibility) : vim online
<<Working with Unicode (platform-independent) | Preexisting code indentation >>

Additional Notes
Anonymous, July 7, 2002 17:03
This doesn't work in gvim on MS-Windows.
Apparently you need to use CTRL-Q instead of CTRL-V,
eg, CTRL-Q u00f1.
antoine.mechelynck@belgacom.net, July 25, 2002 17:53
I use gvim on W32 but I avoid sourcing $VIMRUNTIME/mswin.vim so
Ctrl-V works for me. But you are right, I ought to have mentioned
that if Ctrl-V has been mapped to do a paste, then one should use
Ctrl-Q instead.
-- The Author.
antoine.mechelynck@belgacom.net, July 26, 2002 12:46
About the byte-order mark:
The Unicode standard defines a byte-order mark for optional use at
the start of all Unicode files (ucs-8 as well as little-endian or
big-endian utf-16 and utf-32); it is the character "zero-width nonbreaking space", codepoint U+0xFEFF and comes out as follows:
utf-8:
utf-16
utf-16
utf-32
utf-32

le:
be:
le:
be:

EF BB BF
FF FE
FE FF
FF FE 00 00
00 00 FE FF

It is guaranteed not to clash with a valid Unicode character of a


different encoding and/or endianness. It defines both unit size
(8|16|32 bits) and endianness. I don't know if Vim can generate it
for utf-8. You can always "make one" by typing Ctrl-V u FEFF at the
start of a file (or use Ctrl-Q if Ctrl-V doesn't work for you, see
above).
utf-16 and utf-32 are known in Vim as ucs-2 and ucs-4 respectively.
Tony.
antoine.mechelynck@belgacom.net, October 7, 2003 18:21
My example above for the 'fileencodings' heuristic option is
invalid (see :help 'fileencodings'). There should be at most one
single-byte encoding, and it should be last. Replace the line in
question by (for instance)
set fileencodings=ucs-bom,utf-8,iso-8859-15
Regards,
Tony.
antoine.mechelynck@belgacom.net, October 12, 2003 14:56

http://www.vim.org/tips/tip.php?tip_id=246 (3 of 4) [18/02/2004 14:50:34]

Tip #246 - Working with Unicode (the same, rewritten for legibility) : vim online

I just uploaded a utility script for switching over to Unicode in


an orderly manner, see
http://vim.sourceforge.net/scripts/script.php?script_id=789
Regards,
Tony.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=246 (4 of 4) [18/02/2004 14:50:34]

SourceForge
Logo

Tip #247 - Preexisting code indentation : vim online

not logged in (login)

Home
Search

Tip #247: Preexisting code indentation


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 24/14, Viewed by 1712

created: May 17, 2002 0:46


author: Riccardo Casini

complexity: basic
as of Vim: 5.7

Using tabs as elementary unit in your code indentation


has two advantages: first, you may modify 'tabstop' and
immediately all the indentations depths are modified
according to it; second, your file will be smaller.
But how can we change some already-written code in order
to convert spaces to tabs. Very simple!
Suppose your old code has an indentation unit of 2
spaces
:ret! 2
:x
will replace every 2-spaces to one tab, independently
from your current tabstop value, and will save the
modified file.
Then, if you open again the file with tabstop=2, the
file will look as before but it will be smaller. If you
open the file with tabstop=4, the code vill have a more
indented look, and so on...
Cheers!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Working with Unicode (the same, rewritten for legibility) | Auto-save the current buffer periodically.
>>

Additional Notes
parlorinventor@hotmail.com, May 17, 2002 6:08

http://www.vim.org/tips/tip.php?tip_id=247 (1 of 2) [18/02/2004 14:50:36]

Tip #247 - Preexisting code indentation : vim online

Ehm, maybe... But what if you have two spaces somewhere


in your code where it belongs (like, in a textstring or
so)? I think you'd better unindent by removing all
spaces at beginnings of lines (:%s/$\s+//g or so), be
sure your tabsettings are good and gg=G your text to reindent....
parlorinventor@hotmail.com, May 17, 2002 6:10
Ehm... maybe gg=G is already removing all the
whitespace at the beginning of lines before
reindenting. Dunno exactly (too lazy to find out :) )
informatik.hu-berlin.de: piefel, May 23, 2002 7:04
Changing tabstop is always asking for trouble in my
experience. There will always be people who open your
file with a different tabstop (or just the default 8)
and then write new code using spaces to indent. Et
voil , your formatting is busted.
Try softtabstop instead. Use modelines. Don't just
change tabstop.
Anonymous, October 17, 2002 10:15
I always use 2 commands to avoid reformatting double
spaces inside the valid code...
:s/^ /^I/
Then
:s/I /^I^I/g
emallove@yahoo.com, January 5, 2004 9:19
I do,
:%s/

/\t/g

and note, the number of spaces that comes after ":%s/"


is the width of the tab stop you currently have.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=247 (2 of 2) [18/02/2004 14:50:36]

SourceForge
Logo

Tip #248 - Auto-save the current buffer periodically. : vim online

not logged in (login)

Home
Search

Tip #248: Auto-save the current buffer periodically.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/7, Viewed by 855

created: May 17, 2002 7:00


author: salmanhalim@hotmail.com

complexity: intermediate
as of Vim: 6.0

I have no idea if this was implemented in vim 5.3 or not, but you can
definitely do the following kludge in 6.x by using CursorHold and
localtime:
- When you
time:

start reading a file,

set a buffer variable

to the current

au BufRead,BufNewFile * let b:start_time=localtime()


- Set a CursorHold event to check to see if
since the last save and save if not:

enough time

has elapsed

au CursorHold * call UpdateFile()


- Define a function to save the file if needed:
" only write if needed and update the start time after the save
function! UpdateFile()
if ((localtime() - b:start_time) >= 60)
update
let b:start_time=localtime()
else
echo "Only " . (localtime() - b:start_time) . " seconds have
elapsed so far."
endif
endfunction
- Reset the start time explicitly after each save.
au BufWritePre * let b:start_time=localtime()
Obviously, you should get rid of the else portion once
that this does indeed do what you wanted.

you're certain

The thing to note is that the CursorHold will only fire after
'updatetime' milliseconds of inactivity have elapsed. So, if you type
rapidly for one and a half minutes non-stop, it won't actually save
anything until you STOP activity long enough. This may be what you want
anyway because it won't interrupt your activity with a forced save.
The actual save-delay can be changed from '60' to another number (in
seconds) or a variable or anything like that. This entire functionality
can be easily wrapped inside a nice script which enables/disables this
on a per-buffer basis (maybe with maps etc.). If desired, I can provide
that also.
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=248 (1 of 2) [18/02/2004 14:50:38]

Helpful

Unfulfilling

rate

Tip #248 - Auto-save the current buffer periodically. : vim online


<<Preexisting code indentation | C/C++: Quickly insert #if 0 - #endif around block of code >>

Additional Notes
vim at tritarget.com, May 20, 2002 23:08
This is cool. However I personaly like how swap files do this for me.
By default a swap file is writen to after either 200 characters are
typed or 4 seconds of inactivity has elapsed. Since a swap file writes
faster and updates sooner a recovery is quite simple and sometimes
more reliable if something goes wrong.
This is just my personal preference. Some may like the physical auto
saving as opposed to swap file recovery. Word for example uses both
methods by default. (Yes, I know bad example! Please no flames. ^_^)
salmanhalim@hotmail.com, May 22, 2002 5:55
Actually, it wasn't my intention to provide this as a mechanism
without knowing about the swap file -- am fully aware of how that
works. However, someone had asked about this on the Vim email list
and since I posted a longish answer there, I decided to make a tip out
of it also.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=248 (2 of 2) [18/02/2004 14:50:38]

SourceForge
Logo

Tip #249 - C/C++: Quickly insert #if 0 - #endif around block of code : vim online

not logged in (login)

Home
Search

Tip #249: C/C++: Quickly insert #if 0 - #endif around block of code
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/6, Viewed by 940

created: May 22, 2002 17:58


author: David Thompson

complexity: basic
as of Vim: 5.7

One of my favorite macros that I use in vim (and vi)


inserts a #if 0 #endif sandwich
around a block of code. I always map this to the 2 key
sequence ;' which is the
semi-colon followed by the single quote. Look at your
keyboard, you will notice
these keys are adjacent to one another. I like this
mapping because it's very fast,
my fingers easily roll from one key to the next,
obviously YMMV.
To use this mapping, go to the line of code that you
want the '#if 0' to be on, type
ma to mark this line with the marker a, then move to the
line that should be last line
just above the '#endif' and press ;'
" insert #if 0 - #endif around block of code
map ;' mz'aO<Esc>i#if 0<Esc>'zo<Esc>i#endif<Esc>
-David Thompson
dat1965@yahoo.com
rate this tip

Life Changing

Helpful

Unfulfilling

<<Auto-save the current buffer periodically. | One big window >>

Additional Notes
nospam@nospam.org, May 23, 2002 3:05
Clever~ :-)
pottsdl@netzero.net, May 23, 2002 4:59

http://www.vim.org/tips/tip.php?tip_id=249 (1 of 2) [18/02/2004 14:50:40]

rate

Tip #249 - C/C++: Quickly insert #if 0 - #endif around block of code : vim online

You could also modify this just a bit and make it a


vmap, that way you
wouldn't need to mark the beginning of the line set
(though not vi compatible).
vmap ;' '<O<Esc>i#if 0<Esc>'>o<Esc>i#endif<Esc>
nospam2@nospam.org, May 23, 2002 14:26
1. What about removing '#if 0...' ? It should be easy
to do.
2. I like to do this with a range argument as well "3;'" in your case.
3. However, you get all this with various schemes for
commenting/uncommenting code...
svickers@iteamsolutions-dot-com, October 18, 2002 11:06
A very handy tip indeed... I tweaked it a bit by using
0<C-D> (instead of <Esc>i) and made a version for Perl
by replacing '#if 0' with '=pod' and '#endif' with
'=cut'.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=249 (2 of 2) [18/02/2004 14:50:40]

SourceForge
Logo

Tip #250 - One big window : vim online

not logged in (login)

Home
Search

Tip #250: One big window


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 31/15, Viewed by 1726

created: May 23, 2002 6:40


author: Kontra Gergely

complexity: basic
as of Vim: 5.7

If you like to see your files in fullscreen, and you


have to edit more files, you can do the following.
* Use only one window
* Open further files with :e
* type :nm <A-Up> :bp!<CR>
* type :nm <A-Down> :bn!<CR>
* type :nm <C-F4> :bd!<CR>
You can of course change the keys.
Now to switch between windows, you can press Alt-Up, and
Alt-Down
(Just in the GUI, if you use console, don't use Alt key)
Another idea is to map them to Ctrl-Tab, and Ctrl-ShiftTab
To close the current file you can press Ctrl-F4
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<C/C++: Quickly insert #if 0 - #endif around block of code | c/c++: align #endif with corresponding
#if/#ifdef >>

Additional Notes
Anonymous, May 23, 2002 7:47
When I say type, I mean put it into your .vimrc of
course
Anonymous, May 23, 2002 19:37
Should the 'hidden' option be set for this to work?
Sitar@procaut.sk, May 27, 2002 6:07
Consider using :bwipeout instead of :bd
see :help bd

http://www.vim.org/tips/tip.php?tip_id=250 (1 of 2) [18/02/2004 14:50:42]

Tip #250 - One big window : vim online

alinets@yahoo, June 11, 2002 8:23


For some odd reason A-Up and A-Down was not working for
me.
I think C-Left and C-Right are also a nice combination
Gergely Kontra, June 12, 2002 6:57
Yes, all the Alt combinations are problematical and
works only in the GUI.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=250 (2 of 2) [18/02/2004 14:50:42]

SourceForge
Logo

Tip #251 - c/c++: align #endif with corresponding #if/#ifdef : vim online

not logged in (login)

Home
Search

Tip #251: c/c++: align #endif with corresponding #if/#ifdef


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/2, Viewed by 682

created: May 24, 2002 14:28


author: Kartik Agaram

complexity: basic
as of Vim: 5.7

If you try to impose any sort of alignment on your


preprocessor directives, rather than just starting them on
column 0, this mapping will align the #endif 'correctly'
when you type '#en', start a new line, and bring you back
to the correct alignment to edit code.
inoremap <buffer> #en
X<BS><Esc>?#if<CR>"zy0^Og0"zpDa#endif<CR>X<BS><Esc>?#end?1<CR>^"zy0^O0"zpDa
I am reasonably sure this is insensitive to vim options...
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<One big window | python script to align statements >>

Additional Notes
Kartik, October 24, 2002 23:34
This tip is currently at -1/1 - I'm not sure why, since
I use it a lot. In any case, here's an updated version
that handles nested #if blocks.
inoremap #en #endif<Esc>bbd0%y0<C-o>0PA
I've stopped positioning the cursor on the next line
because I found myself doing <Esc>dd too often.
In a perfect world, we wouldn't have to deal with code
with such a high density of preprocessor directives as
to make indenting them, and therefore this tip, useful.
Add Note

http://www.vim.org/tips/tip.php?tip_id=251 (1 of 2) [18/02/2004 14:50:44]

Tip #251 - c/c++: align #endif with corresponding #if/#ifdef : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=251 (2 of 2) [18/02/2004 14:50:44]

SourceForge
Logo

Tip #252 - python script to align statements : vim online

not logged in (login)

Home
Search

Tip #252: python script to align statements


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/1, Viewed by 796

created: May 24, 2002 23:55


author: Demian L. Neidetcher

complexity: intermediate
as of Vim: 5.7

i know there's some awk scripts out there that do the


same thing, and if i were a real trooper i would have
written this in vims internal language but...
i wrote a python script to align statements.
i put this in my .vimrc:
map L :!lineUp.py<cr>
" of course lineUp.py is
somewhere in my path
and i have this python file somewhere in my path:
http://ophinity.com/res/dotFiles/lineUp.py
so now i can just pipe the offending lines thru my code:
:5, 10 !lineUp.py
or using the mapping above, visually select the lines
and press 'L'

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<c/c++: align #endif with corresponding #if/#ifdef | The power of | (v75|r- actually...) >>

Additional Notes
jmcpherson@softhome.net, May 28, 2002 12:56
This is a neat idea (and I do like Python), but why not
use vimscript #176? It has more features and is native
vim so you don't have the overhead of the Python
interpreter.
demian 0311 at yah00 d0t c0m, June 2, 2002 13:46

http://www.vim.org/tips/tip.php?tip_id=252 (1 of 2) [18/02/2004 14:50:47]

Tip #252 - python script to align statements : vim online

i had trouble getting the other line-up thing to work,


probably some issue between my chair and my
keyboard. i didn't feel like hunting down the problem
so i just wrote it in python.
in an effort to prove to everyone how lazy i am, i
wrote a couple other helpful code-wrangling python
scripts that tie in nicely with vim, i have them pretty
well documented at:
http://www.ophinity.com/code/wrangling/index.html
...the additional scripts provide for a simple
templating mechanism for multiplying code (hey i coined
a phrase) as well as some scripts to go back and forth
between DB_SCHEMA_NAMING_CONVENTIONS and
JavaNamingConventions.
anyone think i should post those as a tip?

script?

ekw@backgam.com, July 22, 2003 15:57


the www.ophinity.com URLs don't work.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=252 (2 of 2) [18/02/2004 14:50:47]

SourceForge
Logo

Tip #253 - The power of | (v75|r- actually...) : vim online

not logged in (login)

Home
Search

Tip #253: The power of | (v75|r- actually...)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 17/8, Viewed by 1390

created: May 26, 2002 8:20


author: RobertKellyIV

complexity: basic
as of Vim: 6.0

'|' as you may well be aware is the goto column motion,


and that "75|" will place your cursor on column 75 of
the current line.
That in itself is pretty handy at times, but some true
power arises when used in conjuction with visual mode
and replace. Or you could just say a sneaky trick :)
v75|rwill repace from the cursor to the end of line with '-'
*breakdown*
v to turn on visual mode
75 for the count
| *bar* to goto column
r to enter repace
- to specify the char to replace.
A handy and quick way to make a noticable section of
your code (or whatever).
A handy way to use this (formated to just drop into
DrChip's CStubs):
"// -[Feral]-------------------------------------------------------------"// <cursor>
elseif wrd == "//"
exe "norm! a -[AuthorId]\<esc>$lv75|r-$a\<cr>\<esc>$a "
"// -[Feral:146/02@08:31]------------------------------------------------"// <cursor>
elseif wrd == "///"
exe "norm! s -[AuthorId:\<CR>=strftime('%j/%y@%H:%M')\<CR>]\<esc>$lv75|r$a\<cr>\<esc>$a "
"/* -[Feral:146/02@08:31]-------------------------------------------------

http://www.vim.org/tips/tip.php?tip_id=253 (1 of 5) [18/02/2004 14:50:50]

Tip #253 - The power of | (v75|r- actually...) : vim online

" * <cursor>
" * ------------------------------------------------------------------- */
elseif wrd == "/*"
exe "norm! a -[AuthorId:\<CR>=strftime('%j/%y@%H:%M')\<CR>]\<esc>$lv75|r$a\<cr>\<cr>\<esc>2lv72|r-$a */\<esc>k$a "
Have to love VIM!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<python script to align statements | Using \%[] to easily match parts of a word. >>

Additional Notes
Anonymous, May 26, 2002 17:03
Very nice feature.
Additional question:
How can I move the "bar" in
foo bar
to column 30?
O.K., I can think of several ways to do that, but I'd
like to do that without thinking about how many spaces
or shiftwidths I might need. I'd love to know a command
"move everything after the cursor to column [count]".
RobertKellyIV <feral@firetop.com>, May 26, 2002 20:18
That is also quite easy to do as it turns out. "move
everything after the cursor to column [count]". equates
to:
d$30|p
*breakdown*
d$ to del to end of line (into unnamed register)
30| to place cursor on column 30
p to paste unnamed register.
I.e.
http://www.vim.org/tips/tip.php?tip_id=253 (2 of 5) [18/02/2004 14:50:50]

Tip #253 - The power of | (v75|r- actually...) : vim online

Before:
int foo = bar;
<place cursor where desired (on b of bar)>
d$30|p
Becomes:
int foo =

bar;

VIM is neat :)
Anonymous, May 26, 2002 21:33
This tip made no sense to me until I ":set
virtualedit=all", so if it's not working for you, try
that.
Anonymous, May 27, 2002 1:02
Thanks Robert, it works great.
Anonymous, May 27, 2002 2:37
for some reason | wont go beyond the newline character
and is completely meaningless on an empty line.
so I just do "75i-<esc>"
RobertKellyIV <feral@firetop.com>, May 27, 2002 10:47
That should be because (as Anonymous, May 26, 2002
21:33) mentioned,
:set virtualedit=all
Is needed (opoligies for forgetting to mention that..)
The `problem` with just 75i-<esc> is that it will inset
75 chars(or strings as case may be) regardless of what
column you are in. So, to trim the line at column 75
you would need to add 75|D (goto column 75 and delete
to end of line).
There is an advantage to doing things that way however,
one it works regardless of how you have virtualedit set
(I have a hard time fathoming it being anything but all
personally ;) ) but you can also specify a string to
repeate, thus "=-=-=-=-=-=-=-=-=-=-=-" or some such is
possible (75i=-<esc>75|D)
The same idea holds true for positioning the rest of a
line at a specific column:
//place cursor on start of word you want at column
30i <esc>30|dw
http://www.vim.org/tips/tip.php?tip_id=253 (3 of 5) [18/02/2004 14:50:50]

Tip #253 - The power of | (v75|r- actually...) : vim online

(goto column 30 and delete word (i.e. the extra spaces)


)
Happy VIMing! (=
Anonymous, May 27, 2002 20:53
A nice tip. Now, it would be better if I could set a
default count for the '|' command; something like
:set defaultbarcolumn=75
Anonymous, May 29, 2002 10:30
Is there a way to use this to align variable
declarations?
Say I have three spaces then the variable name then
some unknown number of spaces and the type information.
If I want to align all the type information at column
20, how would I do that?
I essentially need to eliminate the leading whitespace
before pasting I think...
RobertKellyIV <feral@firetop.com>, May 30, 2002 2:35
Sort of messy but given:
varname typeinfo
varname typeinfo
varname

typeinfo

0weldw20i <esc>20|dw
on each line will result in:
varname
varname
varname

typeinfo
typeinfo
typeinfo

*breakdown*
0 = start of line, column 0
wel = place cursor one char past first word (var name)
dw = delete spaces to next word (type definition)
20i <esc> = instert 20 spaces.
20|dw = goto column 20 and delete the spaces from here
to next word (type definition)
RobertKellyIV <feral@firetop.com>, May 30, 2002 2:40

http://www.vim.org/tips/tip.php?tip_id=253 (4 of 5) [18/02/2004 14:50:50]

Tip #253 - The power of | (v75|r- actually...) : vim online

*note to self* this forum no like tabs.


Imagine the first two entries under given to look like:
varname
varname
varname

typeinfo
typeinfo
typeinfo

Or some such, as long as there is one space between


varname and typeinfo the above method should work.
Sreny@SverGbc.Pbz (Rot13ed), July 6, 2003 21:57
See also, vimscript #686 , which is: feralalign.vim :
Simple script to save you from "ciw<tab><tab><tab>" to
align text.
Which is relevant to the alignment of variables
question/answer above.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=253 (5 of 5) [18/02/2004 14:50:50]

SourceForge
Logo

Tip #254 - Using \%[] to easily match parts of a word. : vim online

not logged in (login)

Home
Search

Tip #254: Using \%[] to easily match parts of a word.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 8/7, Viewed by 845

created: May 30, 2002 7:22


author: RobertKellyIV

complexity: basic
as of Vim: 6.0

This code fragment is suitable to drop into DrChip's


CStubs.
After much searching I was unable to find a tip nor script
number to referance, I believe where I found Dr. Chip's
CStubs originally :
http://users.erols.com/astronaut/vim/vimscript/drcstubs.vim
Thank you Dr. Chip! (=

Site Help

If you have ever wanted to match parts of a word you may


have considered something like:
if wrd == "re" || wrd == "ret" || wrd == "retu" || wrd ==
"retur"
"do something
Althought the above works well enough it is a pain to
maintain and add new words (not to mention its just a touch
messy ;) )
A more elegant (and easier to use I believe) method would
be to use \%[] as part of a pattern.
For instance, "\\<re\\%[tur]\\>" will match "re", "ret",
"retu" or "retur"
*breakdown*
\\< = start of word
re = first letters of word we want to require to match
\\%[tur] = optionally match chars bewteen the braces, i.e.
't', 'tu' or 'tur'
\\> = end of word
So, we can use this as a pattern for match like so (In
DrChip's CStubs)
elseif match(wrd, "\\<re\\%[tur]\\>") > -1
exe "norm! bdWireturn\<Esc>"
Which, I think, is a little better than the longer
alternative:
http://www.vim.org/tips/tip.php?tip_id=254 (1 of 2) [18/02/2004 14:50:52]

Tip #254 - Using \%[] to easily match parts of a word. : vim online

" vs
elseif wrd == "re" || wrd == "ret" || wrd == "retu" || wrd
== "retur"
exe "norm! bdWireturn\<Esc>"
Just another one of those VIM things that made me smile :)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<The power of | (v75|r- actually...) | arbitrary tags for file names >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=254 (2 of 2) [18/02/2004 14:50:52]

SourceForge
Logo

Tip #255 - arbitrary tags for file names : vim online

not logged in (login)

Home
Search

Tip #255: arbitrary tags for file names


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/1, Viewed by 626

created: June 4, 2002 22:24


author: Travis

complexity: basic
as of Vim: 5.7

This definitely work on linux and there is probably some


windows equivalent.
I've started working with tomcat and many many .jsp
files. I find this trick to be very helpful.
find -name '*.jsp' -printf '%f\t%P\t1\n' |sort >
jsp.tags
This will create a file called jsp.tags with tag entries
for each .jsp file. Within Vim I use
:set tags+=jsp.tags
Now I can to simple :tag file.jsp to quickly switch b/w
the many, many .jsp files.
One important
of LC_COLLATE
locale. This
"LC_COLLATE=C
rate this tip

note. The utility sort will use the value


to sort according to your
will give Vim issues. So try
sort" instead of plain "sort"

Life Changing

Helpful

Unfulfilling

rate

<<Using \%[] to easily match parts of a word. | Opening current Vim file in your Windows browser >>

Additional Notes
Mark Hillebrand, June 4, 2002 23:10

http://www.vim.org/tips/tip.php?tip_id=255 (1 of 2) [18/02/2004 14:50:54]

Tip #255 - arbitrary tags for file names : vim online

There's also the :find command and the path-option,


with which one can easily switch between files in
arbitrary directories.
For example, if one sets
:set path+=/usr/include
on a Unix system one can do ":find stdio.h" to jump to
the stdio-header file.
Recursive search is also possible by using the doublestar:
:set path+=./**
Vim will :find any file under the current sub
directory.
Use :sfind (split find) to open the file in a new
window.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=255 (2 of 2) [18/02/2004 14:50:54]

SourceForge
Logo

Tip #256 - Opening current Vim file in your Windows browser : vim online

not logged in (login)

Home
Search

Tip #256: Opening current Vim file in your Windows browser


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 8/5, Viewed by 992

created: June 6, 2002 13:36


author: David John Rayner (zzapper)

complexity: basic
as of Vim: 5.7

Hi Vimmers
open current file in browser
map ,f
:update<CR>:silent !start
c:\progra~1\intern~1\iexplore.exe file://%:p<CR>
open http link under cursor in your browser

Site Help

map ,i
:update<CR>: !start
c:\progra~1\intern~1\iexplore.exe <cWORD><CR>
Note use of cWORD (not cword) meaning OUTER Word
Works for me in XP & 98
(Original came from a posting by Ralf Arens)
zzapper
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<arbitrary tags for file names | fast page up/down. >>

Additional Notes
Anonymous, June 6, 2002 13:42
If your windows browser is set up correctly, you will
probably be able to get away with these instead.
map ,f
map ,i

:update<CR>:silent !start %:p<CR>


:update<CR>: !start <cWORD><CR>

This way, it should open in whatever the current


browser is, whether it be Nutscape, Internet Exploder,
Bloatzilla, etc.
http://www.vim.org/tips/tip.php?tip_id=256 (1 of 2) [18/02/2004 14:50:56]

Tip #256 - Opening current Vim file in your Windows browser : vim online

Anonymous, June 7, 2002 10:58


Something corresponding for unix ppl:
function! Browser ()
let line = getline (".")
let line = matchstr (line, "http[^ ]*")
execute "!opera ".line
endfunction
map <Leader>w :call Browser ()<CR>
This needs a browser that can send URLs from the
commandline to an existing process.
Anonymous, June 7, 2002 19:00
Oops, the above function for unix will open a browser
with the URL in the current line. Not quite what this
tip is about...
Anonymous, June 12, 2002 7:06
With gvim 6.0 on XP, I am getting the error msg: E371:
Command not found.
It seems to be complaining about the !Start command.
imran_k01(at)hotmail.com, August 4, 2002 22:16
Anyone know how to make the file open in a currently
open browser?
robertx2@speakeasy.net, March 16, 2003 11:28
re: open http link under cursor ...
On Windows, using cWORD to open a link in a browser
window does not work when the URL is in an html tag
surrounded by quotes. But using cfile instead works for
both situations - plain URL and html tag URL ...
map ,i
:update<CR>: !start
c:\progra~1\intern~1\iexplore.exe <cfile><CR>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=256 (2 of 2) [18/02/2004 14:50:56]

SourceForge
Logo

Tip #257 - fast page up/down. : vim online

not logged in (login)

Home
Search

Tip #257: fast page up/down.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 2/17, Viewed by 1054

created: June 7, 2002 0:58


author: marius ursache

complexity: basic
as of Vim: 6.0

i discovered a cool way to move between pages of the


same document in vim 6.1. press a number in -normal modeand the page up/down. the document will move with that
number of pages up/down.if the number is greater that
the nr of pages, document will move to begin/end of
file.
i didn't test it on other version.

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Opening current Vim file in your Windows browser | how long is the current word? >>

Additional Notes
Anonymous, June 14, 2002 9:41
Pressing any number 'n' followed by any command will
repeat the command 'n' times. This is pretty clearly
covered in the tutorial . . .
marius@ee.utt.ro, June 17, 2002 9:22
i read it after i wrote the tip :)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=257 [18/02/2004 14:50:58]

SourceForge
Logo

Tip #258 - how long is the current word? : vim online

not logged in (login)

Home
Search

Tip #258: how long is the current word?


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating 8/5, Viewed by 899

created: June 10, 2002 9:05


author: colin dearing

complexity: intermediate
as of Vim: 6.0

ever wondered how long the current word is?


quite useful when editing data files.
simply add the following to your .vimrc

this can be

Scripts
Tips
My Account

nmap <C-_> :echo 'word' expand("<cword>") '


strlen(expand("<cword>"))<CR>

wordlen ='

Site Help

and it will tell you the word under the cursor, and how
long it is.
and for things that arent words, this addition to your
.vimrc works on sections of a line that have been
hightligted in visual mode
vmap <C-_> "-y:echo 'word' @- '
)<CR>

wordlen =' strlen(@-

again you see the "word", and its length


this may also work on vim 5.x, but i havent checked to
make sure.
rate this tip

Life Changing

Helpful

Unfulfilling

<<fast page up/down. | removing the toolbar (icons) from gvim >>

Additional Notes
SBrueggemann@gmx.net, June 11, 2002 1:51

http://www.vim.org/tips/tip.php?tip_id=258 (1 of 2) [18/02/2004 14:51:00]

rate

Tip #258 - how long is the current word? : vim online

If showcmd is set, viw also shows the length of the


current word.
v - start visual mode per character
iw - select inner word
Kind regards
Sven
Anonymous, June 11, 2002 4:17
well i didnt know that.

live and learn :)

colin
Anonymous, June 11, 2002 4:23
trying this, i have just remembered why i never
discovered this. running vim 6 in a terminal emulator,
showcmd slows down screen redraws considerably. so
normally i have ruler, status bar, etc all turned off,
to increase scrolling and redraw speed.
Colin
jc_cann@yahoo.com, April 21, 2003 6:26
I tried this nmap command in vim 5.3 and it
works. Thanks for the tip, it's been useful for me.
Jeff
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=258 (2 of 2) [18/02/2004 14:51:00]

SourceForge
Logo

Tip #259 - removing the toolbar (icons) from gvim : vim online

not logged in (login)

Home
Search

Tip #259: removing the toolbar (icons) from gvim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/9, Viewed by 1010

created: June 12, 2002 18:52


author: Ali Rizvi

complexity: basic
as of Vim: 6.0

Change good or bad usually encounters interia from


people in excepting it.
gvim 6.0 is the first version that introduced the icons
shortcut in shape of a toolbar under the menu.
when we upgraded to the new and improved vim 6.1 from
vim 5.7 some of people in our company encountered some
problems with their syntax highlighting
and some of them objected on the new toolbar which
displayed icons for some common tasks for people more
used to GUI.
I finally figured out how to remove this new feature
since I also didn't see much use for it
Here is for all those who haven't figured it out yet
In your .gvimrc include the following two lines
unmenu ToolBar
unmenu! ToolBar
Doing this from an open gvim does not remove them but
grays them out but doing from gvimrc does the job
I was also trying to remove the menus at the top and
almost succeeded with a similar technique but somehow
the Buffer menu item stays there no matter what. IMHO it
is a bug but it could very well be a feature ;)
I tried this
unmenu *
unmenu! *
even added this line after the above two but didn't help
unmenu Buffers
I hope this benefits you all as much as I have
benefitted from all your tips

http://www.vim.org/tips/tip.php?tip_id=259 (1 of 3) [18/02/2004 14:51:03]

Tip #259 - removing the toolbar (icons) from gvim : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<how long is the current word? | gvim-->mouse-->popup menu >>

Additional Notes
salmanhalim@hotmail.com, June 12, 2002 19:13
So how about just doing the following:
:set guioptions-=T
This causes the toolbar to not show.
have it.)

(This is how I

salmanhalim@hotmail.com, June 12, 2002 19:15


Similarly,
:set guioptions-=m
or -=M (more extreme solution, I think) works quite
well for hiding the menus.
Perhaps a more general :help 'guioptions' should be
suggested? *grin*
tomk@emcity.net, July 29, 2002 13:19
As I posted in another thread on hiding the toolbar,
this will make the toolbar/menu toggleable:
set guioptions-=T "get rid of toolbar
:let g:toggleTool = 0
map <silent> <S-F1> :if g:toggleTool == 1<CR>:set
guioptions-=T<CR>:let g:toggleTool = 0<CR>:else<CR>:set
guioptions+=T<CR>:let g:toggleTool = 1<CR>:endif<CR>
"
set guioptions-=m "get rid of menu
:let g:toggleMenu = 0
map <silent> <S-F2> :if g:toggleMenu == 1<CR>:set
guioptions-=m<CR>:let g:toggleMenu = 0<CR>:else<CR>:set
guioptions+=m<CR>:let g:toggleMenu = 1<CR>:endif<CR>
Tom Kimpton
emailgopi@n0spam.netscape.net, August 27, 2003 8:10

http://www.vim.org/tips/tip.php?tip_id=259 (2 of 3) [18/02/2004 14:51:03]

Tip #259 - removing the toolbar (icons) from gvim : vim online

Just wanted to add that removing the toolbars and the


menu improves responsiveness when using gvim under X11
over a remote connection. For some reason certain
operations (like say :diffupdate) causes the X11 server
to spend huge amounts of time refreshing the toolbars
and the menus over a remote connection.
hashstat at eudoramail dot com, October 29, 2003 7:43
I found that toggling the menubar using Tom's script
(above) ate up one line each time (using Andale Mono
font). Below is a modified version of that script
which adjusts the number of lines displayed as the
menubar and toolbar are toggled, keeping the GVim
window at a more uniform size.
"
get rid of menu
set guioptions-=m
:let g:toggleMenu = 0
map <silent> <S-F1> :if g:toggleMenu == 1<CR>:set
guioptions-=m<CR>:set lines+=1<CR>:let g:toggleMenu =
0<CR>:else<CR>:set guioptions+=m<CR>:let g:toggleMenu =
1<CR>:endif<CR>
"
get rid of toolbar
set guioptions-=T
:let g:toggleTool = 0
map <silent> <S-F2> :if g:toggleTool == 1<CR>:set
guioptions-=T<CR>:set lines+=3<CR>:let g:toggleTool =
0<CR>:else<CR>:set lines-=3<CR>:set
guioptions+=T<CR>:let g:toggleTool = 1<CR>:endif<CR>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=259 (3 of 3) [18/02/2004 14:51:03]

SourceForge
Logo

Tip #260 - gvim-->mouse-->popup menu : vim online

not logged in (login)

Home
Search

Tip #260: gvim-->mouse-->popup menu


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 27/18, Viewed by 1183

created: June 13, 2002 0:36


author: ncr

complexity: basic
as of Vim: 6.0

This tip is for those who prefer to do some of the


common
operations like cut/copy/paste etc using mouse. All u
have to do is
:set mousemodel=popup
by this u get a popup menu on right click of your mouse
and u can
do all the common operations like undo, cut, copy,
paste, select etc
using mouse.
u can also customise your popup menu by editing
$VIMRUNTIME/menu.vim

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<removing the toolbar (icons) from gvim | Close windows from Gvim poup menu >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=260 [18/02/2004 14:51:05]

SourceForge
Logo

Tip #261 - Close windows from Gvim poup menu : vim online

not logged in (login)

Home
Search

Tip #261: Close windows from Gvim poup menu


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/10, Viewed by 650

created: June 13, 2002 2:15


author: sean

complexity: basic
as of Vim: 6.0

To close windows from the popup menu add these lines to


your .gvimrc
:amenu PopUp.Close.\ Window :confirm close<CR>
:amenu PopUp.Close.\ Other :confirm only<CR>
You obviously need ':set mousemodel=popup' in your
.gvimrc as well :=)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<gvim-->mouse-->popup menu | Bored of ur arrow shapped mouseptr? >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=261 [18/02/2004 14:51:07]

SourceForge
Logo

Tip #262 - Bored of ur arrow shapped mouseptr? : vim online

not logged in (login)

Home
Search

Tip #262: Bored of ur arrow shapped mouseptr?


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/10, Viewed by 1141

created: June 13, 2002 22:44


author: ncr

complexity: basic
as of Vim: 6.0

here is how u can change the shape of ur mouseptr in


gvim.
:set mouseshape=n:pencil
this will change the shape of the mouseptr to pencil in
normal mode.
u can choose different shapes for different modes. see
:h mouseshape
Want more shapes?
Then look for the file cursorfont.h in ur X11/
directory.
This file contains lots of cursor shape #define
definitions, like
.
#define XC_heart 62
.
now :set mouseshape=n:62 will set the shape of the
mouseptr to heart
in normal mode.
-ncr
rate this tip

Life Changing

Helpful

<<Close windows from Gvim poup menu | color active line >>

Additional Notes
Anonymous, June 14, 2002 2:02
Not available for Windows.
Anonymous, June 26, 2002 18:28
http://www.vim.org/tips/tip.php?tip_id=262 (1 of 2) [18/02/2004 14:51:10]

Unfulfilling

rate

Tip #262 - Bored of ur arrow shapped mouseptr? : vim online

Actually, only certain built-in cursors are available


in windows. Pencil doesn't work, but others do.
See
<tt>:help mouseshape</tt>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=262 (2 of 2) [18/02/2004 14:51:10]

SourceForge
Logo

Tip #263 - color active line : vim online

not logged in (login)

Home
Search

Tip #263: color active line


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 22/17, Viewed by 2303

created: June 18, 2002 7:05


author: Armin Rehm (rehm.armin@schwenk.de)

complexity: basic
as of Vim: 6.0

This tip shows how to color the active line, the line in
which the cursor is, for better reading.
You should try possibility 2 before 1, IMHO it is mostly
usable.
possibility 1:
:au! CursorHold * let @/ = '\%' . line('.') . 'l.*'
:set ut=500
explanation:
After 500 ms of waiting for you to hit a key, vim
sets the search register to a pattern that matches the
current line.
problem:
Register / holds the search pattern, so you cannot
have color the active line and search.
Therefore another solution:
possibility 2:
:highlight CurrentLine guibg=darkgrey
guifg=white
(or whatever colors you want)
:au! Cursorhold * exe 'match CurrentLine /\%' .
line('.') . 'l.*/'
:set ut=100
explanation:
This solution uses 'match' to highlight a string,
it does not interface with the current search pattern.
addition:
Turning the highlighning off:
:au! Cursorhold
:match none
The order of these commands are important. If
:match none is executed first, the autocommand would
almost immediately execute another match command.

http://www.vim.org/tips/tip.php?tip_id=263 (1 of 4) [18/02/2004 14:51:12]

Tip #263 - color active line : vim online

references
:help
:help
:help
:help
:help

to vim help:
Cursorhold
'ut'
/\%l
"/
\%

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Bored of ur arrow shapped mouseptr? | F5 Compile and Run, F8 Compile (ala Visual Studio) >>

Additional Notes
digitect (at) mindspring com, June 18, 2002 7:38
It should be noted that the CursorHold event is not
updated within insert mode. :(
richardsugg@yahoo.com, June 19, 2002 5:10
now this is cool. I really appreciated this tip. Can
anyone tell me how to make this work in insert mode as
well? Then I'll be giddy with the joy that only vim
can give me.
jonestor1976@yahoo.com, June 21, 2002 10:05
I wrote a script to do this that will work in insert
mode. By the way, it has problems if there is a
delimiter on the line that you are trying to highlight.
Press F2 to highlight a line.
Press F3 to unhighlight the line
The current version is below.
"
"
"
"
"

Vim plugin file


Description:
Maintainer: Torrin <jonestor1976@yahoo.com>
Last Change: 2002 JUN 21
Version:
2

" If we have already loaded this file, don't load it


again.
if exists("loaded_highlightline")
finish
endif
let loaded_highlightline=1

http://www.vim.org/tips/tip.php?tip_id=263 (2 of 4) [18/02/2004 14:51:12]

Tip #263 - color active line : vim online

" Save compatable options


let s:save_cpo = &cpo
set cpo&vim
let linehighlighted=0
map <F2> :call <SID>HighlightLine()<CR>
map <F3> :call <SID>UnHighlightLine()<CR>
imap <F2> <C-O>:call <SID>HighlightLine()<CR>
imap <F3> <C-O>:call <SID>UnHighlightLine()<CR>
function! s:HighlightLine()
"
execute "syntax keyword OneLine \"" . getline(".")
. "\""
if g:linehighlighted == 1
call <SID>UnHighlightLine()
endif
execute "syntax match OneLine +" . getline(".") . "+
oneline"
execute "highlight default link OneLine Visual"
let g:linehighlighted = 1
endfunction
function! s:UnHighlightLine()
if g:linehighlighted == 1
execute "syntax clear OneLine"
let g:linehighlighted = 0
endif
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
jonestor1976@yahoo.com, June 21, 2002 10:18
I've just added the script above to the archive as
vimscript #319
Have fun.
Anonymous, July 4, 2002 1:22
The tip seems to be working better than the script...
flavio [at] polettix.it, November 4, 2002 3:55
The tip does'nt work for me. I have VIM 6.1, but I'm
not using gvim - is this the problem?
TIA,
Flavio.

http://www.vim.org/tips/tip.php?tip_id=263 (3 of 4) [18/02/2004 14:51:12]

Tip #263 - color active line : vim online

dsummersl@yahoo.com, April 30, 2003 9:43


Any idea how one could get the entire ROW to be
hilighted?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=263 (4 of 4) [18/02/2004 14:51:12]

SourceForge
Logo

Tip #264 - F5 Compile and Run, F8 Compile (ala Visual Studio) : vim online

not logged in (login)

Home
Search

Tip #264: F5 Compile and Run, F8 Compile (ala Visual Studio)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 8/11, Viewed by 1899

created: June 22, 2002 9:18


author: Tadghe Danu

complexity: basic
as of Vim: 6.0

I love vim, it's my default editor on my Sun, Windows,


Linux and *BSD boxen. That said, I hate having to flip
windows to compile while doing the write->compile->debug
loop.
If you're used to Visual Studio and the ability it has
to just hit F5 to compile and run the current file or F8
to compile or step through the code you'll appreciate
this...
This is my Windows version of this scriplet/tiplet. For
other platforms, you'll want to change the IF ELSE
loops. You should actually never see the "Unsuccessful"
message from the compile/run loop unless the compiler
completely bombs out.
This is from my _vimrc...
map <F5> :call CompileRunGcc()<CR>
map <F8> : call CompileGcc()<CR>
func! CompileRunGcc()
exec "w"
"Save the file
exec "!gcc % -o %< && cr 10 && IF EXIST %<.exe (%<) ELSE
banner -c = Compile Unsuccessful "
exec "i" "jump back where we were
endfunc
func! CompileGcc()
exec "w"
exec "!gcc % -o %< && IF EXIST %<.exe (cr 5 && banner c # Success) ELSE banner -c # Compile Unsuccessful "
exec "i"
endfunc

http://www.vim.org/tips/tip.php?tip_id=264 (1 of 3) [18/02/2004 14:51:16]

Tip #264 - F5 Compile and Run, F8 Compile (ala Visual Studio) : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<color active line | Fast help in full window >>

Additional Notes
matt@mh.dropbear.id.au, June 23, 2002 23:33
You might like to take a look at vim's quickfix mode.
:help quickfix
Also, on unix systems one setup I used for a while (and
still have, though I'm more often than not using gvim
now) involves running vim from within screen, then you
simply have to double-tap ctrl-a to get a shell window.
$ xterm -name VIM -geometry 132x60 -e screen vim
I especially like this method for editing HTML/XML/TeX
etc where the post-edit operation isn't a compile, but
something like moving files around, rsync, or whatever.
mathew_spamcan@yahoo.com.au, January 28, 2003 1:48
You can also use the :make command.
ou can set the variable makeprg variable if required,
eg I use
set makeprg=gmake\ -j
Parallel build with gnu make.
:make will accept the target name as an option.
The limits are that it does not do a save. I would
MUCH prefer
is ran make in the background somehow too.
libberspam@atlaswebmail.com, February 8, 2003 11:12
hi, under unix this is what i got to compile and run my
program. i would imagine make would be a much better
solution for big projects but for small single file
projects this works great

map <F5> :call CompileRunGcc()<CR>


func! CompileRunGcc()
exec "w"
exec "!gcc % -o %<"
exec "! ./%<"

http://www.vim.org/tips/tip.php?tip_id=264 (2 of 3) [18/02/2004 14:51:16]

Tip #264 - F5 Compile and Run, F8 Compile (ala Visual Studio) : vim online

endfunc
olbyun@hotmail.com, March 20, 2003 3:27
You might want to compile your file when you're in
insert mode.
lmap makes your mapping available in every situation in
vi.
For detailed information, please refer to
:help map.txt
olbyun@hotmail.com, March 20, 2003 3:32
Some reason lmap doesn't work as expected in my
vim/xf86/cygwin/w2k
map! should work.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=264 (3 of 3) [18/02/2004 14:51:16]

SourceForge
Logo

Tip #265 - Fast help in full window : vim online

not logged in (login)

Home
Search

Tip #265: Fast help in full window


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 3/6, Viewed by 735

created: June 22, 2002 12:25


author: Mikolaj Machowski

complexity: basic
as of Vim: 6.0

You can get fast access to help by writing small script


#!/bin/bash
vim -c "help $1" -c only
now name it eg. vih and from cl
$ vih makeprg

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<F5 Compile and Run, F8 Compile (ala Visual Studio) | use -S command line switch >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=265 [18/02/2004 14:51:18]

SourceForge
Logo

Tip #266 - use -S command line switch : vim online

not logged in (login)

Home
Search

Tip #266: use -S command line switch


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/4, Viewed by 786

created: June 26, 2002 23:31


author: Max Ischenko

complexity: basic
as of Vim: 6.0

The -S switch could be used to simplify common idiom:


start Vim and source a script file:
gvim -c ":so foobar.vim" got translated into gvim -S
foobar.vim
Yes, this tip is trivial but I still see the -c ":so x"
way too often. Time to update your mind!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Fast help in full window | selectively displaying abbreviations >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=266 [18/02/2004 14:51:21]

SourceForge
Logo

Tip #267 - selectively displaying abbreviations : vim online

not logged in (login)

Home
Search

Tip #267: selectively displaying abbreviations


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/7, Viewed by 583

created: June 27, 2002 6:42


author: zzapper

complexity: basic
as of Vim: 5.7

Hi Vimmers,
abbreviations have always been one of the most useful parts
of vi(m), trouble is when you've got too many you forgot
what you called them.
You can of course list the whole lot with
:ab<cr>
But did you know that you can type the first few letters of
your abbreviations and get a list of just thos abs eg
:ab php<cr>
gives me all my php abs
&
:ab perl<cr>
gives me all my perls
also try control-D instrad of <cr>
zzapper

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<use -S command line switch | Get cursor position as byte percentage instead of line percentage >>

Additional Notes
david@tvis.co.uk, June 28, 2002 4:45

http://www.vim.org/tips/tip.php?tip_id=267 (1 of 2) [18/02/2004 14:51:23]

Tip #267 - selectively displaying abbreviations : vim online

Hi Just found out that it works for maps as well


eg all my maps beginning with a comma
:map ,
displays
,z
:redir @*|sil exec
'g@<\(input\|select\|textarea\|/\=form\)\>@p
'|redir END<CR>
,y
"yyy@y<CR>
,x

:%s#<script\_.*/script>#<script>^M</script>#g
,v
:e $VIM/_vimrc
,s
:source $VIM/_vimrc
,r
:redir! > c:/aaa/xxx
,i
:update<CR>: !start
c:\progra~1\intern~1\iexplore.exe <cWORD><C
R>
,f
:update<CR>:silent !start
c:\progra~1\intern~1\iexplore.exe fil
e://%:p<CR>
,c
c/["'<;)]<CR>
v ,h
"zda<h1><C-R>z</h1> <Esc>2F>
Anonymous, July 20, 2002 11:32
You can use Tab- and Ctrl-D-completion on the vim
commandline for just about everything. Play around.
Commands, filenames, maps, abbreviations, buffernames and
whatnot. It's context sensitive, so it completes the right
thing at the right place. Extraordinarily useful and an
extreme speed boost.
-Regards,
A.P.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=267 (2 of 2) [18/02/2004 14:51:23]

SourceForge
Logo

Tip #268 - Get cursor position as byte percentage instead of line percentage : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #268: Get cursor position as byte percentage instead of line


percentage
tip karma

Rating 5/9, Viewed by 647

created: June 27, 2002 7:16


author: Larry Clapp

complexity: intermediate
as of Vim: 5.7

On line 300 of a thousand line file, Vim will show you


that you're 30% through the file. But what if most of
the lines have one character in them, and some of them
have twenty thousand? Sometimes it comes in handy to
know your percentage through the file in terms of
current-byte / total-bytes. I looked through the Vim
docs and couldn't find a way to do this, so I wrote a
Vim function to show it.
Put this in your .vimrc:
function! Percent()
let byte = line2byte( line( "." ) ) + col( "." ) - 1
let size = (line2byte( line( "$" ) + 1 ) - 1)
" return byte . " " . size . " " . (byte * 100) /
size
return (byte * 100) / size
endfunction
(Uncomment the first return to see intermediate values.)
And put this somewhere in your "set statusline=...":
%{Percent()}%%
See "help statusline", "help eval".
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<selectively displaying abbreviations | Syntax highlighting is "out of sync", seems to correct itself with
refresh ?? >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=268 (1 of 2) [18/02/2004 14:51:25]

Tip #268 - Get cursor position as byte percentage instead of line percentage : vim online

antoine.mechelynck@belgacom.net, July 25, 2002 17:29


Here is a variation on the same theme. (Sorry Larry, I
would have written to you first if I'd had your addy.)
Add this to your .vimrc, then type :HowFar or :HF to
display "Byte aaaa of bbbbb (xx%)" on the bottom line.
Note: The command! statement is one long line.
-- Tony Mechelynck < antoine.mechelynck@belgacom.net >
function! BytePercent()
let CurByte = line2byte (line ( "." ) ) + col ( "." ) 1
let TotBytes = line2byte( line( "$" ) + 1) - 1
return ( CurByte * 100 ) / TotBytes
endfunction
command! -nargs=0 -bar HowFar echo "Byte " . (
line2byte( line( "." ) ) + col( "." ) - 1 ) . " of " .
( line2byte( line( "$" ) + 1 ) - 1 ) . " (" .
BytePercent() . "%)"
cnoreabbrev HF HowFar
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=268 (2 of 2) [18/02/2004 14:51:25]

SourceForge
Logo

Tip #269 - Syntax highlighting is "out of sync", seems to correct itself with refresh ?? : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #269: Syntax highlighting is "out of sync", seems to correct itself


with refresh ??
tip karma

Rating 39/17, Viewed by 1395

created: June 28, 2002 5:21


author: Douglas Potts

complexity: basic
as of Vim: 5.7

This one has come across the 'vim' users mailing list
many times, and probably
comp.editors as well...
Summary:
see :help :syn-sync
and search for 'sync' in your favorite syntax file in
$VIMRUNTIME/syntax
Long Version:
The syntax highlight code utilizes a certain
synchronization method to efficiently
figure out syntax highlighting, specifically if you
aren't at the very beginning or
end of a file. The specific setting is 'syntax
sync'. For various file types the
method is set by default in this is setup in the syntax
file and one can vary
the degree of trouble which VIM goes to to try and
figure this out. As an example
for C, from $VIMRUNTIME/syntax/c.vim:
if exists("c_minlines")
let b:c_minlines = c_minlines
else
if !exists("c_no_if0")
let b:c_minlines = 50 " #if 0 constructs can be long
else
let b:c_minlines = 15 " mostly for () constructs
endif
endif
exec "syn sync ccomment cComment minlines=" .
b:c_minlines
Where c_minlines is the minimum number of lines that VIM
goes backward
to try to find the start of a comment for syntax

http://www.vim.org/tips/tip.php?tip_id=269 (1 of 2) [18/02/2004 14:51:28]

Tip #269 - Syntax highlighting is "out of sync", seems to correct itself with refresh ?? : vim online

highlighting. If that line which


starts a comment is outside of that range, highlighting
will appear wrong.
You can easily set up something like this in your
.vimrc:
let c_minlines=500
or even bigger, but realize that it is a performance
trade-off and that
syntax highlighting will slow things down.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Get cursor position as byte percentage instead of line percentage | Insert a single character >>

Additional Notes
Robert (MetaCosm), April 14, 2003 8:51
If you are not worried about the speed tradeoff -- and
you just want the problem solved (and a brief
explanation of why you syntax highlighting was broken
in the first place) -- check out:
http://www.vim.org/tips/tip.php?tip_id=454
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=269 (2 of 2) [18/02/2004 14:51:28]

SourceForge
Logo

Tip #270 - Insert a single character : vim online

not logged in (login)

Home
Search

Tip #270: Insert a single character


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 32/31, Viewed by 1631

created: June 29, 2002 5:38


author: Mikko Pulkkinen

complexity: basic
as of Vim: 5.7

Using Insert mode to insert a single character feels


clumsy (you need
3 keypresses for one character), so here's a slightly
easier way:
:nmap <space> i_<esc>r
Now, when in Normal mode, just press space followed by
what
it is you want to insert.
BUG: Repeating the insertion with . doesn't work.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Syntax highlighting is "out of sync", seems to correct itself with refresh ?? | easy (un)commenting
out of source code >>

Additional Notes
manfred.strubegger@irm.at, July 23, 2002 2:59
Very good tip, but I prefer <C-I> as a {lhs}. It is
unused and fits better to the insert logic of VIM,
although it saves less key strokes.
reiss_david AT yahoo DOT com, July 29, 2002 10:30
I use
:map gt i$<esc>r
:map gb a$<esc>r
These macros were derived from one I found in a Vi FAQ.
Anonymous, May 20, 2003 10:44

http://www.vim.org/tips/tip.php?tip_id=270 (1 of 2) [18/02/2004 14:51:30]

Tip #270 - Insert a single character : vim online

yeah, both comments get to the point, but the author


was looking for a way to save a keystroke. both
solutions are 3 keystrokes long.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=270 (2 of 2) [18/02/2004 14:51:30]

SourceForge
Logo

Tip #271 - easy (un)commenting out of source code : vim online

not logged in (login)

Home
Search

Tip #271: easy (un)commenting out of source code


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 81/30, Viewed by 3556

created: June 30, 2002 22:57


author: jmpatton@tds.net

complexity: intermediate
as of Vim: 5.7

Something that I do quite alot is comment out blocks of


text, only to uncomment that same block later. The following
mappings have proven useful to me. They can be applied using
visually selected blocks, or with motion keys.
" lhs comments
map ,# :s/^/#/<CR>
map ,/ :s/^/\/\//<CR>
map ,> :s/^/> /<CR>
map ," :s/^/\"/<CR>
map ,% :s/^/%/<CR>
map ,! :s/^/!/<CR>
map ,; :s/^/;/<CR>
map ,- :s/^/--/<CR>
map ,c :s/^\/\/\\|^--\\|^> \\|^[#"%!;]//<CR>
" wrapping comments
map ,* :s/^\(.*\)$/\/\* \1 \*\//<CR>
map ,( :s/^\(.*\)$/\(\* \1 \*\)/<CR>
map ,< :s/^\(.*\)$/<!-- \1 -->/<CR>
map ,d :s/^\([/(]\*\\|<!--\) \(.*\) \(\*[/)]\\|->\)$/\2/<CR>
The commands to comment a selection of text are as follows,
begining with begining-of-line comments:
,#
,/
,>
,"
,%
,!
,;
,,c

shell, perl, etc


c++
email quote
vim
latex, prolog
assembly?... add single !
scheme
don't remember this one... add -clears any of the previous comments

Here are the wrapping comments, each line wrapped


individually:
,*

http://www.vim.org/tips/tip.php?tip_id=271 (1 of 9) [18/02/2004 14:51:34]

Tip #271 - easy (un)commenting out of source code : vim online

,(
,<
,d

Standard ML
html
clears any of the wrapping comments

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Insert a single character | automaticaly formating pasted text (p=`]) >>

Additional Notes
Anonymous, July 1, 2002 6:28
After executing this tip, the content of "/ is highlighted
in my gvim; which is rather annoying.
In e.g. MapBasic which I'm trying to figure out right now,
I use:
map ,' :s/^/'/<CR> :let @/=""<CR>
Leo
alinets<at>yahoo.com, July 1, 2002 13:26
I am having the same problem,
I have hlsearch option on (highlight search) and when I use
one of the mappings to add comment it leaves me with a lot
of hihjlighting that is not required/intended. Is there a
way to turn off highlight search for these command only ?
alinets<at>yahoo.com, July 1, 2002 14:40
OK, figured it out.
Just add :nohlsearch <CR> at the end of the mapping and it
would remove the highlight.
Highlighting would be reenabled when you do the next
search. I checked it out it works
" lhs comments
map ,# :s/^/#/<CR> <Esc>:nohlsearch <CR>
map ,/ :s/^/\/\//<CR> <Esc>:nohlsearch <CR>
map ,> :s/^/> /<CR> <Esc>:nohlsearch<CR>
map ," :s/^/\"/<CR> <Esc>:nohlsearch<CR>
map ,% :s/^/%/<CR> <Esc>:nohlsearch<CR>
map ,! :s/^/!/<CR> <Esc>:nohlsearch<CR>
map ,; :s/^/;/<CR> <Esc>:nohlsearch<CR>
map ,- :s/^/--/<CR> <Esc>:nohlsearch<CR>
map ,c :s/^\/\/\\|^--\\|^> \\|^[#"%!;]//<CR>
<Esc>:nohlsearch<CR>
" wrapping comments
map ,* :s/^\(.*\)$/\/\* \1 \*\//<CR> <Esc>:nohlsearch<CR>
map ,( :s/^\(.*\)$/\(\* \1 \*\)/<CR><Esc>:nohlsearch <CR>
map ,< :s/^\(.*\)$/<!-- \1 -->/<CR> <Esc>:nohlsearch<CR>

http://www.vim.org/tips/tip.php?tip_id=271 (2 of 9) [18/02/2004 14:51:34]

Tip #271 - easy (un)commenting out of source code : vim online

map ,d :s/^\([/(]\*\\|<!--\) \(.*\) \(\*[/)]\\|->\)$/\2/<CR> <Esc>:nohlsearch<CR>


jmpatton@tds.net, July 1, 2002 14:50
Adding :nohlsearch<cr> to the end of each pattern clears up
the highlighting. Note that this doesn't turn off search
highlighting, it just removes the highlighting that's
there. Here are the ammended regexs:
" lhs comments
map ,# :s/^/#/<CR>:nohlsearch<CR>
map ,/ :s/^/\/\//<CR>:nohlsearch<CR>
map ,> :s/^/> /<CR>:nohlsearch<CR>
map ," :s/^/\"/<CR>:nohlsearch<CR>
map ,% :s/^/%/<CR>:nohlsearch<CR>
map ,! :s/^/!/<CR>:nohlsearch<CR>
map ,; :s/^/;/<CR>:nohlsearch<CR>
map ,- :s/^/--/<CR>:nohlsearch<CR>
map ,c :s/^\/\/\\|^--\\|^> \\|^[#"%!;]//<CR>:nohlsearch<CR>
" wrapping comments
map ,* :s/^\(.*\)$/\/\* \1 \*\//<CR>:nohlsearch<CR>
map ,( :s/^\(.*\)$/\(\* \1 \*\)/<CR>:nohlsearch<CR>
map ,< :s/^\(.*\)$/<!-- \1 -->/<CR>:nohlsearch<CR>
map ,d :s/^\([/(]\*\\|<!--\) \(.*\) \(\*[/)]\\|->\)$/\2/<CR>:nohlsearch<CR>
jmpatton@tds.net, July 1, 2002 14:52
Jinx!
kgergely@mcl.cutit.hu, July 3, 2002 2:53
A more intelligent way is to save the search pattern
highlighted.
let hls=@/|s ... |let @/=hls
jmpatton@tds.net, July 3, 2002 5:52
The problem with that is that it thwarts motion keys. The
way it stands you can do something like '3,#' and it will
comment 3 lines. Ranges don't work with 'let ...',
unfortunately.
l.laursen@stofanet.dk, July 3, 2002 12:16

http://www.vim.org/tips/tip.php?tip_id=271 (3 of 9) [18/02/2004 14:51:34]

Tip #271 - easy (un)commenting out of source code : vim online

This function is based on the various comments here, and


seems to work.
fun CppstyleQuote()
let hls=@/
s/^/\/\//
let @/=hls
endfun
map ,/ :call CppstyleQuote()<CR>
Leo
goyko@gbg.bg, July 6, 2002 17:23
" I use a single mapping, which can comment/uncomment line:
function! C_CommentLine()
if getline(".") =~ '/\*.*\*/'
normal ^2x$xx
else
normal I/* A*/
endif
endfunction
nmap <buffer> <Esc>d :call C_CommentLine()<LF>
" <Esc>d on my term means <M-D> or Alt-D
" This mapping comments the visual selection, You have to
perform a selection from left to
" right or from top to bottom. If you do a linewise
selection, the cursor
" position, not the end of selection matters.
vmap <buffer> <Esc>d a*/ gvo i/*
me@nomail.com, September 23, 2002 19:22
i use the mouse the select the lines i want to
comment/uncomment and have this on the right click menu
to insert/delete // at the start of the line:
:vmenu PopUp.Comments.Add :s/^/\/\//<CR>
:vmenu PopUp.Comments.Remove :s/^..//<CR>
seems to work ok
gloonie@telocity.com, September 28, 2002 16:02
The comment whose language you forgot (in your notes), ,-,
is for SQL comments....
interfac@terra.es, October 12, 2002 11:30

http://www.vim.org/tips/tip.php?tip_id=271 (4 of 9) [18/02/2004 14:51:34]

Tip #271 - easy (un)commenting out of source code : vim online

hi all!!
those are great, but i don't like the highlighted search
and also i like my // allways at the very begining of the
line, so i've wrote this function (very newbie and
unoptimized, but it works XD )
it comments and uncomments the current line:
"""""""""""""""""""""""""""""""""""""""""""""""""
function! MyComm()
let linenum= line('.')
let line = getline('.')
let commpos= match(line, "//")
let n = 0
while n< commpos
if line[n]!= " " && line[n]!= "\t"
break
endif
let n= n+1
endwhile
if n== commpos && commpos!= -1
let line= strpart(line, 0, commpos).strpart(line,
commpos+2)
else
let line= "//".line
endif
let err= setline(linenum, line)
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"and use this keybindings:
map <M-c> :call MyComm()<CR>
imap <M-c> <esc>:call MyComm()<CR>i
" for the /* */ pair, i use visual mode, an then alt-v:
vmap <M-v> v`<I<CR><esc>k0i/*<ESC>`>I<CR><esc>k0i*/<ESC>
hope u find useful :)
stonnedsnake@yahoo.com, October 25, 2002 3:04
Using visual block selection at the start of the lines you
want to comment, along with 'I' (CAPS-EYE), and the
comment character is also very handy. Decommenting would be
(ofcourse!) to select the comments in a visual
block and delete them.
mits_rox@hotmail.com, February 8, 2003 13:37
the '--' comments are also for ADA95 if anyone has has the
pleasure of coding in it.

http://www.vim.org/tips/tip.php?tip_id=271 (5 of 9) [18/02/2004 14:51:34]

Tip #271 - easy (un)commenting out of source code : vim online

nick@kocharhook.com, March 19, 2003 23:02


A few people have said something like this, but I have
found it more useful to not need to remember a different
mapping for each language I'm editing. To this end, I have
several different functions that set up commands based on
which language I'm editing. Like so:
" Define functions
function! PoundComment()
map - :s/^/# /<CR>
map _ :s/^\s*# \=//<CR>
set comments=:#
endfunction
function! SlashComment()
map - :s/^/\/\/ /<CR>
map _ :s/^\s*\/\/ \=//<CR>
endfunction
" And then later...
autocmd FileType perl
autocmd FileType cgi
autocmd FileType csh
autocmd FileType sh
autocmd FileType java

call
call
call
call
call

PoundComment()
PoundComment()
PoundComment()
PoundComment()
SlashComment()

You get the idea. Now, I can always comment a line/range of


lines with - (hyphen), and uncomment it with _
(underscore).
There's More Than One Way To Do It.
Anonymous, November 10, 2003 14:07
-- is also for sql, silly boy
Anonymous, November 10, 2003 16:35
Ok, my turn:
These will handle the :nohl search highlighting case nicely
(nothing's changed, it's automatic)
map \# :call Comment()<CR>
map \-# :call Uncomment()<CR>
map \--# :call UncommentBlock()<CR>
" Comments range (handles multiple file types)
function! Comment() range
if &filetype == "c" || &filetype == "php" || &filetype ==
"css"
execute ":" . a:firstline . "," . a:lastline .
's/^\(.*\)$/\/\* \1 \*\//'
elseif &filetype == "html" || &filetype == "xml" ||
http://www.vim.org/tips/tip.php?tip_id=271 (6 of 9) [18/02/2004 14:51:34]

Tip #271 - easy (un)commenting out of source code : vim online

&filetype == "xslt" || &filetyle == "xsd"


execute ":" . a:firstline . "," . a:lastline .
's/^\(.*\)$/<!-- \1 -->/'
else
if &filetype == "java" || &filetype == "cpp" ||
&filetype == "cs"
let commentString = "//"
elseif &filetype == "vim"
let commentString = '"'
else
let commentString = "#"
endif
execute ":" . a:firstline . "," . a:lastline . 's,^,' .
commentString . ','
endif
endfunction
" Uncomments range (handles multiple file types)
function! Uncomment() range
if &filetype == "c" || &filetype == "php" ||| &filetype
== "css" || &filetype == "html" || &filetype == "xml" ||
&filetype == "xslt" || &filetyle == "xsd"
" http://www.vim.org/tips/tip.php?tip_id=271
execute ":" . a:firstline . "," . a:lastline .
's/^\([/(]\*\|<!--\) \(.*\) \(\*[/)]\|-->\)$/\2/'
else
if &filetype == "java" || &filetype == "cpp" ||
&filetype == "cs"
let commentString = "//"
elseif &filetype == "vim"
let commentString = '"'
else
let commentString = "#"
endif
execute ":" . a:firstline . "," . a:lastline . 's,^' .
commentString . ',,'
endif
endfunction
" Uncomments from current line up to last line that's
commented
function! UncommentBlock()
if &filetype == "c" || &filetype == "php" ||| &filetype
== "css" || &filetype == "html" || &filetype == "xml" ||
&filetype == "xslt" || &filetyle == "xsd"
echoerr "TODO: haven't implemented UncommentBlock; use
Uncomment instead"
else
if &filetype == "java" || &filetype == "cpp" ||
&filetype == "cs"
let commentString = '\/\/'
let firstChar = '/'
http://www.vim.org/tips/tip.php?tip_id=271 (7 of 9) [18/02/2004 14:51:34]

Tip #271 - easy (un)commenting out of source code : vim online

elseif &filetype == "vim"


let commentString = '"'
let firstChar = '"'
else
let commentString = '#'
let firstChar = '#'
endif
if version < 600 && strlen( commentString ) > 1
echoerr "TODO: haven't implemented multi-character
comment block"
else
" TODO: doesn't handle case where the block ends at
end of file
execute ':.,/^\(\(' . commentString . '\)\@!\|[^' .
firstChar . ']\|$\)/-1s/^' . commentString . "//"
endif
endif
endfunction
vale@vip.sina.com, November 12, 2003 19:04
Your script works well, but has little bugs:
1. mistype some 'filetype' to 'filetyle'
2. mistype some '||' to '|||"
Dani, January 30, 2004 6:27
All this was very useful, thanks!
Based on the above and having 4 things in mind: (1) single
keystroke (2) no highlighting (3) C language (4) being
simple - my version became:
function! Komment()
if getline(".") =~ '\/\*'
let hls=@/
s/^\/\*//
s/*\/$//
let @/=hls
else
let hls=@/
s/^/\/*/
s/$/*\//
let @/=hls
endif
endfunction
map k :call Komment()<CR>
So pressing k will comment out the current line if it is
not already so and will uncomment it if it is commented
already. Really handy :)
Dani

http://www.vim.org/tips/tip.php?tip_id=271 (8 of 9) [18/02/2004 14:51:34]

Tip #271 - easy (un)commenting out of source code : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=271 (9 of 9) [18/02/2004 14:51:34]

SourceForge
Logo

Tip #272 - automaticaly formating pasted text (p=`]) : vim online

not logged in (login)

Home
Search

Tip #272: automaticaly formating pasted text (p=`])


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 19/7, Viewed by 952

created: July 4, 2002 14:32


author: RobertKellyIV

complexity: basic
as of Vim: 5.7

In times past I used a nice editor that had the neat


feature of automatically setting pasted text to the
proper indent level. Recently I've begun to miss this so
I went looking in the help and camp up with....
=`]
which will format to the end of the pasted text...
Perfect to call right after you past something as the
cursor ends up at the top of the pasted text, thus the
mapping:
:map <c-p> =`]
" by the by the above may should be nmap and I am pretty
sure c-p is unused, your mileage will vary no doubt.
However I wanted the formatting to automatically be done
so it was two simple (once I figured out how!) nnoremap:
" [Feral:185/02@14:27] map c-p to what p was (past with
no formatting), map p to p and = to end of pasted text.
:nnoremap p p=`]
:nnoremap <c-p> p
This simply (as the comment hints at) maps normal mode p
to what p did (paste) then = to `] (last character in
the previously changed text). While ctrl+p just does
what p did. (just in case you find you don't want a bit
of text auto formatted.).
reference:
:h :nnoremap
:h p
:h =
:h `]
Whatever the name of this idea is, tis something I find
handy :)

http://www.vim.org/tips/tip.php?tip_id=272 (1 of 2) [18/02/2004 14:51:36]

Tip #272 - automaticaly formating pasted text (p=`]) : vim online

Happy VIMing
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<easy (un)commenting out of source code | Fast fixing of email quotations (too long lines) >>

Additional Notes
Feral of firetop.com, October 19, 2002 6:23
See also ]p
Help says, "Like "p", but adjust the indent to the
current line."
Also note [p
{not in Vi}, but then neither is `]
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=272 (2 of 2) [18/02/2004 14:51:36]

SourceForge
Logo

Tip #273 - Fast fixing of email quotations (too long lines) : vim online

not logged in (login)

Home
Search

Tip #273: Fast fixing of email quotations (too long lines)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 58/19, Viewed by 1201

created: July 5, 2002 4:24


author: anonymous

complexity: basic
as of Vim: 5.7

When using VIM as your editor of choice, even for email


processing - as I do - it is often unpleasing how some
MUA's quote the email body produced by mailers such as
Outlook. The lines often span across multiple visual
lines and its difficult to reply on certain parts of it.
With VIM, you can quickly fix those quotations to
maintain a proper 75 char break. For example, when using
Mutt, put this line in your .muttrc, or use a custom
.vimrc_mail for it:
set editor="vim -c 'set fo=tcrq' -c 'set tw=76'"
For other MUA's this has to be fitted. However, now,
when your quoted email is displayed, you can use this
VIM sequence to fix it:
1. move cursor to first line of broken paragraph
2. press 'V' and move to the last line of the paragraph
you want to fix
3. press 'g' and then 'q'. The marked text will wrap
around to your specified textwidth (76 in our case) and
the quotations will be preserved across the lines
rate this tip

Life Changing

Helpful

Unfulfilling

<<automaticaly formating pasted text (p=`]) | Some useful mappings for TeX >>

Additional Notes
Anonymous, July 20, 2002 11:39

http://www.vim.org/tips/tip.php?tip_id=273 (1 of 2) [18/02/2004 14:51:38]

rate

Tip #273 - Fast fixing of email quotations (too long lines) : vim online

You can also simply use the { and } paragraph motions


in conjunction with 'gq'. F.ex move to the top of a
paragraph using {, then hit gq} to reformat it.
realblades@yahoo.com, August 16, 2002 3:36
Like just about everything else, gq will take any
motion command. I find myself stepping through mails
and random files with :set tw=72 or whatnot and gqj and
J and occasionally inserting stray >'s.
Olaf Schulz <linux@village.in-berlin.de>, June 18, 2003 14:09
There are some additional conditions to be met, but
which?
The tip works with an empty/missing ~/.vimrc but not
with my .vimrc although the parameters tw and fo are
set as mentioned. Any clue, where I could look for
don't want to post my 227 lines ~/.vimrc here, but
http://www.village.in-berlin.de/setup/vimrc
Olaf Schulz, June 18, 2003 15:00
the comments setting must contain the quoting character
(usually '>')
so with
set comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:everything works as described.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=273 (2 of 2) [18/02/2004 14:51:38]

SourceForge
Logo

Tip #274 - Some useful mappings for TeX : vim online

not logged in (login)

Home
Search

Tip #274: Some useful mappings for TeX


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/0, Viewed by 581

created: July 6, 2002 17:49


author: Georgi Slavchev goyko@gbg.bg

complexity: basic
as of Vim: 6.0

You know, TeX requires a lot of additional formatting


code. I'm tired of opening and closing braces, brakets,
\beginning and \ending etc. I particularly hate typing
\begin and \end.
To help myself and to save a few(not a few) keystrokes I
naturaly came up to some solutions, which I wish to
share with
other TeXnicians and TeXperts whhich use Vim.
"===============================cut
here=========================
"=============== you can put it in
~/.vim/after/ftplugin/tex.vim ===============
"
" Note: i_<C-L>
" This constructs a skeleton of a TeX environment.
" You write a line like this:
" floatingfigure:ht<C-L>
" and after you press <C-L>, you get:
"
" \begin[ht]{floatingfigure}
"
" \end{floatingfigure}
" -- INSERT -"
" where floatingfigure is the desired environment
" ht are options
" : is delimiter; in fact, you can use whatever
delimiter you want
" as long it is not in &iskeyword option.
inoremap <buffer> <C-L>
\:s/[^][:alnum:]<bar>]\+/,/eg
\I\begin{ ea}[ A] %d%%P
\:s/\[,/[/e
\:s/,]/]/e
\:s/\[]//e
\0f{y%o\end pO
inoremap <buffer> { {} i

http://www.vim.org/tips/tip.php?tip_id=274 (1 of 3) [18/02/2004 14:51:41]

Tip #274 - Some useful mappings for TeX : vim online

inoremap
inoremap
inoremap
inoremap
inoremap

<buffer>
<buffer>
<buffer>
<buffer>
<buffer>

[ [] i
^ ^{} i
_ _{} i
\( \(\) hi
\[ \[\] hi

" Note: v_<C-L>


" For this to work, you have to write on a blank line
the name of
" the desired environment and options (see i_<C-L>) and
visual select
" (from top to bottom) this and following lines.
" After pressing <C-L> the selected lines will be
surrounded
" with begin/end skeleton of the environment.
vnoremap <buffer> <C-L> o
\:s/[^][:alnum:]<bar>]\+/,/eg
\I\begin{ ea}[ A] %d%%P
\:s/\[,/[/e
\:s/,]/]/e
\:s/\[]//e
\0f{y%gvo o\end p
" vnoremap <buffer> { di{} P
" vnoremap <buffer> [ di[] P
vnoremap <buffer> di^{} P
vnoremap <buffer> di_{} P
vnoremap <buffer> \( di\(\) hP
vnoremap <buffer> \[ di\[\] hP
" This makes "two spaces after a comma" before every
:write
au BufWritePre *.tex %s/,\(\S\)/, \1/ge
"==================== You can put this in your ~/.vimrc
========================
" If cursor is inside braces and not before comma, blank
or opening brace,
" exit the brace block and stay in insert mode.
" If cursor is outside braces, it inserts a space or
perform an abbreviation
" as normal.
function! CleverSpace()
let CharOnCursor = strpart( getline('.'), col('.')-2, 1)
let CharAfterCursor = strpart( getline('.'), col('.'),
1)
if CharOnCursor !~ ',\|\s\|(' && CharAfterCursor =~
')\|]\|}'
normal x
endif
endfunction
http://www.vim.org/tips/tip.php?tip_id=274 (2 of 3) [18/02/2004 14:51:41]

Tip #274 - Some useful mappings for TeX : vim online

inoremap <Space> <Space> :call CleverSpace()<LF>a


" I use the last function not only for LaTeX but also in
C sources.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Fast fixing of email quotations (too long lines) | Some useful mappings for TeX >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=274 (3 of 3) [18/02/2004 14:51:41]

SourceForge
Logo

Tip #275 - Some useful mappings for TeX : vim online

not logged in (login)

Home
Search

Tip #275: Some useful mappings for TeX


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/5, Viewed by 1036

created: July 6, 2002 17:56


author: Georgi Slavchev goyko@gbg.bg

complexity: basic
as of Vim: 6.0

You know, TeX requires a lot of additional formatting


code. I'm tired of opening and closing braces, brakets,
\beginning and \ending etc. I particularly hate typing
\begin and \end.
To help myself and to save a few(not a few) keystrokes I
naturaly came up to some solutions, which I wish to
share with
other TeXnicians and TeXperts whhich use Vim.
"===============================cut
here=========================
"=============== you can put it in
~/.vim/after/ftplugin/tex.vim ===============
"
" Note: i_<C-L>
" This constructs a skeleton of a TeX environment.
" You write a line like this:
" floatingfigure:ht<C-L>
" and after you press <C-L>, you get:
"
" \begin[ht]{floatingfigure}
"
" \end{floatingfigure}
" -- INSERT -"
" where floatingfigure is the desired environment
" ht are options
" : is delimiter; in fact, you can use whatever
delimiter you want
" as long it is not in &iskeyword option.
inoremap <buffer> <C-L>
\:s/[^][:alnum:]<bar>]\+/,/eg
\I\begin{ ea}[ A] %d%%P
\:s/\[,/[/e
\:s/,]/]/e
\:s/\[]//e
\0f{y%o\end pO
inoremap <buffer> { {} i

http://www.vim.org/tips/tip.php?tip_id=275 (1 of 3) [18/02/2004 14:51:43]

Tip #275 - Some useful mappings for TeX : vim online

inoremap
inoremap
inoremap
inoremap
inoremap

<buffer>
<buffer>
<buffer>
<buffer>
<buffer>

[ [] i
^ ^{} i
_ _{} i
\( \(\) hi
\[ \[\] hi

" Note: v_<C-L>


" For this to work, you have to write on a blank line
the name of
" the desired environment and options (see i_<C-L>) and
visual select
" (from top to bottom) this and following lines.
" After pressing <C-L> the selected lines will be
surrounded
" with begin/end skeleton of the environment.
vnoremap <buffer> <C-L> o
\:s/[^][:alnum:]<bar>]\+/,/eg
\I\begin{ ea}[ A] %d%%P
\:s/\[,/[/e
\:s/,]/]/e
\:s/\[]//e
\0f{y%gvo o\end p
" vnoremap <buffer> { di{} P
" vnoremap <buffer> [ di[] P
vnoremap <buffer> di^{} P
vnoremap <buffer> di_{} P
vnoremap <buffer> \( di\(\) hP
vnoremap <buffer> \[ di\[\] hP
" This makes "two spaces after a comma" before every
:write
au BufWritePre *.tex %s/,\(\S\)/, \1/ge
"==================== You can put this in your ~/.vimrc
========================
" If cursor is inside braces and not before comma, blank
or opening brace,
" exit the brace block and stay in insert mode.
" If cursor is outside braces, it inserts a space or
perform an abbreviation
" as normal.
function! CleverSpace()
let CharOnCursor = strpart( getline('.'), col('.')-2, 1)
let CharAfterCursor = strpart( getline('.'), col('.'),
1)
if CharOnCursor !~ ',\|\s\|(' && CharAfterCursor =~
')\|]\|}'
normal x
endif
endfunction
http://www.vim.org/tips/tip.php?tip_id=275 (2 of 3) [18/02/2004 14:51:43]

Tip #275 - Some useful mappings for TeX : vim online

inoremap <Space> <Space> :call CleverSpace()<LF>a


" I use the last function not only for LaTeX but also in
C sources.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Some useful mappings for TeX | Function signature previewer >>

Additional Notes
Georgi Slavchev goyko@gbg.bg, July 8, 2002 21:22
I want to correct myself.
For i_<C-L> mapping, there would be more than just one
option, i.e. env:op1:op2,op3.op4
\begin[op1,op2,op3,op4]{env}
\end{env}
For CleverSpace, the cursor position is __after__ and
not before, as I said.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=275 (3 of 3) [18/02/2004 14:51:43]

SourceForge
Logo

Tip #276 - Function signature previewer : vim online

not logged in (login)

Home
Search

Tip #276: Function signature previewer


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/2, Viewed by 766

created: July 6, 2002 18:23


author: Georgi Slavchev goyko@gbg.bg

complexity: basic
as of Vim: 6.0

Have you ever tried to call a function which parameters


you have forgotten?
Especially those long named and with long parameter list
GTK+ functions
like gtk_menu_item_image_from_stock_new(..........) !!!
By accident I saw a function in Vim help. It's name was
PreviewWord and it allowed
one to jump in the preview window to the tag for the
word cursor is on.
I _slightly_ modified this function not to need tags
file, but to search included files instead.
I wrote another function, which uses the above said one,
which triggers PreviewWord
when you open the parenthesis after a function name.
Here it is:
" Note:
" This is literally stolen from Vim help. The only
changes are:
" (1) if w != ""
becomes
if w =~
"\k"
" (2) exe "silent! ptag " . w becomes
exe
"silent! psearch " . w
" * The first change prevents PreviewWord of searching
while cursor is on some
"
non-keyword characters, e.g. braces, asterisks, etc.
function! PreviewWord()
if &previewwindow " don't do this in the preview window
return
endif
let w = expand("<cword>") " get the word under cursor
if w =~ "\k" " if there is one ":ptag" to it
" Delete any existing highlight before showing another
tag
silent! wincmd P " jump to preview window
if &previewwindow " if we really get there...
match none " delete existing highlight

http://www.vim.org/tips/tip.php?tip_id=276 (1 of 3) [18/02/2004 14:51:46]

Tip #276 - Function signature previewer : vim online

wincmd p " back to old window


endif
" Try displaying a matching tag for the word under the
cursor
let v:errmsg = ""
exe "silent! psearch " . w
if v:errmsg =~ "tag not found"
return
endif
silent! wincmd P " jump to preview window
if &previewwindow " if we really get there...
if has("folding")
silent! .foldopen " don't want a closed fold
endif
call search("$", "b") " to end of previous line
let w = substitute(w, '\', '\\\', "")
call search('\<\V' . w . '\>') " position cursor on
match
" Add a match highlight to the word at this position
hi previewWord term=bold ctermbg=green guibg=green
exe 'match previewWord "\%' . line(".") . 'l\%' .
col(".") . 'c\k*"'
wincmd p " back to old window
endif
endif
endfunction
au! CursorHold *.[ch] nested call PreviewWord()
" Note:
" When you open a parenthesis after a function name, and
at the
" line end, that function's definition is previewed
through PreviewWord().
" This is inspired from Delphi's CodeInsight technology.
" Something similar (PreviewClassMembers) could be
written for
" the C++ users, for previewing the class members when
you type
" a dot after an object name.
" If somebody decides to write it, please, mail it to
me.
function! PreviewFunctionSignature()
let CharOnCursor = strpart( getline('.'), col('.')-2, 1)
if col(".") == col("$")
call PreviewWord()
endif
return "("
endfunction
http://www.vim.org/tips/tip.php?tip_id=276 (2 of 3) [18/02/2004 14:51:46]

Tip #276 - Function signature previewer : vim online

inoremap <buffer> ( <C-R>=PreviewFunctionSignature()<LF>


rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Some useful mappings for TeX | Function signature previewer >>

Additional Notes
realblades@yahoo.com, August 16, 2002 3:39
If it's installed neatly and has a manual page, you can
search it by hitting K while on the word (function,
command, filename... anything with a manpage).
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=276 (3 of 3) [18/02/2004 14:51:46]

SourceForge
Logo

Tip #277 - Function signature previewer : vim online

not logged in (login)

Home
Search

Tip #277: Function signature previewer


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 23/7, Viewed by 1742

created: July 6, 2002 18:28


author: Georgi Slavchev goyko@gbg.bg

complexity: basic
as of Vim: 6.0

Have you ever tried to call a function which parameters you have
forgotten?
Especially those long named and with long parameter list GTK+ functions
like gtk_menu_item_image_from_stock_new(..........) !!!
By accident I saw a function in Vim help. It's name was PreviewWord and
it allowed
one to jump in the preview window to the tag for the word cursor is on.
I _slightly_ modified this function not to need tags file, but to search
included files instead.
I wrote another function, which uses the above said one, which triggers
PreviewWord
when you open the parenthesis after a function name.
Here it is:
" Note:
" This is literally stolen from Vim help. The only changes are:
" (1) if w != ""
becomes
if w =~ "\k"
" (2) exe "silent! ptag " . w becomes
exe "silent! psearch " . w
" * The first change prevents PreviewWord of searching while cursor is on
some
"
non-keyword characters, e.g. braces, asterisks, etc.
function! PreviewWord()
if &previewwindow " don't do this in the preview window
return
endif
let w = expand("<cword>") " get the word under cursor
if w =~ "\k" " if there is one ":ptag" to it
" Delete any existing highlight before showing another tag
silent! wincmd P " jump to preview window
if &previewwindow " if we really get there...
match none " delete existing highlight
wincmd p " back to old window
endif
" Try displaying a matching tag for the word under the cursor
let v:errmsg = ""
exe "silent! psearch " . w
if v:errmsg =~ "tag not found"
return
endif
silent! wincmd P " jump to preview window
if &previewwindow " if we really get there...
if has("folding")
silent! .foldopen " don't want a closed fold
endif
call search("$", "b") " to end of previous line
let w = substitute(w, '\', '\\\', "")

http://www.vim.org/tips/tip.php?tip_id=277 (1 of 4) [18/02/2004 14:51:48]

Tip #277 - Function signature previewer : vim online

call search('\<\V' . w . '\>') " position cursor on match


" Add a match highlight to the word at this position
hi previewWord term=bold ctermbg=green guibg=green
exe 'match previewWord "\%' . line(".") . 'l\%' . col(".") . 'c\k*"'
wincmd p " back to old window
endif
endif
endfunction
au! CursorHold *.[ch] nested call PreviewWord()
" Note:
" When you open a parenthesis after a function name, and at the
" line end, that function's definition is previewed through
PreviewWord().
" This is inspired from Delphi's CodeInsight technology.
" Something similar (PreviewClassMembers) could be written for
" the C++ users, for previewing the class members when you type
" a dot after an object name.
" If somebody decides to write it, please, mail it to me.
function! PreviewFunctionSignature()
let CharOnCursor = strpart( getline('.'), col('.')-2, 1)
if col(".") == col("$")
call PreviewWord()
endif
return "("
endfunction
inoremap <buffer> ( <C-R>=PreviewFunctionSignature()<LF>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Function signature previewer | all the right moves >>

Additional Notes
goyko@gbg.bg, September 19, 2002 0:21
There is an error in PreviewWord function. You have to replace line 12
with this:
if w =~ "\i" " if there is one ":psearch" to it
You may also have to convert the fileformat from "dos" to "unix" if you
have downloaded the source under a windoze browser:
:set fileformat=unix
If you want to search in certain dirs, you have to specify them in the
.vim file, like this:
setlocal path+=/usr/include/gtk-1.2/**
setlocal path+=/usr/include/gnome-1.0/**
Thanks to Balaji V T for the bug-report.
kcwu@kcwu.homeip.net, December 26, 2002 4:46

http://www.vim.org/tips/tip.php?tip_id=277 (2 of 4) [18/02/2004 14:51:48]

Tip #277 - Function signature previewer : vim online

I like this tip very much :)


However, I don't know why this script doesn't work
So I modify some lines make it work for me
And let it try ptag first, then psearch
It also avoid previewing some C keyword like for, while, double, etc.
" Note:
" This is literally stolen from Vim help. The only changes are:
" (1) if w != ""
becomes
if w =~ "\k"
" (2) exe "silent! ptag " . w becomes
exe "silent! psearch " . w
" * The first change prevents PreviewWord of searching while cursor is
on some
"
non-keyword characters, e.g. braces, asterisks, etc.
function! PreviewWord()
if &previewwindow " don't do this in the preview window
return
endif
let w = expand("<cword>") " get the word under cursor
if w =~ '\i'
if w =~
'\<\v(for|while|if|else|continue|switch|return|break|case)\m\>'
return
endif
if w =~
'\<\v(int|char|double|long|static|unsigned|const|void|define|undef)\m\>'
return
endif
" if there is one ":ptag" to it
" Delete any existing highlight before showing another tag
silent! wincmd P " jump to preview window
if &previewwindow " if we really get there...
match none " delete existing highlight
wincmd p " back to old window
endif
" Try displaying a matching tag for the word under the cursor
let v:errmsg = ""
exe "silent! ptag " . w
if v:errmsg =~ "tag not found"
exe "silent! psearch " . w
endif
silent! wincmd P " jump to preview window
if &previewwindow " if we really get there...
if has("folding")
silent! .foldopen " don't want a closed fold
endif
call search("$", "b") " to end of previous line
let w = substitute(w, '', '\\', "")
call search('\<\V' . w . '\>') " position cursor on match
" Add a match highlight to the word at this position
hi previewWord term=bold ctermbg=green guibg=green
exe 'match previewWord "\%' . line(".") . 'l\%' . col(".") .
'c\k*"'
wincmd p " back to old window
endif
endif
endfunction

http://www.vim.org/tips/tip.php?tip_id=277 (3 of 4) [18/02/2004 14:51:48]

Tip #277 - Function signature previewer : vim online

" Note:
" When you open a parenthesis after a function name, and at the
" line end, that function's definition is previewed through
PreviewWord().
" This is inspired from Delphi's CodeInsight technology.
" Something similar (PreviewClassMembers) could be written for
" the C++ users, for previewing the class members when you type
" a dot after an object name.
" If somebody decides to write it, please, mail it to me.
function! PreviewFunctionSignature()
let CharOnCursor = strpart( getline('.'), col('.')-2, 1)
if col(".") == col("$")-1
normal h
call PreviewWord()
normal l
endif
endfunction
function Register(...)
let index=1
while index <= a:0
execute 'let ext=a:'.index
execute 'au! CursorHold '.ext.' nested call PreviewWord()'
execute 'au BufNewFile,BufRead '.ext.' nested inoremap <buffer> (
<Esc>:call PreviewFunctionSignature()<CR>a('
let index=index+1
endwhile
endf
call Register('*.[ch]', '*.cc', '*.cpp')
call Register('*.[ch]0','*.cc0','*.cpp0')
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=277 (4 of 4) [18/02/2004 14:51:48]

SourceForge
Logo

Tip #278 - all the right moves : vim online

not logged in (login)

Home
Search

Tip #278: all the right moves


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 53/33, Viewed by 1966

created: July 9, 2002 13:25


author: vim_power

complexity: basic
as of Vim: 5.7

One of the principles of effective text editing is


moving around very efficiently.
Following are some pointers which may help u do that.
h
j

move one character left


move one row down
k
move one row up
l
move one char. right.
w
move to begining of next word
b
move to begining of previous word
e
move to end of word
W
move to begining of next word after a
whitespace
B
move to begining of pervious word before a
whitespace
E
move to end of word before a whitespace.
(All the above movements can be preceeded by a numeric
value . i.e '4j' will move 4 rows down )
^
g_
0
$
gg
G
nG
H
M
L
Ctrl-D
Ctrl-U
Ctrl-B
Ctrl-F

move to first non blank char of the line.


move to last non blank char of the line.
moev to begining of line
move to end of line.
move to first line.
move to last line.
move to "n"th line.
top of screen.
middle of screen
bottom of screen
move half page down
move half page up.
page-up
page down.

Ctrl-o last cursor position.


'[a-z,0-9,A-Z]
jump to the marker. (u can set a
marker on line by :m[a-zA-Z,0-9] and then jump back
http://www.vim.org/tips/tip.php?tip_id=278 (1 of 2) [18/02/2004 14:51:51]

Tip #278 - all the right moves : vim online

to it by '[a-z,A-Z0-9]
n
N
*
#
g*
g#

next matching search pattern


previous matching search pattern
next word under cursor
previous word under cursor.
next matching search pattern under cursor.
previous matching search pattern under cursor.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Function signature previewer | On Windows, make GVim the default action for double-click with
"unknown file types" >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=278 (2 of 2) [18/02/2004 14:51:51]

SourceForge
Logo

Tip #279 - On Windows, make GVim the default action for double-click with "unknown file types" : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #279: On Windows, make GVim the default action for doubleclick with "unknown file types"
tip karma

Rating 43/19, Viewed by 2418

created: July 9, 2002 14:24


author: jcline at ieee.org

complexity: intermediate
as of Vim: 5.7

I find myself installing the following registry


modification for all my PC's now (even other people's
PC's). It applies to Microsoft Windows machines
only. The following is also for Windows 9x... NT or XP
or 2000 may require modifications (which I don't care to
understand!).
The problem: You double-click on a file that doesn't
have a 'registered type' and that pesky "What program
should I use?" dialog pops up. Even worse, depending on
the installation, the GVim icon may not be listed, and
one has to browse to the executable... and then the
type becomes forever bonded to being editted with GVim
(if that box is checked). The standard Vim 6.1
installation does include a "right click to edit" menu
item for all files, but a double-click is so much
faster!
The solution: What if unregistered types would just
automatically open up in GVim? Well, they can.. with a
little registry trickery.
How to Install it:
Step 1. Create a text file called "vimalways.reg" and
paste the below text into it.
Step 2. Important NOTE: You will have to edit the
pathname to correspond to the pathname of your
GVim.exe. The text below works fine for a GVim 6.1
default installation.
Step 3: Save the file.
Step 4: Right-click on the file and select
"install". Then you are done!

http://www.vim.org/tips/tip.php?tip_id=279 (1 of 4) [18/02/2004 14:51:53]

Tip #279 - On Windows, make GVim the default action for double-click with "unknown file types" : vim online

------ vimalways.reg
-REGEDIT4

------- cut here ------snip---snip-

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Open with
&GVim]
@="Open with &GVim"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Open with
&GVim\command]
@="\"C:\\vim\\vim61\\gvim.exe\" \"%1\""
----end of file---- cut here----- snip---snip---Note 1. This can't be de-installed automatically, and
if you want to remove it, you'll have to edit the
registry by hand (annoying, but easy).
Note 2. Keep this file around, so when you upgrade your
GVim, all you have to do is modify the pathname (to say,
for example, vim62) and then install it again.

Ok, thanks for playing!


And thanks to the author(s) of Vim and GVim.
If it weren't for them, I'd still be using elvis or
stevie!
rate this tip

Life Changing

Helpful

Unfulfilling

<<all the right moves | Integration with PyUnit testing framework >>

Additional Notes
jcline at ieee.org, November 27, 2002 2:08

http://www.vim.org/tips/tip.php?tip_id=279 (2 of 4) [18/02/2004 14:51:53]

rate

Tip #279 - On Windows, make GVim the default action for double-click with "unknown file types" : vim online

Compatibility note:
MS Windows
MS Windows
MS Windows
please add

95 - works OK
98 - works OK
NT - not sure; if anyone can confirm this
a note.

MS Windows 2000 - inserts registry entry OK (rightclick the vim.reg file and select "Merge"), but doubleclick on an unknown-type file does not open file in
GVim, so the tip does not work as above. If anyone has
corrections for Windows 2000 please add a note.
MS Windows XP - have not tested. If anyone has tested
this and/or has it working please add a note.

nicodemus@globalite.com.br, January 3, 2003 16:05


The following works for 2000 and XP:
[HKEY_CLASSES_ROOT\Unknown\shell]
@="vim"
[HKEY_CLASSES_ROOT\Unknown\shell\vim]
[HKEY_CLASSES_ROOT\Unknown\shell\vim\command]
@="\"C:\\Program Files\\vim\\gvim.exe\" \"%1\""
jcline at ieee.org, March 4, 2003 17:19
Yes, thanks, I've confirmed the above works on my Win
2k pro.
I assume this must be installed as administrator, and
affects all users.
Modified instructions follow for Win2k (and XP -although I haven't tried it):
How to Install it:
Step 1. Create a text file called "vimalways.reg" and
paste the below text into it.
Step 2. Important NOTE: You will have to edit the
pathname to correspond to the pathname of your
GVim.exe. The text below works fine for a GVim 6.1
default installation.
Step 3: Save the file.
http://www.vim.org/tips/tip.php?tip_id=279 (3 of 4) [18/02/2004 14:51:53]

Tip #279 - On Windows, make GVim the default action for double-click with "unknown file types" : vim online

Step 4: Right-click on the file and select


"install". Then you are done!
------ vimalways.reg
snip--REGEDIT4

------- cut here ------snip---

[HKEY_CLASSES_ROOT\Unknown\shell]
@="vim"
[HKEY_CLASSES_ROOT\Unknown\shell\vim]
[HKEY_CLASSES_ROOT\Unknown\shell\vim\command]
@="\"C:\\Vim\\vim61\\gvim.exe\" \"%1\""
----end of file---- cut here----- snip---snip---Note 1. This can't be de-installed automatically, and
if you want to remove it, you'll have to edit the
registry by hand (annoying, but easy).
Note 2. Keep this file around, so when you upgrade
your GVim, all you have to do is modify the pathname
(to say, for example, vim62) and then install it again.

ricardo@darksignals.com, August 22, 2003 10:59


What I do on any machine I'm working on, and should
work in any of the Windows OSs, is add a shortcut to
Gvim in my SendTo folder. This can be done by:
Right-click on the START button.
Click Explore All Users
Find the folder with your username and open it.
Find the Send To folder, and copy a shortcut to Gvim in
there.
Now, if I right-click on any file, I can choose to send
it to GVim by using the Gvim short-cut on the Send-to
list.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=279 (4 of 4) [18/02/2004 14:51:53]

SourceForge
Logo

Tip #280 - Integration with PyUnit testing framework : vim online

not logged in (login)

Home
Search

Tip #280: Integration with PyUnit testing framework


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/3, Viewed by 1377

created: July 10, 2002 0:16


author: Stefan Roemer & Max Ischenko

complexity: intermediate
as of Vim: 6.0

Vim has a wonderful ability to integrate with external


tools, like compilers, make, ctags etc.
That's one of the reasons we love it.
PyUnit can be seen as a "compiler" for the Python test
code.
To understand it, Vim should be told about the language
the PyUnit speaks. This could be done with 'errorformat'
option:
setlocal efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\
%l%.%#,%Z%[%^\ ]%\\@=%m
This magic spell enables Vim to parse
unittest.TextRunner's output and to enter quick-fix
mode.
To run all your unit tests at once you'll need to setup
'makeprg' option and provide a runner.
I'm using this setup:
setlocal makeprg=./alltests.py
And contents of the alltests.py (for the sake of
completeness):
#!/usr/bin/env python2
import unittest
import sys
sys.path.append('unittests')
modules_to_test = (
'fooTest',
'barTest',
'bazTest',
)

http://www.vim.org/tips/tip.php?tip_id=280 (1 of 2) [18/02/2004 14:51:55]

Tip #280 - Integration with PyUnit testing framework : vim online

def suite():
alltests = unittest.TestSuite()
for module in map(__import__, modules_to_test):
alltests.addTest(unittest.findTestCases(module))
return alltests
if __name__ == '__main__':
unittest.main(defaultTest='suite')
============== end of the alltests.py file
========================
While talking about it, I'd also suggest to add a couple
of mappings.
In the end, my vim/files/ftplugin/python.vim looks like
this:
setlocal makeprg=./alltests.py\ -q
setlocal efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\
%l%.%#,%Z%[%^\ ]%\\@=%m
iabbr <buffer> sae self.assertEquals
iabbr <buffer> sar self.assertRaises

For details see :help quick-fix, :help 'efm' and


'makeprg'.
See also: http://c2.com/cgi/wiki?PythonUnit

:help

Many thanks to Stefan Roemer who patiently spent quite


some time to build 'efm' for me.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<On Windows, make GVim the default action for double-click with "unknown file types" | Stateful zz
>>

Additional Notes
Max Ischenko, May 8, 2003 6:10
pyunit compiler will be included in Vim 6.2 release.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=280 (2 of 2) [18/02/2004 14:51:55]

SourceForge
Logo

Tip #281 - Stateful zz : vim online

not logged in (login)

Home
Search

Tip #281: Stateful zz


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/4, Viewed by 1132

created: July 11, 2002 11:51


author: Bob van Manen

complexity: basic
as of Vim: 5.7

Do you find yourself hitting 'zz' all the time in order


to see some context of what you're
currently working on? If so, then this tip might be for
you. If you add the following line
in your vimrc, you can toggle zz mode by pressing
<Leader>zz.
" maintain a constant zz state, second call will toggle
it back off
map <Leader>zz :let &scrolloff=999-&scrolloff<CR>

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Integration with PyUnit testing framework | Folding with Regular Expression >>

Additional Notes
feline, July 12, 2002 2:46
try
:help scrolloff
with this you can always have some context when
scrolling through files.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=281 [18/02/2004 14:51:58]

SourceForge
Logo

Tip #282 - Folding with Regular Expression : vim online

not logged in (login)

Home
Search

Tip #282: Folding with Regular Expression


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 20/13, Viewed by 2058

created: July 11, 2002 20:55


author: Chris Butler (cz_butler@yahoo.com)

complexity: basic
as of Vim: 6.0

Well, I've tried to understand some of the folding scripts,


but life's
too short. Instead, I added the following lines to my vimrc
file.
set foldexpr=(getline(v:lnum)=~@/)?0:(getline(v:lnum1)=~@/)\|\|(getline(v:lnum+1)=~@/)?1:2
map \z :set foldmethod=expr foldlevel=0 foldcolumn=2<CR>
The first line is an extension of
foldexpr=(getline(v:lnum)=~@/)?0:1
The second line (re)sets the foldmethod to expr(ession)
plus.
First search for /regexp/, then fold everything else with \z
Use zr to reveal more context (before/after) lines.
You could add (getline(v:lnum2)=~@/)\|\|(getline(v:lnum+2)=~@/)?2:3
but it will take longer as folded lines (the majority)
evaluate the full expression.
What could be easier?
rate this tip

Life Changing

Helpful

<<Stateful zz | Turn on syntax coloring in Mac OS X >>

Additional Notes
hari_vim at yahoo.com, July 17, 2002 15:38

http://www.vim.org/tips/tip.php?tip_id=282 (1 of 2) [18/02/2004 14:52:00]

Unfulfilling

rate

Tip #282 - Folding with Regular Expression : vim online

This is a simple but powerful idea. If you want more


control on the amount of context to show around the
matching lines, try the following script:
http://vim.sourceforge.net/scripts/script.php?script_id=158
Hari
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=282 (2 of 2) [18/02/2004 14:52:00]

SourceForge
Logo

Tip #283 - Turn on syntax coloring in Mac OS X : vim online

not logged in (login)

Home
Search

Tip #283: Turn on syntax coloring in Mac OS X


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 68/32, Viewed by 1761

created: July 11, 2002 21:48


author: Mario Martinez

complexity: basic
as of Vim: 6.0

This tip is actually for vim 6.1. To turn on syntax


coloring in Mac OS X enter the following commands, or
place them in your $HOME/.vimrc file.
:set term=builtin_beos-ansi
:syntax on

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Folding with Regular Expression | Mapping to print syntax highlighted buffer in B&W >>

Additional Notes
benji@member.AMS.org, July 12, 2002 10:44
Note that this is only an issue for vim in a
Terminal window, not for the
GUI version, and that it will only work if support for
beos-ansi is compiled in.
For pre-compiled versions for Mac OS X, see
http://vim.sourceforge.net/download.php#mac
There are some further OS X FAQ's on my page,
http://homepage.mac.com/fisherbb/index.html
--Benji Fisher
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=283 [18/02/2004 14:52:02]

SourceForge
Logo

Tip #284 - Mapping to print syntax highlighted buffer in B&W : vim online

not logged in (login)

Home
Search

Tip #284: Mapping to print syntax highlighted buffer in B&W


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 22/7, Viewed by 1126

created: July 20, 2002 2:26


author: Sean

complexity: basic
as of Vim: 6.0

I use this mapping to print syntax highlighted C++ code


in B&W
This tip needs vimscript #233 print_bw.
The mapping is as follows
map <C-p> :color print_bw<CR>:hardcopy<CR>:color
sean<CR>:syn on<CR>
Change ":color sean" to whatever is your chosen color
scheme.
Need to change line 7 of print_bw from "syntax reset" to
"syntax off"
<C-p> on a syntax highlighted buffer turns off syntax
highlighting , sets the colors to B&W, prints the
buffer, resets the color scheme and turns on syntax
highlighting again.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Turn on syntax coloring in Mac OS X | Don't use the escape key! >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=284 [18/02/2004 14:52:04]

SourceForge
Logo

Tip #285 - Don't use the escape key! : vim online

not logged in (login)

Home
Search

Tip #285: Don't use the escape key!


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 240/102, Viewed by 9948

created: July 22, 2002 10:26


author: David A. Rogers

complexity: basic
as of Vim: 5.7

Vim (any vi really) is a dream for touch typists... Until you want to switch from insert
mode to normal mode. Then you've got to reach way up to whack the escape key.
Or at least that's what I was doing until I realized that (drum roll please)
Esc is exactly equivalent to control-[
the left square bracket key)

(that's the control key plus

Site Help

That little bit of knowledge, plus mapping my caps lock to another control key, was what
turned my fascination with Vim into true love. You never have to lose track of the home
row again!
For Xfree86 users - you can make the capslock key another control key by adding
Option "XkbOptions" "ctrl:nocaps"
to the InputDevice section of your XF86Config file.
For Windows NT/2000 users

- use the following .reg file to do the same thing:

REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Mapping to print syntax highlighted buffer in B&W | Recover after doing something... ugly. >>

http://www.vim.org/tips/tip.php?tip_id=285 (1 of 9) [18/02/2004 14:52:08]

Tip #285 - Don't use the escape key! : vim online

Additional Notes
mark@summersault.com, July 24, 2002 12:25
I was also frustrated by location of ESC and CONTROL when using vim. My solution was to
buy two Happy Hacking keyboards:
http://www.pfuca.com/products/hhkb/hhkblite2.html
Not only does it have ESC and CONTROL where I want them, but it makes it easier to
switch between my Mac computer
at work and my FreeBSD box at home.
saiyaga1881@earthlink.net, July 25, 2002 12:01
I've used Ctrl-[ for a long time-- I guess at some point over the years it ceased being
obvious.
As for the ctrl/caps lock under NT, I use:
00 00 00 00 00 00 00 00 03 00 00 00 1d 00 3a 00 3a 00 1d 00 00 00 00 00
which swaps the caps lock and ctrl keys. Format is 2 dwords of 0, 1 dword length
(#mappings + 1), dword mappings (input scan code 16-bit, output scan code 16-bit),
final dword of 0. Can remap any keys this way, even the Esc and ~ key to make your
keyboard work like a happy hacking one.
Sanjay
Anonymous, July 25, 2002 14:01
What could I put in my XFree86 config file to turn Caps Lock into Ctrl-[ instead of
just making it a control modifier key?
In other words, I want CapsLock keystroke to generate "Ctrl-[" key symbol.
Thanks.
jf_____ /at/ fastmail (.) fm, July 26, 2002 1:17

http://www.vim.org/tips/tip.php?tip_id=285 (2 of 9) [18/02/2004 14:52:08]

Tip #285 - Don't use the escape key! : vim online

hey neat! I must say that I hadnt realized that about Ctrl-]. Nice to see that somebody
was thinking along (well, sorta) the same lines as me. I was in fact just a few minutes
ago working for an alternative solution to the problematic "<esc>" key, when something
struck me.
I've always had situations where I had to "make a quick insert" - go into insert mode,
insert a quick word, then come out into normal mode, and navigate elsewhere. To make a
long story short, this is the solution that I came up with :map! <S-space> <esc>
or even
:map! <S-space><S-space> <esc>
if you find the first mapping getting in the may of your typing
With this quick combo ("Shift", + <space>), one can easily (and might I add,
intuitively) go into and come out of insert mode. I guess I always thought the <space>
would be a good way to do this sort of thing, since it is after all, so intuitive in
the typing process. So why not make it such that it can "escape" you out into normal
mode as well? Just type 'i', to go into insert mode, type in your stuff, and once
you're done, hit Shift-space!
(note: I havent automated 'i' into the whole process yet, but does anybody think that
it would be possible? I would certainly like to hear about it if you do work out
something)
dubu AT gmx.net, July 26, 2002 17:35
I changed my CapsLock key to Escape under XFree86 with the following lines in my
~/.Xmodmap:
! Esc on caps lock :-))
remove Lock = Caps_Lock
keysym Caps_Lock = Escape
In my ~/.xinitrc, xmodmap is called to set the mapping:
if [ -f ~/.Xmodmap ]; then
xmodmap ~/.Xmodmap
fi
Finally, my typing speed in vim is the same as with the original HP 9000 ITF HIL
keyboards, which MUST have been designed by vi hackers (Esc key on the outer left,
next to the shift key). :-)
http://www.vim.org/tips/tip.php?tip_id=285 (3 of 9) [18/02/2004 14:52:08]

Tip #285 - Don't use the escape key! : vim online

Anonymous, August 11, 2002 6:29


This is not a good tip if you have e.g. norwegian keyboard layout.
ctrl [ for me is pressing CTRL+Alt Gr + 9
grinderf at adelphia.net, August 20, 2002 20:35
i don't know if it's the "proper" way to do it, but i've always used ctrl+c myself
sadtruth@jaram.org, October 8, 2002 23:35
I have a better tip.
You can use some useful 'imap' keymaps for inserting mode...
for example :
<C-j> <ESC>lji
<C-k> <ESC>lki
<C-u> <ESC>i
<C-l> <ESC> l
<C-h> is crash with scancode of Insert key... so I use <C-u> keymap
Frankly speaking, I bring this ideas from emacs keymaps.
Anyway, if you do so you can move your cursors freely everytimes. :)
Anonymous, October 13, 2002 21:57
Lots of great adivse here!
I love using shift-spacebar for esc
Thanks
Mark, November 11, 2002 15:50
Thanks for the tip on Shift-Spacebar for ESC
etarun@blr.cognizant.com, November 21, 2002 1:03
The shift-space mapping is good thinking indeed.
Esc is way too cumbersome
Anonymous, December 26, 2002 1:46

http://www.vim.org/tips/tip.php?tip_id=285 (4 of 9) [18/02/2004 14:52:08]

Tip #285 - Don't use the escape key! : vim online

Since on the french canadian keyboard the key combination CRTR-[ is perform with
CTRL+AltCar+"the cedilla key" it's not very convinient.
But the TIP of using CTRL-C key combination work well on any keyboard mapping. It
doesn't required you to modify any keymap, so it will work on any vanilla installation.
From my point of view (switching from PC with English_US and Frech_CA keyboard layout)
using CTRL-C instead of the hard to reach ESC key is the real TIP here.
Anonymous, January 14, 2003 22:22
I cannot get 'map! <S-space> <esc>' to work for me. I am running Vim throught a
terminal client(putty), would this effect this mapping to not work.
I would like to
use Shift-Space as ESC, any suggestions?
erik@arbat.com, January 22, 2003 3:24
If you just want the caps lock key to be a second escape key then see my comment on
http://www.vim.org/tip_view.php?tip_id=166
Goggs, February 21, 2003 20:58
Is there any way to remap Shift+CapsLock to ESC (or S+CL to plain CL)? I use the caps
key every now and then (not much I admit)
jallen@cashsystemsinc.com, April 30, 2003 9:59
I have tried mapping "qq" and "jf" to <Esc> but I'm going to try to shift-space.
Incidentally, I mapped the space bar to i. So I will press <Space> to get into insert
mode and <S-space> to get out.
Piet Delport <pjd@303.za.net>, May 4, 2003 12:15
The above-mentioned "Scancode Map" registry key for Win2K/XP is documented here:
http://www.microsoft.com/hwdev/tech/input/w2kscan-map.asp
You can find a full listing of keyboard scancodes here:
http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/keyboard/scancodes1.html
Quick list of pertinent scancodes:
0x01
0x1D
0x38
0x3A

Esc
Ctrl
Alt
Caps Lock

Anonymous, May 10, 2003 8:13


http://www.vim.org/tips/tip.php?tip_id=285 (5 of 9) [18/02/2004 14:52:08]

Tip #285 - Don't use the escape key! : vim online

I'm a touch typist myself and one of the reasons I use Vim is BECAUSE of the Esc.
key! I can't stand all that <Meta>, <Alt>, <Ctrl>, <whatever> nonsense in, for
example, Emacs -- the Esc. key is incredibly easy to locate (just keep going until your
finger can't find any more keys...) and much faster to use. As for losing the home
row, well you know those little bumps on the 'F' and 'J' keys?.....
Anonymous, May 12, 2003 15:48
:map <S-space> i
:imap <S-space> <esc>
From command mode <S-space> takes you to insert mode, from insert mode <S-space> takes
you to command mode.
Anonymous, May 19, 2003 7:57
I am trying to get the <S-space> thing happening in Mac OS X 10.2+ with no luck.
I was able to assign a normal char (e.g. 'a') to the <esc> key as an experiment but not
the <S-space>
Does anyone have any ideas?
David
jvc@nwcs.com, June 5, 2003 7:57
You can also remap the Caps Lock key to Control in Win9x using Microsoft's Windows 95
Kernel Toys (find them at
http://www.microsoft.com/windows95/downloads/contents/WUToys/W95KernelToy/Default.asp);
one of them ("keyboard remap") will let you do this. Despite their saying they're Win95
only, I've used this utility under Win98 and Win98SE without problems.
Anonymous, June 18, 2003 22:00
"I cannot get 'map! <S-space> <esc>' to work for me. I am running Vim throught a
terminal client(putty)"
Since you are in INSERT mode when you want to press escape...it should be:
imap <S-space> <esc>
gcruscoe@yahoo.com, June 24, 2003 9:23

http://www.vim.org/tips/tip.php?tip_id=285 (6 of 9) [18/02/2004 14:52:08]

Tip #285 - Don't use the escape key! : vim online

Can anybody help me remap the Ctrl-Space key? I have an autocomplete function (for
tab) and I want to make it use Ctrl-Space instead. I cannot get any mapping for the
space key to work (including all of the examples above). What would keep vim from
mapping the space key?
Zitty, July 1, 2003 18:37
On Mac OS X:
I, too, am having problems getting the imap <S-space> <esc> scheme to work. I've
noticed some really funky stuff. First, it doesn't work at all using App Terminal
version of vim, nor does it work using the GUI version for Jaguar either. Where the
story gets strange is that it DOES work using the X-Windows version of gvim (via Apple
X11) but not the xterm version.
To sum up, it ONLY works on gvim via Apple's X11.
Hopefully someone can help us figure out what's going on here.
andreis@stud.cs.uit.no, July 11, 2003 10:05
Well, "map! <S-space> <esc>" doesn't work for me either on xterm, eterm or whatever.
For
those with a 'normal' pc keyboard, you probably have the 'windows' key on the bottom
row. Just
use it. Type the following on the commandline or put it in your .bash_profile or
.xinitrc :
"xmodmap -e "keysym Super_L = Escape"
Zitty, July 13, 2003 0:41
Okay a solution. Get the shareware utility "Keyboard Maestro". It allows you to remap
keystrokes for all sorts of tasks. You can add a general remap for the Esc key to what
ever you like, S-Space, or Ctrl-space, etc. Not exactly elegant via vim, but it works.
ulatif@hotmail.com, August 7, 2003 21:59
Try:
map! <S-Enter> <Esc>
instead of <S-Space>
works a lot better and won't get pressed accidentally.
Anonymous, August 14, 2003 16:13

http://www.vim.org/tips/tip.php?tip_id=285 (7 of 9) [18/02/2004 14:52:08]

Tip #285 - Don't use the escape key! : vim online

If you're having trouble getting <C-space> to map in vim, it may be that <C-space> is
being mapped to another keystoke. My keyboard was using <Nul> for <C-space>. So, you
could put in your vimrc:
" Map <C-space> to <Esc>.
map <Nul> <Esc>

CTRL-@ will also be mapped to <Esc>

To get the <> value for a particular keystroke, try pressing CTRL-K before the
keystroke, while in insert mode.
laskava@yahoo.com, September 19, 2003 11:04
imap <Nul> <C-p>
This is really works.
But what is <Nul>? Is it keyboard or X11 defines it?
evan.clark@psl.nmsu.ed, October 3, 2003 10:04
For Win2k and WinXP users, KeyTweak is probably your best bet, since it automates the
registry access. I just downloaded it to swap my escape and capslock keys and it works
great.
http://webpages.charter.net/krumsick/
mtwebb at cs.princeton.edu, October 15, 2003 21:44
more on the os X front:
no dice with shift space, but the enter key adjacent to the right apple key also seems
to serve as an esc key.
Any ideas why this is?
using 10.2.8 and gvim
Anonymous, December 19, 2003 3:07
And for those of us who prefer the console...
Alt-[key] is usually actually sent as <Esc>[key], and generally if you're coming out of
insert mode it's because you want to execute a normal mode command, so...
Instead of <Esc>: to start an Ex command from insert mode, just press Alt-:. Sim. for
everything else.
Anonymous, February 7, 2004 10:39

http://www.vim.org/tips/tip.php?tip_id=285 (8 of 9) [18/02/2004 14:52:08]

Tip #285 - Don't use the escape key! : vim online

It's a good idea to use <ctrl-c> to get back to normal mode. these shift-space-things
aren't easier to use and are user defined.. so if you use another vim installation, you
have to define these two mappings first. so why not using <ctrl-c> instead? however,
the only difference between <ctrl-c> and ESC is that incomplete abbreviations won't be
expanded.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=285 (9 of 9) [18/02/2004 14:52:08]

SourceForge
Logo

Tip #286 - Recover after doing something... ugly. : vim online

not logged in (login)

Home
Search

Tip #286: Recover after doing something... ugly.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/12, Viewed by 1301

created: July 23, 2002 1:07


author: Little Dragon

complexity: basic
as of Vim: 5.7

I was once editing a file and wanted to test something.


The test was meant to add a line at the end of the file,
from outside vim. All was fine, but instead of >>, I
wrote >. You can imagine what happened... :)
If you happen to do something like that, the solution
is:
:recover
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Don't use the escape key! | Cool trick to change numbers >>

Additional Notes
nitya, July 25, 2002 9:55
This command works only if you have swap file. But in
case you don't have swap file, u'll not be able to
recover ur file
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=286 [18/02/2004 14:52:10]

SourceForge
Logo

Tip #287 - Cool trick to change numbers : vim online

not logged in (login)

Home
Search

Tip #287: Cool trick to change numbers


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 47/30, Viewed by 2096

created: July 25, 2002 9:52


author: Nitya

complexity: basic
as of Vim: 5.7

In the gvim if you want to decrement any number just put


ur curcor on that number in Esc mode and pres <CTRL> X
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Recover after doing something... ugly. | A keymapping to generate Java setters and getters
automatically >>

Additional Notes
Robbie S., July 25, 2002 12:36
You can also press Ctrl+A in normal mode to increment
numbers!
Anonymous, July 26, 2002 4:00
You don't even need to be on the number itself. Vim
search automaticaly for the next number before
incrementing / decrementing
salmanhalim@hotmail.com, July 26, 2002 7:30
It should be noted that the 'nrformats' option dictates
whether letters, octal and hexadecimal numbers are
recognized and modified accordingly.
me@me.com, August 4, 2002 10:46
this
nonone@none.com, October 30, 2003 15:10
great tip! how do find things like this in the help
file? I tried :help increment
jaldripublic at comcast.net, November 16, 2003 0:02
:helpgrep subtract
http://www.vim.org/tips/tip.php?tip_id=287 (1 of 2) [18/02/2004 14:52:13]

Tip #287 - Cool trick to change numbers : vim online

jaldripublic @ comcast.net, November 16, 2003 0:12


To use these keys (CTRL-A CTRL-X) on a selection (block
of numbers), download vimscript #821.
This plugin also allows resequencing numbers in a
selected list (example included on the script page).
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=287 (2 of 2) [18/02/2004 14:52:13]

SourceForge
Logo

Tip #288 - A keymapping to generate Java setters and getters automatically : vim online

not logged in (login)

Tip #288: A keymapping to generate Java setters and getters automatically

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 5/2, Viewed by 1246

created: July 25, 2002 19:25


author: Sheer El-Showk

complexity: intermediate
as of Vim: 5.7

This mapping makes it much simpler to write new java classes by simplifying
some of the dull repetative coding (ie setters and getters).
To use, first write a basic class with the following format:
public class MyClass
{

Site Help

private <type> <varname> = <initvalue>;


private <type> <varname> = initvalue>;
// getters
// setters
}
Note the getters/setters comment -- they are important as they are used to
place the getters and setters.
The mapping is:
map jgs mawv/ <Enter>"ty/ <Enter>wvwh"ny/getters<Enter>$a<Enter><Enter>public
<Esc>"tpa<Esc>"npbiget<Esc>l~ea()<Enter>{<Enter><Tab>return
<Esc>"npa;<Enter>}<Esc>=<Enter><Esc>/setters<Enter>$a<Enter><Enter>public void
<Esc>"npbiset<Esc>l~ea(<Esc>"tpa
<Esc>"npa)<Enter>{<Enter><Tab>this.<Esc>"npa=<Esc>"npa;<Enter>}<Esc>=<Enter>`ak

http://www.vim.org/tips/tip.php?tip_id=288 (1 of 3) [18/02/2004 14:52:15]

Tip #288 - A keymapping to generate Java setters and getters automatically : vim online

(the above should be one long line with no spaces between the end of the lines
above).
To use this to generate a class go to the variable that should have a
setter/getter and place the curser at the beginning of the 'private':
private <type> <variable> = <initvalue>'
^
Then type:
jgs
this will create the first getter/setter and then move up to the next
variable. You can just keep typing jgs until all the getters/setters have
been generated.
This should mapping isn't perfect and someone could probably make it a little
cleaner. It could also relatively easily be adapted to C++. Please feel free
to send me any feedback/enhancements as I am trying to compile a list of these.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Cool trick to change numbers | Alternative <escape> that allows you to do a "quick and dirty insert" and get out into normal mode >>

Additional Notes
sheerpub@yahoo.com, July 26, 2002 0:23
This is just an update on the above -- I had my original email removed for
SPAM reasons. If you want to email me regarding this tip please send to
sheerpub _at_ yahoo dot com.
Thanks,
Sheer
http://www.vim.org/tips/tip.php?tip_id=288 (2 of 3) [18/02/2004 14:52:15]

Tip #288 - A keymapping to generate Java setters and getters automatically : vim online

dcop@mindspring.com, September 19, 2002 8:21


This is a great idea, but this implementation is a little lacking. When I
first used it, it put my getters and setters in comments (since it searchers
for // getters, and doing an $a<Enter> on that line continues the
comment). Additionally, it assumes a tabstop of 8 instead of letting the
file type indent do the work, plus the spacing is a little messed up.
What I usually do is type all my private members. I got to the first one and
hit "qa" to start macro recording to register a. Then I make my getter and
setter using only commands that operate on words and not characters. When
done, hit "q" again, and now register a has your macro.
pete-vim AT kazmier.com, November 27, 2002 8:43
If anyone is interested, I wrote a script that does this and a little
more. You can find it here:
http://vim.sourceforge.net/script.php?script_id=490 ;
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=288 (3 of 3) [18/02/2004 14:52:15]

SourceForge
Logo

Tip #289 - Alternative <escape> that allows you to do a "quick and dirty insert" and get out into normal mode : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #289: Alternative <escape> that allows you to do a "quick and


dirty insert" and get out into normal mode
tip karma

Rating 16/11, Viewed by 1176

created: July 26, 2002 1:43


author: Jeffrey Lim

complexity: basic
as of Vim: 5.7

This is an alternative key combo for the escape key from


the one mentioned by David A. Rogers in vimtip #285.
I do a lot of editting in Vim, and I've always found
myself in situations where I had to "do a quick insert" basically (from normal mode), change into insert mode,
type in one quick word, then <esc> out, then navigate
elsewhere.
As has been rightly observed by a lot of people, the
<esc> key can sometimes be a little bit out of the way.
But that's no problem for ViM, is it?
At first, I thought of editting the ViM source code
itself, in order to come up with a command that could do
things like say "let me jump into insert mode, type a
few quick words, then escape out into normal mode when i
press something like double <space>".
It was only later when reading through the section in
Jesse Goerz's "Beginner's Guide to ViM" on remapping
(http://newbiedoc.sourceforge.net/tutorials/vim/mappingvim.html) that I got inspired to retake a look at using
remapping as an alternative instead.
This is what I came up with.. Use whatever is
comfortable for you - single or double <Shift-space>
:map! <S-space> <esc>
:map! <S-space><S-space> <esc>
With this quick combo ("Shift", + <space>), one can
easily (and might I add, intuitively) "do a quick
insert" and exit quickly out into normal mode. I guess I
always thought the <space> would be a good way to do
this sort of thing, since it is after all, so intuitive
in the typing process. So why not make it such that it

http://www.vim.org/tips/tip.php?tip_id=289 (1 of 2) [18/02/2004 14:52:18]

Tip #289 - Alternative <escape> that allows you to do a "quick and dirty insert" and get out into normal mode : vim online

can "escape" you out into normal mode as well? Just type
'i', to go into insert mode, type in your stuff, and
once you're done, hit Shift-space!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<A keymapping to generate Java setters and getters automatically | Text Processing With Integrated
Spell Checking >>

Additional Notes
Anonymous, July 26, 2002 8:22
Also check out vimtip #270.
Anonymous, July 26, 2002 9:45
Ctrl+[ is a builtin equivalent to Esc in insert mode...
antoine.mechelynck@belgacom.net, July 26, 2002 12:07
Ctrl-[ is equivalent to <Esc> indeed; but if you use <SSpace>, beware of using the space bar as "independent
of shift" as on a typewriter!
jmcpherson@softhome.net, July 29, 2002 12:50
Not a bad idea... and more egronomic (although also
less universally available) than the ^[ idea in vimtip
#285.
Incidentally, are you the same Jeffery Lim that wrote
Impulse Tracker?
jf_____@fastmail.fm, July 29, 2002 23:32
erm, nope. Different. For one thing, the "Jeffery" is
spelt differently. Thanks for the compliments for the
tip though.
alex_nanou@yahoo.com, August 14, 2002 16:32
here is another one in relation to the subject: vimtip
#314
Thanks...
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=289 (2 of 2) [18/02/2004 14:52:18]

SourceForge
Logo

Tip #290 - Text Processing With Integrated Spell Checking : vim online

not logged in (login)

Home
Search

Tip #290: Text Processing With Integrated Spell Checking


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 22/12, Viewed by 1683

created: July 26, 2002 13:35


author: David Highley

complexity: intermediate
as of Vim: 6.0

I have written an HTML document to help others use Vim


as a basic text processing application. It discusses how
to integrate spell checking, dictionary, and thesaurus
applications. It also talks about wrapping lines,
indentation, justification, and the vim settings that
effect the behavior of these operations. The document
can be found at:
http://www.highley-recommended.com/textprocessing.html
Everything has been tested with UNIX, Linux, Windows,
and Windows with Cygwin patforms.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Alternative <escape> that allows you to do a "quick and dirty insert" and get out into normal mode |
^P & auto filling of variables and text >>

Additional Notes
david@tvis.co.uk, July 27, 2002 4:21
Hi Y'All
I used above successfully
If you happen to use Aspell on a Unix "shell" eg MKS on
Win32 you may want
:set shellslash

(unix forward slash)

Also if you map the full path to aspell in your map eg


c:/vim/aspell/aspell.exe you wont need an environment
variable
eg
http://www.vim.org/tips/tip.php?tip_id=290 (1 of 2) [18/02/2004 14:52:20]

Tip #290 - Text Processing With Integrated Spell Checking : vim online

map <Leader>s <Esc>:!c:/vim/aspell/aspell.exe -c --dontbackup %<CR>:e! %<CR><CR>


or
map <Leader>s <Esc>:!c:\vim\aspell\aspell.exe -c --dontbackup %<CR>:e! %<CR><CR>
zzapper
dr_kludge@users.sourceforge.net, August 5, 2002 23:10
People love to put spaces in their file names in MS
Windows
these days. I used the aspell lines provided with the
full path
as noted by zzapper, david at tvis dot co dot uk. At
first his
example did not work because I was using someone's file
with a space in it for testing. I then changed
map <Leader>s <Esc>:!c:\vim\aspell\aspell.exe -c --dontbackup %<CR>:e! %<CR><CR>
to
map <Leader>s <Esc>:!c:\vim\aspell\aspell.exe -c --dontbackup "%"<CR>:e! "%"<CR><CR>
Please note the quotes around the percent sign, "%".
Both the tip and David's note are very
effective. You'd want
to do something similar on Linux too. Especially if
you are
serving up files with Samba. See http://www.samba.org
Thanks,
Greg Morgan
Dr. Kludge
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=290 (2 of 2) [18/02/2004 14:52:20]

SourceForge
Logo

Tip #291 - ^P & auto filling of variables and text : vim online

not logged in (login)

Home
Search

Tip #291: ^P & auto filling of variables and text


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 75/26, Viewed by 1425

created: July 30, 2002 3:28


author: rangarao

complexity: intermediate
as of Vim: 6.0

Do you know you can auto fill the variable and names as
you type your code ? This will help most of the
programmers, who always try hard to remember the
variable names and browse through all the files to find
out the variable name.
Use Ctrl+P and Ctrl+N to autofill the variables names
etc. Just practice, you will feel the ease of using vim

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Text Processing With Integrated Spell Checking | vim + cscope + cygwin >>

Additional Notes
Anonymous, July 30, 2002 11:03
Also check out vimscript#182 and vimscript #73
Robert KellyIV (Feral at FireTop . com), July 30, 2002 11:04
Completion such as this is also why it is a good idea
to have descriptive variable names, so you can easily
tell if you have the completion you were after.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=291 [18/02/2004 14:52:22]

SourceForge
Logo

Tip #292 - vim + cscope + cygwin : vim online

not logged in (login)

Home
Search

Tip #292: vim + cscope + cygwin


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 7/3, Viewed by 1295

created: July 30, 2002 4:54


author: Giorgio Marzano

complexity: intermediate
as of Vim: 6.0

I've found that vim + cscope + cygwin does not work. The
problem seems to be that in
sprintf(cmd, "exec %s -dl -f %s", prog,
csinfo[i].fname);
vim execs cscope with the "-dl" options, causing it to
fail. It is probably a cscope bug, but a simple
workaround is top build vim without thad "d":
sprintf(cmd, "exec %s -l -f %s", prog, csinfo[i].fname);
seems to work for me!

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<^P & auto filling of variables and text | remember where you had ended reading help >>

Additional Notes
vsampath@hotmail.com, October 4, 2002 9:59
This (keyword #292) doesn't seem to be true, at least
not anymore. I am using cscope 15.4 and vim 6.1. With a
few hacks, I was able to get cscope to work with vim
under cygwin for Windows 2000. I did not need to change
the sprintf line. The hacks included
1. Copying if_cscope.? to the src directory and the
if_cscope.pro to the src/proto directory. These files
do not come standard with the Windows source
distribution of vim. (I think it should - anybody in
charge of distribution listening?)
2. Edit if_cscope.c to make the following changes:
http://www.vim.org/tips/tip.php?tip_id=292 (1 of 2) [18/02/2004 14:52:25]

Tip #292 - vim + cscope + cygwin : vim online

Add the following includes:


#include <sys/unistd.h>
#include <sys/signal.h>
3. Edit Make_cyg.mak
Add if_cscope.o to OBJ variable.
Add a rule for this at the end
$(OUTDIR)/if_cscope.o: if_cscope.c $(INCL)
$(CC) -c $(CFLAGS) if_cscope.c -o $(OUTDIR)/if_cscope.o
Uncomment the lines following
#>>>>> uncomment this block to build a GUI version
4. Edit feature.h
Force cscope compilation:
# define FEAT_CSCOPE
5. make -f Make_cyg.mak GUI=yes
6. Note that the env variable TMPDIR should be defined
in VIM for cscope to work correctly.
That should do it. Somebody in charge of distribution
please make this standard. It would save a lot of
trouble.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=292 (2 of 2) [18/02/2004 14:52:25]

SourceForge
Logo

Tip #293 - remember where you had ended reading help : vim online

not logged in (login)

Home
Search

Tip #293: remember where you had ended reading help


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 2/2, Viewed by 666

created: July 30, 2002 6:07


author: Max Ischenko

complexity: basic
as of Vim: 5.7

You could jump to the last place you had been while
reading Vim help files if you add this to your
.vimrc file:
au BufLeave * if &ft == "help" | mark H | endif
Then use 'H to go to the mark H.

Site Help

To work between Vim runs 'viminfo' option should be


setup to save file marks.
See :help 'viminfo' and :help file-marks for more
information.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<vim + cscope + cygwin | Use Ctrl-S to save current or new files. >>

Additional Notes
salmanhalim@hotmail.com, July 30, 2002 11:56
Perhaps a modification to allow 'H to open another
window if a help window doesn't already exist might be
useful here. Basically, the problem I had with this
was that if i I hit 'H while editing a buffer, it
replaced the buffer with the help file (though it DID
take me to the right location, as you suggested it
would) instead of opening a new window.
Max Ischenko, July 30, 2002 23:17
What about
nmap <F1> <C-W>s'H
Add Note

http://www.vim.org/tips/tip.php?tip_id=293 (1 of 2) [18/02/2004 14:52:27]

Tip #293 - remember where you had ended reading help : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=293 (2 of 2) [18/02/2004 14:52:27]

SourceForge
Logo

Tip #294 - Use Ctrl-S to save current or new files. : vim online

not logged in (login)

Home
Search

Tip #294: Use Ctrl-S to save current or new files.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 20/12, Viewed by 1339

created: July 30, 2002 12:37


author: Thomas R. Kimpton

complexity: basic
as of Vim: 5.7

I wanted to have a single key stroke that would save


existing files, or call the file browser.
Here's a key map for Ctrl-S to accomplish that (place in
vimrc file):
if has("gui_running")
" If the current buffer has never been saved, it will
have no name,
" call the file browser to save it, otherwise just
save it.
:map <silent> <C-S> :if expand("%") == ""<CR>:browse
confirm w<CR>:else<CR>:confirm w<CR>:endif<CR>
endif
Tom Kimpton
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<remember where you had ended reading help | Line/word/file/whatever completion >>

Additional Notes
salmanhalim@hotmail.com, July 30, 2002 20:14

http://www.vim.org/tips/tip.php?tip_id=294 (1 of 2) [18/02/2004 14:52:42]

Tip #294 - Use Ctrl-S to save current or new files. : vim online

Recommend an imap for the same functionality so one can


hit ctrl-s without having to make sure one isn't in
insert mode:
:imap <c-s> <esc><c-s>
If one prefers to return to insert mode after the save,
the following mapping may be used instead:
:imap <c-s> <c-o><c-s>
Has the nice advantage of allowing one to save in the
middle of typing. (I actually have two different keys
mapped, one for each of the two above behaviours.)
atkinssc AT engr orst edu, August 5, 2002 15:09
use:
imap <c-s> <c-o><c-s><cr>
So that the confirmation doesn't hold you up.
jaldripublic at comcast dot net, November 17, 2003 7:57
mswin.vim (included with GVim 6.2 for windows) defines:
" Use CTRL-S for saving, also in Insert mode
noremap <C-S> :update<CR>
vnoremap <C-S> <C-C>:update<CR>
inoremap <C-S> <C-O>:update<CR>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=294 (2 of 2) [18/02/2004 14:52:42]

SourceForge
Logo

Tip #295 - Line/word/file/whatever completion : vim online

not logged in (login)

Home
Search

Tip #295: Line/word/file/whatever completion


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 63/29, Viewed by 1980

created: July 30, 2002 13:08


author: Nopik

complexity: intermediate
as of Vim: 6.0

In addition to vimtip #291 you can use whole <C-x>


completion mode. It can complete whole lines (<C-x>l,
then <C-p>, <C-n>), filenames (<C-f>), keywords, words
from custom dictionary and many, many others. During
coding it usually saves a LOT of key strokes ;) This
mode has many other powerful features, for example when
completing word (by <C-x><C-p> or just by <C-p>) you can
continue completion with another <C-x><C-p>. For
example, after writing such text:
this is first line
second line is here
Placing cursor at third line and pressing <C-x>l will
double last line - <C-n>, <C-p> in this moment can be
used to manipulate completed line. Or, instead of
completing whole line you can press 'f' and then
complete by <C-p> which will result in 'first' word.
After that you can <C-x><C-p> to get 'line' word (since
this is next word after 'first'). Try yourself for other
powerful combinations.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Use Ctrl-S to save current or new files. | Attach the currently open file to email >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=295 [18/02/2004 14:52:49]

SourceForge
Logo

Tip #296 - Attach the currently open file to email : vim online

not logged in (login)

Home
Search

Tip #296: Attach the currently open file to email


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 22/15, Viewed by 1231

created: August 2, 2002 14:52


author: hari_vim at yahoo

complexity: basic
as of Vim: 5.7

This is very simple, but most people don't seem to take


advantage of this. Often you have some file (source code
or other text file) already open in an existing vim
session and you need to attach it with an email. It is
very simple.
- First copy the filename into clipboard. For this I
put the following mapping in vimrc and press <F2>:
nnoremap <F2> :let @*=expand("%:p")<cr>
- Go to your email compose window and use your
regular file attachment menu (Insert->File in outlook)
and press ^V (or whatever key to paste clipboard) and
press Enter.
That is all there to it. If you are on windows and your
email client doesn't accept forward-slashes, then you
might want to change the map to:
nnoremap <F2> :let @*=substitute(expand("%:p"),
"/", "\\", "g")<cr>
HTH,
Hari
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Line/word/file/whatever completion | Start in insert mode without loosing your escape key >>

Additional Notes
Anonymous, August 3, 2002 20:26
Very nice tip. Thanks
Add Note

http://www.vim.org/tips/tip.php?tip_id=296 (1 of 2) [18/02/2004 14:52:51]

Tip #296 - Attach the currently open file to email : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=296 (2 of 2) [18/02/2004 14:52:51]

SourceForge
Logo

Tip #297 - Start in insert mode without loosing your escape key : vim online

not logged in (login)

Home
Search

Tip #297: Start in insert mode without loosing your escape key
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/5, Viewed by 1047

created: August 3, 2002 17:05


author: atkinss AT onid orst edu

complexity: basic
as of Vim: 5.7

There are two parts to this, each is fairly simple.


First, I want to start in insert mode. Well "set im!"
in my vimrc did the job, but I lost the escape key.
Second, I have found that often times, when I'm in
command mode, I hit escape trying to get back into
insert mode. I am always rewarded with a beep, telling
me once again I made that mistake.
So I mapped esc in command mode to set insert mode
(":set im") and I mapped esc in insert mode to unset
insert mode (<c-o>:set im) Well then I realized if you
hit "i" in command mode, escape woulding work the first
time. So here's the code to add to your vimrc:
set im!
map <esc> :set im!<cr>
goes to insert mode
map i :set im!<cr>
insert mode
map! <esc> <c-o>:set im!<cr>
goes to command mode

" start in insert mode


" escape in command mode
" i in command mode goes to
" escape in insert mode

see :help insert


rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Attach the currently open file to email | Changing case with regular expressions >>

Additional Notes
syndicate@agitated.net, August 3, 2002 20:24
Its spelled 'lose' not 'loose'

http://www.vim.org/tips/tip.php?tip_id=297 (1 of 3) [18/02/2004 14:52:53]

Tip #297 - Start in insert mode without loosing your escape key : vim online

atkinssc AT engr orst edu, August 5, 2002 9:09


I noticed that the comments may be pasted in when
switching modes (atleast with my version of vim.)
recomend moving them.
eg.
" Start in insert mode and
" set escape to switch to
" command mode or back to
" insert.
set im!
map <esc> :set im!<cr>
map i :set im!<cr>
map! <esc> <c-o>:set im!<cr>

So I

Don't forget to change your other scripts to use <c-l>


rather than <esc>. Also, about the speeling mistake,
well, I'm sorry, I wasn't completely awake at the time.
atkinssc AT engr orst edu, August 6, 2002 8:30
Okay, here's a full set of mappings:
" Start in insert mode and
" set escape to switch to
" command mode or back to
" insert.
set im!
map <esc> :set im!<cr><c-o>:echo <cr>
map i :set im!<cr><c-o>:echo <cr>
map! <esc> <c-o>:set im!<cr>:echo <cr>
map a :set im<cr><c-o>l<c-o>:echo <cr>
map A :set im<cr><c-o>$<c-o>:echo <cr>
map o :set im<cr><c-o>$<c-o>:echo <cr><cr>
map O :set im<cr><c-o>^<c-o>:echo <cr><cr><c-o>k
I found that I needed all of these so that scripts
would work correctly and such.
vim@SaurabhSinha.com, August 9, 2002 7:34
I think a better approach would be to use <C-L> to come
to Command Mode from Insert Mode.
The script would then be as simple as:
se im
imap <Esc> <C-L>
SPAMgrayrest@grayrest.com, July 3, 2003 14:45
vim -c 'startinsert'
;]

http://www.vim.org/tips/tip.php?tip_id=297 (2 of 3) [18/02/2004 14:52:53]

Tip #297 - Start in insert mode without loosing your escape key : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=297 (3 of 3) [18/02/2004 14:52:53]

SourceForge
Logo

Tip #298 - Changing case with regular expressions : vim online

not logged in (login)

Home
Search

Tip #298: Changing case with regular expressions


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 55/22, Viewed by 1283

created: August 5, 2002 10:41


author: Jonathan McPherson

complexity: intermediate
as of Vim: 5.7

I stumbled across this factoid on a website about vi. I haven't been able to
locate it in the Vim documentation, but it works in Vim, and it's very handy.
There are times that you might like to go through a file and change the case
of characters that match some arbitrary criteria. If you understand regular
expressions well, you can actually do this fairly easily.
It's as simple as placing \U or \L in front of any backreferences in your
regular expressions. Vim will make the text in the backreference uppercase or
lowercase (respectively).
(A "backreference" is a part of a regular expression that refers to a
previous part of a regular expression. The most common backrefernces are &,
\1, \2, \3, ... , \9).
Some examples that demonstrate the power of this technique:
Lowercase the entire file :%s/.*/\L&/g
(& is a handy backreference that refers to the complete text of the match.)
Uppercase all words that are preceded by a < (i.e. opening HTML tag names):
:%s/<\(\w*\)/<\U\1/g
Please add a note if you know where this is in the documentation. I have done
Ctrl-D searches on upper, lower, \U, and \L with no luck.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Start in insert mode without loosing your escape key | Open file under cursor. >>

Additional Notes
salmanhalim@hotmail.com, August 5, 2002 12:42
:help sub-replace-special
Got there quite simply by starting with :help :s.
pagaltzis () gmx _ net, August 8, 2002 12:58
Note also the gu<motion> and gU<motion> commands.
F.ex, ggguG will lowercase the entire file.
(gg = go to top, gu = lowercase, G = go to EOF).
shawn@deleurme.com, November 26, 2002 15:30

http://www.vim.org/tips/tip.php?tip_id=298 (1 of 2) [18/02/2004 14:52:55]

Tip #298 - Changing case with regular expressions : vim online

By using the \0 general backref instead of the name ones (\1, \2 etc) you
can save some typing for on replace stanza of the regex.
This regex upper cases an explicit set of words to uppercase in a file.
:%s/\(select\)\|\(order)\|\(by\)\|\(from\)\|\(where\)/\U\0/g
Not rocket science, but otherwise you'd have to do this:
:%s/\(select\)\|\(order)\|\(by\)\|\(from\)\|\(where\)/\U\1\U\2\U\3\U\4\U\5/g
2003@karpfenteich.net, February 22, 2003 5:39
convert HTML-Tags to uppercase
:%s/<\/\=\(\w\+\)\>/\U&/g
or to lowercase
:%s/<\/\=\(\w\+\)\>/\L&/g
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=298 (2 of 2) [18/02/2004 14:52:55]

SourceForge
Logo

Tip #299 - Open file under cursor. : vim online

not logged in (login)

Home
Search

Tip #299: Open file under cursor.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -3/16, Viewed by 1274

created: August 6, 2002 4:23


author: Little Dragon

complexity: intermediate
as of Vim: 5.7

A little thing that I did and found quite useful:


function! OpenFileUnderCursor()
let FileName = expand("<cfile>")
let OldPath = getcwd()
silent cd %:p:h
execute "silent sp +e " . FileName
execute "silent cd " . OldPath
endfunction
map! silent <M-e> :call OpenFileUnderCursor()<CR>
Then use Alt+E on a filename to open it (relative to the
directory the current file resides in).
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Changing case with regular expressions | Making a tags file for IDL (Interactive Data Language) >>

Additional Notes
hps@softhome.net, August 6, 2002 4:47
Did you ever try gf? ;-)
salmanhalim@hotmail.com, August 6, 2002 5:53
Not to mention ctrl-w f (for another window).
littledragon@altern.org, August 6, 2002 7:33
Hrm... Never tried gf or C-w f before :)
Cool :)
tborgmann@hh-berlin.de, September 2, 2002 23:42

http://www.vim.org/tips/tip.php?tip_id=299 (1 of 2) [18/02/2004 14:52:57]

Tip #299 - Open file under cursor. : vim online

Hmm, ok, but is there a way to open the file in a NEW


vim?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=299 (2 of 2) [18/02/2004 14:52:57]

SourceForge
Logo

Tip #300 - Making a tags file for IDL (Interactive Data Language) : vim online

not logged in (login)

Home
Search

Tip #300: Making a tags file for IDL (Interactive Data Language)
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/1, Viewed by 552

created: August 6, 2002 6:59


author: Shawn Young

complexity: basic
as of Vim: 5.7

I have recently began using the tags features of vim (:help


tags) with my fortran codes and come to appreciate their
power. I also do a lot of coding in IDL (Interactive Data
Language), but found that ctags did not have native support for
IDL. If you take the time you can learn how to get ctags to
support IDL, but I found, after a search of usenet, that someone
else has already done this and written a perl script called
idltags. It is part of an emacs package (is anyone still
reading?) that you need to download, called idlwave, which is
located at:
http://idlwave.org/
and currently (I don't know if this will change) the direct
download link is
http://idlwave.org/download/idlwave.tar.gz
In the usenet pages the maintainer, JD Smith, was suggesting
that idlwave had outgrown idltags and was not sure it was still
needed, so I don't know how long it will be available.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Open file under cursor. | Edit files in path, or related. >>

Additional Notes
Shawn, August 7, 2002 10:37
JD Smith has updated his web page to make idltags a separate
download to make it available specifically for vi users. The
new link is at
http://idlwave.org/download/idltags
mperrin@astro.berkeley.edu, December 10, 2002 15:20

http://www.vim.org/tips/tip.php?tip_id=300 (1 of 2) [18/02/2004 14:52:59]

Tip #300 - Making a tags file for IDL (Interactive Data Language) : vim online

It's actually quite easy to add support for IDL into ctags.
With Exuberant CTags, all you
need is to put the following in your .ctags file:
--langdef=IDL
--langmap=IDL:.pro
--regex-IDL=/^pro[ \t]+([a-zA-Z0-9_:]+)/\1/p,procedure/i
--regex-IDL=/^function[ \t]+([a-zA-Z0-9_:]+)/\1/f,function/i
and that's enough to get IDL procedures and functions into
your tags files.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=300 (2 of 2) [18/02/2004 14:52:59]

SourceForge
Logo

Tip #301 - Edit files in path, or related. : vim online

not logged in (login)

Home
Search

Tip #301: Edit files in path, or related.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/2, Viewed by 732

created: August 7, 2002 0:09


author: Little Dragon

complexity: intermediate
as of Vim: 5.7

You can write a little shell function that will let you
easily edit any file that is in the path, or which's
location can be retrieved with the whereis tool. This is
something similar to what I have in /etc/profile:
function vvim() { vim `whereis $1|cut -d: -f2` }
function ggvim() { gvim `whereis $1|cut -d: -f2` }
Then just type, for example, "vvim ls", and you'll start
vim with /bin/ls and /usr/share/man/ls.1.gz loaded :)
(it's not very useful to edit /bin/ls, but you get the
ideea ;)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Making a tags file for IDL (Interactive Data Language) | Use gvim in kmail >>

Additional Notes
littledragon@altern.org, August 7, 2002 3:34
A more useful example: vvim profile
weisbier@aol.com, August 8, 2002 19:12
I liked the idea, great for editing scripts, but it
didn't work for the shells
I use. Here's how I got it to work for the 2 shells I
use:
For 'bash':
vvim () { command vim `whereis "$@" | cut -d: -f2` ; }
For 'tcsh' in .tcshrc:
alias vvim 'vim `whereis \!* | cut -d: -f2` '

http://www.vim.org/tips/tip.php?tip_id=301 (1 of 2) [18/02/2004 14:53:02]

Tip #301 - Edit files in path, or related. : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=301 (2 of 2) [18/02/2004 14:53:02]

SourceForge
Logo

Tip #302 - Use gvim in kmail : vim online

not logged in (login)

Home
Search

Tip #302: Use gvim in kmail


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 29/11, Viewed by 1183

created: August 7, 2002 6:08


author: Davide Patti

complexity: basic
as of Vim: 6.0

To automatically open gvim to edit in kmail, "-f"


command line option must be used .
In kmail configuration go to the composer settings , and
write in the "use external editor" field the following
command :
"gvim -f %f"
Without -f option gvim would work in background and
editing would not have any effect on kmail.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Edit files in path, or related. | Statusline Tab Level Function Ruler TVIM >>

Additional Notes
nlm@valtech.se, August 8, 2002 16:02
See also http://freehackers.org/kvim/ - integrating Vim
in KDE. It looks really nice! (I'm not sure of exactly
what is needed to get it running i KMail though - but
look at those nice screenshots..)
zoran@spacemail.com, August 9, 2002 6:51
This tip is basically true for every mua that allows
integration of external editors, e.g. mutt
Anonymous, October 7, 2002 16:46
Thank you, thank you, thank you! I've been trying to
get this working for months! It takes just one
switch. Amazing.
drini@br.crashed.net, January 3, 2003 16:03

http://www.vim.org/tips/tip.php?tip_id=302 (1 of 2) [18/02/2004 14:53:04]

Tip #302 - Use gvim in kmail : vim online

Yes it works also with kvim (which is the KDE way ;)


just put "kvim -f %f"
and you're done, when you start typing, it fires up
kvim, when leave with :x you get back to kmail
kinda like when you use vim with pine
ugly.duck---SNIP---@---SNIP---gmx.de, February 19, 2003 20:57
I have been looking for that commandline-switch too!
"gvim --help" just says:
-f ... Foreground: Don't fork when starting GUI
which was not very helpful for me.
Thank you!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=302 (2 of 2) [18/02/2004 14:53:04]

SourceForge
Logo

Tip #303 - Statusline Tab Level Function Ruler TVIM : vim online

not logged in (login)

Home
Search

Tip #303: Statusline Tab Level Function Ruler TVIM


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -1/3, Viewed by 1423

created: August 8, 2002 2:05


author: TVIM Tamed Vim

complexity: basic
as of Vim: 6.0

I use this function to let me know if my cursor is on a


TAB column.
The t* on the ruler means I am not. But t3 means the
cursor is on tablevel 3
~vimrc ----------------------- My Ruler ----------------------- r4,c13,t3
~vimrc ----------------------- My Ruler ----------------------- r4,c14,t*
If you want to change a tab level you can drag or push
the first character
of a line to a desired tab level. (more on that later)
This ruler replacement will let you know where you are,
whether you
like to use space tabs (see vimtip #12 ) or regular
tabs. My function is set
to four space tabs stops and only goes 9 levels but can
be easily modified.
Actually I just wanted to learn how to use a function in
my _vimrc
and this was my first attempt. Add this to your _vimrc
"--------------------cut-----------------set laststatus=2
"This makes sure the ruler shows. See
help
laststatus
set statusline=%f\ ---------\ My\ Ruler\ ----------\
r%l,c%c,t%{ShowTab()}
"See help statusline (I toggle between 12 helpful
rulers -- more on that later)
fu ShowTab()
let TabLev='*'
let Col=(col("."))
if Col == 1 | let TabLev='0' | en
if Col == 5 | let TabLev='1' | en
if Col == 9 | let TabLev='2' | en
if Col ==13 | let TabLev='3' | en

http://www.vim.org/tips/tip.php?tip_id=303 (1 of 3) [18/02/2004 14:53:07]

Tip #303 - Statusline Tab Level Function Ruler TVIM : vim online

if Col ==17 | let TabLev='4' | en


if Col ==21 | let TabLev='5' | en
if Col ==25 | let TabLev='6' | en
if Col ==29 | let TabLev='7' | en
if Col ==33 | let TabLev='8' | en
if Col ==37 | let TabLev='9' | en
return TabLev
endf
"The ruler (statusline) shows a t* unless you are on col
1,5,9,13,...
"-------------------cut------------------This function ShowTab() gets called and updates the
ruler with every cursor
move but it does not slow things down as I
type. Perhaps a speed typist
may complain :-)
In case I write something else you may search on the key
word TVIM
Best Wishes
TVIM Tamed
Vim
paradocs@frontiernet.net
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Use gvim in kmail | fold braces and javadoc >>

Additional Notes
salmanhalim@hotmail.com, August 8, 2002 7:32
Looks like the tab level is basically set to ( col( '.'
) - 1 ) / 4. The 4 is probably the value of &ts
instead. Of course, this always returns a value even
if you're in the middle of a tab (not actually ON a
tabstop), so something like this:
let TabLevel = ( col( '.' ) - 1 ) / &ts
if ( ( TabLevel * &ts + 1 ) != col( '.' ) )
let TabLevel = '*'
endif
Works for all levels of tabs. . . The proof and
verification thereof is left to the reader as an
exercise(TM).
sputnik, May 20, 2003 14:14

http://www.vim.org/tips/tip.php?tip_id=303 (2 of 3) [18/02/2004 14:53:07]

Tip #303 - Statusline Tab Level Function Ruler TVIM : vim online

well, the 2nd example didnty work for me... so,


fu ShowTab()
let TabLevel=(col('.')-1)
if TabLevel == 0
let TabLevel='*'
endif
return TabLevel
endf
sputnik, May 20, 2003 14:26
and finaly i found THE solution......
fu ShowTab()
let TabLevel = (indent('.') / &ts )
if TabLevel == 0
let TabLevel='*'
endif
return TabLevel
endf
Anonymous, May 22, 2003 14:53
vimtip #477
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=303 (3 of 3) [18/02/2004 14:53:07]

SourceForge
Logo

Tip #304 - fold braces and javadoc : vim online

not logged in (login)

Home
Search

Tip #304: fold braces and javadoc


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 13/8, Viewed by 1104

created: August 10, 2002 4:47


author: Daniel Bauke

complexity: intermediate
as of Vim: 6.0

If you'd like to have javadoc folded together with areas


in braces try that
<pre>
set foldmethod=syntax
set foldenable
syn region foldBraces start=/{/ end=/}/ transparent fold
syn region foldJavadoc start=,/\*\*, end=,\*/,
transparent fold keepend
</pre>
and play a bit with:
<pre>
set foldlevel=0
set foldnestmax=10
</pre>
parameters
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Statusline Tab Level Function Ruler TVIM | Best of VIM Tips (VIM's best Features) >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=304 [18/02/2004 14:53:09]

SourceForge
Logo

Tip #305 - Best of VIM Tips (VIM's best Features) : vim online

not logged in (login)

Home
Search

Tip #305: Best of VIM Tips (VIM's best Features)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1417/453, Viewed by 25623

created: August 10, 2002 6:05


author: zzapper

complexity: intermediate
as of Vim: 5.7

Here's a necessarily cryptic list of "MY" Best Vim Tips


that I've gleaned
from http://vim.sf.net/ ;& comp.editors
http://groups.google.com/groups?safe=off&group=comp.editors
updated version at http://www.rayninfo.co.uk/vimtips.html
----------------------------------------------------------------------------# Absolutely essential
----------------------------------------------------------------------------vim.sf.net
: Visit frequently
comp.editors
: "VIM" dominated newsgroup
* # g* g#
: find word under cursor
(forwards/backwards)
%
: match brackets {}[]()
matchit.vim
: % now matches tags <tr><td><script> etc
<C-N> <C-P>
: word completion in insert mode
<C-X><C-L>
: Line complete SUPER USEFUL
/<C-R><C-W>
: Pull <cword> onto search/command line
:set ignorecase # you nearly always want this
:syntax on
: colour syntax in Perl,HTML,PHP etc
:h slash<C-D> : type control-D and get a list all help
topics containing
slash (plus use TAB for Help completion)
----------------------------------------------------------------------------# MAKE IT EASY TO UPDATE/RELOAD_vimrc
:nmap ,s :source $VIM/_vimrc
:nmap ,v :e $VIM/_vimrc
----------------------------------------------------------------------------#VISUAL MODE Mappings
:vmap sb "zdi<b><C-R>z</b><ESC> : wrap <b></b> around
VISUALLY selected Text
:vmap st "zdi<?= <C-R>z ?><ESC> : wrap <?=
?> around
VISUALLY selected Text
------------------------------------------------------------

http://www.vim.org/tips/tip.php?tip_id=305 (1 of 9) [18/02/2004 14:53:12]

Tip #305 - Best of VIM Tips (VIM's best Features) : vim online

-----------------# Exploring
:Ex
: file explorer note
capital Ex
\be
: builtin buffer explorer
:ls
: list of buffers(eg
following)
:cd ..
: move to parent directory
----------------------------------------------------------------------------# Great
guu
: lowercase line
gUU
: uppercase line
gf
: open file name under
cursor (SUPER)
ga
: display hex,ascii value
of character under cursor
ggVGg?
: rot13 whole file
CTRL-A,CTRL-X
: increment,decerement
number under cursor
win32 users must remap
CNTRL-A
CTRL-R=5*5
: insert 25 into text
----------------------------------------------------------------------------# Makes all other tips superfluous
:h 42
:h holy-grail
:help!
----------------------------------------------------------------------------# Markers & moving about
'.
: jump to last modification line (SUPER)
`.
: jump to exact spot in last modification
line
<C-O>
: retrace your movements in file (old)
<C-I>
: retrace your movements in file (new)
:ju(mps)
:help jump-motions
:history
: list of all your commands
----------------------------------------------------------------------------# Abbreviations & maps
:map
<f7>
:'a,'bw! c:/aaa/x
:map
<f8>
:r c:/aaa/x
:map
<f9>
:w<CR>:!c:/php/php.exe %<CR>
:map
<f11> :.w! c:/aaa/xr<CR>
:map
<f12> :r c:/aaa/xr<CR>
:ab php
: list of abbreviations beginning php
:map ,
: list of maps beginning ,
# For use in Maps
http://www.vim.org/tips/tip.php?tip_id=305 (2 of 9) [18/02/2004 14:53:12]

Tip #305 - Best of VIM Tips (VIM's best Features) : vim online

<CR>
: carriage Return for maps
<ESC>
: Escape
<LEADER>
: normally \
<BAR>
: | pipe
----------------------------------------------------------------------------# List your Registers
:reg
: display contents of all registers
"1p....
: retrieve numeric buffers
----------------------------------------------------------------------------# Useful trick
"ayy@a
: execute "Vim command" in a text file
yy@"
: same thing using unnamed register
----------------------------------------------------------------------------# Get output from other commands
:r!ls.exe
: reads in output of ls
!!date
: same thing
:%!sort -u
: use an external program to filter
content
----------------------------------------------------------------------------# Multiple Files Management
:wn
: write file and move to next (SUPER)
:bd
: remove file from buffer list (SUPER)
:sav php.html
: Save current file as php.html and "move"
to php.html
:sp fred.txt
: open fred.txt into a split
:e!
: return to unmodified file
:w c:/aaa/%
: save file elsewhere
:e #
: edit alternative file
:e %
:rew
: rewwind to first file in ARGS
:bn
: next file
:bp
: next file
:brew
----------------------------------------------------------------------------# Recording (BEST TIP of ALL)
qq # record to q
your commands
q
@q to execute
@@ to Repeat
# editing a register/recording
"ap
<you can now see register contents, edit as required>
"add
@a
-----------------------------------------------------------http://www.vim.org/tips/tip.php?tip_id=305 (3 of 9) [18/02/2004 14:53:12]

Tip #305 - Best of VIM Tips (VIM's best Features) : vim online

-----------------# _vimrc essentials


:set incsearch : jumps to search word as you type (annoying
but excellent)
:set wildignore=*.o,*.obj,*.bak,*.exe
:set shiftwidth=3
----------------------------------------------------------------------------# launching Win IE
:nmap ,f :update<CR>:silent !start
c:\progra~1\intern~1\iexplore.exe file://%:p<CR>
:nmap ,i :update<CR>: !start
c:\progra~1\intern~1\iexplore.exe <cWORD><CR>
----------------------------------------------------------------------------# FTPing from VIM
cmap ,r :Nread ftp://209.51.134.122/public_html/index.html
cmap ,w :Nwrite
ftp://209.51.134.122/public_html/index.html
gvim ftp://209.51.134.122/public_html/index.html
----------------------------------------------------------------------------# appending to registers (use CAPITAL)
# yank 5 lines into "a" then add a further 5
"a5yy
10j
"A5yy
----------------------------------------------------------------------------[I
: show lines matching word under cursor <cword>
----------------------------------------------------------------------------#Conventional Shifting
:'a,'b>>
# visual shifting (builtin-repeat)
:vnoremap < <gv
:vnoremap > >gv
----------------------------------------------------------------------------# searching
/^joe.*fred.*bill/ : normal
/^[A-J]\+/
: search for lines beginning A-J
followed by at leat 1 A-J
/forum\(\_.\)*pent
search over possible multiple lines
/fred\_s*joe/i
: any whitespace including newline
/fred\|joe
: Search for FRED OR JOE
----------------------------------------------------------------------------#substitution
:%s/fred/joe/igc
: general substitute command

http://www.vim.org/tips/tip.php?tip_id=305 (4 of 9) [18/02/2004 14:53:12]

Tip #305 - Best of VIM Tips (VIM's best Features) : vim online

:%s/\r//g
: Delete DOS returns ^M
:'a,'bg/fred/s/dick/joe/gc : VERY USEFUL
:s/\(.*\):\(.*\)/\2 : \1/ : reverse fields separated by :
:%s/^.\{-}pdf/new.pdf/ non greedy matching (ie to first
pdf)
:s/fred/<c-r>a/g substitute "fred" with contents of
register "a"
:%s/^\(.*\)\n\1/\1$/ delete duplicate lines
# non-greedy matching \{-}
:%s/^.\{-}pdf/new.pdf/
:help /\{-}
:s/fred/<c-r>a/g substitute "fred" with contents of
register "a"
# multiple commands
:%s/\f\+\.gif\>/\r&\r/g | v/\.gif$/d | %s/gif/jpg/
:%s/suck\|buck/loopy/gc : ORing
:s/__date__/\=strftime("%c")/ : insert datestring
----------------------------------------------------------------------------# global command
:g/^\s*$/d
:delete all blank lines
:g!/^dd/d
: delete lines not containing string
:v/^dd/d
: delete lines not containing string
:g/fred/,/joe/d : not line based
:v/./.,/./-1join : compress empty lines
:'a,'b g/^Error/ . w >> errors.txt
:g/cmap\|form/p : ORing
----------------------------------------------------------------------------# Paste register *
:redir @*
: redirect commands to paste
:redir END
"*yy
: yank to paste
"*p
: insert paste buffer
----------------------------------------------------------------------------# Formatting text
gq<CR>
gqap (a is motion p paragraph (visual mode))
----------------------------------------------------------------------------# Operate command over multiple files
:argdo %s/foo/bar/
:bufdo %s/foo/bar/
:windo %s/foo/bar/
----------------------------------------------------------------------------# Command line tricks
gvim -h
ls | gvim : edit a PIPE!!
# vg.ksh (shell script)
http://www.vim.org/tips/tip.php?tip_id=305 (5 of 9) [18/02/2004 14:53:12]

Tip #305 - Best of VIM Tips (VIM's best Features) : vim online

# vi all files in directory containing keyword $1 and jump


to $1
gvim.exe -c "/$1" $(grep -isl "$1" *) &
----------------------------------------------------------------------------rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<fold braces and javadoc | Open a web-browser with the URL in the current line >>

Additional Notes
y_ellzs@tsmc.com.tw, August 11, 2002 7:36
test
david@tvis.co.uk, August 14, 2002 13:35
Just a reminder that this is just my
selection,but there's plenty of other good tips
in the vim tip collection
# Vim traps
In regular expressions you must backslash + (match 1 or
more)
/fred\+/
: matches fred/freddy but not free
---------------------------------------# \v or very magic (usually) reduces backslashing
/codes\(\n\|\s\)*where : normal regexp
/\vcodes(\n|\s)*where
: very magic
---------------------------------------# pulling objects onto command/search line (SUPER)
CTRL-R CTRL-W Pull word under the cursor into a command
line or search
CTRL-R : pull small register
CTRL-R [0-9a-z]
: pull named registers
CTRL-R %
: pull file name (also #)
---------------------------------------# manipulating registers
map
<f11> "qyy:let @q=@q."zzz"
---------------------------------------# help
:h visual<C-D><tab>
: obtain list of all visual help
topics
: Then use tab to step thru them
---------------------------------------# where was an option set
:verbose set history
: reveals value of history and
where set

http://www.vim.org/tips/tip.php?tip_id=305 (6 of 9) [18/02/2004 14:53:12]

Tip #305 - Best of VIM Tips (VIM's best Features) : vim online

---------------------------------------# running file thru an external program (eg php)


map
<f9>
:w<CR>:!c:/php/php.exe %<CR>
---------------------------------------david@tvis.co.uk, September 13, 2002 1:45
# Inserting Carriage Returns
:%s/nubian/<C-V><C-M>&/g
: that's what you type
:%s/nubian/<C-Q><C-M>&/g
: for Win32
:%s/nubian/^M&/g
: what you'll see
where ^M is ONE character
---------------------------------------# Retrieving last command line command for copy & pasting
into text
<c-r>:
# Retrieving last Search Command for copy & pasting into
text
<c-r>/
---------------------------------------# doing things over multiple lines \_ means including
newline
/<!--\_p\{-}-->
: search for multiple
line comments
/fred\_s*joe/i
: any whitespace
including newline
/bugs\(\_.\)*bunny
: bugs followed by
bunny anywhere in file
:h \_
: help
---------------------------------------# more completions
<C-X><C-F>
:insert name of a
file in current directory
---------------------------------------# help for help
:h visual<C-D><tab>
: obtain list of all visual help
topics
: Then use tab to step thru them
:h ctrl<C-D>
: list help of all control keys
:h :r
: help for :ex command
:h CTRL-R
: normal mode
:h \r
: what's \r in a regexp
:h i_CTRL-R
: help for say <C-R> in insert
mode
:h c_CTRL-R
: help for say <C-R> in command
mode
:h v_CTRL-V
: visual mode
---------------------------------------kdr_tech@yahoo.com, November 3, 2002 10:23

http://www.vim.org/tips/tip.php?tip_id=305 (7 of 9) [18/02/2004 14:53:12]

Tip #305 - Best of VIM Tips (VIM's best Features) : vim online

This is an extension to
# pulling objects onto command/search line
If you use
/CTRL-R CTRL-A
it brings the whole word under the cursor including any
special characters.
For Ex:
If you are in a HTML page and the cursor is under a
keyword <table>
/CTRL-R CTRL-A brings /<table>
/CTRL-R CTRL-W brings /table (depending on what the
letter under your cursor is ... table or < or >
-Kdr
zzapper@ntlworld.com, December 23, 2002 11:42
The Buffer Explorer scripts mentioned above (\be \bs)
rely on the 2nd most popular VIM script bufexplorer.vim
available at
http://www.vim.org/script.php?script_id=42
Nov-2002

updated 05-

This is a must have script.


Have recently started to appreciate taglist.vim (the most
popular VIM script) it really comes into it's own with
very long programs containting lots of
subroutines/functions as it shows which function/sub
you're in etc etc
http://www.vim.org/script.php?script_id=273 updated 20dec-02
zzapper
wisniewski@frontiernet.net, June 13, 2003 17:28
#ftping with vim

- great functionality

for ascii file transfers add the following line to your


profile
let g:netrw_ftpmode="ascii"
junk4todd@dogbus.org, July 16, 2003 12:06

http://www.vim.org/tips/tip.php?tip_id=305 (8 of 9) [18/02/2004 14:53:12]

Tip #305 - Best of VIM Tips (VIM's best Features) : vim online

If you want to delete multiple duplicate lines in a


sorted file:
:%s/^\(.*\)\n\(\1\n\)*/\1<NL>/
where <NL> is the character sequence that represents a
return in your file type. For Windows, the easiest way
to get this is to highlight a return character in another
program (open a new notepad, hit return once, select all,
and copy) and then use Edit -> Paste in VIM to insert it.
shankarpj@yahoo.com, January 11, 2004 21:28
If you want to number the lines in the file try:
:%! nl -ba
sx7gs7r02@sneakemail.com, February 8, 2004 19:02
Hi,
I think rot13 of the whole file can be improved by this:
ggg?G
It's so much better to read. Saves one byte over ggVGg?
Also, it does not require the overhead of selecting the
whole file,
especially if the file is huge.
Arvind
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=305 (9 of 9) [18/02/2004 14:53:12]

SourceForge
Logo

Tip #306 - Open a web-browser with the URL in the current line : vim online

not logged in (login)

Home
Search

Tip #306: Open a web-browser with the URL in the current line
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 10/4, Viewed by 1796

created: August 10, 2002 21:10


author: Kartik Agaram

complexity: intermediate
as of Vim: 5.7

function! Browser ()
let line = getline (".")
let line = matchstr (line, "http[^ ]*")
exec "!netscape ".line
endfunction
map <Leader>w :call Browser ()<CR>

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Best of VIM Tips (VIM's best Features) | annoying "Hit any key to close this window..." >>

Additional Notes
littledragon@altern.org, August 12, 2002 2:48
http[^ ]* could be replaced with \%(http\|www\.).\{-}\>
littledragon@altern.org, August 12, 2002 2:53
Hrm... The above wouldn't work. Better try:
\%(http://\|www\.\)[^ ,;\t]*
ksteen@users.sourceforge.net, August 12, 2002 11:19
I use a similar script when editing html files to view
changes made to the file.
if exists("loaded_mozilla")
finish
endif
let loaded_mozilla=1
"Setup commands to run mozilla.
":Mozilla - open current file in mozilla.
if !exists(':Mozilla')
command Mozilla :call s:StartMozilla()
http://www.vim.org/tips/tip.php?tip_id=306 (1 of 3) [18/02/2004 14:53:14]

Tip #306 - Open a web-browser with the URL in the current line : vim online

endif
function! s:StartMozilla()
" let s:myfile = getcwd() . "/" . bufname("%")
let s:myfile = expand("%:p")
let s:a = "mozilla -remote 'openurl(file://"; . s:myfile
. ")'"
let s:r =system(s:a)
"Mozilla is not running so start it."
if s:r =~"No running window found."
unlet s:a
let s:a = "mozilla " . s:myfile . "&"
let s:r =system(s:a)
endif
endfunction
Both Netscape and Mozilla accept the remote argument which
reloads an open browser with the supplied url.
David Fishburn, June 25, 2003 8:08
Here is a more generic way to execute a URL (windows only):
vnoremap <silent> <C-F5> :<C-U>let
old_reg=@"<cr>gvy:silent!!cmd /cstart <C-R><CR>"<CR><CR>:let @"=old_reg<cr>
If you visually highlight something, then hit CTRL-F5, it
will tell windows to start the default associated
application.
http://vim.sourceforge.net/tips/add_tip_note.php?tip_id=306
- On my machine this will launch Mozilla (since that is my
default browser).
dave.txt
- On my machine this will launch gvim, on default windows
machines this would launch notepad.exe.
Benyang Tang, January 22, 2004 20:42
This is my modification. It works for http:, ftp: and file:
===============
function! Browser ()
let line0 = getline (".")
let line = matchstr (line0, "http[^ ]*")
:if line==""
let line = matchstr (line0, "ftp[^ ]*")
:endif
:if line==""
let line = matchstr (line0, "file[^ ]*")
:endif
"
echo line

http://www.vim.org/tips/tip.php?tip_id=306 (2 of 3) [18/02/2004 14:53:14]

Tip #306 - Open a web-browser with the URL in the current line : vim online

exec ":silent !mozilla ".line


endfunction
map \w :call Browser ()<CR>
=================
Benyang Tang, January 23, 2004 0:28
Further refinement: (For URL with #?&|%, such as one from a
google search)
"=== evoke a web browser
function! Browser ()
let line0 = getline (".")
let line = matchstr (line0, "http[^ ]*")
:if line==""
let line = matchstr (line0, "ftp[^ ]*")
:endif
:if line==""
let line = matchstr (line0, "file[^ ]*")
:endif
let line = escape (line, "#?&;|%")
"
echo line
exec ":silent !mozilla ".line
endfunction
map \w :call Browser ()<CR>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=306 (3 of 3) [18/02/2004 14:53:14]

SourceForge
Logo

Tip #307 - annoying "Hit any key to close this window..." : vim online

not logged in (login)

Home
Search

Tip #307: annoying "Hit any key to close this window..."


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -8/13, Viewed by 1638

created: August 11, 2002 5:57


author: Chia-po Wei

complexity: basic
as of Vim: 6.0

i use gvim and bash heavily under win98.


i have
let $HOME = substitute($HOME, '\', '/', 'g')
set shell=bash\ --rcfile\ \"$HOME\"_bashrc\ -i
in my _vimrc, and something like
function br()
{
if [ $1 ]; then
explorer.exe ${1//\//\\}
else
explorer.exe ${PWD//\//\\}
fi
}
in my _bashrc. when i finish editing one html file,
i simply type :!br %
everything works fine now. but when :!br % executes,
one console window will bump out and wait me to press
some
key to contiue. i consider this quiet annoying. i want
the console window
to disappear automatically if no fault has happened.
does anyone know how to achieve this?
thanks.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Open a web-browser with the URL in the current line | Move through wrapped lines. >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=307 (1 of 2) [18/02/2004 14:53:17]

Tip #307 - annoying "Hit any key to close this window..." : vim online

ephemera@pchome.com.tw, August 11, 2002 8:57


i find
set shell=bash\ -i
can replace
set shell=bash\ --rcfile\ \"$HOME\"_bashrc\ -i
as long as $HOME is properly set
Chia-po Wei
none, August 12, 2002 5:54
I think a tip is supposed to ANSWER a question, not
pose one.
Anonymous, August 12, 2002 9:39
Obviously, none don't know.
SpiceMan, August 14, 2002 10:32
instead of using
:!br %
use
:silent !br %
that'll do it, just asign it to a key ;)
ephemera, August 18, 2002 6:03
thanks to SpiceMan :p
i feel sorry to pose my problem here.
but i think the description of my problem may be
helpful to someone
using both bash and vim.
jdsumsion, September 9, 2002 9:07
Try recompiling the source for vimrun -- it is the
program that runs and displays the "Hit any key to
close this window..." message.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=307 (2 of 2) [18/02/2004 14:53:17]

SourceForge
Logo

Tip #308 - Move through wrapped lines. : vim online

not logged in (login)

Home
Search

Tip #308: Move through wrapped lines.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 68/29, Viewed by 1185

created: August 12, 2002 1:34


author: Little Dragon

complexity: intermediate
as of Vim: 5.7

If you don't like the fact that when you press Up and
Down on a wrapped line, you get to the next phisical
line instead of the next line on the screen, you can do
something like this:
imap <silent> <Down> <C-o>gj
imap <silent> <Up> <C-o>gk
nmap <silent> <Down> gj
nmap <silent> <Up> gk
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<annoying "Hit any key to close this window..." | close vim you left open remotely >>

Additional Notes
Anonymous, March 9, 2003 16:55
just make sure that you don't do something odd like I
did and copy the spaces at the end of the code :S.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=308 [18/02/2004 14:53:19]

SourceForge
Logo

Tip #309 - close vim you left open remotely : vim online

not logged in (login)

Home
Search

Tip #309: close vim you left open remotely


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 21/12, Viewed by 1455

created: August 12, 2002 22:27


author: noah

complexity: intermediate
as of Vim: 6.0

Vim 6 has this cool client-server protocol. I use it all


the time to edit a file in an existing gvim, like so
$ gvim --remote [filename]
Today I left myself logged in at the console at work,
and when I got home I realized I had left vim running
with files unsaved. I think I even left it in insert
mode. I wanted to edit these files at home. So I ssh'd
to the machine and started playing with the --remote
commands.
:help was a bit cryptic
--remote-send {keys}
and exit.

Send {keys} to server

After a lot of failed attempts, I finally succeeded in


getting the remote vim to save its buffers and quit.
$ DISPLAY=:0 vim --servername GVIM --remote-send
'<ESC>:wqa<CR>'
A couple of notable things. Then environment variable
DISPLAY has to be the display of the remote vim, and you
have to be able to open that display. The client-server
stuff is done through X.
The <CR> is important. This part eluded me for a long
time. The {keys} are just like keys you would press if
you were editing at the console, and you have to press
enter, or vim won't do anything.
Check your .swp files to make sure vim really closed the
files it was editing. Vim provides little feedback as to
the success or failure of what you're trying to do
remotely. Nonetheless, it's clearly a useful feature to
have available.

http://www.vim.org/tips/tip.php?tip_id=309 (1 of 2) [18/02/2004 14:53:22]

Tip #309 - close vim you left open remotely : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Move through wrapped lines. | showing ascii value of the current character in decimal, hex, and
octal >>

Additional Notes
rahul.agrawal@mapleoptical.com, August 13, 2002 11:09
Yeah. Its pretty cool, and provides an edge over other
editors.
Anonymous, September 28, 2002 10:54
To get better feedback you can use the :redir command
to redirect messages to a file, like this:
vim --servername GVIM --remote-send ':redir >>
outputfile<cr>'
You can also evaluate remote expressions, ie:
vim --servername GVIM --remote-expr 'mode()'
this will tell you what mode vim is currently in and
vim --servername GVIM --remote-expr 'getcwd()'
will tell you what directory vim is working in
Anonymous, January 23, 2004 9:17
I never have to worry about leaving a file open,
unsaved. I used to do that a lot, and have developed a
nervous habbit of saving a LOT.
If you are like me, and don't have to worry about that,
then you can simply type "killall vim", and all open
vim's will close themselfs. If you just want to kill
one type "ps -ef | grep vim" to find the pid. You can
then type "kill 1234" where 1234 is the pid.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=309 (2 of 2) [18/02/2004 14:53:22]

SourceForge
Logo

Tip #310 - showing ascii value of the current character in decimal, hex, and octal : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #310: showing ascii value of the current character in decimal,


hex, and octal
tip karma

Rating 19/11, Viewed by 1213

created: August 13, 2002 12:10


author: calvin wong

complexity: basic
as of Vim: 6.0

dont know if you guys know this or not, but i was trying
to make the word "hello" to upper case by trying "gaUw"
(=
which didnt work but it showed the decimal, hex, and
octal of the char under the cursor... ncie to know.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<close vim you left open remotely | Open the folder containing the currently open file >>

Additional Notes
calvin wong, August 13, 2002 12:11
DOH.... i forgot.
its "ga" or ":as" or ":ascii"
Anonymous, August 18, 2002 10:03
vimtip #67
oxcrete@yahoo.com, August 26, 2002 10:53
Don't kow if you already knew this but, the "~" "tilde"
character changes the case of the caharacter under the
cursor and "[count]~" changes the case of "count"
number of characters as in "5~" changes the case of 5
characters. the count is a VIm feature but ~ is an old
vi feature.
keramida@ceid.upatras.gr, October 6, 2002 20:25
Actually, the [count]~ feature is also there in quite
old vi
implementations too. Even Solaris has it in old
versions...
http://www.vim.org/tips/tip.php?tip_id=310 (1 of 2) [18/02/2004 14:53:24]

Tip #310 - showing ascii value of the current character in decimal, hex, and octal : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=310 (2 of 2) [18/02/2004 14:53:24]

SourceForge
Logo

Tip #311 - Open the folder containing the currently open file : vim online

not logged in (login)

Home
Search

Tip #311: Open the folder containing the currently open file
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 15/9, Viewed by 1073

created: August 13, 2002 16:40


author: Thomas R. Kimpton

complexity: basic
as of Vim: 5.7

Occasionally, on windows, I have files open in gvim,


that the folder for that file is not open. This key map
opens the folder that contains the currently open file.
The expand() is so that we don't try to open the folder
of an anonymous buffer, we would get an explorer error
dialog in that case.
if has("gui_running")
if has("win32")
" Open the folder containing the currently open
file. Double <CR> at end
" is so you don't have to hit return after command.
Double quotes are
" not necessary in the 'explorer.exe %:p:h' section.
:map <silent> <C-F5> :if expand("%:p:h") !=
""<CR>:!start explorer.exe %:p:h<CR>:endif<CR><CR>
endif
endif
Tom.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<showing ascii value of the current character in decimal, hex, and octal | Copy, Cut, and Paste >>

Additional Notes
Anonymous, August 14, 2002 7:46
Why have it inside a gui_running block?
a difference?)
Alan.S.Budden@virgin.net, August 21, 2002 2:28

http://www.vim.org/tips/tip.php?tip_id=311 (1 of 2) [18/02/2004 14:53:26]

(Does it make

Tip #311 - Open the folder containing the currently open file : vim online

If you prefer to use full explorer windows (with folder


pane etc), modify as follows:
... !start explorer.exe %:p:h,/e<CR>:endif<CR><CR>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=311 (2 of 2) [18/02/2004 14:53:26]

SourceForge
Logo

Tip #312 - Copy, Cut, and Paste : vim online

not logged in (login)

Home
Search

Tip #312: Copy, Cut, and Paste


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 134/60, Viewed by 4036

created: August 13, 2002 23:20


Anis W. Nugroho
author:
(anis_wn@cbn.net.id)

complexity: intermediate
as of Vim:

5.7

PS: copy, cut, and paste are the words from (usually)
gui editor.
Ever try to cut (or copy) some lines and paste to
another place?
If you need to count the lines first, then try these to
eliminate counting task.
Cut and Paste:
1. Place the cursor at the beginning of the block you
want to CUT.
2. Mark it with md
3. Go to the end of the block.
4. Cut it with d'd
5. Go to the new location that you want to PASTE those
text.
6. Press P.
Copy and Paste:
1. Place the cursor at the beginning of the block you
want to COPY.
2. Mark it with my
3. Go to the end of the block.
4. Cut it with y'y
5. Go to the new location that you want to PASTE those
text.
6. Press P.
The name of the mark used is related to the operation
(d:delete or y:yank).
I found that those mark names requires minimal movement
of my finger. ;)
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=312 (1 of 3) [18/02/2004 14:53:28]

Helpful

Unfulfilling

rate

Tip #312 - Copy, Cut, and Paste : vim online

<<Open the folder containing the currently open file | printing using kprinter (unix + kde) >>

Additional Notes
anis_wn@cbn.net.id, August 13, 2002 23:24
Sorry, step 4 for Copying supposed to be 'Copy...' :(
marcin@amiga.pl, August 13, 2002 23:31
2. Press v to select block
4. Cut it with "dd
4. Copy it with "yd
6. Press P (if you want to paste before) or p (if you
want to paste after).
6. If you want to paste it later press "dp (or "yp for
copy) to insert it after.
rainbrot@snark.com, August 18, 2002 3:12
Cut and paste:
1. Position the cursor where you want to begin cutting.
2. Press v (or upper case V if you want to cut whole
lines).
3. Move the cursor to the end of what you want to cut.
4. Press d.
5. Move to where you would like to paste.
6. Press p to paste after the cursor, or P to paste
before.
Copy and paste can be performed with the same steps,
only pressing y instead of d in step 4.
If you want to copy and paste between editor buffers
(but not between instances of vim), or if you want to
maintain multiple "clipboards" (copy buffers), you can
name your buffer by pressing "x (that's a double quote
followed by x, where x is the single letter name you
choose for your buffer) before the d in step 4, and
again before the p in step 6.
If you happen to be using gvim for Windows and want to
copy or cut into the Windows clipboard, press
Ctrl+Insert in step 4 (to copy) or Shift+Delete to
cut. To paste from the Windows clipboard, press
Shift+Insert.
dedekind@mail.ru, November 16, 2003 1:23

http://www.vim.org/tips/tip.php?tip_id=312 (2 of 3) [18/02/2004 14:53:28]

Tip #312 - Copy, Cut, and Paste : vim online

Hello Guys. How to copy and paste between two instances


of Vim on different Linux consoles?
anis_wn@cbn.net.id, November 28, 2003 13:41
after copying text, open a new buffer for a new file,
ie
:e ~/dummy
paste the text to the new buffer.
write the new buffer. (:w)
switch to the previous buffer (:bp) to release *.swp
now switch to the other console.
put the cursor at the desired place.
read the dummy file (:r ~/dummy).
that's it.
the question is "why do you want to play in the other
console? use multi buffer editing instead."
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=312 (3 of 3) [18/02/2004 14:53:28]

SourceForge
Logo

Tip #313 - printing using kprinter (unix + kde) : vim online

not logged in (login)

Home
Search

Tip #313: printing using kprinter (unix + kde)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 38/16, Viewed by 853

created: August 14, 2002 3:47


author: tom regner

complexity: basic
as of Vim: 6.0

just add
set printexpr=system('kprinter'\ .\ '\ '\ .\
v:fname_in)\ .\ delete(v:fname_in)\ +\ v:shell_error
to your ~/.vimrc; further on all your printing will be
piped through the nice and consistent print-dialog of
kde.
lg,
tomte
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Copy, Cut, and Paste | Insert and back... >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=313 [18/02/2004 14:53:31]

SourceForge
Logo

Tip #314 - Insert and back... : vim online

not logged in (login)

Home
Search

Tip #314: Insert and back...


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 13/10, Viewed by 1377

created: August 14, 2002 16:29


author: Alex A. Naanou

complexity: intermediate
as of Vim: 5.7

this is related to vimtip #289 in terms of programmers


(like I) too lazy to move their hands to reach the far
far away <esc> key.... joking! :)
actually the less your hands move around the faster
you type, and the fester you type the more time you have
on your hands to think of "what" you type...
here is a small snippet from my mappings file, ready to
speed things up:
// the key overloading might be a somewhat confusing at
first....
--cut--imap <S-Space> <esc>l
imap <C-CR> <esc>o
imap <S-CR> <esc>O
nmap <S-Space> i
nmap <space><space> i
nnoremap <CR> o
nmap <S-CR> O
---uncut--Good luck!!
rate this tip

Life Changing

Helpful

<<printing using kprinter (unix + kde) | "Smart <home>" >>

Additional Notes
viking@vi.king.net, August 16, 2002 7:54

http://www.vim.org/tips/tip.php?tip_id=314 (1 of 4) [18/02/2004 14:53:33]

Unfulfilling

rate

Tip #314 - Insert and back... : vim online

I would rather extend my pinky quickly to <ESC>


than pressing two keys at the same time.
What is wrong with <ESC> key ?
By trying to press <SHIFT> "and" <SPACE> at the
same time, your whole hand is already moved downward,
which actually delays the process. I think that you are
not
a touch typist, in which case this is not bothering at
all.
However, for the touch typist, moving the whole hand is
the most annoying thing.
By pressing <ESC> alone with your pinkie, you don't
need to
move your whole hand, and get back to the your typing
very
quickly without looking at the keyboard.
Alex A. Naanou <alex_nanou@yahoo.com>, August 16, 2002 16:19
I personally rest my hands on the keyboard, so as to
have my forefingers relaxed on "f" and "j", my thumbs
on "<space>", pinkys on "<Caps>" and " ' ", and the
middle fingers touching the "number keys". so I reach
all the keys without lifting or moving either hand. all
but the function keys and <esc> to get to which I have
to lift the whole arm, and that turns into a problem as
the escape key gets pressed almost as often as the
shift key.
so what was proposed by Jeffrey Lim in vimtip #289
was quite natural for me, all but the double <S-Space>
which I find a bit slow...
which mappings work for you an which don't, depends
on how you hold your hands, your typing style and maybe
you keyboard, and that is your choice to make...
Best Regards...
Alex.
enviameloa@hotmail.com, August 17, 2002 13:11
I personally found mapping <esc> key to a double
pressing "J" while in insert mode faster and very
convinient.
imap jj <esc>
give it a try,
by
viking@vi.king.net, August 21, 2002 9:40

http://www.vim.org/tips/tip.php?tip_id=314 (2 of 4) [18/02/2004 14:53:33]

Tip #314 - Insert and back... : vim online

mapping jj to ESC... What an excellent idea !


There is no occasion to type jj in any situation,
so jj should be just fine. Yes, it should be much
faster.
But I still need to make it as my habit. Still, because
of
my habit, extending my pinkie to ESC is faster at
this moment.
Thanks a lot ! :-)
Alex A. Naanou <alex_nanou@yahoo.com>, August 21, 2002 17:24
Cool!! I think this one is worth the adaptation
period!! :)
pressing one button in the middle of the keyboard
twice is a lot more intuitive than <S-Space>, and may
be quite a speedup if you spend the time to get used to
it.....
Thanks!!
nithin_sujir@yahoo.com, September 13, 2002 17:47
Ya jj is good. I'm used to <M-j>
jamesb@panmatrix.net, October 19, 2002 15:13
> There is no occasion to type jj in any situation,
Yeah, except when you're trying to add it to your
.vimrc file. ;)
Great idea.
rando@babblica.net, November 6, 2002 4:42
Of course, if you ever DO need to actually type j
twice, you can wait a half second or so between them
(until the cursor moves).
Though Idunno if I could ever get used to something
like this. the escape key isn't that far away. ;)
dev@gaspardbuma.org, June 10, 2003 0:41

http://www.vim.org/tips/tip.php?tip_id=314 (3 of 4) [18/02/2004 14:53:33]

Tip #314 - Insert and back... : vim online

Hi !
I got used to work with the US keyboard layout (much
better for programming : easy access to ;:/.?\"]}[{<>)
instead of the swiss-french one. I found the idea of jj
great, but decided to use jk (faster, two muscles
driven, fun).
impa jk <Esc>
ps : more over, jk makes joke if you try to say it, and
that's very cool.
dev@gaspardbuma.org, June 10, 2003 0:43
sorry for the misstyping :
imap jk <Esc>
fatboyco93@hotmail.com, February 6, 2004 2:18
Hey,
I seemed to type the imap thing just as you said but it
doesn't seem to work.
I typed
imap jj <Esc>
in my .vimrc file but when i'm insert mode it just
gives me a bunch of jj's. Is it just me?
Chad
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=314 (4 of 4) [18/02/2004 14:53:33]

SourceForge
Logo

Tip #315 - "Smart <home>" : vim online

not logged in (login)

Home
Search

Tip #315: "Smart <home>"


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 27/20, Viewed by 1862

created: August 14, 2002 16:46


author: Alex A. Naanou

complexity: advanced
as of Vim: 5.7

to make it faster to navigate through indented code here is a common way


to "go home"...
---cut--fun! s:SmartHome()
if col('.') != match(getline('.'), '\S')+1
norm ^
else
:call cursor(line('.'),2)
norm h
endif
endfun
inoremap <silent><home> <C-O>:call <SID>SmartHome()<CR>
nnoremap <silent><home> :call <SID>SmartHome()<CR>
vnoremap <silent><home> :call <SID>SmartHome()<CR>
---uncut--what this snippet does is make the <home> key behave as it does in such
IDEs as PythonWin or MSVisualStudio, and that is first go to the first
non whitespace, and then to the first char on the line.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Insert and back... | Using /pattern/ search in a script >>

Additional Notes
Anonymous, August 15, 2002 1:16
What's the point of this tip?

I'm happy using ^ and 0 (zero).

Anonymous, August 15, 2002 4:33


nmap <HOME> ^
But, I agree with the previous comment, 0 and ^ are within finger
reach.
jmcpherson@softhome.net, August 15, 2002 10:38

http://www.vim.org/tips/tip.php?tip_id=315 (1 of 3) [18/02/2004 14:53:35]

Tip #315 - "Smart <home>" : vim online

This tip does have a point -- it's helpful for those who are
transitioning from their favorite IDEs to Vim. I use 0 and ^ because I
have them memorized, but others might not...
For those who spend a lot of time in their text editors, it's worth a
few hours of learning up-front -- certainly, the time spent learning
shortcuts like "*" and "t" pays for itself many times over. For others,
who might spend only a little while with their editor, it might not.
For them, it's useful to know that a few lines of code can make Vim
behave like what they already know. And if you happen be such a person,
you may wish to check out Cream, which makes Vim much easier to use for
beginners:
http://cream.sourceforge.net/
And, while I'm being unorthodox, I may as well add a question to my
note:
In some IDEs, the behavior of Home varies depending on how many times
you press it. The first time, it goes to the beginning of the line; the
second, to the top of the screen; and the third, to the top of the
file. This is trivial to accomplish in Vim -- something like
map <HOME> ^
map <HOME><HOME> H
map <HOME><HOME><HOME> gg
But Vim will hesitate after the first Home press to see if you are
going to press Home again (and likewise for the second Home). This
interval can be adjusted with the (t)timeoutlen option, but it is
difficult to select a value that makes <HOME> near-instantaneous and
still make the whole sequence easy to enter without hand spasms.
Is there any way to
be fairly simple to
could check and see
line (or at the top

see what the last few keypresses were? If so, it'd


check them and behave correctly. Or, I suppose, you
if the cursor was _already_ at the beginning of the
of the screen) and behave correctly. Hmmm.

hermitte at free.fr, August 15, 2002 13:29


"Banging" the "normal" calls could be useful.
Otherwise, here is another way to do the same thing :
http://hermitte.free.fr/vim/ressources/vimfiles/plugin/homeLikeVC++.vim
Alex A. Naanou <alex_nanou@yahoo.com>, August 15, 2002 15:56
indeed '0' and '^' are the natural and fast way to use, unless you are
in insert mode, and then it turns into '<home>' and '<C-O>^'. the later
takes two keystrokes "longer" to type, and is used more often (at least
by me)!
'imap <home> <C-O>^' would have been easier to write, but my goal was
to make it both as simple (from the users' point of view) and as fast
as possible.. the perfect solution in my opinion was the way it was
done by the packages I mentioned in the tip.

P.S. I'm on vim since version 4.3a3 (WVim to be exact) :)


Best Regards...
Alex.
Simon Shine <simon at blueshell.dk>, August 19, 2002 11:13

http://www.vim.org/tips/tip.php?tip_id=315 (2 of 3) [18/02/2004 14:53:35]

Tip #315 - "Smart <home>" : vim online

I don't own a keyboard where the home key is any near my fingers, so I
prefer to use '^' and the like. Considering the time it takes to go
into normal mode, do my thing and then return to insert mode rather
than using home, this function is useless; to me, anyway.
lailoken@freeshell.org, August 26, 2002 9:17
Unless I'm confused, why not just use the function like so:
fun! s:SmartHome()
if col('.') == 1
norm ^
else
norm 0
endif
endfun
Please send me email in this regard...
Alex A. Naanou <alex_nanou@yahoo.com>, August 28, 2002 16:23
Thanks for the remark!!!
The function mentioned above is OK, but the thing I wanted is to do
'^' if we are not on the first non-whitespace else do '0'. the proposed
above function does the opposite (first '0' then '^')
// And I must admit that my original else clause is overcomplicated!! (using norm 0 is sufficient) :)
and here we have the new and improved version:
---cut--fun! s:SmartHome()
" this line checks if we are not on the first whitespace.
if col('.') != match(getline('.'), '\S')+1
norm ^
else
norm 0
endif
endfun
inoremap <silent><home> <C-O>:call <SID>SmartHome()<CR>
nnoremap <silent><home> :call <SID>SmartHome()<CR>
vnoremap <silent><home> :call <SID>SmartHome()<CR>
---uncut--Thanks again!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=315 (3 of 3) [18/02/2004 14:53:35]

SourceForge
Logo

Tip #316 - Using /pattern/ search in a script : vim online

not logged in (login)

Home
Search

Tip #316: Using /pattern/ search in a script


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 7/4, Viewed by 1220

created: August 19, 2002 22:54


author: David Brown

complexity: intermediate
as of Vim: 6.0

There are a number of ways you can search for a pattern


in a script.
The search function is the typical way to
search for a pattern. But, it has limited options. In
particular, there are no options to control the position
of the cursor after it matches the pattern.
Instead you can use :normal command. The secret is to
add a <CR> (^M) on the end of the command.
For
example, to search for "pattern" and move the cursor to
the end of the matching pattern issue the command:
:normal /pattern/e+1^M
where ^M is a real carriage return.
with <c-v><c-m>.

It can be entered

Another use is when you want to enter a bunch of normal


commands together. For example, if you were looking to
find a '{' to highlight and delete a C block. The '{'
may not be on the same line so you can't use the "f"
normal command.
:normal V/{/^M%d
A drawback to using the normal command is that if the
pattern does not match then it is difficult to
detect. Also, you can get in trouble with the wrapscan
setting.
For more information about these commands look at
:help /
:help normal
:help search()
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=316 (1 of 2) [18/02/2004 14:53:38]

Helpful

Unfulfilling

rate

Tip #316 - Using /pattern/ search in a script : vim online

<<"Smart <home>" | Mozilla Vim Keybindings >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=316 (2 of 2) [18/02/2004 14:53:38]

SourceForge
Logo

Tip #317 - Mozilla Vim Keybindings : vim online

not logged in (login)

Home
Search

Tip #317: Mozilla Vim Keybindings


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 83/29, Viewed by 3195

created: August 21, 2002 21:23


author: Matthew J. Stott

complexity: basic
as of Vim: 5.7

If you use VIM you like the h, j, k, and l movement keys. I found myself
annoyed at not having these movement keys available when browsing web
pages. Moving to the arrow keys on a laptop is annoying to just scroll the
page.
Locate your mozilla/res/builtin directory (varies by platform). You could
search for htmlBindings.xml to find it. (ie. locate htmlBindings.xml.
On Mac OS X it's inside the Mozilla application
bundle. /Applications/Mozilla/Mozilla.app/Contents/MacOS/res/builtin.
Create a new XML file called userHTMLBindings.xml, making it executable for
all users and making sure the CRLF format is the same as
htmlBindings.xml. i.e. on Mac OS X most files use \r but Vim writes \n
instead. You can either save the file with Vim as a Mac formatted file or
use tr '\n' '\r' < input.xml > output.xml to convert the file.
Place the following XML into the userHTMLBindings.xml file.
<?xml version="1.0"?>
<bindings id="htmlBindings"
xmlns="http://www.mozilla.org/xbl";
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">;
<binding id="browserUser">
<handlers>
<handler event="keypress"
<handler event="keypress"
<handler event="keypress"
<handler event="keypress"
</handlers>
</binding>
</bindings>

key="h"
key="j"
key="k"
key="l"

command="cmd_scrollLeft"/>
command="cmd_scrollLineDown"/>
command="cmd_scrollLineUp"/>
command="cmd_scrollRight"/>

There are many more bindings one could configure to get Vim like
keybindings. You can read
http://www.mozilla.org/unix/customizing.html#keys for more information.
PS. I love the keymaster/gatekeeper xul reference in the xul URL
above. It's from the original GhostBusters movie. ;-)

http://www.vim.org/tips/tip.php?tip_id=317 (1 of 3) [18/02/2004 14:53:40]

Tip #317 - Mozilla Vim Keybindings : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using /pattern/ search in a script | Extended Bracket and Parenthesis + extras for perl >>

Additional Notes
Anonymous, September 7, 2002 19:53
I found this didn't work in userHTMLBindings.xml, but adding relevant
lines in htmlBindings.xml works great - thank you, this is one of those
things I've always wanted!
Mohit Kalra, September 8, 2002 1:35
This comment is not exactly related to vim.
http://labs.google.com/keys/index.html
Google for the keyboard aficionados.
-mohit

Anyways, checkout

Anonymous, September 17, 2002 22:45


I admit it's a bit tricky to get this working. Double-check your file
format (CRLF, LF, CR) for the platform you are on.
Also check that you put the file in the right path for your OS. I've
gotten this to work on Linux, Mac OS X, and Windows equally well. In
some cases (*nix based environments) I think the files may need to be
executable as well. (in other words, where the other binding files were
executable, I made the user binding executable as well).
Good Luck
Anonymous, September 17, 2002 22:48
Didn't know about the Google Keys, that's pretty slick.
flipouk@yahoo.com, September 29, 2002 9:17
Maybe the _greatest_ tip I found here! Thank you!
It is a real live saver for me as I have been used to using lynx for
years and I always used the vi motion in lynx.
I don't use Mozilla but Netscape 7. However, it worked all well for me
(under Linux mdk 8.2)
Absolutely fabulous would be to be able to mimic all lynx keystrokes:
e.g.
"/" to search for a word (crtl-F in Netscape 7)
"g" to open a new URL
"v" to open the bookmarks page (alt-B in Netscape 7)
"a" to add a bookmark (crtl-D in Netscape 7)
etc.
I couldn't figure out how to do it yet.
Any idea?
Anonymous, October 15, 2002 9:45

http://www.vim.org/tips/tip.php?tip_id=317 (2 of 3) [18/02/2004 14:53:40]

Tip #317 - Mozilla Vim Keybindings : vim online

Probably not, at least not without hacking the Mozilla source. Most of
what you listed would include a corded keypress. i.e. ALT+Key,
CTRL+Key. All the Mozilla docs state for legal commands would be mostly
navigation keystrokes like pageup/down, etc. Also some editing and
clipboard stuff. See the link in the Tip for the Mozilla.org
documentation. Of course the modifier keys (CTRL+ALT, etc.) are
customizable as it is done for each platform. i.e. Mac's have a CMD key
(Apple Key) that is used instead of CTRL. A Mac has CTRL, Option(ALT),
and Command(apple logo). Sun has a CTRL, ALT, and a Meta key. It may
still be somewhat possible, you would have to replace the modifier key
cording with a single key press. However, this may produce undesirable
effects that could impact normal Mozilla operation, etc.
Netscape 7 is really Mozilla under the hood. Netscape took Mozilla as
the base and added some stuff that isn't open source. i.e. AIM client
and some other things. I find Netscape 7 to be bloated and full of
useless fluff, but that's my opinion.
Gecko is the rendering engine under the Mozilla hood. XUL is a way to
create a browser interface and can be heavily skinned. XUL is literally
rendered by Gecko. So your widgets are all drawn by the render
engine. Neat concept but it can get a bit bloated (it's gotten much
better with the 1.x releases). There are many projects that take Gecko
and wrap it up in a particular widget kit so it doesn't use XUL for the
interface. This eliminates the skinning but it makes for a lighter
smaller non-cross platform browser, which apparently many people want
badly. Gnome, KDE, Win32, Cocoa/Aqua, etc., etc., etc. They seem to
want a native widget kit that matches their platform better.
Ultimately, I would want a lightweight browser that is really fast and
good at one thing, rendering pages and loading plugins. I could care
less about email, chat, etc. I have other programs for that stuff.

hari_vim at yahoo dot com, March 4, 2003 17:30


Thanks for the tip, it worked on Netscape 7.0 on Windows. But it seemed
like it worked only after removing the couple of ";' in the initial two
lines which seemed like unexpected.
Hari
vim.20.bheckel@spamgourmet.com, January 28, 2004 5:58
Great tip! I got it working under Moz 1.6 and added these to make it
even more Vimlike:
<handler event="keypress" key="g" command="cmd_scrollTop"/>
<handler event="keypress" modifiers="shift" key="g"
command="cmd_scrollBottom"/>
<handler event="keypress" key="b" command="cmd_scrollPageUp"/>
Bob
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=317 (3 of 3) [18/02/2004 14:53:40]

SourceForge
Logo

Tip #318 - Extended Bracket and Parenthesis + extras for perl : vim online

not logged in (login)

Home
Search

Tip #318: Extended Bracket and Parenthesis + extras for perl


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/3, Viewed by 1365

created: August 22, 2002 8:11


author: Abitkin

complexity: intermediate
as of Vim: 5.7

This is an extension of vimtip #153


I found this tip useful, but the jump seemed out of place for me, I couldn't enter just
one ' or ", and so I created an improvement
Basically, I set it up so that when you're in perl and have a non keyword charcter,
(except for @, $ and % for perl) and you type a { you get:
{
| <- cursor
}
Where as, when I have a keyword I get:
word{}
With the cursor in the middle, for hashes in perl. I can jump out of any block, except
the "" or '' blocks, by typing their closing charcter. So } jumps me out past the next }
in the file.
Warning, this search may wrap around.
Finally, I made
<Alt-'> inserts
<Alt-/> inserts
<Alt-[> inserts
<Alt-]> inserts
<Alt--> inserts
<Alt-=> inserts
<Alt-,> inserts
<Alt-.> inserts

it so that, using the alt key,


a '
a "
a [
a ]
a {
a }
a <
a >

"########################################
" File - matchMe.vim
" Date - Wednesday, August 21, 2002
"########################################
" This code fixes my problem with
http://www.vim.org/tips/tip.php?tip_id=318 (1 of 10) [18/02/2004 14:53:43]

Tip #318 - Extended Bracket and Parenthesis + extras for perl : vim online

" does the one format for perl and still keeps hashes
function! InsertBrackets()
let fileType = &ft
if fileType == 'perl'
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k' && getline('.')[col - 1] !~ '\$' &&
getline('.')[col - 1] !~ '@' && getline('.')[col - 1] !~ '%' && getline('.')[col - 1] !~
'#'
return "{\<cr>\<bs>}\<esc>ko"
else
return "{}\<esc>i\<c-o>:echo \<cr>"
endif
else
return "{\<cr>\<bs>}\<esc>ko"
endif
endfunction
" This code jumps out of the brackets
function! JumpNext(normChar)
let ret = "\<space>\<esc>ma\<left>/\\".a:normChar."\<cr>mb`ai\<del>\<esc>`bi\<right>"
return ret
endfunction
" mappings
inoremap " ""<esc>i<c-o>:echo <cr>
inoremap ' ''<esc>i<c-o>:echo <cr>
inoremap < <><esc>i<c-o>:echo <cr>
inoremap ( ()<esc>i<c-o>:echo <cr>
inoremap [ []<esc>i<c-o>:echo <cr>
inoremap { <c-r>=InsertBrackets ()<cr>
inoremap > <c-r>=JumpNext(">")<cr>
inoremap ) <c-r>=JumpNext(")")<cr>
inoremap ] <c-r>=JumpNext("]")<cr>
inoremap } <c-r>=JumpNext("}")<cr>
inoremap <m-[> [
inoremap <m-]> ]
inoremap <m-/> "
inoremap <m--> {
inoremap <m-=> }
inoremap <m-,> <
inoremap <m-.> >
inoremap <m-'> '

http://www.vim.org/tips/tip.php?tip_id=318 (2 of 10) [18/02/2004 14:53:43]

Tip #318 - Extended Bracket and Parenthesis + extras for perl : vim online

"########################################
" End Of File
"########################################
If you have any other suggestions, drop a note...
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Mozilla Vim Keybindings | text formatting (lining up ='s,('s etc)) >>

Additional Notes
atkinssc@engr.orst.edu, August 22, 2002 9:15
Found a bug or two...
Here's the Fix:
"########################################
" File - matchMe.vim
" Date - Wednesday, August 21, 2002
"########################################
" This code fixes my problem with
" does the one format for perl and acts correctly with
" hashes
function! InsertBrackets()
let fileType = &ft
if fileType == 'perl'
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k' && getline('.')[col - 1] !~ '\$' &&
getline('.')[col - 1] !~ '@' && getline('.')[col - 1] !~ '%' && getline('.')[col - 1]
!~ '#'
return "{\<cr>\<bs>}\<esc>ko"
else
return "{}\<esc>i\<c-o>:echo \<cr>"
endif
else
return "{\<cr>\<bs>}\<esc>ko"
endif
endfunction
" This code jumps out of the brackets
http://www.vim.org/tips/tip.php?tip_id=318 (3 of 10) [18/02/2004 14:53:43]

Tip #318 - Extended Bracket and Parenthesis + extras for perl : vim online

function! JumpNext(startChar, endChar)


let ret1 = "\<esc>:echo
searchpair('".a:startChar."','','".a:endChar."','W','synIDattr(synID(line(\".\"),
col(\".\"), 0), \"name\") =~? \"string\"')\<cr>i\<right>"
return ret1
endfunction
" mappings
inoremap " ""<esc>i<c-o>:echo <cr>
inoremap ' ''<esc>i<c-o>:echo <cr>
inoremap < <><esc>i<c-o>:echo <cr>
inoremap ( ()<esc>i<c-o>:echo <cr>
inoremap [ []<esc>i<c-o>:echo <cr>
inoremap { <c-r>=InsertBrackets ()<cr>
inoremap > <c-r>=JumpNext("<",">")<cr>
inoremap ) <c-r>=JumpNext("(",")")<cr>
inoremap ] <c-r>=JumpNext("[","]")<cr>
inoremap } <c-r>=JumpNext("{","}")<cr>
inoremap <m--> [
inoremap <m-=> ]
inoremap <m-/> "
inoremap <m-[> {
inoremap <m-]> }
inoremap <m-,> <
inoremap <m-.> >
inoremap <m-9> (
inoremap <m-0> )
inoremap <m-'> '
Alex A. Naanou <alex_nanou@yahoo.com>, August 22, 2002 15:29
Cool!!!
I used a similar (but mostly far more basic...) set of functions and mappings for my C
and Python code, but with a slightly different behavior...
here is some code I find a bit more convenient (at least for my liking :) )
---cut--fun! s:Toggle_EditHelpers()
if !exists('b:edithelpers_on') || b:edithelpers_on == 0
let b:edithelpers_on=1
inoremap '' ''<esc>i
inoremap ''' '''
http://www.vim.org/tips/tip.php?tip_id=318 (4 of 10) [18/02/2004 14:53:43]

Tip #318 - Extended Bracket and Parenthesis + extras for perl : vim online

inoremap
inoremap
inoremap
inoremap
inoremap
inoremap

""" """
"" ""<esc>i
<> <><esc>i
[] []<esc>i
() ()<esc>i
{} {}<esc>i

cnoremap '' ''<Left>


cnoremap ''' '''
cnoremap """ """
cnoremap "" ""<Left>
cnoremap <> <><Left>
cnoremap [] []<Left>
cnoremap () ()<Left>
cnoremap {} {}<Left>
else
let b:edithelpers_on=0
iunmap ''
iunmap '''
iunmap """
iunmap ""
iunmap <>
iunmap []
iunmap ()
iunmap {}
cunmap ''
cunmap '''
cunmap """
cunmap ""
cunmap <>
cunmap []
cunmap ()
cunmap {}
endif
endfun
" I like most features to be easily switched on and off...
nnoremap <silent><F9> :call <SID>Toggle_EditHelpers()<CR>
vnoremap <silent><F9> <C-C>:call <SID>Toggle_EditHelpers()<CR>
inoremap <silent><F9> <C-O>:call <SID>Toggle_EditHelpers()<CR>
" turn on by default
:call <SID>Toggle_EditHelpers()
---uncut--http://www.vim.org/tips/tip.php?tip_id=318 (5 of 10) [18/02/2004 14:53:43]

Tip #318 - Extended Bracket and Parenthesis + extras for perl : vim online

thanks!!
atkinssc@engr.orst.edu, August 23, 2002 12:58
One more update...
I found this quite useful, as sometimes I delete the ending char, to insert it around a
block, and then when I type it again, I just get a flash...
" This code jumps out of the brackets
function! JumpNext(startChar, endChar,oneItem)
let ret1 = "\<esc>:if
\"0\"==searchpair('".a:startChar."','','".a:endChar."','W','synIDattr(synID(line(\".\"),
col(\".\"), 0), \"name\") =~? \"string\"')\<cr>exec(\"normal
i".a:oneItem."\")\<cr>endif\<cr>i\<right>"
return ret1
endfunction
" mappings
inoremap >
inoremap )
inoremap ]
inoremap }

<c-r>=JumpNext("<",">","\<m-.>")<cr>
<c-r>=JumpNext("(",")","\<m-0>")<cr>
<c-r>=JumpNext("[","]","\<m-=>")<cr>
<c-r>=JumpNext("{","}","\<m-]>")<cr>

Anonymous, August 27, 2002 9:39


Look out for other bracketing scripts!
Anonymous, August 28, 2002 18:34
not sure why, but this mapping tip does not work for me when i use it on gvim6.0 on unix
(seems to be ok for gvim6.1 on PC and gvim5.5 on Unix).
the <esc> char will be mapped directly as text instead of the usual <esc> function.
any idea why is that so??
thanks in advance!!
atkinssc@engr.orst.edu, August 29, 2002 8:43

http://www.vim.org/tips/tip.php?tip_id=318 (6 of 10) [18/02/2004 14:53:43]

Tip #318 - Extended Bracket and Parenthesis + extras for perl : vim online

My only guess is that your escape char is <m-[>


problem.

Changing that binding may fix your

Here's an update, with toggle, and the toggle should let your escape work again:
"########################################
" File - matchMe.vim
" Date - Wednesday, August 21, 2002
" E-Mail - atkinss@onid.orst.edu
"########################################
" This code fixes my problem with
" does the one format for perl, and acts
" correctly with hashes.
function! InsertBrackets()
let fileType = &ft
if fileType == 'perl'
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k' && getline('.')[col - 1] !~ '\$' &&
getline('.')[col - 1] !~ '@' && getline('.')[col - 1] !~ '%' && getline('.')[col - 1]
!~ '#'
return "{\<cr>\<bs>}\<esc>ko"
else
return "{}\<esc>i\<c-o>:echo \<cr>"
endif
else
return "{\<cr>\<bs>}\<esc>ko"
endif
endfunction
" This code jumps out of the brackets
function! JumpNext(startChar, endChar,oneItem)
let ret1 = "\<esc>:if
\"0\"==searchpair('".a:startChar."','','".a:endChar."','W','synIDattr(synID(line(\".\"),
col(\".\"), 0), \"name\") =~? \"string\"')\<cr>exec(\"normal
i".a:oneItem."\")\<cr>endif\<cr>i\<right>"
return ret1
endfunction
" Added toggle.
" Date: Thursday, August 29, 2002 @ 07:57 AM
" Thanks to: Alex A. Naanou <alex_nanou@yahoo.com>
fun! s:Toggle_Edit2()
if exists('b:edithelpers_on') && b:edithelpers_on == 1
http://www.vim.org/tips/tip.php?tip_id=318 (7 of 10) [18/02/2004 14:53:43]

Tip #318 - Extended Bracket and Parenthesis + extras for perl : vim online

if (!exists('b:edithelpers2_on') || b:edithelpers2_on == 0)
let b:edithelpers2_on=1
" mappings
inoremap > <c-r>=JumpNext("<",">","\<m-.>")<cr>
inoremap ) <c-r>=JumpNext("(",")","\<m-0>")<cr>
inoremap ] <c-r>=JumpNext("[","]","\<m-=>")<cr>
inoremap } <c-r>=JumpNext("{","}","\<m-]>")<cr>
inoremap <m-=> ]
inoremap <m-]> }
inoremap <m-.> >
inoremap <m-0> )
else
let b:edithelpers2_on=0
iunmap >
iunmap )
iunmap ]
iunmap }
iunmap <m-=>
iunmap <m-]>
iunmap <m-.>
iunmap <m-0>
endif
endif
endfun
" Added toggle.
" Date: Thursday, August 29, 2002 @ 07:57 AM
" Thanks to: Alex A. Naanou <alex_nanou@yahoo.com>
fun! s:Toggle_Edit()
if !exists('b:edithelpers_on') || b:edithelpers_on == 0
let b:edithelpers_on=1
" mappings
inoremap " ""<esc>i<c-o>:echo <cr>
inoremap ' ''<esc>i<c-o>:echo <cr>
inoremap < <><esc>i<c-o>:echo <cr>
inoremap ( ()<esc>i<c-o>:echo <cr>
inoremap [ []<esc>i<c-o>:echo <cr>
inoremap { <c-r>=InsertBrackets ()<cr>
inoremap <m--> [
inoremap <m-/> "
inoremap <m-[> {
inoremap <m-,> <
inoremap <m-9> (
inoremap <m-'> '
http://www.vim.org/tips/tip.php?tip_id=318 (8 of 10) [18/02/2004 14:53:43]

Tip #318 - Extended Bracket and Parenthesis + extras for perl : vim online

if !exists('b:edithelpers2_on') || b:edithelpers2_on == 0
call <SID>Toggle_Edit2()
endif
else
iunmap "
iunmap '
iunmap <
iunmap (
iunmap [
iunmap {
iunmap <m-->
iunmap <m-/>
iunmap <m-[>
iunmap <m-,>
iunmap <m-9>
iunmap <m-'>
if exists('b:edithelpers2_on') && b:edithelpers2_on == 1
call <SID>Toggle_Edit2()
endif
let b:edithelpers_on=0
endif
endfun
nnoremap <silent><F9> :call <SID>Toggle_Edit()<CR>
inoremap <silent><F9> <C-O>:call <SID>Toggle_Edit()<CR>
call <SID>Toggle_Edit()
nnoremap <silent><F8> :call <SID>Toggle_Edit2()<CR>
inoremap <silent><F8> <C-O>:call <SID>Toggle_Edit2()<CR>
" F-8 toggles the jump
" F-9 toggles the bracketing feature and overrides F-8
quesadaj@psych.colorado.edu, August 15, 2003 23:37
For me, trying to use F9 (Toggle) sends a whole list of error E31 "No such mapping"....
Other than that, it works as expected. Tried both unix and windows, same results
I would love to have the Toggle...
Thanks in advance!
quesadaj@psych.colorado.edu, August 16, 2003 0:22

http://www.vim.org/tips/tip.php?tip_id=318 (9 of 10) [18/02/2004 14:53:43]

Tip #318 - Extended Bracket and Parenthesis + extras for perl : vim online

I think I understand why it doesn't work.


When the fucntion is first called, you get, e.g.,
inoremap " ""<esc>i<c-o>:echo <cr>
but by the time you toggle it (calling the fucntion again)
iunmap "
it doesn't work because the " is substituted by " " by the interpreter, which is under
the influence of the first inoremap, hence the error "No such mapping". I don't know why
the interpreter behaves like this, It might be something I have in my .vimrc.
Any solutions?
THanks a lot!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=318 (10 of 10) [18/02/2004 14:53:43]

SourceForge
Logo

Tip #319 - text formatting (lining up ='s,('s etc)) : vim online

not logged in (login)

Tip #319: text formatting (lining up ='s,('s etc))

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -3/17, Viewed by 2028

created: August 23, 2002 7:01


author: Jahagirdar Vijayvithal S

complexity: basic
as of Vim: 5.7

some time onw would like to reformat text like


a=1;
foo=2;
longstring=1;
c=2
to
a
foo
longstring
c

=1;
=2;
=1;
=2;

Note I am not sure wether the code above is displayed


properly in your browsers what is basically shows is all
the ='s are lined up in a single column
and this is how we achive it
0f=20i<space><esc>020lvf=hx
and this is what it does
0
goes to first column
f=
finds next occurance of =
on current line
20i<space><esc>
inserts 20 spaces before =
0
goesback to first column
20l
forward 20 column
vf=hx
deletes everything up to
the = sign

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Extended Bracket and Parenthesis + extras for perl | Borland pageup/down behavier >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=319 (1 of 7) [18/02/2004 14:53:46]

Tip #319 - text formatting (lining up ='s,('s etc)) : vim online

Anonymous, August 23, 2002 7:31


Any lining up, alignment, etc..just leave it to Dr. Chip
Campbell's Align.vim (search for it here)
Anonymous, August 23, 2002 12:41
This is a more lightweight solution, though. There's
something to be said for that...
Alex A. Naanou <alex_nanou@yahoo.com>, August 23, 2002 16:35
Nice, but I see a BIG drawback!!
what will it do in the following case?? :)
Ex:
---cut--int my_very_informative_variable_name = 0;
---uncut--the result will be:
int my_very_informat= 0;
yes the simplest way out of this is to extend the thing
to say... 40 spaces....
but this will make all the short variable defs look
ugly!
Ex:
int i
char * my_foo_bar

= 0;
= "moo";

the correct way to solve this problem is to find the


longest var in the
list (selected lines) and align accordingly....
Anonymous, August 23, 2002 22:14
some mappings and a python script for alignment.
http://www.ophinity.com/code/wrangling/index.html#lineUp
pro:
humans can understand python
con:
you need to have a python interpreter on your box
it's not as sophisticated as dr. chips script
jahagirdar_vs@yahoo.Ihatespam.com, August 24, 2002 3:51

http://www.vim.org/tips/tip.php?tip_id=319 (2 of 7) [18/02/2004 14:53:46]

Tip #319 - text formatting (lining up ='s,('s etc)) : vim online

I know about the drawback alex mentioned( having a


variable name more than 20 characters long) this was
just a sample example the number of space inserted and
the column at which alignment has to be done can be
changed as per requirement.
Anonymous, August 25, 2002 17:53
You can save a couple keystrokes without visual mode.
0f=20i<space><esc>020ldt=
And a couple more by using the goto-column movement (
:help bar )
0f=20i<space><esc>d20|
And finally, you can fire off something like
:11,32norm 0f=20i<space><ctrl-v><esc>d20|
to do this for a bunch of lines.
agentwho@hotmail.com, August 26, 2002 8:00
0f=gelcw<TAB><ESC>
works well of you have softtabs set to use spaces. (Or
using :retab)
This will align based on next tab collumns. Neat enough
for me.
Marius.
jmcpherson@bigfoot.com, August 28, 2002 15:07
Metatip: Edit your tips with Vim itself (or Notepad, or
another editor that edits raw text in a monospaced
font). Then paste them into the textbox when you are
posting your tip.
That way, the odds of things lining up are much better,
since the tips display in a monospaced font.
argosoco@yahoo.com, August 29, 2002 6:42

http://www.vim.org/tips/tip.php?tip_id=319 (3 of 7) [18/02/2004 14:53:46]

Tip #319 - text formatting (lining up ='s,('s etc)) : vim online

Tip #319: text formatting (lining up ='s,('s etc))


tip karma
Rating -3/3, Viewed by 491
created:
August 23, 2002 7:01
complexity:
basic
author:
Jahagirdar Vijayvithal S
as of Vim:
5.7
some time onw would like to reformat text like
a=1;
foo=2;
longstring=1;
c=2
to
a
foo
longstring
c

=1;
=2;
=1;
=2;

Note I am not sure wether the code above is displayed


properly in your browsers what is basically shows is
all the ='s are lined up in a single column
and this is how we achive it
0f=20i<space><esc>020lvf=hx
and this is what it does
0
goes to first column
f=
finds next occurance of =
on current line
20i<space><esc>
inserts 20 spaces before =
0
goesback to first column
20l
forward 20 column
vf=hx
deletes everything up to
the = sign
rate this tip
Life Changing Helpful Unfulfilling

http://www.vim.org/tips/tip.php?tip_id=319 (4 of 7) [18/02/2004 14:53:46]

Tip #319 - text formatting (lining up ='s,('s etc)) : vim online

<<Extended Bracket and Parenthesis + extras for perl |


Borland pageup/down behavier >>
Additional Notes
Anonymous, August 23, 2002 7:31
Any lining up, alignment, etc..just leave it to Dr. Chip
Campbell's Align.vim

(search for it here)


Anonymous, August 23, 2002 12:41
This is a more lightweight solution, though. There's
something to be said for that...
Alex A. Naanou <alex_nanou@yahoo.com>, August 23, 2002
16:35
Nice, but I see a BIG drawback!!
what will it do in the following case?? :)
Ex:
---cut--int my_very_informative_variable_name = 0;
---uncut--the result will be:
int my_very_informat= 0;
yes the simplest way out of this is to extend the thing
to say... 40 spaces....
but this will make all the short variable defs look
ugly!
Ex:
int i
char * my_foo_bar

= 0;
= "moo";

the correct way to solve this problem is to find the


longest var in the
list (selected lines) and align accordingly....
Anonymous, August 23, 2002 22:14
some mappings and a python script for alignment.

http://www.vim.org/tips/tip.php?tip_id=319 (5 of 7) [18/02/2004 14:53:46]

Tip #319 - text formatting (lining up ='s,('s etc)) : vim online

http://www.ophinity.com/code/wrangling/index.html#lineUp
pro:
humans can understand python
con:
you need to have a python interpreter on your box
it's not as sophisticated as dr. chips script
jahagirdar_vs@yahoo.Ihatespam.com, August 24, 2002 3:51
I know about the drawback alex mentioned( having a
variable name more than 20
characters long) this was just a sample example the
number of space inserted and the column at which
alignment has to be done can be changed as per
requirement.
Anonymous, August 25, 2002 17:53
You can save a couple keystrokes without visual mode.
0f=20i<space><esc>020ldt=
And a couple more by using the goto-column movement (
:help bar )
0f=20i<space><esc>d20|
And finally, you can fire off something like
:11,32norm 0f=20i<space><ctrl-v><esc>d20|
to do this for a bunch of lines.
agentwho@hotmail.com, August 26, 2002 8:00
0f=gelcw<TAB><ESC>
works well of you have softtabs set to use spaces. (Or
using :retab)
This will align based on next tab collumns. Neat enough
for me.
Marius.
jmcpherson@bigfoot.com, August 28, 2002 15:07
Metatip: Edit your tips with Vim itself (or Notepad, or
another editor that edits raw text in a monospaced

http://www.vim.org/tips/tip.php?tip_id=319 (6 of 7) [18/02/2004 14:53:46]

Tip #319 - text formatting (lining up ='s,('s etc)) : vim online

font). Then paste them into the textbox when you are
posting your tip.
That way, the odds of things lining up are much better,
since the tips display in a monospaced font.
Anonymous, August 30, 2002 13:06
agentwho@hotmail.com:
0f=gelcw<TAB><ESC>
will fail if there's no space between the previous word
and the equals sign.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=319 (7 of 7) [18/02/2004 14:53:46]

SourceForge
Logo

Tip #320 - Borland pageup/down behavier : vim online

not logged in (login)

Home
Search

Tip #320: Borland pageup/down behavier


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/5, Viewed by 1123

created: August 26, 2002 14:49


author: Simon "neoneye" Strandgaard

complexity: basic
as of Vim: 6.0

borlandbehavier = the cursor keeps the same xy position


during pageup/down
Im new to VIM scripting, im sure it can be done smarter?
I read vimtip #105 and it gave me a clue of how
BorlandPageUp/Down could be done.
" i could'nt find any get_number_of_visible_lines
function, so i made my own.
function GetNumberOfVisibleLines()
let cur_line = line(".")
let cur_col = virtcol(".")
normal H
let top_line = line(".")
normal L
let bot_line = line(".")
execute "normal " . cur_line . "G"
execute "normal " . cur_col . "|"
return bot_line - top_line
endfunc
" noremap <PageUp> 39<C-U>:set scroll=0<CR>
function! MyPageUp()
let visible_lines = GetNumberOfVisibleLines()
execute "normal " . visible_lines . "\<C-U>:set
scroll=0\r"
endfunction
" noremap <PageDown> 39<C-D>:set scroll=0<CR>
function! MyPageDown()
let visible_lines = GetNumberOfVisibleLines()
execute "normal " . visible_lines . "\<C-D>:set
scroll=0\r"
endfunction
" BorlandPascal pageup/down behavier!

http://www.vim.org/tips/tip.php?tip_id=320 (1 of 2) [18/02/2004 14:53:48]

Tip #320 - Borland pageup/down behavier : vim online

" todo: when hitting top/bottom of file, then restore Y


to lastY
noremap <PageUp> :call MyPageUp()<CR>
noremap <PageDown> :call MyPageDown()<CR>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<text formatting (lining up ='s,('s etc)) | Centura swap with upper/lower line behavier >>

Additional Notes
Anonymous, August 27, 2002 2:34
For maintaining the same x coordinate, help startofline
Anonymous, August 27, 2002 4:21
And CTRL-U (up), CTRL-D (down) may also be useful for
what you want (half page scrolls)
vdvo@seznam.cz, February 2, 2003 12:43
A solution that I use (easier, I would say, but has a
small side-effect) is this:
map <PageDown> :set scroll=0<CR>:set scroll^=2<CR>:set
scroll-=1<CR><C-D>:set scroll=0<CR>
map <PageUp> :set scroll=0<CR>:set scroll^=2<CR>:set
scroll-=1<CR><C-U>:set scroll=0<CR>
I found Vim's normal PgUp/PgDn behaviour weird - I
think it's different from every other editor I've used
and I was unable to get used to it. The above two lines
are godsent! :-)
Andrew Pimlott <andrew@pimlott.net>, February 3, 2003 14:32
I just entered a refinement of vimtip #105 as vimtim
#417. You might find it useful to incorporate the
improvements into this tip.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=320 (2 of 2) [18/02/2004 14:53:48]

SourceForge
Logo

Tip #321 - Centura swap with upper/lower line behavier : vim online

not logged in (login)

Home
Search

Tip #321: Centura swap with upper/lower line behavier


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/5, Viewed by 705

created: August 27, 2002 14:52


author: Simon "neoneye" Strandgaard

complexity: basic
as of Vim: 6.0

I was once forced to use a windows development suite


called "Centura".
The only good thing i remember was its swap current_line
with upper/lower line.
function! MySwapUp()
let cur_col = virtcol(".")
normal ddkkp
execute "normal " . cur_col . "|"
endfunction
function! MySwapDown()
let cur_col = virtcol(".")
normal ddp
execute "normal " . cur_col . "|"
endfunction
" swap lines and preserve cursorx
" todo: in visual mode, perform swap with line
before/after the selection
noremap <S-Up> :call MySwapUp()<CR>
noremap <S-Down> :call MySwapDown()<CR>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Borland pageup/down behavier | text template with placeholders >>

Additional Notes
salmanhalim@hotmail.com, August 27, 2002 19:53
Instead of "ddkkp", how about simply "ddkP"? One less
keystroke! :) (Saving keystrokes is one of the
biggest reasons why people use vi-like editors in the
first place.)

http://www.vim.org/tips/tip.php?tip_id=321 (1 of 3) [18/02/2004 14:53:50]

Tip #321 - Centura swap with upper/lower line behavier : vim online

salmanhalim@hotmail.com, August 27, 2002 20:02


Forgot to mention this, but it might be better to make
the mappings <silent> so the effects can't be seen on
the command-line. Also, swapping up when the cursor is
on the first line doesn't appear to be quite what is
desired (or the first TWO lines if the ddkkp format is
used instead of ddkP), so a check to make sure that
line( '.' ) > 1 for the up and < line( '$' ) for the
down might not be a bad idea.
I DO like this idea and, with the above modifications,
am adding it to my list of mappings so please don't
take the suggestions the wrong way.
salmanhalim@hotmail.com, August 27, 2002 20:09
*Sigh* Try swapping up when on the last line. . . Need
to add yet another check in there; my final version:
function! MySwapUp()
if ( line( '.' ) > 1 )
let cur_col = virtcol(".")
if ( line( '.' ) == line( '$' ) )
normal ddP
else
normal ddkP
endif
execute "normal " . cur_col . "|"
endif
endfunction
function! MySwapDown()
if ( line( '.' ) < line( '$' ) )
let cur_col = virtcol(".")
normal ddp
execute "normal " . cur_col . "|"
endif
endfunction
noremap <silent> <S-Up> :call MySwapUp()<CR>
noremap <silent> <S-Down> :call MySwapDown()<CR>
littledragon@altern.org, September 2, 2002 2:48
Use normal! instead of normal... Who knows what people
might have mapped on d, k or P :)
Add Note

http://www.vim.org/tips/tip.php?tip_id=321 (2 of 3) [18/02/2004 14:53:50]

Tip #321 - Centura swap with upper/lower line behavier : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=321 (3 of 3) [18/02/2004 14:53:50]

SourceForge
Logo

Tip #322 - text template with placeholders : vim online

not logged in (login)

Home
Search

Tip #322: text template with placeholders


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 21/12, Viewed by 1588

created: August 29, 2002 4:34


author: lars_e_krueger

complexity: basic
as of Vim: 6.0

Many scripts/ftplugin provide text or code templates.


Sadly none of the marks the places where you are
supposed to "fill in the form".
My own code templates for C/C++ insert a triple percent
(%%%) where you are supposed to enter something. I
mapped ;; to find the next %%% and change them.
All the template mappings are insert-mode only, while
the "skip to next placeholder" is both insert and normal
mode enabled.
A complete for-loop template for C++ looks like:
:imap <buffer> ;fo <C-O>mzfor( %%%; %%%; %%%)<CR>{ //
%%%<CR>%%%<CR>}<CR><C-O>'z;;
The command to go to the next placeholder is this:
:imap <buffer> ;; <C-O>/%%%<CR><C-O>c3l
:nmap <buffer> ;; /%%%<CR>c3l
Every time I need a for-loop ;fo produces this ( _ is
the cursor position) :
for( _; %%% ; %%%)
{ // %%%
%%%
}
Now I enter starting value (i=0):
for( i=0_; %%% ; %%%)
{ // %%%
%%%
}
and go to the condition using ;;
for( i=0; _ ; %%%)
{ // %%%
%%%

http://www.vim.org/tips/tip.php?tip_id=322 (1 of 3) [18/02/2004 14:53:53]

Tip #322 - text template with placeholders : vim online

}
and so forth.
The choice of %%% proved to be almost universal, it even
works in MATLAB or LaTeX where % is the comment
character.
Even if you forget to replace one %%%, that's not a
problem as the compiler flags is as a syntax error
(except MATLAB and LaTeX, of course).
It made my life easier, maybe it works for you.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Centura swap with upper/lower line behavier | using folders with latex >>

Additional Notes
hermitte at free.fr, August 29, 2002 8:31
Mu-Template proposes a support for placeholders when
inserting template files :
http://vim.sourceforge.net/script.php?script_id=222
Actually, it is based on Stephen Riehm's bracketing
system.
Moreover, regarding C or C++, I propose several files
that define abbreviations that support placeholders :
http://vim.sourceforge.net/script.php?script_id=336
It is based on a collection of scripts of mine :
http://vim.sourceforge.net/script.php?script_id=50
and also it is strongly inspired by Stephen Riehm's
bracketing system.
On my web site, I provide similar script for LaTeX or
HTML coding.
Unfortunately, the definition of the templates is quite
complex as it is possible to change (through a pair of
variables) the markers used (to signal the
placeholders) -- the "jumping" (to the next marker)
functions are also customisable thanks to variables.
Otherwise,I also remember several alternatives (that
focused of the definition of the template) to the same
problem. They are here on SF.

http://www.vim.org/tips/tip.php?tip_id=322 (2 of 3) [18/02/2004 14:53:53]

Tip #322 - text template with placeholders : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=322 (3 of 3) [18/02/2004 14:53:53]

SourceForge
Logo

Tip #323 - using folders with latex : vim online

not logged in (login)

Home
Search

Tip #323: using folders with latex


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 15/11, Viewed by 945

created: September 6, 2002 4:40


author: Raoul Jean Pierre Bonnal

complexity: basic
as of Vim: 5.7

set foldmarker=\\begin,\\end
set foldmethod=marker
this is useful with big latex document
rate this tip

Life Changing

Helpful

Unfulfilling

rate

Site Help
<<text template with placeholders | Search and replace in files named NAME >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=323 [18/02/2004 14:53:55]

SourceForge
Logo

Tip #324 - Search and replace in files named NAME : vim online

not logged in (login)

Home
Search

Tip #324: Search and replace in files named NAME


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 30/12, Viewed by 2188

created: September 7, 2002 14:34


author: Luis Mondesi

complexity: intermediate
as of Vim: 5.7

I'm not sure if there is a simple way to do this from


within Vim, but, I wrote this simple script that does
it. It basically searches for files named NAMED
(whatever name pass) for a given string and replaces
that with a given string:
find_replace.sh NAMED "string_to_find"
"string_to_replace"
This is all done from the command line without opening
Vim.
Of course one could do things like:
:let n = 1
:while n <= argc()
" loop over
all files in arglist
: exe "argument " . n
: " start at the last char in the
file and wrap for the
: " first search to find match at
start of file
: normal G$
: let flags = "w"
: while search("foo", flags) > 0
:
s/foo/bar/g
:
let flags = "W"
: endwhile
: update
" write the
file if modified
: let n = n + 1
:endwhile
As suggested in the Vim help files :-) but, I wanted to
go and find only these files... here is the script:
1 #!/bin/sh
2 # Luis Mondesi < lemsx1@hotmail.com >
3 # DESCRIPTION:
4 #
it uses vim to replace a given string for
5 #
another in a number of files

http://www.vim.org/tips/tip.php?tip_id=324 (1 of 3) [18/02/2004 14:53:57]

Tip #324 - Search and replace in files named NAME : vim online

6 #
7 # usage:
8 #
find_replace.sh file "string" "replace"
9 #
10 if [ $1 -a $2 -a $3 ]; then
11
for i in `find . -name "$1" -type f | xargs
grep -l $2`; do
12
# how do search and replace
13
# the screen might flicker... vim
opening and closing...
14
vim -c ":%s/$2/$3/g" -c ":wq" $i
15
done
16
exit 0
17 fi
18 # I should never reach here
19 echo -e "USAGE: find_replace.sh file 'string'
'replace' \n\n"
20 exit 1

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<using folders with latex | Errorformat for java/ant/junit/cygwin/bash >>

Additional Notes
salmanhalim@hotmail.com, September 8, 2002 8:19
If you have a shell script environment available to
you, you must also have sed. Why not just pipe the
output of the find to xargs sed -e "%s/<from>/<to>/g"?
(Nothing against Vim; just trying to use the right tool
for the job.)
Anonymous, September 15, 2002 11:48
Not an option on a default install of Windows ;o)
Anonymous, October 11, 2002 7:40
What would make this feature more interesting is to be
able to run from inside VIM, ie I'm editing several
files from a tree inside VIM, I want the text replaced
both inside the file I'm currently editing (and the VIM
buffers updated) and all the others from that tree.
Add Note

http://www.vim.org/tips/tip.php?tip_id=324 (2 of 3) [18/02/2004 14:53:57]

Tip #324 - Search and replace in files named NAME : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=324 (3 of 3) [18/02/2004 14:53:57]

SourceForge
Logo

Tip #325 - Errorformat for java/ant/junit/cygwin/bash : vim online

not logged in (login)

Home
Search

Tip #325: Errorformat for java/ant/junit/cygwin/bash


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/4, Viewed by 2100

created: September 9, 2002 10:15


author: John Sumsion

complexity: advanced
as of Vim: 6.0

If you program in Java and use Jakarta ant for builds


*and* if you have the
bash shell, this tip will make your development
experience a little
smoother.
This tip will result in a working compile/edit/debug
system (in Win32
vim/gvim and in Cygwin vim) that takes you to the exact
lines where the
build fails, whether the failure is a compilation error
or a junit test
failure. If you use bash on a linux box, you shouldn't
have to change very
much to get everything to work.
There are
1. set up
2. set up
3. set up
4. set up
5. set up
6. set up

6 sections:
your build script
makeprg
shell options
path formatting options
your errorformat
key mappings

Set up build script


------------------Add the following script to your path (I use
/usr/local/bin/):
mymake:
#!/bin/bash
cd /work/
ant -emacs $* 2>&1 | tr '\' / | tr ^M ' ' | sed -u -n -f
/usr/local/bin/testerrors.sed | tee /tmp/errors
Comment: sed -u is non-standard, use the code at:
http://mail.gnu.org/pipermail/bug-gnu-utils/2002-

http://www.vim.org/tips/tip.php?tip_id=325 (1 of 6) [18/02/2004 14:54:00]

Tip #325 - Errorformat for java/ant/junit/cygwin/bash : vim online

May/000192.html to get
the -u option for sed (this avoids waiting for the build
output to get to
the screen)
testerrors.sed:
# This assumes that all your junit test cases are in a
com.* package
/^Running com\./ {
# duplicate the line
s!\(.*\)!\1\
\1!
P
# turn the test package into a directory path for %D
errorformat
s!.*\(com\..*\)\.[A-Za-z_][A-Za-z0-9_]*!\1!
s!\.!/!g
s!.*!Entering: /work/src/&!
# print the line and go on
p
n
}
# just pass any unmatched lines through
p
Set up makeprg
-------------Add the following lines to your vimrc:
autocmd BufNewFile,BufRead /work/*.java set
makeprg=mymake
autocmd BufNewFile,BufRead ?:/work/*.java set
makeprg=mymake
Set up shell options
-------------------Add the following lines to your vimrc:
" in order to have bash as the shell for win32 vi.exe
and gvim.exe, you have
" to set these options, and also build vimrun.exe in
the cygwin environment
" so that the system() call is executed via bash, not
cmd.exe -- the command
" to build vimrun.exe is "make -f Make_cyg.mak
vimrun.exe"
set shell=bash.exe
set shellcmdflag=-c
set shellslash

http://www.vim.org/tips/tip.php?tip_id=325 (2 of 6) [18/02/2004 14:54:00]

Tip #325 - Errorformat for java/ant/junit/cygwin/bash : vim online

Also to use this environment in Win32 gvim, you must


recompile vimrun so
that gvim invokes the shell via bash, not via cmd.exe.
Set up path formatting options
-----------------------------Add the following lines to your vimrc:
" allows DOS file names from UNIX (Cygwin) vim
set isfname+=\
Set up your errorformat
----------------------Add the following lines to your vimrc:
" the "\%DEntering:\ %f," rule relies on a sed script
which generates
" "Entering: " messages for each test class run (the
directory name is
" generated from the test class package and a hardcoded src root)
" the "%\\C" at the start of the exception matching
line tells to match
" case-exact (the exception mathching lines rely on
the %D rule that sets
" up the correct directory from the package structure)
" ant/junit/javac errorformat
set errorformat=
\%-G%.%#build.xml:%.%#,
\%-G%.%#warning:\ %.%#,
\%-G%\\C%.%#EXPECTED%.%#,
\%f:%l:\ %#%m,
\C:%f:%l:\ %m,
\%DEntering:\ %f\ %\\=,
\%ECaused\ by:%[%^:]%#:%\\=\ %\\=%m,
\%ERoot\ cause:%[%^:]%#:%\\=\ %\\=%m,
\%Ecom.%[%^:]%#:%\\=\ %\\=%m,
\%Eorg.%[%^:]%#:%\\=\ %\\=%m,
\%Ejava.%[%^:]%#:%\\=\ %\\=%m,
\%Ejunit.%[%^:]%#:%\\=\ %\\=%m,
\%-Z%\\C\ at\ com.mypkg.%.%#.test%[AZ]%.%#(%f:%l)\ %\\=,
\%-Z%\\C\ at\ com.mypkg.%.%#.setUp(%f:%l)\ %\\=,
\%-Z%\\C\ at\ com.mypkg.%.%#.tearDown(%f:%l)\
%\\=,
\%-Z%^\ %#%$,
\%-C%.%#,
\%-G%.%#

http://www.vim.org/tips/tip.php?tip_id=325 (3 of 6) [18/02/2004 14:54:00]

Tip #325 - Errorformat for java/ant/junit/cygwin/bash : vim online

NOTE: Make sure that the character before "at" is an


actual Tab character in
the three long -Z lines above
Here is an annotated version:
set errorformat=
" don't treat the build.xml diagnostic as an error
\%-G%.%#build.xml:%.%#,
" don't treat warning lines as errors
\%-G%.%#warning:\ %.%#,
" don't treat lines containing "EXPECTED" as
errors
\%-G%\\C%.%#EXPECTED%.%#,
" look for this standard error format
\%f:%l:\ %#%m,
" look for this standard error format (with C: on
front)
\C:%f:%l:\ %m,
" look for special sed-generated "Entering" lines
while running tests
\%DEntering:\ %f\ %\\=,
" look for exceptions that were thrown in the
tests, use the exception
" description as the error message (don't know how
to also include the
" exception name in the error message)
\%ECaused\ by:%[%^:]%#:%\\=\ %\\=%m,
\%ERoot\ cause:%[%^:]%#:%\\=\ %\\=%m,
\%Ecom.%[%^:]%#:%\\=\ %\\=%m,
\%Eorg.%[%^:]%#:%\\=\ %\\=%m,
\%Ejava.%[%^:]%#:%\\=\ %\\=%m,
\%Ejunit.%[%^:]%#:%\\=\ %\\=%m,
" using the "Entering" directory and the
filename/line number provided
" in the exception trace, go to the test method
where the exception
" was thrown
\%-Z%\\C\ at\ com.mypkg.%.%#.test%[AZ]%.%#(%f:%l)\ %\\=,
\%-Z%\\C\ at\ com.mypkg.%.%#.setUp(%f:%l)\ %\\=,
\%-Z%\\C\ at\ com.mypkg.%.%#.tearDown(%f:%l)\
%\\=,
" empty lines terminate searching for further
http://www.vim.org/tips/tip.php?tip_id=325 (4 of 6) [18/02/2004 14:54:00]

Tip #325 - Errorformat for java/ant/junit/cygwin/bash : vim online

exception lines
\%-Z%^\ %#%$,
" any line can intervene between the start of an
exception printout
" and the line where it ends (last in list so that
it is matched if
" none of the other exception trace patterns
match)
\%-C%.%#,
" all other lines are not errors
\%-G%.%#
Set up key mappings
------------------Add the following lines to your vimrc:
nmap <F10> :clist<CR>
nmap <F11> :cprev<CR>
nmap <F12> :cnext<CR>
This allows for quick error navigation.
NOTES
----Vim treats the "Entering: /work/src/..." messages in a
weird way. If there
are any actual errors, then these error lines are
ignored by the :cnext and
:cprev commands, but if there are no real errors, then
:cnext and :cprev
roll through these "Entering:" messages as if they were
errors, but since
they don't include any line numbers, the cursor position
is never moved.
I thought that this was strange, but even stranger, it
is programmed
directly into the vim error handling code to function
exactly this way.
There were no comments, and nobody responded on the vim
mailing list, so I
just decided to live with it.
The upshot of it all is that if you see an error like
"Entering:", chances
are that your build succeeded and all the tests ran
without a problem.

http://www.vim.org/tips/tip.php?tip_id=325 (5 of 6) [18/02/2004 14:54:00]

Tip #325 - Errorformat for java/ant/junit/cygwin/bash : vim online

Hope this helps...


Mail me with bugs at jdsumsion at earthlink.net.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Search and replace in files named NAME | Help for VIM Help (VIM QuickRef) >>

Additional Notes
John Sumsion, October 14, 2003 7:27
Um, the URL to the sed -u patch changed. I can't
figure out how to edit this tip, but here is the new
URL: http://mail.gnu.org/archive/html/bug-gnuutils/2002-05/msg00051.html
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=325 (6 of 6) [18/02/2004 14:54:00]

SourceForge
Logo

Tip #326 - Help for VIM Help (VIM QuickRef) : vim online

not logged in (login)

Home
Search

Tip #326: Help for VIM Help (VIM QuickRef)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 18/12, Viewed by 1444

created: September 13, 2002 2:27


author: zzapper

complexity: basic
as of Vim: 6.0

Type
:help quickref
or
:h quic
And get a VIM Command Quick Reference Page brilliant for
beginners & oldtimers alike
type
:h help to learn how to use help
Other Help Tips
# help for help
:h visual<C-D><tab>
help topics

: obtain
:
:
:
:
:
:

:h ctrl<C-D>
:h :r
:h CTRL-R
:h \r
:h i_CTRL-R
mode
:h c_CTRL-R
mode
:h v_CTRL-V
:h tutor

list of all visual

Then use tab


list help of
help for :ex
normal mode
what's \r in
help for say

to step thru them


all control keys
command
a regexp
<C-R> in insert

: help for say <C-R> in command


: visual mode
: VIM Tutor

These are also listed in my Best Of VIM Tips vimtip #305

rate this tip

Life Changing

Helpful

<<Errorformat for java/ant/junit/cygwin/bash | key mappings >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=326 (1 of 2) [18/02/2004 14:54:03]

Unfulfilling

rate

Tip #326 - Help for VIM Help (VIM QuickRef) : vim online

david@tvis.co.uk, September 14, 2002 4:00


One of the reasons why :h quic is so useful is that it
is a great place to start when you don't even know the
name of what you are looking for.
It has various sections MOTION,CHANGING TEXT,INSERTING
TEXT,GUI,MAPPING,ABBREVIATIONS,BUFFERS etc.
Also don't forget Command Help
gvim -h
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=326 (2 of 2) [18/02/2004 14:54:03]

SourceForge
Logo

Tip #327 - key mappings : vim online

not logged in (login)

Home
Search

Tip #327: key mappings


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/12, Viewed by 2516

created: September 13, 2002 17:57


author: Nithin

complexity: basic
as of Vim: 6.0

I use my left thumb for the alt key and right for the space.
Using this combo, you can get
some useful key maps for which you don't have to move your hands.
I find I have to turn
my hand a little to press the left ctrl key.
These are some maps i use for C programming.
map ' `
map <C-f> :w<C-m>:!make<C-m>
map <M-]> <C-]>
map <M-[> <C-t>
map <M-u> :!ctags -R *<Cm>
map <M-c>
I/*<Esc>A*/<Esc>
current line
map <M-d> ^xx$xx
comment for a single line
map <M-l> [{zf%
upto the enclosing brace level
map <M-o> zo
map <M-i> zc
map <M-.> :cn<C-m>
next error in list
map <M-,> :cp<Cm>
list
imap <Tab> <Cp>
inoremap <S-Tab>
<Tab>
inoremap {
<CR>{<CR>
and line
inoremap }
<CR>}
line. saves one enter stroke

imap <M-j>

http://www.vim.org/tips/tip.php?tip_id=327 (1 of 4) [18/02/2004 14:54:06]

Tags
Tags
Build Tags
Comment
Delete
Fold
open fold
close fold
Go to

previous error in

Complete word
Tab
Brace

brace and

Tip #327 - key mappings : vim online

<Esc>
Don't want to move my hand to esc key.
imap <M-k> <Cy>
from above.
imap <M-q>
/* */<Esc>hhi
selected lines

Escape.

Copy line

Comment

noremap <M-r> ddko{<C-m>}<Esc>kpko


Convert a simple
statement to a compound statement. And place cursor above prev
line.
noremap <M-k> ddko{<C-m>}<Esc>kpo
Same as above but
place cursor below old line.
vnoremap <M-j> <Esc>
vnoremap <M-c> di/*<C-m>/<C-m><Esc>kkp
selected text

nmap <M-n> :noh<CR>

Commented

No hilight

Bye,
Nithin.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Help for VIM Help (VIM QuickRef) | Vim in Microsoft Visual Foxpro >>

Additional Notes
young@intnet.mu, September 20, 2002 1:57
Hello Nithin,
I was baffled to read that you are attempting to reduce your
hand movements to the minimum [with these key mappings] while
you are typing. Surely you know that this makes you a very good
candidate for RSI (Repetitive Strain Injury). Experts recommend
that the hands "float" over the keyboard, with the fingers as
straight as possible -- instead of curled -- and using full arm
movements --instead of finger and wrist contortions. This
supposedly helps your arms and hands maintain a natural
orientation.
As a professional, I am very concerned with these issues and I
try to follow preventive measures against RSI as much as
possible. I recommend others to do the same. Nevertheless, your
tip was a good start for me to learn about key mappings.
Regards,

http://www.vim.org/tips/tip.php?tip_id=327 (2 of 4) [18/02/2004 14:54:06]

Tip #327 - key mappings : vim online

Eddy Young
rumcho at yahoo dot com, June 25, 2003 14:36
Why are you baffled about? Vim is about fast and efficient
writing, if you move your hands around in order to reach keys
that's slowing you down. I don't deny the possiblity of
developing some health condition but that's something the user
has to make special "accomodations" about and it is not the
goal of vim.
zvezdan@cs.wm.edu, December 10, 2003 16:59
Why remap so many keys just because you have to turn your hand
for Ctrl?
Remap Ctrl key instead. I do that on every system I use.
On any modern UNIX that uses X do:
setxkbmap -option ctrl:swapcaps
and your CapsLock key will become Ctrl, while Ctrl will become
CapsLock,
just like on good old Sun keyboards. That position is right
next to the pinky finger, and feels really
naturally. Considering that Bill Joy wrote vi and founded Sun,
it's not a surprise that Sun keyboards were so ideally suited
to vi. :-)
On older UNIX systems store this in a file:
!
! Swap Caps_Lock and Control_L
!
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L
and execute that file with
xmodmap filename
Probably the best thing is to put one of these commands in
.xsession or equivalent file.
Red Hat Linux and Fedora will execute by default .Xkbmap and
.Xmodmap. In such a case it is enough to put xmodmap commands
in .Xmodmap file, and only -option ctrl:swapcaps in .Xkbmap.
Of course you need only one of these two files.
In fact, I doubt that you'll do it, since you are already used
to your mappings.
But I do not recommend your tip to anybody else. I have put
this detailed description here for
other people who are frustrated with the position of Ctrl key,
yet do not know how to change it.

http://www.vim.org/tips/tip.php?tip_id=327 (3 of 4) [18/02/2004 14:54:06]

Tip #327 - key mappings : vim online

emallove@yahoo.com, December 14, 2003 12:35


These mappings are brilliant mate!
As for "risk of RSI" ... I think anything that makes typing
more comfortable LESSENS the risk of RSI.
Cheers!
Ethan
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=327 (4 of 4) [18/02/2004 14:54:06]

SourceForge
Logo

Tip #328 - Vim in Microsoft Visual Foxpro : vim online

not logged in (login)

Home
Search

Tip #328: Vim in Microsoft Visual Foxpro


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/4, Viewed by 768

created: September 18, 2002 22:53


author: Stanislav Sitar

complexity: basic
as of Vim: 5.7

You can tell MS VFP to use an external


editor for editing project files.
To tell MS VFP to use Vim:
start regedit
locate
[HKEY_CURRENT_USER
\Software
\Microsoft
\VisualFoxPro
\5.0
\Options]
and create a new item
TEDIT
with string content
"/N C:\Progra~1\vim\vim61\gvim.exe"
(or whatever your path to Vim happens to be.)
This will not replace the internal VFP
editor for such things as modifying the
"click method" for a button
(unfortunately),
but when you modify a program, VFP will
fire up gvim.
Start MS VFP, start Help and
look for TEDIT. ;-)
rate this tip

Life Changing

<<key mappings | A map for swapping words >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=328 (1 of 2) [18/02/2004 14:54:08]

Helpful

Unfulfilling

rate

Tip #328 - Vim in Microsoft Visual Foxpro : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=328 (2 of 2) [18/02/2004 14:54:08]

SourceForge
Logo

Tip #329 - A map for swapping words : vim online

not logged in (login)

Tip #329: A map for swapping words

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 66/23, Viewed by 1549

created: September 20, 2002 9:27


author: Chip Campbell, Arun Easi, Benji Fisher

complexity: intermediate
as of Vim: 6.0

Put the following map into your <.vimrc>:


nmap <silent> gw "_yiw:s/\(\%#\w\+\)\(\W\+\)\(\w\+\)/\3\2\1/<cr><c-o><cl>
Then when you put the cursor on or in a word, press "gw", and
the word will be swapped with the next word. The words may
even be separated by punctuation (such as "abc = def").
While we're talking swapping, here's a map for swapping characters:
nmap <silent> gc

xph

This hint was formed in a collaboration between


Chip Campbell - Arun Easi - Benji Fisher
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Vim in Microsoft Visual Foxpro | how to stop auto indenting >>

Additional Notes
cec@NgrOyphSon.gPsfAc.nMasa.gov, September 20, 2002 11:08
Thought I'd mention some of the reasoning behind the gw-map
above. Sequences such as dawelp suffer from one or more problems:
* fencepost problems: they don't work correctly either at the beginning
of a line
or at the end of a line
* single-character-word problems: mappings using b, e, or variants don't
handle
single-character words properly.
jean upfrontsystems co za, October 5, 2002 11:03
Looks like this doesn't swap "this" and "that" when line 2 starts with
"that", and line 1 ends on "this";
that is a problem for another day :)
Just possibly Vim's newline-matching regexps will be able to cope with
this .. but it's probably going
too far.
cec@NgrOyphSon.gPsfAc.nMasa.gov, December 2, 2002 7:42

http://www.vim.org/tips/tip.php?tip_id=329 (1 of 2) [18/02/2004 14:54:10]

Tip #329 - A map for swapping words : vim online

Making vim handle word swapping across a newline is


fairly straightforward:
nmap <silent> gw
o><c-l>

"_yiw:s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<cr><c-

Just one extra underscore (at a suitable location, of course :) .


cec@NgrOyphSon.gPsfAc.nMasa.gov, September 9, 2003 6:48
A map for swapping paragraphs:
nnoremap g{

{dap}p{

A pair of maps for swapping a word to-the-left and to-the-right:


nnoremap <silent> gl
\"_yiw?\w\+\_W\+\%#<CR>:s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<cr><co><c-l>
nnoremap <silent> gr
\"_yiw:s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<cr><co>/\w\+\_W\+<CR><c-l>
cec@NgrOyphSon.gPsfAc.nMasa.gov, November 7, 2003 8:47
A plugin for visual-mode based swapping is now available at
http://www.erols.com/astronaut/vim/index.html#VimFuncs
under "Visual Mode Based Swapping"
* Use a visual mode to select some text (V, v, or ctrl-v), then press
<ctrl-y>
* Use a visual mode to select alternate text, then press <ctrl-x>
The two text regions will then be swapped.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=329 (2 of 2) [18/02/2004 14:54:10]

SourceForge
Logo

Tip #330 - how to stop auto indenting : vim online

not logged in (login)

Home
Search

Tip #330: how to stop auto indenting


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 405/132, Viewed by 5776

created: September 20, 2002 13:01


author: Francis

complexity: intermediate
as of Vim: 6.0

Since VIM 6.0 the indent has been improved so much.


But sometimes when we are pasting formated text (source code
or HTML etc)
into a buffer, VIM indents again so that lines will be
padded with too
much spaces.
Setting nocindent, noautoindent, nosmartindent still cannot
stop this.
All you need to do is "set paste", then paste your stuff,
and then
"set nopaste" again.
Ref: indentexpr
rate this tip

Life Changing

Helpful

Unfulfilling

<<A map for swapping words | modline magic... >>

Additional Notes
maxiangjiang@homail.com, September 20, 2002 22:50
:h pt
even better
jlroyalty@yahoo.com, September 22, 2002 11:21

http://www.vim.org/tips/tip.php?tip_id=330 (1 of 7) [18/02/2004 14:54:13]

rate

Tip #330 - how to stop auto indenting : vim online

I find that I'm annoyed by the indent policy accompanying


some file types (HTML and XML in particular). Adding the
following lines to your .vimrc will turn off ALL indenting
for the given file types:
autocmd
autocmd
autocmd
autocmd

BufEnter
BufEnter
BufEnter
BufEnter

*.html setlocal indentexpr=


*.htm setlocal indentexpr=
*.xml setlocal indentexpr=
*.xsd setlocal indentexpr=

Just change the above to whatever file type (extension) you


want to disable indenting for.
dave.pearce@bbc.co.uk, October 2, 2002 5:51
As a 15 year + vi user I find the latest version of vim
intensely irritating.
I would like a quick way of disabling the irritatingly
stupid indentation and I
am not keen on wasting any time learning how to configure
vim.
To my mind vim -C should disable indentation and
highlighting (which is none to
clever either) but it doesn't- any hints?
edward.corwin@sdsmt.edu, October 2, 2002 18:38
AMEN to the person who finds the indenting exceedingly
annoying. Does anyone know how to disable this so-called
feature completely so that I can type things the way
I want rather than the way someone else decided I should
want? This sort of thing is very un-Unix-like.
Edward.Corwin@sdsmt.edu, October 3, 2002 7:52
I finally found out how to disable the autoindent
annoyance.
Put the following line in the file .vimrc in your home
directory:
filetype off
Amazingly easy to do.
to do it?

Why was it so hard to find out how

mclark@removethis.andthis.godze.us, October 9, 2002 18:34

http://www.vim.org/tips/tip.php?tip_id=330 (2 of 7) [18/02/2004 14:54:13]

Tip #330 - how to stop auto indenting : vim online

Another alternative is to modify $VIMRUNTIME/filetype.vim,


which
is a fairly straight forward process. Just find the
section for the
file type in question and start commenting or deleting
sections
that offend you.
-Michael
And now, my Two Cents:
>>Amazingly easy to do. Why was it so hard to find out how
to do it?
Because most people are not so put off by it.
>>I [want to] type things the way I want rather than the
way someone
>>decided I should want? This sort of thing is very unUnix-like.
Most of the indenting schemes are fairly configurable on an
individual
basis, and almost all conform to de-facto and/or official
code standards.
That's not so un-unix like, is it?
>>I'm a 15 year + vi user I find the latest version of vim
intensely irritating.
>>I am not keen on wasting any time learning how to
configure vim.
Why are you using VIM then? Use a VI clone if you are not
willing to
configure VIM. Why are you unwilling to configure your
editor?
>>To my mind vim -C should disable indentation and
highlighting
I agree. Intuitively I would expect that to disable those
features.
Anonymous, October 22, 2002 11:55
:set pastetoggle=<F11>
rando@babblica.net, November 6, 2002 5:39
To turn off indenting, you can use:
:set noai
:set noautoindent
Anonymous, November 14, 2002 19:42

http://www.vim.org/tips/tip.php?tip_id=330 (3 of 7) [18/02/2004 14:54:13]

Tip #330 - how to stop auto indenting : vim online

To rando:
':set no ai' will not work when filetype (or the new indent
feature) exists. that's all this tip about.
findjaylogan@mailcity.com, January 17, 2003 8:00
Is there a way to make it insert spaces instead of tabs
when it auto-indents?
findjaylogan@mailcity.com, January 17, 2003 8:02
never mind...
the answer to my question was
set expandtabs
anonymous, March 1, 2003 19:39
There's no s on that:
:set expandtab
Also, I tried a few of the options above to turn off the
indenting but none seemed to work
so I renamed the html.vim file in the indent directory to
html_vim.
Syntax highlighting still works but the indenting is
disabled for now until I have time to figure
it out.
vim (at) leonini.net, March 30, 2003 23:57
add in your .vimrc:
" Paste Mode On/Off
map <F11> :call Paste_on_off()<CR>
set pastetoggle=<F11>
let paste_mode = 0 " 0 = normal, 1 = paste
func! Paste_on_off()
if g:paste_mode == 0
set paste
let g:paste_mode = 1
else
set nopaste
let g:paste_mode = 0
endif
return
endfunc
Keith@dontmailme.com, April 11, 2003 15:45

http://www.vim.org/tips/tip.php?tip_id=330 (4 of 7) [18/02/2004 14:54:13]

Tip #330 - how to stop auto indenting : vim online

If you're using gvim for Windows, just deleting all the


contents of the "indent" folder works nicely to disable
this "feature".
cameron.kerr@paradise.net.nz, May 13, 2003 6:12
Serendipidy to the rescue.
:a
Paste in stuff using X or GPM etc
Control-C, or ESC
I find this tremendously useful, but it does bauk sometimes
when you paste in escape codes.
ethan.mallove@libertymutual.com, July 31, 2003 5:54
I would like to shift some text a tabs-width left or
right. For some reason, regardless of what my "set
ts=<some number>" is set to --- it shifts the block 8
spaces. Since I prefer 4 spaces as a tab-width, I have to
jump down, row-by-row and do a "4x" on each row to do what
should be a simple "<L" operation. Any tips?
Anonymous, August 15, 2003 8:34
what you're after is shiftwidth not tabstop
ie :se sw=4
no@never.com, August 24, 2003 3:04
obviously you ppl never code much. vim's auto indent
feature is written for people who don't write letters etc
but who program. I assure you that it is amazingly usefull
for programming and that i for one love the guy who wrote
it! As the people wrote vim obviously write alot of code
they wrote it in to help themselves out (and the many other
programmers out there). For those of you who said it was
"very un-*nix like" i say that its very un-*nix like to
bash features that you don't understand ... if you don't
wanna play round with config files and acutally have to
figure stuff out then go install windows and use notepad
:D </rant>
not_no@never.com, October 8, 2003 17:25
Troll dude - lighten up. Some people (sorry - ppl)
actually _care_ about what they type and use their 'brains'
to decide what kind of indentation/style/whitespace they
wish. For those folks (sorry - fks) the 'new' vi can be a
real pain in the ass - as it's pretty tricky to work out
how to turn the stuff off.
Sylvester

http://www.vim.org/tips/tip.php?tip_id=330 (5 of 7) [18/02/2004 14:54:13]

Tip #330 - how to stop auto indenting : vim online

anonymous, October 10, 2003 15:39


I just upgraded to vim 6.2 also. Can't say I have any
problems with auto indent on my UNIX box, although, the
trick that worked for me using gVim 6.2 on Windows was the
following:
:set nocindent<CR>
:set cinoptions=<CR>
One way to find out what is causing the indent is to just
type ":set<CR>". A list of all options that differ from
their default value will be shown. If something weird
arrises when I'm coding, such as autoindent, I will exit
vim, restart it, check the settings using the ":set"
command, open the file that I was working on, and check
":set" again to see what the differences are.
I suggest looking and the command ":help set". You may be
able to alleviate any future problems by simply looking to
see what values are set to what.
youwouldntknowifitbityouintheass@wisdom.net, October 19, 2003 22:34
RE: "obviously you ppl never code much."
and
RE: "Because most people are not so put off by it."
Amazing!

With arrogance like this, who needs M$?

Common sense goes further than a lot of learning.

Anonymous, October 21, 2003 20:52


To fully disable any and all forms of autoindenting in vim,
you have to add all these options at the bottom of your
vimrc file. If you want the settings in the default vimrc
file that comes with the official distribution of vim but
want autoindening turned off, all you have to do is place
these options at the bottom of the vimrc file.
set nocindent
set nosmartindent
set noautoindent
set indenexpr=
filetype indent off
filetype plugin indent off
To see how I came up with this solution, check out the
thread I began with the subject "disabling all forms of

http://www.vim.org/tips/tip.php?tip_id=330 (6 of 7) [18/02/2004 14:54:13]

Tip #330 - how to stop auto indenting : vim online

auto indentation completely"


in the vim mailing list.
The beginning of the thread of
over a dozen post/replies can be found at the mailing list
site:
http://groups.yahoo.com/group/vim/message/43582
or the alternate site
http://marc.theaimsgroup.com/?l=vim&m=106438290613886&w=4
Alternatively, you can check out the archive set:
http://marc.theaimsgroup.com/?l=vim&r=1&s=disabling&q=b&w=4

Enjoy!
Best Regards,
Carlo
-----Carlo Florendo
Astra Philippines Inc.
www.hq.astra.ph

Anonymous, November 22, 2003 19:27


M$ ne 'Common sense'
Anonymous, February 11, 2004 3:55
Even with all these things set, I had to force vim to use
my ~/.vimrc file by aliasing vim to 'vim -u ~/.vimrc'. Only
then does the cursed autoindenting go away.
As far as I'm concerned this does break the unix standard.
.rc files in a user's home directory should be read last
and should override other settings.
Anyone else know what's going on?
Gilou, February 15, 2004 16:06
Thanks ;)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=330 (7 of 7) [18/02/2004 14:54:13]

SourceForge
Logo

Tip #331 - modline magic... : vim online

not logged in (login)

Tip #331: modline magic...

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 29/13, Viewed by 1836

created: September 22, 2002 14:35


author: Alex A. Naanou

complexity: basic
as of Vim: 5.7

One of the things about vim that are both quite


simple yet very
useful is that you can store by-file settings... that is
each file can
contain settings specific to it. this thing is called a
modline (:help
modline). though this is limited to only the 'set' command
arguments,
you can do allot of local to file things like the indent
type, folding
method and so
on.
the syntax is as follows:
// vim:set ts=4 sw=4 nowrap:
or
/* vim:noai:ts=2:sw=4: */
The modlines can be contained in comments so as to not
interfere with
the file syntax (shown here for C/C++). these lines are
read by vim
when it loads the file, and they can either be in the first
or last 5
lines (by
default).
refer to ':help modline'
//and a happy 20th birthday to the good old smiley!! :-)
rate this tip

Life Changing

Helpful

<<how to stop auto indenting | make footnotes in vim >>

Additional Notes
http://www.vim.org/tips/tip.php?tip_id=331 (1 of 2) [18/02/2004 14:54:15]

Unfulfilling

rate

Tip #331 - modline magic... : vim online

goulding@princeton.edu, September 22, 2002 20:18


That's modeline, and :help modeline
feral@firetop.Ihatespam.com, September 23, 2002 1:28
Speeking of modelines I find it handy to have a very
primitive menu entry to insert my normal modeline for me:
amenu Fe&ral's.Insert\ a\ VIM\ modeline
<Esc><Esc>ggOvim:ff=unix ts=4
ss=4<CR>vim60:fdm=marker<esc>gg
This will net you a (I think proper) modeline at the start
of the file like so:
vim:ff=unix ts=4 ss=4
vim60:fdm=marker
hermitte at free.fr, September 25, 2002 7:11
BTW, this mecanism can be extended to 'let'. Cf. for
instance : vimscript#83
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=331 (2 of 2) [18/02/2004 14:54:15]

SourceForge
Logo

Tip #332 - make footnotes in vim : vim online

not logged in (login)

Home
Search

Tip #332: make footnotes in vim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 17/7, Viewed by 2308

created: September 23, 2002 3:43


author: emmanuel.touzery@wanadoo.fr

complexity: basic
as of Vim: 6.0

I found at
http://groups.google.com/groups?q=vim+changing+shell+to+zsh&hl=en&lr=&ie=UTF8&selm=S_Rh9.716%24a5.124150%40news.uchicago.edu&rnum=4
a macro to insert footnotes in vim, but it doesn't work as of vim6.0.
so i wrote my own; this macro requires two differents shortcuts, one for
entering the first footnote, the other one for all subsequent footnotes.
when you hit "K0" (first footnote) or "KK" (all other footnotes) in normal
mode, your cursor is positionned at the end of the document, in the footnote
& in insert mode. The "a" bookmark is set to the place where you entered the
footnote in the text. so a "`a" will bring you back to the location of the
footnote in the text.
" for now requires entering K0 for the first footnote and then
KK
nmap K0 i[0]<esc>maG$i<end><enter>[0]
nmap KK maG$?\[[0-9]*\]<enter>yt]G$i<end><enter><esc>p<C-a>i<end>]<esc>`aP<Ca><right>i]<esc>maG$i<end><end>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<modline magic... | Syntax-based folding for c/c++/java >>

Additional Notes
emmanuel.touzery@wanadoo.fr, September 23, 2002 5:21
for information i just added a worthwhile special case:
we do not add the footnotes at the end of the document, but on the line
before a "--".
this is useful if you have a signature at the end of your mails, eg, do:
hello[0]!
[0] footnote
-sig
and not:
hello[0]!
-sig
[0] footnote
here is the updated code:
nmap K0 i[0]<esc>maG?--<enter><up>$i<end><enter>[0]
nmap KK maG$?\[[0-9]*\]<enter>yt]G?--<enter><up>$i<end><enter><esc>p<Ca>i<end>]<esc>`aP<C-a><right>i]<esc>maG?--<enter><up>$i<end><end>

http://www.vim.org/tips/tip.php?tip_id=332 (1 of 6) [18/02/2004 14:54:19]

Tip #332 - make footnotes in vim : vim online

(i'll take any suggestion to remove code duplication, but i don't know the
language well enough for now)
emmanuel.touzery@wanadoo.fr, September 24, 2002 6:36
ok, learned some more vim. now it's not anymore a macro, but a function.
you don't have to enter the text of the footnote separately, you are
prompted for it, so it's faster to use. also, there is no more separation
for the first footnote case: you all the time enter KK.
it also supports the case when there is a sig or not.
here is the whole code:
nmap KK :call InsertFootNote()<LF>
function! InsertFootNote()
.
" mark the position of the cursor
.
execute "normal ma"
.
" ask for footnote text
.
let footNoteText = input("enter text for footnote: ")
.
" was there already a footnote?
.
if search("\[[0-9]*]", "w")
.
.
" yes => get the number, copy it, increase
.
.
" it, put it at the footnote position, put
.
.
" the footnote text and position the cursor back.
.
.
execute "normal G$?\[[0-9]*\]\<enter>yt]:call
GotoFootNoteLocation()\<LF>$i\<end>\<enter>\<esc>p\<C-a>i\<end>] " .
footNoteText . "\<esc>`aP\<C-a>\<right>i]\<esc>"
.
else
.
.
" no => put [0], add at the end [0] + footnote text
.
.
" and position cursor back
.
.
execute "normal i[0]\<esc>:call
GotoFootNoteLocation()\<LF>$i\<end>
\<enter>\<enter>[0] " . footNoteText . "\<esc>`a"
.
endif
endfunction
" if there is a signature, the footnote
" should be positionned ontop of it, eg
" mail text
" [0] footnote 0
" -" sig
" and not:
" mail text
" -" sig
" [0] footnote 0
" otherwise it's at the end of the text.
function! GotoFootNoteLocation()
.
" the signature is found by the "--"
.
" pattern.
.
" i don't search from the end because
.
" a fwd will also match this and i don't want
.
" that footnotes are too far off, say after 5-6
.
" old forwarded emails.
.
if search("^--", "w")
.
.
" ok, there's a sig.
.
.
" just go on top of it.
.
.
execute "normal \<up>"
.
else
.
.
" no sig: we go at the end of the
.
.
" document.
http://www.vim.org/tips/tip.php?tip_id=332 (2 of 6) [18/02/2004 14:54:19]

Tip #332 - make footnotes in vim : vim online

.
.
.
endif
endfunction

execute "normal G$"

mikmach@wp.pl, September 24, 2002 9:12


This is easier:
inoremap ,f <esc>:call VimFootnotes()<cr>
inoremap ,r <esc>:exe b:pos<cr>
function! VimFootnotes()
if exists("b:vimfootnotenumber")
let b:vimfootnotenumber = b:vimfootnotenumber + 1
let cr = ""
else
let b:vimfootnotenumber = 0
let cr = "\<cr>"
endif
let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l'
exe "normal a[".b:vimfootnotenumber."]\<esc>G"
if search("-- $", "b")
exe "normal O".cr."[".b:vimfootnotenumber."] "
else
exe "normal o".cr."[".b:vimfootnotenumber."] "
endif
startinsert!
endfunction
salmanhalim@hotmail.com, September 24, 2002 13:12
This works just fine -- and is a pretty cool idea -- except that it would
be nice if ,r would restart insert-mode when done. Replacing the beginning
of the rhs with <c-o> instead of <esc> works in all cases except when the
footnote was added to the end of the line (more likely than not, actually,
since footnotes might be added during the initial text entry).
emmanuel.touzery@wanadoo.fr, September 25, 2002 1:04
mikmach@wp.pl, i really like your 100% function implementation (as opposed
to my half-macro), but i have some comments:
* detail: you don't use an input text to ask the text of the footnote,
which i found nicer than providing a goto footnote (see my latest version).
it's trivial to change though:
function! VimFootnotes()
execute "normal ma"
let footNoteText = input("enter text for footnote: ")
if exists("b:vimfootnotenumber")
let b:vimfootnotenumber = b:vimfootnotenumber + 1
let cr = ""
else
let b:vimfootnotenumber = 0
let cr = "\<cr>"
endif
let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l'
exe "normal a[".b:vimfootnotenumber."]\<esc>G"
if search("-- $", "b")
exe "normal O".cr."[".b:vimfootnotenumber."] " . footNoteText
else
exe "normal o".cr."[".b:vimfootnotenumber."] " . footNoteText
endif
execute "normal `a"
endfunction
* bigger problem: if you insert a footnote, and undo it, and insert a
http://www.vim.org/tips/tip.php?tip_id=332 (3 of 6) [18/02/2004 14:54:19]

Tip #332 - make footnotes in vim : vim online

footnote again, the number is incremented once too much. i guess it's
impossible to catch undo events for vim functions? :O(
btw, can you give me a pointer to a good vim programming website?
mikmach, September 25, 2002 2:07
1. Input field doesn't give possibility to format text
2. The best programming vim page is user manual and vim-mail list
emmanuel.touzery@wanadoo.fr, September 25, 2002 2:28
thanks, point one is a killer :O)
i didn't think about it. i guess at the end i'll take a mix of our scripts
(for the undo thing).
thanks! your code is a good example.
mikmach, September 25, 2002 10:33
And here is another example how nice (although sophisticated) map can
become terrible beast :)
Split of the window is a good compromise between input field and going down
Play with b:vimfootnotetype :) Alpha, alpha, arabic - roman for footnotes
is rare
inoremap ,f <C-O>:call VimFootnotes()<CR>
inoremap ,r <C-O>:q<CR><Right>
let b:vimfootnotetype = "alpha"
function! VimFootnoteType(footnumber)
if !exists("b:vimfootnotetype")
let b:vimfootnotetype = "arabic"
endif
if (b:vimfootnotetype =~ "^alpha\\|^Alpha")
if (b:vimfootnotetype =~ "^alpha")
let upper = "0"
else
let upper = "-32"
endif
if (a:footnumber <= 26)
let ftnumber = nr2char(a:footnumber+96+upper)
elseif (a:footnumber <= 52)
let ftnumber =
nr2char(a:footnumber+70+upper).nr2char(a:footnumber+70+upper)
else
let b:vimfootnotenumber = 1
let ftnumber = nr2char(97+upper)
endif
else
let ftnumber = a:footnumber
endif
return ftnumber
endfunction
function! VimFootnotes()
if exists("b:vimfootnotenumber")
let b:vimfootnotenumber = b:vimfootnotenumber + 1
let b:vimfootnotemark = VimFootnoteType(b:vimfootnotenumber)
let cr = ""
else
let b:vimfootnotenumber = 1
let b:vimfootnotemark = VimFootnoteType(b:vimfootnotenumber)
let cr = "\<cr>"

http://www.vim.org/tips/tip.php?tip_id=332 (4 of 6) [18/02/2004 14:54:19]

Tip #332 - make footnotes in vim : vim online

endif
"let b:pos = line('.').' | normal! '.virtcol('.').'|'.'4l'
exe "normal a[".b:vimfootnotemark."]\<esc>"
let splitposition = &splitbelow
set splitbelow
:5 split
let &splitbelow = splitposition
normal G
if search("^-- $", "bW")
exe "normal O".cr."[".b:vimfootnotemark."] "
else
exe "normal o".cr."[".b:vimfootnotemark."] "
endif
startinsert!
endfunction
Anonymous, September 25, 2002 19:28
Instead of hard-coding numbers like 97, suggest doing something like
char2nr( 'a' ) -- hard-coded numbers frighten me.
hermitte at free.fr, September 26, 2002 0:36
I do also vote for the window-splitting approach. I think it is one of the
best and cleanest choice we can have.
Otherwise, some minor other improvments can be done like "pluginizing" the
script :
It would start with something like :
" ---if exists("g:loaded_footnote_vim") | finish | endif
let g:loaded_footnote_vim = 1
let s:first_footnote = exists('g:first_footnote') : g:first_footnote ? 1
" Because I don't like to start the footnotes with [0]
if !hasmapto('<Plug>AddVimFootnote', 'i')
imap <C-X>f <Plug>AddVimFootnote
endif
if !hasmapto('<Plug>AddVimFootnote', 'n')
nmap <leader>af <Plug>AddVimFootnote
endif
nnoremap <Plug>AddVimFootnote :call <sid>VimFootnotes('a')<cr>
inoremap <Plug>AddVimFootnote <c-o>:call <sid>VimFootnotes('i')<cr>
"Note: be sure there is *NO* space after the '<cr>' when you copy-paste.
" The previous paragraph enables anyone to remap the functions calls
" to anything else that the developper's default bindings. To do so, add
into
" your .vimrc something like :
" nmap ,f <Plug>AddVimFootNote
function! s:VimFootnotes(appendcmd)
....
:below 3sp
" note that you don't need change the value of 'splitbelow'
exe "normal ".a:appendcmd."[".b:vimfootnotenumber."]\<esc>G"
...
Anon, September 26, 2002 6:01

http://www.vim.org/tips/tip.php?tip_id=332 (5 of 6) [18/02/2004 14:54:19]

Tip #332 - make footnotes in vim : vim online

You could technically parse the line just above the place where the next
footnote is going to be placed: something like substitute( getline( '.' 1 ), '^\[\(\w\+\)\]', '\1', '' ) should give you the footnote
number/letter. Then, either increment it as a number or do a char2nr on it
(depending on the footnote style) for the processing. That way, you don't
have to worry about not being able to handle decrementing the footnote
value upon an undo operation.
emmanuel.touzery@wanadoo.fr, October 30, 2002 2:23
there is now a script improving on this tip.
you probably want it instead: http://www.vim.org/script.php?script_id=431
emmanuel
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=332 (6 of 6) [18/02/2004 14:54:19]

SourceForge
Logo

Tip #333 - Syntax-based folding for c/c++/java : vim online

not logged in (login)

Home
Search

Tip #333: Syntax-based folding for c/c++/java


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 59/23, Viewed by 4344

created: September 23, 2002 18:32


author: Kartik Agaram

complexity: intermediate
as of Vim: 6.0

Here's a function to toggle the use of syntax-based folding for a


c/c++/java file. It also handles folding markers.
function! OutlineToggle()
if (! exists ("b:outline_mode"))
let b:outline_mode = 0
endif
if (b:outline_mode == 0)
syn region myFold start="{" end="}" transparent fold
syn sync fromstart
set foldmethod=syntax
silent! exec "%s/{{{/<<</"
silent! exec "%s/}}}/>>>/"
let b:outline_mode = 1
else
set foldmethod=marker
silent! exec "%s/<<</{{{/"
silent! exec "%s/>>>/}}}/"
let b:outline_mode = 0
endif
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

<<make footnotes in vim | Loading scripts in .vimrc safely >>

Additional Notes
feral@firetop.spammersdie.com, September 24, 2002 5:47

http://www.vim.org/tips/tip.php?tip_id=333 (1 of 4) [18/02/2004 14:54:21]

rate

Tip #333 - Syntax-based folding for c/c++/java : vim online

I took Kartik's implementation and played with it, then played


with it some more and finally got it to work.
The "syn region myFold start="{" end="}" transparent fold" method
does not like to work when you have other syn groups for {,}. I
found this annoying (as I like my colored Braces!) so I figured a
pure marker method would work nearly (or just as) good, and it
does at least for my uses.
Hopefully everything works just did v0.03 and I have run out of
time, enjoy!
outlinetoggle.vim from my plugin dir>>>
" vim:ff=unix ts=4 ss=4
" vim60:fdm=marker
" \file outlinetoggle.vim
"
" \brief VIM-Tip #333: Syntax-based folding for c/c++/java
"
" \author author:
Kartik Agaram as of Vim:
6.0
" \author Mangled by Feral@FireTop.Com
" \date Tue, 24 Sep 2002 05:44 Pacific Daylight Time
" \version $Id$
" Version: 0.03
" History:
" [Feral:267/02@05:43] v0.03:
" saves the old marker method now.
" stoped trying to be clever (just do the command twice heh)
" v0.02
" trys to be cleaver and start in the proper outline mode based on
if it
" finds a "{>>" in the file.
"if exists("loaded_outlinetoggle")
" finish
"endif
"let loaded_outlinetoggle = 1
" Tip #333: Syntax-based folding for c/c++/java
" tip karma Rating 0/0, Viewed by 88
"
"created:
September 23, 2002 18:32 complexity:
intermediate
"author:
Kartik Agaram as of Vim:
6.0
"
"Here's a function to toggle the use of syntax-based folding for a
c/c++/java file. It also handles folding markers.
function! <SID>OutlineToggle()
let OldLine = line(".")
let OldCol = virtcol(".")
if (! exists ("b:outline_mode"))
let b:outline_mode = 0
let b:OldMarker = &foldmarker
" :echo confirm(b:OldMarker)
" if search("{>>", 'w') == 0
" " no modifed marker found, must be normal marker mode
http://www.vim.org/tips/tip.php?tip_id=333 (2 of 4) [18/02/2004 14:54:21]

Tip #333 - Syntax-based folding for c/c++/java : vim online

" let b:outline_mode = 0


" else
" let b:outline_mode = 1
" endif
endif
if (b:outline_mode == 0)
let b:outline_mode = 1
" syn region myFold start="{" end="}" transparent fold
" syn sync fromstart
" set foldmethod=syntax
" set foldmethod=indent
set foldmethod=marker
set foldmarker={,}
silent! exec "%s/{{{/{<</"
silent! exec "%s/}}}/}>>/"
else
let b:outline_mode = 0
set foldmethod=marker
let &foldmarker=b:OldMarker
" set foldmarker={{{,}}}
silent! exec "%s/{<</{{{/"
silent! exec "%s/}>>/}}}/"
endif
execute "normal! ".OldLine."G"
execute "normal! ".OldCol."|"
unlet OldLine
unlet OldCol
execute "normal! zv"
endfunction
"*****************************************************************
"* Commands
"*****************************************************************
:command! -nargs=0 OUTLINE call <SID>OutlineToggle()
"
"EOF
<<<
Kartik Agaram, September 25, 2002 20:52
Nice. Not changing foldmethod is definitely more elegant.
bronson@real-time.com, May 20, 2003 6:36
So, how would I set vim up to fold all c and cpp files when I load
them?
This sounds like it should be in the syntax file for cpp just like
the pl syntax file allows perl_fold=1.
Rich S., January 9, 2004 13:05

http://www.vim.org/tips/tip.php?tip_id=333 (3 of 4) [18/02/2004 14:54:21]

Tip #333 - Syntax-based folding for c/c++/java : vim online

Hi,
The tip in the comment is great. As is the whole concept of easy
folding.
I popped this into my .vimrc:
map <silent> <F12> :OUTLINE<CR>
This makes F12 switch in and out of outline (folded) mode.
You could probably use autocommand to make the folding happen when
you open something you want to fold.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=333 (4 of 4) [18/02/2004 14:54:21]

SourceForge
Logo

Tip #334 - Loading scripts in .vimrc safely : vim online

not logged in (login)

Home
Search

Tip #334: Loading scripts in .vimrc safely


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 42/14, Viewed by 1339

created: September 30, 2002 9:59


author: piaip@csie.ntu.edu.tw (Francis)

complexity: basic
as of Vim: 6.0

If you copy your .vimrc to many places, you might get a


problem:
writing a portable .vimrc is sometimes painful.
Maybe in some places you have latest VIM6.1, and in some
places
you have VIM 5.x. And maybe you have some favorite
scripts in
your own computer while other places does not.
Here're some tips and examples on writing portable
.vimrc that will not make error
messages when environment changes:
(1) Check version:
if version >= 600
set foldcolumn=2
endif
(2) Use environment variables:
source $VIMRUNTIME/vimrc_example.vim
(3) Loading scripts(especially useful for scripts just
merged into standard macros):
if filereadable($VIMRUNTIME . "/macros/matchit.vim")
source $VIMRUNTIME/macros/matchit.vim
endif

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Syntax-based folding for c/c++/java | Copy C++ function declaration into implementation file >>

Additional Notes
salmanhalim@hotmail.com, September 30, 2002 17:15
http://www.vim.org/tips/tip.php?tip_id=334 (1 of 2) [18/02/2004 14:54:23]

Tip #334 - Loading scripts in .vimrc safely : vim online

Regarding sourcing stuff inside the runtime directory


such as the macros stuff, look at the :runtime command - it doesn't require error checking (though it might be
only for 6.x or above so pop it inside the version
check).
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=334 (2 of 2) [18/02/2004 14:54:23]

SourceForge
Logo

Tip #335 - Copy C++ function declaration into implementation file : vim online

not logged in (login)

Home
Search

Tip #335: Copy C++ function declaration into implementation file


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/9, Viewed by 2541

created: October 1, 2002 6:47


author: Leif Wickland

complexity: basic
as of Vim: 5.7

There's a handy plug in for MS Visual Studio called CodeWiz that has a nifty ability to copy a function
declaration and deposit it into the implementation file on command. I actually missed while using vim,
so I wrote an approximation of that capability. This isn't foolproof, but it works alright.
" Copy Function Declaration from a header file into the implementation file.
nmap <F5> "lYml[[kw"cye'l
nmap <F6> ma:let
@n=@/<cr>"lp==:s/\<virtual\>/\/\*&\*\//e<cr>:s/\<static\>/\/\*&\*\//e<cr>:s/\s*=\s*0\s*//e<cr>:s/(.\{}\zs=\s*[^,)]\{-1,}\>\ze\(\*\/\)\@!.*)/\/\*&\*\//e<cr>:s/(.\{-}\zs=\s*[^,)]\{1,}\>\ze\(\*\/\)\@!.*)/\/\*&\*\//e<cr>:s/(.\{-}\zs=\s*[^,)]\{1,}\>\ze\(\*\/\)\@!.*)/\/\*&\*\//e<cr>:let @/=@n<cr>'ajf(b"cPa::<esc>f;s<cr>{<cr>}<cr><esc>kk
To use this, source it into vim, for example by placing it in your vimrc, press F5 in normal mode with
the cursor on the line in the header file that declares the function you wish to copy. Then go to your
implementation file and hit F6 in normal mode with the cursor where you want the function
implementation inserted.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Loading scripts in .vimrc safely | type the line number and press enter to get there >>

Additional Notes
feral@firetop.dontspamme.com, October 1, 2002 21:16

http://www.vim.org/tips/tip.php?tip_id=335 (1 of 9) [18/02/2004 14:54:27]

Tip #335 - Copy C++ function declaration into implementation file : vim online

I liked the idea behind Leif?s TIP and I thought ~a~ command you could call in the header ~or~ source
file would be good(one less thing for me to remember) an besides I knew just how I wanted to do it!
Along the way I?ve made a slight improvement or two (no longer clobbers registers/marks for instance).
This is formatted to stuff into a file and drop into your plugin directory.
So it seems to work in most cases (single line Member functions all(?) seem to work, anything else
well, doesn?t) (trips on the same things Leif?s implementation does of course because it IS Leif?s
implementation! I just moved some lines around ;) )
Happy VIMing!
copycppdectoimp.vim>>>
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

vim:ff=unix ts=4 ss=4


vim60:fdm=marker
\file
copycppdectoimp.vim
\brief
\note

From VIM-Tip #335: Copy C++ function declaration into implementation file
by Leif Wickland
as of Vim:
5.7
See: http://vim.sourceforge.net/tip_view.php?tip_id=335

\author
Leif Wickland
\author
(Mangled by) Robert KellyIV <Feral@FireTop.Com>
\note
This file and work is based totally on Leif Wickland's VIM-TIP#335
\date
Tue, 01 Oct 2002 21:03 Pacific Daylight Time
\version
$Id$
Version:
0.2
History: {{{
[Feral:274/02@20:42] 0.2
Improvments: from Leif's Tip (#335):
* can handle any number of default prams (as long as they are all
on the same line!)
* Options on how to format default params, virtual and static.
(see below) TextLink:||@|Prototype:|
* placed commands into a function (at least I think it's an
improvement ;) )
* Improved clarity of the code, at least I hope.
* Preserves registers/marks. (rather does not use marks), Should
not dirty anything.
* All normal operations do not use mappings i.e. :normal!
(I have Y mapped to y$ so Leif's mappings could fail.)
Limitations:
* fails on multi line declorations. All prams must be on the same
line.
* fails for non member functions. (though not horibly, just have
to remove the IncorectClass:: text...
0.1
Leif's original VIM-Tip #335

http://www.vim.org/tips/tip.php?tip_id=335 (2 of 9) [18/02/2004 14:54:27]

Tip #335 - Copy C++ function declaration into implementation file : vim online

" }}}
if exists("loaded_copycppdectoimp")
finish
endif
let loaded_copycppdectoimp = 1
"{{{ [basic] Tip #335: Copy C++ function declaration into implementation file
" tip karma
Rating 5/2, Viewed by 49
"
"created:
October 1, 2002 6:47
complexity:
basic
"author:
Leif Wickland
as of Vim:
5.7
"
"There's a handy plug in for MS Visual Studio called CodeWiz that has a nifty ability to copy a
function declaration and deposit it into the implementation file on command. I actually missed while
using vim, so I wrote an approximation of that capability. This isn't foolproof, but it works
alright.
"
"" Copy Function Declaration from a header file into the implementation file.
"nmap <F5> "lYml[[kw"cye'l
"nmap <F6> ma:let
@n=@/<cr>"lp==:s/\<virtual\>/\/\*&\*\//e<cr>:s/\<static\>/\/\*&\*\//e<cr>:s/\s*=\s*0\s*//e<cr>:s/(.\{}\zs=\s*[^,)]\{-1,}\>\ze\(\*\/\)\@!.*)/\/\*&\*\//e<cr>:s/(.\{-}\zs=\s*[^,)]\{1,}\>\ze\(\*\/\)\@!.*)/\/\*&\*\//e<cr>:s/(.\{-}\zs=\s*[^,)]\{1,}\>\ze\(\*\/\)\@!.*)/\/\*&\*\//e<cr>:let @/=@n<cr>'ajf(b"cPa::<esc>f;s<cr>{<cr>}<cr><esc>kk
"
"To use this, source it into vim, for example by placing it in your vimrc, press F5 in normal mode
with the cursor on the line in the header file that declares the function you wish to copy. Then go
to your implementation file and hit F6 in normal mode with the cursor where you want the function
implementation inserted.
" }}}
function! <SID>GrabFromHeaderPasteInSource(howtoshowVirtual, howtoshowStatic, howtoshowDefaultParams)
"{{{
"
echo confirm(expand("%:e"))
if expand("%:e") ==? "h"
"nmap <F5> "lYml[[kw"cye'l
"
execute ":normal! ml"
let SaveL = line(".")
let SaveC = virtcol(".")

"
"

" into l yank the entire line


" ([Feral:274/02@19:06] MY Y is mapped to y$, so I account for that below)
:let Was_Reg_l = @l
execute ':normal! "lY'
execute ':normal! 0"ly$'
echo confirm(@l)
:let s:LineWithDecloration = @l
:let @l=Was_Reg_l

http://www.vim.org/tips/tip.php?tip_id=335 (3 of 9) [18/02/2004 14:54:27]

Tip #335 - Copy C++ function declaration into implementation file : vim online

" [Feral:274/02@14:41] this works peachy for a member function, not so


" well for a normal function, how can we fix this? Or do we bother?
execute ":normal! [["
execute ":normal! kw"
:let Was_Reg_c = @c
execute ':normal! "cye'
:let s:ClassName = @c
:let @c=Was_Reg_c
"

execute ":normal! 'l"


:execute ":normal! ".SaveL."G"
:execute ":normal! ".SaveC."|"

"

echo confirm(s:ClassName)
else

"

"

echo confirm(s:ClassName)
let SaveL = line(".")
let SaveC = virtcol(".")
:execute ':normal! ma'
:let Was_Reg_n = @n
:let @n=@/
:execute ':normal! O'.s:LineWithDecloration
:execute ':normal! =='
" XXX if you want virtual commented in the implimentation:
if a:howtoshowVirtual == 1
:s/\<virtual\>/\/\*&\*\//e
else
" XXX else, remove virtual and any spaces/tabs after it.
:s/\<virtual\>\s*//e
endif
" XXX if you want static commented in the implimentation:
if a:howtoshowStatic == 1
:s/\<static\>/\/\*&\*\//e
else
" XXX else, remove static and any spaces/tabs after it.
:s/\<static\>\s*//e
endif
" wipe out a pure virtual thingie-ma-bob. (technical term? (= )
:s/\s*=\s*0\s*//e
" Handle default params, if any.
if a:howtoshowDefaultParams == 1
" Remove the default param assignments.
:s/\s\{-}=\s\{-}[^,)]\{1,}//ge
else

http://www.vim.org/tips/tip.php?tip_id=335 (4 of 9) [18/02/2004 14:54:27]

Tip #335 - Copy C++ function declaration into implementation file : vim online

" Comment the default param assignments.


:s/\s\{-}\(=\s\{-}[^,)]\{1,}\)/\/\*\1\*\//ge
if a:howtoshowDefaultParams == 3
" Remove the = and any spaces to the left or right.
:s/\s*=\s*//ge
endif
endif
:let @/=@n
:let @n=Was_Reg_n
:execute ":normal!
:execute ":normal!
:execute ':normal!
:execute ':normal!

".SaveL."G"
".SaveC."|"
f(b'
i'.s:ClassName.'::'

" find the ending ; and replace it with a brace structure on the next line.
:execute ":normal! f;s\<cr>{\<cr>}\<cr>\<esc>kk"
endif
endfunc
"}}}
"*****************************************************************
"* Commands
"*****************************************************************
" given:
"
virtual void Test_Member_Function_B3(int _iSomeNum2 = 5, char * _cpStr = "Yea buddy!");
" Prototype:
"GrabFromHeaderPasteInSource(VirtualFlag, StaticFlag, DefaultParamsFlag)
" VirtualFlag:
" 1:
if you want virtual commented in the implimentation:
"
/*virtual*/ void Test_Member_Function_B3(int _iSomeNum2 = 5, char * _cpStr = "Yea buddy!");
" else:
remove virtual and any spaces/tabs after it.
"
void Test_Member_Function_B3(int _iSomeNum2 = 5, char * _cpStr = "Yea buddy!");
" StaticFlag:
" 1:
if you want static commented in the implimentation:
"
Same as virtual, save deal with static
" else:
remove static and any spaces/tabs after it.
"
Same as virtual, save deal with static
"
"
"
"
"
"

DefaultParamsFlag:
1:
If you want to remove default param reminders, i.e.
Test_Member_Function_B3(int _iSomeNum2, char * _cpStr);
2:
If you want to comment default param assignments, i.e.
Test_Member_Function_B3(int _iSomeNum2/*= 5*/, char * _cpStr/*= "Yea buddy!"*/);
3:
Like 2 but, If you do not want the = in the comment, i.e.

http://www.vim.org/tips/tip.php?tip_id=335 (5 of 9) [18/02/2004 14:54:27]

Tip #335 - Copy C++ function declaration into implementation file : vim online

"
Test_Member_Function_B3(int _iSomeNum2/*5*/, char * _cpStr/*"Yea buddy!"*/);
"
" Examples:
" smallest implimentation:
"
void Test_Member_Function_B3(int _iSomeNum2, char * _cpStr);
":command! -nargs=0 GHPH call <SID>GrabFromHeaderPasteInSource(0,0,1)
"
Verbose...:
"
/*virtual*/ void Test_Member_Function_B3(int _iSomeNum2/*5*/, char * _cpStr/*"Yea buddy!"*/);
":command! -nargs=0 GHPH call <SID>GrabFromHeaderPasteInSource(1,1,3)
"
What I like:
"
void Test_Member_Function_B3(int _iSomeNum2/*5*/, char * _cpStr/*"Yea buddy!"*/);
:command! -nargs=0 GHPH call <SID>GrabFromHeaderPasteInSource(0,0,3)
" Bit of trivia... GHPH.. get header, put header. ~shrug~ I needed a
" command name.... (Name it whatever you wish, of course!)
" eof
<<<copycppdectoimp.vim
hermitte at free.vim, October 7, 2002 15:36
Several things can still be improved :
* There is no need for using registers
* We can easily find the class name (if any) -- easy because I'd already done this for my set of C++
ftplugins
* We can accept prototypes written on several lines (this first version only supports parameters
written on several lines).
There are still some other things that can be done to improve this _ft_plugin, but here is a first
(third) shot.
<=== cut from here
if exists("b:loaded_copycppdectoimp")
let b:loaded_copycppdectoimp = 1

| finish | endif

" Accept commands expressed on several lines


let s:cpo_save=&cpo
set cpo&vim
" The main command, it could also be very interresting to propose
" default mappings (:h <plug>)
command! -buffer -nargs=0 GHPH
\ call <SID>GrabFromHeaderPasteInSource(1,1,1)
if exists("g:loaded_cpp_GotoMemberImpl_vim")
let &cpo=s:cpo_save
finish
endif
let g:loaded_cpp_GotoMemberImpl_vim = 1
"-----------------------------------------------------------------------http://www.vim.org/tips/tip.php?tip_id=335 (6 of 9) [18/02/2004 14:54:27]

Tip #335 - Copy C++ function declaration into implementation file : vim online

" Function: s:GetFunctionPrototype " {{{


" Todo:
" * Retrieve the type even when it is not on the same line as the function
"
identifier.
" * Retrieve the const modifier even when it is not on the same line as the
"
')'.
function! s:GetFunctionPrototype(lineNo)
exe a:lineNo
" 0- Go to the end of the current line (stop at the first found)
call search( ')\|\n')
" 1- Go to the start of the current prototype
let pos = searchpair('\<\i\+\>\%(\n\|\s\)*(', '', ')', 'bW')
let l0 = line('.')
" 2- Go to the "end" of the current prototype
let pos = searchpair('\<\i\+\>\%(\n\|\s\)*(', '', ')', 'W')
let l1 = line('.')
" Abort if nothing has been found
if ((0==pos) || (l0>a:lineNo)) | return '' | endif
" 3- Build the protoype string
let proto = getline(l0)
while l0 < l1
let l0 = l0 + 1
let proto = proto . "\n" . getline(l0)
endwhile
" 4- and return it.
exe a:lineNo
return proto
endfunction
" }}}
"-----------------------------------------------------------------------" Function: Cpp_SearchClassDefinition {{{
" Excerpt from cpp_FindContextClass.vim
function! Cpp_SearchClassDefinition(lineNo)
let pos = a:lineNo
exe a:lineNo
let class = ""
while pos != 0
let pos = searchpair('class\s\+\<\i\+\>\%(\n\|\s\)*{', '', '};', 'bW')
if pos != 0
let cls_name = substitute(getline(pos),
\ '^.*\s*class\s\+\(\<\i\+\>\).*$', '\1', '')
let class = class . '::' . cls_name
endif
endwhile
exe a:lineNo
return substitute (class, '^:\+', '', 'g')
endfunction
" }}}
"-----------------------------------------------------------------------http://www.vim.org/tips/tip.php?tip_id=335 (7 of 9) [18/02/2004 14:54:27]

Tip #335 - Copy C++ function declaration into implementation file : vim online

" Function: s:GrabFromHeaderPasteInSource "{{{


function! s:GrabFromHeaderPasteInSource(
\ HowToShowVirtual, HowToShowStatic, HowToShowDefaultParams)
" 1- Retrieve the context {{{
" 1.1- Get the class name,if any -- thanks to cpp_FindContextClass.vim
let className = Cpp_SearchClassDefinition(line('.'))
" 1.2- Get the whole prototype of the function (even if on several lines)
let impl = s:GetFunctionPrototype(line('.'))
" }}}
" 2- Build the result string {{{
" 2.1- XXX if you want virtual commented in the implementation:
let impl = substitute(impl, '\(\<virtual\>\)\(\s*\)',
\ (1 == a:HowToShowVirtual ? '/*\1*/\2' : ''), '')
" 2.2- XXX if you want static commented in the implementation:
let impl = substitute(impl, '\(\<static\>\)\(\s*\)',
\ (1 == a:HowToShowStatic ? '/*\1*/\2' : ''), '')
" 2.3- Handle default params, if any.
"
0 -> ignored
"
1 -> commented
"
2 -> commented, spaces trimmed
if
a:HowToShowDefaultParams == 0 | let pattern = ''
elseif a:HowToShowDefaultParams == 1 | let pattern = '/*\1*/'
elseif a:HowToShowDefaultParams == 2 | let pattern = '/*=\2*/'
else
| let pattern = ''
endif
let impl = substitute(impl, '\s*\(=\s*\([^,)]\{1,}\)\)', pattern, 'g')
" 2.4- Add '::' to the class name (if any).
if "" != className | let className = className . '::' | endif
let impl = substitute(impl, '\<\i\+\>\('."\n".'\|\s\)*(', className.'\0', '')
" 2.5- Remove the last part, ';' expected
let impl = substitute(impl, '\(\s*=\s*0\)\=\s*;\s*$', "\n{\n}", '')
" }}}
" 3- Add the string to the implementation file {{{
if exists(':AS') " from a.vim
silent AS cpp
else
let file = fnamemodify(expand('%'), ':r') . '.cpp'
silent exe ":sp ".file
endif
silent $put=impl
let nl = strlen(substitute(impl, "[^\n]", '', 'g'))
exe (line('$')-nl).',$v/^$/normal =='
" }}}
endfunction
http://www.vim.org/tips/tip.php?tip_id=335 (8 of 9) [18/02/2004 14:54:27]

Tip #335 - Copy C++ function declaration into implementation file : vim online

" }}}
let &cpo=s:cpo_save
"======================================================================
" vim60:fdm=marker
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=335 (9 of 9) [18/02/2004 14:54:27]

SourceForge
Logo

Tip #336 - type the line number and press enter to get there : vim online

not logged in (login)

Home
Search

Tip #336: type the line number and press enter to get there
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -4/25, Viewed by 1626

created: October 3, 2002 2:06


author: Odyss...

complexity: basic
as of Vim: 5.7

an easy way to to get to a line (whose number we


know) faster is to combine some existing ways that
are;
:132<ENTER>
or
123G
or
123gg
and the solution is to map in normal mode the enter to G
so with
:nmap <ENTER> G
we can type the line number and then press enter to get
there...
it's very small gain ... but it is!!!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Copy C++ function declaration into implementation file | editing remote files via scp in vim >>

Additional Notes
steveaa@icgate.net, October 3, 2002 7:42

http://www.vim.org/tips/tip.php?tip_id=336 (1 of 2) [18/02/2004 14:54:29]

Tip #336 - type the line number and press enter to get there : vim online

A corollary:
Though
:132[Enter]
takes you to line 132 in the file,
132[Enter] takes you 132 lines down from your present
position.
It's a subtle difference that can make a big
difference.
Anonymous, October 14, 2002 10:48
if u want to go 123 lines down u can use either
123 <DOWN>
either
123j
so wy have three times the same thing???
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=336 (2 of 2) [18/02/2004 14:54:29]

SourceForge
Logo

Tip #337 - editing remote files via scp in vim : vim online

not logged in (login)

Home
Search

Tip #337: editing remote files via scp in vim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 208/75, Viewed by 3068

created: October 3, 2002 12:56


author: Matthew Weier O'Phinney

complexity: intermediate
as of Vim: 6.0

VIM 6.x has the netrw plugin installed as a standard plugin. It


allows you to edit files via ftp, rcp, scp, or http. If your
username differs on the remote host, however, and you're trying
to use scp, things can get a little wierd, particularly if
you're not editing a document under your user tree.
To get around this, try opening the file as follows:
vim scp://remoteuser@server.tld//path/to/document
Notice two things: adding the "remoteuser@" syntax, and the use
of two slashes (//) between the servername and the path. The
first sets the remote user so that scp will not grab the
$USERNAME environment variable, the second will appropriately
set the absolute path.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<type the line number and press enter to get there | vim + cscope + cygwin >>

Additional Notes
nickm(at)mail.sochi.ru, October 14, 2002 13:41
Good tip!
ps RTFM ;-)
as_krishna@hotmail.com, December 24, 2002 0:25
Does the same work for FTP as well?.
When I try to do it using ftp am not able to open the
file(yes, it exists on the server!), but vim returns an error
saying 4 lines filtered and some information about not being
able to open a file in the tmp directory
TIA,
kris
tevfik, March 20, 2003 12:56
I need ftp too...

http://www.vim.org/tips/tip.php?tip_id=337 (1 of 3) [18/02/2004 14:54:31]

Tip #337 - editing remote files via scp in vim : vim online

tevfik, March 20, 2003 13:04


Hey.. this is great.. it is working for ftp.. REALLY GREAT.
cec@NgrOyphSon.gPsfAc.nMasa.gov, April 8, 2003 9:14
The latest netrw.vim, available under

http://www.erols.com/astronaut/vim/index.html#vimlinks_scripts
as "Network Oriented Reading and Writing"
has several improvements. Later Windows' ftp is handled, new
protocols
(rsync, cadaver, fetch), user fixup functions, etc.
gaita@uv.es, July 4, 2003 8:46
The tip is great. I have been looking for a way to work
remotely like this for months
(well, admittedly not looking very much, but really wanting
it!).
I just would need an extra feature which doesn't seem to work:
:E in the remote file is not able to navigate through the
remote folder.
Anyone knows if this should work?
Thanks!
tilman@ucsd.edu, July 5, 2003 11:45
I was wondering if anyone knew how to edit files remotely as
described above but manually specifying the port to be used by
scp.
I have an ssh server running on a different port and am not
sure if this is supported by vim.
Any advice?
thanks
seanahern@llnl.gov, September 2, 2003 17:44
Yes.
bit.

Change the g:netrw_scp_cmd to include a "-p ###"


That should work. (I have not tried it.)

medaveda@popmail.com, October 22, 2003 11:17


how can we store the password?? it prompts for password each
time we save!
Anonymous, November 4, 2003 10:36
I just got this working on Win2k w/ PuTTY's command line scp
program http://www.chiark.greenend.org.uk/~sgtatham/putty/
1) copy pscp.exe into your path somewhere as scp.exe
2) put "let g:netrw_cygwin= 0" in your $VIM/_vimrc
rountree@san.rr.com, January 20, 2004 9:31

http://www.vim.org/tips/tip.php?tip_id=337 (2 of 3) [18/02/2004 14:54:31]

Tip #337 - editing remote files via scp in vim : vim online

If you don't want to bother typing in passwords, have a look


at http://hacks.oreilly.com/pub/h/66 to see how to set up
public keys.
greyl0rd@yahoo.com, February 3, 2004 19:05
ftp works for me, but syntax highlighting went away?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=337 (3 of 3) [18/02/2004 14:54:31]

SourceForge
Logo

Tip #338 - vim + cscope + cygwin : vim online

not logged in (login)

Home
Search

Tip #338: vim + cscope + cygwin


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 36/14, Viewed by 2121

created: October 4, 2002 10:01


author: Vijay Sampath

complexity: intermediate
as of Vim: 5.7

Tip #292 doesn't seem to be true, at least not anymore.


I am using cscope 15.4 and vim 6.1. With a few hacks, I
was able to get cscope to work with vim under cygwin for
Windows 2000. I did not need to change the sprintf line.
The hacks included
1. Copying if_cscope.? to the src directory and the
if_cscope.pro to the src/proto directory. These files do
not come standard with the Windows source distribution
of vim. (I think it should - anybody in charge of
distribution listening?)
2. Edit if_cscope.c to make the following changes:
Add the following includes:
#include <sys/unistd.h>
#include <sys/signal.h>
3. Edit Make_cyg.mak
Add if_cscope.o to OBJ variable.
Add a rule for this at the end
$(OUTDIR)/if_cscope.o: if_cscope.c $(INCL)
$(CC) -c $(CFLAGS) if_cscope.c -o $(OUTDIR)/if_cscope.o
Uncomment the lines following
#>>>>> uncomment this block to build a GUI version
4. Edit feature.h
Force cscope compilation:
# define FEAT_CSCOPE
5. make -f Make_cyg.mak GUI=yes

http://www.vim.org/tips/tip.php?tip_id=338 (1 of 3) [18/02/2004 14:54:34]

Tip #338 - vim + cscope + cygwin : vim online

6. Note that the env variable TMPDIR should be defined


in VIM for cscope to work correctly.
That should do it. Somebody in charge of distribution
please make this standard. It would save a lot of
trouble.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<editing remote files via scp in vim | "tabbed windows" >>

Additional Notes
JavaCoder, October 4, 2002 10:57
Does anyone know if there's a cscope for Windows? I'd
surely love to use it directly under Windows (not in
Cygwin).
perd, October 6, 2002 19:23
There is cscope for windows, but the problem doesn't
lie in cscope, it lies in vim's integration with
cscope. It uses a few apis that are only available w/
cygwin.
JavaCoder, October 9, 2002 7:42
Where can I find cscope for windows?
Brian K, October 15, 2002 14:33
Another alternative is to install the XFree86 packages
that are part of the Cygwin distribution
(http://xfree86.cygwin.com/). I installed that along
with the WindowMaker window manager. I then downloaded
the vim Unix source and edited the src/Makefile. I
uncommented:
CONF_OPT_CSCOPE = --enable-cscope
and
CONF_OPT_GUI = --enable-gui=motif
I rebuilt vim and installed it to /usr/bin/vim. I can
now use cscope on Windows by running gvim (vim -g) in
WindowMaker session.

http://www.vim.org/tips/tip.php?tip_id=338 (2 of 3) [18/02/2004 14:54:34]

Tip #338 - vim + cscope + cygwin : vim online

Anonymous, October 25, 2002 15:00


Brian's way is actually even better.
Anonymous, November 1, 2002 8:37
There's a windows version of cscope here:
http://www.geocities.com/shankara_c/cscope.html
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=338 (3 of 3) [18/02/2004 14:54:34]

SourceForge
Logo

Tip #339 - "tabbed windows" : vim online

not logged in (login)

Home
Search

Tip #339: "tabbed windows"


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 27/13, Viewed by 3189

created: October 8, 2002 15:37


author: barrett@9hells.org

complexity: basic
as of Vim: 5.7

This is what I use to emulate the multi-tab environment


of certain editors like EditPlus, and easly switch
between multiple files being edited (opened with the
:split command):
" put this in your .vimrc file to rotate windows with
Alt-K / Alt-J
set winminheight=0
nmap <M-k> <C-W>r<C-W>k:resize<CR>
nmap <M-j> <C-W>j<C-W>R:resize<CR>
imap <M-k> <ESC><M-k>i
imap <M-j> <ESC><M-j>i
" end
The only problem is that after a :split you have to AltK-J to keep the new window "maximized".
rate this tip

Life Changing

Helpful

<<vim + cscope + cygwin | Visual Select And Search >>

Additional Notes
interfac@hotmail.com, October 9, 2002 0:59

http://www.vim.org/tips/tip.php?tip_id=339 (1 of 3) [18/02/2004 14:54:36]

Unfulfilling

rate

Tip #339 - "tabbed windows" : vim online

well, another way is to bind a key for switch between


opened buffers:
""with F5 go to the previous buffer
map <F5> :bp!<CR>
imap <F5> <esc>:bp!<CR>
and you can also bind another key for close the current
buffer..
map <C-F5> :bw<CR>
imap <C-F5> <esc>:bw<CR>
so with F5 and C-F5 you have all the movement you want
between buffers ;)
barrett@9hells.org, October 9, 2002 15:09
good.
the difference is that with :split you can see the name
of the files opened, but otoh you loose one line of
screen space for each file..
Sreny@SverGbc.Pbz (Rot13ed), November 4, 2002 21:22
For what it is worth, I've been using a variant of this
which works quite nicely I think.
This simple reduces other split windows to their
statusbar thingie while keeping their position.. A
little easier to keep track of what window is what
while still using this methodology, I think.
" [Feral:288/02@02:21] Based on VIM-Tip #339
set winminheight=0
nnoremap <M-k> <C-W>k:resize<CR>
nnoremap <M-j> <C-W>j:resize<CR>
Thank you for the tip, I was ignorant of :resize :)
Happy VIMing
ss@aao.gov.au, October 28, 2003 19:15
There exists a generic tabbing module for the FVWM
window manager
which can allow (amongst other things) tabbed Vim
editors.
See:
http://users.tpg.com.au/users/scottie7/fvwmtabs.html

http://www.vim.org/tips/tip.php?tip_id=339 (2 of 3) [18/02/2004 14:54:36]

Tip #339 - "tabbed windows" : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=339 (3 of 3) [18/02/2004 14:54:36]

SourceForge
Logo

Tip #340 - Visual Select And Search : vim online

not logged in (login)

Home
Search

Tip #340: Visual Select And Search


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 13/4, Viewed by 1204

created: October 10, 2002 18:59


author: Chris Butler (cz_butler@yahoo.com)

complexity: intermediate
as of Vim: 6.0

The following visual select and search map is a


combination of information
from Benji's vimrc file (vmap S y/<CR>=escape(@",'/')<CR>) and a tip that
mentions the "\n" to "\\\\n" substitution.
It works for special characters and multiple lines.
vmap \s y/\V<CR>=substitute(escape(@",'/'),"\n","\\\\n","g")<CR>/<CR>
Quick explanation:
vmap
\s
y
/
\V
<C-R>=
substitute
escape
(@")
<CR>
/<CR>

visual map
your choice
yank selected text
search delimiter
no magic, just text
expression
substitute "\n" for "\\\\n"
escape '/' (delimiter) and '' in yanked text
end expression
search

Warning: Folding will not match if the foldexpr


expression is using
getline() to match against a search pattern that spans
multiple lines.
Enjoy.
rate this tip

Life Changing

<<"tabbed windows" | switch color schemes >>

http://www.vim.org/tips/tip.php?tip_id=340 (1 of 3) [18/02/2004 14:54:38]

Helpful

Unfulfilling

rate

Tip #340 - Visual Select And Search : vim online

Additional Notes
Chris Butler, October 11, 2002 14:23
Sorry, something was lost when I pasted it (besides the
line format :)
The substitute string is '/' - that's forward slash +
backward slash.
One needs to escape any '' (backslash) to nulify any
specials.
Chris Butler, October 11, 2002 14:25
Let try that again ...
Sorry, something was lost when I pasted it (besides the
line format :)
The substitute string is '/\' - that's forward slash +
backward slash.
One needs to escape any '\' (backslash) to nulify any
specials.
David Fishburn, June 4, 2003 5:51
I have this in my vimrc file.
It will deal with correctly escaping the string you
have visually selected.
This was hashed out on the vim mailing list a few
months back, and this is the final version.
It also maintains the register we pull the text into.
" Courtesy of Michael Naumann, Jrgen Krmer
" Visually select text, then search for it, forwards or
backwards
vmap <silent> * :<C-U>let old_reg=@"<cr>
\gvy/<C-R><C-R>=substitute(
\escape(@", '\\/.*$^~[]'), "\n$", "",
"")<CR><CR>
\:let @"=old_reg<cr>
vmap <silent> # :<C-U>let old_reg=@"<cr>
\gvy?<C-R><C-R>=substitute(
\escape(@", '\\/.*$^~[]'), "\n$", "",
"")<CR><CR>
\:let @"=old_reg<cr>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=340 (2 of 3) [18/02/2004 14:54:38]

SourceForge
Logo

Tip #340 - Visual Select And Search : vim online

http://www.vim.org/tips/tip.php?tip_id=340 (3 of 3) [18/02/2004 14:54:38]

Tip #341 - switch color schemes : vim online

not logged in (login)

Home
Search

Tip #341: switch color schemes


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 10/4, Viewed by 2265

created: October 11, 2002 12:46


author: andreas berg

complexity: intermediate
as of Vim: 6.0

This function is similar to the vimtip #211. I did not


recognize that s.o.
already wrote a function for that, but this one has one
advantage:
It just takes all possible colorschemes in the given
directorys and rotates
them. Just put the following code in your .vimrc file:

Site Help

let SwitchSchemesFiles =
globpath("$VIMRUNTIME,$HOME/.vim","colors/*.vim")
let SwitchSchemesIndex = 0
function! SwitchSchemes()
let sep="\n"
if g:SwitchSchemesIndex == -1
let g:SwitchSchemesIndex=0
endif
exe "source " .
NextElement(g:SwitchSchemesFiles, sep,
g:SwitchSchemesIndex)
let g:SwitchSchemesIndex =
NextIndex(g:SwitchSchemesFiles, sep,
g:SwitchSchemesIndex + 1)
endfunction
In addition you need the
http://www.vim.org/script.php?script_id=109
Put it in the plugin directory.
If you use e.g. a map to F12, you can easily switch
between all
installed themes:
map <f12> :call SwitchSchemes()<CR>

http://www.vim.org/tips/tip.php?tip_id=341 (1 of 2) [18/02/2004 14:54:40]

Tip #341 - switch color schemes : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Visual Select And Search | Remap <ESC> >>

Additional Notes
Anonymous, April 25, 2003 4:52
It might also be useful to output the name of the color
scheme after changing it, something like this:
nmap <C-F12> :call SwitchSchemes()<CR>:echo
g:colors_name<CR>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=341 (2 of 2) [18/02/2004 14:54:40]

SourceForge
Logo

Tip #342 - Remap <ESC> : vim online

not logged in (login)

Home
Search

Tip #342: Remap <ESC>


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 22/15, Viewed by 1830

created: October 11, 2002 13:54


author: mrts

complexity: intermediate
as of Vim: 6.0

Tired of hunting down <ESC> at upper-left of your


keyboard while using a keyboard with useless Windows
keys?
Well, remap them -xmodmap config file
You may have to use
~/.xinitrc in *BSD

use xmodmap. I'm using Debian and my


is in /etc/X11/xinit/xmodmap, ymmv.
xmodmap directly (from
or whatever).

Anyway, here's my xmodmap:


[ .. other irrelevant mappings skipped ... ]
keycode 115 = braceleft
keycode 116 = Escape
keycode 117 = braceright
Btw, the keys are:
* 115 - Windows key, between the left-hand Ctrl and
Alt keys
* 116 - Windows key, to the right of the AltGr key
* 117 - Menu key, to the left of the right-hand Ctrl
key
Valid for all environments with X, on *BSD as well as on
Linux.
You get the same mappings under ordinary console by
modifying the console keymap file (pretty selfexplanatory), in my case it's
/usr/share/keymaps/i386/qwerty/et.kmap.gz.
I'm using mapping braces to winkeys because of my
Estonian keyboard.
rate this tip

Life Changing

Helpful

<<switch color schemes | Faster loading of large files >>

http://www.vim.org/tips/tip.php?tip_id=342 (1 of 3) [18/02/2004 14:54:46]

Unfulfilling

rate

Tip #342 - Remap <ESC> : vim online

Additional Notes
Anonymous, October 12, 2002 11:58
I have remapped Caps Lock to Esc. Who use Caps Lock any
way?
Anonymous, October 12, 2002 15:00
I think users with german, slavic (and probably some
other) keyboards will have better things to do with the
windows key - because we need additional keys for
"umlauts" like etc. or other language-specific
letters, some of the important signs, namely {[]}\ are
the "third-function" of number keys 7 and above. You
have to type those with the right hand, while
simultaneously pressing "Alt Ctr" located right of the
spacebar which at least I never learned to do properly,
you can't do that without changing the position of the
hand, and I keep hitting the wrong key. I've been
raging about this stupid mapping for a long time
without it ever occurring to me that there's a free key
you could map to Alt Ctr and use it with your left
hand. So I guess not only the mapping is stupid.
Cheers
Horror Vacui
Anonymous, October 12, 2002 19:09
I don't understand the term "useless", if XFree86 is
configured correctly for a 104 key PC keyboard, the
penguin keys are mapped to Meta_L and Meta_R and the
Menu key is mapped to Menu. No need to use xmodmap.
Anonymous, October 13, 2002 8:11
Doh... useless for a vim user...
mrts, October 14, 2002 2:38
Horror Vacui:
why don't you map
* left winkey -> {
* shift+left winkey -> [
* right winkey -> <ESC>
* right winmenu -> }
* shift+right winmenu ]
Solves all my problems :)
mrts

http://www.vim.org/tips/tip.php?tip_id=342 (2 of 3) [18/02/2004 14:54:46]

Tip #342 - Remap <ESC> : vim online

Anonymous, October 14, 2002 11:51


Ctrl+[ is already mapped to escape...
frew@myrealbox.com, October 15, 2002 14:52
Arg, I am stuck on a windows box at school and even
though it is nice that I can use vim, I cannot use
xmodmap...:-/
frew@myrealbox.com, October 15, 2002 14:52
Arg, I am stuck on a windows box at school and even
though it is nice that I can use vim, I cannot use
xmodmap...:-/
remapESCkey@isForBitches, October 16, 2002 23:50
hmm, ESC key is in the wrong place, eh? . . . hah
hahhah hah hah!!
daniel@brot.t0c.de, October 18, 2002 5:30
is there a way to remap capslock for the console, too?
(talking about linux)
im not using xfree very often.. indeed perhaps
10minutes/day for surfing.
and btw: ^c is mapped to esc, too. Im using only ^c,
but caps would
be even faster.
thanks, Daniel
dan@mojavelinux.com, October 23, 2002 17:22
The answer to this last question is YES, if you are
using KDE3...just go into the control panel under
keyboard and choose to make the CapsLock another
control key. then you can use capslock-[ the way it
was originally intended to be used in VIM (because
stupid Microsoft put the capslock where the control key
existed to help little ol' ladies to data entry on a
windows box) and it is fluid as hell. Forget you ever
knew escape.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=342 (3 of 3) [18/02/2004 14:54:46]

SourceForge
Logo

Tip #343 - Faster loading of large files : vim online

not logged in (login)

Home
Search

Tip #343: Faster loading of large files


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 36/19, Viewed by 2076

created: October 12, 2002 11:32


author: Erik Remmelzwaal

complexity: intermediate
as of Vim: 6.0

In the past I experienced long loading times for large


files ( size > 10MB )
These files are normally generated by SQL tracing, XML
message based
protocols tracing etc.
One of the causes of long loading times was syntax
parsing, creating swap file etc.
Normally one want to view these files and remove not
relevant details by
deleting lines, but do not want to have undo
capabilities and auto recalculation of
syntax highlighting.
The code below, I put in my _vimrc to switch off a
number of defaults for
large files.
One can modify the g:LargeFile variable and reload a
file to test:
:let g:LargeFile=10
:e
It would be interesting to know if others have more or
better suggestions.
" Protect large files from sourcing and other overhead.
" Files become read only
if !exists("my_auto_commands_loaded")
let my_auto_commands_loaded = 1
" Large files are > 10M
" Set options:
"
eventignore+=FileType (no syntax
highlighting etc
"
assumes FileType always on)
"
noswapfile (save copy of file)
"
bufhidden=unload (save memory when other
file is viewed)
"
buftype=nowritefile (is read-only)

http://www.vim.org/tips/tip.php?tip_id=343 (1 of 2) [18/02/2004 14:54:48]

Tip #343 - Faster loading of large files : vim online

"
undolevels=-1 (no undo possible)
let g:LargeFile = 1024 * 1024 * 10
augroup LargeFile
autocmd BufReadPre * let
f=expand("<afile>") | if getfsize(f) > g:LargeFile | set
eventignore+=FileType | setlocal noswapfile
bufhidden=unload buftype=nowrite undolevels=-1 | else |
set eventignore-=FileType | endif
augroup END
endif
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Remap <ESC> | Cut / Copy / Delete / Paste Lines without knowing the number of lines >>

Additional Notes
maxiangjiang@yahoo.com, October 13, 2002 18:50
Can we just set scratch buffer for such purpose?
help special-buffers
Yakov, July 22, 2003 6:15
File will load faster if you open it read-only: vim -R
HugeFile.txt
BigUser, December 15, 2003 17:24
Try to open a 2 Gig text file. It takes to long and
uses all my systems memory.
Looking for a solution.....
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=343 (2 of 2) [18/02/2004 14:54:48]

SourceForge
Logo

Tip #344 - Cut / Copy / Delete / Paste Lines without knowing the number of lines : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #344: Cut / Copy / Delete / Paste Lines without knowing the
number of lines
tip karma

Rating 80/38, Viewed by 2905

created: October 15, 2002 11:57


author: Kdr

complexity: basic
as of Vim: 5.7

If you ever need to cut / copy / delete / paste lines


without knowing the actual number of lines, here is what
you should do.
1. In the command Mode, Go to the beginning of the first
mark (lets say line 50).
2. Type: mk
3. Go to the end of your selection (lets say 100), using
j's or Ctrl -F or anything. You don't need to count the
lines.
4. Type: "ay'k (i.e. Double Quotes, <reg name from a-z>,
<y-yank or d-delete>, single quote, k
5. The above command copies those lines into register a.
6. If you do "ad'k , it will delete them from the
current location and copies them into register a.
7. You can paste those lines wherever you want just as
you print from registers, i.e. "ap
I use this a lot, since I don't need to count the number
of lines.
-Kdr
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Faster loading of large files | Visual Studio + vim Quickfix mode + cygwin + XFree86 >>

Additional Notes
tunacat@yahoo.com, October 15, 2002 18:13
Be sure to check out visual mode. V will allow to
select a range of lines, which you can then "ay, etc.
This is one of the coolest features of vim.

http://www.vim.org/tips/tip.php?tip_id=344 (1 of 3) [18/02/2004 14:54:51]

Tip #344 - Cut / Copy / Delete / Paste Lines without knowing the number of lines : vim online

Feral@firetop.dontspamme.com, October 15, 2002 19:33


A related thought:
I like to think of " as into and ' as till.
So, something like "ay'k can be thought of as "into a
yank till k"
ramming@web.de, October 15, 2002 23:24
I normally don't count the lines, but use a range using
line numbers like ".,100y"
('.' means line number at cursorpos). The range can be
relative (".,+5"), of course you know the number of
lines then.
So I don't have to move the cursor around just for
yanking and put it again to the position whre I want to
drop the lines.
Visual marking with the mouse is a powerful
alternative, because you don' have to copy/delete
complete lines.
You also can visually mark rectangle blocks of text by
pressing <CTRL-V> in visual mode.
Remember: VIM automatically copies the visually marked
text, so you can simply drop it by clicking the middle
mouse button
at cursor position without using named registers.
Anonymous, October 17, 2002 6:02
Vim doesn't automatically copy the selected text unless
'clipboard' and 'guioptions' settings have specific
values. (I believe they are autoselect and a,
respectively.)
Anonymous, October 22, 2002 3:17
:h guioptions
only 'a' needs to be added. my 'guioptions=gmrLtTa',
clipboard is empty.
Anonymous, October 23, 2002 1:24
Other good way is use / to find the place to which
delete/copy, e.g., d/This sentence should be left<CR>.
For smaller deletes, dt<letter> and df<letter> are also
useful.
sjspam at geeky point net, December 21, 2002 22:27

http://www.vim.org/tips/tip.php?tip_id=344 (2 of 3) [18/02/2004 14:54:51]

Tip #344 - Cut / Copy / Delete / Paste Lines without knowing the number of lines : vim online

An easier-to-remember way:
Forget about registers.
Go to desired start line,
hit
ma ("mark this line as 'a'"), then go to desired
end line, and hit
y'a or d'a ("yank or delete to
the line marked 'a'"). Paste using p.
A character-level way: (not line-level)
Go to desired start character, hit
ma (same as
above), then go to desired end character (can be in a
different line), and hit
y`a or d`a (notice that
it's the "tick", not the "apostrophe"). Paste using p.
lylez@kc.rr.com, January 21, 2003 21:31
If you need to select a series of consecutive lines,
type V}
Lyle
Anonymous, January 20, 2004 6:50
I don't get it. Why would I use this incredibly
convoluted method instead of just using visual mode?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=344 (3 of 3) [18/02/2004 14:54:51]

SourceForge
Logo

Tip #345 - Visual Studio + vim Quickfix mode + cygwin + XFree86 : vim online

not logged in (login)

Tip #345: Visual Studio + vim Quickfix mode + cygwin + XFree86

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/1, Viewed by 2941

created: October 15, 2002 15:13


author: Brian K

complexity: basic
as of Vim: 5.7

I run gvim inside a cygwin XFree86 session running


WindowMaker. Because I'm inside cygwin-XFree86, I can't
use the useful VisVim plugin to step through Visual
Studio compiler errors. To work around this limitation,
I wrote a Bash/Perl script that munges nmake output into
something that has cygwin compliant path and is
parseable by the default quickfix errorformat setting .
Here's what to do:
1.

install the following from cygwin:

- perl
- cygutils
- bash
2. Set up Visual Studio to support command line
compiles.
Basically this involves adding paths to the
PATH, INCLUDE, and LIB environment variables. See
vcvars32.bat in the Visual Studio VC98/bin directory for
guidelines.
3. Export a makefile for your dsp project file via the
Visual Studio "Project|Export Makefile..."
4. Create the cygwin shell script defined below.
the script in '/bin/dovcmake'
---begin cut----#!/bin/bash
# This script takes output from
# Visual Studio's nmake and reformats
# it so that it can be parsed by
# cygwin's vim default errorformat
# setting
nmake /F $1 2>&1 | perl -n -e \
' chomp;

http://www.vim.org/tips/tip.php?tip_id=345 (1 of 3) [18/02/2004 14:54:53]

Put

Tip #345 - Visual Studio + vim Quickfix mode + cygwin + XFree86 : vim online

if(/^([a-z]:[^(]+)\((\d+)\)(.+)$/i) {
$f = $1; $l = $2; $m = $3;
$f =~ s/\\/\//g;
$cyp = `cygpath -au $f`; \
chomp $cyp;
print qq{"$cyp",$l:$m\n};}
elsif(/error/i) {
print qq{$_\n};
}'
---end cut ----5.

Add this map to your vimrc:

set makeprg=/bin/dovcmake
map <f7> :make <c-r>%<cr>
6. Fire up cygwin vim and open the makefile from step
3. If you hit F7, you'll automatically start a Visual
Studio build and you'll be able to step through compiler
errors via the :cp and :cn commands.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Cut / Copy / Delete / Paste Lines without knowing the number of lines | Wrap text in HTML/XML
tags after prompting for the tag name >>

Additional Notes
Anonymous, October 16, 2002 1:09
You should look at the errorformat variable. This may
solve your problem without perl.
Brian K, October 16, 2002 13:47
I needed to use perl because I needed to convert
windows paths from nmake's output to cygwin
paths. Otherwise I would have used errorformat
Anonymous, December 2, 2002 6:54
You could use Cygwin's cygpath to translate between
Cygwin (posix) and windows paths instead of Perl.
Brian K, December 3, 2002 11:21

http://www.vim.org/tips/tip.php?tip_id=345 (2 of 3) [18/02/2004 14:54:53]

Tip #345 - Visual Studio + vim Quickfix mode + cygwin + XFree86 : vim online

I am using cygpath within the perl script to translate


the paths, but the perl script does more that just
translate paths. It also filters extraneous nmake
output , such as the MS copyright info that nmake
generates.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=345 (3 of 3) [18/02/2004 14:54:53]

SourceForge
Logo

Tip #346 - Wrap text in HTML/XML tags after prompting for the tag name : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #346: Wrap text in HTML/XML tags after prompting for the tag
name
tip karma

Rating 21/12, Viewed by 1881

created: October 16, 2002 8:33


author: fishburn@sybase.com

complexity: basic
as of Vim: 6.0

Someone else posted this sometime ago on this mailing


list, I have enhanced it slightly and made a tip out of
it.
I thought it was pretty clever and very generic.
If you have a block of text and you want to wrap it in
<TAG_NAME>...</TAG_NAME> then this function will prompt
you for the tag name and wrap the text.
If there is no text VISUALLY selected, it will wrap the
current word in the tag, otherwise it will wrap the
visually selected text.
It will also strip off any leading spaces.
For the end tag, it will use the first word of the tag
only.
Consider an ANT build file, which has tags like this:
<target name="init">
...
</target>
When prompted for the tag you would enter:
target name="init"
And it will wrap the text in:
<target name="init">
...
</target>
" Tag Select/Wrapper
" These mappings and TagSelection function will allow
you to place " an XML tag around either the current
word, or the current selected " text
nmap <Leader>t viw<Leader>t
vnoremap <Leader>t <Esc>:call TagSelection()<CR>

http://www.vim.org/tips/tip.php?tip_id=346 (1 of 3) [18/02/2004 14:54:56]

Tip #346 - Wrap text in HTML/XML tags after prompting for the tag name : vim online

nmap <Leader>t viw<Leader>t


vnoremap <Leader>t <Esc>:call TagSelection()<CR>
function! TagSelection()
let l:tag = input("Tag name? ")
" exec "normal `>a</" . l:tag . ">\e"
" Strip off all but the first work in the tag for the
end tag
exec "normal `>a</" .
\ substitute( l:tag, '[
\t"]*\(\<\w*\>\).*', '\1>\e', "" )
exec "normal `<i"
\ substitute( l:tag, '[ \t"]*\(\<.*\)',
'<\1>\e', "" )
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Visual Studio + vim Quickfix mode + cygwin + XFree86 | Format paragraph without changing the
cursor position >>

Additional Notes
wl1012@excite.com, February 18, 2003 9:50
With XML namespace that contains a ":", the first
substitute doesn't really work as desired. It may be
changed to the following (note using the \S instead of
a \w):
function! TagSelection()
let l:tag = input("Tag name?")
" exec "normal `>a</" . l:tag . ">\e"
" Strip off all but the first work in the tag for the
end tag
exec "normal `>a</" .
\ substitute( l:tag, '[
\t"]*\(\<\S*\>\).*', '\1>\e', "" )
exec "normal `<i"
\ substitute( l:tag, '[ \t"]*\(\<.*\)',
'<\1>\e', "" )
endfunction
Add Note

http://www.vim.org/tips/tip.php?tip_id=346 (2 of 3) [18/02/2004 14:54:56]

Tip #346 - Wrap text in HTML/XML tags after prompting for the tag name : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=346 (3 of 3) [18/02/2004 14:54:56]

SourceForge
Logo

Tip #347 - Format paragraph without changing the cursor position : vim online

not logged in (login)

Home
Search

Tip #347: Format paragraph without changing the cursor position


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/9, Viewed by 1325

created: October 18, 2002 21:02


author: Kartik Agaram

complexity: intermediate
as of Vim: 6.0

map <silent> <C-j> :let line=line(".")<CR>:let


col=col(".")<CR>gqap:exec ":".line<CR>:exec "normal " .
col . "\|"<CR>
imap <silent> <C-j> <Esc>:let line=line(".")<CR>:let
col=col(".")<CR>gqap:exec ":".line<CR>:exec "normal " .
col . "\|"<CR>a
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Wrap text in HTML/XML tags after prompting for the tag name | Quickly insert a single word >>

Additional Notes
Anonymous, October 23, 2002 1:20
Why not simply use <C-O> after gq command?
Kartik, October 23, 2002 17:52
Hmm... let me try to describe a case. Let's say you
open a text file and start inserting text somewhere in
between without ever adding to the jump list (just
arrow keys, '{}'). Now typing <Esc> gqap <C-o> doesn't
restore cursor position. At least for me.
Anonymous, October 24, 2002 6:33
Ok, mea culpa - I always used gq}, and it worked. The
gqap is different.
ds26@gte.com (Dorai Sitaram), March 13, 2003 11:47

http://www.vim.org/tips/tip.php?tip_id=347 (1 of 2) [18/02/2004 14:54:58]

Tip #347 - Format paragraph without changing the cursor position : vim online

It may be more desirable to preserve the cursor's


logical position (i.e., which word it
is currently on), rather than its line/col position.
The following nmap does this by inserting a small and
unusual bogus text at the current
cursor position; formatting the paragraph; using search
to get to the bogus word;
and then deleting it.
nmap gb i<zqfm><esc>gqip?<zqfm><cr>df>
Kartik, October 23, 2003 19:07
Absolutely outstanding. Thanks, Dorai!
thomas@schuerger.com, November 23, 2003 12:56
Is there a way to make "gqap" use filling spaces to
have
block alignment instead of left alignment in the lines?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=347 (2 of 2) [18/02/2004 14:54:58]

SourceForge
Logo

Tip #348 - Quickly insert a single word : vim online

not logged in (login)

Home
Search

Tip #348: Quickly insert a single word


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/7, Viewed by 1691

created: October 19, 2002 15:43


author: spudnic

complexity: basic
as of Vim: 5.7

I've had something like this for a single character for


some time, and this may be something that everyone is
already doing, but it's really convenient for me. These
two mappings make it quick and easy to insert a word.
nmap <buffer> <silent> ,w :exec ":imap \<space\>
\<space\>\<esc\>,BB"<cr>i
nmap <buffer> <silent> ,BB :exec ":iunmap \<space\>"<cr>
Given the sentence:
The quick fox.
To add the word "brown" you would put your curser on the
f in fox and type ",w" (or whatever you decide is a good
mapping). Type the word brown. As soon as you hit
space you are out of insert mode.
If there's an easier way to do this, please feel free to
comment.
Thanks.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Format paragraph without changing the cursor position | Format your xml document using xmllint >>

Additional Notes
mark@summersault.com, October 23, 2002 8:33
Unless I missed something, this doesn't save any
keystrokes. Without, I would use two keystrokes "i" to
enter insert mode and ESC to exit. Here I still would
still need two keystokes "," and "w".

http://www.vim.org/tips/tip.php?tip_id=348 (1 of 2) [18/02/2004 14:55:00]

Tip #348 - Quickly insert a single word : vim online

Anonymous, October 23, 2002 11:21


Size isn't everything! This seems easier. Finding the
ESC is harder than , . and with this you're
entering ,w together rather than a key before your word
and another key at the end. So you start this with 2
characters, but it ends itself automatically, which
seems easier and more fluid to me.
schoon@home.se, October 30, 2002 1:50
I am no vim wizard, so this might be offensively
ridiculous. Anyway, having used
"standard" vi for a number of years before stumbling on
vim, I have mapped my
arrow keys so that I leave insert mode as soon as I try
to move anywhere with
them. I simply found it annoying to remain in insert
mode after "being done" at
one place. The effect of this mapping on the problem
described is that after having
added a word or two in insert mode, I rarely have to
think about actively exiting
insert mode. That is taken care of by the arrow key
mappings. I have to admit
that I cannot recall exactly what I do, or rather, how
painful I find it, to punch that
escape key in the cases I plan to move away from the
spot where the word was
inserted in greater strides than with arrow keys.
timothy@voidnet.com, January 17, 2003 22:06
ctrl+[ is equivalent to escape, beats reaching that
hand way up to that escape key..priceless tip I found
in another tip thread =)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=348 (2 of 2) [18/02/2004 14:55:00]

SourceForge
Logo

Tip #349 - Format your xml document using xmllint : vim online

not logged in (login)

Home
Search

Tip #349: Format your xml document using xmllint


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 32/14, Viewed by 1801

created: October 23, 2002 17:18


author: Daniel Allen

complexity: basic
as of Vim: 6.0

If you open an xml document that is either totally or partially


unindented, you can use the GNU libxml2 libary's xmllint to
reformat and align your document. This is especially good if
you want to save your xml documents using as little space as
possible (which would be totally unindented). Just add this
under the autocmd section of your .vimrc file
au FileType xml exe ":silent 1,$!xmllint --format --recover 2>/dev/null"
This instructs vim to take the entire contents of a *.xml file
and pass it through xmllint, using the --format and --recover
flags and silencing any errors that may occur. This is
generally a very effective process and will only mess up on
very poorly typed (a large amout of incorrect syntax) xml
documents. Please note that xmllint only adds and removes
structural space. It does not remove space from regular text
nodes (as doing so would be incorrect).
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Quickly insert a single word | when 'formatoptions' has o easily enter a non commented line: go/gO mappings >>

Additional Notes
Anonymous, October 24, 2002 14:11
will this work in win2k version of gvim?
maxiangjiang@homail.com, October 29, 2002 16:59
How can make it as a filter?
I tried sth like
let&l:equalprg='xmllint --format --recover'
but it didn't work since xmllint doesn't take STDIN?
any idea?
dean at mndsolutions dot de, November 8, 2002 9:47
http://www.vim.org/tips/tip.php?tip_id=349 (1 of 4) [18/02/2004 14:55:02]

Tip #349 - Format your xml document using xmllint : vim online

notice the '-' given as the file argument to xmllint. This


usually means stdin.
dan@mojavelinux.com, November 14, 2002 13:13
Yes, xmllint can read from stdin, please note the '-' that
occurs at the end of the options. This tells it to dump the
file contents to the stdin pipe for xmllint. As far as I
know, xmllint can be run in windows if you have gcc, but I am
just projecting...look into it. If not, I am sure you can
find something to take its place...the tip is just that, a
tip, build on it.
tobiasreif pinkjuice com, December 20, 2002 12:39
Regarding the filter question:
Start playing with
" one or more lines:
vmap ,px !xmllint --format -<CR>
" pretty-print current line
nmap ,px !!xmllint --format -<CR>
Question:
How to send s.th. like }?
(as with >})
... so that no visial selection is necessary.
Tobi
ggodfrey@io.com, January 11, 2003 11:55
"xmllint --format" indents comment lines to 0 which screws up
the formatting for vim. A simple fix for single line comments
can be made in indent/xml.vim. Copy indent/xml.vim to
~/.vim/xml.vim (Unix systems) and change the line that says:
let lnum = prevnonblank(a:lnum - 1)
To this:
let lnum = a:lnum
while lnum > 0
let lnum = prevnonblank(lnum - 1)
let line = getline(lnum)
if strpart(line, 0, 4) != "<!--"
break
endif
endwhile
Gary Godfrey
Austin, TX USA
johngraves03@comcast.net, January 14, 2003 12:12

http://www.vim.org/tips/tip.php?tip_id=349 (2 of 4) [18/02/2004 14:55:02]

Tip #349 - Format your xml document using xmllint : vim online

Nobody answered the previous question, as I am also curious,


how does one make this work in the win32 version of vim?
Anonymous, January 21, 2003 11:30
This might be helpful to you in making xmllint work with gvim
under Windows,
http://www.pinkjuice.com/vim/vimrc.txt
Klaus Horsten, June 14, 2003 11:05
Windows:
GNU libxml2 libary's xmllint.exe is buggy.
(See http://gnuwin32.sourceforge.net/packages.html)
Nothing happens. The input is the same as the output.
It does not work on windows, because the xmllint.exe is
unusable (at least in this respect).
This is true for June 2003.
The syntax in vim would be easy:
Go into the xml-file and type:
:! xmllint.exe --format %
--Klaus
foo@foo.com, July 21, 2003 15:18
Klaus Horsten wrote:
> It does not work on windows, because the xmllint.exe
> is unusable (at least in this respect)."
Try
http://www.zlatkovic.com/projects/libxml/
http://www.zlatkovic.com/projects/libxml/binaries.html .
Currently the latest version is
http://www.zlatkovic.com/projects/libxml/libxml22.5.8.win32.zip .
> The syntax in vim would be easy:
>
> Go into the xml-file and type:
> :! xmllint.exe --format %
This would do nothing by itself AFAICS.
Check
http://www.pinkjuice.com/howto/vimxml/setup.xml#xmllint ,
http://www.pinkjuice.com/howto/vimxml/tasks.xml#prettyprinting
and
http://www.vim.org/tips/tip.php?tip_id=349 (3 of 4) [18/02/2004 14:55:02]

Tip #349 - Format your xml document using xmllint : vim online

http://www.pinkjuice.com/howto/vimxml/tasks.xml#validation
Tobi

dsewell@virginia.edu, August 4, 2003 14:35


One problem with "xmllint --format" is that it turns non-ASCII
UTF-8 characters into numeric references. This isn't a problem
if you're taking the input of xmllint and editing it with an
XML editor that internally converts everything to UTF-8 (like
XMetal), but if what you want to do is use Vim to edit the
file as a native UTF-8 (with :set encoding=utf8), then you
*don't* want a bunch of numeric references instead of Unicode.
The xmllint developer knows about this issue but feels that
adding an option to keep/not keep UTF-8 would complicate the
code too much. So... is there another XML reformatter more
suitable for producing output that Vim can use?
tobiasreif pinkjuice com, August 21, 2003 14:30
Hi,
try
http://www.pinkjuice.com/howto/vimxml/tasks.xml#prettyprinting
HTH,
Tobi
tobiasreif pinkjuice com, August 24, 2003 7:37
I will change the solution described at the above URL since
there is a very simple solution to the problem:
http://mail.gnome.org/archives/xml/2003-August/msg00017.html
http://mail.gnome.org/archives/xml/2003-August/msg00018.html
:%!xmllint --format --encode UTF-8 Tobi
heyspearsy@yahoo.ca, September 16, 2003 7:57
Any ideas on how to use xmllint, but change the tab/indent
width? It seems to filter, on windows, with 2 spaces for a
tab.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=349 (4 of 4) [18/02/2004 14:55:02]

SourceForge
Logo

Tip #350 - when 'formatoptions' has o easily enter a non commented line: go/gO mappings : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #350: when 'formatoptions' has o easily enter a non commented


line: go/gO mappings
tip karma

Rating 1/3, Viewed by 542

created: October 24, 2002 2:13


author: Feral of firetop dot com

complexity: basic
as of Vim: 5.7

This is relevant when your 'formatoptions' has o.


From :h fo-table, "Automatically insert the current
comment leader after hitting 'o' or 'O' in Normal mode."
I like this behavior enough to keep the o option,
however at times I want to NOT insert the comment chars,
and although manually deleting the added chars is not
hard I present these simple mappings that delete the
added chars automatically.
(from my .vimrc)
nnoremap go o<esc>S
nnoremap gO O<esc>S
This makes go open a new line under the cursor and
removes inserted chars, while gO opens a new line above
the cursor and removes inserted chars.
Your mileage will vary of course (:
Happy VIMing!
rate this tip

Life Changing

Helpful

Unfulfilling

<<Format your xml document using xmllint | Using quickfix in a different way >>

Additional Notes
Feral <Sreny@SverGbc.Pbz> (Rot13ed), June 1, 2003 3:35

http://www.vim.org/tips/tip.php?tip_id=350 (1 of 2) [18/02/2004 14:55:04]

rate

Tip #350 - when 'formatoptions' has o easily enter a non commented line: go/gO mappings : vim online

It should be noted that the go mapping presented above


will interfere with VIM's default go (Go to {count}
byte in the buffer; :h go) command.
There should be a much more elegant way of achieving
the same effect, but I am currently unaware of what it
might be.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=350 (2 of 2) [18/02/2004 14:55:04]

SourceForge
Logo

Tip #351 - Using quickfix in a different way : vim online

not logged in (login)

Home
Search

Tip #351: Using quickfix in a different way


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 37/19, Viewed by 1234

created: October 24, 2002 6:11


author: Karthick Gururaj

complexity: intermediate
as of Vim: 6.0

I'm a software developer and I find vim's quickfix


(:help quickfix) very helpful.
You can also use this while debugging your code, in a
slightly different way...
Usually, you will have some print messages in your code,
and after the program
runs, you'll look at the output to see the execution
trace (e.g which if-constructs
were taken, how many times did a while loop iterate.. ).
If you precede these
statements with a <filename>:<linenumber>, then, the
program output can be parsed
with a :cfile, and the execution trace becomes very
simple.
For instance, in C++
// fdebug is the pointer to the debug file called,
debug.txt say.
#define DEBUG_MESG( ) fprintf(fdebug, "%0s:%0d\n",
__FILE__, __LINE__)
...
function( )
{
...
if (something)
DEBUG_MESG( );
else
DEBUG_MESG( );
...
}
Open your code in vim and do a ":cfile debug.txt"

http://www.vim.org/tips/tip.php?tip_id=351 (1 of 3) [18/02/2004 14:55:07]

Tip #351 - Using quickfix in a different way : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<when 'formatoptions' has o easily enter a non commented line: go/gO mappings | disabling cabbrev
>>

Additional Notes
Anonymous, November 6, 2002 7:21
In your vimrc file add:
ia prtf fprintf(fdebug, "%0s:%0d\n", __FILE__,
__LINE__) ;
to make this macro part of vim aliases in "insert"
mode.
Anonymous, November 6, 2002 7:33
One disadvantage of having fprints scattered all over
the code is, after debugging, you got to remove them.
If you have defined a macro instead, you can easily
(re)define it to null..
Btw, if you want to debug shell
scripts/perl/tcl/whatever, consider getting yourself a
generic preprocessor. I found filepp
(http://www.cabaret.demon.co.uk/filepp/) pretty good.
No vim stuff.. anyways..
- Karthick
Anonymous, November 6, 2002 16:12
The advantage of the alias is that you can modify the
expanded alias to suite your need at point of
insertion.
ie.
fprintf(fdebug, "%0s:%0d\n >>> the variable i am
interested = %d<<<", __FILE__, __LINE__,
variable_in_question) ;
I work in embedded system and a lot of time our only
debugging tool for code is printf. Not all of us have
in circuit emulators available to us.
And like you said, this is debugging.
The code does not go live with debugging statements,
they are removed.
http://www.vim.org/tips/tip.php?tip_id=351 (2 of 3) [18/02/2004 14:55:07]

Tip #351 - Using quickfix in a different way : vim online

Anonymous, November 7, 2002 1:02


Sigh.
A bug.
You'll have to print as <filename>:<linenumber>: (the
second colon after <linenumber> was missing in the
original post). Or you'll have to change 'errorformat'
I think.. but why would you want to do that?
So we have,
#define DEBUG_MESG( ) fprintf(fdebug, "%0s:%0d:\n",
__FILE__, __LINE__)
and
ia prtf fprintf(fdebug, "%0s:%0d:\n", __FILE__,
__LINE__) ;
- Karthick.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=351 (3 of 3) [18/02/2004 14:55:07]

SourceForge
Logo

Tip #352 - disabling cabbrev : vim online

not logged in (login)

Home
Search

Tip #352: disabling cabbrev


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/3, Viewed by 558

created: October 24, 2002 21:55


author: Kartik Agaram

complexity: intermediate
as of Vim: 5.7

Have you ever been annoyed by an over-zealous cabbrev? A


simple way to temporarily disable it is to set invpaste.
Very convenient in combination with the pastetoggle key.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using quickfix in a different way | Swap caps-lock and control keys using MS Windows Registry >>

Additional Notes
Kartik, October 24, 2002 22:11
Does anybody have a better way to disable cabbrev's?
The vim docs (a little above help abbreviate-local) say
pressing <C-v> twice somewhere within the abbrev avoids
expanding it. Doesn't work for me, though. Pressing <Cv><Space> works in the ':' prompt, but not while
searching - what if I don't want to include a space in
the pattern?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=352 [18/02/2004 14:55:09]

SourceForge
Logo

Tip #353 - Swap caps-lock and control keys using MS Windows Registry : vim online

not logged in (login)

Home
Search

Tip #353: Swap caps-lock and control keys using MS Windows Registry
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 45/18, Viewed by 1575

created: October 29, 2002 11:41


author: Jacques Petit

complexity: basic
as of Vim: 5.7

This will allow you to use the caps-lock key as a control key. Makes using vim in
win32 much nicer in my opinion.
Place the following text into a text file with the extension *.reg and update
your registry by double-clicking the file:
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<disabling cabbrev | Find in files - recursively (NOT :grep!). Only for unix clones. >>

Additional Notes
digitect (at) mindspring com, October 29, 2002 18:58

http://www.vim.org/tips/tip.php?tip_id=353 (1 of 2) [18/02/2004 14:55:11]

Tip #353 - Swap caps-lock and control keys using MS Windows Registry : vim online

I'd suggest, if the text above is copied into a file "caps2ctrl.reg", also
making a file "un-caps2ctrl.reg" in which you place the following:
---------------------------------------------------------------------REGEDIT4
[-HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
---------------------------------------------------------------------This gives you a way to reverse things if you don't like it. ;)
bhl at bigredswitch.com, November 1, 2002 12:04
This site has an explanation on what's going on here:
http://www.annoyances.org/exec/forum/winxp/t1004806455
This
j r p e t i t AT y @ h o o . c o m, November 27, 2002 11:45
Quick addendum to my tip. The registry entry above sets the caps to ctrl. The
following registry entry actually swaps the caps-lock and registry keys on your
keyboard. Useful if you like using caps-lock from time to time.
Remember, to undo this, just delete this entry and your system will revert to
the default behavior.
-- Jacques
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode
Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,1d,00,3a,00,3a,00,1d,00,00,00,00,00
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=353 (2 of 2) [18/02/2004 14:55:11]

SourceForge
Logo

Tip #354 - Find in files - recursively (NOT :grep!). Only for unix clones. : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #354: Find in files - recursively (NOT :grep!). Only for unix
clones.
tip karma

Rating 16/10, Viewed by 1673

created: October 30, 2002 4:31


author: Karthick Gururaj

complexity: basic
as of Vim: 5.7

You probably know about the grep command in vim (:help


grep)
There is one limitation of this - you can't search for a
pattern recursively in files (why doesn't grep have some
kind of -R option for searching recursively? Have looked
around enough at the man pages for that..). The script
below does this. Cut-paste this in to your
.vimrc/_vimrc. Type ":Fif" (without arguments) to see
usage.
" Start of script
" Location where the temporary file (.fif.tmp) would
be stored
let g:Fif_tmp_dir = "/tmp"
function! Fif_fun(...)
if a:0 == 0
" Print usage info and quit
echo "Usage: Fif <pattern-to-be-searched> <filepattern>. E.g:"
echo "Fif struct *.c"
echo "searches for the word struct in all the c
files from the current directory"
return
endif
if a:0 != 2
echohl Error
echo "Error! Wrong number of arguments. Type
:Fif with no arguments to see usage"
echohl None
return
endif
let tmp_file = g:Fif_tmp_dir . "/.fif.tmp"
execute "!touch " . tmp_file . " 2> /dev/null"
if ! filewritable(tmp_file)
echohl Error
echo "No permissions to create " . tmp_file

http://www.vim.org/tips/tip.php?tip_id=354 (1 of 4) [18/02/2004 14:55:14]

Tip #354 - Find in files - recursively (NOT :grep!). Only for unix clones. : vim online

echo "Try setting the g:Fif_tmp_dir variable to


the right value"
echohl None
return
endif
" Put quotes around the file pattern
let com_string = '!find . -name "' . a:2 . '" '
" Do NOT put quotes around the pattern to be
searched - leave it to the user
let com_string = com_string . '-exec grep -n ' .
a:1 . ' /dev/null {} \; > ' . tmp_file
execute com_string
if ! filereadable(tmp_file)
echohl Error
echo "Can't open " . tmp_file . " for reading"
echohl None
return
endif
execute "cfile " . tmp_file
execute '!rm -f ' . tmp_file . ' 2> /dev/null'
endfunction
com -nargs=* Fif call Fif_fun(<f-args>)
" End of script.
No vim magic here, just some shell util usage.
Tested on HPUX.
Should work on Windows with Cygwin. You'll have to
1. Remove those /dev/null's
2. Make sure that the Cygwin's find and grep utils are
used, and not the windows ones
3. Change the default value of g:Fif_tmp_dir
4. Cygwin's grep differs from the version I have on HP.
For forcing grep to print the filename, you'll have to
give it a "-H" option, in addition to "-n"
Some more tinkering can be done with this.. for
instance, if you want to search in all the text files,
irrespective of the extention, you can consider doing
something like this:
" Find all files.
let com_string = '!find . -type f -print '
" Get the file type
let com_string = com_string . '| xargs file '
" Filter out the text files
let com_string = com_string . "| awk '/text/ {print
$1}' "
" Some formatting to remove the trailing ':'
let com_string = com_string . "| sed 's/://' "
" grep for the pattern in all the files
http://www.vim.org/tips/tip.php?tip_id=354 (2 of 4) [18/02/2004 14:55:14]

Tip #354 - Find in files - recursively (NOT :grep!). Only for unix clones. : vim online

let com_string = com_string . '| xargs grep -n ' .


a:1
Cheers!
Karthick.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Swap caps-lock and control keys using MS Windows Registry | Comment Lines according to a
given filetype >>

Additional Notes
ctechols@mindspring.com, October 30, 2002 4:55
I don't know about grep on HP-UX, but GNU grep *can*
recurse into directories using either the "-d recurse",
or "--recursive" options.
stonnedsnake@yahoo.com, October 30, 2002 21:05
Mea culpa. Maxima culpa. The version of grep I have in
HP does *not* have the "-d recurse" feature, but yes,
the GNU grep has, and I have the GNU grep now. Thanks
for the information.
- Karthick.
PS: Is there a way to remove a tip from these archives?
Anonymous, November 16, 2002 18:02
You can even abbreviate that as -r for GNU grep. I
often do something like
grep -r 'some_func(' .
Really convenient.
shawn at deleurme dot calm., June 13, 2003 12:57
or, if you can't get GNU grep (which you should) you
can always use:
find . | xargs grep whatever

scottu@apptechsys.com, June 18, 2003 13:21

http://www.vim.org/tips/tip.php?tip_id=354 (3 of 4) [18/02/2004 14:55:14]

Tip #354 - Find in files - recursively (NOT :grep!). Only for unix clones. : vim online

Or, from within vim:


:grep whatever `find . -name "*.cpp"`
or whatever
Anonymous, August 25, 2003 13:38
Give this a try.
:grep -i "looking for someting"
*/*/*.h

*.c */*.c *.h */*.h

I think this could work for you, unless I am


missunderstanding the problem.
~rs3
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=354 (4 of 4) [18/02/2004 14:55:14]

SourceForge
Logo

Tip #355 - Comment Lines according to a given filetype : vim online

not logged in (login)

Home
Search

Tip #355: Comment Lines according to a given filetype


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/5, Viewed by 1479

created: October 30, 2002 8:12


author: Luis Mondesi

complexity: intermediate
as of Vim: 6.0

There is probably an easier way to do this, but, if I


cannot find an easy solution for a given problem, I just
device one that works for the meantime -- which usually
becomes permanent :-) .
This function comments out lines according to file type.
So if a file is .sh, it uses # to comment lines. And if
a file is type .c it will start the comments with /* and
end them with */.
Put this lines in your .vimrc file:
" -------- vimrc --------" comment out highlighted lines according to file type
" put a line like the following in your
~/.vim/filetype.vim file
" and remember to turn on filetype detection: filetype
on
" au! BufRead,BufNewFile *.sh,*.tcl,*.php,*.pl let
Comment="#"
" if the comment character for a given filetype happens
to be @
" then use let Comment="\@" to avoid problems...
fun CommentLines()
"let Comment="#" " shell, tcl, php, perl
exe ":s@^@".g:Comment."@g"
exe ":s@$@".g:EndComment."@g"
endfun
" map visual mode keycombo 'co' to this function
vmap co :call CommentLines()<CR>
" ------- end vimrc ------Now create a ~/.vim/filetype.vim file if you don't have
one and add things like these to it (remember to put a
line
filetype on, in your vimrc file ... again if you don't
already have one. Vim needs to be compiled with filetype
detection
support for this to work. You have been warned.):

http://www.vim.org/tips/tip.php?tip_id=355 (1 of 3) [18/02/2004 14:55:16]

Tip #355 - Comment Lines according to a given filetype : vim online

-------- filetype.vim --------if exists("did_load_filetypes")


finish
endif
augroup filetypedetect
au! BufRead,BufNewFile
*.inc,*.ihtml,*.html,*.tpl,*.class set filetype=php |
let Comment="<!-- " | let EndComment=" -->"
au! BufRead,BufNewFile *.sh,*.pl,*.tcl let
Comment="#" | let EndComment=""
au! BufRead,BufNewFile *.js set filetype=html | let
Comment="//" | let EndComment=""
au! BufRead,BufNewFile *.cc,*.php,*.cxx let
Comment="//" | let EndComment=""
au! BufRead,BufNewFile *.c,*.h let Comment="/*" |
let EndComment="*/"
augroup END
------ end filetype.vim ------All set, now whenever you are editing a file of those
you have defined in your filetype.vim script, you can
just go into Visual mode, highlight what you want to
comment out, and type "co". Simple.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Find in files - recursively (NOT :grep!). Only for unix clones. | Quick yank and paste >>

Additional Notes
hermitte at free.fr, October 30, 2002 11:29
Why don't you use EnhancedCommentify or
ToggleCommentify ?
They do work fine, they are maintained, extensible,
etc.

http://www.vim.org/tips/tip.php?tip_id=355 (2 of 3) [18/02/2004 14:55:16]

Tip #355 - Comment Lines according to a given filetype : vim online

lemsx1[at]hotmail.com, October 30, 2002 22:59


As I said in the first line: "There is probably an
easier way to do this, but ..."
That's why. I couldn't find a script to do what I
wanted.
Now that you mention EnhancedCommentify I downloaded it
and started going thru it. Essentially the same idea,
but bloated :-). At least I learned that you can do "if
fileType =~" maybe avoiding using a filetype.vim file
to set the comment start and comment end variables.
I don't want to take merit out of EnhancedCommentify or
the other one mentioned. They serve a purpose. In my
case, I only needed to comment out blocks quick and
dirty, never thinking about un-commenting them (or if I
had to I could probably just quickly search thru the
lines I just commented out: 1,23s/#//g ... you get the
idea...)
Thanks anyway for the tip!
Koenraad HEijlen <vipie @ ulyssis.org>, November 27, 2002 17:37
I was used to using 'boxes' as an external filter to
comment/decomment, but pushing to the program and back
is more 'expensive' then using a simple script, but
boxes really is better then EnhancedCommentify.vim (at
least I haven't found a way yet to make it behave just
like I want it to.).
But I would prefer a maintained thing anyday ;)
regards, koenraad.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=355 (3 of 3) [18/02/2004 14:55:16]

SourceForge
Logo

Tip #356 - Quick yank and paste : vim online

not logged in (login)

Home
Search

Tip #356: Quick yank and paste


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/10, Viewed by 2467

created: October 30, 2002 12:54


author: Niels Aan de Brugh

complexity: basic
as of Vim: 5.7

Since I didn't want to interfere with the standard Vim


mappings I removed all the <C-c>, <C-v>, etc. mappings
found in the default vimrc. But quickly copy-pasting
text is a must, so I added the following keymaps. This
is very simple, but it works like a charm.
vmap
nmap
imap
nmap

<C-Space> "ay
<C-Space> "aP
<C-Space> <C-o>"ap
<C-c> "ayiw

Niels
My vimrc if you're interested:
http://home.student.utwente.nl/n.h.m.aandebrugh/_vimrc

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Comment Lines according to a given filetype | Adding a console to gdbvim >>

Additional Notes
Anonymous, November 16, 2002 18:04
You might want to post that to http://www.dotfiles.com
also. (And have a look around there of course.)
Breadman, July 31, 2003 20:15

http://www.vim.org/tips/tip.php?tip_id=356 (1 of 2) [18/02/2004 14:55:18]

Tip #356 - Quick yank and paste : vim online

I found the insertion mapping faulty: its behavior


depended on whether I was at the end of the line. The
following work well for me:
vmap
nmap
vmap
nmap
imap

<C-c>
<C-c>
<C-p>
<C-p>
<C-p>

"py
"pyiw
"pp
"pP
<Esc>"ppa

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=356 (2 of 2) [18/02/2004 14:55:18]

SourceForge
Logo

Tip #357 - Adding a console to gdbvim : vim online

not logged in (login)

Home
Search

Tip #357: Adding a console to gdbvim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/1, Viewed by 2054

created: November 1, 2002 18:06


author: Suresh Govindachar

complexity: advanced
as of Vim: 6.0

This tip shows how to enhance the gdbvim vimscript #84


by
making the outputs from gdb appear in a "console buffer"
inside vim.
"1.a) In gdbvim.vim, one needs to add the following two
buffer
"
manipulation functions:
"-------------------------------------------------------" Buffer manipulation functions {{{1
"
" function! s:GdbFocusBuf(nameref) {{{2
" move the focus to the buffer nameref -- create
" it if it doesn't exist
" return the number of the currently focused buffer
"
function! s:GdbFocusBuf(nameref)
let l:oldnr = bufnr("%")
let l:win_nu = bufwinnr(a:nameref)
if l:win_nu > 0
execute l:win_nu "wincmd w"
else
if bufexists(a:nameref)
execute "sbuffer" a:nameref
else
execute "new" a:nameref
endif
endif
return l:oldnr
endfunction
" function! s:GdbAppendBuf(nameref, stuff) {{{2
" append stuff to buffer nameref
"
function! s:GdbAppendBuf(nameref, stuff)

http://www.vim.org/tips/tip.php?tip_id=357 (1 of 5) [18/02/2004 14:55:21]

Tip #357 - Adding a console to gdbvim : vim online

let l:oldnr = s:GdbFocusBuf(a:nameref)


call append("$", a:stuff)
execute "normal G\<End>"
return l:oldnr
endfunction
"1.b) And modify the two source file management
functions
"
to be as follows:
"-------------------------------------------------------" Source file management functions {{{1
" function! Gdb_Bpt(id, file, linenum) {{{2
"
function! Gdb_Bpt(id, file, linenum)
let s:nowfile = a:file
let l:curnr = s:GdbFocusBuf(a:file)
execute "sign unplace ". a:id
execute "sign place " . a:id ." name=breakpoint
line=".a:linenum." file=".a:file
execute a:linenum
endfunction
" function! Gdb_CurrFileLine(file, line) {{{2
"
function! Gdb_CurrFileLine(file, line)
if a:file != 0
let s:nowfile=a:file
endif
let l:curnr = s:GdbFocusBuf(s:nowfile)
execute
execute
execute
line=".a:line."
execute
endf

"silent! " . a:line . "foldopen"


"sign unplace ". 1
"sign place " . 1 ." name=current
file=".s:nowfile
a:line

"1.c) And add the following console function:


"-------------------------------------------------------" function! Gdb_Console(stuff, set_prompt) {{{2
"
function! Gdb_Console(stuff, set_prompt)
let l:fooey = s:GdbAppendBuf("console", a:stuff)
if a:set_prompt == 1
" What needs to happen here is to enter command
http://www.vim.org/tips/tip.php?tip_id=357 (2 of 5) [18/02/2004 14:55:21]

Tip #357 - Adding a console to gdbvim : vim online

mode
" with the partial command ":Gdb " typed out.
" The following line shows what doesn't work
" call input(":Gdb ")
endif
endfunction
"1.d) And while we are modifying gdbvim.vim, we could
also
"
add a text section to the definitions of the
signs:
"-------------------------------------------------------sign define breakpoint linehl=DebugBreak
text=bb
sign define current
linehl=DebugStop
text=cc
#2) The subroutine worker in the perl script gdbvim
needs to
#
be modified as indicated below. The key points to
note
#
are the two calls the vim-script function
Gdb_Console().
# this function processes the gdb output, prints it and
sends vim commands
sub worker # {{{
{
vim_call('Gdb_interf_init(\"'.$PIPE.'\",
\"'.$ENV{"PWD"}.'\")');
print GDB_WTR "set prompt (gdb)\\n\n";
while (<GDB_RDR>)
{
if (/^.*?gdb\)/)
{
print RL_WTR "READ\n";
chomp ;
print $_ . " ";
vim_call("Gdb_Console(\\\"$_\\\", 1)");
}
else
{
my $stuff = $_;
if(
s/Breakpoint ([0-9]+) at 0x.*: file
([^,]+), line ([0-9]+)./Gdb_Bpt($1,\\\"$2\\\",$3)/ ||
s/Breakpoint ([0-9]+), 0x.*at
([^,]+):([0-9]+)/Gdb_CurrFileLine(\\\"$2\\\",$3)/ ||
s/^\s*0x.*\s+at\s+(\S+):([09]+)/Gdb_CurrFileLine(\\\"$1\\\",$2)/ ||

http://www.vim.org/tips/tip.php?tip_id=357 (3 of 5) [18/02/2004 14:55:21]

Tip #357 - Adding a console to gdbvim : vim online

s/\032\032([^:]*):([09]+).*/Gdb_CurrFileLine(\\\"$1\\\", $2)/ ||
s/^\s*0x\S+\s*([09]+)\s+.*/Gdb_CurrFileLine(0, $1)/
)
{
chomp;
vim_call($_);
}
print $stuff;
chomp($stuff);
# the next substitution is because I
couldn't figure out how to
# pass (from perl) double quotes inside
string arguments to
# vim-script functions
$stuff =~ s/"/'/g;
vim_call("Gdb_Console(\\\"$stuff\\\",
0)");
}
}
vim_call("Gdb_interf_close()");
close GDB_RDR; close GDB_WTR;
}; # }}}
That's all the modifications -- and now gdbvim will show
the output of gdb inside a vim. (Errors from gdb won't
show up in the console but still go to the terminal.)
Happy gdbVimming!
Acknowledgment:
I learnt about functions in vim-scripts by the
process of tracking
down an annoying behavior in cvscommand.vim vimscript
#90.
Also, the author of cvscommand.vim, Bob Hiestand,
graciously
improved my earlier versions of the functions
GdbFoucBuf and
GdbAppendBuf.
rate this tip

Life Changing

Helpful

Unfulfilling

<<Quick yank and paste | Get a random colorscheme on vim startup >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=357 (4 of 5) [18/02/2004 14:55:21]

rate

Tip #357 - Adding a console to gdbvim : vim online

Anonymous, November 5, 2002 2:29


can you posted diff file?
sgovindachar@yahoo.com, November 11, 2002 8:56
In the preceding, the second argument to
Gdb_Console(stuff, set_prompt)
is not used. The purpose of the second argument was to
try to provide the
user with the ":Gdb " prompt in gvim. This result can
actually be achieved
in the perl script by executing the following command
immediately after the
first call to Gdb_Console in sub worker:
system("/usr/local/bin/gvim --servername $VIMNAME -u
NONE -U NONE --remote-send \":Gdb \"");

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=357 (5 of 5) [18/02/2004 14:55:21]

SourceForge
Logo

Tip #358 - Get a random colorscheme on vim startup : vim online

not logged in (login)

Home
Search

Tip #358: Get a random colorscheme on vim startup


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/5, Viewed by 1407

created: November 4, 2002 3:31


author: Madoka Machitani

complexity: intermediate
as of Vim: 6.0

This script picks a colorscheme randomly among all


available schemes files
when vim starts up. This is similar to vimtip #341, but
differs in that it
is independent of other script liblaries, besides the
randomness.
Copy & paste the lines below to somewhere appropriate in
your .vimrc.
" Create the comma-separated list of colorscheme files
let s:colors = substitute(globpath(&runtimepath,
'colors/*.vim'), "\n", ',', 'g')
" Make backward slashes forward if necessary
if (has('dos16') || has('dos32') || has('win16') ||
has('win32') || has('os2')) && !&shellslash
let s:colors = substitute(s:colors, '', '/', 'g')
endif
if strlen(s:colors)
" If there are two or more colorschemes
if s:colors =~ ','
let s:rnd = matchstr(localtime(), '..$') + 0
let s:loop = 0
" Rotate the list s:rnd times
while s:loop < s:rnd
let s:colors = substitute(s:colors,
'^\([^,]\+\),\(.*\)$', '\2,\1', '')
let s:loop = s:loop + 1
endwhile
endif
" Obtain the filename of the first colorscheme in the
list. e.g.:
"
c:/home/vimfiles/colors/foo.vim
" Then, trim unecessary parts to get this:
"
foo
let s:color = substitute(matchstr(s:colors,

http://www.vim.org/tips/tip.php?tip_id=358 (1 of 3) [18/02/2004 14:55:23]

Tip #358 - Get a random colorscheme on vim startup : vim online

'^[^,]\+'), '^.*/\(.*\)\.vim$', '\1', '')


execute "colorscheme" s:color
endif
unlet! s:colors s:color s:rnd s:loop
Please be noted that adding this script might slightly
slow down the startup
time of vim. Enjoy!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Adding a console to gdbvim | Download RedHat RPMS of the latest and greatest version of VIM. >>

Additional Notes
madokam@zag.att.ne.jp, November 4, 2002 3:44
Ah! A backward slash has disappeared on the script
line 5.
Please correct the line
let s:colors = substitute(s:colors, '', '/', 'g')
to:
let s:colors = substitute(s:colors, "\\", '/', 'g')
Sorry.
madokam@zag.att.ne.jp, October 14, 2003 3:53
I've made a slight improvement:
" Create the comma-separated list of colorscheme files
let s:colors = substitute(globpath(&runtimepath,
'colors/*.vim'), '\n', ',', 'g')
if strlen(s:colors)
" Count the number of color schemes
let s:num = strlen(substitute(s:colors, '[^,]\+', '',
'g')) + 1
if s:num > 1
let s:loop = localtime() % s:num
" Rotate the list s:loop times
while s:loop
let s:colors = substitute(s:colors,
'^\([^,]\+\),\(.*\)$', '\2,\1', '')
let s:loop = s:loop - 1
endwhile
http://www.vim.org/tips/tip.php?tip_id=358 (2 of 3) [18/02/2004 14:55:23]

Tip #358 - Get a random colorscheme on vim startup : vim online

endif
let s:color = matchstr(s:colors, '^[^,]\+')
unlet! g:colors_name
execute 'source' s:color
" Prevent the message from disappearing
redraw
echomsg 'Color applied: '.(exists('g:colors_name') ?
g:colors_name : '').' ('.s:color.')'
endif
unlet! s:colors s:color s:num s:loop
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=358 (3 of 3) [18/02/2004 14:55:23]

SourceForge
Logo

Tip #359 - Download RedHat RPMS of the latest and greatest version of VIM. : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Tip #359: Download RedHat RPMS of the latest and greatest version
of VIM.
tip karma

Rating 18/12, Viewed by 1295

created: November 4, 2002 21:06


author: Jeremy Brand, B.S.

complexity: basic
as of Vim: 6.0

You can now download RedHat RPMS of the latest and


greatest version of VIM.
Here is the annoucement:
http://marc.theaimsgroup.com/?l=vim&m=103629270123503&w=2
Here is the download link:
http://nirvani.org/software/vim/

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Get a random colorscheme on vim startup | ':e <dir>' enter files and directories >>

Additional Notes
jeremy@nirvani.net, November 4, 2002 21:09
I am the maintainer of these RedHat VIM RPMS. My plan
is to keep them up to date with the latest and greatest
version of vim. Check back often, or whenever there is
a new version of VIM.
Download link to VIM RedHat RPMS:
http://nirvani.org/software/vim/
Jeremy Brand, B.S.
max@malva.ua, November 5, 2002 5:49
Would you mind to put .nosrc.rpm or a .spec-file as
well?
jeremy@nirvani.net, November 7, 2002 23:00

http://www.vim.org/tips/tip.php?tip_id=359 (1 of 2) [18/02/2004 14:55:25]

Tip #359 - Download RedHat RPMS of the latest and greatest version of VIM. : vim online

I do not know what you mean by ".nosrc.rpm", but the


spec file is in the vim*src.rpm.
http://nirvani.org/software/vim/
Jeremy Brand, B.S.
anon, November 8, 2002 12:58
For each build (minimal, enhanced and X11), is there
any way to know
the detailed version (i.e., output of "vim --verson")
without actually
installing the RPMS? If so, how?
jeremy@nirvani.net, November 25, 2002 0:46
Here is how to find out the version of vim contained in
the RPM files.
For example:
vim-common-6.1-261_1.i386.rpm is vim version 6.1.261.
Jeremy
http://nirvani.org/software/vim/
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=359 (2 of 2) [18/02/2004 14:55:25]

SourceForge
Logo

Tip #360 - ':e <dir>' enter files and directories : vim online

not logged in (login)

Home
Search

Tip #360: ':e <dir>' enter files and directories


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 13/9, Viewed by 797

created: November 5, 2002 3:37


author: Thomas Ramming

complexity: basic
as of Vim: 6.0

You can directly enter files with ':e filename', but did
you know you can 'enter' directories that way ?
e.g. ':e ..' opens a buffer window with the entries of
the parent directory.
If you then double click on an entry the directory is
opened in the same way (if it's a directory)
or the file is opened for editing (if it's a file).
(Don't ask me, if it's normal vim behaviour or the
effect of any script.)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Download RedHat RPMS of the latest and greatest version of VIM. | Use xdvi (or kdvi) in
conjunction with gvim (or vim) and converse >>

Additional Notes
Anonymous, November 6, 2002 7:38
See also ":help :Explore" and ":help :Sexplore"
zzapper@ntlworld.com, November 6, 2002 9:48

http://www.vim.org/tips/tip.php?tip_id=360 (1 of 2) [18/02/2004 14:55:27]

Tip #360 - ':e <dir>' enter files and directories : vim online

:e ..
also
:Ex
:Sex
does the same in split Window (& not Thailand)
all part I presume of bufexplorer.vim (recently
updated)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=360 (2 of 2) [18/02/2004 14:55:27]

SourceForge
Logo

Tip #361 - Use xdvi (or kdvi) in conjunction with gvim (or vim) and converse : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #361: Use xdvi (or kdvi) in conjunction with gvim (or vim) and
converse
tip karma

Rating 16/4, Viewed by 1031

created: November 5, 2002 14:07


author: Christine Noot-Huyghe

complexity: intermediate
as of Vim: 6.0

source: the xdvi man page


For recent xdvi versions (>= 22.38), (or recent
Unix/Linux versions), xdvi can
interact with any editor provided with a client-server
mode. We explain
here how to use xdvi in conjunction with vim (compiled
with the client-server
option) or gvim (mostly compiled with this option). I
have tested that
with Linux Mandrake 9.0. On that system, gvim is
compiled with the
client-server option and vim is not.
0-Check that your xdvi version provides the "sourcespecial" functions,
by typing 'xdvi -version' or 'man xdvi'
1-Configuration of the source file (file.tex)
Put the following line at the beginning of the latex
file:
\usepackage[active]{srcltx}
or the following line at the beginning of the tex file
\include{srctex}
2-Configuration of xdvi
xdvi has to be called with the following options
xdvi -editor 'gvim --remote-wait +%l %f' file.dvi &
(or with 'xterm -e vim --remote-wait +%l %f' if vim has
been compiled with the client-server option).
To make it easier to use you can define an environement
variable XEDITOR to set the value of 'editor' or add
the following line in your .Xdefaults
xdvi.editor: gvim --remote-wait +%l %f
Launch 'xrdb -load ~/.Xdefaults' to make sure that
xdvi.editor is set to the good value.

http://www.vim.org/tips/tip.php?tip_id=361 (1 of 3) [18/02/2004 14:55:30]

Tip #361 - Use xdvi (or kdvi) in conjunction with gvim (or vim) and converse : vim online

If you have defined such a variable, xdvi will always be


launched
with the -editor option. To avoid this unsafe behavior,
launch 'xdvi -safer'.
3-Conversely, if you call xdvi within gvim with the sourceposition
option, cursor is placed in the dvi file on the
corresponding position.
Syntax is:
xdvi -sourceposition l:cfile.tex file.dvi
l is the line number, c is the column number
(Be carefull: there is no space between "c" (column
number) and
file.tex).
To make it easier to use, you can do the following
First create a file named for example "xdvi_source.vim"
with following lines
" This script calls xdvi source and puts cursor in xdvi
viewer at
" the position corresponding to the position in the
source file
"
:exec "silent !xdvi -sourceposition
".line(".").':'.col(".")."%".' '."%:r.dvi"
Then launch the following command within gvim editing
the .tex
source file. Pressing simultaneously <CTRL> and -> will
open
the dvi file at the right position:
:noremap <buffer> <C-Right> :so xdvi_source.vim<CR>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<':e <dir>' enter files and directories | matchit.vim and coldfusion (and perhaps others) >>

Additional Notes
Anonymous, November 19, 2002 23:04
Seems it doesn't work for multiple tex source files.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=361 (2 of 3) [18/02/2004 14:55:30]

SourceForge

Tip #361 - Use xdvi (or kdvi) in conjunction with gvim (or vim) and converse : vim online

Logo

http://www.vim.org/tips/tip.php?tip_id=361 (3 of 3) [18/02/2004 14:55:30]

Tip #362 - matchit.vim and coldfusion (and perhaps others) : vim online

not logged in (login)

Home
Search

Tip #362: matchit.vim and coldfusion (and perhaps others)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/3, Viewed by 688

created: November 7, 2002 2:19


author: zzapper

complexity: basic
as of Vim: 5.7

Hi VIMmites
I couldn't get any tags to match in Coldfusion files
*.cfm either HTML Javascript or ColdFusion tags
themselves <cfif ..> ... </cfif>
Much pain was gone thru before I realised that the
Syntax File for ColdFusion
(/syntax/cf.vim) was called cf and not cfm
Therefore in matchit.cfm I need to add CF in following
line and NOT CFM
au FileType html,jsp,php,cf if !exists("b:match_words")
|
zzapper
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Use xdvi (or kdvi) in conjunction with gvim (or vim) and converse | Starting up Vim very fast
expecially from a telnet session >>

Additional Notes
zzapper@ntlworld.com, November 7, 2002 6:18
I meant edit matchit.vim (not matchit.cfm)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=362 [18/02/2004 14:55:31]

SourceForge
Logo

Tip #363 - Starting up Vim very fast expecially from a telnet session : vim online

not logged in (login)

Home
Search

Tip #363: Starting up Vim very fast expecially from a telnet session
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 56/29, Viewed by 1533

created: November 7, 2002 14:06


author: vim_power

complexity: basic
as of Vim: 5.7

when you telnet to a remote machine and fire Vim on that


machine,
sometimes it takes a lot of time for Vim to start.
instead if you use
vim -X
it will start vim almost instantaneously. This is
because "-X" options
tells vim not to connect to the local X server, which
can save a lot of startup time.
Also
vim -X --noplugin
will not load any plugins in $VIMRUNTIME/plugin
directory, this will again speed up the
starting and is very useful especially when running vim
from a Disk mounted over NFS.
Njoy
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<matchit.vim and coldfusion (and perhaps others) | Automatic file type detection with fully qualified
ClearCase names >>

Additional Notes
hkraenz@mdli.com, November 19, 2002 3:34

http://www.vim.org/tips/tip.php?tip_id=363 (1 of 2) [18/02/2004 14:55:34]

Tip #363 - Starting up Vim very fast expecially from a telnet session : vim online

This one is great!


I alway use vim via telnet on remote machines but it
always tried to connect to my XServer. Up to now, I
always made something like 'unset DISPLAY; vim ...'.
I think it's a bug in the manual pages since the option
-X is not mentioned there (same applies for -O).
This makes life much more easier!
Thanks
Helge
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=363 (2 of 2) [18/02/2004 14:55:34]

SourceForge
Logo

Tip #364 - Automatic file type detection with fully qualified ClearCase names : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #364: Automatic file type detection with fully qualified ClearCase
names
tip karma

Rating 21/9, Viewed by 738

created: November 8, 2002 1:47


author: Arnaud Cassignol

complexity: basic
as of Vim: 6.0

I am using the great plugin from Douglas Potts


(vimscript #15).
When you load a specific ClearCase version of a file,
vim cannot find the correct file type in the full name
(ex. filename.c@@/main/foo/1). To improve that, you can
create an autocommand in the filetype.vim file in your
user runtime directory.
augroup filetypedetect
au BufNewFile,BufRead */*@@*
\ if expand("<afile>") =~ '@@' |
\
exe "doau filetypedetect BufRead " .
expand("<afile>:s?@@.*$??") |
\ endif
augroup END
The test in the command is for compatibility with path
containing '@@' sequence.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Starting up Vim very fast expecially from a telnet session | Vim Book Online >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=364 [18/02/2004 14:55:36]

SourceForge
Logo

Tip #365 - Vim Book Online : vim online

not logged in (login)

Home
Search

Tip #365: Vim Book Online


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 83/35, Viewed by 3265

created: November 8, 2002 3:47


author: Mike Wall

complexity: basic
as of Vim: 5.7

New Riders has released Steve Oualline book Vi iMproved


(VIM) under their Open Publication License (OPL). View
it at
http://www.newriders.com/books/opl/ebooks/0735710015.html

rate this tip

Life Changing

Helpful

Unfulfilling

rate

Site Help
<<Automatic file type detection with fully qualified ClearCase names | really basic RCS interaction from
within vim >>

Additional Notes
chris@nominet.org.uk, November 12, 2002 2:29
It's a pity the sidebar with the contents doesn't
display properly in Opera. Even IE complains that
there is an error in the Javascript...
Anonymous, November 13, 2002 8:17
I found this under the Documentation Link on
vim.sourceforge.net
http://www.truth.sk/vim/vimbook-OPL.pdf
Anonymous, November 18, 2002 7:08
Or, ofcourse, http://www.vim.org/docs.php
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=365 [18/02/2004 14:55:41]

SourceForge
Logo

Tip #366 - really basic RCS interaction from within vim : vim online

not logged in (login)

Home
Search

Tip #366: really basic RCS interaction from within vim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/4, Viewed by 817

created: November 8, 2002 8:31


author: Peter

complexity: basic
as of Vim: 6.0

I've looked all around and haven't found RCS functions


built into vim (which surprises me, really), so I looked
more and found some almost working RCS scripts for textmode. Key there is almost. It's still a kludge, but it
works without too much hassle.
I've chosen F1 and F2, because I never use those keys
for what they are intended. I use :help for command
reference, not for a tutorial style thing. So, use some
discretion. Also, the write command could just as
easily have been a :write!, but I decided against that
in the case of files that weren't checked out. You
should check them out, first, and they should be
writable.
map <F1>
%<CR>:edit!<CR>
map <F2>

:write %<CR>:!ci -l
:!co -l %<CR>:edit!<CR>

New RCS files work just fine with the first mapping.
There would be some use to creating the RCS directory,
if it's not already there, but I don't see an "if exists
and is directory" function, right now.
There's a good menu-driven rcs client for graphical
vim, but I hate menus and graphical interfaces.
rate this tip

Life Changing

Helpful

<<Vim Book Online | What is this $VIMRUNTIME ? >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=366 (1 of 2) [18/02/2004 14:55:48]

Unfulfilling

rate

Tip #366 - really basic RCS interaction from within vim : vim online

pottsdl@yahoo.com, November 8, 2002 9:53


If you are referring to rcs-menu.vim, even though it
has a menu/graphical interface,
it also creates mappings to do the same operations,
which to me is more useful. So
I guess you really get the best of both worlds that
way.
feral of the firetop, November 9, 2002 1:15
> but I don't see an "if exists and is directory"
function, right now.
How about isdirectory() ?
if isdirectory("c:/vim/vimfiles/")
"dir exists
endif
Luck!
bcnelson@imcglobal.com, February 28, 2003 9:21
See rcsdiff.vim (vimscript #360) for visual rcsdiff.
Integrates Vim's diffsplit with RCS.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=366 (2 of 2) [18/02/2004 14:55:48]

SourceForge
Logo

Tip #367 - What is this $VIMRUNTIME ? : vim online

not logged in (login)

Home
Search

Tip #367: What is this $VIMRUNTIME ?


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/10, Viewed by 1765

created: November 8, 2002 13:03


author: vim_power

complexity: basic
as of Vim: 5.7

$VIMRUNTIME points to a directory where most of the


files needed by Vim are kept.
As the name suggests these files are needed during "runtime". Though they are not necessary for
Vim to run, but they help in adding extra functionality
to the basic Vim.
Here is a brief overview of files and directories in
$VIMRUNTIME.
bugreport.vim :- Use this file if you think you have
discovered a bug in VIM. see "help bugreport"
colors :- Contains various clorschemes. see ":help
:colorscheme"
compiler :- Contains compilation scripts for various
languages. see ":help :compiler"
delmenu.vim :- Deletes all Menu's
doc :- Contains Documentation :-)
evim.vim :- script for easy vim. see :help evim"
filetype.vim :- Detects filetype of files based on their
extensions. see "help filetype"
ftoff.vim :- SOurce this to disable ditection of
filetypes.
ftplugin :- Contains plugins that are loaded based on
the filetype.
ftplugin.vim :- Enables flietype plugins
ftplugof.vim :- Disables filetype plugins
gvimrc_example.vim :- The name says it all, right :-)
indent :- contains indentaion scripts for various
languages
indent.vim :- Enables indentation based on filetype.
indoff.vim :- Disables indentation based on filetype.
keymap :- Contains keymap files for various encodings.
see ":help keymap"
lang :- Contains Message files in different language.
see ":help language"
macros :- Contains variuos cool stuff. read

http://www.vim.org/tips/tip.php?tip_id=367 (1 of 2) [18/02/2004 14:55:51]

Tip #367 - What is this $VIMRUNTIME ? : vim online

"macros/README.txt"
menu.vim :- Default Menus
mswin.vim :- sets options for Vim to behave like
Windows.
optwin.vim :- commands to create option window.
plugin :- Contains plugins. All .vim files in this
directory are automatically sourced.
scripts.vim :- helps detect filetype in Vim scripts.
syntax :- Contains Syntax defination files for various
programming languages.see ":help syntax"
tools :- Some useful tools. like blink to blink the
cursor in xterm.
tutor :- Contains tutor.vim. see ":help tutor"
vim32x32.xpm :- Vim Logo.
vimrc_example.vim :- again name says it all.
~
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<really basic RCS interaction from within vim | Use gvim in VS.Net >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=367 (2 of 2) [18/02/2004 14:55:51]

SourceForge
Logo

Tip #368 - Use gvim in VS.Net : vim online

not logged in (login)

Home
Search

Tip #368: Use gvim in VS.Net


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 42/25, Viewed by 1889

created: November 8, 2002 16:52


author: Mark Fernandes

complexity: basic
as of Vim: 5.7

This tip presumes you have both VS.Net (Developer


Studio.Net) and gvim installed, and know where gvim is
located on your system.
- Create a solution in VS.Net, any project type will do.
- In the solution explorer (View->Solution or Ctrl + R)
you should see a list of files (click on the "Solution
Explorer" tab if you do not see the file list).
- Right click on any of the files and choose "Open
With...", this brings up the Open With dialog.
- Click on "Add..." this brings up the Add Program
dialog.
- Click on "Browse..." and point the Browse dialog to
your gvim location.
- You have now added gvim to the list of editors, you
may also select gvim to be the default editor for that
file type.
You may need to do this for all file types you wish to
edit with gvim. And yes you still have VS.Net open the
file in its own editor.
Of course if you want to reverse changes simply remove
gvim from the list of editors and why would you want to
do that? :)
Enjoy!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<What is this $VIMRUNTIME ? | Comment/UnComment visually selected text >>

Additional Notes
narayanpavgi@hotmail.com, January 22, 2003 4:46

http://www.vim.org/tips/tip.php?tip_id=368 (1 of 2) [18/02/2004 14:55:54]

Tip #368 - Use gvim in VS.Net : vim online

Slightly disappointing is that VS.net opens the window


in the middle of the screen and at the location and
size of the its "source pane". How can I adjust where
and of what size is the vim window when it opens ?
nospam@ea.com, February 28, 2003 12:32
in _vimrc:
gui
winpos 33 0
set lines=100
mattknowles7@yahoo.com, July 22, 2003 13:03
VS.Net insists on opening each file in a new vim
window, is there a way to force it to open each file in
the same window?
itmaybeyou.ignore@hotmail.com, January 26, 2004 17:39
Yes, what would really be nice is vim commands within
the VS.NET environment, w/o opening a new window.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=368 (2 of 2) [18/02/2004 14:55:54]

SourceForge
Logo

Tip #369 - Comment/UnComment visually selected text : vim online

not logged in (login)

Home
Search

Tip #369: Comment/UnComment visually selected text


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 34/17, Viewed by 2141

created: November 15, 2002 0:57


author: Amit Neogy

complexity: intermediate
as of Vim: 5.7

Comment/UnComment visually selected code


========================================
Visually selected code can be easily Commented out and
uncommented by using
the following functions. The functions insert/delete
C/C++/Java style
comments. The comment characters can be modified by
editing the functions.
Add the following to your .vimrc file. It will add two
menu items under
the "Edit" menu in gVim. The function calls can be
mapped to keystrokes
if desired.
----------------------------------------------------------------------------"Menu items for Commenting and Un-Commenting code
amenu 20.435 &Edit.-SEP4- :
amenu Edit.Comment <ESC>`<:let fl=line(".")<CR>`>:let
ll=line(".")<CR>:call Comment(fl, ll)<CR>
amenu Edit.UnComment <ESC>`<:let fl=line(".")<CR>`>:let
ll=line(".")<CR>:call UnComment(fl, ll)<CR>
"Function for commenting a block of Visually selected
text
function Comment(fl, ll)
let i=a:fl
let comment="//"
while i<=a:ll
let cl=getline(i)
let cl2=comment.cl
call setline(i, cl2)
let i=i+1
endwhile
endfunction

http://www.vim.org/tips/tip.php?tip_id=369 (1 of 4) [18/02/2004 14:55:56]

Tip #369 - Comment/UnComment visually selected text : vim online

"Function for Un-Commenting a block of Visually selected


text
function UnComment(fl, ll)
let i=a:fl
let comment="//"
while i<=a:ll
let cl=getline(i)
let cl2=substitute(cl, "//", "", "")
call setline(i, cl2)
let i=i+1
endwhile
endfunction
----------------------------------------------------------------------------rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Use gvim in VS.Net | always cd to the current file's directory >>

Additional Notes
tomte@subdimension.com, November 15, 2002 3:55
There are a few scripts here already, that will do the
same in a more general way, nevertheless I'd suggest
the following changes
let comment="// "
in Comment() for better readability
and
let cl2=substitute(cl, "^\s*// ", "", "")
in UnComment() to ensure the comment will only be
replaced at the beginning of a line.

Anonymous, November 16, 2002 22:52

http://www.vim.org/tips/tip.php?tip_id=369 (2 of 4) [18/02/2004 14:55:56]

Tip #369 - Comment/UnComment visually selected text : vim online

I find it easier to simply select the area you want to


comment out in visual-block mode (usually CTRL-V or
CTRL-Q), type "I" (CAPS - EYE) type the comment
character '//' and ESC. This gives me the flexibility
to change my comment character (for instance make it
/// for later searches) and is straight-forward. To
uncomment, simply select the comment characters is
visual-block mode, and delete them.
anom, November 18, 2002 0:09
What about C (/* ... */)?
Anonymous, November 20, 2002 4:09
isn't more pratical select the lines (block-visual) and
insert your comment (i do it inserting 'c' on fortran
sources):
<c-v>
... move around ...
0
(be sure to stay at first column!)
I
(insert)
// (or what you like)
<esc>
to remove them, select it (<c-v> do the magic), and
press 'x'
d95mback@dtek.chalmers.se, November 21, 2002 7:15
I use the following (for haskell style comments, just
replace -- with whatever your line comment characters
are)
map ,c :s/^/-- /<CR>
map ,u :s/^-- //<CR>
So, typing ,c in normal mode will comment lines, typing
,u will uncomment them.
Works in visual mode as well.
d95mback@dtek.chalmers.se, April 7, 2003 3:02

http://www.vim.org/tips/tip.php?tip_id=369 (3 of 4) [18/02/2004 14:55:56]

Tip #369 - Comment/UnComment visually selected text : vim online

This is my current setup, it works very nicely.


au FileType haskell,vhdl,ada
let
b:comment_leader = '-- '
au FileType vim
let
b:comment_leader = '" '
au FileType c,cpp,java
let
b:comment_leader = '// '
au FileType sh,make
let
b:comment_leader = '# '
au FileType tex
let
b:comment_leader = '% '
noremap <silent> ,c :<C-B>sil <C-E>s/^/<CR>=escape(b:comment_leader,'\/')<CR>/<CR>:noh<CR>
noremap <silent> ,u :<C-B>sil <C-E>s/^\V<CR>=escape(b:comment_leader,'\/')<CR>//e<CR>:noh<CR>
,c comments out a region
,u uncomments a region
suraj_amin@yahoo.com, May 2, 2003 1:04
Is there a way to add a popup item too? Menu becomes
too cumbersome to access.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=369 (4 of 4) [18/02/2004 14:55:56]

SourceForge
Logo

Tip #370 - always cd to the current file's directory : vim online

not logged in (login)

Home
Search

Tip #370: always cd to the current file's directory


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 105/45, Viewed by 2251

created: November 15, 2002 0:59


author: Dubhead

complexity: basic
as of Vim: 6.0

When I have several or more files from various


directories opened and am going to open another, I find
it counter-intuitive to specify the file path from Vim's
current directory. I think it's more natural to specify
it from current file's directory (though this is not the
traditional vi way). If you feel similarly, this simple
tip may help you.
My solution is to have Vim always cd to the current
file's directory. Put this in your .vimrc:
function AlwaysCD()
if bufname("") !~ "^ftp://";
lcd %:p:h
endif
endfunction
autocmd BufEnter * call AlwaysCD()
Note that Vim doesn't cd to a remote machine's
directory. If you never open a file through network,
just use this instead:
autocmd BufEnter * lcd %:p:h
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Comment/UnComment visually selected text | Encrypting a file within vim session and not leaving
behind traces. >>

Additional Notes
Dubhead, November 15, 2002 1:05
Oops, please remove that semicolon at the end of the
'if' line. I'm sorry.

http://www.vim.org/tips/tip.php?tip_id=370 (1 of 3) [18/02/2004 14:55:59]

Tip #370 - always cd to the current file's directory : vim online

Anonymous, November 16, 2002 18:23


I've been using this for a long time and it's really
convenient. I did notice the shortcoming on remote
files but so far hadn't bothered to fix it. Thanks for
the hint.
Here's a version that will work for all URI schemes,
not just ftp, and doesn't require a function:
:autocmd BufEnter * if bufname("") !~ "^\[A-Za-z09\]*://" | lcd %:p:h | endif
Perfect. :)
Anonymous, November 17, 2002 19:11
I small problem that you'll probably never have to deal
with, is if you type "vim fgfdg/fdgfdg/file.txt" and
the directories don't exist, you'll get a nasty error
message...add sil! before the lcd call and you won't :)
mr_july@gmx.net, November 18, 2002 6:20
What do I need to do in this case, when I have spaces
or other symbols in path? For example under "Program
Files".
Dubhead, November 18, 2002 22:51
mr_july, quote the space in the pathname with a
backslash. It would look like
c:\Program\ Files\
I guess you can automatically get it when you hit the
space bar to complete the pathname, though.
If you're using Windows 2k/XP (not 98/ME), there's
another workaround: Create a 'junction'. You can
create a junction point, say "C:\ProgramFiles" (note
the lack of the space), as an alias for "C:\Program
Files". Then you can refer to "C:\Program
Files\SomeApp\readme.txt" as
"C:\ProgramFiles\SomeApp\readme.txt".
Junction is a feature of NT filesystem, but Windows
somehow lacks a UI to create it. There are some third
party utilities for that, such as 'Winlinks' by
Thirty4 Interactive (go to http://www.thirty4.com/ and
select PROJECTS).
And thanks for the function-less solution and the
'silent!' suggestion. I combined them and it works :-)

http://www.vim.org/tips/tip.php?tip_id=370 (2 of 3) [18/02/2004 14:55:59]

Tip #370 - always cd to the current file's directory : vim online

Anonymous, November 27, 2002 0:07


Another useful thing for Windows user:
add a link under your user configuration in the
directory 'SendTo' and edit the target like:
U:\MyTools\vim\gvim.exe --cmd "lcd %:p:h"
So you can start gvim with the selected file(s) from
Windows explorer by selecting gvim via the context menu
/ send to / gvim.
In the same way you can start a vimdiff for the
selected files from Windows explorer.
Just add '-d' to the target line:
U:\MyTools\vim\gvim.exe -d --cmd "lcd %:p:h"
Dubhead, June 12, 2003 2:01
I'm happy to find that Vim version 6.2 made this tip
obsolete: Just use the new 'autochdir' option.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=370 (3 of 3) [18/02/2004 14:55:59]

SourceForge
Logo

Tip #371 - Encrypting a file within vim session and not leaving behind traces. : vim online

not logged in (login)

Tip #371: Encrypting a file within vim session and not leaving behind traces.

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/9, Viewed by 1275

created: November 20, 2002 21:44


author: Prakash Patil

complexity: basic
as of Vim: 6.0

I was desperately looking for a simple way to encrypt files.


(I find this very useful. Despite all the user permissions you set, it's
easy for someone/admin
to do sudo and read your personal files..Many work environments provide
users the permission
to sudo or become super user)
Vim let's you encrypt file within the edit session.
:X
Will prompt for encryption key. Enter the encryption key and REMEMBER to
save
it using :w. That will encrypt the file.
Try
:help :X
for more info.
If you don't want to leave behind traces of your edits:
By default, once you finish your vim session, ~/.viminfo will be written
with
the files you edited (marks), commands you entered and possibly what you
wrote
(the registers you copied or pasted...). If you don't want such trace to
be left behind,
then place the following file in in your .vimrc
set viminfo='0,\"0,\/0,:0,f0
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<always cd to the current file's directory | Remove unwanted empty or blank lines for english and chinese >>

Additional Notes
sorry, no spam please, November 20, 2002 23:22

http://www.vim.org/tips/tip.php?tip_id=371 (1 of 3) [18/02/2004 14:56:01]

Tip #371 - Encrypting a file within vim session and not leaving behind traces. : vim online

There are a lot of other vim settings to make sure you leave no trace
behind like swapfiles, backupfiles, etc.
I once investigated these settings and set up a gvimrc file for editing
files containing
e. g. a collection of 'secret' information like passwords, ident
numbers, etc..
I copied this encrypted file, gvimrc, and the program files (gvim.exe)
on a 3.5" Floppy,
which makes you 'autarkic'.
I'm trying hard not to forget copying the settings to the VIM tips.
Does anybody know how 'safe' is gvim encryption ?
Thomas
vim_power, November 21, 2002 11:29
from VIM help files.
- The algorithm used is breakable. A 4 character key in about one hour,
a 6
character key in one day (on a Pentium 133 PC). This requires that
you know
some text that must appear in the file. An expert can break it for
any key.
When the text has been decrypted, this also means that the key can be
revealed, and other files encrypted with the same key can be
decrypted.
- Pkzip uses the same encryption, and US Govt has no objection to its
export.
Pkzip's public file APPNOTE.TXT describes this algorithm in detail.
- Vim originates from the Netherlands. That is where the sources come
from.
Thus the encryption code is not exported from the USA.
Anonymous, December 4, 2002 4:03
I am using these settings in a _gvimrc on a disc (containing gvim.exe
and vimrun.exe) for keeping secrets secret:
"/*===================================================================*/
" Eintrge fr Editieren von Pawortgeschtzten Dateien (':X'):
" keine Swap- oder temp files verwenden:
set noswapfile
set nobackup
set nowritebackup
" kein info file mit history eintraegen:
set viminfo=
"/*===================================================================*/
Of course the RAM and the swapfile of Windows still may be read in plain
ASCII / hex by spies.
Thomas
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=371 (2 of 3) [18/02/2004 14:56:01]

SourceForge
Logo

Tip #371 - Encrypting a file within vim session and not leaving behind traces. : vim online

http://www.vim.org/tips/tip.php?tip_id=371 (3 of 3) [18/02/2004 14:56:01]

Tip #372 - Remove unwanted empty or blank lines for english and chinese : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #372: Remove unwanted empty or blank lines for english and
chinese
tip karma

Rating 30/19, Viewed by 907

created: November 21, 2002 16:51


author: slimzhao

complexity: basic
as of Vim: 5.7

This tip is inspired by tip #72 which titled 'Remove


unwanted empty lines'.
:g/^$/d
==================
Well, if the line contains <Space> and <Tab>
:g/^\s*$/d
==================
If the line contains <Space> and <Tab> and chinese
character <Space>, which takes two bytes, and the ASCII
is 0xA1 0xA1.
:g/^\(\s\|\)*$/d
Herein after the | I paste the `<Space> as a chinese
character'.
:g/^[ \t|?]*$/d
Note the `|?' represents a single character which ascii
is 0xA1, and inputed by
CTRL-VxA1
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Encrypting a file within vim session and not leaving behind traces. | Run find/replace/search on
multiple files and subdirectories >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=372 [18/02/2004 14:56:03]

SourceForge
Logo

Tip #373 - Run find/replace/search on multiple files and subdirectories : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #373: Run find/replace/search on multiple files and


subdirectories
tip karma

Rating 20/16, Viewed by 3528

created: November 22, 2002 10:02


author: David Fishburn

complexity: basic
as of Vim: 6.0

I wanted to recursively edit all html files in a


folder/subfolders and run a search and replace command
(substitute) in each one, then save the files when
finished.
Vim 6.1.255
This is what my batch (WinXP) file does:
Note, since this is running in a windows batch/command
file, I had to
escape the % sign.
First start a new instance of gvim, so it doesn't use
one that I am already using.
Give it a specific name so the commands are contained to
it.
start gvim --servername BEAD
Using the FOR statement recursively edit all htm files
and send them to the gvim session I just started:
FOR /R %%i IN (*.htm) DO gvim --servername BEAD --remotesilent "%%i"
Now, send the bufo command to that server that will run
a substitute command.
Note, I had to double up the % signs since I am in a
batch/cmd file.
I also used the ge options so that no error was reported
if the search string was not found.
gvim --servername BEAD --remote-send "<ESC>:bufdo
%%s/Tweety Bird/Road
Runner/ge<CR>"
Now save all files and exit
gvim --servername BEAD --remote-send "<ESC>:xall<CR>"

http://www.vim.org/tips/tip.php?tip_id=373 (1 of 3) [18/02/2004 14:56:06]

Tip #373 - Run find/replace/search on multiple files and subdirectories : vim online

Complete batch/cmd file (minus the ***'s)


***********************
start gvim --servername BEAD
FOR /R %%i IN (*.htm) DO gvim --servername BEAD --remotesilent "%%i"
gvim --servername BEAD --remote-send "<ESC>:bufdo
%%s/Tweety Bird/Road
Runner/ge<CR>"
gvim --servername BEAD --remote-send "<ESC>:bufdo
%%s/\(^File:.*JPG\).*/\1/ge<CR>"
rem Write all files and exit
gvim --servername BEAD --remote-send "<ESC>:xall<CR>"
***********************
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Remove unwanted empty or blank lines for english and chinese | VIM's Filtering Commands
Summary >>

Additional Notes
Anonymous, November 25, 2002 3:48
See :args and :argdo
Anonymous2, December 3, 2002 12:55
How to use :args to search recursive in subdirectories?
Anonymous, March 4, 2003 5:19
you can use something like this:
:args *.cpp */*.cpp */*/*.cpp
Not exactly *recursive*, but works well for reasonably
flat directory hierarchies.
raghuramvemuri@yahoo.com, June 18, 2003 10:26
Fantastic Tip. Saved me a lot of time.
I had put the [ ! ] after the bufdo command so it would
move on to the next buffer.
gvim --servername BEAD --remote-send "<ESC>:bufdo!
%%s/Tweety Bird/Road Runner/ge<CR>"
Thanks.
Add Note

http://www.vim.org/tips/tip.php?tip_id=373 (2 of 3) [18/02/2004 14:56:06]

Tip #373 - Run find/replace/search on multiple files and subdirectories : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=373 (3 of 3) [18/02/2004 14:56:06]

SourceForge
Logo

Tip #374 - VIM's Filtering Commands Summary : vim online

not logged in (login)

Home
Search

Tip #374: VIM's Filtering Commands Summary


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 26/15, Viewed by 1383

created: November 24, 2002 14:54


author: zzapper

complexity: basic
as of Vim: 6.0

Vim's Filtering Commands or how to get text into or out


of a file
# Redirection to Paste register * (or any other a-z)
:redir @*
: start redirect commands
to paste buffer
:history
:g/fred/
etc etc
:redir END
: end redirect
# Redirection to a file
:redir >> out.txt
blahblah
:redir END

: redirect to a file
: end redirect

# Storing glob results in register a (note must use


APPEND)
:g/fred/y A
: append all lines fred to
register a
# to a file (must use >>)
:'a,'b g/^Error/ . w >> errors.txt
# Get output from external commands
:r!ls.exe
: reads in output of ls
!!date
: same thing
# Filtering current file using an external command
:%!sort -u
: use an external program
to sort current file
:'a,'b!sort -u
: use an external program
to sort current file
These tips are "filtered" from vimtip #353

rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=374 (1 of 2) [18/02/2004 14:56:09]

Helpful

Unfulfilling

rate

Tip #374 - VIM's Filtering Commands Summary : vim online

<<Run find/replace/search on multiple files and subdirectories | autocmd for skeleton html file
(BufFileNew) >>

Additional Notes
david@tvis.co.uk, November 24, 2002 14:59
Ahem I meant filtered from vimtip #305 of course
Anonymous, November 26, 2002 23:18
to sort the actual paragraph at cursorposition from
normal mode with external sort program (-u deletes
multiple lines):
!1} sort -u
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=374 (2 of 2) [18/02/2004 14:56:09]

SourceForge
Logo

Tip #375 - autocmd for skeleton html file (BufFileNew) : vim online

not logged in (login)

Home
Search

Tip #375: autocmd for skeleton html file (BufFileNew)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 19/7, Viewed by 786

created: November 25, 2002 12:23


author: Dan Allen

complexity: basic
as of Vim: 5.7

How about starting your new html document with a nice shiny skeleton!
Add this in your autocmd section in your .vimrc file
" Start with an html skeleton docuement when opening a new *.html file
au BufNewFile *.html | execute "normal :set ai!\<kEnter>i<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transiti
onal//EN\">\<kEnter><html>\<kEnter> <head>\<kEnter>
<style>\<kEnter>
</style>\<kEnter>
<script>\<kEnte
r>
</script>\<kEnter> </head>\<kEnter> <body>\<kEnter> </body>\<kEnter></html>\<ESC>:set ai\<kEnter>gg"
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<VIM's Filtering Commands Summary | A totally useless tip...or is it ? >>

Additional Notes
bigredlinux at yahoo.com, November 25, 2002 12:26
The tip added endlines where they are not supposed to be...please remove all endlines so that the command list just a single line.
david@tvis.co.uk, November 26, 2002 2:36
Slight Variant (without tabs/spaces)
au BufNewFile *.html | execute "normal
:\<kEnter>i\<html>\<kEnter><head>\<kEnter><title>title</title>\<kEnter><script>\<kEnter></script>\<kEnter></head>\<kEnter><body>\<kEnter></body>\<kEnter></html>\<ESC>gg"
perry.tew cibavision.novartis.com, October 21, 2003 11:59
I added some spaces to make the indentation a little prettier:
au BufNewFile *.html | execute "normal :\<kEnter>i\<html>\<kEnter>
<head>\<kEnter>
<title></title>\<kEnter>
<script
language=\"javascript\">\<kEnter>
</script>\<kEnter>
</head>\<kEnter>
<body>\<kEnter>
</body>\<kEnter></html>\<ESC>gg"
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=375 [18/02/2004 14:56:12]

SourceForge
Logo

Tip #376 - A totally useless tip...or is it ? : vim online

not logged in (login)

Home
Search

Tip #376: A totally useless tip...or is it ?


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/42, Viewed by 2901

created: November 25, 2002 14:27


author: vim_power

complexity: basic
as of Vim: 5.7

Would it not be cool to have your Name listed as part of


a Vim command.
Well If you build your VIM from source , you can do
that.
CD to the source directory and do
./configure --with-compiledby="<Your Name>" <otheroptions>
After building and installing Vim,
Whenever you issue
:version <enter>
You will see your Name in the "compiled by" line.
NJoy.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<autocmd for skeleton html file (BufFileNew) | Microsoft Natural Multimedia Keyboard Scancodes >>

Additional Notes
Anonymous, November 26, 2002 11:09
I'm not sure what the tip is here. I don't add that -compiled-by argument when I compile and I still see my
name in the Compiled by line from the version command.
Anonymous, November 28, 2002 2:00
Yes, you see compiled by user@host... But, with that
tip, you can override this by setting a custom
string...
Add Note

http://www.vim.org/tips/tip.php?tip_id=376 (1 of 2) [18/02/2004 14:56:14]

Tip #376 - A totally useless tip...or is it ? : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=376 (2 of 2) [18/02/2004 14:56:14]

SourceForge
Logo

Tip #377 - Microsoft Natural Multimedia Keyboard Scancodes : vim online

not logged in (login)

Home
Search

Tip #377: Microsoft Natural Multimedia Keyboard Scancodes


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 30/16, Viewed by 1420

created: November 27, 2002 0:55


author: Jeremy Brand, B.S.

complexity: basic
as of Vim: 6.0

I have collected most of the special keys' scancodes on the Microsoft


Natural Multimedia Keyboard. This might be helpful for those of you that do
lots of key-bindings.
http://nirvani.org/docs/Microsoft_natural_multimedia_keyboard_scancodes.html
-Jeremy Brand <jeremy@nirvani.net>
http://nirvani.org/software/vim/

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<A totally useless tip...or is it ? | Auto insert Java class template when editing a new Java file >>

Additional Notes
Anonymous, December 21, 2002 22:57
To actually 'use' the multimedia keys, its usefull to be able to map them
with nmap or something. The easiest/best way to do this is to find the
key's scancode via runing xev and pressing the key, looking at the
scancode output, then doing a
xmodmap -e "keycode 139 = F13"
for example, replacing the 139 with whatever your special multimedia key's
scancode was, and the F13 with whatever key you want, i used the F keys >
13 since my keyboard doesnt have anything above 12, and you can define
upto i think 35 F keys (so i just mapped all my 'multimedia' keys to F13F29 and then maped those F keys in vim to things i wanted to do, or to my
windowmanager to do other stuff)
So thats a method that should work on any keyboard, and doesnt rely on
special propriatary(sp) key layout stuff, but it does take a couple steps
to get your scancodes n such. Here is what my .xinitrc looks like so i
make sure and get all my keys mapped whenever i load X (i just put in the
last lines that do anything, your X file may have some funny startup stuff
it does)
Note the first two lines are me mapping my Caps Lock to the Escape key, so
i dont have to make that horrible reach to the escape key to get outa
whatever mode i am in. If you don want that, just dont have the top two
lines (i just thought a few people might find that of interest)
xmodmap
xmodmap
xmodmap
xmodmap

-e
-e
-e
-e

"remove Lock = Caps_Lock"


"keysym Caps_Lock = Escape"
"keycode 158 = F13"
"keycode 165 = F14"

http://www.vim.org/tips/tip.php?tip_id=377 (1 of 2) [18/02/2004 14:56:17]

Tip #377 - Microsoft Natural Multimedia Keyboard Scancodes : vim online

xmodmap -e "keycode 159


xmodmap -e "keycode 151
xmodmap -e "keycode 164
xmodmap -e "keycode 162
xmodmap -e "keycode 166
xmodmap -e "keycode 233
xmodmap -e "keycode 232
xmodmap -e "keycode 229
xmodmap -e "keycode 121
xmodmap -e "keycode 230
xmodmap -e "keycode 130
xmodmap -e "keycode 236
xmodmap -e "keycode 129
xmodmap -e "keycode 166
xmodmap -e "keycode 164
exec /usr/bin/wmaker

=
=
=
=
=
=
=
=
=
=
=
=
=
=
=

F15"
F16"
F17"
F18"
F19"
F20"
F21"
F22"
F23"
F24"
F25"
F26"
F27"
F28"
F29"

Hope that does someone some good. Again, to find out your scancode key,
run the program
xev
then start hitting keys, and watch as stuff scrolls by, look for the
keypress event as you hit a key, then look for the 'keycode' and thats the
number you want!
- Random contributor you dont care about
Anonymous, December 22, 2002 16:40
With regards to xmodmap, you might find it tidier to put all your mappings
into (e.g.) ~/.xmodmap and then call "xmodmap ~/.xmodmap" from
~/.xinitrc. Also, for those of you using xdm/kdm/gdm instead of
startx/xinit, use ~/.xsession instead of ~/.xinitrc.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=377 (2 of 2) [18/02/2004 14:56:17]

SourceForge
Logo

Tip #378 - Auto insert Java class template when editing a new Java file : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #378: Auto insert Java class template when editing a new Java
file
tip karma

Rating 18/15, Viewed by 1308

created: November 27, 2002 8:50


author: Pete Kazmier

complexity: basic
as of Vim: 6.0

If you are lazy like me, tend to use lengthy and verbose
Java class names, then this tip is for you. When
creating a new Java class file, the first thing that I
do after creating it is to add the following block of
text:
public class ClassName
{
}
Rather than have to type the ClassName twice (once when
you first opened the new file, and then again for this
block), you can use this autocmd to insert that text for
you automatically:
autocmd BufNewFile *.java
\ exe "normal Opublic class " .
"\n{\n}\<Esc>1G"

rate this tip

Life Changing

Helpful

expand('%:t:r') .

Unfulfilling

rate

<<Microsoft Natural Multimedia Keyboard Scancodes | 1,$ s/^M//g gets rid of control-Ms (windows
carriage returns) >>

Additional Notes
vipie @ ulyssis.org, November 27, 2002 17:25
This autocommand generated multiple 'public class..{}'
entries sometimes. I have no idea why...
stelliosk@optushome.com.au, November 27, 2002 19:51

http://www.vim.org/tips/tip.php?tip_id=378 (1 of 3) [18/02/2004 14:56:19]

Tip #378 - Auto insert Java class template when editing a new Java file : vim online

added this to add comments on top, constructor and


comments on bottom - no big deal
autocmd BufNewFile *.java
\ exe "normal O/** " . expand('%:t:r') ".java\n/
\n\npublic class " . expand('%:t:r') .
\ "\n{\n\tpublic " . expand('%:t:r') "(){}\n}\n//" .
expand('%:t:r') ".java \<Esc>1G"
lk1@teamten.com, January 10, 2003 10:27
I use the code below to type in the package
name. Otherwise I often forget to type that in and the
class file goes in the wrong place. It assumes that
the top-level directory is "com", which may be wrong
but I couldn't think of any other way to do it.
autocmd BufNewFile *.java call InsertJavaPackage()
function! InsertJavaPackage()
let dir = getcwd()
let dir = substitute(dir, "^.*\/com\/", "com/", "")
let dir = substitute(dir, "\/", ".", "g")
let dir = "package " . dir . ";"
let result = append(0, "")
let result = append(1, dir)
let filename = expand("%")
let filename = substitute(filename, "\.java", "",
"")
let result = append(2, "")
let result = append(3, "class " . filename . " {")
let result = append(4, "}")
endfunction
bofh@diegeekdie.com, February 12, 2003 5:53

http://www.vim.org/tips/tip.php?tip_id=378 (2 of 3) [18/02/2004 14:56:19]

Tip #378 - Auto insert Java class template when editing a new Java file : vim online

I always have my source code under a src dir and I


often stand in the basedir and open new files with the
correct path, ie:
vi src/se/hogia/innovation/Test.java
So I changed the function to this:
function! InsertJavaPackage()
let filename = expand("%")
let filename = substitute(filename, "\.java$", "",
"")
let
let
let
let

dir
dir
dir
dir

=
=
=
=

getcwd() . "/" . filename


substitute(dir, "^.*\/src\/", "", "")
substitute(dir, "\/[^\/]*$", "", "")
substitute(dir, "\/", ".", "g")

let filename = substitute(filename, "^.*\/", "",


"")
let dir = "package " . dir . ";"
let result = append(0, dir)
let result = append(1, "")
let result = append(2, "class " . filename . " {")
let result = append(4, "}")
endfunction
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=378 (3 of 3) [18/02/2004 14:56:19]

SourceForge
Logo

Tip #379 - 1,$ s/^M//g gets rid of control-Ms (windows carriage returns) : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #379: 1,$ s/^M//g gets rid of control-Ms (windows carriage


returns)
tip karma

Rating 44/31, Viewed by 2529

created: November 27, 2002 23:11


author: bothered by control M

complexity: basic
as of Vim: 5.7

This has got to be in the tips somewhere else, but


darned if I could find it. I had been bothered by the
pesky ^M characters that appeared at the end of lines in
files that were generated in MS Windows -- particulary
appserver log files for me. My new best friend showed
me this regex substitution that gets rid of them:
:1,$ s/^M//g
Note - If I don't have this in the command buffer, I
usually wind up copying and pasting the ^M into the
regex if I'm in windows, since I'm not sure how to type
it from the keyboard (shift 6 followed by capital M
doesn't work). In unix, I can ususally type ctrl-V
followed by Enter to get the ^M.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Auto insert Java class template when editing a new Java file | Using gvim as frontend for dbx >>

Additional Notes
jigho@caramail.com, November 27, 2002 23:46

http://www.vim.org/tips/tip.php?tip_id=379 (1 of 4) [18/02/2004 14:56:21]

Tip #379 - 1,$ s/^M//g gets rid of control-Ms (windows carriage returns) : vim online

I think a proper way to do this is :


:set fileformat=unix
or in short terms:
:set ff=unix
Of course, you can also use it from unix to ms-dos
fileformat :
:set ff=dos
And even to mac format :
:set ff=mac
Have a look at :help fileformat
By the way, ":1,$s/..." can be shortened in ":%s/..."
zzapper@ntlworld.com, November 28, 2002 0:07
The Vim way is
:%s/\r//g
xburgerNOSPAMhout AT freeler DOT nl, November 28, 2002 3:14
You can also add a modeline to the file; this way vim
will keep it in the desired file format no matter what.
Just add this line to the file:
/* vim: set ff=dos: */
feral@firetop.spammerssmell.com, November 28, 2002 13:15
I did not see using $ as part of the pattern so I'll
mention that...
I like to specify a little more exact pattern so I get
rid of only what I think I am getting rid of, so I
append the end of line marker to the end of the
pattern.
I.e.
:%s/^M$//
I.e. only ^Ms at EOL.
:h /$
feral@firetop.spamspamspam.com, November 28, 2002 13:21

http://www.vim.org/tips/tip.php?tip_id=379 (2 of 4) [18/02/2004 14:56:21]

Tip #379 - 1,$ s/^M//g gets rid of control-Ms (windows carriage returns) : vim online

Ways to get ^M:


\r
<c-v>013
<c-v><c-m>
<c-v><enter> (at least on this win2kbox)
I believe as Zzapper mentioned, \r is the best for a :s
pattern; though I often do one of the <c-v> varients :)
salmanhalim@hotmail.com, November 29, 2002 11:10
While tweaking the fileformat may work, it should be
noted that Vim typically figures out the fileformat for
you automatically. A file with \r\n linefeeds only
becomes dos and a file with \n only becomes unix (\r
only becomes mac). However, when a file contains BOTH
\r\n and \n linefeeds, Vim declares it as a UNIX file
and displays the ^M (\r) characters therein in the
normal fashion as they are just another character
inside a Unix file.
salmanhalim@hotmail.com, November 29, 2002 11:12
As an addendum, these mixed-eol files come about from
stuff edited in different editors: some editors only
save the lines actually changed so convert only part of
the file to DOS-style line endings, for example. This
also happens with files generated by user-written
programs if a consistent mechanism for line termination
isn't used.
peter@nospamplease.horza.freeserve.co.uk, December 3, 2002 8:15
on my windows 2000 box ctrl-v is mapped to paste, so I
have to do a ctrl-q ctrl-m to get a ^M.
abuse@127.1.1.1, March 12, 2003 13:09
My 2-cents worth.
You are on Windows(2K), You get a file from someone
that was created/edited on UNIX.
You open it with gVim and its covered with the dreaded
CTL-M ^M control-M chars all over the place.
SOLUTION:
:%s/<ctl-q><ctl-m>/\r/g
WHERE:
<ctl-q> = Press Crtl and Q keys at the same time
<clt-m> = Press Crtl and M keys at the same time

http://www.vim.org/tips/tip.php?tip_id=379 (3 of 4) [18/02/2004 14:56:21]

Tip #379 - 1,$ s/^M//g gets rid of control-Ms (windows carriage returns) : vim online

Explained:
CTL-V is mapped to the Windows PASTE function, so, you
can't invoke [ESC]escape sequence [CTL-V] like you do
in UNIX.
In WINDOWS, the [ESC] is actived by CTL-Q.
The above command will change all the UNIX style
<CR><LF> to the Windows normal behavior.
Hope this helps, it took me about 2 hours of trial and
error and on-line searching to find the answer.
YOU'RE WELCOME! ;-}
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=379 (4 of 4) [18/02/2004 14:56:21]

SourceForge
Logo

Tip #380 - Using gvim as frontend for dbx : vim online

not logged in (login)

Home
Search

Tip #380: Using gvim as frontend for dbx


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/4, Viewed by 915

created: December 2, 2002 5:51


author: Dirk Volkmar

complexity: basic
as of Vim: 6.0

There is a easy, fast way to use gvim as somewhat like a


frontend for the solaris dbx - debugger. Add the
following to your .dbxrc:
alias sc=" gvim --remote +$vlineno $vfile"
when stop { gvim --remote +$vlineno $vfile ;}
Allways the debugger stops it shows you the current
positon in the gvim. My gvim does'nt take the focus, I
dont know why, but so I just can walk through the code.
The sc alias shows the current position and is helpful
after loading the executable to show the start (we
have'nt stopped at this point).
Unfortunately it doesn't work at the first stop after
attaching to a process.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<1,$ s/^M//g gets rid of control-Ms (windows carriage returns) | Running the win32-version of Vim
from cygwin >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=380 [18/02/2004 14:56:24]

SourceForge
Logo

Tip #381 - Running the win32-version of Vim from cygwin : vim online

not logged in (login)

Home
Search

Tip #381: Running the win32-version of Vim from cygwin


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 32/14, Viewed by 1904

created: December 3, 2002 8:40


author: Luc Hermitte

complexity: basic
as of Vim: 5.7

This tip does not only concern Vim, but any native win32
application (NWA) we may want to run from cygwin.
Note: I call a "native win32 application", any program
that has not been specifically compiled to run on
cygwin.
Typical examples are internet explorer, yap, acrobat
reader, ... and of course the win32 version of Vim
available on this site or on
http://cream.sourceforge.net.
The problem with running NWAs from cygwin comes from the
fact that paths in cygwin can be expressed in ways that
NWAs can't understand. Indeed from cygwin, we can also:
- express paths as *nix-like paths ; e.g. /etc/profile
- use paths that, as a matter of fact, are symbolic
links.
So, to come around this issue, here is a shell script
that can be used to define aliases:
http://hermitte.free.fr/cygwin/cyg-wrapper.sh
[More help available on:
http://hermitte.free.fr/cygwin#Win32]
All you have to do is to drop it into one directory from
your $PATH, and define into your .profile something
like:
alias gvim='cyg-wrapper.sh
"C:/Progra~1/Edition/vim/vim61/gvim.exe" -c'
Notes:
- under MsWindows 9x, I had to writte the path to
gvim.exe in the windows short form
- the '-c' is here to tell cyg-wrapper.sh that: when
calling VIM, the parameter following '-c' is not a path.
This enables to write:
gvim -c '/^$/' foo.xxx

http://www.vim.org/tips/tip.php?tip_id=381 (1 of 4) [18/02/2004 14:56:26]

Tip #381 - Running the win32-version of Vim from cygwin : vim online

Regarding the use of *nix-like paths from win32-VIM,


check Johannes Zellner's plugin (cygwin.vim) that will
convert *nix paths into MsWindows paths on file-opening - there are different autocommand to add, but it will
give you the main idea.
Last point, the win32 version of Vim can not expand
paths expressed in the *nix way ;
e.g. ':sp /etc/pr<tab>' won't expand.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using gvim as frontend for dbx | Search and replace in all open buffers >>

Additional Notes
hermitte {at} free {dot} fr, December 3, 2002 9:27
I made a small mistake, I help page is:
http://hermitte.free.fr/cygwin/#Win32
hermitte {at} free {dot} fr, December 4, 2002 8:41
I have just update cyg-wrapper.sh.
Now, you will be able to:
(*) Use absolute paths expressed in the windows
form
>
gvim c:/bar/foo.txt
(*) Use multiple-level of indirections through symbolic
links
>
ln -s foo1 somepath
>
ln -s foo2 foo1
>
...
>
gvim foon
(*) Use symbolic links pointing to absolute paths
expressed in the windows form
>
ln -s foo c:/bar/foo.txt
>
gvim foo
hermitte {at} free {dot} fr, December 5, 2002 10:32

http://www.vim.org/tips/tip.php?tip_id=381 (2 of 4) [18/02/2004 14:56:26]

Tip #381 - Running the win32-version of Vim from cygwin : vim online

Just to announce the ver 2.2 of cyg-wrapper.sh.


It is quicker than the version 1.x, the options are
correctly supported and we can ask for a non forking
program to fork (thanks to Jonathon M. Merz)
The new syntax to use it with gvim is:
alias gvim='cyg-wrapper.sh
"C:/Progra~1/Edition/vim/vim61/gvim.exe"
--binary-opt=-c,--cmd,-T,-t,--servername,--remote-send,-remote-expr
--fork=1'
Check 'cyg-wrapper.sh --help | less' for help.
Note: This version requires cygUtils and more
precisally realpath.exe
hermitte {at} free {dot} fr, December 5, 2002 10:35
Just to announce the ver 2.2 of cyg-wrapper.sh.
It is quicker than the version 1.x, the options are
correctly supported and we can ask for a non forking
program to fork (thanks to Jonathon M. Merz)
The new syntax to use it with gvim is:
alias gvim='cyg-wrapper.sh
"C:/Progra~1/Edition/vim/vim61/gvim.exe"
--binary-opt=-c,--cmd,-T,-t,--servername,--remote-send,-remote-expr
--fork=1'
Check 'cyg-wrapper.sh --help | less' for help.
Note: This version requires cygUtils and more
precisally realpath.exe
Anonymous, December 17, 2002 0:33
> Last point, the win32 version of Vim can not expand
paths expressed in the *nix way ;
> e.g. ':sp /etc/pr<tab>' won't expand.
:help 'shellslash'
hermitte {at} free {dot} fr, February 6, 2003 5:13

http://www.vim.org/tips/tip.php?tip_id=381 (3 of 4) [18/02/2004 14:56:26]

Tip #381 - Running the win32-version of Vim from cygwin : vim online

> > Last point, the win32 version of Vim can not expand
paths expressed in the *nix > > way ; e.g. ':sp
/etc/pr<tab>' won't expand.
> :help 'shellslash'
'shellslash' has almost nothing to do with that
problem.
On Cygwin, "/etc/something" refers in fact to
"c:\Cygwin\etc\something" (assuming Cygwin has been
installed into "c:\Cygwin").
Vim is not able to translate *nix paths into plain
MsWindows paths -- a convertion layer needs to be
introduced if we want to use paths in such form.
Matthias.Morche@szm.de, October 22, 2003 6:00
I've detected a tiny flaw: if You want to use netrw
(eg. gvim scp://somehost/somefile) from the commandline
You loose. Here's the patch to recognise url syntax and
handle it properly:
--- /DownLoad/vim/cyg-wrapper.sh
2003-10-22
14:49:25.084774400 +0200
+++ /opt/bin/cyg-wrapper.sh
2003-10-22
14:55:04.392675200 +0200
@@ -254,6 +254,9 @@
else
ptransl="$1"
fi
+
elif [ `expr "$1" : "[a-z]*://.*"` -gt 0 ] ; then
+
# some netrw protocol like http://host or
ftp://host : leave as is
+
ptransl="$1"
else
# Convert pathname "$1" to absolute path (*nix
form) and resolve
# all the symbolic links
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=381 (4 of 4) [18/02/2004 14:56:26]

SourceForge
Logo

Tip #382 - Search and replace in all open buffers : vim online

not logged in (login)

Home
Search

Tip #382: Search and replace in all open buffers


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 13/4, Viewed by 1709

created: December 4, 2002 16:56


author: Sean

complexity: basic
as of Vim: 6.0

Useful for doing simple refactoring i.e. changing a


method or variable name. Prompts for a word and then
replaces all instances of <cword> in open buffers with
the word.
"-------------------------------------------------------------------------" Search for <cword> and replace with input() in all
open buffers
"-------------------------------------------------------------------------fun! Replace()
let s:word = input("Replace " . expand('<cword>') .
" with:")
:exe 'bufdo! %s/' . expand('<cword>') . '/' . s:word
. '/ge'
:unlet! s:word
endfun
map \r :call Replace()<CR>
Thanks to Jurgen Kraemer for showing me how to use the
:exe command :)
Sean
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Running the win32-version of Vim from cygwin | a Map to jump to a subroutine/function from where
it is called >>

Additional Notes
pottsdl@netzero.net, December 5, 2002 7:41

http://www.vim.org/tips/tip.php?tip_id=382 (1 of 2) [18/02/2004 14:56:28]

Tip #382 - Search and replace in all open buffers : vim online

Two things you need to be careful about here:


1) To actually succeed in changing between files after
they have had changes made
requires that the 'autowrite' option be turned on,
otherwise VIM will fail with an error message
that "changes made have not been saved", and stop the
'bufdo' operation.
2) The other is that bufdo operates on all the
currently loaded buffers (those that may not
currently be open in a window, but not those that are
'unloaded', see help for more detail).
So for instance, you open up a new C file, and you have
a template that gets read into it,
that template is in your buffer list, and will be
subject to your search and replace function.
Great tip, just wanted to help out with any
disclaimers....
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=382 (2 of 2) [18/02/2004 14:56:28]

SourceForge
Logo

Tip #383 - a Map to jump to a subroutine/function from where it is called : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #383: a Map to jump to a subroutine/function from where it is


called
tip karma

Rating 1/6, Viewed by 1117

created: December 6, 2002 4:33


author: zzapper

complexity: basic
as of Vim: 6.0

Hi
When writing/debugging code you often want to jump from
where a subroutine/function is called to where it
actually is . Hitting the "*" key is frustrating if the
sub/func is called many times. The following mapping
solves the problem. (Notice how it can be altered for
other lanaguages)
nmap gx yiw/^\(sub\<bar>function\)\s\+<C-R>"<CR>
Instructions: place cursor over called function (normal
mode) and type gx
How it works:
yiw : Yank inner work to un-named register
/^\(sub\<bar>function\)\s\+ : search for sub or
function followed by 1 or more spaces
<C-R>" : Retrieve un-named register
<CR> : Start Search
(also included in vimtip #305 )

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Search and replace in all open buffers | Easily switch between source and header file >>

Additional Notes
Anonymous, December 6, 2002 9:02
Take a look at :help tags-and-searches
Anonymous, December 16, 2002 23:33
http://www.vim.org/tips/tip.php?tip_id=383 (1 of 2) [18/02/2004 14:56:31]

Tip #383 - a Map to jump to a subroutine/function from where it is called : vim online

g]
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=383 (2 of 2) [18/02/2004 14:56:31]

SourceForge
Logo

Tip #384 - Easily switch between source and header file : vim online

not logged in (login)

Home
Search

Tip #384: Easily switch between source and header file


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 29/14, Viewed by 2133

created: December 6, 2002 15:26


author: bubbleboy

complexity: intermediate
as of Vim: 5.7

To switch between header and source files very quickly,


all you need to do is add a few key mappings in your
filetype plugin files. Let me explain with an example:
Let's say that you're editing C files, so all you would
have to do is edit your ftplugin/c_extra.vim file and
include
nmap ,s :find %:t:r.c<cr>
nmap ,S :sf %:t:r.c<cr>
to switch to the corresponding source file, and
nmap ,h :find %:t:r.h<cr>
nmap ,H :sf %:t:r.h<cr>
to switch to the corresponding header file.
The built-in 'find' command will search (recursively or
not) for the specified file anywhere in your vim 'path'
setting. The 'sf' is short for split-find, meaning that
if vim finds your file it will open it in a split
window. Simply add the 'vert' keyword before 'sf' if you
want a vertical split.
See these help pages for a full description of these
built-in features:
help expand
# for a description of the %, :t, :r
expansion
help find
# for a description of the 'find' and 'sf'
features
help ftplugin
# for a description of how filetype
plugins work
help path
# for a description of how the path setting
works
This method is also highly configurable. All you have to
do is change the 'path' setting when switching to

http://www.vim.org/tips/tip.php?tip_id=384 (1 of 3) [18/02/2004 14:56:33]

Tip #384 - Easily switch between source and header file : vim online

different projects, and modify the corresponding


filetype plugin to support other languages.
This tip is very similar to vimscript #31 by Mike
Sharpe, however this method only takes a few lines, and
his script spans several pages!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<a Map to jump to a subroutine/function from where it is called | some java & vim tips >>

Additional Notes
salmanhalim@hotmail.com, December 6, 2002 22:11
Two things:
1) The mappings should be made buffer-specific with a
<buffer> modifier.
2) If you use an if clause in your ftplugin/c.vim file
(that checks to see if the current file ends in a .h or
.c), you might be able to use the same mapping to go to
the .h file if you're editing the .c and vice
versa. You could easily map the sequence to a simple
function that does a variation of expand("%") (with a
modification flag) to extract the extension. . .
Anonymous, December 9, 2002 7:52
Since nobody mentioned it so far, I will do
it: vimscript #31 (a.vim) provides
exectly the functionality you mentioned and can be
configured for various
filetypes (not only C/Cpp).
bubbleboy, December 9, 2002 10:35
My my... do we have an urge to over-complicate things?
=D I think the <buffer> idea is a good one, but adding
a function to first inspect the suffix seems to be of
little benefit. The idea here is simplicity!
One reason this idea is better than vimscript #31
(IMHO) is because additional file types can be added
with very little effort and without modification to the
original script (a.vim). Also it's 10,000% shorter. ;-D
anonymous, December 10, 2002 6:03

http://www.vim.org/tips/tip.php?tip_id=384 (2 of 3) [18/02/2004 14:56:33]

Tip #384 - Easily switch between source and header file : vim online

A few notes :)
1) :find foo.c when foo.c does not exist can be a
rather long time consuming search, particularly when
foo.c does not exist. vimscript #31 does not have this
problem. And if foo.c does not exist the switch still
works...you do not get the E345 error message.
2) vimscript #31 works with multiple extensions, C,
C++, ada etc, can be configured for more without
editing the script. Read some of the comments in the
10000 line file :)
3) vimscript #31 works with different extension styles
.C .cxx .cpp .CPP .cc <--> .h .hpp .H .HPP all at the
same time. :A will switch between any of the source
extensions to any of the header extensions. Different
extension styles are sadly common in large projects.
4) 10000 lines?? less than 200 once comments are
stripped and utility functions could be moved to a
common.vim for reuse if size is an issue.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=384 (3 of 3) [18/02/2004 14:56:33]

SourceForge
Logo

Tip #385 - some java & vim tips : vim online

not logged in (login)

Home
Search

Tip #385: some java & vim tips


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 96/30, Viewed by 3654

created: December 9, 2002 7:38


author: demian l neidetcher

complexity: intermediate
as of Vim: 6.0

i started to aggregate some java & vim tips (in part because i easily forget stuff). they're the
kind of tips that are a little elusive but deliver a big bang for their effort; like actually
getting quickfix to work with java, using ctags with java, etc....
http://www.ophinity.com/papers/jim/index.html
...on that note, i wonder if vim.org should start organizing tips and scripts into areas of
interest or perhaps cross-indexing? some things that come to mind are document generation (tex/
latex), oracle/ db integration, java development, c/ c++ coding, win32 issues, etc...
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Easily switch between source and header file | Cut/copy and paste using visual selection >>

Additional Notes
bubbleboy, December 9, 2002 11:45
You can avoid using
autocmd BufRead *.java ...
commands by using filetype plugins. See :help filetype. These files will be sourced only when
opening a source file of the corresponding file type.
maxiangjiang@hotmail.com, December 9, 2002 16:53
I found using jikes is 10x faster than javac!
rvijay2001@hotmail.com, December 12, 2002 18:12
Thank you! Thank you!
If only there was a way to debug java from within Vim.
http://www.vim.org/tips/tip.php?tip_id=385 (1 of 6) [18/02/2004 14:56:36]

I would never have to leave the editor.

Tip #385 - some java & vim tips : vim online

gmann@femto.med.unc.edu, December 14, 2002 20:22


Wondering if others are having luck with the quickfix stuff on Win2000? Almost everything works
except going to the error after building. I can do :clist to get all errors and the ant printout
exists but all javac stuff is missing, which means it is filtering javac comments/errors but not
returning them to buffer. Any pointers?
love@vim.org, December 16, 2002 20:58
Try the following:
if executable("jikes") || executable("jikes.exe")
let&l:errorformat='%f:%l:%v:%*\d:%*\d:%*\s%m'
nn<silent><buffer> [1
\:let&l:mp='jikes -nowarn -d <C-R>=$cp<CR> -Xstdout +E %:t'<CR>
elseif executable("javac") || executable("javac.exe")
let&l:errorformat='%A%f:%l:%m,%-Z%p^,%-C%.%#'
nn<silent><buffer> [1 :let&l:mp='javac -d <C-R>=$cp<CR> %:t'<CR>
endif
gmann@femto.med.unc.edu, December 17, 2002 17:59
Sorry, I failed to mention I was using Ant.

I am wondering if another plugin is messing with me.

bane@uchicago.edu, December 18, 2002 16:54


Nice page of tips.
One problem, your gc mapping doesn't really work, because gd depends on [[ (:help gd; :help [[),
which only finds the beginning of a function if you put your opening curly braces on a line of
their own. Many people don't.
i.e., it will work in functions like this:
public void function(String args)
{
function code
....
}
but not in functions like this:
public void function(String args) {
function code
....
}
So basically you'll get something totally wrong if your instance variable name occurs anywhere
before the function.
I'm a vim newbie, so I'm still working on coming up with a mapping that works in both cases.
ideas?
http://www.vim.org/tips/tip.php?tip_id=385 (2 of 6) [18/02/2004 14:56:36]

Any

Tip #385 - some java & vim tips : vim online

etarun AT blr DOT cognizant DOT com, January 7, 2003 2:58


Add a quick tip on navigation as well. I only recently found out that [m
and ]m goes to end of method

goes to start of method

Thanks,
Tarun
jonbo372@student.liu.se, January 17, 2003 13:01
Hi all!
I have been reading all the tips about making quickfix work but there is something that I miss. I
use ant 1.5.1, vim 6.1 and javac (yes its slow i know)
i have the following line in my .vimrc file
set makeprg=ant\ -emacs\ -q\ -find\ build.xml\
I read somewhere that if you use the -emacs option you would not have to mess with the
errorformat. but guess what, it does not work. it will give me zero erros. however, if i have ant
dump the stuff to a file it clearly shows that there are errors in the file. the dump looks like
this:
C:\private\programmering\test of ant\src\HelloWorld.java:17: ';' expected
t.foo()
^
C:\private\programmering\test of ant\src\HelloWorld.java:19: cannot resolve symbol
symbol : variable f
location: class HelloWorld
f.doSomething();
^
2 errors
BUILD FAILED
file:C:/private/programmering/test of ant/build.xml:18: Compile failed; see the compiler error
output for details.
Total time: 2 seconds
so why doesnt these errors show up when i do clist???
i have also tried not using the -q and -emacs option with the following errorformat
set efm=%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
when compiling it will report lots of errors but no real ones. it will falsely report the
following:
1: Searching for build.xml ...
2: Buildfile: c:\private\programmering\test of ant\build.xml
3:
http://www.vim.org/tips/tip.php?tip_id=385 (3 of 6) [18/02/2004 14:56:36]

Tip #385 - some java & vim tips : vim online

4: init:
5:
6: compile:
7: [javac] Compiling 1 source file to c:\private\programmering\test of ant\build
and thats it... no mention about the real errors...
btw, im running xp but i have been trying it on win2k as well.
could someone please tell me what im doing wrong...
Thanks,
Jonas
peterderooij@yahoo.com, February 4, 2003 8:03
Hi,
on the problem of making the quickfix work on Win2000 (or XP):
I had the problem mentioned by Jonas, and setting
set shellpipe=>%s\ 2>&1
fixed it. (Note that this is the value for shellredirect.)
Cheers, Peter
clamey@infonow.com, October 30, 2003 14:04
Another useful Java setup I use is to build a tags file for the source code of the JDK and have
vim use it. The JDK source code can be downloaded from Sun.
Then I build two tag files, one for my project, one for the JDK:
pushd $HOME
ctags -f jdk_tags -R $JAVA_HOME/src
ctags -f proj_tags --exclude=CVS -R $PROJ_HOME/com $PROJ_HOME/webapps
popd
In .vimrc, I tell Vim to use the JDK tags first, then my Project:
set tags=$HOME/jdk_tags,$HOME/proj_tags
This is useful when using tags for completions, along with tagjumping for definitions (and see
how things are implemented by Sun).
Along with this, I use the dictionary keyword completion on a per-buffertype basis and the smart
tab completion metioned on the above webpage.
My completion is set like so:
set cpt=k,.,w,b,u,t,i
http://www.vim.org/tips/tip.php?tip_id=385 (4 of 6) [18/02/2004 14:56:36]

Tip #385 - some java & vim tips : vim online

Which means that when I start to type something and hit <tab>, it will essentially first go
through the Java keywords, then the JDK source, then my project source.
These are also helpful Java settings:
" Highlight functions using Java style
let java_highlight_functions="style"
" Don't flag C++ keywords as errors
let java_allow_cpp_keywords=1
And this abbreviation is cool as well:
iab ff for (Iterator i =; i.hasNext())
{<LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT><LEFT>
clamey@infonow.com, October 30, 2003 15:37
At some point along the way, Vim included an ant.vim compiller script that does the set
makeprg/errorformat for ant and javac, respectively. It can be enabled like this:
:compiler ant
Unfortunately, this seems to not persist through buffers during the quick fix mode.
do this:

So you can

:au BufReadPost *.java exe ":compiler ant"


Which will do a :compiler ant on every buffer reading in a .java file.
For me, because I need to pass in some extra args to ant every time I compile, I defined a
function with those arguments:
function! BuildJar(jarname)
exe "make -Dtarget=jar -Dversion=DEV ".a:jarname
endfunction
And then defined a command to run it:
:command -nargs=1 Ant :call BuildJar(<f-args>)
And then an abbreviation because I don't want to have to type 'Ant' all the time.
:cab ant Ant
So in Vim I do this:
:ant target
And it runs ant with my args in quick fix mode.
http://www.vim.org/tips/tip.php?tip_id=385 (5 of 6) [18/02/2004 14:56:36]

Tip #385 - some java & vim tips : vim online


Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=385 (6 of 6) [18/02/2004 14:56:36]

SourceForge
Logo

Tip #386 - Cut/copy and paste using visual selection : vim online

not logged in (login)

Home
Search

Tip #386: Cut/copy and paste using visual selection


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 410/153, Viewed by 6319

created: December 9, 2002 18:49


author: rainbrot

complexity: basic
as of Vim: 5.7

Visual selection, although common in applications today,


is a key feature that differentiates vim from
traditional vi.
To cut (or copy) and paste using visual selection:
1. Position the cursor at the beginning of the text you
want to cut/copy.
2. Press v to begin character-based visual selection (or
upper case V to select whole lines, or Ctrl-V for a
vertical block).
3. Move the cursor to the end of the text to be
cut/copied. (While selecting text, you can perform
searches and other advanced movement, a feature that
sets vim apart from most other editors.)
4. Press d (as in "delete") to cut, or y (as in "yank",
which I imagine meaning "yank so hard and fast that it
leaves a copy behind") to copy.
5. Move the cursor to the desired paste location.
6. Press p to paste after the cursor, or P to paste
before.
In gvim, visual marking (steps 1-3) can be replaced by
selecting text using a mouse or similar pointing device,
although I strongly prefer to navigate using the
keyboard.
Bonus tip: To replace the selected text with new text
(to be entered by you), press 'c' instead of 'd' or 'p'
on step 4. This deletes the selection and leaves you in
insert mode. Then, instead of (or prior to) steps 5-6,
type your replacement text.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<some java & vim tips | A way to quickly prefix a char(or chars) to a parameter list, via :s >>

http://www.vim.org/tips/tip.php?tip_id=386 (1 of 4) [18/02/2004 14:56:39]

Tip #386 - Cut/copy and paste using visual selection : vim online

Additional Notes
Anonymous, December 9, 2002 23:15
If you just want to copy (yank) the visually marked
text, you do not need to 'y'ank it. Marking it will
already copy it.
Using a mouse, you can insert it at another position by
clicking the middle mouse button.
This also works in across vim applications on Windows
systems (clipboard is inserted)
:-))
niklas, December 10, 2002 12:01
This is a really useful thing in Vim. I feel lost
without it in any other editor. I have some more points
I'd like to add to this tip:
* While in (any of the three) Visual mode(s), pressing
'o' will move the cursor to the opposite end of the
selection. In Visual Block mode, you can also press
'O', allowing you to position the cursor in any of the
four corners.
* If you have some yanked text, pressing 'p' or 'P'
while in Visual mode will replace the selected text
with the already yanked text. (After this, the
previously selected text will be yanked.)
* Press 'gv' in Normal mode to restore your previous
selection.
* It's really worth it to check out the register
functionality in Vim: ':help registers'.
* If you're still eager to use the mouse-juggling
middle-mouse trick of common unix copy-n-paste, or are
into bending space and time with i_CTRL-R<reg>,
consider checking out ':set paste' and ':set
pastetoggle'. (Or in the latter case, try with i_CTRLR_CTRL-O..)
(Btw - of course I never actually feel lost: I never
use any other editor. ;)
Anonymous, July 5, 2003 11:52

http://www.vim.org/tips/tip.php?tip_id=386 (2 of 4) [18/02/2004 14:56:39]

Tip #386 - Cut/copy and paste using visual selection : vim online

You can replace a set of text in a visual block very


easily by selecting a block, press c and then make
changes to the first line. Pressing <esc> twice
replaces all the text of the original selection.
See *v_b_c*
foo@bar.com, August 15, 2003 12:43
I would really like to know how I can replace one block
of text with another block of text. For example, I
want to copy this (which I know how to do):
abc
123
xyx
into this:
11111111
22222222
3333333
44444444
55555555
so that it looks like this:
11111111
22abc222
3312333
44xyz444
55555555
Using the visual yank and put described above will not
allow me to copy an arbitrary selection into a new
visual region. This would be really useful to me
(especially right now)
temp001@sigfpe.com, September 13, 2003 9:43
Visual marking is broken out-of-the-box with recent
vims (>6.0). Maybe someone can post some details on how
to repair it by adding some stuff to my .vimrc. I would
use the docs but since I last downloaded vim so many
other things have been broken that I'm still working on
them and the docs are pretty hard to navigate. What has
happened to my dearly beloved vim?
Anonymous, December 14, 2003 18:43
did you try ctrl + q for visual block?

http://www.vim.org/tips/tip.php?tip_id=386 (3 of 4) [18/02/2004 14:56:39]

Tip #386 - Cut/copy and paste using visual selection : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=386 (4 of 4) [18/02/2004 14:56:39]

SourceForge
Logo

Tip #387 - A way to quickly prefix a char(or chars) to a parameter list, via :s : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #387: A way to quickly prefix a char(or chars) to a parameter list,


via :s
tip karma

Rating 0/2, Viewed by 755

created: December 13, 2002 1:10


author: feral@firetop.spammersgetthefilter.com

complexity: basic
as of Vim: 6.0

This is a way to quickly prefix a char(or chars) to a


parameter list, via :s
In the thought that others may like the same preferred
style as I, here is an
easy way to prefix each param with an underscore.
The command:
:s/\<\(\I\i*\s\{-}[,)]\)/_\1/g
A sample menu entry:
amenu Fe&ral's.Prefix\ underscores\ to\
params
<Esc><Esc>:s/\<\(\I\i*\s\{-}[,)]\)/_\1/g
<bar> :noh<CR>
An Example:
Before:
BOOL CSomeView::Create(DWORD dwStyle, const RECT& rect,
CWnd* pParentWnd, UINT nID)
After:
BOOL CSomeView::Create(DWORD _dwStyle, const RECT&
_rect, CWnd* _pParentWnd, UINT _nID)
Happy VIMing :)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Cut/copy and paste using visual selection | Insert C++, LaTeX, and other comments easily >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=387 (1 of 2) [18/02/2004 14:56:41]

Tip #387 - A way to quickly prefix a char(or chars) to a parameter list, via :s : vim online

Anonymous, January 2, 2003 13:20


Tip should not be "basic" user level, intermediate
(requires, IMO, slightly more than basic knowledge of
regex, and s/ command). To average newbie, looks like
alphabet soup (I just asked one! she had to hit the
books, and when she came back, she was
"intermediate"... all that for just one tip!).
Thx, useful tho!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=387 (2 of 2) [18/02/2004 14:56:41]

SourceForge
Logo

Tip #388 - Insert C++, LaTeX, and other comments easily : vim online

not logged in (login)

Home
Search

Tip #388: Insert C++, LaTeX, and other comments easily


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 103/48, Viewed by 2975

created: December 16, 2002 4:40


author: Pavel

complexity: basic
as of Vim: 6.0

Visual selection combined with powerful replace (:s)


command can be used for fast inserting C++ (//), LaTeX
(%), and other comments at the beginning of a block of
lines.
If you have, for example, paragraph in a LaTeX file and
you want to comment it (so that it does not appear in
the output anymore), then you have to insert the percent
sign '%' at the beginning of every line. An easy way to
do this is to select visually the block of text, press
':' for entering a vim command (which automatically
expands to :'<,'>) and to use substitute
s/^/%/
The whole command then looks like
:'<,'>s/^/<your comment here>/
So just press enter and the comment will be inserted at
the beginning of all the selected lines.
If you want to delete it later, just use column blocks
(Control-V starts blockwise visual selection) to select
first column(s) and d to delete them.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<A way to quickly prefix a char(or chars) to a parameter list, via :s | search only in unfold text(intend
to work with diff) >>

Additional Notes
SBrueggemann<somewhere at>gmx.net, December 16, 2002 8:03

http://www.vim.org/tips/tip.php?tip_id=388 (1 of 2) [18/02/2004 14:56:43]

Tip #388 - Insert C++, LaTeX, and other comments easily : vim online

Have a look at vimtip #194.


vim@affenmann.de, December 18, 2002 3:18
Another way to do the same thing goes as follows:
Mark the area which is to be commented using the
*blockwise* visual mode (CTRL-V, in Windows this is
CTRL-Q). Then press I (capital i) and write the text
you want to prepend to each line of the selected block,
e.g. %. Then press ESC and the text will be inserted to
the left of each line of the selected block.
This also works to insert something in the middle of
the line, though I mostly use it to add LaTex comments.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=388 (2 of 2) [18/02/2004 14:56:43]

SourceForge
Logo

Tip #389 - search only in unfold text(intend to work with diff) : vim online

not logged in (login)

Home
Search

Tip #389: search only in unfold text(intend to work with diff)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/0, Viewed by 693

created: December 17, 2002 12:56


author: Demai Ni

complexity: basic
as of Vim: 6.0

hi,
sometimes I would like to search/replace the code in the
latest version. That is when I show diff between two
version of code, I would like to only search the unfold.
The following function may do the replace job:
function Foldrepl(spattern, tpattern)
normal gg
"go to top of the file
if &diff
"need to change fold option for
diff
exec "set diffopt=context:0"
endif
"echo a:spattern
"echo a:tpattern
let mycount =0
while search(a:spattern, "W") > 0 "find the search
pattern
if foldlevel(line(".")) < 1
"not in flod
exec "s/".a:spattern."/".a:tpattern."/g"
let mycount = mycount + 1
endif
endwhile
if &diff
"need to restore fold option,
mine is 4
set diffopt=context:4
endif
echo mycount ." lines are changed"
endfunction
It can be changed to do the search job or both
Demai
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=389 (1 of 2) [18/02/2004 14:56:46]

Helpful

Unfulfilling

rate

Tip #389 - search only in unfold text(intend to work with diff) : vim online

<<Insert C++, LaTeX, and other comments easily | combining vimdiff with cvs diff >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=389 (2 of 2) [18/02/2004 14:56:46]

SourceForge
Logo

Tip #390 - combining vimdiff with cvs diff : vim online

not logged in (login)

Home
Search

Tip #390: combining vimdiff with cvs diff


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/5, Viewed by 1739

created: December 18, 2002 5:17


author: Jens Finkhuser

complexity: basic
as of Vim: 6.0

i like using vim's diff mode for comparing different revisions of source code files. usually
older versions do not live in the directory structure with the current versions, but in a cvs
repository. the command below, CVSdiff, can compare the current file to any given revision
number in the cvs repository. please note that in case a revision number does not exist, empty
files will be displayed, as the below script does not do any error checking (yep, i'm lazy, and
this works for me). a vertical split is performed on the current file and its given previous
revision.
command -nargs=1 CVSdiff silent call CVSdiff("%", "<args>")
function! CVSdiff(filename, cvsversion)
" append a:filename to keep extension and therefore highlighting mode
let patchname = tempname() . a:filename
let tempname = tempname() . a:filename
let newname
= tempname() . a:filename
execute "!cvs diff -a -r " . a:cvsversion . " " . a:filename . " > " . patch
execute "!cp " . a:filename . " " . tempname
execute "!patch -R -o " . newname . " " . tempname . " < " . patchname
execute "vertical diffsplit " . newname
call delete(patchname)
call delete(tempname)
call delete(newname)
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<search only in unfold text(intend to work with diff) | Simple programmers TODO list using grep and quickfix >>

Additional Notes
xburgerhout@nospamplease.freeler.nl, December 18, 2002 5:53
http://www.vim.org/tips/tip.php?tip_id=390 (1 of 2) [18/02/2004 14:56:48]

Tip #390 - combining vimdiff with cvs diff : vim online

Take a look at vimscript #58, I find it very useful.


sgovindachar, December 18, 2002 8:21
I use vimscript#90 (cvscommand.vim)
srinirao@amplewave.com, November 24, 2003 2:38
Hi, Do you have a VIM plugin/script/TIP for mergeing CVS files ? I am looking for one, please
give me some pointers. Thanks Srini...
winfred@itri.org.tw, January 2, 2004 4:35
FYI,
there is an little error of this tip, and I believe it is just a typo.
line 7:
execute "!cvs diff -a -r " . a:cvsversion . " " . a:filename . " > " . patch
'patch' should be corrected into 'patchname'.
BTW,
I myself recommand <a
href="vimscript#90</a>">http://www.vim.org/scripts/script.php?script_id=90">vimscript#90</a>;,
too. :)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=390 (2 of 2) [18/02/2004 14:56:48]

SourceForge
Logo

Tip #391 - Simple programmers TODO list using grep and quickfix : vim online

not logged in (login)

Home
Search

Tip #391: Simple programmers TODO list using grep and quickfix
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 35/21, Viewed by 2669

created: December 19, 2002 13:25


author: Sean

complexity: basic
as of Vim: 6.0

I use this to maintain a TODO list for projects I am


working on. All my projects are pretty small scale with
each project stored in it's own directory so this tip
was writtten with that in mind. Basically it is two
keymappings one which inserts
//TODO_ITEM
leaving Vim in insert mode so you can add a note to help
you remember what you wanted to do ;)
The other mapping uses :grep to search for all
occurrences of TODO_ITEM in files in the current
directory excluding ~ files and then opens the error
window displaying the list of TODO_ITEMs.
imap \q <ESC>i//TODO_ITEM<SPACE>
map \q i//TODO_ITEM<SPACE>
imap \w <ESC>:grep --exclude=*~ TODO_ITEM * <CR> :copen
<CR>
map \w :grep --exclude=*~ TODO_ITEM * <CR> :copen <CR>
Change the comment style to suit your language and the
lame keymappings to something better.
Sean
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<combining vimdiff with cvs diff | fileencodings: how to make it work correctly? >>

Additional Notes
alec aaattttt korn dddotttt ch, December 29, 2002 19:10

http://www.vim.org/tips/tip.php?tip_id=391 (1 of 2) [18/02/2004 14:56:50]

Tip #391 - Simple programmers TODO list using grep and quickfix : vim online

This is a bit of self-advertising, but I develop in


exactly the same fashion (ie. one project per
directory) and developed a program to do exactly this,
called devtodo (http://devtodo.sf.net).
Anonymous, January 13, 2003 2:51
Be sure to have 'grepprg=grep -n', because vim needs
the line numbers.
Thomas, January 13, 2003 2:54
You can do this 'quickfix' search for any word under
the cursor:
" grep for word under cursor in c/cpp/h-files
map <F9> <ESC>:exec("grep ".expand("<cword>")."
../*/*.c* ../*/*.h")<CR>
"same as menu entry:
22amenu Search.Grep\ for\ word\ under\ cursor
<ESC>:exec("grep ".expand("<cword>")." ../*/*.c*
../*/*.h")<CR>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=391 (2 of 2) [18/02/2004 14:56:50]

SourceForge
Logo

Tip #392 - fileencodings: how to make it work correctly? : vim online

not logged in (login)

Home
Search

Tip #392: fileencodings: how to make it work correctly?


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -25/29, Viewed by 1241

created: December 30, 2002 6:21


author: newbie

complexity: basic
as of Vim: 5.7

For 6.0+, we have 'encoding', 'fileencoding', and


'fileencodings'.
If I work with Big5(Taiwan), sjis(Japan), ucs-bom, utf8, and plain ASCII (latin1),
how should I set the *encoding options?
I've tried several cases and finally got something like
below:
set fileencodings=plain,ucs-bom,utf-8,big5,sjis
This works fine with loading files.
(The order is important. If you put big5/sjis befure ucsbom/utf-8,
the unicode family will never be used)
But if I start editing a plain ASCII file (which will
set fileencoding
to latin1) and then entered some non-ASCII characters
which is
in unicode, big5, or sjis, then trying to write the file
out will get
an error message like "XXX write error, conversion
failed"
Is there a better (or correct) way to set fileencodings
so that it
will detect multiple charsets, and to write out in
correct manner?
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Simple programmers TODO list using grep and quickfix | PCRE search and replace (Perl
Compatible Regular Expressions) >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=392 (1 of 2) [18/02/2004 14:56:53]

Tip #392 - fileencodings: how to make it work correctly? : vim online

Anonymous, December 30, 2002 14:31


Ask such questions in comp.editors (newsgroup) or
vim@vim.org (mailing list). This is a *tips* database.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=392 (2 of 2) [18/02/2004 14:56:53]

SourceForge
Logo

Tip #393 - PCRE search and replace (Perl Compatible Regular Expressions) : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #393: PCRE search and replace (Perl Compatible Regular


Expressions)
tip karma

Rating 96/34, Viewed by 2802

created: December 30, 2002 8:16


author: Anonymous

complexity: intermediate
as of Vim: 5.7

1. Verify in :ver that +perl or +perl/dyn is compiled


in.
2. Install Perl if necessary. On Windows, ActivePerl is
required.
3. Type :perldo s/searchme/replaceme/g
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<fileencodings: how to make it work correctly? | pop up menu for checking the meaning of the word
from internet >>

Additional Notes
ned@bike-nomad.com, December 31, 2002 10:11
Or if you have ruby compiled in (look for +ruby in :ver
output):
:rubydo sub! /pattern/,'replacement'
detlef@lindenthal.com, January 5, 2003 10:41
What are the advantages compared with this:
:1,$s/searchexpression/replaceexpression/gc ?
That now you can have the exact syntax of perl
regex?
myrddin@cwpn.org, January 7, 2003 11:26
The advantage is that when you know Perl regex well its
easier to write Perl regex than vi regex. Either is
find for simple expressions, but when the expressions
get more complex its much easier to work with the
syntax you know the best.
vimtips@iamafreeman.com, January 11, 2003 15:59
http://www.vim.org/tips/tip.php?tip_id=393 (1 of 3) [18/02/2004 14:56:55]

Tip #393 - PCRE search and replace (Perl Compatible Regular Expressions) : vim online

one advantage is that perl isn't stuck with / as a


separator
s|http://www.example.com/|http://cheese.com/|g
works and is clearer that a bunch of dogs teeth \/ \/
hari_vim at yahoo dot com, January 11, 2003 20:47
Vim has this feature too. You can have any character as
separator.
webmaster@topfx.com, February 21, 2003 18:07
Perl regexes also have a different set of "special
characters"
For example, the brackets () are special characters
that automatically do grouping and capturing in
perl. In a vi regex, they need to be escaped \( \)
before they'll turn special.
Again as another poster mentioned, whatever you're most
intimate with probably gives you a bit more power.
Anonymous, March 21, 2003 9:40
Does anyone know if there's an easier way to do perl
based filtering of lines?
I do it like this:
%!perl -ne "print if (/searchstring/)"
t.goedderz@gmx.net, May 17, 2003 9:45
PCRE are much more powerful and faster than POSIX
compatible, like used in vi (afaik). Just take a look
at perlre [1].
[1] http://perldoc.com/perl5.8.0/pod/perlre.html
brons_vim@rinspin.com, August 19, 2003 19:35
OK, this RULES! Trying to remember the differences
between vi REs and perl REs drives me nuts. vi REs are
so chunky and inconsistent (like * vs. \+).
Is there any way of turning on perldo by default?
like to use perl REs everywhere!
admin@aik4ever.com, January 24, 2004 16:08
Skellefte AIK Sux!
Add Note

http://www.vim.org/tips/tip.php?tip_id=393 (2 of 3) [18/02/2004 14:56:55]

I'd

Tip #393 - PCRE search and replace (Perl Compatible Regular Expressions) : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=393 (3 of 3) [18/02/2004 14:56:55]

SourceForge
Logo

Tip #394 - pop up menu for checking the meaning of the word from internet : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #394: pop up menu for checking the meaning of the word from
internet
tip karma

Rating 25/11, Viewed by 2502

created: January 2, 2003 20:45


author: xiangjiang

complexity: basic
as of Vim: 6.0

To check the meaning of the word under the cursor, right


click
mouse, and choose Dic. Either IE or mozilla will be
opened
and dictionary service offered by www.m-w.com will be
ready.
Following is the map:
To open mozilla
nme <silent> PopUp.&Dic :sil! !start
C:/Progra~1/mozilla.org/Mozilla/mozilla -nosplash
"http://www.m-w.com/cgibin/dictionary?book=Dictionary&va=<cword>"<CR>;
To open internet explorer:
nme <silent> PopUp.&Dic :sil! !start iexplore -nohome
"http://www.m-w.com/cgibin/dictionary?book=Dictionary&va=<cword>"<CR>;
This is tested for gvim.exe on windows 2000
professional.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<PCRE search and replace (Perl Compatible Regular Expressions) | visual marks >>

Additional Notes
mark.thomas@bigswamp.org, January 3, 2003 1:55
http://www.vim.org/tips/tip.php?tip_id=394 (1 of 4) [18/02/2004 14:56:58]

Tip #394 - pop up menu for checking the meaning of the word from internet : vim online

Although ':sil! !start notepad' works on my system (XP


Pro), ':sil! !start iexplore' does not. I used this
instead:
nme <silent> PopUp.&Dic :sil! !start "C:\Program
Files\Internet Explorer\iexplore.exe" -nohome
"http://www.m-w.com/cgi-bin/dictionary?
book=Dictionary&va=<cword>"<CR>;
Fantastic idea. Thanks.
-Mark
maxiangjiang@hotmail.com, January 7, 2003 16:47
Want to search Google for cWORD under the cursor?
(Both normal and visual maps were tested on windows
2000 professional)
nm gF vviWgF
vn<silent> gF y:sil! !start
C:/progra~1/intern~1/iexplore.exe -nohome
http://www.google.com/search?hl=en&q=<C-R>0<CR>;

maxiangjiang@hotmail.com, January 7, 2003 16:53


Another one, just open stand URL under the cursor:
For example: http://vim.sourceforge.net
ftp://ftp.vim.org/pub/vim/patches/README
(Both normal and visual maps were tested on windows
2000 professional)
nm gF viWgF
vn<silent> gF y:sil! !start
C:/progra~1/intern~1/iexplore.exe <CR>=escape(@0,"#%")<CR><CR>

maxiangjiang@hotmail.com, January 7, 2003 17:24

http://www.vim.org/tips/tip.php?tip_id=394 (2 of 4) [18/02/2004 14:56:58]

Tip #394 - pop up menu for checking the meaning of the word from internet : vim online

Another cute one:


Open Windows Explorer on the current working directory
from within gvim:
right click the mouse, and choose Explorer or hit "e"
nme <silent> PopUp.&Explorer :sil! !start
C:/progra~1/intern~1/iexplore.exe -nohome -e "<CR>=getcwd()<CR>"<CR>
Anonymous, January 7, 2003 23:29
Using internet explorer with leo (german<->english):
nme <silent> PopUp.&Dic :sil! !start
"c:\programme\Internet explorer\iexplore.exe" -nohome
"http://dict.leo.org/?search=<cword>"<CR>;
tnx for the tip !
Thomas
Anonymous, January 9, 2003 8:56
Is there a secret to making this work on Linux/UNIX?
dholmes@jccc.net, January 23, 2003 7:48
Since we Linux users use our right click to highlight
large blocks of text, this might be helpful to some.
I you are using gvim, you could just add a menu in your
.vimrc like so:
amenu &Lookup.&PHP :sil! !devphoenix.sh
"http://www.php.net/<cword>"<CR>;;
amenu &Lookup.&Google :sil! !devphoenix.sh
"http://www.google.com/search?q=<cword>"<CR>;;
where devphoenix.sh is a shell script like so:
-------------#!/bin/bash
BROWSER=~/apps/phoenix/phoenix
BROWSER_BIN=phoenix-bin
if [ -z `ps --noheaders -o pid -C $BROWSER_BIN| head 1` ]
then $BROWSER & sleep 5
fi
$BROWSER -remote "openURL($1,new-tab)"
---------------http://www.vim.org/tips/tip.php?tip_id=394 (3 of 4) [18/02/2004 14:56:58]

Tip #394 - pop up menu for checking the meaning of the word from internet : vim online

This way, if you have a browser open, you get it in a


new tab, otherwise you just get the url. I use this
little script all the time. ;-) Of course, you can
leave out the script and just call it directly, etc.
if you use console vim, I'm sure that you could bind it
to a key command with map instead of "amenu
[menuitem]". But I've never tried.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=394 (4 of 4) [18/02/2004 14:56:58]

SourceForge
Logo

Tip #395 - visual marks : vim online

not logged in (login)

Home
Search

Tip #395: visual marks


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/6, Viewed by 1572

created: January 8, 2003 7:29


author: Thomas Ramming

complexity: basic
as of Vim: 6.0

Hi,
Setting visual bookmarks in a file / buffer can be done
in a simple way by using VIM's 'sign' feature.
This solution just sets the background of the current
line to light blue.
Also see ':help sign'.
Add these lines to your gvimrc:
" define a highlight colour group for bookmarks
hi default BookmarkCol ctermfg=blue ctermbg=lightblue
cterm=bold guifg=DarkBlue guibg=#d0d0ff gui=bold
" define a bookmark / sign: just highlight the line
sign define MyBookmark linehl=BookmarkCol
" add something to the context menue (right mouse)
amenu 1.200 PopUp.-SEP3- :
amenu 1.200 PopUp.&mark.set\ bookmark :exe 'sign place
1000 name=MyBookmark line='.line(".").'
buffer='.winbufnr(0)<CR>
amenu 1.200 PopUp.&mark.del\ bookmarks :sign unplace
1000 <CR>
amenu 1.200 PopUp.&mark.list\ bookmarks :sign list<CR>
Happy VIMming
Thomas
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<pop up menu for checking the meaning of the word from internet | Highlighting whitespaces at end
of line >>

http://www.vim.org/tips/tip.php?tip_id=395 (1 of 3) [18/02/2004 14:57:01]

Tip #395 - visual marks : vim online

Additional Notes
maxiangjiang@hotmail.com, January 8, 2003 15:38
1 We need to add <silent> on the map to make it work
smoothly
amenu<silent> 1.200 PopUp.&mark.set\ bookmark :exe
'sign place 1000 name=MyBookmark line='.line(".").'
buffer='.winbufnr(0)<CR>
2. bookmark deletion doesn't work as expected.
Is it possible to delete highlighted bookmark under the
cursor?
Thanks.
Anonymous, January 8, 2003 23:34
The problem might be the 'id' (I used the same '1000'
for each bookmark).
You have to find a way to automatically use unique ids
or 'unplace'
will delete the bookmarks in the order they have been
created.
There is a script 'showmarks' in the script database
(search for 'showmarks'),
which shows 'normal' vim marks (Thanks to the author!).
Thomas
Anonymous, January 9, 2003 5:02
To get unique identifier you can use the actual line
number as identifier:
amenu<silent> 1.200 PopUp.&mark.set\ bookmark :exe
'sign place '.line(".").' name=MyBookmark
line='.line(".").' buffer='.winbufnr(0)<CR>
amenu<silent> 1.200 PopUp.&mark.del\ bookmark :exe
'sign unplace '.line(".")<CR>
Thomas
Anonymous, January 9, 2003 6:31
Just download the showmarks.vim plugin from this site
and forget about it :) It'll automatically show you a
mark as a sign when you set one.

http://www.vim.org/tips/tip.php?tip_id=395 (2 of 3) [18/02/2004 14:57:01]

Tip #395 - visual marks : vim online

zzapper@ntlworld.com, January 10, 2003 3:33


vimscript #152

showmarks.vim

maxiangjiang@hotmail.com, February 5, 2003 14:09


Thanks, Thomas
Eventually, I have the following short and sweet
version in my .vimrc:
nme <silent>PopUp.bookmark_&x :exe 'sign unplace
'.line(".")<CR>
nme <silent>PopUp.bookmark_&a :exe 'sign
place
'.line(".").
' name=bookmark line='.line(".").'
buffer='.winbufnr(0)<CR>
sign define bookmark linehl=DiffDelete
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=395 (3 of 3) [18/02/2004 14:57:01]

SourceForge
Logo

Tip #396 - Highlighting whitespaces at end of line : vim online

not logged in (login)

Home
Search

Tip #396: Highlighting whitespaces at end of line


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 63/32, Viewed by 1477

created: January 9, 2003 19:04


author: Dubhead

complexity: basic
as of Vim: 6.0

Whitespace characters (tabs, spaces, etc) at end of line


are rarely meant to be there; they are usually there by
accident. If you don't want them, maybe it pays to
highlight them with an alarming color. (After all, GNU
Emacs has it (show-trailing-whitespace), so why not in
vim :-) )
Put this in your ~/.vimrc to highlight the whitespace
characters at end of line:
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<visual marks | mapping for better browsing of :help docs >>

Additional Notes
Anonymous, January 9, 2003 22:13
:set list
<Look at trailing spaces and tabs>
:set nolist
< Now get rid of them>
:%s/\s*$//g
xburgerhout at freeler dot nl, January 9, 2003 23:52
You can also add this line to .vimrc:
let c_space_errors=1
This wil enable trailing whitespace errors in C/C++
files only.

http://www.vim.org/tips/tip.php?tip_id=396 (1 of 3) [18/02/2004 14:57:04]

Tip #396 - Highlighting whitespaces at end of line : vim online

mgedmin@mail.lt, January 10, 2003 4:55


I prefer
set list listchars=tab:>-,trail:.,extends:>
falcon611@yahoo.com, January 11, 2003 3:57
You can also use the Cream-based 'showinvisibles'
script, which puts bullets for every whitespace at the
end of a line
vim@linuxwebguy.com, April 4, 2003 11:02
I run into the problem where some of the files I use
have spaces instead of tabs at the front of the
line. I have this in my .vimrc now:
<pre>
" Check for extra whitespace
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/
match WhitespaceEOL /^\ \+/
</pre>
Dubhead, April 20, 2003 19:21
Here is a revision. In addition to whitespaces at endof-line, this also highlights spaces before a tab.
" Highlight redundant whitespaces.
highlight RedundantSpaces ctermbg=red guibg=red
match RedundantSpaces /\s\+$\| \+\ze\t/
suraj_amin@yahoo.com, May 2, 2003 0:07
Hey...
The Highlight redundant whitespaces didn't work for
me....
Following are the things I added to my rc file from
this tip:
" Highlighting whitespaces at end of line
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/
" Check for extra spaces instead of tabs at the front
of the line
match WhitespaceEOL /^\ \+/
" Highlight redundant whitespaces.
http://www.vim.org/tips/tip.php?tip_id=396 (2 of 3) [18/02/2004 14:57:04]

Tip #396 - Highlighting whitespaces at end of line : vim online

highlight RedundantSpaces ctermbg=red guibg=red


match RedundantSpaces /\s\+$\| \+\ze\t/

suraj_amin@yahoo.com, May 2, 2003 0:07


Hey...
The Highlight redundant whitespaces didn't work for
me....
Following are the things I added to my rc file from
this tip:
" Highlighting whitespaces at end of line
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/
" Check for extra spaces instead of tabs at the front
of the line
match WhitespaceEOL /^\ \+/
" Highlight redundant whitespaces.
highlight RedundantSpaces ctermbg=red guibg=red
match RedundantSpaces /\s\+$\| \+\ze\t/

suraj_amin@yahoo.com, May 2, 2003 0:10


Sorry for the multiple post. Happened by mistake :(
xpto_xpto@sapo.pt, December 13, 2003 8:16
thanks mgedmin@mail.lt
listchars was really what i was looking for whitespace
lang since its better than syntax highlighting blocks

xpto_xpto@sapo.pt, December 13, 2003 8:23


btw
sounds the best for me
set list listchars=tab:\|_,trail:.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=396 (3 of 3) [18/02/2004 14:57:04]

SourceForge
Logo

Tip #397 - mapping for better browsing of :help docs : vim online

not logged in (login)

Home
Search

Tip #397: mapping for better browsing of :help docs


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 24/12, Viewed by 660

created: January 9, 2003 23:01


author: Stanislav Sitar

complexity: basic
as of Vim: 6.0

I personally find it very akward and un-intuitive to


browse the documentation
using Ctrl-] for following the link and Ctrl-Shift-t to
go back.
I have had an idea to to remap those commands to Enter
and Backspace, since
I do not use those keys in help in normal mode.
The command :nnoremap <buffer> can remap the key only in
the given buffer
without affecting the other buffers.
just create file
$VIMRUNTIME/ftplugin/help.vim
with following contens
""""""""""""""""""""""""""""""""""""""""""""""""
"""" begining of the file
" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
finish
endif
" map ctrl-] to enter in normal mode only for this
buffer
nnoremap <buffer><cr> <c-]>
" map ctrl-T to backspace in normal mode only for this
buffer
nnoremap <buffer><bs> <c-T>
"""" End of the file
""""""""""""""""""""""""""""""""""""""""""""""""

http://www.vim.org/tips/tip.php?tip_id=397 (1 of 2) [18/02/2004 14:57:06]

Tip #397 - mapping for better browsing of :help docs : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Highlighting whitespaces at end of line | Mapping for quicker access to macros >>

Additional Notes
mark.addison@itn.co.uk, January 10, 2003 8:41
You can adapt this to also use it with the man page
file type, so you can hit return on a ref to another
man page etc.
I had to use the after config file
"~/.vim/after/ftplugin/man.vim" and nmap instead of
nnoremap to getting it working. (I think this is
because the default man.vim needs to set its remap of
<c-]> first.)
goulding@princeton.edu, January 10, 2003 21:22
Very useful mappings for helpfiles. I've added them to
my help.vim, which also contains these for navigating
from |label| to |label|:
nnoremap <buffer> <Tab> /<Bar>\k*<Bar><CR>
nnoremap <buffer> <S-Tab> ?<Bar>\k*<Bar><CR>
" Can't get s-tab to work in xterm, so...
nmap <buffer> . <Tab>
nmap <buffer> , <S-Tab>
Anonymous, February 23, 2003 9:09
hmmm, nice tip, but I couldn't get it working by using
the help.vim file. Adding these lines to .vimrc seems
to work though:
:au filetype help :nnoremap <buffer><cr> <c-]>
:au filetype help :nnoremap <buffer><bs> <c-T>
- Chris
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=397 (2 of 2) [18/02/2004 14:57:06]

SourceForge
Logo

Tip #398 - Mapping for quicker access to macros : vim online

not logged in (login)

Home
Search

Tip #398: Mapping for quicker access to macros


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 13/7, Viewed by 588

created: January 10, 2003 9:44


author: torelg

complexity: basic
as of Vim: 5.7

:nnoremap <space> @q
Start recording keystrokes by hitting 'qq'.
End recording with 'q' (<esc> q if you're in insert
mode).
Play keystrokes by hitting space.
--Refs:
:help register
:help record

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<mapping for better browsing of :help docs | fold away empty lines >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=398 [18/02/2004 14:57:08]

SourceForge
Logo

Tip #399 - fold away empty lines : vim online

not logged in (login)

Home
Search

Tip #399: fold away empty lines


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/5, Viewed by 797

created: January 13, 2003 2:48


author: Thomas

complexity: basic
as of Vim: 6.0

You can fold sequences of at least two empty lines (may


contain blanks) with these settings:
" fold empty lines with white spaces:
syn match MyEmptyLines "\(^[ ^I]*\n\)\+"

fold

You probably can substitute '[ ^I]' with '\s'.


If you have set 'foldcolumn' to more than 0 you can just
open/close these empty lines block
by clicking the '+' or '-' with the mouse in the folder
column.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Mapping for quicker access to macros | Fast scroll mappings (incl. insert mode) >>

Additional Notes
Anonymous, January 15, 2003 13:07
%s/^$/d
Anonymous, January 15, 2003 13:08
Oops:
%g/^$/d
kartikeya_rindani@hotmail.com, January 15, 2003 19:34
Probably the tip aims at getting rid of empty lines
from the display, not from the file.
Anonymous, January 15, 2003 23:08
exactly.
Anonymous, January 15, 2003 23:12

http://www.vim.org/tips/tip.php?tip_id=399 (1 of 2) [18/02/2004 14:57:10]

Tip #399 - fold away empty lines : vim online

@ Anonymous_1 and _2:


don't forget the white spaces,
leave one empty line.
Never had a look on files created and maintained by
other people ?
Deletion is NOT the problem for this tip.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=399 (2 of 2) [18/02/2004 14:57:10]

SourceForge
Logo

Tip #400 - Fast scroll mappings (incl. insert mode) : vim online

not logged in (login)

Home
Search

Tip #400: Fast scroll mappings (incl. insert mode)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -1/1, Viewed by 613

created: January 13, 2003 10:58


author: John Sumsion

complexity: basic
as of Vim: 6.0

" allow Alt-[movement keys] to scroll window


if !has("gui_running")
nmap ^[l <A-l>
nmap ^[h <A-h>
nmap ^[k <A-k>
nmap ^[j <A-j>
vmap ^[l <A-l>
vmap ^[h <A-h>
vmap ^[k <A-k>
vmap ^[j <A-j>
imap ^[l <A-l>
imap ^[h <A-h>
imap ^[k <A-k>
imap ^[j <A-j>
endif
" To have <A-h> available for the mappings below, search
menu.vim for the
" first instance of &Help and change it to Hel&p so that
<Alt-H> isn't used
" for the GUI Help menu
nmap <A-l> 4zl
nmap <A-h> 4zh
nmap <A-k> <C-y>
nmap <A-j> <C-e>
vmap <A-l> 4zl
vmap <A-h> 4zh
vmap <A-k> <C-y>
vmap <A-j> <C-e>
imap <A-l> <C-o>4zl
imap <A-h> <C-o>4zh
imap <A-k> <C-x><C-y>
imap <A-j> <C-x><C-e>
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=400 (1 of 2) [18/02/2004 14:57:12]

Helpful

Unfulfilling

rate

Tip #400 - Fast scroll mappings (incl. insert mode) : vim online

<<fold away empty lines | A mapping for easy switching between buffers >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=400 (2 of 2) [18/02/2004 14:57:12]

SourceForge
Logo

Tip #401 - A mapping for easy switching between buffers : vim online

not logged in (login)

Home
Search

Tip #401: A mapping for easy switching between buffers


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/8, Viewed by 983

created: January 14, 2003 3:27


author: chris

complexity: basic
as of Vim: 6.0

Instead of using a buffer-explorer I looked for a


simpler method for fast switching between buffers. So on
a rainy day I invented a simple mapping:
map
map

<C-Up> :bn<Return>
<C-Down> :bp<Return>

This works very well for an intermediate amount of


buffers. Of course you can take other keys (instead of
the up and down arrows) for the mapping.
Chris.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Fast scroll mappings (incl. insert mode) | Just using space-bar: jump between splitted windows and
open them wide >>

Additional Notes
yourock@devo.com, January 14, 2003 18:53
Shazam!

That _vimrc is gettin way too big.

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=401 [18/02/2004 14:57:15]

SourceForge
Logo

Tip #402 - Just using space-bar: jump between splitted windows and open them wide : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #402: Just using space-bar: jump between splitted windows and
open them wide
tip karma

Rating 12/9, Viewed by 1079

created: January 14, 2003 9:30


author: Klaus Horsten

complexity: basic
as of Vim: 6.0

Jump between splitted windows and open them wide.


Use only the space-bar for this.
Press space-bar once and you jump to the next window.
Press it twice and the window opens wide for better
reading - this works
for horizontal and vertically open windows.
Put this in your vimrc:
"Jump between windows
map <space> <c-W>w
"Open window wide
map <space><space> :call OpenSplittedWindowWide()<cr>
function OpenSplittedWindowWide()
normal ^W|
normal ^W20+
endfunction
Note:
^W must be generated by vim (must be one character).
------------------------------The first tip is not new I know it - to jump between
windows using the space-bar.
But the combination jumping and opening wide with just
using the space-bar this is new.
If not, please apologize, I cannot know all the tips and
possibilites published.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<A mapping for easy switching between buffers | Request for tip - interleaving '.' and '@:' >>

Additional Notes
http://www.vim.org/tips/tip.php?tip_id=402 (1 of 3) [18/02/2004 14:57:17]

Tip #402 - Just using space-bar: jump between splitted windows and open them wide : vim online

yourock@devo.com, January 14, 2003 18:50


yowzer.

That is too nice.

happy.house@gmx.de, January 15, 2003 5:47


:map <space><space> <c-W>w<c-W>_ will do the job of
swichting and maximaizing splitted windows
Klaus Horsten <email.5@gmx.net>, January 16, 2003 7:30
>:map <space><space> <c-W>w<c-W>_ will do the job of
swichting and maximaizing splitted windows
Only for horinzontal open windows not for vertically
open ones.
Klaus
dihar@web.de, January 16, 2003 11:52
Fantastic.
Dieter
vim@geert.triple-it.nl, January 24, 2003 2:25
A more intuitive (for Vi) way of switching between
horizontal splits, is using the 'j' and 'k' keys
Following an earlier issued tip, I use the following
mappings:
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
This maps Ctrl-j to "go down 1 window and maximize it"
This maps Ctrl-k to "go up 1 window and maximize it"
anonymous, February 13, 2003 21:07
Great tip! I combined CTRL-i/j and the space so CTRLspace and SHIFT-space to move to the next and previous
split, respectively.
map <c-space> <c-w>w<c-w>_
map <s-space> <c-w>W<c-w>_
Anonymous, April 23, 2003 16:14

http://www.vim.org/tips/tip.php?tip_id=402 (2 of 3) [18/02/2004 14:57:17]

Tip #402 - Just using space-bar: jump between splitted windows and open them wide : vim online

Weird, when I do just


map <space> <c-W>w
I get a few windows going, hit space, and vim goes into
an infinite loop of continually cycling through the
windows. If I do the same mapping with anything other
than <space>, it works fine. Strange.
Tobi, May 2, 2003 7:53
...because there is a space at the end of your line
vshrinath@rediffmail.com, January 2, 2004 0:40
I use map <C-space> <esc><C-W><C-W>
imap <S-space> <esc>
nmap <S-space> <esc>:
This way, I can quit to the command mode using just the
Shift-Spacebar combination from insert mode.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=402 (3 of 3) [18/02/2004 14:57:17]

SourceForge
Logo

Tip #403 - Request for tip - interleaving '.' and '@:' : vim online

not logged in (login)

Home
Search

Tip #403: Request for tip - interleaving '.' and '@:'


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -11/21, Viewed by 563

created: January 15, 2003 22:13


author: Kartik Agaram

complexity: advanced
as of Vim: 5.7

I'm looking for a way to repeat the last command,


whether it is an ex command or not. '.' repeats the last
non-ex command, while '@:' repeats the last ex command.
Can anyone think of a way to interleave the two? It may
not seem very useful, but since you can map a keystroke
to an ex command (or a sequence of them), isn't it
reasonable to expect a uniform way to repeat the last
keystroke, without having to remember how it's
implemented?
As a random note, it occurs to me that the undo command
probably maintains sufficient information to do this if only we could get at it.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Just using space-bar: jump between splitted windows and open them wide | Tags for Mixed
Assembly and C >>

Additional Notes
zzapper@ntlworld.com, January 16, 2003 0:40
A better place for requests is
comp.editors
http://groups.google.com/groups?q=comp.editors
Kartik Agaram, January 16, 2003 12:34
Apologies.
Kartik Agaram, January 16, 2003 12:45

http://www.vim.org/tips/tip.php?tip_id=403 (1 of 2) [18/02/2004 14:57:19]

Tip #403 - Request for tip - interleaving '.' and '@:' : vim online

For the benefit of others like me who haven't seen it,


vimtip #98 has some discussion on this.
Purely as an aside, it is interesting to observe Vim
Online policy being spontaneously created by its (at
least more outspoken) users, using Karma ratings to
admonish non-conforming entries.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=403 (2 of 2) [18/02/2004 14:57:19]

SourceForge
Logo

Tip #404 - Tags for Mixed Assembly and C : vim online

not logged in (login)

Home
Search

Tip #404: Tags for Mixed Assembly and C


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/2, Viewed by 590

created: January 16, 2003 17:45


author: Vasudev Nayak

complexity: basic
as of Vim: 5.7

Probably this is a no-brainer, but thought would share


it just the same. While accessing C functions/variables
from assembly (esp for those DSP/low level guys out
there) the usual exhuberant ctags doesn't work.
The solution
a) Make a copy of 'tags' file
b) Search and replace all variables & functions of C
files with _variables & _functions in the copy file, say
'Tags'
(ex in Vim ":g/\.c\>/s/^\(\l.\)/_\1/")
c) In Vim :set tags=tags,Tags
d) Use Ctrl-] to sail through.
Tried to find an elegant (read complicated) solution,
but then gave up :). Of course if you need to be doing
ctags all the time write a perl scripts or something to
do this.
Cheers
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Request for tip - interleaving '.' and '@:' | ShowBlockName one-liner equivalent for one coding style
>>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=404 [18/02/2004 14:57:22]

SourceForge
Logo

Tip #405 - ShowBlockName one-liner equivalent for one coding style : vim online

not logged in (login)

Home
Search

Tip #405: ShowBlockName one-liner equivalent for one coding style


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/2, Viewed by 432

created: January 17, 2003 13:27


author: William Natter

complexity: intermediate
as of Vim: 6.0

I use [[ and its look-alikes a lot for browsing my C++


code. You can use ShowLine() and the following mapping
to obtain something close to ShowBlockName (and it's
pretty fast):
map <silent> z[ [[k:call ShowLine()<CR>``
Thanks for your scripts, Gary Holloway.
to using z[ heavily!

I look forward

Cheers,
William
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Tags for Mixed Assembly and C | Alternate delimiters for the replace command >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=405 [18/02/2004 14:57:24]

SourceForge
Logo

Tip #406 - Alternate delimiters for the replace command : vim online

not logged in (login)

Home
Search

Tip #406: Alternate delimiters for the replace command


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 42/15, Viewed by 791

created: January 17, 2003 21:05


author: Raj Kiran

complexity: basic
as of Vim: 5.7

This text is from


http://www.troubleshooters.com/lpm/200212/200212.htm
-- pasted text -In many VI implementations you don't need to use the
slash character as the expression delimiter. You can use
most non-alphanumeric characters (but not \, " or |).
This is very handy when working with UNIX filenames, as
in the following example:
:s+/usr/local/+/opt/+Whatever character follows the :s
is defined to be the delimiter character. If your
implementation doesn't support this, you can represent
slashes in search and replace expressions by escaping
them with backslashes, as follows:
:s/\/usr\/local\//\/opt\//As you can see, the escaping
method is much less readable, so if you can use
alternative delimiter characters, it's a good idea.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<ShowBlockName one-liner equivalent for one coding style | PHPdoc: Use JCommenter.vim for phpscripts >>

Additional Notes
zzapper@ntlworld.com, January 18, 2003 5:52
:'a,'bs#str1#str2#gci
:1,23s=str1=str2=gci
I use one of the above ie either = or #

http://www.vim.org/tips/tip.php?tip_id=406 (1 of 2) [18/02/2004 14:57:29]

Tip #406 - Alternate delimiters for the replace command : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=406 (2 of 2) [18/02/2004 14:57:29]

SourceForge
Logo

Tip #407 - PHPdoc: Use JCommenter.vim for php-scripts : vim online

not logged in (login)

Home
Search

Tip #407: PHPdoc: Use JCommenter.vim for php-scripts


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/4, Viewed by 761

created: January 18, 2003 23:57


author: Klaus Horsten

complexity: intermediate
as of Vim: 6.0

Use JCommenter.vim for php-scripts:


jcommenter.vim : A script for automatically generating
JavaDoc comments
http://vim.sourceforge.net/script.php?script_id=20
PHPdoc is an imitation of JAVAdoc.
The syntax between the two languages is very close,
see the examples below:
Example 1:
You have the PHP-function:
function serialize_it($something) {
$person = serialize($something);
return $person;
}
Put the cursor on the first line and call :call
JCommentWriter()<CR>
You get
/**
*
*
* @param $something
* @return
*/
function serialize_it($something) {
$personen = serialize($something);
return $personen;
}
Example 2:
You have the PHP-class:
class submenu {
...
}

http://www.vim.org/tips/tip.php?tip_id=407 (1 of 2) [18/02/2004 14:57:31]

Tip #407 - PHPdoc: Use JCommenter.vim for php-scripts : vim online

Put the cursor on the first line and call :call


JCommentWriter()<CR>
You get
/**
*
*
* @author
* @version
*/
class submenu {
...
}
Example 3:
For a class-variable you get:
/**
*
*/
var $urls;
Note:
It does not work if you have = '' like in
function serialize_it($something = '') {}
But I think jscript.vim can be adapted for the use with
PHP.
Klaus
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Alternate delimiters for the replace command | Enhance Calendar (script 52) with special dates >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=407 (2 of 2) [18/02/2004 14:57:31]

SourceForge
Logo

http://www.vim.org/tips/tip.php?tip_id=408

not logged in (login)

Home
Search

Tip #408: Enhance Calendar (script 52) with special dates


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/4, Viewed by 1145

created: January 19, 2003 20:00


author: Suresh Govindachar

complexity: basic
as of Vim: 6.0

To enhance Calendar (vimscript #52) with display of special


dates:
Step 1) Create a file called "holidays" in the directory
assigned to g:calendar_diary
(Default value for g:calendar_diary is ~/diary).
This file will contain the special dates. Essence
of contents of the
holidays file is the special dates encoded as
(10000+(month*100)+day).
____example_contents_of_file_g:calendar_diary/holidays_________
List of holidays: ^(10000 + ((month * 100)+day))
Encoded
Date

Sign

Color

Description

10101
10217
10214
10414
10526
10703
10704
+ 1 day
10901
11127
+ 1 day
11128
11225
1 day
11226
1 day

n
p
v
s
m
i
i

blue
blue
red
green
blue
gold
gold

Jan
Feb
Feb
Apr
May

l
t

blue
blue

Sep 01
(Mon)
- Labor Day
Nov 27&28(Thu & Fri)- Thanksgiving Day

t
c

blue
silver

Dec 25&26(Thu & Fri)- Christmas Day +

silver

Dec 25&26(Thu & Fri)- Christmas Day +

Step 2)

01
17
14
14
26

Jul 3&4

(Wed)
(Mon)
(Fri)
(Mon)
(Mon)

New Year's Day


President's Day
Valentine's Day
Spring Break
Memorial Day

(Thu & Fri)- Independence Day

Add the following to your vimrc file:

let calendar_sign = 'MyGetSpecialDay'


function! MyGetSpecialDay(day, month, year)
let l:m100d = 10000 + (a:month * 100 ) + a:day
let l:holidays = expand(g:calendar_diary) . "/holidays"
exe "split " . l:holidays
http://www.vim.org/tips/tip.php?tip_id=408 (1 of 2) [18/02/2004 14:57:34]

http://www.vim.org/tips/tip.php?tip_id=408

let l:found = search(l:m100d)


if l:found
let l:found = 'h'
endif
quit
return l:found
endfunction
That's all.
Note: The preceding constitutes basic support for display of
special dates.
With this basic support, all special dates are shown
with the same
sign (viz. +) and the same highlight color. An
enhancement would
be to pick up the sign and the highlight color from
the holidays file.
(Also, I suspect management of buffer for the
holidays file can be
speeded up, perhaps by opening it only once, keeping
it in the
background and searching with warp-around flag
('w').)

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<PHPdoc: Use JCommenter.vim for php-scripts | Using selected text as part of a command? >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=408 (2 of 2) [18/02/2004 14:57:34]

SourceForge
Logo

Tip #409 - Using selected text as part of a command? : vim online

not logged in (login)

Home
Search

Tip #409: Using selected text as part of a command?


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/15, Viewed by 1040

created: January 21, 2003 22:46


author: Lyle

complexity: basic
as of Vim: 5.7

I wish to use selected text as part of a command - say,


to substitute instances of a very long variable with a
shorter name:
:%s/<selected text>/ShorterName/g
How would I do this? (Hope its OK to ask a question, as
opposed to presenting an answer).
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Enhance Calendar (script 52) with special dates | Allow Inform header files to be distinguished from
C headers >>

Additional Notes
Mark Hillebrand, January 22, 2003 2:01
1. yank your selected text using the 'y' key.
2. when entering your command you can use control-r
followed by " whenever you need your selections.
(control-r " inserts the contents of the "-register
which is the standard register for yanking)
I don't know exactly, if this was already possible in
vim 5.7.
michael@familie-boehler.de, January 22, 2003 3:08
Just put the cursor over the word in your text.
In the command line press <C-R><C-W> the to get the
word.
See h: c_<C-R>_<C-W>
lewocz@acm.org, January 22, 2003 5:25

http://www.vim.org/tips/tip.php?tip_id=409 (1 of 2) [18/02/2004 14:57:36]

Tip #409 - Using selected text as part of a command? : vim online

I have the following maps:


vmap ,g
map ,g

:s/<C-R>//
:s/<C-R>//

I then just add the closing delimiter and flags and hit
return.
These mappings have
saved me a great deal of time.
zzapper@ntlworld.com, January 22, 2003 7:43
Hi,
A better place your discussions about VIm is
http://groups.google.com/groups?q=comp.editors

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=409 (2 of 2) [18/02/2004 14:57:36]

SourceForge
Logo

Tip #410 - Allow Inform header files to be distinguished from C headers : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #410: Allow Inform header files to be distinguished from C


headers
tip karma

Rating 14/5, Viewed by 592

created: January 22, 2003 2:55


Stephen Thomas, Ross Presser, Neil
author:
Cerruti

complexity: intermediate
as of Vim:

6.0

Inform is an Interactive Fiction authoring


language. It's header files often use a '.h' extension,
which causes VIM to think they are
C files, or do not have any extension at all, leaving
VIM unable to determine what kind of file they
are. This is irritating to Inform
developers using VIM with syntax highlighting.
The solution is to use a custom 'filetype.vim' and
'scripts.vim'. Create a '$HOME/.vim/filetype.vim':
if exists("did_load_filetypes")
finish
endif
augroup filetypedetect
au BufNewFile,BufRead *.h
FTCheck_inform()
augroup END

call

" function to detect inform code (any extension)


fun! FTCheck_inform()
if getline(1) =~ "^!"
setfiletype inform
elseif getline(2) =~ "^!"
setfiletype inform
else
let s:colnum = col('.')
let s:linenum = line('.')
call cursor(500, 1)
if search('\[\(\s*\I\i*\)*\s*;', 'bW') > 0
setfiletype inform
endif
call cursor(s:linenum, s:colnum)
endif
endfun

http://www.vim.org/tips/tip.php?tip_id=410 (1 of 2) [18/02/2004 14:57:39]

Tip #410 - Allow Inform header files to be distinguished from C headers : vim online

On loading a file with a '.h' extension, a function is


called to examine the file for certain Inform-specific
constructs. If it finds any, it sets the filetype as
inform, otherwise it leaves the filetype unset, allowing
the global 'filetype.vim' to determine the filetype.
For files with no extension, create a
'$HOME/.vim/scripts.vim':
" local scripts.vim gets called when
" all autocommands have failed to identify file type,
" but before global scripts.vim
"
call FTCheck_inform()
See also the site
http://www.stephenthomas.uklinux.net/informvim

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using selected text as part of a command? | How to initialize plugins >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=410 (2 of 2) [18/02/2004 14:57:39]

SourceForge
Logo

Tip #411 - How to initialize plugins : vim online

not logged in (login)

Home
Search

Tip #411: How to initialize plugins


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 26/14, Viewed by 2183

created: January 23, 2003 6:52


author: Charles E. Campbell, Jr.

complexity: basic
as of Vim: 6.0

Plugins have two basic ways of being initialized:


a) via some variable that the plugin script uses;
the initialization here is obvious -- set the
desired variables in your <.vimrc> (or use
an appropriate autocmd to do so).
b) via a map or function call. The problem here
is that <.vimrc> is sourced prior to plugin
sourcing, so the map or function call isn't
available yet.
Solution: put in .vim/after/plugin a file
of the same name as the plugin you're
initializing.
In that file put
call TheInitializationFunction()
-ornorm TheInitializationMap
For example, the <HiMtchBrkt.vim> script which supports
the
highlighting of matching brackets as you move onto a
bracket is not on by default. Normally it requires one
to
type "\[i" to start it. However, if you'd like to have
the
script to start enabled, then put
norm \[i
into the file <.vim/after/plugin/HiMtchBrkt.vim> (see
tip
vimtip#177).
(Windows users: mentally change .vim to _vimfiles and /

http://www.vim.org/tips/tip.php?tip_id=411 (1 of 2) [18/02/2004 14:57:41]

Tip #411 - How to initialize plugins : vim online

to \
in the tip above)

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Allow Inform header files to be distinguished from C headers | Easy menu-style switch between files
with a simple map >>

Additional Notes
bnouane@uark.edu, March 6, 2003 12:45
just wanted to say that i use the windows version, and
i had to goto the directory vim/vim61/plugin, and i
added the line
norm \[i
at the very end of the file HiMtchBrkt.vim
also when i opened a file, an annoying window popped
up, so i commented out the echo command at line 108 of
the file.
boonth
cec@NgrOyphSon.gPsfAc.nMasa.gov, March 17, 2003 12:24
The fix for that annoying little message box is to use:
silent norm \[i
The box no longer shows up. Enjoy!
jlanus@netscape.net, October 4, 2003 7:20
I'm trying the plugin with those old FORTRAN progrms I
work with.
Most lines start with tabs, and the pligin seems to get
confused by this fact.
If I replace the tabs by spaces it works fine, even
witn multiline sentences.
Juan Lanus
TECNOSOL Argentina
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=411 (2 of 2) [18/02/2004 14:57:41]

SourceForge
Logo

Tip #412 - Easy menu-style switch between files with a simple map : vim online

not logged in (login)

Home
Search

Tip #412: Easy menu-style switch between files with a simple map
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 45/18, Viewed by 937

created: January 29, 2003 9:15


author: Raghavan Subramaniyan

complexity: basic
as of Vim: 6.0

When there are several files opened in a vim session, it


becomes difficult to keep track of the files and their
respective buffer numbers.
Switching to a different file is made easier using a
simple map:
:map <F5> :buffers<CR>:e #
When F5 is pressed, a numbered list of file names is
printed, and the user needs to type a single number
based on the "menu".
Another good thing is that the "menu" disappears after
choosing the number and hitting enter. So it appears
only when you need it.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<How to initialize plugins | Drag and Drop file names into VIM's command line >>

Additional Notes
jh_sec@gmx.net, January 29, 2003 23:14
great tip!
i've never memorized how to switch between my files,
this is great.
Anonymous, January 29, 2003 23:33

http://www.vim.org/tips/tip.php?tip_id=412 (1 of 3) [18/02/2004 14:57:43]

Tip #412 - Easy menu-style switch between files with a simple map : vim online

- ':ls' is shorter than ':buffers'


- there are some scripts in this script database here
keeping track of open buffers via menu selection.
e.g. mru.vim or FavMenu.vim.
Thomas
bogleg@bogleg.org, January 30, 2003 0:31
Just thought I'd throw out there what I use:
" buffer navigation:
" ":e <filename>" to make a buffer with that file in it
(duh)
" ",s" and ",f" for back and forth on the buffer list
" ",d" for a list of what's in each buffer
" ",1", ",2", .. ",9", ",0" to go straight to that
numbered buffer (0 = 10)
" ",g" to toggle between two buffers (my most used
probably)
map ,s :bN<CR>
map ,d :buffers<CR>
map ,f :bn<CR>
map ,g :e#<CR>
map ,1 :1b<CR>
map ,2 :2b<CR>
map ,3 :3b<CR>
map ,4 :4b<CR>
map ,5 :5b<CR>
map ,6 :6b<CR>
map ,7 :7b<CR>
map ,8 :8b<CR>
map ,9 :9b<CR>
map ,0 :10b<CR>
Suresh Govindachar, January 30, 2003 8:08
Useful tip!

Try also:

:b <any substring from name of buffer>


:sb <any substring from name of buffer>

and

Raghavan Subramaniyan, January 30, 2003 8:34


A useful side effect:
If you press <F5> and then hit return without entering
any number, it goes to the previous file that was
opened. Repeated <F5><CR> basically toggles between two
files (which I use frequently enough to map to a single
separate key)

http://www.vim.org/tips/tip.php?tip_id=412 (2 of 3) [18/02/2004 14:57:43]

Tip #412 - Easy menu-style switch between files with a simple map : vim online

Anonymous, January 30, 2003 19:42


Raghavan, try CTRL-^ for that.

See :help CTRL-^

zzapper@ntlworld.com, January 31, 2003 4:33


Also
:wn
:wp
:last
:first

write current file goto next


write current file goto previous
goto last
goto first (:rew)

Anonymous, February 20, 2003 10:38


My version for the :ls-combined-with-:b mapping is:
nmap <F5> :ls<cr>:b!<space>
nmap <S-F5> :ls!<cr>:b!<space>
:e or :b, I don't know what's better...but I like the
"!" when the current buffer is modified. (modified
"abandoned" buffers get a "+" in the buffer list,
that's enough).
With :b, you can press <esc> or <cr> if you want to
stay in the buffer (if you just needed :ls or :ls!).
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=412 (3 of 3) [18/02/2004 14:57:43]

SourceForge
Logo

Tip #413 - Drag and Drop file names into VIM's command line : vim online

not logged in (login)

Home
Search

Tip #413: Drag and Drop file names into VIM's command line
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/17, Viewed by 1106

created: January 29, 2003 23:55


author: Thomas Ramming

complexity: basic
as of Vim: 6.0

You can open files in VIM by Drag&Drop of selected file


names from Windows Explorer. (not very surprising).
This also works by dropping into the VIM command line,
so you can e.g. type
':split '
then drag&drop a selected file to VIM window
and hit <CR>
The complete path and filename is transferred to
commandline and the file is opened in a new VIM
buffer/window.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Easy menu-style switch between files with a simple map | Change guifont to see more of your file.
>>

Additional Notes
foo@bar.com, January 30, 2003 23:47
This also works in an X-Windows environment, such as
Linux uses.
:edit <drag file on to Gvim window> <Return> also works
as you would expect.
Anonymous, January 16, 2004 13:27
In X, you don't even need to type ":edit" first. Just
grab a file from your file manager (like Rox) and
drag/drop it into Vim.
Add Note

http://www.vim.org/tips/tip.php?tip_id=413 (1 of 2) [18/02/2004 14:57:46]

Tip #413 - Drag and Drop file names into VIM's command line : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=413 (2 of 2) [18/02/2004 14:57:46]

SourceForge
Logo

Tip #414 - Change guifont to see more of your file. : vim online

not logged in (login)

Home
Search

Tip #414: Change guifont to see more of your file.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 62/32, Viewed by 2690

created: January 30, 2003 5:12


author: benrich@mail.com

complexity: basic
as of Vim: 5.7

Sometimes, its nice to be able to quickly jump to a


smaller font to
see more of the file you're editing at once, and jump
back again to
make the text more readable. I use these mapping:
:map
:map
:map
:map

<f9> :set guifont=Lucida_Console:h9:cANSI<Cr>


<f11> :set guifont=Lucida_Console:h11:cANSI<Cr>
<S-f9> :set guifont=Courier_New:h9:cANSI<Cr>
<S-f11> :set guifont=Courier_New:h11:cANSI<Cr>

9 and 11 are my mnemonics for the font size. <f10>


wouldn't work for me
because it activates the menu. Of course, this only
works in gvim.
Ben
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Drag and Drop file names into VIM's command line | easy way to edit two files using split window >>

Additional Notes
jkr@jottkaerr.de, January 30, 2003 6:50

http://www.vim.org/tips/tip.php?tip_id=414 (1 of 4) [18/02/2004 14:57:48]

Tip #414 - Change guifont to see more of your file. : vim online

For decreasing/increasing the current font size by one


point
you can also use these mappings:
nmap <F12>
:let &guifont = substitute(&guifont,
':h\(\d\+\)', '\=":h" . (submatch(1) - 1)', '')<cr>
nmap <S-F12> :let &guifont = substitute(&guifont,
':h\(\d\+\)', '\=":h" . (submatch(1) + 1)', '')<cr>
Because notation of fonts is highly system dependent,
this might
only work on Windows.
Anonymous, January 30, 2003 7:49
In addition you can set the blank space between the
lines:
"number of pixel lines to use between lines
set lsp=0
Thomas
japaget@ix.netcom.com, January 30, 2003 15:37
1) This tip probably works only for Windows but the
basic idea can be applied to UNIX and other platforms.
2) You mileage may vary regarding the point size,
depending on the your screen resolution and whether you
are using small fonts or large ones. The same issues
apply to 75 dpi vs 100 dpi fonts on X11.
3) On Windows, you can 'set wak=no' to prevent <F10>
from bringing up the menu.
vi@lover.com, January 30, 2003 22:37
Is it possible to map <CTRL-+> <CTRL-->
like we have on mozilla?
That would be great!!!
davidr@pobox.com, January 31, 2003 19:47

http://www.vim.org/tips/tip.php?tip_id=414 (2 of 4) [18/02/2004 14:57:48]

Tip #414 - Change guifont to see more of your file. : vim online

Try this script, which allows you to enlarge or shrink


your font sizes by half-point increments. It works on
Win32. The script is easily modified to deal with wholepoint increments, of course.
function! ScaleFontUp()
let gf_size_whole = matchstr(&guifont,
'\(\:h\)\@<=\d\+')
let gf_size_frac = matchstr(&guifont,
'\(\:h\d\+\.\)\@<=\d\=')
let font_size = gf_size_whole * 10 + gf_size_frac
let font_size = font_size + 5
let gf_size_whole = font_size / 10
let gf_size_frac = font_size - gf_size_whole * 10
let new_font_size =
':h'.gf_size_whole.'.'.gf_size_frac.':'
let &guifont = substitute(&guifont, '\:h.\{-}\:',
new_font_size, '')
endfunction
function! ScaleFontDown()
let gf_size_whole = matchstr(&guifont,
'\(\:h\)\@<=\d\+')
let gf_size_frac = matchstr(&guifont,
'\(\:h\d\+\.\)\@<=\d\=')
let font_size = gf_size_whole * 10 + gf_size_frac
let font_size = font_size - 5
let gf_size_whole = font_size / 10
let gf_size_frac = font_size - gf_size_whole * 10
let new_font_size =
':h'.gf_size_whole.'.'.gf_size_frac.':'
let &guifont = substitute(&guifont, '\:h.\{-}\:',
new_font_size, '')
endfunction
nmap <C-S-F11> :call ScaleFontDown()<CR>
nmap <C-S-F12> :call ScaleFontUp()<CR>
Ctrl-Shift-F11 and -F12 reduces and enlarges the font
sizes, respectively.
- Dave Rahardja
gmann@femto.med.unc.edu, February 3, 2003 13:30

http://www.vim.org/tips/tip.php?tip_id=414 (3 of 4) [18/02/2004 14:57:48]

Tip #414 - Change guifont to see more of your file. : vim online

And if you don't ever use the guis.


set guioptions-=T "get rid of toolbar
set guioptions-=m "get rid of menu
Ahhhh, much better (3 more lines)
a.anderson@utoronto.ca, March 20, 2003 19:13
Check guifont++.vim plugin:
http://www.vim.org/scripts/script.php?script_id=593
When you drop it into your plugin directory, keys +, -,
and = will be remapped: + makes the font larger by 1, makes the font smaller by 1, = restores whatever the
original font size was. And these key mappings can be
redefined to something else (if you use your +, -, or =
keys) in your vimrc file (see the plugin description
for info on that).
foobarbaz99@hotmail.com, August 13, 2003 23:19
Ever want that great looking unix font for gvim on
win32?
I have, and I just found where you can get them:
http://www.tomasek.cz/semtel/download/fonts.zip
This guy has hacked some of the most common unix fonts
(.bdf format) into
win32 .fon style fonts. Just drop the desired font into
your c:\winnt\fonts directory
and you're good to go!
My personal favorite is 7x14, which combined with vim's
":set lsp=0" makes my
gvim screen on win32 look just like my vim terminal on
unix. Horray!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=414 (4 of 4) [18/02/2004 14:57:48]

SourceForge
Logo

Tip #415 - easy way to edit two files using split window : vim online

not logged in (login)

Home
Search

Tip #415: easy way to edit two files using split window
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -28/32, Viewed by 2317

created: January 30, 2003 9:40


author: david cantrell

complexity: intermediate
as of Vim: 5.7

In my rc ($HOME/.exrc) file, I have the following lines:


map K ESC:split
map k ^K ^W^W
where the 'ESC', '^K', and '^W^W' are escape sequences.
This allows the user to split the screen using 'K', then
switch between the two screens using 'k'. This in
conjuction with the :e to edit a different file can be
powerful. Useful for pulling lines (or blocks) from one
file into another without having to cut/paste or use the
:r command. Personally I use this alot so I find it
useful. I got the syntax from the O'Reilly book
'Learning the vi editor' in the section about 'ex
commands'.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Change guifont to see more of your file. | Fix error "E97: Cannot create diffs" on VIM for Windows
>>

Additional Notes
skrishna23@excite.com, January 30, 2003 11:53
If you use 'k', what command do you use to move UP ???
Don't say remap....,It's better not to use existing
keys.
Anonymous, January 30, 2003 23:23

http://www.vim.org/tips/tip.php?tip_id=415 (1 of 2) [18/02/2004 14:57:50]

Tip #415 - easy way to edit two files using split window : vim online

Why using letter keys instead of cursor keys for cursor


movement ?
In addition I have these mappings in my gvimrc:
" mapping Shift-keys
" open new line after actual line
map <S-Insert> ^[o
" delete actual line
map <S-Delete> ^[dd
" mapping Control-keys
" delete actual line from Cursorpos to EOL
map <C-Delete> ^[C^[
" in insert mode type <ctrl-v><ESC> to get '^['
Thomas
Anonymous, January 31, 2003 8:01
Cursor keys are for the weak.
Even more anonymous, February 3, 2003 6:16
Letter keys are faster! Don't have to take your hand
off the home keys. Bet you use the mouse, too, huh?
Anonymous, February 3, 2003 7:26
No I'm directly entering my thoughts.
Cursor moves are done automatically by detecting where
I am looking to.
new vim, old vi user, February 3, 2003 12:43
why do you even bother using VI? Go back to emacs or
whatever windoze editor you love using.
Split window: ^WS
Close window: ^WC
Switch window: ^WW
(control key also also works for 2nd key, ie ^WS =
^W^S)
Me, March 31, 2003 18:21
Or if you can't figure that out you can do ^W^Q for
close :D since ^W^C doesn't work
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=415 (2 of 2) [18/02/2004 14:57:50]

SourceForge
Logo

Tip #416 - Fix error "E97: Cannot create diffs" on VIM for Windows : vim online

not logged in (login)

Home
Search

Tip #416: Fix error "E97: Cannot create diffs" on VIM for Windows
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 41/30, Viewed by 1246

created: January 31, 2003 10:44


author: Juan M. Medina

complexity: basic
as of Vim: 6.0

I read a couple postings of people having this issue,


even if they have a diff program in their path when
running on Windows platforms.
Check out your _vimrc file, function "MyDiff". If the
path to the diff file contains ANY spaces, enclose the
path in double quotes. Alternatively you can remove the
path and just leave the diff file and check.
This is the line that if fixed in my _vimrc:
Changed
silent execute '!C:\Program Files\Vim\vim61\diff -a '
. opt . v:fname_in . ' ' . v:fname_new . ' > ' .
v:fname_out
To be:
silent execute '!"C:\Program Files\Vim\vim61\diff" -a
' . opt . v:fname_in . ' ' . v:fname_new . ' > ' .
v:fname_out
I am running the diff program that comes with CygWin and
it works just fine.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<easy way to edit two files using split window | combining move and scroll [IMPROVED] >>

Additional Notes
justin.buist@siemens.com, April 30, 2003 7:56

http://www.vim.org/tips/tip.php?tip_id=416 (1 of 3) [18/02/2004 14:57:53]

Tip #416 - Fix error "E97: Cannot create diffs" on VIM for Windows : vim online

The instructions make a lot more sense when you find


this example in the documentation:
set diffexpr=MyDiff()
function MyDiff()
let opt = ""
if &diffopt =~ "icase"
let opt = opt . "-i "
endif
if &diffopt =~ "iwhite"
let opt = opt . "-b "
endif
silent execute "!diff -a " . opt . v:fname_in . " "
. v:fname_new .
\ " > " . v:fname_out
endfunction
r.erens@eurosys.nl, June 20, 2003 6:38
And don't forget to update your path to the diff
program if you upgrade to vim6.2
John, July 8, 2003 17:48
To correct E97 I found that I had to add double quotes
around the entire command, like so:
silent execute '!""C:\Program
Files\vim\vim62\diff.exe" -a ' . opt . '"' . v:fname_in
. '" "' . v:fname_new . '" > "' . v:fname_out . '""'
I am running gVIM 6.2 on a Win2000 Server. My shell
command, "cmd.exe /c", was stripping the double quotes
around Program Files and causing the execution to fail.

zintzunn@yahoo.com, August 2, 2003 10:44


The last one worked out just fine for me.
I;m running WXP
avlxyz@GetRidOfMe.yahoo.com, November 27, 2003 18:18

http://www.vim.org/tips/tip.php?tip_id=416 (2 of 3) [18/02/2004 14:57:53]

Tip #416 - Fix error "E97: Cannot create diffs" on VIM for Windows : vim online

I'm running gvim 6.1 on Windows 2000, not the OS of my


choice...
My problem was as simple as diff.exe not being in the
PATH.
I added a diff.bat to my a "bin" directory that was in
the path and it solved it:
@"C:\Program Files\Vim\vim61\diff.exe" %*
I couldn't find MyDiff in my _vimrc. erhaps I had an
old _vimrc.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=416 (3 of 3) [18/02/2004 14:57:53]

SourceForge
Logo

Tip #417 - combining move and scroll [IMPROVED] : vim online

not logged in (login)

Home
Search

Tip #417: combining move and scroll [IMPROVED]


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 15/6, Viewed by 918

created: February 3, 2003 14:29


author: Andrew Pimlott

complexity: intermediate
as of Vim: 5.7

A long time ago, I entered vimtip #105. I used that


mapping for a long time, but it always had a couple
problems. One, it reset the scroll parameter. Two, it
didn't work in visual mode, because :set scroll exits
visual mode. I was reviewing my vim configuration and
learning some new tricks, and in the process I improved
this mapping.

Site Help

Now, Ctrl-J and Ctrl-K will move the cursor one line
down or up, and scroll one line down or up--so the
cursor remains on the same screen line (except near the
beginning and end of the file)--in both normal and
visual modes. And the scroll parameter is unaffected.
" N<C-D> and N<C-U> idiotically change the scroll
setting
function! s:Saving_scroll(cmd)
let save_scroll = &scroll
execute "normal" a:cmd
let &scroll = save_scroll
endfunction
" move and scroll
nmap <C-J>
:call
D>")<CR>
vmap <C-J> <Esc>:call
D>")<CR>
nmap <C-K>
:call
U>")<CR>
vmap <C-K> <Esc>:call
U>")<CR>

<SID>Saving_scroll("1<C-V><C<SID>Saving_scroll("gv1<C-V><C<SID>Saving_scroll("1<C-V><C<SID>Saving_scroll("gv1<C-V><C-

This is an example of several terrible vim hacks, to


boot.
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=417 (1 of 2) [18/02/2004 14:57:55]

Helpful

Unfulfilling

rate

Tip #417 - combining move and scroll [IMPROVED] : vim online

<<Fix error "E97: Cannot create diffs" on VIM for Windows | Stop the beeping in gvim. >>

Additional Notes
bach2tony@yahoo.com, February 6, 2003 9:48
OH YEAH, WELL YUO = TEH SUX0R!!!111
vimizer, February 8, 2003 19:21
I set 'scrolloff' value for somewhat of the same
effect. Your way is more complete though.
mkelly@hp.com, February 10, 2003 21:34
Thanks, this is great, almost exaclty what I was
looking for !
The only two things left I still am searching for are :
1) (related) I want to keep the cursor column in the
same place unless the new line is shorter in which case go to
the end of
the new line. This always puts the column at 0
when I scroll.
Still excellent tho, thanks !
2). (not related) I want to restore the screen buffer
to what it was
before I entered vim. I think a ioctl/tcgetattr
to get the initial
settings and then another one at the end to
restore might
do it - but I am just looking at the code now to
see how/where.
Maybe there is a better way ?
thanks for your help,
mark
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=417 (2 of 2) [18/02/2004 14:57:55]

SourceForge
Logo

Tip #418 - Stop the beeping in gvim. : vim online

not logged in (login)

Home
Search

Tip #418: Stop the beeping in gvim.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 97/77, Viewed by 1997

created: February 3, 2003 19:58


author: Dave

complexity: basic
as of Vim: 6.0

How do you stop gvim from beeping on error?


rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<combining move and scroll [IMPROVED] | Auto-fold perl subs (and possibly other languages) >>

Site Help

Additional Notes
darkeye@chol.net, February 3, 2003 20:38
:set vb
Have nice day!
srinath AT fastmail DOT fm, February 3, 2003 20:39
To all the intellectually challenged:
This is a place for posting "tips" which are objects of
information you beleive will help other vim users.
This is _NOT_ a place to ask questions. Use
comp.editors (with the word "vim" in the subject line),
or
subscribe to vim@vim.org and ask the really helpful
people there.
Please stop messing up this lovely website.
I wish there were some way of removing these obviously
bad "tips".
Anonymous, February 3, 2003 23:17
where the answer transform the question to tip ...
Anonymous, February 6, 2003 7:37

http://www.vim.org/tips/tip.php?tip_id=418 (1 of 4) [18/02/2004 14:57:58]

Tip #418 - Stop the beeping in gvim. : vim online

In fact the 'visualbell' (aka 'vb') setting already


exists in most primitive versions of 'vi'.
This is definitively *NOT* a 'vim' tip (but rather a
'vi' one).
yav_a@hotmail.com, February 8, 2003 0:12
I tried :set vb. In a GUI, it's just murder on the
eyes. I'd much rather suffer through the ``bells''.
(digitect) (at) (mindspring) (dot) (com), February 8, 2003 17:25
Couldn't resist trying to redeem this one!
Paste the following function into your vimrc:
-------------------------------------------------function! Errorbells_off(...)
" control Vim's audio and visual warnings
" * Arguments:
"
"beep":
turn off just beeping
"
"flash": turn off just flashing
"
(empty): both off
" * Must be initialized after the GUI starts!
" off
if a:0 == 0
let myeb = ""
else
let myeb = a:1
endif
if

myeb ==? "flash"


" audibly beep on error
set errorbells
" Screen flash on error
set novisualbell
set t_vb=
elseif myeb ==? "beep"
" audibly beep on error
set noerrorbells
" Screen flash on error
set visualbell
set t_vb&
elseif myeb ==? ""
" audibly beep on error
set noerrorbells
" Screen flash on error
set visualbell
set t_vb=

http://www.vim.org/tips/tip.php?tip_id=418 (2 of 4) [18/02/2004 14:57:58]

messages
(See also 't_vb')

messages
(See also 't_vb')

messages
(See also 't_vb')

Tip #418 - Stop the beeping in gvim. : vim online

endif
endfunction
-------------------------------------------------Re-start Vim and enter
:call Errorbells_off("beep") -- turns off beeps
:call Errorbells_off("flash") -- turns off flashes
:call Errorbells_off()
-- turns off both
We use this the Cream for Vim project
(http://cream.sourceforge.net).
samrat2107@hotmail.com, March 21, 2003 11:45
removing complexity of the program .
just type following in your .vimrc
set noerrorbells
set visualbells
set t_vb=
thats all folks.
dev@null.org, April 6, 2003 8:39
quote:
srinath AT fastmail DOT fm, February 3, 2003 20:39
To all the intellectually challenged:
This is a place for posting "tips" which are objects of
information you beleive will help other vim users.
end quote
Uhm.. If this is _not_ a place for posting "Tips" that
is supposed to help other vim users then what is this?
I do agree that the "tip" is a little useless for
seasoned vim users, you are just being too rash IMO...
Anonymous, April 29, 2003 9:58
I reached this thread instantly from gooling. The first
tip/advise/information is exacly what I needed, clear
and simple. I think people like srinath AT fastmail DOT
fm should go play with himself.
zzapper@ntlworld.com, May 21, 2003 16:41

http://www.vim.org/tips/tip.php?tip_id=418 (3 of 4) [18/02/2004 14:57:58]

Tip #418 - Stop the beeping in gvim. : vim online

A good place to discuss/ask questions/search for


solutions/chew the cud about VIM is comp.editors
http://groups.google.com/groups?group=comp.editors
Srinath is the author of several important Vim scripts

Anonymous, September 17, 2003 6:54


being an "author of several important scripts" does not
preclude him from being a jerk.
Thanks for the important scripts and continuing to
support them. Now stop being a jerk.
drNchipO@ScampbellPfamilyA.bizM - nospam, December 22, 2003 9:05
I fully agree with Srinath and Zzapper -- this forum is
for tips, not questions,
and certainly not for insults. I think an apology is
in order...
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=418 (4 of 4) [18/02/2004 14:57:58]

SourceForge
Logo

Tip #419 - Auto-fold perl subs (and possibly other languages) : vim online

not logged in (login)

Home
Search

Tip #419: Auto-fold perl subs (and possibly other languages)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 51/21, Viewed by 1959

created: February 3, 2003 20:43


author: Mina Naguib

complexity: intermediate
as of Vim: 6.0

Add this to your .vimrc file and it'll automatically


fold perl functions (and possibly other languages that
define a subroutine with "sub ...")
Once you open a perl file, you'll see all functions are
folded. You can then move to a function and (space) or
"zo" to open it, "zc" to close it, "zR" to open all
folds (normal file) and "zM" to re-fold all folds. It
makes skimming over a file a breeze. See ":help folding"
for more info on folding in general.
function GetPerlFold()
if getline(v:lnum) =~ '^\s*sub'
return ">1"
elseif getline(v:lnum + 2) =~ '^\s*sub' &&
getline(v:lnum + 1) =~ '^\s*$'
return "<1"
else
return "="
endif
endfunction
setlocal foldexpr=GetPerlFold()
setlocal foldmethod=expr
rate this tip

Life Changing

Helpful

Unfulfilling

<<Stop the beeping in gvim. | get rid of annoying menu/tool bar >>

Additional Notes
webmaster@topfx.com, February 3, 2003 21:49

http://www.vim.org/tips/tip.php?tip_id=419 (1 of 4) [18/02/2004 14:58:00]

rate

Tip #419 - Auto-fold perl subs (and possibly other languages) : vim online

Regarding vimtip #419 , I modified it to:


1. Correctly recognize subs beginning, as well as
disregard "substr"
2. Correctly recognize end of sub, as well as disregard
any following comments (commonly belonging to NEXT SUB)
and not include it in fold
Here's the new code:
function GetPerlFold()
if getline(v:lnum) =~ '^\s*sub\s'
return ">1"
elseif getline(v:lnum) =~ '\}\s*$'
let my_perloffset = 1
while (1)
let my_perldata = getline(v:lnum +
my_perloffset)
if my_perldata == ""
return "<1"
elseif my_perldata =~ '^\s*sub\s'
return "<1"
elseif my_perldata =~ '^\s*\(\#.*\)\?$'
" do nothing
else
return "="
endif
let my_perloffset = my_perloffset + 1
endwhile
else
return "="
endif
endfunction
setlocal foldexpr=GetPerlFold()
setlocal foldmethod=expr
webmaster@topfx.com, February 3, 2003 23:00
Yet another bugfix. This one fixes a bug where if a sub
has inside it a } followed by an empty line, the fold
would end there instead of at the real end of the sub
function GetPerlFold()
if getline(v:lnum) =~ '^\s*sub\s'
return ">1"
elseif getline(v:lnum) =~ '\}\s*$'
let my_perlnum = v:lnum
let my_perlmax = line("$")
while (1)
let my_perlnum = my_perlnum + 1
if my_perlnum > my_perlmax
http://www.vim.org/tips/tip.php?tip_id=419 (2 of 4) [18/02/2004 14:58:00]

Tip #419 - Auto-fold perl subs (and possibly other languages) : vim online

return "<1"
endif
let my_perldata = getline(my_perlnum)
if my_perldata =~ '^\s*\(\#.*\)\?$'
" do nothing
elseif my_perldata =~ '^\s*sub\s'
return "<1"
else
return "="
endif
endwhile
else
return "="
endif
endfunction
setlocal foldexpr=GetPerlFold()
setlocal foldmethod=expr
zak at pobox.com, February 4, 2003 0:42
The perl syntax file already has this functionality.
To enable it, just put the line:
let perl_fold=1
in your .vimrc, _vimrc or ftplugin/perl.vim.
webmaster@topfx.com, February 4, 2003 8:47
Aww man ! Why wasn't I told about this before !
Well, at least I learnt a little bit of vimscripting. The let perl_fold=1 seems to do it more
gracefully than my code.
Thanks for the tip.
Anonymous, February 7, 2003 0:05
In most cases one should look into the
$VIMRUNTIME/syntax/*.vim files. There is additional
'documentation' about extra options for folding and
syntax highlighting.
anonymous, February 10, 2003 16:44
Better yet - try ":help perl.vim" (or "help html.vim",
...)
cnf@antwerpen.be, July 4, 2003 12:15
if u put let perl_fold = 1 in your .vimrc
fold on marker doesnt work anymore

http://www.vim.org/tips/tip.php?tip_id=419 (3 of 4) [18/02/2004 14:58:00]

Tip #419 - Auto-fold perl subs (and possibly other languages) : vim online

roberth@hydrix.com, July 14, 2003 10:05


I remember seeing komodo code folding if,elsif,else
clauses as well as functions which was rather cool.
Anonymous, January 26, 2004 14:26
i found let perl_fold = 1 works unreliably-depends on
indentation etc.
The function above works better.
However, that function does not recognize .cgi files as
perl(.pl OK) perl_fold recognizes both.
what to do?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=419 (4 of 4) [18/02/2004 14:58:00]

SourceForge
Logo

Tip #420 - get rid of annoying menu/tool bar : vim online

not logged in (login)

Home
Search

Tip #420: get rid of annoying menu/tool bar


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 30/22, Viewed by 1447

created: February 10, 2003 21:19


author: garbageman

complexity: basic
as of Vim: 6.0

if you also get annoyed by the menu bar and/or tool bar
in the gui version of vim, you can get rid
of them with the following:
set guioptions-=m
bar
set go-=T
bar

" to get rid of the menu


" to get rid of the tool

and then you're back to the look and feel of how vim
should always be =]
-your friendly neighbourhood garbage man.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Auto-fold perl subs (and possibly other languages) | the simplest map to highlight the current line >>

Additional Notes
Anonymous, February 10, 2003 21:21
ofcourse you can also put them back with
set guioptions += ...
Anonymous, February 10, 2003 23:06
and there might be people who do not want to think
about or figure out
HOW they have to do what they want to do - the menu
might help concentrating
on the real problem, not learning VIM.
Anonymous, February 11, 2003 23:11

http://www.vim.org/tips/tip.php?tip_id=420 (1 of 3) [18/02/2004 14:58:03]

Tip #420 - get rid of annoying menu/tool bar : vim online

VIM is a fast and lightweight editor, the menu/toolbar


even if you don't use it, is
not annoying, i don't see any reason to remove it...
Anonymous, February 12, 2003 3:49
Just because those who want to remove the toolbar can,
doesn't mean you have to if you do not want to. So
what's everyone's problem with this tip??
Anonymous, February 12, 2003 4:19
The problem is the title, some people don't think the
menu bar or the toolbar are annoying.
daniel.elstner@gmx.net, February 12, 2003 10:10
Use ed.
mc_gee@qbix.co.ke, February 12, 2003 17:19
i think this #420 was meant for those of us that
appreciated the old days when we were working
on purely console based terms...
the extra two lines gained were much appreciated...
mC-gee
vid, February 12, 2003 17:45
come on?! you people with your menu bar loving... your
kind will be the death of vim: brewing
windoze culture. .. besides, manually invoked commands
are much much faster.. and if you're
xp programmer [http://www.extremeprogramming.org] time
saved is not negligible.
j. vid
daniel.elstner@gmx.net, February 13, 2003 1:50
"your kind will be the death of vim" -- did you ever
contribute any bit of code to Vim? See.
petro@ncf.ca, March 30, 2003 3:18
Thanks for the tip. I never use the menu and the
toolbar anyway. they just take up useful space. :)
tomk@emcity.net, March 31, 2003 13:15

http://www.vim.org/tips/tip.php?tip_id=420 (2 of 3) [18/02/2004 14:58:03]

Tip #420 - get rid of annoying menu/tool bar : vim online

vimtip #89 was also on this very subject. I also prefer


to have more screen real estate, but, sometimes want
the menus handy, so, to reiterate what I posted to that
tip, here are some function keys to toggle the menu and
tool bars:
set guioptions-=T "get rid of toolbar
:let g:toggleTool = 0
map <silent> <F2> :if g:toggleTool == 1<CR>:set
guioptions-=T<CR>:let g:toggleTool = 0<CR>:else<CR>:set
guioptions+=T<CR>:let g:toggleTool = 1<CR>:endif<CR>
"
set guioptions-=m "get rid of menu
:let g:toggleMenu = 0
map <silent> <F1> :if g:toggleMenu == 1<CR>:set
guioptions-=m<CR>:let g:toggleMenu = 0<CR>:else<CR>:set
guioptions+=m<CR>:let g:toggleMenu = 1<CR>:endif<CR>
Tom Kimpton.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=420 (3 of 3) [18/02/2004 14:58:03]

SourceForge
Logo

Tip #421 - the simplest map to highlight the current line : vim online

not logged in (login)

Home
Search

Tip #421: the simplest map to highlight the current line


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 18/9, Viewed by 1515

created: February 10, 2003 23:15


author: Xiangjiang Ma

complexity: basic
as of Vim: 5.7

This is the simplest map to highlight the current line


nn <silent> K mk:exe 'match Search
/\\%'.line(".").'l/'<CR>
Note: abstract from
http://vim.sourceforge.net/tips/tip.php?tip_id=411
http://vim.sourceforge.net/tips/tip.php?tip_id=177
To turn off highlight, type :match<CR>
rate this tip

Life Changing

Helpful

Unfulfilling

<<get rid of annoying menu/tool bar | A Quick Reference >>

Additional Notes
Anonymous, February 11, 2003 9:37
It should be either
'match Search /\%'
or
"match Search /\\%"
Anonymous, February 11, 2003 10:25
The initial

mk

is not required.

Anonymous, February 11, 2003 13:57


why not "V"?
maxiangjiang@hotmail.com, February 11, 2003 20:55

http://www.vim.org/tips/tip.php?tip_id=421 (1 of 3) [18/02/2004 14:58:05]

rate

Tip #421 - the simplest map to highlight the current line : vim online

1. we need double backslash if the map is in .vimrc


2. mk is not needed, but it helps to keep track of the
highlighted line if we type G
3. V is another way, but you are in visual mode then
4. plugin is another way, but lots of keys were remapped
jojo, February 24, 2003 17:13
Regarding above comments...
1. Double backslash fails in my .vimrc, single
backslash works.
2. If I type G I go to the end of the file. I guess
you mean g'k or just 'k
Also,
- Make sure you set 'hlsearch', or else nothing is
highlighted.
(Another option, use another group like
'ErrorMsg' instead of 'Search')
- I only get the first/last character highlighted, to
get the whole line add a '.*' :
nn <silent> K mk:exe 'match ErrorMsg
/\%'.line(".").'l.*/'<CR>
Interesting tip, though...
Anonymous, February 26, 2003 7:40
Seems that vimscript#555 on "Highlighting the Current
Line" is more
apropos than the ones on initializing plugins and
highlighting
matching brackets.
maxiangjiang@hotmail.com, March 3, 2003 9:18
It is interesting to know quite a few people told me
that double backslashes is are not needed.
I only tested on gvim.exe on w2k, and "\\" is needed
in my _vimrc.
A question,

how to make this map to local buffer?

Now, this map works for all buffers. If I highlight


line 3 and then :next <CR> to anther buffer,
line 3 in that file will be highlighted also. That is
not my intention, though.
Thanks
http://www.vim.org/tips/tip.php?tip_id=421 (2 of 3) [18/02/2004 14:58:05]

Tip #421 - the simplest map to highlight the current line : vim online

maxiangjiang@hotmail.com, March 3, 2003 10:01


Okay, finally, I found a working version for both UNIX
and windows.
I tested on Windows and Solaris boxes.
===================================================
nn <silent> K mk:exe 'match Search
/<Bslash>%'.line(".").'l.*'<CR>
===================================================
Anonymous, March 6, 2003 11:55
Again! Why not using "V" in command mode?
maxiangjiang@hotmail.com, March 19, 2003 15:28
V is another way, but you are in visual mode then
rsivara1@baan.com, April 19, 2003 3:52
does it not do automatically?
anonymous, May 7, 2003 10:46
By automatically, do you mean having your line h
ighlighted as you move?
This tip is intended for manual current-line
highlighting; if you want the
line highlighted when you move to it
automatically, check out
vimscript#555
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=421 (3 of 3) [18/02/2004 14:58:05]

SourceForge
Logo

Tip #422 - A Quick Reference : vim online

not logged in (login)

Home
Search

Tip #422: A Quick Reference


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 61/25, Viewed by 4425

created: February 12, 2003 13:38


author: William Natter

complexity: basic
as of Vim: 5.7

After using vi and similar for a few years, I have


accumulated a list of commands I use most often, and pass
it on to people starting with vi. The available quick
reference tends to be verbose, but is useful for people
with more vi experience (type ":help quickref" or go
to http://vim.sourceforge.net/htmldoc/quickref.html). For
beginners, here is my file:

Site Help

VI is a text editor. Its idea is that you manipulate text


(as opposed to enter it all the time). Almost all commands
can be "repeated" a number of times, which you specify
before typing the command itself (to delete a line, type
dd; to repeat the deletion of a line 55 times, type 55dd).
At almost any time, "u" means "undo", and "Esc" stops all
command or text entering. For help, type
:help<enter>. There is a difference between what I call
direct and indirect commands: "u" is a direct command, ":h"
is an indirect one (it uses an underlying program).
:q to quit, :q! to quit without saving
Entering and manipulating text:
Command
.
i<text>Esc
current position
I<text>Esc
beginning of line
a<text>Esc
character position
A<text>Esc
end of the line
o<text>Esc
O<text>Esc
r<character>
repeated times,

http://www.vim.org/tips/tip.php?tip_id=422 (1 of 6) [18/02/2004 14:58:08]

Interpretation
repeat the last command
enter <text> on current line, at
enter <text> on current line, at
enter <text> on current line, at next
enter <text> on current line, at the
enter <text> on a new line below
enter <text> on a new line above
replace characters by <character>

Tip #422 - A Quick Reference : vim online

starting from cursor towards end of


line
s<text>Esc
substitute characters by <text>,
starting from cursor
towards end of line
R<text>Esc
substitute characters by <text>,
starting from cursor
towards end of line
~
change the case
d
delete (combine with a movement: dl
deletes to the
right, d0 deletes to beginning of line,
5dw deletes 5
words forward)
dd
delete line
D
delete to the end of the line (like d$)
c
change (same combinations as with d)
cc
change line
C
change to the end of the line (like c$)
S
change line, like cc
x
delete the character at the current
position
X
delete the character at the left
(backspace)
J
join the next line to the current line
y
yank (copy, same combinations as with
d)
p, ]p
paste the result of the last deletion
or yanking command
after the cursor
P, [p
paste the result of the last deletion
or yanking command
before the cursor
/, ?
find forward, backward (then, n means
next in the same
direction, N means next in the opposite
direction)
Ctrl-a, Ctrl-x
increase, decrease by 1 the number
under the cursor (5Ctrl-a
increases by 5)
:<number1>,<number2>g/<pattern>/<command>
on all lines within <number1>,<number2>
range and matching
<pattern>, execute <command>.
:3,$g/^ table/d
deletes all lines from 3 to end of
buffer that start
with " table"
:%g/[a-z0-9]$/s/boo/table/
on all lines in buffer that end
with a lowercase letter
http://www.vim.org/tips/tip.php?tip_id=422 (2 of 6) [18/02/2004 14:58:08]

Tip #422 - A Quick Reference : vim online

or a digit, replace "boo" with


"table"
:%g/[^RT]umble.*cran[0-6]/m'a
move all lines in buffer of the
kind "Aumble...cran4"
or "Gumble...cran6" (NOT Tumble or
Rumble) underneath
line marked as a.
:<number1>,<number2>v/<pattern>/<command>
on all lines within <number1>,<number2>
range and not
matching <pattern>, execute <command>.
:<number1>,<number2>!<command>
execute shell <command> on lines
<number1> to <number2>
Moving around:
Command
0, $
h, j, k, l
the arrow keys)
H, M, L
line on screen
{, }
%
square bracket or

Interpretation
jump to the beginning, end of the line
left, down, up, right (you can also use
jump to the highest, middle, lowest
move up, down to the next empty line
jump to the corresponding parenthesis,
curly brace
jump to the beginning, end of the file
jump to the beginning, end of the file
jump to line <number> (without the

[[, ]]
:1, :$
<number>G
number, jumps to the

end of the file)


Ctrl-f, Ctrl-b
next page down, up
Ctrl-d, Ctrl-u
next half-page down, up
Ctrl-e, Ctrl-y
shift all the text by one line down, up
w, b
go forward, backward to the next word
e, ge
go to the end of the word, backwared to
the end of the previous word
f<char>
goes to the next <char> in the current
line
t<char>
goes to the character just before the
next <char>
m<character>, '<character>
set mark <character>, go to mark
<character>
''
go to the line that was last modified
Manipulating files:
Command
http://www.vim.org/tips/tip.php?tip_id=422 (3 of 6) [18/02/2004 14:58:08]

Interpretation

Tip #422 - A Quick Reference : vim online

:r <file>
read file in
:w <file>
write current buffer to <file>
(default: write current
buffer to current file, if defined)
:w! <file>
same as write file, overriding
permissions
:wq, ZZ
write to file and quit
:wq!
write to file and quit, no matter what
:sp <file>
split window and edit file
:e <file>
edit <file>
:n
edit next file in list
:ls
list buffers
:buf <number>
edit buffer number <number>
Executing a command easily several times:
Mapped keys:
To map a key to a command to execute, type:
:map <key> <command>
Then, type <key> to execute <command>.
Macros:
To enter a macro, type:
q<character><commands>q
To execute the macro <number> (default: 1) times, type:
<number>@<character>
Important note: macros can contain calls to mapped
keys.
Registers:
To use a register named <character>, type "<character>
before your command.
Example: copying the word under the cursor and saving
into register z:
"zyw
Example: pasting the result of register c before this
word or line:
"cP
Important note 1: register characters are independent
http://www.vim.org/tips/tip.php?tip_id=422 (4 of 6) [18/02/2004 14:58:08]

Tip #422 - A Quick Reference : vim online

of marks ('a is not affected by "a)


Important note 2: a macro named <character> is actually
stored in the register of same name. To edit the macro f,
just create a new line (o<Esc>), paste the contents of
register f ("fp), edit the commands (...), go to the
beginning of the line and delete/store the line into
register f (0"fD), and remove the temporary line (dd).
Additions to this file are welcome, but make sure it's
concise...
William

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<the simplest map to highlight the current line | Finding more available keys to map >>

Additional Notes
Anonymous, February 12, 2003 22:31
To vi beginners I always say
"Think in English what you want to do, then type the
first letters of that words and just do it."
For Windows users it could be useful to have most of
these commands entered in the menu
until they get used to the keyboard shortcuts.
Thomas
Anonymous, February 13, 2003 9:23
Just a note about Ctrl-A and Ctrl-X. William says these
work to increment or decrement the number under the
cursor, but I have found that VIM's behavior is even more
handy: You don't have to have the cursor ON the number;
the incrementing or decrementing works for the next
number on the line on or after the cursor.
nonline@kocharhook.com, April 19, 2003 0:54
You're right about the next number after the cursor part,
but it appears Vim sticks to the same line. Still useful
as all heck. I like doing things such as "35^A".
Add Note

http://www.vim.org/tips/tip.php?tip_id=422 (5 of 6) [18/02/2004 14:58:08]

Tip #422 - A Quick Reference : vim online


If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=422 (6 of 6) [18/02/2004 14:58:08]

SourceForge
Logo

Tip #423 - Finding more available keys to map : vim online

not logged in (login)

Home
Search

Tip #423: Finding more available keys to map


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -5/7, Viewed by 1067

created: February 13, 2003 8:07


author: Marion W. Berryman

complexity: basic
as of Vim: 5.7

One of my ongoing problem with VIM is finding more keys


on my keyboard onto which I can map functions without
losing some other functionality. I finally went on a
search of terminal emulations that maximize the
programability of the keyboard when accessing Linux
servers from a Windows 2000 client.
I am in no way associated with the author or the
company, but I wanted to give other VIM users a pointer
to check out the ZOC terminal emulator from Emtec at
http://www.emtec.com/zoc. Not only does this support
full use of the Alt key, but it also supports compete
remapping based on the NumLock and ScrollLock
keys. Keys can be mapped to send any string including
binary codings. ZOC also supports a Linux console
terminal mode.
Again I'm not advertising for a particular product; I'm
just passing on my solution to a particularly onerous
problem when attempting to use the full potential of
VIM.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<A Quick Reference | Copy, cut, and paste macros that also work in old vi >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=423 [18/02/2004 14:58:11]

SourceForge
Logo

Tip #424 - Copy, cut, and paste macros that also work in old vi : vim online

not logged in (login)

Home
Search

Tip #424: Copy, cut, and paste macros that also work in old vi
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 8/9, Viewed by 1450

created: February 13, 2003 9:13


author: M.W. Berryman

complexity: basic
as of Vim: 5.7

The following three mappings implement a useful, quick


line-oriented copy, cut, and paste scheme that not only
works in VIM but also standard old vi. These macros use
yank or delete commands to either copy or delete lines
to named register m where those lines are defined by the
motion command to mark m. The put command is then used
to insert the contents of register m at the desired
location.
There's nothing special about mark m or register m,
thery're just somewhere in the middle. Meta-g is
mnemonic for "get". Meta-v looks like an insertion
mark. Meta-q looks like Meta-g but with a twist. Of
course any other keys, registers, or marks could be
used.
map <M-g> mn"my'm`n
map <M-q> "md'm
map <M-v> "mp
To copy some lines ( only in command mode ):
1. Put the cursor on the first or last line and press
"mm"
2. Move to the other end of the line range, last or
first, and press meta-g
3. Move to the line above where you wish to insert the
lines and press meta-v
To cut some lines and move them to a new location use
the same procedure but replace meta-g in step 2 with
meta-q.
I find that in programming I constantly use these simple
functions to position code in the proper place. I
started using this scheme years ago and find it useful
now because not all systems have vim, and because it is
so quick and easy that it has become part of my finger
habits. Some day I will have to learn the visual mode

http://www.vim.org/tips/tip.php?tip_id=424 (1 of 2) [18/02/2004 14:58:13]

Tip #424 - Copy, cut, and paste macros that also work in old vi : vim online

of VIM better.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Finding more available keys to map | Forcing Syntax Coloring for files with odd extensions >>

Additional Notes
gmann@femto.med.unc.edu, February 16, 2003 18:08
Just making sure this is here as
well: http://vim.sf.net/tip_view.php?tip_id=312

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=424 (2 of 2) [18/02/2004 14:58:13]

SourceForge
Logo

Tip #425 - Forcing Syntax Coloring for files with odd extensions : vim online

not logged in (login)

Home
Search

Tip #425: Forcing Syntax Coloring for files with odd extensions
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 33/23, Viewed by 1691

created: February 13, 2003 11:32


author: zzapper

complexity: basic
as of Vim: 5.7

If you are editting a file containing PHP script (for


example) but the file doesn't have the extension .php
you can force the desired syntax coloring with
:set syntax=php
similarly
:set syntax=perl
:set syntax=html
Alternatively if the extension causes an undesired
coloring, switch off coloring with
:set syntax=off
look in the directory *vim/vim61/colors/ for supported
languages

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Copy, cut, and paste macros that also work in old vi | Protecting a file you're referencing >>

Additional Notes
zzapper@ntlworld.com, February 13, 2003 11:45
Of course I meant
look in */vim/vim61/ftplugin
ftplugin == FileType Plugin
Anonymous, February 13, 2003 22:52

http://www.vim.org/tips/tip.php?tip_id=425 (1 of 4) [18/02/2004 14:58:15]

Tip #425 - Forcing Syntax Coloring for files with odd extensions : vim online

you can also let vim determine the filetype by


examining the file contents with getline(),
see ':h new-filetype-scripts'
Thomas
Anonymous, February 13, 2003 23:01
I got these detections by content in my
$VIM/vimfiles/ftplugin/filetype.vim:
" IAR option files for compiler/linker
if getline(1) =~ '-!'
set ft=xcl
" c/cpp in any file containing c/cpp comment in line
1 or 2
elseif ((getline(1) =~ '\/\*') || (getline(1)=~
'\/\/') || (getline(2) =~ '\/\*') || (getline(2)=~
'\/\/'))
set ft=c
" dosbatch in any file containing comment in line 1,
2 or 3
elseif ((getline(1) =~ '^rem') || (getline(2)=~
'^rem') || (getline(3)=~ '^rem'))
set ft=dosbatch
endif
This already worked in vim5.x using script file, see
':h myscriptsfile'
Thomas
goulding@princeton.edu, February 14, 2003 11:43
You mean vim/vim61/syntax. The ftplugin files contain
such things as useful mappings for editing certain
filetypes, not syntax colouring.
rpresser@imtek.com, February 17, 2003 11:10
What is the difference between
:set syntax=blahblahblah
and
:cal SetSyn("blahblahblah")
? When I select a syntax from the default menus on
win32 gvim, it uses the latter.

http://www.vim.org/tips/tip.php?tip_id=425 (2 of 4) [18/02/2004 14:58:15]

Tip #425 - Forcing Syntax Coloring for files with odd extensions : vim online

Anonymous, February 17, 2003 15:21


Something that is also very useful for PHP
programmers: Sometimes, when you are at a particular
place in a file, the Vim buffer "forgets" what the
highlighting should be, PHP or HTML. First, try
refreshing the window using Ctrl-L. If this does not
work, then try changing php_minlines. This can be done
by the following line in your .vimrc file.
let php_minlines=500
The default is 100 lines.
Anonymous, February 17, 2003 23:17
@goulding:
I do mean '$VIM/vimfiles/ftplugin/filetype.vim', on
Windows NT.
the filetype.vim coming with the VIMdistribution/installation is located in $VIM/.
To keep my own stuff away from the original
distribution files, I use that 'vimfiles' directory
(it's another name on Unix, may be '.vim' ?). I have
additional private syntax files
like $VIM/vimfiles/after/syntax/c.vim, which contains
additional syntax coloring definitions
I like to have e.g. for C/C++ formalised comments.
Thomas
jaldri1 at gl dot umbc dot edu, July 8, 2003 9:39
fun! SetSyn(name)
can be found in
synmenu.vim
in ($VIM/vim62 on
win2k); and after some initial handling, runs:
exe "set syn=" . name
On Win2k, the current all-in-one installer puts the
default filtype.vim in
$VIM/vim62.
My augmentation
of filetype.vim (with the same name) is under
$VIM/vimfiles.
Check out
:h runtime
:h runtimepath
to understand the search order.
http://www.vim.org/tips/tip.php?tip_id=425 (3 of 4) [18/02/2004 14:58:15]

I have a number of

Tip #425 - Forcing Syntax Coloring for files with odd extensions : vim online

syntax highlighting files under


$VIM/vimfiles/syntax,
only a couple of ftplugins
under
$VIM/vimfiles/ftplugin
(typically for key
mapings), and one indent file under
$VIM/vimfiles/indent.
But, any special handling for
filetype detection goes in the
filetype.vim.
LoneOwl, October 26, 2003 13:32
Using ':setf perl' also works well, and is fewer
characters.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=425 (4 of 4) [18/02/2004 14:58:15]

SourceForge
Logo

Tip #426 - Protecting a file you're referencing : vim online

not logged in (login)

Home
Search

Tip #426: Protecting a file you're referencing


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/11, Viewed by 910

created: February 13, 2003 11:42


author: zzapper

complexity: basic
as of Vim: 5.7

A common programmimg situation, you are comparing two


versions of the same file.
One is the "reference file" which you DONT WANT to
update.
However they look so similar that you can get confused.
Solution:
:set ro
(readonly) in the master file
additionally change it's color scheme (peachpuff is
quite a benign one!)
:colorscheme peachpuff
look in vim/vim61/colors for available colorschemes
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Forcing Syntax Coloring for files with odd extensions | Fast window resizing with +/- keys >>

Additional Notes
Anonymous, February 19, 2003 11:15
I would also :set nomodifiable on the reference file.
zzapper@ntlworld.com, February 22, 2003 6:11
:set noma
(non modifiable)
Yes this is better than :set ro as it won't even let
you start changing stuff.
:set ro will only warn you (once)
zzapper@ntlworld.com, February 26, 2003 8:21

http://www.vim.org/tips/tip.php?tip_id=426 (1 of 2) [18/02/2004 14:58:18]

Tip #426 - Protecting a file you're referencing : vim online

You can permanently protect a file by setting a


suitable modeline (:h modeline)
// vim:noma
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=426 (2 of 2) [18/02/2004 14:58:18]

SourceForge
Logo

Tip #427 - Fast window resizing with +/- keys : vim online

not logged in (login)

Home
Search

Tip #427: Fast window resizing with +/- keys


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 32/25, Viewed by 2199

created: February 14, 2003 6:00


author: Bob Heckel

complexity: basic
as of Vim: 5.7

Depending on your willingness to occasionally consume


the + and - keys, here's a fast way to resize the active
window if you have more than one window open:
if bufwinnr(1)
map + <C-W>+
map - <C-W>endif
I normally use the scrollpad + and - keys.
The map eliminates the need for time-consuming chording
and if you liked chording, you'd be using Emacs instead
of Vim anyway...

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Protecting a file you're referencing | Wordwise Ctrl-Y in insert mode >>

Additional Notes
gmann@femto.med.unc.edu, February 16, 2003 15:18
Depending on your screen size, and your brain's memory
capacity for more vim mappings (caution this will
affect your every day speech when vim mappings exceeds
100), you may want to increase the windows' frame size
to some preselected settings. I am sure there is a
more elegant solution for incrementing the size of this
(get the current setting into the buffer, increment it
and set it again). I am too lazy so I use full screen
and min screen based on my 1400x1050 and
guifont=lucida_console:h7:w5 " small (94 lines in one
screen)

http://www.vim.org/tips/tip.php?tip_id=427 (1 of 4) [18/02/2004 14:58:20]

Tip #427 - Fast window resizing with +/- keys : vim online

map <M-[> :set


"fullscreen
map <M-]> :set
"minimumscreen
map <M-\> :set
default screen

co=210<CR>:set lines=180<CR>
co=50<CR>:set lines=50<CR>
co=120<CR>:set lines=80<CR>
size

"my

webmaster@topfx.com, February 19, 2003 20:32


I'm not much for resizing windows.. However, I stole
your tip and made a slight modification:
if bufwinnr(1)
map - <C-W><UP>
map + <C-W><DOWN>
endif
Now I can go through my open windows very easily with +
and - :)
alex@netWindows.org, February 24, 2003 14:17
the <C-W><UP> and <C-W><DOWN> work well if you're only
split horizontally, but if you split vertically, this
might make rotating between windows a bit easier:
if bufwinnr(1)
map - <C-W><C-W>
map + <S-C-W><S-C-W>
endif
HTH
daniel@brot.t0c.de, February 26, 2003 22:20
I have several mappings for window movement/operations
in my .vimrc, too.
Here are some of them:
| map + <c-w>+
| map - <c-w>What was posted as the original tipp. I had the same
idea, i think ;-)
| map <c-n> <c-w><
| map <c-m> <c-w>>
Similar to the mappings above, but for horizontal
resizing.
| map <c-w>F <c-w>_<c-w><bar>
Fullscreen the actual window. (not depending on the

http://www.vim.org/tips/tip.php?tip_id=427 (2 of 4) [18/02/2004 14:58:20]

Tip #427 - Fast window resizing with +/- keys : vim online

terminal's size)
| map <Up> <c-w>k<c-w>_<c-w><bar>
| map <Down> <c-w>j<c-w>_<c-w><bar>
| map <Left> <c-w>h<c-w>_<c-w><bar>
| map <Right> <c-w>l<c-w>_<c-w><bar>
Walking through windows and make them fullscreen at the
same time.
In addition, I've set winminwidth and winminheight to
0.
cu, Daniel
szathml@delfin.klte.hu, June 28, 2003 18:26
Using the ideas above I come up with this version :)
"Fast window resizing with +/- keys (horizontal); / and
* keys (vertical)
if bufwinnr(1)
map <kPlus> <C-W>+
map <kMinus> <C-W>map <kDivide> <c-w><
map <kMultiply> <c-w>>
endif
+ / - didn't work for me, it moved the cursor up and
down, but with kPlus, etc. it's OK.
Laszlo
fishburn@ianywhere.com, November 11, 2003 13:53
I have added the following to my vimrc file.
This came from the list, author unknown.
Holding down the SHIFT key and using the arrow keys is
quick and efficient for resizing the windows.
" Window
nnoremap
nnoremap
nnoremap
nnoremap

resizing mappings /*{{{*/


<S-Up>
:normal <c-r>=Resize('+')<cr><cr>
<S-Down>
:normal <c-r>=Resize('-')<cr><cr>
<S-Left>
:normal <c-r>=Resize('<')<cr><cr>
<S-Right> :normal <c-r>=Resize('>')<cr><cr>

function! Resize(dir)
let this = winnr()
if '+' == a:dir || '-' == a:dir
execute "normal \<c-w>k"
let up = winnr()
if up != this
execute "normal \<c-w>j"
http://www.vim.org/tips/tip.php?tip_id=427 (3 of 4) [18/02/2004 14:58:20]

Tip #427 - Fast window resizing with +/- keys : vim online

let x = 'bottom'
else
let x = 'top'
endif
elseif '>' == a:dir || '<' == a:dir
execute "normal \<c-w>h"
let left = winnr()
if left != this
execute "normal \<c-w>l"
let x = 'right'
else
let x = 'left'
endif
endif
if ('+' == a:dir && 'bottom' == x) || ('-' == a:dir
&& 'top' == x)
return "5\<c-v>\<c-w>+"
elseif ('-' == a:dir && 'bottom' == x) || ('+' ==
a:dir && 'top' ==
x)
return "5\<c-v>\<c-w>-"
elseif ('<' == a:dir && 'left' == x) || ('>' ==
a:dir && 'right' ==
x)
return "5\<c-v>\<c-w><"
elseif ('>' == a:dir && 'left' == x) || ('<' ==
a:dir && 'right' ==
x)
return "5\<c-v>\<c-w>>"
else
echo "oops. check your ~/.vimrc"
return ""
endif
endfunction
" /*}}}*/
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=427 (4 of 4) [18/02/2004 14:58:20]

SourceForge
Logo

Tip #428 - Wordwise Ctrl-Y in insert mode : vim online

not logged in (login)

Home
Search

Tip #428: Wordwise Ctrl-Y in insert mode


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/7, Viewed by 1365

created: February 18, 2003 0:19


author: Dubhead

complexity: basic
as of Vim: 5.7

Ctrl-Y in insert mode is one of Vim's handy extensions


that inserts character which is above cursor (see :help
i_CTRL-Y). However, sometimes this is not very useful
when a user wants to insert many characters. In this
case it's better to get a *word* above cursor.
Put this in ~/.vimrc:
" Wordwise Ctrl-Y in insert mode
noremap! <C-Y> <Esc>klyWjpa
You might want to substitute 'W' with 'w', 'E', or
'e'. Try them and choose one that works best for you.
Unfortunately, this simple map doesn't work at the
beginning or end of line. Improvements are welcome.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Fast window resizing with +/- keys | Using '< and '> marks >>

Additional Notes
cec@NgrOyphSon.gPsfAc.nMasa.gov, February 20, 2003 8:27
How about a small mod:
noremap! <C-Y> <Esc>klyWjPa
cec@NgrOyphSon.gPsfAc.nMasa.gov, February 25, 2003 11:43

http://www.vim.org/tips/tip.php?tip_id=428 (1 of 2) [18/02/2004 14:58:23]

Tip #428 - Wordwise Ctrl-Y in insert mode : vim online

Other interesting variants, depending upon what one


wants:
inoremap <C-Y> <Esc>klyiWjPa
inoremap <C-Y> <Esc>klyiwjPa
The yiw yanks the "inner word", yiW yanks the "inner
WORD".
Both of these forms appear to work at both the
beginning and
end of sentences, with the exception that neither works
for a
single letter word at the beginning of a sentence.
Tobi, May 2, 2003 7:41
I think,
:imap <F1> <C-O>:set virtualedit=all<CR><C-O>k<C-O>yw<CO>j<C-O>P<C-O>:set virtualedit=<CR>
is a little bit better, but not really satisfying (a
bug in virtualedit/<C-O> ?)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=428 (2 of 2) [18/02/2004 14:58:23]

SourceForge
Logo

Tip #429 - Using '< and '> marks : vim online

not logged in (login)

Home
Search

Tip #429: Using '< and '> marks


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 20/11, Viewed by 1954

created: February 18, 2003 4:50


author: Max Ischenko

complexity: intermediate
as of Vim: 5.7

Today I discovered that '< and '> persists even after


the selection is gone.
Thus, to repeat an Ex command over a previously selected
(via V command) block
just use : history -- no need to reselect block again.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Wordwise Ctrl-Y in insert mode | Fast switching between buffers >>

Additional Notes
cec@NgrOyphSon.gPsfAc.nMasa.gov, February 20, 2003 8:18
gv is even easier!
Max Ischenko, February 21, 2003 6:04
> gv is even easier.
To repeat an Ex command (like :s) you don't have to
reselect block at all, so gv is not needed.
That's the point of this tip.
yeti@physics.muni.cz, February 21, 2003 9:52
Most people can type gv: much faster than :'<,'> (just
try it :-)
Moreover, gv makes the selection visible. (Yes, I know,
it's very non-vi to have a visual feedback for what you
are doing ;-)
Max Ischenko, February 24, 2003 1:20

http://www.vim.org/tips/tip.php?tip_id=429 (1 of 2) [18/02/2004 14:58:25]

Tip #429 - Using '< and '> marks : vim online

> Most people can type gv: much faster than :'<,'>
I bet typing :<Up> still faster then gv:<Up>.
rickismyid@yahoo.com, March 5, 2003 5:09
I think just pressing the period will work too. Unless
I'm missunderstanding what is being done.
jaldri1 at gl dot umbc dot edu, June 6, 2003 12:47
So, I can start a visual block with <c-v> (win: <c-q>
|CTRL-V-alternative|) at the start of some columen and
select some text with, say, 4j$.
Now I have a
highlighted selection.
I can press y to yank. If I
press :, ex mode starts with :'<,'> already filled
in. If I press !, I get :'<,'>!. Unfortunately, if I
enter an external command such as sort, it operates on
the whole lines (^.*$) not just the column of the
visual block.
Anyway, I can yank and move elsewhere, paste, and then
return to the original selection with gv (not
:gv). And, that selection will be highlighted just as
before.
I can also use '< to move to the first line
of the selection or '> to move to the last line of the
selection.
Have I explained it well enough, or was there more
intended?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=429 (2 of 2) [18/02/2004 14:58:25]

SourceForge
Logo

Tip #430 - Fast switching between buffers : vim online

not logged in (login)

Home
Search

Tip #430: Fast switching between buffers


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 45/26, Viewed by 1835

created: February 28, 2003 11:59


author: Prateek Jetly

complexity: basic
as of Vim: 5.7

This is one for Tab key fans. I use these mapping to


quickly cycle between buffers using Tab and
Shift-Tab. I use them in normal more as I use tab for
word completion when in editing more. Put these in your
.vimrc or gvimrc. The buffer will be written before
switching to the next one. The test makes sure that the
file can be written to and is modified.
nmap
<cr>
nmap
<cr>

<tab> :if &modifiable && !&readonly && &modified


:w<cr> :endif<cr> :bn<cr>
<s-tab> :if &modifiable && !&readonly && &modified
:w<cr> :endif<cr> :bp<cr>

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using '< and '> marks |


map to toggle between backslash and forwardslash >>

Additional Notes
vigor96@linux.co.kr, March 4, 2003 16:35
it is better than using "write buffer" to ":set hidden"
salmanhalim@hotmail.com, March 5, 2003 6:06
Instead of doing all these checks, if you want the
buffer to be written automatically if you move away and
it's been modified, why not simply set 'autowrite' in
your vimrc? That way, you can map to simply :bn<cr> or
:bp<cr>. (It won't discard the buffer if autowrite is
NOT set -- it'll give you an error message.)
Add Note

http://www.vim.org/tips/tip.php?tip_id=430 (1 of 2) [18/02/2004 14:58:27]

Tip #430 - Fast switching between buffers : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=430 (2 of 2) [18/02/2004 14:58:27]

SourceForge
Logo

Tip #431 - map to toggle between backslash and forwardslash : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #431:
map to toggle between backslash and forwardslash
tip karma

Rating 8/4, Viewed by 663

created: March 3, 2003 21:11


author: maxiangjiang@hotmail.com

complexity: basic
as of Vim: 5.7

Microsoft is backward, ie, using C:\Progra~1\Outloo~1\


To get it back forward, we can do
:s#\\#/#g<CR>
Now, life turns back to normal: C:/Progra~1/Outloo~1/
However, to copy and paste this normal path to Windows'
applications,
we have to substitute slash to backslash:
:s#/#\\#g<CR>
Here came a small map to toggle between "/" and "\"
within one line.
Usage:
Put the cursor on "/", and type v\, all "/" becomes "\".
Put the cursor on "\", and type v\, all "\" becomes "/".
Map:
vn <silent><Bslash> y:let c=getline(line("."))[col(".")1]
\<CR>:if(c=='/')<Bar>s#/#\\<CR><Bar>elseif(c=='\')
\<Bar>s#\\\\#/<CR><Bar>endif<CR>`<
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Fast switching between buffers | Putting the current file on the Windows clipboard >>

Additional Notes
salmanhalim@hotmail.com, March 5, 2003 6:24

http://www.vim.org/tips/tip.php?tip_id=431 (1 of 3) [18/02/2004 14:58:29]

Tip #431 - map to toggle between backslash and forwardslash : vim online

I think that TWO different mappings, one to convert to


backslash and one to convert to slash are probably
better (v/ and v\) rather than running double-duty with
the one mapping, especially one whose behaviour is
controlled by context. With two different mappings,
one doesn't have to move the cursor until it's
positioned just so -- it can be anywhere on the line -and one doesn't have to worry about knowing the
contextual behaviours of the mapping -- v/ converts to
/ and v\ converts to \: simple.
One other question:
mode?

WHY are these mappings visual

The other thing I absolutely can't stand are supposed


no-side-effect mappings which change the search
register!
Something like:
nmap <silent> v/ :let tmp=@/<cr>:s:\\:/:ge<cr>:let
@/=tmp<cr>
nmap <silent> v<bslash> :let
tmp=@/<cr>:s:/:\\:ge<cr>:let @/=tmp<cr>
Seems easier to manage -- one hits the slash one wants,
one still hits the v first, but the mappings are no
longer visual mode, it is no longer context dependent
AND the search register is restored.
maxiangjiang@hotmail.com, March 5, 2003 8:02
My map is actually as following (to reset search
registry):
nn g/ :let @/=@_<Bar>echo line("'>")-line("'<")+1<CR>
vm <silent><Bslash> y:let c=getline(line("."))[col(".")1]
\<CR>:if(c=='/')<Bar>s#/#\\<CR><Bar>elseif(c=='\')
\<Bar>s#\\\\#/<CR><Bar>endif<CR>g/`<
It is not necessary to use visual mode mapping. It is
just for
my conviencence, because I don't have enough normal
keys for
mapping :).
v/ and v\ are a good idea, but we lost one default map:
"v" (go
to visual mode).

http://www.vim.org/tips/tip.php?tip_id=431 (2 of 3) [18/02/2004 14:58:29]

Tip #431 - map to toggle between backslash and forwardslash : vim online

Also, using one map to toggle between "/" and "\" is


fun to show
off vim to those who never uses vi/vim.

salmanhalim@hotmail.com, March 6, 2003 6:14


So don't use 'v' -- use another character. For what
it's worth, ambiguous mappings are now allowed and
hitting v will simply go to visual mode after a brief
timeout. (I mapped vv to the visual mode a long time
ago so I could do other stuff with v.)
I only used 'v' so that I wouldn't change what you had
done TOO much -- I actually like to start my mappings
with <leader>.
I like the search registry thing.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=431 (3 of 3) [18/02/2004 14:58:29]

SourceForge
Logo

Tip #432 - Putting the current file on the Windows clipboard : vim online

not logged in (login)

Home
Search

Tip #432: Putting the current file on the Windows clipboard


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/4, Viewed by 734

created: March 5, 2003 6:39


author: Salman Halim

complexity: basic
as of Vim: 6.0

Sometimes I want to use the file I'm editing in Vim (on


Windows) in another application; I created the following
command:
com! Copyfile let @*=substitute(expand("%:p"), '/', '\',
'g')
This simply copies the entire path and filename of the
current file -- substituting backslashes for slashes (in
case there are any) -- onto the Windows clipboard. I
can then just go and paste the value wherever I want
(such as a File -> Open dialog).
For example, for my _vimrc file, I get c:\vim\_vimrc in
the clipboard.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<
map to toggle between backslash and forwardslash | a rough mapping to spellcheck the buffer >>

Additional Notes
salmanhalim@hotmail.com, March 5, 2003 6:42
As an addendum, I didn't want to make a mapping out of
this because I don't do it often enough; however, one
can easily do something like:
:map <leader>cf :Copyfile<cr>
I noticed that hitting :C<tab> was almost as fast as
the mapping characters anyway.
maxiangjiang@hotmail.com, March 5, 2003 7:52

http://www.vim.org/tips/tip.php?tip_id=432 (1 of 3) [18/02/2004 14:58:32]

Tip #432 - Putting the current file on the Windows clipboard : vim online

Here is my map to do the same thing:


nn <silent><C-G> :let @*='<CR>=expand("%:p")<CR>'<CR>:f<CR>
I overloaded <C-G>, and because I set ssl, I don't need
worry about backslash.
salmanhalim@hotmail.com, March 6, 2003 6:22
The problem with your mapping is you're corrupting the
clipboard every time you want to simply get information
about where one is in the file. (I actually use ctrl-g
every so often and it would be nice if it didn't have a
side effect.) Basically, for new users, overloading
existing commands with side effects can become
confusing and not intuitive.
The whole point of 'ssl' is to replace backslashes with
FORWARD slashes. It doesn't help with pasting the
filepath into another Windows application -- SOME of
them may understand forward slashes but many will not,
hence the substitution.
You don't need the quotes around the let expression in
your mapping.
salmanhalim@hotmail.com, March 6, 2003 11:04
Let me correct myself: you DO need the quotes around
your mapping the way you have it. However, you can
simply change it to:
nn <silent><C-G> :let @*=expand("%:p")<CR>:f<CR>
Assignments accept expressions that aren't literals so
you don't need the register expansion.
maxiangjiang@hotmail.com, March 7, 2003 14:56
Wow. Thanks. That is great!
I just modified all register assignment statements in
my vimrc!
epoc@bsab.com, March 8, 2003 2:50

http://www.vim.org/tips/tip.php?tip_id=432 (2 of 3) [18/02/2004 14:58:32]

Tip #432 - Putting the current file on the Windows clipboard : vim online

For vim rookies -like me- the way to copy current file
content in Windows clipboard is
:1,$ y *
that is, yanking from line 1 to end-of-file represented by $- into register '*'. After that, go to
Notepad and do a simply CTRL + V. And map it, if you
want
:map <F3> :1,$ y * <CR>
maxiangjiang@hotmail.com, March 9, 2003 20:04
simpler one:
:%y*<CR>
Anon, March 10, 2003 6:02
The file-content copy things probably should be a
separate tip altogether. Plus, it's not complete
without a mention of the 'clipboard' and 'guioptions'
options. Try :help gui-clipboard for more details.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=432 (3 of 3) [18/02/2004 14:58:32]

SourceForge
Logo

Tip #433 - a rough mapping to spellcheck the buffer : vim online

not logged in (login)

Home
Search

Tip #433: a rough mapping to spellcheck the buffer


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/2, Viewed by 538

created: March 5, 2003 11:26


author: leorosa

complexity: intermediate
as of Vim: 6.0

well, certainly
well, certainly there are plugins to do this much
better, but, if you
like to have most of the stuff placed on your vimrc
file, the
following must help:
map ,SS :exec system("ispell -l -t -d br <
".expand("%")." \| sort -u \| sed 's/\\(.*\\)/syntax
match Underlined \"\\\\<\\1\\\\>\" contains=TOP /'")
basically, i use 'ispell' to collect all misspelled
words, and assign
each one to the 'Underlined' syntax group (seems better
than 'Error')
=]
improvements aren't so hard to do; actually, I use
another mappings
for another 'spell' functions, but the essential can fit
in just one
line;
leorosa
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Putting the current file on the Windows clipboard | Autogroup commands for C/C++ editing inserting skeletons etc (long post!) >>

Additional Notes
Anonymous, March 5, 2003 11:29

http://www.vim.org/tips/tip.php?tip_id=433 (1 of 2) [18/02/2004 14:58:34]

Tip #433 - a rough mapping to spellcheck the buffer : vim online

of course, "-d br" option of ispell are only applied to


portuguese documents...
leorosa
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=433 (2 of 2) [18/02/2004 14:58:34]

SourceForge
Logo

Tip #434 - Autogroup commands for C/C++ editing - inserting skeletons etc (long post!) : vim online

not logged in (login)

Home
Search

Tip #434: Autogroup commands for C/C++ editing - inserting skeletons etc (long post!)
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/2, Viewed by 1104

created: March 6, 2003 0:09


author: Karthick Gururaj

complexity: intermediate
as of Vim: 6.0

Hi all,
When you start editing a *.h file, you'd need some format like this:
CODE STARTS:
/*****************************************************************
* Filename: abc.h
* Description:
* Created: Mar 5 03 09:00:00
* Last modified: Mar 6 03 09:00:00
* <some more stuff like author, copyright, blah-blah>
*
* Revision History
*
Date
Author
Remarks
*
Mar 5 2003
KG
File Created
*******************************************************************/
#ifndef _ABC_H_
#define _ABC_H_
#endif
// vim:ts=3:sw=3:ft=c
CODE ENDS
I wanted my gvim to do the following things at various stages of editing a abc.h
file:
1. Upon opening a new file, insert the skeleton like the one above, and leave me in
insert mode after "Description"
2. When writing a file, update the "Last Modified" timestamp
3. On opening a existing file, modify the "Revision History" to add a new line, and
leave me in insert mode below "Remarks"

http://www.vim.org/tips/tip.php?tip_id=434 (1 of 6) [18/02/2004 14:58:37]

Tip #434 - Autogroup commands for C/C++ editing - inserting skeletons etc (long post!) : vim online

The following autogroup (:help au) commands let you do these (put these in your
.vimrc):
CODE STARTS:
if !exists("autocommands_loaded")
let autocommands_loaded = 1
au BufNewFile *.h call InsertCHHeader()
au BufWrite *.h call ModifyTime()
" You might want to comment-out the line below - see note 6 at the end of the
post.
au BufReadPost *.h call ModifyHeader()
endif
function! InsertCHHeader()
call InsertSkeleton("skeleton.h")
call InsertFname()
1
" Search for Description
call search("Description:")
normal $
startinsert
endfunction

" CHANGE this!

function! InsertSkeleton(fname)
let path_to_skeletons = $HOME . "/etc/skeletons/" " CHANGE this!
" Save cpoptions
let cpoptions = &cpoptions
" Remove the 'a' option - prevents the name of the
" alternate file being overwritten with a :read command
exe "set cpoptions=" . substitute(cpoptions, "a", "", "g")
exe "read " . path_to_skeletons . a:fname
" Restore cpoptions
exe "set cpoptions=" . cpoptions
" Delete the first line into the black-hole register
1, 1 delete _
" Search for Filename:
call search("Filename:")
exe "normal A " . expand("%:t")
" Search for Created:
let current_time = strftime("%b %d %Y %T") "CHANGE this!
call search("Created:")
exe "normal A " . current_time
" Search for Last modified:
http://www.vim.org/tips/tip.php?tip_id=434 (2 of 6) [18/02/2004 14:58:37]

Tip #434 - Autogroup commands for C/C++ editing - inserting skeletons etc (long post!) : vim online

call search("Last modified:")


exe "normal A " . current_time
" Search for Date
let date_line_no = search("Date")
let rev_history = getline(line("."))
let rev_history = substitute(rev_history, "Date
", strftime("%b %d %Y"),
"") " CHANGE this!
let rev_history = substitute(rev_history, "Author", "KG
", "") "CHANGE this!
let rev_history = substitute(rev_history, "Remarks", "File created.", "")
call append(date_line_no, rev_history)
endfunction
function! InsertFname()
" Convert newname.h to _NEWNAME_H_
let fname = expand("%:t")
let fname = toupper(fname)
let fname = substitute(fname, "\\.", "_", "g")
" Search for #ifndef
call search("#ifndef")
exe "normal A " . "_" . fname . "_"
" Search for #define
call search("#define")
exe "normal A " . "_" . fname . "_"
endfunction
function! ModifyHeader()
" Modify header only if we have write permissions
if &readonly == 0
" Search for Date
let date_line_no = search("Date")
if date_line_no != 0
let rev_history = getline(line("."))
" Substitute Date, and Author fields
let rev_history = substitute(rev_history, "Date
", strftime("%b %d
%Y"), "") " CHANGE this!
let rev_history = substitute(rev_history, "Author", "KG
", "") "
CHANGE this!
let rev_history = substitute(rev_history, "Remarks", "", "")
" echo "Modified = " . rev_history
call append(date_line_no, rev_history)
normal j$
http://www.vim.org/tips/tip.php?tip_id=434 (3 of 6) [18/02/2004 14:58:37]

Tip #434 - Autogroup commands for C/C++ editing - inserting skeletons etc (long post!) : vim online

startinsert
endif
endif
endfunction
function! ModifyTime()
" Do the updation only if the current buffer is modified
if &modified == 1
let current_time = strftime("%b %d %Y %X") " CHANGE this!
" Save current position at mark i
normal mi
" Search for Last modified:
let modified_line_no = search("Last modified:")
if modified_line_no != 0 && modified_line_no < 10
" There is a match in first 10 lines
" Go to the : in modified:
exe "normal f:2l" . strlen(current_time) . "s" . current_time
echo "Modified date stamp to " . current_time
sleep 500m
" Restore position
normal `i
endif
endif
endfunction
CODE ENDS
Notes:
1. The strftime( ) function is not-portable. You might need to change the format
specifier for your system
2. The autogroup commands assumes that there is a file called skeleton.h at the
location ~/etc/skeletons.
You might have to modify the path and file name. In my case, the skeleton.h
file looks like:
/******************************************************************************
* Filename:
* Description:
*
* Version: 1.0
* Created:
* Last modified:
* Revision: None
*
http://www.vim.org/tips/tip.php?tip_id=434 (4 of 6) [18/02/2004 14:58:37]

Tip #434 - Autogroup commands for C/C++ editing - inserting skeletons etc (long post!) : vim online

* Author:
Karthick Gururaj
* Company: [Removed]
* e-mail: [Removed]
*
* Revision history
* Date
Author
Remarks
*
******************************************************************************/
#ifndef
#define
#endif
// vim:sw=3:ts=3
Search the script for the pattern "CHANGE" to see where you might have to make
changes..
3. I have not tried to make the script super-portable (that looks obvious eh?). The
reasoning is, any changes are a one time effort.
4. The scripts don't modify search history or register values. I have used one
letter for marking thou'
5. If you open a new header file, and quit it without writing, no file is created.
6. I found having an autogroup command for modifing the revision history everytime
the file is opened to be irritating. So I have disabled this in my system. Note on
note: I also had some problems when trying to open the file thro' the quickfix
window.
7. You can define more such skeletons for other extentions.
8. Feedback is welcome!
Cheers!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<a rough mapping to spellcheck the buffer | remarks to script c.vim : statement oriented editing of C / C++ programs >>

Additional Notes
salmanhalim@hotmail.com, March 8, 2003 11:37

http://www.vim.org/tips/tip.php?tip_id=434 (5 of 6) [18/02/2004 14:58:37]

Tip #434 - Autogroup commands for C/C++ editing - inserting skeletons etc (long post!) : vim online

If you're providing code samples of this complexity, consider submitting a script


instead of a tip.
Also, there are some pretty good scripts for skeleton insertion already submitted
-- they have the added advantage of working with several different filetypes. (I
was debating doing something similar to what you have at one time to make my life
easier, but located one of these instead and haven't ever looked back.)
cobacat@ig.com.br, March 8, 2003 18:25
valews gente
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=434 (6 of 6) [18/02/2004 14:58:37]

SourceForge
Logo

Tip #435 - remarks to script c.vim : statement oriented editing of C / C++ programs : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #435: remarks to script c.vim : statement oriented editing of C /


C++ programs
tip karma

Rating -1/1, Viewed by 820

created: March 6, 2003 23:11


author: Thomas

complexity: basic
as of Vim: 6.0

Seems to be a nice, powerful addition for C-programmers.


The screenshots show a really dangerous C++ trap:
NEVER add C++ comments after a '#define' statement
!
The Preprocessor will substitute the defined text
literally,
so all of your code behind the defined text will be
commented out.
I used abbreviations for C-constructs like 'cfor' for
empty for loops, 'cif' for if then elses, etc.,
so typing in insert mode has not to be interupted. The
cursor will be positioned for entering the following
code.
Another thing is standard C-comments for file/function
headers. I used a command line tool (perl script)
to get a personalized version from a standard template
and read in the output with ':r !<mytool> <options>'.
This is a solution for workgroups where no one HAS to
use VIM.
I had autocommands for automatically read in the comment
headers when opening new header or source files.
Thomas
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Autogroup commands for C/C++ editing - inserting skeletons etc (long post!) | Accidently typed
control-u and lost your input? >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=435 (1 of 2) [18/02/2004 14:58:39]

Tip #435 - remarks to script c.vim : statement oriented editing of C / C++ programs : vim online

Anonymous, September 15, 2003 14:30


It would be nice if you shared the definition of your
abbreviations and such, rather than just talked about
them. It would be much more helpful.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=435 (2 of 2) [18/02/2004 14:58:39]

SourceForge
Logo

Tip #436 - Accidently typed control-u and lost your input? : vim online

not logged in (login)

Home
Search

Tip #436: Accidently typed control-u and lost your input?


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/5, Viewed by 1136

created: March 7, 2003 2:23


author: John Wright

complexity: basic
as of Vim: 5.7

If you've accidently typed control-U to delete a line


then accidently typed ESC straight after that because
you've been using web forms and ESC in IE forms is like
undo and basically you really didn't want to do that
then you should do this:
:let @a = @.
"aP
The . register is basically everything you've just typed
in input mode including the control-U. When you paste
this buffer it acts like you're typing it again and
deletes the line. You need to reassign it to another
register with the let command before you can paste it
properly and get at your nice input.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<remarks to script c.vim : statement oriented editing of C / C++ programs | extending keywords >>

Additional Notes
sb@c-lab.de, March 7, 2003 3:36
If you don't want to change register a, use
:dis .
to see the contents of the . register, than yank with
the mouse.
/Siegfried
Anonymous, March 7, 2003 7:27

http://www.vim.org/tips/tip.php?tip_id=436 (1 of 2) [18/02/2004 14:58:41]

Tip #436 - Accidently typed control-u and lost your input? : vim online

Is there any use for Ctrl-U in insert mode? If not,


why not simply use the following mapping and not have
to worry about losing anything if you press C-U while
you are in insert mode?
imap <C-U> <ESC>a
jaldripublic at comcast dot net, November 17, 2003 7:43
To search for an insert mode control key, use the form:
:h i_ctrl-<letter>
e.g.
:h i_ctrl-u

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=436 (2 of 2) [18/02/2004 14:58:41]

SourceForge
Logo

Tip #437 - extending keywords : vim online

not logged in (login)

Home
Search

Tip #437: extending keywords


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/5, Viewed by 704

created: March 7, 2003 21:31


author: hzp
sometime
(such as
keywords
release,
keywords

complexity: intermediate
as of Vim: 6.0

when you are working with an extended language


uC++) there exist
that are not included as keywords in the vim
so you can easily update
in two ways.

1. edit your c.vim file [if you are coding c/c++] try
'vim61/runtime/syntax/' for location of these files,
and add the keywords in the correct groups,
2. the second way is you can put them all in a separate
file, and source it, eg:
say i had some new c types, called uTask or uMutex i
could get them highlighted as types
using the following command:
:syn keyword type uTask uMutex uNoMutex [etc..]
enjoy.
.. hzp.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Accidently typed control-u and lost your input? | Search/replace "within selection" in gvim using '< '>
>>

Additional Notes
salmanhalim@hotmail.com, March 8, 2003 11:29

http://www.vim.org/tips/tip.php?tip_id=437 (1 of 2) [18/02/2004 14:58:43]

Tip #437 - extending keywords : vim online

Rather than editing an existing syntax file which will


get overwritten every time you upgrade to a newer
revision or version of Vim, it's better if you simply
create a file in the after/syntax directory (anywhere
inside the 'runtimepath') that has the same name as the
file you're enhancing (c.vim, for example).
Try :help 'runtimepath' for more details on both the
runtimepath as well as the order in which files are
loaded (which explains why the "after" directory
works).
cobacat@ig.com.br, March 8, 2003 18:21
um otimo siate valew a todos que o fizeram
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=437 (2 of 2) [18/02/2004 14:58:43]

SourceForge
Logo

Tip #438 - Search/replace "within selection" in gvim using '< '> : vim online

not logged in (login)

Home
Search

Tip #438: Search/replace "within selection" in gvim using '< '>


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/9, Viewed by 1296

created: March 8, 2003 22:06


author: Chris Smith

complexity: intermediate
as of Vim: 5.7

In other editors I've always used the search/replace


"within selection" features a lot but never knew how to
do that in gvim. I finally found the '< and '> marks
'< goes to the start of the last graphical selection (in
gvim)
'> goes to the end of the last graphical selection
so you can use these to simulate the search "within
selection" option that other programs have. eg:
:'<,'>s/fred/joe/g
will replace fred with joe in the last graphical
selection
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<extending keywords | Replace text in highlighted search >>

Additional Notes
martine@cs.washington.edu, March 8, 2003 23:54
If you visually select a region (use "v") and hit
colon, it fills those extents in by default (or it at
least does so for me...).
salmanhalim@hotmail.com, March 9, 2003 8:22
It does that for all three visual selection types;
furthermore, if you get out of a visual selection but
decide that you want to then act on it again, hitting
gv will get you the last visual selection from where
you can type : to get the '<,'> bit (gv: is faster to
type).
http://www.vim.org/tips/tip.php?tip_id=438 (1 of 2) [18/02/2004 14:58:46]

Tip #438 - Search/replace "within selection" in gvim using '< '> : vim online

cec@NdjOinnSi.gPsfAc.nMasa.gov, March 10, 2003 7:15


:'<,'>s ... will apply not only to the highlighted
area but also to the entire lines enclosing
that area. There is no difference between the two for
V-style selection, of course; however,
v and <ctrl-v> typically select only portions of the
lines. See vimtip#63 for how to restrict
substitutes (and actually any ex command) to operate on
just the selected region.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=438 (2 of 2) [18/02/2004 14:58:46]

SourceForge
Logo

Tip #439 - Replace text in highlighted search : vim online

not logged in (login)

Home
Search

Tip #439: Replace text in highlighted search


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/5, Viewed by 1208

created: March 9, 2003 11:53


author: Thomas Nickl

complexity: basic
as of Vim: 5.7

you can search for text and highlight it,


using /pattern
usually you want to replace the exact found occourences
with another string, because the common trick to e.g.
repeadetly pressing:
1. cw = change till end of word, or ct( = change till
first occourence of character (
2. n = next found pattern
3. . = do command 1. again
3. goto 2.
is too cumbersome, besides, you already specified what
you want to replace with /pattern.
solution:
use c//e as 1. (it replaces till end of highlight).
you will NEED to bind:
nnoremap n //<CR>
nnoremap N ??<CR>
in your vimrc, or step 2. will end up with the
cursorposition on the last character of your match,
because it will remember the pseudo-search-command in
step 1.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Search/replace "within selection" in gvim using '< '> | Automatic formatting of paragraphs >>

Additional Notes
janjaapsandee@hotmail.com, March 14, 2003 5:10

http://www.vim.org/tips/tip.php?tip_id=439 (1 of 2) [18/02/2004 14:58:48]

Tip #439 - Replace text in highlighted search : vim online

I usually just do
:1,$s/{string}/{newstring}/g
the 1,$ can be replaced with any valid range of line
numbers.
Works quite fast. Except when certain strings should
not be replaced.
Anonymous, April 23, 2003 11:58
If certain strings should not be replaced, just add a
'c' (for confirm) at the end of your expression:
s/origword/neword/gc
This way, vim will ask you before each replace.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=439 (2 of 2) [18/02/2004 14:58:48]

SourceForge
Logo

Tip #440 - Automatic formatting of paragraphs : vim online

not logged in (login)

Home
Search

Tip #440: Automatic formatting of paragraphs


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 30/12, Viewed by 1762

created: March 10, 2003 1:20


author: Stanislav Sitar

complexity: intermediate
as of Vim: 6.0

When I use Vim to create plain-text files (like mail


messages) I like the feature that automatically makes
lines
XY characters long. I simply type ':set tw=60' on the
command line, and as I type lines are broken
(autorwapped)
before they reach 60 characters length. The problem is,
when I latter decide to edit the paragraph. When I
delete or
add some words, the paragraph looks broken.
The solution is to type '<Esc>gqap' to format a
paragraph or
make a mapping for this command. However, it annoys me
to do
it repeatedly.
There is a better solution.
1. Go to http://cream.sourceforge.net/vim.html
and download the latest patched Vim
2. Install the program.
3. See :help auto-format.
I will not repeat the docs here. For the impatient, set
fotmatoptions to aw2tq ':set fo=aw2tq' and start typing.
The text flows automagically between lines as you type
text inside the paragraph.
GREAT!!!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Replace text in highlighted search | Toggle auto-wrap using txtwidth in INSERT mode >>

http://www.vim.org/tips/tip.php?tip_id=440 (1 of 3) [18/02/2004 14:58:51]

Tip #440 - Automatic formatting of paragraphs : vim online

Additional Notes
Anonymous, March 10, 2003 10:41
not bad, but if you do
set linebreak
set breakat=\
set nolist
, and place a mapping:
"move one 'corsor-line' line instead of one 'code-line'
up/down
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
you can also type and edit paragraphs, and will never
need to format it (because it will keep one long line
:)
yeti@physics.muni.cz, March 11, 2003 1:27
Keeping paragraphs as a one long line is a pretty bad
idea if the text is to be read by other people, with
other tools.
maxiangjiang@hotmail.com, March 11, 2003 9:26
This is double-edge settings.
I found it is a disaster for editing scripts, such as
vimrc and jsp,
but very good for editing free-style text file.
To get the best of both worlds, I used the following:
au BufEnter *.txt setl tx ts=4 sw=4 fo+=n2a
(Only all *.txt files will use this auto thing)
Stanislav Sitar, March 12, 2003 2:02

http://www.vim.org/tips/tip.php?tip_id=440 (2 of 3) [18/02/2004 14:58:51]

Tip #440 - Automatic formatting of paragraphs : vim online

Reaction on notes.
There a few people that were demanding such
functionality
some time ago on the Vim mailing list. So when I saw
that
auto-format thing mentioned, I thought that some people
might be interested.
Of course auto-format is only useful in very specific
situations.
Like when I type mail AND I want to have list
characters switched
on. Sometimes I want to see control characters like
tabs, trailing
spaces and line feeds, so I do ':set list' but when I
do that, the
long lines are not wraped visualy on word boundaries.
For me,
this is the most annoying feature in Vim. I like to
have list enabled
all the time AND I would like to see long lines wraped
properly at
the same time. This is just a dirty workaround.
Stano
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=440 (3 of 3) [18/02/2004 14:58:51]

SourceForge
Logo

Tip #441 - Toggle auto-wrap using txtwidth in INSERT mode : vim online

not logged in (login)

Home
Search

Tip #441: Toggle auto-wrap using txtwidth in INSERT mode


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating 10/4, Viewed by 938

created: March 11, 2003 9:20


author: Xiangjiang Ma

complexity: basic
as of Vim: 6.0

In INSERT mode, I would like to

Scripts
Tips
My Account

1. keep tying without auto-wrap (good for editing vimrc


and c)
2. wrap long line at will (good for email and text)

Site Help

Following is the map I figured out, using <C-B> in this


example:
set sr fo=roqm1 tw=64
im <C-B> <C-O>:setl sr! fo<C-R>=strpart("+",&sr,1)<CR>=tc<CR>_<BS><Right>
By default, it goes without auto-wrap. If I want, I can
type
<C-B> to triggle auto-wrap. Another <C-B> toggles back.
Basically it toggles two settings:
a) :set fo+=tc<CR>
b) :set fo-=tc<CR>
strpart() is used for toggling; "sr" is choosing for no
good
reason; "_" can be any char; <BS><Right> is needed to
*triggle"
this action.
It works for me on W2K. Please tell me if you have
better ideas
to get this job done.
Note: We may use 'linebreak', but that still leaves a
really
long line. I would like to keep my &tw.
Thanks

http://www.vim.org/tips/tip.php?tip_id=441 (1 of 2) [18/02/2004 14:58:53]

Tip #441 - Toggle auto-wrap using txtwidth in INSERT mode : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Automatic formatting of paragraphs | Show all lines that contain keyword under cursor >>

Additional Notes
maxiangjiang@hotmail.com, March 11, 2003 14:33
I found on UNIX, we don't need the last part of the
map.
im <C-B> <C-O>:setl sr! fo<C-R>=strpart("+",&sr,1)<CR>=tc<CR>
maxiangjiang@hotmail.com, March 12, 2003 10:16
Just found that it is not related UNIX or Windows.
It is a settting of virtualedit. For current vim
version (6.1), if we
:set virtualedit=insert
We need the last part in the map, otherwise, we don't
need it.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=441 (2 of 2) [18/02/2004 14:58:53]

SourceForge
Logo

Tip #442 - Show all lines that contain keyword under cursor : vim online

not logged in (login)

Home
Search

Tip #442: Show all lines that contain keyword under cursor
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 78/32, Viewed by 1471

created: March 15, 2003 4:56


author: Dopey

complexity: basic
as of Vim: 5.7

Started finding this one pretty useful.


If you want to view a list of all the lines in the
current buffer that contain a word, place your cursor
over the word and press [I
Handy to see where you last used variables, functions,
etc.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Toggle auto-wrap using txtwidth in INSERT mode | A better interfacing of (La)TeX with the quickfix
mode >>

Additional Notes
Anonymous, March 15, 2003 19:48
This is kind of useful but is there any way so that you
can run [I on all loaded buffers (or all files in a
directory)?
Anonymous, March 17, 2003 2:55
Actually, the [I is even more powerfull than that. It
does not search only current buffer, but also included
files, where meaning of 'included' depends on settings,
but defaults are set for C (i.e., #included files,
searched in ., /usr/include and maybe elsewhere). It is
really good thing.
To previous comment, :grep would be probably more
appropriate...
Anonymous, March 18, 2003 23:14

http://www.vim.org/tips/tip.php?tip_id=442 (1 of 2) [18/02/2004 14:58:55]

Tip #442 - Show all lines that contain keyword under cursor : vim online

" grep for word under cursor in c/cpp/h-files


map <F9> <ESC>:exec("grep ".expand("<cword>")."
../*/*.c* ../*/*.h")<CR>
You can omit '<CR>' for manual changing the file
pattern before searching.
if you have configured 'set grepprg=mygrep\ -n ' then
you can use quickfix mode for jumping to the found
locations.
Thomas
VimUser, March 20, 2003 23:06
When I get the results from [I, how do I scroll between
them or navigate the list and perhaps jump to an item
on the list?
shawn@deleurme.com, March 23, 2003 10:16
to jump to those results, just use
# to go to the first match
[ CNTR-I
# to go to the others.
] CTRL-I
This follows the C-I/C-O jumping patterns.
Also, try
prepending the windowing operator (CTRL-W) and a new
window will open into the appropriate file.

wnatter@nortelnetworks.com, March 25, 2003 10:18


Hi,
With regard to the above notes, is there a way to add
include directories? In this way, all files of
importance to me would be searched... I currently have
a grep-like solution that uses make (:make search
S='search string'), where the "search" target uses
"grep -n" on a bunch of files.
William
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=442 (2 of 2) [18/02/2004 14:58:55]

SourceForge
Logo

Tip #443 - A better interfacing of (La)TeX with the quickfix mode : vim online

not logged in (login)

Home
Search

Tip #443: A better interfacing of (La)TeX with the quickfix mode


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/2, Viewed by 1041

created: March 15, 2003 7:28


author: Christian Obrecht

complexity: basic
as of Vim: 5.7

VIM's quickfix mode is a very nice feature.


Nevertheless, I was not
completely satisfied when I used it together with
(La)TeX. Here are the
main reasons:
* The default error format pattern is able to extract
the line number
and the error message, but not the column number.
* This pattern is of course unable to deal with BibTeX's
or MakeIndex's
error messages.
* TeX's messages are quite verbose. Having them
displayed at each run,
even when no error occurs is sometimes annoying.
Thus I implemented TeXwrapper, a small program which
silently runs TeX
and optionally some associated tool like BibTeX,
MakeIndex, eukleides or
Dvips. When an error occurs, TeXwrapper scans the
transcript files and
prints to stderr "compiler style" error messages, i.e.:
<filename>:<line>:<column>:<message>
This allows very simple settings on VIM's side, that is:
set makeprg=texwrapper
set errorformat=%f:%l:%c:%m
Someone writing an article with LaTeX containing cross
references and a
bibliography may then use: "make -lb2 %". Option -l
stands for "run
LaTeX" (instead of TeX), -b for "run BibTeX", -2 for

http://www.vim.org/tips/tip.php?tip_id=443 (1 of 2) [18/02/2004 14:58:57]

Tip #443 - A better interfacing of (La)TeX with the quickfix mode : vim online

"run twice" (to get


correct cross references).
Another feature is the --window option (short: -w). When
something goes
wrong, a GTK+ window pops up, displaying a summary of
the encountered
errors. Hence, one may use: "silent make -w %" which
enables to avoid
the "Hit ENTER or type command to continue" message at
each run.
TeXwrapper has been developed on a GNU/Linux system, but
it should build
on any system where flex has been ported. The pop up
window is opened by
a separate program, named texwrapper_window, which of
course requires
the GTK+ library.
TeXwrapper has been released under the GPL and is
available at:
http://perso.wanadoo.fr/obrecht/texwrapper
Happy Vimming & TeXing!
Christian Obrecht
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Show all lines that contain keyword under cursor | quickfix show entire contents of multiline error in
cwindow on cn, cp and cc >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=443 (2 of 2) [18/02/2004 14:58:57]

SourceForge
Logo

Tip #444 - quickfix show entire contents of multiline error in cwindow on cn, cp and cc : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #444: quickfix show entire contents of multiline error in cwindow


on cn, cp and cc
tip karma

Rating 2/4, Viewed by 716

created: March 17, 2003 13:32


author: eric sherman

complexity: basic
as of Vim: 5.7

put this in your .vimrc if you use the cwindow


" \cc
map <Leader>cc :cwindow<cr>:cc<cr><c-w>b<cr>
" \cn
map <Leader>cn :cwindow<cr>:cn<cr><c-w>b<cr>
" \cp
map <Leader>cp :cwindow<cr>:cp<cr><c-w>b<cr>
and when you use \cc (or whatever your leader character
is + cc), \cn or \cp, it will do what :cc, :cn and :cp
usually did, with the added bonus of showing the entire
contents of multiline errors. this is especially useful
for javac via ant, and it's obnoxious to keep typing <cw>b<cr> every time i do a :cn, so i mapped this.
detailed explaination:
":cwindow<cr>" ensures that the quickfix window is show.
":cc" (:cn, and :cp) actually do the operation
"<c-w>b" go to the bottom window (which cwindow will be
if it's shown) which will magically center on the error
"<cr>" carriage-return on the error line, taking you
back to the code with the error
i know it probably seems superfluous if you haven't been
personally affected by this particular annoyance.
thanks to freenode #vim for inspiration.
rate this tip

Life Changing

Helpful

Unfulfilling

<<A better interfacing of (La)TeX with the quickfix mode | Formatting stuff >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=444 (1 of 2) [18/02/2004 14:59:03]

rate

Tip #444 - quickfix show entire contents of multiline error in cwindow on cn, cp and cc : vim online

<Eric Sherman> eds22@drexel.edu, March 17, 2003 13:45


Sorry! I'm a dunce.
"z<cr>"

I forgot to do the magic part,

" \cc
map <Leader>cc :cwindow<cr>:cc<cr><c-w>bz<cr><cr>
" \cn
map <Leader>cn :cwindow<cr>:cn<cr><c-w>bz<cr><cr>
" \cp
map <Leader>cp :cwindow<cr>:cp<cr><c-w>bz<cr><cr>
Ok, that should work.
"z<cr>" will reposition the buffer in the window so
that the current line becomes the top line in the
window
garyjohn@spk.agilent.com, March 17, 2003 23:03
Another solution to this problem is to "set
cmdheight=2" which will provide
two lines at the bottom of the screen for quickfix
error lines instead of the
default one.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=444 (2 of 2) [18/02/2004 14:59:03]

SourceForge
Logo

Tip #445 - Formatting stuff : vim online

not logged in (login)

Home
Search

Tip #445: Formatting stuff


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/5, Viewed by 2142

created: March 18, 2003 8:53


author: Se7en

complexity: basic
as of Vim: 5.7

Hello all, Im new to VIM, but I wanted to post some of my ideas for
everyone here. Mark T, a friend of mine, just reciently got me in to
VIM and I havent looked back yet! I really like this program, and I
feel it's a valuable tool.
Mark and I program in Lisp and Visual lisp for AutoCAD. (Its a program
for drafting) and I have been adding stuff to my 'rc' file for lisp
programing for abbout a month now. Mark has convinced me to post some
tips here. So here they are:
**********************************************************************
imap <Backspace> <left><del>
" this will allow me to always use the backspace key in insert mode
imap <C-j> <Esc>Ji
" this will allow me to join a line while still in insert mode
map .f v%zf
" fold an entire block of code
nnmap ,y <S-v>y
" This will select a whole line of text or it will select
" everything in a fold.
map .; v%:s/^/;;;/<CR>:noh<CR>
" comments out and entire block of code from paren to paren
:au BufRead *.lsp :loadview 1<cr>
:au BufRead *.LSP :loadview 1<cr>
" load the first fold view file for the current file
map st :set tw=70<cr>v<S-}>gq<End>
" this will allow you to format an entire block of text
**********************************************************************
John
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<quickfix show entire contents of multiline error in cwindow on cn, cp and cc | Quick and dirty Postgres query >>

Additional Notes
Anonymous, March 19, 2003 1:11
http://www.vim.org/tips/tip.php?tip_id=445 (1 of 2) [18/02/2004 14:59:06]

Tip #445 - Formatting stuff : vim online

Hi!
Welcome to vim.
Regarding imap <backspace> ... you might want to
:help 'bs'
sitar at procaut.sk, March 19, 2003 2:44
You can also do
imap <C-j> <Esc>Ji
this way
imap <C-j> <C-o>J
this way you do not leave insert mode.
You might also consider using
inoremap <C-j> <C-o>J
I personaly use quite a few '<C-o> style' mappings
Most of them from example_vimrc file ;-)
see
:help i_CTRL-O
Anonymous, March 19, 2003 8:59
Hello there. Thanx for the welcome.
I will look into these sugestions you have given me, but if there
are any more, please keep 'em comming. (I would really like to learn
more.)
Thank you.
Anonymous, March 21, 2003 4:47
I found out more about the Backspace topic in the help file and in
the example rc file. Thanx for the tip.
set backspace=indent,eol,start
" allow backspacing over everything in insert mode
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=445 (2 of 2) [18/02/2004 14:59:06]

SourceForge
Logo

Tip #446 - Quick and dirty Postgres query : vim online

not logged in (login)

Home
Search

Tip #446: Quick and dirty Postgres query


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/5, Viewed by 787

created: March 23, 2003 10:20


author: Shawn Deleurme

complexity: basic
as of Vim: 5.7

Here is a simple and usefull mapping for anyone who


can't stand developing queries on the psql prompt or
messing around with the single \e psql edit buffer.
map <F9> :!psql -d yourdb < % <BAR> less
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Formatting stuff | Use the upper-lower case ~, also on Windows (ita) >>

Additional Notes
David Fishburn, March 24, 2003 13:04
You could also consider use the database extension
plugin for Vim, which provides a lot of features for
Postgress.
db_ext.vim
http://vim.sourceforge.net/script.php?script_id=356
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=446 [18/02/2004 14:59:08]

SourceForge
Logo

Tip #447 - Use the upper-lower case ~, also on Windows (ita) : vim online

not logged in (login)

Home
Search

Tip #447: Use the upper-lower case ~, also on Windows (ita)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -12/22, Viewed by 923

created: March 25, 2003 6:42


author: Gianmichele Murano

complexity: basic
as of Vim: 6.0

For who know to change the case of key typed, otherwise


see before the Tip #49 :^)
I had find usefull use ~ ( on linux :^) to change the
case of word, but also a my friend want this option on
windows.
So i told him to use the ~ for this.
But italian keyboard have not the ~ on board.
So i have mapped this to a key, let read the code:
map <the key that you want> ~
Thats all.
I have used this on windows and italian keyboard, but i
believe that is possible also on other keyboard yhat not
have the tilde like us-keyboard.
NOTE:
Make attention to key that you use for mapping ~, some
key ar used by vim, so for this don't work.
Have a nice day :^)

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Quick and dirty Postgres query | Yank (copy) decimal numbers from hex numbers. >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=447 (1 of 2) [18/02/2004 14:59:11]

Tip #447 - Use the upper-lower case ~, also on Windows (ita) : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=447 (2 of 2) [18/02/2004 14:59:11]

SourceForge
Logo

Tip #448 - Yank (copy) decimal numbers from hex numbers. : vim online

not logged in (login)

Home
Search

Tip #448: Yank (copy) decimal numbers from hex numbers.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 13/6, Viewed by 1009

created: March 25, 2003 21:04


author: Mohit Kalra

complexity: intermediate
as of Vim: 6.0

Here is a mapping that will copy a hexadecimal number in


a register after converting it to the decimal
equivalent. The tip is pretty useful if you are a
programmer.
:map \y g*<esc>:let @*=@/ + 0<enter>
Usage:
1. Place the cursor on any hexadecimal number (eg 0xff,
0xfefe, 0x3434) and press \y.
2. Place the cursor at the location where you want to
paste the number in decimal and press "*p
3. The number is also copied to the clipboard (windows)
so you can paste it in other applications.
Example:
If the hexadecimal number is 0xff, then 255 will be
copied to the clipboard.
Configuring the tip.
If you do not like the above key combinations or the
register being used, you can configure the tip to use
other mappings as explained below:
1. Change \y in the above mapping to any key
combination of your choice.
2. Change @* to @<any_other_lower_case_letter> to copy
the contents to another register. If you do this,
pasting will require the command
"<that_same_lower_case_letter>p
Side effects:
1. The tip uses the search register for the
conversion. Therefore any last search will be lost.
2. The tip also uses a register to yank the
result. The earlier contents of that register (in our
case the * register) will be lost.
-mohit

http://www.vim.org/tips/tip.php?tip_id=448 (1 of 2) [18/02/2004 14:59:13]

Tip #448 - Yank (copy) decimal numbers from hex numbers. : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Use the upper-lower case ~, also on Windows (ita) | FORTRAN highlighting problems >>

Additional Notes
Anonymous, March 26, 2003 4:11
There is a way of doing this without changing the
search history
map \y :let @*=<C-R><C-W> +0<cr>
And a way to not change the " * " register contents
would be to use some global variables instead I
guess...Some think like
map \y :let g:HexYank=<C-R><C-W> +0<cr>
for yanking, and..
map \p :if exists("g:HexYank") <Bar> exe "normal i"
. g:HexYank <Bar> endif <cr>
for pasting
- Me Thinks
Anonymous, March 28, 2003 17:20
"<some-register>yiw
should also work instead of searching.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=448 (2 of 2) [18/02/2004 14:59:13]

SourceForge
Logo

Tip #449 - FORTRAN highlighting problems : vim online

not logged in (login)

Tip #449: FORTRAN highlighting problems

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/3, Viewed by 776

created: March 26, 2003 4:23


author: Fabien Bouleau

complexity: basic
as of Vim: 6.0

Sometimes the FORTRAN syntax file doesn't set the


correct source form.
So if you want to choose it by yourself, add the
following line in your vimrc file:
au BufNew *.for let b:fortran_fixed_source=1
the correct value

" set

The other way to do this is to change the file extension


(F77/F90/F95), but it might be a long and/or hazardous
work for big projects...
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Yank (copy) decimal numbers from hex numbers. | Working with multiple sessions >>

Additional Notes
syrion@freesbee.fr, March 26, 2003 5:50
This one placed before "syntax on" works better:
au BufRead *.for let b:fortran_fixed_source=1
FB
Anonymous, March 26, 2003 23:34
You can also add the following line to a source file:
C

vim:set ft=fortran:
Add Note

http://www.vim.org/tips/tip.php?tip_id=449 (1 of 2) [18/02/2004 14:59:16]

Tip #449 - FORTRAN highlighting problems : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=449 (2 of 2) [18/02/2004 14:59:16]

SourceForge
Logo

Tip #450 - Working with multiple sessions : vim online

not logged in (login)

Home
Search

Tip #450: Working with multiple sessions


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/4, Viewed by 1920

created: March 26, 2003 4:47


author: Me Thinks

complexity: basic
as of Vim: 5.7

The problem I'm trying to solve:


I usually need to work on different projects (let us
call them: PROJ1 and PROJ2). These are in different
directories, have
different files.. etc. It would be nice if I can
instruct my editor to take me back to the exact session
(see :help sessions)
for each of these projects - open the required files and
buffers, window layout etc...
Solution
1. Append the following code to your .vimrc
- Change the variable g:PathToSessions to your
desired place, if needed (make sure that this directory
exists and is writable)
2. Open all/some files in a particular project (as if
you are working on that) in gvim. Say I open all my
PROJ1 related files.
You can split windows etc.. and make it look as if
you are really working! :-) Do a
:SetSession PROJ1
3. Quit gvim
4. Restart gvim without any filenames at the command
line.
5. You ought to get a popup-entry asking you which
session to restore. Choose PROJ1.vim to see the effect.
6. Repeat with other projects.
Note:
1. You don't have to :SetSession everytime you open gvim
as in step 5. Only once.
2. If you start vim with no files at the command line,
you have an option of going back to the last saved
session (this
is available in the gui if you choose
LastSession.vim)

http://www.vim.org/tips/tip.php?tip_id=450 (1 of 6) [18/02/2004 14:59:19]

Tip #450 - Working with multiple sessions : vim online

CODE STARTS
au VimLeave * call VimLeave()
au VimEnter * call VimEnter()
let g:PathToSessions = $HOME . "/.vim/sessions/"
function! VimEnter()
if argc() == 0
" gvim started with no files
if has("browse") == 1
let g:SessionFileName = browse(0, "Select
Session", g:PathToSessions, g:PathToSessions .
"LastSession.vim")
if g:SessionFileName != ""
exe "source " . g:SessionFileName
endif
else
" For non-gui vim
let LoadLastSession = confirm("Restore last
session?", "&Yes\n&No")
if LoadLastSession == 1
exe "source " . g:PathToSessions .
"LastSession.vim"
endif
endif
endif
endfunction
function! VimLeave()
exe "mksession! " . g:PathToSessions .
"LastSession.vim"
if exists("g:SessionFileName") == 1
if g:SessionFileName != ""
exe "mksession! " . g:SessionFileName
endif
endif
endfunction
" A command for setting the session name
com -nargs=1 SetSession :let g:SessionFileName =
g:PathToSessions . <args> . ".vim"
" .. and a command to unset it
com -nargs=0 UnsetSession :let g:SessionFileName = ""
CODE ENDS
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<FORTRAN highlighting problems | KDE Konsole renameSession to edited file name >>

http://www.vim.org/tips/tip.php?tip_id=450 (2 of 6) [18/02/2004 14:59:19]

Tip #450 - Working with multiple sessions : vim online

Additional Notes
bertilow@gmx.net, March 27, 2003 7:48
Nice tip, but I had to change the code a lot before I
got it to work.
Perhaps your setup (or platform) is somehow different
from mine...
Anyway, here's my code. It works great for me:
------------------------------------------------------------au VimLeave * call VimLeave()
au VimEnter * call VimEnter()
let g:PathToSessions = $HOME . "/.vim/sessions"
function! VimEnter()
if argc() == 0
" gvim started with no files
if has("browse") == 1
let g:SessionFileName = browse(0, "Select
Session", g:PathToSessions, "/LastSession.vim")
if g:SessionFileName != ""
exe "source " . g:SessionFileName
endif
else
" For non-gui vim
let LoadLastSession = confirm("Restore last
session?", "&Yes\n&No")
if LoadLastSession == 1
exe "source " . g:PathToSessions .
"/LastSession.vim"
endif
endif
endif
endfunction
function! VimLeave()
exe "mksession! " . g:PathToSessions .
"/LastSession.vim"
if exists("g:SessionFileName") == 1
if g:SessionFileName != ""
exe "mksession! " . g:SessionFileName
endif
endif

http://www.vim.org/tips/tip.php?tip_id=450 (3 of 6) [18/02/2004 14:59:19]

Tip #450 - Working with multiple sessions : vim online

endfunction
" A command for setting the session name
com! -nargs=1 SetSession :let g:SessionFileName =
g:PathToSessions . "/" . <args> . ".vim"
" .. and a command to unset it
com! -nargs=0 UnsetSession :let g:SessionFileName = ""
------------------------------------------------------------Anonymous, March 31, 2003 9:45
consider putting this in the scripts section rather
than the tips section.
tony.young@ir.com, March 31, 2003 23:47
I had to had a line to VimEnter:
exe "source ~/.vim/syntax/mysyntax.vim"
to keep my personal syntax highlighting.
Sourcing the session file seemed to switch the
highlighting back to the default.
Apart from that it was an excellent tip
bertilow@gmx.net, April 2, 2003 2:28
One more detail:
Instead of
:SetSession PROJ1
I find I have to do
:SetSession "PROJ1"

Anonymous, April 3, 2003 5:17


Oops.
:SetSession "PROJ1"
is correct.
Apart from that, I don't see why the changes to the
g:PathToSessions (removing the "/") and the rest of the
code were needed. As has been said, maybe our setups
are somehow different.. I have tested on HPUX and
Windows NT.. the original script seemed to work fine..
Regarding personal syntax highlighting, normal filetype
detection ought to take place, and it does for me, and
http://www.vim.org/tips/tip.php?tip_id=450 (4 of 6) [18/02/2004 14:59:19]

Tip #450 - Working with multiple sessions : vim online

the appropriate syntax file gets sourced. Again, I


don't know why this doesn't work at your end..
One more issue: mksession also saves values of vim
variables, like 'path' for instance, so changes in your
.vimrc to these variables will get overwritten when you
source the PROJ1.vim file
Maybe I'll iron these out, add some more glamour, and
move it to scripts section.
Thanks for your comments!
-

Me Thinks

chaokuo at iname dot com, September 11, 2003 16:25


I've edited the script a
move my hand just to use
file, and make them work
or non-GUI. It's just a

bit so that i don't have to


the mouse to click on the
more consistently either GUI
quick hack.

function! VimEnter()
if argc() == 0
let LoadLastSession = confirm("Restore last
session?", "&Yes\n&No")
if LoadLastSession == 1
exe "source " . g:PathToSessions .
"/LastSession.vim"
else
call LoadSessions()
endif
endif
endfunction
function! LoadSessions()
let result = "List of sessions:"
let sessionfiles = glob(g:PathToSessions .
"/*.vim")
while stridx(sessionfiles, "\n") >= 0
let index = stridx(sessionfiles, "\n")
let sessionfile = strpart(sessionfiles, 0,
index)
let result = result . "\n " .
fnamemodify(sessionfile, ":t:r")
let sessionfiles = strpart(sessionfiles, index
+ 1)
endwhile
let result = result . "\n " .
fnamemodify(sessionfiles, ":t:r")
let result = result . "\n" . "Please enter a
http://www.vim.org/tips/tip.php?tip_id=450 (5 of 6) [18/02/2004 14:59:19]

Tip #450 - Working with multiple sessions : vim online

session name to load (or empty to start normally):"


let sessionname = input(result)
if sessionname != ""
exe "source " . g:PathToSessions . "/" .
sessionname . ".vim"
endif
endfunction
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=450 (6 of 6) [18/02/2004 14:59:19]

SourceForge
Logo

Tip #451 - KDE Konsole renameSession to edited file name : vim online

not logged in (login)

Home
Search

Tip #451: KDE Konsole renameSession to edited file name


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 21/11, Viewed by 1153

created: March 28, 2003 7:21


author: warb@tgf.tc.faa.gov

complexity: intermediate
as of Vim: 6.0

In Kde the renameSession will set the Konsole name. Add


this to your
.vimrc file to name the session after the edited file.
autocmd BufReadPost * :silent !dcop
$KONSOLE_DCOP_SESSION renameSession %
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Working with multiple sessions | Unix: Editing multiple files, listed in a file, one per line, from the
command-line >>

Additional Notes
me again, March 28, 2003 13:04
This one set the title to the current working dirctory
when you leave vim.
autocmd VimLeavePre * :silent !dcop
$KONSOLE_DCOP_SESSION renameSession $PWD
lamba@faatc.com, April 8, 2003 23:19

http://www.vim.org/tips/tip.php?tip_id=451 (1 of 4) [18/02/2004 14:59:21]

Tip #451 - KDE Konsole renameSession to edited file name : vim online

Dan thanks for the vim help, however I do not use


konsole.
So I modified my .tcshrc with this:
# This makes it possible to make vim automagically set
the date and time
# in the title bar.
#
alias vimdate '/bin/date "+%A, %B %e, %Y Time: %H:%M"'
setenv mydate `vimdate`
alias vi 'setenv mydate `vimdate` ; /usr/bin/vim \!* ;
cd `pwd`'
then I read the how to for setting or unsetting the
title in vim,
so I set my .vimrc with this:
:auto BufEnter * let &titlestring = $USER . " on " .
hostname() . " :
\ Viming: " . expand("%:p") . " Date: " . $mydate
:set title titlestring=%<%F%=%l/%L-%P titlelen=70
This with the .tcshrc mod will give you your name on
machine Viming : filename : date and time.
gregf@bigtimegeeks.com, April 9, 2003 9:31
great tip!
cniehaus@kde.org, April 11, 2003 15:11
Is there a smart way to set the title of the session to
QString::NULL if on
leaves vim? Because with this DCOP-call the session
will keep the name
until you a) close the session or b) edit another file
in vim...
lamba@faatc.com, April 11, 2003 22:53
Hi,
I might not always use kde, so I have my xterm do my
title work for me.
My .tcshrc for my xterms, looks like this:
### -------------------------------------------------------------# This is where cd is overloaded and it adjusts the
prompt.
#
# cds: change directory hybrid queueish stack
set cds = ( $HOME )
#
alias cd
'if ( ${#cds} >= 4 ) shift cds;\\
http://www.vim.org/tips/tip.php?tip_id=451 (2 of 4) [18/02/2004 14:59:21]

Tip #451 - KDE Konsole renameSession to edited file name : vim online

chdir \!*;\\
setprompt;\\
set cds = ( $cds $cwd );\\
echo $cds'
#
alias lastdir
$cwd );\\

'if ( ${#cds} <= 1 ) set cds = ( $cds


@ idx = ${#cds} - 1;\\
chdir $cds[$idx];\\
setprompt;\\
set cds = ( $cds[1-$idx] );\\
echo $cds;\\
unset idx'

#
setprompt
#
### -------------------------------------------------------------#
#
### -------------------------------------------------------------# This is where the title bar of the xterm is set.
#
alias date '/bin/date "+%A, %B %e, %Y Time: %H:%M:%S"'
#
if ($?tcsh) then
#
set prompt="$host{`whoami`}%\!: "
#
if ($?term) then
alias cwdcmd 'echo -n "^[]2;" "$USER on
$host : $cwd
`date`^G"'
cwdcmd
endif
#else # regular csh
#
set prompt="$hostnm{`whoami`}\!: "
#
if ($term == xterm) echo -n "^[]0;$hostnm^G"
endif
#
### -------------------------------------------------------------Note: In the alias cwdcmd line, after the `echo -n
"^[]2;" the ^[ is a control h,
I think.
This is why I aliases vi to 'setenv mydate `vimdate` ;
/usr/bin/vim \!* ; cd `pwd`
When I do a cd `pwd` it automatically changes my title
bar to:
http://www.vim.org/tips/tip.php?tip_id=451 (3 of 4) [18/02/2004 14:59:21]

Tip #451 - KDE Konsole renameSession to edited file name : vim online

me on machine : $PWD

day, date, Time: time.

This works with xterm, aterm, wterm, kterm, rxvt, and


konsole.
Please feel free to email me if you would like me to
send you a copy.
Also I run Debian, so there for everything is generic;
so I had to figure out how to
modify/customize everything with dot files; this way I
learn more by doing it myself.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=451 (4 of 4) [18/02/2004 14:59:21]

SourceForge
Logo

Tip #452 - Unix: Editing multiple files, listed in a file, one per line, from the command-line : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #452: Unix: Editing multiple files, listed in a file, one per line,
from the command-line
tip karma

Rating 12/14, Viewed by 2230

created: March 28, 2003 12:08


author: ooglek

complexity: intermediate
as of Vim: 5.7

I needed to edit about 300 files in a directory tree


that all contained a specific line. I used -w
{scriptout} on the first file to write my macro, and
then used this command line to execute the rest:
vim -s scriptin `cat file-containing-files`
This cats the file containing the multiple files, one
per line, to the command line, allowing you to edit
tens, hundreds or even thousands of files using the same
script. Of course, I had to use a recursive macro to
get it done. Here's what I used:
qq/\.\.\.\.\.\.Complete^Mdd:wn^M^M@qq@q
Basically recording the macro, searching for my string,
deleting that line, writing the file and going to the
next, then executing itself (@q), ending the macro and
then executing itself. This way one script could be
used to edit all 300 of my files.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<KDE Konsole renameSession to edited file name | Use Taglist with LaTeX files >>

Additional Notes
salmanhalim@hotmail.com, March 29, 2003 8:05
Once the files have been loaded, why not just execute a
bufdo? It'll execute the same command (a :g/<expr>/d,
in this case) in all buffers.
Anonymous, March 31, 2003 12:48

http://www.vim.org/tips/tip.php?tip_id=452 (1 of 2) [18/02/2004 14:59:24]

Tip #452 - Unix: Editing multiple files, listed in a file, one per line, from the command-line : vim online

Couldn't you do the same thing more more elegantly with


sed?
Anonymous, April 4, 2003 10:45
aye. this would take a single line with sed's inline &
recursive switches.
anony@email.com, April 12, 2003 5:38
hey fget all that
did u see :h argdo
:)
jaldri1 at gl dot umbc dot edu, June 16, 2003 16:21
So many choices. Note that most shells won't take
thousands of files on the command line (and we're not
even talking about DOS). You need an "ls -1| while
read fn; do <script..." for that (bash,ksh). AND, if
you use perl instead of sed, you can get nice backups
(e.g. perl -i'.bak' -pe 's/<pattr>/<changes>/g' ...).
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=452 (2 of 2) [18/02/2004 14:59:24]

SourceForge
Logo

Tip #453 - Use Taglist with LaTeX files : vim online

not logged in (login)

Home
Search

Tip #453: Use Taglist with LaTeX files


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/4, Viewed by 669

created: April 14, 2003 7:51


author: Florent Manens

complexity: intermediate
as of Vim: 6.0

First, you have to add a new language to ctags


in ~/.ctags add :
<.ctags>
--langdef=tex
--langmap=tex:.tex
--regex-tex=/\\subsubsection[ \t]*\*?\{[ \t]*([^}]*)\}/\1/s,subsubsection/
--regex-tex=/\\subsection[ \t]*\*?\{[
\t]*([^}]*)\}/+\1/s,subsection/
--regex-tex=/\\section[ \t]*\*?\{[
\t]*([^}]*)\}/\1/s,section/
--regex-tex=/\\chapter[ \t]*\*?\{[
\t]*([^}]*)\}/\1/c,chapter/
--regex-tex=/\\label[ \t]*\*?\{[
\t]*([^}]*)\}/\1/l,label/
--regex-tex=/\\ref[ \t]*\*?\{[ \t]*([^}]*)\}/\1/r,ref/
</.ctags>
I think this good for me but if someone found something
better, i will be happy :)
Edit taglist.vim (my patch for version 2.4) :
--- taglist.vim 2003-04-14 16:47:25.000000000 +0200
+++ .vim/plugin/taglist.vim
2003-04-14
15:00:04.000000000 +0200
@@ -509,6 +509,9 @@
" vim language
let s:tlist_def_vim_settings =
'vim;a:autocmds;v:variable;f:function'
+" tex language
+let s:tlist_def_tex_settings =
'tex;s:section;c:chapter;l:label;r:ref'
+
" yacc language
let s:tlist_def_yacc_settings = 'yacc;l:label'
in vim, type :

http://www.vim.org/tips/tip.php?tip_id=453 (1 of 2) [18/02/2004 14:59:26]

Tip #453 - Use Taglist with LaTeX files : vim online

:Tlist
or see taglist doc
references :
Taglist :
http://www.vim.org/scripts/script.php?script_id=273
ctags : http://ctags.sourceforge.net
Vim-LaTeX : http://vim-latex.sf.net/

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Unix: Editing multiple files, listed in a file, one per line, from the command-line | Syntax Highlighting
Keeps Breaking (and how to fix it!) >>

Additional Notes
xurelo AT onetel DOT net DOT uk, April 14, 2003 10:49
Could this be extended to work recursively?
iago
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=453 (2 of 2) [18/02/2004 14:59:26]

SourceForge
Logo

Tip #454 - Syntax Highlighting Keeps Breaking (and how to fix it!) : vim online

not logged in (login)

Home
Search

Tip #454: Syntax Highlighting Keeps Breaking (and how to fix it!)
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 42/22, Viewed by 1707

created: April 14, 2003 8:22


author: Robert (MetaCosm)

complexity: basic
as of Vim: 5.7

If you vim syntax highlight keeps breaking as you move


around your document this is the tip for you!
:)
First of all, how to fix it:
put the following in your .vimrc (_vimrc on
windows):
"autocmd BufEnter * :syntax sync fromstart"
now, you might say, "Robert, I already put 'syntax sync
fromstart' in my .vimrc, and it doesn't work!" -- and in
saying that, you would be correct, because of a few
factors coming together to cause you pain.
Factors:
1. Vim syntax files should define the best syntax
sync method for that langauge
2. Many vim syntax files do not do #1
3. Almost all syntax files do a :syntax clear which
removes _your_ sync setting
Notes:
The syntax files that tend to have the most trouble
keeping sane highlighting are multilangauge files
(html/javascript -- html/php/javascript ...), yet the
all work perfectly with :syntax sync fromstart. This is
not a vim bug, but a problem with the syntax files, yet,
it has been argued that maybe vim should NOT clear out
the sync setting when doing a syntax clear -- and just
wait for it to be overwritten... like everything else -that is debatable :)
Hope this helps you... join #vim on irc.freenode.net for
all your vim help needs :)
rate this tip

Life Changing

Helpful

Unfulfilling

<<Use Taglist with LaTeX files | Map a function key to toggle line wrapping >>

http://www.vim.org/tips/tip.php?tip_id=454 (1 of 3) [18/02/2004 14:59:29]

rate

Tip #454 - Syntax Highlighting Keeps Breaking (and how to fix it!) : vim online

Additional Notes
cec@NgrOyphSon.gPsfAc.nMasa.gov, April 16, 2003 8:32
syn sync fromstart
makes for improved accuracy in syntax highlighting, but
at a price: sluggish screen updating. This command is
telling vim to parse from the beginning of the file
every time the screen needs updating. Long files and
languages that involve complex highlighting rules will
be adversely affected, moreso, of course, on older
(slower) computers. Fair warning!
private, April 16, 2003 12:02
sluggish screen updates vs. constantly messed up syntax
highlighting == easy choice
I was about to give up on vim entirely before I found
out about this.
Since vim is basically useless if
everytime you page down or pageup it breaks you syntax
highlighting.
cec@NgrOyphSon.gPsfAc.nMasa.gov, April 17, 2003 8:58
Depends on how sluggish!
As a less sluggish alternative, something like
syn sync minlines=200
may be of help. That tells vim to start looking for
synchronization points 200 lines previous in the file;
use more if one needs to and fewer to improve
speed. The problem occurs in recognizing large
regions. Consider a large list of equations in LaTeX,
say 100 of them, one per line. With the screen
starting its display in the middle of the list, proper
highlighting will occur only if vim recognizes that its
in the middle of a list of equations. It needs to hunt
backwards to do this. If the minlines is too small, it
won't see the \begin{eqnarray} and so highlighting will
be incorrect. Set minlines too large or use the
fromstart suggestion, and vim will be doing a lot of
extra work that gets thrown away at every screen
refresh.
On the other hand, if one has a multi-gigahertz
machine, extra cpu work is cheap.
http://www.vim.org/tips/tip.php?tip_id=454 (2 of 3) [18/02/2004 14:59:29]

Tip #454 - Syntax Highlighting Keeps Breaking (and how to fix it!) : vim online

Anonymous, April 21, 2003 14:04


Even if you decide to use minlines, you still need to
use an autobuf since they will be lost on the :syntax
clear.
Also, I was wondering if someone could how
minlines effects languages that call other syntax files
(does it effect all the active syntax highlighting
methods).
Doesn't matter -- since I do have a multi-ghz machine,
and generally work with sub-1000 line files -- so
worring about preformance in my case is really silly.
Anonymous, April 21, 2003 14:06
on last comment :%s/could/could explain

:)

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=454 (3 of 3) [18/02/2004 14:59:29]

SourceForge
Logo

Tip #455 - Map a function key to toggle line wrapping : vim online

not logged in (login)

Home
Search

Tip #455: Map a function key to toggle line wrapping


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/7, Viewed by 793

created: April 15, 2003 15:26


author: Thomas R. Kimpton

complexity: basic
as of Vim: 5.7

Most of the time I want to have line wrapping on. But,


there are some times that I want to toggle it off, to
check structures or something... here's a function key
for toggling line wrapping:
:set wrap
:let g:toggleWrap = 0
map <silent> <F6> :if g:toggleWrap == 1<CR>:set
wrap<CR>:let g:toggleWrap = 0<CR>:else<CR>:set
nowrap<CR>:let g:toggleWrap = 1<CR>:endif<CR>
Tom.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Syntax Highlighting Keeps Breaking (and how to fix it!) | escape select mode in a map command
(used to map indent in select mode) >>

Additional Notes
maxiangjiang@hotmail.com, April 15, 2003 16:49
nn <F6> :setl wrap!<Bar>echon "wrap="&wrap<CR>
mike@mester.demon.co.uk, April 16, 2003 4:14
" Map F6 to toggle wrap on and off
imap <silent> <F6> <Esc>:set wrap!<CR>a
nmap <silent> <F6> :set wrap!<CR>
yeti@physics.muni.cz, April 20, 2003 12:29

http://www.vim.org/tips/tip.php?tip_id=455 (1 of 2) [18/02/2004 14:59:31]

Tip #455 - Map a function key to toggle line wrapping : vim online

Please don't use <esc> ... <a> for insert mode


mappings. If you are at the begin of line, it moves the
cursor (right). Use Ctrl-O instead:
imap <f6> <c-o>:set wrap!<cr>
and even better:
imap <f6> <c-o><f6>
once <f6> in nmaped as before.
Tobi, May 2, 2003 6:52
What about:
map <F6> :set wrap!<CR>
?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=455 (2 of 2) [18/02/2004 14:59:31]

SourceForge
Logo

Tip #456 - escape select mode in a map command (used to map indent in select mode) : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #456: escape select mode in a map command (used to map


indent in select mode)
tip karma

Rating 13/4, Viewed by 540

created: April 16, 2003 3:50


author: aLLtraX

complexity: basic
as of Vim: 6.0

When using mswin behaviour, the select mode is activated


each time you select some text with shit+arrows or with
the mouse. Then entering '>' to ident the text will just
replace selected text with >. To offer a behaviour
similar to visual text editor, I use the following
mappings :
vmap
vmap

<Tab>
<S-Tab>

^0
^0

>
<

then in select mode, tab will go to to visual mode,


shift one block and then return to select mode ! ShitTab will just do the same thing, going backward.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Map a function key to toggle line wrapping | Follow tag in new window >>

Additional Notes
Anonymous, April 16, 2003 12:32
The maps in this post have a space following the > and
<. This is probably ok
unless one has mapped <space> to something. If you
have mapped <space> be sure
to remove the trailing space if you copy/paste from
this post.
Anonymous, September 19, 2003 13:36
"Shit-Tab" - too cool.
Anonymous, September 19, 2003 13:36

http://www.vim.org/tips/tip.php?tip_id=456 (1 of 2) [18/02/2004 14:59:33]

Tip #456 - escape select mode in a map command (used to map indent in select mode) : vim online

"Shit-Tab" - too cool.


Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=456 (2 of 2) [18/02/2004 14:59:33]

SourceForge
Logo

Tip #457 - Follow tag in new window : vim online

not logged in (login)

Home
Search

Tip #457: Follow tag in new window


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 7/4, Viewed by 800

created: April 16, 2003 12:13


author: PopEsc

complexity: basic
as of Vim: 6.0

If you use tags, you might want to follow a tag, but


leave the current window open. The following mapping
allows you to do this easily with Ctrl-\.
:map <C-\> :sp<CR><C-]><C-w>_
rate this tip

Life Changing

Helpful

Unfulfilling

rate

Site Help
<<escape select mode in a map command (used to map indent in select mode) | How to use quickfix
mode to see all errors in one window (:cwindow). >>

Additional Notes
James.A.Paget@aero.org, April 16, 2003 13:20
This creates a new window of maximal size and the
original window
shrinks to one line. To have the windows be of equal
size, just
eliminate the "<C-w>_" at the end.
Gary Johnson <garyjohn@spk.agilent.com>, April 16, 2003 14:17
Why not just 'CTRL-W ]'?
Anonymous, April 17, 2003 11:51
Why not <C-W>]? Because I did not know of that command
when I thought of this.
Thanks for the lesson.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=457 [18/02/2004 14:59:36]

SourceForge
Logo

Tip #458 - How to use quickfix mode to see all errors in one window (:cwindow). : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #458: How to use quickfix mode to see all errors in one window
(:cwindow).
tip karma

Rating 37/12, Viewed by 736

created: April 20, 2003 3:30


author: Omanakuttan

complexity: intermediate
as of Vim: 6.0

Uptil vim 5.8, I was using the cfile, clist...etc for


quickfix mode.
In vim6.x, I found out that :cw will boost my
productivity as a programmer.
To make,
type :make as we do in older versions of vim (<6.0).
Instead of clist,cfile...etc, type
:cw<enter>
you get one split window, in which errors are listsed.
Current error line will be highlighted and cursor will
move to the corresponding source file line.
Doing an <enter> on any error line in the error window
will take the cursor to the corresponding source line.
This eliminates the need for the process described in
vimtip #345.(Now you can get rid of Visual studio
altogether !)
Details:
Help is available in vim 6.x onwards by entering :help
cw
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Follow tag in new window | Use Ctrl-O instead of Esc in insert mode mappings >>

Additional Notes
jallen@cashsystemsinc.com, April 30, 2003 7:19
I think you have to add a colon:
:help :cw
jallen@cashsystemsinc.com, April 30, 2003 8:20

http://www.vim.org/tips/tip.php?tip_id=458 (1 of 2) [18/02/2004 14:59:38]

not :help cw

but

Tip #458 - How to use quickfix mode to see all errors in one window (:cwindow). : vim online

I guess I should say what works for me for compiling


Java programs on MS Windows. It can be improved, but I
am not sure how. I put the following in _vimrc.
set makeprg=javac
set makeef=c:\dev\src\errors.txt
set shellpipe=2>
set errorformat=%A%f:%l:\ %m,%C%m
noremap <M-1> :w<Enter>:set ch=5<Enter>:make -d
C:\\dev\\classes %:p<Enter>
noremap <M-2> :cp<Enter>
noremap <M-3> :cn<Enter>
noremap <M-4> :cl<Enter>
Press Alt-1 to compile the current file. Alt-2 and Alt3 move the cursor in the source code to previous and
next errors. (I have another command to reset the
command line height when I'm done looking at errors.)
Problem: it removes spaces so the caret that javac
uses to point to the error location is wrong. I have
tried all kinds of different formats. If someone does
not know a better error format for javac, I just
discoved that :set shellpipe= will open DOS window with
all the spaces preserved.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=458 (2 of 2) [18/02/2004 14:59:38]

SourceForge
Logo

Tip #459 - Use Ctrl-O instead of Esc in insert mode mappings : vim online

not logged in (login)

Home
Search

Tip #459: Use Ctrl-O instead of Esc in insert mode mappings


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 59/22, Viewed by 1071

created: April 20, 2003 13:06


author: Yeti

complexity: basic
as of Vim: 5.7

Theory: Ctrl-O in insert mode switches to normal mode


for one command and then switches back to insert mode.
Practice: Mappings like
:imap <f5> <esc>:set number!<cr>a
move the cursor one character right when it's in the
first column. Use
:imap <f5> <c-o>:set number!<cr>
instead, it has no side-effects. If you have <f5> mapped
in normal mode too (to do the same thing),
:imap <f5> <c-o><f5>
is even better.
When you need to do more than one thing in the mapping,
you can
- use more Ctrl-O, one before each command, or
- use | to run more commands at once, or
- define a command (or function) doing everything and
map <f5> to it.
- ... (TMTOWTDI)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<How to use quickfix mode to see all errors in one window (:cwindow). | how to implement vertical
lines showing tab groups.. >>

Additional Notes
dat1965@yahoo.com, May 2, 2003 23:52

http://www.vim.org/tips/tip.php?tip_id=459 (1 of 2) [18/02/2004 14:59:41]

Tip #459 - Use Ctrl-O instead of Esc in insert mode mappings : vim online

I've had this mapping for awhile,


" always make F8 toggle paste mode
map <F8> :set invpaste<CR>:set paste?<cr>
but it requires I press F8 before I enter insert
mode. Well, that's
backwards to my brain, so this tip helped me realize I
needed
this mapping,
imap <F8> <c-o>:set invpaste<cr>
which allows me to enter insert mode, then press F8 (in
case
I had forgotten to do that), click paste with my mouse,
then
press ESC and press F8 again, and I've quickly pasted
text in my buffer without having my indent settings
mess
up the pasted text. Sweet.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=459 (2 of 2) [18/02/2004 14:59:41]

SourceForge
Logo

Tip #460 - how to implement vertical lines showing tab groups.. : vim online

not logged in (login)

Home
Search

Tip #460: how to implement vertical lines showing tab groups..


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 67/30, Viewed by 1408

created: April 21, 2003 13:32


author: Robert (MetaCosm)

complexity: basic
as of Vim: 5.7

When browsing the jEdit screenshots page, I saw a


feature I wanted and didn't have in vim. It was a
vertical line showing tab groups.
if (this) {
|
if (that) {
|
|
do stuff;
|
}
}
http://www.jedit.org/index.php?page=screenshot&image=10
<-- show a much better example that my little example
did...
I was wondering how todo this in vim.. turns out it is
simple
:set list
:set listchars=tab:\|\
:h listchars for help
Hope this helps you... join #vim on irc.freenode.net for
all your vim help needs :)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Use Ctrl-O instead of Esc in insert mode mappings | Open a Perl module based on it's module
name >>

Additional Notes
Anonymous, April 21, 2003 13:35

http://www.vim.org/tips/tip.php?tip_id=460 (1 of 4) [18/02/2004 14:59:43]

Tip #460 - how to implement vertical lines showing tab groups.. : vim online

You could really use ANY char to do your vertical


groups....
.
and
|
tend to work very
well
Anonymous, April 21, 2003 13:46
highlight SpecialKey guifg=<color> ctermfg=<color> in
order to tweak the colors
Mohit Kalra, April 21, 2003 21:39
I missed the trailing space after the backslash. So for
people who missed it too......read the line above as set listchars+=backslash-pipe-backslash-space
cec@NgrOyphSon.gPsfAc.nMasa.gov, April 22, 2003 8:07
Good tip -- here's a function+command to facilitate
use:
Usage:
:SeeTab
tabbing styles)

(toggles between normal and bar'd

" SeeTab: toggles between showing tabs and using


standard listchars
fu! SeeTab()
if !exists("g:SeeTabEnabled")
let g:SeeTabEnabled
= 1
let g:SeeTab_list
= &list
let g:SeeTab_listchars = &listchars
let regA
= @a
redir @a
hi SpecialKey
redir END
let g:SeeTabSpecialKey = @a
let @a
= regA
silent! hi SpecialKey guifg=black guibg=magenta
ctermfg=black ctermbg=magenta
set list
set listchars=tab:\|\
else
let &list
= g:SeeTab_list
let &listchars = &listchars
silent! exe "hi
".substitute(g:SeeTabSpecialKey,'xxx','','e')
unlet g:SeeTabEnabled g:SeeTab_list
g:SeeTab_listchars
endif
endfunc
com! -nargs=0 SeeTab :call SeeTab()
gowri.satyanarayana@oracle.com, April 23, 2003 0:32
http://www.vim.org/tips/tip.php?tip_id=460 (2 of 4) [18/02/2004 14:59:43]

Tip #460 - how to implement vertical lines showing tab groups.. : vim online

hey! but this wont work with expandtabs on!


i would rather have expand tabs on because otherwise,
if i ship my source to someone else who has a different
tabstop, then all my indenting will get all messed up
and lines will go beyond 80 and wrap around and what
not...
does anybody have a solution for this in an expand tabs
scenario??
bphelan@mathworks.co.uk, April 24, 2003 2:11
Use syntax highlighting when expand tabs are on. Note
the use of &sw to get the current shiftwidth for the
expanded tabs.
###############################
fu! SeeTab()
if !exists("g:SeeTabEnabled")
let g:SeeTabEnabled = 0
end
if g:SeeTabEnabled==0
syn match leadspace /^\s\+/ contains=syntab
exe "syn match syntab /\\s\\{" . &sw .
"}/hs=s,he=s+1 contained"
hi syntab guibg=Grey
let g:SeeTabEnabled=1
else
syn clear leadspace
syn clear syntab
let g:SeeTabEnabled=0
end
endfunc
com! -nargs=0 SeeTab :call SeeTab()
Robert (MetaCosm), April 24, 2003 10:38
Wow -- great comments on this tip.
I am hoping to tie
this wonderf comment together into a Script.
Great
work guys.
The ability to work with expandtab is
really wonderful!
gowri.satyanarayana@oracle.com, April 24, 2003 22:12
this is GR8! but one correction - expand tabs setting
expands tabs according to the tabstop setting not
shiftwidth - so in the SeeTab() function, replace &sw
by &ts
bphelan@mathworks.co.uk, April 25, 2003 3:19

http://www.vim.org/tips/tip.php?tip_id=460 (3 of 4) [18/02/2004 14:59:43]

Tip #460 - how to implement vertical lines showing tab groups.. : vim online

Gowri,
I've installed the script at
http://www.vim.org/scripts/script.php?script_id=627
with the change you suggested
cec@NgrOyphSon.gPsfAc.nMasa.gov, April 25, 2003 14:11
Hello!
OK, I've put my version, vimscript#628.
both
expandtab on and off cases. Enjoy!

It now handles

Anonymous, April 25, 2003 14:41


/me claps -- nothing like a little good competition
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=460 (4 of 4) [18/02/2004 14:59:43]

SourceForge
Logo

Tip #461 - Open a Perl module based on it's module name : vim online

not logged in (login)

Home
Search

Tip #461: Open a Perl module based on it's module name


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 19/13, Viewed by 668

created: April 22, 2003 11:57


author: Mark Stosberg

complexity: basic
as of Vim: 6.0

This may be of interest to Perl programmers using vim.


Sometimes I want to open up the source code of a system
Perl module that's installed. Here's one way to do that:
:e `perldoc -l Module::Name`
I find that useful.

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<how to implement vertical lines showing tab groups.. | G's of Vim >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=461 [18/02/2004 14:59:45]

SourceForge
Logo

Tip #462 - G's of Vim : vim online

not logged in (login)

Home
Search

Tip #462: G's of Vim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating 39/39, Viewed by 2175

created: April 22, 2003 18:53


author: Nitya

complexity: intermediate
as of Vim: 5.7

Hi Guys !!
You can play with THE "g" in VIM editor.

Scripts
Tips
My Account

Try this

Site Help

gd
will take you to the local declaration
gD
will take you to the global declaration.
g*
search for the word under the cursor. It's
just like * but don't put < or > around words
so here you can search word which contains
word under your cursor
Confused ???? try it NOW :-)
g#
same as g* but in backward direction

Place the cursor on any variable in your program.

Now time for gssssss


ggdG
takes out all your hard work ;-) I mean
deletes the content of the file ..
Happy viming ...

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Open a Perl module based on it's module name | XSLT Mappings I use to speed up developing
XSLT files. >>

Additional Notes
Anonymous, April 23, 2003 11:25

http://www.vim.org/tips/tip.php?tip_id=462 (1 of 2) [18/02/2004 14:59:48]

Tip #462 - G's of Vim : vim online

g* and g# are very cool.


For source code browsing, I definitely recommend using
cscope in parallel with vim. You can find more info
about cscope and vim elsewhere on this site or by
googling.
Anonymous, April 27, 2003 23:58
Set your 'path' variable properly, put the cursor on a
filename (in a #include say) and do a
gf
Anonymous, May 2, 2003 5:31
How is this different from using * or # on their own?
Save a keystroke ;)
sathishvj@yahoo_stop_spam.com, May 2, 2003 18:54
If ur cursor was under the word "file", and assuming
ignorecase is on then
*, #
- will find: file, File, FiLe etc.
g*, g#
- will find, apart from the above,
also: FileOpen, MyFilename, file_handle etc.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=462 (2 of 2) [18/02/2004 14:59:48]

SourceForge
Logo

Tip #463 - XSLT Mappings I use to speed up developing XSLT files. : vim online

not logged in (login)

Home
Search

Tip #463: XSLT Mappings I use to speed up developing XSLT files.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 8/4, Viewed by 857

created: April 23, 2003 5:50


author: Steven Spears

complexity: basic
as of Vim: 6.0

I recently added these mapping to speed up typing XSLT


elements. As this is my first tip, I hope these might be
useful to someone else. I added these mappings to my
copy of Devin Weaver's xmledit script.
imap <Leader>pi <?xml version="1.0" ?>^M
imap <Leader>ap <xsl:apply-templates/>
imap <Leader>ap`s <xsl:apply-templates select=""/>^[F"i
imap <Leader>ap`sm <xsl:apply-templates select=""
mode=""/>^[3F"i
imap <Leader>at <xsl:attribute name="">^[F"i
imap <Leader>el <xsl:element name="">^[F"i
imap <Leader>if <xsl:if test="">>^[kf"a
imap <Leader>im <xsl:import href=""/>^[F"i
imap <Leader>in <xsl:include href=""/>^[F"i
imap <Leader>ou <xsl:output method=""/>^[F"i
imap <Leader>pa <xsl:param name=""/>^[F"i
imap <Leader>pa`ns <xsl:param name="" select=""/>^[3F"i
imap <Leader>st <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">>;
imap <Leader>te <xsl:template match="">>^[kf"a
imap <Leader>te`n <xsl:template name="">>^[kf"a
imap <Leader>te`mm <xsl:template match=""
mode="">>^[kf"a
imap <Leader>va <xsl:value-of select=""/>^[F"i
imap <Leader>wi <xsl:with-param name=""/>^[F"i
imap <Leader>wi`ns <xsl:with-param name=""
select=""/>^[3F"
For more information:
vimscript #301
help: imap
rate this tip

Life Changing

Helpful

<<G's of Vim | search & replace the word under the cursor >>

http://www.vim.org/tips/tip.php?tip_id=463 (1 of 2) [18/02/2004 14:59:50]

Unfulfilling

rate

Tip #463 - XSLT Mappings I use to speed up developing XSLT files. : vim online

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=463 (2 of 2) [18/02/2004 14:59:50]

SourceForge
Logo

Tip #464 - search & replace the word under the cursor : vim online

not logged in (login)

Home
Search

Tip #464: search & replace the word under the cursor
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 34/17, Viewed by 1672

created: April 27, 2003 13:42


author: maurice

complexity: intermediate
as of Vim: 6.0

I have this usefull mapping in my vimrc:


nmap ; :%s/\<<c-r>=expand("<cword>")<cr>\>/
Now, if you see a word 'foo' which should be replaced,
you only have to put the cursor on it and type ';'.
Then the command-prompt has already the annoying
:%s/\<foo\>/ and you just have to enter your new word.
For information:
:help <c-r>
:help expand
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<XSLT Mappings I use to speed up developing XSLT files. | generic xml imap to make an element of
any word you type >>

Additional Notes
gmann, April 27, 2003 14:55
I am curious how this is more beneficial than cw ? Am
I missing something? One more keystroke? Thanks for
any advice.
maurice, April 27, 2003 15:08
As mentioned, this opens the prompt for search &
replace, which applies to the whole buffer and not only
for the one occurrence of the word.
Anonymous, April 27, 2003 17:14
your script is interesting, but non-standard, that's
why it's not very useful
http://www.vim.org/tips/tip.php?tip_id=464 (1 of 4) [18/02/2004 14:59:53]

Tip #464 - search & replace the word under the cursor : vim online

Anonymous, April 27, 2003 23:09


'cw' only changes the word at the current position,
'%s' does theat for all occurances in the file.
Well, what is 'standard' ?
'non-standard' may also be useful. I often found tips
and scripts here rated useful, but not for me.
So what about senseless 795,32 colour schemes which may
be 'standard' but useless ?
;-)) Thomas
feral at firetop dot comthingie, April 28, 2003 1:47
Another way of accomplishing basically the same thing:
If you do not specify the pattern for <kbd>:s</kbd> it
will use register / (current search string), as such
I've been <kbd>*:%s//whatever</kbd> whenever I have
wanted to change all occurrences of a word.
I had not really thought of using a nmap to construct
the :substitute .. (By the by I have been mulling over
menu entries)
Related, use <kbd>&</kbd> as part of the replace string
to modify your search string (see :h sub-replacespecial)
Also related consider this nmap that uses the contents
of the unnamed register: <kbd>nmap ; :%s/<c-r>"/</kbd>
Thanks for the tip Maurice!
p.s. just pretend the html kbd tags did what they are
supposed to and denote what to type (=
marena@zor.org, April 28, 2003 2:44
Great idea!
BTW you can use nmap ; :%s/\<<c-r><c-w>\>/ as well...
niklas, April 28, 2003 10:07
Nice tip. One thing though: nmapping ";" disables the
default command for that key. That is "repeat last jump
to character using f, F, t or T" (for which "," repeats
in opposite direction). See ":help f" and the 5 related
commands below that one in "motion.txt".
Maurice, April 28, 2003 11:06

http://www.vim.org/tips/tip.php?tip_id=464 (2 of 4) [18/02/2004 14:59:53]

Tip #464 - search & replace the word under the cursor : vim online

Oh.. never used this jumps. But after trying them out
it seems that I will do this in the future. Very cool
:)
Guess I have to map this replace-stuff to another
key...
What is this non-standard-thing? Thought that if its
listed in the vim help, it is ok :)
gmann, April 30, 2003 20:06
Thanks for the clarification Maurice. The tip is quite
nice, standard or not. I like the jumps as well (vi =
very impressive). This would also be nice to map along
with the AllBuffers method, can you think of how I can
map this, so that I can do the same thing across all
buffers which I have open? Something like the
following (which doesn't work)
map <M-t> :call AllBuffers(":%s/\<<c-r><c-w>\>/
Maurice, May 1, 2003 8:22
I don't know about a function 'AllBuffers'. But I think
what you want is the bufdo-command.
Your mapping would be something like this:
map <M-t> :bufdo :%s/\<<c-r><c-w>\>/
JonathanOrlev@yahoo.com, May 21, 2003 1:55
Great macro, thanks.
I have a small question:
When entering this line as it is to my .vimrc file, the
last '/' "messes" the syntax of the configuration
file.
IE: it changes the colors of some of the following
commands. This is probably due to the special role of
'/' .
I "solved" it by removing the '/' (and I enter it
manually whenever I need to use the macro).
Any better advice ?
Regards,
Jonathan Orlev.
atum@gmx.de, May 21, 2003 2:01

http://www.vim.org/tips/tip.php?tip_id=464 (3 of 4) [18/02/2004 14:59:53]

Tip #464 - search & replace the word under the cursor : vim online

Anybody knows how I performe it, if I mark with


":v2w" 2words and put it directly in the command line
for searching and replacing?
Maurice, June 1, 2003 9:32
> Anybody knows how I performe it, if I mark with
":v2w" 2words and put it directly in the command line
for searching and replacing?
For example with the help of a register:
vnoremap <your-key> "ty:%s/<c-r>=@t<cr>/
But note that this will alter the register 't'.
If you use XFree, where the clipboard is automatically
set by selecting some text, you could also use the '*'Register:
vnoremap S <esc>:%s/<c-r>*/
matt@littlebluepeople.com, October 19, 2003 16:24
nnoremap ; :%s/\<<c-r><c-w>\>/
works well for me, it selects the current word and only
replaces whole word matches, for example:
$xml_parser = xml_parser_create();
....
if the cursor was on $xml_parser and you typed ';'
only $xml_parser would be replaced, not
xml_parser_create()
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=464 (4 of 4) [18/02/2004 14:59:53]

SourceForge
Logo

Tip #465 - generic xml imap to make an element of any word you type : vim online

not logged in (login)

Home
Search

Tip #465: generic xml imap to make an element of any word you type
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 44/17, Viewed by 672

created: April 29, 2003 12:05


author: Bart van Deenen

complexity: basic
as of Vim: 5.7

Hi all.
We're doing a lot of xml work, in docbook and custom xml
files.
I'd just like to share one macro I've developed, that I
really can't live without.
imap ,,, <esc>bdwa<<esc>pa><cr></<esc>pa><esc>kA
If in isert mode I type programlisting,,,
the text immediately get's modified to
<programlisting>
</programlisting>
with the cursor in between, still in Insert mode.
The same happens with any other word i type followed by
three commas.
<tryit>
</tryit>
It saves me a lot of work, and I'd like to share it.
Hope you can use it
Bart van Deenen. (bart@vandeenensupport.com)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<search & replace the word under the cursor | Insert one character only >>

Additional Notes
gmann, April 29, 2003 18:46
please share any other mappings you like!
quite nice!
http://www.vim.org/tips/tip.php?tip_id=465 (1 of 5) [18/02/2004 14:59:55]

That one is

Tip #465 - generic xml imap to make an element of any word you type : vim online

bart@vandeenensupport.com, April 30, 2003 3:05


Chris Lear had a small modification, which allows the
same imap to be used with namespaced elements (such as
used all the time in xsl).
just change the b in B and the w in W, and the imap
will go over the colon in the namespace.
fuzz01@spamfilter.dk, April 30, 2003 7:26
Is it possible to modify this map, so the indentation
will be kept. So
test,,,<cr><tab>test2,,,
results in
<test>
<test2>
</test2>
<test>
It would also be nice, if it was possible to detect if
the line already contains non-whitespace so
this is a bold,,,bold<esc>f> test
resulted in
this is a <bold>bold</bold> test
bart@vandeenensupport.com, April 30, 2003 12:33
Your question about indenting is easily fulfilled by
:set ai which sets auto indenting.
The other one is really intriguing, and I'll have a go
at it, because that would indeed be helpfull
Bart van Deenen
bart ot vandeenensupport point com, May 1, 2003 8:31

http://www.vim.org/tips/tip.php?tip_id=465 (2 of 5) [18/02/2004 14:59:55]

Tip #465 - generic xml imap to make an element of any word you type : vim online

Hi
I improved my imap with a function (my first in vim)
(can probably be done in a one-liner :)
Put the following in xml.vim in your ftplugin
directory, our source it in your .vimrc. The ^] and ^M
are entered via <CTRL-V><esc> and <CTRL-V><CR>
function! Make_element()
"function to make an xml element at the current
cursor position out of the
"contents of the just deleted unnamed
register
"
"Bart van Deenen
if match(getline('.'),'^\s*'.@".'\s*$') == -1
"the deleted word was not alone on the line
let @w = "i<^[ea></^[pa>^[F<i"
else
"the deleted word was on it's
own on the line
let @w =
"i<^[ea>^M</^[pa>^[kA"
endif
endfunction
"include colon(58) for namespaces in xsl for instance
set iskeyword=@,48-57,_,192-255,58
imap <buffer> ,,, <Esc>bye:call
Make_element()<enter>@w
It seems to do the job with me.
Thanks for the question, I learned something from
finding the answer
Bart van Deenen
bart van deenen, May 1, 2003 10:41
hi
it's probably better to use :setlocal iskeyword than
:set
Bart
arnarb at oddi dot is, May 1, 2003 10:45

http://www.vim.org/tips/tip.php?tip_id=465 (3 of 5) [18/02/2004 14:59:55]

Tip #465 - generic xml imap to make an element of any word you type : vim online

Just a quick note, instead of setting the "iskeyword"


like that, you can use
:set iskeyword+=:
to add the colon to the list of characters/ranges, this
way you won't break anything else if it depends on
specific settings of iskeyword.
References
:help set+=
:help set-=
:help set<CTRL-D>
arnarb at oddi dot is, May 1, 2003 10:47
Nice.. that four minute difference between my comment
and the one before that one was about the time it took
me to write it :o) Hence.. I didn't see it until after
I posted.
bart, May 1, 2003 11:11
Hi all
I uploaded this as vimscript #632.
Happy vimming!
Bart
fs111@linuxmail.org, October 6, 2003 6:00
This tip is great, but it does not work if the word is
only one character long, like "a" in html. If I type
a,,, the result is:
<
a></>
What is going wrong?
Andr
tobiasreif pinkjuice com, October 13, 2003 3:30

http://www.vim.org/tips/tip.php?tip_id=465 (4 of 5) [18/02/2004 14:59:55]

Tip #465 - generic xml imap to make an element of any word you type : vim online

Hi
If you install vimscript #301 (Devin Weaver's xmledit)
you can do
i<foo>>
and get
<foo>
[cursore here]
</foo>
Also see

vimtip #583 (Vim as XML Editor).

Have fun,
Tobi
Anonymous, November 29, 2003 4:48
Andr wrote:
This tip is great, but it does not work if the word is
only one character long, like "a" in html. If I type
a,,, the result is:
<
a></>
It has to do with a part of the script where I use bye
to go to the beginning of the word (a in your case),
and yank the word into a buffer. Unfortunately the 'b'
command skips over the start of the 'a' word, so you
end up with garbage.
I don't have a fix yet, but if I find one, I'll post
it. Somebody else?
Bart (the author of the tip)
P.S. sorry for the late answer, I was on honeymoon :-)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=465 (5 of 5) [18/02/2004 14:59:55]

SourceForge
Logo

Tip #466 - Insert one character only : vim online

not logged in (login)

Home
Search

Tip #466: Insert one character only


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 59/30, Viewed by 1528

created: April 30, 2003 10:10


author: johnmaxa

complexity: basic
as of Vim: 5.7

I have not yet seen this idea yet. But early in my use
and love of Vim, I got frustrated in command mode when I
wanted to insert just one character of text. So I put
this in _vimrc:
"insert one character
noremap <somekey> i<Space><Esc>r
I think it has been one of the most time saving mappings
-- and I have remapped most of my keyboard.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<generic xml imap to make an element of any word you type | vim windows displaying output inside
vim window >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=466 [18/02/2004 14:59:59]

SourceForge
Logo

Tip #467 - vim windows displaying output inside vim window : vim online

not logged in (login)

Home
Search

Tip #467: vim windows displaying output inside vim window


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/8, Viewed by 1563

created: April 30, 2003 21:45


author: char

complexity: basic
as of Vim: 5.7

In vim for *nix or cygwin, the command


:!cmd
displays the output inside vim windows,
but for vim windows, the output is displayed in the
console window.
To make the output displayed inside vim or gvim window,
can use
:echo system("command")
references:
:help system()
:help echo
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Insert one character only | display date-and-time on status line >>

Additional Notes
wnatter@nortelnetworks_cba.com, May 2, 2003 10:21
If you want, you can have the output of the command
sent into your file by using the '!' mechanism a little
further:
:<range>!<command>
This will send the lines in the range to the standard
input of your command, and replace them with the
standard output of the command (see help for
details). Please remove _cba in my address to send me
a note.

http://www.vim.org/tips/tip.php?tip_id=467 (1 of 3) [18/02/2004 15:00:02]

Tip #467 - vim windows displaying output inside vim window : vim online

Anonymous, May 4, 2003 9:16


hmm this is a good tip, but does anyone know how to
make it expand % into the current buffer?
Most of the times I am running an external command it
involves %
For example, after recovering a swap file:
(very
common on windows due to frequent crashes :-)
)
:cp % %.rec
and then
!diff % %.rec
which of course spawns the annoying DOS box to give you
the result of the diff.
I tried
echo system("diff expand("%") expand("%.rec")")
echo system('diff expand("%") expand("%.rec")')
echo system("diff expand('%') expand('%.rec')")
But in all cases the shell doesn't get the expanded
buffer name.
I even got fancy and tried:
execute "echo system('diff " . expand('%') . " " .
expand('%.rec') . "')"
but that seemed to return no output at all, even by
checking :messages
:(
Help, anyone?
But none of these successfully expand the % such that
the shell receives the actual buffer name :(
Anonymous, May 7, 2003 22:32

http://www.vim.org/tips/tip.php?tip_id=467 (2 of 3) [18/02/2004 15:00:02]

Tip #467 - vim windows displaying output inside vim window : vim online

You don't use vimdiff ?


Using the script DirDiff.vim, you get some commands
(diffsplit, diffget, diffput)
to work visually with two or more files with colour
marked differences, each in a separate
vim-window.
To read output of system commands into the actual file
at filepos use ':r !<command>'.
<command> may be any shell-command, '%' is substituted
with current file name,
e.g. ':r !ls -l %.bak' reads in the output of 'ls -l
test.cpp.bak' while editing test.cpp.
Works fine on WIndows NT4/2000.
Thomas
jaldri1 at gl dot umbc dot edu, June 11, 2003 9:22
Try this.
:echo system("dir ".expand("%"))
John
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=467 (3 of 3) [18/02/2004 15:00:02]

SourceForge
Logo

Tip #468 - display date-and-time on status line : vim online

not logged in (login)

Home
Search

Tip #468: display date-and-time on status line


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 56/37, Viewed by 1855

created: May 1, 2003 8:42


author: Dorai Sitaram

complexity: basic
as of Vim: 5.7

It didn't seem like an existing tip mentioned this, so:


The following lines in .vimrc or a plugin file will
display
the time of day and calender date (some of us need that
reminder)
on the editor status line:
set ruler
set rulerformat=%55(%{strftime('%a\ %b\ %e\ %I:%M\
%p')}\ %5l,%-6(%c%V%)\ %P%)
It doesn't update time if you issue no keystrokes, but
as soon as you
do anything at all in the editor, you will get the
current time.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<vim windows displaying output inside vim window | The use of %< instead of % >>

Additional Notes
Anonymous, May 1, 2003 10:47

http://www.vim.org/tips/tip.php?tip_id=468 (1 of 2) [18/02/2004 15:00:04]

Tip #468 - display date-and-time on status line : vim online

"My vimrc has the following. (Some people might find


that these
"lines slow down the response of vim too much.)
set laststatus=2 "black status line at bottom of window
"
if has("win32")
set statusline=%<%f%h%m%r%=%{strftime(\"%I:%M:%S\
\%p,\ %a\ %b\ %d,\ %Y\")}\ %{&ff}\ %l,%c%V\ %P
else
set statusline=%<%f%h%m%r%=%{strftime(\"%l:%M:%S\
\%p,\ %a\ %b\ %d,\ %Y\")}\ %{&ff}\ %l,%c%V\ %P
endif
Anonymous, May 9, 2003 8:22
Excellent!
I didn't add this to the status line, but I did add it
to the pheader (printheader), which uses the same
syntax.
That way when I print the file, I can also print the
current clock time. Now: how can I print the file
modify time?
Here is my _vimrc (section):
set pheader=%<%f%h%m%40{strftime(\"%I:%M:%S\ \%p,\ %a\
%b\ %d,\ %Y\")}%=Page\ %N
(filename, time, page N)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=468 (2 of 2) [18/02/2004 15:00:04]

SourceForge
Logo

Tip #469 - The use of %< instead of % : vim online

not logged in (login)

Home
Search

Tip #469: The use of %< instead of %


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/9, Viewed by 1776

created: May 2, 2003 5:22


author: Vincent NAUDOT

complexity: basic
as of Vim: 5.7

This tips is for vim or gvim user. We know the following


map
map! /' ^[:w^M:! latex %^Mi
is doing the following. By typing "/'" in insert mode,
this
will save the current tex file, and compile it.
The reader understand that one can change "/'" by
anything he want,
as long as it does not bug its own configuration, I like
this map 'cause
on an english keyboard both / and ' are close to
eachother.
We may wonder
what to do if we wish to open the associated dvi file?!
Indeed one has to replace % by %<.dvi and then we get
map! <F4> ^[:! xdvi %<.dvi ^Mi
or
map! <F4> ^[:! kdvi %<.dvi ^M
if you are using K environement.
The same thing apply indeed for any other extension
i.e.,
the map
map! <F5> ^[:! gv %<.ps ^Mi
will open the associated ps file with gv.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<display date-and-time on status line | Map to quickly swap/exchange arbitrary text >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=469 (1 of 2) [18/02/2004 15:00:07]

Tip #469 - The use of %< instead of % : vim online

blah@blah.com, May 4, 2003 8:59


nice one, but realise this is deprecated, the
preferred form is %:r
And in fact there's a whole bunch more things you can
do than just remove the extension - you can remove the
directory/path, keep just the extension, etc etc by
using different ':' modifiers.
:he filename-modifers
cniehaus@kde.org, May 8, 2003 6:26
There is the vim-latex-project:
http://vim-latex.sourceforge.net/
If you install that in your ~/.vim you will have _a
lot_ improvments all over the map. \ll compiles you
.tex-file,
\lv shows you the .dvi. `d give you \delta and `D gives
you \Delta. There is so much, just check it out!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=469 (2 of 2) [18/02/2004 15:00:07]

SourceForge
Logo

Tip #470 - Map to quickly swap/exchange arbitrary text : vim online

not logged in (login)

Home
Search

Tip #470: Map to quickly swap/exchange arbitrary text


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 47/22, Viewed by 1115

created: May 5, 2003 10:31


author: Piet Delport

complexity: intermediate
as of Vim: 5.7

When editing text, it's not uncommon to need to swap two


bits of text. In
Vim, it's easy to swap adjacent characters, words and
lines (see vimtip #47),
but to swap non-adjacent text (such as comma-separated
words, variable
assignments, and function parameters), you usually have
to resort to a tedious
delete/move/put/delete/move/put sequence.
Mappings such as the one in vimtip #329 can help in some
cases, but for a more
general solution, try this mapping:
vnoremap <C-X> <Esc>`.``gvP``P
To use it: First, delete some text (using any normal
Vim command, such as
daw, {Visual}x, or dt,). Then, visually select some
other text, and press
CTRL-X. The two pieces of text should now be swapped.
For example, to swap "apple" and "orange" in the line
below:
int apple, lemon, orange;
1. Delete "apple", using (for example) diw or <doubleclick>d
2. Visually select "orange"
3. Press CTRL-X
The mapping is not limited to single words, though, and
will work with
anything you can delete/select (even lines and blockwise
selections).

http://www.vim.org/tips/tip.php?tip_id=470 (1 of 4) [18/02/2004 15:00:10]

Tip #470 - Map to quickly swap/exchange arbitrary text : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<The use of %< instead of % | Bridging the worlds: putting your rodent to work for vim in xterms >>

Additional Notes
david@tvis.co.uk, May 6, 2003 1:27
Hi I've needed this about a billion times!! zzapper
How it works (AFAIK)
vnoremap <C-X> <Esc>`.``gvP``P
<ESC> disappears visual selection
`.
return to exact spot of last modification
(the deleted text)
``
jump back to where you were (exactly)
gv
re-highlight last visual text
P
Put/paste last deleted text over visually
selected text
``
Toggle to where text was deleted
P
Visually Selected Text now in default
register so just paste it.
Notes:
Note use throughout of BACK tip `
When you initially delete text , don't delete the
trailing space
<C-X> can still be used for decrement
ad_scriven@postmaster.co.uk, May 7, 2003 3:18
This is a nice map. However it breaks in the case where
the
first word you delete is on the same line as the one
you
highlight and is further to the right (vim shifts the
`.
mark about). Here is a horrible fix. I'm sure someone
else
can do better. Replace ^V with ctrl-V.
vnoremap <silent> <C-X> <Esc>`.``:exe
line(".")==line("'.") && col(".") < col("'.") ? 'norm!
:let c=col(".")^V^V^V^V<CR>gvp```]:let c=col(".")c^V^V^V^V<CR>``:silent call
cursor(line("."),col(".")+c)^V^V^V^V<CR>P' : "norm!
gvp``P"<CR>
http://www.vim.org/tips/tip.php?tip_id=470 (2 of 4) [18/02/2004 15:00:10]

Tip #470 - Map to quickly swap/exchange arbitrary text : vim online

Antony
pjd@303.za.net, May 7, 2003 7:38
Good catch. The problem doesn't seem to be caused by
Vim moving the `. mark
about, though, but rather by the fact that Vim
*doesn't* move it.
IOW, when you change a line by inserting/deleting
characters, any marks to the
right of the change don't get adjusted to correct for
the change, but stay
pointing at the exact same column as before the change
(which is not the right
place anymore).
It seems there's already a todo-item for this (line
2998 in todo.txt):
7

Try to keep marks in the same position when:


[...snip...]
- inserting/deleting characters in a line.

ad_scriven@postmaster.co.uk, May 7, 2003 12:32


Yeah, that's what I mean't! The mark stays at the same
column (it moves relative to the text, in my mind).
Didn't
realise it was in todo.txt. Same thing happens with
visual
selection, because the `< and `> stay put relative to
the
screen.
Makes this sort of thing tricky. You can't (as far as I
can
see in this context) insert markers in the text to find
the
correct place with / because this makes the `. mark
wrong.
Antony
tdh_sam@hotmail.com, June 4, 2003 14:48
Why is it that mapping never works for me :((((
I tried doing this stuff but nothing happened.
I am using 6.1. Any HELP?
Add Note

http://www.vim.org/tips/tip.php?tip_id=470 (3 of 4) [18/02/2004 15:00:10]

Tip #470 - Map to quickly swap/exchange arbitrary text : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=470 (4 of 4) [18/02/2004 15:00:10]

SourceForge
Logo

Tip #471 - Bridging the worlds: putting your rodent to work for vim in xterms : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #471: Bridging the worlds: putting your rodent to work for vim in
xterms
tip karma

Rating 43/16, Viewed by 1311

created: May 8, 2003 7:48


author: pagaltzis at gmx dot de

complexity: basic
as of Vim: 6.0

If, like me, you don't want to use the GUI vim because
you work in an xterm most of the time anyway, you may be
annoyed at the shortcomings this presents. For example,
during my webbrowsing, I'll often fire up vim in one of
the already lying around xterms to conveniently write a
long text (such as this one), and then paste from vim
into a textfield on a HTML form in the browser.
The first problem is caused by line numbering, which I
keep enabled at all times.
:set number
:help number
Normally, if you try to copy text out of the xterm that
vim is running in, you'll get the text as well as the
numbers. The GUI version gets this right: it only
selects the text, keeping the line numbers out of the
picture. But I don't want the GUI version. So instead, I
added this to my vimrc:
:set mouse=a
Much better. You can also selectively enable mouse
support for specific modes only by using something other
than 'a' (for 'all').
:help mouse
Now although I'm more of a keyboarder, when I juggle
text between X apps (or maybe between xterms), it's just
more convenient and efficient to keep my hands on my
mouse, since they're there anyway. Now, if you own a
moderately recent model, you'll know this lovely little
wheel they have (which usually also doubles as mouse
button 2). Rolling it scrolls the window in GUI vim,
which simplifies life when selecting several, distant

http://www.vim.org/tips/tip.php?tip_id=471 (1 of 3) [18/02/2004 15:00:14]

Tip #471 - Bridging the worlds: putting your rodent to work for vim in xterms : vim online

passages to paste one after the other. But I don't want


to use the GUI vim - you can imagine my delight when I
ran across this in the vim documentation:
:help wheel
It involves adding a couple mappings to your vimrc and
corresponding VT100 translations to your .Xresources
file as a prerequisite. Don't forget
$ xrdb -load .Xresources
after you edit the file. The running xterm will not heed
the changes; you need to open a new one to see the
effect.
The wheel may not work with the mappings as described in
the helpfile. They worked without a hitch for me at
first (using Xfree 4.1 then), but broke after I upgraded
my distro. Whether it was the switch to 4.3 on this
binary has been built with different options, I don't
know. At any rate, I had to experiment a bit with the
list from
:help keycodes
After a bit of trial and error, I finally fixed them by
substituting <xCSI> for <M-Esc>:
:map <xCSI>[62~ <MouseDown>
" etc
" ...
Done. Load a large text file and marvel at mousewheel
scrolling.
rate this tip

Life Changing

Helpful

Unfulfilling

<<Map to quickly swap/exchange arbitrary text | Handy option flag toggler >>

Additional Notes
pagaltzis at gmx dot de, May 8, 2003 7:52

http://www.vim.org/tips/tip.php?tip_id=471 (2 of 3) [18/02/2004 15:00:14]

rate

Tip #471 - Bridging the worlds: putting your rodent to work for vim in xterms : vim online

: Whether it was the switch to 4.3 on this binary has


been built with different options, I don't know.
That is, of course:
Whether it was the switch to 4.3 *or* this binary has
been built with different options, I don't know.
waxmop@sarcastic-horse.com, May 30, 2003 7:43
But how to copy from a browser and paste into an xterm
vim? That's what I want to know...
Anonymous, May 30, 2003 16:15
re: pasting into an xterm vim..
Select text in your browser, goto vim, :set paste,
insert mode, middle click (button 2)
If you don't set paste mode, you're probably not going
to be happy with the results due to indendation and
whatnot.. I bound F11 to toggle paste mode, in both
insert mode and normal mode. From my .vimrc:
" F11 to toggle paste mode
map <F11>
:set invpaste<CR>
set pastetoggle=<F11>
Hope this helps.
maurice, June 1, 2003 14:08
Does anybody know of a way to get this working for an
aterm?
deeni@altern.org, July 18, 2003 16:45
Re how to make it work in an aterm...
Have you tried :set mouse=a ? It's worked fine for
ages for me in an aterm.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=471 (3 of 3) [18/02/2004 15:00:14]

SourceForge
Logo

Tip #472 - Handy option flag toggler : vim online

not logged in (login)

Home
Search

Tip #472: Handy option flag toggler


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/5, Viewed by 647

created: May 12, 2003 9:52


author: robin at isometry dot net

complexity: basic
as of Vim: 6.0

Here's a little function I put together to make some of


my mappings easier to read, understand and change.
function ToggleFlag(option,flag)
exec ('let lopt = &' . a:option)
if lopt =~ (".*" . a:flag . ".*")
exec ('set ' . a:option . '-=' . a:flag)
else
exec ('set ' . a:option . '+=' . a:flag)
endif
endfunction
Examples of use:
map <silent> <F8> :call ToggleFlag("guioptions","m")<CR>
map <silent> <F9> :call ToggleFlag("guioptions","T")<CR>
Can anyone see anyway to improve it?
e.g. remove the leading exec... "if &{a:option}..."
doesn't work.
e.g. a regex match doesn't seem the cleanest of checks,
though I prefer it to setting a variable for each
possible flag.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Bridging the worlds: putting your rodent to work for vim in xterms | "compiler" for perl >>

Additional Notes
robin at isometry dot net, May 12, 2003 17:53

http://www.vim.org/tips/tip.php?tip_id=472 (1 of 3) [18/02/2004 15:00:16]

Tip #472 - Handy option flag toggler : vim online

Hmmm. The following might be more flexible (I think it


should work for any flag-style option.
function ToggleFlag(option,flag)
exec ('let tf_old = &' . a:option)
exec ('set ' . a:option . '-=' . a:flag)
exec ('let tf_new = &' . a:option)
if (tf_o == tf_t)
exec ('set ' . a:option . '+=' . a:flag)
endif
endfunction
And here's another for valued rather than flag options,
such as foldcolumn:
function CycleNum(option,min,inc,max)
exec ('let tz_value = ((&'.a:option.'+'.a:inc.''.a:min.')%('.a:max.'+'.a:inc.'))+'.a:min)
if (tz_value < a:min) " in case inc<0
let tz_value = tz_value+a:max
endif
exec ('set '.a:option.'='.tz_value)
endfunction
e.g.
map <silent> <F6> :call
CycleNum("foldcolumn",0,2,4)<CR>
robin at isometry dot net, May 16, 2003 1:10
Here are my revised functions, and mappings:
" my function to cycle a numeric option
function CycleNum(option,min,inc,max)
exec ('let tz_value = (((&'.a:option.''.a:min.')+'.a:inc.')%(('.a:max.''.a:min.')+'.a:inc.'))+'.a:min)
if (tz_value < a:min) " in case inc<0
let tz_value = tz_value+a:max
endif
exec ('setlocal '.a:option.'='.tz_value)
endfunction
" my function to toggle an option flag
function ToggleFlag(option,flag)
exec ('let tf_o = &'.a:option)
exec ('setlocal '.a:option.'-='.a:flag)
exec ('let tf_t = &'.a:option)
if (tf_o == tf_t)
exec ('setlocal '.a:option.'+='.a:flag)
endif
endfunction
http://www.vim.org/tips/tip.php?tip_id=472 (2 of 3) [18/02/2004 15:00:16]

Tip #472 - Handy option flag toggler : vim online

" Toggle folding column


noremap <silent> <F7> :call
CycleNum("foldcolumn",0,2,6)<BAR>set foldcolumn?<CR>
imap
<F7> <C-O><F7>
" Toggle window appearance
noremap <silent> <F8> :call
ToggleFlag("guioptions","m")<BAR>set guioptions?<CR>
imap
<F8> <C-O><F8>
noremap <silent> <F9> :call
ToggleFlag("guioptions","T")<BAR>set guioptions?<CR>
imap
<F9> <C-O><F9>
" Cycle tabstop
noremap <silent> <M-t>s :call
CycleNum("tabstop",4,4,8)<BAR>set tabstop?<CR>
" Cycle shiftwidth
noremap <silent> <M-t>w :call
CycleNum("shiftwidth",4,4,8)<BAR>set shiftwidth?<CR>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=472 (3 of 3) [18/02/2004 15:00:16]

SourceForge
Logo

Tip #473 - "compiler" for perl : vim online

not logged in (login)

Home
Search

Tip #473: "compiler" for perl


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 13/7, Viewed by 1524

created: May 13, 2003 22:17


author: Chris Forkin http://www.forkin.com/

complexity: basic
as of Vim: 5.7

At on stage I was writing a lot of perl scripts/modules


with Vim and found it useful to be able
to run the perl syntax-checker (perl -c) from within Vim
via the "make" function. To be able
to do this you'll need to add the following Module
(VimCompile.pm) to your @INC
---------------<cut here>--------------#!/usr/bin/perl -w
#$Id: VimCompile.pm,v 1.2 2002/02/16 01:07:03 forkin Exp
$
# reformat "perl -c" syntax-check error-/warningmessages for Vim
package VimCompile;
use strict;
sub _die {
my ($msg)=@_;
$msg=~s/^((.* at )((.*) line )([0-9]+)(\.|, near
.*))$/$4:$5: $1/mg;
die qq/$msg/;
}
sub _warn {
my ($msg)=@_;
$msg=~s/^((.* at )((.*) line )([0-9]+)(\.|, near
.*))$/$4:$5: $1/mg;
warn qq/$msg/;
}
$SIG{'__DIE__'}=\&_die;
$SIG{'__WARN__'}=\&_warn;
# return OK
1;
__END__
------------<cut here>--------------This Module will reformat the warnings/errors so that
Vim can parse them (to allow you to
jump to the location/source-code of the error). You will

http://www.vim.org/tips/tip.php?tip_id=473 (1 of 2) [18/02/2004 15:00:18]

Tip #473 - "compiler" for perl : vim online

also need to deposit the following


(perl.vim) in your ~/.vim/runtime/compiler directory.
------------<cut here>--------------" Vim compiler file
" Compiler:
perl (output of "die" massaged)
" Maintainer:
Chris Forkin, chris@forkin.com
if exists("current_compiler")
finish
endif
let current_compiler = "perl"
" A workable errorformat for "perl -c"
setlocal errorformat=%f:%l:\ %m
" default make
setlocal makeprg=perl\ -MVimCompile\ -c\ %
------------<cut here>--------------rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Handy option flag toggler | have . restore the cursor position a la emacs in viper mode >>

Additional Notes
Anonymous, May 14, 2003 23:58
:h errorformat-perl
or have a look at $VIMRUNTIME/tools/efm_perl.pl
to use quickfix mode with perl scripts.
Thomas
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=473 (2 of 2) [18/02/2004 15:00:18]

SourceForge
Logo

Tip #474 - have . restore the cursor position a la emacs in viper mode : vim online

not logged in (login)

Home
Search

Tip #474: have . restore the cursor position a la emacs in viper mode
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/5, Viewed by 595

created: May 14, 2003 21:39


Brett Williams (brett_williams at agilent dot
author:
com)

complexity: basic
as of Vim:

6.0

Before making the switch to vim, I spent time in limbo


using EMACS in viper mode (which is EMACS with vi
emulation). Despite the vast improvements in most
areas, there were a few things I missed from EMACS. One
thing I really missed was the behavior of the . command,
which always restored the cursor position.
For example, let's say I had the following:
foo.some_method.each do { |x| puts x }
foo.some_other_method(Time.now)
foo.close()
and I wanted to change foo to bar.
cw and then the . command:
cwbar<cr>j.j.

I would always use a

rather than making a substitute command which would make


me worry about the range over which it should take place
etc.
When making the switch to vim, I was disconcerted
because after the first . my cursor was at the end of
the second 'bar'.
In fact I pretty much always wanted this behavior from
'.', so this mapping helped me out:
"make . not move the cursor
noremap . mz.`z
I've since noticed this is just a special case of the
tip *restore-position* in the help manual, but it took
me a while to find out how to do this. One other former
emacs/viper user also was searching for this. Hopefully
this tip makes it easier for the next person to find who
finally finds their way out of EMACS.
http://www.vim.org/tips/tip.php?tip_id=474 (1 of 3) [18/02/2004 15:00:21]

Tip #474 - have . restore the cursor position a la emacs in viper mode : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<"compiler" for perl | wrap visual selection with fold markers >>

Additional Notes
Anonymous, May 15, 2003 2:19
You can also use the following mapping, that doesn't
modify the z mark
noremap .

.'^

JohnSivak at Hotmail.com, May 15, 2003 7:56


You can also use "set nostartofline" in your .vimrc.
See ":help startofline"
Anonymous, May 15, 2003 12:47
nostartofline doesn't apply to '.' according to the
help:
This applies to the commands: CTRL-D, CTRL-U,
CTRL-B,
CTRL-F, "G", "H", "M", "L", , and to the
commands "d", "<<" and ">>"
with a linewise operator, with "%" with a count
and to buffer changing
commands (CTRL-^, :bnext, :bNext, etc.). Also
for an Ex command that
only has a line number, e.g., ":25" or ":+".
JohnSivak at Hotmail.com, May 16, 2003 5:58
You're right. I thought "startofline" was doing
something it isn't..
sitar@procaut.sk, May 26, 2003 2:33

http://www.vim.org/tips/tip.php?tip_id=474 (2 of 3) [18/02/2004 15:00:21]

Tip #474 - have . restore the cursor position a la emacs in viper mode : vim online

when changing the text you always have several


ways of how to specify the text to change
you can change a word by typing cw at the begining
of the word. However I would prefer ciw - using text
objects.
It was the "dot" command that made me to start using
text objects aw, iw, ap, ip, ... .
see :help objects
Stano
brett_williams@agilent.com, May 27, 2003 18:30
Stano, great tip on the text objects.
and I'm learning more of the objects.

'ciw' is great

Does anyone know if the concept of text blocks etc. is


extended to use matchit delimiters so that changing a
block would work not only with {}, but with do ... end
for example?
Anonymous, June 23, 2003 19:15
>You can also use the following mapping, that doesn't
modify the z mark
>noremap .

.'^

Wouldn't this be:


noremap . .'[
Anonymous, June 23, 2003 19:16
Shoot. I meant
noremap . .`[
The special single quote jumps the cursor to the
correct column
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=474 (3 of 3) [18/02/2004 15:00:21]

SourceForge
Logo

Tip #475 - wrap visual selection with fold markers : vim online

not logged in (login)

Home
Search

Tip #475: wrap visual selection with fold markers


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 2/3, Viewed by 760

created: May 18, 2003 6:46


author: culley

complexity: basic
as of Vim: 6.0

Use this vmap to enclose a block with fold markers:


vmap
<leader>fold mz:<esc>'<O// {{{<esc>'>o//
}}}<esc>`z?{{{<cr>A<space>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

Site Help
<<have . restore the cursor position a la emacs in viper mode | multime errorformat & makeprgs >>

Additional Notes
Kartik Agaram, May 18, 2003 12:08
Prefer the zf command, in combination with
foldmethod=marker.
:help zf
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=475 [18/02/2004 15:00:23]

SourceForge
Logo

Tip #476 - multime errorformat & makeprgs : vim online

not logged in (login)

Home
Search

Tip #476: multime errorformat & makeprgs


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 6/3, Viewed by 552

created: May 20, 2003 9:39


author: sputnik

complexity: basic
as of Vim: 5.7

I was fiddling around with the errorformat and makeprg


opts, and as I code in different languages, i was
wondering if there was a way of specifiing a special
makeprg and errorformat parameter for each language....
and THERE IS!!
just edit the $VIM/ftplugin/[syntaxfile].vim
i.e.: perl.vim
added at the end :
set makeprg=$HOME/bin/vimparse.pl\ -c\ %\ $*
set errorformat=%f:%l:%m
c.vim
set makeprg=g++\ %
well, and you get the pattern.
It works delightfully with the :Make tip vimtip #203
Ah! I mapped F-5 to :Make, and made it go back to the
main window:
map <F5> :Make<cr><C-w><Up>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<wrap visual selection with fold markers | How to put the indentation level on the status line >>

Additional Notes
brett williams at agilent dot com, May 20, 2003 12:13

http://www.vim.org/tips/tip.php?tip_id=476 (1 of 2) [18/02/2004 15:00:25]

Tip #476 - multime errorformat & makeprgs : vim online

I prefer to make a compiler plugin, then use a ftplugin


to set a default compiler, i.e.:
~/.vim/compiler/xmllint.vim:
if exists("current_compiler")
finish
endif
let current_compiler = "xmllint"
setlocal makeprg=xmllint\ --valid\ --noout\ %
setlocal errorformat=%f:%l:\ %m
~/.vim/ftplugin/xml.vim
compiler xmllint
This way you can actually set up as many compilers as
you want for the same filetype. I set a default in my
ftplugin, but then a quick ':compiler somecompiler'
will change to a different one as opposed to having to
set makeprg and errorformat (remembering those is nontrivial)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=476 (2 of 2) [18/02/2004 15:00:25]

SourceForge
Logo

Tip #477 - How to put the indentation level on the status line : vim online

not logged in (login)

Home
Search

Tip #477: How to put the indentation level on the status line
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating 14/12, Viewed by 1350

created: May 20, 2003 14:33


author: sputnik

complexity: basic
as of Vim: 5.7

related to vimtip #303


in .vimrc

Scripts
Tips
My Account

set statusline=<Whaterever your status


is>\t%{ShowTab()}\ %P

Site Help

fu ShowTab()
let TabLevel = (indent('.') / &ts )
if TabLevel == 0
let TabLevel='*'
endif
return TabLevel
endf
rate this tip

Life Changing

Helpful

Unfulfilling

<<multime errorformat & makeprgs | Copy the search results into clipboard >>

Additional Notes
Anonymous, May 20, 2003 16:50
fu ShowTab()
return (indent('.') / &ts )
endf
Anonymous, May 21, 2003 0:00
s/ts/sw/
;-)
Add Note

http://www.vim.org/tips/tip.php?tip_id=477 (1 of 2) [18/02/2004 15:00:27]

rate

Tip #477 - How to put the indentation level on the status line : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=477 (2 of 2) [18/02/2004 15:00:27]

SourceForge
Logo

Tip #478 - Copy the search results into clipboard : vim online

not logged in (login)

Home
Search

Tip #478: Copy the search results into clipboard


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/6, Viewed by 1153

created: May 22, 2003 7:18


author: JAS

complexity: basic
as of Vim: 6.0

" previous clear the clipboard with this command :normal


"*y0
" Usage: :g/<pattern>/call CopyPattern()
function CopyPattern()
let idx = 0
let xEnd = 0
while idx >= 0
let @* = @* . matchstr(getline("."), '' . histget("/", 1), idx) . "\n"
let xEnd = matchend(getline("."), '' . histget("/", -1),
idx)
let idx = match(getline("."), '' . histget("/", -1),
xEnd)
endwhile
unlet idx
unlet xEnd
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<How to put the indentation level on the status line | Replace with NO Typing >>

Additional Notes
bsamim@yahoo.com, June 13, 2003 7:55

http://www.vim.org/tips/tip.php?tip_id=478 (1 of 2) [18/02/2004 15:00:30]

Tip #478 - Copy the search results into clipboard : vim online

a few more details or an example would be helpful, do


you run this command in your vimrc file and what is it
doing exactly? I was looking to create a mapping to
easily copy and paste text from my windows session to
my vim using something like vmap <C-c> "*y but this did
not seem to work in non gui mode, and I was lookign for
some answers with that... this might be somethign
different but I still could not understand the context
of this example immediately from reading it. thanks,
ben
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=478 (2 of 2) [18/02/2004 15:00:30]

SourceForge
Logo

Tip #479 - Replace with NO Typing : vim online

not logged in (login)

Tip #479: Replace with NO Typing

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/13, Viewed by 2311

created: May 23, 2003 10:45


author: johnmaxa

complexity: intermediate
as of Vim: 5.7

Often I replace one word with another. This is much


faster than the substitute command and requires no
typing.
For example, to change badName(...) to goodName(...)
(with the mappings below):
1.

Put the cursor anywhere on goodName and type:

2.

Move the cursor to badName and type:

gy

gp

That's it!
If there are more than one badNames, type *N before
typing go, then n gp to change the next one.
I mapped go to put a space after the word, but someone
clever might be able to combine them.
Here is how I mapped the commands:
"replace word with register b WITH SPACE AFTER word
noremap go lb"bPldwi <Esc>hbye
"replace word with reg b WITHOUT SPACE after word
"(lb so no move to previous word, but gives error at end
of line)
noremap gp lb"bPldwhbyw
"copy this word to register b for replacing with go and
gp
noremap gy lb"bye
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Copy the search results into clipboard | editing files on an ftp server listening on a non-standard
port >>

http://www.vim.org/tips/tip.php?tip_id=479 (1 of 3) [18/02/2004 15:00:32]

Tip #479 - Replace with NO Typing : vim online

Additional Notes
jallen@cashsystemsinc.com, May 23, 2003 11:05
I have always wanted to be a clever guy, so I took a
shot at combining them right after I wrote that. Try
this
noremap gp heli x<Esc>b"bPldwxbyw
and you can us gp for both words with and without
spaces.
Anonymous, May 24, 2003 20:35
" COMMENT:
'gp' is already assigned by vim
nmap gw lb"wPlcw<Esc>bb
"
Word from register w replaces the word under
cursor. Use with 'gy'
"
After replace, reposition to previous word for
possibly another replace.
nmap gy lb"wye
"
Yank word into register w.
"
----------------------------------------------Thanks to vimmers.
Anonymous, May 25, 2003 4:13
I usually search for "badName", then do a "cw" (Change
word), type "goodName", and then use the "." (repeat
last action) to substitute further occurences..
If the cursor is not at the beginning of "badName", I
can always do "bcw" (back-a-word + change word), or
"viwc" (change visual-inner-word)
Seems good enough! :-)
yeti@physics.muni.cz, June 1, 2003 1:49

http://www.vim.org/tips/tip.php?tip_id=479 (2 of 3) [18/02/2004 15:00:32]

Tip #479 - Replace with NO Typing : vim online

I don't quite understand what this is good for unless


you are lucky and have goodName somewhere, where you
can jump to really fast. And even then, jumping is
context switching and thus slow (on the human's side).
When there's only one thing to change, I do `ctN' and
type `good' -- or do `cw', type `good' and Tab to
complete it, depending on the situation.
When there's a few of them, I use `.' to repeat it.
When there's many of them, I do
`%s/\<^R^W\>/goodName/gc' or whatever regexp and flags
are appropriate.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=479 (3 of 3) [18/02/2004 15:00:32]

SourceForge
Logo

Tip #480 - editing files on an ftp server listening on a non-standard port : vim online

not logged in (login)

Home
Search

Tip #480: editing files on an ftp server listening on a non-standard port


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 19/12, Viewed by 990

created: May 29, 2003 8:18


author: George Harrison

complexity: basic
as of Vim: 6.0

Vim will edit files on an FTP server with the command:


e ftp://ftp.server/path/to/file/filename
But if you are using a virtual FTP server as in Bricolage
to edit templates, the FTP server is listening on a nonstandard port (typically 2121, but it can be something
different).
In that case, the command would be
e ftp://ftp.server\#2121/path/to/file/filename.
Note the "\#". The standard syntax for specifying a port
number is to append #2121 to the server name, where "2121"
is the port to connect to. But Vim treats an unescaped
"#2121" as an alternate file reference and fails with the
message "No alternate file name to substitue for
'#'". Escaping the "#" causes Vim to treat is an another
character in the string, and the connection works.
help edit and then search for "count" to find the syntax
for editing alternate files
This works on Red Hat and on WindowsNT.

rate this tip

Life Changing

Helpful

Unfulfilling

<<Replace with NO Typing | abbreviations only on shortcut >>

Additional Notes
cec@NgrOyphSon.gPsfAc.nMasa.gov, May 29, 2003 13:02

http://www.vim.org/tips/tip.php?tip_id=480 (1 of 3) [18/02/2004 15:00:35]

rate

Tip #480 - editing files on an ftp server listening on a non-standard port : vim online

<netrw.vim> will accept a colon for ports with ftp, too:


ftp://[user@]machine[[:#]port]/path/to/file
jaldri1 at gl dot umbc dot edu, June 6, 2003 10:04
Mind blowing! But, don't to add username@; vim treats it
as part of the hostname (i.e. "Unknown host
username@host"). {Tested on Win2k}
cec@NgrOyphSon.gPsfAc.nMasa.gov, June 13, 2003 7:18
Hmm, you're right, somewhere along the way the "user@" got
disabled. I've uploaded v33 under
http://www.erols.com/astronaut/index.html#vimlinks_scripts
which fixes that problem.
dougvim at claar dot org, July 16, 2003 13:19
This script is great, but beware! It does not check to see
if it really wrote your file! If, for example, you are
using a source control system, and forget to check out the
file before modifying it, you will lose your work. (Gee, I
wonder how he knows that...) I sent a revised copy of the
script to the author that checks status for the ftp case
(since that's the only case I can use), but either he
didn't get it, he's busy, he didn't like my changes, or
he's working on making it work for other protocols...I
hesitate to submit it without his blessing; it's the first
vim script I've ever mucked with. It also checks to see if
the read worked. I've put diffs from v33 below. I hope
that works!
==Doug Claar
D:\Vim\vim62\plugin>diff netrw.v33 netrw.vim
391a392,395
>
" If non-blank, show error message
>
if getline(1) !~ "^$"
>
echoerr getline(1)
>
endif
433a438,442
>
>
" If non-blank, show error message
>
if getline(1) !~ "^$"
>
echoerr getline(1)
>
endif
625a635,636
> let l:mod=&mod
" Save the modification state of
file
>
723a735
>
let l:mod=0
" Assume it worked
741a754,759

http://www.vim.org/tips/tip.php?tip_id=480 (2 of 3) [18/02/2004 15:00:35]

Tip #480 - editing files on an ftp server listening on a non-standard port : vim online

>
if getline(1) =~ "^$"
>
let l:mod=0
" No message=>it worked
>
else
>
" Output the error message
>
echoerr getline(1)
>
endif
772a791,796
>
if getline(1) =~ "^$"
>
let l:mod=0
" No message=>it worked
>
else
>
" Output the error message
>
echoerr getline(1)
>
endif
784a809
>
let l:mod=0
" Assume it worked
818a844
>
let l:mod=0
" Assume it worked
829a856
>
let l:mod=0
" Assume it worked
842c869
< if a:firstline == 1 && a:lastline == line("$")
--> if a:firstline == 1 && a:lastline == line("$") && l:mod
== 0
843a871,872
> else
>
set mod
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=480 (3 of 3) [18/02/2004 15:00:35]

SourceForge
Logo

Tip #481 - abbreviations only on shortcut : vim online

not logged in (login)

Home
Search

Tip #481: abbreviations only on shortcut


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/11, Viewed by 735

created: June 3, 2003 15:44


author: maurice

complexity: basic
as of Vim: 6.0

Actually, this is just a more flexible completion.


I made the following (example) to have a unique
abbreviation:
iabbrev date^A

<c-r>=strftime("%F")<cr>

Note that ^A is Control-A (insert with <c-v><c-a>).


This is to avoid the completion if you really want to
write 'date'.
And now this mapping:
inoremap <c-b> <c-v><c-a><c-[>a
Now type date<c-b> in insert-mode and you will get the
date.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<editing files on an ftp server listening on a non-standard port | Use VIM as an organizer of Memos,
bookmarks, todo, etc. >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=481 [18/02/2004 15:00:37]

SourceForge
Logo

Tip #482 - Use VIM as an organizer of Memos, bookmarks, todo, etc. : vim online

not logged in (login)

Home
Search

Tip #482: Use VIM as an organizer of Memos, bookmarks, todo, etc.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 47/16, Viewed by 2641

created: June 5, 2003 18:55


author: hypertext organizer

complexity: intermediate
as of Vim: 5.7

No one has perfect memory. I know this when I saw clever person often key in notes in his
computer.
He uses a number of small files with ".txt" extension and "grep" through them. To me this is
not good
because you still need to give a different name to different things and as time goes by, you
will useup
common words and starts "name1", "name2", ... to enumerate.
Have you ever thought of having one single Memo at hand that can put things down as normal
editor, still very easy to search and navigate through? HTML would be perfect for hypertext
navigation, but it is not as perfect for writting notes. Who knows what <H3> means level 3
headings
when i just want to use to highlight my text, ... A lot inconvenience.
I use VIM! For many years it helps me remember almost everything and still enjoy it. Let me
share
the experience with you. Of course I expect you be a VIMMER as me first.
VIM as an organizing tool? The help system of VIM is so well organized that we can think
of reusing the same for our everyday purpose. For example, here is my own Memo (abridged):
<<cut here>>
*memo.txt*
My Memo
- extending my poor memories
|guide|
-----------------------------------------------------------------------------------------------------------*subjects*
*toc*
|cmd| command tips
|def|
definitions
|dev|
developments
|ed|
editors
|friends| friends
|lang| languages
|misc|
others
|private| personal info
|sys|
system
-----------------------------------------------------------------------------------------------------------Commands
*cmd*

http://www.vim.org/tips/tip.php?tip_id=482 (1 of 8) [18/02/2004 15:00:41]

Tip #482 - Use VIM as an organizer of Memos, bookmarks, todo, etc. : vim online

*General
http://www.cslab.vt.edu/manuals
......
|doskey|
DOS key utility
<F8>: expand history
|man|
Unix manual
man foo
nroff -man foo.1 | less
nroff -man foo.1 | a2ps -m
|unix|
http://gd.tuwien.ac.at/linuxcommand.org/
|winhelp|
.....
-----------------------------------------------------------------------------------------------------------Development
*develop*
*dev*
...
-----------------------------------------------------------------------------------------------------------vim:tw=78:fo=tcq2:isk=!-~,^*,^\|,^\":ts=8:ft=help:norl:
<<cut here>>
Some explainations:
1) The last line instructs VIM with a number of editing settings. The most
important one here is "ft=help", which says file-type is "help"! So the VIM
will highlight thing for us.
2) You can use *foo* to indicate an anchor to the "help" system of VIM.
If you press Ctrl + ] on a word "foo", the cursor will jump to the first *foo*.
You can also see |foo| as a way to highlight it as implicit keywords.
3) This is not magic. The mechanism behind is the tag system. VIM needs
to have the following tag file to go to where you want it to go:
===================================
%userprofile%
memo.txt
/*%userprofile%*
.htaccess
meo.txt
/*.htaccess*
access memo.txt
/*access*
access.conf memo.txt
/*access.conf*
addressbook memo.txt
/*addressbook*
anchor_keyword memo.txt
/*anchor_keyword*
apache memo.txt
/*apache*
as index.txt
/*as*
at index.txt
/*at*
awk index.txt
/*awk*
===================================
Each line defines a tag, the first element is the keyword,
the second is the file where the tag belongs (yes, you can use
multiple files as long as you know what they are), and the last
http://www.vim.org/tips/tip.php?tip_id=482 (2 of 8) [18/02/2004 15:00:41]

Tip #482 - Use VIM as an organizer of Memos, bookmarks, todo, etc. : vim online

element is the command which as VIM to perform at the keyword (you


can as well do something wield here, but that's your own business).
4) But that's tedious! How to write these tags? God save you and thanks
VIM, you can find this utility to do it:
cc doctags.c -o doctags
doctags memo.txt | sort -f | awk -f cases.awk >tags
uniq -d -2 tags
-----------------------------------------------------------------------------<<cut here>> doctags.c
/* vim:set ts=4 sw=4:
* this program makes a tags file for vim_ref.txt
*
* Usage: doctags vim_ref.txt vim_win.txt ... >tags
*
* A tag in this context is an identifier between stars, e.g. *c_files*
*/
#include
#include
#include
#include

<stdio.h>
<string.h>
<ctype.h>
<stdlib.h>

#define LINELEN 200


int
main(argc, argv)
int argc;
char **argv;
{
char line[LINELEN];
char *p1, *p2;
char *p;
FILE *fd;
if (argc <= 1)
{
fprintf(stderr, "Usage: doctags docfile ... >tags\n");
exit(1);
}
printf("help-tags\ttags\t1\n");
while (--argc > 0)
{
++argv;
fd = fopen(argv[0], "r");
if (fd == NULL)
http://www.vim.org/tips/tip.php?tip_id=482 (3 of 8) [18/02/2004 15:00:41]

Tip #482 - Use VIM as an organizer of Memos, bookmarks, todo, etc. : vim online

{
fprintf(stderr, "Unable to open %s for reading\n", argv[0]);
continue;
}
while (fgets(line, LINELEN, fd) != NULL)
{
p1 = strchr(line, '*'); /* find first '*' */
while (p1 != NULL)
{
p2 = strchr(p1 + 1, '*'); /* find second '*' */
if (p2 != NULL && p2 > p1 + 1) /* skip "*" and "**" */
{
for (p = p1 + 1; p < p2; ++p)
if (*p == ' ' || *p == '\t' || *p == '|')
break;
/*
* Only accept a *tag* when it consists of valid
* characters and is followed by a white character or
* end-of-line.
*/
if (p == p2 && (p1 == line || p1[-1] != '-') &&
(strchr(" \t\n\r", p[1]) != NULL || p[1] == '\0'))
{
*p2 = '\0';
++p1;
printf("%s\t%s\t/*", p1, argv[0]);
while (*p1)
{
/* insert backslash before '\' and '/' */
if (*p1 == '\' || *p1 == '/')
putchar('\');
putchar(*p1);
++p1;
}
printf("*\n");
p2 = strchr(p2 + 1, '*'); /* find next '*' */
}
}
p1 = p2;
}
}
fclose(fd);
}
return 0;
}
http://www.vim.org/tips/tip.php?tip_id=482 (4 of 8) [18/02/2004 15:00:41]

Tip #482 - Use VIM as an organizer of Memos, bookmarks, todo, etc. : vim online

<<cut here>> cases.awk


{
print tolower($1) "\t" $2 "\t" tolower($3);
}
<<cut here>>
That's it. Good luck VIMMER.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<abbreviations only on shortcut | Using GREP for a list occurrences and quickfix help command. >>

Additional Notes
maurice, June 6, 2003 4:10
See also :helptags
digitect (at) mindspring com, June 6, 2003 14:04
Make your own tags file within Vim with:
:execute "helptags " . expand("%:p:h")
from within the open file.
Sreny@SverGbc.Pbz (Rot13ed), June 7, 2003 9:29
There is one downside with :helptags. It opertes only on *.txt files.
Here is another method for generating a tags file for *word* style tags; written in python
and based off the ptags.py from the python22 distribution
Usage:
tags.py [file] [file,etc.]
i.e.
tags.py myfile.html myfile.c etc.etc
tags.py:
>>>
#! /usr/bin/env python
#{{{ File header information
"""
/*!
\file
tags.py
\brief
Create a tags file (of *WORDS*), usable with VIM61, possibly earlier.
http://www.vim.org/tips/tip.php?tip_id=482 (5 of 8) [18/02/2004 15:00:41]

Tip #482 - Use VIM as an organizer of Memos, bookmarks, todo, etc. : vim online

\note

based on ptags.py from the python22


modifed by Feral to find only *word*
tailored for VIM6.1
\author
Original author unknown, based on
This file modified and maintained by
\version
1.02
\note
$Id$

distribution
style tags (for my documtation) output
ptags.py from the python22 distribution.
Feral <Sreny@SverGbc.Pbz> (Rot13ed)

Changelog:
1.01: [Feral:240/02@08:36] now warns on a duplicate entry, slow and crude method
(checks each addition to tags)
1.00: [yesterday]
Initial version, based on ptags.py from the python22 distrobution.
*/
"""
#}}}
import sys, re, os
tags = []

# Modified global variable!

def main():
args = sys.argv[1:]
print args
for file in args:
treat_file(file)

# keep in mind that the tags are sorted, this line !should! end up at the top...
tags.append("!_TAG_FILE_SORTED\t1\n")
print tags

if tags:
fp = open('tags', 'w')
tags.sort()
for s in tags:
fp.write(s)
print s

expr = '.*\*([a-zA-Z0-9_]+)\*.*'
matcher = re.compile(expr)
def treat_file(file):
print "treating file", file
dacount = 0
try:
fp = open(file, 'r')
http://www.vim.org/tips/tip.php?tip_id=482 (6 of 8) [18/02/2004 15:00:41]

Tip #482 - Use VIM as an organizer of Memos, bookmarks, todo, etc. : vim online

#
#
#
#

#
#
#

except:
sys.stderr.write('Cannot open %s\n' % file)
return
base = os.path.basename(file)
while 1:
line = fp.readline()
print "line:",line
if not line:
break
m = matcher.match(line)
if m:
content = m.group(1)
s = content + '\t' + base + '\t/*' + content + '*\n'
SO: [Feral:240/02@08:32] Hack in a warning if the item exists already.
Original:
tags.append(s)
THe hack:
for item in tags:
if item == s:
print "Duplicate entry:", content
tags.append(s)
EO: Feral [Feral:240/02@08:32]
print "content: ",content
print s
dacount = dacount + 1
print "\t", dacount, "matches."

if __name__ == '__main__':
main()
#EOF
<<<
Now hopefully this forum didn't mangle the indent! heh
Anonymous, June 8, 2003 16:39
Also see Thlnk.vim
http://www.vim.org/scripts/script.php?script_id=293
gpwen, June 11, 2003 18:40

http://www.vim.org/tips/tip.php?tip_id=482 (7 of 8) [18/02/2004 15:00:41]

Tip #482 - Use VIM as an organizer of Memos, bookmarks, todo, etc. : vim online

It will be better if combined with the folding. I put this on the modeline:
vim:fdm=marker:tw=78:isk=!-~,^*,^\|,^\":ts=8:ft=help:norl:
And add folding marks at the end of the section title, like this:
==================================================
Commands
{{{1
==================================================
"{{{1" is the default folding mark for level one. You can use multiple level
folders as well (:he Folding). Vim will folder the items automatically so you
can get all items at one glance. Really nice feature!
yijun@cs.toronto.edu, July 29, 2003 12:54
Thank you for helping me to simplify the task! I have modified my Memo with the following
template:
--------------------------------------TITLE
*tag* {{{
...content...
}}}
In summary, using "helptags ." can also warn me about any redundant tags.
Another idea, maybe useful, is it possible to use two connected words as the tags
automatically? Like
WikiWiki, PikiPiki and MoinMoin (don't need to enter | | and * *, just use a pattern like [AZ][a-z0-9]*[A-Z][a-z0-9]*.
Furthermore, is it possible to allow Unicode keywords to be automatically found?
davev at ziplip dot com, November 22, 2003 19:25
I just intregrated much of these functions (links, folding, etc.) into one script on
Vimscript#828.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=482 (8 of 8) [18/02/2004 15:00:41]

SourceForge
Logo

Tip #483 - Using GREP for a list occurrences and quickfix help command. : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #483: Using GREP for a list occurrences and quickfix help
command.
tip karma

Rating 1/1, Viewed by 1079

created: June 7, 2003 9:08


author: Feral (Rot13ed)

complexity: intermediate
as of Vim: 6.0

This is inspired by VIMTIP#391: Simple programmers TODO


list using grep and quickfix
taglist.vim is VIMSCRIPT#273
This is a little tip on shortcuts to make :grep just a
little bit more handy.
:GREP is simply a front end to :grep which uses the
current word under the cursor and the current file.
Use this for the times when you want a list
occurrences type search. (See also :h :ilist another
method)
" [Feral:158/03@07:02] Easily GREP current word in
current file.
command GREP
:execute 'grep '.expand('<cword>').'
'.expand('%') | :copen | :cc
Certainly nothing fancy here.
Now given that continually typing :cnext, :cprev and :cc
can get a bit cumbersome to type one might consider
mappings to speed up the process. When such mappings
call a user function we can get somewhat fancy as
illustrated below.
"[Feral:314/02@19:33] Assign some keys for handy
quickfix window commands.
if has("win32")
nnoremap <kPlus>
:call
<SID>Fancy_Quickfix_Cmd(':cnext')<cr>
nnoremap <kMinus>
:call
<SID>Fancy_Quickfix_Cmd(':cprev')<cr>
nnoremap <kMultiply>
:call
<SID>Fancy_Quickfix_Cmd(':cc')<cr>
nnoremap <c-kPlus>
:clast<CR>
nnoremap <c-kMinus>
:cfirst<CR>

http://www.vim.org/tips/tip.php?tip_id=483 (1 of 3) [18/02/2004 15:00:43]

Tip #483 - Using GREP for a list occurrences and quickfix help command. : vim online

nnoremap <m-kPlus>
nnoremap <m-kMinus>
endif

:cnewer<CR>
:colder<CR>

" [Feral:158/03@08:02] Very simple wrapper: do quickfix


cmd, center line and
"
if taglist.vim's window is open sync
function s:Fancy_Quickfix_Cmd(Cmd)
:try
execute a:Cmd
:catch /^Vim(\a\+):E553:/
:echohl ErrorMsg | echo v:exception | echohl
None
:endtry
:norm! zz
" If the taglist window is open then :TlistSync
"
Tag list window name: '__Tag_List__'
if bufwinnr('__Tag_List__') != -1
:TlistSync
endif
endfunction
NOTE that s:Fancy_Quickfix_Cmd() uses VIM 6.2s new
try/catch commands; For previous versions just omit the
try/catch endtry lines. The function works well enough
just is not as graceful when you reach the first or last
of the error list. I.e. PRE 6.2 version:
function s:Fancy_Quickfix_Cmd(Cmd)
execute a:Cmd
:norm! zz
" If the taglist window is open then :TlistSync
"
Tag list window name: '__Tag_List__'
if bufwinnr('__Tag_List__') != -1
:TlistSync
endif
endfunction
Just as an asside, if you did not want to use a user
command for something like this you can do something
like this:
nnoremap <kPlus>
:TlistSync<CR>
nnoremap <kMinus>
:TlistSync<CR>
nnoremap <kMultiply>

http://www.vim.org/tips/tip.php?tip_id=483 (2 of 3) [18/02/2004 15:00:43]

:cnext<CR> :norm! zz<cr>


:cprev<CR> :norm! zz<cr>
:cc<CR> :norm! zz<cr>

Tip #483 - Using GREP for a list occurrences and quickfix help command. : vim online

Of course if you do not have/want the syncing with


taglist.vim simplly remove :TlistSync.
Now, the advantage of having s:Fancy_Quickfix_Cmd() is
that we can conditionally do something based on the
command, or some other attribute. In this case we
function the same for all commands (and just blindly
execute them). We do check to see if the taglist window
is open and if so ask it to Sync, if it is not, we
don't. One other (minor, cosmetic) advantage to this is
we see the user command in the echo area and not the
last command executed (as with just the pure mapping
method directly above).
You may need to modify the :GREP command so that your
grep has the proper flags, etc. On win32 I have my
grepprg set to "set grepprg=C:\Dev\bin\grep.exe\ -niH",
fwiw.
Happy VIMing!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Use VIM as an organizer of Memos, bookmarks, todo, etc. | Console-like fonts for Windows GVim
>>

Additional Notes
Sreny@SverGbc.Pbz (Rot13ed), July 2, 2003 3:11
by the by, another way to list occurrences (at least
for the current file)
would be a :g//:p (see :h :g and :h :p) and have the
text you want to list as
your current search pattern.
Just as an aside, :cnext can be abbreviated to :cn and
:cprev can be
abbreviated to :cp, of course.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=483 (3 of 3) [18/02/2004 15:00:43]

SourceForge
Logo

Tip #484 - Console-like fonts for Windows GVim : vim online

not logged in (login)

Home
Search

Tip #484: Console-like fonts for Windows GVim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 11/9, Viewed by 1670

created: June 8, 2003 6:23


author: Matt Gregory

complexity: basic
as of Vim: 5.7

For some excellent "DOS"-like fonts in multiple sizes


(.fon format) check out http://www.uwesieber.de/dosfon_e.html. Very cool for GVim and console
windows!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

Site Help
<<Using GREP for a list occurrences and quickfix help command. | Open a new window and read in
the man page for the word under the cursor >>

Additional Notes
Anonymous, June 9, 2003 4:28
The link is
http://www.uwe-sieber.de/dosfon_e.html
Anonymous, June 11, 2003 1:28
I quite like
http://www.raize.com/DevTools/Tools/RzFont.htm
Anonymous, July 3, 2003 11:16
Also recommended, esp. for those who loved Monaco on
the Mac or 6x10/6x13 on X11: ProFont (available for
Windows and MacOS as TrueType). http://www.tobiasjung.de/seekingprofont/
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=484 [18/02/2004 15:00:46]

SourceForge
Logo

Tip #485 - Open a new window and read in the man page for the word under the cursor : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #485: Open a new window and read in the man page for the word
under the cursor
tip karma

Rating 15/8, Viewed by 864

created: June 13, 2003 22:25


author: munk

complexity: intermediate
as of Vim: 6.0

This short function opens a new window and reads in the


Unix man page for the word under the cursor. To use it
add the following to your ~/.vimrc file:
fun! ReadMan()
" Assign current word under cursor to a script
variable:
let s:man_word = expand('<cword>')
" Open a new window:
:exe ":wincmd n"
" Read in the manpage for man_word (col -b is for
formatting):
:exe ":r!man " . s:man_word . " | col -b"
" Goto first line...
:exe ":goto"
" and delete it:
:exe ":delete"
endfun
" Map the K key to the ReadMan function:
map K :call ReadMan()<CR>
cf:
:help windows
:help wincmd
etc
The col command may differ on your version of Unix, see
col(1) for details.
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=485 (1 of 3) [18/02/2004 15:00:48]

Helpful

Unfulfilling

rate

Tip #485 - Open a new window and read in the man page for the word under the cursor : vim online

<<Console-like fonts for Windows GVim | Search for word under cursor, but don't move. >>

Additional Notes
jez.hancock@munk.nu, June 14, 2003 4:34
Addendum:
"AFTER THIS:
" and delete it:
:exe ":delete"
" ADD THIS!:
" finally set file type to 'man':
:exe ":set filetype=man"
Which formats the page for man type (make sure to
'setenv TERM xterm' first or similar to see the pwetty
colours :)
goulding@princeton.edu, June 14, 2003 13:25
Note that if you're using a recent version of groff,
you may have to disable SGR (Ansi escape sequences) in
order to view man pages within vim. If you see a whole
lot of garbage on the screen, try adding to your .vimrc
the line:
let $GROFF_NO_SGR=1
bstrohhaecker@gmx.de, June 16, 2003 1:27
Also take a look at ":e $VIMRUNTIME/ftplugin/man.vim".
lpenz@terra.com.br, June 16, 2003 9:11
I'd rather put in my ~/.vimrc:
source $VIMRUNTIME/ftplugin/man.vim
nnoremap K :Man <C-R><C-W><CR>
jacob@fugal.net, June 18, 2003 8:44

http://www.vim.org/tips/tip.php?tip_id=485 (2 of 3) [18/02/2004 15:00:48]

Tip #485 - Open a new window and read in the man page for the word under the cursor : vim online

I had the problem that it would open the new window,


but loaded the man page itself into the old window.
Changing:
:exe ":wincmd n"
to
:exe ":new"
fixed it for me.
cec@NgrOyphSon.gPsfAc.nMasa.gov, June 24, 2003 14:26
Of course, you could use vimscript#489 to do this,
too. In addition, one gets :Man topic as well as the
use of K to look up the word under the cursor.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=485 (3 of 3) [18/02/2004 15:00:48]

SourceForge
Logo

Tip #486 - Search for word under cursor, but don't move. : vim online

not logged in (login)

Home
Search

Tip #486: Search for word under cursor, but don't move.
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/6, Viewed by 958

created: June 16, 2003 3:28


author: Jakob Frandsen

complexity: basic
as of Vim: 5.7

This is very, very simple:


:noremap <F1> #*
I find this helpful when editing multiple files and I
want to search for the word under the cursor in
*another* file.
I then type F1, C-^, n.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Open a new window and read in the man page for the word under the cursor | jump to a file to a
certain line number >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=486 [18/02/2004 15:00:51]

SourceForge
Logo

Tip #487 - jump to a file to a certain line number : vim online

not logged in (login)

Home
Search

Tip #487: jump to a file to a certain line number


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/3, Viewed by 971

created: June 16, 2003 10:09


author: yijun

complexity: basic
as of Vim: 5.7

Dear VIMMERS:
It is useful to have cn, cl for locating errors.
however, when the compilation was done off-line,
gcc ... >& compile.log
how to use the compile.log to locate the errors? for
example,
vim.h:1506
if i use "gf" when the cursor is over "vim.h", it just
jumps to the begining of the file.
here may be one solution by combining several steps:
nmap gt mAT f:l"aywbbgf:^Ra^M
"mA"
--- marks the current position to global register
A so that i can return the log file by 'A
"T "
--- goes to the begining of the tag, so in any
characters of "vim.h:1506", it first places the cursor
to "v".
"f:"
--- goes to the ":" separator
"l"
--- goes to the starting of line number
"ayw
--- try to use register a to remember the line
number
"bb"
--- move cursor back to the filename
"gf"
--- now jump to the file
":^Ra^M"
--- jump to the line number remembered in
register a
nmap gt ... place the above steps into key combinations
"g" "t" so next time use "gt" instead of "gf" on the
error tag!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Search for word under cursor, but don't move. | vimrc setting for wider vim diff window (gVim) >>

http://www.vim.org/tips/tip.php?tip_id=487 (1 of 2) [18/02/2004 15:00:54]

Tip #487 - jump to a file to a certain line number : vim online

Additional Notes
gpwen, June 16, 2003 21:48
You can try the :cfile command:
:help cfile
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=487 (2 of 2) [18/02/2004 15:00:54]

SourceForge
Logo

Tip #488 - vimrc setting for wider vim diff window (gVim) : vim online

not logged in (login)

Home
Search

Tip #488: vimrc setting for wider vim diff window (gVim)
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/7, Viewed by 1046

created: June 16, 2003 15:57


author: jaldri1 at gl dot umbc dot edu

complexity: basic
as of Vim: 6.0

The Vim diff feature (fantastic as it is) opens with the default
window width (gVim), and the two files each get a half width
buffer windows with a vertical split between them. When you
resize, only one buffer window changes. We might write function
to automatically center the split and possibly trigger it
automatically with an autocmd (advanced). However, we can still
have Vim open with a wider window when performing a diff. The
following code can be added to the vimrc file. Be sure to
adjust the numbers for the available screen real-estate and the
other settings to taste.
"===============================================================
" Window settings
set lines=60
" Set window height
set columns=98
" Set window width 'co'
set guioptions+=b
" Add bottom scroll bar 'go'
" If comparing files side-by-side, then ...
if &diff
" double the width up to a reasonable maximum
let &columns = ((&columns*2 > 172)? 172: &columns*2)
endif
"===============================================================
Remember, the default for the columns setting is either 80 or
the terminal width. I wouldn't expect consistant results for
non-gVim usage. By the way, I still need to add a test to
detect vim vs. gVim in my own vimrc (perhaps greping $VIM for
gvim) so that I can adjust colors and other settings
accordingly. Note that the expression in the let statement can
be replaced with a constant. But, that expression may prove
usefull if the columns setting is to vary (e.g. a filetype
plugin). For a general function (intermediate), someone would
want to come up with some global names like MaxScreenColumns or
MaxBufferColumns.
rate this tip

Life Changing

Helpful

Unfulfilling

<<jump to a file to a certain line number | Section jump in Latex >>

http://www.vim.org/tips/tip.php?tip_id=488 (1 of 2) [18/02/2004 15:00:57]

rate

Tip #488 - vimrc setting for wider vim diff window (gVim) : vim online

Additional Notes
niklas, June 18, 2003 3:32
To check if the GUI is enabled, just test with:
if has("gui_running") ... endif
Another solution is to put GUI-specific code in your .gvimrc
instead, which can make stuff a lot cleaner.
jaldri1 at gl dot umbc dot edu, June 18, 2003 3:38
Thanks to everyone for the feedback on testing for a GUI
mode.
For code that should only be executed when running gVim, wrap
it in:
if has("gui")
" ...
endif
You can also check the availability of options with
exists("+guioptions"). Note that for exists(), '+' is
different then '&'.
Anonymous, July 17, 2003 20:03
If you want exactly 80 columns in each half:
if &diff
let &columns = 160 +

2*&foldcolumn + 1

endif
The last 1 is for the vertical separator.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=488 (2 of 2) [18/02/2004 15:00:57]

SourceForge
Logo

Tip #489 - Section jump in Latex : vim online

not logged in (login)

Home
Search

Tip #489: Section jump in Latex


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/6, Viewed by 589

created: June 19, 2003 12:51


author: Aditya Mahajan

complexity: basic
as of Vim: 6.0

This is a small mapping that can be used for jumping sections in a latex
file (just like ]m and [m for Java methods)
map <silent> ]s :/\\\(sub\)\{,2}section\s*{<CR> :noh<CR>
map <silent> [s :?\\\(sub\)\{,2}section\s*{<CR> :noh<CR>
I want to extend it to recognize something like 2]s to move two sections
forward. How to do it.
Aditya
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<vimrc setting for wider vim diff window (gVim) | Paste vim registers in search or colon command-line instead of using the system
clipboard >>

Additional Notes
juhas@seas.upenn.edu, June 19, 2003 14:17
Here is an excerpt from my tex ftplugin, where section jumping works
with
count. The search() function is used rather than // command to avoid
the
wrap-arounds and end-of-file messages. Also, if you want to keep the
original search pattern, just comment out the "let @/ = pat" line.
Hope this helps,
Pavol

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" section jumping
noremap <buffer> <silent> ]] :<c-u>call TexJump2Section( v:count1, ''
)<cr>
noremap <buffer> <silent> [[ :<c-u>call TexJump2Section( v:count1, 'b'
)<cr>
function! TexJump2Section( cnt, dir )
let i = 0
let pat =
'^\\\(part\|chapter\|\(sub\)*section\|paragraph\)\>\|\%$\|\%^'
let flags = 'W' . a:dir
while i < a:cnt && search( pat, flags ) > 0
let i = i+1
endwhile
let @/ = pat

http://www.vim.org/tips/tip.php?tip_id=489 (1 of 2) [18/02/2004 15:00:59]

Tip #489 - Section jump in Latex : vim online

endfunction
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=489 (2 of 2) [18/02/2004 15:00:59]

SourceForge
Logo

Tip #490 - Paste vim registers in search or colon command-line instead of using the system clipboard : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Tip #490: Paste vim registers in search or colon command-line


instead of using the system clipboard
tip karma

Rating 57/21, Viewed by 715

created: June 20, 2003 8:30


author: rainbrot

complexity: intermediate
as of Vim: 5.7

To paste something into a search or the colon commandline without using the system clipboard, press Ctrl-R"
(including the quote, which represents the unnamed
register), or replace the quote with another register.
For more information about registers, see ":help
resisters".

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Section jump in Latex | can anyone tell me how to get rid of the F1 mapping ? >>

Additional Notes
japaget@ix.netcom.com, June 20, 2003 22:59
The correct help command is ":help registers", not
":help resisters".
This correction aside, this is an excellent tip!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=490 [18/02/2004 15:01:02]

SourceForge
Logo

Tip #491 - can anyone tell me how to get rid of the F1 mapping ? : vim online

not logged in (login)

Home
Search

Tip #491: can anyone tell me how to get rid of the F1 mapping ?
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating -23/28, Viewed by 720

created: June 21, 2003 0:01


author: cnf

complexity: basic
as of Vim: 5.7

owkay
i have been googeling for 2 hours now

Scripts
Tips
My Account

and i cant find how to remove that really anoying <F1>


map

Site Help

i keep hitting it as i go for esc, and its really


starting to piss me off ^^;
can anyone tell me how to get rid of the F1 mapping ?
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Paste vim registers in search or colon command-line instead of using the system clipboard | jump to
file from :CVSDiff output >>

Additional Notes
cnf@antwerpen.be, June 21, 2003 0:05
owkay, seems it works, but not on all files ...
nnoremap <F1> za<esc>
works on a perl file
does NOT work on a tex file
anyone know why ?
insaneevilcoder@yahoo.com, June 21, 2003 5:51
nnoremap <F1> <ESC>
inoremap <F1> <ESC>
yacoob@chruptak.plukwa.net, June 22, 2003 3:49

http://www.vim.org/tips/tip.php?tip_id=491 (1 of 2) [18/02/2004 15:01:05]

Tip #491 - can anyone tell me how to get rid of the F1 mapping ? : vim online

I just would like to remind, that it is supposed to be


TIPS page, not QUESTION page. Questions should be
directed to mailing list.
david@rayninfo.co.uk, June 22, 2003 5:36
Also try comp.editors
http://groups.google.com/groups?hl=en&lr=&ie=UTF8&group=comp.editors
Anonymous, June 24, 2003 3:18
:nnoremap <F1> :echo "Doing nothing... ;-)))"<CR>
arupam at dacafe dot com, June 24, 2003 3:21
You can add the following line in your vimrc file:
:nnoremap <F1> :echo "Doing nothing... ;-)))"<CR>
or
:nnoremap <F1> <Nop>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=491 (2 of 2) [18/02/2004 15:01:05]

SourceForge
Logo

Tip #492 - jump to file from :CVSDiff output : vim online

not logged in (login)

Home
Search

Tip #492: jump to file from :CVSDiff output


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/1, Viewed by 398

created: June 24, 2003 2:07


author: daniel kullmann

complexity: basic
as of Vim: 5.7

I use :CVSDiff from cvscommand.vim quite often to get an


overview of the changes i made to a file.
I always want to jump from the diff to the corresponding
line in the original file.
So I wrote a small script that does that, and put it in
$VIM/after/syntax/diff.vim
Pressing <Return> will execute that script.
function! DiffJumpToFile()
let a=line(".")
current line number
let b=search("^\\(---\\|\\*\\*\\*\\) ", "b")
search for line like *** 478,489 ***
let c=getline(b)
this line as string
let d=strpart(c, 4, match(c, ",")-4)
the first line number (478) from that string

"
"
" get
" get

let f=search("^\\(---\\|\\*\\*\\*\\) .*\\t", "b") "


search for line like *** fileincvs.c ....
let g=getline(f)
"
get this line as string
let h=match (g, "\\t", 4)
"
look for end of filename (terminated by tab) in string
let i=strpart(g, 4, h-4)
"
get the filename
execute ":b " . i
change to that file
execute "normal " . (d+a-b-1) . "G"
go to right line number
endfunction

| "
| "

nmap <buffer> <Return> :call DiffJumpToFile()<CR>


I didn't put that script in the script section because
it doesn't have any error checking at all.

http://www.vim.org/tips/tip.php?tip_id=492 (1 of 2) [18/02/2004 15:01:08]

Tip #492 - jump to file from :CVSDiff output : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<can anyone tell me how to get rid of the F1 mapping ? | Open the directory for the current file in
Windows >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=492 (2 of 2) [18/02/2004 15:01:08]

SourceForge
Logo

Tip #493 - Open the directory for the current file in Windows : vim online

not logged in (login)

Home
Search

Tip #493: Open the directory for the current file in Windows
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 29/16, Viewed by 908

created: June 24, 2003 9:10


author: Adam Wolff

complexity: basic
as of Vim: 6.0

It's often handy to open the folder that corresponds to a


file I'm editing (as much as I hate to leave Vim!) I've
added this mapping:
map <C-e> :silent !explorer %:p:h:gs?\/?\\\\\\?<CR>
So that typing ctrl-e in any buffer opens the folder that
the file lives in in Windows.
See :help filename-modifiers for more.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<jump to file from :CVSDiff output | maximize or restore window >>

Additional Notes
rpilkey at magma.ca, June 24, 2003 9:42
Good tip, I changed it to this:
map <C-e>

:!start explorer %:p:h:gs?\/?\\\\\\?<CR>

This stops the console window from flashing up on the


screen. See :help !start
Rog
Anonymous, June 24, 2003 12:59

http://www.vim.org/tips/tip.php?tip_id=493 (1 of 3) [18/02/2004 15:01:11]

Tip #493 - Open the directory for the current file in Windows : vim online

Very good!
I call instead the windows explorer the explorer plugin
with:
map <C-e>

:Exp %:p:h:gs?\/?\\\\\\?<CR>

But this works only on Windows. Anybody knows how it should


looks for unix?

maxiangjiang@hotmail.com, June 24, 2003 15:10


Well, I found I can reuse iexplore.exe, as in the
following:
map <silent> <C-E> :sil!!start
C:/PROGRA~1/INTERN~1/iexplore -nohome -e <CR>=getcwd()<CR><CR>
If cygwin is installed, we can have a simple one:
map <silent> <C-E> :sil!r!cygstart -x .<CR>

randydefauw@yahoo.com, June 24, 2003 15:12


On Unix, try using a free program called Worker:
http://www.boomerangsworld.de/worker/woverview.php3?lang=en
It is an X-based file explorer, similar to Windows
explorer.
I had to modify the mapping to:
map <C-e> :silent !worker %:p:h<CR>
nlm@valtech.se, June 26, 2003 7:14
For quite a while now I've been doing it this way:
func! OpenCWD()
if has("gui_running")
if has("win32")
let s:stored_shellslash = &shellslash
set noshellslash
!start explorer.exe %:p:h
let &shellslash = s:stored_shellslash
elseif has("gui_kde")
!konqueror %:p:h &
elseif has("gui_gtk") " TODO: test!
!nautilus %:p:h &
elseif has("mac") && has("unix")
!open %:p:h
endif
http://www.vim.org/tips/tip.php?tip_id=493 (2 of 3) [18/02/2004 15:01:11]

Tip #493 - Open the directory for the current file in Windows : vim online

endif
endfunc
command! OpenCWD call OpenCWD() " or whatever you like
I'm not sure how flawless it is, but it has worked for me
on a couple of different platforms.
radbelt_res@yahoo.com, June 26, 2003 19:07
A solution that I like is to use the vi file manager
(http://vifm.sourceforge.net). You can use it with or
without being in vim (a vim plugin comes with the
distribution). Unfortunately, I have not been able to get
it to compile in cygwin on windows yet, and I am on a
windows machine right now, so I can't access it to give
more of the specifics. I think the plugin comes with a
command like :Vifm, but, that could be mapped.
sgovindachar at yahoo, June 27, 2003 8:38
Since I perfer to stay within Vim, I use the following:
:sf %:p:h
This splits the window and lists the contents of the
directory of the file. Putting the cursor on an item from
the list in that window and typing o opens up a new window
with the contents of the item.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=493 (3 of 3) [18/02/2004 15:01:11]

SourceForge
Logo

Tip #494 - maximize or restore window : vim online

not logged in (login)

Home
Search

Tip #494: maximize or restore window


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/1, Viewed by 637

created: June 26, 2003 8:01


author: Hosup Chung

complexity: basic
as of Vim: 6.0

I used to define 2 different mapping for maximize and


restore window. But I wanted a map that can toggle
between them. So, I came up with this function. This
function assumes you are using win32 version of gvim. If
you are using different version, then substitute :simlat
~[rx] by the key combination for your window manager.
Add following lines on your [._]g*vimrc
let w:windowmaximized = 0
function! MaxRestoreWindow()
if w:windowmaximized == 1
let w:windowmaximized = 0
" restore the window
:simalt ~r
else
let w:windowmaximized = 1
" maximize the window
:simalt ~x
endif
endfunction
map <F5> :call MaxRestoreWindow()<CR>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Open the directory for the current file in Windows | Backspace key using puTTY to RH9 box >>

Additional Notes
Anonymous, June 26, 2003 12:12

http://www.vim.org/tips/tip.php?tip_id=494 (1 of 2) [18/02/2004 15:01:14]

Tip #494 - maximize or restore window : vim online

hmm.. I thought window scope should be used in this


case, but it doesn't work when a window has multiple
screen. It seems working with global variable.
let g:WindowMaximized = 0
function! MaxRestoreWindow()
if g:WindowMaximized == 1
let g:WindowMaximized = 0
" restore the window
:simalt ~r
else
let g:WindowMaximized = 1
" maximize the window
:simalt ~x
endif
endfunction
gmannATfemtoDOTTmeddOTTuncDOTTedu, June 27, 2003 18:12
I don't know how to spell this correctly but:
TSONGMING

NI

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=494 (2 of 2) [18/02/2004 15:01:14]

SourceForge
Logo

Tip #495 - Backspace key using puTTY to RH9 box : vim online

not logged in (login)

Home
Search

Tip #495: Backspace key using puTTY to RH9 box


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 17/10, Viewed by 870

created: June 26, 2003 9:10


author: Tom Kompare

complexity: basic
as of Vim: 5.7

I connect to a RedHat9 server via


"puTTY" from a Windows computer.
the <Backspace> was working as it
was not. No matter what I did in
always acted like a <Delete> key.

the free software


On the shell (tcsh),
should, but in VIM it
the .vimrc file, it
Very annoying.

I've discovered that one must use the keyboard setting


of "linux" in the puTTY settings in order for the
<Backspace> key to work properly in VIM. The "linux"
keyboard is not the default. If one does not do this,
VIM always is sent the <Delete> key command when
pressing on the <Backspace>.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<maximize or restore window | This is the hyperlinked html format of the Vim Reference Manual. >>

Additional Notes
omanakuttan(at)tataelxsi(dot)co(dot)in(nospam), June 28, 2003 5:50
If you use dtelnet (dave's telnet) to RH 7.3, and 8.0,
same problem appears, not only in vim, but throughout
the session. Choosing term=linux from the menu helps
you there also.
lmasterson at hcocntf dot org, July 22, 2003 7:36
The key thing here is changing the string that PuTTy
sends to 'linux' from the default of 'xterm'
Doing this magically made everything work as it
should.
Add Note

http://www.vim.org/tips/tip.php?tip_id=495 (1 of 2) [18/02/2004 15:01:17]

Tip #495 - Backspace key using puTTY to RH9 box : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=495 (2 of 2) [18/02/2004 15:01:17]

SourceForge
Logo

Tip #496 - This is the hyperlinked html format of the Vim Reference Manual. : vim online

not logged in (login)

Home
Search

Tip #496: This is the hyperlinked html format of the Vim Reference Manual.
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -2/6, Viewed by 1020

created: June 26, 2003 14:05


author: Vangelis Eustratius

complexity: basic
as of Vim: 5.7

DESCRIPTION
---------This is the hyperlinked html format of the Vim Reference Manual.
Vim is much more than just a text editor; it's a cross-platform working
environment, but quite counter-intuitive to use. A Greek translation
of the Vim Tutor and Menu is on the drawing board at LynxX.org.
If you have a Web browser, the official hypertext version is
currently at <http://www.vim.org/>;. This unofficial version looks much
nicer than the official hypertext versions that exist at vim.org or can
readily be converted to html from the RefMan documents, but is an exact
copy of the source docs.
You can downloaded it from here:
-- FTP <ftp://lynxx.org/misc/download>;
-- HTTP <http://lynxx.org/misc/download>;

DISCLAIMER
---------This document is freely redistributable, but I take no liability
for the correctness and safety of any procedures or advice given here.
This document is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY, explicit or implied for the MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
BUGS
---If you find any mistakes or dead links, please contact:
<vangelise@lynxx.org>
Vangelis Eustratius
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Backspace key using puTTY to RH9 box | Replacing a string with default buffer contents >>

Additional Notes
mmm@hotmail.com, June 27, 2003 16:31

http://www.vim.org/tips/tip.php?tip_id=496 (1 of 2) [18/02/2004 15:01:19]

Tip #496 - This is the hyperlinked html format of the Vim Reference Manual. : vim online

http://lynxx.org/misc/download/ is empty
ftp://lynxx.org requires login/password
:-(
Marena
lynxx238@lynxx.org, June 28, 2003 9:00
Alternate download links for vimeditor_manual_html:
http://blake.prohosting.com/keytron/misc/download/vimeditor_manual_html.tgz
http://blake.prohosting.com/keytron/misc/download/vimeditor_manual_html.zip
Vangelis E.
david@rayninfo.co.uk, June 30, 2003 3:40
http://lynxx.org/misc/download/
now working but seems to have missing index.html or refmain.html
vangelise@lynxx.org, August 16, 2003 2:50
This document is readily available and can be viewed on-line at:
http://lynxx.org/ranerox/scripts/demos/vim_refman/index.html

Vangelis E.
vangelise@lynxx.org, August 27, 2003 12:54
Above-mentioned Greek language menus/messages/encodings for Vim61 are now
available at, and can be freely downloaded from:
http://lynxx.org/misc/download/vim-6.1-menu_el.zip
http://lynxx.org/misc/download/vim-6.1-menu_el.tgz
See VimTip #545 for more details.
That's all, folks
GREEKLISH
--------Ellynika menou gia to Vim61 einai diahesima kai mporoun na metafortwhoun
apo tyn parapanw istoselida.
Des VimTip

#545 gia perissoteres plyrofories.

Xairete
Vangelis Eustratius
vangelise@lynxx.org
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=496 (2 of 2) [18/02/2004 15:01:19]

SourceForge
Logo

Tip #497 - Replacing a string with default buffer contents : vim online

not logged in (login)

Home
Search

Tip #497: Replacing a string with default buffer contents


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/5, Viewed by 632

created: June 27, 2003 12:27


author: Adam Wolff

complexity: basic
as of Vim: 6.0

It's common to replace a given string in a file with


something that appears elsewhere in the file. Often I don't
think to put the replacement string in a named register, so
it's hard to delete the text I'm replacing without replacing
what's in the default (@") copy register -- :let is too
cumbersome for this. (BTW, is there a way to issue a command
like 'd' or 'c' *without* replacing what's in @"?)
Anyway, I've been using this map
vmap R
:<BACKSPACE><BACKSPACE><BACKSPACE><BACKSPACE><BACKSPACE>:let
@9=@"<CR>gvx"9P
which replaces what's highlighted in visual mode the
contents of ""
It's ugly though (all the backspaces are necessary to delete
the default :'<,'> that shows up when you start a command
in visual mode.)
I find this useful enough that I use it, but what I really
want is something similar where I could type say
R3w
(where R is remapped to my special command) that replaces
the next three words the contents of @"
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<This is the hyperlinked html format of the Vim Reference Manual. | Completation using the syntax file >>

Additional Notes
niklasl, June 28, 2003 3:44

http://www.vim.org/tips/tip.php?tip_id=497 (1 of 2) [18/02/2004 15:01:22]

Tip #497 - Replacing a string with default buffer contents : vim online

Afaik, Vim already works like your mapping. If you press


'p' when in visual mode, the selected text is replaced by
the contents of the default
register ('"<chosen_register>p' works as well). The
deleted text is yanked as if deleted normally.
Anonymous, June 28, 2003 9:42
"_d deletes to the black hole register and does not
change any normal register
See :help "_
Maurice, June 28, 2003 18:26
And you can replace these <backspace>'es with one <c-u>
Anonymous, June 30, 2003 11:54
black hole buffer. just what I was looking for. gracias
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=497 (2 of 2) [18/02/2004 15:01:22]

SourceForge
Logo

Tip #498 - Completation using the syntax file : vim online

not logged in (login)

Home
Search

Tip #498: Completation using the syntax file


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 53/16, Viewed by 1611

created: June 29, 2003 7:00


author: Daniel Molina

complexity: intermediate
as of Vim: 5.7

To use the vim completion you can use a dictionary.


:set complete=k
As a dictionary you can use a syntax file (which are in the
/syntax/ directory), so you can complete
the reserved words.
Inserting in your .vimrc a line like that
autocmd Syntax * exec('set dict=/usr/share/vim/syntax/'
.expand('<amatch>') .'.vim')
you can avoid to select the dictionary for each filetype.
(Don't forget to use your correct syntax directory for
this).
To get more info:
:help autocmd
:help complete
rate this tip

Life Changing

Helpful

Unfulfilling

<<Replacing a string with default buffer contents | View character class >>

Additional Notes
maxiangjiang@hotmail.com, June 29, 2003 12:19
It is cool.
How to make it work without

"syn on" first?

(most of time, I don't use syntax color)


Thanks
fischer@ms-net.de, June 30, 2003 4:58
http://www.vim.org/tips/tip.php?tip_id=498 (1 of 4) [18/02/2004 15:01:25]

rate

Tip #498 - Completation using the syntax file : vim online

this is not working


I also tried to use my old dictionary file in the 'set
dict=' statement
for testing, no success.
a 'set cpt=k/path/to/your/dictionary/file' is working
maxiangjiang@hotmail.com, June 30, 2003 10:12
It is working. The condition is that you have to do :syn on
first on your .vimrc
The map I hacked is
syn on
au Syntax * exe("set
dict+=".$VIMRUNTIME."/syntax/".expand('<amatch>').".vim")
(Anyone has a simpler solution? How to get rid of :syn on
from .vimrc?)
Thanks
dwsharp at hotmail dot com, June 30, 2003 12:25
> How to make it work without

"syn on" first?

If you are using filetype detection (i.e., you have


'filetype on' or 'filetype plugin on' in your .vimrc) you
can use 'au FileType' in place of 'au Syntax'. Also, I
would suggest using 'setlocal' in place of 'set' and using
+= in place of just =, so that the change is local to the
current buffer and file is added to the existing 'dict'
list instead of replacing it.
autocmd FileType * exec('setlocal
dict+=/usr/share/vim/syntax/' .expand('<amatch>') .'.vim')
maxiangjiang@hotmail.com, June 30, 2003 22:57
Thanks.
unix:

My final version in my .vimrc, for both PC and

autocmd FileType * exec('setlocal


dict+='.$VIMRUNTIME.'/syntax/'.expand('<amatch>').'.vim')

fischer@ms-net.de, July 1, 2003 0:43

http://www.vim.org/tips/tip.php?tip_id=498 (2 of 4) [18/02/2004 15:01:25]

Tip #498 - Completation using the syntax file : vim online

> autocmd FileType * exec('setlocal


dict+='.$VIMRUNTIME.'/syntax/'.expand('<amatch>').'.vim')
this works.
i replaced $VIMRUNTIME with its value for testing and it
stops working, so this was the problem.
zzapper@ntlworld.com, July 1, 2003 8:56
I've just started a general keyword completion file (not
filetype dependent)
set cpt=kc:/cygwin/home/davidr/vimfiles/dictionary.txt
set cpt+=kc:/cygwin/home/davidr/vimfiles/syntax/cf.vim
(couldn't get the auto stuff to work)
hgs@dmu.ac.uk, July 1, 2003 12:10
On the PC I had to change the reference to $VIMRUNTIME to
escape('$VIMRUNTIME',' ')
to get this to work. My vim path had spaces in, so I
needed to escape both space and backslash
characters.
utmaggot@hotmail.com, July 4, 2003 8:14
If the above example doesn't work for you (as it didn't for
me) try this
autocmd FileType * exe "setlocal
dict+=".escape($VIMRUNTIME.'\syntax' .&filetype.'.vim','
\$,')
Requires that you are using filetypes.
[With a little help from VIM guru Michael Geddes]
dmolina@programador.com, July 4, 2003 8:59
Hi, I was the person who put the tip originally.
I want to thanks to people who have made better the tip, I
didn't know enough to do better, but I am learning :-).
maxiangjiang@hotmail.com, July 4, 2003 20:20

http://www.vim.org/tips/tip.php?tip_id=498 (3 of 4) [18/02/2004 15:01:25]

Tip #498 - Completation using the syntax file : vim online

Thanks for inspiration of &filetype. Now, I have one-line


version
(72 chars) in my vimrc:
au FileType * exe('setl
dict+='.$VIMRUNTIME.'/syntax/'.&filetype.'.vim')
I tested it and it worked for me on W2K, cygwin console,
and Unix.
(I tested by checking :set dict?)
(Sorry for those who have space in $VIMRUNTIME.
I don't know it worked or not, because I tried to avoid
such situation)

utmaggot@hotmail.com, July 5, 2003 1:53


Pro Noblemo Dude!
I have just noticed however that these syntax files don't
have a lot of keywords in them.
Does anyone know where one can download 'pre-rolled'
dictionary files for C++, Javascript etc?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=498 (4 of 4) [18/02/2004 15:01:25]

SourceForge
Logo

Tip #499 - View character class : vim online

not logged in (login)

Home
Search

Tip #499: View character class


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -5/5, Viewed by 252

created: July 2, 2003 18:03


author: beo

complexity: intermediate
as of Vim: 6.0

This one shows the definition of a predefined character


class. ([:alpha:], [:graph:] etc.) The cursor is assumed
to point to the name of the character class one wants to
examine. Press "cc" ...
fun! s:Show()
norm! viwy
echo 'class [:' . @" . ':]' . "\n"
let pat = '[[:' . @" . ':]]'
let i = 0
while i < 256
let ch = nr2char(i)
if ch =~ pat | echon ch . '(' . i . ')' . "\t" |
endif
let i = i + 1
endwhile
endfun
nn cc :call <SID>Show()<Cr>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Completation using the syntax file | View character class >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=499 [18/02/2004 15:01:27]

SourceForge
Logo

Tip #500 - View character class : vim online

not logged in (login)

Home
Search

Tip #500: View character class


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -3/3, Viewed by 266

created: July 2, 2003 18:03


author: beo

complexity: intermediate
as of Vim: 6.0

This one shows the definition of a predefined character


class. ([:alpha:], [:graph:] etc.) The cursor is assumed
to point to the name of the character class one wants to
examine. Press "cc" ...
fun! s:Show()
norm! viwy
echo 'class [:' . @" . ':]' . "\n"
let pat = '[[:' . @" . ':]]'
let i = 0
while i < 256
let ch = nr2char(i)
if ch =~ pat | echon ch . '(' . i . ')' . "\t" |
endif
let i = i + 1
endwhile
endfun
nn cc :call <SID>Show()<Cr>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<View character class | View character class >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=500 [18/02/2004 15:01:30]

SourceForge
Logo

Tip #501 - View character class : vim online

not logged in (login)

Home
Search

Tip #501: View character class


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -4/4, Viewed by 330

created: July 2, 2003 18:05


author: beo

complexity: intermediate
as of Vim: 6.0

This one shows the definition of a predefined character


class. ([:alpha:], [:graph:] etc.) The cursor is assumed
to point to the name of the character class one wants to
examine. Press "cc" ...
fun! s:Show()
norm! viwy
echo 'class [:' . @" . ':]' . "\n"
let pat = '[[:' . @" . ':]]'
let i = 0
while i < 256
let ch = nr2char(i)
if ch =~ pat | echon ch . '(' . i . ')' . "\t" |
endif
let i = i + 1
endwhile
endfun
nn cc :call <SID>Show()<Cr>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<View character class | View character class >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=501 [18/02/2004 15:01:32]

SourceForge
Logo

Tip #502 - View character class : vim online

not logged in (login)

Home
Search

Tip #502: View character class


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -5/5, Viewed by 697

created: July 2, 2003 18:07


author: beo

complexity: intermediate
as of Vim: 6.0

This one shows the definition of a predefined character


class. ([:alpha:], [:graph:] etc.) The cursor is assumed
to point to the name of the character class one wants to
examine. Press "cc" ...
fun! s:Show()
norm! viwy
echo 'class [:' . @" . ':]' . "\n"
let pat = '[[:' . @" . ':]]'
let i = 0
while i < 256
let ch = nr2char(i)
if ch =~ pat | echon ch . '(' . i . ')' . "\t" |
endif
let i = i + 1
endwhile
endfun
nn cc :call <SID>Show()<Cr>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<View character class | PuTTY numeric keypad mappings >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=502 [18/02/2004 15:01:35]

SourceForge
Logo

Tip #503 - PuTTY numeric keypad mappings : vim online

not logged in (login)

Home
Search

Tip #503: PuTTY numeric keypad mappings


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 33/11, Viewed by 1227

created: July 3, 2003 6:03


author: Michael Metzger

complexity: advanced
as of Vim: 5.7

Purpose: Add support for {rhs} of keyboard numeric


keypad while in vim insert mode and using PuTTY as a SSH
terminal connection.
What to do: Add these mappings to your _vimrc or
_gvimrc. PuTTY's default terminal type is xterm. Check
your settings or just echo $TERM at the command prompt
on most unix systems to verify xterm type.
Code to add to _vimrc:
:imap ^[Oq 1
:imap ^[Or 2
:imap ^[Os 3
:imap ^[Ot 4
:imap ^[Ou 5
:imap ^[Ov 6
:imap ^[Ow 7
:imap ^[Ox 8
:imap ^[Oy 9
:imap ^[Op 0
:imap ^[On .
:imap ^[OQ /
:imap ^[OR *
:imap ^[Ol +
:imap ^[OS Any questions about vim and PuTTY please send to
mmetzger@mv-research.com.
Michael Metzger
rate this tip

Life Changing

<<View character class | syntax check >>

http://www.vim.org/tips/tip.php?tip_id=503 (1 of 3) [18/02/2004 15:01:37]

Helpful

Unfulfilling

rate

Tip #503 - PuTTY numeric keypad mappings : vim online

Additional Notes
mmetzger@mv-research.com, July 3, 2003 7:55
You might also want to include the mappings for the
normal mode as well. For example, going to a specific
line
#+shift G will not work unless you put these additional
mappings in _vimrc.
:map
:map
:map
:map
:map
:map
:map
:map
:map
:map

^[Oq
^[Or
^[Os
^[Ot
^[Ou
^[Ov
^[Ow
^[Ox
^[Oy
^[Op

1
2
3
4
5
6
7
8
9
0

chills@ne-worcs.ac.uk, July 8, 2003 7:14


Sadly, this does not work for me (vim v6.1.265,
TERM=xterm). Using these mappings, vim resorts to the
regular behaviour of inserting a new character on the
previous line.
me@rairai82.com, July 12, 2003 7:39
Additionally, those of you that are having issues with
the keypad can remap it using the following command
sequence in your vimrc file:
:imap
:imap
:imap
:imap

^[0A
^[0A
^[0A
^[0A

<Up>
<Down>
<Left>
<Right>

These settings also seemed to correct the quirk of the


mode text (or whatever it is properly called: --INSERT-) not showing up at the bottom of the screen when in
insert mode.
Anonymous, July 30, 2003 8:18
Maybe a simpler way to do this in PuTTY's settings: Set
"Disable application keypad mode" under Terminal->Features.
slist@lilotux.net, September 24, 2003 4:51

http://www.vim.org/tips/tip.php?tip_id=503 (2 of 3) [18/02/2004 15:01:37]

Tip #503 - PuTTY numeric keypad mappings : vim online

I'm using :
:imap <Esc>Oq
:imap <Esc>Or
:imap <Esc>Os
:imap <Esc>Ot
:imap <Esc>Ou
:imap <Esc>Ov
:imap <Esc>Ow
:imap <Esc>Ox
:imap <Esc>Oy
:imap <Esc>Op
:imap <Esc>On
:imap <Esc>OQ
:imap <Esc>OR
:imap <Esc>Ol
:imap <Esc>OS

1
2
3
4
5
6
7
8
9
0
.
/
*
+
-

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=503 (3 of 3) [18/02/2004 15:01:37]

SourceForge
Logo

Tip #504 - syntax check : vim online

not logged in (login)

Home
Search

Tip #504: syntax check


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -13/18, Viewed by 1267

created: July 4, 2003 11:26


author: cnf

complexity: basic
as of Vim: 6.0

i need a condition depending on what syntax a file is


like
if syntax = perl
do foo
endif
tried above code, didnt work
how do i check what syntax file is loaded ?
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<PuTTY numeric keypad mappings | email from vim! >>

Additional Notes
cnf@antwerpen.be, July 4, 2003 20:51
ok
solved it with
autocmd Syntax perl do foo
a spot of trouble arose with "let perl_fold=1" but i
got around that too
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=504 [18/02/2004 15:01:40]

SourceForge
Logo

Tip #505 - email from vim! : vim online

not logged in (login)

Home
Search

Tip #505: email from vim!


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -40/67, Viewed by 2005

created: July 7, 2003 14:42


author: Adam Wolff

complexity: basic
as of Vim: 5.7

I always found myself typing <ESC> into my email editor


and wishing that it had the nice features of Vim. There
are a bunch of hacky ways to email from Vim, but there's
actually an elegant solution: Pine!
The University of Washington has turned what was once a
lame console program into a sopohisticated IMAP email
client with server-based address books and configuration
files. Among its many options is one that allows you to
use your favorite text editor to edit emails. There's
even a very good port for Windows called PC-Pine. Here's
the link:
http://www.washington.edu/pine/

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<syntax check | Open windows Help files (chm) using <CWORD> or selected area >>

Additional Notes
Anonymous, July 7, 2003 20:09
Pine's email editor is almost exactly like pico as far
as I can tell... nothing like vim
Anonymous, July 7, 2003 21:51
well, the point is that PINE allows you to use VIM
instead of PICO as the default editor. so you get a
sophisticated mail client, and you get to use vim to do
your editing.
hermitte {at} free.Fr, July 8, 2003 7:59
Pine is not the only MUA that can be interfaced with
Vim. You can also check mutt and many more.

http://www.vim.org/tips/tip.php?tip_id=505 (1 of 3) [18/02/2004 15:01:47]

Tip #505 - email from vim! : vim online

gakk[at]sinnssyk[dot]com, July 8, 2003 16:50


...or you could just use mutt instead, which requires
you to choose your $EDITOR for mail-editing and such...
Anonymous, July 9, 2003 16:09
This tip is a joke.

I mean, come on.

tosco@carcass.dhs.org, July 9, 2003 22:17


This is ridiculous and a big, fat waste of my time.
Anonymous, July 13, 2003 12:20
what does this really have to do with vim?
really. duh.

nothing

malcolm81@katamail.com, September 2, 2003 10:27


It's quite a useful tip in my opinion. VIM users will
like to be able to use it for their email editing, and
it integrates very well in Pine. I use this combination
all the time. Last but not least, Pine is an excellent
program, and as far as I know there is no Windows port
of Mutt, which is what made me choose Pine.
Anonymous, September 17, 2003 23:46
mutt??
ewestra@wave.co.nz, September 18, 2003 17:08
I actually think this tip is a good one -- but only for
those with IMAP mailservers. Like the author of this
tip, I also wish I could use vim for writing E-Mails,
but alas my ISP only provides POP and not IMAP, which
means that pine is basically useless (yes, I know that
pine "sort of" supports POP, but its a kludge and
doesn't work well enough for heavy E-Mail users like
myself). Can anyone suggest an alternative E-Mail
client which properly supports POP mailboxes and allows
you to use VIM for writing E-Mails? Unfortunately, I'm
running on M$ windows (though work requirements, not
choice), so mutt isn't an option either. Any ideas?
jon@excession.com, September 22, 2003 7:05
Mahogany?
Anonymous, December 2, 2003 7:46

http://www.vim.org/tips/tip.php?tip_id=505 (2 of 3) [18/02/2004 15:01:47]

Tip #505 - email from vim! : vim online

> as far as I know there is no Windows port of Mutt


Mutt can be run through Cygwin. As of version
1.4.1-2, it also runs on Windows 9x without any
problems.
http://www.cygwin.com/packages/mutt/
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=505 (3 of 3) [18/02/2004 15:01:47]

SourceForge
Logo

Tip #506 - Open windows Help files (chm) using <CWORD> or selected area : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #506: Open windows Help files (chm) using <CWORD> or


selected area
tip karma

Rating 4/7, Viewed by 1054

created: July 8, 2003 12:48


author: David Fishburn

complexity: intermediate
as of Vim: 6.0

If you want to open a CHM (HTML Help) file and force the
index to go to a specific entry you can do the following
(on WinXP or any windows platform that has keyhh.exe).
" Create mappings to launch the ASA9 Help file with
context
nnoremap <C-F1> :silent!!cmd.exe /cstart keyhh.exe \#klink "<C-R><C-W>" "$ASANY9\docs\dbmaen9.chm"<CR><CR>
vnoremap <C-F1> :<C-U>let
old_reg=@"<cr>gvy:silent!!cmd.exe /cstart keyhh.exe \#klink "<C-R><C-R>""
"$ASANY9\docs\dbmaen9.chm"<CR><CR>:let
@"=old_reg<cr>:echo ""<CR>
Each of these are on one line.
nnoremap opens the help file using the <CWORD> that the
cursor is on.
vnoremap allows you to visually select a block of text
and open the search window with that text. It also
restores what ever was previously visually selected
after the launch.
If you use the map repeatedly, the same HTML Help window
will be used.

rate this tip

Life Changing

<<email from vim! | Quick window resizing >>

http://www.vim.org/tips/tip.php?tip_id=506 (1 of 2) [18/02/2004 15:01:50]

Helpful

Unfulfilling

rate

Tip #506 - Open windows Help files (chm) using <CWORD> or selected area : vim online

Additional Notes
David Fishburn, July 9, 2003 7:51
If you windows machine does not have keyhh.exe it can
be downloaded (free) from:
http://www.keyworks.net/keyhh.htm
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=506 (2 of 2) [18/02/2004 15:01:50]

SourceForge
Logo

Tip #507 - Quick window resizing : vim online

not logged in (login)

Home
Search

Tip #507: Quick window resizing


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/13, Viewed by 1428

created: July 10, 2003 18:57


author: Tom Slee

complexity: basic
as of Vim: 5.7

These key mappings (placed in your _vimrc) let you use


the F8 and F9 keys to make a window wider or
taller. The shift key reverses the effect, and the Ctrl
and Alt modifiers go to a choice of standard settings.
Mappings to change the font size.(which work slightly
differently) are also included. Obviously you can change
F8 and F9 to keys of your choice.
" Window size appearance
augroup guiappearance
au!
set guifont=Andale_Mono:h12
:map <F7> :set guifont=Andale_Mono:h12<CR>
:map <S-F7> :set guifont=Andale_Mono:h10<CR>
:map <C-F7> :set guifont=Andale_Mono:h14<CR>
:map <F9> :set lines+=5<CR>
:map <S-F9> :set lines-=5<CR>
:map <C-F9> :set lines=60<CR>
:map <M-F9> :set lines=30<CR>
:map <F8> :set columns+=10<CR>
:map <S-F8> :set columns-=10<CR>
:map <C-F8> :set columns=132<CR>
:map <M-F8> :set columns=80<CR>
augroup END
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Open windows Help files (chm) using <CWORD> or selected area | Problem with .vimrc >>

Additional Notes
uws@xs4all.invalid, July 14, 2003 1:41

http://www.vim.org/tips/tip.php?tip_id=507 (1 of 3) [18/02/2004 15:01:53]

Tip #507 - Quick window resizing : vim online

Window resizing can also be done at window-manager


level, so that it will work for all applications. In my
case .fluxbox/keys contains:
# window sizing
Mod4 m :MaximizeWindow
Mod1 Mod4 h :HorizontalDecrement
Mod1 Mod4 j :VerticalIncrement
Mod1 Mod4 k :VerticalDecrement
Mod1 Mod4 l :HorizontalIncrement
# window movement
Mod4 h :BigNudgeLeft
Mod4 j :BigNudgeDown
Mod4 k :BigNudgeUp
Mod4 l :BigNudgeRight
As you can see, I used the familiar vim movement keys ;)
I mapped mod4 to the windows-key on my keyboard. To
achieve this, you will need to put the following lines
in ~/.Xmodmap:
! alt keys (explicitly configured, without this section
meta doesn't work)
keycode 64 = Alt_L
add mod1 = Alt_L
keycode 113 = Alt_R
add mod1 = Alt_R
! ms flag keys
keycode 115 = Meta_L
keycode 116 = Meta_R
add mod4 = Meta_L
add mod4 = Meta_R
woodyjin@hotmail.com, July 16, 2003 15:52
There is an amazingly intutitive script replacement,
called "mouse".
Although I wouldn't use it for each cursor movement,
I would definitely use it in this particular case,
rather than keys bound by some scripts.
joachim.hof@gmx.de, July 17, 2003 9:42

http://www.vim.org/tips/tip.php?tip_id=507 (2 of 3) [18/02/2004 15:01:53]

Tip #507 - Quick window resizing : vim online

Addition:
I use <Ctrl> plus Cursor Keys to resize the current
window relative to the neighbour window of a splitted
screen.
' resize horzontal split window
nmap <C-Left> <C-W>-<C-W>nmap <C-Right> <C-W>+<C-W>+
' resize vertical split window
nmap <C-Up> <C-W>><C-W>>
nmap <C-Down> <C-W><<C-W><
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=507 (3 of 3) [18/02/2004 15:01:53]

SourceForge
Logo

Tip #508 - Problem with .vimrc : vim online

not logged in (login)

Home
Search

Tip #508: Problem with .vimrc


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -31/48, Viewed by 1562

created: July 12, 2003 4:49


author: pakeer

complexity: intermediate
as of Vim: 6.0

Hello,
I am new to vim/gvim. I have used some of the tips given in
this page but when i type gvim <filename> The following
warning is comming:
Error detected while processing /users/pakeer/.vimrc:
line
6:
E518: Unknown option: on
Warning: Cannot convert string "<Key>Escape,_Key_Cancel" to
type VirtualBinding
Warning: Cannot convert string "<Key>Home,_Key_Begin" to type
VirtualBinding
Warning: Cannot convert string "<Key>F1,_Key_Help" to type
VirtualBinding
Warning: Cannot convert string "Shift<Key>F10,_Key_Menu" to
type VirtualBinding
Warning: Cannot convert string "<Key>F10,Shift_Key_Menu" to
type VirtualBinding
Warning: Cannot convert string "<Key>KP_Enter,_Key_Execute"
to type VirtualBinding
Warning: Cannot convert string
"Alt<Key>Return,Alt_Key_KP_Enter" to type VirtualBinding
Can somebody help me out what i need to do in my .vimrc.
Regards,
Pakeer.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Quick window resizing | Commands that don't clobber the search register >>

Additional Notes
insaneevilcoder@yahoo.com, July 12, 2003 8:54
please post your problem on in the comp.editors news group

http://www.vim.org/tips/tip.php?tip_id=508 (1 of 2) [18/02/2004 15:01:58]

Tip #508 - Problem with .vimrc : vim online

chadb at beardendesigns .D.O.T. c o m, July 14, 2003 17:17


Please post your .vimrc
Anonymous, July 14, 2003 22:51
Start gvim and have a look at the information found by
:helpgrep Cannot convert
jdhedden@1979.usna.com, September 26, 2003 11:56
In vim type
:help message.txt
then search for 'Cannot convert'.
The explanation is that its an X11 config problems and says
to check out:
http://groups.yahoo.com/group/solarisonintel/message/12179
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=508 (2 of 2) [18/02/2004 15:01:58]

SourceForge
Logo

Tip #509 - Commands that don't clobber the search register : vim online

not logged in (login)

Home
Search

Tip #509: Commands that don't clobber the search register


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/5, Viewed by 578

created: July 15, 2003 8:32


author: Salman Halim

complexity: intermediate
as of Vim: 6.0

I frequently execute commands (mappings, usually) that


perform operations that change the value of the search
register for the sake of the mapping. They might do a
:s or some such that affects the search register. I
don't always want this side effect, so I use the
following command/function:
" Executes a command (across a given range) and
restores the search register
" when done.
function! SafeSearchCommand(line1, line2, theCommand)
let search = @/
execute a:line1 . "," . a:line2 . a:theCommand
let @/ = search
endfunction
com! -range -nargs=+ SS call SafeSearchCommand(<line1>,
<line2>, <q-args>)
" A nicer version of :s that doesn't clobber the search
register
com! -range -nargs=* S call SafeSearchCommand(<line1>,
<line2>, 's' . <q-args>)
Basically, :SS followed by any command will execute that
command (to simulate keystrokes, use :normal as the
command) and restore the search register when it's
done. :S is a replacement for :s which works EXACTLY
the same way (without or without range, flags etc. etc.)
but doesn't clobber the search register in the process.
rate this tip

Life Changing

Helpful

Unfulfilling

<<Problem with .vimrc | one way to set $VIMRUNTIME within vimrc >>

http://www.vim.org/tips/tip.php?tip_id=509 (1 of 2) [18/02/2004 15:02:01]

rate

Tip #509 - Commands that don't clobber the search register : vim online

Additional Notes
Anonymous, July 15, 2003 8:35
The "without or without range" should be "with or
without range". (Probably obvious, but I didn't want
anybody to think I was stuttering!)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=509 (2 of 2) [18/02/2004 15:02:01]

SourceForge
Logo

Tip #510 - one way to set $VIMRUNTIME within vimrc : vim online

not logged in (login)

Home
Search

Tip #510: one way to set $VIMRUNTIME within vimrc


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/7, Viewed by 558

created: July 18, 2003 9:41


author: maxiangjiang@hotmail.com

complexity: basic
as of Vim: 6.0

In general, $VIMRUNTIME cannot be set within vimrc.


(:set helpfile is not so useful)
Bram prefers to let vim figures it out.
This tip is for those who want to avoid setting
$VIMRUNTIME as an enviromental variable
(either rc file on UNIX or enviroment on Windows).
I found the following steps worked on my PC and unix:
1. find out your $VIM
(On Windows, it is the directory where gvim.exe
lives)
2. create a directory called doc under $VIM
(now, we have $VIM/doc)
3. copy help.txt from official $VIMRUNTIME/doc
(now, we have $VIM/doc/help.txt)
Now, we can set $VIMRUNTIME within vimrc, for example
let $VIMRUNTIME='C:/usr/share/vim/vim62'
I find it is useful on PC especially when I have cygwin
installed, thus a single copy of VIMRUNTIME can be
shared for
both vi (cygwin version) and gvim.exe (win32 version).

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Commands that don't clobber the search register | key mapping for goto the absolute line number
>>

http://www.vim.org/tips/tip.php?tip_id=510 (1 of 2) [18/02/2004 15:02:04]

Tip #510 - one way to set $VIMRUNTIME within vimrc : vim online

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=510 (2 of 2) [18/02/2004 15:02:04]

SourceForge
Logo

Tip #511 - key mapping for goto the absolute line number : vim online

not logged in (login)

Home
Search

Tip #511: key mapping for goto the absolute line number
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -12/14, Viewed by 659

created: July 20, 2003 20:30


author: Sean Chen

complexity: basic
as of Vim: 6.0

It's quite simple,


nmap <ENTER><ENTER> G
Now, you can keep the original [count]<ENTER> function
and have an easier way to goto the abolute line number.
Have a nice day!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<one way to set $VIMRUNTIME within vimrc | Automatic insertion of C/C++ header gates >>

Additional Notes
jigho@caramail.com, July 20, 2003 23:35
Why do you need to add a third entry for an action that
already have 2 ?
"<count>G"
or
":<count><enter>"
are enough, don't you think ?
animesh@motorola.com, July 21, 2003 7:31
"<count>G"
or
":<count><enter>"
out of these two options, second one needs 3... for the
first one, I prefer "<count><ENTER><ENTER>" over
"<count>G".
gsinclair@soyabean.com.au, July 22, 2003 8:30
57gg to go to hte 57th line does me fine, thank you
very much!
gsinclair@soyabean.com.au, July 22, 2003 8:30

http://www.vim.org/tips/tip.php?tip_id=511 (1 of 2) [18/02/2004 15:02:08]

Tip #511 - key mapping for goto the absolute line number : vim online

57gg to go to the 57th line does me fine, thank you


very much!
kallumama, July 30, 2003 10:01
I dont know if this is useful at all.
If you want to go up 17 lines, type
17<backspace>
in command mode
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=511 (2 of 2) [18/02/2004 15:02:08]

SourceForge
Logo

Tip #512 - Automatic insertion of C/C++ header gates : vim online

not logged in (login)

Home
Search

Tip #512: Automatic insertion of C/C++ header gates


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/7, Viewed by 390

created: July 21, 2003 14:10


author: Morten Fjord-Larsen

complexity: basic
as of Vim: 5.7

C/C++ header files should be guarded against multiple


inclusions using preprocessor directives, e.g.:
#ifndef FOO_H
#define FOO_H
/* Declarations. */
#endif
Placing the following snippet in your .vimrc file makes
vim insert these preprocessor gates automatically:
function! s:insert_gates()
let gatename = substitute(toupper(expand("%:t")), "\\.",
"_", "g")
execute "normal i#ifndef " . gatename
execute "normal o#define " . gatename . "
"
execute "normal Go#endif /* " . gatename . " */"
normal kk
endfunction
autocmd

BufNewFile *.{h,hpp} call <SID>insert_gates()

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<key mapping for goto the absolute line number | Automatic insertion of C/C++ header gates >>

Additional Notes
anonymous, August 8, 2003 10:54
These commands could be shortened a bit with use
of :put ='text'

http://www.vim.org/tips/tip.php?tip_id=512 (1 of 2) [18/02/2004 15:02:14]

Tip #512 - Automatic insertion of C/C++ header gates : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=512 (2 of 2) [18/02/2004 15:02:14]

SourceForge
Logo

Tip #513 - Automatic insertion of C/C++ header gates : vim online

not logged in (login)

Home
Search

Tip #513: Automatic insertion of C/C++ header gates


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/1, Viewed by 442

created: July 21, 2003 14:11


author: Morten Fjord-Larsen

complexity: basic
as of Vim: 5.7

C/C++ header files should be guarded against multiple


inclusions using preprocessor directives, e.g.:
#ifndef FOO_H
#define FOO_H
/* Declarations. */
#endif
Placing the following snippet in your .vimrc file, makes
vim insert these preprocessor gates automatically, when
a new header file is created:
function! s:insert_gates()
let gatename = substitute(toupper(expand("%:t")), "\\.",
"_", "g")
execute "normal i#ifndef " . gatename
execute "normal o#define " . gatename . "
"
execute "normal Go#endif /* " . gatename . " */"
normal kk
endfunction
autocmd

BufNewFile *.{h,hpp} call <SID>insert_gates()

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Automatic insertion of C/C++ header gates | Automatic insertion of C/C++ header gates >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=513 (1 of 2) [18/02/2004 15:02:20]

Tip #513 - Automatic insertion of C/C++ header gates : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=513 (2 of 2) [18/02/2004 15:02:20]

SourceForge
Logo

Tip #514 - Automatic insertion of C/C++ header gates : vim online

not logged in (login)

Home
Search

Tip #514: Automatic insertion of C/C++ header gates


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 36/18, Viewed by 1174

created: July 21, 2003 14:12


author: Morten Fjord-Larsen

complexity: basic
as of Vim: 5.7

C/C++ header files should be guarded against multiple


inclusions using preprocessor directives, e.g.:
#ifndef FOO_H
#define FOO_H
/* Declarations. */
#endif
Placing the following snippet in your .vimrc file, makes
vim insert these preprocessor gates automatically, when
a new header file is created:
function! s:insert_gates()
let gatename =
substitute(toupper(expand("%:t")), "\\.", "_", "g")
execute "normal i#ifndef " . gatename
execute "normal o#define " . gatename . "
"
execute "normal Go#endif /* " . gatename . " */"
normal kk
endfunction
autocmd

BufNewFile *.{h,hpp} call <SID>insert_gates()

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Automatic insertion of C/C++ header gates | see filenames of all scripts that vim loaded or tried to
load >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=514 (1 of 2) [18/02/2004 15:02:22]

Tip #514 - Automatic insertion of C/C++ header gates : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=514 (2 of 2) [18/02/2004 15:02:22]

SourceForge
Logo

Tip #515 - see filenames of all scripts that vim loaded or tried to load : vim online

not logged in (login)

Home
Search

Tip #515: see filenames of all scripts that vim loaded or tried to load
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/10, Viewed by 549

created: July 23, 2003 0:19


author: Yakov Lerner

complexity: intermediate
as of Vim: 6.0

To see filenames of all scripts that vim loaded,


including
those loaded implicitly at startup:
:scriptnames
This does not show names of 'would-be scripts' -- that
is,
scripts that vim tried to open, did not find and was
silent about it.
To see the 'would-be' scripts -- that is, scripts that
vim
tried to open, did not find and was silent about it -add
'-V' option when starting vim:
vim -V
Also:
vim --version
rc-files

# shows system-dependent location of


# but does not show location of

system/personal
# plugins
:help startup
rate this tip

Life Changing

Helpful

Unfulfilling

<<Automatic insertion of C/C++ header gates | find two words in either order >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=515 (1 of 2) [18/02/2004 15:02:25]

rate

Tip #515 - see filenames of all scripts that vim loaded or tried to load : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=515 (2 of 2) [18/02/2004 15:02:25]

SourceForge
Logo

Tip #516 - find two words in either order : vim online

not logged in (login)

Home
Search

Tip #516: find two words in either order


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 43/16, Viewed by 928

created: July 23, 2003 7:56


author: Yakov Lerner

complexity: intermediate
as of Vim: 6.0

The shortest regular expression to find two words


in either order (on the same line):
.*alice\&.*bob
(Thanks to Piet Delport and Matthew Winn)
Other solutions:

Site Help

\(alice.*bob\)\|\(bob.*alice\)

-- "old-style" regexp

^\(.*Alice\)\@=\(.*Bob\)\@=
Keywords: find, match, search, words in either order,
regular expression
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<see filenames of all scripts that vim loaded or tried to load | Rejustification of *roff style markup. >>

Additional Notes
zzapper@ntlworld.com, July 23, 2003 10:35
Cool!
Just added to my Best of Vim Tips vimtip #305
zzapper@ntlworld.com, July 23, 2003 17:15
:h \& is the relevant help section
Anonymous, July 25, 2003 7:39
one thing to note is that the \& variant is much slower
than the more verbose \| variant.
not that it matters most of the time :-)

http://www.vim.org/tips/tip.php?tip_id=516 (1 of 3) [18/02/2004 15:02:28]

Tip #516 - find two words in either order : vim online

pjd@303.za.net (Piet Delport), August 13, 2003 14:45


Regarding Anonymous's comment above:
isn't necessarily slower
than the \| variant.

the \& variant

I took an arbitrary large file i had lying around (a


20MB list of email
headers, clocking in at some 450k lines) and ran some
benchmarks[1] over it,
with these results:
1870
1870
1870
1870
1870

matches
matches
matches
matches
matches

in
in
in
in
in

1s for ^\(.*www\&.*x\)
1s for ^\(.*www\)\@=\(.*x\)\@=
5s for .*www\&.*x
9s for www.*x\|x.*www
18s for \(www.*x\)\|\(x.*www\)

So, the the \| variant the slowest of them all, by at


least an order of
magnitude.
Some particular notes:
- Omitting the parens in \(www.*x\)\|\(x.*www\) roughly
doubles its speed, by
avoiding the overhead of filling in back-references
internally.
- While being the shortest pattern, .*www\&.*x is not
the fastest. It can be
sped up to the same level as ^\(.*www\)\@=\(.*x\)\@=
(the fastest pattern)
with only a slight increase in complexity (anchoring
it to the start of the
line), though.
- Finding out which of ^\(.*www\&.*x\) and
^\(.*www\)\@=\(.*x\)\@= is actually
faster is left as an exercise for the reader.
the former's brevity
and simplicity in either case, though.

I like

[1] Here's a listing of the benchmark function i used:


:function Test(re)
: let c=0
: let t=localtime()
: exec 'g/'.a:re.'/let c=c+1'
: return c.' matches in '.(localtime()-t).'s for
http://www.vim.org/tips/tip.php?tip_id=516 (2 of 3) [18/02/2004 15:02:28]

Tip #516 - find two words in either order : vim online

'.a:re
:endfunction
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=516 (3 of 3) [18/02/2004 15:02:28]

SourceForge
Logo

Tip #517 - Rejustification of *roff style markup. : vim online

not logged in (login)

Home
Search

Tip #517: Rejustification of *roff style markup.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/2, Viewed by 343

created: July 23, 2003 18:28


author: Cameron Kerr

complexity: intermediate
as of Vim: 5.7

Normally, I bind F4 to gqap, which suffices nicely to


rejustify plain text, and most of my latex and HTML
stuff (with due care taken to have plenty of blank lines
for delimiting.
However, if you're dealing with *roff style markup, such
as man-pages or (in my case) documents using the -ms
groff macros, it won't work, as the tags
are on the line just above, such as the following
example.
<begin example>
.IP Boggart
Magical being that transforms into whatever the viewer
most fairs.
Proffessor Lupin used a boggart to
teach Harry how to repel Dementors, as
(at that time) Harry most faired Dementors.
<end example>
Ideally, I'd just position the cursor on the body of the
text (this a definition list entry, if anyone is
wondering), and just press F4. But that would also
rejustify the argument to the IP macro, which would be
bad.
So instead of using gqap, I use gq an a selected range
of lines. I search upwards something that might be a
macro, or a blank line, move down a
line into the body, start to select, search forward for
the next macro or
blank line, then gq to rejustify.
The regex I use to search for the extents is
\(^\.[A-Za-z]\{2\}\\|^$\)
Since the document I'm working with has an extension of

http://www.vim.org/tips/tip.php?tip_id=517 (1 of 2) [18/02/2004 15:02:31]

Tip #517 - Rejustification of *roff style markup. : vim online

.groff, I bind, on BufferEnter, the following macro.


au BufEnter *.groff nmap <F4> ?\(^\.[A-Zaz]\{2\}\\|^$\)<Enter>jV/\(^\.[A-Zaz]\{2\}\\|^$\)<Enter>kgq
And it works. I'm using vim 6.1.320, although I believe
it should work on most versions.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<find two words in either order | errorformat for icc7 >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=517 (2 of 2) [18/02/2004 15:02:31]

SourceForge
Logo

Tip #518 - errorformat for icc7 : vim online

not logged in (login)

Home
Search

Tip #518: errorformat for icc7


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/2, Viewed by 290

created: July 25, 2003 7:16


author: t

complexity: basic
as of Vim: 5.7

This is a errorformat for Intel icc7 compiler:


errorformat=%E%f(%l): %m,%-C,%-C%p,%Z
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Rejustification of *roff style markup. | Folding like in Visual Basic .NET >>

Additional Notes
Anonymous, August 29, 2003 18:41
Spaces should be prexeded with a \ so the exact string
is:
errorformat=%E%f(%l):\ %m,%-C,%-C%p,%Z
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=518 [18/02/2004 15:02:34]

SourceForge
Logo

Tip #519 - Folding like in Visual Basic .NET : vim online

not logged in (login)

Home
Search

Tip #519: Folding like in Visual Basic .NET


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/8, Viewed by 1334

created: July 29, 2003 6:11


author: Eric Boucher

complexity: basic
as of Vim: 6.0

If your are using Microsoft Visual Studio .NET for


editing Visual Basic .NET files, the Window Form
Designer Generated Code is folded by default. If you
want to have the same nice feature when editing the same
file in Vim, put this code in your _vimrc file so you
can switch between the folded and unfolded mode:
function! NetFold()
set foldmethod=syntax
syn region myFold start="#Region" end="#End Region"
transparent fold keepend extend
syn sync fromstart
set foldcolumn=2
endfunction
function! NetUnFold()
set foldmethod=manual
set foldcolumn=0
norm zE
endfunction
So when your are editing a *.vb file, you simply have to
call the function like this:
:call NetFold()
or
:call NetUnFold()
Also, if you want that little function to be called
automatically when you edit a *.vb file, put these two
lines in your _vimrc file:
autocmd BufNewFile,BufRead *.vb setfiletype vb
autocmd BufNewFile,BufRead *.vb call NetFold()
Hope this will help. If you have any other suggestion,
don't be shy to add them!

http://www.vim.org/tips/tip.php?tip_id=519 (1 of 2) [18/02/2004 15:02:37]

Tip #519 - Folding like in Visual Basic .NET : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<errorformat for icc7 | Searching for Identifiers >>

Additional Notes
bhilverdink@hotmail.com, July 31, 2003 5:41
:g/^#R/,/^#E/fo
eric_boucher60@yahoo.com, August 5, 2003 10:52
I made a big mistakes when entering this line:
syn region myFold start="#Region" end="#End Region"
transparent fold keepend extend
It is in fact:
syn region myFold start="#Region" end="#End Region"
fold
Please replace the old on with the new one for those
who copy/pasted this tips.
I'm very sorry for any inconvenience. The old one was
simply a test for myself.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=519 (2 of 2) [18/02/2004 15:02:37]

SourceForge
Logo

Tip #520 - Searching for Identifiers : vim online

not logged in (login)

Home
Search

Tip #520: Searching for Identifiers


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/6, Viewed by 677

created: July 30, 2003 10:12


author: MightyByte

complexity: intermediate
as of Vim: 5.7

The problem:
It's always annoying trying to do a search and replace
for identifiers in C when the identifier that you are
searching for is a substring of other identifiers or
keywords in the program. For instance, let's say you
want to search for every place you access the ubiquitous
loop variable 'i'. If you do a search, you'll hit all
the i's in the "if" and "while" keywords and any other
identifiers that contain the letter i. For awhile I
have been looking for some way to do this in vim. Other
IDE's that I have seen have a "whole word" option where
the text must be the whole word. Vim has the "]CTRL-I"
command, but that is useless for search and replace
because when you replace one instance, you won't have
the original identifier under your cursor any
more. Until recently, I didn't know how to do it in vim
without manually typing the whole regular expression for
C identifiers.
The solution:
Use the "\<" and "\>" in your search. Evidently, these
respresent the start and end of words. So, to search
for all occurrences of the variable 'i', you would use
the following command:
/\<i\>
If you want all identifiers that start with 'i', you use
"/\<i" and similarly, for all identifiers ending in 'i',
use "/i\>".
If anyone knows a better solution, I would love to know
about it.
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=520 (1 of 2) [18/02/2004 15:02:40]

Helpful

Unfulfilling

rate

Tip #520 - Searching for Identifiers : vim online

<<Folding like in Visual Basic .NET | Something in GVIM for fun >>

Additional Notes
Anonymous, July 30, 2003 10:43
You can also use the '*' key in command mode. Check tip
# 1 for more details.
'gd' will bring you to the first occurence of the word
under the cursor.
Sreny@SverGbc.Pbz (Rot13ed), July 30, 2003 12:30
No Evidently about it, see ":h \<" and ":h \>"
What I like to do is highlight the var I want to
replace as a search string
(say via '*' or the like) this allows me to visually
(and easily) see what I am
about to replace.
I then linewise visual (:h linewise-visual) the section
of code I wish to
change (say all of a for loop).
It is then a simple matter of ":s//new_value_here/g"
linnc@cs.arizona.edu, July 31, 2003 14:43
For those as lazy as myself:<br>
If you happen to already have at least one occurrence
of your variable onscreen, you can place your cursor
over it and use Shift+# and it will automatically do a
search for the word using the \<mystring\> notation.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=520 (2 of 2) [18/02/2004 15:02:40]

SourceForge
Logo

Tip #521 - Something in GVIM for fun : vim online

not logged in (login)

Home
Search

Tip #521: Something in GVIM for fun


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/11, Viewed by 1558

created: July 31, 2003 16:05


author: Nitya

complexity: basic
as of Vim: 5.7

Try these for fun


Open gvim with some text in it and try
set rl
to come back to where u were try set norl
In Gvim
type ggvGg? --- This encrypts the whole of text
Happy vimiiiing !!!!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Searching for Identifiers | Fix an autoindent error >>

Additional Notes
anonymous@slashdot.org, July 31, 2003 17:07
As a note, the encryption is ROT-13
qwert, August 3, 2003 11:56
for cript visual mode not necessary
ggg?G
jigho@caramail.com, August 4, 2003 0:57
":set rl" only works if you installed the "rightleft"
option... and I do not see why we should install it if
we don't need it ? gvim is huge enough without it...
anonymous, August 12, 2003 8:20
How do you un-do it?
Anonymous, August 20, 2003 10:34

http://www.vim.org/tips/tip.php?tip_id=521 (1 of 2) [18/02/2004 15:02:44]

Tip #521 - Something in GVIM for fun : vim online

repeat it to undo
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=521 (2 of 2) [18/02/2004 15:02:44]

SourceForge
Logo

Tip #522 - Fix an autoindent error : vim online

not logged in (login)

Home
Search

Tip #522: Fix an autoindent error


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/0, Viewed by 953

created: July 31, 2003 18:45


author: Breadman

complexity: basic
as of Vim: 5.7

When splitting a line in two, I sometimes insert a


return before a space. Unfortunately, this mangles the
autoindentation: the last tab turns into spaces. The
following map fixes that problem:
"Fixes a rare autoindent error
inoremap <CR> <C-R>=ReturnWrapper()<CR>
function ReturnWrapper()
if strpart(getline('.'), col('.') - 1) =~ '^\s*\S'
return "\<ESC>wi\<CR>"
else
return "\<CR>"
endif
endf
Thanks to vimtip #102 for the tip on using <c-r> with a
wrapper function.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Something in GVIM for fun | Folding functions with the prototype included >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=522 [18/02/2004 15:02:48]

SourceForge
Logo

Tip #523 - Folding functions with the prototype included : vim online

not logged in (login)

Home
Search

Tip #523: Folding functions with the prototype included


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/4, Viewed by 988

created: August 2, 2003 14:46


author: Matt Perry

complexity: intermediate
as of Vim: 6.0

I used to use folding to fold functions in C/C++ from the "{"


to the "}", but I wanted a way to fold the prototype as
well. Using foldexpr allows this.
" ----------- CUT
function FoldBrace()
if getline(v:lnum+1)[0] == '{'
return '>1'
endif
if getline(v:lnum)[0] == '}'
return '<1'
endif
return foldlevel(v:lnum-1)
endfunction
set foldexpr=FoldBrace()
set foldmethod=foldexpr
" ---------- END CUT
Note that this will only work if you put the braces on lines by
themselves in the very first column, ie:
void func()
{
....
}
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Fix an autoindent error | evaluate expression in any mode, including normal mode, using <CTRL-R>= >>

Additional Notes
hermitte {at} free {dot} fr, August 2, 2003 18:34

http://www.vim.org/tips/tip.php?tip_id=523 (1 of 3) [18/02/2004 15:02:50]

Tip #523 - Folding functions with the prototype included : vim online

Johannes Zellner started to define a fold(ing?) plugin for C


& C++.
I've tried to enhanced it a little, but unfortunately, it is
still imperfect.
You may found it at:
http://hermitte.free.fr/vim/ressources/vimfiles/fold/cfold.vim
May it inspires you.
--Luc Hermitte
Anonymous, August 2, 2003 22:40
That certainly is more featureful than my version. But I
prefer to use foldnestmax=1 - I find it annoying to have more
than 1 fold level.
I've modified my fold function to work if the { is on the
same line as the function, ie:
void bla() {
}
I'd like to be able to use v:foldstart in my fold function so
I can check that the } has the same indent as the line
containing the {. That way I could match braces that aren't
in the first column. But this is good enough for my
purposes.
" ----- CUT
function FoldBrace()
if getline(v:lnum+1)[0] == '{'
return 1
endif
if getline(v:lnum) =~ '{'
return 1
endif
if getline(v:lnum)[0] =~ '}'
return '<1'
endif
return -1
endfunction
astrobe@netcourrier.com, August 5, 2003 4:18
a minor mistake:
set foldmethod=expr
vasud@mailcity.com, August 27, 2003 12:40

http://www.vim.org/tips/tip.php?tip_id=523 (2 of 3) [18/02/2004 15:02:50]

Tip #523 - Folding functions with the prototype included : vim online

How can I have both these forms fold andstill see prototype
in a single line.
void func()
{
...
}
void func() {
...
}
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=523 (3 of 3) [18/02/2004 15:02:50]

SourceForge
Logo

Tip #524 - evaluate expression in any mode, including normal mode, using <CTRL-R>= : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #524: evaluate expression in any mode, including normal mode,


using <CTRL-R>=
tip karma

Rating 5/2, Viewed by 566

created: August 3, 2003 23:44


author: Yakov Lerner

complexity: basic
as of Vim: 6.0

The <CTRL-R>= things evaluates the expression. For


example:
<CTRL-R>=12+34<cr>
<CTRL-R>= works in insert mode and in command mode.I
felt
it more convenient if <CTRL-R>= did the same thing
in normal mode too.
I have this in my .vimrc:
map <CTRL-R>= :echo
Now <CTRL-R>=123*456<CR> evaluates expressions for me in
all 3 modes: normal mode, insert mode, and command mode.
In fact I found it much more convenient to do casual
calculations
using <CTRl-R>= in normal mode than in any other mode.
Be warned: when typing <CTRL-R>= in normal mode, don't
make
long pause before '='. <CTRL-R> alone means 'redo' in
normal mode.
Vim is very smart, and figures the difference between
single
<CTRL-R> (which is 'redo') and the mapped sequence <CTRLR>= (which is
remapped). The 'timeoutlen' option controls this
difference.
The default value of 'timeoutlen' option is very
convenient.

This is expansion of vimtip #73 "using vim as


calculator"

http://www.vim.org/tips/tip.php?tip_id=524 (1 of 2) [18/02/2004 15:02:53]

Tip #524 - evaluate expression in any mode, including normal mode, using <CTRL-R>= : vim online

References: :he c_CTRL-R


:he i_CTRL-R
:he 'timeoutlen'
:he 'ttimeoutlen'
Keywords: calculator, expression evaluation, normal mode
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Folding functions with the prototype included | JavaBeans helper function >>

Additional Notes
srinath AT fastmail DOT fm, August 4, 2003 1:28
To get the behavior like i_CTRL-r in normal mode, use
@=. For example, in normal mode, @='dd'<cr> will
delete the current line just as if you had pressed dd
in normal mode.
:help @
for more information. You can also do things like
:let @a = 'dd'
and then press @a in normal mode. This does the same
thing.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=524 (2 of 2) [18/02/2004 15:02:53]

SourceForge
Logo

Tip #525 - JavaBeans helper function : vim online

not logged in (login)

Home
Search

Tip #525: JavaBeans helper function


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/0, Viewed by 602

created: August 4, 2003 5:06


author: Lech Ambrzykowski

complexity: intermediate
as of Vim: 6.0

This one helps creating beans. Nothing serious actually, but


might come in handy. It's pretty fresh, cuz I just got
annoyed with Netbeans - I haven't tested it fully. Perhaps we
could create some bigger Java Struts thing, huh?
nnoremap <buffer> <silent>dc :call <SID>AddBean()<CR>
function! s:AddBean()
let line = line('.')
let name = inputdialog('Enter the name of the variable:
')
let type = inputdialog('Enter the type of the variable:
')
let upperName = substitute(name, '^\(\w\)\(.*\)$',
'\u\1\2', '')
call append(line, "\t}")
call append(line, "\t\tthis.".name." = ".name.";")
call append(line, "\tpublic void
set".upperName."(".type." ".name.") {")
call append(line, "")
call append(line, "\t}")
call append(line, "\t\treturn (this.".name.");")
call append(line, "\tpublic ".type."
get"."".upperName."() { ")
call append(line, "")
call append(line, "\tprivate ".type." ".name.";")
call append(line, "\t//".name)
return line
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<evaluate expression in any mode, including normal mode, using <CTRL-R>= | enhancing Benji Fisher's
word_complete.vim script >>

Additional Notes
demian0311@yahoo.com, August 28, 2003 11:41

http://www.vim.org/tips/tip.php?tip_id=525 (1 of 2) [18/02/2004 15:02:56]

Tip #525 - JavaBeans helper function : vim online

you might be interested in


http://www.ophinity.com/papers/wrangling/index.html#multiply
it's fairly generic but i use it to chug thru a list of
values and apply those to a code-template. it lends itself
to setters & getters.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=525 (2 of 2) [18/02/2004 15:02:56]

SourceForge
Logo

Tip #526 - enhancing Benji Fisher's word_complete.vim script : vim online

not logged in (login)

Home
Search

Tip #526: enhancing Benji Fisher's word_complete.vim script


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -1/1, Viewed by 620

created: August 9, 2003 0:29


author: Adrian von Bidder

complexity: intermediate
as of Vim: 5.7

I suggest you first look at the script itself:


http://www.vim.org/scripts/script.php?script_id=73
Since the script has some problems (at least for me)
when I paste text in X11 with the mouse, and since I
need to switch to paste more anyway, I now use this in
my .vimrc:
" the word_complete.vim plugin just *rocks*
autocmd VimEnter * call DoWordComplete()
fun! SetComplete()
call DoWordComplete()
set nopaste
nunmap <F12>
iunmap <F12>
nmap <F12> :call UnsetComplete()<CR>
imap <F12> <Esc>:call UnsetComplete()<CR>a
echo
endfun
fun! UnsetComplete()
call EndWordComplete()
set paste
nunmap <F12>
iunmap <F12>
nmap <F12> :call SetComplete()<CR>
imap <F12> <Esc>:call SetComplete()<CR>a
echo
endfun
nmap <F12> :call UnsetComplete()<CR>
imap <F12> <Esc>:call UnsetComplete()<CR>a
Issues:
(i) I'm sure this can be done better
(ii) in insert mode, F12 switches to paste mode, but not
back again. In normal mode, it works. I'm sure this is
going to be something really, really silly.

http://www.vim.org/tips/tip.php?tip_id=526 (1 of 2) [18/02/2004 15:02:59]

Tip #526 - enhancing Benji Fisher's word_complete.vim script : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<JavaBeans helper function | vim (console/xterm) colors in gvim >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=526 (2 of 2) [18/02/2004 15:02:59]

SourceForge
Logo

Tip #527 - vim (console/xterm) colors in gvim : vim online

not logged in (login)

Home
Search

Tip #527: vim (console/xterm) colors in gvim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 15/7, Viewed by 1434

created: August 9, 2003 11:08


author: Peter Backes

complexity: basic
as of Vim: 6.0

You might have noticed that gvim uses slightly different


colors compared to the console version. If you like the
console colors more than the gvim default colors (as I
do), you can add the following to your .vimrc:
set background=dark
hi SpecialKey
guifg=Blue
hi MoreMsg
guifg=Green
hi Visual
guifg=NONE guibg=NONE
hi Folded
ctermbg=4 guibg=Blue
hi FoldColumn
ctermbg=7
hi DiffAdd
guibg=Blue
hi DiffChange
guibg=Magenta
hi DiffDelete
guibg=Cyan
hi Normal
guifg=Gray guibg=Black
hi Cursor
guibg=White
hi lCursor
guibg=White
hi Comment
guifg=Cyan
hi Constant
guifg=Magenta
hi Special
guifg=Red
hi Identifier
guifg=Cyan
hi Statement
guifg=Yellow
hi PreProc
guifg=Blue
hi Type
guifg=Green
hi Underlined
guifg=Blue
hi Todo
guifg=Black
There's one little difference: Folded is changed to
something better for console *and* gui and FoldColumn is
left as is in gvim and changed for console vim to match
the gvim version.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<enhancing Benji Fisher's word_complete.vim script | Make search results appear in the middle of
the screen. >>

http://www.vim.org/tips/tip.php?tip_id=527 (1 of 2) [18/02/2004 15:03:02]

Tip #527 - vim (console/xterm) colors in gvim : vim online

Additional Notes
tom@canobe.com, August 11, 2003 1:32
For those of you who like the old school VGA console
feel, heres a truetype version of the VGA font used by
most graphics cards. Make sure you set it to be used at
size 17 cos thats the only font size it will work at.
http://canobe.sourceforge.net/VGA.ttf
jose_de_paula@ig.com.br, September 5, 2003 7:04
Man, this should be distributed with vim among the
other colorschemes. I think the only thing that is
missing are the colors of the ruler (when switching
colorschemes, the ruler's colors are not updated).
Perhaps
hi StatusLine guifg=black guibg=gray
should do the trick. Thanks!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=527 (2 of 2) [18/02/2004 15:03:02]

SourceForge
Logo

Tip #528 - Make search results appear in the middle of the screen. : vim online

not logged in (login)

Home
Search

Tip #528: Make search results appear in the middle of the screen.
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 45/18, Viewed by 1071

created: August 10, 2003 17:25


author: Yada

complexity: intermediate
as of Vim: 5.7

Some useful mapping to make search results appear in the


middle of the screen.
nmap
nmap
nmap
nmap
nmap
nmap

n nmzz.`z
N Nmzz.`z
* *mzz.`z
# #mzz.`z
g* g*mzz.`z
g# g#mzz.`z

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<vim (console/xterm) colors in gvim | Making <s-tab> (shift-tab) work >>

Additional Notes
p.w.debruin@its.tudelft.nl, August 11, 2003 0:24
Why set the marks? The following works without messing
up existing marks:
nmap
nmap
nmap
nmap
nmap
nmap

n nzz
N Nzz
* *zz
# #zz
g* g*zz
g# g#zz

Or am I missing a finer point?


ykhov@hotmail.com, August 11, 2003 7:52
Yes, your're right.

The mark is not needed.

I reserved my z mark for last search result.

http://www.vim.org/tips/tip.php?tip_id=528 (1 of 2) [18/02/2004 15:03:05]

Tip #528 - Make search results appear in the middle of the screen. : vim online

vim@torrin.net, August 11, 2003 8:18


You can always make the cursor stay at the center of
the screen.
See :help 'scrolloff
linus81@hanmail.net, August 12, 2003 7:58
Life changing tip!
But, Yada's mapping is better to me in that that
mapping doesn't chew VIM's message;
"search hit BOTTOM, continuing at TOP".
I don't know the reason why 'nmap n nzz' chews the
message. Am I missing some configurations?
I'm using VIM 6.2 under Win32.
harkavy at qualexphoto dot com, August 13, 2003 9:19
You know it qualifies as a "life changing tip" when you
look at it and think, "hmmm. may be useful." then
implement it and say (out loud, in the middle of the
cube farm) "holy crap! I didn't even know I was
annoyed by that!" One of those things I knew could be
done, and might have even figured out on my
own. Maybe. Eventually. Some day.
thanks!
brett_williams@agilent.com, August 14, 2003 6:36
linus81, I have the same problem on vim 6.2 linuxi686. So I've sacrificed my z mark to the god of Yada,
as this is an excellent tip.
phil at codesourcery com, September 7, 2003 13:41
Not sure what "chewing" a message refers to (I've never
read the tips archive before), but the "continuing at
top" message
still appears normally for me under 6.1.474, using
":nmap n nzz". So I'll try this without the marks for
now.
And yes, it's definitely life-changing.

:-)

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=528 (2 of 2) [18/02/2004 15:03:05]

SourceForge
Logo

Tip #529 - Making <s-tab> (shift-tab) work : vim online

not logged in (login)

Home
Search

Tip #529: Making <s-tab> (shift-tab) work


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 11/5, Viewed by 1083

created: August 12, 2003 2:36


author: Geoff Hubbard

complexity: intermediate
as of Vim: 5.7

Shift Tab <s-tab> is a useful key combination to be able


to use.
I wanted to use it for tab completion: vimtip #102
Many people also use it for unindenting: vimtip #456
But shift tab seemed not to work on my system (slackware
8.1)
but I managed to find a solution, and a workaround.

Site Help

Diagnosis:
Make sure you are getting something from the keypress.
Go into insert mode:
and press <control-v> then <tab>
You should get a tab.
and press <control-v> then <shift-tab>
You should get ^[[Z
If this happens, it is good, you can skip the next part
of the diagnosis.
Diagnosis Part 2:
If you get nothing when you do <control-v> then <shifttab> go to a command line prompt (#) and type:
# xmodmap -pke | grep 'Tab'
It should either show:
keycode 23 = Tab
or
keycode 23 = Tab ISO_Left_Tab
Now, which one is the 'right' one seems to depend on
what terminal program you are using its various
settings.
(I need to use the 'ISO_Left_Tab' one with 'xterm' but
the 'Tab' one with Eterm)
I suggest you try changing to the mapping to the other
one and test what you get from the keypresses again. If
http://www.vim.org/tips/tip.php?tip_id=529 (1 of 3) [18/02/2004 15:03:08]

Tip #529 - Making <s-tab> (shift-tab) work : vim online

it doesn't work, you can just change it back.


To change the mapping:
# xmodmap -e 'keycode 23 = Tab ISO_Left_Tab'
or
# xmodmap -e 'keycode 23 = Tab'
If changing the xmodmap setting worked, you'll probably
need to put it somewhere where it will load on X startup
or login.
(.xinitrc or .bashrc or somewhere else depending on your
system config.)
If it didn't work see the other things to try below.
Interpreting shift-tab correctly:
Once you have the shift-tab key combo generating the
correct string ^[[Z you just need to make sure that is
then interpreted by vim as <s-tab>
As of version 6.2 vim does this, so upgrading to 6.2
would be good.
If you cannot upgrade for whatever reason try this
workaround:
:map <esc>[Z <s-tab>
:ounmap <esc>[Z
This will map the key you get when you press shift tab
to <s-tab> which
you can then use in other maps/scripts
I suggest adding these lines (minus the leading : of
course) to your .vimrc
Other things to try:
If none of the above worked, here are some other things
to investigate.
Make sure your window manager is not eating the
keystrokes. - You don't have it mapped there to change
desktop, or switch between windows
or something do you?
Use 'xev' to check that shift-tab is registering as a
keypress and what it is returning.
Good Luck.

http://www.vim.org/tips/tip.php?tip_id=529 (2 of 3) [18/02/2004 15:03:08]

Tip #529 - Making <s-tab> (shift-tab) work : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Make search results appear in the middle of the screen. | How do I get the name of the current file
>>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=529 (3 of 3) [18/02/2004 15:03:08]

SourceForge
Logo

Tip #530 - How do I get the name of the current file : vim online

not logged in (login)

Tip #530: How do I get the name of the current file

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 15/19, Viewed by 1223

created: August 13, 2003 7:07


author: Geoff Hubbard

complexity: basic
as of Vim: 5.7

To get the name of the file you are currently editing


use:
@%
If you want to make sure of the path as well use:
expand("%:p")

Site Help

see also:
help @
help expand
vimtip #296 for why it might be a useful thing to do.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Making <s-tab> (shift-tab) work | 1-2-3, let's make gvim.exe for free >>

Additional Notes
Anonymous, August 13, 2003 13:34
to enter the name of the current file in insert or
command mode, use <C-R>%.
Anonymous, August 14, 2003 5:36
If you want to use it as part of a command line just
use %
eg: !echo %
see also:
:help cmdline-special
oxcrete@yahoo.com, August 14, 2003 19:40

http://www.vim.org/tips/tip.php?tip_id=530 (1 of 2) [18/02/2004 15:03:11]

Tip #530 - How do I get the name of the current file : vim online

ctrl-g is a less key intensive way to get this info.


Used to work on old vi too.
Anonymous, August 16, 2003 1:59
If you need to insert otherfile names (say the *.h name
in an #include), you can do C-X+C-F for filename
completion.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=530 (2 of 2) [18/02/2004 15:03:11]

SourceForge
Logo

Tip #531 - 1-2-3, let's make gvim.exe for free : vim online

not logged in (login)

Home
Search

Tip #531: 1-2-3, let's make gvim.exe for free


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 26/12, Viewed by 1291

created: August 16, 2003 22:45


author: maxiangjiang@hotmail.com

complexity: basic
as of Vim: 6.0

This tip is for those who is interested to make gvim.exe


on
Windows without using MSVC or BCC. The condition is that
cygwin
is installed. (Another tip for Windows users: cygwin
makes
Windows really useful!)
Following is three steps (under any shell and any
directory)
step 1:
cvs -z3 -d:pserver:anonymous@cvs.vim.sf.net:/cvsroot/vim
co vim
step 2:
cd vim/src
step 3:
make -f Make_cyg.mak IME=yes
I have tested under Windows 2000 and have used my own
gvim.exe
for months without any problem.
Special thanks to Dan Sharp to develop/debug
Make_cyg.mak, which
make it possible.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<How do I get the name of the current file | usefule keymaps -- for comment out,etc.. >>

Additional Notes
ptoennies@hotmail.com, September 4, 2003 14:59

http://www.vim.org/tips/tip.php?tip_id=531 (1 of 2) [18/02/2004 15:03:13]

Tip #531 - 1-2-3, let's make gvim.exe for free : vim online

Thanks for the useful tip. Does anyone know how to


compile regular vim.exe on Windows using the g++
compiler? I prefer the non-GUI vim to gvim.
Thank you,
Peter
maxiangjiang@hotmail.com, September 5, 2003 10:49
Dan has an end-to-end solution for almost all problems
for vim compiling on Windows:
http://mywebpage.netscape.com/sharppeople/vim/howto/VimCompile-Win32-HOWTO/index.html
Anonymous, September 11, 2003 21:12
Dan is good at compiling many programs under Cygwin, not
only the gvim, it is he who tells me how to compile
MudOS v22 on cygwin.
mohsin@synplicity.com, September 30, 2003 19:31
Use mwing32 -- gcc for windows. Builds native exe.
From

http://www.mingw.org/

MinGW: A collection of freely available and freely


distributable Windows specific header files and import
libraries combined with GNU toolsets that allow one to
produce native Windows programs that do not rely on any
3rd-party DLLs.
maxiangjiang@hotmail.com, October 1, 2003 11:54
Note that the resulting gvim.exe built from cygwin
package is "native".
It has no dependancy on cygwin.dll at all.
Anonymous, October 14, 2003 7:18
The gvim.exe produced does not use cygwin-style
paths. :( I've got a lot of cygwin mounts that I would
like to use.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=531 (2 of 2) [18/02/2004 15:03:13]

SourceForge
Logo

Tip #532 - usefule keymaps -- for comment out,etc.. : vim online

not logged in (login)

Home
Search

Tip #532: usefule keymaps -- for comment out,etc..


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 2/16, Viewed by 1075

created: August 18, 2003 4:21


author: rajesh

complexity: basic
as of Vim: 5.7

-->a key map for commenting out lines -- use f12 key
append this line into your .vimrc/.gvim rc file
map <F12> ^i#<Esc>j
-->key maps to avoid a long shift press
nmap :X
:x
nmap :W
:w
nmap :Q
:q

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<1-2-3, let's make gvim.exe for free | Page 1 of 123 in header of :hardcopy >>

Additional Notes
yeti@physics.muni.cz, August 18, 2003 12:40
Remapping :something in normal mode is quite silly.
command -nargs=0 -bang Q q<bang>
is probably a better method of dealing with the too
long shift problem.
ewan.chalmers@comnitel.com, August 19, 2003 8:06
Key maps for Java style comment/uncomment
"comment out with CTRL-/
map ^_ 0i//<esc>j
"uncomment with CTRL-\
map ^\ :s/\/\///<CR>j
shawvrana at acm dot org, August 19, 2003 9:22

http://www.vim.org/tips/tip.php?tip_id=532 (1 of 2) [18/02/2004 15:03:17]

Tip #532 - usefule keymaps -- for comment out,etc.. : vim online

Or if you like C-style comments:


" Comment current line with ctrl-k in command mode
map <c-k> mzI/* <esc>A */ <esc>`z
" uncomment line line with ctrl-l
map <c-l> <esc>:s/\(.*\)\(\/\*
\)\(.*\)\(\*\/\)/\1\3/<CR>
Luc Hermitte -- hermitte {at} free.fr, August 19, 2003 13:39
Have you considered the numerous plugins that are
dedicated to commenting and uncommenting texts whatever
the language is ?
I'm using EnhancedCommentify and it is working just
fine!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=532 (2 of 2) [18/02/2004 15:03:17]

SourceForge
Logo

Tip #533 - Page 1 of 123 in header of :hardcopy : vim online

not logged in (login)

Home
Search

Tip #533: Page 1 of 123 in header of :hardcopy


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 15/6, Viewed by 521

created: August 18, 2003 16:14


author: Mikolaj Machowski

complexity: intermediate
as of Vim: 6.0

To get this to work you have to know how many lines per
page :hardcopy
is normally making. Open empty document and in Normal
mode "100o". Then
make ":%s/^/\=line('.')". Now ":hardcopy > nu.ps". Open
nu.ps in
PostScript viewer. You will see how many lines per page
Vim is printing.
In my case this is 73.
Now set 'printheader' option:
:set printheader=%<%f%h%m%=Page\ %N\ of\
%{line('$')/73+1}
Explanations of % items in option are here
|'statusline'|.
line('$') - number of lines in buffer
73 - number of lines per page
+1 - Vim don't know floating point math and everything
rounds down.
rate this tip

Life Changing

Helpful

Unfulfilling

<<usefule keymaps -- for comment out,etc.. | for verilog users only >>

Additional Notes
Mikolaj, August 19, 2003 4:36

http://www.vim.org/tips/tip.php?tip_id=533 (1 of 2) [18/02/2004 15:03:20]

rate

Tip #533 - Page 1 of 123 in header of :hardcopy : vim online

"I forgot about case when total number of lines is


multiplication of
"lines per page. Here is an improved version. Number of
lines per page
"was put in variable - you have to change it only once
:)
function! PH_Multiple()
let lpp = "73"
" lpp - lines per page
let modulo = line('$') % lpp
if modulo != 0
return ( line('$') / lpp ) + 1
else
return line('$') / lpp
endif
endfunction
set printheader =%<%f%h%m%=Page\ %N\ of\
%{PH_Multiple()}
Mikolaj, August 20, 2003 8:20
Some nice additions from comp.editors:
Peppe Guldberg:
:set printheader=%<%f%h%m%=Page\ %N\ of\
%{line('$')/73+(line('$')%73!=0)}
NOTE: smart use of condition
Anthony:
:set printheader=%<%f%h%m%=Page\ %N\ of\ %{(line('$')1)/73+1}
IMO this is best of all: oneliner and number of lines
appears only once - easy to correct.
Thanks!
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=533 (2 of 2) [18/02/2004 15:03:20]

SourceForge
Logo

Tip #534 - for verilog users only : vim online

not logged in (login)

Home
Search

Tip #534: for verilog users only


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 20/5, Viewed by 447

created: August 19, 2003 6:50


author: rajesh

complexity: basic
as of Vim: 5.7

for all verilog users dealing with netlists,this an


easier way to find out in which module you are really
working in.add this map to your .vimrc/.gvimrc file.use
`(tick) key to find out in which module u are actually
residing in.
map ` ma?module<CR>Wyiw'a:echo "module -->" @0<CR>
note:
this map works only when u are whithin the
module.placing it on module/endmodule does not make any
sense.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Page 1 of 123 in header of :hardcopy | Working with only one term/console? >>

Additional Notes
inti.rajesh@analog.com, August 19, 2003 20:50
an improved version of this if you are using a
searching for a particular net/wire and then u want to
know in which module you are really in.add this to your
.vimrc/.gvimrc file
map ` ma?module<CR>Wyiw'a/<Up><Up><CR>:echo "module ->" @0<CR>
if your are not searching for any particular net the
above map will do.
inti.rajesh@analog.com, August 19, 2003 20:51

http://www.vim.org/tips/tip.php?tip_id=534 (1 of 2) [18/02/2004 15:03:23]

Tip #534 - for verilog users only : vim online

an improved version of this if you are using a


searching for a particular net/wire and then u want to
know in which module you are really in.add this to your
.vimrc/.gvimrc file
map ` ma?module<CR>Wyiw'a/<Up><Up><CR>:echo "module ->" @0<CR>
if your are not searching for any particular net the
above map will do.
Anonymous, August 21, 2003 18:46
haha

smart !

vjiron@yahoo.com, October 12, 2003 7:15


Dont know but its not working for me. vim seems to be
kind of hanging then i press C-C to break it.
mine is VIM version 6.0
BTW but if some signals are having <module> in the
signal names?
wont work i think!
any comments.
inti.rajesh@analog.com, October 20, 2003 10:25
this will not work if u have module ith names line
module_AND...
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=534 (2 of 2) [18/02/2004 15:03:23]

SourceForge
Logo

Tip #535 - Working with only one term/console? : vim online

not logged in (login)

Home
Search

Tip #535: Working with only one term/console?


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 28/17, Viewed by 969

created: August 19, 2003 9:24


author: Gnaphos

complexity: basic
as of Vim: 6.0

Sometimes you can only work with a single


terminal/console, or you hate having
too many windows open and need to switch between them,
or QuickFix does not
work on your favourite languages? This simple, yet
powerful key stroke (Ctrl-Z)
might be very useful to you.
For example, let's say you are composing an email using
vim on mutt, or you want
to compile your <insert your favourite language> file,
you can simply press Ctrl-Z,
gives you the prompt back, do multiple commands and
whatever you want, and
goes back to vim editing by typing "fg" again.
If you need to admin some machine that only have vi
instead of vim on some reason,
you can edit multiple files by suspend them, using
"jobs" to list them and "fg %n" (n
is the job number) to load them back.
So by using the simple Ctrl-Z, not only that you can
edit multiple files in the same vim,
you can edit multiple groups of files in different vim.
Although it is a shell feature, but it goes together
nicely with vim.
Just in case for people that do not know, if all you
want is to run a single external
command, use ":!cmd", or "!<motion><filter>" to filter
<motion> text throught the
command.
For example, if you have a line "1 + 1 * 2", position
cursor on it, and type "!}bc",
you got "3" for you answer back.

http://www.vim.org/tips/tip.php?tip_id=535 (1 of 2) [18/02/2004 15:03:25]

Tip #535 - Working with only one term/console? : vim online

Or another example, position your cursor at the first


line of your paragraph and
type "!}fmt", now the paragraph is nicely formatted.
With all these in hand, you don't need to waste key
strokes to switch between
different windows anymore, the only drawback is it only
works in *nix.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<for verilog users only | Automaticly quit Vim if quickfix window (buffer) is the last >>

Additional Notes
Anonymous, February 2, 2004 4:05
I like to use GNU screen in only one terminal/console.
Pressing C-a C-a can quickly switch between different
"windows" . And C-a C-c opens a new window.
http://www.gnu.org/software/screen/screen.html
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=535 (2 of 2) [18/02/2004 15:03:25]

SourceForge
Logo

Tip #536 - Automaticly quit Vim if quickfix window (buffer) is the last : vim online

not logged in (login)

Home
Search

Tip #536: Automaticly quit Vim if quickfix window (buffer) is the last
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/4, Viewed by 277

created: August 21, 2003 6:40


author: David Kalita

complexity: intermediate
as of Vim: 6.0

I was confused when I do some development job. Usually I


have open one window with source code and one with error
codes (command :copen). When I quit the source code
quickfix window stay open. I'm lazy man so I must close
this window with additional typing. I make simple
autocmd which this difficult work in my stead.
If you like it (or are lazy too) include this code in
your .vimrc and use your spared time somewhere else :-).
au BufEnter * call MyLastWindow()
function! MyLastWindow()
" if the window is quickfix go on
if &buftype=="quickfix"
" if this window is last on screen quit without
warning
if winbufnr(2) == -1
quit!
endif
endif
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Working with only one term/console? | mimicking the shift-arrows (mark block) in terminals that
don't understand shift-arrow (e.g. putty) >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=536 (1 of 2) [18/02/2004 15:03:28]

SourceForge
Logo

Tip #536 - Automaticly quit Vim if quickfix window (buffer) is the last : vim online

http://www.vim.org/tips/tip.php?tip_id=536 (2 of 2) [18/02/2004 15:03:28]

Tip #537 - mimicking the shift-arrows (mark block) in terminals that don't understand shift-arrow (e.g. putty) : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #537: mimicking the shift-arrows (mark block) in terminals that


don't understand shift-arrow (e.g. putty)
tip karma

Rating 3/3, Viewed by 365

created: August 21, 2003 22:40


author: urlwolf

complexity: intermediate
as of Vim: 6.0

I like the MS-windows default behavior (ctrl-c for copy,


ctrl-v for paste, etc) even when I'm running vimon a
unix terminal. However, using mswin doesn't give the
right "mark block" behavior in the terminal I use
(putty). This may hold true for other Xterm emulators:
the shift-arrows (mark block) don't work because shiftarrow sends exactly the same signal as just arrows. I
have some maps that fix this by assinging some imaps and
vmaps to the combination of ctrl-arrows (thanks to
Antoine J. Mechelynck)
" make arrow keys work in visual mode
vmap <ESC>OA k
vmap <ESC>OB j
vmap <ESC>OC l
vmap <ESC>OD h
" simulate shift-arrows (select block in windows) with
control-arrows
inoremap <ESC>[A <C-O>vk
vnoremap <ESC>[A k
inoremap <ESC>[B <C-O>vj
vnoremap <ESC>[B j
inoremap <ESC>[C <C-O>vl
vnoremap <ESC>[C l
inoremap <ESC>[D <C-O>vh
vnoremap <ESC>[D h
rate this tip

Life Changing

Helpful

Unfulfilling

<<Automaticly quit Vim if quickfix window (buffer) is the last | e-mail archive >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=537 (1 of 2) [18/02/2004 15:03:32]

rate

Tip #537 - mimicking the shift-arrows (mark block) in terminals that don't understand shift-arrow (e.g. putty) : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=537 (2 of 2) [18/02/2004 15:03:32]

SourceForge
Logo

Tip #538 - e-mail archive : vim online

not logged in (login)

Home
Search

Tip #538: e-mail archive


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 12/3, Viewed by 500

created: August 23, 2003 7:21


author: Mark Thomas

complexity: basic
as of Vim: 5.7

This is a small archive of all the email sent to the Vim


mailing list (vim_at_vim.org). This archive covers 2-1/2
years, they are gzipped text files that contain six
months each. http://www.theswamp.org/vim/

rate this tip

Life Changing

Helpful

Unfulfilling

rate

Site Help
<<mimicking the shift-arrows (mark block) in terminals that don't understand shift-arrow (e.g. putty) |
Quick access to vim tips and scripts with konqueror / kde >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=538 [18/02/2004 15:03:34]

SourceForge
Logo

Tip #539 - Quick access to vim tips and scripts with konqueror / kde : vim online

not logged in (login)

Home
Search

Tip #539: Quick access to vim tips and scripts with konqueror / kde
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/4, Viewed by 473

created: August 23, 2003 10:56


author: zoran

complexity: basic
as of Vim: 5.7

For those of you using KDE and Konqueror to browse the


vim.sf.net, you can add it to the so called "Web Shortcuts" in
konqueror:
1. In Konqueror choose "Settings/Configure Konqueror"
2. Goto "Web Shortcuts", choose "Add..."
3. Now configure the shortcut:
* Search Name Provider: "VIM Tips"
* Search URI:
"http://vim.sourceforge.net/tips/tip.php?tip_id=\{@}"
* URI shortcuts: "vt,vimt,vimtip"
4. Click OK and Apply the changes to Konqueror
You can now use: "vt:4" in Konqueror's location bar to jump
directly to Vim Tip #4.
Feel free to do the same for VIM scripts using
"http://vim.sourceforge.net/scripts/script.php?script_id=\{@}"
as the Search URI.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<e-mail archive | vim6.2 or vim6.1? >>

Additional Notes
Anonymous, August 23, 2003 18:41
With a uri of
"http://vim.sourceforge.net/scripts/script.php?script_id=\{@}"
and the same method you can also easily access a specific
script.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=539 [18/02/2004 15:03:37]

SourceForge
Logo

Tip #540 - vim6.2 or vim6.1? : vim online

not logged in (login)

Home
Search

Tip #540: vim6.2 or vim6.1?


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -63/63, Viewed by 1476

created: August 23, 2003 12:12


author: ashesh

complexity: basic
as of Vim: 6.0

I have installed Vim6.1 from RH distro and now have


downloaded vim6.2 and have installed. I didnot remove
vim6.1 before installing...
I want to add the color schemes as given in
\"http://www.vim.org/scripts/script.php?script_id=625\"
ButI am not able to find the /vim foolder... there is a
folder as follows: /usr/share/vim with color folder, but
that corresponds to vim61...
I didnt know where to post the problem, so am posting in
a tip...
Sorry for the inconvenience.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Quick access to vim tips and scripts with konqueror / kde | How to get help using VIM >>

Additional Notes
Anonymous, August 25, 2003 18:40
Exactly like you said, not the right place to ask
questions...
Also, you don't provide enough information about your
situation, in particular, did you install vim 6.2 as an
RPM or after compiling it yourself? If it is an rpm,
check the rpm doc, rpm can display you the locations it
will install files to, it you used ./configure && make
then check in /usr/local/...
Bye,
Squisher

http://www.vim.org/tips/tip.php?tip_id=540 (1 of 2) [18/02/2004 15:03:41]

Tip #540 - vim6.2 or vim6.1? : vim online

spam@affenmann.de, August 26, 2003 5:00


Try asking such questions at comp.editors ;-)
Anonymous, September 11, 2003 21:08
Sorry, my friend, ``I didnt know where to post the
problem'' should not be the reason to post on tips.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=540 (2 of 2) [18/02/2004 15:03:41]

SourceForge
Logo

Tip #583 - Vim as XML Editor : vim online

not logged in (login)

Home
Search

Tip #583: Vim as XML Editor


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 67/22, Viewed by 2405

created: October 10, 2003 4:14


author: Tobi

complexity: intermediate
as of Vim: 6.0

If Vim is your main text editor, and if you do a lot of XML editing,
then this mini howto might help you to make that even more fun:
Vim as XML Editor
http://www.pinkjuice.com/howto/vimxml/

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Quick way to write to your file. | Awesome text formatter >>

Additional Notes
tobiasreif pinkjuice com, October 13, 2003 3:41
I appreciate any feedback. Error reports are especially welcome.
email: tobiasreif pinkjuice com
Tobi
william at knowmad dot com, December 29, 2003 14:15
Tobias,
This is a most excellent tutorial! Many thanks for your work in
putting this documentation together. I hope that others find it as
useful.
Do you have any info about using Vim to edit DocBook files? It'd be
nice to have folding support. Is this possible?
Thanks,
William
tobiasreif pinkjuice com, December 31, 2003 8:54

http://www.vim.org/tips/tip.php?tip_id=583 (1 of 2) [18/02/2004 15:03:44]

Tip #583 - Vim as XML Editor : vim online

Hi William,
thank you very much for the kind words.
> Do you have any info about using Vim to edit DocBook files?
Various sections use DocBook as example language , see
http://www.pinkjuice.com/howto/vimxml/tasks.xml
and
http://www.pinkjuice.com/howto/vimxml/moretasks.xml
I recommend to set up OASIS catalogs, see
http://www.pinkjuice.com/howto/vimxml/setup.xml#catalogs
If you have more specific questions feel free to post them here or
to send them via email.
> It'd be nice to have folding support. Is this possible?
Yes, folding is discussed shortly in
http://www.pinkjuice.com/howto/vimxml/tasks.xml#creatingdocuments
See
http://www.pinkjuice.com/howto/vimxml/setup.xml#vimrc
under
map <Leader>x
for stuff to set:
:set filetype=xml<CR>
\:source $VIMRUNTIME/syntax/xml.vim<CR>
\:set foldmethod=syntax<CR>
[...]
Tobi
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=583 (2 of 2) [18/02/2004 15:03:44]

SourceForge
Logo

Tip #582 - Quick way to write to your file. : vim online

not logged in (login)

Home
Search

Tip #582: Quick way to write to your file.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -4/24, Viewed by 1351

created: October 9, 2003 17:07


author: somebody

complexity: basic
as of Vim: 5.7

Put this in your .vimrc


map , :w^M
When you need to save your file instead of typing :w and
hitting enter, just hit the comma (,) Note that with vim
you may need to type CTRL-Q first to get the verbose
CTRL-M character in your file. For those who have
earlier versions or non-PC compatible, CTRL-V before
CTRL-M will get that character in there. Has been lifechanging for me :-). I can't take the credit as I found
this one years back when scanning info about building
html pages. The author had a little script that checked
the update of the file and sent a message to the browser
to re-read the file when the file was written. He's the
one who suggested mapping an unmapped button to do this.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using vim to view source and edit textarea in mozilla/firebird | Vim as XML Editor >>

Additional Notes
Anonymous, October 10, 2003 13:27
I think this would break all those scripts that use a
comma as a leading character.
Anonymous, October 13, 2003 4:46
See ":help :update"
map , :update<cr>
misof, December 16, 2003 13:06

http://www.vim.org/tips/tip.php?tip_id=582 (1 of 2) [18/02/2004 15:03:47]

Tip #582 - Quick way to write to your file. : vim online

also useful is :set autowrite, usually I want to save


the file exactly before I try to compile / tex it,
autowrite does it for me...
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=582 (2 of 2) [18/02/2004 15:03:47]

SourceForge
Logo

Tip #581 - Using vim to view source and edit textarea in mozilla/firebird : vim online

not logged in (login)

Home
Search

Tip #581: Using vim to view source and edit textarea in mozilla/firebird
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 39/13, Viewed by 1504

created: October 8, 2003 21:56


author: maxiangjiang@hotmail.com

complexity: basic
as of Vim: 5.7

This is the feature I have dreamed for months, please refer


to
http://mozex.mozdev.org

rate this tip


Site Help

Life Changing

Helpful

Unfulfilling

rate

<<Switching back and forth between ViM and Visual Studio .NET | Quick way to write to your file. >>

Additional Notes
dicpan@hotmail.com, October 9, 2003 1:45
The current version 1.07 does not work quite as it sounds.
I opened the Mozilla mail and the vim is not launched when
composing a message.
When Viewing the page source or edit textarea, it reports an
error: temporary directory c:\windows\temp does not
exist.What the heck is this? it certainly does not exist on
any PCs which do not have windows98 installed, neither does
it exist on PCs which do not have the system installed on
drive c:
The 'standard' temp directory should be
%systemdrive%\winnt\temp. While user may specify their
preference of temp directory in environment variable %temp%.
What is more, I found problem uninstalling this plugin...
maxiangjiang@hotmail.com, October 9, 2003 10:18

http://www.vim.org/tips/tip.php?tip_id=581 (1 of 3) [18/02/2004 15:03:49]

Tip #581 - Using vim to view source and edit textarea in mozilla/firebird : vim online

It works great for me on my W2k box.


Assuming that
1. gvim.exe is located at C:\vim\gvim.exe
2. temperoray directory is C:\tmp
Following is the setting in my user.js:
////////////////////////////////////////////////////////////
user_pref("mozex.command.source",
"C:\\vim\\gvim.exe %t");
user_pref("mozex.command.textarea", "C:\\vim\\gvim.exe %t");
user_pref("mozex.general.tmpdir", "C:\\tmp");
////////////////////////////////////////////////////////////
Note that mozillaFB plugin uninstall is still buggy,
and that is why I only have one plugin installed.

dicpan@hotmail.com, October 9, 2003 20:38


So, is there any alternative way to safety remove the mozex
plugin?
maxiangjiang@hotmail.com, October 9, 2003 21:05
To remove firebird plugin, I guess the best way for now is
to wait for official release of Firebird 0.7 and install
from the beginning. You can also try grep "mozex" in your
profile directory and edit one by one.
I believe future Firebire will have a solid uninstallation
feature.
Also, I put a request on mozilla site for a builtin vim-viewsource support:
http://forums.mozillazine.org/viewtopic.php?t=28677
Please back me up if you want such a feature, to put
together the two best applications (vim and mozillaFB)
the world. Thanks.

in

maxiangjiang@hotmail.com, October 9, 2003 23:33


Just found that we can vote for this bug ("allow external
source viewer/editor"):
http://bugzilla.mozilla.org/show_bug.cgi?id=172817
If enough votes are gathered, then I guess we can use vim to
view source in mozillaFB!
dicpan@hotmail.com, October 10, 2003 6:05

http://www.vim.org/tips/tip.php?tip_id=581 (2 of 3) [18/02/2004 15:03:49]

Tip #581 - Using vim to view source and edit textarea in mozilla/firebird : vim online

The problem in MozillaFB is less serious than that in


Mozilla (brower), in mozilla, you wil be unable to edit the
textarea, nor view the source page, whether you want to use
vim or not.
sitar {at} procaut <dot> sk, October 21, 2003 7:20
I have installed Mozex into Mozilla
In browser window I can right-click and select Mozex->view
page source
I get a Vim window with a page source. MAGNIFICENT!
However I could not start Vim from inside Mozilla mail.
How do I do it?
I was hoping that vim fires up whenever I jump into the text
composing area
for mail. No luck here
No luck with Thunderbird either.
Stano
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=581 (3 of 3) [18/02/2004 15:03:49]

SourceForge
Logo

Tip #580 - Switching back and forth between ViM and Visual Studio .NET : vim online

not logged in (login)

Home
Search

Tip #580: Switching back and forth between ViM and Visual Studio .NET
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 26/8, Viewed by 1623

created: October 6, 2003 10:43


author: Francois Leblanc

complexity: intermediate
as of Vim: 6.0

This tip is for when you work on a devstudio project and need the
debugger heavily and/or can't stay in ViM all the time. But when it
comes time to make changes you want to do them in ViM and don't want to
relocate the file and line number.
After you have made the change and perhaps opened another file or
navigated your way to a new section of the code you want to switch back
to devstudio at the spot you were in ViM. It may be because you want to
set a breakpoint or any reason.
The easy part:
Launching ViM from DevStudio.NET is easy.
From the DevStudio menu item Tools|External Tools... add a new entry
where:
The "Command Line" field is set to the path of the ViM executable
The "Arguments" field contains: --servername gmain --remote-silent
+$(CurLine) +"normal zz" $(ItemPath)
The "Initial Directory" may optionally contain: $(ItemDir)
This will start a ViM session or connect to an already existing one (-remote-silent) named gmain (--servername gmain). This will use only one
instance of ViM for all devstudio editing. It will open the file
specified by $(ItemPath) and set the cursor pos to $(CurLine). It will
also execute the normal command zz to center the cursor.
You can then create a keyboard shorcut to map to this tool
(Tools|Options||Environment|Keyboard, select Tools.ExternalCommandX)
and you will be able to switch to ViM quickly.
The hard part:
Opening a file in an existing DevStudio.NET instance is a pain and
setting the cursor to a line number is even more so.
DevStudio cannot be controlled by the command line. To open a file in
an existing instance a DDE call must be initiated. Its an old and
obsolete technology called Dynamic Data Exchange used for interprocess
communication. When you click on a .cpp file in the Windows Explorer it
calls devenv.exe with the /DDE switch (its undocumented) and sends it
an Open DDE command. You can see it for yourself if you look at the
file type mapping of .cpp in the Windows Explorer (if you haven't
already changed them to open ViM :-)). The Explorer shell is DDE
enabled but I found no way to send DDE from the command line (I didn't
really look for it either ;-)). So I wrote a small C++ console app from
the code I got from an Experts Exchange question. I formatted the code,
renamed references from DevStudio to DevEnv and put it in a project.

http://www.vim.org/tips/tip.php?tip_id=580 (1 of 4) [18/02/2004 15:03:52]

Tip #580 - Switching back and forth between ViM and Visual Studio .NET : vim online

Setting the line number is a different problem. I wrote a Perl script


using the Win32::GuiTest module. This module allows interacting with
the Windows GUI and provides a very useful function called SendKeys.
The script finds the Visual C++ window (if you are using a different
language change the script) and sends it: a CTRL-G, the current line
number as specified on the command line and ENTER.
It is integrated in ViM by a function (in _vimrc) that gets the current
file name and line number and silently executes the script:
function! DevEnvDDE()
let cmd = '!devenvdden.pl %:p ' . line(".")
silent execute cmd
endfunction
All that is left is to map the function to a key.
You can get the source files for the Perl script and DDE project at
http://dunderxiii.tripod.com/vimtips/devenvdde.zip
The original DDE code was taken at http://www.expertsexchange.com/Programming/Programming_Platforms/Win_Prog/Q_20489782.html
Win32::GUITest is located at http://groups.yahoo.com/group/perlguitest/

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Cut&Paste without too much newlines, eg. into WORD | Using vim to view source and edit textarea in mozilla/firebird >>

Additional Notes
mosh@cs.albany.edu, October 6, 2003 18:46
I have the script send-to-msdev.sh, that uses Perl + Win32::Ole
to open files in VC. You can even set breakpoints from perl,
this script has pointers to MSDN documentation.
http://www.cs.albany.edu/~mosh/Perl/send-to-msdev.ksh
Caveats: All win32 perl to be buggy in some respect,
but active perl55 is the only one that can talk to vc.
Very few commands in msdev can be automated, some dont
even have a name, you just have to click to get to them!
- Mohsin
"Her bed is India; there she lies, a pearl" - Troillus and Cressida
1.1, WS.
# Guts of the OLE messages that work (part of sh script)
d:/perl/perl_55x/bin/perl.exe -e '
push(@INC,"d:/perl/perl_55x/lib/site");
require Win32::OLE;
$app = Win32::OLE->GetActiveObject("MSDev.Application");
$app = Win32::OLE->new("MSDEV.APPLICATION") if ! defined $app;
die "Cant open MsDev.\n" unless $app;
$app->{"WindowState"} = 1 if $app->{"WindowState"} == 2;
http://www.vim.org/tips/tip.php?tip_id=580 (2 of 4) [18/02/2004 15:03:52]

Tip #580 - Switching back and forth between ViM and Visual Studio .NET : vim online

$app->{"Visible"}=1;
$app->{"Active"}=1;
$file = $app->{"Documents"}->Open("'$VIEWFILE'");
die "Cant open file='$VIEWFILE' in msdev.\n" unless $file;
print( $app->FullName()," ",$file->FullName()," type=",$file>Type(),".\n" );
print("PWD=",$app->CurrentDirectory(),".\n");
$file->Selection()->GotoLine("'$GOTOLINE'") if $ENV{"GOTOLINE"};
# dsMatchWord is in vc/include/objmodel/textdefs.h
$file->Selection()->FindText($ENV{"FINDTEXT"},2) if $ENV{"FINDTEXT"};
$file->Selection()->Selectline(); # highlight it.
exit 0;
'
dunderxiii@hotmail.com, October 10, 2003 7:39
I udated the DevEnvDDE program to connect to Visual Studio .NET 2003.
The code now supports an extra command line parameter that specifies
the visual studio instance to open the file in (VS6, VSNET or
VSNET2003). Simply download the new sources (same link).
Note: it now defaults to Visual Studio .NET 2003 instead of Visual
Studio .NET
Anonymous, October 22, 2003 13:47
Thanks for this!
Just a small note regarding the perl script - you don't say which
version of Win32::GUITest you are using but I found that I had to
change WaitWindow to FindWindowLike to get the script
working. WaitWindow must be deprecated or something.
orthober@msoe.edu, January 29, 2004 8:30
Just to let you know, to open a file with Visual Studio (At least the
current versions) you simple can put the file name as an arument to
the command line.
Example:
"C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\IDE\devenv.exe" "BE-NotInDirectory\main.cpp" "CClate\main.c
pp" "DO\Lab 5.cpp" "MG\Lab5.cpp" "NathanK\main.cpp" "NH\func.h"
"NH\func.cpp" "NH\main.cpp" "NM-late\main.cpp"
Would open all of these files.
What I am looking for is a way to tell VS to Auto Print these
files. I have also made a program that will SENDKEYS to VS to print
these, but I would like a better way.
Thanks
Jeff O
Add Note

http://www.vim.org/tips/tip.php?tip_id=580 (3 of 4) [18/02/2004 15:03:52]

Tip #580 - Switching back and forth between ViM and Visual Studio .NET : vim online
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=580 (4 of 4) [18/02/2004 15:03:52]

SourceForge
Logo

Tip #579 - Cut&Paste without too much newlines, eg. into WORD : vim online

not logged in (login)

Home
Search

Tip #579: Cut&Paste without too much newlines, eg. into WORD
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/5, Viewed by 733

created: October 6, 2003 2:43


author: Siegfried Bublitz

complexity: basic
as of Vim: 5.7

Sometimes I am forced to enter text into MS Word. Since


this tool is not
reliable and fast enough for me, I often prefer to
create the text in
VIM before and cut&paste it into Word.
Unfortunately, Word creates newlines of its own and
regards entered
newlines as paragraphs. So I created a mapping that
deletes all single
newlines from a selected area but keeps multiple ones.
Here it is:
vmap <C-C> "+y:let @+ = substitute(@+, "\n\n\n*", "",
"g")
\\|:let @+ = substitute(@+, "\n", " ", "g")<CR>
\\|:let @+ = substitute(@+, "", "\\n", "g")<CR>
\\|'<
Just shortly what is does:
Copy the visual area into the selection register +,
subsitute two and
more newlines but a strange symbol hopefully not
contained in the area
(), substitute single newlines by a blank and
resubstitute the strange
symbol by one newline, then go back to the beginning of
the selected area.
If you select now text in VIM with V, it is copied with
<Ctrl-C> as
described and can be pasted normally into another
application.
Siegfried

http://www.vim.org/tips/tip.php?tip_id=579 (1 of 2) [18/02/2004 15:03:55]

Tip #579 - Cut&Paste without too much newlines, eg. into WORD : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Specify Range with search patterns | Switching back and forth between ViM and Visual Studio .NET
>>

Additional Notes
sgovindachar at yahoo, October 6, 2003 9:43
Here's another way:
Step 1: set text width to a very large number; the
number should
be bigger than the number of words in any
para.
Example: set tw=5000
Step 2: Reformat the entire text with the gq command,
for
example, by using the series of commands
below
(the first three commands below select the
text, the
last is the gq command):
gg
Ctrl-q
G
gq
To copy to word, one can do the following:
gg
"*yG
The preceding copies the text into the clipboard.
Then go to word and paste using "Ctrl-v"

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=579 (2 of 2) [18/02/2004 15:03:55]

SourceForge
Logo

Tip #578 - Specify Range with search patterns : vim online

not logged in (login)

Home
Search

Tip #578: Specify Range with search patterns


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 19/16, Viewed by 672

created: October 5, 2003 22:48


author: duvell

complexity: intermediate
as of Vim: 6.0

I was recently using sed to pull out multi-line fields


with sed when I wondered if I could specify a range
using two search patterns in vim as I can in sed. Sure
enough it works. I am using 6.1 and do not know if this
feature is new but I suspect it has probably been
around.
Here is a contrived example. Suppose I had a vim script
I was editing and I want to comment out the function
declaration of a function named My_func. Instead of
searching for it, marking the range and then adding a
comment to the start of the line, the following command
will work:
:/^ *function *My_funct\>/,/^ *endfunction/s/^/" /
The range is specified by two patterns. For the start
of the range I look for the line which contains function
My_funct. I added the \> end of word delimeter to the
pattern in case I had other functions that had names
beginning with My_func.
The end of the range will be the first occurance of the
second pattern, /^ *endfunction/ starting from where the
first pattern was matched.
The two patterns are separated with a comma as any range
would be and the command to perform on the range
follows. In this case a substitution, s/^/: / but it
could be any command.
This has become useful and even though I have used vim
for several years this was a new discovery for me.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Access vim@vim.org using Newsgroup Reader | Cut&Paste without too much newlines, eg. into

http://www.vim.org/tips/tip.php?tip_id=578 (1 of 2) [18/02/2004 15:03:57]

Tip #578 - Specify Range with search patterns : vim online

WORD >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=578 (2 of 2) [18/02/2004 15:03:57]

SourceForge
Logo

Tip #577 - Access vim@vim.org using Newsgroup Reader : vim online

not logged in (login)

Home
Search

Tip #577: Access vim@vim.org using Newsgroup Reader


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 27/9, Viewed by 393

created: October 5, 2003 21:02


author: Pan Shizhu

complexity: basic
as of Vim: 6.0

For some reason one may not prefer mailling lists over
usenet newsgroups (like me).
IMHO Newsgroup reader is a lot more versatile and easy
to use. So, find a newsgroup equivalent for vim@vim.org
is improtant for newsgreoup users. Unfortunately, the
comp.editors on USENET is not as active as vim@vim.org.
The non-official news server news.gmane.org, have a
mirror to vim@vim.org, named gmane.editors.vim, the
maillist vim@vim.org and newsgroup gmane.editors.vim
seemed to be syncronised together.
To access the gmane news, just new an account with the
NNTP server news.gmane.org, then find the newsgroup
gmane.editors.vim, then you can enjoy vim@vim.org with
your favorate news reader program, and without messing
up mailling list messages with your private e-mail
client (which is what the newsgroup designed for).
I think gmane.editors.vim should be highly recommended
for newsgoup users.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<one call to generate all unicode "characters" from within vim | Specify Range with search patterns
>>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=577 [18/02/2004 15:04:00]

SourceForge
Logo

Tip #576 - one call to generate all unicode "characters" from within vim : vim online

not logged in (login)

Home
Search

Tip #576: one call to generate all unicode "characters" from within vim
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/5, Viewed by 507

created: October 5, 2003 17:16


author: maxiangjiang@hotmail.com

complexity: basic
as of Vim: 6.0

This is a small function to generate all unicode "characters".


It might be interesting to those who are familiar with CJK.
I modified Frank's idea,
http://groups.yahoo.com/group/vim/message/43907,
with a neat format. (Thank you, Frank)
Tony Mechelynck offered a great tip as how to work with utf-8 in
http://vim.sourceforge.net/tip_view.php?tip_id=246
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! GenerateUnicode()
let i = 0
while i <= 16*16*16*16
let n = i
let j = 0
let h = ""
while n
let h = '0123456789ABCDEF'[n%16].h
let n = n/16
endwhile
let c = h.' '
while j<16
let u = i+j
let c = c.nr2char(u).' '
let j = j+1
endwhile
$put = c
let i = i+16
if (i%(16*16) == 0)
$put='---------------------------------------------------'
$put='
0 1 2 3 4 5 6 7 8 9 A B C D E F
'
$put='---------------------------------------------------'
endif
endwhile
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

http://www.vim.org/tips/tip.php?tip_id=576 (1 of 2) [18/02/2004 15:04:02]

Tip #576 - one call to generate all unicode "characters" from within vim : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<chop long lines. | Access vim@vim.org using Newsgroup Reader >>

Additional Notes
maxiangjiang@hotmail.com, October 5, 2003 18:15
Here is the screen shot:
http://www.clarkson.edu/~maxi/unicode.gif
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=576 (2 of 2) [18/02/2004 15:04:02]

SourceForge
Logo

Tip #575 - chop long lines. : vim online

not logged in (login)

Home
Search

Tip #575: chop long lines.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/1, Viewed by 633

created: October 4, 2003 11:42


author: mosh@cs.albany.edu

complexity: basic
as of Vim: 6.0

" Some regexp substitutions for your menus from .vimrc


:amenu Mo1.Format.ChopLongLines
80,}\)\s!\1<C-v>\r!gc

:%s!\(.\{-

:amenu Mo1.Format.JoinHypenatedLines
\n(\s*)(\S+)\s*, \1\3^M\2,gc

:%s,\v\s+(\w+)-

:amenu Mo1.Format.JoinBackSlashLines

:%s,\\\n,,gc

" - Mohsin Ahmed http://www.cs.albany.edu/~mosh


" > How now, how now, chop-logic! What is this? Capulet, R & Juliet 3.5, WS.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<delete/move matching paragraphs/lines | one call to generate all unicode "characters" from within
vim >>

Additional Notes
Anonymous, December 3, 2003 13:46

http://www.vim.org/tips/tip.php?tip_id=575 (1 of 2) [18/02/2004 15:04:05]

Tip #575 - chop long lines. : vim online

Hmm.. As far as chopping lines goes, look at man fmt :)


Note that fmt chops lines to 72 (or is it 75?) by
default. You can also set it using fmt flag.
Chop long lines from line 1 to 10
:1,10!fmt
Also, you can do visual block and use fmt! (This is the
best part :-)
1) 'v' to start visual mode in command mode.
2) select a block
3) then type '!fmt<enter>'
Woo hoo~~
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=575 (2 of 2) [18/02/2004 15:04:05]

SourceForge
Logo

Tip #574 - delete/move matching paragraphs/lines : vim online

not logged in (login)

Home
Search

Tip #574: delete/move matching paragraphs/lines


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/1, Viewed by 422

created: October 4, 2003 11:32


author: mosh@cs.albany.edu

complexity: basic
as of Vim: 6.0

" Put these in .vimrc, and these four items will become
menu items.
" You can of course just type these one liners, if you
don't have menus.
" Edit /word/ before pressing return,
" Note: /word/ can be any perl expression to select
paras.
:amenu Mo1./.Delete-Matching-Paras<tab>:1,$!perl :1,$!
perl -0000lne 'print if m/word/'
:amenu Mo1./.Delete-Matching-Lines<TAB>:g//d
:g//d<CR>
:amenu Mo1./.Delete-Non-Matching-Lines<TAB>:v//d
:v//d<CR>
:amenu
ma:g//
:amenu
ma:v//

Mo1./.Move-Matching-Lines-Top<TAB>g//\.m0
.m0<CR>`a
Mo1./.Move-Non-Matching-Lines-Last<TAB>v//\.m$
.m$<CR>`a

" - Mohsin Ahmed http://www.cs.albany.edu/~mosh


" > To match thy goodness? My life will be too short,
" > And every measure fail me. -- Cordelia, King Lear
4.7
rate this tip

Life Changing

Helpful

Unfulfilling

<<Repeating a substitute from current cursor position | chop long lines. >>

Additional Notes

Add Note

http://www.vim.org/tips/tip.php?tip_id=574 (1 of 2) [18/02/2004 15:04:08]

rate

Tip #574 - delete/move matching paragraphs/lines : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=574 (2 of 2) [18/02/2004 15:04:08]

SourceForge
Logo

Tip #573 - Repeating a substitute from current cursor position : vim online

not logged in (login)

Home
Search

Tip #573: Repeating a substitute from current cursor position


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/3, Viewed by 584

created: October 3, 2003 7:30


author: Charles E. Campbell, Jr.

complexity: intermediate
as of Vim: 6.0

The :RS /pattern/subpattern/{flags} command+function as


shown
below allows one to repeat a RS-substitute after the
current
cursor position.
Ex.
cursor starts...
one two three one two three one two three
o^here
:RS /two/TWO/
one TWO three one two three one two three
one TWO^cursor ends up here
move cursor:
one TWO three one two three one two three
one TWO three one two ^
cursor ends up:
one TWO three one two three one TWO three
one TWO three one two three one TWO^
(normally I'd have left the characters preceding the
^ as blanks but I'm
trying to avoid problems with proportional fonts)
Put the following into your <.vimrc> if you'd like to be
able to do this:
" -------------------------------------------------------------------" RS: repeat substitution command
com! -range -nargs=* RS call RepeatSubst(<q-args>)
" RepatSubst:
fun! RepeatSubst(subexpr)
if a:subexpr != ""

http://www.vim.org/tips/tip.php?tip_id=573 (1 of 2) [18/02/2004 15:04:11]

Tip #573 - Repeating a substitute from current cursor position : vim online

let g:repeatsubst= a:subexpr


endif
let curcol= col(".")
let sep
= strpart(g:repeatsubst,0,1)
let pat
= substitute(g:repeatsubst,'^.\(.\{}\)'.sep.'.*$','\1','')
s/\%#./\r&/
let curcol= curcol + matchend(getline("."),pat)
exe "s".g:repeatsubst
norm! k
j!
exe 'norm! '.curcol.'|'
endfun
" -------------------------------------------------------------------rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<auto highlight word under cursor (when reading new code) | delete/move matching paragraphs/lines
>>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=573 (2 of 2) [18/02/2004 15:04:11]

SourceForge
Logo

Tip #572 - auto highlight word under cursor (when reading new code) : vim online

not logged in (login)

Home
Search

Tip #572: auto highlight word under cursor (when reading new code)
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/7, Viewed by 881

created: September 30, 2003 20:32


author: mosh@cs.albany.edu

complexity: basic
as of Vim: 6.0

" Highlight all instances of word under cursor, when


idle.
" Useful when studying strange source code.
" Turn on/off with z/ (or key of your choice)
:map z/ :call Mosh_Auto_Highlight_Toggle()<CR>
:function! Mosh_Auto_Highlight_Cword()
:exe "let @/='\\<".expand("<cword>")."\\>'"
:endfunction
function! Mosh_Auto_Highlight_Toggle()
:if exists("#CursorHold#*")
: au! CursorHold *
: let @/=''
:else
: set hlsearch
: set updatetime=500
: au! CursorHold * nested call
Mosh_Auto_Highlight_Cword()
:endif
endfunction
" There is cold meat i' the cave; we'll browse on that,
" -- GUIDERIUS, in Cymbeline by Shakespeare.
" No occupation; all men idle, all;
" -- GONZALO, Tempest by ShakesPear.
" http://www.cs.albany.edu/~mosh - Mohsin.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<source ..../vimrc and use ..../tags in an ancestor directory. | Repeating a substitute from current
cursor position >>

http://www.vim.org/tips/tip.php?tip_id=572 (1 of 2) [18/02/2004 15:04:13]

Tip #572 - auto highlight word under cursor (when reading new code) : vim online

Additional Notes
Salman Halim, October 1, 2003 6:42
I would suggest placing the CursorHold event inside an
autocommand group (augroup); the way this is right now
would clobber my other CursorHold autocommands. . .
Anonymous, October 1, 2003 18:29
Question. What does the colon do here? I noticed some
other people use it also.
Anonymous, October 6, 2003 14:02
Well, what does the colon do when you're using vim
normally? Starts a command. Same thing here.
Anonymous, November 3, 2003 9:56
I'm new to vim, but why do u need the colons at the if
else and endif statements then?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=572 (2 of 2) [18/02/2004 15:04:13]

SourceForge
Logo

Tip #571 - source ..../vimrc and use ..../tags in an ancestor directory. : vim online

not logged in (login)

Home
Search

Tip #571: source ..../vimrc and use ..../tags in an ancestor directory.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -1/1, Viewed by 553

created: September 30, 2003 20:23


author: mosh@cs.albany.edu

complexity: basic
as of Vim: 5.7

" Source .../.vimrc and use .../tags in ancestor of source


directory.
" useful when you have source tree eight fathom deep,
" an exercise in vim loops.
let parent=1
let local_vimrc = ".vimrc"
let local_tags = "tags"
while parent <= 8
if filewritable(local_vimrc)
echomsg "sourcing " . local_vimrc
exe ":so " . local_vimrc
endif
let local_vimrc = "../". local_vimrc
let local_tags = "../". local_tags
exe ":set tags+=".local_tags
let parent = parent+1
" ToDo: stop at the root on windows and ~ on unix.
endwhile
unlet parent local_vimrc
" Vat be all you, one, two, tree, four, come for?
" -- DOCTOR CAIUS, Windsor, Shakespeare.
" http://www.cs.albany.edu/~mosh - Mohsin.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Align badly formatted text region into table. | auto highlight word under cursor (when reading new code) >>

Additional Notes
hermitte at free dot fr, October 1, 2003 13:51
It does not handle tags directly, but the following plugin
handles local-vimrc's.
http://vim.sourceforge.net/scripts/script.php?script_id=727

http://www.vim.org/tips/tip.php?tip_id=571 (1 of 2) [18/02/2004 15:04:16]

Tip #571 - source ..../vimrc and use ..../tags in an ancestor directory. : vim online

Kartik Agaram, October 2, 2003 18:44


There's a simpler way to do this for tags:
set tags+=tags;/
[help file-searching]
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=571 (2 of 2) [18/02/2004 15:04:16]

SourceForge
Logo

Tip #570 - Align badly formatted text region into table. : vim online

not logged in (login)

Tip #570: Align badly formatted text region into table.

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -1/1, Viewed by 638

created: September 30, 2003 20:10


author: mosh@cs.albany.edu

complexity: basic
as of Vim: 6.0

" What: Aligns badly formatted text into a table.


" How: Select region and press <A-a>,
"
in this case aligns the '=', you decide the
centering string
"
before pressing return
" You need the perl script "align" from
http://www.cs.albany.edu/~mosh/Perl/align
"
" Inspired by Emacs align.el
" Works on Windows and Unix.
" Default key Mapping is:
:vmap <A-a> !perl ~/perl/align -c:=
" Example input:
" x = 1;
"
xyz = 245;
" a=1;
" Example Output:
"
x = 1;
" xyz = 245;
"
a = 1;
"

" I know not what; but format in apparel,


" In gait and countenance surely like a father.
" -- BIONDELLO in Taming of Shrew by Shakespeare.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Insert line numbers or filter thru perl. | source ..../vimrc and use ..../tags in an ancestor directory. >>

http://www.vim.org/tips/tip.php?tip_id=570 (1 of 2) [18/02/2004 15:04:19]

Tip #570 - Align badly formatted text region into table. : vim online

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=570 (2 of 2) [18/02/2004 15:04:19]

SourceForge
Logo

Tip #569 - Insert line numbers or filter thru perl. : vim online

not logged in (login)

Home
Search

Tip #569: Insert line numbers or filter thru perl.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/0, Viewed by 562

created: September 30, 2003 19:55


author: mosh@cs.albany.edu

complexity: basic
as of Vim: 6.0

" Create a menu item to call perl on the file


" Edit the -e "script" before pressing return to filter
thru perl
" Script below works shell=sh, and add line numbers to
the file.
:amenu Mo1.Format.NumberLines<TAB>:!perl :1,$!perl -ne
\"printf(\\"\%3d:\%s\\",\$.,\$_);\"
"
" http://www.cs.albany.edu/~mosh Mohsin

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Use temporary tags file when browsing new source. | Align badly formatted text region into table. >>

Additional Notes
Siegfried.Bublitz@c-lab.de, October 1, 2003 0:13
If you don't have access to Perl, you can do it
directly from VIM by calling this function:
function! Listing()
" set line numbers in front of lines
let i=line("$")
let pre = ' '
while (i > 0)
if match(i, '^9*$') == 0
let pre = pre . '0'
endif
call setline(i, pre . i . "\t" . getline(i))
let i=i-1
endwhile
endfunction
http://www.vim.org/tips/tip.php?tip_id=569 (1 of 2) [18/02/2004 15:04:21]

Tip #569 - Insert line numbers or filter thru perl. : vim online

- Siegfried
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=569 (2 of 2) [18/02/2004 15:04:21]

SourceForge
Logo

Tip #568 - Use temporary tags file when browsing new source. : vim online

not logged in (login)

Home
Search

Tip #568: Use temporary tags file when browsing new source.
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 1/1, Viewed by 280

created: September 30, 2003 19:50


author: mosh@cs.albany.edu

complexity: basic
as of Vim: 6.0

" Create and Use $TMP/tags for local source dir (which
may be unwriteable)
" Unix users can change c:/tmp to ~/tmp/ (I use $TMP
with sh).
:map <c-k>t :!(cd %:p:h;ctags -o c:/tmp/tags -R
.)&<CR>:set tags^=c:/tmp/tags<CR>

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Edit a temporary copy of the current file | Insert line numbers or filter thru perl. >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=568 [18/02/2004 15:04:24]

SourceForge
Logo

Tip #567 - Edit a temporary copy of the current file : vim online

not logged in (login)

Home
Search

Tip #567: Edit a temporary copy of the current file


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 0/0, Viewed by 203

created: September 30, 2003 19:44


author: mosh@cs.albany.edu

complexity: basic
as of Vim: 6.0

" Edit a copy of the current file as $TMP/file-$DATE by


pressing 'zs'
:map zs
:exe "sav $TMP/" . expand("%:t") .
strftime("-%Y-%m-%d_%H%M%S")<CR>

Site Help

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Autocomplete with TAB when typing words | Use temporary tags file when browsing new source. >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=567 [18/02/2004 15:04:27]

SourceForge
Logo

Tip #566 - Autocomplete with TAB when typing words : vim online

not logged in (login)

Home
Search

Tip #566: Autocomplete with TAB when typing words


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/5, Viewed by 961

created: September 30, 2003 19:41


author: mohsin@synplicity.com

complexity: basic
as of Vim: 6.0

"-- Use TAB to complete when typing words, else inserts


TABs as usual.
"-- Uses dictionary and source files to find matching
words to complete.
"-- See help completion for source,
"-- Note: usual completion is on <C-n> but more trouble
to press all the time.
"-- Never type the same word twice and maybe learn a new
spellings!
"-- Use the Linux dictionary when spelling is in doubt.
"-- Window users can copy the file to their machine.
"-- http://www.cs.albany.edu/~mosh - Mohsin Ahmed
function! Mosh_Tab_Or_Complete()
if col('.')>1 && strpart( getline('.'), col('.')-2,
3 ) =~ '^\w'
return "\<C-N>"
else
return "\<Tab>"
endfunction
:inoremap <Tab> <C-R>=Mosh_Tab_Or_Complete()<CR>
:set

dictionary="/usr/dict/words"

rate this tip

Life Changing

Helpful

Unfulfilling

<<never see ^M again | Edit a temporary copy of the current file >>

Additional Notes
Anonymous, September 30, 2003 23:35
http://www.vim.org/tips/tip.php?tip_id=566 (1 of 2) [18/02/2004 15:04:30]

rate

Tip #566 - Autocomplete with TAB when typing words : vim online

See :help ins-completion


And :help i_CTRL-X_CTRL-K
benji@member.AMS.org, October 2, 2003 9:45
Even easier than <Tab> is to have words completed
automatically. There are some drawbacks to this, but
the word_complete.vim plugin works pretty well.
http://www.vim.org/scripts/script.php?script_id=73
vimtip@bzzt.net, December 17, 2003 3:42
to use the dictionary, add 'k' to your ':set complete'.
For language keywords (tags), also add ']'. See ':help
complete' ;)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=566 (2 of 2) [18/02/2004 15:04:30]

SourceForge
Logo

Tip #565 - never see ^M again : vim online

not logged in (login)

Home
Search

Tip #565: never see ^M again


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 55/29, Viewed by 1975

created: September 26, 2003 17:40


author: Usman Latif

complexity: basic
as of Vim: 5.7

There have been plenty of tips dealing with ridding of


^M characters
appended to dos text files. However, all of the previous
tips involve
some typing. With the following command in your vimrc,
you won't have to
type anything. Moreover, you are not likely to see ^M
characters again
at all, they get removed before you get to view the
file. The only
exception being readonly files.
autocmd BufRead * silent! %s/^M$//
Note: Use <C-V><C-M> to enter ^M and not caret followed
by M

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<mouse wheel for scroll only - disable paste on middle button press. | Autocomplete with TAB when
typing words >>

Additional Notes
zzapper@ntlworld.com, September 29, 2003 6:59
# \r easier to type tham ^m
# cope with possible multiple trailing ^m's
autocmd BufRead * silent! %s/\r\+$//
# also delete pesky trailing whitespace at the same
time
autocmd BufRead * silent! %s/[\r \t]\+$//

http://www.vim.org/tips/tip.php?tip_id=565 (1 of 2) [18/02/2004 15:04:33]

Tip #565 - never see ^M again : vim online

natter_SIHT_EVOMER with aeiGARBAGE.ca, September 29, 2003 7:00


The fileformat (:help ff) variable should help
you. Usually, you see ^M when opening a DOS file in
Unix format. The file format should be set
automatically to the right thing, but if that is not
the case, type: ":set ff=dos".
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=565 (2 of 2) [18/02/2004 15:04:33]

SourceForge
Logo

Tip #564 - mouse wheel for scroll only - disable paste on middle button press. : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #564: mouse wheel for scroll only - disable paste on middle
button press.
tip karma

Rating 8/7, Viewed by 640

created: September 26, 2003 12:58


author: Girish Gajwani

complexity: basic
as of Vim: 5.7

I have had a problem when using the mousewheel for


scrolling. I occasionaly press the wheel and it pastes
text in the clipboard's "*" register at the place where
the scroll wheel was pressed accidentally. This has been
a constant irritation.
The workaround is documented in VIM help :help <MiddleMouse>
From change.txt (VIM help):
"If you have a scrollwheel and often accidentally paste
text, you can use these mappings to disable the
pasting with the middle mouse button: >
:map <MiddleMouse> <Nop>
:imap <MiddleMouse> <Nop>"
Also, to revert to the original setting for middle
button click, simply unmap the previous setting.
:unmap <MiddleMouse>
:iunmap <MiddleMouse>
Enjoy!
rate this tip

Life Changing

Helpful

Unfulfilling

<<useful Occurences under cursor and with prompt | never see ^M again >>

Additional Notes
cristi001 at hotmail, October 7, 2003 17:08

http://www.vim.org/tips/tip.php?tip_id=564 (1 of 2) [18/02/2004 15:04:35]

rate

Tip #564 - mouse wheel for scroll only - disable paste on middle button press. : vim online

While at it, take care also of 2-MiddleMouse, 3MiddleMouse and (oh, humanity! :) ) 4-MiddleMouse.
(that's for middle double clicks and triple and ...)
Alternatively, instead of simply ignoring it, make it
the same as a left click with a noremap <MiddleMouse>
<LeftMouse> (also with noremap!, and the whole 2-,3,etc. list above).
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=564 (2 of 2) [18/02/2004 15:04:35]

SourceForge
Logo

Tip #563 - useful Occurences under cursor and with prompt : vim online

not logged in (login)

Home
Search

Tip #563: useful Occurences under cursor and with prompt


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -1/1, Viewed by 605

created: September 24, 2003 21:28


author: lechee

complexity: basic
as of Vim: 6.0

[I is very useful display all lines that contain the


keyword under the cursor
so following are two function for selection contain in
two way under cursor or prompt find
a big thanx Yegappan give me the hint for ijump
function! s:UnderOccurences()
exe "normal [I"
let nr = input("Which one: ")
if nr == ""
return
endif
exe "normal " . nr . "[\t"
endfunction!
function! s:FindOccurences()
let pattern = input("Prompt Find: ")
if pattern == ""
return
endif
exe "ilist " . pattern
let nr = input("Which one: ")
if nr == ""
return
endif
exe "ijump " . nr . pattern
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<modeline sets vimrc options on a per file basis | mouse wheel for scroll only - disable paste on
middle button press. >>

Additional Notes
http://www.vim.org/tips/tip.php?tip_id=563 (1 of 2) [18/02/2004 15:04:38]

Tip #563 - useful Occurences under cursor and with prompt : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=563 (2 of 2) [18/02/2004 15:04:38]

SourceForge
Logo

Tip #562 - modeline sets vimrc options on a per file basis : vim online

not logged in (login)

Home
Search

Tip #562: modeline sets vimrc options on a per file basis


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 7/4, Viewed by 618

created: September 22, 2003 13:24


author: Duane Smeckert

complexity: basic
as of Vim: 5.7

Sometimes I want vi to treat a file different than the


.vimrc file.
For example, I have a file that has fixed length text
records,
tabs in this file would mess it up.
Setting the option expandtab will force tabs to be
converted to spaces.
Near the top of the file I put a line that says:
# vim: set expandtab:
When I open the file after that it will replace ^I (tab
characters) with the correct number of spaces.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Context Sensitive h and l | useful Occurences under cursor and with prompt >>

Additional Notes
Anonymous, September 23, 2003 12:00
To read more about modelines, type:
:help auto-setting
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=562 [18/02/2004 15:04:43]

SourceForge
Logo

Tip #561 - Context Sensitive h and l : vim online

not logged in (login)

Home
Search

Tip #561: Context Sensitive h and l


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/2, Viewed by 621

created: September 19, 2003 22:19


author: Usman Latif

complexity: basic
as of Vim: 5.7

While writing an email I noticed that the h key does


nothing when pressed at
the start of the line. It occurred to me that it would
be very natural behavior
for the h key to move to the end of the previous line
under the above situation.
Similarly, it would be fairly useful behavior for the l
key to move to the
start of the next line when the cursor is at the end of
the line.
The following illustration should clarify the behavior I
am talking about:
pressing l at the end of this line -->
<-- should move to the beginning of this line
pressing h at the start of the next line, should move to
end of this line -->
<-I have coded two functions that implement
behavior. Putting the
code given at the end of this tip in your
the h and l keys to
behave in a context sensitive manner. The
that under
"virtualedit=all" h/l keys will revert to
vim behavior.

the desired
vimrc will map
only caveat is
their usual

This tip is similar in spirit to vimtim# 548, which


concerned the H and L keys.
Robert Kelly created vimscript# 763 for the code in
vimtip# 548. I suggest that
he adds the code below to that script. You can also
retrieve a script
with mappings for all the above mentioned keys on my
download page
http://www.vim.org/tips/tip.php?tip_id=561 (1 of 3) [18/02/2004 15:04:45]

Tip #561 - Context Sensitive h and l : vim online

http://www.techuser.net?content=5
------------------------------------cut here---------------------------------nmap <silent> h :<C-U>call ContextLeft()<CR>
nmap <silent> l :<C-U>call ContextRight()<CR>
func! ContextLeft()
let cnt = v:count == 0 ? 1 : v:count
if col('.') == 1 && line('.') != 1 && &ve != "all"
exe "normal! " . cnt. "k$"
else
exe "normal! " . cnt. "h"
endif
endfunc
func! ContextRight()
let cnt = v:count == 0 ? 1 : v:count
if col('.') >= strlen(getline('.')) && line('.') !=
line('$') && &ve != "all"
exe "normal! " . cnt . "j^"
else
exe "normal! " . cnt . "l"
endif
endfunc
------------------------------------cut here----------------------------------

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Generate calendar file | modeline sets vimrc options on a per file basis >>

Additional Notes
cec@NgrOyphSon.gPsfAc.nMasa.gov, September 20, 2003 9:09
Check out :he 'ww' ; in particular try :set
ww=h,l . For a more complete set, try
set ww=b,s,<,>,[,],h,l
latif@techuser.net, September 24, 2003 20:32
The 'ww' option works much better than my script, so I
will be taking the script off my site. Thanks for
posting the comment.
Add Note

http://www.vim.org/tips/tip.php?tip_id=561 (2 of 3) [18/02/2004 15:04:45]

Tip #561 - Context Sensitive h and l : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=561 (3 of 3) [18/02/2004 15:04:45]

SourceForge
Logo

Tip #560 - Generate calendar file : vim online

not logged in (login)

Home
Search

Tip #560: Generate calendar file


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 7/4, Viewed by 1092

created: September 18, 2003 1:31


author: Siegfried Bublitz

complexity: basic
as of Vim: 5.7

Since I work on different machines, I prefer all my calendar items to be


available in one single ASCII file, which is easily handable with vim.
The function Calendar() below generates the following output (extract)
...............
----- Week 1 ----Mo 30
Tu 31
====================
====================
-------------------We 01
Th 02
Fr 03
Sa 04
Su 05
----- Week 2 ----Mo 06
Tu 07
...............

2003
Q 1
Jan 2003

========================================
========================================
----------------------------------------

This may be stored in a file accessible by a single key stroke from vim.
Here is the function:
function! Calendar(year, month, day, weekday, week, daycount)
" output daycount calendar days starting from given date
" into new buffer
new
set buftype=nofile bufhidden=hide noswapfile
let year = a:year
let month = a:month
let day = a:day
let wd = a:weekday
let week = a:week
let index = 0
let date = ''
let diy = 777 " day in year, wrong before next year
while (index < a:daycount) " no of days to output
let diy = diy + 1
if (wd > 7)
let wd = 1
let week = week + 1
if (week >= 53)
if (week >= 54)

http://www.vim.org/tips/tip.php?tip_id=560 (1 of 5) [18/02/2004 15:04:48]

Tip #560 - Generate calendar file : vim online

let week = 1
elseif (day >= 28 || day <= 3)
let week = 1
endif
endif
endif
if (wd == 1) " day name
let dn = "Mo"
elseif (wd == 2)
let dn = "Tu"
elseif (wd == 3)
let dn = "We"
elseif (wd == 4)
let dn = "Th"
elseif (wd == 5)
let dn = "Fr"
elseif (wd == 6)
let dn = "Sa"
elseif (wd == 7)
let dn = "Su"
else
let dn = "** ERROR: Unknown day name ** "
endif
if ((day > 31) || (month == 2 && (day > 29 || day > 28 && year % 4))
\ || (month == 4 && day > 30) || (month == 6 && day > 30)
\ || (month == 9 && day > 30) || (month == 11 && day > 30))
let day = 1
let month = month + 1
if (month > 12)
let month = 1
let diy = 1
let year = year + 1
if (wd <= 3)
let week = 1
endif
endif
if (month == 1)
let yline = "===================="
call append(line("$"), yline . "
" . year . "
" . yline . yline )
call append(line("$"), yline . "
Q 1
" . yline . yline )
let monthn = "Jan" " month name
elseif (month == 2)
let monthn = "Feb"
elseif (month == 3)
let monthn = "Mar"
elseif (month == 4)
let monthn = "Apr"
call append(line("$"), yline . "
Q 2
" . yline . yline )
elseif (month == 5)
let monthn = "May"
elseif (month == 6)
let monthn = "Jun"
elseif (month == 7)
let monthn = "Jul"
call append(line("$"), yline . "
Q 3
" . yline . yline )
elseif (month == 8)
let monthn = "Aug"
elseif (month == 9)
let monthn = "Sep"
http://www.vim.org/tips/tip.php?tip_id=560 (2 of 5) [18/02/2004 15:04:48]

Tip #560 - Generate calendar file : vim online

elseif (month == 10)


let monthn = "Oct"
call append(line("$"), yline . "
Q 4
" . yline . yline )
elseif (month == 11)
let monthn = "Nov"
elseif (month == 12)
let monthn = "Dec"
else
let monthn = "** ERROR: Unknown month ** "
endif
let mline = "--------------------"
call append(line("$"), mline . " " . monthn . " " . year . " "
. mline . mline )
endif
if (wd == 1)
"call append(line("$"), "----- Week " . week . " (" . diy . "..) ----")
call append(line("$"), "----- Week " . week . " -----")
endif
let date = dn . " " " beginn with name of day of week
if (month < 10)
let date = date . year . '-0' . month
else
let date = date . year . '-' . month
endif
" skip month, year
let date = dn . " " " not interested in year, month
if (day < 10)
let date = date . '0' . day
else
let date = date . day
endif
" let date = date . " (" . diy . ")"
call append(line("$"), date)
let index = index + 1
let day = day + 1
let wd = wd + 1
endwhile
endfunction
map <S-F7> :call Calendar(2002, 12, 30, 1, 1, 1000)<CR><CR>
" Dec 30, 2003 is Monday (day 1 in week), week 1 in 2003
Put the above code in your vimrc and call the function, here it is shown
with entries for 1000 days. Of course, if you do not use correct
arguments matching and existing day, all output will be mess.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Use Vim to Expire your Mail (So that Mutt can delete them later) | Context Sensitive h and l >>

Additional Notes
Siegfried.Bublitz@c-lab.de, September 22, 2003 5:07

http://www.vim.org/tips/tip.php?tip_id=560 (3 of 5) [18/02/2004 15:04:48]

Tip #560 - Generate calendar file : vim online

Ok, the computation of the leapyears I have done at little careless;


the code will regard year 2100 as a leapyear, which it is not.
Maybe it is better to substitute the code part
if ((day > 31) || (month == 2 && (day > 29 || day > 28 && year %
4))
\ || (month == 4 && day > 30) || (month == 6 && day > 30)
\ || (month == 9 && day > 30) || (month == 11 && day > 30))
with this
if ((day > 31) || (day > 30 &&
\ (month == 4 || month == 6 || month == 9 || month == 11))
\ || (month == 2 &&
\ (day > 29 || (day > 28 && (year%4 || (!(year%100) && year%400))))))
but you have more than 90 years time to do this :-)
- Siegfried
aditya dot mahajan at alumni dot iitk dot ac dot in, September 22, 2003 9:33
It would be better if you post it as a script in the script section.
Also is something like this possible
We 10 : _*_
Th
11: _*_
When I move my cursor is always at the place marked with _*_, then I
do not have to move right if I want to write something for a
particular day..
Great Tip!
-Aditya
Siegfried.Bublitz@c-lab.de, October 2, 2003 0:05
If you want to go to the current day with one keystroke, you can do
the following.
Assuming the calendar is contained in a file pointed to by the global
variable cal and the
formatting of month and days is as generated, this should work by just
pressing Shift-F4:
function! Today()
let calfile = g:cal
if (bufnr(calfile) > 0)
exe ":bu " . bufnr(calfile)
else
exe "edit " . calfile
endif
let a = search("- " . strftime("%b %Y") . "
let a = search("^.. " . strftime("%d"), "w")
endfunction
map <S-F4> :call Today()<CR>
Add Note

http://www.vim.org/tips/tip.php?tip_id=560 (4 of 5) [18/02/2004 15:04:48]

-", "w")

Tip #560 - Generate calendar file : vim online


If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=560 (5 of 5) [18/02/2004 15:04:48]

SourceForge
Logo

Tip #559 - Use Vim to Expire your Mail (So that Mutt can delete them later) : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #559: Use Vim to Expire your Mail (So that Mutt can delete them
later)
tip karma

Rating 3/3, Viewed by 607

created: September 16, 2003 22:55


author: Nazri Ramliy

complexity: basic
as of Vim: 6.0

Mutt has a feature to list expired mails (~E). Sadly,


there's no built in way to
set the expiry date of a certain mail so I came up with
a vim mapping to manually
insert the "Expiry:" field of the mail header. It will
ask for the date the email should
expire (default is 'today') and then run the date
command to produce the rfc-822
compliant date.
Here's the mapping and related function:
" Set expire date for the currently edited mail
nmap ,e gg/^Date: <CR>:call GetExpiryDate()<CR>:exe
"normal! oExpires:\ndate --rfc-822 -d '".
ExpiryDate."'"<ESC>!!sh<CR>kJ<CR>
function GetExpiryDate()
call inputsave()
let g:ExpiryDate = input("Enter expiry date: ", "today")
call inputrestore()
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using TagList for ANT build files | Generate calendar file >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=559 (1 of 2) [18/02/2004 15:04:51]

SourceForge

Tip #559 - Use Vim to Expire your Mail (So that Mutt can delete them later) : vim online

Logo

http://www.vim.org/tips/tip.php?tip_id=559 (2 of 2) [18/02/2004 15:04:51]

Tip #558 - Using TagList for ANT build files : vim online

not logged in (login)

Home
Search

Tip #558: Using TagList for ANT build files


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/3, Viewed by 513

created: September 16, 2003 17:49


author: David Fishburn

complexity: basic
as of Vim: 6.0

ANT is a XML based make utility (mainly for Java,


http://ant.apache.org).
A build file can have several projects, and each project
can have many targets.
Here is a simple example:
ant clean
ant compile
ant run
Editing an ANT file can be tiresome looking for the
appropriate target entry.
Using the taglist plugin at least version 2.02
(http://vim.sourceforge.net/script.php?script_id=273)
you can easily navigate an ANT file by creating these
entries:
In your _vimrc file:
let g:tlist_ant_settings = 'ant;p:Project;t:Target'
And either add to or create a ctags.cnf file:
--langdef=ant
--langmap=ant:.xml
--regex-ant=/^[ \t]*<[ \t]*project.*name="([a-zA-Z0-9
]+)".*>/\1/p,project/i
--regex-ant=/^[ \t]*<[ \t]*target.*name="([a-zA-Z0-9
]+)".*>/\1/t,target/i
To determine where to create the ctags.cnf file see the
ctags documentation
(http://ctags.sourceforge.net/ctags.html, on WinXP this
file goes into C:\Documents and
Settings\local_user_name\ctags.cnf).
When this is used in conjuction with the Vim compiler
for ANT and a Vim Menu for ANT
(http://www.vim.org/script.php?script_id=155), it can be

http://www.vim.org/tips/tip.php?tip_id=558 (1 of 3) [18/02/2004 15:04:54]

Tip #558 - Using TagList for ANT build files : vim online

very powerful.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Opening several files in vim via ListFile | Use Vim to Expire your Mail (So that Mutt can delete them
later) >>

Additional Notes
Anonymous, September 17, 2003 9:16
Wow, this is cool!
A few further suggestions on the ctags config file
(things I've added to mine now):
(1) a pattern can also be (optionally) added for
properties:
--regex-ant=/^[ \t]*<[ \t]*property.*name="([-.a-zA-Z09 ]+)".*>/\1/r,property/i
(2) Since almost any character can be used in an Ant
name, I also modified the regex for the names to only
exclude those characters that Ant won't allow:
--regex-ant=/^[ \t]*<[ \t]*project.*name="([-.a-zA-Z0-9
]+)".*>/\1/p,project/i
--regex-ant=/^[ \t]*<[ \t]*target.*name="([-.a-zA-Z0-9
]+)".*>/\1/t,target/i
--regex-ant=/^[ \t]*<[ \t]*property.*name="([-.a-zA-Z09 ]+)".*>/\1/r,property/i
Also, to use the property tags, change the
tlist_ant_settings in the .vimrc to:
let g:tlist_ant_settings =
'ant;p:Project;t:Target;r:Property'
Anonymous, September 17, 2003 9:18
Arggghh! Stupid me.
supposed to be:

That second set of ant regexs was

--regex-ant=/^[ \t]*<[
\t]*project.*name="([^<"&]+)".*>/\1/p,project/i
--regex-ant=/^[ \t]*<[
\t]*target.*name="([^<"&]+)".*>/\1/t,target/i
--regex-ant=/^[ \t]*<[
\t]*property.*name="([^<"&]+)".*>/\1/r,property/i
(sorry)
http://www.vim.org/tips/tip.php?tip_id=558 (2 of 3) [18/02/2004 15:04:54]

Tip #558 - Using TagList for ANT build files : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=558 (3 of 3) [18/02/2004 15:04:54]

SourceForge
Logo

Tip #557 - Opening several files in vim via ListFile : vim online

not logged in (login)

Home
Search

Tip #557: Opening several files in vim via ListFile


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/4, Viewed by 638

created: September 16, 2003 5:40


author: Alex J.

complexity: intermediate
as of Vim: 5.7

Suppose You want to open several files in vim, but the


names of the files to open are stored in a file, each
file name on separate line. This is the case with Total
Commander, when You open a program and pass it %L as a
parameter.
It is possible to do it like that:
gvim "+gl/^/exec 'badd '.getline('.')" +bdel +nohls +"cd
%:h" LISTFILE
where LISTFILE contains list of file names to open.
For abovementioned Total Commander, I create new item in
"start menu", and assign a shortcut, let's say
CTRL+ALT+F4 to it. Set path\gvim.exe as a command.
This is what i put in a "parameters" section:
"+gl/^/exec 'badd '.getline('.')" +bdel +nohls +"cd
%%:h" %L
Then I can select several files, press CTRL+ALT+F4 and
load all of them into my favourite text editor :)
rate this tip

Life Changing

Helpful

Unfulfilling

<<Help on <F2> for Python with pydoc | Using TagList for ANT build files >>

Additional Notes
Anonymous, September 26, 2003 10:15

http://www.vim.org/tips/tip.php?tip_id=557 (1 of 2) [18/02/2004 15:04:56]

rate

Tip #557 - Opening several files in vim via ListFile : vim online

try:
gvim -c ":args `type mylist`"
FWIW,

things like: gvim *\2*\xx.txt

work too, even with my w2k.


Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=557 (2 of 2) [18/02/2004 15:04:56]

SourceForge
Logo

Tip #556 - Help on <F2> for Python with pydoc : vim online

not logged in (login)

Home
Search

Tip #556: Help on <F2> for Python with pydoc


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/3, Viewed by 613

created: September 11, 2003 16:33


author: Fritz Cizmarov

complexity: basic
as of Vim: 6.0

Add the following 2 lines to your


~/.vim/ftplugin/python.vim, open an pythonscript place
the cursor over an keyword and press F2 and be happy.
map <F2> :exec "!xterm -e 'pydoc
".expand("<cword>")."'"<CR><CR>
imap <F2> <ESC>:exec "!xterm -e 'pydoc
".expand("<cword>")."'"<CR><CR>i

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Vim as bookmark manager | Opening several files in vim via ListFile >>

Additional Notes
fritz@mail4free.at, September 11, 2003 16:42
You may replace the xterm in the two lines to the gnometerminal or kterm or some other
fs111@linuxmail.org, September 12, 2003 0:29
Does not work for me, what may be wrong?
Anonymous, September 12, 2003 1:48

http://www.vim.org/tips/tip.php?tip_id=556 (1 of 2) [18/02/2004 15:04:59]

Tip #556 - Help on <F2> for Python with pydoc : vim online

You can open the doc inside vim with like:


function! ShowDoc(name)
enew
execute "read !pydoc " . a:name
setlocal nomodifiable
setlocal nomodified
set filetype=man
normal 1G
endfunction
map <buffer> <silent> +m :call ShowDoc("<C-R><CW>")<CR>
this is not tested, but I use something very similar
for perl.
fritz@mail4free.at, September 12, 2003 5:55
if it does not work, be sure that xterm and pydoc
exists, to see the returnmessage in the pythonvim
delete the last <CR> in the lines.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=556 (2 of 2) [18/02/2004 15:04:59]

SourceForge
Logo

Tip #555 - Vim as bookmark manager : vim online

not logged in (login)

Home
Search

Tip #555: Vim as bookmark manager


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/7, Viewed by 1168

created: September 11, 2003 5:08


author: Mikolaj Machowski

complexity: intermediate
as of Vim: 6.0

Vim as bookmarks manager


Sometimes you are collecting bookmarks from various
sources, not only
web, mail client, usenet even newspapers. Sometimes it
is not possible, easy etc.
to insert them in your favorite web browser bookmark
manager. But
nothing is lost - you can use your Editor :)
Keep all URLs in one file called eg. url. One URL per
line.
Put this in your .vimrc:
autocmd BufRead ~/url map <F8> :call BrowserURL()<cr>
let g:web_browser = "konqueror"
function! BrowserURL()
if getline('.') !~ '^\s*\#'
if g:web_browser == "konqueror"
exe ":!dcop `dcopfind -a 'konqueror*'` konquerormainwindow\\#1 newTab ".getline('.')
elseif g:web_browser == "mozilla"
exe ":!mozilla -remote \"openurl(".getline('.').", newtab)\""
endif
endif
endfunction
Note: you can select in Visual mode few lines and open
in one keypress
few tabs. Comment lines with # at the beginning. This
lines won't be
precessed with function.
I am sure such operation are possible also with other
webbrowsers with
tabs.

http://www.vim.org/tips/tip.php?tip_id=555 (1 of 2) [18/02/2004 15:05:02]

Tip #555 - Vim as bookmark manager : vim online

Konqueror from KDE3.2-Alpha1 (but this dcop commands


should work also
with older versions)
Mozilla 1.4
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Smarter Table Editing II | Help on <F2> for Python with pydoc >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=555 (2 of 2) [18/02/2004 15:05:02]

SourceForge
Logo

Tip #554 - Smarter Table Editing II : vim online

not logged in (login)

Home
Search

Tip #554: Smarter Table Editing II


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/3, Viewed by 1059

created: September 10, 2003 18:25


author: Usman Latif

complexity: basic
as of Vim: 5.7

In vimtip #547 I described some functions that enable easier navigation


and editing of tables. I have considerably enhanced the functionality
and placed all the relevant code in a script file vimscript #769.
The idea of the script is to automatically extract fields from a table
row and use that information to create maps that aid in editing and
navigation of the table. The user first marks a table row as table
heading. The line does not literally have to be the table heading, but
it should be representative of the typical row of the table in
question.
After this step the script maps tab and shift-tab keys to move between
fields. These mappings work in both insert and normal modes. The tab
mapping is especially useful in insert mode as it inserts the correct
amount of padding to reach the start of the next field.
The script also has an alignment feature that aligns the fields of the
row with that of the heading. Editing a pre-existing table frequently
leads to misaligned rows and this feature alleviates the need to
manually add/remove padding.
To better illustrate the functionality of the script, I have created
the table below:
====================================================================
This table
illustrates the use of
table.vim script
====================================================================
<Leader>th
marks a line as table heading and
activates maps for <Tab>
and <S-Tab> keys
<Leader>th
must be invoked on a well
formed line with
the right
number of columns
This means
that the above line does not
qualify
Also notice
that the field separator is
atleast two spaces
-------------------------------------------------------------------when the maps
are active, pressing
<Tab> here
<-- moves here <Tab> here
<-- moves here
<==
<S-Tab> moves back to "<=="
<**
<S-Tab> here
moves to "<**" above
-------------------------------------------------------------------The maps for
<Tab> and <S-Tab> work in
insert and normal
modes, and can be deactivated by pressing
<Leader>tt

http://www.vim.org/tips/tip.php?tip_id=554 (1 of 3) [18/02/2004 15:05:05]

Tip #554 - Smarter Table Editing II : vim online


pressing
<Leader>tt again,
re-enables the maps
-------------------------------------------------------------------The script
has some very basic support
for field alignment
It is very
easy to get out of alignment
when editing
<Leader>ta
on the line above will
fix the line to:
It is very
easy to get out of alignment
when editing
-------------------------------------------------------------------<Leader>ta
can be very handy if the user wants to expand or
contract
fields, just change the width of the fields on the
heading line
and press
<Leader>th
to mark the
new heading and then
num<Leader>ta
on the top
line of the table.
num is the
number of
lines in the table
-------------------------------------------------------------------The alignment
command fails when a row has
more fields than
the heading
or when the contents of a
field don't fit
inside the
field, as specified by the
heading row
case1
is
this
row
case2 is this row
...
...
this is another
example of case2, there
is no space for
field
separator on the first
field on above line
====================================================================
If you don't like the default mappings change them to whatever you
like. The mappings are defined on top of the table.vim script file.
To install the script, place table.vim in the vim macros directory
and source it in your vimrc using:
source $VIMRUNTIME/macros/table.vim
If you simply want to check the functionality of the script, place
the script file in your current directory, open vim in the same
directory and use
:so table.vim
If you have questions/comments or bug-reports to submit, send them
to latif@techuser.net or visit my website http://www.techuser.net
The script can also be downloaded from http://www.techuser.net/files

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Prev and Next | Vim as bookmark manager >>

Additional Notes
Kartik Agaram, September 14, 2003 0:41
Nice, but I think it belongs in the documentation of the corresponding script. No need to allocate multiple
tip/script ids for the same thing. Hence I vote -1 here but 1 on the script.
latif@techuser.net, September 16, 2003 22:15

http://www.vim.org/tips/tip.php?tip_id=554 (2 of 3) [18/02/2004 15:05:05]

Tip #554 - Smarter Table Editing II : vim online


The scripts section is a repository for code and the tips section is about
solutions to text-editing problems. The two serve very different and distinct
purposes. Recently I posted vimtip #548 and someone turned it into a script,
vimscript #763. No one questioned it, as it was a very natural thing to do.
Similarly, I have divided this tip into a download part and a problem/solution
part, and I consider it good organization.
I think people should be using the scripts section only to provide file
downloads. If they have non-trivial comments that provide motivation for
downloading the script, they should be putting them in the tips section. That
way there will be one central place where users can look for solutions to
text-editing problems.
Please post your opinion on the issue as a comment. I suggest that the site
maintainers consider all the discussion here and turn it into a set of
guidelines for people posting tips/scripts.
Kartik Agaram, October 23, 2003 18:51
"I think people should be using the scripts section only to provide file downloads."
I disagree.
When you upload a script you want to motivate then and there why people will find it useful. Tips and scripts are
both meant for problem/solution descriptions; I select which section to add something depending on whether I am
uploading any significant amount of code that people can use out of the box (dump into plugins, etc.).
If everyone followed you and simply put up a .vim file or a tarball in the scripts section, linking to
tip with an explanation of what it does, I think vim online would be a lot less useful than it is now.
section would just be a glorified repository, and we could get rid of it from the webpages altogether,
using the script IDs transparently in the background. There is a reason why both tips and scripts have
room for explanation and description. Duplicating something in both places is just noise.

it from a
The scripts
simply
lots of

I realize that whether something constitutes a tip or script is a subjective opinion. You may disagree with me,
but it is not worth debating imo. Select one of the two sections. Just one.
As a postscript, it is interesting to compare the karma of your vimtip #548 and Robert Kelly's vimscript #763. I
will hazard the hypothesis that the vim online community has a pretty good idea of where that particular (very
useful!) idea belongs.
Anonymous, November 10, 2003 12:38
Great plugin.
Suggestion: add some messages to the user such as "tablemode: enabled" and "tablemode: heading is invalid", etc.,
using echo
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=554 (3 of 3) [18/02/2004 15:05:05]

SourceForge
Logo

Tip #547 - Smarter Table Editing : vim online

not logged in (login)

Home
Search

Tip #547: Smarter Table Editing


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/5, Viewed by 1152

created: August 30, 2003 17:32


author: Usman Latif

complexity: intermediate
as of Vim: 5.7

Smarter Table Editing


I frequently need to edit tables where the fields are of
varying lengths.
Switching between fields is a pain as the fields can
contain multiple words and
using the w key is impractical. Moreover adding a new
row to the table is most
troublesome. The new fields need to be aligned with the
old entries and tabs
don't work very well. Below is an example of such a
table that I pulled from
the vim user's guide:
USAGE

RESULT

DESCRIPTION

append( {lnum}, {string})


below line {lnum}
argc()
in the argument list
argidx()
the argument list
argv( {nr})
the argument list

Number

append {string}

Number

number of files

Number

current index in

String

{nr} entry of

* The table above might not be aligned vertically


because of the font vim-online
is using
I wrote the NextField function (given below) to
automatically check the fields
on the line directly above and move the cursor to the
beginning of the next
field. The function pads the line if required. I am
using 2 or more spaces as
the field separator but the field separator is an
argument to the function and
can be changed easily.
http://www.vim.org/tips/tip.php?tip_id=547 (1 of 5) [18/02/2004 15:05:09]

Tip #547 - Smarter Table Editing : vim online

I have mapped <S-Tab> (Shift-Tab) to invoke the


function. In the case of the
above table hitting <S-Tab> anywhere on the lines after
the line that starts
with "append" will cause the cursor to move to the next
field position or just
before it depending on the context. The function will
not work on the line
starting with "append" as there is an empty line with no
fields above it. It
will work on the empty line below the table titles as
there are fields on the
line above it. Same is the case with the empty line
below the last line of the
table.
The function takes the following arguments:
fieldsep:
A pattern that specifies the field separator
between table columns
minlensep: Minimum length of field separator. It is
used to make the function
move to the next field even when the cursor
is positioned less than
the length of a field separator from the
next table column. Set this
to 0 if you are not sure what this argument
is for.
padstr:
The string to be used for padding when the
current line needs to be
padded in order to reach the next table
column.
offset:
The offset at which you want the cursor to
be positioned in the
next table column. Set it to 0 if you want
the cursor positioned at
the start of the next table column.
(The above table is another case where the function is
helpful)
To use the function, place the code below in vimrc and
add the following lines
after it:
map <S-Tab> :call NextField(' \{2,}',2,' ',0)<CR>
map! <S-Tab> <C-O>:call NextField(' \{2,}',2,' ',0)<CR>
Note: If the whitespace between the fields consists of
anything other than
http://www.vim.org/tips/tip.php?tip_id=547 (2 of 5) [18/02/2004 15:05:09]

Tip #547 - Smarter Table Editing : vim online

spaces, the function will not work correctly without


changing the field
separator. Use expandtab option if you must use tabs.
Many variations of the above idea are possible. One
variation would be to have
a plugin that when invoked on a specific line, extracts
the field information
on that line and maps the tab key to move to the next
field then onwards. That
way there won't be any dependence on the line directly
above the cursor. If you
have any suggestions of your own let me know. If enough
people show interest in
enhancing this feature I most likely will code an
enhanced version.
--------------------------------Cut Here--------------------------------------" function: NextField
" Args: fieldsep,minlensep,padstr,offset
"
" NextField checks the line above for field separators
and moves the cursor on
" the current line to the next field. The default field
separator is two or more
" spaces. NextField also needs the minimum length of the
field separator,
" which is two in this case. If NextField is called on
the first line or on a
" line that does not have any field separators above it
the function echoes an
" error message and does nothing.
func! NextField(fieldsep,minlensep,padstr,offset)
let curposn = col(".")
let linenum = line(".")
let prevline = getline(linenum-1)
let curline = getline(linenum)
let nextposn = matchend(prevline,a:fieldsep,curposna:minlensep)+1
let padding = ""
if nextposn > strlen(prevline) || linenum == 1 ||
nextposn == 0
echo "last field or no fields on line above"
return
endif
echo ""

http://www.vim.org/tips/tip.php?tip_id=547 (3 of 5) [18/02/2004 15:05:09]

Tip #547 - Smarter Table Editing : vim online

if nextposn > strlen(curline)


if &modifiable == 0
return
endif
let i = strlen(curline)
while i < nextposn - 1
let i = i + 1
let padding = padding . a:padstr
endwhile
call
setline(linenum,substitute(curline,"$",padding,""))
endif
call cursor(linenum,nextposn+a:offset)
return
endfunc
--------------------------------Cut Here---------------------------------------

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Vim goes INTL - Translating Messages, Menus, Encodings | Using H and L keys as context
sensitive pagedown/pageup >>

Additional Notes
latif@techuser.net, September 1, 2003 18:32
If you have any suggestions as to improving the table
editing feature outlined in this tip please send your
comments to latif@techuser.net. I am giving out free
text processing consulting on my website
http://www.techuser.net. You can make a request for any
additional functionality (vim scripts, etc.) not
related to this tip on my website.
tkieselstein@web.de, September 3, 2003 2:39
In my settings, I had to use offset = -1 to start
exactly at the next table column.
Alternatively, change line 37 of the function
from:
call cursor(linenum,nextposn+a:offset)
to:
call cursor(linenum,nextposn+a:offset-1)

http://www.vim.org/tips/tip.php?tip_id=547 (4 of 5) [18/02/2004 15:05:09]

Tip #547 - Smarter Table Editing : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=547 (5 of 5) [18/02/2004 15:05:09]

SourceForge
Logo

Tip #546 - Vim goes INTL - Translating Messages, Menus, Encodings : vim online

not logged in (login)

Home
Search

Tip #546: Vim goes INTL - Translating Messages, Menus, Encodings


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 8/2, Viewed by 596

created: August 27, 2003 12:32


author: Vangelis E.

complexity: advanced
as of Vim: 5.7

Vim goes INTL - Translating Vim Editor Messages, Menus, Encodings


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Message Translation
===================
The program used for internationalizing sources is the GNU
`gettext'
utility. It is discussed in detail by its creators so we won't go
into
it here.
Instead, we'll follow the GNU `gettext' diagram to the letter so
that
we can visualize the process of creating our vim.po and vim.mo
files
using the program.
Numbers in parentheses represent the steps we'll actually
carry out (1 through 5):
~~~~~~~~~~~~~~~~ QUOTE ~~~~~~~~~~~~~~~~
(#1)

[1.1]

Original C Sources ---> PO mode ---> Marked C Sources ---.


|
.---------<--- GNU gettext Library
|
.--- make <---+
|
|
`---------<--------------------+-----------'
(#2)
|
|
|
.-----<--- PACKAGE.pot <--- xgettext <---'
.---<--- PO
Compendium
|
|
|
|
|
`---.
[2.1]
|
`---.
+---> PO
mode ---.
|
+----> tupdate -------> LANG.pox --->-------'
|
|
.---

http://www.vim.org/tips/tip.php?tip_id=546 (1 of 9) [18/02/2004 15:05:14]

^
|

Tip #546 - Vim goes INTL - Translating Messages, Menus, Encodings : vim online

'
|
|
|
|
.

`-------------<--------------|

(#3)
|
+--- LANG.po <--- New LANG.pox
<----'
|
.--- LANG.gmo <--- msgfmt <---'
|
|
(#4)
(#5)
|
`---> install ---> /.../LANG/PACKAGE.mo ---.
|
+---> "Hello
world!"
`-------> install ---> /.../bin/PROGRAM -------'
~~~~~~~~~~~~~~ END QUOTE ~~~~~~~~~~~~~~
(drwng got distorted in textarea)
STEP #1
------Get the most recent of the vim sources (vim-6.1-src1.tar.gz,
vim-6.1-src2.tar.gz) from http://www.vim.org/download.php
# create a temporary folder - let's call it "vim_tmp" # anywhere on your disk:
mkdir /path/to/vim_tmp
# copy the vim source tarball(s) in the temporary directory:
cp /original/location/vim???.tar.gz /path/to/vim_tmp
# change to that directory:
cd /path/to/vim_tmp
# and decompress them (currently there are only two source
# archives):
tar xvfz vim-6.1-src1.tar.gz ; tar xvfz vim-6.1-src2.tar.gz
NOTE: Several subdirectories are created, but only the `src'
directory contains really translatable strings.
[1.1]
------We bypass this step since all canditate strings for
translation in C sources are already marked with `N_()' or `_()'
in
vim source files. For a full discussion of how to mark strings
as
translatable in C source files, please refer to the GNU `gettext'
utilities manpage. We'll return later to this step as the
keywords in

http://www.vim.org/tips/tip.php?tip_id=546 (2 of 9) [18/02/2004 15:05:14]

Tip #546 - Vim goes INTL - Translating Messages, Menus, Encodings : vim online

vim source files (`N_' and `_') are needed as an argument to the
`xgettext' command.
IMPORTANT: Before proceeding to make the PO file, we'll have to
tag the sources, i.e. create the `tags' file:
# since the `src' directory is the only one containing
# translatable strings, and because only *.c files plus
# two more fileS (globals.h, if_perl.xs) have them,
# we switch to the `src' directory and issue:
etags *.[ch] *.xs
# to make sure all files get tagged
# we could just as well have issued:
etags src/*/*.*

STEP #2
------The command-line options we'll use are fully described
in the gettext manpage.
NOTE: (i) We'll add the `join' option in the second instance
of the command line so that the strings for the second keyword
(`_')
be extracted and appended to the same vim.po file; otherwise a
second
file vim.po would have to be created. (ii) We use
INPUTFILE=*.[ch]
because we know where the strings are to be exctracted from; else
we
must use INPUTFILE=* to exctract from all files.
# We are ready
# keyword, and
#
# translatable
xgettext -a -d

to issue the `xgettext' command - once for each


only for the files we know they contain
strings (i.e. *.c, globals.h and if_perl.xs):
vim -k N_ -s *.c *.h *.xs

xgettext -a -j -d vim -k _ -s *.c *.h *.xs


# It can also be invoked in full:
xgettext --extract-all --default-domain=vim \
--keyword=N_ --sort-output *.c *.h *.xs
xgettext --extract-all --join-existing --default-domain=vim \
--keyword=_ --sort-output *.c *.h *.xs
CAUTION: Don't be surprised when opening a vim.po file in a
text editor. It looks something like this:
...
#: ex_cmds.c:4421
msgid "E149: Sorry, no help for %s"
msgstr ""
http://www.vim.org/tips/tip.php?tip_id=546 (3 of 9) [18/02/2004 15:05:14]

Tip #546 - Vim goes INTL - Translating Messages, Menus, Encodings : vim online

#: globals.h:1053
msgid "E14: Invalid address"
msgstr ""
...
Now before proceeding to get the binary text we're after
(vim.mo), we'll have to translate _all_and_each_messages_
listed in the vim.po file. The translator must insert the
translated sting as the value of the `msgstr' variable
(between quotation marks).
To stay with the previous quotation, the Italian translation
of the excerpt above is:
...
#: ex_cmds.c:4421
msgid "E149: Sorry, no help for %s"
msgstr "E149: Spiacente, nessun aiuto per %s"
#: globals.h:1053
msgid "E14: Invalid address"
msgstr "E14: Indirizzo invalido"
...
[2.1]
------We currently have no use for the `tupdate' command since
there's no vim.po file yet; however, this program comes handy
when we
already have a *.po file and must update it based on a new
release of
sources. The command is simple enough. After unpacking the new
tarballs to our "vim_tmp" directory (step 1), we issue:
# change to tmp directory
cd /path/to/vim_tmp
# rename "vim.po" to "OLD_vim.po" assuming it's placed here:
mv vim.po OLD_vim.po
# update OLD_vim.po:
tupdate NEW_vim.po OLD_vim.po
# rename "NEW_vim.po" back to its usable filename:
mv NEW_vim.po vim.po
In case we don't want to go through the whole process of
creating a vim.po file after a new vim-###-src#.tar.gz
release, this program will take care of recreating our updated
vim.po file (NEW_vim.po) from OLD_vim.po, including the old
translations which will be taken over to the newly created
file as long as they still match. However, it is recommended
that, after a new vim_src### release, we actually start over.
Just in case!
http://www.vim.org/tips/tip.php?tip_id=546 (4 of 9) [18/02/2004 15:05:14]

Tip #546 - Vim goes INTL - Translating Messages, Menus, Encodings : vim online

STEP #3
------Next step is simplicity itself--assuming all messages
have already been translated in vim.po. We'll only use one option
out
of several that the `msgfmt' program supports; they are fully
described
in the `msgfmt' manpage. For hints on internationalizing Vim see
the
previous VimTip (VimTip#).
# change to tmp directory where our vim.po is placed:
cd /path/to/vim_tmp
# create vim.mo from vim.po:
msgfmt -o vim.mo vim.po
# or in full-text:
msgfmt --output-file=vim.mo vim.po
STEP #4
------Installing the vim.mo file requires that a directory
in $VIMRUNTIME$ (i.e. currently /path/to/vim61) exists or is
created
express for the language you'll be supporting.
Let's suppose the language we support is Greek (abbreviated as
`gr' or `el'). We do:
# create directory named `el' in $VIMRUNTIME$/path/to/lang
# with a standard subdirectory `LC_MESSAGES':
mkdir /path/to/vim61/lang/el
mkdir /path/to/vim61/lang/el/LC_MESSAGES
# copy our vim.mo file for Greek language supported:
cp /path/to/vim_tmp/vim.mo /path/to/vim61/lang/el/LC_MESSAGES
STEP #5
------Vim detects the system's local language settings when
starting and--if supported--loads it automatically; else you'll
have
to change default message language from within Vim using:
" lan[guage] {name} e.g.: lan el
" now let's test if it's working by issuing an erroneous vim
command--like: :HELP
" and you'll get the message:
: HELP
" that's all Greek to me: HELP
http://www.vim.org/tips/tip.php?tip_id=546 (5 of 9) [18/02/2004 15:05:14]

Tip #546 - Vim goes INTL - Translating Messages, Menus, Encodings : vim online

Not an editor command: HELP


Summary
-------

Download and unpack the vim sources in a temporary directory.


Use GNU `gettext' to get your template (untranslated) file.
Translate all entries in the template in your language.
Convert the translated PO file into a MO file using `msgfmt'.
Place MO file in /vim##/lang/your_language/LC_MESSAGES folder.
Set the 'language', 'messages', 'menu' options in Vim.
Test Vim and use it with your newly installed language.

Menu Translation
================
BASICS
-----For Latin-based languages, menu translation is
fairly painless. Open a `menu_xx_xx.latin1.vim' and use it as
a template to create the menu after translating the relevant
strings into the Latin-based language you intend to support.
You only have to pay attention that unique letter identifiers
in a given submenu don't repeat (e.g. &Open binds the letter
`O' uniquely so that the keyboard responds to Alt-O, and
cannot be repeated in the "File" menu. For Latin-based
languages, at least one encoding must be defined as the
default encoding for a given system; Latin1 is used on all
OS'. If your canditate language is non-Latin but Latin-based,
--as a rough rule--do menu translations in at least one of the
following encodings:
o utf-8
o iso-####-#
o an MS-DOS/wINDOWS code page
--consult old MS-DOS (v.5 or 6.2) online help for
codepage and/or country setting details).
HOW-TO
-----To create the menu file, we use one or several
word processors that supports one or several of the encodings
for the language we intend to support. If we can find the
above encodings in the SaveAs option of our word processor(s),
it's already sufficient -- depending on the number of OS' you
wish to support. We can use, for example, an existing
menu_xx_xx.latin1.vim template and translate the translatable
strings pretty much like the gettext program prepares them by
distinguishing between `msgid "ABC"' and `msgstr "XYZ"'.
Instead we'll do it manually. Save only the translated
strings of the supported language (i.e. `msgstr "XYZ"' in our
example) into a separate file using the Save As option of a
word processor (e.g. MS-Word). Now we have, for example, a
file containing the translated stings, say in iso-####-x with
filename `msgstr_iso-####-x'.
http://www.vim.org/tips/tip.php?tip_id=546 (6 of 9) [18/02/2004 15:05:14]

Tip #546 - Vim goes INTL - Translating Messages, Menus, Encodings : vim online

Here's the Hungarian menu for the iso_8859-2 specification


(lang/menu_hu_hu.iso_8859-2.vim):
msgid "ABC" msgstr "XYZ"
~~~~~~~~~~~~~~~~~~~~~~ QUOTE ~~~~~~~~~~~~~~~~~~~~~~
...
scriptencoding iso-8859-2
" Help menu
menutrans &Help &Sg
menutrans &Overview<Tab><F1> &ttekints<Tab><F1>
menutrans &How-to\ links &HOGYAN\ linkek
menutrans &User\ Manual &Kziknyv"
...
~~~~~~~~~~~~~~~~~~~~ END QUOTE ~~~~~~~~~~~~~~~~~~~~
We would create two plain text files, one with filename
`msgid_iso-####-y', containing the left-most part of
menu_hu_hu.iso_8859-2.vim:
...
menutrans
menutrans
menutrans
menutrans
...

&Help
&Overview<Tab><F1>
&How-to\ links
&User\ Manual

and one with filename `msgstr_iso-####-z' we got with the


SaveAs option of our word processor, containing the right-side
part of menu_hu_hu.iso_8859-2.vim:
...
&Sg
&ttekints<Tab><F1>
&HOGYAN\
linkek
&Kziknyv"
...
CAUTION: Do not use a spreadsheet to do the job as
these apps add/remove bytes to encodings and reset counters
when saved and distort them. Only use your wordprocessor's
SaveAs option and make sure it's a good one at that.
Then we open both files in a simple text editor (Windows
Notepad or vim) and paste line by line the left-side-file to
the right-side-file so that the we get the joined file. Now
them as a simple text. This is, say, our
save menu_aa_bb.iso_8859-cc.vim
CAUTION TOO: Do not use a legacy word processessing
program for this last Save-As-Text-Only file operation. Do

http://www.vim.org/tips/tip.php?tip_id=546 (7 of 9) [18/02/2004 15:05:14]

Tip #546 - Vim goes INTL - Translating Messages, Menus, Encodings : vim online

not use the word processor that helped with the encoding; else
you might get the wrong bytes in encodings when the left-most
part of the file is saved along with the rest.
We can repeat the same (painstaking, yet menus are short)
process with utf-8 encoding, MS-wINDOWS codepage, and any
other encoding we need to support.
Encodings
=========
To create the language encodings files for Vim in any
language, we first jot down the full specification of the
encodings in the most common OS' for the language we intend to
support.
Next we create a corresponding menu_xx_yy.ABC_mn-zz.vim file
for each of these supported encondings (making sure they
exist!).
We may use only one or several menu translations (we suggested
three basic ones above, sect. 2); one of these -- the one
with the translated strings -- can be used as the default
encoding to reference other ones. We reference the encodings
we cannot create with a word processor to the default encoding
using any menu_xx_yy.ABC_mn-zz.vim as a template.
Here's the Spanish menu for the MS-wINDOWS codepage 850
specification (lang/menu_spanish_spain.850.vim):
~~~~~~~~~~~~~~~~~~~~~~ QUOTE ~~~~~~~~~~~~~~~~~~~~~~
source <sfile>:p:h/menu_es_es.iso_8859-1.vim
~~~~~~~~~~~~~~~~~~~~ END QUOTE ~~~~~~~~~~~~~~~~~~~~
As you can see, it contains only one line and sources this spec
here from another one (i.e. es_es.iso_8859-1 in this case).
Examples
========
As an example for fully supporting a specific language you may
download the Greek tarball:
http://lynxx.org/misc/download/vim-6.1-menu_el.zip
http://lynxx.org/misc/download/vim-6.1-menu_el.tgz
See also VimTip "Vim goes Greek - Complete set of Greek language
support for Vim 6.1" (VimTip#).
Disclaimer
==========

http://www.vim.org/tips/tip.php?tip_id=546 (8 of 9) [18/02/2004 15:05:14]

Tip #546 - Vim goes INTL - Translating Messages, Menus, Encodings : vim online

This document is freely redistributable, but I take no


liability for the correctness and safety of any procedures or
advice given here. This document is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY, explicit or
implied for the MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
Happy PO-MO-ing!
Vangelis Eustratius
vangelise@lynxx.org

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Vim goes Greek - Greek language support for Vim 6.1 | Smarter Table Editing >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=546 (9 of 9) [18/02/2004 15:05:14]

SourceForge
Logo

Tip #545 - Vim goes Greek - Greek language support for Vim 6.1 : vim online

not logged in (login)

Home
Search

Tip #545: Vim goes Greek - Greek language support for Vim 6.1
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating 5/2, Viewed by 407

created: August 27, 2003 12:27


author: Vangelis E

complexity: intermediate
as of Vim: 5.7

Vim goes Greek - Complete set of Greek language support for Vim 6.1
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Scripts
Tips
My Account

ENGLISH TEXT
------------

Site Help

This is the full set of messages, menus and encodings to


be used to support Greek language. This set contains:
vim.pot
-- dummy portable
object template for
vim-6.1 (can be used
with any language)
vim.po
-- the above vim.pot
file with strings
translated in Greek
lang/el/LC_MESSAGES/vim.mo
-- the Greek vim.po
file formatted in
machine object mode
(vim.mo)
lang/menu_gr_gr.greek.vim
-- Greek used as
the default encoding
lang/menu_gr_gr.latin1.vimq
-- Greek for Latin
lang/menu_gr_gr.iso_8859-1.vim
-- Latin-based ISO
encoding sourceing
from iso_8859-7 spec
lang/menu_gr_gr.iso_8859-7.vim
-- Greek-Latinbased
ISO encoding
lang/menu_greece_greek.737.vim -- MS-DOS/wINDOWS codepage
for Greek (737)
lang/menu_greek_greece.1253.vim -- MS-DOS/wINDOWS codepage
for Greek (1253)
lang/menu_greek_greece.cp437.vim
-- Unix CodePage for
Greek
(nl_cp437)
lang/menu_gr_gr.utf-8.vim
-- UTF-8 for Greek
tutor/tutor.gr -- Vim TUTOR in Greek
README.TXT -- this file
These compressed archives can be downloaded from:
http://lynxx.org/misc/download/vim-6.1-menu_el.zip

http://www.vim.org/tips/tip.php?tip_id=545 (1 of 4) [18/02/2004 15:05:26]

Tip #545 - Vim goes Greek - Greek language support for Vim 6.1 : vim online

http://lynxx.org/misc/download/vim-6.1-menu_el.tgz
To use Vim to edit in Greek (or any) language, we first enable
the language option for the keyboard (Control
Panel|Keyboard|Languages|Greek) and enable a key sequence
(e.g. Ctrl-Shift) to toggle between the default language and
Greek. In Vim the Greek language is displayed correcty.
Finally, we unzip vim-6.1-menu_el to the vim61 directory. This
ensures that the above files are place in the correct path. If
you don't know how to extract to $VIMRUNTIME, unzip to any
temporary folder. Then drag&drop or copy-and-paste each of the
above files to its place after creating the container folders
(/path/to/vim61/lang/el).
This is what one may call manual extraction, so please wash your
hands beforehand.
For help on setting up Vim to support Greek -- from Vim do:
:help language
:help messages
:help encoding
For messages you'll have to set at least:
let $LANG='el' / let $LANG='gr'
:lan mes el / :lan mes gr
For menus:
:menut English Greek / let menut=Greek
from the cmdline or in the _vimrc file.
For more information see VimTip #
"Vim goes INTL Translating Vim Editor Messages, Menus, Encodings".
Enjoy Vim a la Greek!

GREEK TEXT
---------Vim - Vim 6.1
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
,
Vim 6.1.
:
++++++++++++
vim.pot --
vim-6.1 (

http://www.vim.org/tips/tip.php?tip_id=545 (2 of 4) [18/02/2004 15:05:26]

Tip #545 - Vim goes Greek - Greek language support for Vim 6.1 : vim online


vim.po -- vim.pot

.
lang/el/LC_MESSAGES/vim.mo
-- vim.po

(vim.mo)
lang/menu_gr_gr.greek.vim
-- Greek


lang/menu_gr_gr.latin1.vimq
-- Latin
lang/menu_gr_gr.iso_8859-1.vim
-- ISO

,
iso_8859-7
lang/menu_gr_gr.iso_8859-7.vim
-- ISO

-
lang/menu_greece_greek.737.vim -- MS-DOS/wINDOWS
(737)
lang/menu_greek_greece.1253.vim -- MS-DOS/wINDOWS
(1253)
lang/menu_greek_greece.cp437.vim
-- Unix
(nl_cp437)
lang/menu_gr_gr.utf-8.vim
-- UTF-8
tutor/tutor.gr -- Vim
README.TXT --
:
http://lynxx.org/misc/download/vim-6.1-menu_el.zip
http://lynxx.org/misc/download/vim-6.1-menu_el.tgz
Vim
( ,
( ||
|) (.. )

. Vim .
, vim-6.1-menu_el vim61.

. $VIMRUNTIME,
. --
--

(///vim61/lang/el).

http://www.vim.org/tips/tip.php?tip_id=545 (3 of 4) [18/02/2004 15:05:26]

Tip #545 - Vim goes Greek - Greek language support for Vim 6.1 : vim online

,
.
Vim
, Vim, :
:help language
:help messages
:help encoding
Vim.
:
let $LANG='el' / let $LANG='gr'
:lan mes el / :lan mes gr
:
:menut English Greek / let menut=Greek
_vimrc.
, VimTip # ("Vim goes INTL Translating Vim Editor Messages, Menus, Encodings").
Kales epejergasies keimenou!
Vaggelis Efstratiou
vangelise@lynxx.org
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Vim goes Greek - Greek language support for Vim 6.1 | Vim goes INTL - Translating Messages, Menus, Encodings >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=545 (4 of 4) [18/02/2004 15:05:26]

SourceForge
Logo

http://www.vim.org/tips/tip.php?tip_id=544

not logged in (login)

Home
Search

Tip #544: Vim goes Greek - Greek language support for Vim 6.1
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating 4/1, Viewed by 236

created: August 27, 2003 12:26


author: Vangelis E

complexity: intermediate
as of Vim: 5.7

Vim goes Greek - Complete set of Greek language support for Vim 6.1
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Scripts
Tips
My Account

ENGLISH TEXT
------------

Site Help

This is the full set of messages, menus and encodings to


be used to support Greek language. This set contains:
vim.pot -- dummy portable
object template for
vim-6.1 (can be used
with any language)
vim.po -- the above vim.pot
file with strings
translated in Greek
lang/el/LC_MESSAGES/vim.mo -- the Greek vim.po
file formatted in
machine object mode
(vim.mo)
lang/menu_gr_gr.greek.vim -- Greek used as
the default encoding
lang/menu_gr_gr.latin1.vimq -- Greek for Latin
lang/menu_gr_gr.iso_8859-1.vim -- Latin-based ISO
encoding sourceing
from iso_8859-7 spec
lang/menu_gr_gr.iso_8859-7.vim -- Greek-Latin-based
ISO encoding
lang/menu_greece_greek.737.vim -- MS-DOS/wINDOWS codepage
for Greek (737)
lang/menu_greek_greece.1253.vim -- MS-DOS/wINDOWS codepage
for Greek (1253)
lang/menu_greek_greece.cp437.vim-- Unix CodePage for Greek
(nl_cp437)
lang/menu_gr_gr.utf-8.vim -- UTF-8 for Greek
tutor/tutor.gr -- Vim TUTOR in Greek
README.TXT -- this file
These compressed archives can be downloaded from:
http://lynxx.org/misc/download/vim-6.1-menu_el.zip
http://lynxx.org/misc/download/vim-6.1-menu_el.tgz

http://www.vim.org/tips/tip.php?tip_id=544 (1 of 4) [18/02/2004 15:05:30]

http://www.vim.org/tips/tip.php?tip_id=544

To use Vim to edit in Greek (or any) language, we first enable


the language option for the keyboard (Control
Panel|Keyboard|Languages|Greek) and enable a key sequence
(e.g. Ctrl-Shift) to toggle between the default language and
Greek. In Vim the Greek language is displayed correcty.
Finally, we unzip vim-6.1-menu_el to the vim61 directory. This
ensures that the above files are place in the correct path. If
you don't know how to extract to $VIMRUNTIME, unzip to any
temporary folder. Then drag&drop or copy-and-paste each of the
above files to its place after creating the container folders
(/path/to/vim61/lang/el).
This is what one may call manual extraction, so please wash your
hands beforehand.
For help on setting up Vim to support Greek -- from Vim do:
:help language
:help messages
:help encoding
For messages you'll have to set at least:
let $LANG='el' / let $LANG='gr'
:lan mes el / :lan mes gr
For menus:
:menut English Greek / let menut=Greek
from the cmdline or in the _vimrc file.
For more information see VimTip #
"Vim goes INTL Translating Vim Editor Messages, Menus, Encodings".
The present document was posted as VimTip # and can be viewed
online at:
http://www.vim.org/tips/tip.php?tip_id=
Enjoy Vim a la Greek!

GREEK TEXT
---------Vim - Vim 6.1
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
,
Vim 6.1.
:
++++++++++++
vim.pot --
http://www.vim.org/tips/tip.php?tip_id=544 (2 of 4) [18/02/2004 15:05:30]

http://www.vim.org/tips/tip.php?tip_id=544

vim-6.1 (


vim.po -- vim.pot

.
lang/el/LC_MESSAGES/vim.mo
-- vim.po

(vim.mo)
lang/menu_gr_gr.greek.vim
-- Greek


lang/menu_gr_gr.latin1.vimq
-- Latin
lang/menu_gr_gr.iso_8859-1.vim
-- ISO

,
iso_8859-7
lang/menu_gr_gr.iso_8859-7.vim
-- ISO

-
lang/menu_greece_greek.737.vim -- MS-DOS/wINDOWS
(737)
lang/menu_greek_greece.1253.vim -- MS-DOS/wINDOWS
(1253)
lang/menu_greek_greece.cp437.vim
-- Unix
(nl_cp437)
lang/menu_gr_gr.utf-8.vim
-- UTF-8
tutor/tutor.gr -- Vim
README.TXT --
:
http://lynxx.org/misc/download/vim-6.1-menu_el.zip
http://lynxx.org/misc/download/vim-6.1-menu_el.tgz
Vim
( ,
( ||
|) (.. )

. Vim .
, vim-6.1-menu_el vim61.

. $VIMRUNTIME,
. --
--

http://www.vim.org/tips/tip.php?tip_id=544 (3 of 4) [18/02/2004 15:05:30]

http://www.vim.org/tips/tip.php?tip_id=544


(///vim61/lang/el).
,
.
Vim
, Vim, :
:help language
:help messages
:help encoding
Vim.
:
let $LANG='el' / let $LANG='gr'
:lan mes el / :lan mes gr
:
:menut English Greek / let menut=Greek
_vimrc.
, VimTip # ("Vim goes INTL Translating Vim Editor Messages, Menus, Encodings").
VimTip #
:
http://www.vim.org/tips/tip.php?tip_id=
Kales epejergasies keimenou!
Vaggelis Efstratiou
vangelise@lynxx.org
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<vim.po - Internationalizing the Vim editor | Vim goes Greek - Greek language support for Vim 6.1 >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=544 (4 of 4) [18/02/2004 15:05:30]

SourceForge
Logo

Error : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Vim Online Error

Couldn't find tip 0. Are you sure it exists?

Scripts
Tips
My Account
Site Help

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id [18/02/2004 15:05:33]

SourceForge
Logo

Tip #543 - vim.po - Internationalizing the Vim editor : vim online

not logged in (login)

Home
Search

Tip #543: vim.po - Internationalizing the Vim editor


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/1, Viewed by 332

created: August 27, 2003 12:22


author: Vangelis E.

complexity: basic
as of Vim: 5.7

vim.po - Internationalizing the Vim editor


+++++++++++++++++++++++++++++++++++++++++++
For a given vim-###-src#.tar.gz release there is only
one
vim.po file that can be created for translation
purposes.
However, this vim.po is not unique since several options
may
be set while extracting with `xgettext', depending
mostly on
the format of comments. For your convenience you can
download
a standard vim.pot to use as a translation template for
vim-6.1 to most any language(s):
http://lynxx.org/misc/download/vim-6.1-pot.tgz
This is the general template for translating messages in
Vim 6.1
using the Xgettext format. It contains all English
messages in
the (untranslated) form:
msgid "ABC" - English text
msgstr "" - canditate language
To translate Vim 6.1 messages, proceed line-by-line,
taking
care not to translate commands and options specific to
the
editor. See the GNU `gettext' man-page for more info
and
details on this.
This vim.pot should be used only with v. 6.1 to
translate to
any language.

http://www.vim.org/tips/tip.php?tip_id=543 (1 of 2) [18/02/2004 15:05:36]

Tip #543 - vim.po - Internationalizing the Vim editor : vim online

When Vim versions advance, a standard vim.po must be


created
from the newer sources, as delineated in the next VimTip
"Vim
goes INTL - Translating Vim Editor Messages, Menus, and
Encodings' (VimTip#).
You may also want to download a complete set in Greek to
use as
an example of full support for a specific language:
http://lynxx.org/misc/download/vim-6.1-menu_el.zip
http://lynxx.org/misc/download/vim-6.1-menu_el.tgz
Happy Intl-ing!
Vangelis Eustratius
vangelise@lynxx.org
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Edit remote files locally via SCP/RCP/FTP | Vim goes Greek - Greek language support for Vim 6.1
>>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=543 (2 of 2) [18/02/2004 15:05:36]

SourceForge
Logo

Tip #542 - Edit remote files locally via SCP/RCP/FTP : vim online

not logged in (login)

Home
Search

Tip #542: Edit remote files locally via SCP/RCP/FTP


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 66/21, Viewed by 1176

created: August 27, 2003 11:10


author: Roberto

complexity: intermediate
as of Vim: 6.0

I'm frequently editing files remotely, but if the


network traffic is tight, then a normal VIM session
turns into a tortuous event. The solution to that was
right under my nose: VIM's Network-Oriented File
Transfers (:help netrw).
Instead of editing the file remotely, it can be
transfered from the host server, to a local copy, edited
and then sent back when done. I know that you can do
this manually, but it's a hassle, besides, if it can be
done automatically, why not go for that? :)
Assuming you have the following installed and properly
configured:
1. VIM
2. netrw.vim (afaik comes in all recent vim installs)
3. scp, rcp, ftp or ftp+
Then to use, all you need to go is specify the protocol,
user, host and path to the file you want to edit:
vim scp://konimi@vim.org//var/www/html/rtc_functions.php
gvim scp://konimi@vim.org//var/www/html/tips/add_tip.php
Every time you write the file (:w etc.) the file will
get copied over to the source and you will be brought
back to your session for further editing.
If you already have an open session, then just issue the
following commands:
To read/load up a file: :Nread
scp://konimi@vim.org//var/www/html/rtc_functions.php
To write the file back: :Nwrite
scp://konimi@vim.org//var/www/html/rtc_functions.php
That's it! You'll be editing at local speed.

http://www.vim.org/tips/tip.php?tip_id=542 (1 of 2) [18/02/2004 15:05:39]

Tip #542 - Edit remote files locally via SCP/RCP/FTP : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<How to get help using VIM | vim.po - Internationalizing the Vim editor >>

Additional Notes
rob@machorro.net, August 27, 2003 11:18
Soon after I had posted this item, I stumbled into
http://www.vim.org/tips/tip.php?tip_id=337 from Matthew
Weier O'Phinney. Don't want to post a similar Tip so as
soon as I figure out how to delete this Tip, I will.
cec@NdjOinnSi.gPsfAc.nMasa.gov, August 27, 2003 12:53
There's no way to delete a tip, sorry to say.
<netrw.vim> also supports rsync, fetch, dav, and rcp.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=542 (2 of 2) [18/02/2004 15:05:39]

SourceForge
Logo

Tip #541 - How to get help using VIM : vim online

not logged in (login)

Home
Search

Tip #541: How to get help using VIM


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 17/8, Viewed by 920

created: August 23, 2003 13:32


author: Hate_Silly_Tips

complexity: basic
as of Vim: 5.7

If you need help with vim and do not know where to go.
Check out the Community link on the left. Or click this
link
http://vim.sourceforge.net/community.php

rate this tip

Life Changing

Helpful

Unfulfilling

rate

Site Help
<<vim6.2 or vim6.1? | Edit remote files locally via SCP/RCP/FTP >>

Additional Notes
zzapper@ntlworld.com, August 23, 2003 15:53
also
http://groups.google.com/groups?group=comp.editors
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=541 [18/02/2004 15:05:42]

SourceForge
Logo

Tip #548 - Using H and L keys as context sensitive pagedown/pageup : vim online

not logged in (login)

Home
Search

Tip #548: Using H and L keys as context sensitive pagedown/pageup


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 19/7, Viewed by 672

created: September 2, 2003 20:26


author: Usman Latif

complexity: basic
as of Vim: 5.7

The H and L keys move the cursor to the top or bottom of


the window
respectively. They can be a real time saver, instead of
hitting j/k many times,
a single H/L can move the cursor to the proper place.
However, when you are
already at the top of the window the H key does nothing
and similarly at the
bottom of the window the L key does nothing.
I started using the H/L keys a few days ago and quickly
discovered that after
getting to the top using H, I often want to scroll up.
Hitting H again does
nothing, so I wrote a function Hcontext which makes the
H key context
sensitive. I then mapped Hcontext to the H key. Now
hitting the H key anywhere
other than at the top of the window leads to the usual
behavior but hitting H
at the first line of the window causes the window to
scroll one page back and
positions the cursor at the top of the window. Similar
behavior is implemented
by the Lcontext function but in the other direction.
Hitting L on the last line
of the window now acts like the pagedown key.
Even if you have never used the H/L keys before you can
now start using them
as replacement pagedown/pageup keys. Just cut and paste
the code at the end
into your vimrc and put the following maps after that.
noremap H :call Hcontext()<CR>
noremap L :call Lcontext()<CR>
The unmapped H and L keys take a numeric count as well.

http://www.vim.org/tips/tip.php?tip_id=548 (1 of 5) [18/02/2004 15:05:45]

Tip #548 - Using H and L keys as context sensitive pagedown/pageup : vim online

Unfortunately, I am not
aware of a way to make that count available to the user
functions I wrote. The
typical vim behavior in case of user functions is to
supply the count as a
range to the user function. This works most of the time
but sometimes the count
gets rejected because of range checking. If you are
aware of a workaround
please let me know.
You can contact me by writing to latif@techuser.net. If
you have suggestions as
to other keys that can be made context sensitive without
affecting their
original function, email me. I also maintain a webpage
where you can ask help
for your text processing problems. The webpage is at
http://www.techuser.net
---------------------------------Cut Here--------------------------------------func! Hcontext()
if (winline() == 1 && line(".") != 1)
exe "normal! \<pageup>H"
else
exe "normal! H"
endif
echo ''
endfunc
func! Lcontext()
if (winline() == winheight(0) && line(".") !=
line("$"))
exe "normal! \<pagedown>L"
else
exe "normal! L"
endif
echo ''
endfunc
---------------------------------Cut Here--------------------------------------rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Smarter Table Editing | Switching normal and insert-mode disturbes cursorposition >>

Additional Notes
http://www.vim.org/tips/tip.php?tip_id=548 (2 of 5) [18/02/2004 15:05:45]

Tip #548 - Using H and L keys as context sensitive pagedown/pageup : vim online

johann-guenter.simon@linde-le.com, September 3, 2003 9:22


My suggestion for improvement is to take care of the
scrolloff option
My modification of the function:
---------------------------------Cut Here--------------------------------------func! Hcontext()
if (winline() == &so+1 && line(".") != 1)
exe "normal! \<PageUp>H"
else
exe "normal! H"
endif
echo ''
endfunc
func! Lcontext()
if (winline() == winheight(0)-&so && line(".") !=
line("$"))
exe "normal! \<PageDown>L"
else
exe "normal! L"
endif
echo ''
endfunc
---------------------------------Cut Here---------------------------------------

sreny@svergbc.pbz (rot13ed), September 8, 2003 2:12


I thought these tips were pretty handy so I converted
it to a plugin for my own use, Thank you both.
Aformentioned plugin is vimscript #763
latif@techuser.net, September 9, 2003 17:38
I found some problems with the original implementation
of the two
functions. The functions don't work when the bottom or
top line is longer
than window width and is spread over multiple window
lines. The cursor
needs to be on the top or bottom-most window-line to
work correctly.
I fixed the problem and the new code, updated to
incorporate suggestions
from Klaus Bosau, is given below. However, there is one
http://www.vim.org/tips/tip.php?tip_id=548 (3 of 5) [18/02/2004 15:05:45]

Tip #548 - Using H and L keys as context sensitive pagedown/pageup : vim online

case where the


functions don't work. This case occurs when a count is
supplied that will
take the cursor to a line that is not visible. The
proper behavior is to do
nothing, but the code below instead does a
pagedown/pageup. In practice
I don't expect this behavior to be a problem for
anyone. Ofcourse, if you
have a workaround you are more than welcome to submit
it.
--------------------------------------------------------------------------map <silent> H :<C-U>call HContext()<CR>
map <silent> L :<C-U>call LContext()<CR>
func! HContext()
let moved = MoveCursor("H")
if !moved && line('.') != 1
exe "normal! " . "\<pageup>H"
endif
endfunc
func! LContext()
let moved = MoveCursor("L")
if !moved && line('.') != line('$')
exe "normal! " . "\<pagedown>L"
endif
endfunc
func! MoveCursor(key)
let cnum = col('.')
let lnum = line('.')
let wline = winline()
exe "normal! " . v:count . a:key
let moved = cnum != col('.') || lnum != line('.')
|| wline != winline()
return moved
endfunc
--------------------------------------------------------------------------Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=548 (4 of 5) [18/02/2004 15:05:45]

SourceForge
Logo

Tip #548 - Using H and L keys as context sensitive pagedown/pageup : vim online

http://www.vim.org/tips/tip.php?tip_id=548 (5 of 5) [18/02/2004 15:05:45]

Tip #549 - Switching normal and insert-mode disturbes cursorposition : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #549: Switching normal and insert-mode disturbes


cursorposition
tip karma

Rating -2/2, Viewed by 648

created: September 3, 2003 13:38


author: MikeTheGuru

complexity: intermediate
as of Vim: 6.0

I've found that switching from insert-mode to normal


mode (by <ESC>) and back to insert mode (by <INS>) will
move the cursor 1 position to the left (Try it: open any
file with some long line, put the cursor into it and
alternatively press <ESC> and <INS>...).
Furthermore, you cannot distinguish between position 1
(insert-cursor before the 1st character) and position 2
(insert-cursor after 1st character).
Enter the following small function and source it:
:function! EchoCursor()
echo "-->" . col(".") . "<--"
" assume you will replace characters starting at current
position...
:endfun
and map it to an unsed key (I've used A-F12):
:map <A-F12> :call EchoCursor()<CR>
:imap <A-F12> <esc>:call EchoCursor()<CR>
While A-F12 will work fine in normal mode, it won't work
correct in insert-mode: you get a "1" if the cursor is
before or after the 1st character (compare it with the
statusline!).
But when mapping
:imap <A-F12> <right><esc>:call EchoCursor()<CR>
you will get different (and correct) positions.

rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=549 (1 of 2) [18/02/2004 15:05:48]

Helpful

Unfulfilling

rate

Tip #549 - Switching normal and insert-mode disturbes cursorposition : vim online

<<Using H and L keys as context sensitive pagedown/pageup | FreeBSD Fix: Arrow keys/cursor
movement prints A B C D letters on remote shell: xterm, vt100. >>

Additional Notes
latif@techuser.net, September 3, 2003 17:42
Vim provides the <C-O> combination to invoke functions
from insert mode. You can use the following mapping:
imap <A-F12> <C-O>:call EchoCursor()<CR>
The above will report the correct cursor position and
also leave the cursor in insert mode. You might have
trouble viewing the echo message as it will be quickly
replaced. You can use the getchar() function to make
vim wait and let you see the echo message.

yeti@physics.muni.cz, September 6, 2003 0:14


please search existing tips before adding a new one -see vimtip #459
Anonymous, September 11, 2003 3:47
Thx for your notes...
But I haven't found any documentation or help
concerning <c-o>? Where did you learn this?
cec@NgrOyphSon.gPsfAc.nMasa.gov, September 29, 2003 9:46
:he i_ctrl-o
i_ -- help with insertmode stuff
ctrl-o -- the actual key we want help for
You'll also find a brief mention under

:he inserting

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=549 (2 of 2) [18/02/2004 15:05:48]

SourceForge
Logo

Tip #550 - FreeBSD Fix: Arrow keys/cursor movement prints A B C D letters on remote shell: xterm, vt100. : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #550: FreeBSD Fix: Arrow keys/cursor movement prints A B C D


letters on remote shell: xterm, vt100.
tip karma

Rating 52/20, Viewed by 704

created: September 5, 2003 3:44


author: VT

complexity: basic
as of Vim: 6.0

Hi,
I wonder how many of you are pissed of with arrow keys
behavior during INSERT mode in Vim.
So was I.
Leave all the key mappings default, do not change your
TERM environment.
Here's a simple tip,
:set term=cons25 and save the settings for Vim usage.
It was tested with Vim 5.8 and 6.1 editions on; FreeBSD
4.X-STABLE; xterm(-color),VT100 remote terminals; (t)csh
shells.
Greets.
Peace.
Legalize it.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Switching normal and insert-mode disturbes cursorposition | automatic indenting XML file in VIM
with the help of XSLT >>

Additional Notes
cat@eecs.harvard.edu, September 25, 2003 17:07

http://www.vim.org/tips/tip.php?tip_id=550 (1 of 2) [18/02/2004 15:05:51]

Tip #550 - FreeBSD Fix: Arrow keys/cursor movement prints A B C D letters on remote shell: xterm, vt100. : vim online

This doesn't really work very well for me on SunOS -- I


have the same problem but :set term=cons25 just gives
me OC everywhere before each character until I
redraw. Weird.
But, :set term=ansi works great, and the arrow keys
work.
A better solution is to, while in vi, type in insert
mode [ctrl-v][arrow up] and see what you get.
Then, in your .vimrc, add the lines
set t_ku=[ctrl-v][esc]OA
# or whatever you saw
so it ends up looking something like
set t_ku=^[OA
set t_kd=^[OB
set t_kr=^[OC
set t_kl=^[OD
(though you want REAL escape chars instead of ^[.)
Anonymous, October 2, 2003 9:15
Well, as I wrote, it's FreeBSD workaround, not SunOS's.
Regards,
VT
Anonymous, October 2, 2003 9:21
(...)
And in addition, set term=ansi makes syntax color off
in vim (afair FreeBSD with color xterm).
VT
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=550 (2 of 2) [18/02/2004 15:05:51]

SourceForge
Logo

Tip #551 - automatic indenting XML file in VIM with the help of XSLT : vim online

not logged in (login)

Home
Search

Tip #551: automatic indenting XML file in VIM with the help of XSLT
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/6, Viewed by 846

created: September 5, 2003 16:16


author: yijun@cs.toronto.edu

complexity: advanced
as of Vim: 5.7

Do you want to indent an XML file? Try the following XSLT:


---------------------------------------- name it indent.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">;
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
---------------------------------------In VIM, whenever a file with the ".xml" extension is loaded
into the buffer, you can try the following
in your ~/.vimrc to trigger the XSLT for filtering on the
buffer contents:
---------------------------------------if version >= 540
augroup filetype
autocmd FileType xml '[,']!xsltproc indent.xsl %
augroup END
endif
" other autocmds
if version>540
autocmd!
endif
---------------------------------------Voila! Next time when you load an XML file in VIM, it will be
indented automatically.
Cheers,

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<FreeBSD Fix: Arrow keys/cursor movement prints A B C D letters on remote shell: xterm, vt100. | replace buffer
list when switching >>

http://www.vim.org/tips/tip.php?tip_id=551 (1 of 3) [18/02/2004 15:05:54]

Tip #551 - automatic indenting XML file in VIM with the help of XSLT : vim online

Additional Notes
anon@hello.com, September 6, 2003 13:21
What is xsltproc?
fs111@linuxmail.org, September 7, 2003 7:21
It is a command line tool and it is part of the gnome libxslt.
Look at their website for more information:
http://xmlsoft.org/XSLT.html
regards Andr
nil@nil.com, September 11, 2003 7:19
Yep, using an XSLT which copies the document (not the file) is
a common way to get pretty-printed XML.
Here are some more tips, variations, and alternatives:
http://www.pinkjuice.com/howto/vimxml/tasks.xml#prettyprinting
and
http://www.pinkjuice.com/howto/vimxml/setup.xml#xsltlint
Tobi
joey@neuralyte.org, October 2, 2003 18:50
If you don't have a copy of XSLT, you can use the following to
indent XML/HTML:
:%s/></>\r</g
:0
=:$
Anonymous, October 28, 2003 11:15
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">;
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
Anonymous, October 28, 2003 11:15

http://www.vim.org/tips/tip.php?tip_id=551 (2 of 3) [18/02/2004 15:05:54]

Tip #551 - automatic indenting XML file in VIM with the help of XSLT : vim online

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">;
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=551 (3 of 3) [18/02/2004 15:05:54]

SourceForge
Logo

Tip #552 - replace buffer list when switching : vim online

not logged in (login)

Home
Search

Tip #552: replace buffer list when switching


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download

Rating 3/3, Viewed by 454

created: September 9, 2003 7:26


author: Mark Stosberg

complexity: basic
as of Vim: 5.7

I use vim's session file feature a lot to switch between


projects. Preserving all that context is nice. Usually
my process goes like this:

Scripts
Tips
My Account

1. Save the current session:


:mks! ~/v/project1.vim

Site Help

2. Quit vim
:xa
3. Restart with different session file:
vim -S ~/v/project2.vim
I was exiting and re-opening vim because if I just
loaded the second project file, a list of /both/
projects buffers would appear in my buffer list. This
was not what I wanted-- I wanted to replace the first
buffer list completely wtih the second.
There is a simple way to do this.
At the top of a session file, add this:
1,999bdelete
That will delete the first 999 existing buffers,
effectively allowing any new buffer definitions in the
rest of the session file to replace
what is currently there. Now you can switch directly to
a new session without exiting. Just use:
:so ~/v/project2.vim

rate this tip

Life Changing

Helpful

Unfulfilling

<<automatic indenting XML file in VIM with the help of XSLT | Prev and Next >>

http://www.vim.org/tips/tip.php?tip_id=552 (1 of 2) [18/02/2004 15:05:57]

rate

Tip #552 - replace buffer list when switching : vim online

Additional Notes
of(AT)oersted(DOT)dtu(DOT)dk, September 10, 2003 0:22
Instead of
1,999bdelete
which deletes 'only' buffers 1 to 999 (which is
sufficient in most cases), you can easily write
%bdelete
which deletes ALL buffers.
jkr@jottkaerr.de, September 10, 2003 23:34
This won't always work.
%bdelete
only deletes as many buffers as there are lines in the
current buffer.
vim@torrin.net, September 11, 2003 16:17
How about this . . .
:execute "1," . bufnr("$") . "bdelete"
That should delete all the buffers. When I say delete,
it will only unlist them. The check this execute the
above command then run this command.
:ls!
akawaka@nospam.skynet.ie, October 8, 2003 21:29
Is there anyway to reset the buffer index numbers?
After switching between two or three sessions for a
while the buffer numbers can become pretty large.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=552 (2 of 2) [18/02/2004 15:05:57]

SourceForge
Logo

Tip #553 - Prev and Next : vim online

not logged in (login)

Home
Search

Tip #553: Prev and Next


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 34/12, Viewed by 885

created: September 10, 2003 10:02


author: pmf

complexity: basic
as of Vim: 5.7

One of the most useful key combinatins that remain


unknown to the masses are <C-o> and <C-i>.
They work like the "back" and "next" arrows in your HTTP
user agent, meaning you can jump back and back again
between files/locations within the same file very very
easily and comfortable.
:jumplist

for a list of possible locations.

Try it.
Use it.
Have a nice day.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<replace buffer list when switching | Smarter Table Editing II >>

Additional Notes
better.not@11101010010101001000101010110110100101001.101,
September 10, 2003 10:06

:jumps

not

:jumplist

And: the list is a history of files/positions in files


you recently visted.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=553 [18/02/2004 15:06:00]

SourceForge
Logo

Tip #584 - Awesome text formatter : vim online

not logged in (login)

Tip #584: Awesome text formatter

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 45/15, Viewed by 2465

created: October 10, 2003 14:16


author: mosh@cs.abany.edu

complexity: basic
as of Vim: 5.7

The berkeley program 'par' can format/justify


text/c-comments (examples below) better (and much more)
than
the default unix formatters.
Download from: http://www.cs.berkeley.edu/~amc/Par/

Usage:
Select region and press <A-q> to format.
In ~/_vimrc put (-j is for justify lines)
:set formatprg=par\ -w60
: map <A-q> {v}!par -jw60<CR>
:vmap <A-q> !par -jw60<CR>
Examples from par.man
Before:
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*

We the people of the United States, */


in order to form a more perfect union, */
establish justice, */
insure domestic tranquility, */
provide for the common defense, */
promote the general welfare, */
and secure the blessing of liberty */
to ourselves and our posterity, */
do ordain and establish the Constitution */
of the United States of America. */

After "par -59":

in

/*
We the people of the United States,
*/
/* order to form a more perfect union, establish

*/
/* justice, insure domestic tranquility, provide
http://www.vim.org/tips/tip.php?tip_id=584 (1 of 12) [18/02/2004 15:06:06]

Tip #584 - Awesome text formatter : vim online

*/
/* for the common defense, promote the general
*/
/* welfare, and secure the blessing of liberty
*/
/* to ourselves and our posterity, do ordain
*/
/* and establish the Constitution of the
United */
/* States of
America.
*/
Or after "par -59f":
/*
/*
/*
/*
/*
/*
/*
/*
/*

We the people of the United States,


in order to form a more perfect union,
establish justice, insure domestic
tranquility, provide for the common
defense, promote the general welfare,
and secure the blessing of liberty to
ourselves and our posterity, do ordain
and establish the Constitution of the
United States of America.

*/
*/
*/
*/
*/
*/
*/
*/
*/

Or after "par -59l":

in

/*
We the people of the United States,
*/
/* order to form a more perfect union, establish

*/
/* justice, insure domestic tranquility,
*/
/* provide for the common defense, promote
*/
/* the general welfare, and secure the
*/
our
the

/* blessing of liberty to ourselves and


*/
/* posterity, do ordain and establish
*/
/* Constitution of the United States of America.

*/
Or after "par -59lf":
/*
/*
/*
/*
/*

We the people of the United States,


in order to form a more perfect union,
establish justice, insure domestic
tranquility, provide for the common
defense, promote the general welfare,

http://www.vim.org/tips/tip.php?tip_id=584 (2 of 12) [18/02/2004 15:06:06]

*/
*/
*/
*/
*/

Tip #584 - Awesome text formatter : vim online

/*
/*
/*
/*

and secure the blessing of liberty


to ourselves and our posterity, do
ordain and establish the Constitution
of the United States of America.

*/
*/
*/
*/

Or after "par -59lft0":


/*

We the people of the United States,

*/
/* in order to form a more perfect
union,
*/
/* establish justice, insure
domestic
*/
/* tranquility, provide for the common
*/
/* defense, promote the general welfare,
*/
/* and secure the blessing of
liberty
*/
/* to ourselves and our posterity,
do
*/
/* ordain and establish the Constitution
*/
/* of the United States of
America.
*/
Or after "par -59j":
/*

We

the people

of

the

United States,

in

*/
/* order to form a more perfect union, establish
*/
/* justice, insure domestic tranquility, provide
*/
/* for the

common defense, promote

the general

*/
/* welfare, and

secure the blessing

of liberty

*/
/* to ourselves and our posterity, do ordain and
*/
/* establish

the

Constitution

of

the

United

*/
/* States of
America.

*/

Or after "par -59jl":


/*

We

the

people

of

order

to

form

the

United

States,

more

perfect

*/
/* in

http://www.vim.org/tips/tip.php?tip_id=584 (3 of 12) [18/02/2004 15:06:06]

Tip #584 - Awesome text formatter : vim online

*/
/* union,

establish

justice,

insure

domestic

*/
/* tranquility, provide for

the common defense,

*/
/* promote

the

general

welfare,

and

secure

*/
/* the

blessing

of

/* our

posterity, do

liberty to

ourselves

and

*/
ordain and

establish the

*/
/* Constitution of the United States of America.
*/
Before:
Preamble

We the people of the United

to the US
Constitution

in order to form
a more perfect union,
establish justice,
insure domestic tranquility,
provide for the common defense,
promote the general welfare,
and secure the blessing of liberty
to ourselves and our posterity,
do ordain and establish
the Constitution
of the United States of America.

States,

After "par -52h3":


Preamble
to the US
Constitution

We the people of the United


States, in order to form a
more perfect union, establish
justice, insure domestic
tranquility, provide for the
common defense, promote the
general welfare, and secure
the blessing of liberty to
ourselves and our posterity,
do ordain and establish the
Constitution of the United
States of America.

Before:
1
2
3

We the people of the United States,


in order to form a more perfect union,
establish justice,

http://www.vim.org/tips/tip.php?tip_id=584 (4 of 12) [18/02/2004 15:06:06]

Tip #584 - Awesome text formatter : vim online

4
5
6
7
8
9
10

insure domestic tranquility,


provide for the common defense,
promote the general welfare,
and secure the blessing of liberty
to ourselves and our posterity,
do ordain and establish the Constitution
of the United States of America.

After "par -59p12l":


1

We the people of the United States, in order

form a more perfect union, establish

3
4
5

insure domestic tranquility, provide for the


common defense, promote the general welfare,
and secure the blessing of liberty to

to
justice,

ourselves
6

and our posterity, do ordain and establish

Constitution of the United States of

the
America.
Before:
>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>

We the people
of the United States,
in order to form a more perfect union,
establish justice,
ensure domestic tranquility,
provide for the common defense,

Promote the general welfare,


and secure the blessing of liberty
to ourselves and our posterity,
do ordain and establish
the Constitution of the United States of

America.
After "par -52":
>
>
>
>
>
>
>
>
>

>
>
>
>
>

We the people of the United States, in


order to form a more perfect union,
establish justice, ensure domestic
tranquility, provide for the common
defense,

Promote the general welfare, and secure


the blessing of liberty to ourselves and
our posterity, do ordain and establish

http://www.vim.org/tips/tip.php?tip_id=584 (5 of 12) [18/02/2004 15:06:06]

Tip #584 - Awesome text formatter : vim online

> the Constitution of the United States of


> America.
Before:
>
>
>
>
>
>
>
>
>
>
>

We the people
of the United States,
in order to form a more perfect union,
establish justice,
ensure domestic tranquility,
provide for the common defense,
Promote the general welfare,
and secure the blessing of liberty
to ourselves and our posterity,
do ordain and establish
the Constitution of the United States of

America.
After "par -52d":
>
>
>
>
>
>
>
>
>
>

We the people of the United States,


in order to form a more perfect union,
establish justice, ensure domestic
tranquility, provide for the common
defense,
Promote the general welfare, and secure
the blessing of liberty to ourselves and
our posterity, do ordain and establish
the Constitution of the United States of
America.

Before:
#
#
#
#
#
#
#
#
#
#

1. We the people of the United States.


2. In order to form a more perfect union.
3. Establish justice, ensure domestic
tranquility.
4. Provide for the common defense
5. Promote the general welfare.
6. And secure the blessing of liberty
to ourselves and our posterity.
7. Do ordain and establish the Constitution.
8. Of the United States of America.

After "par -37p13dh":


# 1. We the people of the
#
United States.
# 2. In order to form a more
#
perfect union.
# 3. Establish justice,
http://www.vim.org/tips/tip.php?tip_id=584 (6 of 12) [18/02/2004 15:06:06]

Tip #584 - Awesome text formatter : vim online

#
#
#
#
#
#
#
#
#
#
#
#
#

4.
5.
6.

7.
8.

ensure domestic
tranquility.
Provide for the common
defense
Promote the general
welfare.
And secure the blessing
of liberty to ourselves
and our posterity.
Do ordain and establish
the Constitution.
Of the United States of
America.

Before:
/*****************************************/
/*
We the people of the United States, */
/* in order to form a more perfect union, */
/* establish justice, insure domestic
*/
/* tranquility,
*/
/*
*/
/*
*/
/*
[ provide for the common defense, ] */
/*
[ promote the general welfare,
] */
/*
[ and secure the blessing of liberty ] */
/*
[ to ourselves and our posterity, ] */
/*
[
] */
/*
*/
/* do ordain and establish the Constitution */
/* of the United States of America.
*/
/******************************************/
After "par -42r":
/********************************/
/*
We the people of the
*/
/* United States, in order to
*/
/* form a more perfect union,
*/
/* establish justice, insure
*/
/* domestic tranquility,
*/
/*
*/
/*
*/
/*
[ provide for the common ] */
/*
[ defense, promote the
] */
/*
[ general welfare, and
] */
/*
[ secure the blessing of ] */
/*
[ liberty to ourselves
] */
/*
[ and our posterity,
] */
/*
[
] */
http://www.vim.org/tips/tip.php?tip_id=584 (7 of 12) [18/02/2004 15:06:06]

Tip #584 - Awesome text formatter : vim online

/*
*/
/* do ordain and establish the */
/* Constitution of the United
*/
/* States of America.
*/
/********************************/
Or after "par -42re":
/********************************/
/*
We the people of the
*/
/* United States, in order to
*/
/* form a more perfect union,
*/
/* establish justice, insure
*/
/* domestic tranquility,
*/
/*
*/
/*
[ provide for the common ] */
/*
[ defense, promote the
] */
/*
[ general welfare, and
] */
/*
[ secure the blessing of ] */
/*
[ liberty to ourselves
] */
/*
[ and our posterity,
] */
/*
*/
/* do ordain and establish the */
/* Constitution of the United
*/
/* States of America.
*/
/********************************/
Before:
Joe Public writes:
> Jane Doe writes:
> >
> >
> > I can't find the source for uncompress.
> Oh no, not again!!!
>
>
> Isn't there a FAQ for this?
>
>
That wasn't very helpful, Joe. Jane,
just make a link from uncompress to compress.
After "par -40q":
Joe Public writes:
> Jane Doe writes:
>
>
> > I can't find the source for
http://www.vim.org/tips/tip.php?tip_id=584 (8 of 12) [18/02/2004 15:06:06]

Tip #584 - Awesome text formatter : vim online

> > uncompress.


>
> Oh no, not again!!!
>
>
> Isn't there a FAQ for this?
>
That wasn't very helpful, Joe.
Jane, just make a link from
uncompress to compress.
Or after "par 40qe":
Joe Public writes:
>
>
>
>
>
>
>
>

Jane Doe writes:


> I can't find the source for
> uncompress.
Oh no, not again!!!
Isn't there a FAQ for this?

That wasn't very helpful, Joe.


Jane, just make a link from
uncompress to compress.
Or after "par -40qi":
Joe Public writes:
> Jane Doe writes:
> >
> >
> > I can't find the source for
> > uncompress.
> Oh no, not again!!!
>
>
> Isn't there a FAQ for this?
>
>
That wasn't very helpful, Joe.
Jane, just make a link from
uncompress to compress.
Or after "par -40qie":
Joe Public writes:
> Jane Doe writes:
http://www.vim.org/tips/tip.php?tip_id=584 (9 of 12) [18/02/2004 15:06:06]

Tip #584 - Awesome text formatter : vim online

> > I can't find the source for


> > uncompress.
> Oh no, not again!!!
>
> Isn't there a FAQ for this?
That wasn't very helpful, Joe.
Jane, just make a link from
uncompress to compress.
Before:
I sure hope there's still room
in Dr. Jones' section of archaeology.
I've heard he's the bestest. [sic]
After "par -50g":
I sure hope there's still room in
Dr. Jones' section of archaeology.
heard he's the bestest. [sic]

I've

Or after "par -50gc":


I sure hope there's still room in
Dr. Jones' section of archaeology.
heard he's the bestest. [sic]

I've

Before:
John writes:
: Mary writes:
: + Anastasia writes:
: + > Hi all!
: + Hi Ana!
: Hi Ana & Mary!
Please unsubscribe me from alt.hello.
After "par Q+:+ q":
John writes:
:
:
:
:
:
:
:
:
:

Mary writes:
+ Anastasia writes:
+
+ > Hi all!
+
+ Hi Ana!
Hi Ana & Mary!

http://www.vim.org/tips/tip.php?tip_id=584 (10 of 12) [18/02/2004 15:06:06]

Tip #584 - Awesome text formatter : vim online

Please unsubscribe me from alt.hello.


Before:
amc> The b option was added primarily to deal
with
amc>
amc>
released.
amc>
amc>
characters.
amc>
the prefix.
amc>

this new style of quotation


which became popular after Par 1.41 was

Par still pays attention to body


Par should not mistake "Par" for part of
Par should not mistake "." for a suffix.

After "par B=._A_a 50bg":


amc>
amc>
amc>
amc>
amc>
amc>
amc>
amc>
amc>

The b option was added primarily to


deal with this new style of quotation
which became popular after Par 1.41
was released.
Par still pays attention to body
characters. Par should not mistake
"Par" for part of the prefix. Par
should not mistake "." for a suffix.

rate this tip

Life Changing

Helpful

Unfulfilling

<<Vim as XML Editor | Keymap for normal mode >>

Additional Notes
faugn@despammed.com, October 12, 2003 3:00
http://www.nicemice.net/par/
aldy0169@yahoo.com, October 16, 2003 12:18
set equalprg=par
visually select an area and hit '='
ykhov@uwaterloo.ca, October 24, 2003 16:19

http://www.vim.org/tips/tip.php?tip_id=584 (11 of 12) [18/02/2004 15:06:06]

rate

Tip #584 - Awesome text formatter : vim online

I'm using par -w78 option right now and loves it.
Anybody know the option for par to leave double spaces
after each sentences?
Anonymous, November 26, 2003 10:16
Most of what I can see here can be done with built-in
commands as well. See "=", "gq" for instance...
Anonymous, December 5, 2003 5:20
see also fmt(1) on a BSD System
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=584 (12 of 12) [18/02/2004 15:06:06]

SourceForge
Logo

Tip #585 - Keymap for normal mode : vim online

not logged in (login)

Home
Search

Tip #585: Keymap for normal mode


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/10, Viewed by 816

created: October 12, 2003 16:51


author: Bjrn Michaelsen

complexity: basic
as of Vim: 6.0

I generated a keymap for the vim 6.X normal mode on a


german keyboard layout.
Keymaps for other layouts may follow, if someone tells
me about how they look.
The keymap is here:
http://michaelsen.kicks-ass.net/bjoern/keymap.pdf
The author may be contacted here:
bjoern@michaelsen.kicks-ass.net
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Awesome text formatter | Smarter Pasting >>

Additional Notes
fs111@linuxmail.org, October 13, 2003 3:38
The server is down, has someone a copy to share?
Andr
Anonymous, October 13, 2003 7:22
Server should be available again.
It is just a private server with dynamic DNS on DSL.
Feel free to publish the file elsewherean a more
reliable server, but please put a link here.
Greetz, Bjrn
P.S.: Corrections and Additions are welcome!
Add Note

http://www.vim.org/tips/tip.php?tip_id=585 (1 of 2) [18/02/2004 15:06:09]

Tip #585 - Keymap for normal mode : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=585 (2 of 2) [18/02/2004 15:06:09]

SourceForge
Logo

Tip #586 - Smarter Pasting : vim online

not logged in (login)

Home
Search

Tip #586: Smarter Pasting


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/14, Viewed by 1490

created: October 13, 2003 13:42


author: Usman Latif

complexity: basic
as of Vim: 5.7

Frequently I yank a few words or part of a line and like


to have them pasted on a separate line. Vim provides the
put and put! commands for that purpose but they are not
mapped by default to anything. Typing the commands is
much slower than inserting a line and pasting to it so I
have created the following maps:
nnoremap ,p :pu "<CR>
nnoremap ,P :pu! "<CR>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Keymap for normal mode | Preview current file in Mozilla through localhost >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=586 [18/02/2004 15:06:12]

SourceForge
Logo

Tip #587 - Preview current file in Mozilla through localhost : vim online

not logged in (login)

Home
Search

Tip #587: Preview current file in Mozilla through localhost


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -1/3, Viewed by 1029

created: October 14, 2003 20:30


author: Mark Woodward

complexity: intermediate
as of Vim: 5.7

This is something I 'discovered' whilst trying to


preview html or php files in mozilla using the apache
server locally.
Put the path as the first line of a file wrapped in the
appropriate comments.
eg: php:
<?php //
http://localhost/examples/chapter02/vieworders2.php ?>
eg html:
<!-- http://localhost/examples/chapter02/orderform.html ->
Place the following mappings in your .vimrc file
" Typing <S-F12> will open the file in moz through the
server.
nmap <S-F12> :sil! !start mozilla "<cfile>"<CR>
imap <S-F12> <esc>:sil! !start mozilla "<cfile>"<CR>i
As I'm working through Wellings PHP and MySQL Web
Development I can use my tokens plugin to speed creating
the first line as follows:
Add these as the string parts of the array:
(for php)
"phpf <?php //
http://localhost/examples/chapter chapter?
/ file name .php ?>"
(for html)
"htmlf <!-http://localhost/examples/chapter chapter?
/ file name .html -->"
then on the first line of the file if I type phpf
<leader>et I'll only have to enter the chapter number
and the filename without the extension.
eg
04<cr> orders<cr>

http://www.vim.org/tips/tip.php?tip_id=587 (1 of 3) [18/02/2004 15:06:16]

Tip #587 - Preview current file in Mozilla through localhost : vim online

This will insert:


<?php // http://localhost/examples/chapter04/orders.php
?>
Place the cursor anywhere on the file path, <S-F12> and
the file will load (through apache) in moz.
Hope someone finds this useful,
Mark
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Smarter Pasting | How to sort using visual blocks >>

Additional Notes
markwoodwardATbigpond.com, October 14, 2003 20:38
I'd be interested if there's a way to open in a new tab
in moz rather than a new window? Or even open in the
current window (replacing the old page). Does anyone
have any suggestions?
-Mark
fs111@linuxmail.org, October 18, 2003 4:40
Try something like this:
mozilla -remote 'openURL(http://www.vim.org, new-tab)'
HTH
Andr
antoine.mechelynck@belgacom.net, October 30, 2003 12:49
A related piece of info for Windows:
start filename.ext
(in the shell) "opens" the named file with its default
action. This means, for instance, that
:w | ! start %
(in Vim with the cursor on an html file) will save the
current file, then open it in your default browser. On
my system, it opens a new Dos Box and a new Netscape 7
http://www.vim.org/tips/tip.php?tip_id=587 (2 of 3) [18/02/2004 15:06:16]

Tip #587 - Preview current file in Mozilla through localhost : vim online

window. The Dos box must be closed by <Enter> to return


to Vim. You may leave the browser window open if you
like (for instance, after you next make some changes
and save the file, click "Reload" or press Ctrl-R in
the browser to see the new version).
Beware: The space between ! and start is necessary (if
I leave it out, I get Vimm error E371).
Regards,
Tony.
s.vanslyck@spamcop.net, December 21, 2003 13:44
I don't know what "S-" means in "<S-F12>" - does it
mean Shift-F12 possibly?
ste[delete]pta[metoo]n at hot[andme]mai[last]ldot com, January 8, 2004 20:19
Yes, S is shift.
M is alt
C is ctrl
Examples:
<F9>
<M-F9>
<C-F9>

: just press F9
: press alt and F9
: press ctrl and F9

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=587 (3 of 3) [18/02/2004 15:06:16]

SourceForge
Logo

Tip #588 - How to sort using visual blocks : vim online

not logged in (login)

Home
Search

Tip #588: How to sort using visual blocks


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 20/8, Viewed by 1361

created: October 16, 2003 9:08


author: Charles E. Campbell

complexity: basic
as of Vim: 6.0

1. To sort lines based on a visually-selected column:


Check out
http://www.erols.com/astronaut/vim/index.html#VimFuncs ;
look under "Visual Block Sorting". It uses Piet
Delport's
vim-based binary insertion sort and some vim-glue to
provide
visual-block sorts!
To enable it, put <bisort.vim> into your <.vim/plugin>
directory.
To then perform sorting based on a visual-block
selection
(ctrl-v):
:'<,'>Vissort
2. To sort a visually-selected block (and leave the text
outside the
block in place):
Check out
http://www.erols.com/astronaut/vim/index.html#VimFuncs ;
look under "Visual Block Commands". The <vis.vim>
plugin
provides a command which allows other commands to be
applied
only to the visually selected block.
To then perform sorting of just a visual-block (ctrl-v):
:'<,'>B !sort
Or, using Piet Delport's binary insertion sort:
:'<,'>B Bisort

http://www.vim.org/tips/tip.php?tip_id=588 (1 of 2) [18/02/2004 15:06:18]

Tip #588 - How to sort using visual blocks : vim online

Examples:
Original, visual-block select the central column
one
two
three
four five
six
seven eight nine
ten
eleven twelve
:'<,'>Vissort
seven eight nine
ten
eleven twelve
four five
six
one
two
three
:'<,'>B !sort
one
eight three
four eleven six
seven five
nine
ten
two
twelve
:'<,'>B Bisort
one
eight three
four eleven six
seven five
nine
ten
two
twelve
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Preview current file in Mozilla through localhost | Vim as refactoring tool (with examples in C#) >>

Additional Notes
NdrOchip@ScampbellPfamily.AbizM - NOSPAM, January 22, 2004 7:33
vissort has been updated to version 3: it now has
BlockSort() which permits one
to sort blocks of text based on tags contained within
them.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=588 (2 of 2) [18/02/2004 15:06:18]

SourceForge
Logo

Tip #589 - Vim as refactoring tool (with examples in C#) : vim online

not logged in (login)

Home
Search

Tip #589: Vim as refactoring tool (with examples in C#)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 42/22, Viewed by 2084

created: October 16, 2003 9:52


author: Klaus Horsten

complexity: intermediate
as of Vim: 6.0

You can use vim as a refactoring tool.


The advantages are:
1. You automatisate repetitive writing tasks
2. You learn refactoring
You can expect much from a refactoring tool but if you
have a look at the
commercial refactoring tools there is much (not all!)
vim can do too.
Whatever your opinion is, my experience is that vim
helps to refactor.
I give you three examples, all in C#.
Example 1:
Anti-sphagetti code weapon or the "Extract Method"
refactoring.
Sphagetti code example:
public string CreateMenu(string startMenu,string file)
{
string strOutput = "";
int i = 0;
ArrayList startArray = new ArrayList();
string strVariable = "";
string strTemp = "";
XmlDocument XMLDoc = new XmlDocument();
try {
XMLDoc.Load(file);
}
catch (Exception e)
{
strOutput = e.GetBaseException().ToString();

http://www.vim.org/tips/tip.php?tip_id=589 (1 of 7) [18/02/2004 15:06:22]

Tip #589 - Vim as refactoring tool (with examples in C#) : vim online

return strOutput;
}
XmlNodeList nodeList =
XMLDoc.DocumentElement.ChildNodes;
...
Imagine 50 lines of code here.
Use the "extract method refactoring" to make a "composed
method".
I use a vim function (see below) to build the exracted
method.
I highlight the code part I want to extract and press
\em (for e-xtract m-ethod).
A dialog appears and asks me how to name the new method.
I type in "GetXmlDocumentFrom" and do get this:
// = GetXmlDocumentFrom();
private GetXmlDocumentFrom()
{
XmlDocument XMLDoc = new XmlDocument();
try {
XMLDoc.Load(file);
}
catch (Exception e)
{
strOutput = e.GetBaseException().ToString();
return strOutput;
}
// return ;
}
Now I have time to think what parameters the method
needs and what to return.
I end up with the following function and
the original function:

remove it from

private XmlDocument GetXmlDocumentFrom(string XmlFile)


{
XmlDocument XMLDoc = new XmlDocument();
string strOutput = "";
try
{
XMLDoc.Load(XmlFile);

http://www.vim.org/tips/tip.php?tip_id=589 (2 of 7) [18/02/2004 15:06:22]

Tip #589 - Vim as refactoring tool (with examples in C#) : vim online

}
catch (Exception e)
{
strOutput = e.GetBaseException().ToString();
ErrorMessage(strOutput);
}
return XMLDoc;
}
In the original code I put two lines.
XmlDocument XMLDoc = new XmlDocument();
XMLDoc = GetXmlDocumentFrom(XmlFile);
So I reduced the original code for 8 lines and made it
clearer what the code does.
I do this with the rest of the code again and again.
Since the class gets bloated because of the many new
methods I later will use
the "Extract Class" refactoring to put this method in an
own XmlDocument-class.
This has the advantage that our new function is also
available for other
similar purposes.
I will create the new class also with the help of vim,
the actual extracting of
the method into the new class is just a matter of copy &
paste.
Here is the vim-code:
vmap \em :call ExtractMethod()<cr>
function! ExtractMethod() range
let name = inputdialog("Name of new method:")
'<
exe "normal O\<bs>private " . name ."()\<cr>{\<esc>"
'>
exe "normal oreturn ;\<cr>}\<esc>k"
s/return/\/\/ return/ge
normal j%
normal kf(
exe "normal yyPi// = \<esc>wdwA;\<esc>"
normal ==
normal j0w
endfunction

http://www.vim.org/tips/tip.php?tip_id=589 (3 of 7) [18/02/2004 15:06:22]

Tip #589 - Vim as refactoring tool (with examples in C#) : vim online

Example 2:
The "Self Encapsulate Field" refactoring.
I have heard a programmer who just uses Visual Studio
(nothing against Visual
Studio, it's a great tool!) say: "I do not use
properties. It's too much
work." He just uses fields instead.
With vim it is no problem to write a property, id est to
use the "Self
Encapsulate Field" refactoring.
I write a name e.g. "Name" press CTRL-C CTRL-P CTRL-S (create p-roperty with
s-tring). Voila, the new property appears in just a
second:
private string m_Name;
public string Name
{
get
{
return m_Name;
}
set
{
m_Name = value;
}
}
Here are the vim mappings and the underlying function:
"Create property
imap <C-c><C-p><C-s> <esc>:call
CreateProperty("string")<cr>a
imap <C-c><C-p><C-i> <esc>:call
CreateProperty("int")<cr>a
function! CreateProperty(type)
exe "normal bim_\<esc>b\"yywiprivate ".a:type."
\<esc>A;\<cr>public ".a:type."
\<esc>\"ypb2xea\<cr>{\<esc>oget\<cr>{\<cr>return
\<esc>\"ypa;\<cr>}\<cr>set\<cr>{\<cr>\<tab>\<esc>\"yPa =
value;\<cr>}\<cr>}\<cr>\<esc>"
normal 12k2wi
endfunction
You can combine Visual Studio and vim. You can work in
Visual Studio and load
http://www.vim.org/tips/tip.php?tip_id=589 (4 of 7) [18/02/2004 15:06:22]

Tip #589 - Vim as refactoring tool (with examples in C#) : vim online

the file in vim for refactoring. I have made a menu


entry in Visual Studio that
loads the actual file I am writing in vim (cf. Tip #580
http://vim.sourceforge.net/tips/tip.php?tip_id=580).

Example 3:
The "Replace Conditional with Polymorphism" refactoring.
Imagine a switch and you want to replace it with an
abstract class and some
concrete classes which inherit from this parent class.
You may think "Why should I replace this switch? It's
too much work. Writing
all these classes ..."
With vim it's just a question of a few seconds.
To build the abstract class I type, say "Fruit".
Then I press CTRL-C CTRL-A CTRL-C (c-reate a-bstract class) and get
public abstract class Fruit
{
public abstract void |();
}
| means the Cursor position.
Now I fill in the methods.
public
{
public
public
public
}

abstract class Fruit


abstract void Taste();
abstract void Color();
abstract string GetSize();

Now I go on the first letter of "Fruit" and type CTRL-C


CTRL-C CTRL-C (c-reate c-oncrete c-lass).
A dialog appears and asks me for the new name of the
concrete class. I type in Apple and get
public class Apple : Fruit
{
public override void Taste()
{
}
http://www.vim.org/tips/tip.php?tip_id=589 (5 of 7) [18/02/2004 15:06:22]

Tip #589 - Vim as refactoring tool (with examples in C#) : vim online

public override void Color()


{
}
public override string GetSize()
{
}
}
I continue doing so with all the child classes of the
abstract class.
In this way I get code templates that I can implement
now.
Here are my mappings and the underlying funtion.
"Create abstract class
imap <C-c><C-a><C-c> <esc>bipublic abstract class
<esc>A<cr>{<cr>public abstract void
X();<cr>}<esc>:?X<cr>0fXs
"Create concrete class
map <C-c><C-c><C-c> :silent! call
ImplementAbstractClass()<cr>
function! ImplementAbstractClass() range
exe "normal \<esc>\"yyw"
/{
normal "xy%
normal %o
exe "normal \<esc>o"
let name = inputdialog("Name of new method:")
exe "normal ipublic class " .name." : \<esc>\"yp\"xp"
exe "normal }O}\<esc>=="
normal %v%
normal gv
'<,'>s/abstract/override/g
normal gv
'<,'>s/;/\r{\r}\r/g
normal ==
normal %kdd%k
endfunction
Happy vimming ... and happy refactoring!
Klaus

http://www.vim.org/tips/tip.php?tip_id=589 (6 of 7) [18/02/2004 15:06:22]

Tip #589 - Vim as refactoring tool (with examples in C#) : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<How to sort using visual blocks | Using vim to send mail on windows >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=589 (7 of 7) [18/02/2004 15:06:22]

SourceForge
Logo

Tip #590 - Using vim to send mail on windows : vim online

not logged in (login)

Home
Search

Tip #590: Using vim to send mail on windows


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -9/9, Viewed by 1316

created: October 22, 2003 3:17


author: Stanislav Sitar

complexity: basic
as of Vim: 5.7

The question of using Vim for writing email messages


with
Vim on windows was raised many times.
Finally there *is* an elegant solution.
go to
http://sylpheed-claws.sourceforge.net/win32/
and download
sylpheed-0.9.6claws.exe
Install an application
go to menu
configuration -> Common preferences
go to tab Other
and fill something like
c:\Progra~1\Vim\vim62b\gvim.exe -f "%s"
(depending on where your Vim is installed)
as the the editor option
The -f option is very important so Vim does not fork.
You might also go to Compose tab and select
Automatically launch an external editor.
Tada.......
Beware
Sylphed-Claws is a bleeding edge software.
Have a nice time
Stano
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Vim as refactoring tool (with examples in C#) | Have a nice and easy use of plugins >>

http://www.vim.org/tips/tip.php?tip_id=590 (1 of 2) [18/02/2004 15:06:26]

Tip #590 - Using vim to send mail on windows : vim online

Additional Notes
hermitte {at} free {dot} fr, October 22, 2003 15:38
Are you sure about the "-f" flag ? So far, I've never
seen this flag do anything under windows. That's why I
use mutt compiled for cygwin with the win32 version of
Vim.
Anonymous, October 22, 2003 22:27
You wrote "Finally there *is* an elegant solution", but
there is *many* solutions: at random Mahogany
http://mahogany.sf.net (excellent one) or pine (great,
ever great) or ...use google ;-)
Kartik Agaram, October 23, 2003 10:12
Let me get this right - you want me to switch to a
whole new email client just so that I can change its
default editor to something else. Not just vim *anything*. How is this a vim tip, exactly??
hermitte {at} free {dot} fr, October 24, 2003 1:49
You are unfair. I think this is an interresting thing
to know when we are to decide which MUA to install and
use.
When considering which tool to use (IDE, MUA, newsreader, etc.), I often check if I will be able to use
an external editor (which is Vim of course).
Anonymous, November 26, 2003 10:09
PC-Pine offers an external-editor-feature too.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=590 (2 of 2) [18/02/2004 15:06:26]

SourceForge
Logo

Tip #591 - Have a nice and easy use of plugins : vim online

not logged in (login)

Home
Search

Tip #591: Have a nice and easy use of plugins


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/3, Viewed by 826

created: October 24, 2003 4:44


author: Jean-Christophe Clavier

complexity: intermediate
as of Vim: 6.0

Are you tired of hundreds of mappings and functions that


pollute your .vimrc ? Do you want to
nicely organize your customization to quickly find what
you search ? Perhaps is it time for you to
consider the use of plugins (if it is not already done).
Plugins are really easy to do and provide a simple way
to organize functions and mappings. They are
automaticaly loaded
Here is an example of simple and very short plugin that
provides a command MyCommand that saves the
selected text in the file passed in parameter.
I don't know if the function is useful but the example
show the parameter passing, the
autocompletion and the use of ranges in a function.
Autocompletion is very practical to help to remember the
commands you defined. It is often a
problem to remember all the mappings you've done so it
may be faster to type your command than to
remember the mapping you've chosen.
Using user-commands allows you to use mappings only when
it is absolutely pertinent
------------------ file MyPlugin.vim ---------------------" save 'cpo'
let s:cpo_save = &cpo
set cpo&vim
" To Edit the Plugin
nnoremap <F12> :e $VIMRUNTIME/plugins/MyPlugin.vim
" To reload the plugin if you modify it
nnoremap <S-F12> :so $VIMRUNTIME/plugins/MyPlugin.vim
" It is very interesting to define commands to call your
functions because you can then use

http://www.vim.org/tips/tip.php?tip_id=591 (1 of 4) [18/02/2004 15:06:29]

Tip #591 - Have a nice and easy use of plugins : vim online

" autocompletion and other features you cannot use for


usual functions
if !exists(':MyCommand')
command -range=% -nargs=1 -complete=file MyCommand
<line1>,<line2>call s:MyCommandFunction(<f-args>)
endif
" the ! allows you to modify the function and reload the
plugin. It will be your new version that
" will be considered
function! s:MyCommandFunction(...) range
split
execute "norm " . a:firstline . "GV"
execute "norm " . a:lastline . 'G"ay'
enew
norm "ap
exe "sav! " . a:1
q
endfunction
" restore 'cpo'
let &cpo = s:cpo_save
unlet s:cpo_save
---------------------End of file ------------------------commented version of the function :
function! s:MyCommandFunction(...) range
" create a temporary window
split
" select and copy the lines in the range passed
(a:firstline and a:lastline are the vim
" variables for the first and the last lien of the
range
execute "norm " . a:firstline . "GV"
execute "norm " . a:lastline . 'G"ay'
" create a new file and paste
enew
norm "ap
" saves the file with the name passed in parameter
" exe executes the string passed as a command
" a:1 is the first parameter (if you have more, a:2,
a:3. a:0 gives you the number of parameter
" passed
exe "sav! " . a:1
" quit the temporary window
q
endfunction

http://www.vim.org/tips/tip.php?tip_id=591 (2 of 4) [18/02/2004 15:06:29]

Tip #591 - Have a nice and easy use of plugins : vim online

Of course you can separate your functions in different


plugins (one for the mapping, one for the
functions...
You can use prefix to classify your functions and use
the autocompletion more efficiently.
Where to find help on these subjects
General considerations on plugins
:help plugins
How to create a user-command and how to use the
parameters (-range, -nargs, -complete...)
:help user-commands
How to program vim
:help eval.txt
all the buildin functions
:help functions
How to define a function
:help user-functions
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Using vim to send mail on windows | Smart <Home> and <End> keymaps >>

Additional Notes
hermitte {at}free {dot} fr, October 24, 2003 15:18
I definitively agree that plugins are a must -- AFAIK,
ftplugins are the major improvment of Vim over Vi.
However, I have a few remarks:
- You forget the anti-reinclusion guards,
- You can propose a way to override the default
mappings you propose in your plugin -- check vimtip#147
that is a must-read
- You'd better always use ":normal!" and "*noremap"
instead of ":normal" and ":*map". We are never sure of
mappings defined into other plugins.
hermitte {at} free {dot} fr, October 24, 2003 15:24

http://www.vim.org/tips/tip.php?tip_id=591 (3 of 4) [18/02/2004 15:06:29]

Tip #591 - Have a nice and easy use of plugins : vim online

I almost forget.
If you want the exact path of the current plugin:
let s:file = expand('<sfile>:p')
nnoremap <silent> <s-12> :silent exe 'source '.s:file
But a better solution is to rely on ":runtime".
BTW, $VIMRUNTIME is not really meant to be polluted
with our own scripts.
jcclavier@free.fr, October 28, 2003 6:16
These are useful remarks that show that this Tip is not
complete.
It is only a first step to make minimal plugins that
will be ok for self use.
It's aim is rather to show the interest of plugins and
user-commands than to give the best method to develop
plugins to be distributed (vimtip#147 is much better
for that).
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=591 (4 of 4) [18/02/2004 15:06:29]

SourceForge
Logo

Tip #592 - Smart <Home> and <End> keymaps : vim online

not logged in (login)

Home
Search

Tip #592: Smart <Home> and <End> keymaps


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 23/10, Viewed by 753

created: October 26, 2003 2:30


author: Fabio G. Strozzi

complexity: basic
as of Vim: 5.7

I found interesting the way <Home> and <End> keys act in some editors
and I wondered why try not
carry it out with Vim.
Put the following lines in your ~/.vimrc and so <Home> will move the
cursor between the first column and
the first non-blank character. <End> is similar but work at the end of
the line.
I think this should be very useful to the indented code and trailing
characters.
let g:home_key = '0'
let g:end_key = '$'
function ToggleHome()
exe "normal! \<Esc>".g:home_key
let g:home_key = g:home_key == '0'? '^' : '0'
endfunction
function ToggleEnd()
exe "normal! \<Esc>".g:end_key
let g:end_key = g:end_key == '$'? 'g_' : '$'
endfunction
inoremap
nnoremap
inoremap
nnoremap

<silent>
<silent>
<silent>
<silent>

rate this tip

<Home> <Esc>:call ToggleHome()<CR>i


<Home> :call ToggleHome()<CR>
<End> <Esc>:call ToggleEnd()<CR>a
<End> :call ToggleEnd()<CR>

Life Changing

Helpful

Unfulfilling

rate

<<Have a nice and easy use of plugins | basic postfix abbreviations >>

Additional Notes
hermitte {at} free {dot} fr, October 26, 2003 12:26
This mapping is not very handy as it is does take the position of the
cursor into account.
The function you are looking for is available here into a plugin that
define some key bindings inspired by VC++, and as a standalone into:
http://hermitte.free.fr/vim/ressources/vimfiles/plugin/homeLikeVC++.vim
It will be easy to fix the mapping for <end> as well.

http://www.vim.org/tips/tip.php?tip_id=592 (1 of 2) [18/02/2004 15:06:32]

Tip #592 - Smart <Home> and <End> keymaps : vim online


Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=592 (2 of 2) [18/02/2004 15:06:32]

SourceForge
Logo

Tip #593 - basic postfix abbreviations : vim online

not logged in (login)

Home
Search

Tip #593: basic postfix abbreviations


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 12/6, Viewed by 550

created: October 26, 2003 3:24


author: leadhyena_inrandomtan

complexity: basic
as of Vim: 6.0

I'm learning VIM in order to be more competitive in


online programming competitions where speed of accurate
typing is a factor. This may be a basic tip for some
more advanced VIM users out there. I'm very used to
editors that provide prefix abbreviation expansion; for
example, in jEdit I'd type FA,array,<C-ENTER> in order
to make a basic for loop that scanned the array. I
wanted this in VIm as well, but found that it was harder
to program. When I discovered that I could use a postfix
abbreviation instead of a prefix one, I realized that I
really didn't need any programming, but rather a long
:ab statement like this:
"this is for java, c++,c# can reshape as necessary
:ab ff <ESC>^d$ifor(int
i=0;i<<ESC>pi.length;i++){<CR><CR>}//end for loop over
array <ESC>pi[i]<ESC>==k==k==ji<TAB>
this way, if I need a loop over the array lines[] then I
would type
lines<SPACE>ff<SPACE> and vim would transform this into
(with proper indentation)
for(int i=0;i<lines.length;i++){
<CURSOR>
}//end for loop over array lines[i]
similar abreviations with multiple arguments could be
delimited by spaces and could be yanked into multiple
registers and plunked down as necessary. You could even
use a similar structure to writing abbreviations in
jEdit. But, this opens up possibilities for many
different things, because VIM allows you to map real
commands into the abbreviations, instead of just vanilla
text like in jEdit.

http://www.vim.org/tips/tip.php?tip_id=593 (1 of 2) [18/02/2004 15:06:35]

Tip #593 - basic postfix abbreviations : vim online

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Smart <Home> and <End> keymaps | Lookup javadoc HTML help from vim >>

Additional Notes
nrdean@purdue.edu, October 26, 2003 5:36
word of warning, I gave a dangerous example.
abbreviations expand on any word break, so don't use
just for as your abbreviation name. Use something that
doesn't come up in syntax, like Xfor or qqfor.
Sreny@SverGbc.Pbz (Rot13ed), October 27, 2003 17:19
I thought this such an interesting idea and that I like
the post decision to expand I hacked togther vimscript
#804.
It is a quicky but might be useful.
Neat tip, thank you :)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=593 (2 of 2) [18/02/2004 15:06:35]

SourceForge
Logo

Tip #594 - Lookup javadoc HTML help from vim : vim online

not logged in (login)

Home
Search

Tip #594: Lookup javadoc HTML help from vim


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -3/3, Viewed by 622

created: October 28, 2003 14:06


author: vim_power

complexity: basic
as of Vim: 6.0

Do you use VIM for lot of Java Coding, but miss the feature
of looking up
javadoc help like some other Java based IDEs ?
Well I have written I plugin to do just that, right now its
in an infant state, but
can lookup javadoc html of a java Class, from VIM
get it at
http://vim.sourceforge.net/scripts/script.php?script_id=801
Please leave any comments , notes, feature request on this
tip or
email me at vim_power@yahoo.com
thanks
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<basic postfix abbreviations | suppressing file changed warnings in a specific buffer >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=594 [18/02/2004 15:06:40]

SourceForge
Logo

Tip #595 - suppressing file changed warnings in a specific buffer : vim online

not logged in (login)

Home
Search

Tip #595: suppressing file changed warnings in a specific buffer


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/1, Viewed by 248

created: October 29, 2003 11:34


author: Adam Wolff

complexity: intermediate
as of Vim: 5.7

I generally liked the warnings that VIM gives when a


file changes outside of the editor. However, there are
times when I want to run a shell command that changes
the buffer, and I don't want to hear about it.
I've come up with the following convoluted method to do
this, but if there's a better way, I'd love to know.
function ChangeThisBuffer
"set an environment variable to current buffer name
let $aucfile = expand( "%" )
"add autocmd which only applies to this buffer which
removes itself once it runs once
autocmd FileChangedShell $aucfile autocmd!
FileChangedShell $aucfile
execute( 'silent !mycommand' )
endfunction
One problem with this approach is that if the shell
command fails, or doesn't really change the file, then
you won't be notified the <b>next</b> time it changes.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Lookup javadoc HTML help from vim | Insert location of the currently edited file >>

Additional Notes
Sreny@SverGbc.Pbz (Rot13ed), October 30, 2003 1:51

http://www.vim.org/tips/tip.php?tip_id=595 (1 of 2) [18/02/2004 15:06:43]

Tip #595 - suppressing file changed warnings in a specific buffer : vim online

UNTESTED, but this sounds like it would work/is what


you are after.
:h 'autoread'
function ChangeThisBuffer
setlocal autoread
execute( 'silent !mycommand' )
set autoread<
endfunction
Hope it helps anyway.
Gary Johnson <garyjohn@spk.agilent.com>, October 30, 2003 11:38
To avoid the problem with the autocommand not being
removed, you could
explicity remove it in the function instead of relying
on the
autocommand itself to do so. Here's what I have in
some of my
functions:
checktime
exe "au FileChangedShell " . expand("%") . " let
&cpo = &cpo"
" Do stuff to the file.
checktime
exe "au! FileChangedShell " . expand("%")
The "let &cpo = &cpo" command is just a convenient noop.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=595 (2 of 2) [18/02/2004 15:06:43]

SourceForge
Logo

Tip #596 - Insert location of the currently edited file : vim online

not logged in (login)

Home
Search

Tip #596: Insert location of the currently edited file


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 1/1, Viewed by 410

created: October 30, 2003 0:53


author: Max Ischenko

complexity: basic
as of Vim: 5.7

With
:imap <C-r>@ <C-r>=expand("%:p:h")<cr>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<suppressing file changed warnings in a specific buffer | indet a code block - >i{ >>

Site Help

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=596 [18/02/2004 15:06:46]

SourceForge
Logo

Tip #597 - indet a code block - >i{ : vim online

not logged in (login)

Home
Search

Tip #597: indet a code block - >i{


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 122/41, Viewed by 1257

created: October 30, 2003 1:43


author: Marcel Preda

complexity: intermediate
as of Vim: 6.0

Let's say we have:


// some code
{ // start block
//some other code
// HERE IS THE CURSOR
// other code
} // end block
The command ">i{" will indent the current block of
lines, inside {}.
The { and } are unmodified.
The ">a{" will modify also the { } lines.
"<i{" will shift to the left (let's say UNindent).
Similar "<a{"
Hope this helps.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Insert location of the currently edited file | (PHP) on line help >>

Additional Notes
hermitte {at} free {dot} fr, October 30, 2003 11:26
With the indent options correctly defined, =% works
just fine ...
none@nowhere, October 31, 2003 11:25
Holy crap, these are very good tips. Both the original
and the = tip. visual = just made my day! Thanks.
don@seiler.us, January 14, 2004 7:45
You are truly the king of kings.
http://www.vim.org/tips/tip.php?tip_id=597 (1 of 2) [18/02/2004 15:06:50]

Tip #597 - indet a code block - >i{ : vim online

catalin (at) isp-software (dot) de, February 14, 2004 7:12


This has been one of the greatest tips; saved me a lot
of >> typings
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=597 (2 of 2) [18/02/2004 15:06:50]

SourceForge
Logo

Tip #598 - (PHP) on line help : vim online

not logged in (login)

Home
Search

Tip #598: (PHP) on line help


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 66/21, Viewed by 902

created: October 30, 2003 2:08


author: Macel Preda

complexity: basic
as of Vim: 5.7

Hi,
vim is my favorite; so, I use it for .php file.
Very often I need the php manual to see the parametrs
order for functions.
Unitl a month ago I always opened a browser and gone to
http://http://ro.php.net/FUNCTION_NAME
for example http://ro.php.net/printf .

Site Help

A month ago I have discovered


set keywordprg=a_script
What it does:
default, when you ar with the cursor on a WORD and press
K (SHIFT+k) in `command mode',
the vim will run 'man WORD'.
If you set keywordprg=a_script, the vim will run
`a_script WORD'
So I have
set keywordprg=/home/marcel/php_doc
and php_doc looks like:
#######
#!/usr/bin/bash
links http://www.php.net/$1
#######
And now I have the online help
`links' is a text browser for *nix,
http://links.browser.org/
Of course you can use the `lynx'.
Hope this helps
rate this tip

Life Changing

http://www.vim.org/tips/tip.php?tip_id=598 (1 of 2) [18/02/2004 15:06:53]

Helpful

Unfulfilling

rate

Tip #598 - (PHP) on line help : vim online

<<indet a code block - >i{ | vim plugin for clearcase >>

Additional Notes
catalin at run.ro, November 6, 2003 3:38
And How can I get back in my file after I visit the doc
file?
marcel_preda@yahoo.com, November 6, 2003 7:10
after you get out from the browser [use q]
all you have to do is:
`Hit ENTER or type command to continue'
[vim says that]
info at multivitaminicdream.com, November 19, 2003 23:07
If you work in X and you use more mozilla than lynx i
think you could like this script instead of other:
#!/bin/bash
#php_doc
mozilla=/when/you/have/mozilla
if ( $mozilla -remote "ping()" &> /dev/null );then
$mozilla -remote
"openurl(http://www.php.net/$1, new-tab)" &
else
$mozilla http://www.php.net/$1 &
fi
This script start mozilla if not running, and send it
the new url.
If you want to know the others command to use with remote flag see here:
http://www.mozilla.org/unix/remote.html
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=598 (2 of 2) [18/02/2004 15:06:53]

SourceForge
Logo

Tip #599 - vim plugin for clearcase : vim online

not logged in (login)

Home
Search

Tip #599: vim plugin for clearcase


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -3/9, Viewed by 970

created: October 30, 2003 9:47


author: Guo

complexity: basic
as of Vim: 6.0

The ccase.vim vim clearcase plugin is very useful. But


there is a bug in clearcase, if you are doing multisite
development, even if you checkout file unreserved, it
still hold the mastership. So your partner on other side
still cannot checkin code.
The default unreserved checkout swith on ccase.vim is "unreserved", need to change to "-unreserved -nma".
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<(PHP) on line help | Copy current file name into windows clipboard >>

Additional Notes
hermitte {at} free {dot} fr, November 1, 2003 8:08
Please, when you find a bug in a plugin, contact its
author.
Tips are meant to be tips not a forum. :(
Anonymous, November 27, 2003 0:58
and if the author won't change and update, we will die
dumb ...
;-)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=599 [18/02/2004 15:06:56]

SourceForge
Logo

Tip #600 - Copy current file name into windows clipboard : vim online

not logged in (login)

Home
Search

Tip #600: Copy current file name into windows clipboard


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 22/16, Viewed by 1251

created: October 30, 2003 12:43


author: Igor Keselman

complexity: basic
as of Vim: 5.7

Sometimes I need to use a file name that I'm editing in


other applications (compiling, attaching to e-mail,
referencing in document) etc.
I found these two mappings to be useful for copying file
name to the windows clipboard.
Inside VIm I do ",cs" or ",cl" and then simply paste
into other document using regular windows paste command.
The mappings work in normal mode.
,cs is used to copy just the file name
,cl is used to copy file name including the full path
nmap ,cs :let @*=expand("%")<CR>
nmap ,cl :let @*=expand("%:p")<CR>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<vim plugin for clearcase | Tag with line:column >>

Additional Notes
maxiangjiang@hotmail.com, October 30, 2003 15:36
An alternative for the first of your map:
nmap ,cs :%y*<CR>
(It works even when we have no filename.)
Marcel van der Laan, October 31, 2003 0:16
This is not quite the case... You are yanking the
contents of the file, not the file name.
maxiangjiang@hotmail.com, October 31, 2003 9:40

http://www.vim.org/tips/tip.php?tip_id=600 (1 of 2) [18/02/2004 15:07:00]

Tip #600 - Copy current file name into windows clipboard : vim online

Ops, you are right. Mine was for content, not for
filename.
I am offering a third one, to make it up :)
nmap ,c8 :let @*=expand("%:p:8")<CR>
(For Windows users, to get DOS filename)
hermitte {at} free {dot} fr, November 1, 2003 8:04
Another way for the first map (only):
nnoremap <leader>cs :let @+=@%<cr>
JonathanOrlev@yahoo.com, November 9, 2003 7:19
Great tip !
Thank you very much.
Jonathan Orlev
fishburn@ianywhere.com, November 11, 2003 14:02
I use the following in my vimrc:
" Copy the filename of the current buffer into the
clipboard
if has('win32')
nnoremap <Leader>ff :let
@*=substitute(expand("%:p"), "/", "\\", "g")<cr>
else
nnoremap <Leader>ff :let @*=expand("%:p")
endif
This takes care of flipping the slashes for windows
platforms.
This came from:
Tip #296: Attach the currently open file to email
http://vim.sourceforge.net/tip_view.php?tip_id=296
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=600 (2 of 2) [18/02/2004 15:07:00]

SourceForge
Logo

Tip #601 - Tag with line:column : vim online

not logged in (login)

Home
Search

Tip #601: Tag with line:column


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/3, Viewed by 993

created: October 30, 2003 13:03


author: mosh@cs.albany.edu

complexity: basic
as of Vim: 6.0

Tags allow us to jump to a particular line,


but I needed to get to the exact column also,
eg. when I have many tags on one long line.
This is not possible with the tag format, however
with Vim's regexp extensions, I am able to generate
and use such tags, eg:
> tail -1 ./tags
main mohsin.c /^\%89l\%12c/ ;" Goto line 89, column
12.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Copy current file name into windows clipboard | How to remove one mark or all marks at once >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=601 [18/02/2004 15:07:03]

SourceForge
Logo

Tip #602 - How to remove one mark or all marks at once : vim online

not logged in (login)

Home
Search

Tip #602: How to remove one mark or all marks at once


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/11, Viewed by 1298

created: November 1, 2003 0:55


author: Remove marks

complexity: basic
as of Vim: 6.0

To remove a mark you can use \mh in normal mode. Go to


the mark and type \mh.
If you are using marks in a script you can use the
function below.
Then you would write e.g.
function! MyFunction()
...
kl "set mark l
...
"do something
...
call RemoveMark("l") "Mark l is no longer used, remove
it
...
endfunction
Here is the function:
function! RemoveMark(mark)
try
exe "normal '" . a:mark "go to the mark
normal \mh "remove it
catch
endtry
endfunction
If you want to remove all your marks in normal mode you
can use the mapping
map \rm :call RemoveMarks()<cr>
It calls the function:
function! RemoveMarks()
try
call RemoveMark("a")
call RemoveMark("b")

http://www.vim.org/tips/tip.php?tip_id=602 (1 of 4) [18/02/2004 15:07:06]

Tip #602 - How to remove one mark or all marks at once : vim online

call RemoveMark("c")
call RemoveMark("d")
call RemoveMark("e")
call RemoveMark("f")
call RemoveMark("g")
call RemoveMark("h")
call RemoveMark("i")
call RemoveMark("j")
call RemoveMark("k")
call RemoveMark("l")
call RemoveMark("m")
call RemoveMark("n")
call RemoveMark("o")
call RemoveMark("p")
call RemoveMark("q")
call RemoveMark("r")
call RemoveMark("s")
call RemoveMark("t")
call RemoveMark("u")
call RemoveMark("v")
call RemoveMark("w")
call RemoveMark("x")
call RemoveMark("y")
call RemoveMark("z")
catch
endtry
endfunction
Could you think of other possibilities?
Please share it with us.
Note:
I am using the try-catch clause so the following works
only for >= vim 6.2.
If you want to use the functions for an older version
remove the try-catch
clauses.
Happy vimming
Klaus

rate this tip

Life Changing

Helpful

<<Tag with line:column | Bookmarks as menu item >>

http://www.vim.org/tips/tip.php?tip_id=602 (2 of 4) [18/02/2004 15:07:06]

Unfulfilling

rate

Tip #602 - How to remove one mark or all marks at once : vim online

Additional Notes
Klaus Horsten, November 1, 2003 1:12
Alas!
I put the title in the wrong field (in the author
field).
Pair programming would be good.
Klaus
Anonymous, November 2, 2003 12:18
http://www.mono211.com/content/releases/mtkmp120.html
cec@NgrOyphSon.gPsfAc.nMasa.gov, November 3, 2003 6:42
\mh is a mapping to s:ShowMarksClearMark(), which is
provided by the
<showmarks.vim> plugin (see vimscript#152). So don't
expect the \mh
command to work without that plugin. Furthermore, the
plugin doesn't
actually remove the mark; instead, it moves it to line
1.
juhas@seas.upenn.edu, November 8, 2003 20:09
To remove all marks you can also use
or :%!type on windows.

:%!cat

on unix

Anonymous, November 13, 2003 20:45


Removing all marks the way the tip suggests is FAR more
efficient than using type or cat; it doesn't spawn an
external process, for one and will execute in fixed
time regardless of the size of the buffer, for
another. Not to be mean, but I think alternatives to
tips should be posted only if they actually IMPROVE
upon the tip.
drchip@campbellfamily.biz, November 14, 2003 13:48
As I mentioned above, \mh doesn't remove marks. It
doesn't work at all without the <showmarks.vim> plugin.
The \mh map moves marks to line 1.
The !cat /!type solution, on the other hand, actually
does result in the removal of the marks. Seems like a
good idea to me to present a real solution.

http://www.vim.org/tips/tip.php?tip_id=602 (3 of 4) [18/02/2004 15:07:06]

Tip #602 - How to remove one mark or all marks at once : vim online

Anonymous, November 26, 2003 9:54


Wouldn't it be easier (and maybe more efficient) to use
something like "%d | put | 1d" to remove all marks? (Or
did I miss something here?)
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=602 (4 of 4) [18/02/2004 15:07:06]

SourceForge
Logo

Tip #603 - Bookmarks as menu item : vim online

not logged in (login)

Home
Search

Tip #603: Bookmarks as menu item


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/1, Viewed by 696

created: November 14, 2003 17:47


author: mosh.cs.albany.edu

complexity: basic
as of Vim: 6.0

I like to save location of files I am editing


in a bookmark file. Each bookmark shows up as a
menu item.
Add the attached lines to ~/_vimrc, and the Bookmark->Add
menu items will appeare in gvim (I use it on Windows/NT).
Note: I used cmd.exe,sh.exe,echo.exe to write the bookmark
to a file, it is tricky to get the quotes right.
It would be whole lot easier if vim had a function
append-register-or-string-to-file. Maybe someone can
find a way to do this without external shells?
- Mohsin (mosh.cs.albany.edu)
:set shell=sh shellslash shellcmdflag=-c shellxquote=\"
shellpipe=\|\ tee
:amenu Mo2.BookMarks.Add
\ :let @b='\\042 Bookmark: '.
\
" DATE=".strftime("%Y-%b-%d_%X").
\
" PWD=".escape(getcwd(),'').
\ escape("\\n",'').
\ ":amenu Mo2.BookMarks.".
\ escape(escape(expand("%:t"),'.'),'').
\ ' :sp +'.line(".").' '.
\ escape(expand("%:p"),' ')<CR>
\ :exe ':!(echo '.@b.' >> $HOME/bookmark.vim)'<CR>
\ :so $HOME/bookmark.vim<CR>
:amenu Mo2.BookMarks.Edit :sp $HOME/bookmark.vim<CR>
:amenu Mo2.BookMarks.Load :so $HOME/bookmark.vim<CR>
if filereadable(expand("$HOME/bookmark.vim"))
:amenu Mo2.BookMarks.-Sep- :
:so $HOME/bookmark.vim
endif

rate this tip

Life Changing

Helpful

Unfulfilling

<<How to remove one mark or all marks at once | Doing <enter> in nmode >>

http://www.vim.org/tips/tip.php?tip_id=603 (1 of 3) [18/02/2004 15:07:09]

rate

Tip #603 - Bookmarks as menu item : vim online

Additional Notes
mosh.cs.albany.edu, November 14, 2003 17:55
Please add a single backslash to the second arg of escape, in
all three calls. It gets deleted while posting.
eg. escape("\\n",'') should be escape("\\n",'backslash-here')
vimuser@mailinator.com, November 15, 2003 8:59
double backslash =\\
single back slash=\ <= is this visible?
manu.anand@igate.com, November 17, 2003 1:51
Script breaks if the file has any spaces or . in the filename.
Also the header part ie part before :amenu confuses Vim Script
Interpretor.
Env: WinNT, Vim6.2
fred.bartholomai@acsatlanta.com, November 17, 2003 11:32
I get the following error when I attempt to bookmark a file:
( I added the backslash as you mentioned ).
!(echo \\042 Bookmark: DATE=2003-Nov-17_14:32:05
PWD=/home/freddyb\\n:amenu Mo
2.BookMarks.NetworkMsgs\\.C :sp +1
/users/acs/V8.0/src/Network/NetworkMsgs.C >>
$HOME/bookmark.vim)
sh: line 1: (echo \042 Bookmark: DATE=2003-Nov-17_14:32:05
PWD=/home/freddyb\n:
amenu Mo2.BookMarks.NetworkMsgs\.C :sp +1
/users/acs/V8.0/src/Network/NetworkMsg
s.C >> /users/freddyb/bookmark.vim): No such file or directory
Any help would be appreciated.
mosh.cs.albany.edu, November 17, 2003 18:56
This works on linux (redhat71) with vim61 and bash (I shortened
it for linux):
:amenu Mo2.BookMarks.Add
\ :let @b=":amenu Mo2.BookMarks.".
\ escape(escape(expand("%:t"),'.'),'').
\ ' :sp +'.line(".").' '.
\ escape(expand("%:p"),' ')<CR>
\ :exe ':!(echo '.@b.' >>
$HOME/hist/bookmark.vim)'<CR>
\ :so $HOME/bookmark.vim<CR>
As usual the web posting may delete a backslash from the
second argument to escape(), you can add it back so it looks as
follows:

http://www.vim.org/tips/tip.php?tip_id=603 (2 of 3) [18/02/2004 15:07:09]

Tip #603 - Bookmarks as menu item : vim online

....
escape(escape(expand("%:t"),'<dot><backslash>'),'<backslash>').
...
escape(expand("%:p"),' <backslash>')<CR>
You can test it even in the console mode vim command line:
:emenu Mo2.Bookmarks.Add
:sp ~/bookmark.vim
- Mohsin.
mosh.cs.albany.edu, November 17, 2003 18:58
This should be correct for linux:
:amenu Mo2.BookMarks.Add
\ :let @b=":amenu Mo2.BookMarks.".
\ escape(escape(expand("%:t"),'.\'),'\').
\ ' :sp +'.line(".").' '.
\ escape(expand("%:p"),' \')<CR>
\ :exe ':!(echo '.@b.' >>
$HOME/bookmark.vim)'<CR>
\ :so $HOME/bookmark.vim<CR>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=603 (3 of 3) [18/02/2004 15:07:09]

SourceForge
Logo

Tip #604 - Doing <enter> in nmode : vim online

not logged in (login)

Home
Search

Tip #604: Doing <enter> in nmode


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/5, Viewed by 500

created: November 18, 2003 14:52


author: Sigurd

complexity: basic
as of Vim: 5.7

Although very simple, I think this is nifty:


:nmap <enter> _i<enter><esc>
Now one can press enter in normal mode to insert an
empty line. This spares me from alot of typing.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Bookmarks as menu item | replace a word with the yanked text >>

Additional Notes
jeromeguigue@yahoo.fr, November 19, 2003 4:28
why "_" before "i" ?
ykhov@student.cs.uwaterloo.ca, November 19, 2003 15:14
I've been using something similar for years.
" Enter a blank line below/above cursor in Normal mode
without
" having to go to Insert. (Using o command will
continue comments in programming as well.)
"comma o"
nmap
nmap

,o
,O

o<ESC>k
O<ESC>j

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=604 [18/02/2004 15:07:12]

SourceForge
Logo

Tip #605 - replace a word with the yanked text : vim online

not logged in (login)

Home
Search

Tip #605: replace a word with the yanked text


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 24/11, Viewed by 1538

created: November 18, 2003 19:55


author: Yang Xiangyu

complexity: basic
as of Vim: 6.0

I often need to replace a word with the yanked text when


programming, so I add this map:
map S diw"0P
I rarely use S command, because it's equal to cc.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Doing <enter> in nmode | Seeing the man pages while being in VIM >>

Additional Notes
jigho@caramail.com, November 18, 2003 23:16
I was looking for something like that for years !
Nonetheless, it does not seem to be able to replace the
word with a previously deleted text, which is also very
useful. Someone can help me ?
Anonymous, November 19, 2003 1:31
Use numbered register 2 to insert previously deleted
text.
map S diw"2P
see
:help registers
jigho@caramail.com, November 19, 2003 23:23
Thanks a lot.
In fact, diwP is what I want, since it pastes from the
unnamed register (filled with text from the last d, c,
s, x or y comand)
http://www.vim.org/tips/tip.php?tip_id=605 (1 of 3) [18/02/2004 15:07:16]

Tip #605 - replace a word with the yanked text : vim online

Anonymous, November 20, 2003 5:20


If I create a file with the lines:
word1
word2
word3
move my cursor to line1 and do "dw" and move my cursor
to word2 and do "diw" then do ":display" I get:
""
"-

word2
word2

so, unless I have misunderstood the map needs to be


something like:
:map S :let @x=@-<CR>diw"xP
which uses the x register to save the - register before
deleting (in my example) deleting word2
JonathanOrlev@yahoo.com, November 20, 2003 18:04
Great tip,
Thanks :-)
jigho@caramail.com, November 20, 2003 23:34
Oups, you are right "Anonymous", diwP doesn't work :(
mike@denio.com, November 21, 2003 14:28
Another variant is:
nmap <silent> S :let @x=@"<CR>"_diw"xP
This allows you to replace the word with the last
yanked or deleted text multiple times.
Anonymous, November 25, 2003 18:30
Another semi-useful variant on this is using the Visual
mode to replace a selection with yanked text. In visual
mode you can select a portion of text in the usual
fashion and then use 'p' to paste over the selection
with the last thing yanked. :)
Anonymous, December 7, 2003 7:58

http://www.vim.org/tips/tip.php?tip_id=605 (2 of 3) [18/02/2004 15:07:16]

Tip #605 - replace a word with the yanked text : vim online

In .vimrc
map S viw"0P
viw on word
and go to another word
S

Anonymous, December 7, 2003 8:02


mistake above
map X viwy
map S viw"0P
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=605 (3 of 3) [18/02/2004 15:07:16]

SourceForge
Logo

Tip #606 - Seeing the man pages while being in VIM : vim online

not logged in (login)

Home
Search

Tip #606: Seeing the man pages while being in VIM


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 45/23, Viewed by 1271

created: November 19, 2003 0:00


author: Manas Behera

complexity: basic
as of Vim: 5.7

You can see the man pages of anything you want from VIM.
No need to exit VIM. Just put the cursor under the
word.and press shift+k (Capital K) and you will be in
the man page section. when you are through just press
'q' and you will be out of VIM. Press enter to come back
to VIM.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<replace a word with the yanked text | Opening gvim atop a console window >>

Additional Notes
ivon@jinr.ru, November 19, 2003 0:56
Thank you! Now I can remove my function from .vimrc
which do the same thing :)
drNchipO@ScampbellPfamilyA.Mbiz - NOSPAM, November 19, 2003 7:02
After moving my <.vimrc> to <DOTVIMRC> and my <.vim/>
to <DOTVIM/>, so as to avoid
any of my customizations, and writing a new <.vimrc>
with just
set nocp
filetype plugin indent on
the tip did not work using <ctrl-k> on "printf(...)" in
a C file. Obviously it needs something!
May I suggest looking at vimtip#167 "Using vim as a manpage viewer under Unix" and
vimscript#489 "Manpageview.vim".
drNchipO@ScampbellPfamilyA.Mbiz, November 19, 2003 7:05
http://www.vim.org/tips/tip.php?tip_id=606 (1 of 2) [18/02/2004 15:07:21]

Tip #606 - Seeing the man pages while being in VIM : vim online

Whoops -- yes it does work -- use K, not <ctrl-k>.


Anonymous, November 23, 2003 7:03
If you use ftplugin/man.vim
you can use the VIM builtin manpage viewer, with
ability of
hyperlinking via the tags mechanism.
just do
:Man <your favourite man page>
a lot better (but a little slower) than the Shift+K
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=606 (2 of 2) [18/02/2004 15:07:21]

SourceForge
Logo

Tip #607 - Opening gvim atop a console window : vim online

not logged in (login)

Home
Search

Tip #607: Opening gvim atop a console window


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/2, Viewed by 1393

created: November 19, 2003 7:57


author: drNchipO@ScampbellPfamilyA.Mbiz

complexity: basic
as of Vim: 5.7

I like to have gvim open atop the current xterm I'm using,
rather
like a vim console would. Here's some Korn shell script
for
setting up a function "gv" which queries X for the current
window's
geometry and adjusts the window for the current fontsize,
borders,
and menu region.
Admittedly the adjustments for that vary with border sizes,
etc,
so you'll likely need to adjust x,y,w,h in the Adjustments
section.
Usage:

gv files, options, etc

# =======================================
# gv: gvim covers starting console window
function gv
{
if [[ "${WINDOWID}" = "" ]]; then
echo "***error*** unknown window id!"
return
fi
xwi=$(xwininfo -id $WINDOWID)
xyposn=${xwi##*Corners: }
xyposn=${xyposn%% -*}
wh=${xwi##*geometry }
wh=${wh%+0+0}
integer x y w h
x=${xyposn%+[0-9]*}
y=${xyposn#+[0-9]*}
w=${wh%x*}
hh=${wh#*x}
h=${hh%[-+]*}
# ---------------------------# Adjustments:
#
x,y in pixels

http://www.vim.org/tips/tip.php?tip_id=607 (1 of 3) [18/02/2004 15:07:24]

Tip #607 - Opening gvim atop a console window : vim online

#
w,h in characters
# ---------------------------# for RH8 Linux, GTK, courier-12-r
h=h-4
x=4
y=y-18
# ---------------------------# invoke gvim
gvim -geometry "${w}x${h}+${x}+${y}" $*
}
# =======================================
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Seeing the man pages while being in VIM | Evaluate current line (or pease of line) using Python >>

Additional Notes
Anonymous, November 19, 2003 15:43
don't know if this is useful directly (i don't
particularly mind where the window manager places the
window), but the fact that you can get a shell window's
info like this is very interesting.
drNchipO@ScampbellPfamilyA.Mbiz , November 21, 2003 7:29
Found a few bugs; probably should've made this a script
since one can't "adjust" tips.
Enjoy!
#
==========================================================
# gv: gvim covers starting console window
function gv
{
if [[ "${WINDOWID}" = "" ]]; then
return
fi
xwi=$(xwininfo -id $WINDOWID)
xyposn=${xwi##*Corners: }
xyposn=${xyposn%% -*}
wh=${xwi##*geometry }
wh=${wh%%[-+]*}
integer x y w h
x=${xyposn%+[0-9]*}
y=${xyposn##*+}
w=${wh%x*}
http://www.vim.org/tips/tip.php?tip_id=607 (2 of 3) [18/02/2004 15:07:24]

Tip #607 - Opening gvim atop a console window : vim online

hh=${wh#*x}
h=${hh%%[-+]*}
# --------------------------------------------------------# Adjustments: account for window borders, menus,
fontsizes
# --------------------------------------------------------# Adjust for RH8 Linux: courier-12-r
h=h-4
x=x-4
y=y-18
# --------------------------------------------------------# execute gvim with geometry
gvim -geometry "${w}x${h}+${x}+${y}" $*
}
#
==========================================================
dolphinq@com.ne.kr, November 28, 2003 4:41
hi
i am korean.
Send this manual tim vim

this E-mail.(dolphinq@com.ne.kr)

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=607 (3 of 3) [18/02/2004 15:07:24]

SourceForge
Logo

Tip #608 - Evaluate current line (or pease of line) using Python : vim online

not logged in (login)

Home
Search

Tip #608: Evaluate current line (or pease of line) using Python
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/3, Viewed by 644

created: November 24, 2003 4:57


author: Eugene M. Minkovskii

complexity: intermediate
as of Vim: 6.0

Pyhton language has more powerfull evaluation functions


than vim editor. If you have need to evaluate some by
python you can use command
:py print 2*2
(see :help :if_pyth.txt)
But I can tell you more pleasant example. Write in your
.vimrc file followings:
=== begin paste ========
python << EOL
import vim
# do not say from vim import * beacuse this instraction
# delete builtins function eval
def EvaluateCurrentLine(*args):
cur_str = vim.current.line
action, symb = None, None
for i in args:
if i in ["r","p"]: action = i
else:
symb
= i
try:
start = cur_str.rindex(symb)+len(symb)
except: start = 0
result = eval(cur_str[start:],globals())
if action == "r":
vim.current.line = cur_str[:start]+str(result)
else:
print result
EOL
command -narg=* PyEv python EvaluateCurrentLine(<fargs>)
=== end paste ============
Be carefull about identation in python part. This text
provide command
:PyEv
This command evaluate expression in line under cursor
and print result in echo area. With r argument

http://www.vim.org/tips/tip.php?tip_id=608 (1 of 2) [18/02/2004 15:07:28]

Tip #608 - Evaluate current line (or pease of line) using Python : vim online

:PyEv r
evaluate expression and replased it by resalt of
evaluation. And other arg in argument searching the arg
backword from the end of current line and evaluate
followed expression. For example: let we have string
\setlength{\textwidth}{450-63
:PyEv r {
\setlength{\textwidth}{387
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Opening gvim atop a console window | Execute python from within current file >>

Additional Notes
emin@mccme.ru, November 24, 2003 5:28
Sorry, internet formatter killing all ident in the
python sript
I'm try again:
def EvaluateCurrentLine(*args):
cur_str = vim.current.line
action, symb = None, None
for i in args:
if i in ["r","p"]: action = i
else:
symb
= i
try:
start = cur_str.rindex(symb)+len(symb)
except: start = 0
result = eval(cur_str[start:],globals())
if action == "r":
vim.current.line = cur_str[:start]+str(result)
else:
print result
Anonymous, November 25, 2003 15:57
"pease"?

You mean "piece"?

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=608 (2 of 2) [18/02/2004 15:07:28]

SourceForge
Logo

Tip #609 - Execute python from within current file : vim online

not logged in (login)

Home
Search

Tip #609: Execute python from within current file


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 10/7, Viewed by 876

created: November 28, 2003 15:22


author: Steve Halpin

complexity: intermediate
as of Vim: 6.0

Inspired by vimtip #608.


To execute python from a range within the current text file and write
the output to that file (replacing the python), add the snippet below
to .vimrc (or other suitable *rc file).
Requires a 'proper' python setup so that the imported modules can be
found.
I find it a handy intermediate step between using the python
interpreter on command line and running a complete script. Can be used
for easy buffer manipulation, filtering input, preprocessing text and
templating-like tasks.
def PyExecReplace(line1,line2):
r = vim.current.buffer.range(int(line1),int(line2))
redirected = cStringIO.StringIO()
sys.stdout = redirected
exec('\n'.join(r[:]) + '\n')
sys.stdout = sys.__stdout__
output = redirected.getvalue().split('\n')
r[:] = output[:-1] # the -1 is to remove the final blank line
redirected.close()
EOL
command -range Pyer python PyExecReplace(<f-line1>,<f-line2>)
Some examples of use:
Simple
-----print 2 + 2
:Pyer
(if cursor is on the 'print' line, replaces line with 4)
Filter
-----for line in vim.current.buffer:
if line[0] != '\t':
print line
:%Pyer
(filters out lines beginning with a tab in the current buffer)
Inserting time
-------------import time
print time.ctime()
:%Pyer
(replaces line with date/time)

http://www.vim.org/tips/tip.php?tip_id=609 (1 of 3) [18/02/2004 15:07:33]

Tip #609 - Execute python from within current file : vim online

Getting web content without tags


------------------------------import urllib2,htmllib,formatter
h =
htmllib.HTMLParser(formatter.AbstractFormatter(formatter.DumbWriter()))
h.feed(urllib2.urlopen('http://www.somesite.com').read())
:%Pyer
(inserts the web page text, but not the html tags, for a given site)
I also use a slightly modified version that appends the output, leaving
the python intact.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Evaluate current line (or pease of line) using Python | Saves you frequent typings of certain words. >>

Additional Notes
fs111@linuxmail.org, December 1, 2003 5:23
The Tipp is cool, but it does not wor the way you posted it. On my
fedora core 1 I had to change it into:
python << EOL
import vim, StringIO,sys
def PyExecReplace(line1,line2):
r = vim.current.buffer.range(int(line1),int(line2))
redirected = StringIO.StringIO()
sys.stdout = redirected
exec('\n'.join(r[:]) + '\n')
sys.stdout = sys.__stdout__
output = redirected.getvalue().split('\n')
r[:] = output[:-1] # the -1 is to remove the final blank line
redirected.close()
EOL
command -range Pyer python PyExecReplace(<f-line1>,<f-line2>)
Andr
Steve Halpin, December 10, 2003 10:06
My apologies - cut & paste error, thanks for the correction.
Now what was that vim command that takes what you actually copied to
the clipboard and replaces it with what you meant to copy .... :)
MIBSchmidt@gmx.de, December 12, 2003 5:00

http://www.vim.org/tips/tip.php?tip_id=609 (2 of 3) [18/02/2004 15:07:33]

Tip #609 - Execute python from within current file : vim online

Hello
can somebody tell how to change the scrip so that it:
1. writes the python output to a new window and not replaceing the
source
2. evaluates the hole buffer and not a selection
thank you
Michael
Anonymous, February 10, 2004 19:17
>can somebody tell how to change the scrip so that it:
>1. writes the python output to a new window and not replaceing the
source
You can just enter 'u' in command mode to 'undo' the output and get
your source back. However, as you suggest sending the output to (for
instance, the Preview window) would probably be better.
> 2. evaluates the hole buffer and not a selection
':%Pyer' does this. '%' represents the whole buffer in vim.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=609 (3 of 3) [18/02/2004 15:07:33]

SourceForge
Logo

Tip #610 - Saves you frequent typings of certain words. : vim online

not logged in (login)

Home
Search

Tip #610: Saves you frequent typings of certain words.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 34/20, Viewed by 1825

created: November 29, 2003 23:00


author: VIM autocomplete feature

complexity: intermediate
as of Vim: 5.7

You can use VIM's autocomplete feature in insert mode.


Just edit the .vimrc file and add this lines
iab <key> <expansion>
<key> is the letter which should be expanded to
<expansion>
Example:
iab #i #include
( typing "#i" and
space will be expanded to "#include")
iab #d #define
( typing "#d" and
spacet will be expanded to "#define")
iab s struct
(typing "s"
and space will be expanded to "struct")
iab t typedef
( typing "t" and
space will be expanded to "typedef")
You can add your custon expansion words.
PITFALLS:
In some cases VIM expands a letter
automatically you dont want. You have to take care of
that. But this is a good utility.
rate this tip

Life Changing

Helpful

Unfulfilling

<<Execute python from within current file | Open big files and work fast >>

Additional Notes
Anonymous, November 30, 2003 9:59

http://www.vim.org/tips/tip.php?tip_id=610 (1 of 3) [18/02/2004 15:07:37]

rate

Tip #610 - Saves you frequent typings of certain words. : vim online

Similarly (at least as of vim 6.1 (maybe earlier) ), in


insert mode you can hit Ctrl+P or Ctrl+N to
autocomplete. Ctrl+P searches upward in your text for
what your trying to complete to, Ctrl+N searches
forward in your text. After exhausting the current
buffer, both of these commands will begin searching
other open buffers. I'm not sure, but I believe that
there is also a search path you can specify in the
.vimrc if you wish...
Anonymous, November 30, 2003 10:28
Use a dictionary file:
set complete+=k
set dictionary+=/your/dict/file
Ctrl+N, Ctr+P will now search for completions from that
dict file.
Anonymous, December 1, 2003 20:58
I also use iab's as a poor man's spel chekur ;-)
You simply iab your most common typographical misteaks
with the correct spelung and Robert's yer father's
brother.
eg
iab teh the
iab seperate separate
iab shit Microsoft
noone@mail.ru, December 2, 2003 9:11
Hi,
Is there a way to cut the space from the resulted
substitution?
For example:
iab <t <target name=""></target><esc>10hi
produces:
<target name=" "></target>
with the cursor on the second double-quote.
I'd like not to have the space between the quotes...
Thanks!

http://www.vim.org/tips/tip.php?tip_id=610 (2 of 3) [18/02/2004 15:07:37]

Tip #610 - Saves you frequent typings of certain words. : vim online

Anonymous, December 2, 2003 15:52


From ":help abbrevations"
[...]
An exception to this is the character <C-]>, which is
used to expand an abbreviation without inserting any
extra characters.
Example: >
:ab hh hello
<
"hh<Space>" is expanded to "hello<Space>"
"hh<C-]>" is expanded to "hello"
...so just type "<t" and then <C-]> instead of space
... the result will be <target name=""></target> and
the cursor ends between the quotes (at least for 6.2 it
works).
Anonymous, December 2, 2003 16:16
Try:
iab <t <target name="%"></target><esc>F%s<c-o>:call
getchar()<cr>
The key is to use getchar() to eat up that space.
hermitte {at} free {dot} fr, December 3, 2003 14:52
Regarding how to eat the last typed character (when it
is a space) : in vimscript#50, I've integrated the
result of a thread that occured on the mailing-list.
Check :Iabbr and :Inoreabbr.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=610 (3 of 3) [18/02/2004 15:07:37]

SourceForge
Logo

Tip #611 - Open big files and work fast : vim online

not logged in (login)

Home
Search

Tip #611: Open big files and work fast


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/5, Viewed by 1401

created: December 4, 2003 7:50


author: William

complexity: intermediate
as of Vim: 5.7

When opening big files, having no swap file and no undo


levels speeds up Vim dramatically. Here are lines to
set that up automatically beyond a given file size
threshold (BufSizeThreshold):
let g:SaveUndoLevels = &undolevels
let g:BufSizeThreshold = 1000000
if has("autocmd")
" Store preferred undo levels
au VimEnter * let g:SaveUndoLevels = &undolevels
" Don't use a swap file for big files
au BufReadPre * if getfsize(expand(<afile>)) >=
g:BufSizeThreshold | setlocal noswapfile | endif
" Upon entering a buffer, set or restore the number
of undo levels
au BufEnter
* if getfsize(expand(<afile>)) <
g:BufSizeThreshold | let &undolevels=g:SaveUndoLevels |
hi Cursor term=reverse ctermbg=black guibg=black | else
| set undolevels=-1 | hi Cursor term=underline
ctermbg=red guibg=red | endif
endif
Many thanks to Antoine and Chip, and to Ron who
triggered the thread on vim@vim.org.
William
PS: I have not done a search for big file handling
tips...
PPS: we could also disable syntax highlighting and
restore it for small files, but I just thought about it
now.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Saves you frequent typings of certain words. | save a nanosecond with marks >>

http://www.vim.org/tips/tip.php?tip_id=611 (1 of 2) [18/02/2004 15:07:40]

Tip #611 - Open big files and work fast : vim online

Additional Notes
Anonymous, December 4, 2003 23:18
You should place a " around <afile> or vim will be
complaining too load and too much.
user=natter aei=domain dot NOcaJUNK, December 5, 2003 9:16
Thanks. I have it as expand("%") in my vimrc, but
expand("<afile>") is more accurate.
Anonymous, December 5, 2003 12:54
Checking the file size each time one enters the buffer
can be very expensive (time delays) when file is stored
on shares etc. I use as an extention to tip #343; the
following line that makes also auto command on the fly,
only for the file that is considered to be large, and
remove the auto commands when the file is closed (The
variable g:LargeFileUL is the save-value of undo
levels):
au BufReadPre * let f=expand("<afile>") | if
getfsize(f) > g:LargeFile | set ei=FileType | setlocal
noswf bh=unload bt=nowrite ro | let
f=escape(substitute(f,'\','/','g'),' ') |exe "au
LargeFile BufEnter ". f ." set ul=-1" | exe "au
LargeFile BufLeave ". f ." set ul=". LargeFileUL | exe
"au LargeFile BufUnload ". f ." au! LargeFile * ". f |
exe "" | else | set ei= | endif
Its all one line ;-) I'm not sure if this also works
for version 5.x.
Erik
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=611 (2 of 2) [18/02/2004 15:07:40]

SourceForge
Logo

Tip #612 - save a nanosecond with marks : vim online

not logged in (login)

Home
Search

Tip #612: save a nanosecond with marks


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -6/23, Viewed by 1042

created: December 4, 2003 14:33


author: J Kawabata

complexity: basic
as of Vim: 5.7

Instead of marking all the time with "ma", mark with


"ml". When you need to return to the mark, `l is a
little quicker to type than `a.
If you save a fraction of a second many times, you'll
have saved as much time as it took to read this tip!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Open big files and work fast | open last edited file, AKA lvim for bash >>

Additional Notes
Anonymous, December 4, 2003 18:33
Actually, 'ma' will save you time compared with 'ml' if
you are typing with both of your hands.
Just my 2 cents
Anonymous, December 5, 2003 3:45
I use "mm", which is even faster for marking
Anonymous, December 5, 2003 6:51
I think the point is that you use the same finger for
'`' as for 'a', so '`a', '`z', and '`q' are slower to
type than for other marks.
Anonymous, December 5, 2003 8:32
Try ":mark a".
Anonymous, December 5, 2003 11:36

http://www.vim.org/tips/tip.php?tip_id=612 (1 of 2) [18/02/2004 15:07:45]

Tip #612 - save a nanosecond with marks : vim online

The backquote is far enough up there that most of my


left hand moves when I reach for it. Any right-handed
letter should work about as well, excluding indexfinger letters other than m.
Anonymous, December 8, 2003 1:47
Alternatively, you could just use the normal quote 'a
rather than the backtick. Then it doesn't matter which
letter you use -- as long as it's on the left hand,
it'll be quick for both m and '.
Anonymous, December 9, 2003 20:49
who cares do whatever you feel like
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=612 (2 of 2) [18/02/2004 15:07:45]

SourceForge
Logo

Tip #613 - open last edited file, AKA lvim for bash : vim online

not logged in (login)

Home
Search

Tip #613: open last edited file, AKA lvim for bash
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/3, Viewed by 318

created: December 10, 2003 11:54


author: Adam Monsen

complexity: basic
as of Vim: 5.7

The starting.txt help file


(http://vim.org/htmldoc/starting.html) tells you how to
open the last edited file in csh. In bash, do it like
so:
alias lvim='vim -c "normal '''0"'
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<save a nanosecond with marks | perldoc function and module keyboard mappings >>

Additional Notes
adamm@wazamatta.com, December 10, 2003 11:56
There needs to be a backslash in front of the second
single quote before the zero. This interface doesn't
let me write a backslash, so you have to replace the
word BACKSLASH with a literal backslash.
alias lvim='vim -c "normal 'BACKSLASH''0"'
Michael-O-Mendelsohn@vsnl.com, December 12, 2003 19:26
Put this in _vimrc, and invoking vim without arguments
will got last open file (it will get the last file and
position from .viminfo). Oh yes, replace BS by
Backslash.
- Michael O Mendelsohn
" Go to last buf if invoked without args.
:au VimEnter * nested if
BS
argc()
== 0
BS && bufname("%")
== ""
BS && bufname("2" + 0) != ""
BS | exe("normal `0")
http://www.vim.org/tips/tip.php?tip_id=613 (1 of 2) [18/02/2004 15:07:48]

Tip #613 - open last edited file, AKA lvim for bash : vim online

BS | endif
" From http://www.zellner.org/vim/vimrc and Campbell's
correction QUOTE to BACKQUOTE.
" Go to last cursor location, ie. goto
mark(double_quote)
:au BufReadPost * if
BS line("'BS"")
BS && line("'BS"") <= line("$")
BS | exe "normal `BS""
BS | endif
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=613 (2 of 2) [18/02/2004 15:07:48]

SourceForge
Logo

Tip #614 - perldoc function and module keyboard mappings : vim online

not logged in (login)

Home
Search

Tip #614: perldoc function and module keyboard mappings


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 8/2, Viewed by 307

created: December 10, 2003 14:05


author: Adam Monsen

complexity: intermediate
as of Vim: 5.7

" put the cursor over a perl function and try backslashpf to see perldoc
:nmap <Leader>pf :!perldoc -f <cword><CR>
" put the cursor over a perl module name and try
backslash-pd to see perldoc
:nmap <Leader>pd :e `perldoc -ml <cword>`<CR>
" see ':help mapleader' for more info... default is
backslash.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<open last edited file, AKA lvim for bash | Moving to the next word in insert mode >>

Additional Notes
webmaster@topfx.com, December 16, 2003 13:43
Here's something similar I use, with these improvements
on original poste:
1. Only sets up the mapping when editing perl files
2. Sets up 1 smart mapping that automatically works for
perl functions as well as modules
3. Uses vim's build-in keyword definition feature
instead of defining a new mapping
In your .vimrc add these 2 lines:
autocmd BufEnter
*.pl,*.pm,*.cgi let oldkp=&kp |
set keywordprg=perl \ -e\
$c=shift;exec\"perldoc\".($c=~/^[a-z]+$/?\"\ -f\ \":\"\
\").$c'
autocmd BufLeave
http://www.vim.org/tips/tip.php?tip_id=614 (1 of 2) [18/02/2004 15:07:51]

*.pl,*.pm,*.cgi let

Tip #614 - perldoc function and module keyboard mappings : vim online

&keywordprg=oldkp
Then when editing a perl file you can use perl's builtin keyword definition mapping (capital K == shift+k)
when under a perl function or module to see it's POD.
See
:help K
For more information.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=614 (2 of 2) [18/02/2004 15:07:51]

SourceForge
Logo

Tip #615 - Moving to the next word in insert mode : vim online

not logged in (login)

Home
Search

Tip #615: Moving to the next word in insert mode


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 15/18, Viewed by 979

created: December 10, 2003 17:39


author: kallumama

complexity: basic
as of Vim: 5.7

You can move to the next word in insert mode using


<shift> <right arrow key>
You can move to the next word in command mode using w
You can move to the previous word in insert mode using
<shift> <left arrow key>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<perldoc function and module keyboard mappings | Have Vim check automatically if the file has
changed externally >>

Additional Notes
Anonymous, December 10, 2003 21:10
This is true when not using :behave mswin.
and <C-Right> will work in either case.

<C-Left>

Anonymous, December 12, 2003 1:49


Not quite. <C-Right> differs depending on whether you
are in insert mode or not.
normal mode: <c-right> moves by WORDS (like ":normal
W")
[:help <C-Right>]
insert mode: <c-right> moves by words (like ":normal
w")
[:help i_<C-Right>]
Does anyone know how to get i_<C-Right> to also stop at
the end of line?
Add Note

http://www.vim.org/tips/tip.php?tip_id=615 (1 of 2) [18/02/2004 15:07:55]

Tip #615 - Moving to the next word in insert mode : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=615 (2 of 2) [18/02/2004 15:07:55]

SourceForge
Logo

Tip #616 - Have Vim check automatically if the file has changed externally : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #616: Have Vim check automatically if the file has changed
externally
tip karma

Rating 0/0, Viewed by 612

created: December 10, 2003 18:50


author: David Fishburn

complexity: basic
as of Vim: 6.0

You can place this in your vimrc file, and then run:
:CheckForUpdates
This will toggle the behaviour for the given buffer.
" If you are using a console version of Vim, or dealing
" with a file that changes externally (ie a web server
log)
" then Vim does not always check to see if the file has
been changed.
" The GUI version of Vim will check more often (for
example on Focus change),
" and prompt you if you want to reload the file.
"
" There can be cases where you can be working away, and
Vim does not
" realize the file has changed.
"
" This function will force Vim to check more often.
"
" The function will turn on the :checktime command so
that the
" file is checked based on the CursorHold event.
"
" Thanks to Jrgen Krmer, Antoine J. Mechelynck for the
help.
"
" CheckForUpdates will toggle the behaviour on the
current buffer.
function! CheckForUpdates()
" Save the current default register
let saveB=@"
" Check to see if the checkforupdates autocommand
exists
redir @"

http://www.vim.org/tips/tip.php?tip_id=616 (1 of 3) [18/02/2004 15:07:59]

Tip #616 - Have Vim check automatically if the file has changed externally : vim online

silent! exec 'au checkforupdates'


redir END
if @" =~ 'E216'
augroup checkforupdates
if has("win32")
" will do this except for file paths that
contain spaces -- and if
" you are on Windows, backslashes should be
converted to slashes,
" too:
exec "au Cursorhold " . escape(
\ substitute(expand("%:p"), '',
'/', 'g')
\ , ' ') . " :checktime"
else
exec "au Cursorhold " . expand("%:p") . "
:checktime"
endif
augroup END
else
" Using a autogroup allows us to remove it
easily with the following
" command. If we do not use an autogroup, we
cannot remove this
" single :checktime command
" augroup! checkforupdates
au! checkforupdates
augroup! checkforupdates
endif
let @"=saveB
endfunction
command! CheckForUpdates :call CheckForUpdates()
rate this tip

Life Changing

Helpful

Unfulfilling

<<Moving to the next word in insert mode | Fun with case twiddling >>

Additional Notes
jkr@jottkaerr.de, December 10, 2003 23:13

http://www.vim.org/tips/tip.php?tip_id=616 (2 of 3) [18/02/2004 15:07:59]

rate

Tip #616 - Have Vim check automatically if the file has changed externally : vim online

In the line
\ substitute(expand("%:p"), '', '/', 'g')
there should be a backslash inside the first pair of
single quote. Let's
see, if it gets accepted this time
\ substitute(expand("%:p"), '', '/', 'g')
David Fishburn, December 12, 2003 16:34
Yes, you are right, I didn't notice that it was removed
during the posting.
I see the same thing happened to you.
So this line:
\ substitute(expand("%:p"), '', '/', 'g')
Should be:
\ substitute(expand("%:p"), '\', '/', 'g')
The first pair of single quotes after "%:p", should
have a backslash between them.
I will try this again, escaping it twice for the post:
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=616 (3 of 3) [18/02/2004 15:07:59]

SourceForge
Logo

Tip #617 - Fun with case twiddling : vim online

not logged in (login)

Home
Search

Tip #617: Fun with case twiddling


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/2, Viewed by 803

created: December 10, 2003 23:01


author: Tofer Chagnon

complexity: intermediate
as of Vim: 5.7

Someone came on #vim asking about "sentence case",


meaning Capitalization Of Every Word.
I came up with some bad solutions before learning this:
:s/\(^\|\s\)\([a-z]\)/\1\U\2/g
This inspired me to come up with a silly script for
rotating between ALL CAPS, all lower, and Sentence Case.
MiXed Case is set to UPPER.
Then I mapped it (in visual mode) to ~, thus breaking
the wonderful tilde :)
Here's the script:
fun! TwiddleCase(str)
if a:str == toupper(a:str)
let ans = tolower(a:str)
elseif a:str == tolower(a:str)
let ans = substitute(a:str,"\\(^\\|\\s\\)\\([az]\\)","\\1\\U\\2","g")
else
let ans = toupper(a:str)
endif
return ans
endfun
And the mapping:
vmap ~ x:call setreg('"', TwiddleCase(getreg('"')))^MP
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Have Vim check automatically if the file has changed externally | how to make and submit a patch
>>

http://www.vim.org/tips/tip.php?tip_id=617 (1 of 2) [18/02/2004 15:08:03]

Tip #617 - Fun with case twiddling : vim online

Additional Notes
Anonymous, December 10, 2003 23:02
Sorry about the indentation, I won't try to cut-andpaste tabs next time :)
Anonymous, December 10, 2003 23:20
Remind me never to type in a tip at 2AM again.
What I meant to be talking about was "Title
Case". "Sentence Case" is the style I skipped.
Anonymous, December 11, 2003 6:18
s/\<\(.\)/\U\1/g

is easier

george@like_vim_a_lot.com, December 11, 2003 9:32


Found an easier way to upper / lower case the whole
file/part file.
do a visual select of the lines you want to do the
modifications and
gU ==> uppercase and
gu ==> lowercase
Anonymous, December 15, 2003 4:31
With a visual selection, just U is sufficient to switch
to uppercase and u gives you all lowercase. No need to
type a 'g' before the u or U!
mmr@b1n.org, February 5, 2004 11:07
use ~ (tilde) to toggle between upper and lower case.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=617 (2 of 2) [18/02/2004 15:08:03]

SourceForge
Logo

Tip #618 - how to make and submit a patch : vim online

not logged in (login)

Home
Search

Tip #618: how to make and submit a patch


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/5, Viewed by 691

created: December 12, 2003 15:47


author: Benji Fisher

complexity: basic
as of Vim: 5.7

Vim is developed using an open-source model, and


users are encouraged to contribute to its
development. Users with programming experience should
have a look at the to-do list from time to time (:help
todo), and even beginners can help by asking and
answering questions on the mailing lists, adding tips to
this database, and suggesting improvements to the
documentation. (IMHO, if you get a question answered on
one of the lists, a good way to repay the Vim community
is by posting the answer as a tip here.) Even rating
tips and scripts on the vim web site helps others, by
pointing them to the most useful ones.
Another way to give back to the community is to
support vim's charity:
:help uganda
Here is how to make a patch. Make a local copy of
the file you are going to change, and edit it. Then,
change to the directory (such as vim62/) containing the
src/ source directory. If you are editing one of the
help files and do not have the vim source files, change
to your $VIMRUNTIME directory (usually
/usr/local/share/vim/vimxx/ on *NIX systems). Use the
diff program to make the patch like this:
$ diff -c /src/eval.c path/to/my/eval.c >
/tmp/eval.c.diff
for a patch to the source or (assuming you do not have
the sources)
$ diff -c doc/help.txt path/to/my/help.txt >
/tmp/help.txt.diff
The directory and file name for the patches are just
suggestions. If you change more than one file, you can

http://www.vim.org/tips/tip.php?tip_id=618 (1 of 3) [18/02/2004 15:08:06]

Tip #618 - how to make and submit a patch : vim online

concatenate the patches or read the man page for diff to


create one big patch.
If you are on a Windows system that does not have
the diff program, you may be able to get one from
http://gnuwin32.sourceforge.net/ . (I have not used
Windows for a while now, so I have not tried this.) If
the usage is substantially different from the above,
perhaps someine will be kind enough to add a comment
below explaining this.
The -c option produces a "context diff." This is
fairly easy for both humans and machines to read, and
all official patches for vim are released in this form.
Once you have your patch, you can submit it to the
vim-dev mailing list.
:help vim-dev
or
http://www.vim.org/maillist.php#vim-dev

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Fun with case twiddling | HowTo make a keymap >>

Additional Notes
Merging patches is no picnic, December 12, 2003 19:19
I had real trouble applying big 'cvs diff' patches,
and found the following gnu doc tools and doc useful:
http://www.gnu.org/software/diffutils/diffutils.html
"Comparing and Merging Files with GNU diff and patch"
by David MacKenzie, Paul Eggert, and Richard
Stallman
I use gnu-emacs for merges and patches, because no
other tool
comes close to emacs' power in interactive merging of
files
No, none of winmerge,araxis,windiff,vim -d, provide
half the
functionality of gnu-emacs-ediff-emerge.

http://www.vim.org/tips/tip.php?tip_id=618 (2 of 3) [18/02/2004 15:08:06]

Tip #618 - how to make and submit a patch : vim online

- Michael O Mendelsohn
benji@member.AMS.org, January 2, 2004 5:26
If you are not subscribed to the vim-dev list, or
if you are submitting a small documentation patch and
do not feel it is worth the bandwidth to send it to the
list, you can send your patch directly to the
maintainer at bugs@vim.org .
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=618 (3 of 3) [18/02/2004 15:08:06]

SourceForge
Logo

Tip #619 - HowTo make a keymap : vim online

not logged in (login)

Home
Search

Tip #619: HowTo make a keymap


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 6/3, Viewed by 800

created: December 14, 2003 17:29


author: Tony Mechelynck

complexity: basic
as of Vim: 6.0

The present tip explains how to make a keymap for


yourself. It is based on what is said under
:help mbyte-keymap
:help keymap-file-format
and you'll also find relevant information under

Site Help

:help
:help
:help
:help
*1*

'keymap'
'iminsert'
language-mapping
<Char>

How to name the file and where to place it.

Keymaps reside in the "keymap" subdirectory of the


directories named in 'runtimepath'. Their names are of
one of the forms
<keymap>.vim
<keymap>_<encoding>.vim
so if you need keymaps for Czech and Norwegian, and want
to use them under UTF-8, you will probably create two
keymaps, named, for instance, "czech_utf8.vim" and
"norwegian_utf8.vim". If those names collide with names
already present in $VIMRUNTIME/keymap/, then either use
slightly different names before the underline, or put
them in the "keymap" subdirectory of a directory named
earlier than $VIMRUNTIME in 'runtimepath', so yours will
be found first (but in the latter case you won't be able
to use the default keymap of the same name). Create the
needed directory if it doesn't exist yet.
*2* What a keymap consists of.
A keymap consists of three parts:
a) a Vim script
http://www.vim.org/tips/tip.php?tip_id=619 (1 of 4) [18/02/2004 15:08:10]

Tip #619 - HowTo make a keymap : vim online

b) a line containing only the word "loadkeymap" (without


quotes)
c) the key mappings themselves.
*3* First part of a keymap: the Vim script.
This may contain any Ex-commands and Vim comments
germane to the use of the keymap. In particular, the
following Ex-commands are useful:
a) If this keymap is only a slight modification of
another, preexisting one: a "source" statement for the
keymap on which this one is based. Then you will only
have to code the changes.
b) A short name, for instance in a keymap for Czech
let b:keymap_name="cz"
This will appear as <cz> near the right end of the
standard status line for any window where the keymap in
question is enabled (by having its long name set ot
setlocal'ed in 'keymap' and 'iminsert' setlocal'ed to
1).
c) A cursor color for when keymaps are in use. This one
is more controversial (Bram comments it out in published
keymaps) but I find it useful in my "private" ones.
highlight lCursor ctermbg=red guibg=red
Use any color that pleases you, and beware that
highlight groups are global for the whole of Vim, so it
is possible to use different keymaps in split windows of
a single Vim instance, but not different language cursor
colors, unless you set up an autocommand to change the
lCursor highlight at the WinEnter event. (How to make
that work is outside the scope of this HowTo.)
*4* Second part: the "loadkeymap" command.
This is just to tell Vim that whatever comes after, to
the end of the file, is a series of language-mappings,
in a special format which will be described hereafter.
*5* Third part: The mappings themselves.
Each key mapping line consists of three parts; the
optional third one may contain spaces but not the first
two:
http://www.vim.org/tips/tip.php?tip_id=619 (2 of 4) [18/02/2004 15:08:10]

Tip #619 - HowTo make a keymap : vim online

{lhs}

{rhs}

[comment]

Vim interprets this line as if (in a standard Vim


script) there had been
lmap

<buffer>

{lhs}

{rhs}

The {lhs} is what you press, as interpreted by your


default (English) keyboard. It is usually a single
character, but it may be more than one: in that case all
of them but the last act as "dead keys". For instance,
in a German keymap, you may want to use the colon as a
prefix to tell that the following vowel gets an umlaut
(so that :A maps to , :a to etc.)
Any key or key combination which does not appear as an
{lhs} keeps its "English" meaning in the target
language. (This will usually be the case for the space
bar :-) and for any punctuation, or even letters, that
you don't want to move about on the keyboard.) This
means that if, for instance, you map the sz letter pair
to the German eszet, you'll still be able to use the
small-s letter with its usual meaning whenever it is not
followed by z. Similarly, if you map the colon as above,
a colon remains a colon if followed by anything other
than a vowel, for instance a space or a digit.
In all cases, you can force the initial key(s) of a
mapping to keep their original meaning, either by
waiting for the mapping to time out, or by moving the
cursor about, for instance with <Left><Right>.
The {rhs} is what it translates to, in the target
language. For UTF-8 the {rhs} may be of the form <Char0> to <Char-2347483647> (decimal), or <Char-0x0> to
<Char-0x7FFFFFFF> (hex), or <Char-00> to <Char017777777777> (octal) -- see ":help <Char>". For other
encoding targets, the <Char> notation may also be used,
but of course only as far as the target permits: e.g. in
8-bit encodings, only till 255 / 0xFF / 0377.
The [comment] is the easiest: it's for the human reader
of the keymap, not for Vim.
rate this tip

Life Changing

Helpful

Unfulfilling

<<how to make and submit a patch | getting to know the function prototypes >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=619 (3 of 4) [18/02/2004 15:08:10]

rate

Tip #619 - HowTo make a keymap : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=619 (4 of 4) [18/02/2004 15:08:10]

SourceForge
Logo

Tip #620 - getting to know the function prototypes : vim online

not logged in (login)

Home
Search

Tip #620: getting to know the function prototypes


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 61/25, Viewed by 812

created: December 15, 2003 5:33


author: Sunil Parolia

complexity: basic
as of Vim: 6.0

Use "[ i" for display of function prototypes at bottom


or "[ ctl i" for jumping to the file containing the
prototype. also can use " I" for listing of proto.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<HowTo make a keymap | Vim as a syntax highlighting engine for web publishing >>

Additional Notes
lpenz@terra.com.br, December 15, 2003 18:07
ctrl+i = TAB
So, "[ <TAB>" goes to the function prototype also, and
IMHO is easier to remember.
Anonymous, December 30, 2003 20:08
but what can I do if the prototype is longer than 1
line? Can help?
Anonymous, January 2, 2004 3:26
Its not working. I think you require a ctags file for
doing this operation. Otherwise how VIM will
know about the prototypes and definations. ANd "I"
(capital I) is required to insert at the begining
of a line NOT for listing of proto.
Manas Behera
sunil parolia, January 5, 2004 23:55

http://www.vim.org/tips/tip.php?tip_id=620 (1 of 2) [18/02/2004 15:08:13]

Tip #620 - getting to know the function prototypes : vim online

sorry for the typo "I" (capital I) should be replaced


with "[ I" wich list's the prototypes and places of use
of that function in our file and also in other file in
search path. i dont know how to make it search for use
of that function in our file only instead of searching
in path. any answer ??
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=620 (2 of 2) [18/02/2004 15:08:13]

SourceForge
Logo

Tip #621 - Vim as a syntax highlighting engine for web publishing : vim online

not logged in (login)

Home
Search

Tip #621: Vim as a syntax highlighting engine for web publishing


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 7/6, Viewed by 1131

created: December 15, 2003 13:18


author: Giuseppe Maxia

complexity: advanced
as of Vim: 5.7

Geoff Richards has written a Perl module to turn Vim


into a highlighting
engine for the web.
Text::VimColor
(http://search.cpan.org/perldoc?Text::VimColor).
See some basic usage at
http://www.perlmonks.org/index.pl?node_id=314528
where I also show a caching module to improve
Text::VimColor performance.
Enjoy
gmax
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<getting to know the function prototypes | Deleting a buffer without changing your window layout >>

Additional Notes
mmr@b1n.org, February 5, 2004 11:09
within any file type (that has its own syntax
highlight) use
:runtime syntax/2html.vim
ta-da!
you got an html version.
Add Note

http://www.vim.org/tips/tip.php?tip_id=621 (1 of 2) [18/02/2004 15:08:17]

Tip #621 - Vim as a syntax highlighting engine for web publishing : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=621 (2 of 2) [18/02/2004 15:08:17]

SourceForge
Logo

Tip #622 - Deleting a buffer without changing your window layout : vim online

not logged in (login)

Home
Search

Tip #622: Deleting a buffer without changing your window layout


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 44/14, Viewed by 573

created: December 17, 2003 8:22


author: Charles E. Campbell, Jr.

complexity: basic
as of Vim: 5.7

Here's a small command for your <.vimrc>:


com! Kwbd let kwbd_bn= bufnr("%")|enew|exe "bdel
".kwbd_bn|unlet kwbd_bn
To use it, type

:Kwbd

Kwbd stands for: Keep window (layout) and delete the


associated buffer.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Vim as a syntax highlighting engine for web publishing | External Paste Buffer >>

Additional Notes
Anonymous, December 17, 2003 9:45
At last!!
Anonymous, December 17, 2003 10:22
I had this need. Thank you for finding and sharing the
solution.
hari_vim at yahoo dot com, December 17, 2003 19:07
You can simplify this as:
com! Kwbd enew|bw #
Hari
Anonymous, December 17, 2003 19:14
YAY!
xburgerhout AT freeler DOT nl, December 17, 2003 22:59

http://www.vim.org/tips/tip.php?tip_id=622 (1 of 3) [18/02/2004 15:08:20]

Tip #622 - Deleting a buffer without changing your window layout : vim online

Great tip!
Additionally, I remapped bd to Kwbd:
map bd :Kwbd<CR>
Also, I added bn to Kwbd to automatically get the next
buffer:
com! Kwbd enew|bw #|bn
L.Josifovski@dcs.shef.ac.uk, January 9, 2004 6:31
When a buffer is open in sevral windows, those other
windows still get closed?!
I'm using the following at present - ugly (so many
lines for a simple task) but works for me:
" Delete the current buffer, issuing bnext in all
windows
" where displayed before that
function DeleteBuffer2()
let bid = bufnr("%")
let wid = winnr()
windo if bid == bufnr("%") | bprev | endif
exe "bdel " . bid
exe "normal " . wid . "^W^W"
endfunction
" count the number of buffers
function BufferCount()
" save cur buf number
let cbuf = bufnr("%")
let bnum = 0
bufdo let bnum = bnum + 1
" return to the buf
exe "b " . cbuf
return bnum
endfunction
"
"
function DeleteBuffer()
if BufferCount() > 1
call DeleteBuffer2()
else
exe "bdel"
endif
endfunction
"
map <C-K> :call DeleteBuffer()<CR>
imap <C-K> <C-O><C-K>

http://www.vim.org/tips/tip.php?tip_id=622 (2 of 3) [18/02/2004 15:08:20]

Tip #622 - Deleting a buffer without changing your window layout : vim online

http://www.cs.albany.edu, January 9, 2004 14:10


I am using the bdel tip given here, but it is very
confusing, as my
original view is lost
This how bdel should work (gnu-emacs kill-buffer does
it right):
> visit a file in window,
> go to 2nd file (vim gf)
> go to 3rd file
> kill-buffer of 3rd file, and you are back to the view
of 2nd file,
without disturbing windows splits / cursor position
> kill 2nd file, and viola, you are back to 1st file.
:com! Kwbd let kwbd_bn= bufnr("%")|enew|exe "bdel
".kwbd_bn|unlet kwbd_bn
A command should not interrupt your train of thought Emperor Ashoka.
NdrOchip@ScampbellPfamily.AbizM - NOSPAM, February 10, 2004 8:28
To confused: I suggest that you look into
o and :he ctrl-i

:he ctrl-

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=622 (3 of 3) [18/02/2004 15:08:20]

SourceForge
Logo

Tip #623 - External Paste Buffer : vim online

not logged in (login)

Home
Search

Tip #623: External Paste Buffer


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 8/2, Viewed by 662

created: December 17, 2003 10:31


author: zzapper

complexity: basic
as of Vim: 5.7

We are forever using copy and paste to copy information


from application to application. Inevitably however we
need to edit/reformat the buffer contents . This tip
allows you to quickly open a separate VIM containing
just the paste contents. You may then edit these
contents as required, writing or closing VIM
automatically causes the changed contents to be
rewritten to the paste buffer.
The following is a CygWin script (could just as easily
be a Win32 batch file)
function vxp
{
# description : Edit paste contents
gvim -c 'normal ggdG"*p' c:/aaa/xp
}
Such that I just type vxp and it opens a new Vim just
containing the
current paste buffer.
To automatically cause the rewriting of the paste buffer
add the following to your .vimrc
autocmd bufWritePost c:/aaa/xp normal ggVG"*y
(Thanks to Bob Chan et al from comp.editors)
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Deleting a buffer without changing your window layout | Insert template files into buffer ( HTML
editing for example) >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=623 (1 of 2) [18/02/2004 15:08:31]

Tip #623 - External Paste Buffer : vim online

zzapper@ntlworld.com, December 18, 2003 4:12


Similarly to autocmd bufWritePost you can also get Vim
to automatically perform commands on entering or
leaving a file(s)
BufEnter After entering a buffer. Useful for setting
options for a file type. Also executed when
starting to edit a buffer, after the
BufReadPost autocommands.
BufLeave Before leaving to another buffer. Also when
leaving or closing the current window and the
new current window is not for the same buffer.
Not used for ":qa" or ":q" when exiting Vim.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=623 (2 of 2) [18/02/2004 15:08:31]

SourceForge
Logo

Tip #624 - Insert template files into buffer ( HTML editing for example) : vim online

not logged in (login)

Home
Search

Tip #624: Insert template files into buffer ( HTML editing for example)
tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 6/5, Viewed by 880

created: December 18, 2003 4:35


author: A.L Marin

complexity: intermediate
as of Vim: 5.7

While editing HTML I want to use template files to be


expanded on my html pages. Say for example I have
something like this on my html file:
<!--"header.html"-->
<p>html code here</p>
<p>more html code here...</p>
<!--"footer.tml"-->
I want the files "header.html" and "footer.html" to be
inserted on my page, you can do this with the following
global command:
:g%<!--"\w\+.\w\+"--\>%exe ":r " .
matchstr(getline("."), "\\w\\+\\.\\w\\+")

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<External Paste Buffer | Typing print statements faster and more ergonomically (esp in C++) >>

Additional Notes
User-command-REVIM, December 20, 2003 14:30

http://www.vim.org/tips/tip.php?tip_id=624 (1 of 3) [18/02/2004 15:08:34]

Tip #624 - Insert template files into buffer ( HTML editing for example) : vim online

Above does not work if full path of template must be


specified (because only
word characters get matched -- excludes slashes,
spaces, and semicolons).
Probably not a good idea to embed files in comments
because they could be
easily overlooked later.
Strive for generality in
usage.
Suggest using
#revim=path/file
construct at the _beginning_ of a line
where revim stands for "read vim" (also close to
"revise").
The suitable global command would be,
:g/^#revim=/exe ":r " . strpart(getline("."),
7) | normal kdd
Even more useful, would be to establish a user command
Revim...
command! -range=% Revim <line1>,<line2>g/^#revim=/exe
":r " . strpart(getline("."), 7) | normal kdd
"
'Read_vim' / Revise by reading in file
templates.
"
Get the string part after the = sign, on
line(s) which
"
*begin* with #revim= , and use that to read in
said file
"
-------------------- (kdd deletes the # line;
put comments in templates).
Usage example:
#revim=c:/templates/header-html.txt
Executing user command Revim replaces the # line by
reading in said file.

Anonymous, December 20, 2003 17:14

http://www.vim.org/tips/tip.php?tip_id=624 (2 of 3) [18/02/2004 15:08:34]

Tip #624 - Insert template files into buffer ( HTML editing for example) : vim online

Great ideas!
I changed the name of the user command to Refile -- to
remind
me to rename the file after the alterations, and to
keep the
reference file with the #refile=path/file
lines intact...
refile > read ref(erence) file(s)
This would require changing that magic number from 7 to
8,
because "refile" has one more letter than "revim" ...
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=624 (3 of 3) [18/02/2004 15:08:34]

SourceForge
Logo

Tip #625 - Typing print statements faster and more ergonomically (esp in C++) : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #625: Typing print statements faster and more ergonomically


(esp in C++)
tip karma

Rating 1/5, Viewed by 1064

created: December 23, 2003 16:31


author: Kartik Agaram

complexity: basic
as of Vim: 5.7

Guess what the most common word is in the C++ language?


I wager it is 'cout'.
Interactive debuggers and logging libraries are all very
well, but most of us still have in our debugging
toolboxes the technique of adding short-lived statements
to our programs whose only purpose is to help us figure
out the bug currently occupying us by printing the value
of a variable. If you find yourself often typing such
statements they are worth optimizing for.
For example, strings in most languages are surrounded by
double quotes which require an extra motion and
keystroke for the left shift key. With my coding style I
multiply that motion towards the shift key by 4-6 times
per print statement and 10-100 print statements
everyday. The result is to significant slow me down and
bring me closer to the Home for the Aged Wrist. The
analogous cout statement in c++ is even more egregious
in this regard. Consider statements like the following
that I frequently find myself typing:
cout << "AAA: " << someVarName << ": " <<
someOtherVarName << "\n" ;
That's *12* times my left hand moves towards the shift
key for *one* statement! Unacceptable. My solution is to
remap keys to interchange '<' and ',' as well as double
quotes and single quotes. Rather than force myself to
learn a new keyboard mapping within vim I cause the
mappings to trigger in a context-sensitive mannter,
within only a cout statement, from the time I type
'cout' to the time I type the ';' in the end.
Here's my code fragment to do this:
function! CppSetupCout ()
inoremap , <Space><<

http://www.vim.org/tips/tip.php?tip_id=625 (1 of 3) [18/02/2004 15:08:37]

Tip #625 - Typing print statements faster and more ergonomically (esp in C++) : vim online

inoremap < ,
inoremap ' "
inoremap " '
imap ; <Esc>:call CppResetCout ()<CR>a;
map <Esc>, :call CppResetCout ()<CR>
imap <Esc>, <C-o>:call CppResetCout ()<CR>
endf
function! CppResetCout ()
iunmap ,
iunmap <
iunmap '
iunmap "
iunmap ;
imap <Esc>, <C-o>:call CppSetupCout ()<CR>
map <Esc>, :call CppSetupCout ()<CR>
endfunction
function! AuCpp ()
inoremap cout <End><Esc>:call CppSetupCout
()<CR>acout <<
imap <Esc>, <C-o>:call CppSetupCout ()<CR>
map <Esc>, :call CppSetupCout ()<CR>
endfunction
autocmd FileType cpp call AuCpp()
Notice that I use <Esc>, (or Alt-,) to quickly toggle
these mappings on or off in other situations.
For some other languages it's prob sufficient to simply
switch single- and double-quotes. Java might call for
switching '+' and '=' within system.out.println. Come to
think of it:
autocmd FileType java iabbrev sop system.out.println
You get the idea.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Insert template files into buffer ( HTML editing for example) | open vimrc file >>

Additional Notes
Anonymous, December 24, 2003 3:52

http://www.vim.org/tips/tip.php?tip_id=625 (2 of 3) [18/02/2004 15:08:37]

Tip #625 - Typing print statements faster and more ergonomically (esp in C++) : vim online

my solution for C is the line in my .vimrc:


nmap _if ofprintf(0<C-d>stderr, "{%s} {%d} - \n",
__FILE__, __LINE__);<Esc>F\i
so i type _if, and then start typing the error message
i want. adding __FILE__ and __LINE__ is invaluable
when i come to remove the debugging i have scattered
across half a dozen files. the 0<C-d> is so that these
debug statements arent indented, which makes them
easier to pick out visually and to remove.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=625 (3 of 3) [18/02/2004 15:08:37]

SourceForge
Logo

Tip #626 - open vimrc file : vim online

not logged in (login)

Home
Search

Tip #626: open vimrc file


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -1/7, Viewed by 1308

created: December 24, 2003 3:27


author: vim_user

complexity: basic
as of Vim: 5.7

I edit my _vimrc file on a frequent basis.


I usually browse for the file then select it, but this
can be a bit tedious so I made command that loads the
file into a new window
Put this line into your _vimrc file
:com Openvimrc :new c:\vim\_vimrc
adjust the path as necessary - this assumes win32
platform
So now you can just go ':Openvimrc' and you get the
file to edit.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Typing print statements faster and more ergonomically (esp in C++) | Customizing ftplugin, syntax
etc. (eg for TeX) >>

Additional Notes
Anonymous, December 24, 2003 6:34
I'm using it slightly different way:
:cabbrev vi $VIM/_vimrc
:cabbrev gvi $VIM/_gvimrc
now whenever i want to tweak my setup i just type:
:e vi<space>
or
:vs vi<space>
or
:sp vi<space>
and voila!
( <space> is pressing spacebar key )
Nice tip, anyway! :)

http://www.vim.org/tips/tip.php?tip_id=626 (1 of 2) [18/02/2004 15:08:41]

Tip #626 - open vimrc file : vim online

Anonymous, December 26, 2003 6:32


Me too. I am always tweeking lil things in my 'rc file.
Here is what i use to split open my 'rc file.
map <F7> :sp $HOME/_vimrc<cr>
" allows me to split-open my vimrc file in the current
buffer
That way im only a quick hit of the F7 key away from my
'rc file.
mjeaton_1@yahoo.com, December 31, 2003 7:44
Not sure where I picked this mapping up from, but it
works for me:
map ,v :e $vim\_vimrc<CR>
vshrinath@rediffmail.com, January 1, 2004 22:56
Just adding to the previous note, to edit and source
vimrc, I use
nmap ,v :sp $VIM\_vimrc
nmap ,s :source $VIM\_vimrc
Makes it easier to source changes immediately.
Shrinath
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=626 (2 of 2) [18/02/2004 15:08:41]

SourceForge
Logo

Tip #627 - Customizing ftplugin, syntax etc. (eg for TeX) : vim online

not logged in (login)

Home
Search

Tip #627: Customizing ftplugin, syntax etc. (eg for TeX)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/3, Viewed by 673

created: December 24, 2003 17:06


author: Suresh Govindachar

complexity: basic
as of Vim: 6.0

It is possible to customize the default environment that vim


provides (based on filetype). In older versions of vim (5.x),
this was done with a "myfiletypefile" file. In newer versions,
one customizes by adding files to the appropriate subdirectory
under the vimfiles directory.
For example, to customize the default TeX environment (of 6.1),
I added the following ftplugin and syntax files:
"-------------------------" vimfiles/ftplugin/tex.vim
"-------------------------if exists("b:did_myftplugin")
finish
endif
let b:did_myftplugin = 1
" Set 'formatoptions' to break comment lines but not other lines,
" and insert the comment leader when hitting <CR> or using "o".
setlocal fo-=t fo+=croql
" Allow "[d" to be used to find a macro definition:
" Recognize plain TeX \def, \gdef, \let and \font
setlocal
define=\\\\def\\\\|\\\\gdef\\\\|\\\\let\\\\|\\\\font\\\\|\\\\\\(re\\)\\=newcommand{
"---*---*---*---*---*--"-------------------------" vimfiles/syntax/tex.vim

http://www.vim.org/tips/tip.php?tip_id=627 (1 of 3) [18/02/2004 15:08:45]

Tip #627 - Customizing ftplugin, syntax etc. (eg for TeX) : vim online

"-------------------------if exists("b:did_mysyntax")
finish
endif
let b:did_mysyntax = 1
"hilight 1 true in, 1truein, 1 truein, 1true in, 1in, 1 in, 1.1 truein, etc.
syn match texTrueLength "\<\d\+\(\.\d\+\)\=\(\ *true\ *\|\ *\)\
\(\ *pt\|\
\ *he\|\
\ *bp\|\
\ *cc\|\
\ *cm\|\
\ *dd\|\
\ *em\|\
\ *ex\|\
\ *in\|\
\ *mm\|\
\ *pc\|\
\ *pt\|\
\ *sp\)\>"
if version >= 508 || !exists("did_c_syn_inits")
if version < 508
let did_c_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink texTrueLength Number
delcommand HiLink
endif
"---*---*---*---*---*---

rate this tip

Life Changing

Helpful

<<open vimrc file | Execut "things" in Win98 from within VIM >>

http://www.vim.org/tips/tip.php?tip_id=627 (2 of 3) [18/02/2004 15:08:45]

Unfulfilling

rate

Tip #627 - Customizing ftplugin, syntax etc. (eg for TeX) : vim online

Additional Notes
Suresh Govindachar, December 24, 2003 18:04
The first four lines in each file should _NOT_ be present:
if exists("b:did_my...")
finish
endif
let b:did_my... = 1
When these lines are present, they prevent the loading
of the customization when, for example, the user
does ":e!".
benji@member.AMS.org, December 30, 2003 13:25
Unless you add
let b:did_ftplugin
to the ftplugin, the default ftplugin/tex.vim will still be read, and it will
clobber your customizations. Similar remarks apply to the other customization
files. See
:help ftplugin-overrule
for more details.
This can be useful as an example, but before you decide not to use the
default settings, have a look at what you are losing. Because of a typo, the
default ftplugin/tex.vim does not recognize \gdef, but it does recognize \def,
\let, \font, \newcommand, and \renewcommand, as well as \futurelet, \newcount,
and several other variants. If you care about \gdef, the best thing to do is to
alert the maintainer (in this case, c'est moi).
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=627 (3 of 3) [18/02/2004 15:08:45]

SourceForge
Logo

Tip #628 - Execut "things" in Win98 from within VIM : vim online

not logged in (login)

Home
Search

Tip #628: Execut "things" in Win98 from within VIM


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 4/3, Viewed by 601

created: January 1, 2004 16:07


author: Suresh Govindachar

complexity: basic
as of Vim: 6.0

The following mappings help to execute "things" in win98.


1) If you are editing a file (eg, html file) file and want
to view it, the mapping \xf will do it.
2) If you want to execute the string under the cursor
(<cWORD>):
The mapping \x executes the <cWORD> "as is", whereas
the mapping \xl executes it after pre-pending it with
the
full path to the current file.
Example for \xf -- viewing an html file while editing it.
Example for \x -- the string under the cursor can be a google
search for the word mail on this web-site:
http://www.google.com/search?q=mail+site:vim.sourceforge.net
(It can also be things such as the name of a file (foo.pdf,
foo.bat) or directory etc.)
"__________________________________________
"The mappings:
" eXecute File being edited
nmap \xf :silent !start rundll32 url.dll,FileProtocolHandler
%:p <CR>
"eXecute string below cursor
nmap \x
:silent !start rundll32 url.dll,FileProtocolHandler
<cWORD> <CR>
" eXecute string below cursor after prepending it with path to
file
nmap \xl :silent !start rundll32 url.dll,FileProtocolHandler
%:p:h/<cWORD> <CR>
"__________________________________________
See:
help filename-modifiers

http://www.vim.org/tips/tip.php?tip_id=628 (1 of 3) [18/02/2004 15:08:49]

Tip #628 - Execut "things" in Win98 from within VIM : vim online

help

<cWORD>

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Customizing ftplugin, syntax etc. (eg for TeX) | After quitting VIM, comeback to the same file position where
you were while quitting. >>

Additional Notes
Suresh Govindachar, January 1, 2004 16:27
Executing a directory works, but this is not a good usage
of the mapping -- since it is better to edit a directory!
See help file-explorer
Suresh Govindachar, January 1, 2004 20:08
Although the example given above about searching this website
for "mail" does work with \x, there is a bug in rundll32 that
prevents \x from working on url's that end with an actual
file -- see
"http://support.microsoft.com/default.aspx?scid=kb;enus;283225";
The following mapping can be used for such cases (based on
vimtip #394):
nmap \e
:silent !start "c:\program files\internet
explorer\iexplore.exe" -nohome <cWORD> <CR>
hermitte {at} free {dot} fr, January 6, 2004 1:51
Because sometimes URLs can be within a pair of brackets or
<>, I'm using : the following mappings:
nnoremap <silent> <C-L>e
\ :exe ':!start cygstart '.
\
matchstr(expand('<cWORD>'),
\
'\%(.\{}\zs\%(news:\\|mailto:\\|ftp://\\|https\=://\)\)\=[^:;,<>]\+'
\ )<CR>
vnoremap <silent> <C-L>e
\ <C-\><C-N>:let w:a_save=@a<cr>gv"ay
\ :exe ':!start cygstart '.@a<CR>:let
@a=w:a_save<cr>:unlet w:a_save<cr>
(Note as filenames may contains spaces, I haven't tried to
support file:///)

http://www.vim.org/tips/tip.php?tip_id=628 (2 of 3) [18/02/2004 15:08:49]

Tip #628 - Execut "things" in Win98 from within VIM : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=628 (3 of 3) [18/02/2004 15:08:49]

SourceForge
Logo

Tip #629 - After quitting VIM, comeback to the same file position where you were while quitting. : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #629: After quitting VIM, comeback to the same file position
where you were while quitting.
tip karma

Rating -14/14, Viewed by 899

created: January 2, 2004 3:21


author: Smart opening and closing

complexity: basic
as of Vim: 5.7

many a times while editing a big file we may temporarily


want to go to command prompt and
open the same file again. Then again you will be in the
first character of the file. This is a smarter tip for
taking the cursor to the same position where you were
while quitting.
Just when you want to quit VIM instead of pressing ESC
:q
just press ctrl+z. You can see this
[1]+ Stopped
vim <filename>
you are in command prompt now. Do your work and when u
want to return to VIm press fg.
Thats it.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Execut "things" in Win98 from within VIM | usefull for programming >>

Additional Notes
drNchip@OcampSbellPfamilyA.bizM, January 2, 2004 7:19
In order to exit vim and return later to the file at
the same file position, see vimtip#80.
Anonymous, January 5, 2004 2:55
May be using '0 or `0 is easier? :)
sgs_ocp@yahoo.com, January 7, 2004 1:03

http://www.vim.org/tips/tip.php?tip_id=629 (1 of 3) [18/02/2004 15:08:53]

Tip #629 - After quitting VIM, comeback to the same file position where you were while quitting. : vim online

Hi
i don't know exactly how but my VIM 6.2 on win 2k saves
position when i re open the file !
i use :wq to save and exit
Romland, January 8, 2004 3:42
...and if you found this interesting you might also
find that you can open more VIMs at the command prompt
and suspend those too (with ctrl-z). Then to see a list
of all suspended VIMs (processes) you type 'jobs'.
Might look something like this:
fnurt@iblam[www]$ jobs
[1]- Stopped
vim foo
[2]+ Stopped
vim bar
To return to either of the processes just type %1 for
the first one and %2 for the second one and so forth.
cheers.
da_infamous_one@hotmail.com, February 5, 2004 8:06
....unfortunately you cannot suspend processes like
that in windows.
Another solution to edit multiple files in vim is to
use vim's multiple buffers.
Just place the following in your .vimrc file
map <M-Left> :bN!<CR>
map <M-Right> :bn!<CR>
map <M-Up> :buffers<CR>
Just load up all your files in vim, by recursive :e
command or at prompt vim *
Now you can cycle through your multiple buffers by
pressing the alt-left or alt-right.
Oh and alt-up will show your buffer list...
enjoy.
da_infamous_one@hotmail.com, February 5, 2004 8:06

http://www.vim.org/tips/tip.php?tip_id=629 (2 of 3) [18/02/2004 15:08:53]

Tip #629 - After quitting VIM, comeback to the same file position where you were while quitting. : vim online

....unfortunately you cannot suspend processes like


that in windows.
Another solution to edit multiple files in vim is to
use vim's multiple buffers.
Just place the following in your .vimrc file
map <M-Left> :bN!<CR>
map <M-Right> :bn!<CR>
map <M-Up> :buffers<CR>
Just load up all your files in vim, by recursive :e
command or at prompt vim *
Now you can cycle through your multiple buffers by
pressing the alt-left or alt-right.
Oh and alt-up will show your buffer list...
mmr@b1n.org, February 5, 2004 10:58
Well, that is not a VIM issue. That is shell's behavior
(ie. its environment dependent).
Honestly, this tip is pretty useless for non-unix
users.
Read this tip:
http://vim.sourceforge.net/tips/tip.php?tip_id=80 if
you want something really clever.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=629 (3 of 3) [18/02/2004 15:08:53]

SourceForge
Logo

Tip #630 - usefull for programming : vim online

not logged in (login)

Home
Search

Tip #630: usefull for programming


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 15/14, Viewed by 1881

created: January 2, 2004 19:59


author: Andrzej Cuber

complexity: basic
as of Vim: 6.0

Hello,
I was looking for that feature for the very long time.
I use vim for programming and I always keep forgetting
about closing the parents, quotes etc.
I wanted to remap the keyboard in insert mode in that
way that when I open a quote or parent I will get the
closing one and the cursor would be placed between these
two characters.
here is
<pre>
:imap (
:imap [
:imap "
</pre>

the stuff I put in my ~/.vimrc file


()<Left>
[]<Left>
<C-V>"<C-V>"<left>

I had to use <C-V> to avoid recursive mapping of the "


character.
Maybe there is the feature build in vim already but I
couldn't find it :)
Every comment is welcome :)

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<After quitting VIM, comeback to the same file position where you were while quitting. | Disabling IME
input in Windows >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=630 (1 of 2) [18/02/2004 15:08:57]

Tip #630 - usefull for programming : vim online

hermitte {at} free {dot} fr, January 3, 2004 11:50


There exist several (many ?) plugins and tips focusing
on this issue on this site.
For instance, check my set of plugins available here
vimtip#50, and used in several ftplugins (see
vimtip#336, and http://hermitte.free.fr/vim/) of mine.
Regarding the recursive definition of ", dont use
:imap, but :inoremap. Actually, you'd better always use
the :*noremap commands and reserve :*map for the cases
you explicitely need them.
hermitte {at} free {dot} fr, January 3, 2004 11:53
Oups ! I did,'t mean vimtip#... but vimscript#50 and
vimscript#336.
fish=natter, aei.ca=school, January 21, 2004 8:08
I love this one:
inoremap ; <C-O>A;
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=630 (2 of 2) [18/02/2004 15:08:57]

SourceForge
Logo

Tip #631 - Disabling IME input in Windows : vim online

not logged in (login)

Home
Search

Tip #631: Disabling IME input in Windows


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 9/7, Viewed by 589

created: January 4, 2004 15:03


author: Avery M.

complexity: basic
as of Vim: 5.7

Often, your Windows locale will reflect a foreign


country (e.g. Japan) so you can write text in another
character set, but you don't want Vim to do that by
default. It is annoying to have to disable IME input
every time you start up Vim. But it's much easier than
that. Simply add this line to your vimrc (usually at
C:\vim\_vimrc):
set iminsert=0
Now, you will start out in regular Roman input mode,
without IME. Enjoy!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<usefull for programming | Setting the font in the GUI >>

Additional Notes
Anonymous, January 4, 2004 18:04
imcmdline and imsearch can also be disabled in the same
way.
Anonymous, January 5, 2004 2:08
set imdisable
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=631 [18/02/2004 15:09:01]

SourceForge
Logo

Tip #632 - Setting the font in the GUI : vim online

not logged in (login)

Home
Search

Tip #632: Setting the font in the GUI


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 41/20, Viewed by 1203

created: January 7, 2004 11:53


author: Tony Mechelynck

complexity: basic
as of Vim: 6.0

This tip concerns the setting of the 'guifont' option.


It is assumed that 'guifontset" and 'guifontwide' will,
if available, be left empty or set to a non-conflicting
value. Of course, this apples only to the GUI, since the
font for 'console' vim is determined by the particular
terminal or terminal emulator being used.
Background
---------1. As of this writing (January 2004) there are 3
different possible formats for the 'guifont' option,
namely GTK+2, other-X11 and other. Each version of the
GUI accepts only one of them.
2. Some versions allow selecting the font by means of a
menu, using
:set guifont=*
However, the result is usually too restrictive.
3. Most versions allow setting an option by editing the
current value, using
:set guifont=<Tab>
:set guifont=<Ctrl-E>

(if 'nocompatible'), or
(if 'compatible')

The current value appears, with escaping backslashes if


and where needed. Change what you want to change, write
it down so you can later enter it in your vimrc if you
find out that you like it, then press <Enter> to accept
the new result.
How to proceed
-------------The default value for 'guifont' is the null string.
However, a default or system vimrc may already have set
http://www.vim.org/tips/tip.php?tip_id=632 (1 of 3) [18/02/2004 15:09:04]

Tip #632 - Setting the font in the GUI : vim online

some value. If what you see is "almost" what you want,


use method 3 above. If the current value is empty, you
will have to proceed in some other way. In that case,
press <Esc> to leave command-line mode.
If the current value is empty, or if the current font
has neither the shape nor the size that you want, try
method 2 above. If it doesn't work, copy the code
snippet found at the end of this tip into your vimrc and
start from there, changing one thing at a time until
you're satisfied.
If your version of vim allows selecting fonts via a
menu, I recommend (for X11 without GTK+2) keeping only
what is required to have a working font and replacing
the rest (including, most especially, the last
parameter, which is the encoding) by dash-separated
asterisks; or (for other systems) keeping the font name
and size and removing the rest (or, for non-X11, setting
the encoding to cDEFAULT). See the examples below.
Now here is a snippet of code, applicable (I hope) to
all versions of gvim. The only reason I haven't tested
them all is I don't have them all. Start with that,
change the "set" statements as needed, and put it in
your vimrc.
if has("gui_running")
if has("gui_gtk2")
set guifont=Courier\ New\ 11
elseif has("x11")
set guifont=-*-courier-medium-r-normal-*-*180-*-*-m-*-*
else
set guifont=Courier_New:h11:cDEFAULT
endif
endif
Happy Vimming!
Tony.
rate this tip

Life Changing

Helpful

Unfulfilling

<<Disabling IME input in Windows | spell check of word below cursor >>

Additional Notes

http://www.vim.org/tips/tip.php?tip_id=632 (2 of 3) [18/02/2004 15:09:04]

rate

Tip #632 - Setting the font in the GUI : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=632 (3 of 3) [18/02/2004 15:09:04]

SourceForge
Logo

Tip #633 - spell check of word below cursor : vim online

not logged in (login)

Home
Search

Tip #633: spell check of word below cursor


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 20/11, Viewed by 958

created: January 8, 2004 3:42


author: nobody

complexity: intermediate
as of Vim: 6.0

poor man's grep of spell checking for unix based systems


requires aspell/ispell to be available in path or use
full path in map command
map <A-e> :!echo <cword> \| ispell -d british -a -<return>
map <A-d> :!echo <cword> \| ispell -d danish -a -<return>
spell check words in either english or danish
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Setting the font in the GUI | To view all colours available to gvim >>

Additional Notes
JonathanOrlev@yahoo.com, January 11, 2004 1:30
Very nive tip.
ThanQ very much.
don@seiler.us, January 14, 2004 7:41
This probably deserves an RTFM, but what does "map <Ae>" map to? Meaning what keys do I hit to run the
command?
surs.deletethis@cis.ohio-state.edu, January 14, 2004 7:49

http://www.vim.org/tips/tip.php?tip_id=633 (1 of 2) [18/02/2004 15:09:08]

Tip #633 - spell check of word below cursor : vim online

Nice tip, I've been looking for something like this.


I don't know what <A-e> maps to, but I've mapped it to
,s (which is easier to remember!)
map ,s :!echo <cword> \| ispell -a -- <return>
s7726@yahoo.com, January 22, 2004 13:42
<A-e> maps to Alt-e as per the manual
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=633 (2 of 2) [18/02/2004 15:09:08]

SourceForge
Logo

Tip #634 - To view all colours available to gvim : vim online

not logged in (login)

Tip #634: To view all colours available to gvim

Home
Search

tip karma
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 7/7, Viewed by 1031

created: January 8, 2004 15:40


author: mosh at http://www.cs.albany.edu/~mosh

complexity: basic
as of Vim: 6.0

What: To see all the colours available in gvim, with


their names.
How:

Save this tip and open in gvim and do ':source %'

Caveats: some colours appear wrong in gvim,


but are correct in opera/eudora/emacs.

Site Help

See: Color names are from X11/rgb.txt, see also


$VIM/syntax/colortest.vim
- http://www.cs.albany.edu/~mosh
---- cut-here ------/\ssnow/,$ g/^" \\w/ exec 'hi col_'.expand("<cword>").'
guifg='.expand("<cword>")|
\\ exec 'syn keyword
col_'.expand("<cword>")." ".expand("<cword>")
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

snow
GhostWhite
WhiteSmoke
gainsboro
FloralWhite
OldLace
linen
AntiqueWhite
PapayaWhip
BlanchedAlmond
bisque
PeachPuff
NavajoWhite
moccasin
cornsilk
ivory
LemonChiffon

http://www.vim.org/tips/tip.php?tip_id=634 (1 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

seashell
honeydew
MintCream
azure
AliceBlue
lavender
LavenderBlush
MistyRose
white
black
DarkSlateGray
DarkSlateGrey
DimGray
DimGrey
SlateGray
SlateGrey
LightSlateGray
LightSlateGrey
gray
grey
LightGrey
LightGray
MidnightBlue
navy
NavyBlue
CornflowerBlue
DarkSlateBlue
SlateBlue
MediumSlateBlue
LightSlateBlue
MediumBlue
RoyalBlue
blue
DodgerBlue
DeepSkyBlue
SkyBlue
LightSkyBlue
SteelBlue
LightSteelBlue
LightBlue
PowderBlue
PaleTurquoise
DarkTurquoise
MediumTurquoise
turquoise
cyan
LightCyan
CadetBlue
MediumAquamarine

http://www.vim.org/tips/tip.php?tip_id=634 (2 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

aquamarine
DarkGreen
DarkOliveGreen
DarkSeaGreen
SeaGreen
MediumSeaGreen
LightSeaGreen
PaleGreen
SpringGreen
LawnGreen
green
chartreuse
MediumSpringGreen
GreenYellow
LimeGreen
YellowGreen
ForestGreen
OliveDrab
DarkKhaki
khaki
PaleGoldenrod
LightGoldenrodYellow
LightYellow
yellow
gold
LightGoldenrod
goldenrod
DarkGoldenrod
RosyBrown
IndianRed
SaddleBrown
sienna
peru
burlywood
beige
wheat
SandyBrown
tan
chocolate
firebrick
brown
DarkSalmon
salmon
LightSalmon
orange
DarkOrange
coral
LightCoral
tomato

http://www.vim.org/tips/tip.php?tip_id=634 (3 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

OrangeRed
red
HotPink
DeepPink
pink
LightPink
PaleVioletRed
maroon
MediumVioletRed
VioletRed
magenta
violet
plum
orchid
MediumOrchid
DarkOrchid
DarkViolet
BlueViolet
purple
MediumPurple
thistle
snow1
snow2
snow3
snow4
seashell1
seashell2
seashell3
seashell4
AntiqueWhite1
AntiqueWhite2
AntiqueWhite3
AntiqueWhite4
bisque1
bisque2
bisque3
bisque4
PeachPuff1
PeachPuff2
PeachPuff3
PeachPuff4
NavajoWhite1
NavajoWhite2
NavajoWhite3
NavajoWhite4
LemonChiffon1
LemonChiffon2
LemonChiffon3
LemonChiffon4

http://www.vim.org/tips/tip.php?tip_id=634 (4 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

cornsilk1
cornsilk2
cornsilk3
cornsilk4
ivory1
ivory2
ivory3
ivory4
honeydew1
honeydew2
honeydew3
honeydew4
LavenderBlush1
LavenderBlush2
LavenderBlush3
LavenderBlush4
MistyRose1
MistyRose2
MistyRose3
MistyRose4
azure1
azure2
azure3
azure4
SlateBlue1
SlateBlue2
SlateBlue3
SlateBlue4
RoyalBlue1
RoyalBlue2
RoyalBlue3
RoyalBlue4
blue1
blue2
blue3
blue4
DodgerBlue1
DodgerBlue2
DodgerBlue3
DodgerBlue4
SteelBlue1
SteelBlue2
SteelBlue3
SteelBlue4
DeepSkyBlue1
DeepSkyBlue2
DeepSkyBlue3
DeepSkyBlue4
SkyBlue1

http://www.vim.org/tips/tip.php?tip_id=634 (5 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

SkyBlue2
SkyBlue3
SkyBlue4
LightSkyBlue1
LightSkyBlue2
LightSkyBlue3
LightSkyBlue4
SlateGray1
SlateGray2
SlateGray3
SlateGray4
LightSteelBlue1
LightSteelBlue2
LightSteelBlue3
LightSteelBlue4
LightBlue1
LightBlue2
LightBlue3
LightBlue4
LightCyan1
LightCyan2
LightCyan3
LightCyan4
PaleTurquoise1
PaleTurquoise2
PaleTurquoise3
PaleTurquoise4
CadetBlue1
CadetBlue2
CadetBlue3
CadetBlue4
turquoise1
turquoise2
turquoise3
turquoise4
cyan1
cyan2
cyan3
cyan4
DarkSlateGray1
DarkSlateGray2
DarkSlateGray3
DarkSlateGray4
aquamarine1
aquamarine2
aquamarine3
aquamarine4
DarkSeaGreen1
DarkSeaGreen2

http://www.vim.org/tips/tip.php?tip_id=634 (6 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

DarkSeaGreen3
DarkSeaGreen4
SeaGreen1
SeaGreen2
SeaGreen3
SeaGreen4
PaleGreen1
PaleGreen2
PaleGreen3
PaleGreen4
SpringGreen1
SpringGreen2
SpringGreen3
SpringGreen4
green1
green2
green3
green4
chartreuse1
chartreuse2
chartreuse3
chartreuse4
OliveDrab1
OliveDrab2
OliveDrab3
OliveDrab4
DarkOliveGreen1
DarkOliveGreen2
DarkOliveGreen3
DarkOliveGreen4
khaki1
khaki2
khaki3
khaki4
LightGoldenrod1
LightGoldenrod2
LightGoldenrod3
LightGoldenrod4
LightYellow1
LightYellow2
LightYellow3
LightYellow4
yellow1
yellow2
yellow3
yellow4
gold1
gold2
gold3

http://www.vim.org/tips/tip.php?tip_id=634 (7 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

gold4
goldenrod1
goldenrod2
goldenrod3
goldenrod4
DarkGoldenrod1
DarkGoldenrod2
DarkGoldenrod3
DarkGoldenrod4
RosyBrown1
RosyBrown2
RosyBrown3
RosyBrown4
IndianRed1
IndianRed2
IndianRed3
IndianRed4
sienna1
sienna2
sienna3
sienna4
burlywood1
burlywood2
burlywood3
burlywood4
wheat1
wheat2
wheat3
wheat4
tan1
tan2
tan3
tan4
chocolate1
chocolate2
chocolate3
chocolate4
firebrick1
firebrick2
firebrick3
firebrick4
brown1
brown2
brown3
brown4
salmon1
salmon2
salmon3
salmon4

http://www.vim.org/tips/tip.php?tip_id=634 (8 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

LightSalmon1
LightSalmon2
LightSalmon3
LightSalmon4
orange1
orange2
orange3
orange4
DarkOrange1
DarkOrange2
DarkOrange3
DarkOrange4
coral1
coral2
coral3
coral4
tomato1
tomato2
tomato3
tomato4
OrangeRed1
OrangeRed2
OrangeRed3
OrangeRed4
red1
red2
red3
red4
DeepPink1
DeepPink2
DeepPink3
DeepPink4
HotPink1
HotPink2
HotPink3
HotPink4
pink1
pink2
pink3
pink4
LightPink1
LightPink2
LightPink3
LightPink4
PaleVioletRed1
PaleVioletRed2
PaleVioletRed3
PaleVioletRed4
maroon1

http://www.vim.org/tips/tip.php?tip_id=634 (9 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

maroon2
maroon3
maroon4
VioletRed1
VioletRed2
VioletRed3
VioletRed4
magenta1
magenta2
magenta3
magenta4
orchid1
orchid2
orchid3
orchid4
plum1
plum2
plum3
plum4
MediumOrchid1
MediumOrchid2
MediumOrchid3
MediumOrchid4
DarkOrchid1
DarkOrchid2
DarkOrchid3
DarkOrchid4
purple1
purple2
purple3
purple4
MediumPurple1
MediumPurple2
MediumPurple3
MediumPurple4
thistle1
thistle2
thistle3
thistle4
gray0
grey0
gray1
grey1
gray2
grey2
gray3
grey3
gray4
grey4

http://www.vim.org/tips/tip.php?tip_id=634 (10 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

gray5
grey5
gray6
grey6
gray7
grey7
gray8
grey8
gray9
grey9
gray10
grey10
gray11
grey11
gray12
grey12
gray13
grey13
gray14
grey14
gray15
grey15
gray16
grey16
gray17
grey17
gray18
grey18
gray19
grey19
gray20
grey20
gray21
grey21
gray22
grey22
gray23
grey23
gray24
grey24
gray25
grey25
gray26
grey26
gray27
grey27
gray28
grey28
gray29

http://www.vim.org/tips/tip.php?tip_id=634 (11 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

grey29
gray30
grey30
gray31
grey31
gray32
grey32
gray33
grey33
gray34
grey34
gray35
grey35
gray36
grey36
gray37
grey37
gray38
grey38
gray39
grey39
gray40
grey40
gray41
grey41
gray42
grey42
gray43
grey43
gray44
grey44
gray45
grey45
gray46
grey46
gray47
grey47
gray48
grey48
gray49
grey49
gray50
grey50
gray51
grey51
gray52
grey52
gray53
grey53

http://www.vim.org/tips/tip.php?tip_id=634 (12 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

gray54
grey54
gray55
grey55
gray56
grey56
gray57
grey57
gray58
grey58
gray59
grey59
gray60
grey60
gray61
grey61
gray62
grey62
gray63
grey63
gray64
grey64
gray65
grey65
gray66
grey66
gray67
grey67
gray68
grey68
gray69
grey69
gray70
grey70
gray71
grey71
gray72
grey72
gray73
grey73
gray74
grey74
gray75
grey75
gray76
grey76
gray77
grey77
gray78

http://www.vim.org/tips/tip.php?tip_id=634 (13 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"

grey78
gray79
grey79
gray80
grey80
gray81
grey81
gray82
grey82
gray83
grey83
gray84
grey84
gray85
grey85
gray86
grey86
gray87
grey87
gray88
grey88
gray89
grey89
gray90
grey90
gray91
grey91
gray92
grey92
gray93
grey93
gray94
grey94
gray95
grey95
gray96
grey96
gray97
grey97
gray98
grey98
gray99
grey99
gray100
grey100
DarkGrey
DarkGray
DarkBlue
DarkCyan

http://www.vim.org/tips/tip.php?tip_id=634 (14 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

" DarkMagenta
" DarkRed
" LightGreen

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<spell check of word below cursor | getting colors to work on solaris >>

Additional Notes
mosh, January 8, 2004 16:05
In the first two lines, change double backslashes to
single-backslashes.
I can't post single backslashes from the web interface.
Also keep the cursor the first line, when doing ':so
%'.
drNchip@OcampSbellPfamilyA.comM - NOSPAM, January 9, 2004 9:48
I believe vim is limited to 224 concurrent colors due
to the way it is stored.
Anonymous, January 9, 2004 20:16
Hmm... all colors show in :highlight though.
Couldn't ever get this to work within the file on
WinXP, although again, :highlight showed them all.
http://www.cs.albany.edu/~mosh, January 13, 2004 18:52
I simplified the script below, you can try it on 100
colors at a time
to see your choices, since vim seems to have a limit on
the
number of simultaneous colors.
Note that the second line has two double backslashes,
they might
get deleted in the process the web posting.
- mosh
-- cut here -call search("^$")
while search("\\w\\+") > 0
http://www.vim.org/tips/tip.php?tip_id=634 (15 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

:exec 'hi col_'.expand("<cword>").'


guifg='.expand("<cword>")|
:exec 'syn keyword col_'.expand("<cword>")."
".expand("<cword>")
endwhile
" snow GhostWhite WhiteSmoke gainsboro FloralWhite
OldLace linen
" AntiqueWhite PapayaWhip BlanchedAlmond bisque
PeachPuff NavajoWhite
" moccasin cornsilk ivory LemonChiffon seashell
honeydew MintCream azure
" AliceBlue lavender LavenderBlush MistyRose white
black DarkSlateGray
" DarkSlateGrey DimGray DimGrey SlateGray SlateGrey
LightSlateGray
" LightSlateGrey gray grey LightGrey LightGray
MidnightBlue navy
" NavyBlue CornflowerBlue DarkSlateBlue SlateBlue
MediumSlateBlue
" LightSlateBlue MediumBlue RoyalBlue blue DodgerBlue
DeepSkyBlue
" SkyBlue LightSkyBlue SteelBlue LightSteelBlue
LightBlue PowderBlue
" PaleTurquoise DarkTurquoise MediumTurquoise turquoise
cyan LightCyan
" CadetBlue MediumAquamarine aquamarine DarkGreen
DarkOliveGreen
" DarkSeaGreen SeaGreen MediumSeaGreen LightSeaGreen
PaleGreen SpringGreen
" LawnGreen green chartreuse MediumSpringGreen
GreenYellow LimeGreen
" YellowGreen ForestGreen OliveDrab DarkKhaki khaki
PaleGoldenrod
" LightGoldenrodYellow LightYellow yellow gold
LightGoldenrod goldenrod
" DarkGoldenrod RosyBrown IndianRed SaddleBrown sienna
peru burlywood
" beige wheat SandyBrown tan chocolate firebrick brown
DarkSalmon salmon
" LightSalmon orange DarkOrange coral LightCoral tomato
OrangeRed red
" HotPink DeepPink pink LightPink PaleVioletRed maroon
MediumVioletRed
" VioletRed magenta violet plum orchid MediumOrchid
DarkOrchid DarkViolet
" BlueViolet purple MediumPurple thistle snow1 snow2
snow3 snow4
" seashell1 seashell2 seashell3 seashell4 AntiqueWhite1
AntiqueWhite2
http://www.vim.org/tips/tip.php?tip_id=634 (16 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

" AntiqueWhite3 AntiqueWhite4 bisque1 bisque2 bisque3


bisque4 PeachPuff1
" PeachPuff2 PeachPuff3 PeachPuff4 NavajoWhite1
NavajoWhite2 NavajoWhite3
" NavajoWhite4 LemonChiffon1 LemonChiffon2
LemonChiffon3 LemonChiffon4
" cornsilk1 cornsilk2 cornsilk3 cornsilk4 ivory1 ivory2
ivory3 ivory4
" honeydew1 honeydew2 honeydew3 honeydew4
LavenderBlush1 LavenderBlush2
" LavenderBlush3 LavenderBlush4 MistyRose1 MistyRose2
MistyRose3
" MistyRose4 azure1 azure2 azure3 azure4 SlateBlue1
SlateBlue2 SlateBlue3
" SlateBlue4 RoyalBlue1 RoyalBlue2 RoyalBlue3
RoyalBlue4 blue1
" blue2 blue3 blue4 DodgerBlue1 DodgerBlue2 DodgerBlue3
DodgerBlue4
" SteelBlue1 SteelBlue2 SteelBlue3 SteelBlue4
DeepSkyBlue1 DeepSkyBlue2
" DeepSkyBlue3 DeepSkyBlue4 SkyBlue1 SkyBlue2 SkyBlue3
SkyBlue4
" LightSkyBlue1 LightSkyBlue2 LightSkyBlue3
LightSkyBlue4 SlateGray1
" SlateGray2 SlateGray3 SlateGray4 LightSteelBlue1
LightSteelBlue2
" LightSteelBlue3 LightSteelBlue4 LightBlue1 LightBlue2
LightBlue3
" LightBlue4 LightCyan1 LightCyan2 LightCyan3
LightCyan4 PaleTurquoise1
" PaleTurquoise2 PaleTurquoise3 PaleTurquoise4
CadetBlue1 CadetBlue2
" CadetBlue3 CadetBlue4 turquoise1 turquoise2
turquoise3 turquoise4
" cyan1 cyan2 cyan3 cyan4 DarkSlateGray1 DarkSlateGray2
DarkSlateGray3
" DarkSlateGray4 aquamarine1 aquamarine2 aquamarine3
aquamarine4
" DarkSeaGreen1 DarkSeaGreen2 DarkSeaGreen3
DarkSeaGreen4 SeaGreen1
" SeaGreen2 SeaGreen3 SeaGreen4 PaleGreen1 PaleGreen2
PaleGreen3
" PaleGreen4 SpringGreen1 SpringGreen2 SpringGreen3
SpringGreen4
" green1 green2 green3 green4 chartreuse1 chartreuse2
chartreuse3
" chartreuse4 OliveDrab1 OliveDrab2 OliveDrab3
OliveDrab4 DarkOliveGreen1
" DarkOliveGreen2 DarkOliveGreen3 DarkOliveGreen4

http://www.vim.org/tips/tip.php?tip_id=634 (17 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

khaki1 khaki2 khaki3


" khaki4 LightGoldenrod1 LightGoldenrod2
LightGoldenrod3 LightGoldenrod4
" LightYellow1 LightYellow2 LightYellow3 LightYellow4
yellow1 yellow2
" yellow3 yellow4 gold1 gold2 gold3 gold4 goldenrod1
goldenrod2 goldenrod3
" goldenrod4 DarkGoldenrod1 DarkGoldenrod2
DarkGoldenrod3 DarkGoldenrod4
" RosyBrown1 RosyBrown2 RosyBrown3 RosyBrown4
IndianRed1 IndianRed2
" IndianRed3 IndianRed4 sienna1 sienna2 sienna3 sienna4
burlywood1
" burlywood2 burlywood3 burlywood4 wheat1 wheat2 wheat3
wheat4 tan1
" tan2 tan3 tan4 chocolate1 chocolate2 chocolate3
chocolate4 firebrick1
" firebrick2 firebrick3 firebrick4 brown1 brown2 brown3
brown4 salmon1
" salmon2 salmon3 salmon4 LightSalmon1 LightSalmon2
LightSalmon3
" LightSalmon4 orange1 orange2 orange3 orange4
DarkOrange1 DarkOrange2
" DarkOrange3 DarkOrange4 coral1 coral2 coral3 coral4
tomato1 tomato2
" tomato3 tomato4 OrangeRed1 OrangeRed2 OrangeRed3
OrangeRed4 red1 red2
" red3 red4 DeepPink1 DeepPink2 DeepPink3 DeepPink4
HotPink1 HotPink2
" HotPink3 HotPink4 pink1 pink2 pink3 pink4 LightPink1
LightPink2
" LightPink3 LightPink4 PaleVioletRed1 PaleVioletRed2
PaleVioletRed3
" PaleVioletRed4 maroon1 maroon2 maroon3 maroon4
VioletRed1 VioletRed2
" VioletRed3 VioletRed4 magenta1 magenta2 magenta3
magenta4 orchid1
" orchid2 orchid3 orchid4 plum1 plum2 plum3 plum4
MediumOrchid1
" MediumOrchid2 MediumOrchid3 MediumOrchid4 DarkOrchid1
DarkOrchid2
" DarkOrchid3 DarkOrchid4 purple1 purple2 purple3
purple4 MediumPurple1
" MediumPurple2 MediumPurple3 MediumPurple4 thistle1
thistle2 thistle3
" thistle4 gray0 grey0 gray1 grey1 gray2 grey2 gray3
grey3 gray4 grey4
" gray5 grey5 gray6 grey6 gray7 grey7 gray8 grey8 gray9
grey9 gray10

http://www.vim.org/tips/tip.php?tip_id=634 (18 of 19) [18/02/2004 15:09:14]

Tip #634 - To view all colours available to gvim : vim online

" grey10 gray11 grey11 gray12 grey12


gray14 grey14 gray15
" grey15 gray16 grey16 gray17 grey17
gray19 grey19 gray20
" grey20 gray21 grey21 gray22 grey22
gray24 grey24 gray25
" grey25 gray26 grey26 gray27 grey27
gray29 grey29 gray30
" grey30 gray31 grey31 gray32 grey32
gray34 grey34 gray35
" grey35 gray36 grey36 gray37 grey37
gray39 grey39 gray40
" grey40 gray41 grey41 gray42 grey42
gray44 grey44 gray45
" grey45 gray46 grey46 gray47 grey47
gray49 grey49 gray50
" grey50 gray51 grey51 gray52 grey52
gray54 grey54 gray55
" grey55 gray56 grey56 gray57 grey57
gray59 grey59 gray60
" grey60 gray61 grey61 gray62 grey62
gray64 grey64 gray65
" grey65 gray66 grey66 gray67 grey67
gray69 grey69 gray70
" grey70 gray71 grey71 gray72 grey72
gray74 grey74 gray75
" grey75 gray76 grey76 gray77 grey77
gray79 grey79 gray80
" grey80 gray81 grey81 gray82 grey82
gray84 grey84 gray85
" grey85 gray86 grey86 gray87 grey87
gray89 grey89 gray90
" grey90 gray91 grey91 gray92 grey92
gray94 grey94 gray95
" grey95 gray96 grey96 gray97 grey97
gray99 grey99 gray100
" grey100 DarkGrey DarkGray DarkBlue
DarkMagenta DarkRed
" LightGreen

gray13 grey13
gray18 grey18
gray23 grey23
gray28 grey28
gray33 grey33
gray38 grey38
gray43 grey43
gray48 grey48
gray53 grey53
gray58 grey58
gray63 grey63
gray68 grey68
gray73 grey73
gray78 grey78
gray83 grey83
gray88 grey88
gray93 grey93
gray98 grey98
DarkCyan

a_or_pschultz@msn.com, February 12, 2004 17:57


what do the colors mean? Directory-blue
file-green are there more?//

Executable

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=634 (19 of 19) [18/02/2004 15:09:14]

SourceForge
Logo

Tip #635 - getting colors to work on solaris : vim online

not logged in (login)

Home
Search

Tip #635: getting colors to work on solaris


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 14/9, Viewed by 526

created: January 14, 2004 14:24


author: Brad Lhotsky

complexity: basic
as of Vim: 5.7

You need to get the latest ncurses package available at


http://www.sunfreeware.com/ and then configure with this
option:
--with-tlib=ncurses
This will link to ncurses which fully supports the color
codes. Then make sure your display is exported as
a color capable terminal.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<To view all colours available to gvim | Adding Vim to MS-Windows File Explorer Menu >>

Additional Notes
smaillboy@yahoo.com, January 22, 2004 23:54
I tried this in sun solaris 2.8.. but didn't work
out.
I installed ncurses from the site mentioned and of no
use...
-Prem
sleelsc@yahoo.com, January 23, 2004 20:52
I tried type in the line as VIM command, it return
error: "E492: Not an editor command: --withtlib=ncuerses."
And it dosen't work either, if I put it in my .vimrc
file.
Someone know anything about this, please help!!!
ipkiss _at_ via.ecp.fr, January 29, 2004 7:18

http://www.vim.org/tips/tip.php?tip_id=635 (1 of 2) [18/02/2004 15:09:18]

Tip #635 - getting colors to work on solaris : vim online

This tip didn't work for me either, but i found another


solution: setting the TERM environment variable to "suncolor" did the trick. What's more, it worked only when
i did NOT compile with --with-tlib=ncurses (letting it
to the default automatic detection) because with it vim
said my TERM was unknown :-)
Brad Lhotsky, January 29, 2004 8:18
You also need to setup ld to search /usr/local/lib. To
do this see man crle. Add that in, make distclean,
reconfigure, and build..
Note: This is NOT a runtime
(command line/ vimrc) tip, its a compilation tip.
mzhao@net9.org, February 9, 2004 2:10
Maybe you should "export TERM=xterm-color" in addition
to "configure with this option: --with-tlib=ncurses ".
It works well on my box.
schella@comp.uark.edu, February 15, 2004 21:16
Here's what works on my Solaris 8/9 boxes:
(I lifted this off of somewhere and possibly refined
it, but I have no idea where).
:if &term =~ "xterm"
: if has("terminfo")
:
set t_Co=8
:
set t_Sf=ESC[3%p1%dm
:
set t_Sb=ESC[4%p1%dm
: else
:
set t_Co=8
:
set t_Sf=ESC[3%dm
:
set t_Sb=ESC[4%dm
:endif
:endif
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=635 (2 of 2) [18/02/2004 15:09:18]

SourceForge
Logo

Tip #636 - Adding Vim to MS-Windows File Explorer Menu : vim online

not logged in (login)

Home
Search

Tip #636: Adding Vim to MS-Windows File Explorer Menu


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 18/8, Viewed by 1022

created: January 14, 2004 17:53


author: http://www.cs.albany.edu/~mosh

complexity: basic
as of Vim: 5.7

What: To Add 'Edit with Vim' to 'Windows File


Explorer'
'right click Menu'
1. Save this file as edit-with-vim.reg,
2. Make sure the paths are right for your machine
3. Change each fowardslash to backslash
with the vim command :%s,/,\\,g
4. Click on it in explorer or import this file in
regedit.exe
voila, your explorer right-click menu will have extra
action items,
it's better than the send-to.
5. The double quotes are needed for filenames with
spaces.
6. The '*' means 'for all files'.
REGEDIT4
[HKEY_CLASSES_ROOT/*/shell]
[HKEY_CLASSES_ROOT/*/shell/vim]
@="Edit with &vim"
[HKEY_CLASSES_ROOT/*/shell/vim/command]
@="c://bin32//gvim.exe /"%1/""
[HKEY_CLASSES_ROOT/*/shell/_emacs]
@="Edit with &Emacs"
[HKEY_CLASSES_ROOT/*/shell/_emacs/command]
@="c://emacs//bin//runemacs.exe /"%1/""

rate this tip

Life Changing

Helpful

Unfulfilling

<<getting colors to work on solaris | execute accidently inserted commands >>

Additional Notes
http://www.vim.org/tips/tip.php?tip_id=636 (1 of 2) [18/02/2004 15:09:21]

rate

Tip #636 - Adding Vim to MS-Windows File Explorer Menu : vim online

Anonymous, January 15, 2004 18:44


Why don't you use GvimExt?
viswanathb@yahoo.com, January 16, 2004 2:08
i thought this facility is already available if
you install gvim... am i wrong?
http://www.cs.albany.edu/~mosh, January 16, 2004 20:12
This will allow window's explorer to launch
vim on directories also (the paths have double
backslashes).
[HKEY_CLASSES_ROOT\Directory\shell\vim_dired]
@="gvim dired"
[HKEY_CLASSES_ROOT\Directory\shell\vim_dired\Command]
@="c:\\bin32\\gvim.exe \"%1\""

Anonymous, January 17, 2004 9:52


What I'd kill for would be the ability to always have
GvimExt's "Edit with Vim" menu item as the *first* item
on the menu (like it was with Vim 5.x) and *also* have
2 additional context menu options:
- Vertically split into existing Vim [foo]
- Horizontally split into existing Vim [foo]
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=636 (2 of 2) [18/02/2004 15:09:21]

SourceForge
Logo

Tip #637 - execute accidently inserted commands : vim online

not logged in (login)

Home
Search

Tip #637: execute accidently inserted commands


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 23/8, Viewed by 424

created: January 17, 2004 12:44


author: Jochen Behrens

complexity: basic
as of Vim: 5.7

If you are in insert mode and typed an command for


normal mode, you can use it.
inoremap <somekey> <esc>u@.
This mapping switches to normal mode, undo'es the last
insertion and takes it as a command.
Most times I need it, if I typed dd and the line still
remains because of Insert-Mode and the unwanted 'dd' ist
somewhere
in my text.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Adding Vim to MS-Windows File Explorer Menu | Editing ActiveState Perl batch files >>

Additional Notes
bertilow@gmx.net, January 18, 2004 3:12
I guess you meant:
inoremap <somekey> <esc>u:@.
sergio@imovelweb.com.br, January 19, 2004 13:01
I prefer inoremap <somekey> <esc>u@. i
zzapper@ntlworld.com, January 20, 2004 1:58
Also
yy@"
yy
@"

yank current line into default register


execute default recording

http://www.vim.org/tips/tip.php?tip_id=637 (1 of 2) [18/02/2004 15:09:25]

Tip #637 - execute accidently inserted commands : vim online

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=637 (2 of 2) [18/02/2004 15:09:25]

SourceForge
Logo

Tip #638 - Editing ActiveState Perl batch files : vim online

not logged in (login)

Home
Search

Tip #638: Editing ActiveState Perl batch files


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/1, Viewed by 294

created: January 19, 2004 2:28


author: David DelGreco

complexity: basic
as of Vim: 5.7

To run Perl scripts under Windows, you can either add


the .pl extension to the PATHEXT env variable, or use
pl2bat, which comes with ActiveState's Perl and makes a
very nice batch file. A quirk of Perl under Win32 is
that piping doesn't work with .pl files (as in bar.pl |
foo.pl) but works fine with the batch files. It has
something to do with how Windows loads files. Anyway,
this all works fine, but every time I do any extensive
edits to a perl/batch file, I have to set cindent and
syntax=perl or it drives me crazy. This tip modifies
filetype.vim to check batch files to see if they're
really perl scripts in disguise.
--->First, find these lines:
" Batch file for MSDOS (*.cmd is close enough)
au BufNewFile,BufRead *.bat,*.cmd,*.sys setf dosbatch
--->Then change them to this:
" Batch file for MSDOS (*.cmd is close enough)
au BufNewFile,BufRead *.bat,*.cmd,*.sys call
FTCheck_bat()
" Perl scripts converted to bat by pl2bat have a unique
string that
" identifies the file. It should be the first line.
fun! FTCheck_bat()
if exists("g:filetype_bat")
exe "setf " . g:filetype_bat
else
let l = getline(nextnonblank(1))
if l =~ '--\*-Perl-\*--'
setf perl
else
setf dosbatch
endif
endif

http://www.vim.org/tips/tip.php?tip_id=638 (1 of 3) [18/02/2004 15:09:28]

Tip #638 - Editing ActiveState Perl batch files : vim online

endfun
--->That's it! This is very specific to look for the
string pl2bat adds to the file, but can be easily
modified to your needs.

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<execute accidently inserted commands | Comment highlight #ifdef DEBUG for code-read ease
(C/C++) >>

Additional Notes
Anonymous, January 19, 2004 4:10
Add this line at the top of your converted pl2bat
script and everything should work automatically:
@rem vim: set ft=perl:
See :h modeline
Same anonymous, January 19, 2004 4:16
A little offtopic about perl:
Under windows you _can_ use piping _not converting to
bat files_
#file test.pl
print "hi!\n";
#file test1.pl
$str = <>;
print "\$str=$str\n";
Now just run perl test.pl | perl test1.pl
And you see piping. :)
Anonymous, January 20, 2004 2:23

http://www.vim.org/tips/tip.php?tip_id=638 (2 of 3) [18/02/2004 15:09:28]

Tip #638 - Editing ActiveState Perl batch files : vim online

Offtopic response. Sorry. It's <STDIN> that doesn't


work correctly. I've got a number of scripts with
multiple command line options with know -specifiers. I know if I use Getopt:: it will clear out
@ARGV (or I can do it myself), but the files have a
long-standing syntax and I just opted to read from
STDIN. Curiously, it works if you pipe to 'perl
foo.pl' or if you use the batch syntax, which does the
same thing, but it actually does not work if you
specify <STDIN> for reading. Try it.
David DelGreco, January 21, 2004 13:52
Thanks to the other posters. I still haven't mastered
the depths of Vim and just didn't think of the
modeline. I'll read up on that. It's certainly a more
direct and reliable of enabling the proper syntax for a
file without relying on the extension.
The last poster was closer to what I was talking about
(incompletely). Try this code:
# foo.pl
($file, $p1, $p2) = @ARGV;
if ($file eq '-') { $s = <STDIN> }
else { open F, $file; $s = <F> }
print $s;
Then try this:
some_filter.pl

foo.pl

param1

param2

For some reason, this doesn't work. Using <> instead


of <STDIN> works, and running this works:
some_filter.pl

perl foo.pl

param1

param2

But not the way I have it. I suppose tihs may point to
a bug in Perl on Windows, but I could also write my
scripts differently. Thanks for some enlightenment on
two subjects.
</offtopic>
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=638 (3 of 3) [18/02/2004 15:09:28]

SourceForge
Logo

Tip #639 - Comment highlight #ifdef DEBUG for code-read ease (C/C++) : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #639: Comment highlight #ifdef DEBUG for code-read ease


(C/C++)
tip karma

Rating 5/5, Viewed by 518

created: January 20, 2004 1:11


author: Karthick Gururaj

complexity: basic
as of Vim: 6.0

Hi all,
If your C/C++ code is scattered with statements like
#ifdef DEBUG
// Some code..
cout << "Debug output: blah" << endl;
#endif
and you would like to highlight these segments in a
different colour (so that
you can skip them visually), add the following code in
your .vimrc (colouring
follows that of comments)
CODE STARTS
syn region MySkip contained
start="^\s*#\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$"
end="^\s*#\s*endif\>" contains=MySkip
let g:CommentDefines = ""
hi link MyCommentOut2 MyCommentOut
hi link MySkip MyCommentOut
hi link MyCommentOut Comment
map <silent> ,a :call AddCommentDefine()<CR>
map <silent> ,x :call ClearCommentDefine()<CR>
function! AddCommentDefine()
let g:CommentDefines = "\\(" . expand("<cword>") .
"\\)"
syn clear MyCommentOut
syn clear MyCommentOut2
exe 'syn region MyCommentOut
start="^\s*#\s*ifdef\s\+' . g:CommentDefines . '\>"
end=".\|$" contains=MyCommentOut2'
exe 'syn region MyCommentOut2 contained start="' .

http://www.vim.org/tips/tip.php?tip_id=639 (1 of 2) [18/02/2004 15:09:32]

Tip #639 - Comment highlight #ifdef DEBUG for code-read ease (C/C++) : vim online

g:CommentDefines . '"
end="^\s*#\s*\(endif\>\|else\>\|elif\>\)"
contains=MySkip'
endfunction
function! ClearCommentDefine()
let g:ClearCommentDefine = ""
syn clear MyCommentOut
syn clear MyCommentOut2
endfunction
CODE ENDS
To see the effect, position the cursor on the word DEBUG
in the C code snippet above and type ,a
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Editing ActiveState Perl batch files | See your vim templates in Windows Explorer's New context
menu >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=639 (2 of 2) [18/02/2004 15:09:32]

SourceForge
Logo

Tip #640 - See your vim templates in Windows Explorer's New context menu : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #640: See your vim templates in Windows Explorer's New


context menu
tip karma

Rating 0/2, Viewed by 533

created: January 20, 2004 20:17


author: Mark Fernandes

complexity: basic
as of Vim: 5.7

Do you wish you had your own vim settings for a file
appear automatically when
you right click in Windows Explorer? If so then read on,
following these steps
sequentially:
- Create a template file where the last few lines
control vim. See below for a
sample:
-[sample template file begins below this line]--------------------------------End of Text--------------------------------The line below controls vim, which you can get free
from: http://www.vim.org/
vim:tw=80:ai:ft=txt:norl:
-[sample template file ends above this line]- Call the above sample template file GVIM.vtd and save
it in
"C:\Windows\ShellNew\" directory. You may use another
extension, but I
played it safe and used one that wasn't being used on
my system. Moreover, I
did not change the default location of Windows
installation, but you may
need to do so if your system does not match mine.
- Open Explorer and click on Tools->Folder Options... in
the dialog box that
appears, click on File Types and then scroll the file
types until you reach
VTD. Click on the file extension VTD and click on
Change; now associate
gvim.exe with this file extension.

http://www.vim.org/tips/tip.php?tip_id=640 (1 of 3) [18/02/2004 15:09:36]

Tip #640 - See your vim templates in Windows Explorer's New context menu : vim online

- Next, open the registry with regedit by clicking on


Start->Run and typing
regedit in the Run dialog box
- In the registry, scroll HKEY_CLASSES_ROOT until you
get to Vim.Application
- then add a key; call it "shell"
- next scroll into:
[HKEY_CLASSES_ROOT\Vim.Application\shell]
- and add a key; call it "open"
- once more scroll into:
[HKEY_CLASSES_ROOT\Vim.Application\shell\open]
- and add yet another key; call it "command"
- now change, by double clicking on, the "(Default)"
value of
"command" to point it to the location of gvim.exe on
your
hard drive. On my system, I entered the following in
the text
field "Value data"
C:\PROGRA~1\Vim\vim62\gvim.exe "%1"
- Finally open up Explorer and navigate to any directory
on your hard drive.
Now, right click on, the pane displaying the files, to
see "Vim" as one of
your options. When you choose Vim, you will create a
file called "New
Vim.vtd" in that directory. When you open "New
Vim.vtd" you should see the
above sample text and Vim uses the settings used in
the last line of the file.
- Any changes made to the original template in
C:\Windows\ShellNew appear in
the new files that you create.
I tried to get this to work with using TweakUI but that
did not help in Windows
XP, so I had to do it the long way. So, I hope this tip
helps at least a few of
you,
Enjoy!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Comment highlight #ifdef DEBUG for code-read ease (C/C++) | Highlighting of method names in the
definition (C++) >>

http://www.vim.org/tips/tip.php?tip_id=640 (2 of 3) [18/02/2004 15:09:36]

Tip #640 - See your vim templates in Windows Explorer's New context menu : vim online

Additional Notes
Mark Fernandes, January 20, 2004 20:42
Sorry I forgot to add this important information too...
- In the registry editor (Start->Run->regedit) goto
HKEY_CLASSES_ROOT and then
scroll till you get to ".vtd" and change string value
(Default) to Vim.Application
- next click on [HKEY_CLASSES_ROOT\.vtd]; add a key;
call it "ShellNew"
- next click on "ShellNew" and add a String Value; call
it "FileName";
double click on "FileName" and enter GVIM.vtd
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=640 (3 of 3) [18/02/2004 15:09:36]

SourceForge
Logo

Tip #641 - Highlighting of method names in the definition (C++) : vim online

not logged in (login)

Home
Search

Tip #641: Highlighting of method names in the definition (C++)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 17/8, Viewed by 728

created: January 21, 2004 10:53


author: Olivier Teuliere

complexity: basic
as of Vim: 6.0

When editing big cpp files, it can be very convenient to


highlight the method name
(the part after "::") in a method definition.
--> I use the following function in my .vimrc:
" Add highlighting for function definition in C++
function! EnhanceCppSyntax()
syn match cppFuncDef
"::\~\?\zs\h\w*\ze([^)]*\()\s*\(const\)\?\)\?$"
hi def link cppFuncDef Special
endfunction
--> I have another line to call this function
automatically when editing a C++ file:
autocmd Syntax cpp call EnhanceCppSyntax()
--> That's it! This doesn't work in all cases (for
instance, it doesn't highlight constructors
using an initialization list on the same line) but it
shouldn't highlight function calls
(such as "MyClass::MyStaticMethod( int foo );" )
Don't hesitate to extend the regular expression for a
more accurate matching...
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<See your vim templates in Windows Explorer's New context menu | Windows: Get K to not display a
DOS box that needs closing >>

Additional Notes
Niklas, January 22, 2004 16:41

http://www.vim.org/tips/tip.php?tip_id=641 (1 of 2) [18/02/2004 15:09:40]

Tip #641 - Highlighting of method names in the definition (C++) : vim online

Hi,
good tip! To further facilitate adding user-defined
extensions to existing syntax files, you can use a
".vim/after/syntax/" directory. See:
:help mysyntaxfile-add
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=641 (2 of 2) [18/02/2004 15:09:40]

SourceForge
Logo

Tip #642 - Windows: Get K to not display a DOS box that needs closing : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #642: Windows: Get K to not display a DOS box that needs
closing
tip karma

Rating 13/8, Viewed by 494

created: January 21, 2004 17:37


author: David Risner

complexity: basic
as of Vim: 6.0

To get the K command to open a Windows program without


creating DOS box that needs to be closed you can do the
following:
In your _vimrc add the following:
map K yiw:exec "silent !".&kp." ".@0<CR>
You can then set the keywordprg (abbreviated kp above)
to the program you want to run.
Thanks to Jacob Lerner, Tim Chase, and Suresh
Govindachar for coming up with this.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Highlighting of method names in the definition (C++) | Disable built-in command >>

Additional Notes
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=642 [18/02/2004 15:09:43]

SourceForge
Logo

Tip #643 - Disable built-in command : vim online

not logged in (login)

Home
Search

Tip #643: Disable built-in command


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 8/4, Viewed by 308

created: January 26, 2004 12:41


author: Alfvaen

complexity: intermediate
as of Vim: 5.7

If there's a built-in key command in vim that you just


can't stand, find annoying, and/or often hit by
accident(for me it's "K", with ">" a close second), then
you can disable it using ":map". You can't use
":unmap", as you might think. Instead, you can map it
to nothing, like:
:map K <Nop>
(<Nop> is not the "Nop" key on your keyboards, but
literal letters inside literal pointy brackets.)
Of course, you can always
:unmap K
if you start doing C programming and want to instantly
"man" things under the cursor again.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Windows: Get K to not display a DOS box that needs closing | restoring indent for '#' >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=643 [18/02/2004 15:09:46]

SourceForge
Logo

Tip #644 - restoring indent for '#' : vim online

not logged in (login)

Home
Search

Tip #644: restoring indent for '#'


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 16/4, Viewed by 511

created: January 27, 2004 1:50


author: stsi

complexity: basic
as of Vim: 6.0

In 'smatrindent' mode '#' removes the indent if it is


the first char on the line.
Very annoying for me.
From Vim's help:
When typing '#' as the first character in a new
line, the indent for
that line is removed, the '#' is put in the
first column. The indent
is restored for the next line. If you don't
want this, use this
mapping: ":inoremap # X^H#", where ^H is entered
with CTRL-V CTRL-H.
This helps, but it failes to work when placed in
~/.vimrc.
The fillowing mapping work in any case:
:inoremap # a#^Oh^Ox^OA, where ^O is entered with CTRL-V
CTRL-O.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Disable built-in command | Enabling Windows shortcuts (eg alt+space, F10 etc) for gvim window >>

Additional Notes
Anonymous, January 29, 2004 19:45
Too bad that map doesn't work when there are characters
on the line after where you are trying to insert the #,
then you wind up with an "a" instead. Instead try
:inoremap # a#<Left><BS><Right>
Add Note

http://www.vim.org/tips/tip.php?tip_id=644 (1 of 2) [18/02/2004 15:09:50]

Tip #644 - restoring indent for '#' : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=644 (2 of 2) [18/02/2004 15:09:50]

SourceForge
Logo

Tip #645 - Enabling Windows shortcuts (eg alt+space, F10 etc) for gvim window : vim online

not logged in (login)

Home
Search
About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Tip #645: Enabling Windows shortcuts (eg alt+space, F10 etc) for
gvim window
tip karma

Rating 1/1, Viewed by 590

created: January 28, 2004 4:44


author: Girish Gajwani

complexity: basic
as of Vim: 5.7

I was trying to figure out why Alt+space would not work,


as i would have to use the mouse to
maximize/restore/minimize my gvim window (on Win32)
which was a pain
and found that i needed to
set winaltkeys=yes
to make this work. Now I can use
Alt+Space followed by 'x to maximize
Alt+Space followed by 'n' to minimize
Alt+Space followed by 'r' to restore!
See
help winaltkeys
Also see this:
vimtip #494

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<restoring indent for '#' | moving lines up/down in a file >>

Additional Notes
jevonsdu@hotmail.com, January 28, 2004 5:19
I use VIM on Win2K, ALT+Space works well on English
Win2K platform, it seems this shortcut does not work on
multi-byte language Win2K (e.g. Chinese Win2K). Is this
a bug ?
slackorama@GOAWAYSPAMMERS_hotmail.com, January 28, 2004 18:28

http://www.vim.org/tips/tip.php?tip_id=645 (1 of 2) [18/02/2004 15:09:55]

Tip #645 - Enabling Windows shortcuts (eg alt+space, F10 etc) for gvim window : vim online

I'm using vim 6.1 on WinXP and the Alt+Space works for
me but not in the normal way. I have to press Alt,
release it and then press the space bar to bring up the
menu. In most other programs I can press and hold Alt
and then hit the space bar.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=645 (2 of 2) [18/02/2004 15:09:55]

SourceForge
Logo

Tip #646 - moving lines up/down in a file : vim online

not logged in (login)

Home
Search

Tip #646: moving lines up/down in a file


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 37/19, Viewed by 928

created: January 28, 2004 22:33


author: Frank Butler

complexity: basic
as of Vim: 5.7

The following mappings in .vimrc provide a quick way to


move a line of text up or down within a file:
map <C-Up> dd-P
map <C-Down> ddp
Hold down the Control key, and the <Up> and <Down> arrow
keys move the line. Check it out!
This is particularly useful when editing a file
consisting of single-line items in a particular order
(such as priority) - it makes it easy to change the
relative position of items in the list.
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Enabling Windows shortcuts (eg alt+space, F10 etc) for gvim window | Single letter insert >>

Additional Notes
salmanhalim@hotmail.com, January 29, 2004 7:00
This works everywhere except at the top or bottom of
the buffer. There was a discussion about this on the
Vim list a while back and a swap line plugin came out
of it -- I don't know who produced it in the first
place and I won't want to post it here without giving
due credit, but basically it mapped the key
combinations to two different functions that would
first store the current column the cursor was in, then
swap the line (behaving differently at the
beginning/end of the buffer -- try doing the
combination in the original tip here to see what I mean
about the need to behave differently at the edges of
the buffer) and then restore the cursor position,

http://www.vim.org/tips/tip.php?tip_id=646 (1 of 3) [18/02/2004 15:09:59]

Tip #646 - moving lines up/down in a file : vim online

leaving you where you started, but with the lines


swapped.
jcm314@hotmail.com, January 30, 2004 13:22
I've been using the following for a while. I like them
because:
- they work in any mode.
- in visual mode they operate on the entire block.
- the indentation is adjusted automagically.
- they can handle the tops and bottoms of files.

" move the current line up or down


nmap <C-Down> :m+<CR>==
nmap <C-Up> :m-2<CR>==
imap <C-Down> <C-O>:m+<CR><C-O>==
imap <C-Up> <C-O>:m-2<CR><C-O>==
" move the current line left or right
nmap <C-Left> <<
nmap <C-Right> >>
imap <C-Left> <C-O><<
imap <C-Right> <C-O>>>
" move the selected block up or down
vmap <C-Down> :m'>+<CR>gv=gv
vmap <C-Up> :m'<-2<CR>gv=gv
" move the selected block left or right
vmap <C-Right> >gv
vmap <C-Left> <gv
zzapper@ntlworld.com, February 2, 2004 11:12
A variation on the above, <f11> stores one line <f12>
restores it, also allows copying one line to another
file
map
map!
map
map!

<f11>
<f11>
<f12>
<f12>

:.w! c:/aaa/xr<CR>
<ESC>:.w! c:/aaa/xr<CR>
:r c:/aaa/xr<CR>
<ESC>:r c:/aaa/xr<CR>

frankbutler@ieee.org, February 9, 2004 16:42


Cool! I took jcm314's nmap's for up/down (you get an
error at top/bottom of file) and left/right, except
dropped the == from the end (don't want line to get
reformatted when I move it).
Add Note

http://www.vim.org/tips/tip.php?tip_id=646 (2 of 3) [18/02/2004 15:09:59]

Tip #646 - moving lines up/down in a file : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=646 (3 of 3) [18/02/2004 15:09:59]

SourceForge
Logo

Tip #647 - Single letter insert : vim online

not logged in (login)

Home
Search

Tip #647: Single letter insert


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating -1/3, Viewed by 778

created: January 30, 2004 6:40


author: Astrobe

complexity: basic
as of Vim: 5.7

Often I have to insert only one character ( typically a


paren)
:map <C-x> ylpr

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<moving lines up/down in a file | Uniq - Removing duplicate lines >>

Additional Notes
Anonymous, January 30, 2004 6:51
Doesn't work when there is nothing already on the line.
I use
:map ,i i?<Esc>r
and
:map ,a a?<Esc>r
Anonymous, January 30, 2004 6:53
The previous note wasn't an original, but grew out of
vimtip #466 .
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=647 [18/02/2004 15:10:03]

SourceForge
Logo

Tip #648 - Uniq - Removing duplicate lines : vim online

not logged in (login)

Home
Search

Tip #648: Uniq - Removing duplicate lines


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 11/5, Viewed by 635

created: February 1, 2004 20:45


author: Michael Geddes

complexity: intermediate
as of Vim: 6.0

There are two versions, the first leaves only the last line,
the second leaves only the first line.
g/^\(.*\)$\n\1$/d
g/\%(^\1$\n\)\@<=\(.*\)$/d
Breakdown of the second version:

Site Help

g//d

<-- Delete the lines matching the regexp

\@<=
<-- If the bit following matches, make sure the bit
preceding this symbol directly precedes the match
\(.*\)$

<-- Match the line into subst register 1

\%( )
<--- Group without placing in a subst register.
^\1$\n
<--- Match subst register 1 followed by end of line
and the new line between the 2 lines
In this simple format (matching the whole line), it's not
going to make much difference, but it will start to matter if
you want to do stuff like match the first word only
This does a uniq on the first word in the line, and deletes
all but the first line:
g/\%(^\1\>.*$\n\)\@<=\(\k\+\).*$/d

rate this tip

Life Changing

Helpful

<<Single letter insert | expand existing abbreviation >>

Additional Notes
box1024@post.com, February 2, 2004 4:57

http://www.vim.org/tips/tip.php?tip_id=648 (1 of 3) [18/02/2004 15:10:07]

Unfulfilling

rate

Tip #648 - Uniq - Removing duplicate lines : vim online

Or you could simply pipe the file, (Or range of lines)


through uniq(1) thusly:
:%!uniq
Cheers,
Morel.
Anonymous, February 2, 2004 5:35
unless you are stuck inside a windows machine using vim, in
which case this tip is most appreciated :)
-- RS
scott2237@yahoo.com, February 2, 2004 10:33
then again, windows users can have 'sort', 'uniq', 'grep' and
a host of others if they visit the unxutils.sourceforge.net
site
Anonymous, February 2, 2004 15:34
Or http://www.cygwin.com
Anonymous, February 2, 2004 16:38
Of course, personally, I use sort | uniq whether on my
Windows or my Unix box. However if you were (for example)
going to make a script that wanted to use uniq, then you
shouldn't be assuming either exists.
As sombody else has come up with sort, I thought I'd give a
go at a pure vim version of uniq.
I would definitely use this in a script over assuming an
environment. Not everybody wants to download cygwin or
friends for the lack of one or two commands. (Not that
M*cr*s*ft doesn't suck in so many ways). I'm sure that with
the multitude of platforms that Vim runs on, there a few out
there that don't have convenient ports of/alternates to unix
commands.
//.ichael Geddes
ads@metawire.org, February 4, 2004 8:08
Here are some more vim-native ways for removing duplicate
lines. This time they don't have to be adjacent. Line order
is preserved.
This one can be a bit slow.
:nno \d1
:g/^/m0<CR>:g/^\(.*\)\n\_.*\%(^\1$\)/d<CR>:g/^/m0<CR>
This is faster (some help from Preben Guldberg with this
one).
Uses mark l.
:nno \d2 :g/^/kl\|if

http://www.vim.org/tips/tip.php?tip_id=648 (2 of 3) [18/02/2004 15:10:07]

Tip #648 - Uniq - Removing duplicate lines : vim online

search('^'.escape(getline('.'),'\.*[]^$/').'$','bW')\|'ld<CR>
Antony
ads@metawire.org, February 4, 2004 8:10
Here are some more vim-native ways for removing duplicate
lines. This time they don't have to be adjacent. Line order
is preserved.
This one can be a bit slow.
:nno \d1
:g/^/m0<CR>:g/^\(.*\)\n\_.*\%(^\1$\)/d<CR>:g/^/m0<CR>
This is faster (some help from Preben Guldberg with this
one).
Uses mark l.
:nno \d2 :g/^/kl\|if
search('^'.escape(getline('.'),'\.*[]^$/').'$','bW')\|'ld<CR>
Antony
ads@metawire.org, February 4, 2004 8:10
Here are some more vim-native ways for removing duplicate
lines. This time they don't have to be adjacent. Line order
is preserved.
This one can be a bit slow.
:nno \d1
:g/^/m0<CR>:g/^\(.*\)\n\_.*\%(^\1$\)/d<CR>:g/^/m0<CR>
This is faster (some help from Preben Guldberg with this
one).
Uses mark l.
:nno \d2 :g/^/kl\|if
search('^'.escape(getline('.'),'\.*[]^$/').'$','bW')\|'ld<CR>
Antony
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=648 (3 of 3) [18/02/2004 15:10:07]

SourceForge
Logo

Tip #649 - expand existing abbreviation : vim online

not logged in (login)

Home
Search

Tip #649: expand existing abbreviation


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/2, Viewed by 294

created: February 4, 2004 7:07


author: Yakov Lerner

complexity: basic
as of Vim: 6.0

This mapping expands existing abbreviation


map <C-X><C-X> diw:exe "normal i".@"<cr>
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Uniq - Removing duplicate lines | abbreviation that prompts whether to expand it or not >>

Additional Notes
ads@metawire.org, February 4, 2004 7:54
That won't work if the abbrev. is the last word on the
line. Try:
:nno <C-X><C-X> ciw@<Esc>"_s<C-R>"<Esc>b
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=649 [18/02/2004 15:10:09]

SourceForge
Logo

Tip #650 - abbreviation that prompts whether to expand it or not : vim online

not logged in (login)

Home
Search

Tip #650: abbreviation that prompts whether to expand it or not


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 5/5, Viewed by 392

created: February 4, 2004 7:13


author: Yakov Lerner

complexity: basic
as of Vim: 6.0

You can define abbreviation in such a way that it will


ask whether to expand it or not. The trick is to define
it as insert-mode mapping with special body, not as
abbreviation.
Here is how to define it:
function! MyExpand(abbr,expansion)
let answer=confirm("Expand '".a:abbr."' [y] ",
"&Yes\n&No")
if answer==2
exec "normal! a".a:abbr
else
exec "normal! a".a:expansion
endif
endfunction
imap ABC <esc>:call AskExpand("ABC","...expansion for
ABC ...")<cr>a
imap XYZ <esc>:call AskExpand("XYZ","...expansion for
XYZ ...")<cr>a
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<expand existing abbreviation | Edit gnupg-encrypted files. >>

Additional Notes
mark.thomas@tampagov.net, February 4, 2004 9:26
In your example shouldn't 'AskExpand' read 'MyExpand' ?
Add Note

http://www.vim.org/tips/tip.php?tip_id=650 (1 of 2) [18/02/2004 15:10:14]

Tip #650 - abbreviation that prompts whether to expand it or not : vim online

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=650 (2 of 2) [18/02/2004 15:10:14]

SourceForge
Logo

Tip #651 - Edit gnupg-encrypted files. : vim online

not logged in (login)

Home
Search

Tip #651: Edit gnupg-encrypted files.


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 11/5, Viewed by 462

created: February 5, 2004 13:57


author: Frank Price

complexity: intermediate
as of Vim: 6.0

It can be somewhat laborious to edit a file which you


have encrypted: first you have to decrypt to plaintext,
then use vim and save; then encrypt again. The method
below lets vim take care of some of the dirty work.
First, be sure you have gnupg setup to the point where
you can ascii-armor encrypt a file using your own public
key, and decrypt it again.
Then put this into your .vimrc (don't duplicate the 'if
has("autocmd")' part if it is already there):
if has("autocmd")
augroup GPGASCII
au!
au BufReadPost *.asc :%!gpg -q -d
au BufReadPost *.asc |redraw
au BufWritePre *.asc :%!gpg -q -e -a
au BufWritePost *.asc u
au VimLeave *.asc :!clear
augroup END
endif " has ("autocmd")
you might also want to add these options to your
~/.gnupg/options file to decrease the messages gnupg
outputs:
no-greeting
quiet
default-recipient-self #to always encrypt for
yourself.
Now vim a new file, the name of which ends with .asc:
vim important.asc
and edit. When you save and quit, gnupg may prompt for
gnupg ids to encrypt for (if you don't have defaultrecipient-self set). Enter your own. To edit, just vim
it again and you'll be prompted for your passphrase.
This isn't perfect -- in particular, you occasionally

http://www.vim.org/tips/tip.php?tip_id=651 (1 of 2) [18/02/2004 15:10:18]

Tip #651 - Edit gnupg-encrypted files. : vim online

have to tell vim to redraw with ctrl-L to get rid of


gnupg crud -- but it works pretty well for me. I'd love
to hear about improvements!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<abbreviation that prompts whether to expand it or not | save all open buffers at once >>

Additional Notes
victorlei@yahoo.com, February 10, 2004 3:18
One should be aware of leaving pieces of the plaintext
inside registers
in .viminfo file.
http://www.cs.albany.edu/~mosh, February 10, 2004 19:12
Specify -n option, so that vim doesn't use swap file
and save the plain text to disk.
I wrote the vimcrypt functionality in vim5.7 when I was
in India,
its not strong, but keeps the grandmons and admin at
bay.
- Mohsin.
schella@comp.uark.edu, February 15, 2004 21:11
Nice, very helpful! When I do a :w though, cursor
position is reset to the beginning of the buffer. Is
there any way to prevent this and keep it at where it
was?
ingok@gmx.net, February 16, 2004 8:36
if gpg fails, your encrypted file is gone :(
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=651 (2 of 2) [18/02/2004 15:10:18]

SourceForge
Logo

Tip #652 - save all open buffers at once : vim online

not logged in (login)

Home
Search

Tip #652: save all open buffers at once


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/9, Viewed by 595

created: February 6, 2004 3:50


author: Andreas Berg

complexity: intermediate
as of Vim: 6.0

Since i like to work with more than one buffer, i always


have had the problem
that i left one of them unsaved by mistake. For this
purpose i wrote this
small function which saves all open buffers (only if
changes were made).
If you map the function to a key (e.g. F12), this is
quite a convenient way.
add this to your .vimrc:
function! SaveBuffers()
if !buflisted(bufnr('%'))
return
end
let myBufferNumber = bufnr('%')
exec("bufdo update")
exec("b".myBufferNumber)
endfunction
nmap <F12> :call SaveBuffers()<CR>

rate this tip

Life Changing

Helpful

Unfulfilling

<<Edit gnupg-encrypted files. | doxygen '///' :comments setting >>

Additional Notes
loveunixnet@tom.com, February 6, 2004 19:01
how about :wa
I like to use it
wormdetector@gmx.de, February 7, 2004 1:02
http://www.vim.org/tips/tip.php?tip_id=652 (1 of 2) [18/02/2004 15:10:22]

rate

Tip #652 - save all open buffers at once : vim online

:-)
good hint. I didn't know it.
mosh, February 10, 2004 19:06
:xa
to save all modified buffers and exit.
:wa
will update files even if unmodified.
- Mohsin
wormdetector@gmx.de, February 13, 2004 2:07
sorry, Mosh, that's not correct.
:wa

writes only modified buffers

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=652 (2 of 2) [18/02/2004 15:10:22]

SourceForge
Logo

Tip #653 - doxygen '///' :comments setting : vim online

not logged in (login)

Home
Search

Tip #653: doxygen '///' :comments setting


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 3/3, Viewed by 384

created: February 10, 2004 9:42


author: Michael Brailsford

complexity: intermediate
as of Vim: 6.0

This will continue lines of '///' doxygen comments when


you reach the end of a line while typing a comment. It
also works if you use 'o' to open a new line while on a
comment starting with '///'. It only works if there is
a space between the last '/' and the first letter of the
comment, that is no big deal, since it lends itself to
readability. So for example:
/// This will work.
///This won't.
Here is the magic line. Make sure you put it somewhere
that will get sourced whenever you open a file you want
to use with doxygen. I have it in
~/.vim/after/ftplugin/c/c.vim, so it gets sourced for
all C and C++ files.
set comments=sO:*\ -,mO:*\ \
,exO:*/,s1:/*,mb:*,ex:*/,bO:///,O://
All other comments will continue to work as expected.
- Michael
rate this tip

Life Changing

Helpful

Unfulfilling

<<save all open buffers at once | special characters in VIM substitution >>

Additional Notes
allanneal@myrealbox.com, February 12, 2004 10:44

http://www.vim.org/tips/tip.php?tip_id=653 (1 of 2) [18/02/2004 15:10:28]

rate

Tip #653 - doxygen '///' :comments setting : vim online

I am not all that familiar with vim scripting. I would


like to know how to do exactly this with other comment
beginners. I use the TVO outlining plugin and would
like to be able to do this with the | char as the
comment line beginner char. Can anyone help?
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=653 (2 of 2) [18/02/2004 15:10:28]

SourceForge
Logo

Tip #654 - special characters in VIM substitution : vim online

not logged in (login)

Home
Search

Tip #654: special characters in VIM substitution


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/0, Viewed by 241

created: February 15, 2004 17:03


author: Hyouck Kim

complexity: basic
as of Vim: 6.0

Let's think about the code below


void
howdy(void)
{
M00 =
M01 =
M10 =
M11 =
M20 =
M21 = 0;
}
Now you want to change the code like
void
howdy(void)
{
M[0][0] =
M[0][1] =
M[1][0] =
M[1][1] =
M[2][0] =
M[2][1] = 0;
}
You can easily do that with
:g/\(M\)\([0-9]\)\([0-9]\)/s//\1[\2][\3]/g
Here,
\1 is a special substitute character meaning first
pair of the search pattern.
To specify a pair in your search pattern,
simply enclose your search pattern with "\(" and "\)".
Thus, in the above example

http://www.vim.org/tips/tip.php?tip_id=654 (1 of 2) [18/02/2004 15:10:31]

Tip #654 - special characters in VIM substitution : vim online

\(M\) corresponds to \1, and


\([0-9]\) to \2 and etc...
And substitute pattern "\1[\2][\3]" means
"1st pair" + "[" + "2nd pair" + "]" + "[" + "3rd pair" +
"]",
which is what we want here.
For more information on special substitute characters,
simply do :help substitute.
Happy Vim-ing!
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<doxygen '///' :comments setting | search with one key >>

Additional Notes
Anonymous, February 15, 2004 22:32
why not?
%s/\(\d\)\(\d\)/[\1][\2]/
elvegamx@yahoo.com.mx, February 16, 2004 5:53
this works too:
%s/\v(\d)(\d)/[\1][\2]
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=654 (2 of 2) [18/02/2004 15:10:31]

SourceForge
Logo

Tip #655 - search with one key : vim online

not logged in (login)

Home
Search

Tip #655: search with one key


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating -4/6, Viewed by 259

created: February 16, 2004 13:06


author: vim_user

complexity: basic
as of Vim: 5.7

* is 2 keys (shift and press 8)


I found it simpler to map these to a single key.
put these mappings in your _vimrc file
:nmap

<F8> :execute ":normal #"<CR>

:nmap

<F9> :execute ":normal *"<CR>

Site Help

Now you can search for the word under the cursor in
normal mode with the F8 key backwards and the F9 key
forwards.
Can this be done in insert mode?
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<special characters in VIM substitution | Recursive mappings - (2 examples to learn from) >>

Additional Notes
sandor.kopanyi@essnet.se, February 16, 2004 23:41
In insert mode just escape to normal mode, do the same
thing, then go back to insert mode with "a":
:imap

<F8> <Esc> :execute ":normal #"<CR> a

:nmap

<F9> <Esc> :execute ":normal *"<CR> a

Peter Palm, February 17, 2004 4:55

http://www.vim.org/tips/tip.php?tip_id=655 (1 of 2) [18/02/2004 15:10:35]

Tip #655 - search with one key : vim online

To execute just one command in normal mode (from insert


mode), use <C-O>.
The mapping above could be written as:
:imap <F8> <C-O>#
:imap <F9> <C-O>*
anon, February 17, 2004 10:06
see also vimtip #154
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=655 (2 of 2) [18/02/2004 15:10:35]

SourceForge
Logo

Tip #656 - Recursive mappings - (2 examples to learn from) : vim online

not logged in (login)

Home
Search

Tip #656: Recursive mappings - (2 examples to learn from)


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account

Rating 14/5, Viewed by 204

created: February 16, 2004 21:06


author: Mohit Kalra

complexity: advanced
as of Vim: 5.7

Recursive mappings are fun to learn and really handy


when you want to do repetitive tasks. One way to do
this is Tip#144 (recording). This is another way when
you find that you are using the same **editing pattern**
again and again. Recursion may seem a bit complicated
at first but it is very intuitive once you get the hang
of it.
Here are two examples for you to learn from.

Site Help

For example, you have a file with the following contents


aaa.txt
bbbbbb.txt
ccc.txt
You want to change the file as follows wc aaa.txt> aaa.log
echo "HelloWorld"
wc bbbbbb.txt > bbbbbb.log
echo "HelloWorld"
wc ccc.txt> ccc.log
echo "HelloWorld"
A simple recursive mapping that will do the job is
:map z Iwc <Esc>lyawA><Esc>pa.log<CR>echo
"HelloWorld"<Esc>jz
Now type z in the first line and everything else is
magic.
Here is the breakup where {} contain the vim commands.
1. Goto the beginning of the line and type "wc " and
then come back to normal mode {Iwc <Esc>}
2. Copy the word aaa (or bbbb or ccc). We do this by
going right one character and copying the word under it.
{lyaw}
3. Goto the end of the line and append > and then come
http://www.vim.org/tips/tip.php?tip_id=656 (1 of 3) [18/02/2004 15:10:39]

Tip #656 - Recursive mappings - (2 examples to learn from) : vim online

back to normal mode.


{A><Esc>}
4. Paste what we had copied {p}
5. Append .log<CR>echo "HelloWorld" to the
line. {a.log<CR>echo "HelloWorld"}
6. Goto the next line but first we switch to the normal
mode. {<Esc>j}
7. Do steps 1 to 7 all overagain {z}
The recursion terminates when the j cannot take you one
more line further. If you manually execute a command
for one line, you will find it very intuitive to create
recursive mappings.
Here is another example.
Say you
#define
#define
#define

want to change
myid
199
myid2 200
myid3 201

To
#define myid
201
#define myid2 202
#define myid3 203
The simple mapping would be :map z 2^Ajz
Where ^A is CTRL_V+A
1.
2.
3.

Add 2 to the number in the line


Go down one line.
Do steps 1 to 3 again.

Also see
:help recursive_mapping
:help CTRL-A
:help nowrapscan // when using recursion with
searching.
There may be many ways to solve the above problems...
this is just another way which I like to use. Recursion
is very powerful espcially when I manipulate many open
windows where the content of one is to be used in
another.
rate this tip

Life Changing

Helpful

<<search with one key | have a question about vim? >>

http://www.vim.org/tips/tip.php?tip_id=656 (2 of 3) [18/02/2004 15:10:39]

Unfulfilling

rate

Tip #656 - Recursive mappings - (2 examples to learn from) : vim online

Additional Notes
Mohit Kalra, February 17, 2004 8:19
Ignore the extra space in front of 199 in the second
example (in case you are copy pasting from the
examples).
It just got there somehow.
anon, February 17, 2004 12:16
How does one stop a recursion that starts with a
search?
For example, I went through a document marking the
paragraphs of
interest with ^*****, and then tried yanking them using
the recursion:
nmap z /^\*\*\*\*\*k"Ay}3jz
This went into an infinite loop -- which I killed with
^C. Then, after
pasting register a, I had to delete the duplicate
stuff.
--Anon
Mohit Kalra, February 17, 2004 20:25
>>How does one stop a recursion that starts with a
search?
:set nowrapscan
See the "Also See" section in the tip above.
The terminating condition for such a recursive mapping
is that the search should not find anything. If the
wrapscan is on, the search starts from the top of the
document again. So setting wrapscan to **off** makes
sure that the search has a terminating condition.
BTW I think nmap z /^\*\*\*\*\*k"Ay}3jz
should be
nmap z /^\*\*\*\*\*<CR>k"Ay}3jz
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=656 (3 of 3) [18/02/2004 15:10:39]

SourceForge
Logo

Tip #657 - have a question about vim? : vim online

not logged in (login)

Home
Search

Tip #657: have a question about vim?


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 2/5, Viewed by 191

created: February 17, 2004 11:57


author: Adam Wolff

complexity: basic
as of Vim: 5.7

www.vim.org is a great place to find tips and scripts,


but if you have a question about vim, don't post it
here! (People don't take kindly to that.)
Check out http://www.vimuser.com/

rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Recursive mappings - (2 examples to learn from) | Switching to unit test module for python >>

Additional Notes
Anon, February 17, 2004 21:16
**Please use this site responsibly.**
IMHO - This tip is no better than the questions posted
here. The site you mention has two messages posted and
only two registered members.
Try
http://groups.google.com/groups?hl=en&lr=&ie=UTF8&oe=UTF-8&group=comp.editors
Anonymous, February 18, 2004 7:06

http://www.vim.org/tips/tip.php?tip_id=657 (1 of 2) [18/02/2004 15:10:44]

Tip #657 - have a question about vim? : vim online

Google Groups are just NNTP groups....not that


friendly....and most people hate using NNTP these
days....even with web interfaces. VIM's existing Yahoo
groups are cool....except for the contant ad's. The
vimuser site suffers from a huge lack of usage....but
hey it is new. Would be better if you could get the
content from Yahoo and initialize vimuser.com with
that. But the you have to wonder how long and how well
maintained vimuser.com will be. These forums would be
better hosted on vim.sf.net or some other site
maintained by the vim development team.
Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=657 (2 of 2) [18/02/2004 15:10:44]

SourceForge
Logo

Tip #658 - Switching to unit test module for python : vim online

not logged in (login)

Home
Search

Tip #658: Switching to unit test module for python


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 1/1, Viewed by 50

created: February 18, 2004 0:22


author: Max Ischenko

complexity: basic
as of Vim: 6.0

Doing a lot of programming in Python, I need to switch


quickly between Python module and corresponding unittest module. Often there is one unit-testing module for
multiple python modules.
This function allows you to switch to correct unit
testing module quickly, using the filename hardcoded at
the end of the file. Idea is stolen from Twisted
sources.
Put this to your ftplugin/python.vim:
nmap <buffer> <F5> :call JumpToTestFile()<CR>
fun! JumpToTestFile()
let line = getline("$")
if line =~ "^### testfile: "
let filename = strpart(line, 14)
execute ":e " . filename
else
echo "TEST PATTERN ### testfile: NOT FOUND!"
endif
endfun
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<have a question about vim? | Collect filenames of current subtree >>

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=658 (1 of 2) [18/02/2004 15:10:53]

SourceForge
Logo

Tip #658 - Switching to unit test module for python : vim online

http://www.vim.org/tips/tip.php?tip_id=658 (2 of 2) [18/02/2004 15:10:53]

Tip #659 - Collect filenames of current subtree : vim online

not logged in (login)

Home
Search

Tip #659: Collect filenames of current subtree


tip karma

About Vim
Community
News
Sponsoring
Trivia
Documentation
Download
Scripts
Tips
My Account
Site Help

Rating 0/0, Viewed by 52

created: February 18, 2004 4:36


author: Siegfried Bublitz

complexity: basic
as of Vim: 5.7

In vim you can edit directories, but sometimes for me it


is more convenienant to have the names of all files in
the complete subtree listed in one buffer. The below
function does just this. In essential, it globs the file
names of the current directory and iterates throught all
the names, globbing it again if it is a directory.
The following mapping abbreviates the invocation to
pressing '_L':
map _L :call ListTree('.')<CR>
function! ListTree(dir)
new
set buftype=nofile
set bufhidden=hide
set noswapfile
normal i.
while 1
let file = expand("<cWORD>")
if (file == '')
normal dd
elseif (isdirectory(file))
normal dd
let @" = glob(file . "/*")
normal O
normal P
let @" = glob(file . "/.[^.]*")
if (@" != '')
normal O
normal P
endif
else
if (line('.') == line('$'))
return
else
normal j
endif

http://www.vim.org/tips/tip.php?tip_id=659 (1 of 2) [18/02/2004 15:10:59]

Tip #659 - Collect filenames of current subtree : vim online

endif
endwhile
endfunction
rate this tip

Life Changing

Helpful

Unfulfilling

rate

<<Switching to unit test module for python |

Additional Notes

Add Note

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.

http://www.vim.org/tips/tip.php?tip_id=659 (2 of 2) [18/02/2004 15:10:59]

SourceForge
Logo

Вам также может понравиться