diff --git a/nvim/init.lua b/nvim/init.lua index bdcffe0..5700b24 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,227 +1 @@ -local cmd = vim.cmd -local o_s = vim.o -local map_key = vim.api.nvim_set_keymap -local g = vim.g -local api = vim.api -local fn = vim.fn -local ncmd = vim.api.nvim_command -local o, wo, bo = vim.o, vim.wo, vim.bo - -local buffer = { o, bo } -local window = { o, wo } - - -local utils = require('utils') -local map = utils.map -local set = utils.set - ---vim.lsp.set_log_level('debug') --- Preset --- Prerequisites Must have neovim installed -if fn.has('nvim') == 0 then - return -end - -vim.g.mapleader = " " -- Make sure to set `mapleader` before lazy so your mappings are correct -vim.g.maplocalleader = "\\" -- Same for `maplocalleader` - -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" -if not (vim.uv or vim.loop).fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release - lazypath, - }) -end -vim.opt.rtp:prepend(lazypath) - -require("lazy").setup("plugins") --- -- Ensure packer installed --- 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 }) --- cmd('packadd packer.nvim') --- end --- --- reopen last position --- cmd([[ autocmd BufReadPost * normal! g`" ]]) - --- Shcemas and colors -set('termguicolors', true) -- 开启24bit的颜色,开启这个颜色会更漂亮一些 -cmd([[ colorscheme tokyonight ]]) ---set('background', 'dark') -- 主题背景 dark-深色; light-浅色 - --- CMDs --- cmd [[syntax enable]] --- cmd [[syntax on]] -- 开启文件类型侦测 -cmd('filetype plugin indent on') -cmd([[ autocmd FileType php setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=120 ]]) -cmd([[ autocmd FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4 ]]) -cmd([[ autocmd FileType json setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab ]]) -cmd([[ autocmd FileType go setlocal tabstop=8 shiftwidth=8 softtabstop=8 textwidth=120 noexpandtab ]]) --- in makefiles, don't expand tabs to spaces, since actual tab characters are --- needed, and have indentation at 8 chars to be sure that all indents are tabs --- (despite the mappings later): -cmd([[ autocmd FileType make set noexpandtab shiftwidth=8 softtabstop=0]]) -cmd([[ autocmd FileType html,htmldjango,xhtml,haml setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=0 ]]) -cmd([[ autocmd FileType yaml setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=0 expandtab ]]) -cmd([[ autocmd FileType ruby setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=120 ]]) -cmd([[ autocmd FileType less,sass,scss,css setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=120 ]]) -cmd( - [[ autocmd FileType javascript,javascript.jsx,javascriptreact,typescript,typescriptreact setlocal tabstop=2 shiftwidth=2 softtabstop=4 expandtab ]] -) - -cmd([[iabbrev pdb import pdb; pdb.set_trace()]]) -cmd([[iabbrev ipdb import ipdb; ipdb.set_trace()]]) --- auto compile packer -cmd([[ -augroup packer_user_config - autocmd! - autocmd BufWritePost plugins.lua source | PackerCompile -augroup end -]]) --- autocmd BufRead,BufNewFile *.bean,*.beancount set filetype=beancount - --- cmd [[command ShowBlank set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣]] - --- Settings --- max timeout for common command -set('timeoutlen', 1000) --- set number, cusor or line/column -set('nu', true, window) -set('rnu', true, window) -set('cul', true, window) -set('cuc', true, window) - --- tab 缩进 --- set("tabstop", 4) -- 设置Tab长度为4空格 --- set("shiftwidth", 4) -- 设置自动缩进长度为4空格 --- set("autoindent", true) -- 继承前一行的缩进方式,适用于多行注释 --- set("colorcolumn", "80") -- 设置长度提示79 --- set('noswapfile', true) -- 不设置swap文件 - -set('showmatch', true) -- 显示括号匹配 -set('mouse', 'a') -- set scroll mode -set('langmenu', 'zh_CN.UTF-8') -set('helplang', 'cn') -set('encoding', 'utf-8') -set('fencs', 'utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936') -set('hidden', true) -set('wildmenu', true) -set('hlsearch', true) -set('matchtime', 1) -set('updatetime', 100) -set('smarttab', true) -set('expandtab', true) -set('laststatus', 2) -set('showcmd', true) -set('ruler', true) -set('history', 300) -set('backup', false) -set('swapfile', false) -set('foldenable', false) -set('autoread', true) -set('autowrite', true) -set('mouse', 'a') -set('incsearch', true) -- 开启实时搜索 -set('ignorecase', true) -- 搜索时大小写不敏感 - -set('number', true, window) --- set('relativenumber', true, window) -set('cursorline', true, window) -set('cursorcolumn', true, window) -set('signcolumn', 'auto:2') - --- set("textwidth", 120, buffer) -set('smartindent', true, buffer) -set('autoindent', true, buffer) -set('cindent', true, buffer) -set('shiftwidth', 4, buffer) -set('softtabstop', 4, buffer) -set('tabstop', 4, buffer) -set('synmaxcol', 120) - --- set autowrite --- set("backspace", "indent,eol,start") - --- Key mappings --- map Leader key to --- g.mapleader = [[ ]] - --- v 模式下复制内容到系统剪切板 -map('v', 'cp', '"+yy') --- n 模式下复制一行到系统剪切板 -map('n', 'cp', '"+yy') --- n 模式下粘贴系统剪切板的内容 -map('n', 'v', '"+p') --- reload vimrc -map('n', 'rv', ':source $MYVIMRC') - --- insert mode mapping ---map('i', '', 'b') ---map('i', '', 'l') ---map('i', '', 'j') ---map('i', '', 'k') - -map('n', '', '') -map('i', '', '') - ---map('i', '', '') ---map('i', '', '') ---map('i', '', '') ---map('i', '', '') - --- map('n', 'e', '1w') --- map('n', 'p', ':wincmd p') - -map('i', '', 'copilot#Accept()', { expr = true }) -vim.g.copilot_no_tab_map = 1 -vim.g.copilot_no_maps = 1 -vim.g.copilot_assume_mapped = 1 - - --- require('plugins') -require('funcs') - --- Neoformat -if not fn.executable('luafmt') then - cmd([[ :!npm install -g lua-fmt]]) -end - --- barbar -local opts = { noremap = true, silent = true } -map('n', '=', ':BufferPick', opts) - --- choosewin -map('n', '-', '(choosewin)', { noremap = false }) - --- sort go imports --- vim.api.nvim_create_autocmd('BufWritePre', { --- pattern = '*.go', --- callback = function() --- vim.lsp.buf.code_action({ context = { only = { 'source.organizeImports' } }, apply = true }) --- end --- }) - -vim.api.nvim_set_keymap('n', 'of', ':lua OpenFinder()', { noremap = true, silent = true }) - -function OpenFinder() - local current_path = vim.fn.expand('%:p:h') - vim.cmd('!open ' .. current_path) -end - --- Some configurations not able to migrate -api.nvim_exec( - [[ -" set nocompatible -"function! NearestMethodOrFunction() abort -" return get(b:, 'vista_nearest_method_or_function', '') -"endfunction -" -"set statusline+=%{NearestMethodOrFunction()} -]], - false -) +require('core') diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index 3e09094..a1cb303 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -15,22 +15,22 @@ "image_preview.nvim": { "branch": "main", "commit": "8de950078bdecf1916e8dbddfbee451e095b023c" }, "incolla.nvim": { "branch": "master", "commit": "a3e5f170e37c8da61906f31fd8d61a475b32bfd5" }, "indent-blankline.nvim": { "branch": "master", "commit": "d98f537c3492e87b6dc6c2e3f66ac517528f406f" }, - "lazy.nvim": { "branch": "main", "commit": "24fa2a97085ca8a7220b5b078916f81e316036fd" }, - "lsp_signature.nvim": { "branch": "master", "commit": "529e8861d0410389f0163a5e5c2199d4a4ef5bf6" }, + "lazy.nvim": { "branch": "main", "commit": "b0ba3f9399bf48c86abaa4db1a40bd0b681d5018" }, + "lsp_signature.nvim": { "branch": "master", "commit": "2ec2ba23882329c1302dff773b0d3620371d634f" }, "lspkind-nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" }, "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, - "neoconf.nvim": { "branch": "main", "commit": "f1fd38d61d11f3b1b3e7dc75dc667f79cf2fa58b" }, - "neodev.nvim": { "branch": "main", "commit": "ce9a2e8eaba5649b553529c5498acb43a6c317cd" }, + "neoconf.nvim": { "branch": "main", "commit": "a432a7802b60d52caebd484348266b64bdd1fb21" }, + "neodev.nvim": { "branch": "main", "commit": "1f4ebcc10852518166ce165e57d425a4265a10d4" }, "nvim-autopairs": { "branch": "master", "commit": "c15de7e7981f1111642e7e53799e1211d4606cb9" }, "nvim-cmp": { "branch": "main", "commit": "5260e5e8ecadaf13e6b82cf867a909f54e15fd07" }, - "nvim-lspconfig": { "branch": "master", "commit": "b124ef3bd4435a6db7ff03ea2f5a23e1e0487552" }, + "nvim-lspconfig": { "branch": "master", "commit": "74e14808cdb15e625449027019406e1ff6dda020" }, "nvim-scrollbar": { "branch": "main", "commit": "35f99d559041c7c0eff3a41f9093581ceea534e8" }, - "nvim-tree.lua": { "branch": "master", "commit": "5a87ffe35c4739ffb6b62052572583ad277a20ae" }, - "nvim-treesitter": { "branch": "master", "commit": "b7d50e59b1b2990b3ce8761d4cf595f4b71c87e2" }, - "nvim-treesitter-context": { "branch": "master", "commit": "f62bfe19e0fbc13ae95649dfb3cf22f4ff85b683" }, + "nvim-tree.lua": { "branch": "master", "commit": "26632f496e7e3c0450d8ecff88f49068cecc8bda" }, + "nvim-treesitter": { "branch": "master", "commit": "a80fe081b4c5890980561e0de2458f64aaffbfc7" }, + "nvim-treesitter-context": { "branch": "master", "commit": "5efba33af0f39942e426340da7bc15d7dec16474" }, "nvim-treesitter-endwise": { "branch": "master", "commit": "8b34305ffc28bd75a22f5a0a9928ee726a85c9a6" }, "nvim-treesitter-refactor": { "branch": "master", "commit": "65ad2eca822dfaec2a3603119ec3cc8826a7859e" }, - "nvim-treesitter-textobjects": { "branch": "master", "commit": "3557e41418b4a6c5b85d5d64abe94c9c50fa9b14" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "fd41b7ccc5490a3a99c734d1ee418b68d06c48a9" }, "nvim-web-devicons": { "branch": "master", "commit": "b77921fdc44833c994fdb389d658ccbce5490c16" }, "nvim-yati": { "branch": "main", "commit": "c4307e6855f17ff89f0132787e2daba27495d254" }, "playground": { "branch": "master", "commit": "ba48c6a62a280eefb7c85725b0915e021a1a0749" }, @@ -38,12 +38,12 @@ "sentiment.nvim": { "branch": "main", "commit": "ecde8d877881bb78fdb90060c0991e76770dbdbc" }, "statuscol.nvim": { "branch": "main", "commit": "483b9a596dfd63d541db1aa51ee6ee9a1441c4cc" }, "telescope.nvim": { "branch": "master", "commit": "dfa230be84a044e7f546a6c2b0a403c739732b86" }, - "todo-comments.nvim": { "branch": "main", "commit": "e1549807066947818113a7d7ed48f637e49620d3" }, + "todo-comments.nvim": { "branch": "main", "commit": "70a93ce66083699571adc361166504b03cc39c2b" }, "toggleterm.nvim": { "branch": "main", "commit": "fee58a0473fd92b28c34f8f724e4918b15ba30a3" }, - "tokyonight.nvim": { "branch": "main", "commit": "0fae425aaab04a5f97666bd431b96f2f19c36935" }, + "tokyonight.nvim": { "branch": "main", "commit": "7e5ef71a103e7de5fe6c05f5d6ab97d1640f08cf" }, "vim-fugitive": { "branch": "master", "commit": "4f59455d2388e113bd510e85b310d15b9228ca0d" }, "vim-vsnip": { "branch": "master", "commit": "02a8e79295c9733434aab4e0e2b8c4b7cea9f3a9" }, "vim-vsnip-integ": { "branch": "master", "commit": "1914e72cf3de70df7f5dde476cd299aba2440aef" }, "vim-wakatime": { "branch": "master", "commit": "3cb40867cb5a3120f9bef76eff88edc7f1dc1a23" }, - "which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" } + "which-key.nvim": { "branch": "main", "commit": "4b7167f8fb2dba3d01980735e3509e172c024c29" } } \ No newline at end of file diff --git a/nvim/lua/core/cmd.lua b/nvim/lua/core/cmd.lua new file mode 100644 index 0000000..e69de29 diff --git a/nvim/lua/core/extension.lua b/nvim/lua/core/extension.lua new file mode 100644 index 0000000..96c0acb --- /dev/null +++ b/nvim/lua/core/extension.lua @@ -0,0 +1,10 @@ +function GetPath() + vim.fn.setreg('+', vim.fn.getreg('%')) +end + +function OpenFinder() + local current_path = vim.fn.expand('%:p:h') + vim.cmd('!open ' .. current_path) +end +vim.api.nvim_set_keymap('n', 'of', ':lua OpenFinder()', { noremap = true, silent = true }) + diff --git a/nvim/lua/core/filetype.lua b/nvim/lua/core/filetype.lua new file mode 100644 index 0000000..e69de29 diff --git a/nvim/lua/core/init.lua b/nvim/lua/core/init.lua new file mode 100644 index 0000000..b156970 --- /dev/null +++ b/nvim/lua/core/init.lua @@ -0,0 +1,207 @@ +require('core.prelude') +require('core.cmd') +require('core.lazy') +require('core.filetype') +require('core.keymap') +require('core.extension') + +local cmd = vim.cmd +local o_s = vim.o +local map_key = vim.api.nvim_set_keymap +local g = vim.g +local api = vim.api +local fn = vim.fn +local ncmd = vim.api.nvim_command +local o, wo, bo = vim.o, vim.wo, vim.bo + +local buffer = { o, bo } +local window = { o, wo } + + +local utils = require('utils') +local map = utils.map +local set = utils.set + +--vim.lsp.set_log_level('debug') +-- Preset +-- Prerequisites Must have neovim installed + + +-- -- Ensure packer installed +-- 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 }) +-- cmd('packadd packer.nvim') +-- end +-- +-- reopen last position +-- cmd([[ autocmd BufReadPost * normal! g`" ]]) + +-- Shcemas and colors +-- cmd([[ colorscheme tokyonight ]]) +--set('background', 'dark') -- 主题背景 dark-深色; light-浅色 + +-- CMDs +-- cmd [[syntax enable]] +-- cmd [[syntax on]] -- 开启文件类型侦测 +cmd('filetype plugin indent on') +cmd([[ autocmd FileType php setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=120 ]]) +cmd([[ autocmd FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4 ]]) +cmd([[ autocmd FileType json setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab ]]) +cmd([[ autocmd FileType go setlocal tabstop=8 shiftwidth=8 softtabstop=8 textwidth=120 noexpandtab ]]) +-- in makefiles, don't expand tabs to spaces, since actual tab characters are +-- needed, and have indentation at 8 chars to be sure that all indents are tabs +-- (despite the mappings later): +cmd([[ autocmd FileType make set noexpandtab shiftwidth=8 softtabstop=0]]) +cmd([[ autocmd FileType html,htmldjango,xhtml,haml setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=0 ]]) +cmd([[ autocmd FileType yaml setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=0 expandtab ]]) +cmd([[ autocmd FileType ruby setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=120 ]]) +cmd([[ autocmd FileType less,sass,scss,css setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=120 ]]) +cmd( + [[ autocmd FileType javascript,javascript.jsx,javascriptreact,typescript,typescriptreact setlocal tabstop=2 shiftwidth=2 softtabstop=4 expandtab ]] +) + +cmd([[iabbrev pdb import pdb; pdb.set_trace()]]) +cmd([[iabbrev ipdb import ipdb; ipdb.set_trace()]]) +-- auto compile packer +-- cmd([[ +-- augroup packer_user_config +-- autocmd! +-- autocmd BufWritePost plugins.lua source | PackerCompile +-- augroup end +-- ]]) +-- autocmd BufRead,BufNewFile *.bean,*.beancount set filetype=beancount + +-- cmd [[command ShowBlank set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣]] + +-- Settings +-- max timeout for common command +set('timeoutlen', 1000) +-- set number, cusor or line/column +set('nu', true, window) +set('rnu', true, window) +set('cul', true, window) +set('cuc', true, window) + +-- tab 缩进 +-- set("tabstop", 4) -- 设置Tab长度为4空格 +-- set("shiftwidth", 4) -- 设置自动缩进长度为4空格 +-- set("autoindent", true) -- 继承前一行的缩进方式,适用于多行注释 +-- set("colorcolumn", "80") -- 设置长度提示79 +-- set('noswapfile', true) -- 不设置swap文件 + +set('showmatch', true) -- 显示括号匹配 +set('mouse', 'a') -- set scroll mode +set('langmenu', 'zh_CN.UTF-8') +set('helplang', 'cn') +set('encoding', 'utf-8') +set('fencs', 'utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936') +set('hidden', true) +set('wildmenu', true) +set('hlsearch', true) +set('matchtime', 1) +set('updatetime', 100) +set('smarttab', true) +set('expandtab', true) +set('laststatus', 2) +set('showcmd', true) +set('ruler', true) +set('history', 300) +set('backup', false) +set('swapfile', false) +set('foldenable', false) +set('autoread', true) +set('autowrite', true) +set('mouse', 'a') +set('incsearch', true) -- 开启实时搜索 +set('ignorecase', true) -- 搜索时大小写不敏感 + +set('number', true, window) +-- set('relativenumber', true, window) +set('cursorline', true, window) +set('cursorcolumn', true, window) +set('signcolumn', 'auto:2') + +-- set("textwidth", 120, buffer) +set('smartindent', true, buffer) +set('autoindent', true, buffer) +set('cindent', true, buffer) +set('shiftwidth', 4, buffer) +set('softtabstop', 4, buffer) +set('tabstop', 4, buffer) +set('synmaxcol', 120) + +-- set autowrite +-- set("backspace", "indent,eol,start") + +-- Key mappings +-- map Leader key to +-- g.mapleader = [[ ]] + +-- v 模式下复制内容到系统剪切板 +map('v', 'cp', '"+yy') +-- n 模式下复制一行到系统剪切板 +map('n', 'cp', '"+yy') +-- n 模式下粘贴系统剪切板的内容 +map('n', 'v', '"+p') +-- reload vimrc +map('n', 'rv', ':source $MYVIMRC') + +-- insert mode mapping +--map('i', '', 'b') +--map('i', '', 'l') +--map('i', '', 'j') +--map('i', '', 'k') + +map('n', '', '') +map('i', '', '') + +--map('i', '', '') +--map('i', '', '') +--map('i', '', '') +--map('i', '', '') + +-- map('n', 'e', '1w') +-- map('n', 'p', ':wincmd p') + +map('i', '', 'copilot#Accept()', { expr = true }) +vim.g.copilot_no_tab_map = 1 +vim.g.copilot_no_maps = 1 +vim.g.copilot_assume_mapped = 1 + + +-- require('plugins') +require('funcs') + +-- Neoformat +if not fn.executable('luafmt') then + cmd([[ :!npm install -g lua-fmt]]) +end + +-- barbar +local opts = { noremap = true, silent = true } +map('n', '=', ':BufferPick', opts) + +-- choosewin +map('n', '-', '(choosewin)', { noremap = false }) + +-- sort go imports +-- vim.api.nvim_create_autocmd('BufWritePre', { +-- pattern = '*.go', +-- callback = function() +-- vim.lsp.buf.code_action({ context = { only = { 'source.organizeImports' } }, apply = true }) +-- end +-- }) + +-- Some configurations not able to migrate +-- api.nvim_exec( +-- [[ +-- " set nocompatible +-- "function! NearestMethodOrFunction() abort +-- " return get(b:, 'vista_nearest_method_or_function', '') +-- "endfunction +-- " +-- "set statusline+=%{NearestMethodOrFunction()} +-- ]], +-- false +-- ) diff --git a/nvim/lua/core/keymap.lua b/nvim/lua/core/keymap.lua new file mode 100644 index 0000000..e69de29 diff --git a/nvim/lua/core/lazy.lua b/nvim/lua/core/lazy.lua new file mode 100644 index 0000000..fc3f978 --- /dev/null +++ b/nvim/lua/core/lazy.lua @@ -0,0 +1,28 @@ + +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup({ + spec = { + { import = 'plugins' }, + }, + ui = { + border = 'rounded', + icons = { + task = ' ', + } + }, + -- change_detection = { + -- notify = false, + -- } +}) diff --git a/nvim/lua/core/prelude.lua b/nvim/lua/core/prelude.lua new file mode 100644 index 0000000..58e519a --- /dev/null +++ b/nvim/lua/core/prelude.lua @@ -0,0 +1,8 @@ +if vim.fn.has('nvim') == 0 then + return +end + +vim.o.termguicolors = true + +vim.g.mapleader = " " -- Make sure to set `mapleader` before lazy so your mappings are correct +vim.g.maplocalleader = "\\" -- Same for `maplocalleader`