3

is there any way to have Vim help like links in my .vimrc file?

Like to use it for, like for example, at the beginning of the file offer like a contents table to my whole .vimrc file? It's not small, and I often find it useful to quick travel between two sections of my .vimrc file.

So is this possible? I'm talking about the links you have in all help files, like you press Ctrol+] and it will send you to the section of the file to which that link goes to. That kind of link.

Is it possible to have these in my .vimrc file? If so, how, the same way like with the help?

Thanks for all your help!

greduan
  • 4,770
  • 6
  • 45
  • 73

3 Answers3

7

vim help uses a tag file:

$VIMRUNTIME/doc/tags

You can create a tag file for your .vimrc.

Then you need to set tags options to locate it:

:set tags+=/path/to/your/tags

Type :help 'tags' to read more.

kev
  • 155,172
  • 47
  • 273
  • 272
  • Thanks, that's what I was looking for. I now have some studying to do. :) – greduan Nov 25 '12 at 13:19
  • It's possible to generate the tags file using the helptags command, but it only works on .txt and translation files for the help. Also, don't expect to have the "help" syntax in addition to the original syntax (if any). The links should work using ctrl-] commands and the like, but not with the mouse in gvim (for what I've tried). – pbarill Mar 24 '13 at 00:16
7

If you just want to have a table of contents, I recommend to fold your .vimrc file. It is much easier than creating tags to jump around. My .vimrc looks like the following, where only the last section gets unfolded:

" vim:fdm=marker:fen:fdl=0:
+-- 20 lines: buffer
+-- 12 lines: tty
+-- 10 lines: look
+--  9 lines: spell
+-- 12 lines: highlight
+-- 25 lines: filetype
+-- 16 lines: folding
+-- 26 lines: mapping
" latex-box {{{1
let g:LatexBox_output_type="dvi"
let g:LatexBox_viewer="xdvi"

The first line is a 'modeline', where I tell vim to use default markers ({{{) to mark a section, to enable folding once the file gets opened, to fold the whole file from level 0 (top level of the table of contents). You can use normal j/k keys to move up and down in this list, h/l to open a fold (if you configure the vim to do so). This way, you realize a table of contents as well. But you don't need to maintain tags by hands at all.

':help folding' and ':help modeline' may help you around. Here is a short list of keys to get you in and out of folders:

" zR    Unfold all folded lines in file.
" za    Open/close (toggle) a folded group of lines.
" zA    Open a closed fold or close an open fold recursively.
" zc    Close a folded group of lines.
" zC    Close all folded lines recursively.
" zd    Delete a folded line.
" zD    Delete all folded lines recursively.
" zE    Eliminate all folded lines in file.
" zF    Create "N" folded lines.
Jing
  • 283
  • 1
  • 8
  • Thanks Jing, I already have this system, but nevertheless +1 for all they key combinations, I was missing those. – greduan Nov 25 '12 at 13:16
2

I used a table of content for vmrc file with tags but eventually got rid of it since folding method turned out to be more convenient. Jing already described it in his answer.

Alternative folding method for those who hate ugly {{{1 signs in their files.

Start each section with a heading:

" = Another section =

At the last line of the file add a modeline:

"  vim:fdm=expr:fen:fdl=0:foldexpr=getline(v\:lnum)=~'^\"\\s='?'>1'\:'=':

Which reads:

  • vim: - this is modeline for this file, use the following local settings
  • fdm=expr - folding method is by expression
  • fen - folding enabled
  • fdl=0 - open only level 0 folds, that means close all
  • foldexpr - if line starts with " = then start fold level 1, else line is in the same level as a line above.

If you like to have more than one level then you better use a function for this. It is very well described in this answer

My most helpful short cut is

zi -  Invert 'foldenable'.

It is a toggle command: open all folds or close all folds except those that I opened and did not close explicitly with zc.

Community
  • 1
  • 1
ISQ
  • 2,704
  • 1
  • 14
  • 8