Skip to content

Instantly share code, notes, and snippets.

@romainl
Last active January 10, 2024 18:02
Show Gist options
  • Save romainl/3e0cb99343c72d04e9bc10f6d76ebbef to your computer and use it in GitHub Desktop.
Save romainl/3e0cb99343c72d04e9bc10f6d76ebbef to your computer and use it in GitHub Desktop.
Automatic file marks

Automatic file marks

File marks are like regular marks except that they are associated to a specific file, which makes them pretty useful for quick file navigation. One use that is commonly mentionned would be to add a V mark to one's vimrc, for example, which would make editing it only one 'V away.

Here, a mnemonic mark is left when leaving files of a specific kind:

  • mark C for "CSS" and "SCSS",
  • mark H for "HTML",
  • etc.

which makes it super easy to jump back to the last file of a certain kind that was edited:

'E

This is very handy in long sessions where you edit lots of filetypes.


This was initially VERY influenced by another one I found online, circa 2011-12. I didn't bookmark it at the time, though. I have posted my own version in various forums over the years but I could never point people to the actual original and give credit where credit is due. If you know where to find it I would gladly link to it.

augroup AutomaticMarks
autocmd!
autocmd BufLeave *.css,*.scss normal! mC
autocmd BufLeave *.html normal! mH
autocmd BufLeave *.js,*.ts normal! mJ
autocmd BufLeave *.vue normal! mV
autocmd BufLeave *.yml,*.yaml normal! mY
autocmd BufLeave .env* normal! mE
autocmd BufLeave *.md normal! mM
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment