On 2020-06-21 19:18, Chris Jones wrote: > Seems a straightforward solution might consist in a regex-based > search of the files and populating some kind of associative array > (dictionary?) thusly as I go along: > > { '[1]' 'footnote #1', '[2]' 'footnote #2', ... }
To build this associative array, you might try :$?^$?,$g/\[\d\+\]/let b:a[getline('.')]=getline(line(".")+1) This assumes - the content of each footnote is only one line (snagging multi-line footnotes becomes an uglier task) - all your footnotes are compactly at the end of the file with no blank lines between the start of the footnotes and the end of the file. If there are, you'd have to manually specify the range to cover the range of footnotes instead of using the automatically-determined range "$?^$?,$" > ... and proceed to a second pass that substitutes each anchor by the > contents of the corresponding footnote. You can then use :1,$?^$?s/\[\d\+]/\='^['.b:a[submatch(0)].']'/g (again, if you have blank lines among your footnotes, manually specify the end of the text-range instead of automatically determining it with "$?^$?") to find all the footnote-references in your text and replace them with the footnote text with added markup notation. You can then do simple clean-up to remove the now-redundant footnote block: :$?^$?,$d and reformat/reflow everything as you see fit, maybe with gggqG Hope this helps, -tim -- -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200621185751.098604a6%40bigbox.attlocal.net.