diff --git a/config/neovim/README.md b/config/neovim/README.md new file mode 100644 index 0000000..24e1da7 --- /dev/null +++ b/config/neovim/README.md @@ -0,0 +1,13 @@ +# Neovim Config + +Backup from live config to this folder: + +```bash +cp ~/.config/nvim/{init.lua,lazy-lock.json} config/neovim/ +``` + +Restore from this folder to live config: + +```bash +cp config/neovim/{init.lua,lazy-lock.json} ~/.config/nvim/ +``` diff --git a/config/neovim/init.lua b/config/neovim/init.lua new file mode 100644 index 0000000..6e541b5 --- /dev/null +++ b/config/neovim/init.lua @@ -0,0 +1,181 @@ +-- INSTALL LAZY.NVIM (if not bootstrapping automatically): +-- git clone --filter=blob:none https://github.com/folke/lazy.nvim.git --branch=stable \ +-- ~/.local/share/nvim/lazy/lazy.nvim + +-- NOTE: if vscode-neovim is active, exit early for stock behavior. +if vim.g.vscode then + return +end + +-- aliases +local o = vim.o +local c = vim.cmd +local map = vim.api.nvim_set_keymap + +-- leader keys +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +-- options +o.termguicolors = true +o.mouse = 'a' +o.smartindent = true +o.wrap = false +o.relativenumber = true +o.tabstop = 4 +o.shiftwidth = 4 +o.expandtab = true + +-- Prefer LSP semantic tokens over treesitter captures when both exist. +vim.hl.priorities.semantic_tokens = 140 +vim.hl.priorities.treesitter = 100 + +-- ensure .svelte files are detected correctly +vim.filetype.add({ + extension = { + svelte = 'svelte', + }, +}) + +-- set wrap if markdown file +vim.cmd('autocmd FileType markdown setlocal wrap') + +-- keybinds +map('n', '', ':NvimTreeToggle', { silent = true }) + +map('n', '', ':ToggleTerm direction="float"', { silent = true }) +map('t', '', ':ToggleTerm', { silent = true }) + +map('n', 'gs', ':Telescope git_status', { silent = true }) +map('n', 'gc', ':Telescope git_commits', { silent = true }) +map('n', ':', ':Telescope commands', { silent = true }) +map('n', '', ':Telescope find_files', { silent = true }) +map('n', 'f', ':Telescope grep_string', { silent = true }) +map('n', 'e', 'lua vim.diagnostic.open_float()', { silent = true }) + +map('n', '', ':GitGutterPrevHunk', { silent = true }) +map('n', '', ':GitGutterNextHunk', { silent = true }) + +-- buffer management +map('n', '', ':bp', { silent = true }) +map('n', '', ':bn', { silent = true }) + +-- lazy.nvim bootstrap +local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + 'git', + 'clone', + '--filter=blob:none', + 'https://github.com/folke/lazy.nvim.git', + '--branch=stable', + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +require('lazy').setup({ + { + 'Mofiqul/vscode.nvim', + name = 'vscode', + priority = 1000, + lazy = false, + config = function() + require('vscode').setup({ + transparent = true, + }) + end, + }, + { 'airblade/vim-gitgutter' }, + { + 'nvim-lualine/lualine.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function() + require('lualine').setup({ + options = { + theme = 'vscode', + globalstatus = true, + }, + }) + end, + }, + { + 'nvim-treesitter/nvim-treesitter', + build = ':TSUpdate', + config = function() + local treesitter = require('nvim-treesitter') + local wanted = { 'svelte', 'javascript', 'typescript', 'html', 'css' } + treesitter.setup({}) + + vim.api.nvim_create_autocmd('FileType', { + pattern = wanted, + callback = function() + pcall(vim.treesitter.start) + end, + }) + end, + }, + { + 'neovim/nvim-lspconfig', + config = function() + local capabilities = require('cmp_nvim_lsp').default_capabilities() + + vim.lsp.config('pyright', { capabilities = capabilities }) + vim.lsp.config('ts_ls', { capabilities = capabilities }) + vim.lsp.config('svelte', { capabilities = capabilities }) + vim.lsp.config('rust_analyzer', { capabilities = capabilities }) + + vim.lsp.enable('pyright') + vim.lsp.enable('ts_ls') + vim.lsp.enable('svelte') + vim.lsp.enable('rust_analyzer') + + vim.api.nvim_create_autocmd('LspAttach', { + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + if client and client.server_capabilities.semanticTokensProvider then + vim.lsp.semantic_tokens.start(args.buf, client.id) + end + end, + }) + end, + }, + { 'hrsh7th/cmp-nvim-lsp' }, + { + 'hrsh7th/nvim-cmp', + dependencies = { 'hrsh7th/cmp-nvim-lsp' }, + config = function() + local cmp = require('cmp') + cmp.setup({ + sources = { + { name = 'nvim_lsp' }, + }, + }) + end, + }, + { + 'nvim-tree/nvim-tree.lua', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function() + require('nvim-tree').setup({ view = { width = 42 } }) + end, + }, + { + 'nvim-telescope/telescope.nvim', + dependencies = { 'nvim-lua/plenary.nvim' }, + }, + { + 'akinsho/toggleterm.nvim', + version = '*', + config = function() + require('toggleterm').setup() + end, + }, +}) + +-- NOTE: pcall prevents plugin system errors on first load +if not pcall(function() + c.colorscheme('vscode') +end) then + print('Failed to load colorscheme - probably has not been installed') +end diff --git a/config/neovim/lazy-lock.json b/config/neovim/lazy-lock.json new file mode 100644 index 0000000..10caca1 --- /dev/null +++ b/config/neovim/lazy-lock.json @@ -0,0 +1,15 @@ +{ + "cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" }, + "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, + "lualine.nvim": { "branch": "master", "commit": "47f91c416daef12db467145e16bed5bbfe00add8" }, + "nvim-cmp": { "branch": "main", "commit": "da88697d7f45d16852c6b2769dc52387d1ddc45f" }, + "nvim-lspconfig": { "branch": "master", "commit": "44acfe887d4056f704ccc4f17513ed41c9e2b2e6" }, + "nvim-tree.lua": { "branch": "master", "commit": "e11ce83ed9a00f065bf676ae4e6c261c766989ba" }, + "nvim-treesitter": { "branch": "main", "commit": "3edb01f912867603c2aef9079f208f0244c0885b" }, + "nvim-web-devicons": { "branch": "master", "commit": "746ffbb17975ebd6c40142362eee1b0249969c5c" }, + "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "telescope.nvim": { "branch": "master", "commit": "5255aa27c422de944791318024167ad5d40aad20" }, + "toggleterm.nvim": { "branch": "main", "commit": "50ea089fc548917cc3cc16b46a8211833b9e3c7c" }, + "vim-gitgutter": { "branch": "main", "commit": "0acb772e76064cc406664ab595b58b3fac76488a" }, + "vscode": { "branch": "main", "commit": "aa1102a7e15195c9cca22730b09224a7f7745ba8" } +} diff --git a/config/neovim/macos/init.lua b/config/neovim/macos/init.lua deleted file mode 100644 index 689a4ad..0000000 --- a/config/neovim/macos/init.lua +++ /dev/null @@ -1,134 +0,0 @@ --- INSTALL PACKER: --- git clone --depth 1 https://github.com/wbthomason/packer.nvim\ --- ~/.local/share/nvim/site/pack/packer/start/packer.nvim - --- check for vscode nvim plugin --- (https://github.com/vscode-neovim/vscode-neovim) -if vim.g.vscode then - do return end -else - if vim.g.neovide then - vim.o.guifont = "CaskaydiaCove Nerd Font:h14" - vim.g.neovide_hide_mouse_when_typing = true - end -end - --- aliases - -local o = vim.o -local c = vim.cmd -local map = vim.api.nvim_set_keymap - --- options - -o.termguicolors = true -o.mouse = 'a' --- o.autoindent = true -o.smartindent = true -- replacing autoindent with this -o.wrap = false -o.nobinary = true -o.relativenumber = true -o.tabstop = 4 -o.shiftwidth = 4 -o.expandtab = true - --- set wrap if markdown file -vim.cmd('autocmd FileType markdown setlocal wrap') - --- NOTE: pcall prevents plugin system from shitting itself on first load -if not pcall(function() - -- c.colorscheme 'catppuccin' - c.colorscheme "vscode" -end) then - print("Failed to load colorscheme - probably has not been installed") -end - --- keybinds - --- file management --- map('n', '', ':CHADopen', {silent = true}) -map('n', '', ':NvimTreeToggle', {silent = true}) - -map('n', '', ':ToggleTerm direction="float"', {silent = true}) --- exit terminal requires prefix -map('t', '', ':ToggleTerm', {silent = true}) - -map('n', 'gs', ':Telescope git_status', {silent = true}) -map('n', 'gc', ':Telescope git_commits', {silent = true}) -map('n', ':', ':Telescope commands', {silent = true}) -map('n', '', ':Telescope find_files', {silent = true}) -map('n', 'f', ':Telescope grep_string', {silent = true}) - --- buffer management -map('n', '', ':bp', {silent = true}) -map('n', '', ':bn', {silent = true}) - --- plugin configs - -vim.g['airline_powerline_fonts'] = 1 -vim.g['airline_theme'] = 'powerlineish' -vim.g['airline#extensions#tabline#enabled'] = 1 -vim.g['airline#extensions#tabline#fnamemod'] = ':t' - --- plugin imports - -return require('packer').startup(function(use) - - -- Packer can manage itself - use 'wbthomason/packer.nvim' - - -- Visual - use 'vim-airline/vim-airline' - use 'vim-airline/vim-airline-themes' - use { "catppuccin/nvim", as = "catppuccin" } - use 'airblade/vim-gitgutter' - - -- Editor - use {'neovim/nvim-lspconfig', config = function() - local lspc = require('lspconfig') - -- lspc['pyright'].setup{} - -- lspc['tsserver'].setup{} - -- lspc['clojure_lsp'].setup{} - -- lspc['racket_langserver'].setup{} - -- lspc['rust_analyzer'].setup{} - -- lspc['gopls'].setup{} - end} - use 'hrsh7th/cmp-nvim-lsp' - use {'hrsh7th/nvim-cmp', config = function() - local cmp = require 'cmp' - cmp.setup { - sources = { - { name = 'nvim_lsp' }, - } - } - end} - - use {"nvim-tree/nvim-tree.lua"} - use {"nvim-tree/nvim-web-devicons"} - require("nvim-tree").setup() - - use 'nvim-lua/plenary.nvim' - use 'nvim-telescope/telescope.nvim' - use {"akinsho/toggleterm.nvim", tag = '*'} - require("toggleterm").setup() - use {'nvim-treesitter/nvim-treesitter', run = ':TSUpdate', config = function() - require'nvim-treesitter.configs'.setup{ - highlight = {enable = true} - } - end} - - -- vscode theme - use 'Mofiqul/vscode.nvim' - - -- NOTE: requires Node.js >= 17 - -- use {'github/copilot.vim', run = ':Copilot setup'} - - - -- Specify Filetype for .python Files - -- vim.api.nvim_exec([[ - -- autocmd BufNewFile,BufRead *.sage set filetype=python - -- ]], false) - -end) - -