Vim-转到之前的位置

假设我在 Vim 中打开一个文件。我从第1行第1列开始,按住 j直到我到达第14行。按 :7CR就是7号线。我按 yy到“ yank”。

我如何返回到第14行?使用 CTRL + o将我带回到文件的顶部。``给我同样的结果。

35813 次浏览

Why not set a mark using ma for example, and then return to it later using `a or 'a?

Mark the line you were originally on using ma, then 'a to return there.

<C-o> and <C-i> allow you to go down and up the jumplist. They work with "jump" commands but not with jjjjjjjjjjj.

To take advantage of this feature — and save a lot of time and keypresses in the process — I'd advise you to get into the habit of using better ways to navigate through your code : /?^$fFtTbBeEwW{} and so on.

And yes, use marks.

You can type 7G to jump to line#7, then type Ctrl-o to jump back.
:set showcmd to show what you have typed at the right bottom.


To yank line#7 (No cursor moving):

:7y

To paste line#7 below line#14:

:7t14

One more way: To jump back to another line, you can use ''. This works similar to an automatic mark, which is set for certain jump movements.

If you want to return to a previous location, first you have to mark that location using the mark (m) command, followed by any letter a-z or A-Z, like ma to mark a location as 'a'.

To return to that location you would enter `a.