I've created key mappings in my ~/.vimrc file to automate creating empty
XHTML, C/C++ and PERL files as well as mappings that automate putting in
commonly used statements and commands like:
printf("",);
and
<a href=""></a>
and then I just fill in the blanks but I'm finding having so many
mappings is actually slowing Vim down. Is there a way to do something like:
"------------------------- C/CPP SECTION -----------------------------
if FileType = c,cpp
vmap ,pr diprintf("\n", );<ESC>2F"pf a
set makeprg=gcc\ -o\ %<\ %\ -lnsl\ -lsocket\ -lresolv\ -Wall\ -O2
...
end if
"------------------------- X/HTML SECTION ----------------------------
if FileType = xhtml,html
vmap ,ahref di<a href=""></a><ESC>2F"pf>p
map ,ol i<ol><CR><TAB><li><CR></li><CR><BS></ol><Up><Up><c-o><s-$>
...
end if
"---------------------------------------------------------------------
so all irrelevant sections are ignored for current document type and
don't slow Vim down?
Cheers and TIA,
Steve
--
SunOS, TCP/IP and Vim
What more could you want?!
Yes indeed. Steve, you really should read that helpfile; but in a
nutshell, place your "special" sections by filetype each in its own
file, name the file by the filetype followed by .vim, don't forget to
use ":setlocal" rather than ":set" and ":map <buffer>" rather than plain
":map", and drop the files, for Windows in
$HOME/vimfiles/after/ftplugin/ or for Unix in
$HOME/.vim/after/ftplugin/. Create any not-yet-existing directory as you
go along.
Best regards,
Tony.
--
Hacking's just another word for nothing left to kludge.
Thanks very much Tony and Sergio. Just what I was looking for.
It works wonderfully.
Cheers,
Steve
Is the "after" directory necessary? I'm on Linux and I have it, but
it's empty. My "ftplugin" directory is under .vim:
.vim/ftplugin
It's necessary if you want your custom settings to override any standard
settings for that file type.
--Ted
--
Ted Pavlic <t...@tedpavlic.com>
If you put these *.vim scripts in ~/.vim/ftplugin/ they can be
overridden by those by the same name in $VIMRUNTIME/ftplugin/ (which you
should NEVER modify, because any upgrade can silently remove your
changes). If you put them in ~/.vim/after/ftplugin/ the opposite is true
(your scripts override those distributed with Vim).
The 'vimruntime' directory trees are normally set up as follows;
normally they don't exist except for those where you need to put something:
$HOME/vimfiles/
(Windows) single-user full scripts
$HOME/.vim/
(Unix) single-user full scripts
$VIM/vimfiles/
(all) system-wide full scripts
$VIMRUNTIME/
(DO NOT MODIFY)
(all) scripts distributed with Vim
$VIM/vimfiles/after/
(all) system-wide tweaks to any of the above
$HOME/.vim/after/
(Unix) single-user tweaks to any of the above
$HOME/vimfiles/after/
(Windows) single-user tweaks to any of the above
The structure of all these trees is the same; e.g., scripts sourced when
the current file's 'filetype' has just been set are in the /ftplugin/
subdirectory of any of them.
Best regards,
Tony.