View previous topic :: View next topic |
Author |
Message |
alex.blackbit Advocate
Joined: 26 Jul 2005 Posts: 2397
|
Posted: Mon Feb 26, 2007 10:35 pm Post subject: vim pasting "stairway" [SOLVED] |
|
|
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 |
|
|
ppurka Advocate
Joined: 26 Dec 2004 Posts: 3256
|
|
Back to top |
|
|
alex.blackbit Advocate
Joined: 26 Jul 2005 Posts: 2397
|
Posted: Mon Feb 26, 2007 10:58 pm Post subject: |
|
|
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 |
|
|
bertk n00b
Joined: 20 Jul 2006 Posts: 8
|
|
Back to top |
|
|
SiberianSniper Guru
Joined: 06 Apr 2006 Posts: 378 Location: Dayton, OH, USA
|
Posted: Thu Jul 19, 2007 1:46 am Post subject: |
|
|
why not just use this:
~/.vimrc: | nnoremap <silent> <F11> :set paste!<CR> |
|
|
Back to top |
|
|
swimmer Veteran
Joined: 15 Jul 2002 Posts: 1330 Location: Netherlands
|
Posted: Thu Jul 19, 2007 8:58 am Post subject: |
|
|
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 |
|
|
jlh Tux's lil' helper
Joined: 06 May 2007 Posts: 145 Location: Switzerland::Zürich
|
Posted: Thu Jul 19, 2007 1:44 pm Post subject: |
|
|
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 |
|
|
Stu_28 Tux's lil' helper
Joined: 12 Jun 2003 Posts: 129
|
Posted: Thu Jul 19, 2007 3:08 pm Post subject: |
|
|
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 |
|
|
SiberianSniper Guru
Joined: 06 Apr 2006 Posts: 378 Location: Dayton, OH, USA
|
Posted: Fri Jul 20, 2007 5:18 am Post subject: |
|
|
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 |
|
|
swimmer Veteran
Joined: 15 Jul 2002 Posts: 1330 Location: Netherlands
|
Posted: Fri Jul 20, 2007 10:27 am Post subject: |
|
|
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 |
|
|
timeBandit Bodhisattva
Joined: 31 Dec 2004 Posts: 2719 Location: here, there or in transit
|
Posted: Sat Jul 21, 2007 1:24 am Post subject: |
|
|
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 |
|
|
|