Help - Search - Members - Calendar
Full Version: OT: vim commands....
914World.com > The 914 Forums > 914World Garage
bd1308
I googled it and came up with information, but none of it could prove to be useful.

if i write something long, like a story or something and I want to edit a word in the middle, is there any way to skip line by line through the wrapped "line" in vim? or do I just have to use the right arrow key for ten days to go through each letter until i get the right one?
Dr. Roger
In command mode....

:1, $s/word/anotherword/g will replace word with anotherword throughout the file.
mightyohm
hit enter every once in a while instead of entering huge wrapped lines, vim wasn't intended to be a word processor (in that sense)
bd1308
thanks guys. It's a shame though, because vim WAS meant to be way more than just a small editor for files.

mutt uses it.
Gint
Look at the man page and other reference material for vi. vim uses similar commands.

Use "/" and then enter your search term or string. Then use "n" to go to the next of your search terms throughout the file. Then you can use standard vi like replace commands.

Roger came very cose. ":1" will take you to line 1, a different number will take you to that line. "Cntrl-g" will show you what line your actually on of how many lines in the file BTW. Use ":" to enter command mode if not already there. Then, %s/wordtoreplace/newword vim doesn't seem to require the "g" and the end to make the change global as vi does. So if you only want to change one word, you'll have to use the first method I listed (or one of many other's) or otherwise figure that out on your own.

Jeff's advice is good also. I always use manual line breaks with vi in a long file. It's only a text editor. It wasn't intended for desktop publishing.

Buy a book! Find a good tech forum. You can usually search and find answers to these types f questions on a good firum for the subject matter.
bd1308
thanks guys.


smile.gif
mightyohm
vim also has very, very extensive online help.

i used to use it every day a few years ago, now I stumble around in it like everyone else, but at least I am not terrified every time some unix app pops me into vi like i used to be.

biggrin.gif

PS: If you are used to Word, you are expecting that text will be automatically formatted to fit the page when you keep typing (without making your own line breaks). vim takes a simpler approach and lets you define the line breaks. I am guessing this is because in some programming languages line breaks define instructions and you wouldn't want the text editor to decide on the line structure for you.

vim is extremely powerful and hands down my favorite editor for coding, it is very fast and very coder-friendly. To tell you the truth, you can probably enable a feature to give it Word style line wraps/autoformatting. The preferences options are a mile long. Some versions also have a syntax highlighting feature for various programming languages, which is VERY cool. Check it out.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.