From 034db637c7aad13491afedc35823124b2ce0909a Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Fri, 30 Aug 2024 17:41:44 +0200 Subject: [PATCH] vim:keys: Relax [[ maps for different style guides I use the [[ & etc. mappings to jump between function definitions in C. This works as long as the braces are put on a newline (like in the kernel coding style guide). Relax the mappings for opening braces to jump to unindented lines with an opening brace to cover also different style guides. --- .config/vim/vimrc.d/40-keys.vim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.config/vim/vimrc.d/40-keys.vim b/.config/vim/vimrc.d/40-keys.vim index ac52b55..c00f596 100644 --- a/.config/vim/vimrc.d/40-keys.vim +++ b/.config/vim/vimrc.d/40-keys.vim @@ -268,6 +268,15 @@ augroup END nnoremap utc ciw=strftime("%F %T", @") vnoremap utc s/\v(^\|[^0-9])\zs[0-9]{10}\ze([^0-9]\|$)/\=strftime("%F %T",submatch(0))/g +" Relax mappings that jump to opening braces on first column: Just make sure +" they are on an unindented line. This is useful for files that use a different +" coding style guide than the kernel and similar. +" TODO: [count] sections? (see :h [[) +nnoremap [[ m':call search('^\S.*{', "bW") +vnoremap [[ m':exe "normal! gv"call search('^\S.*{', "bW") +nnoremap ]] m':call search('^\S.*{', "W") +vnoremap ]] m':exe "normal! gv"call search('^\S.*{', "W") + " Match the behaviour of [[ and []. ]] forward to next '}' in the first column " and ][ fw to next '[', instead of the other way around. noremap ]] ][