summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlistout <listout@protonmail.com>2022-08-25 01:14:33 +0530
committerlistout <listout@protonmail.com>2022-09-01 16:26:42 +0530
commitdd31843246ccdf9783f1b54d79b5e1ee22596399 (patch)
tree9b0f42dbe44fd0dd79d8de963092daf04671e6d9
parentf07108dca88d47eeae67587011994c6179a7d035 (diff)
[wip] better lua config for nvim
Signed-off-by: listout <listout@protonmail.com>
-rw-r--r--init.lua25
-rw-r--r--lua/core/appearance.lua2
-rw-r--r--lua/core/colorscheme.lua6
-rw-r--r--lua/core/options.lua1
-rw-r--r--lua/plugins/cmp.lua72
-rw-r--r--lua/plugins/coc-config.lua13
-rw-r--r--lua/plugins/lsp-config.lua46
-rw-r--r--lua/plugins/plugins.lua72
-rw-r--r--lua/plugins/treesitter.lua38
9 files changed, 241 insertions, 34 deletions
diff --git a/init.lua b/init.lua
index ebbc782..016cffc 100644
--- a/init.lua
+++ b/init.lua
@@ -3,14 +3,19 @@ Neovim init file
--]]
-- Import Lua modules
-require('core/colorscheme')
-require('core/appearance')
-require('core/options')
-require('core/utils')
-require('core/settings')
-require('core/keymaps')
+require('core.colorscheme')
+require('core.appearance')
+require('core.options')
+require('core.utils')
+require('core.settings')
+require('core.keymaps')
-require('plugins/plugins')
-require('plugins/coc')
-require('plugins/usnippet')
-require('plugins/statusline')
+require('plugins.plugins')
+require('plugins.cmp')
+require('plugins.lsp-config')
+require('plugins.usnippet')
+require('plugins.statusline')
+require('plugins.treesitter')
+
+-- Per project configuration
+require('nvim-projectconfig').setup()
diff --git a/lua/core/appearance.lua b/lua/core/appearance.lua
index 452c4b9..a1ff443 100644
--- a/lua/core/appearance.lua
+++ b/lua/core/appearance.lua
@@ -12,7 +12,7 @@ opt.splitbelow = true -- Horizontal split to the bottom
opt.ignorecase = true -- Ignore case letters when search
opt.smartcase = true -- Ignore lowercase for the whole pattern
opt.linebreak = true -- Wrap on word boundary
-opt.termguicolors = true -- Enable 24-bit RGB colors
+opt.termguicolors = false -- Enable 24-bit RGB colors
opt.laststatus = 2 -- Set global statusline
opt.splitbelow = true
opt.splitright = true
diff --git a/lua/core/colorscheme.lua b/lua/core/colorscheme.lua
index 209fde3..7c8fbb6 100644
--- a/lua/core/colorscheme.lua
+++ b/lua/core/colorscheme.lua
@@ -1,7 +1,3 @@
-- Config in lua
-vim.g.tokyonight_style = "storm"
-vim.g.tokyonight_italic_functions = 1
-vim.g.tokyonight_sidebars = {"packer", "qf", " vista_kind", "terminal"}
-
-- Load the colorscheme
-vim.cmd[[colorscheme tokyonight]]
+vim.cmd[[colorscheme substrata]]
diff --git a/lua/core/options.lua b/lua/core/options.lua
index 12609e3..3d5855f 100644
--- a/lua/core/options.lua
+++ b/lua/core/options.lua
@@ -29,6 +29,7 @@ opt.hlsearch = false -- No highlight search
opt.incsearch = true
opt.ignorecase = true
opt.backspace = 'indent,eol,start'
+--opt.autochdir = true
-----------------------------------------------------------
-- Tabs, indent
diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua
new file mode 100644
index 0000000..e42b9f2
--- /dev/null
+++ b/lua/plugins/cmp.lua
@@ -0,0 +1,72 @@
+-- luasnip setup
+local luasnip = require 'luasnip'
+
+-- nvim-cmp setup
+local cmp = require 'cmp'
+cmp.setup {
+ view = {
+ entries = "custom",
+ },
+ snippet = {
+ expand = function(args)
+ luasnip.lsp_expand(args.body)
+ require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
+ end,
+ },
+ mapping = cmp.mapping.preset.insert({
+ ['<C-d>'] = cmp.mapping.scroll_docs(-4),
+ ['<C-f>'] = cmp.mapping.scroll_docs(4),
+ ['<C-Space>'] = cmp.mapping.complete(),
+ ['<CR>'] = cmp.mapping.confirm {
+ behavior = cmp.ConfirmBehavior.Replace,
+ select = true,
+ },
+ ['<Tab>'] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_next_item()
+ elseif luasnip.expand_or_jumpable() then
+ luasnip.expand_or_jump()
+ else
+ fallback()
+ end
+ end, { 'i', 's' }),
+ ['<S-Tab>'] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_prev_item()
+ elseif luasnip.jumpable(-1) then
+ luasnip.jump(-1)
+ else
+ fallback()
+ end
+ end, { 'i', 's' }),
+ }),
+ sources = {
+ { name = 'path' },
+ { name = 'buffer' },
+ { name = 'nvim_lsp_signature_help' },
+ { name = 'nvim_lsp' },
+ { name = 'luasnip' },
+ { name = 'nvim_lua' },
+ },
+}
+-- Set configuration for specific filetype.
+cmp.setup.filetype('gitcommit', {
+ sources = cmp.config.sources({
+ { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
+ }, {
+ { name = 'buffer' },
+ })
+})
+-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
+require'cmp'.setup.cmdline('/', {
+ sources = {
+ { name = 'buffer' } -- cmp-buffer needed
+ }
+})
+-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
+require'cmp'.setup.cmdline(':', {
+ sources = {
+ { name = 'cmdline' },
+ { name = 'path' }, -- cmp-path needed
+ }
+})
diff --git a/lua/plugins/coc-config.lua b/lua/plugins/coc-config.lua
new file mode 100644
index 0000000..cd5f14f
--- /dev/null
+++ b/lua/plugins/coc-config.lua
@@ -0,0 +1,13 @@
+-- Change leader to a comma
+vim.g.mapleader = ','
+
+vim.api.nvim_set_keymap("n", "<leader>.", "<Plug>(coc-codeaction)", {})
+vim.api.nvim_set_keymap("n", "<leader>l", ":CocCommand eslint.executeAutofix<CR>", {})
+vim.api.nvim_set_keymap("n", "gd", "<Plug>(coc-definition)", {silent = true})
+vim.api.nvim_set_keymap("n", "K", ":call CocActionAsync('doHover')<CR>", {silent = true, noremap = true})
+vim.api.nvim_set_keymap("n", "<leader>rn", "<Plug>(coc-rename)", {})
+vim.api.nvim_set_keymap("n", "<leader>f", ":CocCommand prettier.formatFile<CR>", {noremap = true})
+vim.api.nvim_set_keymap("i", "<C-Space>", "coc#refresh()", { silent = true, expr = true })
+vim.api.nvim_set_keymap("i", "<tab>", "pumvisible() ? '<C-n>' : '<tab>'", {noremap = true, silent = true, expr = true})
+vim.api.nvim_set_keymap("i", "<S-TAB>", "pumvisible() ? '<C-p>' : '<C-h>'", {noremap = true, expr = true})
+vim.api.nvim_set_keymap("i", "<CR>", "pumvisible() ? coc#_select_confirm() : '<C-G>u<CR><C-R>=coc#on_enter()<CR>'", {silent = true, expr = true, noremap = true})
diff --git a/lua/plugins/lsp-config.lua b/lua/plugins/lsp-config.lua
new file mode 100644
index 0000000..17e7de9
--- /dev/null
+++ b/lua/plugins/lsp-config.lua
@@ -0,0 +1,46 @@
+-- Add additional capabilities supported by nvim-cmp
+local capabilities = vim.lsp.protocol.make_client_capabilities()
+capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
+
+local lspconfig = require('lspconfig')
+
+vim.lsp.set_log_level(vim.log.levels.DEBUG)
+
+-- Mappings.
+-- See `:help vim.diagnostic.*` for documentation on any of the below functions
+local opts = { noremap=true, silent=true }
+vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
+vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
+vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
+vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
+
+-- Use an on_attach function to only map the following keys
+-- after the language server attaches to the current buffer
+local on_attach = function(client, bufnr)
+ -- Enable completion triggered by <c-x><c-o>
+ vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
+
+ -- Mappings.
+ -- See `:help vim.lsp.*` for documentation on any of the below functions
+ local bufopts = { noremap=true, silent=true, buffer=bufnr }
+ vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
+ vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
+ vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
+ vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
+ vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
+ vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
+ vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
+ vim.keymap.set('n', '<space>wl', function()
+ print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
+ end, bufopts)
+ vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
+ vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
+ vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
+ vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
+ vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
+end
+
+local lsp_flags = {
+ -- This is the default in Nvim 0.7+
+ debounce_text_changes = 150,
+}
diff --git a/lua/plugins/plugins.lua b/lua/plugins/plugins.lua
index 5b9bc6b..185514d 100644
--- a/lua/plugins/plugins.lua
+++ b/lua/plugins/plugins.lua
@@ -1,38 +1,74 @@
-- This file can be loaded by calling `lua require('plugins')` from your init.vim
-- Only required if you have packer configured as `opt`
-vim.cmd [[packadd packer.nvim]]
-
-return require('packer').startup(function(use)
+local use = require('packer').use
+return require('packer').startup(function()
-- Packer can manage itself
use 'wbthomason/packer.nvim'
-- Nord color scheme
- use 'folke/tokyonight.nvim'
-
- -- Completion
- use {'neoclide/coc.nvim', branch = 'release'}
+ use 'arzg/vim-substrata'
+ -- Completion and language server
+ use {'neovim/nvim-lspconfig'} -- Collection of configurations for built-in LSP client
+ use {'hrsh7th/cmp-nvim-lsp'} -- LSP source for nvim-cmp
+ use {'hrsh7th/cmp-buffer'} -- LSP source nvim-cmp
+ use {'hrsh7th/cmp-path'} -- LSP source for nvim-cmp
+ use {'hrsh7th/cmp-cmdline'} -- LSP source nvim-cmp
+ use {'hrsh7th/cmp-nvim-lsp-signature-help'}
+ use {'hrsh7th/nvim-cmp'} -- Autocompletion plugin
+ use {'hrsh7th/cmp-nvim-lua'}
+ use {'saadparwaiz1/cmp_luasnip'} -- Snippets source for nvim-cmp
+ use {'L3MON4D3/LuaSnip'} -- Snippets plugin
+ -- Show color under hex codes
use {'ap/vim-css-color'}
- use {'jiangmiao/auto-pairs'}
- use {'preservim/nerdcommenter'}
- use { 'dhruvasagar/vim-table-mode', ft = {'markdown', 'markdown.pandoc'} }
+ -- Productivity plugins
+ use {'jiangmiao/auto-pairs'} -- Auto add matching brackets
+ use {'preservim/nerdcommenter'} -- Easy commenting
+ use {'dhruvasagar/vim-table-mode', ft = {'markdown', 'markdown.pandoc'} } -- Markdown easy tables
+ use {'junegunn/fzf', run = ":call fzf#install()" }
+ use {'junegunn/fzf.vim' } -- Fuzzy file finding
+ use {'tpope/vim-surround'} -- Easy surrounding with brackets, quotes ...
+ use {'junegunn/vim-easy-align'} -- Easy aling with space, = ...
+
+ -- Writing
+ use {'junegunn/goyo.vim', ft = {'markdown', 'markdown.pandoc'}}
+ use {'junegunn/limelight.vim', ft = {'markdown', 'markdown.pandoc'}}
use { 'vim-pandoc/vim-pandoc-syntax', ft = { 'markdown', 'markdown.pandoc' } }
use { 'lervag/vimtex', ft = { 'tex' } }
- use { 'junegunn/fzf', run = ":call fzf#install()" }
- use { 'junegunn/fzf.vim' }
+ -- Git intigration
+ use { 'tpope/vim-fugitive', ft = {'cpp', 'c'} }
+
+ -- Treesitter integration
+ use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }
- use { 'honza/vim-snippets' }
- use { 'SirVer/ultisnips' }
+ -- Better per project settings
+ use { 'windwp/nvim-projectconfig' }
+ --[[
+ [use {
+ [ "klen/nvim-config-local",
+ [ config = function()
+ [ require('config-local').setup {
+ [ -- Default configuration (optional)
+ [ config_files = { ".vimrc.lua", ".vimrc" }, -- Config file patterns to load (lua supported)
+ [ hashfile = vim.fn.stdpath("data") .. "/config-local", -- Where the plugin keeps files data
+ [ autocommands_create = true, -- Create autocommands (VimEnter, DirectoryChanged)
+ [ commands_create = true, -- Create commands (ConfigSource, ConfigEdit, ConfigTrust, ConfigIgnore)
+ [ silent = false, -- Disable plugin messages (Config loaded/ignored)
+ [ lookup_parents = true, -- Lookup config files in parent directories
+ [ }
+ [ end
+ [}
+ ]]
- use {'tpope/vim-surround'}
- use {'junegunn/vim-easy-align'}
+ --[[ Most probably not needed anymore
+ [use { 'honza/vim-snippets' }
+ [use { 'SirVer/ultisnips' }
+ ]]
- use { 'tpope/vim-fugitive', ft = {'cpp', 'c'} }
- use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }
end)
diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua
new file mode 100644
index 0000000..7141d3d
--- /dev/null
+++ b/lua/plugins/treesitter.lua
@@ -0,0 +1,38 @@
+require'nvim-treesitter.configs'.setup {
+ -- A list of parser names, or "all"
+ ensure_installed = { "c", "lua", "cpp" },
+
+ -- Install parsers synchronously (only applied to `ensure_installed`)
+ sync_install = true,
+
+ -- Automatically install missing parsers when entering buffer
+ auto_install = true,
+
+ -- List of parsers to ignore installing (for "all")
+ ignore_install = { "javascript" },
+
+ 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,
+ },
+
+ indent = true,
+
+ --[[
+ [indent = {
+ [ enable = true,
+ [},
+ ]]
+}