Skip to content

Instantly share code, notes, and snippets.

@masihtehrani
Last active January 17, 2024 09:54
Show Gist options
  • Save masihtehrani/2444e99169ff8735a126ee77b6473aab to your computer and use it in GitHub Desktop.
Save masihtehrani/2444e99169ff8735a126ee77b6473aab to your computer and use it in GitHub Desktop.
lunarvim golang python lvim neovim nvim ide ~/.config/lvim/config.lua
--[[
lvim is the global options object
Linters should be
filled in as strings with either
a global executable or a path to
an executable
]]
-- THESE ARE EXAMPLE CONFIGS FEEL FREE TO CHANGE TO WHATEVER YOU WANT
-- general
lvim.log.level = "warn"
lvim.format_on_save = true
lvim.colorscheme = "onedarker"
-- keymappings [view all the defaults by pressing <leader>Lk]
lvim.leader = "space"
-- add your own keymapping
lvim.keys.normal_mode["<C-s>"] = ":w<cr>"
-- unmap a default keymapping
lvim.keys.normal_mode["<C-Up>"] = ""
-- edit a default keymapping
lvim.keys.normal_mode["<C-q>"] = ":q<cr>"
-- Change Telescope navigation to use j and k for navigation and n and p for history in both input and normal mode.
-- we use protected-mode (pcall) just in case th plugin wasn't loaded yet.
local _, actions = pcall(require, "telescope.actions")
lvim.builtin.telescope.defaults.mappings = {
-- for input mode
i = {
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
["<C-n>"] = actions.cycle_history_next,
["<C-p>"] = actions.cycle_history_prev,
},
-- for normal mode
n = {
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
},
}
-- Use which-key to add extra bindings with the leader-key prefix
lvim.builtin.which_key.mappings["P"] = { "<cmd>Telescope projects<CR>", "Projects" }
lvim.builtin.which_key.mappings["t"] = {
name = "+Trouble",
r = { "<cmd>Trouble lsp_references<cr>", "References" },
f = { "<cmd>Trouble lsp_definitions<cr>", "Definitions" },
d = { "<cmd>Trouble lsp_document_diagnostics<cr>", "Diagnostics" },
q = { "<cmd>Trouble quickfix<cr>", "QuickFix" },
l = { "<cmd>Trouble loclist<cr>", "LocationList" },
w = { "<cmd>Trouble lsp_workspace_diagnostics<cr>", "Diagnostics" },
}
-- TODO: User Config for predefined plugins
-- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile
lvim.builtin.dashboard.active = true
lvim.builtin.terminal.active = true
lvim.builtin.nvimtree.setup.view.side = "left"
lvim.builtin.nvimtree.show_icons.git = 0
-- if you don't want all the parsers change this to a table of the ones you want
lvim.builtin.treesitter.ensure_installed = {
"bash",
"c",
"javascript",
"json",
"lua",
"python",
"typescript",
"css",
"rust",
"java",
"yaml",
"go"
}
lvim.builtin.treesitter.ignore_install = { "haskell" }
lvim.builtin.treesitter.highlight.enabled = true
-- generic LSP settings
-- ---@usage disable automatic installation of servers
-- lvim.lsp.automatic_servers_installation = false
-- ---@usage Select which servers should be configured manually. Requires `:LvimCacheRest` to take effect.
-- See the full default list `:lua print(vim.inspect(lvim.lsp.override))`
-- vim.list_extend(lvim.lsp.override, { "pyright" })
-- ---@usage setup a server -- see: https://www.lunarvim.org/languages/#overriding-the-default-configuration
-- local opts = {} -- check the lspconfig documentation for a list of all possible options
-- require("lvim.lsp.manager").setup("pylsp", opts)
-- you can set a custom on_attach function that will be used for all the language servers
-- See <https://github.com/neovim/nvim-lspconfig#keybindings-and-completion>
-- lvim.lsp.on_attach_callback = function(client, bufnr)
-- local function buf_set_option(...)
-- vim.api.nvim_buf_set_option(bufnr, ...)
-- end
-- --Enable completion triggered by <c-x><c-o>
-- buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
-- end
-- you can overwrite the null_ls setup table (useful for setting the root_dir function)
-- lvim.lsp.null_ls.setup = {
-- root_dir = require("lspconfig").util.root_pattern("Makefile", ".git", "node_modules"),
-- }
-- or if you need something more advanced
-- lvim.lsp.null_ls.setup.root_dir = function(fname)
-- if vim.bo.filetype == "javascript" then
-- return require("lspconfig/util").root_pattern("Makefile", ".git", "node_modules")(fname)
-- or require("lspconfig/util").path.dirname(fname)
-- elseif vim.bo.filetype == "php" then
-- return require("lspconfig/util").root_pattern("Makefile", ".git", "composer.json")(fname) or vim.fn.getcwd()
-- else
-- return require("lspconfig/util").root_pattern("Makefile", ".git")(fname) or require("lspconfig/util").path.dirname(fname)
-- end
-- end
-- -- set a formatter, this will override the language server formatting capabilities (if it exists)
local formatters = require "lvim.lsp.null-ls.formatters"
formatters.setup {
{ exe = "black", filetypes = { "python" } },
{ exe = "isort", filetypes = { "python" } },
{
exe = "prettier",
---@usage arguments to pass to the formatter
-- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}`
args = { "--print-with", "100" },
---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
filetypes = { "typescript", "typescriptreact" },
},
}
-- -- set additional linters
local linters = require "lvim.lsp.null-ls.linters"
linters.setup {
{ exe = "flake8", filetypes = { "python" } },
{
exe = "shellcheck",
---@usage arguments to pass to the formatter
-- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}`
args = { "--severity", "warning" },
},
{
exe = "codespell",
---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
filetypes = { "javascript", "python" },
},
}
-- Additional Plugins
-- lvim.plugins = {
-- {"folke/tokyonight.nvim"},:TSInstall gopls
-- {
-- "folke/trouble.nvim",
-- cmd = "TroubleToggle",
-- },
-- }
-- Autocommands (https://neovim.io/doc/user/autocmd.html)
-- lvim.autocommands.custom_groups = {
-- { "BufWinEnter", "*.lua", "setlocal ts=8 sw=8" },
-- }
lvim.plugins = {
{"mfussenegger/nvim-dap-python"},
{"ray-x/go.nvim"},
{
"phaazon/hop.nvim",
event = "BufRead",
config = function()
require("hop").setup()
vim.api.nvim_set_keymap("n", "s", ":HopChar2<cr>", { silent = true })
vim.api.nvim_set_keymap("n", "S", ":HopWord<cr>", { silent = true })
end,
},
{
'wfxr/minimap.vim',
run = "cargo install --locked code-minimap",
-- cmd = {"Minimap", "MinimapClose", "MinimapToggle", "MinimapRefresh", "MinimapUpdateHighlight"},
config = function ()
vim.cmd ("let g:minimap_width = 10")
vim.cmd ("let g:minimap_auto_start = 1")
vim.cmd ("let g:minimap_auto_start_win_enter = 1")
end,
},
{
"kevinhwang91/nvim-bqf",
event = { "BufRead", "BufNew" },
config = function()
require("bqf").setup({
auto_enable = true,
preview = {
win_height = 12,
win_vheight = 12,
delay_syntax = 80,
border_chars = { "┃", "┃", "━", "━", "┏", "┓", "┗", "┛", "█" },
},
func_map = {
vsplit = "",
ptogglemode = "z,",
stoggleup = "",
},
filter = {
fzf = {
action_for = { ["ctrl-s"] = "split" },
extra_opts = { "--bind", "ctrl-o:toggle-all", "--prompt", "> " },
},
},
})
end,
},
{
"windwp/nvim-spectre",
event = "BufRead",
config = function()
require("spectre").setup()
end,
},
{
"andymass/vim-matchup",
event = "CursorMoved",
config = function()
vim.g.matchup_matchparen_offscreen = { method = "popup" }
end,
},
{
"sindrets/diffview.nvim",
event = "BufRead",
},
{
"f-person/git-blame.nvim",
event = "BufRead",
config = function()
vim.cmd "highlight default link gitblame SpecialComment"
vim.g.gitblame_enabled = 0
end,
},
{
"p00f/nvim-ts-rainbow",
},
{
"nvim-telescope/telescope-project.nvim",
event = "BufWinEnter",
setup = function()
vim.cmd [[packadd telescope.nvim]]
end,
},
{
"folke/lsp-colors.nvim",
event = "BufRead",
},
{
"folke/lsp-colors.nvim",
event = "BufRead",
},
{
"norcalli/nvim-colorizer.lua",
config = function()
require("colorizer").setup({ "*" }, {
RGB = true, -- #RGB hex codes
RRGGBB = true, -- #RRGGBB hex codes
RRGGBBAA = true, -- #RRGGBBAA hex codes
rgb_fn = true, -- CSS rgb() and rgba() functions
hsl_fn = true, -- CSS hsl() and hsla() functions
css = true, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB
css_fn = true, -- Enable all CSS *functions*: rgb_fn, hsl_fn
})
end,
},
{
"tzachar/cmp-tabnine",
run = "./install.sh",
requires = "hrsh7th/nvim-cmp",
event = "InsertEnter",
},
{
"rmagatti/goto-preview",
config = function()
require('goto-preview').setup {
width = 120; -- Width of the floating window
height = 25; -- Height of the floating window
default_mappings = false; -- Bind default mappings
debug = false; -- Print debug information
opacity = nil; -- 0-100 opacity level of the floating window where 100 is fully transparent.
post_open_hook = nil -- A function taking two arguments, a buffer and a window to be ran as a hook.
-- You can use "default_mappings = true" setup option
-- Or explicitly set keybindings
-- vim.cmd("nnoremap gpd <cmd>lua require('goto-preview').goto_preview_definition()<CR>")
-- vim.cmd("nnoremap gpi <cmd>lua require('goto-preview').goto_preview_implementation()<CR>")
-- vim.cmd("nnoremap gP <cmd>lua require('goto-preview').close_all_win()<CR>")
}
end
},
{
"ray-x/lsp_signature.nvim",
event = "BufRead",
config = function()
require "lsp_signature".setup()
end
},
-- {
-- "Pocco81/AutoSave.nvim",
-- config = function()
-- require("autosave").setup()
-- end,
-- },
{
"lukas-reineke/indent-blankline.nvim",
event = "BufRead",
setup = function()
vim.g.indentLine_enabled = 1
vim.g.indent_blankline_char = "‚ñè"
vim.g.indent_blankline_filetype_exclude = {"help", "terminal", "dashboard"}
vim.g.indent_blankline_buftype_exclude = {"terminal"}
vim.g.indent_blankline_show_trailing_blankline_indent = false
vim.g.indent_blankline_show_first_indent_level = false
end
},
{
"iamcco/markdown-preview.nvim",
run = "cd app && npm install",
ft = "markdown",
config = function()
vim.g.mkdp_auto_start = 1
end,
},
{
"ethanholz/nvim-lastplace",
event = "BufRead",
config = function()
require("nvim-lastplace").setup({
lastplace_ignore_buftype = { "quickfix", "nofile", "help" },
lastplace_ignore_filetype = {
"gitcommit", "gitrebase", "svn", "hgcommit",
},
lastplace_open_folds = true,
})
end,
},
{
"metakirby5/codi.vim",
cmd = "Codi",
},
{
"folke/trouble.nvim",
cmd = "TroubleToggle",
},
{
"simrat39/symbols-outline.nvim",
cmd = "SymbolsOutline",
},
{
"nvim-telescope/telescope-fzy-native.nvim",
run = "make",
event = "BufRead",
},
-- {
-- "JoosepAlviste/nvim-ts-context-commentstring",
-- event = "BufRead",
-- },
}
require('go').setup({
goimport='goimports', -- goimport command
gofmt = 'gofumpt', --gofmt cmd,
max_line_len = 120, -- max line length in goline format
tag_transform = false, -- tag_transfer check gomodifytags for details
verbose = true, -- output loginf in messages
log_path = vim.fn.expand("$HOME") .. "/.config/lvim/log.log",
lsp_cfg = true, -- true: apply go.nvim non-default gopls setup
lsp_gofumpt = false, -- true: set default gofmt in gopls format to gofumpt
lsp_on_attach = true, -- if a on_attach function provided: attach on_attach function to gopls
-- true: will use go.nvim on_attach if true
-- nil/false do nothing
lsp_codelens = true,
-- gopls_remote_auto = true, -- set to false is you do not want to pass -remote=auto to gopls(enable share)
-- gopls_cmd = nil,
-- if you need to specify gopls path and cmd, e.g {"/home/user/lsp/gopls", "-logfile", "/var/log/gopls.log" }
lsp_diag_hdlr = true, -- hook lsp diag handler
dap_debug = true, -- set to true to enable dap
dap_debug_keymap = true, -- set keymaps for debugger
dap_debug_gui = true, -- set to true to enable dap gui, highly recommand
dap_debug_vt = true, -- set to true to enable dap virtual text
})
lvim.autocommands.custom_groups = {
{"BufWritePre", "*.go", ":silent! lua require('go.format').goimport()"}
}
-- add your own keymapping
-- lvim.keys.normal_mode["<C-s>"] = ":w<cr>"
-- lvim.keys.normal_mode["<Left>"] = ":echo \"Use h\"<cr>"
-- lvim.keys.normal_mode["<Right>"] = ":echo \"Use l\"<cr>"
-- lvim.keys.normal_mode["<Up>"] = ":echo \"Use k\"<cr>"
-- lvim.keys.normal_mode["<Down>"] = ":echo \"Use j\"<cr>"
lvim.keys.insert_mode["<C-b>"] = "<Left>"
lvim.keys.insert_mode["<C-f>"] = "<Right>"
lvim.keys.insert_mode["<C-p>"] = "<Up>"
lvim.keys.insert_mode["<C-n>"] = "<Down>"
lvim.builtin.lualine.active = true
lvim.builtin.dap.active = true
lvim.builtin.dashboard.active = true
lvim.builtin.terminal.active = true
lvim.builtin.bufferline.active = true
local dap = require "dap"
dap.adapters.go = {
type = 'executable';
command = 'node';
args = {os.getenv('HOME') .. '/vscode-go/dist/debugAdapter.js'}; -- specify the path to the adapter
}
dap.configurations.go = {
{
type = "go",
name = "Attach",
request = "attach",
processId = require("dap.utils").pick_process,
program = "${workspaceFolder}",
dlvToolPath = vim.fn.exepath('dlv')
},
{
type = "go",
name = "Debug curr file",
request = "launch",
program = "${file}",
dlvToolPath = vim.fn.exepath('dlv')
},
{
type = "go",
name = "Debug",
request = "launch",
program = "${workspaceFolder}",
dlvToolPath = vim.fn.exepath('dlv')
},
{
type = "go",
name = "Debug curr test",
request = "launch",
mode = "test",
program = "${file}",
dlvToolPath = vim.fn.exepath('dlv')
},
{
type = "go",
name = "Debug test",
request = "launch",
mode = "test",
program = "${workspaceFolder}",
dlvToolPath = vim.fn.exepath('dlv')
},
}
dap.adapters.python = {
type = 'executable';
command = 'path/to/virtualenvs/debugpy/bin/python';
args = { '-m', 'debugpy.adapter' };
}
dap.configurations.python = {
{
-- The first three options are required by nvim-dap
type = 'python'; -- the type here established the link to the adapter definition: `dap.adapters.python`
request = 'launch';
name = "Launch file";
-- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options
program = "${file}"; -- This configuration will launch the current file if used.
pythonPath = function()
-- debugpy supports launching an application with a different interpreter then the one used to launch debugpy itself.
-- The code below looks for a `venv` or `.venv` folder in the current directly and uses the python within.
-- You could adapt this - to for example use the `VIRTUAL_ENV` environment variable.
local cwd = vim.fn.getcwd()
if vim.fn.executable(cwd .. '/venv/bin/python') == 1 then
return cwd .. '/venv/bin/python'
elseif vim.fn.executable(cwd .. '/.venv/bin/python') == 1 then
return cwd .. '/.venv/bin/python'
else
return '/usr/bin/python'
end
end;
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment