Sublime Forum

Requesting tips for a few new user woes: new windows, macros, bookmarks

#1

HI. . . I just started using Sublime yesterday. I really like it though I’m still in the “considering” stage. I’m a 20+ year emacs user and I do expect to change the way I do certain things (otherwise I wouldn’t even be here). However, there are a few things that I’d prefer to keep my expectations about. I’d appreciate any suggestions.

  1. New windows I’ve seen a good number of questions about getting ST to open a folder in the same window (e.g., unanswered #1, unanswered #2, suggestion to use projects, opening in new window was recently changed functionality). This did lead me to understanding projects which is cool but I’m with one of these users here in that many times the folders I want to open are temporary. I don’t want to have to create a project when I may only be jumping into this directory for the day. Is there a way I can just open a new folder in the current window and have the sidebar populated with the files? Any other suggestions?

  2. Macros My first macro didn’t go so well because when I clicked Save nothing happened. After some investigation I believe it was because whatever I recorded wasn’t something that was recordable (in my case, I think it was opening a folder (regarding my other issue, above) so probably it didn’t record because a new window had opened). Can macros playback things that they can’t record? I mean, can they be edited by hand to do search and replace or other things that are not supported by the macro recorder? A side question on this: is this the best/most complete reference for what is available for putting in a macro?

  3. Home row cursor movement I can’t get used to having to use the arrow keys to move the cursor. I assume key binding would be the best way to get that but is there an easy way to know if a key binding that I want to use is already being used for something else?

Thanks for your help!
Andy

0 Likes

#2

From the command line, subl -a <somedir> will add <somedir> to the current window whether or not that window contains a project, while from within Sublime Project > Add Folder to Project does the same thing (but File > Open Folder opens it in a new window).

Note that although this appears to be project related, it works even in windows without an associated project. A good way to look at this is that every window has some sort of inherent project-like information associated with it, but not all windows have that data persisted to disk in a sublime-project file.

To do something like this from the context menu of a file explorer or such, you need to know how to make your OS run a different command than it’s using currently, but you can take advantage of the same command line parameter as above to pull this off.

Macros can only contain TextCommand commands, which are commands that directly modify the state of a buffer (contents or selections). As such although you can in fact hand modify a macro (and I tend to just create mine that way directly), if you put any other commands in there they will be ignored.

That said, with the plugin system depending on what it is you want to do you can perhaps create a TextCommand that takes whatever actions you want to take, such as manually invoking commands that would otherwise be inaccessible.

Some things, such as Find and Replace, don’t have explicit commands (except to open or hide the panel), so for something like that you may want to look at RegReplace/

A better reference to the command list is available in the Unofficial Documentation. You can also look at things like the default key bindings or use sublime.log_commands(True) in the console to see what commands exist or what commands bound to keys and menu items do.

One way is to open the Sublime console with View > Show Console and then enter sublime.log_commands(True). This makes Sublime log commands as it executes them, so if you press a key and you see output you know that it’s currently doing something. Additionally you can also look at the default key bindings to see what is available; when you select Preferences > Key Bindings from the menu, the left pane in the window is the default bindings for your platform.

Any bindings you make in your User bindings (the right hand pane in the above window) supercede all other bindings that might appear on that key, so you can more or less rebind things with impunity. In such a case you may remove default bindings to commands, but you can always get at them from the menu or the command palette (or add them there if they’re missing) as well as binding them to other more friendly keys.

1 Like

#3

Thank you, @OdatNurd! That was 100% coverage and was really helpful esp. with respect to projects and adding folders to the current window. I’ll forge ahead with all this new information. Greatly appreciated!

Andy

0 Likes

#4

Keep in mind that a window and a project start out the same; a window only becomes a project when you save it as one.

In addition to what @OdatNurd mentioned above, you can also drag & drop files/folders onto a window to open them. See also Keyboard shortcut or method to remove a folder from project.

Yes, Sublime creates a *.sublime-macro file that is just a JSON list of commands & arguments. (see also command docs and default keybindings to correlate)

In addition to what @OdatNurd said above, here are the current docs for keybinding. Note that Preferences -> Key bindings will only show the built-in default key-bindings, none from any plugin. Each plugin has their own set of default keybindings, if applicable.

Also note that keybindings can be restricted to certain contexts, which may make some keybindings difficult to know about, especially if they are scoped to a specific syntax. An example in the default keybindings is the double quote key ("keys": ["\""]) which will move forward instead of inserting a " when the specified criteria are met.

0 Likes

#5

Thanks, @srbs! I was just doing some of that key binding stuff and was using the python console as @OdatNurd suggested which was working fine until I hit ctrl + f which just took me immediately to the Find input dialog. Obviously, ctrl + f is Find but it’s not in the default bindings. Is there another keybinding file?

0 Likes

#6

It’s there, it should look like this:

{ "keys": ["ctrl+f"], "command": "show_panel", "args": {"panel": "find", "reverse": false} }
0 Likes

#7

Oops - my bad. I had regular expression searching enabled so when I typed ctrl+f in the Find dialog it was actually looking for something else. Once I flipped that off I could find them. Thanks!

0 Likes

#8

Man, if I had a nickel for every time I’ve done that… :slight_smile:

I meant to mention above but forgot, you may be interested in taking a peek at the FindKeyConflicts package. It provides a lot of commands for finding key overlaps that may be causing issues, but also generally can tell you what packages are binding what keys and in what circumstances they apply.

Something that can be handy is the FindKeyConflicts: All Key Maps to Quick Panel command; it opens a quick panel where you can fuzzy match by key (no regex :wink:) to see exactly what packages (if any) have a binding on a key.

For example, doing that for the key you mentioned above shows the following output, telling you that both the Default and the Terminus package have bindings for this key, but the Terminus binding is only active in certain situations (here inside of a Terminus terminal view).

 -------------
Entry Details
-------------
 [ctrl+f]
   show_panel                               Default               
   terminus_keypress                        Terminus              [{"key": "terminus_view"}]
0 Likes

#9

There we go… ! That’s exactly what I needed. Thanks, @OdatNurd!

0 Likes

#10

I created a plugin called Emacs Pro Essentials because like you I was a long time (35+ years) emacs user and I didn’t want to relearn basic key bindings and expected motion of commands.

But because sublime is so awesome, I made sure it is all multi-cursor aware. It has incremental search which is close to how emacs’s works, with multi-cursor extensions as well. Things like s-expressions work most of the time, and word motion and numeric arguments via Ctrl-U and Meta-[0-9] all work as expected.

So if you want sublime but also some familiar behaviour, you could give it a try. Good luck either way.

2 Likes

#11

I’ll check it out, thanks, @canoeberry!

0 Likes

#12

I can attest to Emacs Pro Essentials being a decent instantiation of most Emacs binds. Having that also let me put in Emacs bindings in my vhdl-mode package (as an option – I have non-Emacs binds as default.)

1 Like

#13

Emacs Pro Essentials is working really well, thanks for the suggestion!

One quick question: how do I hide/show the sidebar since Cntrl-K has been rebound?

0 Likes

#14

I tend to have the sidebar up all the time personally. For the rare times when I’d like more screen, I use the menu option for that. It would not be terribly difficult to poke through the keybinding file to find the command that toggled the sidebar and come up with a Emacsian bind though.

0 Likes

#15

True, I’m probably the same way though in the same experimentation phase I’ve been going back and forth with the side view.

0 Likes