简体   繁体   中英

How to set up predefined marks for a specific file extension in vimrc

I often have to work with a text file that serves as input to a scientific model for water quality. The files are pretty long and always have the same named title sections, so it is possible to search them and set marks to be able to easily jump between sections in Vim.

Is it possible to automate the process of creating these marks from.vimrc? So far I have managed to create a macros that searches the section headers and creates the marks automatically when opening these files:

au BufNewFile,BufRead *.dat
      let @q = '/General Data^Mm1/\[2\] Determinand^Mm2/\[3\] Reaches^Mm3/\[4\] River Flow^Mm4/\[5\] River Quality^Mm5/\[F\] Effluent Flow & Quality^Mmf/\[6\] River Quality Targets^Mm6/\[7\] Features^Mm7gg'

Where ^M is the return key, input pressing Ctrl + v and M

But I am not sure if this is the best way to do it, plus it requires running the macros after the document has been opened.

Is there a better way to do this?

Record macros using double quotes, this allow you to do things like:

 :let @a="imy first line\<CR>my second line"

Group your autocommands like this:

augroup datafiles
    au!
    autocmd BufNewFile,BufRead *.dat let @q = "/General Data\<CR>m1/\[2\] Determinand\<CR>m2/\[3\] Reaches\<CR>m3/\[4\] River Flow\<CR>m4/\[5\] River Quality\<CR>m5/\[F\] Effluent Flow & Quality\<CR>mf/\[6\] River Quality Targets\<CR>m6/\[7\] Features\<CR>m7gg"
    autocmd BufNewFile,BufRead *.dat normal! @q
augroup END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM