Fandom

Vim Tips Wiki

Insert a non commented line despite formatoptions

Redirected from VimTip350

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Tip 350 Printable Monobook Previous Next

created 2002 · complexity basic · author Feral · version 5.7


This is relevant when your 'formatoptions' includes o.

From :help 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.

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.

CommentsEdit

It should be noted that the go mapping presented above will interfere with Vim's default go (Go to {count} byte in the buffer :help 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.


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 use Ctrl-Backspace instead of Ctrl-W.

imap <C-BS> <C-W>

Also on Fandom

Random Wiki