User-defined keyboard shortcut to delimit selected text with user-defined text delimiters - rstudio

Very often, I have to type the following:
{\texttt{something}}
Is there some possibility of creating a keyboard shortcut that, after having selected something, added {\texttt{}} to something?

Yes, you can do this with an RStudio Add-in. These are relatively easy to build since they're just R packages containing regular R code, and you can add keyboard bindings for them to set up your own hotkeys. Instructions here for making addins:
https://rstudio.github.io/rstudioaddins/
Within your add-in you can use the rstudioapi package's document manipulation methods to locate the cursor/selected text and replace the range with the same value.
https://rstudio.github.io/rstudioapi/reference/rstudio-documents.html

Related

In cloud9 IDE, text in terminal cannot correctly be selected to copy, the position is actually on the left

This is where I choose:
Actually, I select this:
How to fix this, or it's just a bug?
There's a couple things that could be at play. Cloud9 uses the Ace Editor which is not a standard text box. You NEED to use a monospaced font with Ace as otherwise the text selections might not line up with what's being selected (since this is built on an HTML5 canvas).
Additionally, Cloud9 does use a nonstandard clipboard in order to facilitate Ace. Make sure you copy with Ctrl + c and paste with Ctrl + v as otherwise you may use the system's default clipboard (so an older block of text may be used instead).

Disable chordal hotkeys so I can use a custom hotkey

How can I disable all default shortcuts that use key chords? I am trying to add custom shortcuts, but they do not work because there are dozens of shortcuts that use the keys that I want to use as 'key chords.'
I suppose I could find which ones use my keys and go through one by one to remove them, but that would be extremely tedious, since I can only view the command that use it in the 'used by' dropdown, which only shows a few commands at once. I would have to write each of those down, search for them individually, and then remove all the shortcut assignments associated with them.
The shortcuts I intend to use are "ctrl + R" and "ctrl + T", and map them to VS's 'Comment out selected lines' and 'Uncomment out selected lines' functions.
You can go ahead and assign CtrlR to Edit.CommentSelection. Under "Use new shortcut in:", select Text Editor. Visual Studio will automatically remove all hotkey key sequences that begin with CtrlR in the Text Editor context.
I had a similar problem (at VS 2017 (Left Arrow) was pressed. Waiting for second key of chord) and found Resharper's experimental Shortcuts Live View feature invaluable in reporting what actual shortcut had been assigned and are currently active. With that you can identify where a chordal kay has been assigned, and remove it. If you're using the latest Resharper, press the left Ctrl key three times in text editor.

Reformatting code in text mate to established code conventions - Visual studio's ctrl K+D equivalent on Text Mate

Can anyone tell me if there's a quick way to format your code in Text Mate, similar to pressing ctrl K+D in Visual studio?
Thanks!
Edit by Damien_The_Unbeliever:
For those not familiar with Ctrl K+D, it doesn't just indent code - it reformats it using the generally established formatting conventions in the editor - it may replace spaces with tabs or vice-versa for the indentation, ensure code is consistently indented, move braces to separate lines, etc.
TextMate reindenting and reformatting varies a little depending on the language you're using.
You can generally use the Text menu, that depending wether you have an active selection or not it will show you different commands under it. For example, if you have selected a section of code, there will be a Indent Selection menu item. If you have no active selection, it will be Indent Line.
To have this working properly, be sure to select the current language, if it isn't assigned yet (like on unsaved documents). If you're working with HTML, it will simply indent the lines depending on what's above it. It will keep line breaks intact.
If you need something to break out tags on new lines and properly format the document, you should use the Tidy command that is found in the Bundles menu, under HTML (or simply by using the shortcut CTRL+SHIFT+H. If you have a selection active at the moment that you use it, it will simply reindent that section. If instead you have no selection, it will properly reformat the whole document, including checking for tag validity and other errors.
The Bundles for other language have similar commands, like XML (still Tidy) and Javascript (that has a Reformat Document command).
As an ending note, I simply suggest to look into the Bundles menu; there are many little gems in it. ;)
Did you look in the menu bar? Under Text you have a couple of Reformat… entries that may fit your needs.
Beside these native features, some bundles — like the JavaScript one — have custom Reformat… commands : click on the little cog button at the bottom and explore your current language's bundle's content.

