Steven Lu
Steven Lu

Reputation: 43447

Source more than one file with a keybind command in Vim

Here's my bind:

nnoremap <Leader>L :so $MYVIMRC<CR>:so ~/.vim/after/plugin/*.vim<CR>

It worked great right up until I added a second configuration file in the plugin folder. Now I get E77: too many file names from the :so[urce] command.

I found this which doesn't really make it obvious how to do it from an command string like in a keybind.

How do I write a loop in a keybind? Must a function be declared?

P.S. the reason I even have any scripts in .vim/after/plugin/ is because there are certain config commands for certain plugins that must be run after their initializations are run, and plugin load scripts run after vimrc. (so they cant just go in the vimrc).

Upvotes: 1

Views: 142

Answers (2)

romainl
romainl

Reputation: 196606

:source takes only one argument but you can use the :runtime command:

runtime! after/plugin/*.vim

which is almost exactly the second example given under :help :runtime.

Upvotes: 2

Timbinous
Timbinous

Reputation: 2983

You can also chain the commands together, and it's not as nice as romainl's answer but you can break out into terminal and run source there.

nnoremap <Leader>L :so $MYVIMRC|:!source `find ~/.vim/after/plugin/ -name "*.vim"`<CR>

Upvotes: 0

Related Questions