From 0f55d7e47d04ace0743c4ce856af0fad607f0430 Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Fri, 25 Apr 2025 02:42:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20zshrc=20=D0=B8=20neovim?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nvim/init.lua | 1 + nvim/lua/autocommands.lua | 34 ++++----- nvim/lua/colors.lua | 39 ++++++++++ nvim/lua/keymaps.lua | 25 +++++-- nvim/lua/plugins/init.lua | 32 +------- zsh/zshrc | 149 +++++++++++++++++++------------------- 6 files changed, 151 insertions(+), 129 deletions(-) create mode 100644 nvim/lua/colors.lua diff --git a/nvim/init.lua b/nvim/init.lua index 988f88a..e62059f 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -16,3 +16,4 @@ require("keymaps") require("autocommands") require("lsp") require("dap") +require("colors") diff --git a/nvim/lua/autocommands.lua b/nvim/lua/autocommands.lua index ef7353f..d9edd27 100644 --- a/nvim/lua/autocommands.lua +++ b/nvim/lua/autocommands.lua @@ -76,24 +76,6 @@ vim.api.nvim_create_autocmd({ "BufReadPost", "FileReadPost" }, { end, }) -vim.api.nvim_create_autocmd("BufEnter", { - pattern = "*", - callback = function() - vim.defer_fn(function() - vim.cmd("normal! zR") - end, 100) - end, -}) - -vim.api.nvim_create_autocmd("BufWinEnter", { - pattern = "*", - callback = function() - vim.schedule(function() - vim.cmd("normal! zR") - end) - end, -}) - vim.api.nvim_create_autocmd("BufEnter", { callback = function() if vim.bo.filetype == "NvimTree" or vim.fn.expand("%") == "" then @@ -117,6 +99,22 @@ vim.api.nvim_create_autocmd({ "BufWritePost" }, { end, }) +-- Автоматический вход в insert mode при открытии терминала +vim.api.nvim_create_autocmd({ "BufWinEnter", "WinEnter" }, { + pattern = "term://*", + callback = function() + vim.cmd("startinsert") + end, +}) + +-- Автоматический выход из insert mode при уходе с терминала +vim.api.nvim_create_autocmd("BufLeave", { + pattern = "term://*", + callback = function() + vim.cmd("stopinsert") + end, +}) + -- vim.api.nvim_create_autocmd("InsertEnter", { -- pattern = "*", -- command = "set norelativenumber", diff --git a/nvim/lua/colors.lua b/nvim/lua/colors.lua new file mode 100644 index 0000000..e5d90ef --- /dev/null +++ b/nvim/lua/colors.lua @@ -0,0 +1,39 @@ +require("onedark").setup({ + style = "darker", + transparent = false, -- Show/hide background + term_colors = true, -- Change terminal color as per the selected theme style + ending_tildes = true, -- Show the end-of-buffer tildes. By default they are hidden + cmp_itemkind_reverse = false, -- reverse item kind highlights in cmp menu + + -- toggle theme style --- + toggle_style_key = nil, -- keybind to toggle theme style. Leave it nil to disable it, or set it to a string, for example "ts" + toggle_style_list = { "dark", "darker", "cool", "deep", "warm", "warmer", "light" }, -- List of styles to toggle between + + -- Change code style --- + -- Options are italic, bold, underline, none + -- You can configure multiple style with comma separated, For e.g., keywords = 'italic,bold' + code_style = { + comments = "italic", + keywords = "none", + functions = "none", + strings = "none", + variables = "none", + }, + + -- Lualine options -- + lualine = { + transparent = false, -- lualine center bar transparency + }, + + -- Custom Highlights -- + colors = {}, -- Override default colors + highlights = {}, -- Override highlight groups + + -- Plugins Config -- + diagnostics = { + darker = true, -- darker colors for diagnostic + undercurl = true, -- use undercurl instead of underline for diagnostics + background = true, -- use background color for virtual text + }, +}) +require("onedark").load() diff --git a/nvim/lua/keymaps.lua b/nvim/lua/keymaps.lua index 6a1640d..455e5fd 100644 --- a/nvim/lua/keymaps.lua +++ b/nvim/lua/keymaps.lua @@ -15,13 +15,19 @@ map("i", "", "$", { noremap = true, silent = true }) -- Фикс для визуального режима map("v", "i", "", { noremap = true, silent = true }) map("v", "a", "", { noremap = true, silent = true }) +map("v", "J", ":m '>+1gv=gv", { noremap = true, silent = true }) +map("v", "K", ":m '<-2gv=gv", { noremap = true, silent = true }) +map("v", "<", "", ">gv", { noremap = true, silent = true }) -- Управление буферами -- kmap("n", "bn", "bnext", { noremap = true, silent = true, desc = "Next buffer" }) kmap("n", "bp", "bprevious", { noremap = true, silent = true, desc = "Previous buffer" }) kmap("n", "bd", "bdelete", { noremap = true, silent = true, desc = "Delete buffer" }) kmap("n", "w", "wa", { noremap = true, silent = true, desc = "Save all files" }) -kmap("n", "qq", "q") +kmap("n", "qq", "q", { noremap = true, silent = true, desc = "Exit" }) +kmap("n", "vs", "vsplit", { noremap = true, silent = true, desc = "Vertical split" }) + -- Управление вкладками -- kmap("n", "", ":tabnext", { noremap = true, silent = true, desc = "Next tab" }) kmap("n", "", ":tabprevious", { noremap = true, silent = true, desc = "Previous tab" }) @@ -35,19 +41,20 @@ end -- Файловый менеджер -- kmap("n", "", ":NvimTreeToggle", { noremap = true, silent = true, desc = "Toggle file tree" }) -kmap("n", "tt", ":NvimTreeToggle", { noremap = true, silent = true, desc = "Toggle file tree" }) +-- kmap("n", "tt", ":NvimTreeToggle", { noremap = true, silent = true, desc = "Toggle file tree" }) +kmap("n", "tt", ":split:terminal:startinsert", { noremap = true, silent = true }) -- Поиск с Telescope -- kmap("n", "ff", "Telescope find_files", { noremap = true, silent = true, desc = "Find files" }) kmap("n", "fg", "Telescope live_grep", { noremap = true, silent = true, desc = "Live grep" }) kmap("n", "fb", "Telescope buffers", { noremap = true, silent = true, desc = "Find buffers" }) +kmap("n", "fe", "Telescope file_browser", { noremap = true, silent = true, desc = "File browser" }) -- LSP функции -- kmap("n", "e", vim.diagnostic.open_float, { noremap = true, silent = true, desc = "Show diagnostics" }) -kmap("n", "[d", vim.diagnostic.goto_prev, { noremap = true, silent = true, desc = "Previous diagnostic" }) -kmap("n", "]d", vim.diagnostic.goto_next, { noremap = true, silent = true, desc = "Next diagnostic" }) -kmap("n", "q", vim.diagnostic.setloclist, { noremap = true, silent = true, desc = "Add to location list" }) +kmap("n", "d[", vim.diagnostic.goto_prev, { noremap = true, silent = true, desc = "Previous diagnostic" }) +kmap("n", "d]", vim.diagnostic.goto_next, { noremap = true, silent = true, desc = "Next diagnostic" }) kmap("n", "gD", vim.lsp.buf.declaration, { noremap = true, silent = true, desc = "Go to declaration" }) kmap("n", "gd", vim.lsp.buf.definition, { noremap = true, silent = true, desc = "Go to definition" }) @@ -88,7 +95,12 @@ end) kmap("n", "", function() require("dap").step_out() end) -kmap("n", "dt", "lua require'dapui'.toggle()", { noremap = true, silent = true, desc = "Toggle debug UI" }) +kmap( + "n", + "dt", + "lua require'dapui'.toggle()", + { noremap = true, silent = true, desc = "Toggle debug UI" } +) kmap("n", "dc", function() require("dap").continue() end) @@ -102,7 +114,6 @@ kmap("n", "st", function() require("dap").step_out() end) - kmap("n", "b", function() require("dap").toggle_breakpoint() end) diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua index b27e33f..0c3e6a5 100644 --- a/nvim/lua/plugins/init.lua +++ b/nvim/lua/plugins/init.lua @@ -3,15 +3,7 @@ return require("packer").startup({ use("wbthomason/packer.nvim") use("nvim-lua/plenary.nvim") use("neovim/nvim-lspconfig") - use({ - "srt0/codescope.nvim", - config = function() - require("codescope").setup({ - transparent = false, -- Set to true for transparency - }) - vim.cmd.colorscheme("codescope") - end, - }) + use("navarasu/onedark.nvim") use("Snyssfx/goerr-nvim") use({ "lukas-reineke/indent-blankline.nvim", @@ -22,26 +14,6 @@ return require("packer").startup({ use({ "rcarriga/nvim-dap-ui", requires = { "mfussenegger/nvim-dap", "nvim-neotest/nvim-nio" }, - config = function() - local dap, dapui = require("dap"), require("dapui") - dapui.setup() - dap.listeners.before.attach.dapui_config = function() - dapui.open() - vim.cmd(":NvimTreeClose") - end - dap.listeners.before.launch.dapui_config = function() - dapui.open() - vim.cmd(":NvimTreeClose") - end - dap.listeners.before.event_terminated.dapui_config = function() - dapui.close() - vim.cmd(":NvimTreeOpen") - end - dap.listeners.before.event_exited.dapui_config = function() - dapui.close() - vim.cmd(":NvimTreeOpen") - end - end, }) use({ "leoluz/nvim-dap-go", @@ -76,11 +48,13 @@ return require("packer").startup({ require("plugins.treesitter") end, }) + use({ "nvim-telescope/telescope-file-browser.nvim" }) use({ "nvim-telescope/telescope.nvim", config = function() require("plugins.telescope") end, + requires = "nvim-lua/plenary.nvim", }) use({ "nvim-tree/nvim-tree.lua", diff --git a/zsh/zshrc b/zsh/zshrc index 65a8c80..c480aac 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -49,7 +49,7 @@ alias cp="cp -i" alias gitpush="git add . && git commit --amend --no-edit && git push -f" alias yu="ssh-add -e /usr/lib/x86_64-linux-gnu/libykcs11.so; ssh-add -s /usr/lib/x86_64-linux-gnu/libykcs11.so" alias n="nvim" -alias n.="nvim ." +alias nv="nvim ." alias cp="cp -i" alias df="df -h" alias free="free -m" @@ -104,14 +104,84 @@ WORDCHARS=${WORDCHARS//\/[&.;]} autoload -U compinit colors zcalc compinit -d +# Runs before showing the prompt +function mzc_termsupport_precmd { + [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return + title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE +} + +# Runs before executing the command +function mzc_termsupport_preexec { + [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return + + emulate -L zsh + + # split command into array of arguments + local -a cmdargs + cmdargs=("${(z)2}") + # if running fg, extract the command from the job description + if [[ "${cmdargs[1]}" = fg ]]; then + # get the job id from the first argument passed to the fg command + local job_id jobspec="${cmdargs[2]#%}" + # logic based on jobs arguments: + # http://zsh.sourceforge.net/Doc/Release/Jobs-_0026-Signals.html#Jobs + # https://www.zsh.org/mla/users/2007/msg00704.html + case "$jobspec" in + <->) # %number argument: + # use the same passed as an argument + job_id=${jobspec} ;; + ""|%|+) # empty, %% or %+ argument: + # use the current job, which appears with a + in $jobstates: + # suspended:+:5071=suspended (tty output) + job_id=${(k)jobstates[(r)*:+:*]} ;; + -) # %- argument: + # use the previous job, which appears with a - in $jobstates: + # suspended:-:6493=suspended (signal) + job_id=${(k)jobstates[(r)*:-:*]} ;; + [?]*) # %?string argument: + # use $jobtexts to match for a job whose command *contains* + job_id=${(k)jobtexts[(r)*${(Q)jobspec}*]} ;; + *) # %string argument: + # use $jobtexts to match for a job whose command *starts with* + job_id=${(k)jobtexts[(r)${(Q)jobspec}*]} ;; + esac + + # override preexec function arguments with job command + if [[ -n "${jobtexts[$job_id]}" ]]; then + 1="${jobtexts[$job_id]}" + 2="${jobtexts[$job_id]}" + fi + fi + + # cmd name only, or if this is sudo or ssh, the next cmd + local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%} + local LINE="${2:gs/%/%%}" + + title '$CMD' '%100>...>$LINE%<<' +} + +# Emits the control sequence to notify many terminal emulators +# of the cwd +# +# Identifies the directory using a file: URI scheme, including +# the host name to disambiguate local vs. remote paths. +function mzc_termsupport_cwd { + # Percent-encode the host and path names. + local URL_HOST URL_PATH + URL_HOST="$(zsh_urlencode -P $HOST)" || return 1 + URL_PATH="$(zsh_urlencode -P $PWD)" || return 1 + + # common control sequence (OSC 7) to set current host and path + printf "\e]7;%s\a" "file://${URL_HOST}${URL_PATH}" +} autoload -U add-zsh-hook -#add-zsh-hook precmd mzc_termsupport_precmd -#add-zsh-hook preexec mzc_termsupport_preexec +add-zsh-hook precmd mzc_termsupport_precmd +add-zsh-hook preexec mzc_termsupport_preexec # Use a precmd hook instead of a chpwd hook to avoid contaminating output # i.e. when a script or function changes directory without `cd -q`, chpwd # will be called the output may be swallowed by the script or function. -#add-zsh-hook precmd mzc_termsupport_cwd +add-zsh-hook precmd mzc_termsupport_cwd source ~/.config/zsh/conf.d/*.zsh @@ -223,62 +293,6 @@ function title { ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD ZSH_THEME_TERM_TITLE_IDLE="%n@%m:%~" -# Runs before showing the prompt -function mzc_termsupport_precmd { - [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return - title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE -} - -# Runs before executing the command -function mzc_termsupport_preexec { - [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return - - emulate -L zsh - - # split command into array of arguments - local -a cmdargs - cmdargs=("${(z)2}") - # if running fg, extract the command from the job description - if [[ "${cmdargs[1]}" = fg ]]; then - # get the job id from the first argument passed to the fg command - local job_id jobspec="${cmdargs[2]#%}" - # logic based on jobs arguments: - # http://zsh.sourceforge.net/Doc/Release/Jobs-_0026-Signals.html#Jobs - # https://www.zsh.org/mla/users/2007/msg00704.html - case "$jobspec" in - <->) # %number argument: - # use the same passed as an argument - job_id=${jobspec} ;; - ""|%|+) # empty, %% or %+ argument: - # use the current job, which appears with a + in $jobstates: - # suspended:+:5071=suspended (tty output) - job_id=${(k)jobstates[(r)*:+:*]} ;; - -) # %- argument: - # use the previous job, which appears with a - in $jobstates: - # suspended:-:6493=suspended (signal) - job_id=${(k)jobstates[(r)*:-:*]} ;; - [?]*) # %?string argument: - # use $jobtexts to match for a job whose command *contains* - job_id=${(k)jobtexts[(r)*${(Q)jobspec}*]} ;; - *) # %string argument: - # use $jobtexts to match for a job whose command *starts with* - job_id=${(k)jobtexts[(r)${(Q)jobspec}*]} ;; - esac - - # override preexec function arguments with job command - if [[ -n "${jobtexts[$job_id]}" ]]; then - 1="${jobtexts[$job_id]}" - 2="${jobtexts[$job_id]}" - fi - fi - - # cmd name only, or if this is sudo or ssh, the next cmd - local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%} - local LINE="${2:gs/%/%%}" - - title '$CMD' '%100>...>$LINE%<<' -} - # URL-encode a string # # Encodes a string using RFC 2396 URL-encoding (%-escaped). @@ -352,21 +366,6 @@ function zsh_urlencode() { echo -E "$url_str" } -# Emits the control sequence to notify many terminal emulators -# of the cwd -# -# Identifies the directory using a file: URI scheme, including -# the host name to disambiguate local vs. remote paths. -function mzc_termsupport_cwd { - # Percent-encode the host and path names. - local URL_HOST URL_PATH - URL_HOST="$(zsh_urlencode -P $HOST)" || return 1 - URL_PATH="$(zsh_urlencode -P $PWD)" || return 1 - - # common control sequence (OSC 7) to set current host and path - printf "\e]7;%s\a" "file://${URL_HOST}${URL_PATH}" -} - if [ -f env.sh ]; then source ./env.sh fi