Textmate tab and de-tab selected block

Recently switched to Textmate on Mac for coding. On PC when ever I want to tab in or out a block of code I just highlight and press tab or shift+tab to move it in our out. It's very useful when you are adding an extra loop or conditional statement to a block of code to keep everything tidy and neatly indented.
On Textmate however when I try this it just replaces my selected text with a tab. So is there a way to do tab and de-tab lines of code in textmate?
Indent: Alt+Tab
Un-Indent: Shift+Alt+Tab
the hotkey is command-left bracket to move left and command-right bracket to move right
(the buttons next to 'p')
heres a link to more hotkeys and such
http://projects.serenity.de/textmate/tutorials/basics/
You can use Shift+Tab to decrease indent; You just need to make and assign a macro. You can reuse this technique to accomplish a great many things.
Enter some text, and intend them, this is mostly for feedback.
Click the Record Macro Button
Use ⇧+⌥+⇥ (aka; Shift + Option + Tab) to decrease the indentation.
Click the record button to stop recording the macro.
Use the Edit menu or ⌃+⌘+M to save your macro;
Saving will prompt you to create a new bundle*, or add your macro to an existing bundle.
Add a Key Equivalent by clicking in the field and pressing ⇧+⇥
Your bundle-macro should look like the one below, simply Save and you're done! TextMate will now decrease indent on ⇧+⇥
*: (as noted by u/PatrickT) Sadly the create new bundle functionality has not yet been implemented, and you must choose to add to an existing bundle. You can still create a bundle via Bundles -> Edit Bundles then Command + N.
As an alternative, you can change the keybindings, see Link
Here is what I did:
Install Link
Go to File -> Open -> User Key Bindings, this will create/edit ~/Libary/KeyBindings/DefaultKeyBinding.dict
Add a binding, for the action enter shiftRight: (indent) manually (this is a TextMate specific action and not in the pre-populated actions list)
Choose a shortcut, I used cmd+alt+right
Do the same for the action shiftLeft: (un-indent, I used cmd+alt+left)
Save and then restart TextMate
I used a shortcut with arrow keys as my right hand is already on the arrow keys when I am selecting multiple lines, so this is a good fit.
The reason why I did it was because I have a german keyboard and alt+tab/alt+shift+tab don't work for me since I am using Witch for app-switching using these exact shortcuts.
EDIT: cmd+alt+left/right don't work when you have multiple tabs open, as they are used for navigate to next or previous tab in TextMate... seems this cannot be changed or overridden (I tried Setting Shortcut Keys in Textmate). Looking for an alternative shortcut now.

How to free up a key combination in visual studio?

I want to assign a hotkey to a function, but the keys are already used in some other functions' combination.
How can I easely remove this hotkey from all these entries so I free it up and am able to asign it to the function I want?
I am using Visual Studio C# Express 2008, but you can go into Tools/Options/Environment/Keyboard. If you put your cursor in the Press shortcut keys field and type the key you want to remap, it will show you what commands use that key and let you clear or change the assignments.
Go assign the command a shortcut (Tools > Options > Environment > Keyboard). If it's already taken, that will display, but it won't keep you from assigning it to something else (which removes the shortcut from the original task).
Some key shortcuts are layered. So for instance while editing text the Text Editor keys override the Global ones. If you set your shortcut for the priority layer you can ignore whatever is assigned on a lower layer. So for text editing keys assign them under Text Editing and not Global to avoid them being ignored.
Repeat this for as many layers that you run into. I do this part incrementally only if there is some other context I want that same shortcut for.

Resources