commit 36f68238e8b976f50c3a95a9da70ddfd5a3fcc29 Author: Prabhat Maurya Date: Wed Jan 15 23:20:30 2025 +0530 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..55a4278 --- /dev/null +++ b/.gitignore @@ -0,0 +1,43 @@ +# Compiled Lua sources +luac.out + +# luarocks build files +*.src.rock +*.zip +*.tar.gz + +# Object files +*.o +*.os +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo +*.def +*.exp + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + + +plugin/packer_compiled.lua \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..d61b8cc --- /dev/null +++ b/init.lua @@ -0,0 +1,101 @@ +-- -- Load user configuration files + require("user.options") + require("user.keymaps") + require("user.cmp") + require("user.java") + require("user.autopairs") + require("user.telescope") + require("user.gruvbox") + require("user.lsp") + require("user.java") + require("user.treesitter") + require("user.null-ls") -- Load null-ls configuration + require("user.terminal") + require("user.markdown") + require("user.autocmds") + require("user.files_utils") + require("user.commands") +require("user.comment") + + return require("packer").startup(function(use) + -- Let packer manage itself + use("wbthomason/packer.nvim") + + -- Completion framework + use("hrsh7th/nvim-cmp") + use("hrsh7th/cmp-buffer") + use("hrsh7th/cmp-path") + use("hrsh7th/cmp-nvim-lsp") + use("hrsh7th/cmp-nvim-lua") + use("saadparwaiz1/cmp_luasnip") + use("L3MON4D3/LuaSnip") + + -- Load test plugin configuration + require("user.test")(use) + + -- NERDTree plugin + use("preservim/nerdtree") + + -- Plugin for integrating formatters/linters + use("jose-elias-alvarez/null-ls.nvim") + + -- -- TS Server + use("jose-elias-alvarez/nvim-lsp-ts-utils") + + -- Treesitter + use("nvim-treesitter/nvim-treesitter") + + -- Auto pairs + use("windwp/nvim-autopairs") + + -- LSP Configuration + use("neovim/nvim-lspconfig") + + -- Java Language Server support + use("mfussenegger/nvim-jdtls") + + -- Markdown Preview (optional) + use({ "iamcco/markdown-preview.nvim", run = "cd app && npm install" }) + + use({ + "nvim-telescope/telescope.nvim", + tag = "0.1.8", + -- or , branch = '0.1.x', + requires = { { "nvim-lua/plenary.nvim" } }, + }) + + -- Comment + use 'numToStr/Comment.nvim' + + + -- Telescope FZF native + use({ + "nvim-telescope/telescope-fzf-native.nvim", + run = "make", + }) + + use({ "ellisonleao/gruvbox.nvim" }) + + use({ + "williamboman/mason.nvim", + config = function() + require("mason").setup() + end, + }) + + -- Mason LSPConfig for integrating Mason with nvim-lspconfig + use({ + "williamboman/mason-lspconfig.nvim", + config = function() + require("mason-lspconfig").setup({ + ensure_installed = { + "pyright", + "ts_ls", + "jdtls", + "marksman", + "kotlin_language_server", + }, + }) + end, + }) +end) diff --git a/jars/google-java-format.jar b/jars/google-java-format.jar new file mode 100644 index 0000000..5c28f14 Binary files /dev/null and b/jars/google-java-format.jar differ diff --git a/lua/user/autocmds.lua b/lua/user/autocmds.lua new file mode 100644 index 0000000..71a8e9a --- /dev/null +++ b/lua/user/autocmds.lua @@ -0,0 +1,20 @@ +-- lua/user/autocmds.lua +-- Configuration for markdown-preview.nvim + +vim.g.mkdp_auto_start = 0 +vim.g.mkdp_auto_close = 1 + +-- Enable formatting on save for multiple file types +vim.api.nvim_create_autocmd({ "BufWritePre" }, { + pattern = "*", -- Apply this to all filetypes + callback = function() + -- save current position + local pos = vim.api.nvim_win_get_cursor(0) + + -- strip trailing whitespace (essentially this strips comments that are at the end of lines) + vim.cmd([[%s/\s\+$//e]]) + + -- restore cursor position + vim.api.nvim_win_set_cursor(0, pos) + end +}) diff --git a/lua/user/autopairs.lua b/lua/user/autopairs.lua new file mode 100644 index 0000000..27b50d5 --- /dev/null +++ b/lua/user/autopairs.lua @@ -0,0 +1,22 @@ +-- lua/user/autopairs.lua +require('nvim-autopairs').setup{ + disable_filetype = { "TelescopePrompt", "vim" }, + check_ts = true, -- Enable Treesitter integration + ts_config = { + lua = { "string" }, -- Disable auto-pairs inside Lua strings + javascript = { "template_string" }, + java = false, -- Disable Treesitter integration for Java + }, + fast_wrap = { + map = '', -- Trigger fast wrap with Alt+e + chars = { '{', '[', '(', '"', "'" }, + pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], '%s+', ''), + offset = 0, -- Offset from pattern match + end_key = '$', + keys = 'qwertyuiopzxcvbnmasdfghjkl', + check_comma = true, + highlight = 'Search', + highlight_grey='Comment' + }, +} + diff --git a/lua/user/cmp.lua b/lua/user/cmp.lua new file mode 100644 index 0000000..386ffbc --- /dev/null +++ b/lua/user/cmp.lua @@ -0,0 +1,48 @@ +-- ~/.config/nvim/lua/user/cmp.lua + +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.confirm({ select = true }), -- Confirm selection with Enter + + -- Tab to navigate forward through completion menu + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif require("luasnip").expand_or_jumpable() then + require("luasnip").expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + + -- Shift-Tab to navigate backward through completion menu + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif require("luasnip").jumpable(-1) then + require("luasnip").jump(-1) + else + fallback() + end + end, { "i", "s" }), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, -- Snippet support + }, { + { name = "buffer" }, -- Buffer as a fallback source + }), +}) + +-- Ensure that capabilities are extended for LSP +local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) diff --git a/lua/user/commands.lua b/lua/user/commands.lua new file mode 100644 index 0000000..c7b4553 --- /dev/null +++ b/lua/user/commands.lua @@ -0,0 +1,11 @@ +-- lua/user/commands.lua + +-- Define user command for file creation +vim.api.nvim_create_user_command("CreateFile", function(opts) + local filename = opts.args + if filename and filename ~= "" then + require("user.files_utils").create_file(filename) + else + print("Please provide a filename.") + end +end, { nargs = 1, complete = "file" }) diff --git a/lua/user/comment.lua b/lua/user/comment.lua new file mode 100644 index 0000000..8bcf967 --- /dev/null +++ b/lua/user/comment.lua @@ -0,0 +1,17 @@ +-- ~/.config/nvim/lua/user/comment.lua +local status_ok, comment = pcall(require, "Comment") +if not status_ok then + vim.notify("Comment.nvim not found!") + return +end + +require("Comment").setup({ + toggler = { + line = "k", -- Mapping for toggling comments + block = "b", -- Mapping for block comments + }, + opleader = { + line = "k", -- Mapping for operator-pending comments + block = "b", -- Mapping for block comments in operator-pending mode + }, +}) diff --git a/lua/user/files_utils.lua b/lua/user/files_utils.lua new file mode 100644 index 0000000..43cf869 --- /dev/null +++ b/lua/user/files_utils.lua @@ -0,0 +1,15 @@ +-- lua/user/files_utils.lua + +local M = {} + +function M.create_file(filename) + local file = io.open(filename, "w") + if file then + file:close() + print("File created: " .. filename) + else + print("Failed to create file: " .. filename) + end +end + +return M diff --git a/lua/user/gruvbox.lua b/lua/user/gruvbox.lua new file mode 100644 index 0000000..467ad32 --- /dev/null +++ b/lua/user/gruvbox.lua @@ -0,0 +1,26 @@ +-- Default options: +require("gruvbox").setup({ + terminal_colors = true, -- add neovim terminal colors + undercurl = true, + underline = true, + bold = true, + italic = { + strings = true, + emphasis = true, + comments = true, + operators = false, + folds = true, + }, + strikethrough = true, + invert_selection = false, + invert_signs = false, + invert_tabline = false, + invert_intend_guides = false, + inverse = true, -- invert background for search, diffs, statuslines and errors + contrast = "", -- can be "hard", "soft" or empty string + palette_overrides = {}, + overrides = {}, + dim_inactive = false, + transparent_mode = false, +}) +vim.cmd("colorscheme gruvbox") diff --git a/lua/user/java.lua b/lua/user/java.lua new file mode 100644 index 0000000..fe23450 --- /dev/null +++ b/lua/user/java.lua @@ -0,0 +1,7 @@ +-- ~/.config/nvim/lua/user/java.lua + +-- Additional Java-specific configurations can go here + +-- For example, setting up Java-specific keybindings: +vim.api.nvim_set_keymap('n', 'oi', 'lua vim.lsp.buf.organize_imports()', { noremap = true, silent = true }) + diff --git a/lua/user/keymaps.lua b/lua/user/keymaps.lua new file mode 100644 index 0000000..706a455 --- /dev/null +++ b/lua/user/keymaps.lua @@ -0,0 +1,120 @@ +local map = vim.api.nvim_set_keymap +local default_opts = { noremap = true, silent = true } +local search_replace = require("user.search_replace") + + +-- Leader key +vim.g.mapleader = " " -- Set Space as leader key + +-- Keybinding to format the current buffer +vim.api.nvim_set_keymap('n', 'f', ':lua vim.lsp.buf.format({ async = true })', { noremap = true, silent = true }) + +-- Save file +map("n", "w", ":w", default_opts) + +-- Quit +map("n", "q", ":q", default_opts) + +-- Close current buffer +map("n", "c", ":bd", default_opts) + +-- save all buffers and close all but this one +map("n", "bc", ":%bufdo w|%bd|e#", default_opts) + +-- Toggle NERDTree +map("n", "n", ":NERDTreeToggle", default_opts) + +--split +map("n", "v", ":vs", default_opts) +map("n", "h", ":sp", default_opts) + +-- move to end of line +map("n", "e", "$", default_opts) + +-- move to the starting of lin +map("n", "s", "_", default_opts) + +-- Move between windows +map("n", "", "h", default_opts) +map("n", "", "j", default_opts) +map("n", "", "k", default_opts) +map("n", "", "l", default_opts) + +-- Resize windows with arrow keys +map("n", "", ":resize -2", default_opts) +map("n", "", ":resize +2", default_opts) +map("n", "", ":vertical resize -2", default_opts) +map("n", "", ":vertical resize +2", default_opts) + +-- Copy to system clipboard +map("v", "y", '"+y', default_opts) + +-- Paste from system clipboard +map("n", "p", '"+p', default_opts) +map("v", "p", '"+p', default_opts) + +-- Clear search highlighting +map("n", "/", ":nohlsearch", default_opts) + +-- Telescope keybindings +map("n", "ff", "Telescope find_files", default_opts) -- Find files +map("n", "fg", "Telescope live_grep", default_opts) -- Live grep +map("n", "fb", "Telescope buffers", default_opts) -- List buffers +map("n", "fh", "Telescope help_tags", default_opts) -- Help tags + +-- Keymap to invoke the LSP rename function +map("n", "rn", ":lua vim.lsp.buf.rename()", { noremap = true, silent = true }) + +-- Go to definition +map("n", "gd", "lua vim.lsp.buf.definition()", default_opts) + +-- Go back to previous location +map("n", "cb", "", default_opts) -- Map cb to go back + +-- move forwaed to the location from which go back is triggered +map("n", "cf", "", default_opts) + +--test keybindings +map("n", "tn", ":TestNearest", default_opts) +map("n", "tf", ":TestFile", default_opts) +map("n", "ts", ":TestSuite", default_opts) +map("n", "tl", ":TestLast", default_opts) +map("n", "tv", ":TestVisit", default_opts) + +-- code_action +map("n", "a", ":lua vim.lsp.buf.code_action()", default_opts) + +-- Toggle terminal +map("n", "t", ":lua ToggleTerm()", default_opts) +-- Close terminal with t while in terminal mode +map("t", "t", ":lua ToggleTerm()", { noremap = true, silent = true }) + +-- Key bindings for Markdown preview +map("n", "mp", ":MarkdownPreview", { noremap = true, silent = true }) +map("n", "ms", ":MarkdownPreviewStop", { noremap = true, silent = true }) +map("n", "mf", ":MarkdownPreviewFollow", { noremap = true, silent = true }) + +-- Optional: Key binding to toggle Markdown preview +map("n", "mt", ":call ToggleMarkdownPreview()", { noremap = true, silent = true }) + +-- java at key binding +map("n", "jf", ":lua vim.lsp.buf.at()", { noremap = true, silent = true }) + +-- search and replace function +map("n", "sr", ':lua require("user.search_replace").search_replace()', { noremap = true, silent = true }) + +-- Key mapping to trigger LSP rename +vim.api.nvim_set_keymap("n", "rn", ":lua vim.lsp.buf.rename()", { noremap = true, silent = true }) + +-- In init.lua or lua/user/keymaps.lua +vim.api.nvim_set_keymap( + "n", + "cf", + ":lua require('user.files_utils').create_file('NewFile.java')", + { noremap = true, silent = true } +) + +map("n", "d", ":lua vim.lsp.buf.hover()", { silent = true }) + + + diff --git a/lua/user/lsp.lua b/lua/user/lsp.lua new file mode 100644 index 0000000..06939a7 --- /dev/null +++ b/lua/user/lsp.lua @@ -0,0 +1,12 @@ +-- Load language server configuration +require("user.lsp_servers.pyright") +require("user.lsp_servers.ts_ls") +require("user.lsp_servers.jdtls") +require("user.lsp_servers.marksman") +require("user.lsp_servers.kotlin_ls") + +-- Mason setup +require("mason").setup() +require("mason-lspconfig").setup({ + ensure_installed = { "pyright", "ts_ls", "jdtls", "marksman", "kotlin_language_server" }, -- Ensure Kotlin LSP is installed +}) diff --git a/lua/user/lsp_servers/jdtls.lua b/lua/user/lsp_servers/jdtls.lua new file mode 100644 index 0000000..90bd865 --- /dev/null +++ b/lua/user/lsp_servers/jdtls.lua @@ -0,0 +1,72 @@ +local lspconfig = require("lspconfig") +local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) + +lspconfig.jdtls.setup({ + cmd = { + "/home/prabhat/.local/share/nvim/mason/packages/jdtls/bin/jdtls", + "-Declipse.application=org.eclipse.jdt.ls.core.id1", + "-Dosgi.bundles.defaultStartLevel=4", + "-Declipse.product=org.eclipse.jdt.ls.core.product", + "-Dlog.protocol=true", + "-Dlog.level=ALL", + "-Xmx1G", + "-Xms100m", + "--add-modules=ALL-SYSTEM", + "--add-opens", + "java.base/java.util=ALL-UNNAMED", + "--add-opens", + "java.base/java.lang=ALL-UNNAMED", + "-jar", + "/home/prabhat/.local/share/nvim/mason/packages/jdtls/plugins/org.eclipse.equinox.launcher_*.jar", + "-configuration", + "/home/prabhat/.local/share/nvim/mason/packages/jdtls/config_linux", + "-data", + "/home/prabhat/.local/share/nvim/jdtls-workspace", + }, + capabilities = capabilities, + root_dir = function() + return vim.fs.dirname( + vim.fs.find({ ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" }, { upward = true })[1] + ) + end, + settings = { + java = { + completion = { + favoriteStaticMembers = { + "org.junit.jupiter.api.Assertions.*", + "org.mockito.Mockito.*", + "java.util.Objects.requireNonNull", + "java.util.Objects.requireNonNullElse", + }, + filteredTypes = { + "com.sun.*", + "io.micrometer.shaded.*", + "java.awt.*", + "jdk.*", + "sun.*", + }, + }, + import = { + exclusions = { + "**/internal/**", + }, + maven = { + enabled = true, + downloadSources = true, + }, + gradle = { + enabled = true, + }, + settings = { + -- Customize import order + importOrder = { + "java", + "javax", + "org", + "com", + }, + }, + }, + }, + }, +}) diff --git a/lua/user/lsp_servers/kotlin_ls.lua b/lua/user/lsp_servers/kotlin_ls.lua new file mode 100644 index 0000000..1b1003c --- /dev/null +++ b/lua/user/lsp_servers/kotlin_ls.lua @@ -0,0 +1,28 @@ +-- lua/user/lsp_servers/kotlin_ls.lua + +local lspconfig = require("lspconfig") + +-- Setup the Kotlin language server +lspconfig.kotlin_language_server.setup({ + cmd = { "kotlin-language-server" }, -- The command to start the server + on_attach = function(client, bufnr) + -- Key mappings for LSP functions + local opts = { noremap = true, silent = true } + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + + buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) + buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) + buf_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) + end, + flags = { + debounce_text_changes = 150, + }, + settings = { + kotlin = { + linting = { enabled = true }, + completion = { enabled = true }, + }, + }, +}) diff --git a/lua/user/lsp_servers/marksman.lua b/lua/user/lsp_servers/marksman.lua new file mode 100644 index 0000000..7cdac1b --- /dev/null +++ b/lua/user/lsp_servers/marksman.lua @@ -0,0 +1,6 @@ +local lspconfig = require("lspconfig") +-- Setup for Markdown LSP (Marksman) +lspconfig.marksman.setup({ + -- Add additional settings here + filetypes = { "markdown", "md" }, +}) diff --git a/lua/user/lsp_servers/pyright.lua b/lua/user/lsp_servers/pyright.lua new file mode 100644 index 0000000..f82ff95 --- /dev/null +++ b/lua/user/lsp_servers/pyright.lua @@ -0,0 +1,15 @@ +local lspconfig = require("lspconfig") + +lspconfig.pyright.setup({ + on_attach = function(client, bufnr) + -- Custom keymaps and commands for pyright + end, + settings = { + python = { + analysis = { + autoSearchPaths = true, + useLibraryCodeForTypes = true, + }, + }, + }, +}) diff --git a/lua/user/lsp_servers/ts_ls.lua b/lua/user/lsp_servers/ts_ls.lua new file mode 100644 index 0000000..31cc341 --- /dev/null +++ b/lua/user/lsp_servers/ts_ls.lua @@ -0,0 +1,41 @@ +local lspconfig = require("lspconfig") + +lspconfig.ts_ls.setup({ + on_attach = function(client, bufnr) + -- Custom keymaps and commands for tsserver + local opts = { noremap = true, silent = true } + -- Example key mappings + vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) + end, + filetypes = { + "typescript", + "typescriptreact", + "typescript.tsx", + "javascript", + "javascriptreact", + "javascript.jsx", + }, + cmd = { "typescript-language-server", "--stdio" }, + root_dir = lspconfig.util.root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git"), + settings = { + -- Enable document formatting + format = { + enable = true, + insertSpaceAfterCommaDelimiter = true, + insertSpaceAfterSemicolon = true, + insertSpaceBeforeAndAfterOperator = true, + indentStyle = "smart", + indentSize = 2, + wrapLineLength = 120, + }, + -- Diagnostics and completion settings + diagnostics = { + enable = true, + }, + completions = { + enable = true, + }, + }, +}) diff --git a/lua/user/markdown.lua b/lua/user/markdown.lua new file mode 100644 index 0000000..3fbd5f1 --- /dev/null +++ b/lua/user/markdown.lua @@ -0,0 +1,10 @@ +-- Define function to toggle Markdown preview + +vim.cmd([[ +function! StopMarkdownPreview() + if exists('g:mkdp_is_ready') && g:mkdp_is_ready + let g:mkdp_auto_start = 0 + call mkdp#stop() + endif +endfunction +]]) diff --git a/lua/user/null-ls.lua b/lua/user/null-ls.lua new file mode 100644 index 0000000..49b72fa --- /dev/null +++ b/lua/user/null-ls.lua @@ -0,0 +1,38 @@ +-- File: lua/user/null-ls.lua + +local null_ls = require("null-ls") + +-- Define builtins for formatting +local formatting = null_ls.builtins.formatting + +-- Configure null-ls +local sources = { + formatting.prettier, -- Use prettier for formatting (JavaScript, TypeScript, etc.) + formatting.black, -- Use black for Python formatting + formatting.stylua, -- Use stylua for Lua formatting + formatting.google_java_format.with({ + command = "java", + args = { "-jar", "/home/prabhat/.config/nvim/jars/google-java-format.jar", "-" }, + extra_args = { "--aosp" }, -- optional: use AOSP style formatting + --command = "google-java-format", -- specify command if not in PATH + }), + -- Add other formatters based on your needs +} + +null_ls.setup({ + sources = sources, + on_attach = function(client, bufnr) + if client.server_capabilities.documentFormattingProvider then + local lsp_format_group = vim.api.nvim_create_augroup("LspFormatting", { clear = true }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = lsp_format_group, + buffer = bufnr, + callback = function() + local view = vim.fn.winsaveview() + vim.lsp.buf.format({ async = true }) + vim.fn.winrestview(view) + end, + }) + end + end, +}) diff --git a/lua/user/options.lua b/lua/user/options.lua new file mode 100644 index 0000000..6fd0f60 --- /dev/null +++ b/lua/user/options.lua @@ -0,0 +1,67 @@ +local opt = vim.opt + +-- Line numbers +opt.number = true +opt.relativenumber = true + +-- Tabs and indentation +opt.expandtab = true +opt.tabstop = 4 +opt.shiftwidth = 4 +opt.smartindent = true + +-- Disable swapfile +opt.swapfile = false + +-- Enable mouse support +opt.mouse = "a" -- put "a" to enable in all mode or "n" to enable on normal mode + +-- Enable clipboard access +opt.clipboard = "unnamedplus" + +-- Case insensitive searching unless /C or capital in search +opt.ignorecase = true +opt.smartcase = true + +-- Appearance +opt.termguicolors = true +opt.background = "dark" + +-- creates backup files +opt.backup = false + +-- allows neovim to access the system clipboard +opt.clipboard = "unnamedplus" + +-- more space in the neovim command line for displaying messages +opt.cmdheight = 2 + +-- highlight all matches on previous search pattern +opt.hlsearch = true + +-- enable persistent undo +opt.undofile = true + +-- faster completion (4000ms default) +opt.updatetime = 300 + +-- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited +opt.writebackup = false + +-- highlight the current Line +opt.cursorline = true + +-- always show the sign column, otherwise it would shift the text each time +opt.signcolumn = "yes" + +-- display lines as one long line +opt.wrap = true + +-- companion to wrap, don't split words +opt.linebreak = true + +-- minimal number of screen lines to keep above and below the cursor +opt.scrolloff = 8 + +-- minimal number of screen columns either side of cursor if wrap is `false` +opt.sidescrolloff = 8 diff --git a/lua/user/search_replace.lua b/lua/user/search_replace.lua new file mode 100644 index 0000000..38c9b7f --- /dev/null +++ b/lua/user/search_replace.lua @@ -0,0 +1,14 @@ +-- lua/user/search_replace.lua + +local M = {} + +function M.search_replace() + -- Prompt for the old name + local old_name = vim.fn.input("Old name: ") + -- Prompt for the new name + local new_name = vim.fn.input("New name: ") + -- Execute the search and replace command + vim.cmd(string.format("%%s/%s/%s/g", old_name, new_name)) +end + +return M diff --git a/lua/user/snippets.lua b/lua/user/snippets.lua new file mode 100644 index 0000000..cc32ad2 --- /dev/null +++ b/lua/user/snippets.lua @@ -0,0 +1,16 @@ +-- lua/user/snippets.lua +local ls = require('luasnip') + +ls.add_snippets('lua', { + ls.snippet('func', { + ls.text_node('function '), + ls.insert_node(1, 'name'), + ls.text_node('('), + ls.insert_node(2), + ls.text_node(')'), + ls.text_node(' '), + ls.insert_node(0), + ls.text_node('end'), + }), +}) + diff --git a/lua/user/telescope.lua b/lua/user/telescope.lua new file mode 100644 index 0000000..3b001db --- /dev/null +++ b/lua/user/telescope.lua @@ -0,0 +1,59 @@ +-- lua/user/telescope.lua + +local telescope = require('telescope') +local actions = require('telescope.actions') + +telescope.setup{ + defaults = { + prompt_prefix = "> ", + selection_caret = "> ", + entry_prefix = " ", + initial_mode = "insert", + layout_strategy = "horizontal", -- Set layout strategy to vertical + layout_config = { + vertical = { + mirror = false, + preview_height = 0.6, -- Adjust this value for preview height + prompt_position = "top", + width = 0.75, -- Adjust the width of the preview window + }, + horizontal = { + mirror = false, + preview_width = 0.6, -- Adjust this value for preview width + }, + }, + sorting_strategy = "ascending", + file_sorter = require('telescope.sorters').get_fzy_sorter, + file_ignore_patterns = {}, + generic_sorter = require('telescope.sorters').get_generic_fuzzy_sorter, + path_display = { "truncate" }, + winblend = 0, + border = {}, + borderchars = { + '─', '│', '─', '│', + '┼', '│', '┤', '│' + }, + color_devicons = true, + use_less = true, + set_env = { ['COLORTERM'] = 'truecolor' }, + mappings = { + i = { + [""] = false, + [""] = actions.delete_buffer, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + [""] = actions.close, + }, + n = { + [""] = actions.delete_buffer, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + [""] = actions.close, + }, + }, + } +} + +-- Load fzf extension +require('telescope').load_extension('fzf') + diff --git a/lua/user/terminal.lua b/lua/user/terminal.lua new file mode 100644 index 0000000..2e5e007 --- /dev/null +++ b/lua/user/terminal.lua @@ -0,0 +1,26 @@ +-- Define the ToggleTerm function globally +function _G.ToggleTerm() + -- Check if there is a terminal buffer open + local term_buf = nil + for _, buf in ipairs(vim.api.nvim_list_bufs()) do + if vim.api.nvim_buf_get_option(buf, "buftype") == "terminal" then + term_buf = buf + break + end + end + + if term_buf then + -- If terminal buffer is open, find its window + local term_win = vim.fn.bufwinnr(term_buf) + if term_win ~= -1 then + -- If terminal window is open, close it + vim.cmd(term_win .. "close") + else + -- If terminal buffer exists but window is not open, open it in a split + vim.cmd("belowright split | buffer " .. term_buf) + end + else + -- No terminal buffer found, open a new one + vim.cmd("belowright split | terminal") + end +end diff --git a/lua/user/test.lua b/lua/user/test.lua new file mode 100644 index 0000000..692ecb2 --- /dev/null +++ b/lua/user/test.lua @@ -0,0 +1,18 @@ +-- lua/user/test.lua +return function() + -- Set up vim-test plugin + require("packer").use({ + "vim-test/vim-test", + config = function() + vim.cmd([[ + let test#strategy = "neovim" + " Customize the keybindings or other settings here + nmap t :TestNearest + nmap t :TestFile + nmap t :TestSuite + nmap t :TestLast + nmap t :TestVisit + ]]) + end, + }) +end diff --git a/lua/user/treesitter.lua b/lua/user/treesitter.lua new file mode 100644 index 0000000..1cdfe5a --- /dev/null +++ b/lua/user/treesitter.lua @@ -0,0 +1,33 @@ +require("nvim-treesitter.configs").setup({ + ensure_installed = { + "markdown", + "markdown_inline", + "lua", + "python", + "java", + "c", + "cpp", + "javascript", + "kotlin", + "go", + }, + highlight = { + enable = true, + use_language_tree = true, + }, + incremental_selection = { + enable = true, + }, + indent = { + enable = true, + }, + context_commentstring = { + enable = true, + }, + autopairs = { + enable = true, + }, + rainbow = { + enable = true, + }, +})