Is it possible to create a ASCII comment box around the code block?
- ASCII box should be smart enough to extend the box around the maximum of code width. But It should also clear any trailing spaces.
- Notice, it should not have a column line at the beginning of the code.
- In my code shown below,
;
is a comment character. - The code block may contain the comment lines.
- Work flow may be
- pick the code block in visual mode
- Apply the changes.
Here is an example.
Before
; Convert to radians
theta45 = (theta + 45.)/!RADEG
theta90 = (theta + 90.)/!RADEG
theta = theta / !RADEG
Ey = Ey * normal
; Engineering shear strain
Gxy = shear * Exy
After
; -----------------------------------------;
; Convert to radians ;
theta45 = (theta + 45.)/!RADEG ;
theta90 = (theta + 90.)/!RADEG ;
theta = theta / !RADEG ;
Ey = Ey * normal ;
;
; Engineering shear strain ;
Gxy = shear * Exy ;
; -----------------------------------------;
What I have tried so far
'<,'>s/^\(\s*\)\(.*\)$/\=join([submatch(1), ';', submatch(2), repeat('-', 50-len(submatch(1)) - len(submatch(2))), ';'], '')
note I selected a visual block first.
Issues with it
- it adds '-' character to every line, instead of first and last line
- It starts with the first line and ends with last line, I prefer it to have a block before and after the selected lines.
- The trailing spaces are not removed.
- since I have search highlight enabled, it highlights the whole visual block, after the operation.
Here is how it looks:
;; Convert to radians ------------------;
;theta45 = (theta + 45.)/!RADEG------------------;
;theta90 = (theta + 90.)/!RADEG------------------;
;theta = theta / !RADEG ------------------;
;Ey = Ey * normal ------------------;
;--------------------------------------------------;
;; Engineering shear strain ------------------;
;Gxy = shear * Exy ------------------------;
While, it is not very close to what I want to get. I could only get this far!
Thanks for reading and your help.