diff --git a/README.md b/README.md index 60faa86..5913056 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,18 @@ . ├── coc-settings.json ├── init.lua -├── lazy-lock.json ├── lua │   ├── core +│   │   ├── G.lua │   │   ├── keymap.lua │   │   ├── options.lua │   │   └── plug.lua +│   ├── Filetype +│   │   ├── c.lua +│   │   └── markdown.lua │   └── Plugin │   ├── coc.lua -│   ├── lualine.lua -│   └── nerdcommenter.lua +│   └── lualine.lua └── README.md ``` ## vim-surround插件 @@ -56,6 +58,28 @@ select the closest text object. ![官方给的gif](https://raw.githubusercontent.com/gcmt/wildfire.vim/master/_assets/preview.gif) -## nerdcommenter -快速注释插件 -`c` 切换注释状态 +## Markdow-preview +下载后需要到插件目录下使用`npm install`或者`yarn install` + + + + + + + + + + + + + + + + + + + + + + + diff --git a/coc-settings.json b/coc-settings.json index ffe1420..a484f82 100644 --- a/coc-settings.json +++ b/coc-settings.json @@ -1,8 +1,6 @@ { + "snippets.ultisnips.pythonPrompt": false, "explorer.icon.enableNerdfont": true, - "explorer.toggle": true, - "markdown-preview-enhanced.previewTheme":"github-dark.css", - "markdown-preview-enhanced.latexEngine": "pdflatex", - "markdown-preview-enhanced.chromePath": "/usr/bin/wyeb" + "explorer.toggle": true } diff --git a/init.lua b/init.lua index 5bbdcd6..7d7abcf 100644 --- a/init.lua +++ b/init.lua @@ -1,10 +1,7 @@ -vim.g['mapleader'] = ' ' - require('core.plug') require('core.options') require('core.keymap') + require('Plugin.coc') require('Plugin.lualine') -require('Plugin.nerdcommenter') - - +require('Plugin.Imchange') diff --git a/lazy-lock.json b/lazy-lock.json deleted file mode 100644 index 3052808..0000000 --- a/lazy-lock.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "coc.nvim": { "branch": "release", "commit": "e86b15bbcabc2cc1f20a40e7c127a424e7ad3850" }, - "colorizer": { "branch": "master", "commit": "72790a003d5a706c287486a1a81e3a6b32158b54" }, - "gruvbox": { "branch": "master", "commit": "bf2885a95efdad7bd5e4794dd0213917770d79b7" }, - "lazy.nvim": { "branch": "main", "commit": "96d759d1cbd8b0bd0ea0a0c2987f99410272f348" }, - "lazygit.nvim": { "branch": "main", "commit": "32bffdebe273e571588f25c8a708ca7297928617" }, - "lualine.nvim": { "branch": "master", "commit": "0050b308552e45f7128f399886c86afefc3eb988" }, - "markdown-preview.vim": { "branch": "master", "commit": "97388dc537454a90422f186cb4e1a4f9a3f95122" }, - "nerdcommenter": { "branch": "master", "commit": "98cc4a2d64ca67cccbf5b5cf47c682ebadaaff58" }, - "vim-easy-align": { "branch": "master", "commit": "12dd6316974f71ce333e360c0260b4e1f81169c3" }, - "vim-easymotion": { "branch": "master", "commit": "b3cfab2a6302b3b39f53d9fd2cd997e1127d7878" }, - "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" }, - "wildfire.vim": { "branch": "master", "commit": "b371e2b1d938ae0e164146136051de164ecb9aa5" } -} \ No newline at end of file diff --git a/lua/Filetype/markdown.lua b/lua/Filetype/markdown.lua index 475f03b..2b8d825 100644 --- a/lua/Filetype/markdown.lua +++ b/lua/Filetype/markdown.lua @@ -1,4 +1,103 @@ -local map = vim.api.nvim_set_keymap -local openPreview = ":CocCommand markdown-preview-enhanced.openPreview" +local G = require("core.G") +local TogglePreview = "MarkdownPreviewToggle" -map('n', 'r', openPreview, {noremap = false}) +--set to 1, nvim will open the preview window after entering the markdown buffer +--default: 0 +G.g.mkdp_auto_start = 1 + +--set to 1, the nvim will auto close current preview window when change +--from markdown buffer to another buffer +--default: 1 +G.g.mkdp_auto_close = 1 + +--set to 1, the vim will refresh markdown when save the buffer or +--leave from insert mode, default 0 is auto refresh markdown as you edit or +--move the cursor +--default: 0 +G.g.mkdp_refresh_slow = 0 + +--set to 1, the MarkdownPreview command can be use for all files, +--by default it can be use in markdown file +--default: 0 +G.g.mkdp_command_for_global = 0 + +--set to 1, preview server available to others in your network +--by default, the server listens on localhost (127.0.0.1) +--default: 0 +G.g.mkdp_open_to_the_world = 0 + +--use custom IP to open preview page +--useful when you work in remote vim and preview on local browser +--more detail see: https://github.com/iamcco/markdown-preview.nvim/pull/9 +--default empty +G.g.mkdp_open_ip = '' + +--specify browser to open preview page +--for path with space +--valid: `/path/with\ space/xxx` +--invalid: `/path/with\\ space/xxx` +--default: '' +G.g.mkdp_browser = 'wyeb' + +--set to 1, echo preview page url in command line when open preview page +--default is 0 +G.g.mkdp_echo_preview_url = 0 + +--a custom vim function name to open preview page +--this function will receive url as param +--default is empty +G.g.mkdp_browserfunc = '' + +--options for markdown render +--mkit: markdown-it options for render +--katex: katex options for math +--uml: markdown-it-plantuml options +--maid: mermaid options +--disable_sync_scroll: if disable sync scroll, default 0 +--sync_scroll_type: 'middle', 'top' or 'relative', default value is 'middle' +-- middle: mean the cursor position alway show at the middle of the preview page +-- top: mean the vim top viewport alway show at the top of the preview page +-- relative: mean the cursor position alway show at the relative positon of the preview page +--hide_yaml_meta: if hide yaml metadata, default is 1 +--sequence_diagrams: js-sequence-diagrams options +--content_editable: if enable content editable for preview page, default: v:false +--disable_filename: if disable filename header for preview page, default: 0 + +--G.cmd([[ +-- let g:mkdp_preview_options = { +-- \'mkit': {}, +-- \'katex': {}, +-- \'uml': {}, +-- \'maid': {}, +-- \'disable_sync_scroll': 0, +-- \'sync_scroll_type': 'middle', +-- \'hide_yaml_meta': 1, +-- \'sequence_diagrams': {}, +-- \'flowchart_diagrams': {}, +-- \'content_editable': v:false, +-- \'disable_filename': 0, +-- \'toc': {} +-- \} +-- ]]) +--use a custom markdown style must be absolute path +--like '/Users/username/markdown.css' or expand('~/markdown.css') +G.g.mkdp_markdown_css = '' + +--use a custom highlight style must absolute path +--like '/Users/username/highlight.css' or expand('~/highlight.css') +G.g.mkdp_highlight_css = '' + +--use a custom port to start server or empty for random +G.g.mkdp_port = '12345' + +--preview page title +--${name} will be replace with the file name +G.g.mkdp_page_title = '「${name}」' + +--recognized filetypes +--these filetypes will have MarkdownPreview... commands +G.g.mkdp_filetypes = {'markdown'} + +--set default theme (dark or light) +--By default the theme is define according to the preferences of the system +G.g.mkdp_theme = 'dark' diff --git a/lua/core/G.lua b/lua/G.lua similarity index 95% rename from lua/core/G.lua rename to lua/G.lua index 35101c0..68c2fbe 100644 --- a/lua/core/G.lua +++ b/lua/G.lua @@ -5,6 +5,7 @@ G.b = vim.b G.o = vim.o G.fn = vim.fn G.api = vim.api +G.opt = vim.opt function G.map(maps) for _,map in pairs(maps) do @@ -33,4 +34,6 @@ function G.eval(c) return G.api.nvim_eval(c) end +G.g.mapleader = ' ' + return G diff --git a/lua/Plugin/Imchange.lua b/lua/Plugin/Imchange.lua new file mode 100644 index 0000000..c549b5f --- /dev/null +++ b/lua/Plugin/Imchange.lua @@ -0,0 +1,29 @@ +local G, im = require("G"), "keyboard-us" + +function InsertLeave() + local t = io.popen("fcitx5-remote -n") + im = t:read() + G.cmd(":silent !fcitx5-remote -c") +end + +function InsertEnter() + if im == 'pinyin' + then + print(im) + G.cmd("!fcitx5-remote -s pinyin") + end +end + +G.api.nvim_create_autocmd( + {"InsertLeave"}, { + pattern = "*", + callback = InsertLeave + } +) + +G.api.nvim_create_autocmd( + {"InsertEnter"}, { + pattern = "*", + callback = InsertEnter + } +) diff --git a/lua/Plugin/Markdown-preview.lua b/lua/Plugin/Markdown-preview.lua deleted file mode 100644 index 42ce13e..0000000 --- a/lua/Plugin/Markdown-preview.lua +++ /dev/null @@ -1,3 +0,0 @@ -local G = require("core.G") - -G.g['mkdp_path_to_chrome'] = '/usr/bin/wyeb' diff --git a/lua/Plugin/coc.lua b/lua/Plugin/coc.lua index 0a04591..021433c 100644 --- a/lua/Plugin/coc.lua +++ b/lua/Plugin/coc.lua @@ -3,7 +3,6 @@ vim.g['coc_global_extensions'] = { "coc-python", "coc-json", "coc-lua", - "coc-markdown-preview-enhanced", "coc-webview", "coc-translator", diff --git a/lua/Plugin/nerdcommenter.lua b/lua/Plugin/nerdcommenter.lua deleted file mode 100644 index 2de014a..0000000 --- a/lua/Plugin/nerdcommenter.lua +++ /dev/null @@ -1,28 +0,0 @@ -vim.cmd([[ -" Create default mappings -let g:NERDCreateDefaultMappings = 1 - -" Add spaces after comment delimiters by default -let g:NERDSpaceDelims = 1 - -" Use compact syntax for prettified multi-line comments -let g:NERDCompactSexyComs = 1 - -" Align line-wise comment delimiters flush left instead of following code indentation -let g:NERDDefaultAlign = 'left' - -" Set a language to use its alternate delimiters by default -let g:NERDAltDelims_java = 1 - -" Add your own custom formats or override the defaults -let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } } - -" Allow commenting and inverting empty lines (useful when commenting a region) -let g:NERDCommentEmptyLines = 1 - -" Enable trimming of trailing whitespace when uncommenting -let g:NERDTrimTrailingWhitespace = 1 - -" Enable NERDCommenterToggle to check all selected lines is commented or not -let g:NERDToggleCheckAllLines = 1 -]]) diff --git a/lua/core/keymap.lua b/lua/core/keymap.lua index a7761b0..8324c05 100644 --- a/lua/core/keymap.lua +++ b/lua/core/keymap.lua @@ -1,4 +1,4 @@ -local G,opt = require("core.G"), {noremap = true} +local G, opt = require('G'), {noremap = true} G.map({ {'n', 'y', '"+y', opt}, @@ -10,7 +10,7 @@ G.map({ {'v', 'd', '"+d', opt}, {'n', 'nh', ':nohlsearch', opt}, -{'n', 'rp',':%s/',opt}, +{'n', 'rp', ':%s/',opt}, {'v', 'L', '$', opt}, {'v', 'H', '^', opt}, @@ -66,12 +66,3 @@ G.map({ - - - - - - - - - diff --git a/lua/core/options.lua b/lua/core/options.lua index f1f1e8b..85acd0f 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -1,83 +1,69 @@ -local set= vim.opt +local G = require('G') + -- 行号 -set.nu = true -set.rnu = true -set.scrolloff = 999 +G.opt.nu = true +G.opt.rnu = true +G.opt.scrolloff = 999 -- 自动保存 -set.autowrite = true -set.autowriteall = true +G.opt.autowrite = true +G.opt.autowriteall = true -- tab键 -set.sw = 2 -set.ts = 2 -set.softtabstop = 2 -set.smarttab = true -set.expandtab = true -set.autoindent = true +G.opt.sw = 2 +G.opt.ts = 2 +G.opt.softtabstop = 2 +G.opt.smarttab = true +G.opt.expandtab = true +G.opt.autoindent = true -- 光标 -set.cursorline = true +G.opt.cursorline = true -- 分屏 -set.splitright = true -set.splitbelow = true +G.opt.splitright = true +G.opt.splitbelow = true -- 搜索 -set.ignorecase = true -set.incsearch = true +G.opt.ignorecase = true +G.opt.incsearch = true -- 不换行 -set.textwidth = 999 -set.wrap = false +G.opt.textwidth = 999 +G.opt.wrap = false -- 背景 -set.background = 'dark' +G.opt.background = 'dark' -- 主题 -vim.cmd("colorscheme gruvbox") - --- 输入法自动根据模式自动切换 -vim.cmd([[ au InsertLeave * :silent !fcitx5-remote -c ]]) +G.cmd("colorscheme gruvbox") -- 文件判断 -vim.cmd([[ filetype plugin indent on ]]) +G.cmd("filetype plugin indent on") -- 取消换行注释 -vim.api.nvim_create_autocmd({ "BufEnter" }, { +G.api.nvim_create_autocmd({ "BufEnter" }, { pattern = { "*" }, callback = function() -- vim.opt.formatoptions = vim.opt.formatoptions - { "c", "r", "o" } - vim.opt.formatoptions = vim.opt.formatoptions - - "o" -- O and o, don't continue comments + G.opt.formatoptions = G.opt.formatoptions + - "o" -- O and o, don't continue comments + "r" -- But do continue when pressing enter. end, }) local require_markdown = {} + function require_markdown() - require('Filetype.markdown') + require('Filetype.markdown') + G.cmd('MarkdownPreviewToggle') end -vim.api.nvim_create_autocmd( -{"FileType"}, { pattern = "markdown", callback = require_markdown } + +G.api.nvim_create_autocmd( + {"FileType"}, { + pattern = "markdown", + callback = require_markdown + } ) - - - - - - - - - - - - - - - - - - diff --git a/lua/core/plug.lua b/lua/core/plug.lua index 7dc9e04..0e15e46 100644 --- a/lua/core/plug.lua +++ b/lua/core/plug.lua @@ -1,48 +1,45 @@ --- lazy插件自动安装插件 -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" -if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--depth=1", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release - lazypath, - }) +local ensure_packer = function() + local fn = vim.fn + local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' + if fn.empty(fn.glob(install_path)) > 0 then + fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) + vim.cmd [[packadd packer.nvim]] + return true + end + return false end -vim.opt.rtp:prepend(lazypath) +local packer_bootstrap = ensure_packer() +local G = require('G') +return require('packer').startup(function(use) -require("lazy").setup({ -- 主题插件 - 'nvim-lualine/lualine.nvim', - 'morhetz/gruvbox', + use 'nvim-lualine/lualine.nvim' + use 'morhetz/gruvbox' -- lsp 补全 - {'neoclide/coc.nvim', branch = 'release'}, + use {'neoclide/coc.nvim', branch = 'release'} -- surround 和 wildfire 配合有神奇的效果 - 'tpope/vim-surround', - 'gcmt/wildfire.vim', - - -- easymotion - 'easymotion/vim-easymotion', + use 'tpope/vim-surround' + use 'gcmt/wildfire.vim' + -- easymotion + use 'easymotion/vim-easymotion' -- 格式整理 - 'junegunn/vim-easy-align', - 'preservim/nerdcommenter', + use 'junegunn/vim-easy-align' + use 'preservim/nerdcommenter' --颜色识别 - 'lilydjwg/colorizer', + use 'lilydjwg/colorizer' --markdown - 'iamcco/markdown-preview.vim', + use 'iamcco/markdown-preview.nvim' -- git - 'kdheepak/lazygit.nvim', -}) - + use 'kdheepak/lazygit.nvim' + +end)