[mini.pairs] Putting opening bracket on new line #2336
Closed
sebastianstudniczek
started this conversation in
General
Replies: 1 comment 1 reply
-
|
With 'mini.pairs' - I am afraid the answer is a no. It deliberately acts as an equivalent of A possible solution here might be to use if _G.MiniKeymap then
-- Act only when cursor is between `{}`
local is_inside_braces = function()
local line = vim.api.nvim_get_current_line()
local col = vim.api.nvim_win_get_cursor(0)[2]
return line:sub(col, col + 1) == '{}'
end
-- Mock a sequence of keys that produce an Allman style
-- NOTE: It is not perfect, as there might be issues with indentation and
-- trailing whitespace. Adjust it to fit the use case better
local allman_action = function() return '<Left><CR><Right><CR><CR><Up><Tab>' end
local allman_step = { condition = is_inside_braces, action = allman_action }
-- Create a buffer-local mapping that doesn't remap (to be able to use `<CR>` in the output
-- without infinite recursion
local opts = { remap = false, buf = 0 }
MiniKeymap.map_multistep('i', '<CR>', { 'pmenu_accept', allman_step, 'minipairs_cr' }, opts)
end |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I was wondering whether it's possible to implement
Allmanstyle for brackets.I am writing C# where the default convention is putting brackets on separate lines.
Let's say I have such method signature:
Is it possible to put both brackets on separate lines, either directly when inserting the open bracket or hitting enter when inside brackets?
Desired result:
Beta Was this translation helpful? Give feedback.
All reactions