Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which .vimrc setting causes this weird copy-paste behaviour?

Tags:

linux

vim

I recently copy-pasted a bunch of .vimrc settings from somewhere, and now I have this weird behaviour on text copy paste:

  1. alt text

  2. Ctrl + C

  3. Shift + Insert

  4. alt text

I thought it would be autoindent but it is not.

What should I remove from my .vimrc to stop this behaviour and enable normal copy paste?


The fault is somewhere in this part of my .vimrc :

command -range=% -nargs=* Tidy <line1>,<line2>!
    \perltidy -your -preferred -default -options <args>

vmap <tab> >gv 
vmap <s-tab> <gv

nmap <tab> I<tab><esc>
nmap <s-tab> ^i<bs><esc>

let perl_include_pod   = 1
let perl_extended_vars = 1
let perl_sync_dist     = 250

filetype off
set nocompatible
set modelines=0

set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set ic
set ai
set nu

command -range Cm <line1>,<line2>s/^/#/
command -range Uc <line1>,<line2>s/^#//

set encoding=utf-8
set scrolloff=3
set autoindent
set showmode
set showcmd
set hidden
set wildmenu
set wildmode=list:longest
set visualbell
set ttyfast
set ruler
set backspace=indent,eol,start
set laststatus=2

let mapleader = ","
nnoremap <leader>1 yypVr-
nnoremap <leader>2 yypVr=

set ignorecase
set smartcase
set gdefault
set incsearch
set showmatch
set hlsearch

set wrap
set textwidth=79
set formatoptions=qrn1
nnoremap j gj
nnoremap k gk

nnoremap ; :
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
nnoremap <leader>w <C-w>v<C-w>l
syntax on
set backup
set backupdir=~/.vim/backup
set directory=~/.vim/tmp

set noerrorbells
like image 731
Lazer Avatar asked Nov 29 '22 04:11

Lazer


2 Answers

before pasting, to avoid such behavior you should :set paste before pasting and :set nopaste after.

This is because the paste emulate the typing. It's even worst when you paste indented text.

This doesn't surface if you use the vim's yanking (internal "copy-paste").

like image 140
shellholic Avatar answered Dec 06 '22 09:12

shellholic


The r in set formatoptions=qrn1 is supposed to cause this kind of behaviour. But paste mode is more suited to, well pasting. Enter paste mode by giving set paste and leave it by giving set nopaste. help paste has information.

like image 20
dennycrane Avatar answered Dec 06 '22 08:12

dennycrane