* [gentoo-user] Paste into vim keeping indention or original?
@ 2011-01-27 19:07 Mark Knecht
2011-01-27 19:22 ` [gentoo-user] " Mark Knecht
2011-01-27 22:38 ` James
0 siblings, 2 replies; 10+ messages in thread
From: Mark Knecht @ 2011-01-27 19:07 UTC (permalink / raw
To: gentoo-user
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [gentoo-user] Re: Paste into vim keeping indention or original?
2011-01-27 19:07 [gentoo-user] Paste into vim keeping indention or original? Mark Knecht
@ 2011-01-27 19:22 ` Mark Knecht
2011-01-27 19:28 ` Mike Gilbert
2011-01-27 22:38 ` James
1 sibling, 1 reply; 10+ messages in thread
From: Mark Knecht @ 2011-01-27 19:22 UTC (permalink / raw
To: gentoo-user
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [gentoo-user] Re: Paste into vim keeping indention or original?
2011-01-27 19:22 ` [gentoo-user] " Mark Knecht
@ 2011-01-27 19:28 ` Mike Gilbert
2011-01-27 20:11 ` Petri Rosenström
2011-01-27 20:53 ` YoYo Siska
0 siblings, 2 replies; 10+ messages in thread
From: Mike Gilbert @ 2011-01-27 19:28 UTC (permalink / raw
To: gentoo-user
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [gentoo-user] Re: Paste into vim keeping indention or original?
2011-01-27 19:28 ` Mike Gilbert
@ 2011-01-27 20:11 ` Petri Rosenström
2011-01-27 20:53 ` YoYo Siska
1 sibling, 0 replies; 10+ messages in thread
From: Petri Rosenström @ 2011-01-27 20:11 UTC (permalink / raw
To: gentoo-user
On Thu, Jan 27, 2011 at 9:28 PM, Mike Gilbert <floppymaster@gmail.com> wrote:
> 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.
>
>
I usually do as Mike suggest. When I need to paste stuff into vim I
just type :set paste and paste the stuff and continue working.
Best regards
Petri
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [gentoo-user] Re: Paste into vim keeping indention or original?
2011-01-27 19:28 ` Mike Gilbert
2011-01-27 20:11 ` Petri Rosenström
@ 2011-01-27 20:53 ` YoYo Siska
2011-01-28 17:08 ` Bill Longman
1 sibling, 1 reply; 10+ messages in thread
From: YoYo Siska @ 2011-01-27 20:53 UTC (permalink / raw
To: gentoo-user
On Thu, Jan 27, 2011 at 02:28:47PM -0500, Mike Gilbert wrote:
> 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.
BTW, if
- vim has access to X (you run it on your local machine or from
ssh -X or something similar)
- is compiled with X support (check with vim --version | grep +X11)
- and you :set mouse=a
then you can paste by middle clicking in vim (not shift-middle click),
which should paste the text as is...
The difference is that with shift-middle click, or with vim that cannot
talk to X, the terminal sends the selected text to vim as normal input
(as if you would type it) and thus its get indented/formated/etc..
If you have mouse=a set and vim can talk to X, when you middle click
it will ask X for the selection and insert it as is without any
formatting
yoyo
^ permalink raw reply [flat|nested] 10+ messages in thread
* [gentoo-user] Re: Paste into vim keeping indention or original?
2011-01-27 19:07 [gentoo-user] Paste into vim keeping indention or original? Mark Knecht
2011-01-27 19:22 ` [gentoo-user] " Mark Knecht
@ 2011-01-27 22:38 ` James
1 sibling, 0 replies; 10+ messages in thread
From: James @ 2011-01-27 22:38 UTC (permalink / raw
To: gentoo-user
Mark Knecht <markknecht <at> gmail.com> writes:
> 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?
Well, if you want to keep it simple, here is what I do:
edit /etc/vim/vimrc
"set ai " Always set auto-indenting on
set noai " No auto indenting (James added this
now pasting into with vi does not indent deeper with each line.
hth,
James
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [gentoo-user] Re: Paste into vim keeping indention or original?
2011-01-27 20:53 ` YoYo Siska
@ 2011-01-28 17:08 ` Bill Longman
2011-01-28 20:03 ` kashani
2011-01-28 20:20 ` David Abbott
0 siblings, 2 replies; 10+ messages in thread
From: Bill Longman @ 2011-01-28 17:08 UTC (permalink / raw
To: gentoo-user
On 01/27/2011 12:53 PM, YoYo Siska wrote:
> BTW, if
> - vim has access to X (you run it on your local machine or from
> ssh -X or something similar)
> - is compiled with X support (check with vim --version | grep +X11)
> - and you :set mouse=a
> then you can paste by middle clicking in vim (not shift-middle click),
> which should paste the text as is...
>
> The difference is that with shift-middle click, or with vim that cannot
> talk to X, the terminal sends the selected text to vim as normal input
> (as if you would type it) and thus its get indented/formated/etc..
>
> If you have mouse=a set and vim can talk to X, when you middle click
> it will ask X for the selection and insert it as is without any
> formatting
Oooh, aaah. Fireworks. This one's going into my .vimrc file....
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [gentoo-user] Re: Paste into vim keeping indention or original?
2011-01-28 17:08 ` Bill Longman
@ 2011-01-28 20:03 ` kashani
2011-01-28 22:42 ` Bill Longman
2011-01-28 20:20 ` David Abbott
1 sibling, 1 reply; 10+ messages in thread
From: kashani @ 2011-01-28 20:03 UTC (permalink / raw
To: gentoo-user
On 1/28/2011 9:08 AM, Bill Longman wrote:
> On 01/27/2011 12:53 PM, YoYo Siska wrote:
>> BTW, if
>> - vim has access to X (you run it on your local machine or from
>> ssh -X or something similar)
>> - is compiled with X support (check with vim --version | grep +X11)
>> - and you :set mouse=a
>> then you can paste by middle clicking in vim (not shift-middle click),
>> which should paste the text as is...
>>
>> The difference is that with shift-middle click, or with vim that cannot
>> talk to X, the terminal sends the selected text to vim as normal input
>> (as if you would type it) and thus its get indented/formated/etc..
>>
>> If you have mouse=a set and vim can talk to X, when you middle click
>> it will ask X for the selection and insert it as is without any
>> formatting
>
> Oooh, aaah. Fireworks. This one's going into my .vimrc file....
>
You might like one too.
cmap w!! w !sudo tee % >/dev/null
When you forget to sudo vi you can use w!! which pipes writing the file
though sudo. You get some term gunk, but it does work.
kashani
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [gentoo-user] Re: Paste into vim keeping indention or original?
2011-01-28 17:08 ` Bill Longman
2011-01-28 20:03 ` kashani
@ 2011-01-28 20:20 ` David Abbott
1 sibling, 0 replies; 10+ messages in thread
From: David Abbott @ 2011-01-28 20:20 UTC (permalink / raw
To: gentoo-user
> On 01/27/2011 12:53 PM, YoYo Siska wrote:
>> BTW, if
>> - vim has access to X (you run it on your local machine or from
>> ssh -X or something similar)
>> - is compiled with X support (check with vim --version | grep +X11)
>> - and you :set mouse=a
>> then you can paste by middle clicking in vim (not shift-middle click),
>> which should paste the text as is...
Thank You !!!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [gentoo-user] Re: Paste into vim keeping indention or original?
2011-01-28 20:03 ` kashani
@ 2011-01-28 22:42 ` Bill Longman
0 siblings, 0 replies; 10+ messages in thread
From: Bill Longman @ 2011-01-28 22:42 UTC (permalink / raw
To: gentoo-user
On 01/28/2011 12:03 PM, kashani wrote:
>
> You might like one too.
>
> cmap w!! w !sudo tee % >/dev/null
>
> When you forget to sudo vi you can use w!! which pipes writing the file
> though sudo. You get some term gunk, but it does work.
That's what "screen" and PS1 are for....
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-01-28 22:44 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-27 19:07 [gentoo-user] Paste into vim keeping indention or original? Mark Knecht
2011-01-27 19:22 ` [gentoo-user] " Mark Knecht
2011-01-27 19:28 ` Mike Gilbert
2011-01-27 20:11 ` Petri Rosenström
2011-01-27 20:53 ` YoYo Siska
2011-01-28 17:08 ` Bill Longman
2011-01-28 20:03 ` kashani
2011-01-28 22:42 ` Bill Longman
2011-01-28 20:20 ` David Abbott
2011-01-27 22:38 ` James
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox