Text editing - insert comments (#) in Ubuntu with gedit or other text editor
Asked Answered
S

3

7

I am programming in a dedicated language called macro language.

To comment I need to add # at the beginning of the line.

What I want is, in order to spare time, to comment several lines of code at same time with gedit or other program (gedit is nice in terms of the colors, which make the code more readable).

How can I do it?

Thank you in advance.

Shed answered 8/1, 2015 at 10:2 Comment(2)
Actually, is this asking how to comment code generally, or how to specify the line-comment-start string for a specific gtksourceview language definition?Fasano
I need to add a character # to the beginning to each line I want to comment. So what I want is select the code and then at the same time a # to the beginning of each line I selected :)Lucinalucinda
F
13

Possibly need # apt-get install gedit-plugins.

Then go to edit > preferences > plugins > enable "code comment".

Then use ctrl-m to comment and ctrl-shift-m to uncomment.

(Technically, I think this would go in SuperUser though.)

Fasano answered 8/1, 2015 at 10:7 Comment(2)
for me doesn't because the comment character is a # and with that plugin is a %... is there a way to turn around this?Lucinalucinda
@AndréMiguelMonteiro, see my other answer for how to specify a correct line-comment-start for gtksourceview (gedits source code parsing engine).Fasano
W
2

There is a plugin for gedit, which should help for your needs. You can get this from github:

https://github.com/jessevdk/gedit-multi-edit

Working answered 8/1, 2015 at 10:10 Comment(4)
That is... really overkill for commenting out code blocks.Fasano
Yes you are right i was just thinking about multiple editing points, but just for the comment stuff ur way is much easier to do ;)Working
how do I install the plugin?Lucinalucinda
I am not getting it right it is really overkill like David said! But thank you sLyLucinalucinda
F
0

You can specify a custom language definition by putting the below text (with ... replaced with the rest of the language definition) in ~/.local/share/gtksourceview-3.0/language-specs/thingy.lang:

<?xml version="1.0" encoding="UTF-8"?>
<language id="thingy" _name="Thingy Code" version="2.0" _section="Sources">
  <metadata>
    <property name="line-comment-start"># </property>
    ...
  </metadata>
  <styles>
    ...
  </styles>
  <definitions>
    ...
  </definitions>
</language>

You'll probably want to base your language spec off of one of the langage specs in /usr/share/gtksourceview-3.0/language-specs/, since it's kind of a pain to get a working language spec from scratch (especially since the XML parser error messages are anywhere from useless to worse).

Fasano answered 8/1, 2015 at 11:13 Comment(2)
I can't find the folder gtksourceviewLucinalucinda
@AndréMiguelMonteiro, if you mean ~/.local/share/gtksourceview-3.0/, you might have to create it (and language-specs/), since I don't think they get created by default. If you mean /usr/share/gtksourceview-3.0/, then your system is probably completely different from what I can usefully give advice on.Fasano

© 2022 - 2024 — McMap. All rights reserved.