2

Problem

I use vim and vimwiki and have files that have predictable headings like ## Planning and ## Todo.

I want to do something like this in my vimrc:

/## Todo
mt

which will happen on file load if there is a ## Todo in the file.

But I'm not mapping a command with map or imap. It's also not a setting that can be set with set. So I am looking for some vimscript keyword that autostarts on file load.

Question

How do you search and mark on file load in the vimrc?

Ross Jacobs
  • 2,962
  • 1
  • 17
  • 27

1 Answers1

2

This looks like something autocmds can help with (see :h autocmd). You can have commands run on many different events, including on loading a certain file type. You could therefore have an autocmd like:

autocmd FileType vimwiki silent! /## Todo/ | mark t

You should be able to modify the event to only run this on the files that you want. The silent! part is there so you don't get an error message if there is no ## Todo in the file. The | command allows for multiple commands to be run, and the second command isn't run if the first is not successful.

Ross Jacobs
  • 2,962
  • 1
  • 17
  • 27
Mitchell P
  • 198
  • 2
  • 7
  • I changed the filetype to be `vimwiki`, which is the type for vimwiki files. To check what type of file you have opened, use `:echo &filetype`. – Ross Jacobs Sep 26 '20 at 22:09