将光标移动到vim中的文件末尾

在Vim编辑器中,通常需要输入多个键来将光标移动到文件的末尾。一种高效的方法是使用组合键ESC + Shift g,但这在不同机器上可能有所不同。在.vimrc文件中映射快捷键如F3也是一种解决方案,或者直接使用命令。帖子中的讨论提供了多种快捷方式,如 或 ,甚至更快的方式是 。对于在文件末尾进入插入模式,可以使用 。这些技巧能帮助用户更便捷地操作Vim。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文翻译自:Move cursor to end of file in vim

When I want the cursor to go to the end of the file (ie the end of the last line) in Vim, I have to type six keystrokes: 当我希望光标在Vim中转到文件的末尾(即最后一行的末尾)时,我必须输入六个键击:

<ESC>G$a - which translates to ESC + Shift g + Shift 4 + a on my keyboard layout. <ESC>G$a - 在我的键盘布局上转换为ESC + Shift g + Shift 4 + a

How can I do this more efficiently? 我怎样才能更有效地做到这一点?

Since I regularly work on many different machines, I cannot always change .vimrc, so I'm looking for answers without having to edit or create that file. 由于我经常在许多不同的机器上工作,我不能总是改变.vimrc,所以我在寻找答案而不必编辑或创建该文件。


#1楼

参考:https://stackoom.com/question/19Ng4/将光标移动到vim中的文件末尾


#2楼

You could map it to a key, for instance F3, in .vimrc 您可以将它映射到.vimrc中的键,例如F3

map <F3> <Esc>Shift+G<CR>Shift+4<CR>a

I'm really not sure about the Shift+ syntax, you'll need to look that up, but the idea should be sound. 我真的不确定Shift +语法,你需要查看它,但这个想法应该是合理的。


#3楼

No need to explicitly go to the end of line before doing a , use A ; 无需显式地去行结束前做a ,使用A ;
Append text at the end of line [count] times 在行[count]次结束时附加文本

<ESC>GA


#4楼

For starters, there's no need for the return. 对于初学者来说,没有必要返回。 G$ will do. G$会的。 And you're being misleading by counting <Esc> and a in the length of a normal mode command. 和你被计数误导<Esc>a在正常模式命令的长度。

However, you can use <C-End> if you like. 但是,如果您愿意,可以使用<C-End>


#5楼

The best way to go to the last line of the file is with G . 转到文件最后一行的最佳方法是使用G This will move the cursor to the last line of the file. 这会将光标移动到文件的最后一行。

The best way to go to the last column in the line is with $ . 转到该行最后一列的最佳方法是使用$ This will move the cursor to the last column of the current line. 这会将光标移动到当前行的最后一列。

So just by doing G$ you get to the end of the file and the last line. 所以只需要做G$可以到达文件末尾和最后一行。

And if you want to enter insert mode at the end of the file then you just do GA . 如果您想在文件末尾进入插入模式,那么您只需执行GA By doing this you go to the last line of the file, and enter insert mode by appending to the last column. 通过执行此操作,您转到文件的最后一行,并通过附加到最后一列进入插入模式。 :) :)


#6楼

这更快:

<ESC>GA
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值