Showing posts with label pasting problem in vim. Show all posts
Showing posts with label pasting problem in vim. Show all posts

17 May 2012

154. Vim -- weird pasting behaviour

The problem:
Get this
 when you want this?


The solution:
This is perhaps a bit superfluous as it comes from the vim wiki, but it might help someone: 

Edit your ~/.vimrc and add
set pastetoggle=<F3>
Now, before you paste, hit F3 and you can paste as usual (notice the little 'paste' after the 'insert' in the screenshot below).

My full ~/.vimrc is now
set number
set pastetoggle=
set spell
set wrap
nnoremap  :set nonumber!<
Other cool stuff:

* Line number toggle -- nnoremap <F4> :set nonumber!<CR> will map line numbering on /off to F4.

* Substituting only within selection. Go to visual mode and select the text.
Then hit  : which brings up '<,'>.  Anyway, the key is \%V which confines the substitution to the visually selected area.
:'<,'>s/\%Voldphrase/newphrase/g
* Commenting out lines -- the key is ^
: %s/^/#/g 
or
 :'<,'>s/\%V^/#/g

I previously had a bigger ~/.vimrc posted here, but now, a year later, I've reduced it to what I've posted above.
Anyway, the old one is here:

set number
filetype plugin on
filetype indent on
set expandtab
set shiftwidth=4
set tabstop=4
set smarttab
set spell
set lbr
set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines
set grepprg=grep\ -nH\ $*
let g:tex_flavor='latex'
highlight Cursor guifg=white guibg=black
highlight iCursor guifg=white guibg=steelblue
set guicursor=n-v-c:block-Cursor
set guicursor+=i:ver100-iCursor
set guicursor+=n-v-c:blinkon0
set guicursor+=i:blinkwait10
set pastetoggle=<F3>
nnoremap <F4> :set nonumber!<CR>