0

I would like for my vim (actually, neovim) to jump always to a label I leave in the text (or the first one, if there is more than one). So, I have setup this autocommand:

au BufNewFile,BufRead * call search('\$\$\$')

and hope that it would work. Unfortunately, BufRead seems like not enough, because when I open the file now, it just opens it at the top again.

So, I replaced BufRead with BufEnter (after trying BufReadPost, which didn’t work either), and now vim truly jumps to the label, unfortunately it is a way to eager to do it. It jumps to the label (and possibly even replaces the text) when I use spellchecker or basically any time I return to that buffer from anywhere. That is too much.

However, the main point is that I don’t understand, why that BufRead doesn’t work in the first place.

mcepl
  • 2,688
  • 1
  • 23
  • 38
  • That autocommand should work. Is it possible you have another autocommand active that undoes your work? Try `:9verbose edit myfile.txt` to see all autocommands that are invoked as you open your file. – Amadan Jan 20 '20 at 06:50
  • @Amadan easier to start vim without plugins, run the autocommand, and see if it works. Now you know something else is going on (or not) – D. Ben Knoble Jan 20 '20 at 13:14
  • @D.BenKnoble Of course, that’d be the first step, to find out if it indeed “should work”, as internet strangers seem to suggest. I don’t see those as either-or... Knowing about `:9verbose` is still useful (rather than try to do the whack-a-mole of guessing which plugin is at fault). – Amadan Jan 20 '20 at 13:19
  • Agreed! @Amadan just a useful first debugging step. [vi.se] has a whole post on debugging steps – D. Ben Knoble Jan 20 '20 at 13:21
  • Thank you, @Amadan for the reply. When trying it, I got https://paste.gnome.org/pdmpxm6u9, which doesn't seem to be that bad, but my auto-command doesn't seem to be activated at all. – mcepl Jan 20 '20 at 13:26
  • Since all I see is `BufEnter` and `BufWinEnter` events, it seems you executed my command when your buffer was already loaded (so Vim just had to switch to it, without loading the file or creating a new one). Either destroy that buffer using `:bd` or start with a fresh Vim, _then_ try to load (or create) your file with `:9verbose edit`. – Amadan Jan 21 '20 at 06:35
  • @Amadan Run fresh ``nvim`` (without any argument), and then ``:9verbose edit filename.rst`` and I got https://paste.gnome.org/ppuqzmmnj Difference could be in me using neovim (when tried with the Bram’s vim, it didn’t work either, but the output is A WAY more verbose). – mcepl Jan 21 '20 at 17:21

0 Answers0