Commenting out code blocks in Atom - atom-editor

I have been moving from Webstorm and RubyMine to Atom and I really miss a feature from the Jetbrains editors where you select a code block and press CMD + - and it adds language specific comment character(s) to the beginning of each line. (# for ruby. // for js, /* for css etc.).
Is there a built in shortcut for Atom or a package which provides this feature?

According to this, cmd + / should do it.
And for Windows and Linux, it is ctrl + /.

Atom does not have a specific comment-block function, but if you select more rows and then use the normal ctrl-/ (Windows or Linux) cmd-/ (Mac), it will comment all the lines.

Command + / or Ctrl + shift + 7 doesn't work for me (debian + colombian keyboard).
In my case I changed the Atom keymap.cson file adding the following:
'.editor':
'ctrl-7': 'editor:toggle-line-comments'
and now it works!

Also, there are packages:
Comment package for atom (https://atom.io/packages/comment)
Block-comment-lines https://atom.io/packages/block-comment-lines
Sublime Block Comments

Pressing (Cmd + /) will create a single line comment. i.e. // Single line comment
Type (/** and press the Tab key) to create a block comment ala
/**
* Comment block
*/

with all my respect with the comments above, no need to use a package :
1) click on Atom
1.2) then ATL => the menu bar appear
1.3) File > Settings => settings appear
1.4) Keybindings > Search keybinding input => fill "comment"
1.5) you will see :
if you want to change the configuration, you just have to parameter your keymap file

You can use Ctrl + /. This works for me.

Multi-line comment can be made by selecting the lines and by pressing Ctrl+/ .
and Now you can have many plugins for comments
1) comment - https://atom.io/packages/comment
2) block-comment-lines - https://atom.io/packages/block-comment-lines
better one is block-comment try that..

Edit your keymap.cson file and add
Windows
'.platform-win32 .editor':
'ctrl-/': 'editor:toggle-line-comments'
Mac
'.platform-darwin .editor':
'cmd-/': 'editor:toggle-line-comments'
Now just highlight the text you want to comment and hit the keybinding.

You can use Ctrl + Shift + / for Windows.

Atom does not have block comment by default, so I would recommend searching for atom packages by "block comment" and install the one suits to you.
I prefer https://atom.io/packages/block-comment because is has the closest keyboard shortcut to line comment and it works as i need it to, meaning it would not comment the whole line but only the selected text.
line comment: CTRL+/
block comment: CTRL+SHIFT+/ (with the plugin installed)

Possible reason: watch out for overlapping keybindings. It has happened in my case and deactivated the initial toggle line comment binding:
The Keybindings you can find in the Edit -> Preferences -> Keybindings of the application navbar.
The solution was overriding binding for github:toggle-patch-selection-mode

On an belgium keyboard asserted on the mac
command + shift + / is the keystroke for commenting out a block.

CTRL+/ on windows, no need to select whole line, Just use key combination on line which you want to comment out.

first select your block of code then
press cmd + / for MacOS

Related

How can I auto-indent double bracket notation using Atom, in my HTML files?

In my Atom editor, I have a simple shortcut on the keymap:
'atom-text-editor':
'alt-a': 'editor:auto-indent'
In my *.html files, it does not indent Blaze liquid-like tags, for example:
{{#if something}}
{{else}}
{{/if}}
I looked into Atom beautify, but it does not consider the double bracket notation. The beautifier currently attached to *.html is JS beautify. I tried to switch to pretty diff but, while it worked, it also corrupted the i18n helper nested in attributes, eg. title="{{_ "edit"}}" becomes title="{{_ " edit"}}"="edit"}}""
I installed the HTML beautifier gem as suggested in the Atom beautify readme but it does not appear in the list of available beautifiers for HTML in the settings.
Any idea to point me toward the right direction and have my double bracket notation correctly indented?
there’s a package called ‘file-types’, which works wonderfully for changing default syntaxes. file-types link
another solution
Select the code and head to Edit > Lines > Auto Indent.
To speed this up, created a custom keyboard shortcut, enabling me to use Ctrl + Cmd + ] at any point. (On Windows, I would opt for Ctrl + } — which is Ctrl + Shift + ] — as Ctrl + Alt + ] is already taken.)

Show code line numbers in JupyterLab

In Jupyter notebook, cntrl+ m L toggles code line numbers in current cell but how to bring the code line numbers in JupyterLab?
Referred a similar issue opened in github
https://github.com/jupyterlab/jupyterlab/issues/2395 - Shift+L toggles line number visibility.
you can turn this on by default by going into Settings --> Advanced Settings Editor:
As you can see from the screenshot, you can edit other features as well and easily set them back to default by deleting your 'User Overrides'
Go to Settings > Advanced configuration and add:
{
"codeCellConfig": {
"lineNumbers": true
}
}
You can go to View -> Show Line Numbers:
which will display line numbers in the notebook:
Late reply, but it'll still help others!
For Windows users, just hit Shift + L
In your Jupyter Lab, click the chain, View -> Line numbers. This solution is from this GitHub issue.
I'm new at this so don't flame me. But Frank said from View -> Show Line Numbers. I did this from main JupyterLab window. I'm using version 3.5.0.

