Neovimの自動リストの継続とフォーマット、Luaを搭載
この質問は2つの方法で解釈できます。なぜ私はオートリストを作成したのですか、そしてなぜあなたがオートリストを使用する必要があるのか。
シンプルに聞こえますが、私が望んでいたのは、LUAのリスト継続プラグインだけでした。 bulets.vimは機能しますが、vimscriptで書かれており、長さは1000行以上です。言うまでもなく、私は適切なものを見つけることができなかったので、私は自分のものを作成することにしました。
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には2つの特別な関数があります。必要AutolistCycleNext
" AutolistCyclePrev
require("autolist").cycle_next_dr
require("autolist").cycle_prev_dr
一言で言えば、あなたがする必要があるのは、オートリストが新しいリストマーカーを見つけることができるLUAパターンマッチを作成することです。
LUAパターンに関するバッドではない記事は次のとおりですが、これらのパターンの例をPreloaded Patternsセクションで見つけることができます。
カスタムリストを定義する方法は次のとおりです。
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[.)]
)がマークダウンファイルに適用されます。
bullet.vimのようなチェックボックスを切り替えるためのマッピングがありますか?はい。
チェックボックスリストをサポートしていますか?はい。
オートリストを使用するとプラグインが壊れることがわかりましたか? #43を参照してください。基本的に、他のすべてのプラグインの後にオートライストがロードされることを確認する必要があります。それがうまくいかない場合は、新しい問題を自由に作成してください。また、マッピングの大文字が正しいことを確認するか、オートリストが他のプラグインを検出しないことを確認してください( <cr>
は<CR>
)。
この要点に触発されました
「すべてのソフトウェアは、面倒なほど複雑になるまで機能を追加します。その後、「よりシンプルな」ソリューションに置き換えられ、複雑になるまで機能を追加します。」
私は学業があるので、貢献者を探しています。