Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Gentoo User (http://www.linux-archive.org/gentoo-user/)
-   -   Paste into vim keeping indention or original? (http://www.linux-archive.org/gentoo-user/482007-paste-into-vim-keeping-indention-original.html)

Mark Knecht 01-27-2011 06:07 PM

Paste into vim keeping indention or original?
 
What is the solution to begin able to paste code I find on the web
into a file in vim and being able to keep the indentation from
changing?

For instance, here's the first few lines of code from a web page:

#define ARRAYSIZE(x) (sizeof(x)/sizeof(*(x)))

int main(void)
{
const char filename[] = "file.csv";
/*
* Open the file.
*/

The indentation on the code from const down is consistently 3 spaces:


Pasted into vi:

#define ARRAYSIZE(x) (sizeof(x)/sizeof(*(x)))

int main(void)
{
const char filename[] = "file.csv";
/*
* Open the file.
*/

In this case const is correct, but the next line is 6 spaces, then 9
spaces, then 12 spaces.

If it matters, I'm using KDE using Konsole, but I've seen this in
other WMs. I looked at the Tab settings in my Konsole profile but
nothing seems to matter.

Thanks,
Mark

Mark Knecht 01-27-2011 06:22 PM

Paste into vim keeping indention or original?
 
On Thu, Jan 27, 2011 at 11:07 AM, Mark Knecht <markknecht@gmail.com> wrote:
> What is the solution to begin able to paste code I find on the web
> into a file in vim and being able to keep the indentation from
> changing?
>
> For instance, here's the first few lines of code from a web page:
>
> #define ARRAYSIZE(x) *(sizeof(x)/sizeof(*(x)))
>
> int main(void)
> {
> * const char filename[] = "file.csv";
> * /*
> * ** Open the file.
> * **/
>
> The indentation on the code from const down is consistently 3 spaces:
>
>
> Pasted into vi:
>
> #define ARRAYSIZE(x) *(sizeof(x)/sizeof(*(x)))
>
> int main(void)
> {
> * const char filename[] = "file.csv";
> * * */*
> * * * * ** Open the file.
> * * * * * * **/
>
> In this case const is correct, but the next line is 6 spaces, then 9
> spaces, then 12 spaces.
>
> If it matters, I'm using KDE using Konsole, but I've seen this in
> other WMs. I looked at the Tab settings in my Konsole profile but
> nothing seems to matter.
>
> Thanks,
> Mark
>

I solved it by creating a .vimrc file and putting

set pastetoggle=<F2>

in it. Now I hit F2, vim says (paste), I do the paste and it works nicely.

- Mark

Mike Gilbert 01-27-2011 06:28 PM

Paste into vim keeping indention or original?
 
On Thu, Jan 27, 2011 at 2:22 PM, Mark Knecht <markknecht@gmail.com> wrote:
> I solved it by creating a .vimrc file and putting
>
> set pastetoggle=<F2>

Running :set paste will do the job as well if you don't want to assign
a hot key for it.


All times are GMT. The time now is 08:06 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.