Keyboard shortcut for inserting roxygen #' comment start

This question might be over-answered but I could not find one. Basically I am using RStudio and the keyboard shortcut cmd + shift + c for inserting comments. Is there an other combination to insert directly the roxygen tags #' ? Or a way to modify RStudio to tell it to add the ' when I press cmd + shift + c?
You could use an RStudio addin, you'll need a fairly recent version of RStudio. I've just created an RStudio addin that comments/uncomments using roxygen2 tags, i.e. works just like code commenting, but with #'. The addin is hosted on github.
Just install and attach a convenient keyboard shortcut.
If you are interested in other available addins, see the addinmanager addin.
This isn't exactly what you're looking for. But you can add an ROxygen2 skeleton for a function by placing your cursor inside the function then pressing ctr+alt+shift+R. Then if you hit enter in the ROxygen2 codeblock it will automatically add the backtick. So an alternate workflow, edit the function, then insert the skeleton and do the documentation that way.
Rstudio find/replace
Select text to comment out, tick regex option and specify:
find: ^(.+)
replace: #' \1
Above means to find all characters (.+) following beginning of the line ^ and replace them by the #' and the first captured group \1.
vim find/replace
I find this option the easiest as I use Rstudio in vim mode. To replace text one only need to:
select text
go to the "command-line mode" by using : key
enter s/^/#' and hit enter.
s/ stands for "substitute", ^ stands for beginning of the line and #' is the text we are inserting.
This is not a default Rstudio option. Make sure you have Keybindings set to "vim" in RStudio "Global Options"
The absolute simplest answer is in the comments on the addins answer above and deserves its own billing (with attribution):
Rstudio does have column selection, to get multiple cursors alt + mouse to select, or ctrl + alt and the arrow keys, then keys move forward and back by words/lines work as expected. – Peter Apr 16 '16 at 23:55
[ETA: On Mac, ctrl + option + arrow keys or option + mouse.]
#Peter nice. in that case you could just make a chunk of cursors at the beginning of the line and and type in #' . I doubt roxygen comments are used enough to warrant a dedicated keyboard shortcut, but it wouldn't hurt to have I guess – rawr Apr 17 '16 at 1:26

