diff --git a/.gitignore b/.gitignore index 4713cc9..af29904 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,10 @@ sub/zsh/plugins sub/bash/bashrc.d/* !sub/bash/bashrc.d/00_test.sh sub/zsh/zshrc.d/* -!sub/zsh/shrc.d/00_test.sh +!sub/zsh/zshrc.d/00_test.sh sub/vim/tmp/ + +sub/nvim/plugin +sub/nvim/tmp/ + +*.zwc diff --git a/README.md b/README.md index 3f46cd7..9a2b772 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ Config files for: * git * ranger * i3 +* vim +* neovim ### Prompt @@ -74,14 +76,12 @@ echo "Hello $USER!" | ,l | Line number styles | | ,c | Highlight cursor line | | ,/ | Toggle search highlight | -| ,`` | Close all without saving | +| ,qq | Delete current buffer | +| ,qa | Close all without saving | | ,t | Tagbar | | ,rr | Run script in new tab (python, go, preview markdown)| -| ,rm | Run script (make run) | -| ,rf | Format file (go) | -| ,nn | Toggle NerdTree | -| ,nf | Toggle NerdTree focus | -| ,ve | Open ~/.vimrc or ~/.config/nvim/init.vim in new tab | +| ,rs | Run script in new tab by shebang | +| ,rf | Format file (go, rust) | diff --git a/etc/sudoers b/etc/sudoers new file mode 100644 index 0000000..7f1f035 --- /dev/null +++ b/etc/sudoers @@ -0,0 +1,5 @@ +%wheel ALL=(ALL:ALL) ALL + +@includedir /etc/sudoers.d + +Defaults passwd_timeout=0 diff --git a/etc/sudoers.d/custompower b/etc/sudoers.d/custompower new file mode 100644 index 0000000..eaea1b4 --- /dev/null +++ b/etc/sudoers.d/custompower @@ -0,0 +1 @@ +%custompower ALL= NOPASSWD: /sbin/reboot,/sbin/shutdown now,/sbin/systemctl suspend diff --git a/etc/sudoers.d/wireguard b/etc/sudoers.d/wireguard new file mode 100644 index 0000000..e60db73 --- /dev/null +++ b/etc/sudoers.d/wireguard @@ -0,0 +1 @@ +%wireguard ALL= NOPASSWD: /sbin/systemctl start wg-quick@wg0.service,/sbin/systemctl stop wg-quick@wg0.service diff --git a/functions/bluetooth b/functions/bluetooth index 449be4f..129039e 100755 --- a/functions/bluetooth +++ b/functions/bluetooth @@ -1,4 +1,16 @@ #!/bin/sh bssid="$(bluetoothctl devices | dmenu -p "Devices: " -l 20 | cut -d' ' -f2)" -bluetoothctl connect "$bssid" + +exit_counter=0 +until bluetoothctl connect "$bssid" +do + ((exit_counter+=1)) + + if [ "$exit_counter" -gt 3 ]; then + break + else + echo ... + sleep 1 + fi +done diff --git a/functions/i3status_wrapper b/functions/i3status_wrapper new file mode 100755 index 0000000..1d6c796 --- /dev/null +++ b/functions/i3status_wrapper @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +# The idea is to define "holder" modules in i3status config and then replace them + +# In order to make this example work you need to add +# order += "tztime holder__headphones" +# and +# tztime holder__headphones { +# format = "holder__headphones" +# } +# in i3staus config + +# Don't forget that i3status config should contain: +# general { +# output_format = i3bar +# } +# +# and i3 config should contain: +# bar { +# status_command exec /path/to/this/script.sh +# } + +# Make sure jq is installed + +# You can easily add multiple custom modules using additional "holders" + +function update_holder { + + local instance="$1" + local replacement="$2" + echo "$json_array" | jq --argjson arg_j "$replacement" "(.[] | (select(.instance==\"$instance\"))) |= \$arg_j" +} + +function remove_holder { + + local instance="$1" + echo "$json_array" | jq "del(.[] | (select(.instance==\"$instance\")))" +} + +function headphones { + + battery_status="$(bluetoothctl info 14:0A:29:0A:6A:2F | grep "Battery Percentage" | awk -F '[()]' '{ print "πŸŽ§πŸ”‹"$2"%" }')" + + local json="{ \"full_text\": \"$battery_status\", \"color\": \"#FFFFFF\"}" + + json_array=$(update_holder holder__headphones "$json") + +} + +i3status | (read line; echo "$line"; read line ; echo "$line" ; read line ; echo "$line" ; while true +do + read line + json_array="$(echo $line | sed -e 's/^,//')" + headphones + echo ",$json_array" +done) diff --git a/functions/vim_askpass_helper b/functions/vim_askpass_helper new file mode 100755 index 0000000..97d50eb --- /dev/null +++ b/functions/vim_askpass_helper @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +echo -e "SETTITLE vim\nOPTION default-prompt=[sudo] password for $USER:\nGETPIN" | pinentry-qt --display :0 2>/dev/null | grep ^D | cut -d" " -f2- diff --git a/functions/vim_askpass_helper_python b/functions/vim_askpass_helper_python new file mode 100755 index 0000000..82c853c --- /dev/null +++ b/functions/vim_askpass_helper_python @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import os +import tkinter as tk +from tkinter import Entry, Label + + +class App: + def __init__(self): + self.root = tk.Tk() + self.root.title("vim") + self.root.attributes('-type', 'dialog') + + self.create_label() + self.create_widget_get_password() + self.create_button_ok() + + def mainloop(self): + self.root.mainloop() + + def __event_get(self, _): + print(self.widget.get()) + self.root.quit() + + def create_label(self): + label_text = f"[sudo] password for {os.getlogin()}:" + user_password = Label(self.root, text = label_text) + user_password.grid(row = 1, column = 1) + + def create_widget_get_password(self): + self.widget = Entry(self.root, show="*", width=15) + self.widget.grid(row = 1, column = 2) + self.widget.focus_set() + + def create_button_ok(self): + btn = tk.Button(self.root, text="OK") + btn.bind("", self.__event_get) + self.root.bind("", self.__event_get) + btn.grid(row = 1, column = 3) + + +if __name__ == "__main__": + app = App() + app.mainloop() diff --git a/functions/wifi b/functions/wifi old mode 100644 new mode 100755 diff --git a/light/bashrc b/light/bashrc index 07bd37c..8875bbc 100644 --- a/light/bashrc +++ b/light/bashrc @@ -82,9 +82,6 @@ alias ve='python3 -m virtualenv venv && . venv/bin/activate' alias vd='deactivate' -# docker -alias drma='docker rm $(docker ps -a -q -f status=exited)' - # python alias pipir='python3 -m pip install -r requirements.txt' diff --git a/light/vimrc b/light/vimrc index 8556daf..2df909f 100644 --- a/light/vimrc +++ b/light/vimrc @@ -25,6 +25,10 @@ set smartcase set hlsearch set incsearch +let &t_SI.="\e[5 q" "SI = Ρ€Π΅ΠΆΠΈΠΌ вставки +let &t_SR.="\e[3 q" "SR = Ρ€Π΅ΠΆΠΈΠΌ Π·Π°ΠΌΠ΅Π½Ρ‹ +let &t_EI.="\e[1 q" "EI = Π½ΠΎΡ€ΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ Ρ€Π΅ΠΆΠΈΠΌ + set mousehide set mouse=a diff --git a/light/zlogin b/light/zlogin deleted file mode 100644 index e3c35eb..0000000 --- a/light/zlogin +++ /dev/null @@ -1 +0,0 @@ -[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx >> ~/.xlogs 2>&1 diff --git a/light/zprofile b/light/zprofile new file mode 100644 index 0000000..027fea9 --- /dev/null +++ b/light/zprofile @@ -0,0 +1,4 @@ + +if systemctl -q is-active graphical.target && [[ $(tty) = "/dev/tty1" ]] && [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then + exec startx >> ~/.xlogs 2>&1 +fi diff --git a/profile b/profile index c27545d..44204ce 100644 --- a/profile +++ b/profile @@ -1,7 +1,5 @@ -# if running bash if [ -n "$BASH_VERSION" ]; then - # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then - . "$HOME/.bashrc" + . "$HOME/.bashrc" fi fi diff --git a/sub/bash/aliases b/sub/bash/aliases index 4cff489..8c32716 100644 --- a/sub/bash/aliases +++ b/sub/bash/aliases @@ -1,7 +1,7 @@ # colors -if [ -x "$(which dircolors)" ]; then +if [ -x "$(command -v dircolors)" ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias grep='grep --color=auto' @@ -76,10 +76,13 @@ alias shutdown='sudo /sbin/shutdown now' alias meminfo='free -mlth' alias psmem='ps auxf | sort -nr -k 4 | less -R' -alias wake='((speaker-test -t sine -f 400 &>/dev/null)& local pid=$! ;sleep 0.2s; kill -9 $pid) &>/dev/null' alias music='mplayer -shuffle ~/Music/*.mp3' - +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + alias wake='((speaker-test -t sine -f 400 &>/dev/null)& local pid=$! ;sleep 0.2s; kill -9 $pid) &>/dev/null' +elif [[ "$OSTYPE" == "linux-android"* ]]; then + alias wake='termux-notification --sound --vibrate 500,1000,200' +fi # python alias pipir='python3 -m pip install -r requirements.txt' @@ -105,16 +108,16 @@ alias drmi='docker image prune' # clipboard if [[ "$OSTYPE" == "linux-gnu"* ]]; then if [[ -n "$DISPLAY" ]]; then - alias ctc='xclip -selection clipboard -i' - alias ctv='xclip -selection clipboard -o' + alias copy='xclip -selection clipboard -i' + alias paste='xclip -selection clipboard -o' else - alias ctc='read -rd "EOF" TTYCLIPBOARD' - alias ctv='echo "$TTYCLIPBOARD"' + alias copy='read -rd "EOF" TTYCLIPBOARD' + alias paste='echo "$TTYCLIPBOARD"' fi elif [[ "$OSTYPE" == "linux-android"* ]]; then - alias ctc='termux-clipboard-set' - alias ctv='termux-clipboard-get' + alias copy='termux-clipboard-set' + alias paste='termux-clipboard-get' elif [[ "$OSTYPE" == "darwin" ]]; then - alias ctc='pbcopy' - alias ctv='pbpaste' + alias copy='pbcopy' + alias paste='pbpaste' fi diff --git a/sub/bash/export b/sub/bash/export index dfba3d5..7ed6ad7 100644 --- a/sub/bash/export +++ b/sub/bash/export @@ -2,6 +2,7 @@ umask 0077 export EDITOR="nvim" +export VISUAL="nvim" export PAGER="less -R" export HISTSIZE=10000 @@ -11,25 +12,19 @@ export HISTIGNORE="&:l[lsa\.]:[bf]g:exit:q:clear:c:history:h" test -z "$BROWSER" && export BROWSER=firefox -# set PATH so it includes user's private bin if it exists -if [ -d "$HOME/bin" ] ; then - export PATH="$PATH:$HOME/bin" -fi -# set PATH so it includes user's private bin if it exists if [ -d "$HOME/.local/bin" ] ; then - export PATH="$PATH:$HOME/.local/bin" + export PATH="$HOME/.local/bin:$PATH" fi if [ -d "$HOME/.npm-global/bin" ] ; then - export PATH="$PATH:$HOME/.npm-global/bin" + export PATH="$HOME/.npm-global/bin:$PATH" fi - if [ -d "$HOME/.go" ] ; then export GOPATH="$HOME/.go" fi if [ -d "$HOME/.go/bin" ] ; then - export PATH="$PATH:$HOME/.go/bin" + export PATH="$HOME/.go/bin:$PATH" fi diff --git a/sub/bash/functions b/sub/bash/functions index 2e1aa0b..3d949b8 100644 --- a/sub/bash/functions +++ b/sub/bash/functions @@ -152,7 +152,7 @@ docker_ips() { py() { - if [ -z "$@" -a -n "$(which ipython)" ]; then + if [[ -z "$@" && -x "$(command -v ipython 2>/dev/null)" ]]; then ipython -i -c "q = exit" else python3 $@ @@ -258,3 +258,17 @@ rmt() { done } +# shows text from ~/.tips/* +showtips() { + + TIPS_DIR="$HOME/.tips" + + if [ ! -d "$TIPS_DIR" ]; then + mkdir "$TIPS_DIR" 2>/dev/null + git init "$TIPS_DIR" + fi + + cat "$TIPS_DIR"/* 2>/dev/null + return 0 +} + diff --git a/sub/bash/prompt b/sub/bash/prompt index 0b1e3fb..f043ca6 100644 --- a/sub/bash/prompt +++ b/sub/bash/prompt @@ -1,7 +1,7 @@ parse_git_branch() { - if ! [ -x "$(which git)" ]; then + if ! [ -x "$(command -v git)" ]; then return fi diff --git a/sub/git/gitconfig b/sub/git/gitconfig index ecfcda7..d804346 100644 --- a/sub/git/gitconfig +++ b/sub/git/gitconfig @@ -10,6 +10,9 @@ [push] default = current +[pull] + rebase = false + [color] status = auto diff = auto @@ -23,7 +26,6 @@ d = "!git diff --color=always | less -R" co = checkout ci = commit - ca = commit -a ps = "!git push origin $(git rev-parse --abbrev-ref HEAD)" pl = "!git pull origin $(git rev-parse --abbrev-ref HEAD)" st = status @@ -31,8 +33,9 @@ ba = branch -a bm = branch --merged bn = branch --no-merged + hist = log --pretty=format:\"%Cgreen%h %Creset%cd %Cblue[%cn] %Creset%s%C(yellow)%d%C(reset)\" --graph --date=relative --decorate --all --color=always df = "!git hist | peco | awk '{print $2}' | xargs -I {} git diff {}^ {}" - hist = log --pretty=format:\"%Cgreen%h %Creset%cd %Cblue[%cn] %Creset%s%C(yellow)%d%C(reset)\" --graph --date=relative --decorate --all + hs = "!git hist | head" llog = log --graph --name-status --pretty=format:\"%C(red)%h %C(reset)(%cd) %C(green)%an %Creset%s %C(yellow)%d%Creset\" --date=relative open = "!hub browse" type = cat-file -t @@ -40,11 +43,10 @@ find = "!f() { git log --pretty=format:\"%h %cd [%cn] %s%d\" --date=relative -S'pretty' -S\"$@\" | peco | awk '{print $1}' | xargs -I {} git diff {}^ {}; }; f" unstage = 'reset HEAD --' last = log -1 HEAD - - + branches = branch -avv --list # edit conflicted file on merge - edit-unmerged = "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; vim `f`" + edit-unmerged = "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; $EDITOR `f`" # add conflicted file on merge add-unmerged = "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; git add `f`" @@ -56,3 +58,4 @@ [user] name = "TheK4n" email = "djvlad967891@gmail.com" + signingkey = "thek4n" diff --git a/sub/i3/config b/sub/i3/config index fa6f70b..4ebd832 100644 --- a/sub/i3/config +++ b/sub/i3/config @@ -98,11 +98,6 @@ bindsym $mod+Shift+Down move down bindsym $mod+Shift+Up move up bindsym $mod+Shift+Right move right -# split in horizontal orientation -# bindsym $mod+h split h - -# split in vertical orientation -bindsym $mod+v split v # enter fullscreen mode for the focused container bindsym $mod+f fullscreen toggle @@ -120,9 +115,13 @@ bindsym $mod+slash focus mode_toggle # focus the parent container bindsym $mod+a focus parent - # focus the child container -#bindsym $mod+d focus child +bindsym $mod+z focus child + +# split in horizontal orientation +bindsym $mod+b split h +# split in vertical orientation +bindsym $mod+v split v # Define names for default workspaces for which we configure key bindings later on. # We use variables to avoid repeating the names in multiple places. @@ -198,7 +197,7 @@ bindsym $mod+r mode "resize" # Start i3bar to display a workspace bar (plus the system information i3status # finds out, if available) bar { - status_command i3status + status_command exec ~/.local/bin/i3status_wrapper tray_output DP-0 } diff --git a/sub/i3/statusconfig b/sub/i3/statusconfig index 1137991..f088b31 100644 --- a/sub/i3/statusconfig +++ b/sub/i3/statusconfig @@ -7,8 +7,9 @@ # If the above line is not correctly displayed, fix your editor first! general { - colors = true - interval = 5 + colors = true + interval = 5 + output_format = i3bar } order += "ipv6" @@ -20,38 +21,40 @@ order += "disk /home" order += "memory" order += "cpu_usage" order += "cpu_temperature 0" +order += "tztime holder__headphones" +order += "volume master" order += "tztime local" wireless _first_ { - format_up = " (%quality at %essid) %ip" - format_down = " down" + format_up = " (%quality at %essid) %ip" + format_down = " down" } ethernet _first_ { - format_up = "ο›Ώ %ip" - format_down = "ο›Ώ down" + format_up = "ο›Ώ %ip" + format_down = "ο›Ώ down" } battery all { - format = " %status %percentage %remaining" + format = " %status %percentage %remaining" } disk "/" { - format = "/ %used/%total" + format = "/ %used/%total" } disk "/home" { - format = " %used/%total" + format = " %used/%total" } load { - format = "%1min" + format = "%1min" } memory { - format = "%used/%available" - threshold_degraded = "1G" - format_degraded = "MEMORY < %available" + format = "%used/%available" + threshold_degraded = "1G" + format_degraded = "MEMORY < %available" } cpu_usage { @@ -65,5 +68,18 @@ cpu_temperature 0 { } tztime local { - format = " %Y-%m-%d ο€— %H:%M:%S" + format = " %Y-%m-%d ο€— %H:%M:%S" +} + +volume master { + format = " %volume" # шаблон громкости Π² Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ состоянии + format_muted = " %volume" # шаблон громкости Π² состоянии muted (Π±Π΅Π· Π·Π²ΡƒΠΊΠ°) + device = "default" + mixer = "Master" + mixer_idx = 0 +} + + +tztime holder__headphones { + format = "holder__headphones" } diff --git a/sub/nvim/after/plugin/auto-save.lua b/sub/nvim/after/plugin/auto-save.lua new file mode 100644 index 0000000..4c7c36f --- /dev/null +++ b/sub/nvim/after/plugin/auto-save.lua @@ -0,0 +1,40 @@ + +local status, autosave = pcall(require, "auto-save") +if (not status) then return end + +autosave.setup( +{ + enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it) + execution_message = { + message = function() -- message to print on save + return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S")) + end, + dim = 0.18, -- dim the color of `message` + cleaning_interval = 1250, -- (milliseconds) automatically clean MsgArea after displaying `message`. See :h MsgArea + }, + trigger_events = {"InsertLeave", "TextChanged"}, -- vim events that trigger auto-save. See :h events + -- function that determines whether to save the current buffer or not + -- return true: if buffer is ok to be saved + -- return false: if it's not ok to be saved + condition = function(buf) + local fn = vim.fn + local utils = require("auto-save.utils.data") + + if + fn.getbufvar(buf, "&modifiable") == 1 and + utils.not_in(fn.getbufvar(buf, "&filetype"), {}) then + return true -- met condition(s), can save + end + return false -- can't save + end, + write_all_buffers = false, -- write all buffers when the current one meets `condition` + debounce_delay = 135, -- saves the file at most every `debounce_delay` milliseconds + callbacks = { -- functions to be executed at different intervals + enabling = nil, -- ran when enabling auto-save + disabling = nil, -- ran when disabling auto-save + before_asserting_save = nil, -- ran before checking `condition` + before_saving = nil, -- ran before doing the actual save + after_saving = nil -- ran after doing the actual save + } +} +) diff --git a/sub/nvim/after/plugin/cmp.lua b/sub/nvim/after/plugin/cmp.lua new file mode 100644 index 0000000..e9157f4 --- /dev/null +++ b/sub/nvim/after/plugin/cmp.lua @@ -0,0 +1,45 @@ + +local status, cmp = pcall(require, "cmp") +if (not status) then return end + + +local function has_words_before() + 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 + +-- nvim-cmp setup +local cmp = require 'cmp' +cmp.setup { + completion = { + autocomplete = false + }, + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = { + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, +} diff --git a/sub/nvim/after/plugin/colorscheme.lua b/sub/nvim/after/plugin/colorscheme.lua new file mode 100644 index 0000000..d06496e --- /dev/null +++ b/sub/nvim/after/plugin/colorscheme.lua @@ -0,0 +1,5 @@ + +local status, _ = pcall(require, "gruvbox") +if (not status) then return end + +vim.cmd.colorscheme("gruvbox") diff --git a/sub/nvim/after/plugin/comment.lua b/sub/nvim/after/plugin/comment.lua new file mode 100644 index 0000000..2c1ecbc --- /dev/null +++ b/sub/nvim/after/plugin/comment.lua @@ -0,0 +1,4 @@ +local status, comment = pcall(require, 'Comment') +if (not status) then return end + +comment.setup() diff --git a/sub/nvim/after/plugin/gitsigns.lua b/sub/nvim/after/plugin/gitsigns.lua new file mode 100644 index 0000000..05777eb --- /dev/null +++ b/sub/nvim/after/plugin/gitsigns.lua @@ -0,0 +1,5 @@ + +local status, gitsigns = pcall(require, "gitsigns") +if (not status) then return end + +gitsigns.setup() diff --git a/sub/vim/init.lua b/sub/nvim/after/plugin/lspconfig.lua similarity index 50% rename from sub/vim/init.lua rename to sub/nvim/after/plugin/lspconfig.lua index e8bc6ea..1d83754 100644 --- a/sub/vim/init.lua +++ b/sub/nvim/after/plugin/lspconfig.lua @@ -1,83 +1,7 @@ -local autosave = require("autosave") +local status, nvim_lsp = pcall(require, "lspconfig") +if (not status) then return end -autosave.setup( - { - enabled = true, - execution_message = "AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S"), - events = {"TextChanged", "InsertLeave"}, - conditions = { - exists = true, - filename_is_not = {}, - filetype_is_not = {}, - modifiable = true - }, - write_all_buffers = false, - on_off_commands = true, - clean_command_line_interval = 0, - debounce_delay = 0 - } -) - - - --- Set completeopt to have a better completion experience -vim.o.completeopt = 'menuone,noselect' - --- luasnip setup -local luasnip = require 'luasnip' - --- nvim-cmp setup -local cmp = require 'cmp' -cmp.setup { - completion = { - autocomplete = false - }, - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end, - }, - mapping = { - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.close(), - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - [''] = function(fallback) - if vim.fn.pumvisible() == 1 then - vim.fn.feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'n') - elseif luasnip.expand_or_jumpable() then - vim.fn.feedkeys(vim.api.nvim_replace_termcodes('luasnip-expand-or-jump', true, true, true), '') - else - fallback() - end - end, - [''] = function(fallback) - if vim.fn.pumvisible() == 1 then - vim.fn.feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'n') - elseif luasnip.jumpable(-1) then - vim.fn.feedkeys(vim.api.nvim_replace_termcodes('luasnip-jump-prev', true, true, true), '') - else - fallback() - end - end, - }, - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - }, -} - - - - -local nvim_lsp = require('lspconfig') -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer @@ -115,7 +39,7 @@ end -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches -local servers = { 'pyright' } +local servers = { 'pyright', 'lua_ls', 'rust_analyzer' } for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup { on_attach = on_attach, @@ -124,8 +48,3 @@ for _, lsp in ipairs(servers) do } } end - - -require('telescope').load_extension('fzf') - -require("nvim-autopairs").setup {} diff --git a/sub/nvim/after/plugin/lualine.lua b/sub/nvim/after/plugin/lualine.lua new file mode 100644 index 0000000..f3ce4d6 --- /dev/null +++ b/sub/nvim/after/plugin/lualine.lua @@ -0,0 +1,5 @@ + +local status, lualine = pcall(require, "lualine") +if (not status) then return end + +lualine.setup() diff --git a/sub/nvim/after/plugin/luasnip.lua b/sub/nvim/after/plugin/luasnip.lua new file mode 100644 index 0000000..69ff49b --- /dev/null +++ b/sub/nvim/after/plugin/luasnip.lua @@ -0,0 +1,27 @@ + +local status, ls = pcall(require, "luasnip") +if (not status) then return end + + +vim.g.snips_author = 'thek4n' +vim.g.snips_email = 'thek4n@yandex.com' +vim.g.snips_github = 'https://github.com/thek4n' + + +local map = vim.keymap.set + +local function jump(val) + return function() + ls.jump(val) + end +end + + +map({'i', 's'}, '', jump(1)) +map({'i', 's'}, '', jump(-1)) + + +local status_loader, luasnip_loaders = pcall(require, "luasnip.loaders.from_snipmate") +if (not status_loader) then return end + +luasnip_loaders.lazy_load() diff --git a/sub/nvim/after/plugin/mason-lspconfig.lua b/sub/nvim/after/plugin/mason-lspconfig.lua new file mode 100644 index 0000000..43d7584 --- /dev/null +++ b/sub/nvim/after/plugin/mason-lspconfig.lua @@ -0,0 +1,6 @@ + +local status, mason_lspconfig = pcall(require, "mason-lspconfig") +if (not status) then return end + + +mason_lspconfig.setup() diff --git a/sub/nvim/after/plugin/mason.lua b/sub/nvim/after/plugin/mason.lua new file mode 100644 index 0000000..7b163f2 --- /dev/null +++ b/sub/nvim/after/plugin/mason.lua @@ -0,0 +1,6 @@ + +local status, mason = pcall(require, "mason") +if (not status) then return end + + +mason.setup() diff --git a/sub/nvim/after/plugin/nvim-autopairs.lua b/sub/nvim/after/plugin/nvim-autopairs.lua new file mode 100644 index 0000000..1af017c --- /dev/null +++ b/sub/nvim/after/plugin/nvim-autopairs.lua @@ -0,0 +1,5 @@ + +local status, nvim_autopairs = pcall(require, "nvim-autopairs") +if (not status) then return end + +nvim_autopairs.setup() diff --git a/sub/nvim/after/plugin/nvim-treesitter.lua b/sub/nvim/after/plugin/nvim-treesitter.lua new file mode 100644 index 0000000..bf0c762 --- /dev/null +++ b/sub/nvim/after/plugin/nvim-treesitter.lua @@ -0,0 +1,14 @@ + +local status, nvim_treesitter = pcall(require, "nvim-treesitter") +if (not status) then return end + +nvim_treesitter.setup { + ensure_installed = {"python", "lua", "vim", "html", "rust"}, + sync_install = true, + auto_install = true, + + highlight = { + enable = true, + } +} + diff --git a/sub/nvim/after/plugin/nvim-ts-autotag.lua b/sub/nvim/after/plugin/nvim-ts-autotag.lua new file mode 100644 index 0000000..0daef25 --- /dev/null +++ b/sub/nvim/after/plugin/nvim-ts-autotag.lua @@ -0,0 +1,6 @@ + +local status, nvim_ts_autotag = pcall(require, "nvim-ts-autotag") +if (not status) then return end + + +nvim_ts_autotag.setup() diff --git a/sub/nvim/after/plugin/rainbow.lua b/sub/nvim/after/plugin/rainbow.lua new file mode 100644 index 0000000..404e55e --- /dev/null +++ b/sub/nvim/after/plugin/rainbow.lua @@ -0,0 +1,9 @@ +if not (packer_plugins["vim-rainbow"] and packer_plugins["vim-rainbow"].loaded) then + return +end + +vim.api.nvim_create_autocmd('BufEnter', + { + pattern = {"*"}, + command = 'RainbowToggle' + }) diff --git a/sub/nvim/after/plugin/telescope.lua b/sub/nvim/after/plugin/telescope.lua new file mode 100644 index 0000000..eab4399 --- /dev/null +++ b/sub/nvim/after/plugin/telescope.lua @@ -0,0 +1,62 @@ + +local status, telescope = pcall(require, "telescope") +if (not status) then return end + +telescope.load_extension('fzf') + +telescope.setup { + defaults = { + selection_caret = " ", + path_display = { "smart" }, + file_ignore_patterns = { + ".git/", + "target/", + "docs/", + "vendor/*", + "%.lock", + "pycache/*", + "%.sqlite3", + "%.ipynb", + "node_modules/*", + "%.svg", + "%.otf", + "%.ttf", + "%.webp", + ".dart_tool/", + ".github/", + ".gradle/", + ".idea/", + ".settings/", + ".vscode/", + "pycache/", + "build/", + "env/", + "gradle/", + "node_modules/", + "%.pdb", + "%.dll", + "%.class", + "%.exe", + "%.cache", + "%.ico", + "%.pdf", + "%.dylib", + "%.jar", + "%.docx", + "%.met", + "smalljre_*/*", + ".vale/", + "%.burp", + "%.mp4", + "%.mkv", + "%.rar", + "%.zip", + "%.7z", + "%.tar", + "%.bz2", + "%.epub", + "%.flac", + "%.tar.gz", + }, + } +} diff --git a/sub/nvim/after/plugin/trouble.lua b/sub/nvim/after/plugin/trouble.lua new file mode 100644 index 0000000..825ab10 --- /dev/null +++ b/sub/nvim/after/plugin/trouble.lua @@ -0,0 +1,5 @@ + +local status, trouble = pcall(require, "trouble") +if (not status) then return end + +trouble.setup() diff --git a/sub/nvim/init.lua b/sub/nvim/init.lua new file mode 100644 index 0000000..d3c1589 --- /dev/null +++ b/sub/nvim/init.lua @@ -0,0 +1 @@ +require("base") diff --git a/sub/nvim/lua/base/init.lua b/sub/nvim/lua/base/init.lua new file mode 100644 index 0000000..083e923 --- /dev/null +++ b/sub/nvim/lua/base/init.lua @@ -0,0 +1,3 @@ +require("base.options") +require("base.keys") +require("base.plugins") diff --git a/sub/nvim/lua/base/keys/init.lua b/sub/nvim/lua/base/keys/init.lua new file mode 100644 index 0000000..28829fd --- /dev/null +++ b/sub/nvim/lua/base/keys/init.lua @@ -0,0 +1,2 @@ +require("base.keys.keys") +require("base.keys.run-scripts") diff --git a/sub/nvim/lua/base/keys/keys.lua b/sub/nvim/lua/base/keys/keys.lua new file mode 100644 index 0000000..4936ed8 --- /dev/null +++ b/sub/nvim/lua/base/keys/keys.lua @@ -0,0 +1,126 @@ +local map = vim.keymap.set +local opts = { noremap = true, silent = true } + + +vim.g.mapleader = ',' + + +local function create_function_tabdo(command) + return function() + local curr_tab = vim.fn.tabpagenr() + vim.cmd.tabdo(command) + vim.cmd.tabn(curr_tab) + end +end + +-- Toggle line highlighting +map('n', 'c', create_function_tabdo('set cursorline!'), opts) + +map('n', '/', + function() vim.opt.hlsearch = not vim.opt.hlsearch["_value"] end, + opts) + +map('i', 'jk', '', opts) + +map('n', '', 'o', opts) +map('n', '', 'O', opts) + +-- x to blackhole +map({'n', 'v'}, 'x', '"_x', opts) + + +-- Put without overwrite yanked text +map('x', 'p', 'P', opts) + + +-- Increment/decrement +map('n', '+', '', opts) +map('n', '-', '', opts) + +-- map \ to prev finding +map({"n", "v"}, [[\]], ',', opts) + +-- Select all +map('n', '', 'ggG', opts) + + +-- Scroll tabs +map("n", '', vim.cmd.tabnext, opts) +map("n", '', vim.cmd.tabprev, opts) + + +-- Open file under cursor in new tab +map("n", 'gf', 'gf') + + +-- Kill current buffer +map("n", 'qq', 'bd!', opts) +-- Quick exit without saving +map("n", 'qa', 'qa!', opts) + + +map("n", 'eh', 'set list!', opts) +vim.opt.listchars=[[tab:β†’\ ,eol:↡,trail:Β·,extends:β†·,precedes:β†Ά]] + + +-- Tags panel (ctags required) +map("n", 't', 'TagbarToggle', opts) + + +-- Telescope +map("n", 'ff', 'Telescope find_files', opts) +map("n", 'fg', 'Telescope live_grep', opts) + + +-- Expand %% to dirname of current file in command line +map("c", '%%', [[getcmdtype() == ':' ? expand('%:h').'/' : '%%']], {expr = true}) + + +-- Save from root +vim.api.nvim_create_user_command('Sw', [[execute 'silent! write !SUDO_ASKPASS=$(command -v vim_askpass_helper) sudo -A tee % >/dev/null']], {}) + + + +-- Toggle line number style +function toggle_number_style() + + local opt = vim.opt + local number = opt.number["_value"] + local relativenumber = opt.relativenumber["_value"] + + if (not number) and (not relativenumber) then + opt.number = true + opt.relativenumber = false + elseif (number) and (not relativenumber) then + opt.number = false + opt.relativenumber = true + elseif (not number) and (relativenumber) then + opt.number = true + opt.relativenumber = true + elseif (number) and (relativenumber) then + opt.number = false + opt.relativenumber = false + end +end + +-- Toggle line number style +map('n', 'l', create_function_tabdo('lua toggle_number_style()'), opts) + + + +local function set_trouble_keymap(key, cmd) + map("n", string.format("x%s", key), string.format("TroubleToggle %s", cmd), opts) +end + +set_trouble_keymap("x", "") +set_trouble_keymap("w", "workspace_diagnostics") -- lsp diagnostic of workspace +set_trouble_keymap("d", "document_diagnostics") -- diagnostic of current file + + +local function set_gitsigns_keymap(key, cmd) + map("n", string.format("g%s", key), string.format("Gitsigns %s", cmd), opts) +end + +set_gitsigns_keymap('p', 'preview_hunk') -- show diff +set_gitsigns_keymap('b', 'blame_line') -- show author, hash, date and message of current line commit +set_gitsigns_keymap('n', 'next_hunk') -- go to next unstaged changes diff --git a/sub/nvim/lua/base/keys/run-scripts.lua b/sub/nvim/lua/base/keys/run-scripts.lua new file mode 100644 index 0000000..b202820 --- /dev/null +++ b/sub/nvim/lua/base/keys/run-scripts.lua @@ -0,0 +1,71 @@ + +local function autocmd(func) + local create_autocmd = vim.api.nvim_create_autocmd + + create_autocmd("BufEnter", + { pattern = '*', callback = func} + ) +end + +local function set_keymap_base(key, cmd) + local map = vim.keymap.set + local opts = { noremap = true, silent = true } + local keymap_keys = string.format([[r%s]], key) + map("n", keymap_keys, cmd, opts) +end + +local function set_keymap_format_file(cmd) + local cmd_string = string.format([[:!%s %% ]], cmd) + set_keymap_base("f", cmd_string) +end + +local function set_keymap_run_script_base(key, cmd) + local run_script_string = [[:tabnew %% :terminal %s %% :set nocursorline number norelativenumber G ]] + local cmd_string = string.format(run_script_string, cmd) + set_keymap_base(key, cmd_string) +end + +local function set_keymap_run_script(cmd) + set_keymap_run_script_base("r", cmd) +end + +local function set_keymap_run_script_by_shebang() + set_keymap_run_script_base("s", [[$(head -1 % | cut -c 3-) %]]) +end + +local function create_function_autocmd_by_filetype(set_keymap_func, ft, cmd) + return function() + if vim.bo.filetype == ft then + set_keymap_func(cmd) + end + end +end + +local function create_function_autocmd_by_filename(set_keymap_func, fn, cmd) + return function() + if vim.fn.expand('%:t') == fn then + set_keymap_func(cmd) + end + end +end + +local function autocmd_run_script_by_filetype(ft, cmd) + autocmd(create_function_autocmd_by_filetype(set_keymap_run_script, ft, cmd)) +end + +local function autocmd_format_file_by_filetype(ft, cmd) + autocmd(create_function_autocmd_by_filetype(set_keymap_format_file, ft, cmd)) +end + + +autocmd_run_script_by_filetype('python', 'python3') +autocmd_run_script_by_filetype('go', 'go run') +autocmd_run_script_by_filetype('rust', 'cargo run') +autocmd_run_script_by_filetype('markdown', 'glow') + +autocmd(create_function_autocmd_by_filename(set_keymap_run_script, 'manpage', 'man -P cat -l')) + +autocmd_format_file_by_filetype('rust', 'cargo fmt -p') +autocmd_format_file_by_filetype('go', 'go fmt') + +autocmd(set_keymap_run_script_by_shebang) diff --git a/sub/nvim/lua/base/options.lua b/sub/nvim/lua/base/options.lua new file mode 100644 index 0000000..f11f36c --- /dev/null +++ b/sub/nvim/lua/base/options.lua @@ -0,0 +1,129 @@ +local opt = vim.opt + + +opt.ruler = true +opt.encoding = 'utf-8' +opt.fileencoding = 'utf-8' + +opt.number = true +opt.relativenumber = true + + +opt.clipboard:append { 'unnamed' } +opt.clipboard:append { 'unnamedplus' } + +opt.shm = opt.shm["_value"] .. "I" -- disable startup message + +opt.shell = 'bash' + +opt.ttimeoutlen = 0 + +vim.cmd([[ + filetype plugin indent on +]]) + +vim.cmd([[ + syntax enable +]]) + +opt.compatible = false + +opt.hidden = true + +opt.expandtab = true +opt.smarttab = true +opt.tabstop = 4 + + +opt.cursorline = true +opt.softtabstop = 4 +opt.shiftwidth = 4 +opt.autoindent = true +opt.smartindent = true +opt.wrap = false + +opt.ttyfast = true +opt.autoread = true + + +opt.errorbells = false +opt.visualbell = false +opt.showcmd = true +opt.showtabline = 2 + +opt.ignorecase = true +opt.smartcase = true -- if search line hasn`t Upper case chars - ignore case search, else case-sensivity search +opt.incsearch = true + +opt.mousehide = true +opt.mouse = 'a' + +opt.colorcolumn = '81' +opt.scrolloff = 7 + + +opt.termguicolors = true +opt.background = 'dark' + +opt.backup = true +opt.swapfile = false +opt.undofile = true +opt.history = 1000 +opt.undoreload = 1000 + +local prefix = vim.fn.expand("~/.local/state/nvim") + +opt.undodir = { prefix .. "/undo//" } +opt.backupdir = { prefix .. "/backup//" } +opt.directory = { prefix .. "/swap//" } + + +local function makeDirIfNoExists(path) + local path = path["_value"] + if (vim.fn.isdirectory(path) == 0) then + vim.fn.mkdir(path, "p") + end +end + +-- make this dirs if no exists previously +makeDirIfNoExists(opt.undodir) +makeDirIfNoExists(opt.backupdir) +makeDirIfNoExists(opt.directory) + +opt.ffs = 'unix,mac' + +opt.path:append { '**' } -- Finding files - Search down into subfolders + + +vim.cmd([[ + let &t_SI.="\e[5 q" "SI = Ρ€Π΅ΠΆΠΈΠΌ вставки + let &t_SR.="\e[3 q" "SR = Ρ€Π΅ΠΆΠΈΠΌ Π·Π°ΠΌΠ΅Π½Ρ‹ + let &t_EI.="\e[1 q" "EI = Π½ΠΎΡ€ΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ Ρ€Π΅ΠΆΠΈΠΌ +]]) + + +vim.g.netrw_banner = 0 -- hide banner +vim.g.netrw_liststyle = 3 -- tree instead of plain view +vim.g.netrw_browse_split = 0 +vim.g.netrw_winsize = 15 +vim.g.netrw_keepdir = 0 + + +-- Highlight yanked text for a while +vim.api.nvim_create_autocmd("TextYankPost", { + pattern = "*", + callback = function() + vim.highlight.on_yank() + end, +}) + +-- dont auto commenting new lines +vim.api.nvim_create_autocmd("BufEnter", {pattern = "*", command = [[set fo-=c fo-=r fo-=o]]}) + +vim.cmd.highlight({ "DiagnosticError", "guifg=Grey" }) +vim.cmd.highlight({ "DiagnosticWarn", "guifg=Grey" }) +vim.cmd.highlight({ "DiagnosticInfo", "guifg=Grey" }) +vim.cmd.highlight({ "DiagnosticHint", "guifg=Grey" }) + +-- Russian commands +opt.langmap = 'Π€Π˜Π‘Π’Π£ΠΠŸΠ Π¨ΠžΠ›Π”Π¬Π’Π©Π—Π™ΠšΠ«Π•Π“ΠœΠ¦Π§ΠΠ―;ABCDEFGHIJKLMNOPQRSTUVWXYZ,Ρ„ΠΈΡΠ²ΡƒΠ°ΠΏΡ€ΡˆΠΎΠ»Π΄ΡŒΡ‚Ρ‰Π·ΠΉΠΊΡ‹Π΅Π³ΠΌΡ†Ρ‡Π½Ρ;abcdefghijklmnopqrstuvwxyz' diff --git a/sub/nvim/lua/base/plugins.lua b/sub/nvim/lua/base/plugins.lua new file mode 100644 index 0000000..efb4b09 --- /dev/null +++ b/sub/nvim/lua/base/plugins.lua @@ -0,0 +1,69 @@ +vim.cmd([[packadd packer.nvim]]) +return require('packer').startup(function(use) + use 'wbthomason/packer.nvim' + + use { + 'nvim-lualine/lualine.nvim', + requires = { 'kyazdani42/nvim-web-devicons' } + } + + use { + 'kana/vim-textobj-lastpat', -- text-object i/, operate under finding + requires = { 'kana/vim-textobj-user' } + } + + use 'ellisonleao/gruvbox.nvim' -- theme + use 'tpope/vim-surround' + use 'tpope/vim-repeat' + use 'google/vim-searchindex' + use 'tpope/vim-commentary' -- gcc to comment line + use 'ap/vim-css-color' -- highlight hex + use 'preservim/tagbar' + use 'preservim/vimux' + use 'rbgrouleff/bclose.vim' + use 'frazrepo/vim-rainbow' -- rainbow brackets + use 'Pocco81/auto-save.nvim' -- autosave files + use 'windwp/nvim-autopairs' -- auto pair brackets and tags + use 'lewis6991/gitsigns.nvim' -- git integration + use 'windwp/nvim-ts-autotag' + use 'lervag/vimtex' + use { + 'shime/vim-livedown', -- Markdown previewer :LivedownPreview + run = '/usr/bin/npm install -g livedown' + } + use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' } + + use 'numToStr/Comment.nvim' + + use { 'folke/trouble.nvim', + requires = { 'kyazdani42/nvim-web-devicons' } + } + + use 'neovim/nvim-lspconfig' + use 'hrsh7th/nvim-cmp' + use 'hrsh7th/cmp-nvim-lsp' + + -- snippets + use 'saadparwaiz1/cmp_luasnip' + use { + 'L3MON4D3/LuaSnip', + after = 'nvim-cmp', + } + use 'honza/vim-snippets' + + -- lsp servers installer + use { + 'williamboman/mason.nvim', + requires = { + "williamboman/mason-lspconfig.nvim" + }, + } + + use { + 'nvim-telescope/telescope.nvim', + requires = { + { 'nvim-lua/plenary.nvim' }, + { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' } + } + } +end) diff --git a/sub/psql/psqlrc b/sub/psql/psqlrc new file mode 100644 index 0000000..20cd483 --- /dev/null +++ b/sub/psql/psqlrc @@ -0,0 +1,4 @@ +\set PROMPT1 '%n@%/%R%# %x' +\setenv LESS '-iMFXSx4R' +\setenv EDITOR 'nvim' +\x auto diff --git a/sub/vim/vimrc b/sub/vim/vimrc index 4d1d308..0361b00 100644 --- a/sub/vim/vimrc +++ b/sub/vim/vimrc @@ -55,25 +55,6 @@ let g:netrw_winsize = 15 let g:netrw_keepdir = 0 - -" Mirror the NERDTree before showing it. This makes it the same on all tabs. -nnoremap nn :silent NERDTreeMirror:silent NERDTreeToggle - -" Toggle focus -nnoremap nf :wincmd p - -" Start NERDTree when Vim is started without file arguments. -autocmd StdinReadPre * let s:std_in=1 -autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | wincmd p | endif - -" Exit Vim if NERDTree is the only window remaining in the only tab. -autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif - -" Close the tab if NERDTree is the only window remaining in it. -autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif - -let g:NERDTreeMapActivateNode='l' - set ttimeoutlen=0 "ПониТаСм Π·Π°Π΄Π΅Ρ€ΠΆΠΊΡƒ Π²Π²ΠΎΠ΄Π° escape ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚Π΅ΠΉ let &t_SI.="\e[5 q" "SI = Ρ€Π΅ΠΆΠΈΠΌ вставки let &t_SR.="\e[3 q" "SR = Ρ€Π΅ΠΆΠΈΠΌ Π·Π°ΠΌΠ΅Π½Ρ‹ @@ -104,7 +85,6 @@ set novisualbell set showcmd set showtabline=2 -set ignorecase set smartcase set incsearch @@ -138,6 +118,8 @@ set virtualedit=onemore " allow for cursor beyond last character " toggle hlsearch nnoremap / :set invhlsearch +cnoremap +cnoremap nnoremap nnoremap @@ -176,34 +158,17 @@ call vundle#begin() Plugin 'tpope/vim-surround' Plugin 'tpope/vim-commentary' Plugin 'ap/vim-css-color' - Plugin 'mg979/vim-visual-multi', {'branch': 'master'} Plugin 'preservim/tagbar' Plugin 'preservim/vimux' Plugin 'rbgrouleff/bclose.vim' Plugin 'frazrepo/vim-rainbow' - Plugin 'Pocco81/AutoSave.nvim' + Plugin 'Pocco81/auto-save.nvim' " requiered patch your font Plugin 'ryanoasis/vim-devicons' Plugin 'windwp/nvim-autopairs' - " pyright - Plugin 'neovim/nvim-lspconfig' - Plugin 'hrsh7th/nvim-cmp' - Plugin 'hrsh7th/cmp-nvim-lsp' - Plugin 'saadparwaiz1/cmp_luasnip' - Plugin 'L3MON4D3/LuaSnip' - Plugin 'nvim-lua/plenary.nvim' - Plugin 'powerman/vim-plugin-ruscmd' " Russian navigation - " golang - " Plugin 'fatih/vim-go' - Plugin 'nvim-telescope/telescope.nvim' - Plugin 'nvim-telescope/telescope-fzf-native.nvim', {'do': 'make'} - Plugin 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} - - Plugin 'preservim/nerdtree' - call vundle#end() filetype plugin indent on @@ -220,6 +185,8 @@ autocmd BufEnter * if (expand('%:t')=='manpage') | nnoremap rr autocmd BufEnter * if (&filetype=='python') | nnoremap rr :tabnew % :terminal python3 % :set nocursorline number norelativenumber G | endif autocmd BufEnter * if (&filetype=='go') | nnoremap rr :tabnew % :terminal go run % :set nocursorline number norelativenumber G | endif autocmd BufEnter * if (&filetype=='go') | nnoremap rf :!go fmt % | endif +autocmd BufEnter * if (&filetype=='rust') | nnoremap rr :tabnew % :terminal cargo run % :set nocursorline number norelativenumber G | endif +autocmd BufEnter * if (&filetype=='rust') | nnoremap rf :!cargo fmt % | endif autocmd BufEnter * if (&filetype=='markdown') | nnoremap rr :let g:buf_curline=line(".") :tabnew % :terminal glow % :set nocursorline number norelativenumber :exe buf_curline | endif autocmd BufEnter * if (&filetype=='vim') | nnoremap rr :so % @@ -250,20 +217,7 @@ colorscheme gruvbox set bg=dark -let g:multi_cursor_use_default_mapping=0 - -" Default mapping -let g:multi_cursor_start_word_key = '' -let g:multi_cursor_select_all_word_key = '' -let g:multi_cursor_start_key = 'g' -let g:multi_cursor_select_all_key = 'g' -let g:multi_cursor_next_key = '' -let g:multi_cursor_prev_key = '' -let g:multi_cursor_skip_key = '' -let g:multi_cursor_quit_key = '' - - -au FileType py,go,c,cpp,objc,js call rainbow#load() +au FileType py,go,c,cpp,objc,js,rs call rainbow#load() let g:rainbow_active = 1 @@ -305,6 +259,14 @@ endfunction nnoremap l :call TabDo('call ToggleRelativeAbsoluteNumber()') +nnoremap qq :bd! " Quick exiting without save -nnoremap qq :qa! +nnoremap qa :qa! +" expand %% to dirname of cur file in commandline +cnoremap %% getcmdtype() == ':' ? expand('%:h').'/' : '%%' + + + +" :Sw to save file by root +command Sw execute 'silent! write !SUDO_ASKPASS=$(which vim_askpass_helper) sudo -A tee % >/dev/null' diff --git a/sub/zsh/aliases b/sub/zsh/aliases index 6a2543b..a05774a 100644 --- a/sub/zsh/aliases +++ b/sub/zsh/aliases @@ -5,4 +5,9 @@ alias -g OUT="1>/dev/null" # stdOUT alias -g ERR="2>/dev/null" # stdERR alias -g ALL="1>/dev/null 2>&1" alias -g BG="&>/dev/null &" + +alias -s mp4='vlc' +alias -s mp3='audacious' +alias -s flac='audacious' + bindkey '`' autosuggest-accept diff --git a/sub/zsh/completion b/sub/zsh/completion index ae3c014..34f8856 100644 --- a/sub/zsh/completion +++ b/sub/zsh/completion @@ -1,8 +1,11 @@ # enable completion features -fpath+=~/.zfunc +fpath=(~/.zfunc $fpath) autoload -Uz compinit compinit -d ~/.cache/zcompdump +compdef _nvim nvim +compdef _files mcd +compdef _poetry poetry zstyle ':completion:*:*:*:*:*' menu select zstyle ':completion:*' auto-description 'specify: %d' zstyle ':completion:*' completer _expand _complete _correct _approximate diff --git a/sub/zsh/history b/sub/zsh/history index 7346767..2477f74 100644 --- a/sub/zsh/history +++ b/sub/zsh/history @@ -4,6 +4,7 @@ export HISTFILE=~/.zsh_history export HISTSIZE=1000 export SAVEHIST=2000 setopt HIST_IGNORE_SPACE +setopt HIST_FIND_NO_DUPS setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE setopt hist_ignore_dups # ignore duplicated commands history list setopt hist_ignore_space # ignore commands that start with space diff --git a/sub/zsh/options b/sub/zsh/options index 5c0783e..5f9f3a7 100644 --- a/sub/zsh/options +++ b/sub/zsh/options @@ -14,7 +14,48 @@ WORDCHARS=${WORDCHARS//\/} # Don't consider certain characters part of the word PROMPT_EOL_MARK="" # configure key keybindings + +# Activate vim mode. bindkey -v + + +# Change cursor shape for different vi modes. +zle-keymap-select() { + if [[ ${KEYMAP} == vicmd ]] || + [[ $1 = 'block' ]]; then + echo -ne '\e[2 q' + + elif [[ ${KEYMAP} == main ]] || + [[ ${KEYMAP} == viins ]] || + [[ ${KEYMAP} = '' ]] || + [[ $1 = 'beam' ]]; then + echo -ne '\e[5 q' + + fi +} + +zle -N zle-keymap-select + +# Use beam shape cursor on startup. +echo -ne '\e[5 q' + +_fix_cursor() { + echo -ne '\e[5 q' +} + +precmd_functions+=(_fix_cursor) + +# Set cursor style (DECSCUSR), VT520. +# 0 -> blinking block. +# 1 -> blinking block (default). +# 2 -> steady block. +# 3 -> blinking underline. +# 4 -> steady underline. +# 5 -> blinking bar, xterm. +# 6 -> steady bar, xterm. + + + bindkey -M viins 'jk' vi-cmd-mode bindkey ' ' magic-space # do history expansion on space bindkey '^[[3;5~' kill-word # ctrl + Supr @@ -30,3 +71,5 @@ bindkey '^U' kill-whole-line bindkey -M vicmd '^U' kill-whole-line bindkey -M viins '^U' kill-whole-line bindkey -M viins '\e.' insert-last-word +bindkey -M vicmd '^K' up-line-or-history +bindkey -M vicmd '^J' down-line-or-history diff --git a/sub/zsh/zfunc/_nvim b/sub/zsh/zfunc/_nvim new file mode 100644 index 0000000..58d124b --- /dev/null +++ b/sub/zsh/zfunc/_nvim @@ -0,0 +1,16 @@ +#compdef nvim +#autoload + + +_nvim() { + subcmds=($(git diff --name-only --relative 2>/dev/null)) + if [[ -z "$subcmds" ]]; then + _files + else + _values -C 'modified files' $subcmds + _files + fi + +} + +_nvim diff --git a/sub/zsh/zfunc/_poetry b/sub/zsh/zfunc/_poetry new file mode 100644 index 0000000..773fdbb --- /dev/null +++ b/sub/zsh/zfunc/_poetry @@ -0,0 +1,197 @@ +#compdef poetry + +_poetry_1733398420f0b696_complete() +{ + local state com cur + local -a opts + local -a coms + + cur=${words[${#words[@]}]} + + # lookup for command + for word in ${words[@]:1}; do + if [[ $word != -* ]]; then + com=$word + break + fi + done + + if [[ ${cur} == --* ]]; then + state="option" + opts+=("--ansi:Force ANSI output." "--directory:The working directory for the Poetry command \(defaults to the current working directory\)." "--help:Display help for the given command. When no command is given display help for the list command." "--no-ansi:Disable ANSI output." "--no-cache:Disables Poetry source caches." "--no-interaction:Do not ask any interactive question." "--no-plugins:Disables plugins." "--quiet:Do not output any message." "--verbose:Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug." "--version:Display this application version.") + elif [[ $cur == $com ]]; then + state="command" + coms+=("about:Shows information about Poetry." "add:Adds a new dependency to pyproject.toml." "build:Builds a package, as a tarball and a wheel by default." "'cache clear':Clears a Poetry cache by name." "'cache list':List Poetry\'s caches." "check:Checks the validity of the pyproject.toml file." "config:Manages configuration settings." "'debug info':Shows debug information." "'debug resolve':Debugs dependency resolution." "'env info':Displays information about the current environment." "'env list':Lists all virtualenvs associated with the current project." "'env remove':Remove virtual environments associated with the project." "'env use':Activates or creates a new virtualenv for the current project." "export:Exports the lock file to alternative formats." "help:Displays help for a command." "init:Creates a basic pyproject.toml file in the current directory." "install:Installs the project dependencies." "list:Lists commands." "lock:Locks the project dependencies." "new:Creates a new Python project at ." "publish:Publishes a package to a remote repository." "remove:Removes a package from the project dependencies." "run:Runs a command in the appropriate environment." "search:Searches for packages on remote repositories." "'self add':Add additional packages to Poetry\'s runtime environment." "'self install':Install locked packages \(incl. addons\) required by this Poetry installation." "'self lock':Lock the Poetry installation\'s system requirements." "'self remove':Remove additional packages from Poetry\'s runtime environment." "'self show':Show packages from Poetry\'s runtime environment." "'self show plugins':Shows information about the currently installed plugins." "'self update':Updates Poetry to the latest version." "shell:Spawns a shell within the virtual environment." "show:Shows information about packages." "'source add':Add source configuration for project." "'source remove':Remove source configured for the project." "'source show':Show information about sources configured for the project." "update:Update the dependencies as according to the pyproject.toml file." "version:Shows the version of the project or bumps it when a valid bump rule is provided.") + fi + + case $state in + (command) + _describe 'command' coms + ;; + (option) + case "$com" in + + (about) + opts+=() + ;; + + (add) + opts+=("--allow-prereleases:Accept prereleases." "--dev:Add as a development dependency. \(Deprecated\)" "--dry-run:Output the operations but do not execute anything \(implicitly enables --verbose\)." "--editable:Add vcs/path dependencies as editable." "--extras:Extras to activate for the dependency." "--group:The group to add the dependency to." "--lock:Do not perform operations \(only update the lockfile\)." "--optional:Add as an optional dependency." "--platform:Platforms for which the dependency must be installed." "--python:Python version for which the dependency must be installed." "--source:Name of the source to use to install the package.") + ;; + + (build) + opts+=("--format:Limit the format to either sdist or wheel.") + ;; + + ('cache clear') + opts+=("--all:Clear all entries in the cache.") + ;; + + ('cache list') + opts+=() + ;; + + (check) + opts+=() + ;; + + (config) + opts+=("--list:List configuration settings." "--local:Set/Get from the project\'s local configuration." "--unset:Unset configuration setting.") + ;; + + ('debug info') + opts+=() + ;; + + ('debug resolve') + opts+=("--extras:Extras to activate for the dependency." "--install:Show what would be installed for the current system." "--python:Python version\(s\) to use for resolution." "--tree:Display the dependency tree.") + ;; + + ('env info') + opts+=("--path:Only display the environment\'s path.") + ;; + + ('env list') + opts+=("--full-path:Output the full paths of the virtualenvs.") + ;; + + ('env remove') + opts+=("--all:Remove all managed virtual environments associated with the project.") + ;; + + ('env use') + opts+=() + ;; + + (export) + opts+=("--dev:Include development dependencies. \(Deprecated\)" "--extras:Extra sets of dependencies to include." "--format:Format to export to. Currently, only constraints.txt and requirements.txt are supported." "--only:The only dependency groups to include." "--output:The name of the output file." "--with:The optional dependency groups to include." "--with-credentials:Include credentials for extra indices." "--without:The dependency groups to ignore." "--without-hashes:Exclude hashes from the exported file." "--without-urls:Exclude source repository urls from the exported file.") + ;; + + (help) + opts+=() + ;; + + (init) + opts+=("--author:Author name of the package." "--dependency:Package to require, with an optional version constraint, e.g. requests:\^2.10.0 or requests=2.11.1." "--description:Description of the package." "--dev-dependency:Package to require for development, with an optional version constraint, e.g. requests:\^2.10.0 or requests=2.11.1." "--license:License of the package." "--name:Name of the package." "--python:Compatible Python versions.") + ;; + + (install) + opts+=("--all-extras:Install all extra dependencies." "--dry-run:Output the operations but do not execute anything \(implicitly enables --verbose\)." "--extras:Extra sets of dependencies to install." "--no-dev:Do not install the development dependencies. \(Deprecated\)" "--no-root:Do not install the root package \(the current project\)." "--only:The only dependency groups to include." "--only-root:Exclude all dependencies." "--remove-untracked:Removes packages not present in the lock file. \(Deprecated\)" "--sync:Synchronize the environment with the locked packages and the specified groups." "--with:The optional dependency groups to include." "--without:The dependency groups to ignore.") + ;; + + (list) + opts+=() + ;; + + (lock) + opts+=("--check:Check that the poetry.lock file corresponds to the current version of pyproject.toml." "--no-update:Do not update locked versions, only refresh lock file.") + ;; + + (new) + opts+=("--name:Set the resulting package name." "--readme:Specify the readme file format. One of md \(default\) or rst" "--src:Use the src layout for the project.") + ;; + + (publish) + opts+=("--build:Build the package before publishing." "--cert:Certificate authority to access the repository." "--client-cert:Client certificate to access the repository." "--dry-run:Perform all actions except upload the package." "--password:The password to access the repository." "--repository:The repository to publish the package to." "--skip-existing:Ignore errors from files already existing in the repository." "--username:The username to access the repository.") + ;; + + (remove) + opts+=("--dev:Remove a package from the development dependencies. \(Deprecated\)" "--dry-run:Output the operations but do not execute anything \(implicitly enables --verbose\)." "--group:The group to remove the dependency from.") + ;; + + (run) + opts+=() + ;; + + (search) + opts+=() + ;; + + ('self add') + opts+=("--allow-prereleases:Accept prereleases." "--dry-run:Output the operations but do not execute anything \(implicitly enables --verbose\)." "--editable:Add vcs/path dependencies as editable." "--extras:Extras to activate for the dependency." "--source:Name of the source to use to install the package.") + ;; + + ('self install') + opts+=("--dry-run:Output the operations but do not execute anything \(implicitly enables --verbose\)." "--sync:Synchronize the environment with the locked packages and the specified groups.") + ;; + + ('self lock') + opts+=("--check:Check that the poetry.lock file corresponds to the current version of pyproject.toml." "--no-update:Do not update locked versions, only refresh lock file.") + ;; + + ('self remove') + opts+=("--dry-run:Output the operations but do not execute anything \(implicitly enables --verbose\).") + ;; + + ('self show') + opts+=("--addons:List only add-on packages installed." "--latest:Show the latest version." "--outdated:Show the latest version but only for packages that are outdated." "--tree:List the dependencies as a tree.") + ;; + + ('self show plugins') + opts+=() + ;; + + ('self update') + opts+=("--dry-run:Output the operations but do not execute anything \(implicitly enables --verbose\)." "--preview:Allow the installation of pre-release versions.") + ;; + + (shell) + opts+=() + ;; + + (show) + opts+=("--all:Show all packages \(even those not compatible with current system\)." "--latest:Show the latest version." "--no-dev:Do not list the development dependencies. \(Deprecated\)" "--only:The only dependency groups to include." "--outdated:Show the latest version but only for packages that are outdated." "--tree:List the dependencies as a tree." "--why:When showing the full list, or a --tree for a single package, also display why it\'s included." "--with:The optional dependency groups to include." "--without:The dependency groups to ignore.") + ;; + + ('source add') + opts+=("--default:Set this source as the default \(disable PyPI\). A default source will also be the fallback source if you add other sources." "--secondary:Set this source as secondary.") + ;; + + ('source remove') + opts+=() + ;; + + ('source show') + opts+=() + ;; + + (update) + opts+=("--dry-run:Output the operations but do not execute anything \(implicitly enables --verbose\)." "--lock:Do not perform operations \(only update the lockfile\)." "--no-dev:Do not update the development dependencies. \(Deprecated\)" "--only:The only dependency groups to include." "--with:The optional dependency groups to include." "--without:The dependency groups to ignore.") + ;; + + (version) + opts+=("--dry-run:Do not update pyproject.toml file" "--short:Output the version number only") + ;; + + esac + + _describe 'option' opts + ;; + *) + # fallback to file completion + _arguments '*:file:_files' + esac +} + +_poetry_1733398420f0b696_complete "$@" +compdef _poetry_1733398420f0b696_complete /home/kan/.local/bin/poetry diff --git a/sub/zsh/zshrc.d/00_test.sh b/sub/zsh/zshrc.d/00_test.sh new file mode 100644 index 0000000..729aa7f --- /dev/null +++ b/sub/zsh/zshrc.d/00_test.sh @@ -0,0 +1,2 @@ + +# Add here files to source it in ascending order like "01_hello.sh"