diff --git a/init.lua b/init.lua index 44471a68..7f4fbae3 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,7 @@ +-- Load leaders before any plugins +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + require("config.options") require("config.keymaps") require("config.autocmds") diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua index a89f7e3b..e5233a96 100644 --- a/lua/config/autocmds.lua +++ b/lua/config/autocmds.lua @@ -5,4 +5,4 @@ vim.api.nvim_create_autocmd('TextYankPost', { callback = function() vim.hl.on_yank() end, -}) \ No newline at end of file +}) diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index a003f6ae..bc26802c 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -4,9 +4,6 @@ map('i', 'jk', '', { desc = 'Exit insert mode' }) -- Clear highlights on search when pressing in normal mode -- See `:help hlsearch` map('n', '', 'nohlsearch') -map('n', 'z', function() - print("hey") -end, { desc = "Print hey" }) -- Keybinds to make split navigation easier. -- Use CTRL+ to switch between windows @@ -18,5 +15,13 @@ map('n', '', '', { desc = 'Move focus to the upper window' }) -- open Oil map("n", "-", "Oil", { desc = "Open parent directory" } ) + -- Change current dir map("n", "cc", "cd %:p:h", { desc = "Change current dir to a current buffer" }) + +map("n", "vt", function() + vim.cmd.new() + vim.cmd.term() + vim.cmd.wincmd("J") + vim.api.nvim_win_set_height(0, 15) +end) diff --git a/lua/config/options.lua b/lua/config/options.lua index 665d86f8..9a9b308e 100644 --- a/lua/config/options.lua +++ b/lua/config/options.lua @@ -1,7 +1,6 @@ -vim.g.mapleader = ' ' -vim.g.maplocalleader = ' ' + vim.g.have_nerd_font = true -vim.opt.guifont='FiraCode Nerd Font' + -- Make line numbers default vim.opt.number = true @@ -55,3 +54,4 @@ vim.opt.tabstop = 2 vim.opt.shiftwidth = 2 vim.opt.virtualedit = "block" +vim.opt.shell = "powershell.exe" diff --git a/lua/plugins/lazydev.lua b/lua/plugins/lazydev.lua new file mode 100644 index 00000000..4e3410ae --- /dev/null +++ b/lua/plugins/lazydev.lua @@ -0,0 +1,9 @@ +return { -- Let lsp recognize vim functions + "folke/lazydev.nvim", + ft = "lua", -- only load on lua files + opts = { + library = { + { path = "${3rd}/luv/library", words = { "vim%.uv" } }, + }, + }, + } diff --git a/lua/plugins/lsp-config.lua b/lua/plugins/lsp-config.lua new file mode 100644 index 00000000..4ad885ab --- /dev/null +++ b/lua/plugins/lsp-config.lua @@ -0,0 +1,83 @@ +return { + -- Main LSP Configuration + 'neovim/nvim-lspconfig', + dependencies = { + -- Automatically install LSPs and related tools to stdpath for Neovim + -- Mason must be loaded before its dependents so we need to set it up here. + -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})` + { 'mason-org/mason.nvim', opts = {} }, + 'mason-org/mason-lspconfig.nvim', + 'WhoIsSethDaniel/mason-tool-installer.nvim', + + -- Useful status updates for LSP. + { 'j-hui/fidget.nvim', opts = {} }, + + -- Allows extra capabilities provided by blink.cmp + 'saghen/blink.cmp', + }, + config = function() + + -- Autocommand to define keymaps when a buffer attaches to lsp server + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), + callback = function(event) + local map = function(keys, func, desc, mode) + mode = mode or 'n' + vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) + end + + -- Rename the variable under your cursor. + map('grn', vim.lsp.buf.rename, '[R]e[n]ame') + + -- Find references for the word under your cursor. + map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + + -- Jump to the implementation of the word under your cursor. + map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + + -- WARN: This is not Goto Definition, this is Goto Declaration. + -- For example, in C this would take you to the header. + map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + + -- Fuzzy find all the symbols in your current document. + -- Symbols are things like variables, functions, types, etc. + map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols') + + -- Fuzzy find all the symbols in your current workspace. + -- Similar to document symbols, except searches over your entire project. + map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols') + + -- Jump to the type of the word under your cursor. + -- Useful when you're not sure what type a variable is and you want to see + map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definiton') + + -- predefine client supports method + -- leaving it here in case I want to use it + ---@param client vim.lsp.Client + ---@param method vim.lsp.protocol.Method + ---@param bufnr? integer some lsp support methods only in specific files + ---@return boolean + local function client_supports_method(client, method, bufnr) + return client:supports_method(method, bufnr) + end + end, + }) + + -- Diagnostic Options + vim.diagnostic.config { + severity_sort = true, + float = { border = 'rounded', source = 'if_many' }, + underline = { severity = vim.diagnostic.severity.ERROR }, + } + + require('mason-tool-installer').setup { + ensure_installed = { + 'lua-language-server', + 'python-lsp-server', + 'stylua', + } + } + + require("mason-lspconfig").setup() + end +} diff --git a/lua/plugins/plugins.lua b/lua/plugins/plugins.lua index 2beec7f2..2ac434b1 100644 --- a/lua/plugins/plugins.lua +++ b/lua/plugins/plugins.lua @@ -10,58 +10,34 @@ return { end, }, - { - 'nvim-treesitter/nvim-treesitter', - build = ':TSUpdate', - main = 'nvim-treesitter.configs', -- Sets main module to use for opts - opts = { - ensure_installed = { 'c', 'lua', 'vim', 'vimdoc', 'query', 'python' }, - -- Autoinstall languages that are not installed - auto_install = true, - highlight = { - enable = true - }, - indent = { enable = true, disable = { 'ruby' } }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = 'gnn', - node_incremental = 'grn', - scope_incremental = 'grc', - node_decremental = 'grm', - }, - }, - }, - }, --- { -- Leave it here in case we want to configure LSP directly --- "neovim/nvim-lspconfig", --- config = function() --- -- Configure the Pyright language server for Python --- vim.lsp.config('pyright', { --- cmd = { "pyright-langserver", "--stdio" }, --- filetypes = { "python" }, --- }) --- -- Enable the LSP server for Python files --- vim.lsp.enable('pyright') --- end, --- } + { + 'nvim-treesitter/nvim-treesitter', + build = ':TSUpdate', + main = 'nvim-treesitter.configs', -- Sets main module to use for opts + opts = { + ensure_installed = { 'c', 'lua', 'vim', 'vimdoc', 'query', 'python' }, + -- Autoinstall languages that are not installed + auto_install = true, + highlight = { + enable = true + }, + indent = { enable = true, disable = { 'ruby' } }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = 'gnn', + node_incremental = 'grn', + scope_incremental = 'grc', + node_decremental = 'grm', + }, + }, + }, + }, - { - -- handle LSP server installation and management - -- let's be lazy for now. - "mason-org/mason.nvim", - dependencies = { - "mason-org/mason-lspconfig.nvim", - "neovim/nvim-lspconfig", - }, - config = function() - require("mason").setup() - require("mason-lspconfig").setup() - end, - }, { -- Auto completion engine 'saghen/blink.cmp', + event = 'VimEnter', -- Loads the plugin when nvim finishes starting up. dependencies = { 'rafamadriz/friendly-snippets' }, version = '1.*', opts = { @@ -78,16 +54,6 @@ return { opts_extend = { "sources.default" }, }, - { -- Let lsp recognize vim functions - "folke/lazydev.nvim", - ft = "lua", -- only load on lua files - opts = { - library = { - { path = "${3rd}/luv/library", words = { "vim%.uv" } }, - }, - }, - }, - { "echasnovski/mini.nvim", @@ -106,6 +72,7 @@ return { { "stevearc/oil.nvim", + event = 'VimEnter', -- Loads the plugin when nvim finishes starting up. lazy = false, dependencies = { "nvim-tree/nvim-web-devicons" }, config = function () diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 890bdd7b..c1d5c734 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -1,7 +1,12 @@ return { - 'nvim-telescope/telescope.nvim', tag = '0.1.8', + 'nvim-telescope/telescope.nvim', + tag = '0.1.8', dependencies = { + { 'nvim-lua/plenary.nvim' }, + + { 'nvim-telescope/telescope-ui-select.nvim' }, + { 'nvim-telescope/telescope-fzf-native.nvim', -- `build` is used to run some command when the plugin is installed/updated. @@ -12,10 +17,21 @@ return { return vim.fn.executable 'make' == 1 end, }, - { 'nvim-telescope/telescope-ui-select.nvim' }, + }, config = function() - require('telescope').setup({}) + require('telescope').setup({ + extensions = { + ['ui-select'] = { + require('telescope.themes').get_dropdown(), + }, + }, + }) + + -- pcall is like try in python + pcall(require('telescope').load_extension, 'fzf') + pcall(require('telescope').load_extension, 'ui-select') + local keymap = vim.keymap.set local builtin = require 'telescope.builtin' keymap('n', 'fh', builtin.help_tags, { desc = '[F]ind [H]elp' }) diff --git a/sample.py b/sample.py index c96fdc65..b347af8b 100644 --- a/sample.py +++ b/sample.py @@ -1,24 +1,29 @@ json = { - 'a' : 1, - "b" : 2, - "c" : 3, - "d" : 4, + 'a': 1, + "b": 2, + "c": 3, + "d": 4, } print("file name sample.py") -def sample_func(): + + +def sample_fun(): print(123) + print() + + #################################################### -print("hello, worldworld") + print("hello, world, ") print() print("hello, world, ") print("hello, world, ") json = { - "a" : 1, - "b" : 2, - "c" : 3, - "d" : 4, + "a": 1, + "b": 2, + "c": 3, + "d": 4, } print("file name sample.py") if True: @@ -29,10 +34,10 @@ if True: #################################################### json = { - "a" : 1, - "b" : 2, - "c" : 3, - "d" : 4, + "a": 1, + "b": 2, + "c": 3, + "d": 4, } print("file name sample.py") if True: