How to maintain tabs when pasting in Vim

Posted by Ant Wilson on Stack Overflow See other posts from Stack Overflow or by Ant Wilson
Published on 2012-09-25T13:55:13Z Indexed on 2012/09/25 15:37 UTC
Read the original article Hit count: 316

Filed under:
|
|
|
|

I use the tab key to indent my python code in Vim, but whenever I copy and paste a block Vim replaces every tab with 4 spaces, which raises an IndentationError

I tried setting :set paste as suggested in related questions but it makes no difference

Other sites suggest pasting 'tabless' code and using the visual editor to re-indent, but this is asking for trouble when it comes to large blocks

Are there any settings I can apply to vim to maintain tabs on copy/paste?

Thanks for any help with this :)

edit:

I am copying and pasting within vim using the standard gnome-terminal techniques (ctrl+shift+c / mouse etc.)

my .vimrc is:

syntax on
set ts=4
if has("terminfo")
let &t_Co=8
let &t_Sf="\e[3%p1%dm"
let &t_Sb="\e[4%p1%dm"
else
let &t_Co=8
let &t_Sf="\e[3%dm"
let &t_Sb="\e[4%dm"
endif

I looked up that ts -> Sets tab stops to n for text input, but don't know what value would maintain a tab character

© Stack Overflow or respective owner

Related posts about python

Related posts about vim