Vim setup with Visual Studio - configuration

Its being a while where I am using VIM with VS Code. But my current project require use of Visual Studio. While setting vim for vs code I have modified my settings.json and keybindings.json files. How do apply that kind of modifications in Visual Studio 2022.
Following are two files from vscode.
settings.json
{
"vim.easymotion": true,
"vim.incsearch": true,
"vim.useSystemClipboard": true,
"vim.useCtrlKeys": false,
"vim.hlsearch": true,
"vim.insertModeKeyBindings": [
{
"before": ["j", "j"],
"after": ["<Esc>"]
}
],
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["<leader>", "d"],
"after": ["d", "d"]
},
{
"before": ["<C-n>"],
"commands": [":nohl"]
}
],
"vim.leader": "<space>",
"vim.handleKeys": {
"<C-a>": false,
"<C-f>": false
},
}
keybindings.json
[
{
"key": "tab",
"command": "tab",
"when": "editorTextFocus && !editorTabMovesFocus"
},
{
"key": "shift-tab",
"command": "outdent",
"when": "editorTextFocus && !editorTabMovesFocus"
}
]
Note: I have installed VsVim 2022 extension on Visual Studio 2022.

While in Visual Studio type
:set vimrcpaths?
This will show you directory where the plugin looks for the .vimsrc file.
Place the config file there and restart Visual Studio.
I assume you have the VsVim extension installed (it's different than the one for VS Code).

Related

Visual Studio Code - Launching GDB in specific directory

I just have a quick question:
EDIT: This is run under Ubuntu 20.04 WSL2 using Visual Studio Code.
So I am debugging a kernel for gdb and the symbol files require that GDB is launched in the project directory, but the problem is GDB keep launching in the location of the program:
-exec pwd
Working directory /home/user/project-directory/obj/kern
I need GDB to stay in the project-directory:/home/user/project-directory
In the VSCode launch.json file, I made a workaround by adding a custom launch setup as shown below:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Kernel",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/obj/kern/kernel",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"printCalls": true,
"showDevDebugOutput": true,
"setupCommands": [
{
"description": "Change back to the workspace folder",
"text": "cd ${workspaceRoot}",
"ignoreFailures": true
},
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
// "preLaunchTask": "Launch Qemu (no graphic)",
"miDebuggerPath": "/usr/bin/gdb",
"miDebuggerArgs": "",
"targetArchitecture": "x86_64",
"customLaunchSetupCommands": [
{
"text": "target remote localhost:1234",
"description": "Connect to QEMU remote debugger"
},
{
"text": "symbol-file obj/kern/kernel",
"description": "Get kernel symbols"
},
// {
// "text": "set architecture i8086",
// "description": "Sets the current architecture"
// }
],
"avoidWindowsConsoleRedirection": true
}
]
}
The ${workspaceFolder} and ${workspaceRoot} are located in the project's directory, but without the setup to change back into the workspace folder, it won't work. Any tips would be appreciated!

vscode launch.json configuration

I have an issue with launch a cpp project file with vscode, here is my error
launch program {workspace domain}\build\Debug\outDebug does not exist.
and that's true, but i want to know can I add a parameter to my launch.json file or edit it, to work like : if a there is no directory to put the build file into it, so make it!
is it possible to do that ?
here is my launch.json file source
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"cwd": "o:\\Developing\\Projects\\Training\\c++\\School",
"environment": [],
"program": "o:\\Developing\\Projects\\Training\\c++\\School\\build\\Debug\\outDebug",
"internalConsoleOptions": "openOnSessionStart",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"externalConsole": false,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
See docs:
https://code.visualstudio.com/docs/cpp/launch-json-reference
May be there is solve.

VSCode Linux tasks.json MQL4 Compilation

I am switching to VSCode from MetaEditor to develop for MetaTrader4.
I'm using MetaTrader4 and MetaEditor in Linux via Wine.
(and MetaEditor runs quite terribly in Wine)
I would like to create a task to compile the code, and hopefully return the same error log to VSCode to further debug the code as if I was using MetaEditor.
I've used this post to figure out what CLI command has been used to compile MQL4:
Compiling MQL4 via command line through wine metaeditor.exe
/usr/bin/wine /path/to/MT4/metaeditor.exe /compile:"Z:\path\to\MT4\MQL4\Experts\Foo\Bar_EA.mq4" /include:"Z:\path\to\MT4\MQL4" /log
My issue is that I don't understand and cannot find any resource that explains what the "commands" inside the tasks.json file does or list of available variables. Like "/include:" or "presentation":, ${file}, etc.
So I took some guesses and I pieced it together to look something like this so far:
{
"version": "2.0.0",
"tasks": [
{
"label": "MQL4 Compile",
"type": "shell",
"command": "/usr/bin/wine /.wine/drive_c/Program Files (x86)/FXChoice MetaTrader 4/metaeditor.exe",
"args": [
"/compile:${file}"
]
}
]
}
Its probably not quite right.
I appreciate your help, thank you
{
"version": "2.0.0",
"tasks":
[
{
"label": "MQL4-Compile",
"group":
{
"kind" : "build",
"isDefault" : true
},
"presentation":
{
"echo" : true,
"reveal": "always",
"focus" : true,
"panel" : "shared"
},
"promptOnClose" : true,
"type" : "process",
"osx" :
{
"command" : "wine",
"args" :
[
"/Users/SVG/.wine/drive_c/Program Files/MetaTrader/metaeditor.exe",
"/compile:${fileBasename}",
"/log:${fileBasenameNoExtension}.log",
]
},
"windows" :
{
"command" : "C:\\Program Files (x86)\\MetaTrader\\metaeditor.exe",
"args" :
[
"/compile:${fileBasename}",
"/log:${fileBasenameNoExtension}.log",
]
},
}
]
}

Capturing Visual Stadio Command Line Compilier (CL.EXE) Output With Regular Expressions

I've been trying to set up VS command line compiler to use in VS code IDE. I have read the examples and can use GCC with no problem but need to use VS compiler now too.
I have tried a single line problem matcher and I multiple one. Yet VC code seems to capture nothing.
Here is an example of output with error from the compiler:
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.40629 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
helloWorld.c
..\Code\helloWorld.c(7) : error C2143: syntax error : missing ';' before '}'
Using the regExpr Expression:
(.*\n){2,3}\S+(\d+)\W+:\s(\bwarning|error\b\s\w+):\s(\w+\s\w+)\s+:\s(.*)$
It captures all the info I need (checked my work here: https://regex101.com/)
but when I put it in a Tasks.json file for VS code it doesn't work.
{
"version": "0.1.0",
"command": "Build",
"args": [
"${fileBasename}"
],
"isShellCommand": true,
"tasks": [
{
"taskName": "Build",
// Make this the default build command.
"isBuildCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
// No args
"args": [
"all"
],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "(.*\n){2,3}\\S+(\\d+)\\W+:\\s(\bwarning|error\b\\s\\w+):\\s(\\w+\\s\\w+)\\s+:\\s(.*)$",
"file": 1,
"line": 2,
"severity": 3,
"code": 4,
"message": 5
}
}
}
]
}
Anyone know how to setup VS Code IDE to use VS command line compiler? Any help would be greatly appreciated
The first two lines in your output can be avoided by adding /nologo flag to the compiler. So your tasks.json should be:
"tasks": [
{
"taskName": "Build",
"isBuildCommand": true,
"showOutput": "always",
"args": [
"all"
],
"problemMatcher": {
"owner": "cpp",
"severity": "info", // treat note as info
"fileLocation": "absolute",
"pattern": {
"regexp": "^(.*)\\((\\d+)\\):\\s+(warning|error|note)\\s*(\\w+)?:\\s+(.*)$",
"file": 1,
"location": 2,
"severity": 3,
"code": 4,
"message": 5
}
}
}
]

folder path in sublime text build system

My sublime project looks like this:
{
"folders":
[
{
"folder_exclude_patterns":
[
".bzr",
"build",
"webapps",
"work",
".settings"
],
"path": "/home/charles/project/Editor/trunk"
}
],
"settings":
{
"build_on_save": true,
"filename_filter": "\\.(java)$",
"tab_size": 4,
"translate_tabs_to_spaces": false
},
"build_systems":
[
{
"name": "compile",
"cmd": ["ant", "-f", "dev.xml", "compile"]
}
]
}
When I save a file the console says:
Buildfile: dev.xml does not exist!
Build failed
[Finished in 0.2s with exit code 1]
I know that I need to put something before dev.xml but I don't know what.
I found some possibilities here: http://sublimetext.info/docs/en/reference/build_systems.html#variables
But What I need is the folder path "/home/charles/project/Editor/trunk" in my case...
Any idea how I can achieve this?
You are missing "working_dir" in your "build_systems" setup. The example below will use the directory that holds the sublime project file as the build starting directory.
"build_systems":
[
{
"name": "compile",
"working_dir": "${project_path}",
"cmd": ["ant", "-f", "dev.xml", "compile"]
}
]
More information can be found at: http://www.sublimetext.com/docs/2/projects.html