how to create a keyboard shortcut for split view (duplicate of the same file) in sublime text - sublimetext

I want to have a keyboard shortcut key for opening the same file in another tab.
this can be done using File>Split view
How can I create a keyboard shortcut for this

{ "keys": ["ctrl+u", "ctrl+s"],
"command": "clone_file",
"args": {"add_to_selection": true} },
BTW, I found the command's name by typing sublime.log_commands(True) into the console. See OdatNurd's excellent video on this: P101-03 Tools of the Trade: Harnessing the power of the console!

Related

Sublime Text 4 Terminus - Multi Session Terminal Integrated In Panel View

I'm using Sublime Text 4's Terminus package and trying to open more than one terminal session within Sublime's panel view.
In VSCode it looks like this:
The closest I can get is to open each session in a separate tab on grid layout, which works fine, but I get the minimap which is not desired, and also I loose the ability to toggle open & close as opposed to the panel:
After doing a bit of research & watching this video I see in the comments the following question & answer:
Q: is there any way to open several instances of Terminus in the panel?
I could open several instances of it in Tab View, but not in the bottom panel.
A: There is an argument you can use in the terminus commands named "panel"; that gives the created panel a name. If you don't provide it there's a default. Using a different panel name lets you create or toggle extra panels.
So I've been testing Terminus settings with that in mind but no luck so far.
Terminus key bindings:
{
"keys": ["ctrl+alt+p"],
"command": "toggle_terminus_panel",
"args": {
"panel": "git",
"cwd": "${file_path:${folder}}"
}
}
With the above, terminal does open from panel but always with one session, if I add another key binding with a different panel name it still opens & closes the same session as the other key binding.
Tried also "command": "terminus_open" instead of "command": "toggle_terminus_panel", but doesn't work with panel as argument. Adding another panel name like the following does nothing either:
"args": {
"panel": "git",
"panel": "server",
}
Is this actually possible or what am I missing?
As noted in the comments on your question, if your goal is to have multiple panels open simultaneously each with a different visible name (i.e. a tabbed panel interface) that's not possible because currently Sublime supports only a single visible panel at a time.
However, if the goal is to have multiple panels that you call up via key bindings, that is indeed possible. What you tried doesn't work because the argument name is actually panel_name and not panel (sorry for the confusion; I've edited the comment on my video as well to reflect that).
So you can do something like this:
{ "keys": ["alt+`"], "command": "toggle_terminus_panel", "args": {
"panel_name": "first-panel"
}, },
{ "keys": ["shift+alt+`"], "command": "toggle_terminus_panel", "args": {
"panel_name": "other-panel"
}, },
The important consideration is that all key bindings need to include panel_name in them; if you don't provide the argument Terminus defaults to finding and opening the most recently active panel, whatever it happened to be.
Thus you could use a third binding if you always wanted to go to the most recent, if that is also interesting.
Note also that in your question you mentioned putting this in Terminus settings; the appropriate place is in your Key bindings (Preferences > Key Bindings).

How do I get my output panel back in Sublime Text (OSX)?

