我如何去第一行在一个文件在vim ?
转到第一行
:1 或Ctrl + Home
到最后一行
: % 或Ctrl +结束
转到另一行(第27节)
27:
[VIM 7.4(2016)和8.0(2018)上的作品]
解决方案
移动到文件的真正起始字符,即使它是一个空白字符,只输入两个字符:
go
转到缓冲区中的[count]字节。默认[count]是1,开始 该文件。
可以说,它甚至比gg更容易记住(例如,助记符:“只要回到文件的真正开始!”),但就最小的手指运动(或使用一只手的单个手指敲击这种特定的“光标运动节拍”的能力而言,它可能不如gg舒服。)
不幸的是,gg有一个“限制”,即当第一行的起始字符以及后面的字符恰好是空格时,它不会指向真正的起始字符。
以下其他选项也有相同的限制:
1克 : 1 < CR > < Ctrl > - <家>
选择
与gg0一起,输入<Ctrl>-<Home> <Home>确实执行所需的光标移动到文件的真正第一个字符。使用类似后一种选择的组合似乎与ViM原则背道而驰,但谁知道呢,可能有人更喜欢这种特定的(逻辑上的)两个键击变化,这就是为什么我将其作为一种潜在的选择来介绍。
题外话
Somewhat perplexingly, <Ctrl>-<End> does position the cursor at the true last character of the file, whitespace or not, and is probably the only single (logical) key stroke to do so. Personally, I prefer G$ (or the far more contrived Gg_ to position the cursor at the last non-whitespace character of the file), but if my fingers just happen to be "on the long road home after visiting other relatives in that far away neighborhood of the keyboard and there is a pressing need to stop for gas at the end of the file," well, you just might catch me "breaking the rules" and striking <Ctrl>-<End> to "get the job done."
限制
开始工作的唯一先决条件是ViM在编译时启用了byte_offset特性(即+byte_offset)。幸运的是,默认情况下启用了该特性。
To check your particular build of ViM for this feature, you can use the :ve[rsion] command or vim --version from the command line. Both of these display the values of all of the build-time features that were in effect when the instance of ViM being tested was compiled. It is a good idea to commit these all-feature query commands to memory, btw, since the ViM help often refers to feature based restrictions while explaining commands and topics whose availability and/or effect is build feature controlled or restricted.