visual selection in bash / cli

ⅰ亾dé卋堺 提交于 2019-12-06 03:23:29

问题


Is there a way to make bash use visual selections for text replacement?

Standard text input conventions don't work:

  1. If you press Shift+Left Arrow, the character to the left should be visually selected
  2. If you press Ctrl+Left Arrow, the cursor should move to the beginning of the previous word
  3. If you press Shift+Ctrl+Left Arrow, the word to the left should be visually selected
  4. If you visually select some text then press any key, the text should be replaced with the text of the key you press

Vi mode (set -o vi) visual selection conventions don't work:

  1. If you enter normal mode, press 'v' to enter visual selection, then press 'h', it should visually select the character to the left
  2. If you enter normal mode, press 'v' to enter visual selection, then press 'B', it should visually select the word to the left
  3. If you visually select some text and then press 'R', it should erase the text and leave you typing the replacement

回答1:


this guy did it for zsh:

I've made a VI VISUAL Mode for !ZSH. Emulates !VIM 's visual mode "v" in the cmd-line. http://bazaar.launchpad.net/~raybuntu/%2Bjunk/ZSH_stuff/annotate/head%3A/zle_vi_visual.zsh

it's awesome!




回答2:


When I want to do this in ZSH I use edit-command-line. You can add the following into your .zshrc:

autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line

Then I can just type v in command mode and it will open up my $EDITOR. You can do the same thing in Bash by just typing v in command mode without any customization.



来源:https://stackoverflow.com/questions/3464342/visual-selection-in-bash-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!