When I began ST there was a box at the bottom that provided feedback on my code. I've named that the output panel (please enlighten me if that is not the correct term for it)
http://imgur.com/LLovw9B
I must have changed a setting accidentally, because at some point I noticed it had disappeared.
http://imgur.com/a/yAzY6
Solutions tried:
Scrolling the mouse around the area at the bottom of the ST window to try find a bar to drag up, in the hope that would bring the output panel back into view.
Tools/Build Results/Show Build Results.
Clicking on the icon at the far left of the window's bottom panel, selecting "Build Results". There is a "Hide Panel" option too which I've selected. After I select this option the menu remains the same except that that option is no longer there. I can bring it back by selecting the "Build Results" option.
Dragging ST from the applications folder to the Trash, re-downloading the .dmg file from the Internet, and installing the program again.
PS: I've Googled and can't find anyone who has experienced a similar issue.
In Sublime Text, you have the console panel (in which you can enter python commands) and output panels (which can be many).
The console panel is called console (and the default key to open it is CTRL+`), and one already existing output panel is called output.exec (which displays output from building code for example).
To toggle (open/close) a panel, you can bind it to a key:
Open Sublime Key Binding Preferences
In the User Settings file, add a line such as:
{ "keys": ["alt+backquote"], "command": "show_panel", "args": {"panel": "console", "toggle": true} }
Save the file, and try your new shortcut key.
Your User keybindings file should look something like this:
[
{ "keys": ["alt+backquote"], "command": "show_panel", "args": {"panel": "console", "toggle": true} },
{ "keys": ["alt+shift+backquote"], "command": "show_panel", "args": {"panel": "output.exec", "toggle": true} }
]
Note 1: This is JSON so there must be a comma after each line except the final line.
Note 2: Be careful not to set a shortcut already used by your system (Mac OS X)
Modifier Keys:
ctrl = Control key
alt = Alt/Option key
shift = Shift key
super = Command key (or the windows key on MSWindows). It's the key next to the space key usually.
You can see what panels are available by opening the console panel and typing window.panels()
Remove ST (including the system files), download and install again to restore default settings with an output panel.
(This worked for me because I have just started in ST. I imagine it would be an unsatisfactory solution for someone who has customised ST and doesn't want to return to the default settings.)

How to make Sublime text build execute on numpad enter?

I use GoSublime inside sublime text for Golang development.
Pressing Ctrl + B gives me the build pane, then I need to type a command e.g., go run main.go and press Enter. When I want to execute a command using numpad Enter it doesn't work. How to make it work with numpad Enter too?
I checked the default keymap in sublime text it provides only the following key bindings for build tool
{ "keys": ["f7"], "command": "build" },
{ "keys": ["ctrl+b"], "command": "build" },
{ "keys": ["ctrl+shift+b"], "command": "build", "args": {"select": true} },
{ "keys": ["ctrl+break"], "command": "exec", "args": {"kill": true} },
Thank You!
The only suggestion I can give is to try using numpad_enter both with NumLock on and off, and see if it makes a difference. I'm running OS X and using the standard wired Apple keyboard with a numpad, and I'm also running Linux in a virtual machine. When I open up the console (Ctrl`) and run the command
sublime.log_input(True)
then refocus the file I'm working on, pressing Return (the Enter equivalent on the main keyboard) yields
key evt: enter
in the console, whereas hitting Enter on the keypad yields
key evt: keypad_enter
This behavior does not change in OS X or Linux (I haven't tried in my Windows VM yet) regardless of how NumLock is set. If you're on Windows or Linux with a Windows keyboard, it may change, but I doubt it.
The reason Sublime does this is because numpad_enter and Enter/Return send different keycodes to the program. Sublime is looking for a certain keycode (the one sent by Enter) to submit the contents of popup menus and whatnot, and ignores the code sent by numpad_enter. Unfortunately, because this is built-in behavior, there is no setting or key binding that can be set to override it.
The only other possibility I can think of is to use a utility for your OS to reprogram you numpad_enter to send the same keycode as Enter. I'm not terribly familiar with it, but for Windows I've heard that AutoHotKey is a pretty useful utility, and as far as I can tell is free. You can remap keys with it rather easily. You'll have to google for other utilities if you're on OS X or Linux.
Good luck!

Sublime Text 2 - Key Binding for Open Recent?

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...

VIM Ctrl-V Conflict with Windows Paste

I am using VIM in Windows. The problem is that I want to use CtrlV as a visual mode. However, this key has conflict with Windows paste. How can I reset this key back to VIM visual mode instead of pasting. I prefer to set this in my _vimrc configuration file.
From the VIM documentation:
Since CTRLV is used to paste, you can't use it to start a blockwise Visual
selection. You can use CTRLQ instead. You can also use CTRLQ in Insert
mode and Command-line mode to get the old meaning of CTRLV. But CTRLQ
doesn't work for terminals when it's used for control flow.
Check your _vimrc file and see if it sources mswin.vim. That script maps the ^v to the paste. You can either remove that line on your _vimrc file or disable the mapping commands directly on mswin.vim.
Do a :help behave on vim for more info.
Visual mode (and other stuff) working like in Unix requires both JOP's and Windows Programmer's suggestions.
In GVim on Windows, go to the edit menu, click on startup settings, and comment out the windows-specific garbage (using the vimrc comment character, which is a double-quote). The mswin.vim file is where the ctrl-v override is specified, and the behave mswin option makes it so that the arrow keys don't just apply motion like you'd expect (it also changes the mouse selection behavior).
"source $VIMRUNTIME/mswin.vim
"behave mswin
I like to add a black-background colorscheme in there as well, so it looks more like what I'd see in a terminal (and because a light background is great on paper, but awful on a backlit screen):
colorscheme koehler
If this line in your _vimrc troubles you:
behave mswin
then delete that line.
Here's a modern day solution to this problem. It applies to the terminal version of Vim/Neovim, not the GUI version. If you use Microsoft's new-ish Windows Terminal (I highly recommend it.), you can redefine its key bindings to your advantage. The following section of the settings file is initially NOT commented out. If you comment it out, as I've shown, Ctrl+V becomes the rectangular visual select key in Vim we all know and love.
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
//{
// "command": {
// "action": "copy",
// "singleLine": false
// },
// "keys": "ctrl+c"
//},
//{
// "command": "paste",
// "keys": "ctrl+v"
//}
Now here's the weird part. I'd expected this to change the behavior of Ctrl+V outside of Vim in the Terminal, so I checked. It still does a paste, but it's different than the Ctrl+Shift+V paste. Inside Vim, however, all is good: Ctrl+V for rectangular select; and "*P, Ctrl+Shift+V, or Right Mouse Button for pasting from the clipboard.
I prefer the same keystrokes everywhere so I use this in my .vimrc to override mswin.vim:
if has('win32')
" Avoid mswin.vim making Ctrl-v act as paste
noremap <C-V> <C-V>
endif
I'm not sure there is a lot you can do about that. You can use CtrlQ instead though.
For the Windows Terminal (PowerShell), click on the Dropdown arrow right next to the Shell-Tab and select settings. In the "actions" section of settings.json you can comment out the following lines so they're saying:
// { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
and
// { "command": "paste", "keys": "ctrl+v" },
This unbounds Ctrl+V and Ctrl+C from Paste and Copy. However due to the defaults.json you're still able to use Shift+Ctrl+C and Shift+Ctrl+V for Copy and Paste with this solution.
Please see Phil R comment. Didnt see his solution in the first place.
The combination of jop's advice (looking for mswin.vim in the default _vimrc file) and "Windows programmer's" advice (getting rid of the "behave mswin" line) worked like a charm for me.
(my rep is too low to vote them up or combine them -- someone clean this up for me, or I'll come back once my rep is higher)
For VMs on Windows where CTRL+V does the pasting:
Simply do CTRL+SHIFT+V ... works immediately and similarly to original CTRL+V visual selection.^ Source: Comment mentioned by stevesliva.
If the Windows-specific mappings as a whole bother you, you can set
let g:skip_loading_mswin = 1
in your vimrc to disable loading it (mswin.vim) entirely.
In Windows Terminal, the CTRL+V shortcut is assigned to paste command by default. If you use Vim in Terminal, you can change the paste key binding in Terminal's Settings / Actions menu. (Or use the WSL/PowerShell/Command Promt etc... directly, instead of launching it from Terminal.)

Resources