-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Combining with other <CR>
mappings
#131
Comments
Since you're using If you don't mind hard-coding an Endwise reference, this gets much easier to solve: function! s:CarriageReturn() abort
if some_condition
" ... the plugin will handle the <CR> mapping
else
return "\<CR>"
endif
endfunction
if exists('*EndwiseAppend')
imap <script><expr><buffer> <CR> EndwiseAppend(<SID>CarriageReturn())
else
imap <script><expr><buffer> <CR> <SID>CarriageReturn()
endif Now it's idempotent. You'll get the same result even if the map is defined a second time. I can maybe offer more specific advice if I see a complete working solution, one that doesn't have the "second time" problem. |
Ohh I see! I'd like advice in a more complete solution though :) I'm using the function! SmartPairsInitialize() abort
if get(b:, 'smartpairs_mappings_initialize', 0) == 0
let b:smartpairs_mappings_initialize = 1
let b:smartpairs_pairs = has_key(g:smartpairs_pairs, &filetype) ? g:smartpairs_pairs[&filetype] : g:smartpairs_default_pairs
call s:SetUpMappings()
end
endfunction
autocmd BufEnter * :call SmartPairsInitialize() The full source can be seen here. The mappings are defined in Thanks for your help :D |
I would strongly consider mapping globally. If you're going to map in every single buffer anyways, the only thing a buffer local map adds is extra complexity. That same solution I gave you should work if you drop the
|
Makes sense. Thanks for the advice! 🙏 |
If we can't see the existing global map, we can't use it to define a new one. References: #131
Hi, first of all thanks for the hard work in all of your Vim plugins! They are great and I use several of your plugins in my daily vimming.
I wrote a little plugin I use for autocompleting pairs (eg: adding
]
after I type[
). It does have some functionality to indent when pressingCR
.To make that compatible with
vim-endwise
(and maybe other similar plugins which use the<CR>
mapping) I saved the old mapping and restored it, doing something like this:When I'm in a file that uses
vim-endwise
, like a Ruby file, it still works, but when I'm in another file type, like a regular text file, it insertsEndwiseAppend(<SNR>45_CarriageReturn())
whenever I press enter.I see in the version notes, it includes:
I could try and hack something to make my plugin work, but seeing the patch notes I wonder: What's the preferred way to combine my own mappings with
vim-endwise
's<CR>
mappings?The text was updated successfully, but these errors were encountered: