7

I am a moderately experienced vim user, who is now beginning to use GNU emacs. At about the same time as I learned that Ctrl-p and Ctrl-n are the default for up and down in emacs, I also learned they are variants of k and j in normal mode in vim.

Does anyone know the origin of these shortcuts? I suppose that logically they come from p(revious) and n(ext), or maybe (u)p and (dow)n, but I am asking about what programme, system or standard they were part of. It seems unlikely that a couple of random emacs shortcuts were borrowed into vim, so their inclusion in both makes me think that they probably predate both emacs and vim.*

It's hard to find the answers to questions of keystrokes using Google, but interestingly they are not mentioned as "arrow keys" on the seemingly comprehensive Wikipedia article.

*Thanks to Thomas Dickey and Mark Plotnick who have pointed out in comments that the shortcuts in question are documented in 1984 vi (sic), and 1978 emacs reference works, but I think the question of common origin still stands.

  • In emacs (or bash/ksh in emacs mode), I use Previous/Next as a reminder of which way to go. along Forward/Backward. – Archemar Apr 15 '16 at 17:10
  • @Archemar Ah yes, that makes more sense. I've added that in as a more logical origin, but my historical question still stands :-) – harlandski Apr 15 '16 at 17:14
  • They predate vim, e.g., are documented in the 1984 "vi user's handbook". – Thomas Dickey Apr 15 '16 at 20:09
  • The earliest reference I can find for "n for next, p for previous" for the Emacs lineage is AI Memo 447 - An Introduction to the EMACS editor from 1978. It's possible that one of Emacs' predecessors such as RMODE also used n for next and p for previous, but I couldn't find a reference. – Mark Plotnick Apr 15 '16 at 20:12
  • For what it's worth, it's also mentioned in An Introduction to Display Editing with Vi, which is about as old. It didn't come from TECO or SOS. – Thomas Dickey Apr 15 '16 at 20:40
2

I cannot provide proof of any kind, but Ctrl-P and Ctrl-N belong to the emacs key bindings, in contrast to vi bindings (bindkey -e vs. bindkey -v). Under this premise, you should look for an explanation in emacs itself.

emacs' tutorial tells

There are several ways you can do this. You can use the arrow keys, but it's more efficient to keep your hands in the standard position and use the commands C-p, C-b, C-f, and C-n. These characters are equivalent to the four arrow keys, like this:

  • Previous line, C-p
  • Backward, C-b
  • Forward, C-f
  • Next line, C-n

Seems inconvenient for the common vi user, but makes absolute sense.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.