0

Let's say I create a macro that goes down one line.

qajq

Register a contains exactly qajq, and so @a moves me down one line.

Now let's say I type j into my buffer and yank it into register a using "ayy. Now, register a looks like j^J (notice the terminal newline digraph). Now, when I execute the macro a, it jumps down two lines.

What exactly is happening here? Does Vim see the ^J digraph and think that I want to go down an extra line, or is it something more subtle?

I guess this is one of those questions where the answer is, "because that's how it was designed." :P

Raimondi
  • 5,163
  • 31
  • 39
pushkin
  • 9,575
  • 15
  • 51
  • 95

2 Answers2

2

After you type qajq the a register content is the string j. qa starts recording the macro into register a, then you type j and it's the first character recorder, now you type q and vim stops recording. So, you end up with just j in the register a.

The command yy works linewise, so the newline is also inserted into the register. When you type "ayy you end up with j^J in the a register because ^J or Ctrl-J (a line feed) is what vim uses to represent the newline, and it also moves the cursor one line down as described in :help Ctrl-J

In order to yank the line without the newline you can type 0"ay$. That would be the same as typing qajq.

Raimondi
  • 5,163
  • 31
  • 39
0

I don't make sure what happen on your vim. But I'd say what vim should work as right behavior.

You type qajq. So motion j is registered into register a. And you seems type yy to register something into register a. But As far as I know, it register into register " not register a. To yank something into register a, you should type "ayy. It's possible to confirm with :register command. Maybe something wrong typing?

mattn
  • 7,571
  • 30
  • 54