MATLAB: Delete hotkey?

My trackpad is not very convenient, so I try to do the encoding only from my keyboard. My "kill line" hotkey does not work no matter which key I am installing it to. I canceled all conflicts.

A simple question: Is there a way to make a hotkey that deletes a line of code, the cursor (caret) is currently on it (not only all the code after the cursor, like the kill-line)?

+4
source share
4 answers

Kill line( Ctrl+Kdefault on Windows) only works in the default Matlab console window. If you go to File->Preferences->Keyboard->Shortcutsand select the action line Kill line, in the next table (with the inscription Shortcuts for Kill Line) you will see two columns Shortcutand Tolls with shortcut. Therefore, you should do Tools with shortcut All toolsinstead Command Windowby clicking on it and selecting everything.

+4
source

There is. You need to create a new shortcut , bind it to the quick access toolbar and launch it with Alt + number(or a custom shortcut with AHK)

HomeNewCommand Shortcut

Paste this piece of code there and fill in the field Labelusing the line "Delete line" and check Add to quick access toolbar.

currentEditor = matlab.desktop.editor.getActive;
originalSelection =currentEditor.Selection;
row = originalSelection(1);% get row of cursor
C = strsplit(currentEditor.Text,'\n');% Split text of editor by lines
C(row) = [];%remove current row
currentEditor.Text = strjoin(C,'\n');%join it together
currentEditor.Selection =  [originalSelection(1) 1  originalSelection(1) 1 ];
  % make sure cursor is on the same line and on first position

Shortcut editor

, , Search documentation. Alt + 1 .

AutoHotkey.

#IfWinActive MATLAB    ;in MATLAB window
F11::                  ;pressing F11...
Send !1                ;triggers Alt + 1 

. , , , , , . , ""...

0

Alamakanambra , '\n' '\n'

, :

y=eye(5)
x=eye(5)


% set m
m = length(x)

% display value of m
fprintf('value of m is: %d', m)

: y = eye (5) :

x=eye(5)
% set m
m = length(x)
% display value of m
fprintf('value of m is: %d', m)

:

x=eye(5)


% set m
m = length(x)

% display value of m
fprintf('value of m is: %d', m)

The solution is to use the CollapseDelimiters property and set it to false in the strsplit method.

You can find the solution here.

This is the complete solution:

currentEditor = matlab.desktop.editor.getActive;
originalSelection =currentEditor.Selection;
row = originalSelection(1)-1;% get row of cursor
C = strsplit(currentEditor.Text,'\n','CollapseDelimiters',false) % Split text of editor by lines
C(row) = [];%remove current row
currentEditor.Text = strjoin(C,'\n');%join it together
currentEditor.Selection =  [originalSelection(1)-1 1  originalSelection(1) 0 ];
  % make sure cursor is on the same line and on first position
0
source

It is better to use AHK directly:

#IfWinActive,ahk_exe MATLAB.exe
    ^d::send,{End}{Home 2}+{Down}{Del}
#IfWinActive

You can change ^ d (ctrl + d) to any other key you like.

0
source

All Articles