diff --git a/nvim/lua/core/cmd.lua b/nvim/lua/core/cmd.lua index e69de29..8914aa3 100644 --- a/nvim/lua/core/cmd.lua +++ b/nvim/lua/core/cmd.lua @@ -0,0 +1,27 @@ +vim.api.nvim_create_augroup('Init', { clear = true }) +-- highlight yanked text briefly +vim.api.nvim_create_autocmd('TextYankPost', { + group = 'Init', + callback = function() + vim.highlight.on_yank({ + higroup = 'IncSearch', + timeout = 250, + on_visual = true, + }) + end, +}) + +-- reopen last position +vim.api.nvim_create_autocmd('BufReadPost', { + group = 'Init', + callback = function() + local previous_pos = vim.api.nvim_buf_get_mark(0, '"')[1] + local last_line = vim.api.nvim_buf_line_count(0) + if previous_pos >= 1 and previous_pos <= last_line and vim.bo.filetype ~= 'commit' then + vim.cmd('normal! g`"') + end + end, +}) + +vim.cmd([[iabbrev pdb import pdb; pdb.set_trace()]]) +vim.cmd([[iabbrev ipdb import ipdb; ipdb.set_trace()]]) diff --git a/nvim/lua/core/filetype.lua b/nvim/lua/core/filetype.lua index e69de29..8d7c7e3 100644 --- a/nvim/lua/core/filetype.lua +++ b/nvim/lua/core/filetype.lua @@ -0,0 +1,20 @@ +local cmd = vim.cmd +local ncmd = vim.api.nvim_command + +ncmd('filetype plugin indent on') +cmd([[ autocmd FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=120 ]]) +cmd([[ autocmd FileType go setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=120 noexpandtab ]]) +cmd([[ autocmd FileType json,jsonnet setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab ]]) +cmd([[ autocmd FileType yaml setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=0 expandtab ]]) +cmd([[ autocmd FileType php setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=120 ]]) +cmd([[ autocmd FileType html,htmldjango,xhtml,haml setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=0 ]]) +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=2 expandtab ]] +) +cmd([[ autocmd FileType NvimTree setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=0 ]]) +cmd([[ autocmd FileType make set noexpandtab shiftwidth=8 softtabstop=0]]) + +cmd([[ autocmd BufNewFile,BufRead *.proto setfiletype proto ]]) +cmd([[ autocmd FileType proto setlocal shiftwidth=2 expandtab ]]) diff --git a/nvim/lua/core/init.lua b/nvim/lua/core/init.lua index b156970..9c0c7fa 100644 --- a/nvim/lua/core/init.lua +++ b/nvim/lua/core/init.lua @@ -4,204 +4,188 @@ 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') +-- +-- 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]] -- 开启文件类型侦测 +-- -- 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): +-- +-- -- 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') +-- +-- -- Neoformat +-- if not fn.executable('luafmt') then +-- cmd([[ :!npm install -g lua-fmt]]) -- 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 --- ) +-- -- 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 index e69de29..90ea2c0 100644 --- a/nvim/lua/core/keymap.lua +++ b/nvim/lua/core/keymap.lua @@ -0,0 +1,17 @@ +local map = vim.keymap.set + +-- Key bindings +map('', '', 'ggVG$"+y') +map('v', '', '"+y') +map('v', '', '>gv') +map('v', '', '', 'b') +map('i', '', 'l') +map('i', '', 'h') +map('i', '', 'l') +map('i', '', 'j') +map('i', '', 'k') +map('c', '', '') +map('c', '', '') +map('c', '', '') +map('c', '', '') diff --git a/nvim/lua/core/lazy.lua b/nvim/lua/core/lazy.lua index fc3f978..0815307 100644 --- a/nvim/lua/core/lazy.lua +++ b/nvim/lua/core/lazy.lua @@ -15,6 +15,7 @@ vim.opt.rtp:prepend(lazypath) require("lazy").setup({ spec = { { import = 'plugins' }, + { import = 'plugins.lsp' }, }, ui = { border = 'rounded', diff --git a/nvim/lua/core/prelude.lua b/nvim/lua/core/prelude.lua index 58e519a..b1c71e1 100644 --- a/nvim/lua/core/prelude.lua +++ b/nvim/lua/core/prelude.lua @@ -2,7 +2,51 @@ if vim.fn.has('nvim') == 0 then return end +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 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` +vim.g.mapleader = ' ' -- Make sure to set `mapleader` before lazy so your mappings are correct +vim.g.maplocalleader = '\\' -- Same for `maplocalleader` + +vim.o.encoding = 'utf-8' +vim.o.fileencoding = 'utf-8' +vim.o.fencs = 'utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936' +vim.o.hidden = true +vim.o.wildmenu = true +vim.o.hlsearch = true +vim.o.incsearch = true +vim.o.matchtime = 1 +vim.o.showmatch = true +vim.o.updatetime = 100 +vim.o.ignorecase = true +vim.o.smarttab = true +vim.o.expandtab = true +vim.o.laststatus = 2 +vim.o.showcmd = true +vim.o.ruler = true +vim.o.history = 300 +vim.o.backup = false +vim.o.swapfile = false +vim.o.foldenable = false +vim.o.autoread = true +vim.o.autowrite = true +vim.o.mouse = 'a' + +vim.o.number = true +vim.o.cursorline = true +vim.o.relativenumber = true +vim.o.cursorcolumn = true +vim.o.signcolumn = 'auto:1' +-- vim.o.cmdheight = 0 +vim.opt.list = true +vim.opt.listchars:append('eol:↴') +vim.opt.fillchars:append { diff = '╱' } + +vim.o.textwidth = 120 +vim.o.smartindent = true +vim.o.autoindent = true +vim.o.cindent = true +vim.o.shiftwidth = 4 +vim.o.softtabstop = 4 +vim.o.tabstop = 4 diff --git a/nvim/lua/funcs.lua b/nvim/lua/funcs.lua deleted file mode 100644 index d71f199..0000000 --- a/nvim/lua/funcs.lua +++ /dev/null @@ -1,5 +0,0 @@ -local fn = vim.fn - -function GetPath() - fn.setreg('+', fn.getreg('%')) -end diff --git a/nvim/lua/plugins/indentline.lua b/nvim/lua/plugins/indentline.lua index c2f80ef..e249e03 100644 --- a/nvim/lua/plugins/indentline.lua +++ b/nvim/lua/plugins/indentline.lua @@ -30,6 +30,8 @@ return { char = '|', highlight = highlight, }, + whitespace = { + }, exclude = { buftypes = { 'terminal', diff --git a/nvim/lua/plugins/lsp/mason.lua b/nvim/lua/plugins/lsp/mason.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/nvim/lua/plugins/lsp/mason.lua @@ -0,0 +1 @@ +return {}