Thanks to this great plugin : Origami
I am able to obtain the following layout :
How could I save this view to call it from the view/layout menu ?
You can get the layout data from the Auto Save Session.sublime-session file, under the "layout": key. This file is in standard JSON format, and can be opened in ST2 just fine (select View->Syntax->JavaScript->JSON for syntax highlighting if you want). For OSX, this file is (probably, I'm not in front of my Mac at the moment to verify) located in ~/Library/Application Support/Sublime Text 2/Settings - it should be in the same directory as the Packages/ folder where plugins etc. are stored.
So, to make a keyboard shortcut, set up your Origami layout, then perhaps move some files around, search for some text, anything to update the Auto Save Session.sublime-session file. It may already have updated after changing your layout, so check the time stamp to make sure. Then, open the file and search for layout. Copy the contents of the key - the "cells":, "cols": and "rows": keys inside the curly braces, as well as the curly braces themselves. Then, open Sublime Text 2->Preferences->Key Bindings-User and add the following to it (include the square brackets if you don't have anything in this file yet, omit them if you already do. If you already do, make sure to add a comma , after the last curly brace of the item before):
[
{
"keys": ["alt+shift+o"],
"command": "set_layout",
"args":
|
}
]
Set your cursor where I put the | character after "args": (make sure you delete the |) and paste in the contents of the "layout": key from Auto Save Session.sublime-session you copied earlier. Save the file, and you should now have a keyboard shortcut AltShiftO (O for Origami) that will restore your layout for you. If you have more than one layout you'd like to save, repeat the steps above, and just change the "keys": value to another key combination. If you have a lot of plugins, I highly recommend #skuroda's FindKeyConflicts plugin, which is available through Package Control under the same name. With it you can get a full list of all current key mappings, so if you're planning on assigning a new one you can check to see if it's already taken. The plugin does more, as well, so if you're a plugin dev, or just a customization/macro geek like me, it's really quite useful.
As a caveat, with the complexity of the layout you displayed above, the "layout": key is going to be quite large and complex, and is made larger by the fact that each value in the "cells":, "cols": and "rows": keys is on its own line. I don't know enough regex to clean everything up automatically, but I'm sure it can be done.
Related
I have a line of code I want to mass-paste into a file.
The line of code is "enchantment.level.x": "string". I want to paste this multiple times into my program, but each time I paste the line, I want x to increase by one.
So if line 2000 is "enchantment.level.1": "I", I would want line 2001 to be "enchantment.level.2": "I" (but I would change "I" to "II" manually).
Is there a way I can achieve this?
Thank you
I don't think there is any way to do what you want on each paste. But if you make all your pastes first then you can #rioV8's or my extension to accomplish the same goal.
The extension is Find and Transform that I wrote. It supports replacing with the match number (or index). Put this keybinding into your keybindings.json:
{
"key": "alt+m",
"command": "findInCurrentFile",
"args": {
"find": "(?<=enchantment\\.level\\.)x", // match the "x"
"replace": "${matchNumber}", // replace with the matchNumber
"isRegex": true
}
}
You could make that into a named setting too if you don't want to run it from the Command Palette.
${matchNumber} starts at 1. ${matchIndex} starts at 0.
You can use the extension Regex Text Generator to generate the new numbers.
Paste the line as often as you like
Select the number on all the lines with Multiple Cursors
use the extension and use (.*) for match regex and {{=i+1}} for generator expression
I have two dictionaries: ru_RU and en_US. How can I use it together in Sublime Text 3 spell check? Is it possible?
This is currently not possible. It has been mentioned in the official issues list for ST3 - see this issue for details.
I have this working for me using this steps.
Download your dictionary (e.g. from GitHub or following the README.md recipe in this respository).
Create a folder in your Sublime Text 3 config (e.g. "Language - Spanish"), this will be the name shown in the ST menu, and move the dictionary inside this folder.
~/.config/sublime-text-3/Packages/Language - Spanish
Be sure that spell checking is active and the dictionaries as well in your preference settings:
"spell_check": true,
"dictionary": [
"Packages/Language - English/en_US.dic",
"Packages/Language - Spanish/Spanish.dic"
],
Now you can switch the current spell checking:
View > Dictionary > Language - Spanish > Spanish
For me was solved following this instructions:
https://www.sublimetext.com/docs/3/spell_checking.html
I've downloaded the dict files from:
https://github.com/SublimeText/Dictionaries
Then I simply copy the UTF-8 encoded dictionary files (in my case Spanish) into Packages/Language - Spanish/ (You can access it from Preferences/Browse Packages).
Then activate by adding this line to user setting's
"spell_check": true,
Or by View/Spell Check menu.
You can select the dictionary from the View/Dictionary menu.
It would not be an easy task to create the affix for a "merged" language, like 2 dicts working at once. In my case I'd love some Spanglish dict... have to work on it.
I'm trying to figure out a hotkey at work. I just got this job and I am using a Mac for more or less the first time in my life.
Back home on my Laptop, when using Eclipse, I seem to remember there being a single hotkey which would both:
Add a ; to the end of my current line (no matter where the caret was within said line)
Place my cursor at the beginning of a new line, with the same indentation level as the line I had just added a semicolon to
Does anybody know if this was an Eclipse-specific hotkey, or know of a way to replicate said hotkey in Sublime Text 2?
Best solution for this is recording a macro on Sublime Text and then assigning it to a keyboard shortcut. Follow these steps:
Create a line such as alert('hello') and leave the cursor right
after letter 'o'.
Then go to Tools > Record a Macro to start recording.
Press Command+→ to go to the end of line.
Press ; and hit Enter
Stop recording the macro by going to Tools > Stop Recording Macro
You can now test your macro by Tools > Playback Macro (optional)
Save your macro by going to Tools > Save Macro (ex: EndOfLine.sublime-macro)
Create a shortcut by adding this between the square brackets in your
in your Preferences > Key Bindings - User file:
{
"keys": ["super+;"], "command": "run_macro_file", "args": {"file": "Packages/User/EndOfLine.sublime-macro"}
}
Now, every time you hit Command+;, it will
magically place the semicolon at the end of current line and move the cursor to the next line.
Happy coding!
After reading your question about three times, I finally realized that you were looking for one hotkey to perform both operations. Whoops.
Your request sounds like the Ctrl+Shift+; hotkey of the Smart Semicolon Eclipse plugin. While adding semicolons of a genius-level IQ would probably require an entirely new Sublime Text 2 plugin, you can easily create a smart semicolon–esque key binding with Sublime Text's Macros. I actually didn't know about them until now!
In this case, recording the macro yourself is actually the fastest way to create it, rather than copying and pasting a new file (and now you'll have the experience for making more). First, open a new file and type in your favorite garbage line:
Lord Vetinari's cat|
Then move the caret to anywhere within the line:
Lord Veti|nari's cat
Now, press Ctrl+Q, the hotkey for Tools -> Record Macro. If the status bar is enabled, it will notify you that it is "Starting to record [a] macro". Press End (if you don't have an End key, skip to below), then ;, then Enter. Finally, press Ctrl+Q again to stop recording. When you do, the status bar will display "Stopped recording macro". Check that your macro is working by hitting Ctrl+Shift+Q on a code segment of your choosing.
Just pressing Enter will adjust indentation on the next line accordingly as long as the "auto_indent" setting is set to true. See Preferences -> Settings – Default, line 59.
When you're satisfied, save your new macro with Tools -> Save Macro.... I saved mine as Packages/User/smart-semicolon.sublime-macro. My file looked something like this; feel free to copy it if you can't or won't make the macro manually:
[
{
"args":
{
"extend": false,
"to": "eol"
},
"command": "move_to"
},
{
"args":
{
"characters": ";"
},
"command": "insert"
},
{
"args":
{
"characters": "\n"
},
"command": "insert"
}
]
"extend": false, just means that the macro won't add any text to the working selection. Read more about the options for commands at the Unofficial Docs Commands Page.
Now that you have your macro, we can give it a custom key binding. Add the following lines to your Preferences -> Key Bindings – User file:
{ "keys": ["ctrl+shift+;"], "command": "run_macro_file", "args": {"file": "Packages/User/smart-semicolon.sublime-macro"}, "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.java" }
]
},
Replace Ctrl+Shift+; with whatever key binding you prefer, save your file, and give it a shot. The "context" array restricts the key binding to Java files (see the Unofficial Docs Key Bindings page for more information on contexts); if you want the key binding to be active everywhere, use this line instead:
{ "keys": ["ctrl+shift+;"], "command": "run_macro_file", "args": {"file": "Packages/User/smart-semicolon.sublime-macro"} },
This NetTuts+ article has much more information on macros and binding them to keys; I referenced it often. This UserEcho post looks like it has more information on making the insertion more extensible.
You can also use a ready-made sublime package built for this purpose: AppendSemiColon
You can use package control to install it, just search for "AppendSemiColon".
Place a semicolon at the end of the cursor's current line(s) by pressing:
Command+; on OS X
Ctrl+; on Windows and Linux
and
You can also automatically go to the next line at the same time like this:
Command+Shift+; on OS X
Ctrl+Shift+; on Windows and Linux
I've been using this package for a while now, and it works great.
UPDATE:
As the author mentioned in a comment, you can now also change the default hotkeys if you like (personally, I love the defaults). As an example, just change:
[
{ "keys": ["ctrl+;"], "command": "append_semi_colon" },
{ "keys": ["ctrl+shift+;"], "command": "append_semi_colon", "args": {"enter_new_line": "true"} }
]
in your sublime-keymap to use whatever keys you want.
I tested the latest version, and this feature too works fine. There was a bug where extra semicolons were being appended incorrectly upon extra hotkey presses - this minor annoyance has been fixed too. Thanks, MauriceZ/mzee99!
Ctrl+Enter will create a new line with the same level of indentation.
I could not find anything like the Ctrl+A you mentioned
I'm on Sublime Text 3 ... inspired by your post, I've added the following to my .sublime-keymap:
{ "keys": ["ctrl+enter"], "command": "run_macro_file", "args": {"file": "Packages/User/endOfLine.sublime-macro"} },
I'm amazed at how much time this saves.
#Felipe covered the second point. You can mimic the behavior of the first with a simple macro or plugin. I say or because you didn't describe the cursor position after you hit the key combination. Does it move the cursor to the next line? Does it insert a new line? I think you get the idea.
I'm pretty sure eclipse works on OS X as well as windows, so if you are more comfortable with that, why not use it (unless your job requires ST of course)? Most of the key bindings are probably the same/similar (well it's probably command rather than control for shortcuts).
http://www.eclipse.org/downloads/?osType=macosx
If you continue using ST, it's probably worthwhile to learn the basics of plugins. A lot can be built so you have the same behavior as other editors, it just takes some extra effort (through creating the plugin or finding a plugin that does it) up front.
I cannot figure out how to do rectangular selection in Sublime Text 2 using only keyboard. What I seem to always come across is to do ctrl-shift-up or -down (which I assume mean arrow keys), as laid out here: https://stackoverflow.com/a/13796939/1022967
But when I try to use that, I must send an OS-level command, because what happens is that my window slowly recedes and shows me all of the open apps/windows I have going on my Mac (I forget what that's called -- like a dashboard of what I have running). This happens when I use this key chord in apps outside of Sublime Text 2 as well.
Do I have something misconfigured? Could I have alternate key chords to do this?
You do not need to change the Sublime Text key bindings.
Simply go to System Preferences -> Keyboard -> Keyboard Shortcuts, click on Mission Control, and uncheck the boxes next to Mission Control and Application windows, then you will be able to use the default keys for column selection. This is a quick and easy fix, especially if you are not using Mission Control.
Go to the menu:
Sublime Text -> Preferences -> Key Bindings - Default
What are you looking for is:
{ "keys": ["ctrl+shift+up"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["ctrl+shift+down"], "command": "select_lines", "args": {"forward": true} },
The actual keys might be different, you need to find "select_lines" commands with these arguments.
If you want to change the keys, you need to open Key Bindings - User in the menu, then copy-paste and edit these lines according to your needs.
You will notice the change immediately after saving the file, if it has proper format (JSON), otherwise you'll get an error message.
FWIW, on my MacBook Pro running OS X 10.8.5, I set the keyboard bindings for column selection mode in my "Key Bindings - User" file in Sublime. Setting the key binding at the Mac System level in System Preferences > Keyboard > Keyboard Shortcuts > Application Shortcuts doesn't work.
After looking through the Sublime "Key Bindings - Default" preferences file and my Mac system preferences to make sure I wouldn't break an existing key binding, I went with Ctrl+Alt+Shift+Up and Ctrl+Alt+Shift+Down for column selection.
Here's what I have in my Sublime "Key Bindings - User" file:
{ "keys": ["ctrl+alt+shift+up"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["ctrl+alt+shift+down"], "command": "select_lines", "args": {"forward": true} }
Hope this helps.
For Mac, you need to use the command key, not control. So vertical select would be Command-Shift-Up/Down, horizontal is Command-Shift-Right/left
Both of the selection types go from where your cursor is currently so make sure your cursor is in the correct place you want it.
Simplest solution, don't need to touch the bindings file.
Hold down ALT key and make a selection using touchpad in 'clicked' state. It only selects the column.
Right now I have the following mapping to select lines forward:
{ "keys": ["ctrl+alt+down"] , "command": "select_lines", "args": {"forward": true} }
I'd like ctrl+alt+up to simply undo the last ctrl+alt+down. Soft undo doesn't quite work. If you select multiple lines quickly then the undo de-selects them all, instead of just the last one selected.
If there's no out-of-the-box way to do this then maybe I could map ctrl+alt+up to a set of keystrokes that deselects the current line and moves the cursor up one?
this behavior bugged me a lot too, so I've just went and wrote this: https://github.com/kizu/undo_select_lines#readme
This overrides the “soft undo” action in certain context, so it would actually “undo” the single select_lines.
The only downside is that there won’t be redo and the history would be a bit dirty, but whatever while it works.
So, if you didn’t override soft undo in your key bindings, installing this command through git in your Packages:
git clone git://github.com/kizu/undo_select_lines.git
Or download it there.
would fix this problem for you. Otherwise, look at how it’s implemented in the source, so you should replace the keybindings for your “soft undo”.