Lua가 구동하는 Neovim의 자동 목록 연속 및 서식
이 질문은 두 가지 방식으로 해석 될 수 있습니다. 내가 Autolist를 생성 한 이유와 Autolist를 사용해야하는 이유는 무엇입니까?
간단하게 들리지만 Lua의 List Continuation 플러그인이었습니다. 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>
누를 때 목록을 들여 보내려면 AutolistTab
기본적으로 탭을 다시 계산하여 <ct>
로 바꾸기 때문에 <ct>
AutolistRecalculate
으로 매핑하면됩니다.AutolistShiftTab
: 위와 동일하며 워드 프로세서를 복제하는 데 사용됩니다. <s-tab>
이에 매핑하면 <cd>AutolistRecalculate
로 변환됩니다. 위에서 설명한 모든 기능에는 Pascal Case 명령의 뱀 사례 버전 인 LUA 상대가 있습니다. 예를 들어 AutolistNewBullet
은 뱀 케이스가 require("autolist").new_bullet()
lua에 대한 두 가지 특수 기능이 필요합니다 : require("autolist").cycle_next_dr
and require("autolist").cycle_prev_dr
는 AutolistCycleNext
및 AutolistCyclePrev
의 도트-반복 가능한 버전을 제공합니다.
간단히 말해서, Autolist가 새 목록 마커를 찾을 수있는 LUA 패턴 일치를 만듭니다.
다음은 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
},
},
}
})
이제 ASCII 목록과 일치하는 LUA 패턴 (이 경우 %a[.)]
Markdown 파일에 적용됩니다.
Bullets.vim was와 같은 확인란을 토글하기위한 매핑이 있습니까? 예.
확인란 목록을 지원합니까? 예.
Autolist를 사용할 때 플러그인이 파손된다는 것을 알았습니까? #43을 참조하십시오. 기본적으로 다른 모든 플러그인 후에 자동리스트가로드되도록해야합니다. 그래도 효과가 없다면 새로운 문제를 만들어주십시오. 또한 매핑의 대문자가 올바른지 확인하거나 Autolist가 다른 플러그인을 감지하지 못하도록하십시오 ( <cr>
<CR>
).
이 요점에서 영감을 얻었습니다
"모든 소프트웨어는 성가 시게 복잡 할 때까지 기능을 추가합니다. 그런 다음"간단한 "솔루션으로 대체되어 기능이 복잡해 질 때까지 기능을 추가합니다."
학업이 있기 때문에 기고자를 찾고 있습니다.