ความต่อเนื่องของรายการอัตโนมัติและการจัดรูปแบบสำหรับ NeoVim ขับเคลื่อนโดย Lua
คำถามนี้สามารถตีความได้สองวิธี ทำไมฉันถึงสร้าง Autolist และทำไมคุณควรใช้ Autolist
ฟังดูง่าย แต่ทั้งหมดที่ฉันต้องการคือปลั๊กอินต่อเนื่องใน Lua bullets.vim ทำงาน แต่มันถูกเขียนด้วย Vimscript และมีความยาวมากกว่าหนึ่งพันบรรทัด ไม่จำเป็นต้องพูดว่าฉันไม่พบสิ่งที่เหมาะสมดังนั้นฉันจึงตัดสินใจสร้างตัวเอง
ไฟล์ autolist.nvim's
มีขนาดค่อนข้างเล็กโดยมีไฟล์พร้อมความคิดเห็นและการจัดรูปแบบ มันมุ่งมั่นที่จะน้อยที่สุดเท่าที่จะเป็นไปได้ในขณะที่ใช้ฟังก์ชั่นพื้นฐานของรายการอัตโนมัติและดำเนินการตามบริบทการกำหนดหมายเลข/การทำเครื่องหมายของรายการรายการเพื่อปิดใจการจัดรูปแบบและทำงานในพื้นหลังในขณะที่คุณเขียนความคิดของคุณ
นี่คือ Lazy.nvim แต่คุณสามารถปรับให้เข้ากับผู้จัดการแพ็คเกจอื่น ๆ ได้เช่นกัน:
{
" 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
: สิ่งเดียวกับข้างต้นใช้เพื่อทำซ้ำโปรเซสเซอร์ Word การแม็พ <s-tab>
ไปยังสิ่งนี้จะแปลงเป็น <cd>AutolistRecalculate
ฟังก์ชั่นทั้งหมดที่อธิบายไว้ข้างต้นมีคู่ Lua ซึ่งเป็นเพียงรุ่นกรณีงูของคำสั่งกรณี Pascal ตัวอย่างเช่น AutolistNewBullet
มีเคสงู require("autolist").new_bullet()
มีฟังก์ชั่นพิเศษสองอย่างสำหรับ LUA: require("autolist").cycle_next_dr
และ require("autolist").cycle_prev_dr
ซึ่งให้ AutolistCycleNext
และ AutolistCyclePrev
เวอร์ชัน dot-repeatable
โดยสรุปสิ่งที่คุณต้องทำคือทำให้รูปแบบ 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) จะถูกนำไปใช้กับไฟล์ Markdown
มันมีการทำแผนที่สำหรับการสลับช่องทำเครื่องหมายเช่นกระสุนหรือไม่? ใช่.
รองรับรายการช่องทำเครื่องหมายหรือไม่? ใช่.
พบว่าปลั๊กอินแตกเมื่อคุณใช้ Autolist? ดู #43. โดยทั่วไปคุณต้องตรวจสอบให้แน่ใจว่ามีการโหลดอัตโนมัติ หลังจาก ปลั๊กอินอื่น ๆ ทั้งหมด หากไม่ได้ผลอย่าลังเลที่จะสร้างปัญหาใหม่ นอกจากนี้ตรวจสอบให้แน่ใจว่าการทำแผนที่เป็นตัวพิมพ์ใหญ่ของคุณนั้นถูกต้องหรือ Autolist จะไม่ตรวจจับปลั๊กอินอื่น ๆ ( <cr>
ควรเป็น <CR>
)
แรงบันดาลใจจากส่วนสำคัญนี้
"ซอฟต์แวร์ทั้งหมดจะเพิ่มคุณสมบัติจนกว่าจะซับซ้อนอย่างน่ารำคาญจากนั้นจะถูกแทนที่ด้วยโซลูชัน" ง่ายกว่า "ซึ่งเพิ่มคุณสมบัติจนกว่าจะซับซ้อน"
กำลังมองหาผู้มีส่วนร่วมเพราะฉันมีงานโรงเรียนซึ่งหมายความว่าบางครั้งฉันก็ไม่สามารถติดตามปัญหาได้