Sections in ~/.vimrc

1 view
Skip to first unread message

Steve Laurie

unread,
Dec 5, 2008, 1:42:26 AM12/5/08
to vim...@googlegroups.com
Hi all,

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?!

Sergio Acosta

unread,
Dec 5, 2008, 4:43:55 AM12/5/08
to vim...@googlegroups.com
I think you might find useful taking those sections out of your .vimrc
and putting them in filetype plugins.

:h filetype

Tony Mechelynck

unread,
Dec 5, 2008, 7:05:50 AM12/5/08
to vim...@googlegroups.com
On 05/12/08 10:43, Sergio Acosta wrote:
> I think you might find useful taking those sections out of your .vimrc
> and putting them in filetype plugins.
>
> :h filetype
>
> On Dec 5, 2008, at 12:42 AM, Steve Laurie wrote:
[...]

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.

Steve Laurie

unread,
Dec 5, 2008, 9:57:25 AM12/5/08
to vim...@googlegroups.com

Thanks very much Tony and Sergio. Just what I was looking for.
It works wonderfully.

Cheers,
Steve


Mr.SpOOn

unread,
Dec 5, 2008, 11:55:52 AM12/5/08
to vim...@googlegroups.com
2008/12/5 Tony Mechelynck <antoine.m...@gmail.com>:

>> On Dec 5, 2008, at 12:42 AM, Steve Laurie wrote:
> $HOME/vimfiles/after/ftplugin/ or for Unix in
> $HOME/.vim/after/ftplugin/. Create any not-yet-existing directory as you
> go along.

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

Ted Pavlic

unread,
Dec 5, 2008, 12:10:12 PM12/5/08
to vim_use
> 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>

Tony Mechelynck

unread,
Dec 5, 2008, 1:58:54 PM12/5/08
to vim...@googlegroups.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.

Reply all
Reply to author
Forward
0 new messages