Fix Bad Indentation When Pasting Text To Vim

The problem is this:

You’re editing a buffer in vim, you copy a text (say, code snippet) from another place (say, Firefox), and you paste it inside vim (with middle mouse button / shift+insert). Most chances you won’t like what vim has just did to your text.

The problem is that vim doesn’t “know” that you’re actually pasting a text, and it thinks that you’re typing. So, if you have indentation enabled, it will re-indent your text.

The solution is simple: Whenever you want to paste text from outside vim into vim. Type this in command mode:

:set paste

So now vim knows that you’re going to paste text, and it will not touch it.

To disable the paste mode:

:set nopaste

As easy as that ;-)

If you enjoyed this post, make sure you subscribe to my RSS feed!

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Related posts:

  1. Fetch Links From Twitter Into Your RSS Reader
  2. Vim Tip – Convert Code To HTML
  3. NumPad Problems When Using Vim over Tmux
  4. Make Shell Scripts Executable By Default
  5. Enhance The Experience of Logitech Keyboards and Mice on Linux

Tags:

Friday, July 16th, 2010 Vim

Leave a Reply

my email
my photo
Hi,
My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
I'm a Verification Engineer in Mellanox Technologies Ltd.
I love Linux, the Command Line and the OpenSource Community.
I used to write Poems (Arabic) when I was able to find time for this.
July 2010
S M T W T F S
« Jun   Aug »
 123
45678910
11121314151617
18192021222324
25262728293031
SEO Powered by Platinum SEO from Techblissonline

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.