(Change to TipImported template + severe manual clean) |
(Change <tt> to <code>, perhaps also minor tweak.) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | {{review}} |
||
{{TipImported |
{{TipImported |
||
|id=347 |
|id=347 |
||
|previous=346 |
|previous=346 |
||
|next=348 |
|next=348 |
||
− | |created= |
+ | |created=2002 |
− | |complexity= |
+ | |complexity=basic |
− | |author= |
+ | |author= |
|version=6.0 |
|version=6.0 |
||
|rating=18/11 |
|rating=18/11 |
||
+ | |category1= |
||
+ | |category2= |
||
}} |
}} |
||
+ | To format the current paragraph: |
||
− | <pre> |
||
+ | *<code>gqap</code> |
||
− | map <silent> <C-j> :let line=line(".")<CR>:let col=col(".")<CR>gqap:exec ":".line<CR>:exec "normal " . col . "\|"<CR> |
||
+ | *<code>gwap</code> same, but restores cursor position |
||
− | imap <silent> <C-j> <Esc>:let line=line(".")<CR>:let col=col(".")<CR>gqap:exec ":".line<CR>:exec "normal " . col . "\|"<CR>a |
||
− | </pre> |
||
==Comments== |
==Comments== |
||
+ | {{todo}} |
||
− | Why not simply use <C-O> after gq command? |
||
+ | *Thanks to anon who pointed out that gwap makes the original tip obsolete (I have removed it). |
||
− | |||
+ | *We don't have any other tips that explain basics of paragraph formatting, so this may as well be it. |
||
− | ---- |
||
+ | *Need to explain what "format" means here. |
||
− | Let me try to describe a case. Let's say you open a text file and start inserting text somewhere in between without ever adding to the jump list (just arrow keys, '{}'). Now typing <Esc> gqap <C-o> doesn't restore cursor position. At least for me. |
||
+ | *Need to mention textwidth, formatexpr, formatprg and probably more (but keep it simple). |
||
− | |||
− | ---- |
||
− | Ok, mea culpa - I always used gq}, and it worked. The gqap is different. |
||
− | |||
− | ---- |
||
− | It may be more desirable to preserve the cursor's logical position (i.e., which word it is currently on), rather than its line/col position. |
||
− | |||
− | The following nmap does this by inserting a small and unusual bogus text at the current cursor position; formatting the paragraph; using search to get to the bogus word; and then deleting it. |
||
− | |||
− | nmap gb i<zqfm><esc>gqip?<zqfm><cr>df> |
||
− | |||
− | ---- |
||
− | Absolutely outstanding. |
||
− | |||
− | ---- |
Latest revision as of 05:25, 13 July 2012
To format the current paragraph:
gqap
gwap
same, but restores cursor position
Comments[]
TO DO
- Thanks to anon who pointed out that gwap makes the original tip obsolete (I have removed it).
- We don't have any other tips that explain basics of paragraph formatting, so this may as well be it.
- Need to explain what "format" means here.
- Need to mention textwidth, formatexpr, formatprg and probably more (but keep it simple).