LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   vi editor - yank and paste problem (https://www.linuxquestions.org/questions/linux-newbie-8/vi-editor-yank-and-paste-problem-819560/)

chekhov_neo 07-13-2010 05:50 AM

vi editor - yank and paste problem
 
Hi,

I have a peculiar problem in vi editor. When I yank('y') a text and paste('P'), the text which is below gets shifted right instead of shifting down.

e.g.

in the following text:

Line 1
Line 2
Line 3
Line 4
Line 5

if I yank the first two lines and paste it before "Line 3", I'm getting the following output:

Line 1
Line 2
Line 1Line 3
Line 2Line 4
Line 5


when I want it to be like this:

Line 1
Line 2
Line 1
Line 2
Line 3
Line 4
Line 5

My vimrc file has the following contents:

syntax on
set paste
colorscheme darkblue
set tabstop=4
set noai
set shiftwidth=4
set smarttab
set expandtab
set softtabstop=4

---------------
Please help!

tronayne 07-13-2010 06:29 AM

Trying the above with vi (not vim), everything works as expected; i.e., get on the first line, type 2yy, get to line 4, type p, viola. Do similar things and use upper case P (to paste above) and lower case p (to paste below) and all is well.

Hmm.

Did the same thing in vim, same results.

Hmm.

So vim settings are
Code:

  autoindent          hlsearch            ruler              ttymouse=xterm2
  backup              incsearch          showcmd
  helplang=en        modified            showmatch
  history=50          mouse=a            ttyfast
  backspace=indent,eol,start
  backupskip=/tmp/*,/var/spool/cron/*

(So are vi settings).

The only thing I have "different" is a .exrc file (that sets things for vi)
Code:

cat .exrc
set autoindent showmode showmatch

Maybe comment everything in your .vimrc then un-comment one-by-one?

Hope this helps some.

grail 07-13-2010 06:52 AM

Just to confirm ... the file was not created in Windows? Sometimes the funky characters at the end make weird stuff happen.

chekhov_neo 07-13-2010 07:08 AM

Hi,

I guess I figured out the problem. I use visual mode to yank the text. So what I did was

1. Press Ctrl+V to go to visual mode
2. Press 'y' to yank the text.
3. Press 'p' to paste the text.

In the above case, the text which were present already were shifting right. But when I used 'yy' in step2 the text shifted below! So 'y' and 'yy' seem to have different usages.

grail 07-13-2010 09:34 AM

'y' is to yank what you wanted, ie yw - will yank a word
'yy' is to yank an entire line, ie yank yank is from start to end of single line


All times are GMT -5. The time now is 06:38 PM.