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

时间:2013-06-09 17:31:53

标签: vim

当我希望光标在Vim中转到文件的末尾(即最后一行的末尾)时,我必须输入六次击键:

<ESC>G$a - 转换为 ESC + Shift g + Shift 4 + a 在我的键盘布局上。

如何更有效地完成这项工作?

由于我经常在许多不同的机器上工作,所以我不能总是改变.vimrc,所以我在寻找答案而不必编辑或创建该文件。

15 个答案:

答案 0 :(得分:374)

这更快。只需使用此

:$

答案 1 :(得分:304)

在执行a之前无需明确转到行尾,请使用A;
在行[count]次

的末尾追加文字

<ESC>GA

答案 2 :(得分:86)

<ESC> then <SHIFT> + G

答案 3 :(得分:27)

对于初学者来说,没有必要返回。 G$会这样做。并且通过在正常模式命令的长度内计算<Esc>a来误导你。

但是,如果您愿意,可以使用<C-End>

答案 4 :(得分:25)

转到顶部-加倍 g

转到底部- Shift + g

答案 5 :(得分:16)

我认为问题是“将光标移动到vim中的文件末尾”?

文件结束:esc-G
文件开头esc-g(如果你已经在命令区域,则为gg)

答案 6 :(得分:12)

转到文件最后一行的最佳方法是使用G。这会将光标移动到文件的最后一行。

转到该行最后一列的最佳方式是使用$。这会将光标移动到当前行的最后一列。

所以只需执行G$即可到达文件末尾和最后一行。

如果您想在文件末尾进入插入模式,那么您只需执行GA。通过执行此操作,您转到文件的最后一行,并通过附加到最后一列进入插入模式。 :)

答案 7 :(得分:10)

如果你打算写下一行, ESC G o 将进行回车并让你进入下一行的插入模式line(在文件的末尾),节省了几次击键。

答案 8 :(得分:4)

这更快:

<ESC>GA

答案 9 :(得分:3)

  • first() =跳转到文件开头
  • using UnityEngine; using System.Collections.Generic; public class IntegratedScrpt : MonoBehaviour { public List<GameObject> splashImagesGOList; public float InvokeRate = 10f; public GameObject cube01; private int selection; // Loop mode variables private Vector3 startPosition; private Vector3 endPosition; private float distance = 54f; private float distanceCovered; private float currentDistance; //for Vector Lerp private float currentLerpTime = 0f; private float lerpTime = 9f; private float t; void Start() { startPosition = splashImagesGOList[1].transform.position; Debug.LogError("selection VALUE AT" + selection); endPosition = Vector3.back * distance; } void Update() { InvokeRepeating("pickpoints", 1.0f, InvokeRate); //loop mode distanceCovered = Vector3.Distance(startPosition, endPosition); currentDistance = distanceCovered * t; currentLerpTime += Time.deltaTime; if (currentLerpTime == lerpTime) { currentLerpTime = lerpTime; } if (currentLerpTime > lerpTime) { currentLerpTime = 0f; } t = currentLerpTime / lerpTime; Move(); if (currentDistance == 64) { splashImagesGOList[selection].transform.position = startPosition; Move(); } Debug.LogError("SELECTION" + selection); } // method for making the gameobjects move public void Move() { splashImagesGOList[selection].transform.position = Vector3.Lerp(startPosition, endPosition, t); } // code for instantiating the gameobjects void pickpoints() { foreach (GameObject cube01 in splashImagesGOList) { int selection = UnityEngine.Random.Range(0, splashImagesGOList.Count); // Instantiate(splashImagesGOList[selection], cube01.transform.position, cube01.transform.rotation); Instantiate(splashImagesGOList[selection], startPosition, cube01.transform.rotation); } } } =跳至文件末尾

答案 10 :(得分:3)

尝试执行SHIFT + G,您将到达页面的结尾,但您尚无法编辑

答案 11 :(得分:2)

你可以将它映射到一个键,例如F3,在.vimrc中

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

我真的不确定Shift +语法,你需要查看它,但这个想法应该是合理的。

答案 12 :(得分:0)

我一直在寻找将光标移动到行尾,然后在mac终端上进行编辑的方法,这就是它对我有用的方法。退出编辑模式,输入g_(即'g',然后下划线,前面没有冒号),然后只需按一下'a'键,即可将代码“添加”到脚本中

答案 13 :(得分:0)

另一种选择:

:call cursor('.',strwidth(getline('.')))

如果要编写函数,这可能很有用。 另一种情况是当我需要打开特定模板并跳到第一行末尾时,我可以这样做:

vi +"call cursor('.',strwidth(getline(1)))"  notetaking_template.txt

以上操作也可以通过

完成
vi +"execute ':normal! $'" notetaking_template.txt

另请参阅:

vim - Get length of the current line

答案 14 :(得分:0)

如果要在文件类型的末尾粘贴一些剪贴板内容:

previous_score = 'Score: 150\n'             #Which you read from the file with .readline()
score          = previous_score.split()[-1] #Splits a string into words. Take last item. 
print(int(score))