feat: adding keymapping

This commit is contained in:
Kiruel 2023-10-12 22:58:00 +02:00
parent de4c01a8ef
commit 7f70386437
4 changed files with 538 additions and 289 deletions

251
init.lua
View File

@ -64,6 +64,7 @@ vim.opt.rtp:prepend(lazypath)
-- --
-- You can also configure plugins after the setup call, -- You can also configure plugins after the setup call,
-- as they will be available in your neovim runtime. -- as they will be available in your neovim runtime.
require('lazy').setup({ require('lazy').setup({
-- NOTE: First, some plugins that don't require any configuration -- NOTE: First, some plugins that don't require any configuration
@ -78,7 +79,8 @@ require('lazy').setup({
'SirVer/ultisnips', 'SirVer/ultisnips',
'honza/vim-snippets', 'honza/vim-snippets',
'natebosch/dartlang-snippets', 'natebosch/dartlang-snippets',
'dart-lang/dart-vim-plugin',
'morhetz/gruvbox',
-- NOTE: This is where your plugins related to LSP can be installed. -- NOTE: This is where your plugins related to LSP can be installed.
-- The configuration is done below. Search for lspconfig to find it below. -- The configuration is done below. Search for lspconfig to find it below.
{ {
@ -97,7 +99,6 @@ require('lazy').setup({
'folke/neodev.nvim', 'folke/neodev.nvim',
}, },
}, },
{ {
-- Autocompletion -- Autocompletion
'hrsh7th/nvim-cmp', 'hrsh7th/nvim-cmp',
@ -133,16 +134,16 @@ require('lazy').setup({
-- don't override the built-in and fugitive keymaps -- don't override the built-in and fugitive keymaps
local gs = package.loaded.gitsigns local gs = package.loaded.gitsigns
vim.keymap.set({'n', 'v'}, ']c', function() vim.keymap.set({ 'n', 'v' }, ']c', function()
if vim.wo.diff then return ']c' end if vim.wo.diff then return ']c' end
vim.schedule(function() gs.next_hunk() end) vim.schedule(function() gs.next_hunk() end)
return '<Ignore>' return '<Ignore>'
end, {expr=true, buffer = bufnr, desc = "Jump to next hunk"}) end, { expr = true, buffer = bufnr, desc = "Jump to next hunk" })
vim.keymap.set({'n', 'v'}, '[c', function() vim.keymap.set({ 'n', 'v' }, '[c', function()
if vim.wo.diff then return '[c' end if vim.wo.diff then return '[c' end
vim.schedule(function() gs.prev_hunk() end) vim.schedule(function() gs.prev_hunk() end)
return '<Ignore>' return '<Ignore>'
end, {expr=true, buffer = bufnr, desc = "Jump to previous hunk"}) end, { expr = true, buffer = bufnr, desc = "Jump to previous hunk" })
end, end,
}, },
}, },
@ -213,7 +214,16 @@ require('lazy').setup({
}, },
build = ':TSUpdate', build = ':TSUpdate',
}, },
{
'akinsho/flutter-tools.nvim',
lazy = false,
dependencies = {
'nvim-lua/plenary.nvim',
'stevearc/dressing.nvim', -- optional for vim.ui.select
},
config = true,
},
{ 'akinsho/git-conflict.nvim', version = "*", config = true },
-- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart
-- These are some example plugins that I've included in the kickstart repository. -- These are some example plugins that I've included in the kickstart repository.
-- Uncomment any of the lines below to enable them. -- Uncomment any of the lines below to enable them.
@ -229,13 +239,92 @@ require('lazy').setup({
{ import = 'custom.plugins' }, { import = 'custom.plugins' },
}, {}) }, {})
-- [[ Setting options ]] local flutterConfig = require("flutter-tools")
flutterConfig.setup {
ui = {
border = "rounded",
notification_style = 'native'
},
decorations = {
statusline = {
-- set to true to be able use the 'flutter_tools_decorations.app_version' in your statusline
-- this will show the current version of the flutter app from the pubspec.yaml file
app_version = true,
-- set to true to be able use the 'flutter_tools_decorations.device' in your statusline
-- this will show the currently running device if an application was started with a specific
-- device
device = true,
-- set to true to be able use the 'flutter_tools_decorations.project_config' in your statusline
-- this will show the currently selected project configuration
project_config = true,
}
},
debugger = { -- integrate with nvim dap + install dart code debugger
enabled = false,
run_via_dap = false, -- use dap instead of a plenary job to run flutter apps
-- if empty dap will not stop on any exceptions, otherwise it will stop on those specified
-- see |:help dap.set_exception_breakpoints()| for more info
exception_breakpoints = {}
},
root_patterns = { ".git", "pubspec.yaml" }, -- patterns to find the root of your flutter project
fvm = true, -- takes priority over path, uses <workspace>/.fvm/flutter_sdk if enabled
widget_guides = {
enabled = false,
},
closing_tags = {
highlight = "Comment", -- highlight for the closing tag
prefix = "//", -- character to use for close tag e.g. > Widget
enabled = true -- set to false to disable
},
dev_log = {
enabled = true,
notify_errors = false, -- if there is an error whilst running then notify the user
open_cmd = "tabedit", -- command to use to open the log buffer
},
dev_tools = {
autostart = false, -- autostart devtools server if not detected
auto_open_browser = false, -- Automatically opens devtools in the browser
},
outline = {
open_cmd = "30vnew", -- command to use to open the outline buffer
auto_open = false -- if true this will open the outline automatically when it is first populated
},
lsp = {
color = { -- show the derived colours for dart variables
enabled = false, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10
background = false, -- highlight the background
background_color = nil, -- required, when background is transparent (i.e. background_color = { r = 19, g = 17, b = 24},)
foreground = false, -- highlight the foreground
virtual_text = true, -- show the highlight using virtual text
virtual_text_str = "", -- the virtual text character to highlight
},
--- OR you can specify a function to deactivate or change or control how the config is created
capabilities = function(config)
config.specificThingIDontWant = false
return config
end,
-- see the link below for details on each option:
-- https://github.com/dart-lang/sdk/blob/master/pkg/analysis_server/tool/lsp_spec/README.md#client-workspace-configuration
settings = {
showTodos = true,
completeFunctionCalls = true,
renameFilesWithClasses = "prompt", -- "always"
enableSnippets = true,
updateImportsOnRename = true, -- Whether to update imports and other directives when files are renamed. Required for `FlutterRename` command.
}
}
}
---i [[ Setting options ]]
-- See `:help vim.o` -- See `:help vim.o`
-- NOTE: You can change these options as you wish! -- NOTE: You can change these options as you wish!
-- Set highlight on search -- Set highlight on search
vim.o.hlsearch = false vim.o.hlsearch = false
vim.o.exrc = true
-- Make line numbers default -- Make line numbers default
vim.wo.number = true vim.wo.number = true
@ -291,6 +380,14 @@ vim.api.nvim_create_autocmd('TextYankPost', {
pattern = '*', pattern = '*',
}) })
-- Auto format
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = buffer,
callback = function()
vim.lsp.buf.format { async = false }
end
})
-- [[ Configure Telescope ]] -- [[ Configure Telescope ]]
-- See `:help telescope` and `:help telescope.setup()` -- See `:help telescope` and `:help telescope.setup()`
require('telescope').setup { require('telescope').setup {
@ -319,6 +416,7 @@ vim.keymap.set('n', '<leader>/', function()
end, { desc = '[/] Fuzzily search in current buffer' }) end, { desc = '[/] Fuzzily search in current buffer' })
vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' })
vim.keymap.set('n', '<leader>gs', require('telescope.builtin').git_status, { desc = 'Search [G]it [S]tatus' })
vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' })
vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' })
vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' })
@ -326,11 +424,21 @@ vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })
vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' })
-- [[ Configure Flutter tools]]
vim.keymap.set('n', '<leader>r', require('telescope').extensions.flutter.commands, { desc = 'Open command Flutter' })
-- fvm flutter pub get && fvm flutter packages pub ru:build_runner build --delete-conflicting-outputs
vim.keymap.set('n', '<leader>br', function()
vim.api.nvim_command("botright split new")
vim.fn.system { 'echo', 'hi' }
end, { desc = 'Flutter get pub and build runner' })
-- [[ Configure Treesitter ]] -- [[ Configure Treesitter ]]
-- See `:help nvim-treesitter` -- See `:help nvim-treesitter`
require('nvim-treesitter.configs').setup { require('nvim-treesitter.configs').setup {
-- Add languages to be installed here that you want installed for treesitter -- Add languages to be installed here that you want installed for treesitter
ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim' }, ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim',
'dart', 'prisma' },
-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
auto_install = false, auto_install = false,
@ -358,6 +466,7 @@ require('nvim-treesitter.configs').setup {
['if'] = '@function.inner', ['if'] = '@function.inner',
['ac'] = '@class.outer', ['ac'] = '@class.outer',
['ic'] = '@class.inner', ['ic'] = '@class.inner',
['uc'] = '@comment.outer'
}, },
}, },
move = { move = {
@ -398,12 +507,17 @@ vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnos
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
-- Neotree
vim.keymap.set('n', '<leader>tt', '<Cmd>Neotree toggle<CR>', { desc = "Neo[T]ree [T]oggle" })
vim.keymap.set('n', '<leader>tr', '<Cmd>Neotree reveal<CR>', { desc = "Neo[T]ree [R]eveal" })
vim.keymap.set('n', '<leader>ts', '<Cmd>Neotree git_status<CR>', { desc = "Neo[T]ree git [S]tatus" })
-- [[ Configure LSP ]] -- [[ Configure LSP ]]
-- This function gets run when an LSP connects to a particular buffer. -- This function gets run when an LSP connects to a particular buffer.
local on_attach = function(_, bufnr) local on_attach = function(_, bufnr)
-- NOTE: Remember that lua is a real programming language, and as such it is possible -- NOTE: Remember that lua is a real programming language, and as such it is possible
-- to define small helper and utility functions so you don't have to repeat yourself -- to define small helper and utility functions so you don't have to repeat yourself
-- many times. -- many time
-- --
-- In this case, we create a function that lets us more easily define mappings specific -- In this case, we create a function that lets us more easily define mappings specific
-- for LSP related items. It sets the mode, buffer and description for us each time. -- for LSP related items. It sets the mode, buffer and description for us each time.
@ -456,9 +570,9 @@ local servers = {
-- gopls = {}, -- gopls = {},
-- pyright = {}, -- pyright = {},
-- rust_analyzer = {}, -- rust_analyzer = {},
-- tsserver = {}, tsserver = {},
-- html = { filetypes = { 'html', 'twig', 'hbs'} }, prismals = {},
-- html = { filetypes = { 'html', 'twig', 'hbs'} }
lua_ls = { lua_ls = {
Lua = { Lua = {
workspace = { checkThirdParty = false }, workspace = { checkThirdParty = false },
@ -474,6 +588,70 @@ require('neodev').setup()
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
-- Setup language servers.
local lspconfig = require('lspconfig')
lspconfig.dartls.setup({
cmd = { "dart", "language-server", "--protocol=lsp" },
filetypes = { "dart" },
init_options = {
closingLabels = true,
flutterOutline = true,
onlyAnalyzeProjectsWithOpenFiles = true,
outline = true,
suggestFromUnimportedLibraries = true,
},
-- root_dir = root_pattern("pubspec.yaml"),
settings = {
dart = {
completeFunctionCalls = true,
showTodos = true,
},
},
on_attach = function(client, bufnr)
end,
})
-- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<space>f', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})
-- Ensure the servers above are installed -- Ensure the servers above are installed
local mason_lspconfig = require 'mason-lspconfig' local mason_lspconfig = require 'mason-lspconfig'
@ -492,6 +670,30 @@ mason_lspconfig.setup_handlers {
end end
} }
require("lspconfig").dartls.setup({
cmd = { "dart", "language-server", "--protocol=lsp" },
filetypes = { "dart" },
init_options = {
closingLabels = true,
flutterOutline = true,
onlyAnalyzeProjectsWithOpenFiles = true,
outline = true,
suggestFromUnimportedLibraries = true,
},
-- root_dir = root_pattern("pubspec.yaml"),
settings = {
dart = {
completeFunctionCalls = true,
showTodos = true,
},
},
on_attach = function(client, bufnr)
end,
})
require("telescope").load_extension("flutter")
-- [[ Configure nvim-cmp ]] -- [[ Configure nvim-cmp ]]
-- See `:help cmp` -- See `:help cmp`
local cmp = require 'cmp' local cmp = require 'cmp'
@ -541,4 +743,25 @@ cmp.setup {
} }
-- The line beneath this is called `modeline`. See `:help modeline` -- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et -- vim: ts=2 sts=2 sw=2 etc
require('onedark').setup {
colors = {
bright_orange = "#ff8800", -- define a new color
green = '#00ffaa', -- redefine an existing color
},
highlights = {
-- ["@keyword"] = { fg = '$green' },
["@string"] = { fmt = 'bold,italic', fg = '$orange' },
["@function"] = { sp = '$yellow' },
["@function.builtin"] = { fg = '#0059ff' },
["@parameter"] = { fg = '$cyan' },
["@variable.builtin"] = { fg = '#00ffff' },
["@type.builtin"] = { fg = '#00ffff' },
-- ["@constant"] = { fg = '$purple' }
-- ["@constant"] = { fg = '$purple' }
-- ["@constant.builtin"] = { fg = '$purple' }
-- ["@type"] = { fg = '$purple' }
}
}
require('onedark').load()

View File

@ -0,0 +1,17 @@
-- File: lua/custom/plugins/autopairs.lua
return {
"windwp/nvim-autopairs",
-- Optional dependency
dependencies = { 'hrsh7th/nvim-cmp' },
config = function()
require("nvim-autopairs").setup {}
-- If you want to automatically add `(` after selecting a function or method
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local cmp = require('cmp')
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done()
)
end,
}

View File

@ -28,7 +28,7 @@ return {
end, end,
}, },
}, },
config = function () config = function()
require('neo-tree').setup { require('neo-tree').setup {
close_if_last_window = false, -- Close Neo-tree if it is the last window left in the tab close_if_last_window = false, -- Close Neo-tree if it is the last window left in the tab
popup_border_style = "rounded", popup_border_style = "rounded",
@ -37,7 +37,7 @@ return {
enable_normal_mode_for_inputs = false, -- Enable normal mode for input dialogs. enable_normal_mode_for_inputs = false, -- Enable normal mode for input dialogs.
open_files_do_not_replace_types = { "terminal", "trouble", "qf" }, -- when opening files, do not use windows containing these filetypes or buftypes open_files_do_not_replace_types = { "terminal", "trouble", "qf" }, -- when opening files, do not use windows containing these filetypes or buftypes
sort_case_insensitive = false, -- used when sorting files and directories in the tree sort_case_insensitive = false, -- used when sorting files and directories in the tree
sort_function = nil , -- use a custom function for sorting files and directories in the tree sort_function = nil, -- use a custom function for sorting files and directories in the tree
-- sort_function = function (a,b) -- sort_function = function (a,b)
-- if a.type == b.type then -- if a.type == b.type then
-- return a.path > b.path -- return a.path > b.path
@ -86,8 +86,8 @@ return {
-- Change type -- Change type
added = "", -- or "✚", but this is redundant info if you use git_status_colors on the name added = "", -- or "✚", but this is redundant info if you use git_status_colors on the name
modified = "", -- or "", but this is redundant info if you use git_status_colors on the name modified = "", -- or "", but this is redundant info if you use git_status_colors on the name
deleted = "",-- this can only be used in the git_status source deleted = "", -- this can only be used in the git_status source
renamed = "󰁕",-- this can only be used in the git_status source renamed = "󰁕", -- this can only be used in the git_status source
-- Status type -- Status type
untracked = "", untracked = "",
ignored = "", ignored = "",
@ -184,7 +184,7 @@ return {
nesting_rules = {}, nesting_rules = {},
filesystem = { filesystem = {
filtered_items = { filtered_items = {
visible = false, -- when true, they will just be displayed differently than normal items visible = true, -- when true, they will just be displayed differently than normal items
hide_dotfiles = true, hide_dotfiles = true,
hide_gitignored = true, hide_gitignored = true,
hide_hidden = true, -- only works on Windows for hidden files/directories hide_hidden = true, -- only works on Windows for hidden files/directories
@ -207,7 +207,7 @@ return {
}, },
}, },
follow_current_file = { follow_current_file = {
enabled = false, -- This will find and focus the file in the active buffer every time enabled = true, -- This will find and focus the file in the active buffer every time
-- -- the current file is changed while the tree is open. -- -- the current file is changed while the tree is open.
leave_dirs_open = false, -- `false` closes auto expanded dirs, such as with `:Neotree reveal` leave_dirs_open = false, -- `false` closes auto expanded dirs, such as with `:Neotree reveal`
}, },
@ -232,7 +232,7 @@ return {
["<c-x>"] = "clear_filter", ["<c-x>"] = "clear_filter",
["[g"] = "prev_git_modified", ["[g"] = "prev_git_modified",
["]g"] = "next_git_modified", ["]g"] = "next_git_modified",
["o"] = { "show_help", nowait=false, config = { title = "Order by", prefix_key = "o" }}, ["o"] = { "show_help", nowait = false, config = { title = "Order by", prefix_key = "o" } },
["oc"] = { "order_by_created", nowait = false }, ["oc"] = { "order_by_created", nowait = false },
["od"] = { "order_by_diagnostics", nowait = false }, ["od"] = { "order_by_diagnostics", nowait = false },
["og"] = { "order_by_git_status", nowait = false }, ["og"] = { "order_by_git_status", nowait = false },
@ -264,7 +264,7 @@ return {
["bd"] = "buffer_delete", ["bd"] = "buffer_delete",
["<bs>"] = "navigate_up", ["<bs>"] = "navigate_up",
["."] = "set_root", ["."] = "set_root",
["o"] = { "show_help", nowait=false, config = { title = "Order by", prefix_key = "o" }}, ["o"] = { "show_help", nowait = false, config = { title = "Order by", prefix_key = "o" } },
["oc"] = { "order_by_created", nowait = false }, ["oc"] = { "order_by_created", nowait = false },
["od"] = { "order_by_diagnostics", nowait = false }, ["od"] = { "order_by_diagnostics", nowait = false },
["om"] = { "order_by_modified", nowait = false }, ["om"] = { "order_by_modified", nowait = false },
@ -285,7 +285,7 @@ return {
["gc"] = "git_commit", ["gc"] = "git_commit",
["gp"] = "git_push", ["gp"] = "git_push",
["gg"] = "git_commit_and_push", ["gg"] = "git_commit_and_push",
["o"] = { "show_help", nowait=false, config = { title = "Order by", prefix_key = "o" }}, ["o"] = { "show_help", nowait = false, config = { title = "Order by", prefix_key = "o" } },
["oc"] = { "order_by_created", nowait = false }, ["oc"] = { "order_by_created", nowait = false },
["od"] = { "order_by_diagnostics", nowait = false }, ["od"] = { "order_by_diagnostics", nowait = false },
["om"] = { "order_by_modified", nowait = false }, ["om"] = { "order_by_modified", nowait = false },

View File

@ -0,0 +1,9 @@
return {
"folke/trouble.nvim",
dependencies = { "nvim-tree/nvim-web-devicons" },
opts = {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
},
}