diff --git a/install.sh b/install.sh index f3bcaec..1059380 100755 --- a/install.sh +++ b/install.sh @@ -2,21 +2,25 @@ # Инициализация текста сообщений в зависимости от установленного языка в оболочке if test (string match -ri "ru" "$LANG") - function print -a TYPE PARAM1 PARAM2 -d "Вывод сообщений по категориям" + function print -a TYPE PARAM1 PARAM2 -d "Текст сообщений" switch $TYPE case REPOSITORY_EXISTS - set_color yellow; echo -n "[mirzaev/nvim] "; set_color blue; echo -n "[ЗАДАЧА] "; set_color white; echo "Репозиторий \"wbthomason/packer.nvim\" уже существует. Переустановить? (y/N)"; + set_color yellow; echo -n "[mirzaev/nvim] "; set_color blue; echo -n "[ЗАДАЧА] "; set_color white; echo "Репозиторий \"wbthomason/packer.nvim\" уже существует. Переустановить? (y/N) "; case REPOSITORY_CREATED set_color yellow; echo -n "[mirzaev/nvim] "; set_color green; echo -n "[РАБОТА] "; set_color white; echo "Репозиторий \"wbthomason/packer.nvim\" установлен"; + case FORMATTER_NGINX_INSTALL + set_color yellow; echo -n "[mirzaev/nvim] "; set_color blue; echo -n "[ЗАДАЧА] "; set_color white; echo "Установить форматировщик для NGINX? (\"vasilevich/nginxbeautifier\") (y/N) "; end end else - function print -a TYPE PARAM1 PARAM2 -d "Display messages by category" + function print -a TYPE PARAM1 PARAM2 -d "Messages text" switch $TYPE case REPOSITORY_EXISTS - set_color yellow; echo -n "[mirzaev/nvim] "; set_color blue; echo -n "[TASK] "; set_color white; echo "The \"wbthomason/packer.nvim\" repository already exists. Reinstall? (y/N)"; + set_color yellow; echo -n "[mirzaev/nvim] "; set_color blue; echo -n "[TASK] "; set_color white; echo "The \"wbthomason/packer.nvim\" repository already exists. Reinstall? (y/N) "; case REPOSITORY_CREATED - set_color yellow; echo -n "[mirzaev/nvim] "; set_color green; echo -n "[РАБОТА] "; set_color white; echo "Repository \"wbthomason/packer.nvim\" installed"; + set_color yellow; echo -n "[mirzaev/nvim] "; set_color green; echo -n "[WORK] "; set_color white; echo "Repository \"wbthomason/packer.nvim\" installed"; + case FORMATTER_NGINX_INSTALL + set_color yellow; echo -n "[mirzaev/nvim] "; set_color blue; echo -n "[TASK] "; set_color white; echo "Install the formatter for NGINX? (\"vasilevich/nginxbeautifier\") (y/N) "; end end end @@ -49,3 +53,15 @@ else print REPOSITORY_CREATED end + +# Запрос выбора действия с репозиторием +set RESPONSE (read -n 1 -p "print FORMATTER_NGINX_INSTALL") +bind -e y + +if test (string match -ri 'y' "$RESPONSE") + # Запрошена установка 'vasilevich/nginxbeautifier' + + # Установка + npm install -g nginxbeautifier +end + diff --git a/lua/keymaps/plugins.lua b/lua/keymaps/plugins.lua index 4055385..5423781 100644 --- a/lua/keymaps/plugins.lua +++ b/lua/keymaps/plugins.lua @@ -15,7 +15,7 @@ vim.keymap.set('n', 'd0', 'lua require(\'diaglist\').open_buffer_dia --[[ noib3/nvim-cokeline ]] -- Переключение вкладок -vim.keymap.set('n', '', '(cokeline-focus-next)', { noremap = true, silent = true }) +vim.keymap.set('n', '', '(cokeline-focus-next)', { noremap = true, silent = true }) vim.keymap.set('n', '', '(cokeline-focus-prev)', { noremap = true, silent = true }) @@ -28,68 +28,81 @@ vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { noremap = true, sil -- Инициализация только после того, как LSP-сервер подключится к текущему буферу lspconfig_on_attach = function(client, bufnr) - -- Активация завершения - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + -- Активация завершения + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, { noremap = true, silent = true, buffer = bufnr }) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { noremap = true, silent = true, buffer = bufnr }) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, { noremap = true, silent = true, buffer = bufnr }) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { noremap = true, silent = true, buffer = bufnr }) - vim.keymap.set('n', '', vim.lsp.buf.signature_help, { noremap = true, silent = true, buffer = bufnr }) - vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, { noremap = true, silent = true, buffer = bufnr }) - vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, { noremap = true, silent = true, buffer = bufnr }) - vim.keymap.set('n', 'wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, - { noremap = true, silent = true, buffer = bufnr }) - vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, { noremap = true, silent = true, buffer = bufnr }) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, { noremap = true, silent = true, buffer = bufnr }) - vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, { noremap = true, silent = true, buffer = bufnr }) - vim.keymap.set('n', 'gr', vim.lsp.buf.references, { noremap = true, silent = true, buffer = bufnr }) - - -- Форматирование - vim.keymap.set({ 'n', 'v', 't' }, 'F', function() - vim.lsp.buf.format { async = true } - vim.api.nvim_command('PrettierAsync') - end, - { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', 'wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, + { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, { noremap = true, silent = true, buffer = bufnr }) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, { noremap = true, silent = true, buffer = bufnr }) end +-- Formatting +vim.keymap.set({ 'n', 'v', 't' }, 'F', function() + if (vim.bo.filetype == 'nginx') then + -- NGINX configuration file + + vim.api.nvim_exec('w', false) + vim.api.nvim_exec('! nginxbeautifier -i %', false) + vim.api.nvim_exec('redraw', false) + elseif (vim.lsp.buf.server_ready()) then + -- LSP-server is ready + + vim.lsp.buf.format { async = true } + else + -- LSP-server not found + + vim.api.nvim_exec('PrettierAsync', false) + end + end, + { noremap = true, silent = true, buffer = bufnr }) + --[[ lewis6991/gitsigns.nvim ]] -- Инициализация только после того, как LSP-сервер подключится к текущему буферу gitsigns_on_attach = function(bufnr) - -- Инициализация ярлыка - local gs = package.loaded.gitsigns + -- Инициализация ярлыка + local gs = package.loaded.gitsigns - -- Навигация - vim.keymap.set('n', ']c', function() - if vim.wo.diff then return ']c' end - vim.schedule(function() gs.next_hunk() end) - return '' - end, { expr = true, buffer = bufnr }) + -- Навигация + vim.keymap.set('n', ']c', function() + if vim.wo.diff then return ']c' end + vim.schedule(function() gs.next_hunk() end) + return '' + end, { expr = true, buffer = bufnr }) - -- Навигация - vim.keymap.set('n', '[c', function() - if vim.wo.diff then return '[c' end - vim.schedule(function() gs.prev_hunk() end) - return '' - end, { expr = true, buffer = bufnr }) + -- Навигация + vim.keymap.set('n', '[c', function() + if vim.wo.diff then return '[c' end + vim.schedule(function() gs.prev_hunk() end) + return '' + end, { expr = true, buffer = bufnr }) - vim.keymap.set('n', 'hs', 'Gitsigns stage_hunk', { buffer = bufnr }) - vim.keymap.set('v', 'hs', 'Gitsigns stage_hunk', { buffer = bufnr }) - vim.keymap.set('n', 'hr', 'Gitsigns reset_hunk', { buffer = bufnr }) - vim.keymap.set('v', 'hr', 'Gitsigns reset_hunk', { buffer = bufnr }) - vim.keymap.set('n', 'hS', gs.stage_buffer, { buffer = bufnr }) - vim.keymap.set('n', 'hu', gs.undo_stage_hunk, { buffer = bufnr }) - vim.keymap.set('n', 'hR', gs.reset_buffer, { buffer = bufnr }) - vim.keymap.set('n', 'hp', gs.preview_hunk, { buffer = bufnr }) - vim.keymap.set('n', 'hb', function() gs.blame_line { full = true } end, { buffer = bufnr }) - vim.keymap.set('n', 'tb', gs.toggle_current_line_blame, { buffer = bufnr }) - vim.keymap.set('n', 'hd', gs.diffthis, { buffer = bufnr }) - vim.keymap.set('n', 'hD', function() gs.diffthis('~') end, { buffer = bufnr }) - vim.keymap.set('n', 'td', gs.toggle_deleted, { buffer = bufnr }) + vim.keymap.set('n', 'hs', 'Gitsigns stage_hunk', { buffer = bufnr }) + vim.keymap.set('v', 'hs', 'Gitsigns stage_hunk', { buffer = bufnr }) + vim.keymap.set('n', 'hr', 'Gitsigns reset_hunk', { buffer = bufnr }) + vim.keymap.set('v', 'hr', 'Gitsigns reset_hunk', { buffer = bufnr }) + vim.keymap.set('n', 'hS', gs.stage_buffer, { buffer = bufnr }) + vim.keymap.set('n', 'hu', gs.undo_stage_hunk, { buffer = bufnr }) + vim.keymap.set('n', 'hR', gs.reset_buffer, { buffer = bufnr }) + vim.keymap.set('n', 'hp', gs.preview_hunk, { buffer = bufnr }) + vim.keymap.set('n', 'hb', function() gs.blame_line { full = true } end, { buffer = bufnr }) + vim.keymap.set('n', 'tb', gs.toggle_current_line_blame, { buffer = bufnr }) + vim.keymap.set('n', 'hd', gs.diffthis, { buffer = bufnr }) + vim.keymap.set('n', 'hD', function() gs.diffthis('~') end, { buffer = bufnr }) + vim.keymap.set('n', 'td', gs.toggle_deleted, { buffer = bufnr }) - vim.keymap.set('o', 'ih', 'Gitsigns select_hunk', { buffer = bufnr }) - vim.keymap.set('x', 'ih', 'Gitsigns select_hunk', { buffer = bufnr }) + vim.keymap.set('o', 'ih', 'Gitsigns select_hunk', { buffer = bufnr }) + vim.keymap.set('x', 'ih', 'Gitsigns select_hunk', { buffer = bufnr }) end @@ -118,20 +131,20 @@ vim.keymap.set('n', 'fh', builtin.help_tags, { noremap = true, silent = --vim.keymap.set('i', '', [[pumvisible() ? "" : ""]], {expr = true, noremap = true}) _G.PairIT = function() - local autopairs = { - ['('] = ')', - ['['] = ']', - ['{'] = '}', - ['<'] = '>', - [ [=[']=] ] = [=[']=], - [ [=["]=] ] = [=["]=], - } - local set_pairs = vim.keymap.set - for k, v in pairs(autopairs) do - set_pairs('i', k, function() - return k .. v .. '' - end, { expr = true, noremap = true }) - end + local autopairs = { + ['('] = ')', + ['['] = ']', + ['{'] = '}', + ['<'] = '>', + [ [=[']=] ] = [=[']=], + [ [=["]=] ] = [=["]=], + } + local set_pairs = vim.keymap.set + for k, v in pairs(autopairs) do + set_pairs('i', k, function() + return k .. v .. '' + end, { expr = true, noremap = true }) + end end