How do I block comment in Jupyter notebook? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I want to comment out a block of multiple lines in Jupyter Notebook, but can't find out how to do that in this current version.
It used to be in one of the drop down menus but is no longer there.
How do you comment out multi-line blocks of code at once?
This is not a duplicate because the solution given in the following link doesn't seem to work anymore:
How can I block comment code in the IPython notebook?
Ctrl + / does nothing.
Ctrl + / works for me in Chrome browser in MS Windows. On a Mac, use Cmd + / (thanks Anton K).
Please note, if / did not work out of the box, try pressing the / key on the Numpad. Credit: #DreamFlasher in comments to this question.
I have not yet managed to find the best way possible. Since I am using a keyboard with Finnish layout, some of the answers do not work for me (e.g. user5036413's answer).
However, in the meantime, I have come up with a solution that at least helps me not to comment each and every line one by one. I am using Chrome browser in MS Windows and I have not checked other possibilities though.
The solution:
It uses the fact that you can have multiple line cursors in an Ipython Notebook.
Press the Alt button and keep holding it. The cursor should change its shape into a big plus sign. The next step is, using your mouse, to point to the beginning of the first line you want to comment and while holding the Alt button pull down your mouse until the last line you want to comment. Finally, you can release the Alt button and then use the # character to comment. Voila! You have now commented multiple lines.
Try using the / from the numeric keyboard.
Ctrl + / in Chrome wasn't working for me, but when I used the /(division symbol) from the numeric it worked.
Quick Addition to Top Answer: CTRL + / is nice because it toggles back and forth between adding and removing # at beginning of all selected lines. Didn't see that exact nuance mentioned so just wanted to add it here. (This worked in Firefox Developer Edition 54.0b12 on Windows 7).
On a Finnish keyboard use Ctrl + ' to comment on multiple lines and use the same keys to de-comment.
Ubuntu 14.04 Google Chrome
TL;DR:
Using MacBook Pro with Spanish - ISO Keyboard.
Solution: Ctrl + -
Full story
This is an old post but reading it got me thinking about possible shortcuts.
My keyboard is a Latin Apple MacBook Pro, which is called Spanish - ISO. I tried the changing keyboard distribution to U.S. solution... this works but with this solution I have to switch keyboards every time I want to comment which... sucks.
So I tried ctrl + - and it works. The - is where the / is located in an english keyboard but doing Cmd + - only changes the Chrome's zoom so I tried Ctrl which isn't as used as Cmd in macOS.
My takeaway with this would be: if I have more shortcut problems I might try the original shortcut but using the key where the U.S. keyboard would have it.
Select the lines you want to comment out. Then press:
Ctrl + #
I tried this on Mac OSX with Chrome 42.0.2311.90 (64-bit) and this works by using CMD + /
The version of the notebook server is 3.1.0-cbccb68 and is running on:
Python 2.7.9 |Anaconda 2.1.0 (x86_64)| (default, Dec 15 2014, 10:37:34)
[GCC 4.2.1 (Apple Inc. build 5577)]
Could it be a browser related problem? Did you try Firefox or IE?
Use triple single quotes ''' at the beginning and end. It will be ignored as a doc string within the function.
'''
This is how you would
write multiple lines of code
in Jupyter notebooks.
'''
I can't figure out how to print that in multiple lines but you can add a line anywhere in between those quotes and your code will be fine.
Fn + Cmd + / in Safari browser on MacOS
On MacOS 10.11 with Firefox and a German keyboard layout it is Ctrl + ?
Select the lines on windows jupyter notebook and then hit Ctrl+#.
I add the same situation and went in a couple of stackoverfow, github and tutorials showing complex solutions. Nothing simple though! Some with "Hold the alt key and move the mouse while the cursor shows a cross" which is not for laptop users (at least for me), some others with configuration files...
I found it after a good sleep night. My environment is laptop, ubuntu and Jupyter/Ipython 5.1.0 :
Just select/highlight one line, a block or something, and then "Ctrl"+"/" and it's magic :)
After searching for a while I have found a solution to comment on an AZERTY mac. The shortcut is Ctrl +/= key
I am using chrome, Linux Mint; and for commenting and dis-commenting bundle of lines:
Ctrl + /
For a Dutch keyboard layout (on Debian 9 in Chromium 57) it is Ctrl + °
Another thing to add, in the version I'm using, the code has to be initialized in order to be to comment it out using CTRL and / . If you haven't ran the code and the code isn't colorized it wont work.
If you have a Mac and not a English keyboard:
Cmd-/ is still easy to produce.
Follow the below steps:
Just go into the Mac's System Settings, Keyboard, tab "Input Sources" or whatever it might be called in English
Add the one for English (shows up as ABC, strange way to spell English).
Whenever you want a Cmd-/, you have to change to the ABC keyboard (in your menu row at the top of your screen,if you have ticked it to be shown there in the System Settings - Keyboard tab).
Cmd and the key to the left of the right "shift key" gives you Cmd-/.
P.S: Don't forget to switch back to your normal keyboard.

How to remove extra space after a colon in CSS with Sublime Text 2?

When auto-complete is triggered for a CSS style, Sublime by default adds a space after colon like so:
position: relative;
How do I remove this space?
I did some more digging and would like to suggest an alternate solution.
Open ~/Library/Application Support/Sublime Text 2/Packages/CSS/css_completions.py in Sublime.
On line 190, remove the space after the colon:
l.append((p, p + ": "))
The only caveat I can think of is that this might get overwritten when you update Sublime, but this seemed to work great without installing an extra package.
Edit: I submitted a different solution below, but would like to leave this here in case ppl are interested in Emmet which still looks pretty neat.
I'd like to offer up a somewhat tested solution :P I got it to replace my :<space> with a :).
Install the Emmet package for Sublime Text 2: https://github.com/sergeche/emmet-sublime (easiest way is via the Package Manager)
This seems like a pretty popular plugin. I would scan the feature set first though because it looks like it'll add a bunch of shortcuts you might not want.
Check out the documentation on customization: http://docs.emmet.io/customization/preferences/
Search the page for css.valueSeparator -- This is the field you want to change. It defaults to :<space>
– There are instructions for editing the package's preferences here: http://docs.emmet.io/customization/
I think I might actually keep/try this package myself. I hope it gives you what you're looking for.
Edit:
I found the emmet instructions somewhat vague. Specifically, in Sublime Text 2 go to:
Sublime Text 2 > Preferences > Package Settings > Emmet > Settings - User and enter your override preferences there in JSON format. Handily, you can cut and paste template code from Sublime Text 2 > Preferences > Package Settings > Emmet > Settings - Default (but leave that file alone as it'll be overwritten when the package is next updated).
Extra answer to add that if you're working in Sass or SCSS files, you'll need to edit the snippets one-by-one in ~/Library/Application Support/Sublime Text 2/Packages/Sass/Snippets to achieve this.
If you are using the Emmet package, the following solution should work with Sublime Text 3 too:
Open: Sublime Text 3 > Package Setting > Emmet > Settings-User and paste
{
"preferences": {
"css.valueSeparator": ":",
},
}
Solution for Sublime Text 3:
Installing Pacage control (if not already installed):
Open a console ctrl + `
Insert:
import urllib.request,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1514676163dafc88'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
Press eneter, check console and restart the program.
Start Pacage control with combination Ctrl + Shift + P
Select "Pacage control: Install Pacage", wait for new window
Select PackageResourceViewer
Select "PackageResourceViewer: Open Resource"
Select CSS
Select css_completions.py
change:
.append ((p, p + ":"))
on:
.append ((p, p + ":"))
If you have Emmet Pacage, you also need to do:
In the top menu
Package Setting> Emmet> Settings-User and paste
{
"Preferences": {
"Css.valueSeparator": ":"
}
}

Resources