Vim Tips Wiki
Advertisement
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Tip 129 Printable Monobook Previous Next

created 2001 · complexity basic · author Benji Fisher · version 6.0


If you include the "r" or "o" flag in the 'formatoptions' option (:help 'fo', :help fo-table) then the comment leader is inserted automatically when you start a new line in a comment. For example, in TeX the "%" character is the comment leader, and you might type

% This is a tex file.
% The comment leaders on all lines but the first were generated automatically.
% This is the last line of the comment, but Vim will insert the comment leader on the next line.
%

You can get rid of the comment leader (along with anything you may already have typed on the line) without affecting the indent, if any, by typing <C-U> while in Insert mode (in case you do this by accident, there are ways to undo it).

Related point: If you want to adjust the indent while in insert mode, you can use <C-D> (to decrease the indent) or <C-T> (to increase it). See :help 30.4.

See also

References

Comments

Advertisement