gpt4 book ai didi

vim - 缩进后返回到vim中的最后一个光标

转载 作者:行者123 更新时间:2023-12-03 23:53:36 24 4
gpt4 key购买 nike

我使用 gg=G 在 VIM 中自动格式化整个文件。整个文件缩进后,光标回到文件开头。

如何让 VIM 将光标返回到最后一个位置?假设我在第 45 行调用了命令,我希望 VIM 在缩进文件后将我返回到这一行。

编辑:如果有人感兴趣,我确实将以下命令添加到我的 .vimrc 中

" Autoformat document                                                                                                                     
nnoremap F gg=G''

因此,通过使用 Shit+f,我现在可以重新格式化整个文档并停留在同一个光标处。

最佳答案

如/u/nemo157 所述,在 How do I fix the indentation of an entire file in Vi? 的回答评论中,发出 '' 会将您返回到最后一个位置。根据 vim 文档:

                            *''* *``*
'' `` To the position before the latest jump, or where the
last "m'" or "m`" command was given. Not set when the
|:keepjumps| command modifier was used.
Also see |restore-position|.

因此,如果您执行 gg=G'',您将回到起点。

关于vim - 缩进后返回到vim中的最后一个光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22298099/

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