Sublime Text 2 - Key Binding for Open Recent? - sublimetext

How can I map Open Recent, or "open last file" to a keyboard shortcut?
This is my pitiful attempt so far:
{ "keys": ["super+shift+r"], "command": "open_recent"}
I tried looking at the console (Ctrl-`) while using Open Recent but it doesn't display anything.
In general, how does one go about adding key bindings? And is there a more appropriate place that Stack Overflow for this question?
Thanks!

Key bindings should be added to the User key-binding preferences. Adding to the default settings will also work, but the settings will be overwritten when a new version of Sublime Text 2 is installed.
Your attempt matches the general structure of a Sublime Text key-binding, but "open_recent" isn't a valid command. From what I can find in the documentation, I think the Open Recent menu keeps track of the different file names then calls open on whichever file is selected, instead of calling an open_recent command.
If there isn't a way to get the name of the most recent file, you could probably write an extension that kept track of the most recent file and then opened it, but that probably be a fairly kludgy solution.

The command is reopen_last_file. So you should add something like this:
{ "keys": ["ctrl+shift+r"], "command": "reopen_last_file" },
Little PS: I'm using ctrl+shift+t, so that the shortcut for reopening the last document is consistent across my browser, IDE and editor.

I suggest you try out a couple of packages:
https://github.com/spadgos/sublime-OpenRecentFiles
or:
https://github.com/paccator/GotoRecent
And the easiest way to install them is with this package control, package:
http://wbond.net/sublime_packages/package_control/installation
That should give you what you want...

Related

Clear Recent items in Preview Application of Mac OS X..?

Hello all,
Can anyone tell me how to clear the 'Recent items' list in Preview application of Mac OS X through code? Is there a terminal command that can do this?
Or is there any way to click on 'Clear Menu' in 'Open Recent' of the 'File' menu in Preview?
Alternatively, does someone know where Preview stores this information and how do to remove it?
Check out this image to see what I mean.
Ok, so none of the described methods on the websites I could find actually succeeded in getting rid of all the 'recent document' lists in all of my apps.
I feel the most common sense approach would be (for OSX 10.12 / Sierra):
First go to system settings > general and choose "none" in the recent file dropdown menu (my OSX is in another language so the exact terms might be different, but you should be able to see what I mean). / This will get rid of most, but not all recent-items in different apps.
Get familiar with Apple's 'defaults' command in terminal. Now, hunt for any lists you might still want to get rid off, e.g. none of the options mentioned in the answers already listed here helped to get rid of the recent-items list in Finders "GO" menu. I played around with the defaults command and found that: "write com.apple.finder "FXRecentFolders" '({})' && killall Finder" does the trick for me. Playing around I found similar solutions for many of the other apps that where still able to maintain a list of recent items.
Create a shell script containing the commands you found during step 2.
Schedule the script to be run automatically on a preset interval or action (e.g. log out). AND/OR create an alias in your shell's profile (or directly apply the script as a function inside it) so you can call it with a single command from your terminal. (for instance: I have created an alias to it, so when I now type "killrecent" in terminal, it empties all the recent-items lists I've been able to find.
Hope this will be of some help to others. Good luck!
open Preview ->- go to File ->- Open Recent ->- Clear Menu
You may try the approach outlined here, which is to run
defaults delete com.apple.Preview.LSSharedFileList RecentDocuments
in the Terminal (manually or through your app). However I tried this and it didn't work for me (OSX 10.11), since the Preview defaults file doesn't contain this entry.
You can use
defaults write com.apple.Preview NSRecentDocumentsLimit 0
which will hide all recently used items, but as soon as you set that number to anything greater than 0, they will show up again.
I also checked the ScriptingBridge Interface for Preview, but couldn't find anything useful. So unfortunately it looks like this is not possible.
with 10.11, there are at
~/Library/Application\ Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/com.apple.preview.sfl

Using xkb command to change keyboard mapping results in read-only files

I am new to Linux and maybe the answer to my question is too simple but I did my research and found nothing out there.
The key "a" in my laptop is broken. So I need to remap it in another position. I opened the location /usr/share/X11/xkb/symbols/ and tried to edit the file "us" which contains the mapping for the English keyboard but when I tried editing it in "vi" editor I got a "read only" message. I need to edit and save the changed file. How can I do this?

Sublime Text 2 Code Formatting

First let me say I come from a Microsoft background and Visual Studio is my bread and butter. It has a command (keybind is arbitrary) that auto-formats any code syntax. The same command works in HTML, CSS, Javascript, C#, etc.
I have tried plugins for ST2 and so far I've found most don't work on a Windows box and if they do, it's for a very specific purpose like just Javascript.
I have tried (and opened Issues where appropriate):
https://github.com/victorporof/Sublime-HTMLPrettify
https://github.com/jdc0589/JsFormat (this one actually works)
https://github.com/welovewordpress/SublimeHtmlTidy
Have any Windows users of ST2 found anything that works to format CSS/HTML/Javascript, preferably in one shot?
Edit: Since this question is getting lots of views with no activity, I'll say that I am still looking for a plugin that can format various script types within the same command.
October 2013
Still haven't found anything that covers JS+CSS+HTML well however I have settled on JsFormat as by far the most effective and bug free with the least amount of configuration for just JavaScript.
A similar option in Sublime Text is the built in Edit->Line->Reindent. You can put this code in Preferences -> Key Bindings User:
{ "keys": ["alt+shift+f"], "command": "reindent"}
I use alt+shift+f because I'm a Netbeans user.
To format your code, select all by pressing ctrl+a and "your key combination". Excuse me for my bad english.
Or if you don't want to select all before formatting, add an argument to the command instead:
{ "keys": ["alt+shift+f"], "command": "reindent", "args": {"single_line": false} }
(as per comment by #Supr below)
Sublime CodeFormatter has formatting support for PHP, JavaScript/JSON/JSONP, HTML, CSS, Python. Although I haven't used CodeFormatter for very long, I have been impressed with it's JS, HTML, and CSS "beautifying" capabilities. I haven't tried using it with PHP (I don't do any PHP development) or Python (which I have no experience with) but both languages have many options in the .sublime-settings file.
One note however, the settings aren't very easy to find. On Windows you will need to go to your %AppData%\Roaming\Sublime Text #\Packages\CodeFormatter\CodeFormatter.sublime-settings. As I don't have a Mac I'm not sure where the settings file is on OS X.
As for a shortcut key, I added this key binding to my "Key Bindings - User" file:
{
"keys": ["ctrl+k", "ctrl+d"],
"command": "code_formatter"
}
I use Ctrl + K, Ctrl + D because that's what Visual Studio uses for formatting. You can change it, of course, just remember that what you choose might conflict with some other feature's keyboard shortcut.
Update:
It seems as if the developers of Sublime Text CodeFormatter have made it easier to access the .sublime-settings file. If you install CodeFormatter with the Package Control plugin, you can access the settings via the Preferences -> Package Settings -> CodeFormatter -> Settings - Default and override those settings using the Preferences -> Package Settings -> CodeFormatter -> Settings - User menu item.
I can't speak for the 2nd or 3rd, but if you install Node first, Sublime-HTMLPrettify works pretty well. You have to setup your own key shortcut once it is installed. One thing I noticed on Windows, you may need to edit your path for Node in the %PATH% variable if it is already long (I think the limit is 1024 for the %PATH% variable, and anything after that is ignored.)
There is a Windows bug, but in the issues there is a fix for it. You'll need to edit the HTMLPrettify.py file - https://github.com/victorporof/Sublime-HTMLPrettify/issues/12
Maybe this answer is not quite what you're looking for, but it will fomat any language with the same keyboard shortcut.
The solution are language specific keyboard shortcuts.
For every language you want to format, you must find and download a plugin for that, for example a html formatter and a C# formatter. And then you map the command for every plugin to the same key, but with a differnt context (see the link).
Greets

"Open folder in Terminal" for Spotlight or Alfred

Is there any way in Spotlight to have a folder open in a Terminal window, either by providing an "Open in Terminal" option in search results, or (ideally) by holding down a key when selecting a result? Basically the same way holding down command will "Open containing folder" maybe make it so holding option (or whatever key) could "Open in Terminal".
Alternately, is there a way to setup the Alfred app so that it will always open folder search results in the Terminal? that might be even better, then I could use ctrl-space exclusively for opening folders in the Terminal and command-space (Spotlight) for everything else.
The closest thing I can find to anything like these is the "cdto" application, which adds an "Open in Terminal" button to the Finder. This is nice, but being able to do this directly from Spotlight or with a keypress would be much more convenient.
This question is old and you undoubtedly found the answer by now; for the sake of completeness: the latest version of Alfred allows one to search/navigate the filesystem from within Alfred, and take action on the folder or file found. One folder action is "Open Terminal Here", which seems to be what you are asking for.
I've found this to be the fastest method without any external tinkering.
Requirement: need to have iTerm or Terminal in the Dock:
Type the folder name into Alfred / Spotlight
Click and drag the folder that was found into the iTerm / Terminal icon in the Dock
Try this tool:
https://github.com/nmadhok/OpenInTerminal
This is a really handy tool for programmers on Mac as it lets you open the folder directly in Terminal. You can select multiple folders to open them in multiple terminal windows. You can also select files to open the parent directory in Terminal. This application works with Finder as well as without Finder which is a plus!
use this Alfred extension
https://github.com/LeEnno/alfred-terminalfinder
then just lob off the input and set it to a hotkey.. I have one to open the current finder in terminal and vice-versa
#Verboze - I'm still looking for an answer :)
Perhaps it should be migrated to stack exchange or the other one used non-programming topics, such as system administrivia. Though a case could be made that the command line is essential to programming.....
Windows has "Command Prompt Here". Linux has Nautilus' "Open In Terminal". The world's most advanced operating system has nothing (the best I can tell).
For completeness, I did look at the customizable toolbar ('drag your favorites here'; but my favorite is missing). I also found an old Action Script or Automator Script that did not work (the article was old, and it could not be followed).
I did find a program called "CD To...", but its broken. Upon opening the first terminal, the program opens two terminals. I'm not sure what other programming mistakes were made by the developer, and I really don't want to experiment.
Check this: https://github.com/miromannino/alfred-new-terminal-window
It opens a new Terminal/iTerm window in the current space.
Holding the alt key, the new window is also opened opened in the current frontmost Finder folder.
For me that is almost sufficient for my daily work!
Hope it helps!

Is there a Firefox add-on to use vim to edit textboxes?

or "How do I answer questions on SO in Firefox using gVim inside the textboxes?"
It's All Text!
From the extension page:
At the bottom right corner of any edit
box, a little edit button will appear.
Click it. If this is the first time
you've used "It's All Text!" then you
will be asked to set your preferences,
most importantly the editor.
The web page will pop up in your
selected editor. When you save it,
it'll refresh in the web page. Wait
for the magic yellow glow that means
that the radiation has taken effect!
Vimperator makes Firefox act very much like VIM:
Vimperator is a free browser add-on for Firefox, which makes it look and behave like the Vim text editor. It has similar key bindings, and you could call it a modal web browser, as key bindings differ according to which mode you are in.
Once you have the cursor in a text box, hit Ctrl-I to open in your editor, which defaults to gvim.
The current answers don't work anymore now that Mozilla removed XUL in favour of WebExtensions. With recent firefox versions, there are the following options (sorted in descending order by the current popularity on addons.mozilla.org).
GhostText provides instant synchronization between editor and textbox via editor-specific plugins. The project is on github and the vim extension is written in Tcl.
withExEditor is cross-platform but requires a native application written in node.js. In addition to editing text fields it also allows viewing the source of the page, MathML, SVG and the current selection. The project on github and the native node.js application
Textern requires a (currently) Linux-only native application written in Python. Synchronizes the content of the text field while you type in the editor. The extension and the native app can be found on github
Tridactyl is probably what you're looking for nowadays.
It's the spiritual successor to the likes of Pentadactyl and Vimperator, which are not available for the current version of Firefox.
If you want something more like It's All Text, where the editing area appears right on top of the browser text area rather than launching an editor window, and you're willing to use Neovim, check out firenvim.
It's All Text! will let you use whatever editor you want. To use vim with it, you'll need a small shell script to open it in a terminal:
#!/bin/sh
exec xterm -e /usr/bin/vim "$#"
If you have GVim, you won't need the shell, script, obviously.
ViewSourceWith is another addon worth lookng at. It supports more than just edit boxes and text. For example, you can configure it to open images in the GIMP.
Another feature that I find useful is that it can pop-up a dialog box that shows all the js and css scripts used on the page. You can then choose to view/edit file in your preferred editor.
For answering questions on SO, you may also want to get the Vim Markdown Syntax file
The "It's all Text" extension, perhaps?
http://addons.mozilla.org/en-US/firefox/addon/4125
If you use vimperator and have the markdown syntax file installed, a useful line for your .vimperatorrc is:
au LocationChange .* :set editor="gvim -f"
au LocationChange stackoverflow\.com :set editor="gvim -f -c 'set ft=mkd'"
This will tell vim to do syntax highlighting for markdown when you are on stackoverflow.com, but not when you are any other site. There are similar hacks for wikipedia/mediawiki etc. Enjoy :)
One way to do this is to use the vimperator extension - of course, that does a lot more than what you're looking for.
At the time of writing it is experimental, but the jV extension looks good. To quote from the page:
This extension makes all html textareas into a very stripped-down version of Vi[m]. It's modal, supports infinite undo, has register support, search, visual mode, and various movement and editing commands.
When using Vimperator in Windows (I am using Vista) you may need to double-escape the path to gvim.exe to use it as the external editor. Single escaping did not work for me as Vimperator unescapes it twice. Eg:
:set editor="C:\\\\Program\\ Files\\ (x86)\\\\Vim\\\\vim72\\\\gvim.exe" -f
Then while in a text box you use Ctrl+I and it will open gvim for editing. When you save and exit it will update the text box.
There is an experimental way to directly embed the real vim in firefox using embedded editor - though it requires mozplugger and will only work on Linux.
Try out the wasavi extension. You might want to check out the all versions page to make sure you try out the latest version. (Copy of this answer.)
You can also use the ViewSourceWith addon to achieve the same. Just right-click on any text input and you can edit it using Vim.
As said by others,
as a Vi/(g)Vim user you'll probably want to look at the Vimperator addon, which also provides the what you ask:
inside a textbox, hit <C-i> to launch the external editor.
(can be defined in _vimperatorrc: set editor=gvim -f )
A hint for Mac users: if you want to use "It's all text" with vim, the easiest way is to use http://code.google.com/p/macvim/ . Point "It's all text" to the mvim script that's provided along with the .app (you can place this script anywhere, I choose /usr/bin/ so that I can load mvim from the command line)
Pterosaur is a Firefox plugin that allows you to use Vim in all input fields. It uses an actual Vim process in the background so it has all the functionality you expect, including reading your .vimrc configuration and your plugins.
With Firefox-57 on Linux, I installed textern https://addons.mozilla.org/en-US/firefox/addon/textern/, and found it to be a suitable replacement for ViewSourceWith for editing text boxes.

Resources