Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8598107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:04:39+00:00 2026-06-12T01:04:39+00:00

I use the tab key to indent my python code in Vim, but whenever

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:04:40+00:00Added an answer on June 12, 2026 at 1:04 am

    See :h tabstop for all the options and how they interact with each other.

    These are good settings if you prefer tabs:

    set tabstop=4
    set shiftwidth=4
    set noexpandtab
    

    With these settings, you hit <Tab> and you get <Tab>.

    These are good settings if you prefer spaces:

    set tabstop=4
    set shiftwidth=4
    set expandtab
    

    With these settings, you hit <Tab> and you get <Space><Space><Space><Space>.

    Whatever you choose, you should not use your terminal key bindings for copying/pasting. Inside Vim, you should “yank” with y and “put” with p or P; optionally using a specific register like "ay/"ap to yank/put to/from the content of @a or "+y/"+p to yank/paste to/from the system clipboard (if your Vim is built with clipboard support).

    As a side note, you should use the long form names of your settings as they are more readable than their short counterpart. Your future self will thank you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use OpenGL+GLUT for simple application, but I can't handle a Tab key press.
<div style=width:500px;> <p>To create not a block, but an inline code span,use backticks:Press the
I use this code for replacing Enter key with TAB key : function EnterTab()
When you use a tab key to select a textbox, all text in it
It's very easy to set a text editor to use spaces or tab characters
I am trying to use PostMessage to send a tab key. Here is my
how can i change enter key in silverlight forms to tab key.i use the
Newbie- I want to do 2 things with these checkboxes: Use TAB key to
reference How can I disable the use of the Tab key to select the
How do I make vi - Vim never use tabs (converting spaces to tabs,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.