移动到代码行的开头:Emacs
我使用 emacs 进行开发,经常需要移动到行首 (Ca)。但是,如果该行缩进,我想移动到代码开始的位置。
因此,在浏览代码时:( ) for x in xy|z:
。输入 Ca 后,我们得到:|( ) for x in xyz:
。但相反,我想要这样:( ) |for x in xyz:
Here |表示光标,() 表示空格或制表符。
我怎样才能做到这一点?
I use emacs for development and very often need to move to the start of a line (C-a). However if the line is indented, I'd like to move to the point at which code starts.
So while browsing code: ( ) for x in xy|z:
. On typing C-a we get this: |( ) for x in xyz:
. But instead, I would like this:( ) |for x in xyz:
Here | indicates cursor and () indicate spaces or tabs.
How can I make make this happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
元-米
Meta-m
我最喜欢的处理这个问题的方法是让 Ca 在行的开头和代码的开头之间切换。您可以使用此函数来执行此操作:
并将适当的绑定添加到您最喜欢的模式映射中:
A favorite way for me to handle this is to have C-a toggle between the beginning of the line and the beginning of the code. You can do so with this function:
And add the appropriate binding to your favorite mode map:
我使用与 Trey 相同的切换技巧,但默认为缩进而不是行首。它需要稍微多一些的代码,因为据我所知,没有“缩进开始”函数。
这可能会让您继续使用 Ctrl-a 并让它执行您最常用的操作,同时仍然能够轻松获得内置行为。
I do the same toggling trick as Trey, but defaulting to indentation instead of to beginning of line. It takes slightly more code because there's no "at-beginning-of-indentation" function that I know of.
This will probably let you continue to use Ctrl-a and have it do what you want most often, while still being able to get the built-in behavior easily.
默认情况下,Meta-m 运行 < code>back-to-indentation 根据 文档将“将指向移动到该行的第一个非空白字符。”
By default, Meta-m runs
back-to-indentation
which according to the documentation will "Move point to the first non-whitespace character on this line."现代 IDE 中的常见习惯用法是在第二次按下时在第一个/最后一个非空白处移动:
此代码首先移动到实际的开始/结束,新的行为将在后续按下时显示。因此,任何旧的键盘宏都将按预期工作!
Common idiom among modern IDE is to move at the first/last non-whitespace on second press:
This code firstly move to actual begin/end, new behavior show up on subsequent presses. So any old keyboard macros will work as expected!