9

Say I have some hundred custom re-mappings with iab for Java and some other hundred or so re-mappings for Haskell, then I'd want do divide these into different files to make it more manageable. What I'm looking for is to create something like this:

~/.
 ├── .vimrc
 └── .vim
     └── custom
         ├── java.vim
         └── haskell.vim

Where .vimrc might look something like

import java
import haskell

Is something like this possible to do, or am I just overcomplicating things? I guess what I am trying to achive is what one does in LaTeX with the \input command...

  • 2
    Is there a reason you don't put these in ~/.vim/after/ftplugin/$language.vim? – wchargin Dec 3 '14 at 2:35
  • 1
    Not really, should I? What is supposed to go in after/ftplugin? – lindhe Dec 3 '14 at 11:50
  • 2
    If you write a file called, e.g., ~/.vim/after/ftplugin/java.vim, it will automatically be run whenever you open a java file. This seems to be what you want. – wchargin Dec 3 '14 at 19:51
4

You are looking for ftplugins. This is their purpose.

And don't forget to define your mappings, setting, abbreviation, commands, ... as local. Otherwise they'll parasite other buffers once loaded.

Here are some more complete answers:

10

Yes, the vim command you're looking for is :source or :runtime to pull them from runtimepath.

For example, you could do this in your .vimrc:

runtime custom/java.vim
runtime custom/haskell.vim

presuming ~/.vim is in your runtimepath (which it is by default).

You could also drop your scripts in the ~/.vim/plugin directory; see write-plugin in the docs. Vim automatically runs all the scripts in the plugin directory.

  • Cool. Is there any naming convention for what I've here called custom, which is not quite plugins but rather files that could as well have been in .vimrc? – lindhe Dec 2 '14 at 21:53
  • 1
    @Lindh-E Not that I'm aware of. You probably want to use something that you're sure won't be given meaning by a future vim version. Since they strive to stay compatible with 8.3 file names, I'd suggest a directory name >8 characters. – derobert Dec 2 '14 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.