Congrats! Works out of the box and does exactly what I had in mind:
copy-pasted the commands and the result is spectacular. The clever idea
is to use the :g(lobal) command to build the array.
I posted a little too fast and left out an important third³ footnote at
the bottom of my message... something like 'the footnotes in the example
are only one line long so as not to clutter up your screen... but in my
use case many are multi-line'.
But after playing with my files for a while it's pretty easy to reflow
the footnotes so that they're only one line long:
1. add a null line between the footnotes
2. reflow them with a largee textwidth value
3. add a line break after each [nnn] in column 1
4. remove the null lines added in 1
Having done this I'm back to where I was (but with one-line notes)
& your solution will work the same.
What are all these magical dollar signs in the "g(lobal)" and
"s(ubstitute)" commands? They appear to define a vim command 'range' but
since I've never used ranges — and I'm damned if I can figure out how to
read this particular bit of magic...
Since I couldn't think of a way to highlight the targeted section of the
file I did a:
:$?^$?,$w /tmp/t.txt
... and I saw that the footnotes section at the end of the files was
excluded from the resulting /tmp/t.txt file.
Please explain.
Oh, and how would I go about running this sequence of commands on
a bunch of open file (buffers) in a vim session? what would the best
tactics to do :bufdo of all these commands?
Well... I had a hunch this could be 'done the smart way' simply using
basic vim commands... gladd I asked...
Thanks,
CJ
> > To build this associative array, you might try
> >
> > :$?^$?,$g/\[\d\+\]/let b:a[getline('.')]=getline(line(".")+1)
>
> Whoops, before you do this, you might have to let vim know that b:a
> is an array:
>
> :let b:a={}
> :$?^$?,$g/\[\d\+\]/let b:a[getline('.')]=getline(line(".")+1)
>
> > You can then use
> >
> > :1,$?^$?s/\[\d\+]/\='^['.b:a[submatch(0)].']'/g
>
> Oh, this also assumes that all footnote-references have corresponding
> entries in the footnote block. If you have a [13] and there's no
> [13] footnote at the bottom, that substitute will yell at you about a
> "E716: Key not present in Dictionary: {bogus footnote}"
--
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200623001643.GB25135%40turki.local.
No comments:
Post a Comment