Reputation: 1431
In ruby methaprogramming we have special types of comments within multiline string that will be evaluate. They looks like this: https://github.com/rails/rails/blob/8775ffa37231d381cba34f0ecacb8a7bbcf0573f/activesupport/lib/active_support/memoizable.rb#L77
This string divided line by line on two parts: string with interpolate that will be evaluate on the left side and example of code on the right side. Manually type this comments is a hard work. It requires many manual indentation.
Is there some plugins or tools in vim that help with code this type of comments?
Upvotes: 1
Views: 173
Reputation: 392833
First of all, get to know the features that make life easier for stuff like this in vim:
Visual block mode
virtualedit; You can move the cursor to positions where there isn't any text. This is called "virtual space". The user guide has extensive samples talking about editing ascii tables (similar to your situation in some ways):
Here are two approaches:
Assuming that the vertical split is always in a fixed column (like 84 in this sample):
/\%84v#\zs
will locate the vertical divider bar. Now you can operate on that, e.g.
This results in the comment lines being folded right after the 'template' line:
:g//s//\r /
Note: the (9) spaces have been chosen to match the starting indent level of the OP's sample.
IRL, you could useindent('.')
to figure out how many spaces programmatically
Presto:
To recombine:
:g//join!
Possibly combined with something to 'eat' the redundant indent (9 spaces)
:g//j!|norm! n9x
I'd usually opt to split the blocks into physical files instead. Recombining them will take more effort, but editing is much more comfortable and you can leverage vim's diffmode.
Just a quick starter:
ggn<C-v>ND
:tabnew | 0put
:tabprev
gvVxgvVd
:tabnext | vert new | 0put
put the windows in diffmode:
:windo diffthis
Now you can edit both windows independently, with live diff highlighting.
Let me know if you would like more input on this strategy. I might try my hand at recombining from the split temp-window configuration.
Upvotes: 5