diff --git a/init.lua b/init.lua index 09a9b90..ea61502 100644 --- a/init.lua +++ b/init.lua @@ -1,10 +1,10 @@ vim.opt.syntax = 'on' -vim.cmd([[hi MatchParen ctermfg=none ctermbg=none cterm=bold,underline gui=bold,underline guifg=fg guibg=bg +vim.cmd([[ filetype plugin indent on ]]) vim.opt.number = true -- set relativenumber -vim.opt.relativenumber = true +vim.opt.relativenumber = false --vim.opt.path += "**" vim.opt.swapfile = false vim.opt.wildmenu = true @@ -28,6 +28,8 @@ vim.opt.guicursor = "" require("colorschemes") +vim.cmd([[hi MatchParen cterm=bold,underline gui=bold,underline]]) + vim.api.nvim_set_keymap("n", "", "", { noremap = true }) vim.g.mapleader = " " @@ -41,6 +43,9 @@ for _, mode in ipairs({"n", "i"}) do end vim.api.nvim_set_keymap("n", "o", "lua vim.diagnostic.open_float()", { noremap = true }) +vim.api.nvim_set_keymap("n", "", "lua vim.diagnostic.open_float()", { noremap = true }) +vim.api.nvim_set_keymap("n", "i", "lua vim.lsp.buf.code_action()", { noremap = true }) +vim.api.nvim_set_keymap("n", "", "lua vim.lsp.buf.code_action()", { noremap = true }) require('plugins') -- require'lspconfig'.pyright.setup{} @@ -64,53 +69,7 @@ nvim_lsp.pyright.setup{} -- }, -- }) -local cmp = require'cmp' -local snippy = require('snippy') - -cmp.setup({ - - snippet = { - expand = function(args) - snippy.expand_snippet(args.body) - end - }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - [''] = cmp.mapping.confirm({ select = true }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif snippy.can_expand_or_advance() then - snippy.expand_or_advance() - else - fallback() - end - end, { "i", "s" }), - - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif snippy.can_jump(-1) then - snippy.previous() - else - fallback() - end - end, { "i", "s" }), - }), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'snippy' }, - { name = 'buffer' }, - }) -}) +require('completion') local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) nvim_lsp.rust_analyzer.setup({ @@ -133,6 +92,8 @@ vim.diagnostic.config({ } }) +require('treesitter') + -- -- trouble.nvim mappings -- vim.api.nvim_set_keymap("n", "xx", "Trouble", -- {silent = true, noremap = true} diff --git a/lua/completion.lua b/lua/completion.lua new file mode 100644 index 0000000..76aabb7 --- /dev/null +++ b/lua/completion.lua @@ -0,0 +1,61 @@ +local cmp = require'cmp' +local snippy = require('snippy') + +cmp.setup({ + + snippet = { + expand = function(args) + snippy.expand_snippet(args.body) + end + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [''] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif snippy.can_expand_or_advance() then + snippy.expand_or_advance() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif snippy.can_jump(-1) then + snippy.previous() + else + fallback() + end + end, { "i", "s" }), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'snippy' }, + { name = 'buffer' }, + }), + formatting = { + fields = { + cmp.ItemField.Abbr, + cmp.ItemField.Kind, + cmp.ItemField.Menu, + }, + format = function(entry, vim_item) + vim_item.abbr = string.sub(vim_item.abbr, 1, 20) + vim_item.kind = string.sub(vim_item.kind, 1, 10) + vim_item.menu = string.sub(vim_item.menu, 1, 10) + return vim_item + end + } +}) + diff --git a/lua/plugins.lua b/lua/plugins.lua index 0c3d810..1518c65 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -17,5 +17,11 @@ packer.startup( use 'NLKNguyen/papercolor-theme' use 'olimorris/onedarkpro.nvim' use 'EdenEast/nightfox.nvim' + use { + 'nvim-treesitter/nvim-treesitter', + run = function() + require('nvim-treesitter.install').update({ with_sync = true }) + end, + } end ) diff --git a/lua/treesitter.lua b/lua/treesitter.lua new file mode 100644 index 0000000..0d6d4dc --- /dev/null +++ b/lua/treesitter.lua @@ -0,0 +1,33 @@ +require'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" + ensure_installed = { "rust" }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + auto_install = true, + + -- List of parsers to ignore installing (for "all") + ignore_install = { "javascript" }, + + ---- If you need to change the installation directory of the parsers (see -> Advanced Setup) + -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")! + + highlight = { + -- `false` will disable the whole extension + enable = true, + + -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to + -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is + -- the name of the parser) + -- list of language that will be disabled + --disable = { "c", "rust" }, + + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, +}