5

I'm using vim as note-taking software. My notes grow to thousands of lines across 7 different files.

If I was writing code, I would be able to jump to a function definition in a different file with a vim plugin. Or if I open a list of compile errors or grep matches in vim, I could jump to a line in a different file with just two keypresses.

My problem is that I want to jump to one note file from another. This will probably involve tagging the location i wish to jump to.

Hopefully you know what I'm asking now. I can't type in a reference to a second file, (other than using the exact line number file:999 ), but I still need a way to type in references in the files, since I want to organize the same tasks across different note-files.

How can I do this? Would writing in markdown help?

https://superuser.com/questions/290082/how-can-i-configure-custom-vim-tags-for-my-text-file-notes offers a solution by binding a key to vimgrep

5

There are probably better ways but you could the help functionality as long as the filetype being help is ok. I basically use it to write down things I'm learning as I keep learning how to use gvim, it's only been 20 years :).

At the moment I have one file that I edit elsewhere then copy to where the help file is as an archive. It's hit 1600 lines so I'll start breaking it up into separate files, ie a index and section by section.

At the bottom or top of each document you need something like vim:tw=88:ts=4:sw=4:ft=help:norl:foldmethod=indent:foldclose=all:modifiable:noreadonly:conceallevel=3

The important bits

  • vim - Thanks to @D. Benknoble it sets the file up to load vim related flags, poor summary :(

  • tw=88 - Sets the text width. I use a big screen

  • ts=4 - Sets tab spaces to 4
  • ft=help - Important Sets the filetype to text
  • noreadonly - Probably dangerous as it allows edits
  • foldmethod=indent - I use indenting to separate the top level headings and the detail heading, dunno the vim word for headings :)

Then you define a help topic as follows

|sf-search-flags| - | sets the tag and allows jumping between tags using CTRL-]

And the sub topics as so

*sf-search-flags* - Where CTRL-] takes you. You can go to the previous tag using CTRL-o

It looks like this

Help Topic

Ctrl-] on sf-search-flags takes you to

The note

The colours are syntax formatting I'm playing with to make things stand out with out bold etc

After you save the file you need to use

:helptags {dir} (dir) is Optional if you are in the directory) to build the help file tags

See

h :help

h :helptags

:help modeline

Update: Fixed an error and added a better screenshot

2
  • 2
    vim: see :help modeline
    – D. Ben Knoble
    Apr 1 '20 at 21:38
  • @D.BenKnoble Thanks that helps
    – Steve
    Apr 1 '20 at 22:01
1

I think with vim-wiki you can set anchors (from the help):

Anchors~

A wikilink, interwiki link or diary link can be followed by a '#' and the name
of an anchor.  When opening a link, the cursor jumps to the anchor. >
  [[Todo List#Tomorrow|Tasks for tomorrow]]

To jump inside the current wiki file you can omit the file: >
  [[#Tomorrow]]

See |vimwiki-anchors| for how to set an anchor.
1

Another solution I'm playing around with (for my own minimalist wiki setup) is the following (assume all notes are in ~/notes):

  • setlocal path+=$HOME/notes/** for any files in ~/notes (this can be done with autocommands or with ftplugins by adding note. to the filetype of any file in ~/notes, though the latter is slightly more complicated)
  • use gf to jump between files: no special syntax required, just type the name of a file and gf it (like a cross link)
  • if you use gF instead, you can have references with line numbers (not quite like tags, though)
  • use :find and its variants to interactively find a file to jump to
  • use :vimgrep /.../ ~/notes/** to search

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.