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>
)。
受這個要旨的啟發
“所有軟件都添加了功能,直到令人討厭的複雜性。
尋找貢獻者,因為我有學業,這意味著我有時無法跟上問題