FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 01-27-2011, 06:07 PM
Mark Knecht
 
Default 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
 
Old 01-27-2011, 06:22 PM
Mark Knecht
 
Default 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
 
Old 01-27-2011, 06:28 PM
Mike Gilbert
 
Default 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.
 

Thread Tools




All times are GMT. The time now is 07:30 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org