Keyboard shortcut to Un/Comment out code in Mathematica 7? - keyboard-shortcuts

A keyboard shortcut to comment/uncomment out a piece of code is common in other programming IDE's for languages like Java, .Net. I find it a very useful technique when experimenting through trial and error to temporarily comment out and uncomment lines, words and parts of the code to find out what is and isn't working.
I cannot find any such keyboard shortcut on the Mathematica front end in version 7. I know that it is possible to comment out code by selecting the code, right mouse click and select Un/Comment from the menu that appears but this is too slow while coding.
I tried to access this using the menu key Menu on the keyboard but Mathematica frontend doesn't respond to or recognise this key unlike other applications, this could have allowed a key combination for commenting. Can someone else verify that this isn't unique to my machine and that the key isn't recognised by mathematica. I looked at this question and looked in the KeyEventTranslations.tr file but I don't think there is any way to create a shortcut to do this(?). Should I just live with it?
Any other suggestions?
(I have seen there is an Emacs version of mathematica, I have never tried Emacs or this Mma version and imagine that it would have this ability but would prefer not to go to the trouble and uncertainty of installing it. Also I would guess that the Wolfram Workbench could do this, but that may not be worth the investment just for this.)

You can install the shortcut in Mathematica 7.0.x if you are willing to edit the Mathematica system file MenuSetup.tr. You can find it in the same location as the KeyEventTranslations.tr file (i.e. in the installation under "SystemFiles/FrontEnd/TextResources/platform"). In MenuSetup.tr, locate the following line under the definition of the Edit menu:
MenuItem["Check &Balance", "Balance", MenuKey["B", Modifiers->{"Control", "Shift"}]],
Immediately below that line, insert the following:
MenuItem["Un/C&omment Selection", KernelExecute[FE`toggleComment[]], MenuKey["/", Modifiers->{"Command"}], MenuEvaluator -> Automatic, Method -> "Queued"],
The Un/Comment Selection command is now available under the Edit menu, with the keyboard shortcut Cmd-/ or Alt-/ depending on your platform -- just like in Mathematica 8 where this command comes pre-installed.
Please take as read the usual disclaimers about hacking the Mathematica installation files -- no warranty is offered :)
I do not know of any way to map this function to some shortcut involving the Menu key.
Shortcut Key, No Menu
The preceding steps mimic what Mathematica 8 does by installing a new menu item. If you prefer to leave the menus unchanged, then you can install the shortcut in KeyEventTranslations.tr instead. Add the following line:
Item[KeyEvent["/", Modifiers->{Command}], KernelExecute[ToExpression["FE`toggleComment[]"]], MenuEvaluator -> Automatic, Method -> "Queued"]
You'll need a comma on the end of that line if it is not the last item in the list.

Select the code and press one of the following:
Alt+/
Alt-E-O
Alt+E+O
Notes:
Tested only on Windows, using Mathematica 8.
On my non-US keyboard (ABNT Brazil), the shortcut Alt+/ doesn't work, instead I use Alt+E+O.

Here is code for your KeyEventTranslations.tr file that will comment out code. I am still working on the other half.
Item[KeyEvent["/", Modifiers -> {Command}],
FrontEndExecute[{
NotebookApply[FrontEnd`InputNotebook[],
"(*\[SelectionPlaceholder]*)"
]
}]
],
This binds it to Alt+/ as it is in Mathematica 8.

Related

How do I jump to matching brace in VS 2019?

As best as I can tell, Visual Studio 2019 completely removed the ability to jump to matching brace.
I tried the hotkey I've been using for years (Ctrl-]) and it changes indent instead (why would I need that? This is C#, not Python). I also tried looking up the KeyMap (Environment->Keyboard) setting and searching for match, and there was nothing relevant. As far as I can tell, Microsoft has completely removed this feature, but I wanted to confirm that Fattie and I are not the only ones with this problem.
(for reference, here is the question for VS 2008 whose answer no longer works because the default keyboard shortcut has changed.)
EDIT: The setting still exists, but has been renamed to not contain the all-important keyword "match". See accepted answer.
The control is still there.
Go to Tools -> Options -> Environment -> Keyboard and lookup Edit.GotoBrace to see the current key combination for this feature:
You can set the key combination from the pictured menu.
just for the ones among us with non-us keyboard. On my keyboard, I need to press 'AltGr' to access "]". Therefore Ctrl+] doesn't work. Interestingly, VS has already compensated for that problem and changed the hotkey to Ctrl+`, which works nicely for me. You just need to know the hotkey has changed (depending on your keyboard).
Hope this saved a few minutes of your time ;)
Regards,
Eleusius.
On a Finnish/Swedish keyboard the Edit.GotoBrace field is mapped to Ctrl+Å

CLion code navigation with C++ doesn't work

I've used AppCode (Intellij C++/ObjC IDE that replaces Xcode) for a while and really gotten used to being able to Ctrl+Click on any identifier to get to its definition/decleration.
Now on a new work place, I'm using CLion for a somewhat larger code base and Ctrl+Click hardly ever works. It only seem to work when the identifier is in the same file.
Is there anything I need to setup for this to work correctly? CLion seem to index the code successfully and doing text searches works fine.
You need to use import project functionality of CLion from File -> Import Project and give ok for CMakeLists.txt file automatic creation. Never mind the file is for CMake, you can build your project with other tools too, but CLion uses it for the dependencies.
Then append in the beginning of that file a line stating:
include_directories(.)
After that go to File -> Settings and there search for Keymap from the left and after that on right, right below the word "keymap" there is a selection element for taking for example Eclipse default keymapping in use and there you have at least (I tested only it) the ctrl + click functionality working like charm!!
kudos about the include_directories(.) goes to this question: CLion indexer does not resolve some includes in the project directory
You need to press ctrl + alt + shift + n.
And after pressing it a dialog box will appear to enter your variable/function name and click enter.
Tip: Filter the result for a better experience. Filter option is present on right side of the dialog box.
To get a quick peek of function/variable definition press ctrl + q while focusing on the variable or function.
To get the detailed or full definition of function press ctrl + shift + i while focusing on the variable or function.
I just looked at one of my more complicated teaching examples with multiple header/source files where this would come up.
What I see is that ctl-click (and the red/green arrows in the gutter) does work only in the same file. But I can right-click on a method from another file and choose to go to either the declaration (in header) or definition (in cpp).
The hotkeys to do this are not ctl-click. But you can remap hotkeys in IntelliJ ides, so you may be able to come up with hotkey combinations that don't seem too awkward to you.
What helped me was to run File > New CMake Project from Sources
Until that point, Ctrl+click in CLion would go to the definitions, but wouldn't find any usages.

Disable use of MacVim keyboard shortcuts

Is there any way to disable keyboard shortcuts in MacVim? I mean the shortcuts like Cmd + s for example, I want to convince myself to use things like :w, but I can't do so if I can save the file using Cmd + s, you get me?
But I of course, still want to use the GUI, so is there any way to disable these, without stoping using the MacVim GUI?
Thanks for your help. BTW I made a Google search and wasn't able to find an answer.
EDIT:
Following #ChrisJohnsen's suggestion, I have already tried the following with no success:
if has('gui_running')
macmenu File.Save key=<nop>
macmenu File.Save\ As\.\.\. key=<nop>
endif
EDIT 2:
I moved the error I'm getting over to this other question: When I try to run vim in command line I get Python errors
There is no simple way to disable all of the pre-defined Mac-style keyboard shortcuts, but you can definitely change/disable any of them. The important command is :macmenu (see :help :macmenu); it lets you set the Mac-specific properties of any Vim menu item (mostly Mac-specific keyboard shortcuts and Mac-specific actions (e.g. open/save dialog boxes, window manipulations, etc.)).
macmenu File.Save key=<nop>
macmenu File.Save\ All key=<nop>
macmenu File.Save\ As\.\.\. key=<nop>
The thing is that :macmenu commands are only effective if they are in your .gvimrc file.
If you do :e $VIMRUNTIME/menu.vim and search for macm, you will find the list of pre-defined shortcuts and actions. Copy the desired lines to you .gvimrc and replace key=<whatever> with key=<nop>. You can also wrap them in if has("gui_macvim") / endif if you need your .gvimrc to work on multiple platforms.
MacVim has only one "advantage" over plain Vim: it supports native Mac OS X shortcuts. If you don't want those shortcuts you might as well simply use plain Vim.
FWIW, when I switched from TextMate I, too, found after a while that these native shortcuts were an obstacle on my way to learning Vim. My solution was to focus my efforts on plain Vim. After a week in the terminal you should be able to completely disregard those shortcuts.
I'd advise you to take a little pause and think about doing things in a more appropriate order:
In the terminal, do $ vimtutor as many times as needed.
In the terminal again, use $ vim for simple tasks first then more complex tasks. There's a predictable productivity hit at the beginning but it will last only a few days/weeks.
Once you have reached your previous level of productivity, you can start to fly Vim full-time. At that point, using MacVim or GVim or plain $ vim should make no difference whatsoever.
Bonus points for not relying too much on plugins, other people's vimrcs or "distributions" like janus or spf13…

Move line Up/Down shortcut in Visual Studio 2012

In VS2010 I had a shortcut set up Alt+Up/Down to move lines of code up or down, just like I used to have in Eclipse in my Java days.
Now since Power Tools and macros (which is how I set up this shortcut in VS2010) are not available in VS2012, how do I get this to work?
I've seen somebody mentioned that Resharper can do this, but for the love of fire and water, I can't find the command names in the list of commands that can do that.
I have tried ReSharper_MoveUp/MoveDown and that does not move lines up/down:
This moves blocks of text up and down. I just want line-by-line up or down, no fancy logic there.
Before
After ALT+Up (when cursor is on WriteLine line) I would like to see this:
I have seen these threads: What's the equivalent for eclipse's ALT+UP/DOWN (move line) in Visual Studio?, Visual Studio: hotkeys to move line up/down and move through recent changes, but none of the suggested solutions work in VS2012.
Any other ideas?
UPD 7 Nov 2012: . Extensions are catching up with Visual Studio 2012. Now I know at least 3 extensions that provide this functionality:
MoveLine Extension. Link provided by Carl G
Move Line Extension with modifications to 2010 version. By gius
Productivity Power Tools 2012. Have not actually tried this, but this blog post states it does the line move up/down
UPD 15 Nov 2012: Just stumbled across another extension that claims it does what is required here. Have not tried it though: LineMan Extension
UPD 10 May 2015 Just installed VS2015 RC and this is built-in already:
For those who arrived on this question using Visual Studio 2013 or above, the feature is built right into the program. Just use AltUp and AltDown to move the line with your cursor—or the selected lines—up and down.
If you wish to rebind it in Tools > Options > Environment > Keyboard, the keys are Edit.MoveSelectedLinesUp and Edit.MoveSelectedLinesDown. You may need to remove your new combination from other existing keys first.
Update: huzzah, Productivity PowerTools VS2012 is now available and offers this functionality (along with another personal favorite, Tools.AddEndTokenAtTheEnd.)
MoveLine Extension (compatible with VS 2012; I had to manually restart my VS in order to see the commands in VS's keyboard shortcut tool.)
Install ReSharper.
Open Tools -> Options -> Environment -> Keyboard (as shown in a picture)
Find "ReSharper.ReSharper_MoveUp"
In "Use new shortcut in:" choose: "Text Editor"
Click in "Press shortcut keys:" and press your shortcut (for example Alt+ArrowUp)
Press "Assign" button
Same with with "ReSharper.ReSharper_MoveDown"
P.S. Works fine for single lines and multiple selected lines, but removes selection after moved 1 line. Hope there are way to move multiple lines multiple times in one selection.
If you have Resharper, then you can hit Ctrl + Shift + Alt + ↑ to move the current line up. or Ctrl + Shift + Alt + ↓ to move one line down.
This works in VS 2012 Premium with Visual Studio keyboard scheme in Resharper 7 (7.0.97.60 to
be precise).
Edit: This is mapped to 'ReSharper.ReSharper_MoveUp'/'MoveDown' commands.
In Visual Studio 2017(atleast) I have below
You can use Move Line Command extension.
Just follow formula349's comment:
I was able to get this working with 2012 as-is.
Rename the package to .zip and unzip all files into a folder. Edit the extension.vsixmanifest file and look for the SupportedProducts XML node. Change the Version="10.0" to Version="11.0".
Re-zip the folder contents and rename back to .vsix. Works great!
While a lot of people seem to be recommending misc. Visual Studio Extensions and Resharper, I would like to point out there is a native hotkey that accomplishes this goal. I came to this question trying to find the answer, as my Resharper replaced my default hotkeys with their MoveUp and MoveDown versions.
And while Resharper's hotkeys do move things up and down, they are not what the original poster are looking for, and they are not what I wanted. These hotkeys move methods and blocks of code, not individual lines.
Visual studio has two hotkey commands to move your selected lines upwards or downwards.
These hotkeys are:
Edit.MoveSelectedLinesDown
Edit.MoveSelectedLinesUp
I am using Visual Studio 2013 however, so I am unaware if these exist in an older version. If 2012 does not have these hotkeys then perhaps an extension is the only solution.
Either way, I had an issue locating the exact hotkey within visual studio's list and it took me a good while to find these, so I hope that my solution manages to help someone else in a similar situation to my own.
Shift+Del and then Ctrl+V
Shift+Del does the cut (same as Ctrl+X) operation on the current line on which cursor is positioned.
Then you can use Ctrl+V to paste it at any place you like.
Good thing is that you don't need to select the complete current line, just the cursor needs to be positioned on the line.
One downside to using this shortcut is that you won't be able to see the line moving ( up or down ) lively in front of your eyes.
ReSharper's move up and move down shortcuts are smart - instead of just moving the current line (which can easily result in broken code), it will move the current statement up and down in the list of statements that make up the method body. This is much more powerful than just moving a single line of code.
But this doesn't help you get your statement inside the if block. Here you need to do one of two things.
Firstly, move the statement above the if block, then use Ctrl+Shift+Alt+Right to push it down in scope. The statement will now be inside the if block, and you can use up and down to move it around in there. You can also use Ctrl+Shift+Alt+Left to pull it up in scope, outside of the if block.
Alternatively, you can put the text caret on the outside of the closing brace of the if block and use Ctrl+Shift+Alt+Down to move the brace down, stepping over following statements, including them inside the if block.
These keys can do a lot more than just move a single statement. If you put the text caret on a method or class declaration, Up and Down will move the entire method or class declaration up and down. If you put the text caret in the parameter list of a method, Left and Right will rearrange individual parameters (and then Alt+Enter can invoke the Change Signature refactoring).
More details in the help pages.

TextMate map key for next complete to command + spacebar

I found a lot of tutorials and forum questions around remapping key bindings in Textmate and for the most part I know what needs to be done as far as copy the KeyBindings file and then make the changes needed. More on what I am talking about here http://blog.macromates.com/2005/key-bindings-for-switchers/
I am interested in re-mapping the esc key for nextComplete to control + spacebar. The problem is I am having a hard time finding what the code is for the spacebar or if this is even supported.
I mainly do actionscript development in eclipes and code hinting dialogue is triggered by this key combo and I would like to have the same in Textmate. Hitting the esc key kind of sux. I thought I would get used to it but the fact is that it just kills the flow of typing the rest of your code.
I could use some help figuring out what he code is for the space bar. I know control key is the ^ symbol. I tested this by changing the keybinding to ^s and it remapped just fine.
I think this one can be done with the OS X gui:
System Preferences, Keyboard, Click Keyboard Shortcuts Tab
Click the little Plus, and choose Application: Textmate.app, Menu Title: Next Completion, Type Command Space (or Control Space) and click Add and that should work. You might want to remove conflicting shortcuts - possibly spotlight?
For future reference, I used Key Codes to find the key for space is: \UF20