I'd like to edit my Visual Studio Code.
When I write my symbols on my keyboard to VSC, they'll get written Column by Column on the current Row.
\ Line of Code + Column.
(Ln , Col )
Extensions: "Select By"
= to jump to a certain column.
However, when i like to jump to 'column 50', it will only jump to the >End of Line.
// Example
// Goal is to get a Hotkey to Jump to Column 50
// Activated Hotkey*
cout << "Hello World:" << endl; // If i use my Hotkey i get to the Column 30, not 50. Picture is enhanced*
/* The end of line is here: 30. */
Question: How can I achieve my Jump
via the given Extension? (Any easy solution would be helpful).
I don't like to use the Ln, Col in Vsc, because clicking on the UI is for me over the time to slow.
I'd like to use f.e. Cmd + M to get to my "middle", So for me column 50.
Hence, i don't like to go to Middle of my current Screenformat.
Additional prefered Question: One way how i like to solve the issue is in C64 Style.
Is there any way to fill out the Visual Studio Code Screen by empty chars?
So as an Preset.
I know, that i can just copy & Paste. Or write an empty script. But that doesn't seem convenient inside the Configuration. I tryed to find that now unsucessfully since 2 weeks..
The reason is for me, that i currently try to code more cleaner.
And to achieve that (I have read many Clean Code Books during school and Github), i just like to try this time an historical approach by setting my own column points/ marks. (Basic C64-menu wise)
Thank you in advance!
Sincerely
Edit: I have enhanced beforehand.
Edit2: I have tryed the Find and Transform Extension pointed by Mark. Thank you for your time!
When i press the given Hotkey, It does marks the previous chars. but it doesn't start at column 50.
It marks at end of line.
I only like to move the cursor to column 50 and surpress the end of line.
does this key binding work
{
"key": "ctrl+i ctrl+m", // or any other key binding
"when": "editorTextFocus",
"command": "moveby.calculation",
"args": {
"charNrEx": "50"
}
}
Or use Ctrl+G and type lineNr:charNr
At the risk of not fully understanding the question, if what you want to do is pad any line to the 50th column with spaces, you can try this approach.
Install the extension Find and Transform
Make this keybinding (or it could be a command):
{
"key": "alt+q", // whatever keybinding you want
"command": "findInCurrentFile",
"args": {
// this will select the current line, cursor can start anywhere on line
"preCommands": ["cursorEnd", "cursorHomeSelect", "cursorHomeSelect"],
"replace": [
"$${",
"const str = `${TM_CURRENT_LINE}`;",
"let currentLength = str.length;", // current line length
"if (currentLength >= 49) return str;", // do nothing
// pad to whatever column you want
"else return `${str.padEnd(49, ' ')}`;", // pad with spaces
"}$$"
],
"restrictFind": "line", // only on lines with a cursor
"postCommands": ["cursorRight"] // just cancels the selection
}
}
It'll work on multiple lines too if each line has a cursor on it
Related
Is there an easy way to add spaces to multiple lines so that each line has equal amount of characters?
Motivation, say I want to add '*' at end of each line
/***************************
* This is line 1. *
* Line2. *
* May be line3. *
* For sure this is line 4. *
****************************/
Without using any custom format program, is there a way in VS code to add different number of spaces just before the last '*' like so:
/***************************
* This is line 1. *
* Line2 *
* May be line3 *
* For sure this is line 4. *
****************************/
select all the * at the lines that are incorrect
add as much spaces as needed to get all *'s beyond the correct position
Esc to get out of multi cursor
Place Multi Cursor on all lines at the position where you want the *'s
press Ctrl+Delete
Esc to get out of multi cursor
You can do this fairly simply with an extension I wrote, Find and Transform, because it allows you to use javascript or the vscode extension api in a replacement. So starting with this text:
/***************************
* This is line 1.
* Line2.
* May be line3.
* For sure this is line 4.
****************************/
you would make this keybinding (in your keybindings.json):
{
"key": "alt+q", // whatever keybinding you want
"command": "findInCurrentFile",
"args": {
"replace": [
"$${",
"const str = `${selectedText}`;", // get the selected text
// since the selected text can contain newlines, surround the variable with backticks
"let lineArray = str.split('\\n');", // newlines must be double-escaped
"let firstLineLength = lineArray[0].length;",
"lineArray = lineArray.map((line, index) => {",
"if (index === 0) return line;",
"else if (line === lineArray.at(lineArray.length-1)) return line;",
"else return `${line.padEnd(firstLineLength-1, ' ')}*`;",
"});",
"return lineArray.join('\\n');",
"}$$"
]
}
}
So the replacement is straightforward javascript which gets the selected text, splits it on the newlines and then uses the length of the first line to pad the other lines with spaces and then adds a * to the end of each line. It does nothing to the first or last line of the selection.
Demo:
You can do multiple selections at a time too.
I have a custom keybind for Esc for my neovim extension in VS Code, that mapping being the chord "j k". When I am in Insert Mode, I can now successfully type "jk" to exit Insert Mode and enter Normal Mode. The problem is that I now cannot type the letter j followed by anything other than the letter k, or my neovim just gives up and tells me "The key combination (J, *) is not a command." (where * is any non-J key) The solution to this keybind problem would be to add a timeout after the first key of the chord (ie j) or to type j normally if a non-j key is typed after it. How does one do this? I would appreciate any help with either solution, although I would prefer the latter, as it solves the problem completely. I have attached screenshots to depict my keybind and the error from typing "j *". Thanks!
Turns out it was just in the documentation:
[
{
"command": "vscode-neovim.compositeEscape1",
"key": "j",
"when": "neovim.mode == insert && editorTextFocus",
"args": "j"
},
{
"command": "vscode-neovim.compositeEscape2",
"key": "k",
"when": "neovim.mode == insert && editorTextFocus",
"args": "k"
}
]
I have lines like:
"gg":: go to the top:: of the file
"G":: go to the bott::om of the file
"{":: go to the begi::nning of current paragraph
"}":: go to the end ::of current paragraph
"%":: go to the matc::hing pair of (), [], {}
"50%":: go to line a::t the 50% of the file
":NUM":: go to line ::NUM. :28 jumps to line 28
I have cursor in the beginning of each line. So, it looks like:
|"gg":: go to the top:: of the file
|"G":: go to the bott::om of the file
|"{":: go to the begi::nning of current paragraph
|"}":: go to the end ::of current paragraph
|"%":: go to the matc::hing pair of (), [], {}
|"50%":: go to line a::t the 50% of the file
|":NUM":: go to line ::NUM. :28 jumps to line 28
NOTE: Here I am using | as cursor.
Now, I want to move the cursor before first occurrence of :: for each cursor,so that it looks like:
"gg"|:: go to the top:: of the file
"G"|:: go to the bott::om of the file
"{"|:: go to the begi::nning of current paragraph
"}"|:: go to the end ::of current paragraph
"%"|:: go to the matc::hing pair of (), [], {}
"50%"|:: go to line a::t the 50% of the file
":NUM"|:: go to line ::NUM. :28 jumps to line 28
I tried selecting text. then search in selection (ctrl+f>alt+l). then alt+enter. But the issues is, it selects all occurrence of :: and not the first one.
what can I do?
Use the extension Select By
And define a key combo
{
"key": "ctrl+f6", // or any other key combo
"when": "editorTextFocus",
"command": "moveby.regex",
"args": {
"ask": true,
"properties": ["next", "start", "nowrap"]
}
}
I use a shortcut with keybindings.json to put a single line into quotes, ending with a comma.
text --> "text", this works well, but only for one line.
Now I have a long list of text and would like to put every line into quotes
like this
text1 --> "text1",
text2 --> "text2",
text3 --> "text3",
text4 --> "text4",
Is there a way to do it? Help highly appreicated, because I would gain a lot of time, if i dont have to do it line by line.
Best endo
edit:
here is the snippet from keybindings.json which puts every line in brackets
[
{
"key": "cmd+,",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "\"${TM_SELECTED_TEXT}\", "
}
}
]
try to use multi line selection with CTRL + ALT + Up/Down arrow and then, after you selected the rows, apply that shortcut of your
VS Code
if (1 == 1) // When I hit enter here, the cursor moves to the next line at pos (0)
|
else
return; // When I hit enter here, cursor moves to next line/ pos 4
| // why is the cursor here? why not pos 0?
Visual Studio (this is what I want to happen)
if (1 == 1) // When I hit enter here, the cursor moves to the next line at
| // pos 1 if I'm working with Tabs or pos 4 for spaces)
This is not a problem in VS Code if you use braces like this:
if (1 == 1){
return;
}
However, I don't like to use braces in those scenarios, and if I don't, VS Code naturally makes me end up writing this code which is also bad
if (1 == 1)
return;
I'm trying to get the same behaviour in VS Code. I can't seen to find a setting for this, or an extension. Please help. If I have to make an extension, or update the VS Code source and build it myself, I'm up for that, just please point me to the right direction. This is annoying.
You can create code snippet. F1 "usn" => choose language >>
"if": {
"prefix": "if",
"body": [
"if ($1)",
"\t$2",
"$3"
]
},
"ifelse": {
"prefix": "ifelse",
"body": [
"if ($1)",
"\t$2",
"else",
"\t$3",
"$4"
]
},
Just in case add this to settings.json ctrl+,:
"editor.snippetSuggestions": "top",