Emacs:将点移动到最后一个非空白字符

Sab*_*lfy 3 emacs

M-m(back-to-indentation)将点移动到该行上的第一个非空白字符.我想做相反的事情:将点移动到该行上的最后一个非空格字符.我一直无法找到一个"内置"命令,而且我对ELisp不够熟悉,所以请任何帮助.

phi*_*ils 6

(defun my-move-end-of-line-before-whitespace ()
  "Move to the last non-whitespace character in the current line."
  (interactive)
  (move-end-of-line nil)
  (re-search-backward "^\\|[^[:space:]]"))
Run Code Online (Sandbox Code Playgroud)


Der*_*ger 5

通常在这种情况下,我想获得最后一个非空白字符并删除尾随空格,所以我使用这个:

M-\ runs the command delete-horizontal-space, which is an interactive
compiled Lisp function in `simple.el'.
Run Code Online (Sandbox Code Playgroud)

在极少数情况下,我想保留空白,我只使用M-b M-f( backward-word, forward-word),这通常足够接近。

  • 是的,所以 `Ce` `M-\\` 是一种替代解决方案,它将点移动到行尾,然后删除额外的空格。谢谢。 (2认同)