简体   繁体   English

图形和控制台Emacs之间的不同选择行为(23)

[英]Different selection behaviours between graphic and console Emacs (23)

Emacs n00b here, I've fiddled a bit with it in graphical mode and so far I've found it great. Emacs n00b在这里,我在图形模式下对其进行了一些修饰,到目前为止,我发现它很棒。 I wanted to give the terminal version a try and found out that there's a few annoying behaviour differences, in particular with shift-selection. 我想尝试一下终端版本,发现有一些烦人的行为差异,特别是在换档时。

In graphical mode I can combine shift selection (ie holding shift to set a mark) with the arrow keys, the control key (to select whole words) or the origin or end keys (to select the whole/a large part of a line). 在图形模式下,我可以将换档选择(即按住换档以设置标记)与箭头键,控制键(以选择整个单词)或原点或结束键(以选择整个行/大部分行)结合使用。

In terminal mode the keys work fine on their own (I can select regions while holding shift and moving with the arrow keys*, C-left/right allows me to jump whole words, origin and end bring me where I want to go) but I can't combine them (can't select whole words by holding shift and C-arrowing, or select the remaining part of a line with shift-end or shift-origin). 在终端模式下,按键可以单独正常工作(我可以在按住shift键的同时选择区域,并使用箭头键*,C向左/向右键可让我跳过整个单词,起点和终点将我带到我想去的地方),但是我无法将它们组合在一起(无法通过按住shift和C箭头选择整个单词,或选择带有shift-end或shift-origin的行的其余部分)。

I also found that C-backspace didn't work (ie didn't erase the whole word) in console while it does in window mode, though I read about M-backspace after looking for a solution. 我还发现,尽管在寻找解决方案后了解了M-backspace,但是C-backspace在控制台模式下却无法在控制台中运行(即没有擦除整个单词)。

I searched as thoroughly as I could but could not find how to get the terminal version to behave like the graphical version... Lots of people seem to ask questions about Emacs's shift selection but none of them have quite the same problem... Can someone explain where those behaviour differences come from? 我进行了尽可能详尽的搜索,但是找不到如何使终端版本像图形版本一样运行...很多人似乎在询问有关Emacs班次选择的问题,但没有一个问题完全相同...可以有人解释这些行为差异来自何处?

Thanks in advance. 提前致谢。

*Though, holding shift, if I go down (with the arrow key) to select whole lines, I can't go up again to unselect them (" is undefined"). *尽管按住shift键,但如果我向下(使用箭头键)选择整条线,则无法再次向上取消选择它们(“ undefined”)。

[edit /] Okay, so obviously this comes from the fact that my terminal doesn't have the same shortcuts as graphical Emacs does. [编辑/]好吧,很明显,这是因为我的终端没有图形化Emacs相同的快捷方式。 Fair enough. 很公平。 I see a couple of solutions here: 我在这里看到一些解决方案:

  • getting used to default Emacs shortcuts 习惯默认的Emacs快捷方式
  • filling my .emacs with global-set-key's. 用全局设置键填充我的.emacs。 Although I tried 虽然我尝试过
    \n(fset 'select-to-end (fset'选择结束\n[(kbd "C- <spc> <end> ")]) [(kbd“ C- <spc> <end> ”)])\n(global-set-key (kbd "S- <end> ") 'select-to-end) (全局设置键(kbd“ S- <end> ”)'选择端)\n
    but it doesn't work as I intend it to -_- 但它无法正常工作-_-

The short answer is "if you're happy using different keystrokes, that might be easier". 简短的答案是“如果您愿意使用不同的击键,那可能会更容易”。 Personally, I'm a little neurotic about my keybindings and configuration, so I rarely go with this one; 就我个人而言,我对我的键绑定和配置有些神经质,因此我很少去使用它。 in particular, it's frustrating when emacs modes override your bindings. 特别是当emacs模式覆盖您的绑定时,这令人沮丧。 (I don't know if you've yet discovered that global-set-key really means "let anyone in the universe stamp on my keybinding".) (我不知道您是否已经发现global-set-key真正含义是“让宇宙中的任何人都在我的绑定上盖章”。)

The longer answer to your question is "someone along the chain is ignoring your control characters, so you need to figure out who it is, fix it, and then repeat". 对于该问题的更长的答案是“链中有人忽略了控制字符,因此您需要弄清楚它是谁,修复它,然后重复”。 For the keybindings you're talking about here -- CS-<arrows> -- you can definitely get this to work; 对于这里要讨论的键绑定CS-<arrows> –您绝对可以使它起作用; if you want something like \\C-~ , you're going to have a much harder time. 如果您想要\\C-~类的东西,您将遇到更多困难。 (The issue is that some bindings didn't make sense in legacy terminals, so you basically have to use a nonstandard set of control codes to transmit the key combination, and then teach each program to recognize it. This is usually where a termcap comes in, since it's a common language for teaching programs about key events.) (问题是,某些绑定在旧版终端中没有意义,因此,您基本上必须使用一组非标准的控制代码来传输键组合,然后教每个程序识别它。这通常是termcap出现的地方,因为它是用于教授有关关键事件的程序的通用语言。)

Here are the steps I usually take: 这是我通常采取的步骤:

  • Start with your terminal. 从您的终端开始。 You can use \\Cv and then hit a key to insert the literal keystroke (at least in bash) -- start by doing this with C-left, S-left, and CS-left. 您可以使用\\Cv ,然后按一个键以插入文字击键(至少在bash中)-首先从C左,S左和CS左开始。 Confirm that you're getting three different control codes. 确认您得到三个不同的控制代码。
  • If you're not, you need to investigate either (1) your readline settings, (2) your terminal program settings or (3) your termcap settings. 如果不是,则需要调查(1)您的readline设置,(2)您的终端程序设置或(3)您的termcap设置。 Since TERM is xterm , the termcap should be fine. 由于TERMxterm ,因此termcap 应该很好。 I don't know what terminal program you're using, but it may have its own key configuration. 我不知道您使用的是哪种终端程序,但是它可能具有自己的密钥配置。 (For instance, I use a mac and use iTerm2, which is usually my first stop.) If you're going to be spending time at a terminal anyway, you should definitely take the time to read the readline manual and play with your .inputrc a bit. (例如,我使用Mac并使用iTerm2,这通常是我的第一站。)如果您无论如何都要在终端上花费时间,则绝对应该花时间阅读readline手册并使用.inputrc有点。
  • This chain is short: next is emacs. 这条链很短:接下来是emacs。 You can use \\Cq in emacs to do the same thing \\Cv does in bash, or use \\Ch k to find out what the default bindings are. 您可以在emacs中使用\\Cq在bash中执行\\Cv相同的操作,或者使用\\Ch k来查找默认绑定。 Again, start by making sure emacs sees distinct key events for the combinations you're interested in. If not, you'll probably want to start by looking at term/xterm.el in your site-lisp directory and modifying it to your liking. 再次,请确保emacs可以看到您感兴趣的组合的不同键事件。否则,您可能需要先查看site-lisp目录中的term/xterm.el ,然后根据自己的喜好对其进行修改。 。

If you're using tmux or screen , they also get a hand in this, and can usually be tamed. 如果您使用的是tmuxscreen ,他们也可以帮screen忙,通常可以驯服。 The process for finding those problems is the same as bash -- use \\Cv and man tmux to figure out how to get your extra keybindings. 查找这些问题的过程与bash相同-使用\\Cvman tmux找出如何获取额外的键绑定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM