Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to be able to remove the first character of a line when I highlight multiple lines in gedit.

Example:

%Example is
%Commented Code
%Uncomment using this shortcut

I would then highlight/select these lines, and remove the first character to make it look like this:

Example is
Commented Code
Uncomment using this shortcut

I'm pretty sure there is an actual shortcut for this.

If there is another text editor on Linux that it would work in, it would be nice to know how to do it in that editor as well.

share|improve this question
2  
This probably will be specific for editors. Can you provide more detail? –  whitequark Jan 23 '10 at 2:11
    
In some editors you can hold down alt to select a block of text, then delete. –  hyperslug Jan 23 '10 at 2:42
    
added linux tag –  Scott McClenning Jan 24 '10 at 2:48
    
Sublime Text has powerful multiselection features. If the cursor were at the beginning of the first line, you would just go ctrl-alt-down twice, then press delete. –  dangph Dec 9 '12 at 13:26
add comment

4 Answers

That really depends on the software you're using.

For instance, MS-Word would left you alt-select the first character of the lines (if the lines doesn't wrap around).

If you're using an editor that allows Regular Expression search and replace you could use something like ^. to search for the first character of each line.

Unfortunately you need to be more specific.

share|improve this answer
    
In Virtual Studio, it's Ctrl+Shift+E, C to add comment marks to a selection, and Ctrl+Shift+E, U to uncomment a selection. –  Jared Harley Jan 23 '10 at 5:47
add comment

This can be done using gedit Snippets. They are available as part of gedit-plugins from your distro's repositories.

Once they're installed, open gedit, go to Edit -> Preferences -> Plugins, and enable Snippets.

Now you have to create the new snippet which is pretty straightforward and an amazing time saver for code you write frequently.

1. Go to Tools -> Manage Snippets.

2. Find the language/type of file you want to use the snippet for (or Global for all) and click the '+' icon to create new snippet.

3. Name the snippet, then click in the "shortcut key" text box on the right and press your shortcut key combination you want to use: e.g. Shift_ctrl_%

4. Then in the box on the right, enter:

$<
import re
lines = $GEDIT_SELECTED_TEXT.split("\n");
output = "";
for line in lines:
  output += re.sub('^%((.)*)', r"\1\n", line)
return output
>

This uses a python regular expression to only remove the first character in a line if it is '%'.

note: you can use any python code in a snippet, for example if you wanted to remove multiple instances of '%' or '#' at the beginning of a line you could use lstrip.

$<
lines = $GEDIT_SELECTED_TEXT.split("\n");
output = "";
for line in lines:
    output += line.lstrip('%#') + "\n"
return output
>

5. After you create the snippet, click close, highlight your text and hit your shortcut key.

note: If you want a snippet that will return % back t the beginning of all highlighted lines:

$<
lines = $GEDIT_SELECTED_TEXT.split("\n");
output = "";
for line in lines:
  output += "%" + line + "\n";
return output
>

note: for some reason snippets with shortcut keys only work (for me) when they're defined for a specific language. Global shortcut keys don't work but the tab triggers for them do, ymmv.

More info on snippets at http://live.gnome.org/Gedit/Plugins/Snippets

share|improve this answer
add comment

There's a really simple way to do this in gedit.

At the terminal: sudo apt-get install gedit-plugins

Open gedit, then go to Edit -> Preferences -> Plugins tab.

Tick Code comment.

(NB You only have to do the previous 3 steps the first time, to get the plugin set up.)

Open up your file. Assuming it's e.g. bash, latex, then hopefully gedit will auto-detect the filetype and apply syntax rules. If you're not sure, look at the bottom margin of the window - there's a drop down language selector.

Now just highlight a few lines and hit Ctrl + M to comment, or Ctrl + Shift + M to uncomment.

HTH.

share|improve this answer
add comment

In kwrite an the likes (kile,...) it's Ctrl+D to comment and Ctrl+Shift+D to uncomment.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.