From 2dc3c00f98d97a4b898128c081731585910b3b68 Mon Sep 17 00:00:00 2001 From: Stefan Friese Date: Thu, 29 Feb 2024 17:22:45 +0100 Subject: [PATCH] added automated error handling if condition on ee for golang --- vim/.vim/after/ftplugin/go.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vim/.vim/after/ftplugin/go.vim b/vim/.vim/after/ftplugin/go.vim index df0fb7f..6286364 100644 --- a/vim/.vim/after/ftplugin/go.vim +++ b/vim/.vim/after/ftplugin/go.vim @@ -7,3 +7,15 @@ let g:ale_linters = { " let g:ale_completion_enabled = 1 +" Map ee to insert Go error handling if condition +nnoremap ee :call InsertGoErrorHandling() + +function! InsertGoErrorHandling() + let err_handling = "if err != nil { \r return err \r}" + + let save_cursor = getpos(".") + execute "normal! a" . err_handling + normal! jjj$ + normal! $o + startinsert +endfunction