Created
December 22, 2023 12:39
-
-
Save pskrgag/c4544ecfc0b19994e3f8c4a2827be7e6 to your computer and use it in GitHub Desktop.
nvim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('plugins') | |
require('gitsigns').setup() | |
require('lualine').setup() | |
require('nvim_comment').setup() | |
require('hop').setup() | |
require("mason").setup() | |
require("mason-lspconfig").setup() | |
vim.cmd.colorscheme "catppuccin" | |
require("catppuccin").setup({ | |
flavour = "macchiato", -- latte, frappe, macchiato, mocha | |
}) | |
require'lspconfig'.pyright.setup{} | |
-- disable netrw at the very start of your init.lua | |
vim.g.loaded_netrw = 1 | |
vim.g.loaded_netrwPlugin = 1 | |
-- set termguicolors to enable highlight groups | |
vim.opt.termguicolors = true | |
vim.opt.list = true | |
vim.opt.listchars:append { | |
space = '·', | |
trail = '·', | |
extends = '❯', | |
precedes = '❮', | |
} | |
-- empty setup using defaults | |
require("nvim-tree").setup{ | |
renderer = { | |
icons ={ | |
show = { | |
file = false, | |
git = false, | |
} | |
} | |
} | |
} | |
-- CONFIG | |
vim.o.breakindent = true | |
vim.o.inccommand = 'nosplit' | |
vim.wo.number = true | |
vim.wo.relativenumber = true | |
vim.opt.cursorline = true | |
vim.opt.cursorcolumn = true | |
-- APPEARENCE | |
vim.o.termguicolors = true | |
vim.o.background = "dark" | |
-- KEYBOARD | |
local function map(mode, lhs, rhs, opts) | |
local options = {noremap = true} | |
if opts then options = vim.tbl_extend('force', options, opts) end | |
vim.api.nvim_set_keymap(mode, lhs, rhs, options) | |
end | |
-- Files in current directory | |
vim.keymap.set("n", "<c-P>", | |
"<cmd>lua require('fzf-lua').files()<CR>", { silent = true }) | |
map('n', '<F2>', '<cmd>NvimTreeToggle<CR>') | |
map('i', '<F2>', '<cmd>NvimTreeToggle<CR>') | |
vim.api.nvim_create_autocmd("BufEnter", { | |
nested = true, | |
callback = function() | |
if #vim.api.nvim_list_wins() == 1 and require("nvim-tree.utils").is_nvim_tree_buf() then | |
vim.cmd "quit" | |
end | |
end | |
}) | |
-- place this in one of your configuration file(s) | |
local hop = require('hop') | |
local directions = require('hop.hint').HintDirection | |
vim.keymap.set('', 'W', function() | |
hop.hint_words() | |
end, {remap=true}) | |
vim.keymap.set('', 'B', function() | |
hop.hint_words({ current_line_only = true, direction = require'hop.hint'.HintDirection.BEFORE_CURSOR }) | |
end, {remap=true}) | |
vim.keymap.set('', 'm', function() | |
require('mywords').hl_toggle() | |
end, {remap=true}) | |
vim.keymap.set('', 'C', function() | |
require('mywords').uhl_all() | |
end, {remap=true}) | |
-- LSP | |
local lspconfig = require('lspconfig') | |
lspconfig.rust_analyzer.setup { | |
-- Server-specific settings. See `:help lspconfig-setup` | |
settings = { | |
['rust-analyzer'] = {}, | |
}, | |
} | |
lspconfig.clangd.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, | |
}) | |
local sign = function(opts) | |
vim.fn.sign_define(opts.name, { | |
texthl = opts.name, | |
text = opts.text, | |
numhl = '' | |
}) | |
end | |
sign({name = 'DiagnosticSignError', text = ''}) | |
sign({name = 'DiagnosticSignWarn', text = ''}) | |
sign({name = 'DiagnosticSignHint', text = ''}) | |
sign({name = 'DiagnosticSignInfo', text = ''}) | |
vim.o.updatetime = 100 | |
vim.diagnostic.config({ | |
virtual_text = false, | |
signs = true, | |
update_in_insert = true, | |
underline = true, | |
severity_sort = false, | |
-- float = { | |
-- border = 'rounded', | |
-- source = 'always', | |
-- header = '', | |
-- prefix = '', | |
-- }, | |
}) | |
vim.cmd([[ | |
set signcolumn=yes | |
autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) | |
]]) | |
local cmp = require'cmp' | |
cmp.setup({ | |
-- Enable LSP snippets | |
snippet = { | |
expand = function(args) | |
vim.fn["vsnip#anonymous"](args.body) | |
end, | |
}, | |
mapping = { | |
['<C-p>'] = cmp.mapping.select_prev_item(), | |
['<C-n>'] = cmp.mapping.select_next_item(), | |
-- Add tab support | |
['<S-Tab>'] = cmp.mapping.select_prev_item(), | |
['<Tab>'] = cmp.mapping.select_next_item(), | |
['<C-S-f>'] = cmp.mapping.scroll_docs(-4), | |
['<C-f>'] = cmp.mapping.scroll_docs(4), | |
['<C-Space>'] = cmp.mapping.complete(), | |
['<C-e>'] = cmp.mapping.close(), | |
['<CR>'] = cmp.mapping.confirm({ | |
behavior = cmp.ConfirmBehavior.Insert, | |
select = true, | |
}) | |
}, | |
-- Installed sources: | |
sources = { | |
{ name = 'path' }, -- file paths | |
{ name = 'nvim_lsp', keyword_length = 3 }, -- from language server | |
{ name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized | |
{ name = 'nvim_lua', keyword_length = 2}, -- complete neovim's Lua runtime API such vim.lsp.* | |
{ name = 'buffer', keyword_length = 2 }, -- source current buffer | |
{ name = 'vsnip', keyword_length = 2 }, -- nvim-cmp source for vim-vsnip | |
{ name = 'calc'}, -- source for math calculation | |
}, | |
window = { | |
completion = cmp.config.window.bordered(), | |
documentation = cmp.config.window.bordered(), | |
}, | |
formatting = { | |
fields = {'menu', 'abbr', 'kind'}, | |
format = function(entry, item) | |
local menu_icon ={ | |
nvim_lsp = 'λ', | |
vsnip = '⋗', | |
buffer = 'Ω', | |
path = '🖫', | |
} | |
item.menu = menu_icon[entry.source.name] | |
return item | |
end, | |
}, | |
}) | |
local builtin = require('telescope.builtin') | |
vim.keymap.set('n', '<C-f>', builtin.grep_string, {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment