武进网站制作公司,网站营销理念,百度一下百度首页,p2p网站功能VS Code Code Runner 插件使用教程 安装插件 打开 VS Code 进入扩展市场 (CtrlShiftX) 搜索 “Code Runner” 点击安装#xff08;作者#xff1a;Jun Han#xff09; 基本使用方法
运行代码的几种方式#xff1a; 快捷键#xff1a;CtrlAltN#xff08;运行ShiftX)搜索 “Code Runner”点击安装作者Jun Han基本使用方法运行代码的几种方式· 快捷键CtrlAltN运行· 快捷键CtrlAltM停止运行· 右键菜单在编辑器中右键 → “Run Code”· 顶部工具栏点击播放按钮 ▶️· F1命令输入 “Run Code” 或 “Stop Code Run”支持的语言默认支持· C, C, Java, JavaScript, PHP, Python, Perl, Ruby, Go· Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F#· C#, VBScript, TypeScript, CoffeeScript, Scala, Swift· Julia, Crystal, OCaml, R, AppleScript, Elixir· VB.NET, Clojure, Haxe, Objective-C, Rust, Racket· Scheme, AutoHotkey, AutoIt, Kotlin, Dart, Pascal· Haskell, Nim, D, Lisp, Kit, V, SCSS, Sass, CUDA配置设置常用配置打开设置Ctrl,{// 是否在运行代码前保存文件code-runner.saveFileBeforeRun:true,// 是否清空之前的输出code-runner.clearPreviousOutput:true,// 是否在终端中运行code-runner.runInTerminal:false,// 是否保留焦点在编辑器上运行时不切换焦点code-runner.preserveFocus:true,// 是否忽略选择内容总是运行整个文件code-runner.ignoreSelection:true,// 执行超时时间毫秒code-runner.executorTimeout:10000,}自定义命令配置{code-runner.executorMap:{javascript:node,python:python -u,java:cd $dir javac $fileName java $fileNameWithoutExt,c:cd $dir gcc $fileName -o $fileNameWithoutExt $dir$fileNameWithoutExt,cpp:cd $dir g $fileName -o $fileNameWithoutExt $dir$fileNameWithoutExt,go:go run,php:php,rust:cd $dir rustc $fileName $dir$fileNameWithoutExt}}特殊功能运行选中代码选中部分代码右键选择 “Run Code”或使用快捷键 CtrlAltN自定义工作目录{code-runner.fileDirectoryAsCwd:true,// 或指定固定目录code-runner.cwd:D:\\projects}不同语言的特定配置Python 示例配置{code-runner.executorMap:{python:python -u}}Java 示例配置{code-runner.executorMap:{java:cd $dir javac $fileName java $fileNameWithoutExt}}C/C 示例配置{code-runner.executorMap:{c:cd $dir gcc $fileName -o $fileNameWithoutExt $dir$fileNameWithoutExt,cpp:cd $dir g $fileName -o $fileNameWithoutExt $dir$fileNameWithoutExt}}变量说明在自定义命令中可以使用以下变量· $workspaceRootVS Code 打开的文件夹路径· $dir当前文件所在目录· $fileName当前文件名含扩展名· $fileNameWithoutExt当前文件名不含扩展名· $fullFileName当前文件的完整路径常见问题解决问题1中文乱码解决方案{code-runner.executorMap:{cpp:chcp 65001 cd $dir g $fileName -o $fileNameWithoutExt $dir$fileNameWithoutExt}}问题2需要输入参数解决方案开启终端运行模式{code-runner.runInTerminal:true}在终端中输入参数问题3Python 输出不实时显示解决方案{code-runner.executorMap:{python:python -u}}高级技巧自定义运行按钮{code-runner.customCommand:echo Hello World,// 按 CtrlAltK 运行自定义命令code-runner.customCommandKey:ctrlaltk}多语言项目配置{code-runner.executorMapByGlob:{*.js:node,*.py:python,*.java:cd $dir javac $fileName java $fileNameWithoutExt}}集成调试虽然 Code Runner 主要用于快速运行但可以配合 VS Code 的调试功能安装对应语言的调试器扩展按 F5 进行调试按 CtrlAltN 快速运行测试实用示例Python 带参数运行{code-runner.executorMap:{python:python -u},code-runner.runInTerminal:true}然后在终端中输入参数。项目特定配置在项目文件夹下创建 .vscode/settings.json{code-runner.executorMap:{python:venv\\Scripts\\python.exe}}这样配置后Code Runner 将成为你快速测试代码的得力工具