Gentoo Archives: gentoo-user

From: Mark Knecht <markknecht@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: Paste into vim keeping indention or original?
Date: Thu, 27 Jan 2011 19:24:41
Message-Id: AANLkTikkW-ABB9kHbLTvPKsGRih+C+-5NVuwo=8ekz=-@mail.gmail.com
In Reply to: [gentoo-user] Paste into vim keeping indention or original? by Mark Knecht
1 On Thu, Jan 27, 2011 at 11:07 AM, Mark Knecht <markknecht@×××××.com> wrote:
2 > What is the solution to begin able to paste code I find on the web
3 > into a file in vim and being able to keep the indentation from
4 > changing?
5 >
6 > For instance, here's the first few lines of code from a web page:
7 >
8 > #define ARRAYSIZE(x)  (sizeof(x)/sizeof(*(x)))
9 >
10 > int main(void)
11 > {
12 >   const char filename[] = "file.csv";
13 >   /*
14 >    * Open the file.
15 >    */
16 >
17 > The indentation on the code from const down is consistently 3 spaces:
18 >
19 >
20 > Pasted into vi:
21 >
22 > #define ARRAYSIZE(x)  (sizeof(x)/sizeof(*(x)))
23 >
24 > int main(void)
25 > {
26 >   const char filename[] = "file.csv";
27 >      /*
28 >          * Open the file.
29 >              */
30 >
31 > In this case const is correct, but the next line is 6 spaces, then 9
32 > spaces, then 12 spaces.
33 >
34 > If it matters, I'm using KDE using Konsole, but I've seen this in
35 > other WMs. I looked at the Tab settings in my Konsole profile but
36 > nothing seems to matter.
37 >
38 > Thanks,
39 > Mark
40 >
41
42 I solved it by creating a .vimrc file and putting
43
44 set pastetoggle=<F2>
45
46 in it. Now I hit F2, vim says (paste), I do the paste and it works nicely.
47
48 - Mark

Replies

Subject Author
Re: [gentoo-user] Re: Paste into vim keeping indention or original? Mike Gilbert <floppymaster@×××××.com>