-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undo moves the cursor to the beginning of the line #49
Comments
That does seem like it would be very useful. Unfortunately, I can't really figure out a way to implement it :/. The plugin uses I tried placing some I'll leave this issue open in case someone comes up with a drive-by idea how to fix this, but I'm afraid I can't really offer a solution at this time. |
Here is my I'm not proud but it works for me. ™ hack. diff --git a/plugin/switch.vim b/plugin/switch.vim
index 1140ffe..001fa17 100644
--- a/plugin/switch.vim
+++ b/plugin/switch.vim
@@ -276,7 +276,9 @@ autocmd FileType rust let b:switch_definitions =
command! Switch call s:Switch()
function! s:Switch()
- silent call switch#Switch()
+ normal! i.
+ undojoin | normal! x
+ undojoin | silent call switch#Switch()
silent! call repeat#set(":Switch\<cr>")
endfunction |
This works for me: function! switch#mapping#Replace(match) dict
let pattern = a:match.pattern
let replacement = self.definitions[pattern]
let oldsearch = @/
if type(replacement) == s:type_dict
" maintain change delta for adjusting match limits
let delta = 0
for [pattern, sub_replacement] in items(replacement)
let last_column = col('$')
let pattern = s:LimitPattern(pattern, a:match.start, a:match.end + delta)
let pattern = escape(pattern, '/')
let sub_replacement = escape(sub_replacement, '/&')
silent! foldopen!
call setline('.', substitute(getline('.'), pattern, sub_replacement, 'ge'))
" remove pattern from history
call histdel('search', -1)
" length of the line may have changed, adjust
let delta += col('$') - last_column
endfor
else
let pattern = s:LimitPattern(pattern, a:match.start, a:match.end)
let pattern = escape(pattern, '/')
let replacement = escape(replacement, '/&')
call setline('.', substitute(getline('.'), pattern, replacement, ''))
" remove pattern from history
call histdel('search', -1)
endif
let @/ = oldsearch
endfunction That is, using Edit: I was using flags |
@mg979 This is interesting! The original reason I used But it seems like this also works for The remaining problem that I see is multiline patterns. Running the tests, here's the only one that fails for me: Lines 137 to 138 in 49c0eff
It might not be obvious why, but the problem is the start of the pattern, foo = {
one: one,
two: two,
} Switching on the With your change, only the single line is being considered, which removes that context. It's just one pattern, but it's a very convenient one for me, used in Rust as well. I could imagine checking that it's maybe alone on a line, ending with a comma, but the comma after the element is optional in coffeescript, and even in Rust, it's optional for the last element. The curly brackets seem like the most reliable way to tell. |
The best thing to me would be to leave the multiline patterns alone, already I wasn't sure about the call in the Edit: a solution might involve building a single pattern in the for loop and its replacement, then replace it in one go with a |
On this line:
With the cursor at
|
,gs
will toggle betweennot_to
andto
, as expected. If I subsequentlyu
ndo, however, the cursor moves to the beginning of the line. Is it possible for the cursor to remain where it was before the undo?The text was updated successfully, but these errors were encountered: