-
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
Enable switching booleans anywhere on the line and returning to original cursor position #79
Comments
That's a good way to handle one-off patterns. The problem is the more complicated the pattern gets, it gets harder to build something compatible on top of them :D. One thing I'll note is that I think your
I agree it might be useful -- could you add it to the wiki? https://github.com/AndrewRadev/switch.vim/wiki I've linked to the wiki in the docs under "Customization", although I don't know how visible it is. |
Thanks for the tip! I implemented your recommendation and tried to include also 0 and 1 as they do the bool job in some languages. Switch doesn't switch them so I'm doing a search and replace which works in Vim but not inside my function. Can you take a look? function! ToggleBool()
let save_pos = getpos(".")
normal 0
if call search('\c\<true\>\|\<false\>', '', line('.')) > 0
execute 'Switch'
else
execute 's/\<1\>/0/'
execute 's/\<0\>/1/'
endif
call setpos(".", save_pos)
endfunction |
The problem seems to be You can try function! ToggleBool()
let save_pos = getpos(".")
normal! 0
if search('\c\<true\>\|\<false\>', '', line('.')) > 0
Switch
elseif search('\<1\>', '', line('.')) > 0
" decrement 1 -> 0
execute "normal! \<c-x>"
elseif search('\<0\>', '', line('.')) > 0
" increment 0 -> 1
execute "normal! \<c-a>"
endif
call setpos(".", save_pos)
endfunction The mappings |
Awesome! Merci man - it works perfectly 😎 gerazov/vim-toggle-bool@285ff87 |
Awesome :). I'll close this issue for now, but as I said, feel free to add a link to your plugin in the wiki 👍 |
I just added a page 😉 |
Great plugin! 👍
It would be awesome to be able to switch (bools) anywhere on the line and then have the cursor return to the original position. Possibly related to #49 and #14.
I implemented a function to do this for Python. I dunno if it can be used to upgrade the plugin, but it could be useful for someone else, so maybe include it as an example in the documentation?
I've used this function as a bool only toggle plug-in vim-toggle-bool
The text was updated successfully, but these errors were encountered: