Is there a way to comment various lines at the same time in Xcode IDE? Selecting which lines to comment, then clicking somewhere et voilá.. the /* ... */ characters wrapping the code.
Thank you.
Command + Shift + 7
or
Command + /
This inserts // in front of every selected line.
Xcode Version 6.1
Shortcuts:
To Comment: Select the code to be comment, ⌘ + /
To uncomment: Select the code an press ⌘ + /
Also see taskbar Editor>Structure "(un)Comment Selection" as user 2137640 pointed out.
The answer is actually very simple if you want to comment a continuous sequence of lines. Select the consecutive lines, then simply press ⌘ /.
I have no idea how to comment multiple non-consecutive lines. Maybe somebody else can help with this, if it is even possible (I doubt it.)
I've been using the Command + Shift + 7 for years, but now in Xcode 13.1 it just started to open the help menu instead of commenting the selected block.
Apparently the new command for commenting a selection of code is:
Command + Shift + ?
Edit:
Another solution is to deselect "Show Help menu" in settings > keyboard > App Shortcuts
There is such a function in the menu. Try: Edit->Insert Text Macro->C->Comment Section.
It will create a (multi-line) comment around the currently selected text.
However, using the menu is probably often slower than manually inserting the comments. But, you can also bind a key to the menu item via the preferences key binding settings.
For single line Comment use ⌘+/
For multiline Comment you need to install CComent plugin
to install plugin manager use alcatraz
new Xcode 14:
Keys: Command + '
in Xcode 7.x
Shortcuts:
To Comment: Select the code to be comment, ⌘ + /
To uncomment: Select the code an press ⌘ + /
Got it! You have to un-indent the lines so the comments are the first character on the line, not a tab or whitespace - then pressing CMD+/ works. Just tried it in XCode 5.1.1, works like a charm.
This worked !
Higlight the desired lines then press Command + /
The same rule goes for uncommenting.
For xcode 8 ->
sudo /usr/libexec/xpccachectl
restart your computer
In Turkish keyboard cmd + *
You can use uncomment and multiline comment.
Related
Problem:
When I toggle a comment in Pydev it adds a space, inconveniencing me to manually correct this indentation. This was not an issue with earlier versions of Eclipse/Pydev. This problem occurs if I use the comment toggle key (ctrl + /) alone, or if I use it in combination with the uncomment key (ctrl + \).
System Versions:
Eclipse Juno (Version: 4.2.2), Pydev 2.7.3
Examples:
a = 4
# a = 4
a = 4
In line 2 I comment that code (ctrl + /). Line 3 I uncomment (ctrl + /). Notice there is a lingering space before the a in line 3.
Redoing this example with the same version of eclipse but using java no spaces are added:
a = 4
//a = 4
a = 4
So, I think this is a pydev issue.
Research:
As I said before, this is not an issue with my Eclipse Indigo / Pydev 2.5 install. Spaces are neither added nor subtracted when toggling comments (ctrl + /).
This appeared on stackoverflow before as an issue in java. The fix provided there had no effect for me (it doesn't matter if I use tabs or spaces):
Eclipse "Toggle Comment" Shortcut Indents on New Projects
This issue has also been reported on pydev source forge:
http://sourceforge.net/p/pydev/bugs/1547/
Work Around:
This is a solution for me, but isn't a true solution to the problem at hand. As suggested in the link above, do the following:
go to (in Preferences): Pydev | Editor | Code Style | Code Formatter
for the "Spaces in comment start?" combobox select "Don't change manual formatting".
Again, this solves my problem but doesn't solve the true problem at hand for someone who would like there to be spaces separating their comment from the comment symbol.
Also, because the default install preference is set to: "At least one space", this isn't an issue you would intuitively know how to fix upon just installing pydev for the first time.
This may not be exactly what you're seeking, but Eclipse (Oxygen with CDT, PyDev)
seems to preserve spacing spacing pretty well when using block comments. (under Source menu)
Add Comment Block Ctrl + 4
Add Single Comment Block Ctrl+Shift+4
Remove Comment Block Ctrl + 5
Ctrl + 4 works nicely in a .py file for Eclipse Photon with PyDev.
For any files which are not .py it may be useful after selecting text to use:
Edit -> Toggle Block Selection
..to manually put your '# ' simultaneously on all the lines where you want it, like in Sublime.
What are the best code blocks short cuts ? Also is there some way we can directly indent all our code ? In addition how can we move through the active tabs in codeblocks ?
Tips about tab identation are helpful when you write your code from begining. But if you paste code in CodeBlocks from some external source, like PDF document, that code often will not have good identation.
In this case, you need to select code, right click on it, and choose Format use AStyle option.
This is a plugin for CodeBlocks for right text formatting.
I hope this will help someone!
You (these are the default settings I believe) can select a block of code and press the Tab key. This will indent the entire block.
So for indenting a whole file: Ctrl + A, then Tab.
In addition, you can use Shift + Tab on a selected block to "unindent"
You can move through the open tabs with Ctrl + Shift + Tab.
As for the best shortcuts:
I like Ctrl + D to duplicate a line and
Ctrl + L to copy it.
Anyway, you can set whatever shortkeys you like in the Editor menu (there you will also be able to find all shortkey currently set).
]2
Add shortcut as you wish from Settings->Editor->Keyboard shortcuts->plugins->Source code formatters(Astyle) or use Plugins->Source code formatters(Astyle)
CTRL+A to select the code and TAB for alignment.
I have not had much luck with the code formatter in C::B. I like my code to look like this...
if (blah..) {
SomeCode();
} else {
DifferentCode();
}
it allows more code to fit on a screen, and is still reasonably readable.
After trying to tweak the settings in Settings->Editor, then Source Formatter tab, when I went to format my code, it removed the if line entirely, and I have not been able to unset my tweaks to make it work.
Fornatually, ctrl-z still works.
The code formatter should never remove code, only play with white space.
Maybe there is a better plugin.
Mark.
In addition in How to switch between tabs in codeblocks.
codebocks 20.03
Linux (KDE Neon)
To switch between tabs.
Activate this with CTRL+SHIFT+TAB, then you can use the know options:
CTRL+TAB , to switch to the right tab.
CTRL+SHIFT+TAB , to switch to the left tab.
Or this other option, but this is not in the keyboard shortcuts, this option doesn't work in a cycle mode, when your get the last right tab, it jump to the bottom tabs:
CTRL+ right-arrow-key , to switch to the right tab.
CTRL+ left-arrow-key , to switch to the left tab.
Remember to activate with CTRL+SHIFT+TAB.
After you land in the desire tab you can type TAB to begin to start writing code.
I couldn't find such feature in VS's shortcut list. Is there anyway?
If you want to copy a line, simply place cursor somewhere in that line and hit CTRL+C
To cut an entire line CTRL+X
#Sean found what I was looking for:
To disable this default behavior remove the checkmark (or check to re-enable)
Apply cut or copy commands to blank lines when there is no selection
Accessed from the menu bar: Tools | Options | Text Editor | All languages
You can also enter copy into the options search box for quicker access
[Tested in VS2008, 2010, 2017]
Clicking the line 3 times does the trick
If you have ReSharper you could use
Ctrl + W
- Extend Selection
Sidenote: You may have to use it multiple times depending on the context of your present text cursor position.
If you click once on the row number the entire row will be selected.
If you want to select a line or lines you can use the combination of ctrl + E then U. This combination also works for uncommenting a complete line or lines. This combination looks somewhat strange to work with, but it will get habituated very soon :)
You can also use Ctrl + X to cut an entire line. Similarly, you can use Ctrl + C to copy an entire line.
As long as you don't have anything selected, these commands will work on the entire line.
Clicking anywhere on the line and (CRTL + C) will copy entire line.
Clicking three time in quick succession also selects entire line.
There is a simple way of doing it, simple use Home or End button to reach the start or end of line, and then use home + shift or end + Shift depending on where your cursor is. Hope it helps.
Use the following:
Shift + End If cursor is at beginning of line.
or
Shift + Home If cursor is at the end of the line.
Alternatively, if you use resharper, you can also use the following
Ctrl + w while the cursor is positioned on the line you want to select
This won't solve the problem for Visual Studio, but if you're using Visual Studio Code you can use CTRL+L to select the line your cursor is currently on.
(If you're using Visual Studio, this will cut the line you're currently on—which may also be useful, but wasn't the question.)
Other answers require either using a mouse or hitting more than one combination.
So I've created a macro for those who want a VSCode-like Ctrl+L behaviour. It can select multiple lines, and that's useful for moving blocks of code.
To use it, install Visual Commander extension for macros: https://marketplace.visualstudio.com/items?itemName=SergeyVlasov.VisualCommander
Then create a new command, select C# as a language and paste this code:
using EnvDTE;
using EnvDTE80;
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
var ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
if (!ts.ActivePoint.AtStartOfLine)
ts.StartOfLine();
ts.LineDown(true, 1);
}
}
Now you can assign a desired shortcut in preferences:
Tested in VS 2022.
You can use CTRL + U . This shortcut is use also for uncomment.
You can change the shortcut on this feature. Go to Tools->Options->Environment->Keyboard->Edit.UncommentSelection and assign CTRL+W (same as Resharper) or you can use what shortcut do you want.
If you want to select full row Ctrl E + U
Just click in the left margin.
If you click in the margin just left of the Outline expansions [+][-]
it will select the row.
You can also just click and drag to select multiple lines.
Necvetanov eluded to this in his answer above about clicking on the line number.
This is right...but it just happens that the line number is in the margin.
Here is a whole list of the keyboard shortcuts Default keyboard shortcuts in Visual Studio
a work around for this:
ctrl+d = duplicate line
ctrl+l = copy line
ctrl+v = paste copied text
You can enter, home then shift + end as well. What it will do is take you to the beginning of line then select the whole line till end. Or alternatively first enter end then shift + home
You can set a bind to the Edit.ExpandSelection command:
In the options. Click the shortcut until it selects the whole line.
The screenshot above is from the Edit > Advanced menu in Visual Studio 2022. I set this Alt+E, E shortcut myself and I don't remember if it's originally set to something or not.
Simply by clicking on the line number that's being shown on the left in vs-code. just a single click and a line will get selected.
In Mac, it is ⌘+L.
But if you have some specific conflicting keybindings, this won't work. In my case the VSCode Live Server extension auto registered a couple of bindings for these keys. I removed them and it worked.
I assigned a shortcut key to the following functionality. I press the shortcut until it selects the whole current line:
Edit.SubwordExpandSelection
Back Arrow Broken In Xcode?
Is there keyboard command to go back/forward one file at a time.
Xcode 3.2 changed the behavior of Cmd-Opt <-- and -->. As noted in another question, they do not operate on a file level like in previous versions of Xcode, but on an "edit point", making it cumbersome to flip through a list of files (the quick way to do it, since Xcode does not support Tabs, as in Eclipse).
Rob Keniger found a partial solution that he noted in another post:
"Hold down the option key while you click the forward/backward arrows ..."
But this requires fiddling with the mouse. Is there any way to do it with the keyboard only?
EDIT:
Later versions of Xcode (v7.2+) now have a Navigate menu (and it changes the keyboard shortcuts yet again):
In XCode 4.4 the following sequence works:
Cmd + Ctrl + ←
and it operates on a file level.
On Xcode 8 I use 2 fingers left / right
Beginning in XCode 3.2.3, the following key sequence works:
Cmd + Option + Shift + ←
Without the Shift key, it just goes back to the previous cursor position. Adding Shift jumps to the previous file (next file, in combination with →).
Navigation shortcuts for Xcode
In Visual Studio I can navigate backwards by pressing Ctrl + -. This is very useful when checking out the definition of a function and then immediately going back to the code I was working on.
How can I do this in Xcode? (I'm using version 3.1.2)
* Writing this if people using Xcode 4 need the answer for their versions:
In Xcode 4 preferences, it's configured to be ^ + ⌘ + ← (control-command-left arrow) to navigate back and ^ + ⌘ + → (control-command-right arrow) to navigate forwards.
Xcode 3.1.x is admittedly a bit weak in this respect. Happily, the navigation #zoul mentions (The back/forward arrows in the header bar, or ⌘⌥← and ⌘⌥→) is significantly improved in Snow Leopard, and should provide the finer-grained navigation you're hoping for. Sorry there's not an immediate solution, but hopefully it helps to know that a fix is coming...
There’s a Cmd + Alt + ← that goes back in editor history, and conversely Cmd + Alt + → that browses forward. (Not sure if this is exactly what you are looking for.) It goes well with Cmd + Alt + ↑ that switches between the header and the implementation file.
There are small arrows on top left corner of editor pane in Xcode.
On Macs with multitouch trackpads, you can also use three-finger-swipe left and right to navigate through the file history.
Also re: MrDatabase's comments on stefanB's response, if you've been actually jumping from definition to definition (by, for instance, holding down Command and clicking on a symbol) as opposed to just scrolling, I believe that the file history should track navigation even within the same file... perhaps that was a change in Xcode 3.1.3.
Control + Command + Arrow keys work for me.
Other than the 'complete shortcut list', I don't know.
You can find previous with ⇧⌘G, but that's not really what you were after I think.
In Xcode 13.0.0 you can use:
(OS: Mac 11.6)
Control + Command + → or ←
Hope this help!