Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
0
votes
1
answers
32
views
Where is Kwrite's edit menu option "toggle comment"?
I use Kwrite for looking at code. Sometimes I want to test the result of removing a line and Kwrite had a very useful menu option : "Toggle comment" (before there were 2 lines in that menu, "Comment" and 'Uncomment"). As I don't do that every day and as the syntax differs from language to language (...
I use Kwrite for looking at code. Sometimes I want to test the result of removing a line and Kwrite had a very useful menu option : "Toggle comment" (before there were 2 lines in that menu, "Comment" and 'Uncomment"). As I don't do that every day and as the syntax differs from language to language (and sometimes within the same language if you consider CSS to be a part of HTML), I can never remember how to do it.
I've just noticed that this menu option is missing from my current version of Kwrite (on an up-to-date Lubuntu).
How can I get it back? Should I try to install an older version of Kwrite?
Alain Reve
(123 rep)
Feb 10, 2025, 08:08 PM
• Last activity: Feb 10, 2025, 11:05 PM
3
votes
5
answers
263
views
How to let sed un-comment one of multiple paragraphs separated by newlines?
Clarification: Using GNU sed. Status quo - ~/.screenrc, last lines: ``` # name synthpop # screen -t script emacs -nw /home/$USER/bin/synthpop # name thrashmetal # screen -t script emacs -nw /home/$USER/bin/thrashmetal # number 1 # split -v # focus # chdir "/home/$USER/thrashmetal/src" # screen -t sc...
Clarification: Using GNU sed.
Status quo - ~/.screenrc, last lines:
# name synthpop
# screen -t script emacs -nw /home/$USER/bin/synthpop
# name thrashmetal
# screen -t script emacs -nw /home/$USER/bin/thrashmetal
# number 1
# split -v
# focus
# chdir "/home/$USER/thrashmetal/src"
# screen -t scr watch nl asdkjlek.html
# number 2
# focus
# split
# focus
# screen -t output watch thrashmetal asdkjlek.html
# number 3
# focus
# split
# focus
# chdir "/home/$USER/thrashmetal/plan"
# screen -t soll watch less soll
# number 4
# focus
# name darkwave
# screen -t script emacs -nw /home/$USER/bin/darkwave
Aim:
# name synthpop
# screen -t script emacs -nw /home/$USER/bin/synthpop
name thrashmetal
screen -t script emacs -nw /home/$USER/bin/thrashmetal
number 1
split -v
focus
chdir "/home/$USER/thrashmetal/src"
screen -t scr watch nl asdkjlek.html
number 2
focus
split
focus
screen -t output watch thrashmetal asdkjlek.html
number 3
focus
split
focus
chdir "/home/$USER/thrashmetal/plan"
screen -t soll watch less soll
number 4
focus
# name darkwave
# screen -t script emacs -nw /home/$USER/bin/darkwave
My current attempt, which almost does the job but fails stopping as soon as the line comes, which is just a new line without any comment sign or alphanumerical characters:
sed 's+^# \(name thrashmetal\)+\1+;:a;s+# ++;ta' .screenrc
Explanation, intention:
- '
start of a sequence of things to do
- s
replace
- +
use "+" as delimiter
- # …
go through line by line until you find a line starting with "# "…
- \(
start group for later back-reference
- name thrashmetal
and continuing with "name thrashmetal"
- \)
end of group
- +\1+
replace first match within that line with just the group part, without the "# "
- ;
then, from that point on, do another thing…
- :a
do a loop called "a"
- ;s
where for every following line, line by line, you replace…
- +
set "+" as delimiter
- #
the first match of "# " within this line, irrespective of what follows it within this line…
- ++
with nothing, effectively deleting it
- ;ta
do that as long as you fail doing it, **which should be as soon as you have reached the end of the paragraph and then the 2 newlines separating the thrashmetal-block from the darkwave-block**, and then go back to where "a" was
- '
end of a sequence of things to do
- .screenrc
do said sequence of things regarding the file ".screenrc" in my current directory - my home directory
Standard output:
# name synthpop
# screen -t script emacs -nw /home/$USER/bin/synthpop
name thrashmetal
screen -t script emacs -nw /home/$USER/bin/thrashmetal
number 1
split -v
focus
chdir "/home/$USER/thrashmetal/src"
screen -t scr watch nl asdkjlek.html
number 2
focus
split
focus
screen -t output watch thrashmetal asdkjlek.html
number 3
focus
split
focus
chdir "/home/$USER/thrashmetal/plan"
screen -t soll watch less soll
number 4
focus
name darkwave
screen -t script emacs -nw /home/$USER/bin/darkwave
How to fix this? What am I doing wrong that the loop doesn't come to a halt as soon as it reaches the end of the thrashmetal-paragraph, but simply hops over to the next paragraph - the darkwave-paragraph - and continues?
Anything in that loop must be wrong, I guess…
Maybe the "t", but "T" or "b" don't cut it, either…
futurewave
(213 rep)
Mar 20, 2024, 11:33 PM
• Last activity: Mar 25, 2024, 04:22 PM
153
votes
6
answers
414235
views
How to comment multiple lines at once?
How can I select a bunch of text and comment it all out? Currently I go to the first line, go to insert mode then type `#` left-arrow down-arrow and then I repeat that sequence, perhaps saving a few keystrokes by using the `.` repeat feature to do each line. Is there anyway I could (for instance) se...
How can I select a bunch of text and comment it all out?
Currently I go to the first line, go to insert mode then type
#
left-arrowdown-arrow and then I repeat that sequence, perhaps saving a few keystrokes by using the .
repeat feature to do each line.
Is there anyway I could (for instance) select either multiple lines in visual mode or by using a range of lines and an ex ('colon') command and for that range comment out all the lines with a #
to make them a "block comment".
The ability to quickly 'de-comment' (remove the #
's) for a block comment would also be nice.
Michael Durrant
(43563 rep)
Mar 20, 2014, 04:14 PM
• Last activity: Apr 25, 2023, 10:24 AM
0
votes
0
answers
52
views
Capturing comment character from matching pattern
I would like to pick out lines from a file matching # Mode: org `#` can be any comment character for the programming language of the file. Rather than `#`, in could also be any of `;` or `!`, with any preceeding number of spaces using a bash script. Examples # Mode: org ;; Mode: org !! Mode: org One...
I would like to pick out lines from a file matching
# Mode: org
#
can be any comment character for the programming language of the file.
Rather than #
, in could also be any of ;
or !
, with any preceeding number of spaces using a bash script.
Examples
# Mode: org
;; Mode: org
!! Mode: org
One could figure out the language from the file extention
.el emacs
.c c
.cc c++
.sh bash
.rc bash
.f fortran
.F fortran
.f90 fortran
.texi texinfo
.tex tex
This is the current bash function I am using
capture ()
{
local efile="$1"
local begorg endorg charcl
impl="1"
if [ "$impl" = "1" ]; then
charcl='^[[:space:]]*(#|;|!)+[[:space:]]*'
elif [ "$impl" = "2" ]; then
charcl='^[[:space:]]*(//|@c)[[:space:]]*'
fi
begorg="${charcl}"'Mode: org$'
endorg="${charcl}"'# End of org$'
awk -v ccls="$charcl" -v bego="$begorg" -v endo="$endorg" \
'$0 ~ bego { found=1; next }
$0 ~ endo { found=0; }
found { sub(/ccls/,""); print }' "$efile"
}
Would be better to this in awk
, but I struggle on how to include the pattern.
// { set variable to A }
/other pattern/ { set variable to B }
... use variable in sub
Vera
(1363 rep)
Nov 3, 2021, 12:35 PM
• Last activity: Nov 3, 2021, 01:20 PM
3
votes
2
answers
8630
views
Passing Argument to Comment in .sh script
I am a beginner in the use of .sh scripts so please excuse my ignorance. This is my problem: To submit my jobs to our cluster the corresponding submit file has to contain a "slurm header" and looks something like this. #!/bin/sh # ########## Begin Slurm header ########## # #SBATCH --job-name=blabla...
I am a beginner in the use of .sh scripts so please excuse my ignorance. This is my problem:
To submit my jobs to our cluster the corresponding submit file has to contain a "slurm header" and looks something like this.
#!/bin/sh
#
########## Begin Slurm header ##########
#
#SBATCH --job-name=blabla
#
########### End Slurm header ##########
# Load module
module load math/matlab/R2020a
# Start a Matlab program
matlab -nodesktop -r "program $1 $2"
exit
Notice that I am passing two arguments to this .sh file which are then passed on to the matlab program. How can I make the job-name in the Slurm header dynamic according to the input arguments?
Simply writing
#SBATCH --job-name=blabla$1$2
predictably doesn't work.
stollenm
(133 rep)
Sep 17, 2021, 09:10 AM
• Last activity: Sep 21, 2021, 11:05 AM
0
votes
1
answers
81
views
Prepend two lines containing comments and URLs before specific line in python-scripts using sed
In some of my `python`-scripts, I've put the line `if __name__ == '__main__'` in order to make the content only be executed, when the script is run itself as `main`-script (as opposed to being imported, see [this explanation][1]). As I've found that out just recently, I wanted to add two informative...
In some of my
python
-scripts, I've put the line if __name__ == '__main__'
in order to make the content only be executed, when the script is run itself as main
-script (as opposed to being imported, see this explanation ).
As I've found that out just recently, I wanted to add two informative comment-lines before that line using sed
.
*The lines I want to prepend are:*
# Docs on scope of __name__ == "__main__": https://stackoverflow.com/a/419185/12298276
# -> Makes boolean "execute_in_script = True/False" obsolete
In order to accomplish this, I put up the following find
- sed
- command which shall make the desired change in all my python
-scripts automatically:
find /home/andylu/Desktop/Python/Scripts/ -not -path "*.history*" -not -path '*__pycache__*' -type f -exec sed -i -Ee '/^if __name__ == '__main__':.*/i # Docs on scope of __name__ == "__main__": https://stackoverflow.com/a/419185/12298276\n# -> Makes boolean "execute_in_script = True/False" obsolete' {} \;
Unfortunately, it doesn't work. It seems to be running as it takes like 30 seconds to complete, but there is neither any output in the console, nor changes in the python
-scripts.
How do I have to correct my sed
-string, which is like /line of interest/i Lines to\nprepend before that line
, to make it work?
----------
Documentation on how to prepend or append lines with *sed*:
See this blog post .
Andreas L.
(305 rep)
Dec 22, 2020, 08:55 PM
• Last activity: Dec 24, 2020, 06:49 PM
16
votes
1
answers
4221
views
What does (arg: n) in the command prompt mean?
On Codecademy's [Command Line Course](https://www.codecademy.com/learn/learn-the-command-line), when trying to use the keyboard shortcut `Alt+Shift+#` (which is supposed to comment the current line) in the command prompt, it switches the prompt from `$` to `(arg: 3)` instead of adding a dash at the...
On Codecademy's [Command Line Course](https://www.codecademy.com/learn/learn-the-command-line) , when trying to use the keyboard shortcut
The shortcut works fine on my machine.
1. What is this
Alt+Shift+#
(which is supposed to comment the current line) in the command prompt, it switches the prompt from $
to (arg: 3)
instead of adding a dash at the beginning of the line. Alt+Shift+@
will make it display (arg: 2)
instead, etc.
See the last line in the screenshot below. Before I hit Alt+Shift+#
it was just $
.

(arg: n)
thing?
2. What do keyboard shortcuts depend on to work? Keyboard layout? OS distro? Terminal emulator? Default CLI? What?
user331380
(163 rep)
Jan 14, 2019, 09:30 AM
• Last activity: Jan 14, 2019, 11:04 AM
2
votes
0
answers
102
views
How to exclude programs from writing to RAM block cache? (e.g. media player)
When playing back huge video files, the media player ravenously consumes disk cache and thus kicks out blocks cached by other programs. Not to confuse with LinuxAteMyRam.com. I would like the media player just to read the video files without the contents of the video files to be stored into the bloc...
When playing back huge video files, the media player ravenously consumes disk cache and thus kicks out blocks cached by other programs.
Not to confuse with LinuxAteMyRam.com.
I would like the media player just to read the video files without the contents of the video files to be stored into the block cache inside of the RAM, which could lead to other programs slowing down because the video player kicked out their cached RAM data from the disk cache.
----
Related question: https://unix.stackexchange.com/questions/476658/deactivating-disk-cache-for-specific-device-or-partition
neverMind9
(1720 rep)
Aug 31, 2018, 11:53 PM
• Last activity: Oct 21, 2018, 01:36 AM
18
votes
5
answers
36391
views
vimrc - how to block comment?
I don't want to comment lines of text in a text file or code. I am looking for inserting block comments in a *.vimrc* file. To insert a single line comment `"` is used, for example: " remove spaces and tabs as well at the end of line automatically while saving autocmd BufWritePre * :%s/\s\+$//e Now...
I don't want to comment lines of text in a text file or code. I am looking for inserting block comments in a *.vimrc* file. To insert a single line comment
"
is used, for example:
" remove spaces and tabs as well at the end of line automatically while saving
autocmd BufWritePre * :%s/\s\+$//e
Now I've got a relatively large amount of settings/configs/plugins collected over the years after browsing through the internet to add cool features. I'm looking to add some large comment blocks to my .vimrc file. Adding "
to each line is a option but I am looking for a block comment syntax. Similar to /**/
in C.
//
is identical to "
/* */
is identical to ___________ ?
Searching Unix.SE, SO and googling didn't help much.
mtk
(28478 rep)
Jun 3, 2013, 07:37 AM
• Last activity: Dec 15, 2017, 04:22 PM
0
votes
1
answers
1208
views
How to comment out LaTeX code in Gedit?
I am not sure if it is supported but cannot find it. OS: Debian 8.5
I am not sure if it is supported but cannot find it.
OS: Debian 8.5
Léo Léopold Hertz 준영
(7138 rep)
Oct 19, 2016, 09:31 AM
• Last activity: Oct 19, 2016, 07:09 PM
2
votes
2
answers
4007
views
how to use SED to replace comments within a comments section
Assume that I have a file that starts with the following /********************************************************* blah blah blah blah blah blah blah blah blah *********************************************************/ Actual code follows here code code code The command I used: sed -i 's/(/*).*(*/)...
Assume that I have a file that starts with the following
/*********************************************************
blah blah blah
blah blah blah
blah blah blah
*********************************************************/
Actual code follows here
code
code
code
The command I used:
sed -i 's/(/*).*(*/)/\1 newcomment \2/1' file
but I received the error message
sed: -e expression #1, char 14: unknown option to `s'
p.s. my question is ... how can i REPLACE the "blah blah blah..." comments with other bloah bloah bloah comments ?
Chan
(23 rep)
Aug 18, 2016, 08:56 AM
• Last activity: Aug 18, 2016, 09:59 AM
8
votes
1
answers
510
views
Change inside comments with Vim
Is there a way to change inside of a comment with Vim? I know you can change inside brackets and quotes with `i]` and `i"`. For example, If you are on a quote you can press, > ci"my new textESC And this will replace the text inside of the quote with the phrase "my new text", but how can I do the sam...
Is there a way to change inside of a comment with Vim? I know you can change inside brackets and quotes with
i]
and i"
. For example, If you are on a quote you can press,
> ci"my new textESC
And this will replace the text inside of the quote with the phrase "my new text", but how can I do the same thing with C comments which are enclosed with /* and */?
Tyler Durden
(6193 rep)
Sep 7, 2014, 10:21 PM
• Last activity: Sep 7, 2014, 11:41 PM
Showing page 1 of 12 total questions