Skip to content

Instantly share code, notes, and snippets.

@dridk
Last active October 5, 2023 23:08
Show Gist options
  • Save dridk/0ce32046bf06d26a27cd4449d158c40f to your computer and use it in GitHub Desktop.
Save dridk/0ce32046bf06d26a27cd4449d158c40f to your computer and use it in GitHub Desktop.
my nvim
-- MAP KEY
-- CONFIGURATION
vim.opt.number = true
vim.cmd [[colorscheme slate]]
vim.g.mapleader = " "
vim.opt.termguicolors = true
-- Install lazy
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
print(lazypath)
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
"nvim-lua/plenary.nvim",
'nvim-telescope/telescope.nvim', tag = '0.1.3', dependencies = { 'nvim-lua/plenary.nvim' },
'akinsho/bufferline.nvim', version = "*", dependencies = 'nvim-tree/nvim-web-devicons',
'neovim/nvim-lspconfig',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-path',
'hrsh7th/cmp-cmdline',
'hrsh7th/nvim-cmp'
})
require("bufferline").setup({
options = {
indicator_icon = "●",
modified_icon = "☉",
buffer_close_icon=""
}
})
local cmp = require('cmp')
cmp.setup({
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true })}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'buffer' }})
})
local lspconfig = require('lspconfig')
lspconfig.pyright.setup {}
-- 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,
})
-- KEY MAP
vim.keymap.set("n", "<Tab>", ":bnext <CR>")
vim.keymap.set("n", "<C-up>", "<cmd> m .-2<CR>")
vim.keymap.set("n", "<C-down>", "<cmd> m .+1<CR>")
vim.keymap.set("n", "<C-r>", ":%s/<C-r><C-w>//g<left><left>")
vim.keymap.set("n", "<Esc>", "<ESC> :noh <CR>", {remap=true})
vim.keymap.set("v", "<C-S-up>", "dkP`[V`]")
vim.keymap.set("v", "<C-S-down>", "dp`[V`]")
vim.keymap.set("n", "<C-x>", ":bdelete <CR>")
vim.keymap.set("n", "<C-q>", ":q <CR>")
vim.keymap.set("n", "<C-b>", ":!python % <CR>")
vim.keymap.set("n", "<C-a>", "ggVG <CR>")
vim.keymap.set("", "<C-s>", ":w <CR>")
vim.keymap.set("n", "<C-r>", ":! python % <CR>")
vim.keymap.set("n", "source", ":source ~/.config/nvim/init.lua <CR>")
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
vim.keymap.set('n', '<leader>fo', builtin.oldfiles, {})
vim.keymap.set('n', '<leader>r', builtin.lsp_document_symbols, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment