I want to make a Python ftplugin
(but other filetypes will also have this option) where, if the previous line has a comment that starts with #
, the next line can be commented via <Shift><CR>
, an insert-mode mapping (inoremap
). How can I code Vimscript so that it checks whether the current line is commented, and subsequently allows the inoremap
to make a new line commented?
And please don't recommend a third-party plugin like NERD Commenter
(which, btw, I respect very much), I want something as close to vanilla-Vim as possible for this.
<CR>
to add a line with no comment and<Shift-CR>
to add a comment, why do you need it to be conditional on whether the current line has a comment? If you don't want a comment added when you're not currently on a commented line, why would you pressing<Shift-CR>
in that case? Am I misunderstanding the behaviour of the mapping you want to create?