From af0be6d906ada20525dce34bd0a4ef59a9bd7211 Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Tue, 21 Oct 2014 11:04:17 -0400 Subject: [PATCH] Greatly improve text width formatting + arrange the section more clearly --- vim/config/keyboard.vim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/vim/config/keyboard.vim b/vim/config/keyboard.vim index 3cb585e..65bb58a 100644 --- a/vim/config/keyboard.vim +++ b/vim/config/keyboard.vim @@ -566,14 +566,20 @@ "have backspace delete the selected text vnoremap "_x - "formatting options to apply to the whole document - nnoremap J ':set tw=79Vgq:set tw=0:echo "Document text has been formatted to a width of 79 characters"' - vnoremap J ':set tw=79gvgq:set tw=0:echo "Selected text has been formatted to a width of 79 characters"' + "format width to text width (or 80 chars if text width is 0) + nnoremap J ':let b:tw=&textwidth:if (b:tw == 0)set tw=80endifgg0vG$gq:if (b:tw == 0)set tw=0let b:tw=80endif:echo "Document has been formatted to a width of ".b:tw." characters"' + vnoremap J ':let b:tw=&textwidth:if (b:tw == 0)set tw=80endifgvgq:if (b:tw == 0)set tw=0let b:tw=80endif:echo "Selection has been formatted to a width of ".b:tw." characters"' + + "format syntax nnoremap f mzgg=G`z:echo "The document has been formatted" vnoremap f mz=`z:echo "The selection has been formatted" nnoremap F ':Autoformat:echo "The document has been formatted with :Autoformat"' + + "convert tabs to spaces nnoremap w ':FixWhitespace:echo "Trailing whitespace has been removed"' nnoremap t ':retab:noh:echo "Tabs have been converted to spaces"' + + "align comments nnoremap A :exe "%Tabular" '/^[^'.matchstr(&commentstring, '[^%]*').']*\zs'.matchstr(&commentstring, '[^%]*').'.*' vnoremap A :exe "'<,'>Tabular" '/^[^'.matchstr(&commentstring, '[^%]*').']*\zs'.matchstr(&commentstring, '[^%]*').'.*' nnoremap a :exe "%Tabular" '/^\ *[^'.matchstr(&commentstring, '[^%]*').'\ ][^\'.matchstr(&commentstring, '[^%]*').']*\zs'.matchstr(&commentstring, '[^%]*').'.*'