In Netbeans its possible to create a macro for selecting a word and copying it to clipboard
I wonder if its possible with Sublime Text 2 ?
Thanks for any help.
Edit : I understand that this is possible with a plugin. But I dont know Python, if any Python developers can create a plugin for this, it would be awesome! :)
You can easily do this with two keystrokes - CtrlD,CtrlC.
After some searching I managed to find its solution.
And the solution is a plugin.
In the menu, go to Tools -> New Plugin ->
For select the text and copy, this is the plugin content
import sublime, sublime_plugin
class SelectAndCopyCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("find_under_expand")
self.window.run_command("markSelection")
self.window.run_command("copy")
And I saved it as select_and_copy.py
For the select and paste, this is the plugin content
import sublime, sublime_plugin
class SelectAndPasteCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("find_under_expand")
self.window.run_command("markSelection")
self.window.run_command("paste")
And I saved it as select_and_paste.py
And the last thing you need to do is to bind this to a keyevent.
For this, in the menu, go to - Preferences -> Key Bindings - User
I have this content.
[
{ "keys": ["alt+`"], "command": "select_and_copy" },
{ "keys": ["alt+1"], "command": "select_and_paste" }
]
So, thats it, hope this helps for someone ! :)
You can do this using a sublime macro. Create a file named select-copy.sublime-macro in your Package folder:
[
{ "command": "find_under_expand" },
{ "command": "copy" }
]
And add the following entry to your key bindings file:
{
"keys": ["ctrl+up"],
"command": "run_macro_file",
"args": {"file": "res://Packages/User/select-copy.sublime-macro" }
},
And that's it, no plugin needed !
You can also record the macro if you don't want to dive into the config files to find the commands that you need:
Tool > Record Macro
Do some magic here.
Tool > Stop Recording Macro
Tool > Save Macro...
Related
I'm using SublimeText3 and wanted to know if there is an option (package) which can be used to
Find references within the file.
Find references within the folder.
Goto definition.
I found a command called Goto->Reference, but this does not work for the current file and seems buggy.
I also found a package called wordhighlighter which is very useful.https://github.com/SublimeText/WordHighlight. I want to use this to navigate among highlighted words. Is there any keyboard shortcut to achieve this? There is an option to expand and collapse the selection but thats about it.
For someone else who comes up with the same issue, I found the answer here
How to navigate between instances of selected text in Sublime Text 3?
{ "keys": ["alt+super+g"], "command": "find_under" },
{ "keys": ["shift+alt+super+g"], "command": "find_under_prev" },
I recently upgraded the version, there is a need to transplant function, but this feature I do not know because it is installed what plug-in? So now need to manually add, I know you can use shortcut keys binding, but my shortcut keys are occupied, and if you continue to set up but it is not convenient to use.
{ "keys": ["ctrl+*+*"], "command": "save_all" }
demo
needs improvement
Find the Default.sublime-package file,
rename Default.sublime-package to a zip file and unzip.
There we find the file Tab Context.sublime-menu and Context.sublime-menu
Add {"command": "save_all", "caption": "Save All"},
The effect is as follows:
Tab Context
Context
I am running two Sublime windows at the same time. In one window I'm getting code to update the other one. Both are using the same color pattern, so I am confused between them.
My question is, is there a way to distinguish in between the windows? Making color-scheme different, or something like that?
This can be done with a very simple plugin and key binding. First, select Tools -> Developer -> New Plugin... and replace the contents with the following:
import sublime_plugin
class ChangeWindowColorSchemeCommand(sublime_plugin.WindowCommand):
def run(self):
for view in self.window.views():
view.settings().set("color_scheme",
"Packages/Color Scheme - Default/Cobalt.tmTheme")
You should change "Packages/Color Scheme - Default/Cobalt.tmTheme" to whichever color scheme you'd like to use in the window. Save the file as Packages/User/change_window_color_scheme.py - if you just go to File -> Save it should automagically open to Packages/User.
Next, create a new key binding by selecting Preferences -> Key Bindings-User and adding the following if the file is empty:
[
{ "keys": ["ctrl+alt+shift+c", "s"], "command": "change_window_color_scheme" }
]
If you already have some custom key bindings, add the following on the line following the opening square bracket [:
{ "keys": ["ctrl+alt+shift+c", "s"], "command": "change_window_color_scheme" },
Save the file, and everything should be all set. Select the window you'd like to change the color scheme for, then hit CtrlAltShiftC, S - meaning you hit CtrlAltShiftC, release them, and hit S. You can change the key binding if you wish, of course.
Is it possible to play a saved macro using the command palette?
I know that it is possible to assign a keyboard shortcut to a macro but that is another thing to remember and not very feasible when you have more than a few macros.
Yes, it is possible. You need to save your macro to a file at ../sublime-text-3/Packages/User/YOUR_MACRO_NAME.sublime-macro. Then add the following code to file ../sublime-text-3/Packages/User/Default.sublime-commands:
[
{
"caption": "ADD TEXT TO BE DISPLAYED ON COMMAND PALETTE",
"command": "run_macro_file",
"args":
{
"file": "res://Packages/User/YOUR_MACRO_NAME.sublime-macro"
}
}
]
I haven't been able to run a macro from the command palette but I have found the Macroptimize package to be helpful in running my macros - one hotkey gives you a list of defined macros to choose from. Not quite what you're looking for but perhaps it will be helpful.
I am trying to use the package "Alternate VIM Navigation" in ST3 on Linux Ubuntu, but the alt+i and alt+h keybindings bring up the find and help menus rather than their movement keybindings:
{ "keys": ["alt+i"], "command": "move", "args": {"by": "lines", "forward": false}},
{ "keys": ["alt+h"], "command": "move_to", "args": {"to": "bol", "forward": true}},
I have been able to disable the alt key from displaying the application menubar using CompizConfig Settings Manager, but the alt+i still brings up the find menu (and likewise for alt+h).
I have looked in many places for an answer to this, but have found nothing that works for ST3 in Linux. Here are some related answers for OSX and Windows, and an answer in Ubuntu that suggests the CompizConfig Settings Manager:
https://askubuntu.com/questions/553687/change-or-disable-modifier-key-alt-which-activates-the-application-menubar
Change behavior of Alt key in Sublime Text 2
Stop Alt key bringing up the menu in Sublime Text 2
Any solution to this in ST3 for Linux would be much appreciated!
This worked for me:
Open Sublime's packages directory by going to Preferences > Browse Packages.
Open the User directory and create a file called Main.sublime-menu
Paste the following in:
[
{
"caption": "Help",
"mnemonic": "",
"id": "help"
}
]
Save the file and enjoy!
I found a bit of a strange workaround...
I have a sublime text package called "SubRed" which has a file "Main.sublime-menu" (it's in .config/sublime-text-3/Packages/SubRed - I manually installed the package).
To disable the menubar all I have to do is:
ctrl+shift+p view: toggle menu (which does not disable the menu by
itself for some reason),
open the Main.sublime-menu file in sublime,
save it.
Then voila, the menu bar is gone and I can finally use my Alternate Vim package key bindings without conflicting with the alt+[menubar mnemonic].
To get the menu bar back if needed, just simply do ctrl+shift+p view: toggle menu.
If anyone could suggest a better solution based on this (which doesn't involve a random 3rd party package) that would be much appreciated!
The ideal solution would be to not have to disable the menubar, but get it to work like windows where user or package defined st3 keybindings take precedence over default or system bindings. So if "alt+i" is defined by the package as "move up a line", then it no longer opens the "Find" menu, but actually (eureka!) moves up a line! But opening the "Find" menu is still possible with "alt, i" in sequence.