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 |