emacs 相当于 vim 的 shift-h 和 shift-l
我想知道 emacs 是否内置了这些光标移动命令,或者我是否必须编写它们或在某处找到一个片段。我发现它们非常漂亮并且经常在 vim 中使用它们。到目前为止我还没有在 emacs 的文档中找到它们。
在 vim 中,它们看起来像这样: Shift-h ->;将光标移动到屏幕顶部 Shift-m ->;将光标移动到屏幕中间 Shift-l ->;将光标移动到屏幕底部
只是为了澄清,我不想将光标移动到文档的顶部/底部,只是移动到文档当前可见部分的顶部/底部,即当前的部分正在显示在屏幕上。
到目前为止我找到了其中之一。 alt-r 似乎相当于 vim 的 shift-m。它将光标移动到中间行的第一列。
i'm wondering if emacs has these cursor movement commands built in or if i'm going to have to write them or find a snippet somewhere. i find them pretty spiffy and use them in vim regularly. i haven't found them in emacs' documentation so far.
in vim, they look like this:
shift-h -> move cursor to the top of the screen
shift-m -> move cursor to the middle of the screen
shift-l -> move cursor to the bottom of the screen
just to clarify, i'm not looking to move the cursor to the top/bottom of the document, just to the top/bottom of the currently visible part of the document, i.e. the part that's currently being displayed on screen.
i found one of them so far. alt-r seems to be the equivalent of vim's shift-m. it moves the cursor to the first column of the middle line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用:
Alt+0 Alt+r
- 窗口顶部Alt+- Alt+r
- 窗口底部严格来说,这些应该写为
M-0 Mr< /code> 表示屏幕顶部,
M-- Mr
表示屏幕底部。其中M
表示Meta
键,通常映射到Alt
。我计算出这些击键如下:
Mr
运行命令move-to-window-line
。我通过Ch k Mr
发现了这一点,即。Ctrl+h
、k
、Alt+r
。 按键序列Ch k
意味着告诉我下一个按键序列的作用。 它告诉我命令名称,并且您可以将数字参数传递给命令以选择您想要转到的行。如果您没有通过任何操作,它会将点移动到窗口的中间,如您所见。您可以通过在按住 Meta 的同时键入数字来将数字参数传递给命令。减号本身表示-1。现在,要移动到屏幕顶部,我们要传递第 0 行,而移动到屏幕底部则传递 -1 行。这给了我们上面的按键序列。
如果要将
move-to-window-line
绑定到不同的键 看看乔对此问题的回答。Use:
Alt+0 Alt+r
- top of WindowAlt+- Alt+r
- bottom of WindowStrictly, these should be written as
M-0 M-r
for the top of the screen andM-- M-r
for the bottom of the screen. WhereM
means theMeta
key which is usually mapped toAlt
.I worked out these keystrokes as follows:
M-r
runs the commandmove-to-window-line
. I found this out withC-h k M-r
, ie.Ctrl+h
,k
,Alt+r
. The key sequenceC-h k
means tell me what the next key sequence does. It told me the command name and also that you can pass numeric arguments to the command to pick the line you want to go to. If you don't pass any it moves the point to the middle of the window as you have seen.You pass numeric arguments to commands by typing a number while holding down Meta. A minus sign on its own is taken to mean -1. Now, to move to the top of the screen we want to pass line 0 and for the bottom of the screen line -1. This gives us the key sequences above.
If you want to bind
move-to-window-line
to a different key look at Joe's answer to this question.您希望使用的函数是
move-to-window-line
,其定义是:您可以使用
0
调用它以转到页面顶部,然后使用-1
转到页面底部。这些可以通过匿名函数或命名函数绑定到键。给出了两者的例子。匿名函数
命名函数
The function you wish to use is
move-to-window-line
, whose definition is:You would call it with a
0
to go to the top of the page and a-1
to go to the bottom of the page. These can be bound to a key with an anonymous function or a named function. Examples of both are given.Anonymous Functions
Named Functions
在 Emacs 23.2 中,Mr 完全按照您的意愿行事。
第一次调用此命令会将点移动到当前可见窗口的中心,接下来的连续调用会移动到顶部和底部。
无需额外配置或自定义功能。
In Emacs 23.2, M-r does exactly what you want.
The first invocation of this command moves the point to center of the currently visible window, the next successive invocations move to top and bottom.
No additional configuration or custom functions needed.
要添加到 Joe 和 Dave 的答案中,您可以使用以下内容:(
我将
bp
添加到我所有函数的前面,以将它们与内置函数或其他人的函数区分开来...请随意删除那。)To add to Joe's and Dave's answers, you can get middle with:
(I add
bp
to the front of all my functions to distinguish them from built-ins, or other people's... feel free to remove that.)我发现
move-to-window-line
不尊重window-buffer-height
。因此,当缓冲区大小小于窗口时,它实际上并没有提供 Vim 的行为。由于我不从终端使用 Emacs,也不关心最小化它的框架,所以我选择重用它的前缀键,因为 'z' 让我想起 Vim 的zt
,zm
和zb
(也因为我将使用以下内容与 Emacs 的Cl
组合来实现相同的整体效果)。I've found that
move-to-window-line
doesn't respectwindow-buffer-height
. Thus, it doesn't actually provide the behavior Vim has when the buffer size is smaller than the window. Since I don't use Emacs from a terminal, nor do I care about minimizing its frame, I've chosen to reuse its prefix key because the 'z' reminds me of Vim'szt
,zm
, andzb
(and also because I'm going to use the following in combination with Emacs'C-l
to achieve the same overall effect).如果您使用的是 Emacs 23,则只需
Cl
。第一次会到中心,第二次会到顶部,第三次会到底部。编辑:
哎呀,我的错,这将当前行放在窗口的中心/顶部/底部。不过还是有用的:)
If you are using Emacs 23, it's simply
C-l
. The first time it will go to the center, the second time it will go to the top, the third time it will go to the bottom.EDIT:
Oops, my bad, that puts the current line in the center/top/bottom of the window. Still useful though :)