如何在 VS Code 中跳过空行但不跳过代码块?

huangapple go评论69阅读模式
英文:

How to skip empty lines but not blocks in vs code?

问题

我想要一个键绑定命令,将光标移动到下一行非空行。例如:

msg = "Hello World"

print(msg)

将光标移动到这些行之间,跳过它们之间的空行。

英文:

I would like a keybinding command to move cursor to next non empty line.
For example:

msg = "Hello World"


print(msg)

Move the cursor between these lines skipping the empty lines in between.

答案1

得分: 1

你需要一个扩展来实现这个功能。我假设其他“跳转”扩展也可以做到,但是这里有一个我写的扩展,Jump and select,你可以在你的keybindings.json中设置一些按键绑定,如下所示:

{
  "key": "alt+down",          // 你想要的任何按键绑定
  "command": "jump-and-select.jumpForward",
  "args": {

    // 转到下一行/上一行不为空的行
    "text": "^.",
  }
},

{
  "key": "alt+up",
  "command": "jump-and-select.jumpBackward",
  "args": {

    "text": "^.",
    // "text": "#\\d+\n"           // 在必要时进行双重转义
  }
}
英文:

You will need an extension for that. I assume that other "jumping" extensions can do it but here is an extension I wrote, Jump and select, for which you can set up a couple of keybindings (in your keybindings.json) like so:

{
  "key": "alt+down",          // whatever keybindings you want
  "command": "jump-and-select.jumpForward",
  "args": {

                                  // go to next/previous line that isn't empty
    "text": "^.",                 // <== can use strings or regexp's here
  }
},

{
  "key": "alt+up",
  "command": "jump-and-select.jumpBackward",
  "args": {

    "text": "^.",
    // "text": "#\\d+\n"           //  double-escaped where necessary		                                      
  }
}

huangapple
  • 本文由 发表于 2023年5月11日 17:01:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76225858.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定