Post #245,993
2/23/06 9:31:03 PM
|
Ah, if you're trying to do that, here's how you wanna go
You have to issue the wrap command.
Do you know what a motion is? It's a motion over a certain amount of text in the buffer; none, some or all.
So, for example, to go to the end of the current paragraph as seen by vim, you hit the letter 'p'.
To go to the end of the file, you hit the 'G' character, or to the end of the current block of code (programming thing), you'd hit the '}' character. Further, you can modify these by putting more than one of them in a row.
The command to format text according to line width is 'gq'. So, the idea is you issue the command, followed by the motion you want it done over. So, the short form of how to do what you want is if you want to rewrap the text in the rest of the paragraph (from the cursor to the end of the paragraph, to be precise), you would enter 'gqip'. If you want to do the entire paragraph, regardless of where the cursor in the paragraph is, you enter 'gqi}', and if you want to do it from the cursor to the end of the file you would do 'gqiG'.
Type in ':help motion' to get the skinny on all the motions that are available in vim. They are incredibly useful, as you can issue any command followed by the motion you want the command to make to select where it will be applied. The complete listing is in the file 'motion.txt', and it'll be in vim/vim63/help or some such location.
Use the help, Luke! ;)
--\n-------------------------------------------------------------------\n* Jack Troughton jake at consultron.ca *\n* [link|http://consultron.ca|http://consultron.ca] [link|irc://irc.ecomstation.ca|irc://irc.ecomstation.ca] *\n* Kingston Ontario Canada [link|news://news.consultron.ca|news://news.consultron.ca] *\n-------------------------------------------------------------------
|
Post #245,995
2/23/06 9:48:38 PM
|
COOL!!!!!!!
We tried that, the gqiG doesn't work, but the gqG does, without the i. I also had to figure out (with John's help) that it was wrapping my mail headers as well, into one big paragraph, but he discovered if I go below the mail headers before issuing the command, (or motion), it leaves those as they are.
THANKS!!!!! This is soooo much easier!
Brenda
"When you take charge of your life, there is no longer need to ask permission of other people or society at large. When you ask permission, you give someone veto power over your life."
By Geoffrey F. Abert
|
Post #245,999
2/23/06 10:36:57 PM
|
Right on
Don't forget to read the help files; they have many MANY more tricks in them.
--\n-------------------------------------------------------------------\n* Jack Troughton jake at consultron.ca *\n* [link|http://consultron.ca|http://consultron.ca] [link|irc://irc.ecomstation.ca|irc://irc.ecomstation.ca] *\n* Kingston Ontario Canada [link|news://news.consultron.ca|news://news.consultron.ca] *\n-------------------------------------------------------------------
|
Post #246,000
2/23/06 10:46:16 PM
|
I will, I promise!
OBLRPD:
We of the Church of Emacs feel that vi usage isn't a sin, but rather a penance.
Hehehe!
Brenda
"When you take charge of your life, there is no longer need to ask permission of other people or society at large. When you ask permission, you give someone veto power over your life."
By Geoffrey F. Abert
|
Post #246,017
2/24/06 7:11:59 AM
|
Vi is much more powerful than many people realize.
With that sort of command, you've definitely scraped below the surface. Remember you can combine gq with any sort of movement: I often uses it with just j (down 1 line) and then repeat it with . because that lets me incrementally re-format paragraphs. But you could do things like gq'm to re-format to mark 'm'.
Wade.
"Insert crowbar. Apply force."
|
Post #246,057
2/24/06 1:02:39 PM
2/24/06 1:12:07 PM
|
I agree
With that sort of command, you've definitely scraped below the surface. Remember you can combine gq with any sort of movement: I often uses it with just j (down 1 line) and then repeat it with . because that lets me incrementally re-format paragraphs. But you could do things like gq'm to re-format to mark 'm'. Curious, what does mark "m" mean? I mean, what does it do to the m? Or does M stand for something I'm missing? The best part about the gqG format option, is I don't have to go down the entire file and join it with J, which is really nice as I do long letters every month to a group of people, and I want to save them down to the hard drive on a regular basis. I also save all my e-mail down to the hard drive from actual people (not groups and such), so that is what I use this for the most. Also, when people write me screwy e-mail, and I try to save it, sometimes the J option can be tedious and complicated, because in regular Vi it was sometimes hard to tell where the next paragraph started and when to stop joining with J. This was heaven last night, I formatted the entire letter with one command, no hanging broken paragraphs, and no having to tediously check each one! I'm sure there will be exceptions, but this was great! Not only that, but the process was soooo much faster this way than the dos based one. Less typing of vi this file, open this file, wrap this file (with John's program), and then rename this file and delete original unwrapped one. Instead, I had a process of, first rename, then wrap, then edit and file away. Wonderful! I did a total of 42 e-mail edits in less than an hour! Wow, that cut my time by more than half! I still miss the Super DIR DD, Tree stuff, but hey, I could get used to this, as it's faster, more convenient, and easier by far! Brenda
"When you take charge of your life, there is no longer need to ask permission of other people or society at large. When you ask permission, you give someone veto power over your life."
By Geoffrey F. Abert
Edited by Nightowl
Feb. 24, 2006, 01:12:07 PM EST
|
Post #246,324
2/27/06 10:29:40 PM
|
Marking.
Vi lets you mark an arbitrary location in the file. You mark it with m followed by another letter which is the name of the mark. Users who don't use marks much usually drop mark 'm' because that's the simplest key sequence, but all 26 letters work for marking (so you can mark upto 26 different locations!).
You go to a marked location with the single quote followed by the mark's name/letter.
Wade.
"Insert crowbar. Apply force."
|
Post #246,392
2/28/06 2:22:25 PM
|
Okay, a question then
Vi lets you mark an arbitrary location in the file. You mark it with m followed by another letter which is the name of the mark. Users who don't use marks much usually drop mark 'm' because that's the simplest key sequence, but all 26 letters work for marking (so you can mark upto 26 different locations!). You go to a marked location with the single quote followed by the mark's name/letter. Could I use this to, for example, mark a page to not wrap when using the gqG command? I have one particular file that has a poem at the end of the e-mail I sent to everyone, but when I use the gqG command it wraps the poem as well. Would there be a way to put the mark M command in in front of the poem and then say, "wrap to the mark M and stop?" If so, what would be the sequence to use? Meanwhile, John's wrap program is succeeding in wrapping that file for each person's e-mail, I just have to keep switching between his wrap.exe and the gqG comand. Just curious if there's an easy way to use the Mark M command to accomplish the same thing. Thanks, Brenda
"When you take charge of your life, there is no longer need to ask permission of other people or society at large. When you ask permission, you give someone veto power over your life."
By Geoffrey F. Abert
|
Post #246,396
2/28/06 2:40:54 PM
|
Don't know the specifics
but look in motion.txt to find out how to do a motion from the current cursor up to a mark, then when that's done, move the cursor to just after the poem and do it to the end of the file.
--\n-------------------------------------------------------------------\n* Jack Troughton jake at consultron.ca *\n* [link|http://consultron.ca|http://consultron.ca] [link|irc://irc.ecomstation.ca|irc://irc.ecomstation.ca] *\n* Kingston Ontario Canada [link|news://news.consultron.ca|news://news.consultron.ca] *\n-------------------------------------------------------------------
|
Post #246,402
2/28/06 3:07:21 PM
|
ICLRPD (new thread)
Created as new thread #246401 titled [link|/forums/render/content/show?contentid=246401|ICLRPD]
-- Steve [link|http://www.ubuntulinux.org|Ubuntu]
|
Post #246,433
2/28/06 9:35:43 PM
|
Here's how to do it!
You go to the place where you want to mark, (i.e. in my case, the very last page which only has the poem), and put the mark where you want it to stop. I used 'a for the mark.
You can't see the mark, so you check this by going anywhere else in the file and typing 'a which takes you to the mark, and you know it's been set.
Then you go to the place where you want to start wrapping and do the gq thing only instead of typing G after that, you type gq'a. John said that means wrap until this mark.
It worked! Thanks!
Brenda
"When you take charge of your life, there is no longer need to ask permission of other people or society at large. When you ask permission, you give someone veto power over your life."
By Geoffrey F. Abert
|
Post #246,447
3/1/06 12:42:20 AM
|
You figured it out before I got to reply. :-)
"Insert crowbar. Apply force."
|
Post #246,455
3/1/06 3:05:33 AM
|
That's ok :)
Now you can answer the questions I was afraid to ask at first. ;) See my response to Conrad. :)
Brenda
"When you take charge of your life, there is no longer need to ask permission of other people or society at large. When you ask permission, you give someone veto power over your life."
By Geoffrey F. Abert
|
Post #246,452
3/1/06 2:45:16 AM
|
Bravo! You found out exactly what Wade told you a week ago!
|
Post #246,454
3/1/06 3:04:06 AM
|
Actually, it was four days ago. :)
And despite reading what he said: With that sort of command, you've definitely scraped below the surface. Remember you can combine gq with any sort of movement: I often uses it with just j (down 1 line) and then repeat it with . because that lets me incrementally re-format paragraphs. But you could do things like gq'm to re-format to mark 'm'. I didn't completely get it. I wasn't sure what combine gq with any sort of movement meant, until I discovered that the capital G meant to go to the end of the file, and that replacing it with the mark is what he was saying, so the mark would serve as the end of the "wrap" in the file. I also don't know what he means by using it with just J (down one line). I know J is the join command, but what does the (down one line) mean? I got lost somewhere when he explained about incrementally re-formatting paragraphs, I'm not sure what that means. And I didn't know what re-format meant, unless it's a term for the wrapping command. I thought file formatting was mostly about fonts and things. I'm still learning, but at least I admit when I'm not sure of something. I just didn't want to ask these questions then and look stupid, until I had a chance to try and figure it out first. So it took a combination of reading what he said, looking it up, and talking to John, and I got the hang of the command. :) The part that was throwing me most was when Jake said to mark something after the poem and continue to the end of the file. There's nothing after the poem, and the wrapping needed to stop at the top of the poem. But we got it all figured out. :) Brenda
"When you take charge of your life, there is no longer need to ask permission of other people or society at large. When you ask permission, you give someone veto power over your life."
By Geoffrey F. Abert
|
Post #246,462
3/1/06 6:52:34 AM
|
I've given lots of advice about vi over the years.
Mostly to beginners, encouraging them to learn just enough to keep them interested.
I'm sure you really know this, but vi's commands are case sensitive. Lowercase j is just move down 1 line*. Uppercase J is join this line to the next. So gqj will re-wrap the current line and the next line, leaving the cursor on the last line re-wrapped. Re-wrapping lines is sometimes called re-formatting in context where the text has no font information.
Wade.
* I just realized you might not have known that at all! Modern vi's recognize the cursor keys for movement, but the standard keys are hjkl for left, down, up and right respectively. I strongly recommend you teach yourself to use the latter because as you gain more skill and experience at vi, it will be faster to use the letters rather than the arrow keys to move the cursor.
"Insert crowbar. Apply force."
|
Post #246,483
3/1/06 12:33:15 PM
3/1/06 12:37:09 PM
|
I knew part of that
I'm sure you really know this, but vi's commands are case sensitive. Lowercase j is just move down 1 line*. Uppercase J is join this line to the next. So gqj will re-wrap the current line and the next line, leaving the cursor on the last line re-wrapped. Re-wrapping lines is sometimes called re-formatting in context where the text has no font information. * I just realized you might not have known that at all! Modern vi's recognize the cursor keys for movement, but the standard keys are hjkl for left, down, up and right respectively. I strongly recommend you teach yourself to use the latter because as you gain more skill and experience at vi, it will be faster to use the letters rather than the arrow keys to move the cursor. I knew the part about Shift-J joining lines. I don't think I ever figured out that lower-case j meant down one line. But I'm a little confused about the comment, "So gqj will re-wrap the current line and the next line, leaving the cursor on the last line re-wrapped." I get the part about wrapping the current line and next line, but what does it mean when you say "leaving the cursor on the last line rewrapped?" Are you saying it wraps only two lines at a time? I knew some of the movement. I knew h=left and l= right. I have always had problems moving up and down though, so that's nice to know. Remember, I figured the majority of vi out myself, by guesswork. John only taught me mostly the longer strings in order to help me format my e-mail for archiving. For example, when first using the DOS vi version, I found out that dG would delete everything below the line I put it in at. However, now from our discussion and the new vi program, I know that what that actually means is "delete to the end of the file." And I'd never read a manual or had a help file on vi before, and still really haven't really read over it, as I haven't had the patience and time to sit here and read it yet. But I plan to. I just do things like that better late at night, and lately I'm too anxious to stay up much. So I always used a combination of h and l and arrow keys to move around. Now I know why the error sound would sometimes beep when I moved wrong. ;) So I guess that you can say it's kind of like how I learn music. I know how to play the notes correctly, but I couldn't explain the rhythm, the time, or the reason they have to be that way. Same with vi. I know how to use use the letters and strings to format a file, but I never before grasped the "reason" certain letter combinations made things work that way. :) Thanks! Brenda
"When you take charge of your life, there is no longer need to ask permission of other people or society at large. When you ask permission, you give someone veto power over your life."
By Geoffrey F. Abert
Edited by Nightowl
March 1, 2006, 12:37:09 PM EST
|
Post #246,544
3/1/06 11:11:44 PM
|
Cursor location in vi.
Just a quick reply... ... But I'm a little confused about the comment, "So gqj will re-wrap the current line and the next line, leaving the cursor on the last line re-wrapped." I get the part about wrapping the current line and next line, but what does it mean when you say "leaving the cursor on the last line rewrapped?" Are you saying it wraps only two lines at a time? Yes, gqj will re-wrap only two lines at a time: the current and the next. It's just that one or both are very very long, you may get more than 2 lines as a result. After the re-wrapping, the cursor is on the last line it changed. Using gqj again will re-wrap that line - which may be short, BTW - with whatever it can do with the next line. And so on. Wade.
"Insert crowbar. Apply force."
|
Post #246,058
2/24/06 1:08:07 PM
2/24/06 1:09:31 PM
|
I wanted to reply to a few other things here :)
Do you know what a motion is? It's a motion over a certain amount of text in the buffer; none, some or all. Is a motion like the sequence I type in? For example when I'm trying to remove leading spaces (>) from forwarded messages, I use this one: :1,$s/^>(space)// That takes all the >=(greater than) signs from the beginning of each line of the message. And is every command a motion? For example, is Shift-J to join a line a motion as well, or do motions require more letters? I never heard them called motions, but I do them. ;) So, for example, to go to the end of the current paragraph as seen by vim, you hit the letter 'p'. Yep, I knew that. :) To go to the end of the file, you hit the 'G' character, or to the end of the current block of code (programming thing), you'd hit the '}' character. Further, you can modify these by putting more than one of them in a row. Yep, I know the end and beginning ones, and some of the move around in paragraph ones. And I know the Shift-O for space down and little a for space over. Type in ':help motion' to get the skinny on all the motions that are available in vim. They are incredibly useful, as you can issue any command followed by the motion you want the command to make to select where it will be applied. The complete listing is in the file 'motion.txt', and it'll be in vim/vim63/help or some such location. John showed me how to access the help files, so I know how. I was just so excited I was getting all this past mail processed and put away that I wasn't looking to read up on it more yesterday. But I definitely plan to soon! Thanks! Brenda
"When you take charge of your life, there is no longer need to ask permission of other people or society at large. When you ask permission, you give someone veto power over your life."
By Geoffrey F. Abert
Edited by Nightowl
Feb. 24, 2006, 01:09:31 PM EST
|
Post #246,062
2/24/06 1:23:39 PM
|
Re: I wanted to reply to a few other things here :)
Yes, a motion is like some of thse sequences you type in. The general idea is that a motion moves the cursor over the part of the file described by the motion. You can then combine the motion with a command to change the part of the file the motion moves over.
The example you use for the search and replace is not really a motion, though; instead, that's what's called a regular expression, which describes what you're looking for, and what you want to replace it with. So, the ^>(space) means "all the greater-than symbols found at the beginning of a line if it's followed by a space" or "> ". The carat (^) symbol means "beginning of line".
Regular expressions (often referred to as "regexp" for short) are another very powerful way to both search and change text; if you're interested, there's a wealth of online information about them you can peruse. Regular expressions at first appear to be pretty straightforward, but it's actually a pretty deep language concept, involving a kind of language called a "context free" language, which are all languages that are processable by a construct called a "push down automaton". To give a general handle on the first, humans speak natural languages. Context free languages are languages where the meaning of a string of characters is not dependent in any way on any strings that may surround it (eg 'abdde' is embedded in 'thdrabddethre'; the meaning of abdde is not changeable in any way by the text surrounding it in a context free language). There are context dependent languages that are not natural languages like English or Swahili; all turing complete programming languages like C, rexx, perl, java, etc fall into this category.
This is all from a course I took a couple of years ago, so if I've screwed up some specific, I'm sure there will be lotsa people here who can (and probably will) correct me.
If you're interested in the kinds of constructs that can process languages, I'd suggest first reading about 'finite state automata' before reading about 'push down automata', because a push down automaton is basically a finite state automaton with a memory in the form of what's called a 'stack' in computer science. I can rattle on for a significant time on those things, but perhaps it'd be better if you were to look them up for yourself, not least because I don't have all day to spill words into IWeThey today:)
Anyway, there's a knife and fork, dig in my friend!
--\n-------------------------------------------------------------------\n* Jack Troughton jake at consultron.ca *\n* [link|http://consultron.ca|http://consultron.ca] [link|irc://irc.ecomstation.ca|irc://irc.ecomstation.ca] *\n* Kingston Ontario Canada [link|news://news.consultron.ca|news://news.consultron.ca] *\n-------------------------------------------------------------------
|