linux下编辑文件时如何定位光标到文件末尾

我记得上次我在咖啡馆写代码,突然我不得不修改一个数百行的日志文件。
我手头只有一台旧笔记本电脑,系统安装的是Linux。
打开终端并输入“vi access.log”。
屏幕上会出现一行小字,就像看小说一样。

光标在第一行开头,我想跳到最后一句进行记录。
如果你盲目地按键盘上的‘j’‘j’,你必须按一百多次才能向下移动。
突然我想起了老张教我的方法。
我按“gg”,光标就会跳起来。
然后输入“G”,好了,我们到达最后一行。
但是这句话还在后面,我还得按‘→’‘→’‘→’……等等,‘G’后面可以跟数字吗?我尝试了“5 0G”,果然它跳到了第 5 0 行。
等等,还有一件事。
有时文件太大,“gg”响应缓慢。
您可以尝试“1 G”直接进入第一行。

我突然想到,如果光标已经在中间了,我想跳到第1 5 0行,用“gg”然后输入“1 5 0G”是不是有点冗长? ‘5 0G’跳到5 0,然后按‘→’‘→’‘→’……这样可以吗?或者使用'ngg',例如'3 gg'跳转到第3 行?不,我尝试了“2 gg”,光标实际上跳转到第 2 行。
那么“ngg”应该跳转到第 n+1 行吗?
不过话说回来,使用vim的时候,好像有光标位置的记忆功能?关闭文件并重新打开它,您仍然会记得上次所在的位置。
这样就省了麻烦。

在linux命令行下从一行跳入下一行命令,不输入回车,输入什么命令

说实话,我已经好几次把这些键盘快捷键搞混了,尤其是$和^,每次都要在文档中来回查看才能确认。
Let's take nG for example. The last time I processed a 5 00 line log file, I wanted to jump to line 1 2 7 to see the error stack. My hand was shaking and I pressed 2 G and it got stuck on the second line. I was sweating really hard at the time.
n$ This command is interesting. I've used it often when writing shell scripts.请记住:如果要更改配置文件中特定行的最后一个单词,可以先使用 n$ 找到该行的末尾,然后直接开始删除。
This is much more efficient than moving the cursor character by character. But be careful when using it. If the value of n is too large, it may jump straight to the end of the file. For example, $5 0 equals $1 0 in a 1 0-line file.
I am particularly impressed with the M command. When I edit a code file of several hundred KB using Vim, the screen only shows a small snippet in the middle. If you want to see the beginning or end, you have to jump there with M and then position it with 0 and ^, otherwise your eyes will be blinded. At that time I also thought about why M shows the middle line? It's probably the middle position, which is calculated by default based on screen height. I have not personally run the specific algorithm for this.
L and H are relatively easy to remember. L is the last line of the screen and H is the first line. When debugging code, I often use L to quickly find the last few lines where problems may occur and use . to repeat the last change process.但有一个陷阱。
如果文件的行数不是屏幕的整数倍,例如2 3 行的文件在2 4 行的屏幕上,按L可以跳转到倒数第二行。
To do this, it is necessary to know in advance the total number of lines in the file.
h, j, k, l These arrow keys are more common, but h and H are the most confusing, especially when typing on the keyboard in the dark.记得有一次深夜排错的时候,我的手在颤抖,我按了H。
本来我想回到第一行,把临时代码注释掉,结果又回到文件头,几乎把整个文件都删除了。

These keyboard shortcuts are real efficiencies that make money, but they must be used in conjunction with specific scenarios. For example, if you're processing very long files, nG is much faster than pressing j line by line. However, if you adjust the code format, h,j,k,l is more practical than 0x0x0. At the time, I didn't understand why the designer was so detailed about the positioning of the row headers. This could be because early terminal screens were small and required precise control.