Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

Properly cut & pasting in Vim

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
8 posts • Page 1 of 1
Author
Message
tecknojunky
Veteran
Veteran
User avatar
Posts: 1937
Joined: Sat Oct 19, 2002 6:50 am
Location: Montréal
Contact:
Contact tecknojunky
Website

Properly cut & pasting in Vim

  • Quote

Post by tecknojunky » Sun Jul 25, 2004 10:30 pm

I always wondered why when I pasted text into vim, each line, as you go further down the text, is more and more endented.

I just discovered it might have to do with the auto-identation feature of Vim. It would seem that it interprets each pasted newline as if Enter was pressed and idents the nect line to whatever algorithm was program to position the cursor.

I'd put my hand in the fire that there's a more convenient, better, proper way to do this.
(7 of 9) Installing star-trek/species-8.4.7.2::talax.
Top
CybDev
n00b
n00b
User avatar
Posts: 3
Joined: Fri Dec 26, 2003 9:33 pm
Location: /dev/null

  • Quote

Post by CybDev » Sun Jul 25, 2004 11:21 pm

:help paste
"The key to true power is knowledge."
*** ERROR: Cannot join channel: #Real_Life (Invite only)
Top
jftuga
Tux's lil' helper
Tux's lil' helper
Posts: 139
Joined: Wed Jan 21, 2004 4:18 am
Location: Athens, GA

  • Quote

Post by jftuga » Sun Jul 25, 2004 11:30 pm

I have noticed this stair-stepping effect as well. I have put these lines into my .vimrc file:

Code: Select all

:map #1 0vwhxi<tab><esc>j
:map #2 0vwhxi<tab><tab><esc>j
:map #3 0vwhxi<tab><tab><tab><esc>j
:map #4 0vwhxi<tab><tab><tab><tab><esc>j
These map the F1-F4 keys and remove all whitespace between the beginning of each line until right before the 1st character of the line and replace it with a tab when I hit F1, replace it with 2 tabs when I hit F2, etc. etc.

This is good for me when cutting and pasting code as it might need to be indented at different widths.

-John
Top
myuser
Apprentice
Apprentice
User avatar
Posts: 218
Joined: Sat Jan 31, 2004 7:27 pm

  • Quote

Post by myuser » Mon Jul 26, 2004 12:25 am

:set noautoindent

That will solve your problem.

Then when pasted turn it back on:

:set autoindent

It happens because you have a space(s) before the text on a line.

So, if you have 1 space it will indent the following line by 1 space, which if that has 1 space infront of the text will generate 2 spaces and so on.

That is why you get that diagonal affect.
Top
tecknojunky
Veteran
Veteran
User avatar
Posts: 1937
Joined: Sat Oct 19, 2002 6:50 am
Location: Montréal
Contact:
Contact tecknojunky
Website

  • Quote

Post by tecknojunky » Mon Jul 26, 2004 1:53 am

myuser wrote::set noautoindent

That will solve your problem.

Then when pasted turn it back on:

:set autoindent

It happens because you have a space(s) before the text on a line.

So, if you have 1 space it will indent the following line by 1 space, which if that has 1 space infront of the text will generate 2 spaces and so on.

That is why you get that diagonal affect.
Aaaah! I knew it there was a way.

I know just the bare minimal stuff on vi because it is on just about every *nix and they all (more || less) work the same.

Gimme, oh say, may 10 or 15 more years and I guess I'll get to know a few more commands... if i can just get use to that command/edit mode lambada.
(7 of 9) Installing star-trek/species-8.4.7.2::talax.
Top
grover
Tux's lil' helper
Tux's lil' helper
Posts: 77
Joined: Fri Sep 27, 2002 5:56 pm
Location: Melbourne, Australia

  • Quote

Post by grover » Mon Jul 26, 2004 4:18 am

If you're lazy like me you can shorten the above commands to
:set noai
:set ai
Top
mhodak
Veteran
Veteran
Posts: 1218
Joined: Sat Nov 15, 2003 9:23 am

  • Quote

Post by mhodak » Mon Jul 26, 2004 5:07 am

I have this in my ~/.vimrc:

Code: Select all

set pastetoggle=<F11>
What it does is that pressing F11 (or whatever key you want) toggles between modes when indentation is added and when it is not.
Top
jftuga
Tux's lil' helper
Tux's lil' helper
Posts: 139
Joined: Wed Jan 21, 2004 4:18 am
Location: Athens, GA

  • Quote

Post by jftuga » Tue Jul 27, 2004 2:14 pm

mhodak wrote:I have this in my ~/.vimrc:

Code: Select all

set pastetoggle=<F11>
What it does is that pressing F11 (or whatever key you want) toggles between modes when indentation is added and when it is not.
Good idea, I think I will add this one myself. I have one similar to this, but for toggling on/off the display of line numbers, using the F7 key:

Code: Select all

"Toggle line numbers
:map #7 :set invnu<cr>
-John
Top
Post Reply

8 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic