Macro for commenting lines out?

28 views
Skip to first unread message

jason404

unread,
Dec 15, 2019, 9:01:08 AM12/15/19
to niceeditor
Has anybody got a macro which can comment out (as in add a # at the start of) lines within a marked block?  That would be so useful.  And one that could uncomment as well?

I currently use vertical pastes, but they need to be done repeatedly or trimmed, depending on how many lines need to be commented, so what I do more often is do it manually.

Basically, I'm thinking of something just like the Shift function, but it adds or removes a column of hashes and then one column of spaces, rather than spaces/tab.

jason404

unread,
Dec 15, 2019, 9:09:27 AM12/15/19
to niceeditor
I just realised I could use an external script using Through, as it works on marked blocks.

John Gabriele

unread,
Jan 3, 2020, 11:39:24 PM1/3/20
to niceeditor
I created a couple of very simplistic macros for this (I don't remember if someone else suggested their content to me --- Todd is always passing along good ideas), and bound them to [x and [w. The comment macro is:

~~~
InsertString "// "
MoveLeft
MoveLeft
MoveLeft
LineDown
~~~

and the uncomment:

~~~
Mark
MoveRight
MoveRight
MoveRight
Erase
LineDown
~~~

-- John

jason404

unread,
Jan 5, 2020, 1:00:29 PM1/5/20
to niceeditor
Hi.  I just added these to my .keys file:

# META 1
 
KEY
1B1 Through sed 's/^/# /'
 
# META 2
 
KEY
1B2 Through sed 's/^# //'

This adds/removes a hash and then a space at the begging of the lines in a marked block, by typing alt-1/2.

Cheers.

John Gabriele

unread,
Jan 5, 2020, 9:09:38 PM1/5/20
to niceeditor
Nice approach! Thanks for sharing.
Reply all
Reply to author
Forward
0 new messages