diff --git a/init.lua b/init.lua index db62ca4..555c5be 100644 --- a/init.lua +++ b/init.lua @@ -1,8 +1,5 @@ for _, name in ipairs({ - 'mappings.colemak', 'reload', - 'general', + 'settings', 'plugins', - 'mappings.general', - 'theme', }) do require('config.' .. name) end diff --git a/lua/config/general.lua b/lua/config/general.lua deleted file mode 100644 index bf49392..0000000 --- a/lua/config/general.lua +++ /dev/null @@ -1,27 +0,0 @@ --- basic stuff -vim.o.number = true -vim.cmd('filetype plugin on') -vim.cmd('syntax on') -vim.o.cmdheight = 2 -vim.g.mapleader = ' ' - --- line break (wrapping) settings -vim.o.linebreak = true -vim.o.breakindent = true -vim.o.showbreak = '\\ ' - --- lines after end of file empty instead of ~ (fillchars) -vim.o.fcs = 'eob: ' - --- tab -vim.o.expandtab = true -vim.o.softtabstop = 4 -vim.o.shiftwidth = 4 - --- turn of gui colors if in tty -if os.getenv('TERM') ~= 'linux' then - vim.o.termguicolors = true -else - vim.o.termguicolors = false -end - diff --git a/lua/config/mappings/cmp.lua b/lua/config/mappings/cmp.lua deleted file mode 100644 index db7b194..0000000 --- a/lua/config/mappings/cmp.lua +++ /dev/null @@ -1,10 +0,0 @@ -return function(cmp) - return cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), - [''] = cmp.mapping.select_next_item(), - }) -end diff --git a/lua/config/mappings/colemak.lua b/lua/config/mappings/colemak.lua deleted file mode 100644 index 0d6bf02..0000000 --- a/lua/config/mappings/colemak.lua +++ /dev/null @@ -1,22 +0,0 @@ -local map = function(from, to) - vim.keymap.set('n', from, to, { noremap = true, silent = true }) - vim.keymap.set('x', from, to, { noremap = true, silent = true }) -end - -local swap = function(a, b) - map(a, b) - map(b, a) -end - -swap('n', 'h') -swap('e', 'j') -swap('i', 'k') -swap('o', 'l') - -swap('n', 'h') -swap('e', 'j') -swap('i', 'k') -swap('o', 'l') - -swap('N', 'H') -swap('O', 'L') diff --git a/lua/config/mappings/general.lua b/lua/config/mappings/general.lua deleted file mode 100644 index 5e33ecd..0000000 --- a/lua/config/mappings/general.lua +++ /dev/null @@ -1,28 +0,0 @@ -local opts = { noremap = true, silent = true } - -local map = vim.keymap.set -local nmap = function(from, to) map('n', from, to, opts) end -local cmd = function(content) return '' .. content .. '' end - --- terminal -map('t', '', '', opts) -nmap('tm', ':belowright 7sp:termA') - --- off search highlight when escape is pressed -nmap('', ':noh') - --- telescope -nmap('ff', cmd('Telescope find_files')) -nmap('fg', cmd('Telescope live_grep')) -nmap('fb', cmd('Telescope buffers')) -nmap('fh', cmd('Telescope help_tags')) - --- explorer -nmap('e', cmd('Neotree toggle')) - --- lsp (universal) -nmap('E', vim.diagnostic.open_float) -nmap('[d', vim.diagnostic.goto_prev) -nmap(']d', vim.diagnostic.goto_next) -nmap('q', vim.diagnostic.setloclist) - diff --git a/lua/config/mappings/lsp.lua b/lua/config/mappings/lsp.lua deleted file mode 100644 index 6915590..0000000 --- a/lua/config/mappings/lsp.lua +++ /dev/null @@ -1,23 +0,0 @@ -return function(bufnr) - local map = function(from, to) - vim.keymap.set('n', from, to, { noremap = true, silent = true, buffer = bufnr }) - end - - map('gd', vim.lsp.buf.definition) - map('gr', vim.lsp.buf.references) - map('gi', vim.lsp.buf.implementation) - map('gD', vim.lsp.buf.declaration) - - map('K', vim.lsp.buf.hover) - map('', vim.lsp.buf.signature_help) - - map('wa', vim.lsp.buf.add_workspace_folder) - map('wr', vim.lsp.buf.remove_workspace_folder) - map('wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end) - map('D', vim.lsp.buf.type_definition) - map('rn', vim.lsp.buf.rename) - map('ca', vim.lsp.buf.code_action) - map('fm', vim.lsp.buf.formatting) -end diff --git a/lua/config/plugins.lua b/lua/config/plugins.lua new file mode 100644 index 0000000..ab4dca8 --- /dev/null +++ b/lua/config/plugins.lua @@ -0,0 +1,124 @@ +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 + PACKER_BOOTSTRAP = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) + vim.cmd [[packadd packer.nvim]] +end + +local packer = require('packer') +packer.startup(function(use) + use 'wbthomason/packer.nvim' + + -- files + use { + 'nvim-telescope/telescope.nvim', + tag = '0.1.0', + requires = { 'nvim-lua/plenary.nvim' }, + config = function() require 'config.plugins.telescope' end + } + use { + 'nvim-telescope/telescope-fzf-native.nvim', + run = 'make', + requires = { 'nvim-telescope/telescope.nvim' }, + -- doesn't work? + -- config = function() require 'telescope'.load_extension('fzf') end + } + use { + 'nvim-telescope/telescope-ui-select.nvim', + requires = { 'nvim-telescope/telescope.nvim' }, + config = function() require 'telescope'.load_extension('ui-select') end + } + use { + 'nvim-neo-tree/neo-tree.nvim', + branch = "v2.x", + requires = { + 'nvim-lua/plenary.nvim', + 'kyazdani42/nvim-web-devicons', + 'MunifTanjim/nui.nvim' + }, + config = function() require 'config.plugins.neotree' end + } + + -- syntax highlighting + use { + 'nvim-treesitter/nvim-treesitter', + run = function() + require('nvim-treesitter.install').update { with_sync = true } + end, + config = function() + require 'nvim-treesitter.configs'.setup { + highlight = { enable = true } + } + end, + } + + -- autocomplete + use 'hrsh7th/cmp-nvim-lsp' + use 'hrsh7th/cmp-buffer' + use 'hrsh7th/cmp-path' + use 'hrsh7th/cmp-cmdline' + use { + 'hrsh7th/nvim-cmp', + config = function() + require 'config.plugins.cmp' + end + } + + -- snippets + use 'L3MON4D3/LuaSnip' + use 'saadparwaiz1/cmp_luasnip' + + -- autopairs + use { + 'windwp/nvim-autopairs', + config = function() require 'nvim-autopairs'.setup {} end + } + + -- lsp + use { + 'neovim/nvim-lspconfig', + config = function() + require 'config.plugins.lspconfig' + end + } + use { + 'simrat39/rust-tools.nvim', + requires = { + 'nvim-lua/plenary.nvim', + 'mfussenegger/nvim-dap', + } + } + use 'tjdevries/nlua.nvim' + + -- visual + use { + 'navarasu/onedark.nvim', + config = function() + require 'onedark'.setup { style = 'darker' } + require 'onedark'.load() + end + } + use { + 'norcalli/nvim-colorizer.lua', + config = function() + if vim.o.termguicolors then + require 'colorizer'.setup() + end + end + } + use { + 'nvim-lualine/lualine.nvim', + requires = { 'kyazdani42/nvim-web-devicons', opt = true }, + config = function() require 'lualine'.setup() end + } + use { + 'lewis6991/gitsigns.nvim', + config = function() require 'gitsigns'.setup() end + } + + -- sync if bootstrapped + if PACKER_BOOTSTRAP then + require('packer').sync() + end +end) diff --git a/lua/config/plugins/cmp.lua b/lua/config/plugins/cmp.lua new file mode 100644 index 0000000..0b475c9 --- /dev/null +++ b/lua/config/plugins/cmp.lua @@ -0,0 +1,22 @@ +local cmp = require 'cmp' +cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.select_next_item(), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + }), +}) + diff --git a/lua/config/plugins/config.lua b/lua/config/plugins/config.lua deleted file mode 100644 index 284cff3..0000000 --- a/lua/config/plugins/config.lua +++ /dev/null @@ -1,43 +0,0 @@ -require 'telescope'.load_extension('ui-select') - -vim.cmd([[ let g:neo_tree_remove_legacy_commands = 1 ]]) -require 'neo-tree'.setup { - filesystem = { - filtered_items = { - visible = true, - } - }, - window = { - width = 30, - }, -} - -require 'nvim-treesitter.configs'.setup { - highlight = { enable = true } -} - -require 'lualine'.setup() - -local cmp = require 'cmp' -cmp.setup({ - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end - }, - mapping = require 'config.mappings.cmp' (cmp), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'path' }, - }), -}) - -require 'nvim-autopairs'.setup {} - -if vim.o.termguicolors then - require 'colorizer'.setup() -end - -require('gitsigns').setup() - diff --git a/lua/config/plugins/init.lua b/lua/config/plugins/init.lua deleted file mode 100644 index 16ff752..0000000 --- a/lua/config/plugins/init.lua +++ /dev/null @@ -1,4 +0,0 @@ -require 'config.plugins.plugins' -require 'config.plugins.config' -require 'config.plugins.lsps' - diff --git a/lua/config/plugins/lspconfig.lua b/lua/config/plugins/lspconfig.lua new file mode 100644 index 0000000..8e4b050 --- /dev/null +++ b/lua/config/plugins/lspconfig.lua @@ -0,0 +1,63 @@ +local u = require 'config.utils' + +u.nmap('E', vim.diagnostic.open_float) +u.nmap('[d', vim.diagnostic.goto_prev) +u.nmap(']d', vim.diagnostic.goto_next) +u.nmap('q', vim.diagnostic.setloclist) + +local on_attach = function(_, bufnr) + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + vim.o.signcolumn = 'yes' + + local map = function(from, to) + vim.keymap.set('n', from, to, { noremap = true, silent = true, buffer = bufnr }) + end + + map('gd', vim.lsp.buf.definition) + map('gr', vim.lsp.buf.references) + map('gi', vim.lsp.buf.implementation) + map('gD', vim.lsp.buf.declaration) + + map('K', vim.lsp.buf.hover) + map('', vim.lsp.buf.signature_help) + + map('wa', vim.lsp.buf.add_workspace_folder) + map('wr', vim.lsp.buf.remove_workspace_folder) + map('wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end) + map('D', vim.lsp.buf.type_definition) + map('rn', vim.lsp.buf.rename) + map('ca', vim.lsp.buf.code_action) + map('fm', vim.lsp.buf.formatting) +end + +local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + +require 'lspconfig'.sumneko_lua.setup { + on_attach = on_attach, + capabilities = capabilities, + settings = { + Lua = { + diagnostics = { + globals = { 'vim' }, + }, + }, + }, +} + +require 'rust-tools'.setup { + server = { + on_attach = on_attach, + capabilities = capabilities, + } +} + +vim.g.markdown_fenced_languages = { + "ts=typescript" +} +require'lspconfig'.denols.setup{ + on_attach = on_attach, + capabilities = capabilities, +} + diff --git a/lua/config/plugins/lsps.lua b/lua/config/plugins/lsps.lua deleted file mode 100644 index e074847..0000000 --- a/lua/config/plugins/lsps.lua +++ /dev/null @@ -1,35 +0,0 @@ -local on_attach = function(_, bufnr) - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - vim.o.signcolumn = 'yes' - require 'config.mappings.lsp' (bufnr) -end - -local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) - -require 'lspconfig'.sumneko_lua.setup { - on_attach = on_attach, - capabilities = capabilities, - settings = { - Lua = { - diagnostics = { - globals = { 'vim' }, - }, - }, - }, -} - -require 'rust-tools'.setup { - server = { - on_attach = on_attach, - capabilities = capabilities, - } -} - -vim.g.markdown_fenced_languages = { - "ts=typescript" -} -require'lspconfig'.denols.setup{ - on_attach = on_attach, - capabilities = capabilities, -} - diff --git a/lua/config/plugins/neotree.lua b/lua/config/plugins/neotree.lua new file mode 100644 index 0000000..e1728f5 --- /dev/null +++ b/lua/config/plugins/neotree.lua @@ -0,0 +1,14 @@ +local u = require 'config.utils' + +vim.cmd [[ let g:neo_tree_remove_legacy_commands = 1 ]] +require 'neo-tree'.setup { + filesystem = { + filtered_items = { + visible = true, + } + }, + window = { + width = 30, + }, +} +u.nmap('e', u.cmd('Neotree toggle')) diff --git a/lua/config/plugins/plugins.lua b/lua/config/plugins/plugins.lua deleted file mode 100644 index 01f2bb1..0000000 --- a/lua/config/plugins/plugins.lua +++ /dev/null @@ -1,38 +0,0 @@ -local packer = require('packer') -packer.startup(function(use) - use 'wbthomason/packer.nvim' - -- files - use 'nvim-lua/plenary.nvim' - use { 'nvim-telescope/telescope.nvim', tag = '0.1.0' } - use { - 'nvim-telescope/telescope-fzf-native.nvim', - run = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' - } - use 'nvim-telescope/telescope-ui-select.nvim' - use { 'nvim-neo-tree/neo-tree.nvim', branch = "v2.x", } - use 'MunifTanjim/nui.nvim' - -- syntax highlighting - use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' } - -- autocomplete / snippits - use 'hrsh7th/cmp-nvim-lsp' - use 'hrsh7th/cmp-buffer' - use 'hrsh7th/cmp-path' - use 'hrsh7th/cmp-cmdline' - use 'hrsh7th/nvim-cmp' - use 'L3MON4D3/LuaSnip' - use 'saadparwaiz1/cmp_luasnip' - -- auto pairs - use 'windwp/nvim-autopairs' - -- lsp - use 'neovim/nvim-lspconfig' - use 'simrat39/rust-tools.nvim' - use 'mfussenegger/nvim-dap' - use 'nvim-lua/completion-nvim' - use 'tjdevries/nlua.nvim' - -- visual - use 'kyazdani42/nvim-web-devicons' - use 'navarasu/onedark.nvim' - use 'norcalli/nvim-colorizer.lua' - use 'nvim-lualine/lualine.nvim' - use 'lewis6991/gitsigns.nvim' -end) diff --git a/lua/config/plugins/telescope.lua b/lua/config/plugins/telescope.lua new file mode 100644 index 0000000..7c5fc00 --- /dev/null +++ b/lua/config/plugins/telescope.lua @@ -0,0 +1,9 @@ +local u = require 'config.utils' + +require 'telescope'.setup {} + +u.nmap('ff', u.cmd('Telescope find_files')) +u.nmap('fg', u.cmd('Telescope live_grep')) +u.nmap('fb', u.cmd('Telescope buffers')) +u.nmap('fh', u.cmd('Telescope help_tags')) + diff --git a/lua/config/reload.lua b/lua/config/reload.lua index 428a18d..40e6c47 100644 --- a/lua/config/reload.lua +++ b/lua/config/reload.lua @@ -3,18 +3,17 @@ local group = vim.api.nvim_create_augroup("reload", {}) local post_write = function(path, cmd) vim.api.nvim_create_autocmd("BufWritePost", { group = group, - pattern = "**/lua/bryan/" .. path, + pattern = "**/lua/config/" .. path, command = cmd, }) end for _, path in ipairs({ - "general.lua", - "theme.lua", - "mappings/*.lua", - "neovide.lua", + "reload.lua", + "settings.lua", + "utils.lua" }) do post_write(path, "source ") end -- allows you to install and clean plugins after writing to the file -post_write("plugins/plugins.lua", "source | PackerCompile") +post_write("plugins.lua", "source | PackerCompile") diff --git a/lua/config/settings.lua b/lua/config/settings.lua new file mode 100644 index 0000000..89c232f --- /dev/null +++ b/lua/config/settings.lua @@ -0,0 +1,67 @@ +local u = require 'config.utils' +local o = vim.o + +-- basic stuff +o.number = true +vim.cmd('filetype plugin on') +vim.cmd('syntax on') +o.cmdheight = 2 +vim.g.mapleader = ' ' + +-- line break (wrapping) settings +o.linebreak = true +o.breakindent = true +o.showbreak = '\\ ' + +-- lines after end of file empty instead of ~ (fillchars) +o.fcs = 'eob: ' + +-- tab +o.expandtab = true +o.softtabstop = 4 +o.shiftwidth = 4 + +-- turn of gui colors if in tty +if os.getenv('TERM') ~= 'linux' then + o.termguicolors = true +else + o.termguicolors = false +end + +-- highlight extra white space with red +vim.api.nvim_set_hl(0, 'TrailingWhitespace', { ctermbg = 'red', bg = '#ff5555' }) +vim.cmd([[match TrailingWhitespace /\s\+$/]]) + +-- diagnostics +local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) +end + +vim.diagnostic.config({ + virtual_text = { prefix = '●' }; +}) + +-- terminal +u.map('t', '', '') +u.nmap('tm', 'belowright 7sp:termA') + +-- off search highlight when escape is pressed +u.nmap('', 'noh') + +-- colemak +local l = u.layout +l.swap('n', 'h') +l.swap('e', 'j') +l.swap('i', 'k') +l.swap('o', 'l') + +l.swap('n', 'h') +l.swap('e', 'j') +l.swap('i', 'k') +l.swap('o', 'l') + +l.swap('N', 'H') +l.swap('O', 'L') + diff --git a/lua/config/theme.lua b/lua/config/theme.lua deleted file mode 100644 index 87d5869..0000000 --- a/lua/config/theme.lua +++ /dev/null @@ -1,19 +0,0 @@ --- color scheme -vim.g.onedark_config = { style = 'darker' } -vim.cmd('colorscheme onedark') - --- highlight extra white space with red -vim.api.nvim_set_hl(0, 'TrailingWhitespace', { ctermbg = 'red', bg = '#ff5555' }) -vim.cmd([[match TrailingWhitespace /\s\+$/]]) - --- diagnostics -local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } -for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) -end - -vim.diagnostic.config({ - virtual_text = { prefix = '●' }; -}) - diff --git a/lua/config/utils.lua b/lua/config/utils.lua new file mode 100644 index 0000000..edeefa7 --- /dev/null +++ b/lua/config/utils.lua @@ -0,0 +1,20 @@ +local opts = { noremap = true, silent = true } + +local utils = {} +utils.map = function(mode, from, to) vim.keymap.set(mode, from, to, opts) end +utils.nmap = function(from, to) vim.keymap.set('n', from, to, opts) end +utils.cmd = function(content) return '' .. content .. '' end + +local layout = {} +layout.map = function(from, to) + vim.keymap.set('n', from, to, opts) + vim.keymap.set('x', from, to, opts) +end +layout.swap = function(a, b) + utils.layout.map(a, b) + utils.layout.map(b, a) +end +utils.layout = layout + +return utils +