Reputation: 16184
I want to perform auto-formatting on a certain code block, after a specific character has been typed, similar to visual studio's auto-formatting.
For example, when an endline character has been typed, the previous line could be formatted, like one were hitting Vgq
on that line.
What is the easiest and most efficient way to achieve this?
I already thought about using the InsertCharPre
event, but I actually would need a InsertCharPost
event. Unfortunately that doesn't exist.
Upvotes: 0
Views: 238
Reputation: 195079
if format code block
you meant is gq
, you could try:
inoremap <cr> <esc>Vgqo
this mapping does: when you type Enter in INSERT mode, it will does automatically vgq
for you, and place cursor in next line, staying in INSERT mode.
Hope it is what you are looking for.
Upvotes: 2