diff --git a/autoload/multiedit.vim b/autoload/multiedit.vim index d0996cc..af7faa1 100644 --- a/autoload/multiedit.vim +++ b/autoload/multiedit.vim @@ -1,4 +1,18 @@ -" *multiedit.txt* Multi-editing for Vim +" *multiedit.txt* Multi-editing for Vim + +" If Multiple_cursors_after function has been defined in ~/.vimrc, call it +func! multiedit#triggerEndEvents() + if exists('*Multiple_cursors_after') + exe "call Multiple_cursors_after()" + endif +endfunc + +" If Multiple_cursors_after function has been defined in ~/.vimrc, call it +func! multiedit#triggerStartEvents() + if exists('*Multiple_cursors_before') + exe "call Multiple_cursors_before()" + endif +endfunc " addRegion() {{ func! multiedit#addRegion() @@ -12,8 +26,8 @@ func! multiedit#addRegion() let endcol = col('.')+1 " add selection to list - let sel = { - \ 'line': line, + let sel = { + \ 'line': line, \ 'col': startcol, \ 'len': endcol-startcol, \ 'suffix_length': col('$')-endcol @@ -93,12 +107,14 @@ endfunc " start() {{ func! multiedit#start(bang, ...) - if !exists("b:regions") + if !exists("b:regions") if g:multiedit_auto_restore == 0 || !multiedit#again() return endif endif + call multiedit#triggerStartEvents() + let lastcol = b:first_region.col + b:first_region.len " If bang exists OR the first region is a marker, then clear it before @@ -133,7 +149,7 @@ func! multiedit#start(bang, ...) else startinsert endif - + " Where the magic happens augroup multiedit au! @@ -141,7 +157,7 @@ func! multiedit#start(bang, ...) au CursorMovedI * call multiedit#update(0) " Once you leave INSERT, apply changes and delete this augroup - au InsertLeave * call multiedit#update(1) | call s:maps(0) | au! multiedit + au InsertLeave * call multiedit#update(1) | call s:maps(0) | multiedit#triggerEndEvents() | au! multiedit if g:multiedit_auto_reset == 1 " Clear all regions once you exit insert mode @@ -180,7 +196,7 @@ func! multiedit#clear(...) if !exists("b:regions") return endif - + " The region to delete might have been provided as an argument. if a:0 == 1 && type(a:1) == 4 let sel = a:1 @@ -235,7 +251,7 @@ func! multiedit#update(change_mode) " Clear highlights so we can make changes syn clear MultieditRegions syn clear MultieditFirstRegion - + " Prepare the new, altered line let linetext = getline(b:first_region.line) let lineendlen = (len(linetext) - b:first_region.suffix_length) @@ -256,7 +272,7 @@ func! multiedit#update(change_mode) for region in regions if a:change_mode - let region.col += s:offset + let region.col += s:offset if region.line != b:first_region.line || region.col != b:first_region.col " Get the old line let oldline = getline(region.line) @@ -269,7 +285,7 @@ func! multiedit#update(change_mode) let suffix = oldline[(region.col+region.len-1):] " Update the line - call setline(region.line, prefix.newtext.suffix) + call setline(region.line, prefix.newtext.suffix) endif if col >= b:first_region.col @@ -283,7 +299,7 @@ func! multiedit#update(change_mode) " ...move the highlight offset of regions after it if region.col >= b:first_region.col - let region.col += s:offset + let region.col += s:offset let s:offset = s:offset + len(newtext) - b:first_region.len endif @@ -316,7 +332,7 @@ func! multiedit#update(change_mode) " Remeasure the strlen let b:first_region.suffix_length = col([b:first_region.line, '$']) - b:first_region.col - b:first_region.len - + " Restore cursor location call cursor(b:first_region.line, b:first_region.col + cursor_col) @@ -415,7 +431,7 @@ func! s:isOverlapping(selA, selB) " Check for overlapping let selAend = a:selA.col + (a:selA.len - 1) let selBend = a:selB.col + (a:selB.len - 1) - return a:selA.col == a:selB.col || selAend == selBend + return a:selA.col == a:selB.col || selAend == selBend \ || a:selA.col == selBend || selAend == a:selB.col \ || (a:selA.col > a:selB.col && a:selA.col < selBend) \ || (selAend < selBend && selAend > a:selB.col) diff --git a/doc/multiedit.txt b/doc/multiedit.txt index b1c8236..536fb1f 100644 --- a/doc/multiedit.txt +++ b/doc/multiedit.txt @@ -93,6 +93,20 @@ The highlight regions can be customized, these are the defaults: hi default link MultieditRegions Search hi default link MultieditFirstRegion IncSearch < +If other plugins cause odd behaviour during multiple region editing, two +function scan be used to disable/re-enable this behaviour at apprpriate +times. An example showing how to disable NeoComplete during multiple +region editing is below: + + function! Multiple_cursors_before() + exe 'NeoCompleteLock' + echo 'Disabled autocomplete' + endfunction + + function! Multiple_cursors_after() + exe 'NeoCompleteUnlock' + echo 'Enabled autocomplete' + endfunction ============================================================================== KNOWN ISSUES *multiedit-issues* @@ -117,6 +131,11 @@ Thank you! ============================================================================== CHANGELOG *multiedit-changelog* +2014-11-13 [2.0.3] +- New: added conditional calls to Multiple_cursors_after/Multiple_cursors_before + functions defined in your ~/.vimrc. These functions allow disabling of + NeoComplete while editing multiple regions, for example. Implemenation copied + from terryma/vim-multiple-cursors issue #51 2013-03-28 [2.0.2] - Fix: when the region goes crazy when the text is at the start of the line (when len == 0 it would suddenly expand to the length of the line). diff --git a/plugin/multiedit.vim b/plugin/multiedit.vim index e03ba19..4a6cfbc 100644 --- a/plugin/multiedit.vim +++ b/plugin/multiedit.vim @@ -1,8 +1,8 @@ -" *multiedit.txt* Multi-editing for Vim -" +" *multiedit.txt* Multi-editing for Vim +" " Version: 2.0.2 " Author: Henrik Lissner -" License: MIT license +" License: MIT license " " Inspired by https://github.com/felixr/vim-multiedit, this plugin hopes to " fill that multi-cursor-shaped gap in your heart that Sublime Text 2 left you @@ -58,7 +58,7 @@ if g:multiedit_no_mappings != 1 nmap mA $:MultieditAddMark a nmap mI ^:MultieditAddMark i " Make the current selection/word an edit region - vmap m :MultieditAddRegion + vmap m :MultieditAddRegion nmap mm viw:MultieditAddRegion " Restore the regions from a previous edit session nmap mu :MultieditRestore @@ -73,6 +73,6 @@ if g:multiedit_no_mappings != 1 nmap md :MultieditClear " Unset all regions nmap mr :MultieditReset -endif +endif " vim: set foldmarker={{,}} foldlevel=0 foldmethod=marker