From 367836c01323c22cd3fa07bc88f5195014a2cf52 Mon Sep 17 00:00:00 2001 From: phajw Date: Wed, 4 Oct 2023 06:04:43 -0400 Subject: Move from github --- .gitignore | 1 + README.md | 66 ++++++++++++++++++++++++ init.lua | 17 ++++++ lua/config/editor.lua | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++ lua/config/lsp.lua | 78 ++++++++++++++++++++++++++++ lua/config/packer.lua | 61 ++++++++++++++++++++++ 6 files changed, 363 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 init.lua create mode 100644 lua/config/editor.lua create mode 100644 lua/config/lsp.lua create mode 100644 lua/config/packer.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7ad043 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +plugin/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..08b4293 --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# My Neovim Config +![nvim](https://user-images.githubusercontent.com/91333841/212791030-440472c6-1568-4754-9181-c47e69bc42d6.png) + +### Introduction +Run checkhealth in your Neovim +```vim +:checkhealth +``` +Make sure you analyzed the output properly: +- Your neovim must be >= 0.7.0 to run this config +- You need to setup [Packer](https://github.com/wbthomason/packer.nvim) +```vim +git clone --depth 1 https://github.com/wbthomason/packer.nvim\ + ~/.local/share/nvim/site/pack/packer/start/packer.nvim +``` +- You should install global python provider +```python +pip install pynvim +``` +- You should install clipboard tool (I use xclip but you can use something diffrent) + +### Installation +> Easy way + +You can just clone this repo to your .config folder + +```bash +git clone https://github.com/dsrcr/nvim ~/.config +``` +> Recommended way + +I use gnu-stow to manage my dotfiles, so I encourage you to use it too. + +Use your package manage of choice to get stow, for example: + +```bash +paru -S stow +``` +Clone this repo to your prefered dir and use stow to symlink + +In order to do this you need an empty nvim directory in your .config folder +```bash +cd ~/.config +mkdir nvim +cd ~/yourDirectory +git clone https://github.com/dsrcr/nvim +stow -d ~/yourDirectory -t ~/.config/nvim nvim/ + +``` + +The last step is running this command in your neovim + +```vim +:PackerSync +``` +This command should pull everything you need + +In the next step you will encounter a lot of errors, but don't worry about it. +Packer needs to pull specific plugins and then you need to install Treesitter's support for specific filetypes eg. lua, rust.... etc. +```bash +:TSUpdate +``` +```bash +:TSInstall +``` + diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..6d26278 --- /dev/null +++ b/init.lua @@ -0,0 +1,17 @@ +-- ________ _________ _____ .__ ____ +-- \______ \ / _____/ ____ ____ ____ _/ ____\|__| / ___\ +-- | | \ \_____ \ _/ ___\ / _ \ / \\ __\ | | / /_/ > +-- | ` \ / \\ \___( <_> )| | \| | | | \___ / +-- /_______ //_______ / \___ >\____/ |___| /|__| |__|/_____/ +-- \/ \/ \/ \/ +-- Starting point for my neovim setup +-- https://github.com/dsrcr/nvim + +--Open this file if you want to add new plugins +require("config.packer") + +-- You can find here stuff related to lsp +require("config.lsp") + +-- You can customize editor +require("config.editor") diff --git a/lua/config/editor.lua b/lua/config/editor.lua new file mode 100644 index 0000000..3db21d6 --- /dev/null +++ b/lua/config/editor.lua @@ -0,0 +1,140 @@ +local js_based_languages = { "typescript", "javascript", "typescriptreact", "javascriptreact" } +local option = vim.opt; +local keymap = vim.keymap; + +local dap = require("dap") +local telescope = require('telescope.builtin'); +local autotag = require('nvim-ts-autotag').setup(); +local dap_vscode = require("dap-vscode-js").setup({ + debugger_path = "(runtimedir)/site/pack/packer/opt/vscode-js-debug", + adapters = { 'chrome', 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost', 'node', 'chrome' }, +}) + +--Basic Editor Setup +option.nu = true; +option.tabstop = 2; +option.softtabstop = 2; +option.shiftwidth = 2; +option.expandtab = true; +option.smartindent = true; +option.wrap = false; +option.swapfile = false; +option.hlsearch = false; +option.incsearch = true; +option.updatetime = 50; +option.laststatus = 0; +option.signcolumn = "number"; +option.autoindent = true; +option.clipboard = "unnamedplus"; +option.termguicolors = true; + +-- Setup Editor Theme + vim.cmd.colorscheme("gruvbox") + vim.cmd([[ + highlight GitGutterAdd ctermbg=none + highlight GitGutterAdd guibg=none + highlight Normal ctermbg=none + highlight Normal guibg=none + highlight signcolumn ctermbg=none + highlight signcolumn guibg=none + ]]) + +-- run specific commands after different file extensions +vim.cmd([[ + augroup RunPfOnSave + autocmd! + autocmd BufWritePost *.js,*.ts,*.jsx,*json !prettier --write . + autocmd BufWritePost *.tex :VimtexCompile + autocmd BufWritePost *.md :MarkdownPreview + augroup END +]]) + +-- vim.cmd([[ +-- augroup RunPfOnSave +-- autocmd! +-- augroup END +-- ]]) +-- +-- vim.cmd([[ +-- augroup RunPfOnSave +-- autocmd! +-- autocmd BufWritePost *.tex :VimtexCompile +-- augroup END +--]]) + +-- Gui options +vim.o.guifont = "Fira Code:h7" +vim.g.vimtex_view_method = 'zathura' +vim.g.vimtex_compiler_method = 'latexrun' +vim.g.gitgutter_set_sign_backgrounds = 1; +vim.fn.sign_define('DapBreakpoint',{ text ='🟥', texthl ='', linehl ='', numhl =''}) +vim.fn.sign_define('DapStopped',{ text ='▶️', texthl ='', linehl ='', numhl =''}) + +--Keybinds +vim.g.mapleader = (" ") +keymap.set("n", "e", vim.cmd.Ex) +keymap.set('n', 'f', telescope.find_files, {}) +keymap.set("n", "s", [[:%s/\<\>//gI]]) +keymap.set("n", "a", "ggVG") +keymap.set("v", "J", ":m '>+1gv=gv") +keymap.set("v", "K", ":m '<-2gv=gv") + +-- Debugger keybinds +keymap.set('n', '', require 'dap'.continue) +keymap.set('n', '', require 'dap'.step_over) +keymap.set('n', '', require 'dap'.step_into) +keymap.set('n', '', require 'dap'.step_out) +keymap.set('n', 'b', require 'dap'.toggle_breakpoint) + +keymap.set('n', 'B', function() + require 'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: ')) +end) + +keymap.set('n', 'ui', require 'dapui'.toggle) +for _, language in ipairs(js_based_languages) do + require("dap").configurations[language] = { + { + type = "pwa-node", + request = "launch", + name = "Launch file", + program = "${file}", + cwd = "${workspaceFolder}", + }, + { + type = "pwa-node", + request = "attach", + name = "Attach", + processId = require 'dap.utils'.pick_process, + cwd = "${workspaceFolder}", + }, + { + type = "pwa-chrome", + request = "launch", + name = "Start Chrome with \"localhost\"", + url = "http://localhost:3000", + webRoot = "${workspaceFolder}", + userDataDir = "${workspaceFolder}/.vscode/vscode-chrome-debug-userdatadir" + } + } +end +require("dapui").setup() +local dap, dapui = require("dap"), require("dapui") +dap.listeners.after.event_initialized["dapui_config"] = function() + dapui.open({}) +end +dap.listeners.before.event_terminated["dapui_config"] = function() + dapui.close({}) +end +dap.listeners.before.event_exited["dapui_config"] = function() + dapui.close({}) +end + +--Treesitter +require 'nvim-treesitter.configs'.setup { + ensure_installed = { "javascript", "typescript", "rust", "c", "lua", "vim" }, + sync_install = false, + auto_install = true, + highlight = { + enable = true, + } +} diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua new file mode 100644 index 0000000..623aab3 --- /dev/null +++ b/lua/config/lsp.lua @@ -0,0 +1,78 @@ +-- local lsp = require('lsp-zero') + +local lsp_zero = require('lsp-zero') +local cmp = require('cmp') +require("luasnip.loaders.from_vscode").lazy_load() + +lsp_zero.preset('recommended') +lsp_zero.setup() +lsp_zero.on_attach(function(client, bufnr) + -- see :help lsp-zero-keybindings + -- to learn the available actions + lsp_zero.default_keymaps({buffer = bufnr}) +end) + +require('mason').setup({}) +require('mason-lspconfig').setup({ + -- Replace the language servers listed here + -- with the ones you want to install + ensure_installed = {'tsserver', 'rust_analyzer', 'eslint'}, + handlers = { + lsp_zero.default_setup, + }, +}) + + + +require('tabnine').setup({ + disable_auto_comment=true, + accept_keymap="", + dismiss_keymap = "", + debounce_ms = 800, + suggestion_color = {gui = "#808080", cterm = 244}, + execlude_filetypes = {"TelescopePrompt"} +}) + +cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + window = { + }, + 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 }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, { + { name = 'buffer' }, + }) +}) + +function PrintDiagnostics(opts, bufnr, line_nr, client_id) + bufnr = bufnr or 0 + line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1) + opts = opts or { ['lnum'] = line_nr } + + local line_diagnostics = vim.diagnostic.get(bufnr, opts) + if vim.tbl_isempty(line_diagnostics) then return end + + local diagnostic_message = "" + for i, diagnostic in ipairs(line_diagnostics) do + diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "") + print(diagnostic_message) + if i ~= #line_diagnostics then + diagnostic_message = diagnostic_message .. "\n" + end + end + vim.api.nvim_echo({ { diagnostic_message, "Normal" } }, false, {}) +end + +vim.cmd [[ autocmd! CursorHold * lua PrintDiagnostics() ]] diff --git a/lua/config/packer.lua b/lua/config/packer.lua new file mode 100644 index 0000000..99af8d4 --- /dev/null +++ b/lua/config/packer.lua @@ -0,0 +1,61 @@ +vim.cmd [[packadd packer.nvim]] +return require('packer').startup(function(use) + use 'wbthomason/packer.nvim' + use 'nvim-treesitter/nvim-treesitter' + use 'neovim/nvim-lspconfig' + use 'lukas-reineke/indent-blankline.nvim' + use 'lervag/vimtex' + use 'morhetz/gruvbox' + use 'airblade/vim-gitgutter' + use 'catppuccin/nvim' + use 'jose-elias-alvarez/null-ls.nvim' + use 'windwp/nvim-ts-autotag' + use 'mfussenegger/nvim-dap' + use 'mxsdev/nvim-dap-vscode-js' + use { "rcarriga/nvim-dap-ui", requires = {"mfussenegger/nvim-dap"} } + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.0', + requires = { { 'nvim-lua/plenary.nvim' } } + } + use { + 'VonHeikemen/lsp-zero.nvim', + requires = { + { 'neovim/nvim-lspconfig' }, + { 'williamboman/mason.nvim' }, + { 'williamboman/mason-lspconfig.nvim' }, + { 'hrsh7th/nvim-cmp' }, + { 'hrsh7th/cmp-buffer' }, + { 'hrsh7th/cmp-path' }, + { 'saadparwaiz1/cmp_luasnip' }, + { 'hrsh7th/cmp-nvim-lsp' }, + { 'hrsh7th/cmp-nvim-lua' }, + { 'rafamadriz/friendly-snippets' }, + } + } +use({ + "L3MON4D3/LuaSnip", + -- follow latest release. + tag = "v2.*", -- Replace by the latest released major (first number of latest release) + -- install jsregexp (optional!:). + run = "make install_jsregexp" +}) + use { + 'numToStr/Comment.nvim', + config = function() + require('Comment').setup() + end + } + use({ + "iamcco/markdown-preview.nvim", + run = "cd app && npm install", + setup = function() vim.g.mkdp_filetypes = { "markdown" } end, + ft = { "markdown" }, + }) + use { + "windwp/nvim-autopairs", + config = function() require("nvim-autopairs").setup {} end + } + use { 'codota/tabnine-nvim', run = "./dl_binaries.sh" } + + +end) -- cgit v1.2.3