VimArea - Day 10 - The wicked PUT command
There are things you'll never realize until you've tear it down and see what's inside.

The p and y commands we uses frequently. The behavior seemed natural and we didn't suspect a thing. But when it comes to making these commands. I realized they didn't act what they supposed to do logically.

Say if you want to yank a word, you type in diw then put it somewhere. And you want to yank some range of texts, you could just go into the VISUAL mode and select your text and then type y. Everything looks OK, right?

However, when it comes to line crossing motion1, the put command behaves differently. When you yank a line by typing yy, the line which the cursor is resided in is being yanked. Then you type p to duplicate this line. This behavior was so natural we just take it as granted.

But what it should be doing, logically, is the line being yanked should NOT be put under a new line. What it should be doing is to put the yanked content after the cursor position.

Vim yank, put behavior

Let's say your cursor position is at "G", you yank this line by using "yy".
Then you immediately put it by typing "p" ( content is put under a new line ).

Before:

  aaGaa
  bbbb


After:

  aaGaa
  aaGaa
  bbbb


What it should be doing logically ( content is put after the cursor position! ).

After:

  aaGaaGaa
  aa
  aaGaa
  bbbb
( This however using VISUAL and highlight the entire line manually does not produce the same effect. I guess it is an effort to tell Vim to not do this? )

At this point my mind was blown. Sometimes *logical* is not the way to go. But when it comes to development, it always starts with logical. If I was the originally developer I'd probably go with the logical way and never thought that there were better way to implement it.

And this also means more case to handle. And more codes.

Articles in the series


Useful Links

Project home | Demo

  1. Line crossing motions are motions that crosses one or more lines. ( i.e. \n )
Tag(s): vim BotanJS
Profile picture
斟酌 鵬兄
Thu Mar 31 2016 14:15:05 GMT+0000 (Coordinated Universal Time)
Last modified: Wed Apr 06 2016 19:49:08 GMT+0000 (Coordinated Universal Time)
Comments
No comments here.
Do you even comment?
website: 
Not a valid website
Invalid email format
Please enter your email
*Name: 
Please enter a name
Submit
抱歉,Google Recaptcha 服務被牆掉了,所以不能回覆了