VSCode终端:如何突出显示要复制和粘贴的文本

时间:2019-06-09 19:15:25

标签: visual-studio-code

如何创建用于突出显示终端文本的快捷方式:Ctrl + Shift +右/左,Ctrl + Shift + End,Ctrl + Shift + Home-在Powershell Ise中实现?

如何创建快捷方式来按单词移动光标:Ctrl +向右/向左,类似于Powershell Ise。

谢谢。

3 个答案:

答案 0 :(得分:0)

我正确地说是要使用ctrl + left / right来按单词的开头和结尾来导航光标吗?

转到键盘设置:代码>首选项> keyboard快捷方式

搜索:

cursorWordEndRight并绑定到Ctrl+Right将允许您移动到单词的结尾

cursorWordStartLeft绑定到Ctrl+Left将允许您移动单词的开头

您可能要选择以下内容:

cursorWordStartLeftSelect并绑定到Ctrl+Shift+Left

cursorWordEndRightSelect并绑定到Ctrl+Shift+Right

您的keybindings.json应该看起来像这样:

// Place your key bindings in this file to override the defaults
[
  {
    "key": "ctrl+right",
    "command": "cursorWordEndRight",
    "when": "textInputFocus"
  },
  {
    "key": "ctrl+left",
    "command": "cursorWordStartLeft",
    "when": "textInputFocus"
  },

  {
    "key": "shift+ctrl+left",
    "command": "cursorWordStartLeftSelect",
    "when": "textInputFocus"
  },
  {
    "key": "shift+ctrl+right",
    "command": "cursorWordEndRightSelect",
    "when": "textInputFocus"
  }
]

您可能希望查看此链接以供参考,以便在vscode中重新绑定您的快捷键。

https://github.com/Microsoft/vscode/issues/34457

https://code.visualstudio.com/docs/getstarted/keybindings

希望这会有所帮助:)

答案 1 :(得分:0)

这是部分解决方案:

    {
        "key": "ctrl+left",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u001bb" },
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+right",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u001bf" },
        "when": "terminalFocus"
    }

它将为您提供Windows风格的Ctrl-左/右导航。

这放在您的keybindings.json中。我的位于~\AppData\Roaming\Code\User\keybindings.json~\AppData\Roaming\Code - Insiders\User\keybindings.json。 (我在桌面上运行Windows,但在Linux上进行远程开发。)

如果可以进一步解决,我会进行更新。但这并不容易,因为:

答案 2 :(得分:0)

这是一个几乎*完整的解决方案,需要使用zsh而不是bash。之所以起作用,是因为zsh有一个名为zle的工具,它允许您标记区域-通常由控制台主机处理的功能。

*-剪贴板复制的Ctrl-C不适用于我,因为我使用的是远程docker和本机Windows OpenSSH,这不允许X11转发。如果那不适合您,我建议尝试使用https://github.com/kutsan/zsh-system-clipboard和xsel(或xclip)。在我的场景中,我尝试过使用tmux和/或文件的输出选择并具有vscode文件监视程序任务

感谢https://stackoverflow.com/users/480527/jamie-treworgy的人在这里回答:Zsh zle shift selection

我们有SSO,因此我在dev容器中使用了一个非root用户,该用户具有与桌面用户名相同的用户名,并且依赖于带有桌面用户名标记的预制映像。

在这些步骤中,我安装了zgen,这是一个简单的插件管理器,然后用于安装zsh-autosuggestions,zsh-history-substring-search和zsh-syntax-highlighting.git。我无法让oh-my-zsh正常工作,而zgen似乎是最轻巧的选择。

此处未显示powerlevel10k主题,该主题也随zgen一起加载。

如果您想要的只是Ctrl-Shift-Left功能等,您可以跳过zgen位,但这将是一个错失的机会:-)

devcontainer.json

{
    "name": "devcontainer",
    "image": "devcontainer:${env:USERNAME}",

    "runArgs": [
        // Username
        "-u", "${env:USERNAME}",

        //    ...etc...

Dockerfile

RUN echo "Setting up user ${USERNAME} with UID ${USER_UID} and GID ${USER_GID}" \
    && groupadd --gid $USER_GID $USERNAME \
    && useradd -s /usr/bin/zsh --uid $USER_UID --gid $USER_GID -m $USERNAME

RUN echo 'Installing zsh and zgen...' \
    && apt-get update \
    && apt-get install -y zsh \
    && git clone https://github.com/tarjoilija/zgen /home/${USERNAME}/.zgen --depth=1 \
    && chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.zgen -R \
    #
    && echo 'Installing fonts...' \
    && apt-get install -y fonts-powerline \
    #
    # Clean up
    && apt-get autoremove -y \
    && apt-get clean -y \
    && rm -rf /var/lib/apt/lists/*

COPY --chown=${USERNAME}:${USERNAME} .zshrc /home/${USERNAME}/.zshrc
RUN chmod +x /home/${USERNAME}/.zshrc

...显然,您需要将USERNAME / USER_UID / USER_GID作为构建参数传递。

.zshrc

# Set up the prompt
autoload -Uz promptinit
promptinit
prompt adam1

setopt histignorealldups sharehistory

# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e

# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zsh_history

# Use modern completion system
autoload -Uz compinit
compinit

zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true

zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'

# load zgen
source "${HOME}/.zgen/zgen.zsh"

zgen load zsh-users/zsh-autosuggestions
zgen load zsh-users/zsh-history-substring-search
zgen load zsh-users/zsh-syntax-highlighting.git


# Windows-style keyboard bindings!
# https://stackoverflow.com/questions/5407916/zsh-zle-shift-selection
r-delregion() {
  if ((REGION_ACTIVE)) then
     zle kill-region
  else
    local widget_name=$1
    shift
    zle $widget_name -- $@
  fi
}

r-deselect() {
  ((REGION_ACTIVE = 0))
  local widget_name=$1
  shift
  zle $widget_name -- $@
}

r-select() {
  ((REGION_ACTIVE)) || zle set-mark-command
  local widget_name=$1
  shift
  zle $widget_name -- $@
}

for key     kcap   seq        mode   widget (
    sleft   kLFT   $'\e[1;2D' select   backward-char
    sright  kRIT   $'\e[1;2C' select   forward-char
    sup     kri    $'\e[1;2A' select   up-line-or-history
    sdown   kind   $'\e[1;2B' select   down-line-or-history

    send    kEND   $'\E[1;2F' select   end-of-line
    send2   x      $'\E[4;2~' select   end-of-line

    shome   kHOM   $'\E[1;2H' select   beginning-of-line
    shome2  x      $'\E[1;2~' select   beginning-of-line

    left    kcub1  $'\EOD'    deselect backward-char
    right   kcuf1  $'\EOC'    deselect forward-char

    end     kend   $'\EOF'    deselect end-of-line
    end2    x      $'\E4~'    deselect end-of-line

    home    khome  $'\EOH'    deselect beginning-of-line
    home2   x      $'\E1~'    deselect beginning-of-line

    csleft  x      $'\E[1;6D' select   backward-word
    csright x      $'\E[1;6C' select   forward-word
    csend   x      $'\E[1;6F' select   end-of-line
    cshome  x      $'\E[1;6H' select   beginning-of-line

    cleft   x      $'\E[1;5D' deselect backward-word
    cright  x      $'\E[1;5C' deselect forward-word

    del     kdch1   $'\E[3~'  delregion delete-char
    bs      x       $'^?'     delregion backward-delete-char

  ) {
  eval "key-$key() {
    r-$mode $widget \$@
  }"
  zle -N key-$key
  bindkey ${terminfo[$kcap]-$seq} key-$key
}