sponsor Vim development Vim logo Vim Book Ad

basic Tip #350: when 'formatoptions' has o easily enter a non commented line: go/gO mappings

 tip karma   Rating 29/10, Viewed by 1266 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   October 24, 2002 2:13      complexity:   basic
author:   Feral of firetop dot com      as of Vim:   5.7

This is relevant when your 'formatoptions' has o.
From :h fo-table, "Automatically insert the current comment leader after hitting 'o' or 'O' in Normal mode."
I like this behavior enough to keep the o option, however at times I want to NOT insert the comment chars, and although manually deleting the added chars is not hard I present these simple mappings that delete the added chars automatically.

(from my .vimrc)
nnoremap go o<esc>S
nnoremap gO O<esc>S

This makes go open a new line under the cursor and removes inserted chars, while gO opens a new line above the cursor and removes inserted chars.

Your mileage will vary of course (:
Happy VIMing!

 rate this tip  Life Changing Helpful Unfulfilling 

<< Format your xml document using xmllint | Using quickfix in a different way >>

Additional Notes

Feral <[email protected]> (Rot13ed), June 1, 2003 3:35
It should be noted that the go mapping presented above will interfere with VIM's default go (Go to {count} byte in the buffer; :h go) command.

There should be a much more elegant way of achieving the same effect, but I am currently unaware of what it might be.
[email protected], March 4, 2004 13:08
I look everywhere for a solution to this problem.  My work around is to use Ctrl-W (insert mode) to delete the previous word.

A side note... i find it useful to the use Ctrl-Backspace instead of Ctrl-W.
imap <C-BS> <C-W>
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 the maillist. Help Bram help Uganda.
   
SourceForge.net Logo