我是VS Code的新手,可以使用 Ctrl + enter 将代码运行到python交互式窗口中。我希望光标自动移动到下一行,以便可以逐行浏览代码。
可以做到吗?
答案 0 :(得分:8)
如this blog post中所述,这是使用 Ctrl + enter 进入下一行的VS Code运行代码选择的方法:
###############################
# 1. Install extension "macros" in Visual Code
#
# Hit View on top menu
# Search for extension named "macros" (by geddski)
# Install "macros" extension
#
###############################
###############################
# 2. Add code below to keybindings.json
#
# Hit <Crtl> + <Shift> + <P>
# Enter in search bar: JSON
# Select Open keyboard shortcuts
#
###############################
{
"key": "ctrl+enter",
"command": "macros.pythonExecSelectionAndCursorDown",
"when": "editorTextFocus && editorLangId == 'python'"
}
###############################
# 3. Add code below to settings.json
#
# Hit <Crtl> + <Shift> + <P>
# Enter in search bar: JSON
# Select Open settings
#
###############################
"macros": { // Note: this requires macros extension by publisher:"geddski"
"pythonExecSelectionAndCursorDown": [
"python.execSelectionInTerminal",
"cursorDown"
]
}
答案 1 :(得分:1)
以上 P.Marres 的回答显示了 this blog 帖子的代码,非常棒!我需要这个用于 linux 中的 windows 子系统。
以下是在 Visual Studio Code 中为 Linux 的 Windows 子系统执行此操作的方法:
###############################
# 1. Install extension "macros" in Visual Code
#
# Hit View on top menu
# Search for extension named "macros" (by geddski)
# Install "macros" extension
#
###############################
###############################
# 2. Add code below to keybindings.json
#
# Hit <Crtl> + <Shift> + <P>
# Enter in search bar: JSON
# Select Open keyboard shortcuts
#
###############################
{
"key": "ctrl+enter",
"command": "macros.ExecSelectionAndCursorDown",
}
###############################
# 3. Add code below to settings.json
#
# Hit <Crtl> + <Shift> + <P>
# Enter in search bar: JSON
# Select Open settings
#
###############################
"macros": { // Note: this requires macros extension by publisher:"geddski"
"ExecSelectionAndCursorDown": [
"workbench.action.terminal.runSelectedText",
"cursorDown"
]
}