From 0bb7284511fe87d76d4c4250fdb79a4486d851c0 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Tue, 25 Jul 2017 12:33:24 -0700 Subject: [PATCH] Better recursive functionality and visual mapping. --- plugin/join.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugin/join.vim b/plugin/join.vim index 2da2a0c..0fb15e7 100644 --- a/plugin/join.vim +++ b/plugin/join.vim @@ -108,6 +108,11 @@ function! s:SmartJoin(count) let l:linebreak = s:SmartJoinLine() if l:linebreak exe "normal! j" + " If the line we joined was also greater than textwidth, we should apply a + " smart join to the line before continuing. + if &textwidth != 0 && strlen(getline('.')) > &textwidth + call s:SmartJoin(1) + endif endif if g:smart_join_strip_whitespace_after call setline('.', s:StripTrailing(getline('.'))) @@ -128,10 +133,23 @@ function! g:SaveCursorSmartJoin(count) endfunction +" FUNCTION: SaveCursorVisualSmartJoin(count) {{{1 +" ============================================================================== +" A wrapper around SmartJoin(count) used to save the cursor position. + +function! g:SaveCursorVisualSmartJoin() + call setpos('.', getpos("'<")) + call s:SmartJoin(getpos("'>")[1] - getpos('.')[1]) + exe "normal! `<" +endfunction + + " MAPPINGS: {{{1 " ============================================================================== nmap SmartJoin : call g:SaveCursorSmartJoin(v:count1) +vmap VisualSmartJoin : call g:SaveCursorVisualSmartJoin() nmap J SmartJoin +vmap J VisualSmartJoin