mirror of
https://github.com/cap153/nvim.git
synced 2026-04-28 01:06:37 +08:00
first commit
This commit is contained in:
commit
3b19a9c8a8
29 changed files with 2428 additions and 0 deletions
435
lua/core/cursor.lua
Normal file
435
lua/core/cursor.lua
Normal file
|
|
@ -0,0 +1,435 @@
|
|||
-- ===
|
||||
-- === 光标移动neovide
|
||||
-- ===
|
||||
-- 判断 CPU 架构
|
||||
local arch = jit and jit.arch or ""
|
||||
local is_arm = arch:match("arm") or arch:match("aarch64")
|
||||
if is_arm then
|
||||
vim.o.guifont = "ComicShannsMono Nerd Font:h24"
|
||||
end
|
||||
vim.keymap.set('n', '<sC-c>', '"+y', { noremap = true })
|
||||
vim.keymap.set('v', '<sC-c>', '"+y', { noremap = true })
|
||||
if vim.g.neovide then
|
||||
if not is_arm then
|
||||
vim.env.HTTP_PROXY = "http://127.0.0.1:7897"
|
||||
vim.env.HTTPS_PROXY = "http://127.0.0.1:7897"
|
||||
end
|
||||
-- https://github.com/neovide/neovide/issues/1282
|
||||
vim.api.nvim_set_keymap('n', '<sC-v>', '"+p', { noremap = true })
|
||||
vim.api.nvim_set_keymap('v', '<sC-v>', '"+P', { noremap = true })
|
||||
vim.api.nvim_set_keymap('c', '<sC-v>', '<C-R>+', { noremap = true })
|
||||
vim.api.nvim_set_keymap('i', '<sC-v>', '<C-R>+', { noremap = true })
|
||||
vim.api.nvim_set_keymap('t', '<sC-v>', '<C-\\><C-n>"+Pi', { noremap = true })
|
||||
vim.g.neovide_opacity = 0.75
|
||||
-- vim.o.guifont = "ComicShannsMono Nerd Font:h16" -- text below applies for VimScript
|
||||
vim.o.guifont = "Ioskeley Mono:h15" -- text below applies for VimScript
|
||||
-- 全屏,可以在i3和sway的配置中设置
|
||||
-- vim.g.neovide_fullscreen = true
|
||||
end
|
||||
-- ===
|
||||
-- === map function
|
||||
-- ===
|
||||
local function mapkey(mode, lhs, rhs)
|
||||
vim.api.nvim_set_keymap(mode, lhs, rhs, { noremap = true })
|
||||
end
|
||||
-- interestind stess
|
||||
mapkey('', '[a<LEADER>', '1k')
|
||||
mapkey('', '[r<LEADER>', '2k')
|
||||
mapkey('', '[s<LEADER>', '3k')
|
||||
mapkey('', '[t<LEADER>', '4k')
|
||||
mapkey('', '[d<LEADER>', '5k')
|
||||
mapkey('', '[h<LEADER>', '6k')
|
||||
mapkey('', '[n<LEADER>', '7k')
|
||||
mapkey('', '[e<LEADER>', '8k')
|
||||
mapkey('', '[i<LEADER>', '9k')
|
||||
mapkey('', '[ao<LEADER>', '10k')
|
||||
mapkey('', '[aa<LEADER>', '11k')
|
||||
mapkey('', '[ar<LEADER>', '12k')
|
||||
mapkey('', '[as<LEADER>', '13k')
|
||||
mapkey('', '[at<LEADER>', '14k')
|
||||
mapkey('', '[ad<LEADER>', '15k')
|
||||
mapkey('', '[ah<LEADER>', '16k')
|
||||
mapkey('', '[an<LEADER>', '17k')
|
||||
mapkey('', '[ae<LEADER>', '18k')
|
||||
mapkey('', '[ai<LEADER>', '19k')
|
||||
mapkey('', '[ro<LEADER>', '20k')
|
||||
mapkey('', '[ra<LEADER>', '21k')
|
||||
mapkey('', '[rr<LEADER>', '22k')
|
||||
mapkey('', '[rs<LEADER>', '23k')
|
||||
mapkey('', '[rt<LEADER>', '24k')
|
||||
mapkey('', '[rd<LEADER>', '25k')
|
||||
mapkey('', '[rh<LEADER>', '26k')
|
||||
mapkey('', '[rn<LEADER>', '27k')
|
||||
mapkey('', '[re<LEADER>', '28k')
|
||||
mapkey('', '[ri<LEADER>', '29k')
|
||||
mapkey('', '[so<LEADER>', '30k')
|
||||
mapkey('', '[sa<LEADER>', '31k')
|
||||
mapkey('', '[sr<LEADER>', '32k')
|
||||
mapkey('', '[ss<LEADER>', '33k')
|
||||
mapkey('', '[st<LEADER>', '34k')
|
||||
mapkey('', '[sd<LEADER>', '35k')
|
||||
mapkey('', '[sh<LEADER>', '36k')
|
||||
mapkey('', '[sn<LEADER>', '37k')
|
||||
mapkey('', '[se<LEADER>', '38k')
|
||||
mapkey('', '[si<LEADER>', '39k')
|
||||
mapkey('', '[to<LEADER>', '40k')
|
||||
mapkey('', '[ta<LEADER>', '41k')
|
||||
mapkey('', '[tr<LEADER>', '42k')
|
||||
mapkey('', '[ts<LEADER>', '43k')
|
||||
mapkey('', '[tt<LEADER>', '44k')
|
||||
mapkey('', '[td<LEADER>', '45k')
|
||||
mapkey('', '[th<LEADER>', '46k')
|
||||
mapkey('', '[tn<LEADER>', '47k')
|
||||
mapkey('', '[te<LEADER>', '48k')
|
||||
mapkey('', '[ti<LEADER>', '49k')
|
||||
mapkey('', '[do<LEADER>', '50k')
|
||||
mapkey('', '[da<LEADER>', '51k')
|
||||
mapkey('', '[dr<LEADER>', '52k')
|
||||
mapkey('', '[ds<LEADER>', '53k')
|
||||
mapkey('', '[dt<LEADER>', '54k')
|
||||
mapkey('', '[dd<LEADER>', '55k')
|
||||
mapkey('', '[dh<LEADER>', '56k')
|
||||
mapkey('', '[dn<LEADER>', '57k')
|
||||
mapkey('', '[de<LEADER>', '58k')
|
||||
mapkey('', '[di<LEADER>', '59k')
|
||||
mapkey('', '[ho<LEADER>', '60k')
|
||||
mapkey('', '[ha<LEADER>', '61k')
|
||||
mapkey('', '[hr<LEADER>', '62k')
|
||||
mapkey('', '[hs<LEADER>', '63k')
|
||||
mapkey('', '[ht<LEADER>', '64k')
|
||||
mapkey('', '[hd<LEADER>', '65k')
|
||||
mapkey('', '[hh<LEADER>', '66k')
|
||||
mapkey('', '[hn<LEADER>', '67k')
|
||||
mapkey('', '[he<LEADER>', '68k')
|
||||
mapkey('', '[hi<LEADER>', '69k')
|
||||
mapkey('', '[no<LEADER>', '70k')
|
||||
mapkey('', '[na<LEADER>', '71k')
|
||||
mapkey('', '[nr<LEADER>', '72k')
|
||||
mapkey('', '[ns<LEADER>', '73k')
|
||||
mapkey('', '[nt<LEADER>', '74k')
|
||||
mapkey('', '[nd<LEADER>', '75k')
|
||||
mapkey('', '[nh<LEADER>', '76k')
|
||||
mapkey('', '[nn<LEADER>', '77k')
|
||||
mapkey('', '[ne<LEADER>', '78k')
|
||||
mapkey('', '[ni<LEADER>', '79k')
|
||||
mapkey('', '[eo<LEADER>', '80k')
|
||||
mapkey('', '[ea<LEADER>', '81k')
|
||||
mapkey('', '[er<LEADER>', '82k')
|
||||
mapkey('', '[es<LEADER>', '83k')
|
||||
mapkey('', '[et<LEADER>', '84k')
|
||||
mapkey('', '[ed<LEADER>', '85k')
|
||||
mapkey('', '[eh<LEADER>', '86k')
|
||||
mapkey('', '[en<LEADER>', '87k')
|
||||
mapkey('', '[ee<LEADER>', '88k')
|
||||
mapkey('', '[ei<LEADER>', '89k')
|
||||
mapkey('', '[io<LEADER>', '90k')
|
||||
mapkey('', '[ia<LEADER>', '91k')
|
||||
mapkey('', '[ir<LEADER>', '92k')
|
||||
mapkey('', '[is<LEADER>', '93k')
|
||||
mapkey('', '[it<LEADER>', '94k')
|
||||
mapkey('', '[id<LEADER>', '95k')
|
||||
mapkey('', '[ih<LEADER>', '96k')
|
||||
mapkey('', '[in<LEADER>', '97k')
|
||||
mapkey('', '[ie<LEADER>', '98k')
|
||||
mapkey('', '[ii<LEADER>', '99k')
|
||||
mapkey('', '[aoo<LEADER>', '100k')
|
||||
mapkey('', '[aoa<LEADER>', '101k')
|
||||
mapkey('', '[aor<LEADER>', '102k')
|
||||
mapkey('', '[aos<LEADER>', '103k')
|
||||
mapkey('', '[aot<LEADER>', '104k')
|
||||
mapkey('', '[aod<LEADER>', '105k')
|
||||
mapkey('', '[aoh<LEADER>', '106k')
|
||||
mapkey('', '[aon<LEADER>', '107k')
|
||||
mapkey('', '[aoe<LEADER>', '108k')
|
||||
mapkey('', '[aoi<LEADER>', '109k')
|
||||
mapkey('', '[aao<LEADER>', '110k')
|
||||
mapkey('', '[aaa<LEADER>', '111k')
|
||||
mapkey('', '[aar<LEADER>', '112k')
|
||||
mapkey('', '[aas<LEADER>', '113k')
|
||||
mapkey('', '[aat<LEADER>', '114k')
|
||||
mapkey('', '[aad<LEADER>', '115k')
|
||||
mapkey('', '[aah<LEADER>', '116k')
|
||||
mapkey('', '[aan<LEADER>', '117k')
|
||||
mapkey('', '[aae<LEADER>', '118k')
|
||||
mapkey('', '[aai<LEADER>', '119k')
|
||||
mapkey('', '[aro<LEADER>', '120k')
|
||||
mapkey('', '[ara<LEADER>', '121k')
|
||||
mapkey('', '[arr<LEADER>', '122k')
|
||||
mapkey('', '[ars<LEADER>', '123k')
|
||||
mapkey('', '[art<LEADER>', '124k')
|
||||
mapkey('', '[ard<LEADER>', '125k')
|
||||
mapkey('', '[arh<LEADER>', '126k')
|
||||
mapkey('', '[arn<LEADER>', '127k')
|
||||
mapkey('', '[are<LEADER>', '128k')
|
||||
mapkey('', '[ari<LEADER>', '129k')
|
||||
mapkey('', '[aso<LEADER>', '130k')
|
||||
mapkey('', '[asa<LEADER>', '131k')
|
||||
mapkey('', '[asr<LEADER>', '132k')
|
||||
mapkey('', '[ass<LEADER>', '133k')
|
||||
mapkey('', '[ast<LEADER>', '134k')
|
||||
mapkey('', '[asd<LEADER>', '135k')
|
||||
mapkey('', '[ash<LEADER>', '136k')
|
||||
mapkey('', '[asn<LEADER>', '137k')
|
||||
mapkey('', '[ase<LEADER>', '138k')
|
||||
mapkey('', '[asi<LEADER>', '139k')
|
||||
mapkey('', '[ato<LEADER>', '140k')
|
||||
mapkey('', '[ata<LEADER>', '141k')
|
||||
mapkey('', '[atr<LEADER>', '142k')
|
||||
mapkey('', '[ats<LEADER>', '143k')
|
||||
mapkey('', '[att<LEADER>', '144k')
|
||||
mapkey('', '[atd<LEADER>', '145k')
|
||||
mapkey('', '[ath<LEADER>', '146k')
|
||||
mapkey('', '[atn<LEADER>', '147k')
|
||||
mapkey('', '[ate<LEADER>', '148k')
|
||||
mapkey('', '[ati<LEADER>', '149k')
|
||||
mapkey('', '[ado<LEADER>', '150k')
|
||||
mapkey('', '[ada<LEADER>', '151k')
|
||||
mapkey('', '[adr<LEADER>', '152k')
|
||||
mapkey('', '[ads<LEADER>', '153k')
|
||||
mapkey('', '[adt<LEADER>', '154k')
|
||||
mapkey('', '[add<LEADER>', '155k')
|
||||
mapkey('', '[adh<LEADER>', '156k')
|
||||
mapkey('', '[adn<LEADER>', '157k')
|
||||
mapkey('', '[ade<LEADER>', '158k')
|
||||
mapkey('', '[adi<LEADER>', '159k')
|
||||
mapkey('', '[aho<LEADER>', '160k')
|
||||
mapkey('', '[aha<LEADER>', '161k')
|
||||
mapkey('', '[ahr<LEADER>', '162k')
|
||||
mapkey('', '[ahs<LEADER>', '163k')
|
||||
mapkey('', '[aht<LEADER>', '164k')
|
||||
mapkey('', '[ahd<LEADER>', '165k')
|
||||
mapkey('', '[ahh<LEADER>', '166k')
|
||||
mapkey('', '[ahn<LEADER>', '167k')
|
||||
mapkey('', '[ahe<LEADER>', '168k')
|
||||
mapkey('', '[ahi<LEADER>', '169k')
|
||||
mapkey('', '[ano<LEADER>', '170k')
|
||||
mapkey('', '[ana<LEADER>', '171k')
|
||||
mapkey('', '[anr<LEADER>', '172k')
|
||||
mapkey('', '[ans<LEADER>', '173k')
|
||||
mapkey('', '[ant<LEADER>', '174k')
|
||||
mapkey('', '[and<LEADER>', '175k')
|
||||
mapkey('', '[anh<LEADER>', '176k')
|
||||
mapkey('', '[ann<LEADER>', '177k')
|
||||
mapkey('', '[ane<LEADER>', '178k')
|
||||
mapkey('', '[ani<LEADER>', '179k')
|
||||
mapkey('', '[aeo<LEADER>', '180k')
|
||||
mapkey('', '[aea<LEADER>', '181k')
|
||||
mapkey('', '[aer<LEADER>', '182k')
|
||||
mapkey('', '[aes<LEADER>', '183k')
|
||||
mapkey('', '[aet<LEADER>', '184k')
|
||||
mapkey('', '[aed<LEADER>', '185k')
|
||||
mapkey('', '[aeh<LEADER>', '186k')
|
||||
mapkey('', '[aen<LEADER>', '187k')
|
||||
mapkey('', '[aee<LEADER>', '188k')
|
||||
mapkey('', '[aei<LEADER>', '189k')
|
||||
mapkey('', '[aio<LEADER>', '190k')
|
||||
mapkey('', '[aia<LEADER>', '191k')
|
||||
mapkey('', '[air<LEADER>', '192k')
|
||||
mapkey('', '[ais<LEADER>', '193k')
|
||||
mapkey('', '[ait<LEADER>', '194k')
|
||||
mapkey('', '[aid<LEADER>', '195k')
|
||||
mapkey('', '[aih<LEADER>', '196k')
|
||||
mapkey('', '[ain<LEADER>', '197k')
|
||||
mapkey('', '[aie<LEADER>', '198k')
|
||||
mapkey('', '[aii<LEADER>', '199k')
|
||||
|
||||
|
||||
mapkey("", "'a<LEADER>", "1j")
|
||||
mapkey("", "'r<LEADER>", "2j")
|
||||
mapkey("", "'s<LEADER>", "3j")
|
||||
mapkey("", "'t<LEADER>", "4j")
|
||||
mapkey("", "'d<LEADER>", "5j")
|
||||
mapkey("", "'h<LEADER>", "6j")
|
||||
mapkey("", "'n<LEADER>", "7j")
|
||||
mapkey("", "'e<LEADER>", "8j")
|
||||
mapkey("", "'i<LEADER>", "9j")
|
||||
mapkey("", "'ao<LEADER>", "10j")
|
||||
mapkey("", "'aa<LEADER>", "11j")
|
||||
mapkey("", "'ar<LEADER>", "12j")
|
||||
mapkey("", "'as<LEADER>", "13j")
|
||||
mapkey("", "'at<LEADER>", "14j")
|
||||
mapkey("", "'ad<LEADER>", "15j")
|
||||
mapkey("", "'ah<LEADER>", "16j")
|
||||
mapkey("", "'an<LEADER>", "17j")
|
||||
mapkey("", "'ae<LEADER>", "18j")
|
||||
mapkey("", "'ai<LEADER>", "19j")
|
||||
mapkey("", "'ro<LEADER>", "20j")
|
||||
mapkey("", "'ra<LEADER>", "21j")
|
||||
mapkey("", "'rr<LEADER>", "22j")
|
||||
mapkey("", "'rs<LEADER>", "23j")
|
||||
mapkey("", "'rt<LEADER>", "24j")
|
||||
mapkey("", "'rd<LEADER>", "25j")
|
||||
mapkey("", "'rh<LEADER>", "26j")
|
||||
mapkey("", "'rn<LEADER>", "27j")
|
||||
mapkey("", "'re<LEADER>", "28j")
|
||||
mapkey("", "'ri<LEADER>", "29j")
|
||||
mapkey("", "'so<LEADER>", "30j")
|
||||
mapkey("", "'sa<LEADER>", "31j")
|
||||
mapkey("", "'sr<LEADER>", "32j")
|
||||
mapkey("", "'ss<LEADER>", "33j")
|
||||
mapkey("", "'st<LEADER>", "34j")
|
||||
mapkey("", "'sd<LEADER>", "35j")
|
||||
mapkey("", "'sh<LEADER>", "36j")
|
||||
mapkey("", "'sn<LEADER>", "37j")
|
||||
mapkey("", "'se<LEADER>", "38j")
|
||||
mapkey("", "'si<LEADER>", "39j")
|
||||
mapkey("", "'to<LEADER>", "40j")
|
||||
mapkey("", "'ta<LEADER>", "41j")
|
||||
mapkey("", "'tr<LEADER>", "42j")
|
||||
mapkey("", "'ts<LEADER>", "43j")
|
||||
mapkey("", "'tt<LEADER>", "44j")
|
||||
mapkey("", "'td<LEADER>", "45j")
|
||||
mapkey("", "'th<LEADER>", "46j")
|
||||
mapkey("", "'tn<LEADER>", "47j")
|
||||
mapkey("", "'te<LEADER>", "48j")
|
||||
mapkey("", "'ti<LEADER>", "49j")
|
||||
mapkey("", "'do<LEADER>", "50j")
|
||||
mapkey("", "'da<LEADER>", "51j")
|
||||
mapkey("", "'dr<LEADER>", "52j")
|
||||
mapkey("", "'ds<LEADER>", "53j")
|
||||
mapkey("", "'dt<LEADER>", "54j")
|
||||
mapkey("", "'dd<LEADER>", "55j")
|
||||
mapkey("", "'dh<LEADER>", "56j")
|
||||
mapkey("", "'dn<LEADER>", "57j")
|
||||
mapkey("", "'de<LEADER>", "58j")
|
||||
mapkey("", "'di<LEADER>", "59j")
|
||||
mapkey("", "'ho<LEADER>", "60j")
|
||||
mapkey("", "'ha<LEADER>", "61j")
|
||||
mapkey("", "'hr<LEADER>", "62j")
|
||||
mapkey("", "'hs<LEADER>", "63j")
|
||||
mapkey("", "'ht<LEADER>", "64j")
|
||||
mapkey("", "'hd<LEADER>", "65j")
|
||||
mapkey("", "'hh<LEADER>", "66j")
|
||||
mapkey("", "'hn<LEADER>", "67j")
|
||||
mapkey("", "'he<LEADER>", "68j")
|
||||
mapkey("", "'hi<LEADER>", "69j")
|
||||
mapkey("", "'no<LEADER>", "70j")
|
||||
mapkey("", "'na<LEADER>", "71j")
|
||||
mapkey("", "'nr<LEADER>", "72j")
|
||||
mapkey("", "'ns<LEADER>", "73j")
|
||||
mapkey("", "'nt<LEADER>", "74j")
|
||||
mapkey("", "'nd<LEADER>", "75j")
|
||||
mapkey("", "'nh<LEADER>", "76j")
|
||||
mapkey("", "'nn<LEADER>", "77j")
|
||||
mapkey("", "'ne<LEADER>", "78j")
|
||||
mapkey("", "'ni<LEADER>", "79j")
|
||||
mapkey("", "'eo<LEADER>", "80j")
|
||||
mapkey("", "'ea<LEADER>", "81j")
|
||||
mapkey("", "'er<LEADER>", "82j")
|
||||
mapkey("", "'es<LEADER>", "83j")
|
||||
mapkey("", "'et<LEADER>", "84j")
|
||||
mapkey("", "'ed<LEADER>", "85j")
|
||||
mapkey("", "'eh<LEADER>", "86j")
|
||||
mapkey("", "'en<LEADER>", "87j")
|
||||
mapkey("", "'ee<LEADER>", "88j")
|
||||
mapkey("", "'ei<LEADER>", "89j")
|
||||
mapkey("", "'io<LEADER>", "90j")
|
||||
mapkey("", "'ia<LEADER>", "91j")
|
||||
mapkey("", "'ir<LEADER>", "92j")
|
||||
mapkey("", "'is<LEADER>", "93j")
|
||||
mapkey("", "'it<LEADER>", "94j")
|
||||
mapkey("", "'id<LEADER>", "95j")
|
||||
mapkey("", "'ih<LEADER>", "96j")
|
||||
mapkey("", "'in<LEADER>", "97j")
|
||||
mapkey("", "'ie<LEADER>", "98j")
|
||||
mapkey("", "'ii<LEADER>", "99j")
|
||||
mapkey("", "'aoo<LEADER>", "100j")
|
||||
mapkey("", "'aoa<LEADER>", "101j")
|
||||
mapkey("", "'aor<LEADER>", "102j")
|
||||
mapkey("", "'aos<LEADER>", "103j")
|
||||
mapkey("", "'aot<LEADER>", "104j")
|
||||
mapkey("", "'aod<LEADER>", "105j")
|
||||
mapkey("", "'aoh<LEADER>", "106j")
|
||||
mapkey("", "'aon<LEADER>", "107j")
|
||||
mapkey("", "'aoe<LEADER>", "108j")
|
||||
mapkey("", "'aoi<LEADER>", "109j")
|
||||
mapkey("", "'aao<LEADER>", "110j")
|
||||
mapkey("", "'aaa<LEADER>", "111j")
|
||||
mapkey("", "'aar<LEADER>", "112j")
|
||||
mapkey("", "'aas<LEADER>", "113j")
|
||||
mapkey("", "'aat<LEADER>", "114j")
|
||||
mapkey("", "'aad<LEADER>", "115j")
|
||||
mapkey("", "'aah<LEADER>", "116j")
|
||||
mapkey("", "'aan<LEADER>", "117j")
|
||||
mapkey("", "'aae<LEADER>", "118j")
|
||||
mapkey("", "'aai<LEADER>", "119j")
|
||||
mapkey("", "'aro<LEADER>", "120j")
|
||||
mapkey("", "'ara<LEADER>", "121j")
|
||||
mapkey("", "'arr<LEADER>", "122j")
|
||||
mapkey("", "'ars<LEADER>", "123j")
|
||||
mapkey("", "'art<LEADER>", "124j")
|
||||
mapkey("", "'ard<LEADER>", "125j")
|
||||
mapkey("", "'arh<LEADER>", "126j")
|
||||
mapkey("", "'arn<LEADER>", "127j")
|
||||
mapkey("", "'are<LEADER>", "128j")
|
||||
mapkey("", "'ari<LEADER>", "129j")
|
||||
mapkey("", "'aso<LEADER>", "130j")
|
||||
mapkey("", "'asa<LEADER>", "131j")
|
||||
mapkey("", "'asr<LEADER>", "132j")
|
||||
mapkey("", "'ass<LEADER>", "133j")
|
||||
mapkey("", "'ast<LEADER>", "134j")
|
||||
mapkey("", "'asd<LEADER>", "135j")
|
||||
mapkey("", "'ash<LEADER>", "136j")
|
||||
mapkey("", "'asn<LEADER>", "137j")
|
||||
mapkey("", "'ase<LEADER>", "138j")
|
||||
mapkey("", "'asi<LEADER>", "139j")
|
||||
mapkey("", "'ato<LEADER>", "140j")
|
||||
mapkey("", "'ata<LEADER>", "141j")
|
||||
mapkey("", "'atr<LEADER>", "142j")
|
||||
mapkey("", "'ats<LEADER>", "143j")
|
||||
mapkey("", "'att<LEADER>", "144j")
|
||||
mapkey("", "'atd<LEADER>", "145j")
|
||||
mapkey("", "'ath<LEADER>", "146j")
|
||||
mapkey("", "'atn<LEADER>", "147j")
|
||||
mapkey("", "'ate<LEADER>", "148j")
|
||||
mapkey("", "'ati<LEADER>", "149j")
|
||||
mapkey("", "'ado<LEADER>", "150j")
|
||||
mapkey("", "'ada<LEADER>", "151j")
|
||||
mapkey("", "'adr<LEADER>", "152j")
|
||||
mapkey("", "'ads<LEADER>", "153j")
|
||||
mapkey("", "'adt<LEADER>", "154j")
|
||||
mapkey("", "'add<LEADER>", "155j")
|
||||
mapkey("", "'adh<LEADER>", "156j")
|
||||
mapkey("", "'adn<LEADER>", "157j")
|
||||
mapkey("", "'ade<LEADER>", "158j")
|
||||
mapkey("", "'adi<LEADER>", "159j")
|
||||
mapkey("", "'aho<LEADER>", "160j")
|
||||
mapkey("", "'aha<LEADER>", "161j")
|
||||
mapkey("", "'ahr<LEADER>", "162j")
|
||||
mapkey("", "'ahs<LEADER>", "163j")
|
||||
mapkey("", "'aht<LEADER>", "164j")
|
||||
mapkey("", "'ahd<LEADER>", "165j")
|
||||
mapkey("", "'ahh<LEADER>", "166j")
|
||||
mapkey("", "'ahn<LEADER>", "167j")
|
||||
mapkey("", "'ahe<LEADER>", "168j")
|
||||
mapkey("", "'ahi<LEADER>", "169j")
|
||||
mapkey("", "'ano<LEADER>", "170j")
|
||||
mapkey("", "'ana<LEADER>", "171j")
|
||||
mapkey("", "'anr<LEADER>", "172j")
|
||||
mapkey("", "'ans<LEADER>", "173j")
|
||||
mapkey("", "'ant<LEADER>", "174j")
|
||||
mapkey("", "'and<LEADER>", "175j")
|
||||
mapkey("", "'anh<LEADER>", "176j")
|
||||
mapkey("", "'ann<LEADER>", "177j")
|
||||
mapkey("", "'ane<LEADER>", "178j")
|
||||
mapkey("", "'ani<LEADER>", "179j")
|
||||
mapkey("", "'aeo<LEADER>", "180j")
|
||||
mapkey("", "'aea<LEADER>", "181j")
|
||||
mapkey("", "'aer<LEADER>", "182j")
|
||||
mapkey("", "'aes<LEADER>", "183j")
|
||||
mapkey("", "'aet<LEADER>", "184j")
|
||||
mapkey("", "'aed<LEADER>", "185j")
|
||||
mapkey("", "'aeh<LEADER>", "186j")
|
||||
mapkey("", "'aen<LEADER>", "187j")
|
||||
mapkey("", "'aee<LEADER>", "188j")
|
||||
mapkey("", "'aei<LEADER>", "189j")
|
||||
mapkey("", "'aio<LEADER>", "190j")
|
||||
mapkey("", "'aia<LEADER>", "191j")
|
||||
mapkey("", "'air<LEADER>", "192j")
|
||||
mapkey("", "'ais<LEADER>", "193j")
|
||||
mapkey("", "'ait<LEADER>", "194j")
|
||||
mapkey("", "'aid<LEADER>", "195j")
|
||||
mapkey("", "'aih<LEADER>", "196j")
|
||||
mapkey("", "'ain<LEADER>", "197j")
|
||||
mapkey("", "'aie<LEADER>", "198j")
|
||||
mapkey("", "'aii<LEADER>", "199j")
|
||||
87
lua/core/init.lua
Normal file
87
lua/core/init.lua
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
-- ===
|
||||
-- === Editor behavior
|
||||
-- ===
|
||||
|
||||
-- 开启左侧数字
|
||||
vim.o.number = true
|
||||
-- 使用相对数
|
||||
vim.o.relativenumber = true
|
||||
-- 高亮当前行
|
||||
vim.o.cursorline = false
|
||||
-- 一行不能完全显示时自动换行
|
||||
vim.o.wrap = true
|
||||
-- 在最后一行显示一些内容
|
||||
vim.o.showcmd = true
|
||||
-- 命令模式显示补全菜单
|
||||
vim.o.wildmenu = true
|
||||
-- /搜索时忽略大小写
|
||||
vim.o.ignorecase = true
|
||||
-- /搜索时智能大小写
|
||||
vim.o.smartcase = true
|
||||
-- 共享系统剪切
|
||||
vim.o.clipboard = 'unnamedplus'
|
||||
-- 设置<tab>键
|
||||
vim.o.tabstop = 2
|
||||
vim.o.shiftwidth = 2
|
||||
vim.o.softtabstop = 2
|
||||
-- 随文件自动更改当前路径
|
||||
vim.o.autochdir = true
|
||||
-- 在光标上方和下方保留的最小屏幕行数
|
||||
vim.o.scrolloff = 4
|
||||
-- 自动缩进
|
||||
vim.o.smartindent = true
|
||||
-- 100毫秒没有输入文件将会自动保存交换文件
|
||||
vim.o.updatetime = 100
|
||||
-- 开启鼠标
|
||||
vim.o.mouse = 'a'
|
||||
-- 开启颜色
|
||||
vim.o.termguicolors = true
|
||||
-- 将updatetime设置为较低的值以提高性能
|
||||
vim.opt.updatetime = 200
|
||||
-- 指定keyword
|
||||
vim.opt.iskeyword = "_,49-57,A-Z,a-z"
|
||||
-- 让全局默认边框变成rounded或single
|
||||
vim.o.winborder = 'rounded'
|
||||
-- 始终隐藏字符(不依赖语法高亮),在 Markdown 文件中,粗体、斜体等标记字符可能会被隐藏
|
||||
-- vim.opt.conceallevel = 2
|
||||
|
||||
-- 设置编码格式
|
||||
vim.o.fileencodings = 'utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1'
|
||||
vim.o.enc = 'utf8'
|
||||
|
||||
-- 保存修改历史
|
||||
vim.o.swapfile = true
|
||||
vim.o.undofile = true
|
||||
|
||||
-- 保存折叠记录,在某些独立的窗口会报错
|
||||
-- vim.cmd 'au BufWinLeave * silent mkview'
|
||||
-- vim.cmd 'au BufWinEnter * silent loadview'
|
||||
|
||||
-- 打开文件时进入上次编辑的位置
|
||||
vim.cmd([[au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif]])
|
||||
|
||||
-- fcitx5在normal模式时自动切换为英文输入法,摘自fcitx5的archwiki
|
||||
vim.cmd([[
|
||||
autocmd InsertLeave * :silent !fcitx5-remote -c
|
||||
autocmd BufCreate * :silent !fcitx5-remote -c
|
||||
autocmd BufEnter * :silent !fcitx5-remote -c
|
||||
autocmd BufLeave * :silent !fcitx5-remote -c
|
||||
]])
|
||||
-- 意为:
|
||||
-- 当 进入插入模式 时 触发shell命令 fcitx-remote -c 关闭输入法,改为英文输入
|
||||
-- 当 创建Buf 时 触发shell命令 fcitx-remote -c 关闭输入法,改为英文输入
|
||||
-- 当 进入Buf 时 触发shell命令 fcitx-remote -c 关闭输入法, 改为英文输入
|
||||
-- 当 离开Buf 时 触发shell命令 fcitx-remote -c 关闭输入法, 改为英文输入
|
||||
|
||||
-- 开启高亮复制
|
||||
vim.cmd([[au TextYankPost * silent! lua vim.highlight.on_yank()]])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
305
lua/core/keymap.lua
Normal file
305
lua/core/keymap.lua
Normal file
|
|
@ -0,0 +1,305 @@
|
|||
-- ===
|
||||
-- === map function
|
||||
-- ===
|
||||
|
||||
local function mapkey(mode, lhs, rhs)
|
||||
vim.keymap.set(mode, lhs, rhs, { silent = true, nowait = true })
|
||||
end
|
||||
|
||||
local function mapcmd(key, cmd)
|
||||
vim.keymap.set("n", key, "<cmd>" .. cmd .. "<cr>", { silent = true })
|
||||
end
|
||||
|
||||
local function maplua(modes, key, action, desc)
|
||||
vim.keymap.set(modes, key, action, { silent = true, noremap = true, desc = desc })
|
||||
end
|
||||
|
||||
-- ===
|
||||
-- === Basic Mappings
|
||||
-- ===
|
||||
|
||||
-- leader键设置为空格,; as :
|
||||
vim.g.mapleader = " "
|
||||
mapkey({ "n", "x", "o" }, ";", ":")
|
||||
|
||||
-- 上/下一个搜索结果以及取消搜索结果高亮
|
||||
mapkey({ "n", "x", "o" }, "=", "nzz")
|
||||
mapkey({ "n", "x", "o" }, "-", "Nzz")
|
||||
mapcmd("<leader><cr>", "nohlsearch")
|
||||
|
||||
-- 保存和退出
|
||||
mapkey({ "n", "x", "o" }, "S", ":wall<cr>")
|
||||
mapkey({ "n", "x", "o" }, "Q", ":qall<cr>")
|
||||
|
||||
-- 撤销与反撤销
|
||||
mapkey({ "n", "x", "o" }, "l", "u")
|
||||
mapkey({ "n", "x", "o" }, "L", "<c-r>")
|
||||
|
||||
-- 插入
|
||||
mapkey({ "n", "x", "o" }, "k", "i")
|
||||
mapkey({ "n", "x", "o" }, "K", "I")
|
||||
|
||||
mapkey('n', '<C-n>', '<C-o>')
|
||||
|
||||
-- 折叠
|
||||
mapkey({ "n", "x", "o" }, "<leader>o", "za")
|
||||
mapkey("x", "<leader>o", "zf") -- 可视模式创造折叠
|
||||
-- 读取保存的折叠
|
||||
-- mapkey({ "n", "x", "o" }, "<leader>a", ":loadview<cr>")
|
||||
|
||||
|
||||
-- 以下两个映射默认了
|
||||
-- make Y to copy till the end of the line
|
||||
-- mapkey('','Y','y$')
|
||||
|
||||
-- make D to delete till the end of the line
|
||||
-- mapkey('','D','d$')
|
||||
|
||||
-- 打开lazygit,已用fm-nvim插件
|
||||
-- mapcmd('<c-g>',':tabe<CR>:-tabmove<CR>:term lazygit')
|
||||
|
||||
-- ===
|
||||
-- === treesitter
|
||||
-- ===
|
||||
|
||||
-- 删除i键映射
|
||||
vim.api.nvim_create_autocmd("VimEnter", { -- 所有启动脚本、默认脚本都加载完毕后的最后一个事件
|
||||
callback = function()
|
||||
-- 使用 pcall 忽略如果键位不存在时的报错
|
||||
pcall(vim.keymap.del, { "x", "o" }, "in")
|
||||
end,
|
||||
})
|
||||
|
||||
local function smart_select(ts_method, lsp_dir)
|
||||
return function()
|
||||
-- 如果当前不是普通文件(比如 Quickfix、帮助文档、终端等)那么我们直接发送一个原生的 <CR> 按键并退出,恢复回车原本的功能
|
||||
if lsp_dir == 1 and vim.bo.buftype ~= "" then
|
||||
local cr = vim.api.nvim_replace_termcodes("<CR>", true, false, true)
|
||||
vim.api.nvim_feedkeys(cr, "n", false)
|
||||
return
|
||||
end
|
||||
if vim.treesitter.get_parser(nil, nil, { error = false }) then
|
||||
require("vim.treesitter._select")[ts_method](vim.v.count1)
|
||||
else
|
||||
vim.lsp.buf.selection_range(lsp_dir * vim.v.count1)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- 扩大范围 (回车键):不断向上寻找父节点 (等价于官方的 an)
|
||||
maplua({ "x", "o", "n" }, "<CR>", smart_select("select_parent", 1), "扩大 Treesitter/LSP 范围")
|
||||
-- 缩小范围 (退格键):不断向下寻找子节点
|
||||
maplua({ "x", "o" }, "<BS>", smart_select("select_child", -1), "缩小 Treesitter/LSP 范围")
|
||||
|
||||
-- ===
|
||||
-- === Cursor Movement
|
||||
-- ===
|
||||
-- New cursor movement (the default arrow keys are used for resizing windows)
|
||||
|
||||
-- ^
|
||||
-- u
|
||||
-- < n i >
|
||||
-- e
|
||||
-- v
|
||||
mapkey({ "n", "x", "o" }, "n", "h")
|
||||
mapkey({ "n", "x", "o" }, "u", "k")
|
||||
mapkey({ "n", "x", "o" }, "e", "j")
|
||||
mapkey({ "n", "x", "o" }, "i", "l")
|
||||
|
||||
-- 更快的导航
|
||||
mapkey({ "n", "x", "o" }, "U", "5k")
|
||||
mapkey({ "n", "x", "o" }, "E", "5j")
|
||||
mapkey({ "n", "x", "o" }, "N", "0")
|
||||
mapkey({ "n", "x", "o" }, "I", "$")
|
||||
-- 向下滚动半页,<C-u>默认向上滚动半页
|
||||
mapkey({ "n", "x", "o" }, "<C-e>", "<C-d>")
|
||||
|
||||
-- 更快的行导航
|
||||
mapkey({ "n", "x", "o" }, "W", "5W")
|
||||
mapkey({ "n", "x", "o" }, "B", "5B")
|
||||
|
||||
-- ===
|
||||
-- === Window management
|
||||
-- ===
|
||||
|
||||
-- 使用<space> + 新方向键 在分屏之间移动
|
||||
mapkey({ "n", "x", "o" }, "<LEADER>w", "<C-w>w")
|
||||
mapkey({ "n", "x", "o" }, "<LEADER>u", "<C-w>k")
|
||||
mapkey({ "n", "x", "o" }, "<LEADER>e", "<C-w>j")
|
||||
mapkey({ "n", "x", "o" }, "<LEADER>n", "<C-w>h")
|
||||
mapkey({ "n", "x", "o" }, "<LEADER>i", "<C-w>l")
|
||||
|
||||
-- 使用s + 新方向键 进行分屏
|
||||
mapcmd("su", "set nosplitbelow<CR>:split<CR>:set splitbelow")
|
||||
mapcmd("se", "set splitbelow<CR>:split")
|
||||
mapcmd("sn", "set nosplitright<CR>:vsplit<CR>:set splitright")
|
||||
mapcmd("si", "set splitright<CR>:vsplit")
|
||||
|
||||
-- 使用方向键来调整窗口大小
|
||||
mapcmd("<up>", "res +5")
|
||||
mapcmd("<down>", "res -5")
|
||||
mapcmd("<left>", "vertical resize-5")
|
||||
mapcmd("<right>", "vertical resize+5")
|
||||
|
||||
-- 使分屏窗口上下分布
|
||||
mapkey({ "n", "x", "o" }, "sh", "<C-w>t<C-w>K")
|
||||
-- 使分屏窗口左右分布
|
||||
mapkey({ "n", "x", "o" }, "sv", "<C-w>t<C-w>H")
|
||||
|
||||
-- 按 <SPACE> + q 关闭当前窗口下方的窗口
|
||||
mapkey({ "n", "x", "o" }, "<LEADER>q", "<C-w>j:q<CR>")
|
||||
|
||||
-- ===
|
||||
-- === Tab management
|
||||
-- ===
|
||||
|
||||
-- tu创建新标签,已用bufferline.nvim替代
|
||||
-- mapcmd("tu", "tabe")
|
||||
-- 在标签之间移动
|
||||
-- mapcmd('tn','-tabnext')
|
||||
-- mapcmd('ti','+tabnext')
|
||||
|
||||
-- 移动标签的位置
|
||||
-- mapcmd('tmn','-tabmove')
|
||||
-- mapcmd('tmi','+tabmove')
|
||||
|
||||
-- 关闭当前标签,已用close-buffers替代
|
||||
-- mapcmd('tq','tabc')
|
||||
|
||||
-- ===
|
||||
-- === 批量缩进方法
|
||||
-- ===
|
||||
-- 操作为,esc从编辑模式退到命令模式,将光标移到需要缩进的行的行首,然后按shift+v,可以看到该行已被选中,且左下角提示为“可视”
|
||||
-- 按键盘上的上下方向键,如这里按向下的箭头,选中所有需要批量缩进的行
|
||||
-- 按shift+>,是向前缩进一个tab值,按shift+<,则是缩回一个tab值
|
||||
|
||||
mapkey("x", "<", "<gv")
|
||||
mapkey("x", ">", ">gv")
|
||||
mapkey("x", "<s-tab>", "<gv")
|
||||
mapkey("x", "<tab>", ">gv")
|
||||
|
||||
-- ===
|
||||
-- === 批量替换
|
||||
-- ===
|
||||
|
||||
-- 设置快捷键,替换所有文件内容
|
||||
mapcmd("<leader>sa", "lua search_and_replace()")
|
||||
-- 设置快捷键,替换当前文件内容
|
||||
mapcmd("<leader>sr", "lua search_and_replace_current_file()")
|
||||
|
||||
-- 替换当前目录及子目录下所有文件内容
|
||||
function search_and_replace()
|
||||
-- 获取用户输入的查找内容,使用 input() 函数动态输入替换内容
|
||||
local search_text = vim.fn.input("Search for: ")
|
||||
|
||||
-- 获取用户输入的替换内容
|
||||
local replace_text = vim.fn.input("Replace with: ")
|
||||
|
||||
-- 执行替换命令
|
||||
if search_text ~= "" and replace_text ~= "" then
|
||||
local cmd = 'execute "!grep -rl \\"'
|
||||
.. search_text
|
||||
.. '\\" ./ | xargs sed -i \\"s/'
|
||||
.. search_text
|
||||
.. "/"
|
||||
.. replace_text
|
||||
.. '/g\\""'
|
||||
vim.cmd(cmd)
|
||||
print("Replaced all occurrences of '" .. search_text .. "' with '" .. replace_text .. "'")
|
||||
else
|
||||
print("Search or replace text cannot be empty.")
|
||||
end
|
||||
end
|
||||
|
||||
-- 替换当前文件内容
|
||||
function search_and_replace_current_file()
|
||||
-- 获取用户输入的查找内容
|
||||
local search_text = vim.fn.input("Search for in current file: ")
|
||||
|
||||
-- 获取用户输入的替换内容
|
||||
local replace_text = vim.fn.input("Replace with: ")
|
||||
|
||||
-- 执行替换命令
|
||||
if search_text ~= "" and replace_text ~= "" then
|
||||
-- 使用 sed 替换当前文件中的匹配内容,并正确转义引号
|
||||
local cmd = string.format("!sed -i 's/%s/%s/g' %%", search_text, replace_text)
|
||||
vim.cmd(cmd)
|
||||
print("Replaced all occurrences of '" .. search_text .. "' with '" .. replace_text .. "' in current file.")
|
||||
else
|
||||
print("Search or replace text cannot be empty.")
|
||||
end
|
||||
end
|
||||
|
||||
-- ===
|
||||
-- === 临时“存档”文件当前的版本,并与后续的修改进行 diff 对比
|
||||
-- ===
|
||||
|
||||
-- 创建 :DiffOrig 自定义命令,这个命令会打开一个垂直分屏,加载当前文件存盘时的版本,并启动 diff 模式
|
||||
vim.api.nvim_create_user_command(
|
||||
'DiffOrig',
|
||||
function()
|
||||
-- 在创建新窗口前,先保存当前文件的 filetype
|
||||
local original_filetype = vim.bo.filetype
|
||||
-- 打开一个垂直分屏,并准备好临时缓冲区
|
||||
vim.cmd('vert new | set buftype=nofile')
|
||||
-- 在新的临时缓冲区里,设置我们刚才保存的 filetype,这是确保语法高亮的关键!
|
||||
vim.bo.filetype = original_filetype
|
||||
-- 读取原始文件的磁盘内容,并启动 diff
|
||||
vim.cmd('read ++edit # | 0d_ | diffthis | wincmd p | diffthis')
|
||||
end,
|
||||
{ force = true }
|
||||
)
|
||||
-- <leader>dd 将会执行 :DiffOrig 命令
|
||||
mapcmd('<leader>dd', 'DiffOrig')
|
||||
|
||||
-- ===
|
||||
-- === Other useful stuff
|
||||
-- ===
|
||||
|
||||
-- 打开一个终端窗口
|
||||
mapcmd("<LEADER>/", "set splitbelow<CR>:split<CR>:res +10<CR>:term")
|
||||
|
||||
-- 按两下空格跳转到占位符<++>,并进入插入模式
|
||||
mapkey({ "n", "x", "o" }, "<LEADER><LEADER>", "<Esc>/<++><CR>:nohlsearch<CR>c4l")
|
||||
|
||||
-- 拼写检查
|
||||
mapcmd("<LEADER>sc", "set spell!")
|
||||
|
||||
-- ===
|
||||
-- === 运行代码(该功能已经迁移到plugins/coderunner.lua)
|
||||
-- ===
|
||||
|
||||
-- vim.cmd([[
|
||||
-- au filetype dart noremap r :wall<cr>:Telescope flutter commands<cr>
|
||||
-- au filetype python noremap r :wall<cr>:set splitbelow<cr>:sp<cr>:term uv run %<cr>
|
||||
-- au filetype go noremap r :wall<cr>:set splitbelow<cr>:sp<cr>:term go run %<cr>
|
||||
-- au filetype markdown noremap r :PeekClose<cr>:PeekOpen<cr>
|
||||
-- au filetype rust noremap r :wall<cr>:set splitbelow<cr>:sp<cr>:term cargo run<cr>
|
||||
-- ]])
|
||||
|
||||
|
||||
-- ===
|
||||
-- === map function external environment
|
||||
-- ===
|
||||
|
||||
-- 下面的函数给外部文件调用的
|
||||
-- 使用示例如下
|
||||
-- local map = require("core.keymap")
|
||||
-- map:cmd('<space>p','PasteImg')
|
||||
local map = {}
|
||||
function map:key(mode, lhs, rhs)
|
||||
vim.keymap.set(mode, lhs, rhs, { silent = true })
|
||||
end
|
||||
|
||||
function map:cmd(key, cmd)
|
||||
vim.keymap.set("n", key, "<cmd>" .. cmd .. "<cr>", { silent = true })
|
||||
end
|
||||
|
||||
function map:lua(key, txt_or_func)
|
||||
if type(txt_or_func) == "string" then
|
||||
vim.keymap.set("n", key, "<cmd>lua " .. txt_or_func .. "<cr>", { silent = true })
|
||||
else
|
||||
vim.keymap.set("n", key, txt_or_func, { silent = true })
|
||||
end
|
||||
end
|
||||
|
||||
return map
|
||||
197
lua/core/markdown_table_format.lua
Normal file
197
lua/core/markdown_table_format.lua
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
local table_line_char = {
|
||||
{ ':', ':' },
|
||||
{ ':', '-' },
|
||||
{ '-', ':' },
|
||||
}
|
||||
|
||||
local table_line_char_insert = {
|
||||
{ ':', ':' },
|
||||
{ ':', ' ' },
|
||||
{ ' ', ':' },
|
||||
}
|
||||
|
||||
---Check if the line_number is a markdown table
|
||||
---@param line_number integer
|
||||
---@return integer
|
||||
local function check_markdown_table(line_number)
|
||||
local line = vim.api.nvim_buf_get_lines(0, line_number - 1, line_number, true)[1]
|
||||
return string.match(line, '^|.*|$')
|
||||
end
|
||||
|
||||
---Find the starting or ending line of the markdown table
|
||||
---@param range integer 1 or -1
|
||||
---@return integer
|
||||
local function find_markdown_table(range)
|
||||
local cursor_line, end_line = vim.fn.line('.'), range == -1 and 1 or vim.fn.line('$')
|
||||
|
||||
for l = cursor_line, end_line, range do
|
||||
if not check_markdown_table(l) then
|
||||
return l - range
|
||||
end
|
||||
if (range == -1 and l == 1) or (range == 1 and l == vim.fn.line('$')) then --- if in the first line or last line
|
||||
return l
|
||||
end
|
||||
end
|
||||
|
||||
return -1
|
||||
end
|
||||
|
||||
---Get markdown table cells width
|
||||
---@param table_contents table
|
||||
---@return table integers
|
||||
local function get_markdown_table_cells_width(table_contents)
|
||||
local width = {}
|
||||
for _ = 1, #table_contents[1], 1 do
|
||||
table.insert(width, 0)
|
||||
end
|
||||
for i = 1, #table_contents, 1 do
|
||||
if i ~= 2 then
|
||||
for _, cell in ipairs(table_contents[i]) do
|
||||
width[_] = math.max(width[_], cell and vim.fn.strdisplaywidth(cell) or 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
return width
|
||||
end
|
||||
|
||||
---Update markdown table's cell contents
|
||||
---@param table_contents table
|
||||
---@param width table
|
||||
---@return table
|
||||
local function update_cell_contents(table_contents, width)
|
||||
local function add_space(cell, num) -- add space at markdown table cell contents
|
||||
cell = ' ' .. cell .. ' '
|
||||
cell = cell .. string.rep(' ', num)
|
||||
return cell
|
||||
end
|
||||
|
||||
local function get_chars(cell) -- add chars at second line's left and right
|
||||
local char_left = string.sub(cell, 1, 1)
|
||||
local char_right = string.sub(cell, #cell)
|
||||
return { char_left, char_right }
|
||||
end
|
||||
|
||||
local function get_table_line_char_id(chars) -- get chars at second line's left and right
|
||||
for i, v in ipairs(table_line_char) do -- leave insert
|
||||
if chars[1] == v[1] and chars[2] == v[2] then
|
||||
return i
|
||||
end
|
||||
end
|
||||
for i, v in ipairs(table_line_char_insert) do -- type "|"
|
||||
if chars[1] == v[1] and chars[2] == v[2] then
|
||||
return i
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
local function add_chars(cell, chars) -- update cell contents at second line's left and right
|
||||
cell = chars[1] .. cell .. chars[2]
|
||||
return cell
|
||||
end
|
||||
|
||||
for i, cells in ipairs(table_contents) do -- traversal markdown table lines and update
|
||||
if i == 2 then
|
||||
for j, _ in ipairs(cells) do
|
||||
local chars = get_chars(table_contents[i][j])
|
||||
local id = get_table_line_char_id(chars)
|
||||
table_contents[i][j] = string.rep('-', width[j])
|
||||
table_contents[i][j] =
|
||||
add_chars(table_contents[i][j], id ~= 0 and table_line_char[id] or { '-', '-' })
|
||||
end
|
||||
else
|
||||
for j, cell in ipairs(cells) do
|
||||
local change_length = width[j] - vim.fn.strdisplaywidth(cell)
|
||||
table_contents[i][j] = add_space(cell, change_length)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return table_contents
|
||||
end
|
||||
|
||||
---change every lines's tables to string
|
||||
---@param table_contents table
|
||||
---@return table
|
||||
local function cells_to_table(table_contents)
|
||||
local corner_char = '|'
|
||||
for i = 1, #table_contents, 1 do
|
||||
local line = corner_char
|
||||
for j = 1, #table_contents[i], 1 do
|
||||
line = line .. table_contents[i][j] .. corner_char
|
||||
end
|
||||
table_contents[i] = line
|
||||
end
|
||||
return table_contents
|
||||
end
|
||||
|
||||
local function format_markdown_table()
|
||||
if not check_markdown_table(vim.fn.line('.')) then -- check if the curso is in markdown table
|
||||
return
|
||||
end
|
||||
|
||||
-- find the staring line and ending line of markdown table
|
||||
local table_start_line, table_end_line = find_markdown_table(-1), find_markdown_table(1)
|
||||
local table_contents = {}
|
||||
|
||||
---change table to cells
|
||||
---@param line string
|
||||
---@param lnum integer
|
||||
local function table_to_cells(line, lnum)
|
||||
local table_cells = {}
|
||||
for cell in line:gmatch('([^|]+)%|') do
|
||||
if lnum ~= 1 then
|
||||
cell = cell:match('^%s*(.-)%s*$')
|
||||
end
|
||||
table.insert(table_cells, cell)
|
||||
end
|
||||
table.insert(table_contents, table_cells)
|
||||
end
|
||||
|
||||
-- traversal markdown table lines
|
||||
for lnum = table_start_line, table_end_line, 1 do
|
||||
local line = vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, true)[1]
|
||||
table_to_cells(line, lnum - table_start_line)
|
||||
end
|
||||
|
||||
local width = get_markdown_table_cells_width(table_contents)
|
||||
|
||||
table_contents = update_cell_contents(table_contents, width)
|
||||
table_contents = cells_to_table(table_contents)
|
||||
|
||||
vim.api.nvim_buf_set_lines(0, table_start_line - 1, table_end_line, true, table_contents)
|
||||
end
|
||||
|
||||
local function format_markdown_table_lines()
|
||||
local current_line = vim.api.nvim_get_current_line()
|
||||
local cursor_pos = vim.api.nvim_win_get_cursor(0)
|
||||
local char = current_line:sub(cursor_pos[2], cursor_pos[2])
|
||||
if char == '|' and cursor_pos[2] ~= 1 then
|
||||
format_markdown_table()
|
||||
local length = #vim.api.nvim_get_current_line()
|
||||
vim.api.nvim_win_set_cursor(0, { cursor_pos[1], length })
|
||||
end
|
||||
end
|
||||
|
||||
-- return {
|
||||
-- format_markdown_table = format_markdown_table,
|
||||
-- format_markdown_table_lines = format_markdown_table_lines,
|
||||
-- }
|
||||
|
||||
-- markdown_table_format
|
||||
local au = vim.api.nvim_create_autocmd
|
||||
local group = vim.api.nvim_create_augroup('KicamonGroup', {})
|
||||
au('InsertLeave', {
|
||||
group = group,
|
||||
pattern = '*.md',
|
||||
callback = function()
|
||||
format_markdown_table()
|
||||
end,
|
||||
})
|
||||
au('TextChangedI', {
|
||||
group = group,
|
||||
pattern = '*.md',
|
||||
callback = function()
|
||||
format_markdown_table_lines()
|
||||
end,
|
||||
})
|
||||
25
lua/core/md-snippets.lua
Normal file
25
lua/core/md-snippets.lua
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
vim.cmd([[
|
||||
autocmd Filetype markdown inoremap <buffer> ,f <Esc>/<++><CR>:nohlsearch<CR>"_c4l
|
||||
autocmd Filetype markdown inoremap <buffer> ,w <Esc>/<++><CR>:nohlsearch<CR>"_c5l<CR>
|
||||
autocmd Filetype markdown inoremap <buffer> ,n ---<Enter><Enter>
|
||||
autocmd Filetype markdown inoremap <buffer> ,b **** <++><Esc>F*hi
|
||||
autocmd Filetype markdown inoremap <buffer> ,s ~~~~ <++> <Esc>F~hi
|
||||
autocmd Filetype markdown inoremap <buffer> ,i ** <++><Esc>F*i
|
||||
autocmd Filetype markdown inoremap <buffer> ,d `` <++><Esc>F`i
|
||||
autocmd Filetype markdown inoremap <buffer> ,c ```<Enter>```<Enter><Enter><++><Esc>3kA
|
||||
autocmd Filetype markdown inoremap <buffer> ,m - [ ]
|
||||
autocmd Filetype markdown inoremap <buffer> ,p  <Esc>F[a
|
||||
autocmd Filetype markdown inoremap <buffer> ,a [](<++>) <Esc>F[a
|
||||
autocmd Filetype markdown inoremap <buffer> ,1 #<Space>
|
||||
autocmd Filetype markdown inoremap <buffer> ,2 ##<Space>
|
||||
autocmd Filetype markdown inoremap <buffer> ,3 ###<Space>
|
||||
autocmd Filetype markdown inoremap <buffer> ,4 ####<Space>
|
||||
autocmd Filetype markdown inoremap <buffer> ,l --------<Enter>
|
||||
]])
|
||||
|
||||
-- some modify
|
||||
-- autocmd Filetype markdown inoremap <buffer> ,c ```<Enter><++><Enter>```<Enter><Enter><++><Esc>4kA
|
||||
-- autocmd Filetype markdown inoremap <buffer> ,1 #<Space><Enter><++><Esc>kA
|
||||
-- autocmd Filetype markdown inoremap <buffer> ,2 ##<Space><Enter><++><Esc>kA
|
||||
-- autocmd Filetype markdown inoremap <buffer> ,3 ###<Space><Enter><++><Esc>kA
|
||||
-- autocmd Filetype markdown inoremap <buffer> ,4 ####<Space><Enter><++><Esc>kA
|
||||
Loading…
Add table
Add a link
Reference in a new issue