Neovim的自动列表延续和格式,由LUA提供支持
这个问题可以通过两种方式来解释。为什么我创建自动师,以及为什么要使用自动级。
听起来很简单,但我想要的只是LUA中的列表延续插件。 Bullets.vim工作,但它是用Vimscript编写的,长一千多行。不用说,我找不到合适的一个,所以我决定创建自己的。
autolist.nvim's
文件相对较小,其中包含注释和格式。它努力在实施自动列表的基本功能时尽可能最小,并实现上下文意识到列表条目的重新编号/标记,以使您的思想摆脱格式,并在写下想法时使其在后台工作。
这是使用懒惰的。
{
" gaoDean/autolist.nvim " ,
ft = {
" markdown " ,
" text " ,
" tex " ,
" plaintex " ,
" norg " ,
},
config = function ()
require ( " autolist " ). setup ()
vim . keymap . set ( " i " , " <tab> " , " <cmd>AutolistTab<cr> " )
vim . keymap . set ( " i " , " <s-tab> " , " <cmd>AutolistShiftTab<cr> " )
-- vim.keymap.set("i", "<c-t>", "<c-t><cmd>AutolistRecalculate<cr>") -- an example of using <c-t> to indent
vim . keymap . set ( " i " , " <CR> " , " <CR><cmd>AutolistNewBullet<cr> " )
vim . keymap . set ( " n " , " o " , " o<cmd>AutolistNewBullet<cr> " )
vim . keymap . set ( " n " , " O " , " O<cmd>AutolistNewBulletBefore<cr> " )
vim . keymap . set ( " n " , " <CR> " , " <cmd>AutolistToggleCheckbox<cr><CR> " )
vim . keymap . set ( " n " , " <C-r> " , " <cmd>AutolistRecalculate<cr> " )
-- cycle list types with dot-repeat
vim . keymap . set ( " n " , " <leader>cn " , require ( " autolist " ). cycle_next_dr , { expr = true })
vim . keymap . set ( " n " , " <leader>cp " , require ( " autolist " ). cycle_prev_dr , { expr = true })
-- if you don't want dot-repeat
-- vim.keymap.set("n", "<leader>cn", "<cmd>AutolistCycleNext<cr>")
-- vim.keymap.set("n", "<leader>cp", "<cmd>AutolistCycleNext<cr>")
-- functions to recalculate list on edit
vim . keymap . set ( " n " , " >> " , " >><cmd>AutolistRecalculate<cr> " )
vim . keymap . set ( " n " , " << " , " <<<cmd>AutolistRecalculate<cr> " )
vim . keymap . set ( " n " , " dd " , " dd<cmd>AutolistRecalculate<cr> " )
vim . keymap . set ( " v " , " d " , " d<cmd>AutolistRecalculate<cr> " )
end ,
},
-|+|*
或1.|2.|3.
enter
/ return
,将自动创建一个新列表条目enter
/ return
将删除它,从而为您提供新的新句子。 - [x] checkboxes can be toggled with ` :AutolistToggleCheckbox ` , which is bound to ` return ` in normal mode if you used the default mappings
1 . [x] these can also be numbered
a) [ ] or these can work too
b) [ x ] see?
I. Roman numerals are also supported
II. Just press enter, and autolist will do the calculations for you
MX. All the way up
MXI. to infinity
MXII. It really will continue forever
MXIII. -I think
- you can cycle the type of the list with ` :AutolistCycleNext ` and ` :AutolistCyclePrev `
- below is a copy of this list after cycling twice
1 . you can cycle the type of the list with ` :AutolistCycleNext ` and ` :AutolistCyclePrev `
2 . below is a copy of this list after cycling twice
local list_patterns = {
neorg_1 = " %- " ,
neorg_2 = " %-%- " ,
neorg_3 = " %-%-%- " ,
neorg_4 = " %-%-%-%- " ,
neorg_5 = " %-%-%-%-%- " ,
unordered = " [-+*] " , -- - + *
digit = " %d+[.)] " , -- 1. 2. 3.
ascii = " %a[.)] " , -- a) b) c)
roman = " %u*[.)] " , -- I. II. III.
latex_item = " \ item " ,
}
local default_config = {
enabled = true ,
colon = { -- if a line ends in a colon
indent = true , -- if in list and line ends in `:` then create list
indent_raw = true , -- above, but doesn't need to be in a list to work
preferred = " - " , -- what the new list starts with (can be `1.` etc)
},
cycle = { -- Cycles the list type in order
" - " , -- whatever you put here will match the first item in your list
" * " , -- for example if your list started with a `-` it would go to `*`
" 1. " , -- this says that if your list starts with a `*` it would go to `1.`
" 1) " , -- this all leverages the power of recalculate.
" a) " , -- i spent many hours on that function
" I. " , -- try it, change the first bullet in a list to `a)`, and press recalculate
},
lists = { -- configures list behaviours
-- Each key in lists represents a filetype.
-- The value is a table of all the list patterns that the filetype implements.
-- See how to define your custom list below in the readme.
-- You must put the file name for the filetype, not the file extension
-- To get the "file name", it is just =:set filetype?= or =:se ft?=.
markdown = {
list_patterns . unordered ,
list_patterns . digit ,
list_patterns . ascii , -- for example this specifies activate the ascii list
list_patterns . roman , -- type for markdown files.
},
text = {
list_patterns . unordered ,
list_patterns . digit ,
list_patterns . ascii ,
list_patterns . roman ,
},
norg = {
list_patterns . neorg_1 ,
list_patterns . neorg_2 ,
list_patterns . neorg_3 ,
list_patterns . neorg_4 ,
list_patterns . neorg_5 ,
},
tex = { list_patterns . latex_item },
plaintex = { list_patterns . latex_item },
},
checkbox = {
left = " %[ " , -- the left checkbox delimiter (you could change to "%(" for brackets)
right = " %] " , -- the right checkbox delim (same customisation as above)
fill = " x " , -- if you do the above two customisations, your checkbox could be (x) instead of [x]
},
-- this is all based on lua patterns, see "Defining custom lists" for a nice article to learn them
}
这是所有公共功能:
AutolistNewBullet
:在当前行上添加了一个新子弹AutolistRecalculate
:重新计算有序列表AutolistToggleCheckbox
:在当前行上切换复选框AutolistCycleNext
循环:根据config.cycle
循环列表类型AutolistCyclePrev
:上面,但向后AutolistTab
:具有特殊的用例,在此按下时,您想缩小列表。如果要在按<ct>
时缩进列表,则只需要映射<ct>
即可AutolistRecalculate
因为AutolistTab
基本上将选项卡变成<ct>
然后重新计算。AutolistShiftTab
:与上述相同的内容,用于复制文字处理器。映射<s-tab>
将其转换为<cd>AutolistRecalculate
。上面描述的所有功能都有LUA对应物,这些功能只是Pascal Case命令的蛇案例版本。例如, AutolistNewBullet
的蛇案例对应物require("autolist").new_bullet()
LUA有两个特殊功能: require("autolist").cycle_next_dr
and require("autolist").cycle_prev_dr
,可提供可dot-Repeat-Repeat-Repeat- AutolistCycleNext
和AutolistCyclePrev
。
简而言之,您需要做的就是进行LUA模式匹配,该匹配使Autolist可以找到您的新列表标记。
这是一篇关于LUA模式的不糟糕的文章,但是您可以在“预加载模式”部分中找到这些模式的示例。
这是定义您的自定义列表的方法:
local my_list_patterns = {
test = " %a[.)] "
}
require ( ' autolist ' ). setup ({
lists = {
markdown = {
" %a[.)] " , -- insert your custom lua pattern here
my_list_patterns . test , -- or use a variable
},
},
}
})
现在,您的lua模式(在这种情况下为%a[.)]
与ASCII列表匹配)将应用于降价文件。
它是否有映射来切换Bullets.vim具有的复选框?是的。
它支持复选框列表吗?是的。
发现使用Autolist时插件会断开?参见#43。基本上,您需要确保在所有其他插件之后自动列加载。如果那不起作用,请随时创建一个新问题。另外,请确保您的映射的资本化正确,否则自动人员将无法检测到其他插件( <cr>
应该是<CR>
)。
受这个要旨的启发
“所有软件都添加了功能,直到令人讨厌的复杂性。
寻找贡献者,因为我有学业,这意味着我有时无法跟上问题