Vim logo vim online Vim Book Ad

 Tip #347: Format paragraph without changing the cursor position

 tip karma   Rating 1/3, Viewed by 706 

created:   October 18, 2002 21:02      complexity:   intermediate
author:   Kartik Agaram      as of Vim:   6.0

map <silent> <C-j> :let line=line(".")<CR>:let col=col(".")<CR>gqap:exec ":".line<CR>:exec "normal " . col . "\|"<CR>
imap <silent> <C-j> <Esc>:let line=line(".")<CR>:let col=col(".")<CR>gqap:exec ":".line<CR>:exec "normal " . col . "\|"<CR>a

 rate this tip  Life Changing Helpful Unfulfilling 

<<Wrap text in HTML/XML tags after prompting for the tag name | Quickly insert a single word >>

Additional Notes

Anonymous, October 23, 2002 1:20
Why not simply use <C-O> after gq command?
Kartik, October 23, 2002 17:52
Hmm... 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.
Anonymous, October 24, 2002 6:33
Ok, mea culpa - I always used gq}, and it worked. The gqap is different.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo