Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
vim pasting "stairway" [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
alex.blackbit
Advocate
Advocate


Joined: 26 Jul 2005
Posts: 2397

PostPosted: Mon Feb 26, 2007 10:35 pm    Post subject: vim pasting "stairway" [SOLVED] Reply with quote

hello everybody!

i am not sure if this is a problem of my terminal emulator (xterm), vim or my vim-settings.
in one xterm window with open vim i mark a section with the mouse.
in a second xterm with vim i am in "-- INSERT --" mode and hit the middle mouse button to paste the stuff i copied before.
the posted text is intended too much, like this:
Code:
void
randomize (void)
{
       struct timeval *tv = (struct timeval *) malloc (sizeof (struct timeval));
            struct timezone *tz =
                  (struct timezone *) malloc (sizeof (struct timezone));
                 gettimeofday (tv, tz);
                      srand (tv->tv_usec);
                           free (tv);
                                free (tz);
}
it looked like this:
Code:
void
randomize (void)
{
     struct timeval *tv = (struct timeval *) malloc (sizeof (struct timeval));
     struct timezone *tz =
    (struct timezone *) malloc (sizeof (struct timezone));
     gettimeofday (tv, tz);
     srand (tv->tv_usec);
     free (tv);
     free (tz);
}
before.
does anybody know why this happens? it is very annoying.


Last edited by alex.blackbit on Mon Feb 26, 2007 10:58 pm; edited 1 time in total
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Mon Feb 26, 2007 10:39 pm    Post subject: Reply with quote

http://www.vim.org/tips/tip.php?tip_id=330
:D
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
alex.blackbit
Advocate
Advocate


Joined: 26 Jul 2005
Posts: 2397

PostPosted: Mon Feb 26, 2007 10:58 pm    Post subject: Reply with quote

Code:
" Paste Mode On/Off
map <F11> :call Paste_on_off()<CR>
set pastetoggle=<F11>

let paste_mode = 0 " 0 = normal, 1 = paste

func! Paste_on_off()
        if g:paste_mode == 0
                set paste
                let g:paste_mode = 1
        else
                set nopaste
                let g:paste_mode = 0
        endif
        return
endfunc

thank you for the link ppurka.
i found this piece of code there that you can add to your ~/.vimrc to have a <F11> button to switch between a paste and a nopaste mode.
this is the only thing about vim i find VERY strange.

have a nice day
--alex
Back to top
View user's profile Send private message
bertk
n00b
n00b


Joined: 20 Jul 2006
Posts: 8

PostPosted: Sun Jul 15, 2007 6:28 pm    Post subject: vi vim indention # Reply with quote

"set noautoindent" worked for me.
_________________
:) Linux Tutorials
:) Free Ping Service for feed directories
Back to top
View user's profile Send private message
SiberianSniper
Guru
Guru


Joined: 06 Apr 2006
Posts: 378
Location: Dayton, OH, USA

PostPosted: Thu Jul 19, 2007 1:46 am    Post subject: Reply with quote

why not just use this:

~/.vimrc:
nnoremap <silent> <F11> :set paste!<CR>
Back to top
View user's profile Send private message
swimmer
Veteran
Veteran


Joined: 15 Jul 2002
Posts: 1330
Location: Netherlands

PostPosted: Thu Jul 19, 2007 8:58 am    Post subject: Reply with quote

SiberianSniper wrote:
why not just use this:

~/.vimrc:
nnoremap <silent> <F11> :set paste!<CR>

How to switch back then?

Therefore I use
Code:
set pastetoggle=<F5>
and it works perfect both in insert- and normal-mode ...

HTH
swimmer
Back to top
View user's profile Send private message
jlh
Tux's lil' helper
Tux's lil' helper


Joined: 06 May 2007
Posts: 145
Location: Switzerland::Zürich

PostPosted: Thu Jul 19, 2007 1:44 pm    Post subject: Reply with quote

This happens because vim can't make the difference between typed text and pasted text. Thus the 'paste' setting is useful. However, there's a simpler solution; if you make vim handle the mouse clicks itself, then it will know when you're typing and when you're pasting and do the right thing automatically.

I'm not totally sure how to do this however. You probably need to compile vim with support for X, and you have to set the 'mouse' option to something suitable. I use mouse=a.

(In this mode, you can still make vim not handle mouse clicks by holding down shift. For example when you want to mark text across split windows in a raw way.)
Back to top
View user's profile Send private message
Stu_28
Tux's lil' helper
Tux's lil' helper


Joined: 12 Jun 2003
Posts: 129

PostPosted: Thu Jul 19, 2007 3:08 pm    Post subject: Reply with quote

You could also use the C-indenting formatting function =. So, to indent the whole file you would do "<Esc>gg=G" or to do 5 lines starting from the one you are on, "<Esc>=5". It's pretty handy.
Back to top
View user's profile Send private message
SiberianSniper
Guru
Guru


Joined: 06 Apr 2006
Posts: 378
Location: Dayton, OH, USA

PostPosted: Fri Jul 20, 2007 5:18 am    Post subject: Reply with quote

swimmer wrote:
How to switch back then?

The ! in a set command toggles the variable, so you'd just hit F11 or whatever key bound to that action again to switch back.
Back to top
View user's profile Send private message
swimmer
Veteran
Veteran


Joined: 15 Jul 2002
Posts: 1330
Location: Netherlands

PostPosted: Fri Jul 20, 2007 10:27 am    Post subject: Reply with quote

SiberianSniper wrote:
The ! in a set command toggles the variable, so you'd just hit F11 or whatever key bound to that action again to switch back.

Ah nice to know

Thank you very much!
swimmer :)
Back to top
View user's profile Send private message
timeBandit
Bodhisattva
Bodhisattva


Joined: 31 Dec 2004
Posts: 2719
Location: here, there or in transit

PostPosted: Sat Jul 21, 2007 1:24 am    Post subject: Reply with quote

SiberianSniper wrote:
~/.vimrc:
nnoremap <silent> <F11> :set paste!<CR>

This is wonderful--thank you. The indention nonsense is one of those minor annoyances that didn't burn me enough to hunt down and correct but I really wished I could be rid of it.

One tip: GNOME Terminal intercepts F11 to toggle full-screen mode (for HIG consistency). So those who, like me, often use vim in GNOME Terminals should use a different key binding. (I chose F12.)
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum