gpt4 book ai didi

vim - vim 中 $ 和 g_ 的区别?

转载 作者:行者123 更新时间:2023-12-04 00:47:40 24 4
gpt4 key购买 nike

我试图在 vim 中学习一些新的简洁快捷方式,我发现了 g_。根据
http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/

$  → go to the end of line
g_ → go to the last non-blank character of line

我什么时候使用 g_ 而不是 $?

最佳答案

我认为最重要的区别只是在帮助文件中说明:

:h $
In Visual mode the cursor goes to just after the last character in the line.

因此,如果您执行 v$d 它会删除包括“最后一个字符之后”的换行符,因此它将把它下面的行带到当前行。但是如果你做 vg_d 它会保留换行符。

我其实不知道 g_ ,好像有用。

编辑 由于这个答案得到了赞成,我已经使用了 g_ (及其反向, _ )制作一个映射,拉/删除当前行,不包括前导/尾随空格和换行符:
" delete/yank line, but only whitespace-trimmed version
nnoremap <Leader>dd _yg_"_dd
nnoremap <Leader>yy _yg_

关于vim - vim 中 $ 和 g_ 的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11917814/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com