Keymaps for autocomplete, Setup of Format plugin, Tabs and etc
This commit is contained in:
parent
7f4114cb84
commit
e7db0d487f
140
init.lua
140
init.lua
|
@ -154,6 +154,12 @@ vim.opt.cursorline = true
|
|||
-- Minimal number of screen lines to keep above and below the cursor.
|
||||
vim.opt.scrolloff = 10
|
||||
|
||||
-- Глобальные настройки табуляции
|
||||
vim.o.tabstop = 2
|
||||
vim.o.shiftwidth = 2
|
||||
vim.o.expandtab = true
|
||||
vim.o.softtabstop = 2
|
||||
|
||||
-- [[ Basic Keymaps ]]
|
||||
-- See `:help vim.keymap.set()`
|
||||
|
||||
|
@ -161,6 +167,10 @@ vim.opt.scrolloff = 10
|
|||
vim.opt.hlsearch = true
|
||||
vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
|
||||
|
||||
-- Move highlighted blocks with J and K
|
||||
vim.keymap.set('v', 'J', ":m '>+1<CR>gv=gv")
|
||||
vim.keymap.set('v', 'K', ":m '<-2<CR>gv=gv")
|
||||
|
||||
-- Diagnostic keymaps
|
||||
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' })
|
||||
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' })
|
||||
|
@ -662,6 +672,9 @@ require('lazy').setup({
|
|||
end,
|
||||
formatters_by_ft = {
|
||||
lua = { 'stylua' },
|
||||
python = { 'isort', 'black' },
|
||||
cpp = { 'clang-format' },
|
||||
texlab = { 'latexindent' },
|
||||
-- Conform can also run multiple formatters sequentially
|
||||
-- python = { "isort", "black" },
|
||||
--
|
||||
|
@ -714,6 +727,12 @@ require('lazy').setup({
|
|||
local luasnip = require 'luasnip'
|
||||
luasnip.config.setup {}
|
||||
|
||||
local has_words_before = function()
|
||||
unpack = unpack or table.unpack
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil
|
||||
end
|
||||
|
||||
cmp.setup {
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
|
@ -726,53 +745,90 @@ require('lazy').setup({
|
|||
-- chosen, you will need to read `:help ins-completion`
|
||||
--
|
||||
-- No, but seriously. Please read `:help ins-completion`, it is really good!
|
||||
-- mapping = cmp.mapping.preset.insert {
|
||||
-- -- Select the [n]ext item
|
||||
-- ['<C-n>'] = cmp.mapping.select_next_item(),
|
||||
-- -- Select the [p]revious item
|
||||
-- ['<C-p>'] = cmp.mapping.select_prev_item(),
|
||||
--
|
||||
-- -- Scroll the documentation window [b]ack / [f]orward
|
||||
-- ['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||
-- ['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
--
|
||||
-- -- Accept ([y]es) the completion.
|
||||
-- -- This will auto-import if your LSP supports it.
|
||||
-- -- This will expand snippets if the LSP sent a snippet.
|
||||
-- ['<C-y>'] = cmp.mapping.confirm { select = true },
|
||||
--
|
||||
-- -- If you prefer more traditional completion keymaps,
|
||||
-- -- you can uncomment the following lines
|
||||
-- --['<CR>'] = cmp.mapping.confirm { select = true },
|
||||
-- --['<Tab>'] = cmp.mapping.select_next_item(),
|
||||
-- --['<S-Tab>'] = cmp.mapping.select_prev_item(),
|
||||
--
|
||||
-- -- Manually trigger a completion from nvim-cmp.
|
||||
-- -- Generally you don't need this, because nvim-cmp will display
|
||||
-- -- completions whenever it has completion options available.
|
||||
-- ['<C-Space>'] = cmp.mapping.complete {},
|
||||
--
|
||||
-- -- Think of <c-l> as moving to the right of your snippet expansion.
|
||||
-- -- So if you have a snippet that's like:
|
||||
-- -- function $name($args)
|
||||
-- -- $body
|
||||
-- -- end
|
||||
-- --
|
||||
-- -- <c-l> will move you to the right of each of the expansion locations.
|
||||
-- -- <c-h> is similar, except moving you backwards.
|
||||
-- ['<C-l>'] = cmp.mapping(function()
|
||||
-- if luasnip.expand_or_locally_jumpable() then
|
||||
-- luasnip.expand_or_jump()
|
||||
-- end
|
||||
-- end, { 'i', 's' }),
|
||||
-- ['<C-h>'] = cmp.mapping(function()
|
||||
-- if luasnip.locally_jumpable(-1) then
|
||||
-- luasnip.jump(-1)
|
||||
-- end
|
||||
-- end, { 'i', 's' }),
|
||||
--
|
||||
-- -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
|
||||
-- -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
|
||||
-- },
|
||||
|
||||
-- Настройки горячих клавиш для автодополнения от Александра Романова
|
||||
mapping = cmp.mapping.preset.insert {
|
||||
-- Select the [n]ext item
|
||||
['<C-n>'] = cmp.mapping.select_next_item(),
|
||||
-- Select the [p]revious item
|
||||
['<C-p>'] = cmp.mapping.select_prev_item(),
|
||||
|
||||
-- Прямой пробег по списку автодополнений
|
||||
['<Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif luasnip.expand_or_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
elseif has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
|
||||
-- Обратный пробег по списку автодополнений
|
||||
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
|
||||
-- Отмена автодополнения
|
||||
['<C-e>'] = cmp.mapping.abort(),
|
||||
-- Подтверждение автодополнения
|
||||
['<CR>'] = cmp.mapping.confirm { select = true },
|
||||
|
||||
-- Scroll the documentation window [b]ack / [f]orward
|
||||
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
|
||||
-- Accept ([y]es) the completion.
|
||||
-- This will auto-import if your LSP supports it.
|
||||
-- This will expand snippets if the LSP sent a snippet.
|
||||
['<C-y>'] = cmp.mapping.confirm { select = true },
|
||||
|
||||
-- If you prefer more traditional completion keymaps,
|
||||
-- you can uncomment the following lines
|
||||
--['<CR>'] = cmp.mapping.confirm { select = true },
|
||||
--['<Tab>'] = cmp.mapping.select_next_item(),
|
||||
--['<S-Tab>'] = cmp.mapping.select_prev_item(),
|
||||
|
||||
-- Manually trigger a completion from nvim-cmp.
|
||||
-- Generally you don't need this, because nvim-cmp will display
|
||||
-- completions whenever it has completion options available.
|
||||
['<C-Space>'] = cmp.mapping.complete {},
|
||||
|
||||
-- Think of <c-l> as moving to the right of your snippet expansion.
|
||||
-- So if you have a snippet that's like:
|
||||
-- function $name($args)
|
||||
-- $body
|
||||
-- end
|
||||
--
|
||||
-- <c-l> will move you to the right of each of the expansion locations.
|
||||
-- <c-h> is similar, except moving you backwards.
|
||||
['<C-l>'] = cmp.mapping(function()
|
||||
if luasnip.expand_or_locally_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
['<C-h>'] = cmp.mapping(function()
|
||||
if luasnip.locally_jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
|
||||
-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
|
||||
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
|
||||
},
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
|
|
Loading…
Reference in New Issue