Visual studio code - shortcut to open next file by name - visual-studio-code

I often find myself working on file test-1a.robot and I want to open test-1b.robot, which is the next alphabetical file in the editor list.
With the files are open and I have a "sort tabs" extension enabled I can use ctrl+pgup and ctrl+pgdn which is already something, but I'd like to have it even without the tab sorting or opening files in advance.

Maybe you need to train yourself in the following key combo:
Ctrl+Shift+E DownArrow Enter
I tried to use multi-command to create a combo of
show explorer tab
go to next file down
open this file
For (1.) I could find a command, it sets the focus on the current file in the Explorer.
Edit With the tip from mark for the commands to type the cursor down (2) and select command (3) in listboxes.
You can add this to your settings and create a key binding for this new command
"multiCommand.commands": [
{
"command": "multiCommand.openNextABCFile",
"sequence": [
"workbench.view.explorer",
"list.focusDown",
"list.select"
]
}
]
It opens the next alphabetical filename in preview mode.

Related

How to add "a" shortcut to VSCode for creating a file

I used to use Atom where I could select a folder in the explorer sidebar, press "a", and then this would create a new file.
I thought I had finally gotten this command to work in VSCode by
Setting up the keyboard shortcut for File: New File to be A with a When of sideBarFocus
Disabling file filtering
This configuration allows me to create a new file by pressing "a".
However, if I try to rename a file to contain the letter "a", I cannot, because as soon as I press "a" it tries to create a new file.
I would like to be able to name files to contain the letter "a". (While having "a" still allow me to create a new file when I'm not renaming.)
How can I fix this?
Add another negated when clause to your keybinding:
{
"key": "a",
"command": "explorer.newFile",
"when": "sideBarFocus && !inputFocus"
}
so it won't operate when an input box has focus.

Browsing lines/columns in a big file in VSCode

I work with big flat database files which I like to inspect at line/column.
I have a tool which generates a log with hundreds of lines like:
code --goto path/to/my/file:line:column
Visiting one such a spot works ok if I throw one such a line into the command line window and click it from there, but not from the editor (at least I have not found the way)
I would like to be able to have this log file open in the VSCode editor and hover/click in every line which would take me to the spot I want to visit in the big db file. Is this possible at all?
Should I convert my log file to some script format which supports the hover and click functionality?
Is there otherwise any extension available which can do the trick here?
Thanks a lot.
Miguel
Edit
Using HTML Related Links v0.9.0
I guess we're almost there but it's still not working for me.
The concrete scenario I have is: I have a file
d:\Users\Abc.def\Git\lingware-data\test\spx\spm\spm_cfg3\spm_cfg3_tst_row_valid_lng_abbr.dbr
containing several lines of the type
code --goto d:\Users\Abc.def\Git\lingware-data\dct\spx\dct.u08:176:36
(probably code is not needed, I tried with and without it)
In my settings.json file:
"files.associations": { ".u08": "csv (pipe)", ".dbr": "html" },
"editor.largeFileOptimizations": false,
"html-related-links.include": {
"html": [
{ "find": "--goto ([a-z:]+[^:]+):(\\d+):(\\d+)",
"filePath": "$1",
"lineNr": "$2",
"charPos": "$3"
}
]
}
if I use "plaintext" as languageId I don't get the HTML related links section displayed in the Explorer area, so I am using "html" - I have updated to v0.9.0 of the extension, and what I continue seeing in the explorer view is:
"d:\Users\Abc.def\Git\lingware-data\dct\spx\dct.u08 d:\Users\Abc.def\Git\lingware-data\test\spx\spm\spm_cfg3\d:\Users\Abc.def\Git\lingware-data\dct\spx\dct.u08"
If I click on it nothing happens I hope this is more or less clear.
What am I doing wrong?
*** edit ***
Installed v0.9.1. Enabled Developer console to debug click behavior on a row. What get now is:
[Extension Host] Clicked on: d:\Users\Miguel.Duran\Git\lingware-data\dct\spx\dct.u08
console.ts:137 [Extension Host] goto: 175:28
You can use the extension HTML Related Links v0.9.0 (it not only applies to HTML)
Define this in settings.json
"html-related-links.include": {
"plaintext": [
{ "find": "--goto ([^:]+):(\\d+):(\\d+)",
"filePath": "$1",
"isAbsolutePath": true,
"lineNr": "$2",
"charPos": "$3"
}
]
},
"html-related-links.removePathFromLabel": true
After loading the log file you can lock the Explorer View HTML RELATED LINKS to this file. Use lock button in top right of the view. Now only changes to this log file will update the view.
In an absolute path the label will contain the path and the view adds the directory path at the end. You can remove the path from the label with the setting html-related-links.removePathFromLabel
Click on a row in the view and that file will be opened to the given line:char position.
If on Windows the path is absolute you have to specify the drive first because it contains a :
"find": "--goto ([a-z]:[^:]+):(\\d+):(\\d+)"
Edit
There was a small typo in the regular expression string (need escaping the escape char).
Add possibility for absolute paths.
I would like to be able to have this log file open in the VSCode editor and hover/click in every line which would take me to the spot I want to visit in the big db file.
Is this possible at all?
If you visualize your file in a VSCode terminal, VSCode 1.70 (July 2022) will offer a way.
See issue 140780 ("Jump to line+column in terminal links (format <path> l:c)"), PR 153957 ("Detect terminal links with space, then line:col") and PR 155904 ("Ensure folders with spaces don't impact link line/col")
To test, you can open a terminal and run echo ./myFile.txt 10:5 (replacing the filename with one that exists).
When you click to open the file, it should open to line 10, column 5.
This is available today (July 2022) in Code insiders.

"Go to file" with VSCode, instead of goToSymbol

I see this line in keybindings.json
{ "key": "shift+cmd+o", "command": "workbench.action.gotoSymbol" },
which you can see here:
However, I am trying to find the shortcut for "goToFile" - is there such a shortcut?
Currently, to find a file by name, I use "goToSymbol" and then I delete the ampersand and then type the filename and it works, but that's an extra step I'd like to avoid. See:
So my question is, does anyone know how to go directly to searching for a file by name, instead of using goToSymbol?
It's ctrl+p by default, workbench.action.quickOpen.

Is there a way to make VS Code create HTML file by default?

I want to create .HTML file whenever I choose New File, is this possible?
In VS Code, my separate folders for different HTML projects are stored under an UNTITLED (WORKSPACE).
For a new HTML file, I simply right-click on any folder in (WORKSPACE), select New File and then name that file with an HTML extension. The file is completely empty with no HTML whatsoever. Then, because the Emmet plugin is built into VS Code, I simply type an ! (exclamation point) and press TAB or ENTER and the empty file is filed with a complete HTML5 boilerplate.
5 simple steps to create an HTML file in Visual Studio Code
right-click on folder in (WORKSPACE)
Select New File
Name the file with an HTML extension
Type ! (one exclamation point only)
Press TAB or ENTER
As far as I can see, there is no way to configure VS Code to do this out of the box so I wrote an extension to do it. You can download that extension from the marketplace.
It adds two types of commands:
editor.newFile.withCurrentLanguageMode will open a new file with the same language mode as the currently active file
editor.newFile.withLanguageMode.<languageId> will open a new file with specified id as the language mode. The language must be first added to the configuration and a keybinding set up
So to set up one command to open new html files and another to open markdown files, you can add settings like this:
settings.json:
"editor.newFile.languageModes": ["markdown", "html"]
keybindings.json:
{
"key": "ctrl+shift+t 0",
"command": "editor.newFile.withCurrentLanguageMode",
"when": ""
},
{
"key": "ctrl+shift+t 1",
"command": "editor.newFile.withLanguageMode.markdown",
"when": ""
},
{
"key": "ctrl+shift+t 2",
"command": "editor.newFile.withLanguageMode.html",
"when": ""
}
Using these settings you would then press "ctrl+shift+t" then "0" to open a new file with the same language as whatever file you have active, "ctrl+shift+t" then "1" to open a new file with "markdown" as the language mode, and "ctrl+shift+t" then "2" to open a new file with "html" as the language mode. Of course, you can customize the keybindings however you want and set the languages to whatever you want.

File associations in vscode

Does anyone know is it possible to set file associations in vscode?
I'm working with .pt files which contain html and was looking to set the editor, so that when it opens these files it automatically set the type to html.
Currently changing a mode is not persisted on a file. For the future we will look into an option to allow the user to associate file extensions to modes and persist this setting.
Update for our VS Code 1.0 release:
You can now persist a file to language association in settings. The newly introduced files.associations setting can be used like this:
files.associations: {
"*.php4": "php",
"*.php3": "php"
}
If switching language using the bottom-right menu is annoying you - I have an interim solution, it isn't automated but it allows keyboard-switching:
[
{
"key": "ctrl+l",
"command": "workbench.action.editor.changeLanguageMode",
"when": "editorTextFocus"
}
]
You can now type CTRL + L then HT then ENTER.
VSCode remembers what language you have selected and even remembers that language if you copy and paste files (either in VSCode or on the file system). I can't see where they have stored that information though.
So you would only need to do this for brand new files.