my vimrc is too large, search and modification for me is a bit pain. Is it possible to have a table of contents so that I can jump to the section faster?


2 Answers 2


You can use folding to split your vimrc into sections and keep them collapsed, giving you a high level overview of the sections of the file that ressembles à table of contents. You can then expand folds for specific sections as you read or modify them.

One very effective technique for folding arbitrary sections is to use fold markers, which you can place inside comments, together with a title for a specific section.

If a single level of folding is enough for you, you can use {{{1 markers to start a new first-level fold. In that case, you don't really need to close them with }}}, since you're being explicit about the fold levels.

In order to enable fold markers and set the fold level in a way that folds are closed by default when opening the file, you can use a modeline to set the 'foldmethod' to "marker" and the 'foldlevel' to zero. You can put the modeline at either the top or the bottom of the file.

Here's a simple example of a simple vimrc file using fold markers to delimit sections and a modeline to configure folding correctly when opening the file:

" vim:fdm=marker:fdl=0:
" Sample vimrc file with sections.

" Plug-ins {{{1
call plug#begin()
Plug 'tpope/vim-unimpaired'
" ...
call plug#end()

" Settings {{{1
set laststatus=2
set nowrap
set expandtab

" Mappings {{{1
inoremap jk <Esc>

Opening the file in Vim looks like this:

" vim:fdm=marker:fdl=0:
" Sample vimrc file with sections.

+--  6 lines: Plug-ins ----------------------------
+--  5 lines: Settings ----------------------------
+--  3 lines: Mappings ----------------------------

You might want to look into the commands used to open, close and toggle folds. Also the additional options controlling the way they're displayed and the way they behave.


In my case, I did split my .vimrc using the plugins feature (mentioned in the link of Jake Grossman's comment).

So my final .vimrc contains the definition of the external plugins I use and a couple of autocommands.

Then, I have the following:

~/.vim/plugin/0-settings.vim which contains most of the set commands

~/.vim/plugin/1-utils.vim which contains some functions to use when needed

~/.vim/plugin/2-shortcuts.vim which contains all my mappings

~/.vim/plugin/3-highlight.vim which sets up my syntax highlight, colorscheme and related

I then also have a few type specific plugins stored in ~/.vim/ftplugin

Of course that file organisation is purely subjective. But using this plugin system helps keeping the files small and manageable.

You can get more info on the plugin with :help plugin in Vim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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