简体   繁体   English

如何在 vimrc 中为特定文件扩展名设置预定义标记

[英]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.我经常需要处理一个文本文件,该文件作为科学 model 水质的输入。 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.这些文件很长并且总是具有相同的标题部分,因此可以搜索它们并设置标记以便能够轻松地在 Vim 中的部分之间跳转。

Is it possible to automate the process of creating these marks from.vimrc?是否可以自动化从.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其中 ^M 是返回键,输入按Ctrl + vM

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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