Block commenting in Gedit?
Asked Answered
K

8

63

Is there a way to comment out a chunk of highlighted code?

I am programming in ruby, and I hate putting # on lines individually.

Kenogenesis answered 4/10, 2011 at 14:39 Comment(1)
Ugh, all the suggestions to use block commenting miss the point, IMO: not as easy or intuitive. IMO.Vizcacha
H
126

1.Install gedit plugins

 sudo apt-get install gedit-plugins

2.Go to Edit->Preference->Plugins-> and enable Code Comment

3.Ctl+m to comment block of codes

4.Ctl+Shift+m to uncomment block of codes

Hedelman answered 4/10, 2011 at 14:54 Comment(4)
I appreciate this answer because some languages don't have multiline comment support; this makes life much easier!Cloistral
worked for me for c++ by inserting //,, no clue if that's the comment for Ruby, or if gedit looks at the file extension (.cpp in my case) and chooses the comment characters accordingly.Senility
Unfortunately, the plugin seems to have been discontinued.Brink
Just installed it today, this is perfect. And the size changer one is useful too.Radiopaque
C
7

Ruby has block commenting...

=begin
    Insert comment here
=end

This will avoid the need to add # to each line... However, I don't think Gedit will convert highlighted code into commented lines by default.

Childs answered 4/10, 2011 at 14:46 Comment(0)
K
4

Code Comment plugin obviously is a good one for # (hash) style commenting but what if you need comment out php code block with double // slashes or any other custom commenting style? For example, with one or two whitespaces added after the comment symbol.

  1. Go to Edit->Preferences->Plugins-> and enable External Tools plugin.

  2. Go to Tools->Manage External Tools.

  3. Under the Tools side bar click add (+) sign, call your new tool "Comment out" and add this code into the Edit field:

    #!/bin/bash

    # comment out current selection

    # comment style

    comment="// "

    xargs -i -d\\\n echo $comment{}

  4. Set up your tool.

Shortcut Key: Alt+/ (put the cursor in the field and press Alt+/ or any other keys)

Save: Nothing

Input: Current selection (default to document)

Output: Replace current selection

Applicability: All documents? All languages? (change if you need)

To uncomment commented block of code do the same things except below ones.

  1. Name of the Tool: "Uncomment".

  2. Shortcut Key: Alt+Backspace

  3. Code to insert into the Edit field:

    #!/bin/bash

    # uncomment current selection

    # comment symbols to remove

    uncomment="^\/\/ "

    xargs -i -d\\\n echo {} | sed -ne "s/$uncomment//p"

Change comment/uncomment variable value (double slashes and space) with your desired commenting style.

Enjoy.

Kunkel answered 3/4, 2015 at 20:58 Comment(1)
This is awesome! Thanks for the recipe! Highly recommend to any gedit users out there.Tantra
O
3

Just use a multi-line comment.

Example:

=begin
Anything between a line consisting only of =begin
and a line consisting only of =end
is treated as a comment.
=end
Onomatopoeia answered 4/10, 2011 at 14:44 Comment(0)
E
2
=begin

Code to be commented out

=end
Encyclical answered 4/10, 2011 at 14:43 Comment(0)
B
2

Looks like Code Comment plugin would do it? http://live.gnome.org/GeditPlugins

Bindman answered 4/10, 2011 at 14:44 Comment(0)
V
1

Get the "code comment" plugin.

Vizcacha answered 4/10, 2011 at 14:44 Comment(0)
B
1

You should try gmate! It is a package of cool plugins for Ruby (and not only Ruby) developement under gedit.

You can comment and uncomment bunch of lines like in Sublime or TextMate

Bummer answered 13/6, 2012 at 18:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.