Automatic Code Identation - matlab

I have a huge code and now for testing purpose I have to add that whole script into an infinite while loop is there any short way (without pressing space for each row) to add a space for indentation so the whole code is consider part of the one while loop ? Such as for example when we press ctrl +r it comments out the line

Ctrl-I/Cmd-I will automatically indent the file. Other wse you just select multiple row and use Tab/Shift-Tab to move them backwards and forwards.
For indentation is a must, however Matlab as a language does not care so it is not really a must to indent it. Additionally, you can just execute the code from the command line, say that you script or function is called Umar, then from the command line you just type while 1, Umar; end.

You can copy the code into notepad++.
Activate Column mode selection holding alt+shift and use the mouse to select the column of all the text you want to insert a space/tabulation/etc. and just insert it.
Final step is to copy back the code to matlab.
Matlab does not currently support column selection.

MATLAB has the option to select all your code, then press the right click and select smart indent button.
If you like to use shortcuts, just type the combination of Ctrl+A (select all) followed by Ctrl+I (smart indent)

Related

VSCode select next occurrence of variable

In VSCode on Mac, I can use the keyboard shortcut Cmd + D to select the next occurrence of my currently highlighted text.
For example, if I highlight the variable order on line 1 in the below code, hitting Cmd + D causes order_form on line 2 to be partially highlighted, and hitting Cmd + D again causes order to be highlighted on line 3.
1. order = "Some string"
2. order_form = create_form()
3. return "Here is your order: " + order
However, I just want to select the actual variable order on lines 1 and 3 (i.e. excluding the text that is part of the variable order_form)
What keyboard shortcut can I use to just highlight the actual variables named order on lines 1 and 3?
The Ctrl+D functionality uses the current Find widget settings "behind the scenes" - whether that Find widget is visible or not.
So you would get the behaviour you want if the Whole Word option was enabled in that Find widget first before you began Ctrl+D'ing.
Alternatively, as the demo below shows when you place your cursor on the word you want order you can then hit Alt+W which will toggle the Whole Word option on and off. Note the little box that opens in the top right of the editor that shows only the Find options.
Then all your find next occurrences with Ctrl+D will find only what you want with that Whole Word option still enabled.
If you want to skip any of those occurrences, you can use the command
Add Selection To Previous Find Match
editor.action.addSelectionToPreviousFindMatch
(which you would have to make your own keybinding for). Just trigger that command to skip the next possible match - so follow this order:
Ctrl+D on the first order
Alt+W to enable whole word matching
trigger the command Add Selection To Previous Find Match
Ctrl+D to select the next order
It sounds like a bit of a hassle but they are common commands to know - to skip the next match and to toggle Whole Word matching.
[That little box that opens with the Find options is a little glitchey in that it seems to sometimes also enable the case sensitivity option as well - which isn't a problem in your example.]

How to select whole line in VSCode

I am using VSCode on a Mac.
Does anyone know how to select the entire line that the cursor is on? I know about Command+I, but that only selects what appears to be the whole line, which is not always the whole line if I have word wrap enabled.
I am looking for something like Sublime Text's "Expand Selection to Line" command.
All you need to do is put the cursor anywhere on the line, do not make any selection at all and then do the desired command (Cut, copy, or paste).
When no text selected, VS Code will automatically select the entire line.
just triple click the end of the line it will select the entire line
Triple click at any point on the line
Click once on number of the line
Press Command + L
An alternative to what people have posted is, when your cursor is at the start/end of the line, you can hit shift + end/home respectively.
I find this useful for wrapping a line in curly braces/quotes/etc. whereas the other answers include spaces in the select so whatever you're wrapping it in will be wrapped around that whitespace.
Install the MetaGo extension and use the "metaGo: selectLineDown" command, which will come installed already overriding the "expandLineSelection" command.
This extension has many additional commands that you'll likely find useful as well, including moving up/down over code blocks, centering the active line, and going to any character on the screen.
Now, when I press Command+I, the whole line is selected. I am guessing this was caused by an update to VS Code, but I am not sure.
Ctrl + L on Windows or Command + L on Mac to select the whole line in VS Code.
You can use your mouse to select the whole line by triple-clicking on the line but the better way is to click on the line number to select the whole line or multiple lines.
Tripple click at any point on the line
In case you're wondering why Cmd+L is not working, there might be a chance that there are duplicate shortcuts. You can find out by opening Keyboard Shortcuts in VSC and remove the one that's not needed.
I know its old but for anyone seeking, you can press Alt + arrow up/down to duplicate your cursor to other lines and then without selecting anything copy and paste multiple lines.

Turn multiline selection into multi cursor selection in VSCode

It happens from time to time that I need to edit 100+ lines in a text file all at once.
I know I can use ⌘ Cmd+↑/↓ to select multiple lines but depending on the size of the file that takes a while.
In Atom and Sublime, I can just do a ⌘ Cmd + a to select everything, hit another shortcut (forgot the actual shortcut) and end up with a cursor for every line.
Have not found this in VSCode.
Ctrl-a to select all. (or whatever muli-line selection you want)
Shift-alt-I will put cursors at end of each selected line.
And then if you want those cursors at the beginning of each line you need to trigger the command "cursorLineStart" which is unbound by default. Give it a keybinding and all those end-of-line cursors will jump to the beginning of each line.
With v1.43 and Column Selection Mode this can be quite easy, see Column selection like Visual Studio and How to put the cursor at the end of all selected lines in Visual Studio Code?
FWIW cursorLineStart is not the opposite of Shift-Alt-I. In looking at the commends, Shift-Alt-I is "Add cursors to line ends", but there is not a "Add cursors to line begins" option.
However, the easy trick for that is:
Select your text block
Shift-Alt-I to put a cursor at the end of each line
Command-LeftArrow will move those cursors to the beginning of the lines
Its an extra step but it works. When I get time I will play around with building a custom command to do all this in one action.

How to use editor.action.joinLines in visual studio code?

As the title says, in visual studio code you can use the editor.action.joinLines to join different lines of text to one single line? Being an editor noob, the question is how? How do I map this command to a key board short cut, or what mouse actions do I need to do after selecting the said text, to get two different lines as one single line? Specifically I am working on Mac OS X.
To join several lines you have to select them first (you can read more about various ways of selecting text in the vs code documentation) and then invoke the Join Lines command. As a result, all text from the second and next lines will be appended to the end of first lines.
You can invoke the Join Lines command either from the Command Palette by pressing F1 or ⇧+⌘+P on macOS and typing Join Lines or by pressing the assigned shortcut - ⌃+J
You can also configure your own key bindings by clicking File>Preferences>Keyboardshortcuts on Vscode main menu.
There you can bind the command joinLines to your prefered Keyboard keys as shown in this link.
View image

cannot select text in VTE using keyboard

I'm writing my own terminal application in C using the VTE library. Everything works great except I cannot select text with the keyboard. For example if I have just typed something, in most terminals you can hold down the shift key and select the previous text with the left arrow key, then you can paste it wherever you want. In VTE, all that happens is you get a D in the current cursor position. I can obviously block the printing of D in the terminal by returning TRUE from the keypress (which I have done), but I still cannot select the text.
I thought I might be able to do it manually starting with vte_terminal_get_cursor_position(), but there is no method to select a block of text (that I could find) in VTE once I have the boundaries for the selection.
I've looked at other VTE based projects such as tinyterm, and evilvte, but they just print the D in the terminal as well when that key combination is pressed.
So is there any way to select text in VTE using the keyboard? Thanks.
Correction:
It turns out that very few if any terminals allow you to select text with the keyboard. Not sure how that got into my head. Anyway, I still think it would be a handy capability, so the question stands. Any ideas would be greatly appreciated.