まつもとさんの日記にあった、Effective EmacsのItem3について。もしtransient-mark-mode
を有効にしているなら、C-w
はこうすればいいんじゃないかな。
1 2 3 4 5 6 7 |
(defun kill-region-or-backward-kill-word (&optional arg) "Kill a region or a word backward." (interactive) (if mark-active (kill-region (mark) (point)) (backward-kill-word (or arg 1)))) (global-set-key "\C-w" 'kill-region-or-backward-kill-word) |
zshで同じことをするならこう。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
tcsh-backward-delete-word () { local WORDCHARS="${WORDCHARS:s#/#}" zle backward-delete-word } zle -N tcsh-backward-delete-word kill-region-or-tcsh-backward-delete-word () { if [ $MARK -eq 0 ]; then tcsh-backward-delete-word else zle kill-region MARK=0 fi } zle -N kill-region-or-tcsh-backward-delete-word bindkey '^W' kill-region-or-tcsh-backward-delete-word |
zshにはtransient-mark-mode
はないので、マーク位置がバッファの先頭だったらマークされていないと見なす。
けっこう便利。
※その後変数REGION_ACTIVE
が導入されたので、今は以下でOK。(2013-10-21追記)
1 2 3 4 5 6 7 |
kill-region-or-tcsh-backward-delete-word () { if ((REGION_ACTIVE)); then zle kill-region else tcsh-backward-delete-word fi } |
ピンバック: 工夫と趣向と分別と。
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://www.binance.com/en/register?ref=JHQQKNKN