0

I am trying to set up an abbreviation for :pu as :p, so it is more consistent with :y and :d.

cnoreabbrev p pu

However this doesn;t work. It will just return cnoreabbrev p pu on the command message without doing anything. Why is that?

Edit

Taking this text as an example, where [] is the cursor

hel[]lo
world
foo

I run :2y to copy line 2, and I want to paste it after line 3 with :3p, instead of :3pu.

Didn't realize :p represent :print, is it possible for me to overwrite that, making :p to represent :pu?

3
  • 1
    What are the steps you are taking? Eg, run the command, then type :p ? Or something else? By default p is short for print, which prints the current line without a range.
    – D. Ben Knoble
    Commented Apr 25, 2021 at 12:40
  • Didn't realize :p represents :print. How can I overwrite that? I have updated my question with an example. Commented Apr 25, 2021 at 14:58
  • 1
    The abbreviation actually works as expected... But it only recognizes p as a word by itself. So :3 p will trigger it (as :3 pu) while :3p will not. Also note that the abbreviation triggers elsewhere in the command line (and search prompt, etc.) so it has many adverse side effects!
    – filbranden
    Commented Apr 25, 2021 at 21:17

1 Answer 1

2

In general you can't rename built-in commands (the ones started with lowercase letters).

So no, you can't make :p represent :pu.

But you can use :copy (that has builtin synonym :t) and/or :move commands.

In you case it is simple:

:t3
3
  • This is very useful. Looking at :help :copy right now, it seems that this command is not binded to any key by default? Commented Apr 25, 2021 at 15:44
  • @JohnWinston It's not much different from Y/:yank followed by 3jp or :+3put; it's just ex versus normal and is linewise. :copy does have advantages! e.g., no cursor movement, arbitrary ranges, etc. Just different styles of doing things.
    – D. Ben Knoble
    Commented Apr 25, 2021 at 15:51
  • Or is this key possible to be binded? Unlike other command, this key requires a range and an address. Commented Apr 25, 2021 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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