Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After reading your question about three times, I finally realized that you were looking for <em>one</em> hotkey to perform both operations. Whoops.</p> <p>Your request sounds like the <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>;</kbd> hotkey of the <a href="https://code.google.com/p/smartsemicolon/" rel="nofollow noreferrer">Smart Semicolon</a> Eclipse plugin. While adding <a href="https://stackoverflow.com/questions/7187477/vim-smart-insert-semicolon">semicolons of a genius-level IQ</a> would probably require an entirely new Sublime Text 2 plugin, you can easily create a smart semicolon–esque key binding with Sublime Text's <a href="https://sublime-text-unofficial-documentation.readthedocs.org/en/latest/extensibility/macros.html" rel="nofollow noreferrer">Macros</a>. I actually didn't know about them until now!</p> <p>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:</p> <pre><code>Lord Vetinari's cat| </code></pre> <p>Then move the caret to anywhere within the line:</p> <pre><code>Lord Veti|nari's cat </code></pre> <p>Now, press <kbd>Ctrl</kbd>+<kbd>Q</kbd>, the hotkey for <code>Tools -&gt; Record Macro</code>. If the status bar is enabled, it will notify you that it is "Starting to record [a] macro". Press <kbd>End</kbd> (if you don't have an <kbd>End</kbd> key, skip to below), then <kbd>;</kbd>, then <kbd>Enter</kbd>. Finally, press <kbd>Ctrl</kbd>+<kbd>Q</kbd> again to stop recording. When you do, the status bar will display "Stopped recording macro". Check that your macro is working by hitting <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Q</kbd> on a code segment of your choosing.</p> <p>Just pressing <kbd>Enter</kbd> will adjust indentation on the next line accordingly as long as the <code>"auto_indent"</code> setting is set to <code>true</code>. See <code>Preferences -&gt; Settings – Default</code>, line 59. </p> <p>When you're satisfied, save your new macro with <code>Tools -&gt; Save Macro...</code>. I saved mine as <code>Packages/User/smart-semicolon.sublime-macro</code>. My file looked something like this; feel free to copy it if you can't or won't make the macro manually:</p> <pre class="lang-json prettyprint-override"><code>[ { "args": { "extend": false, "to": "eol" }, "command": "move_to" }, { "args": { "characters": ";" }, "command": "insert" }, { "args": { "characters": "\n" }, "command": "insert" } ] </code></pre> <p><code>"extend": false,</code> just means that the macro won't add any text to the working selection. Read more about the options for commands at the <a href="https://sublime-text-unofficial-documentation.readthedocs.org/en/latest/reference/commands.html" rel="nofollow noreferrer">Unofficial Docs Commands Page</a>.</p> <p>Now that you have your macro, we can give it a custom key binding. Add the following lines to your <code>Preferences -&gt; Key Bindings – User</code> file:</p> <pre class="lang-json prettyprint-override"><code> { "keys": ["ctrl+shift+;"], "command": "run_macro_file", "args": {"file": "Packages/User/smart-semicolon.sublime-macro"}, "context": [ { "key": "selector", "operator": "equal", "operand": "source.java" } ] }, </code></pre> <p>Replace <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>;</kbd> with whatever key binding you prefer, save your file, and give it a shot. The <code>"context"</code> array restricts the key binding to Java files (see <a href="https://sublime-text-unofficial-documentation.readthedocs.org/en/latest/reference/key_bindings.html" rel="nofollow noreferrer">the Unofficial Docs Key Bindings</a> page for more information on contexts); if you want the key binding to be active everywhere, use this line instead:</p> <pre class="lang-json prettyprint-override"><code> { "keys": ["ctrl+shift+;"], "command": "run_macro_file", "args": {"file": "Packages/User/smart-semicolon.sublime-macro"} }, </code></pre> <p>This <a href="http://webdesign.tutsplus.com/tutorials/workflow-tutorials/quick-tip-banish-repetitive-tasks-with-sublime-text-2-macros/" rel="nofollow noreferrer">NetTuts+ article</a> has <em>much</em> more information on macros and binding them to keys; I referenced it often. This <a href="http://sublimetext.userecho.com/topic/90524-add-semicolon-and-newline/" rel="nofollow noreferrer">UserEcho post</a> looks like it has more information on making the insertion more extensible.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload