commit 6fa77b0a86714f32a9a7bee82fb5c75897cd7f10 Author: Lee Tang Date: Sat Mar 12 08:41:28 2022 +0800 init diff --git a/.Brewfile.Darwin.mbp-arm64 b/.Brewfile.Darwin.mbp-arm64 new file mode 100644 index 0000000..d660f4c --- /dev/null +++ b/.Brewfile.Darwin.mbp-arm64 @@ -0,0 +1,148 @@ +tap "blendle/blendle" +tap "bufbuild/buf" +tap "homebrew/bundle" +tap "homebrew/cask" +tap "homebrew/cask-drivers" +tap "homebrew/cask-fonts" +tap "homebrew/cask-versions" +tap "homebrew/core" +tap "homebrew/services" +tap "jesseduffield/lazygit" +tap "mongodb/brew" +tap "muesli/tap" +tap "universal-ctags/universal-ctags" +tap "wez/wezterm" +brew "autojump" +brew "automake" +brew "awscli" +brew "bat" +brew "bpytop" +brew "bzip2" +brew "llvm" +brew "ccls" +brew "cmake" +brew "coreutils" +brew "ctags", link: false +brew "dosbox" +brew "dpkg" +brew "fzf" +brew "gcc" +brew "gh" +brew "git" +brew "glib" +brew "unbound" +brew "gnutls" +brew "gnupg" +brew "go" +brew "grpcurl" +brew "hadoop" +brew "hbase" +brew "helm" +brew "htop" +brew "imagemagick" +brew "jmeter" +brew "jq" +brew "k9s" +brew "zookeeper" +brew "kafka" +brew "kind" +brew "kompose" +brew "kubernetes-cli" +brew "krew" +brew "kubectx" +brew "lazygit" +brew "lbzip2" +brew "qemu" +brew "lima" +brew "lrzsz" +brew "lsd" +brew "lua" +brew "luarocks" +brew "lzlib" +brew "maven" +brew "minikube" +brew "protobuf" +brew "mosh" +brew "mysql" +brew "neofetch" +brew "neovim" +brew "nghttp2" +brew "nload" +brew "nmap" +brew "node" +brew "openssl@3" +brew "podman" +brew "postgresql", restart_service: true +brew "pyenv" +brew "pyenv-virtualenv" +brew "python@3.8" +brew "rabbitmq" +brew "rclone" +brew "rebar3" +brew "redis", restart_service: true +brew "ripgrep" +brew "ruby" +brew "ruby@2.7" +brew "rust" +brew "rustup-init" +brew "socat" +brew "sshuttle" +brew "starship" +brew "stylua" +brew "telnet" +brew "the_silver_searcher" +brew "thrift" +brew "tmux" +brew "velero" +brew "wakeonlan" +brew "wget" +brew "zlib" +brew "zsh" +brew "bufbuild/buf/buf" +brew "mongodb/brew/mongodb-community" +brew "muesli/tap/duf" +brew "universal-ctags/universal-ctags/universal-ctags", args: ["HEAD"] +cask "adoptopenjdk" +cask "adoptopenjdk8" +cask "anki" +cask "balenaetcher" +cask "beyond-compare" +cask "brave-browser" +cask "calibre" +cask "charles" +cask "clashx" +cask "daisydisk" +cask "discord" +cask "font-jetbrains-mono-nerd-font" +cask "google-chrome" +cask "google-cloud-sdk" +cask "google-drive" +cask "hiddenbar" +cask "iina" +cask "iterm2" +cask "jetbrains-toolbox" +cask "lark" +cask "neteasemusic" +cask "netnewswire" +cask "notion" +cask "openemu" +cask "openvpn-connect" +cask "paw" +cask "postman" +cask "qq" +cask "qqmusic" +cask "racket" +cask "raycast" +cask "rectangle" +cask "sourcetree" +cask "spotify" +cask "stats" +cask "sunlogincontrol" +cask "surge" +cask "telegram" +cask "typora" +cask "visual-studio-code" +cask "wechat" +cask "wechatwork" +cask "wezterm-nightly" +cask "zerotier-one" diff --git a/.Brewfile.Darwin.mbp-x86-64 b/.Brewfile.Darwin.mbp-x86-64 new file mode 100644 index 0000000..3f62d27 --- /dev/null +++ b/.Brewfile.Darwin.mbp-x86-64 @@ -0,0 +1,144 @@ +tap "blendle/blendle" +tap "bufbuild/buf" +tap "homebrew/bundle" +tap "homebrew/cask" +tap "homebrew/cask-drivers" +tap "homebrew/cask-fonts" +tap "homebrew/cask-versions" +tap "homebrew/core" +tap "homebrew/services" +tap "jesseduffield/lazygit" +tap "mongodb/brew" +tap "muesli/tap" +tap "universal-ctags/universal-ctags" +tap "wez/wezterm" +brew "readline" +brew "sqlite" +brew "xz" +brew "python@3.10" +brew "autojump" +brew "automake" +brew "awscli" +brew "bat" +brew "bpytop" +brew "llvm" +brew "ccls" +brew "cmake" +brew "coreutils" +brew "ctags", link: false +brew "dosbox" +brew "dpkg" +brew "fzf" +brew "gcc" +brew "gh" +brew "glib" +brew "unbound" +brew "gnutls" +brew "gnupg" +brew "go" +brew "grpcurl" +brew "hadoop" +brew "hbase" +brew "helm" +brew "htop" +brew "imagemagick" +brew "jmeter" +brew "jq" +brew "k9s" +brew "zookeeper" +brew "kafka" +brew "kind" +brew "kompose" +brew "kubernetes-cli" +brew "kubectx" +brew "lazygit" +brew "lima" +brew "lrzsz" +brew "lsd" +brew "lua" +brew "luarocks" +brew "maven" +brew "minikube" +brew "node@14" +brew "protobuf" +brew "mysql" +brew "neofetch" +brew "neovim" +brew "nghttp2" +brew "nload" +brew "nmap" +brew "node" +brew "openssl@3" +brew "podman" +brew "postgresql", restart_service: true +brew "pyenv" +brew "pyenv-virtualenv" +brew "python@3.8" +brew "rabbitmq" +brew "rclone" +brew "rebar3" +brew "redis", restart_service: true +brew "ripgrep" +brew "ruby" +brew "ruby@2.7" +brew "rustup-init" +brew "shfmt" +brew "socat" +brew "sshuttle" +brew "starship" +brew "stylua" +brew "telnet" +brew "the_silver_searcher" +brew "thrift" +brew "tmux" +brew "velero" +brew "wakeonlan" +brew "wget" +brew "zlib" +brew "zsh" +brew "bufbuild/buf/buf" +brew "mongodb/brew/mongodb-community" +brew "muesli/tap/duf" +brew "universal-ctags/universal-ctags/universal-ctags", args: ["HEAD"] +cask "adoptopenjdk" +cask "adoptopenjdk8" +cask "anki" +cask "balenaetcher" +cask "beyond-compare" +cask "brave-browser" +cask "calibre" +cask "charles" +cask "clashx" +cask "daisydisk" +cask "discord" +cask "font-jetbrains-mono-nerd-font" +cask "google-chrome" +cask "google-cloud-sdk" +cask "google-drive" +cask "iina" +cask "iterm2" +cask "jetbrains-toolbox" +cask "lark" +cask "logitech-options" +cask "monodraw" +cask "neteasemusic" +cask "netnewswire" +cask "notion" +cask "openemu" +cask "paw" +cask "postman" +cask "qbittorrent" +cask "qq" +cask "qqmusic" +cask "racket" +cask "raycast" +cask "sourcetree" +cask "spotify" +cask "stats" +cask "surge" +cask "telegram" +cask "typora" +cask "visual-studio-code" +cask "wechat" +cask "wechatwork" +cask "wezterm-nightly" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1944d95 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +nvim/plugin/ +nvim/.netrwhist +*.env +.git/ +.DS_Store diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..65efe48 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tmux/plugins/tpm"] + path = tmux/plugins/tpm + url = https://github.com/tmux-plugins/tpm diff --git a/.ideavimrc b/.ideavimrc new file mode 100644 index 0000000..3af6363 --- /dev/null +++ b/.ideavimrc @@ -0,0 +1,55 @@ +"" Source your .vimrc +"source ~/.vimrc + +"" -- Suggested options -- +" Show a few lines of context around the cursor. Note that this makes the +" text scroll if you mouse-click near the start or end of the window. +set scrolloff=5 + +" Do incremental searching. +set incsearch +set easymotion + +let mapleader="\" +" Don't use Ex mode, use Q for formatting. +map Q gq + + +map l (easymotion-lineforward) +map j (easymotion-j) +map k (easymotion-k) +map h (easymotion-linebackward) +map w (easymotion-w) +map b (easymotion-b) +nmap s (easymotion-s2) +nmap t (easymotion-t2) + +let g:EasyMotion_smartcase = 1 + +" ==== 系统剪切板复制粘贴 ==== +" v 模式下复制内容到系统剪切板 +vmap c "+yy +" n 模式下复制一行到系统剪切板 +nmap c "+yy +" n 模式下粘贴系统剪切板的内容 +nmap v "+p + + + +"" -- Map IDE actions to IdeaVim -- https://jb.gg/abva4t +"" Map \r to the Reformat Code action +"map \r (ReformatCode) + +"" Map d to start debug +"map d (Debug) + +"" Map \b to toggle the breakpoint on the current line +"map \b (ToggleLineBreakpoint) + + +" Find more examples here: https://jb.gg/share-ideavimrc + +map("i", "", "b") +map("i", "", "l") +map("i", "", "j") +map("i", "", "k") diff --git a/.tmux.conf b/.tmux.conf new file mode 100644 index 0000000..6b74c68 --- /dev/null +++ b/.tmux.conf @@ -0,0 +1,118 @@ +# ==== Common ==== +# rebind PREFIX to C-a +set-option -g prefix C-a + +# set title for terminal(using tmux sesion/window name) +set-option -g set-titles on +set-option -g set-titles-string "#S / #W" + +# send interval to 1s to avoid conflicts with vim +set -sg escape-time 1 +# set session starts with 1 +set -g base-index 1 +# set pane starts with 1 +setw -g pane-base-index 1 +# enable mouse +set -g mouse on +# set history limit +set -g history-limit 10000 +# reload config +bind r source-file ~/.tmux.conf \; display "Reloaded!" +# send C-a to other apps +bind C-a send-prefix +# split window horizontally +bind | split-window -h -c "#{pane_current_path}" +# split window vertically +bind - split-window -v -c "#{pane_current_path}" +# create new window with current path +bind c new-window -c "#{pane_current_path}" +# reorder windows +bind R \ + move-window -r\; \ + display-message "Windows reordered..." + +# move cursor between panes +bind h select-pane -L +bind j select-pane -D +bind k select-pane -U +bind l select-pane -R + +# rename session/window +bind n command-prompt 'rename-window %%' +bind N command-prompt 'rename-session %%' + +# switch window +bind-key , previous-window # < +bind-key . next-window # > +bind-key < swap-window -t :- +bind-key > swap-window -t :+ +# move cursor between windows +bind -r C-h select-window -t :- +bind -r C-l select-window -t :+ + +# ajdust pane size +bind -r H resize-pane -L 5 +bind -r J resize-pane -D 5 +bind -r K resize-pane -U 5 +bind -r L resize-pane -R 5 + +set-window-option -g mode-keys vi +bind-key -T copy-mode-vi v send -X begin-selection +bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" +bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy" +bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy" + +# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) +run '~/.config/tmux/plugins/tpm/tpm' + +# List of plugins +set -g @plugin 'tmux-plugins/tpm' +set -g @plugin 'tmux-plugins/tmux-sensible' +set -g @plugin 'tmux-plugins/tmux-resurrect' +set -g @plugin 'tmux-plugins/tmux-continuum' +set -g @continuum-restore 'on' +set -g @continuum-save-interval '30' + +# Colors +set -g default-terminal "screen-256color" +set -g terminal-overrides ',xterm-256color:Tc' + +# Dracula Color +white='#f8f8f2' # Foreground +dark_gray='#282a36' # Background +gray='#44475a' # Current Line / Selection +light_purple='#bd93f9' # Purple +dark_purple='#6272a4' # Comment +cyan='#8be9fd' # Cyan +green='#50fa7b' # Green +orange='#ffb86c' # Orange +red='#ff5555' # Red +pink='#ff79c6' # Pink +yellow='#f1fa8c' # Yellow + +set -g status on +set -g status-fg $dark_purple +set -g status-bg $gray +set -g status-justify left +set -g status-interval 1 + +set -g status-left-length 100 +set -g status-right-length 100 + +# Options -> ⧉ ❐ +set -g status-left "#{?client_prefix,#[fg=$dark_gray bg=$green],#[fg=$dark_gray bg=$light_purple]} ⧉ #S " +set -g status-right "#[fg=$white] #{pane_current_path}" + +set-window-option -g window-status-current-style "fg=$dark_purple bg=$white" +set-window-option -g window-status-current-format "#[bold italics] #I: #W #F " + +# for some unknown reason this tmux section is being set to reverse from +# somewhere so we explictly remove it here +set-window-option -g window-status-style "fg=$dark_gray dim" +set-window-option -g window-status-format "#[none] #I: #{=20:window_name} " +set-window-option -g window-status-separator "" + +# Set window notifications +set-option -g monitor-activity on +set-option -g visual-activity off + diff --git a/.zlogin b/.zlogin new file mode 100644 index 0000000..6607c4c --- /dev/null +++ b/.zlogin @@ -0,0 +1 @@ +workup diff --git a/.zshrc b/.zshrc new file mode 100644 index 0000000..3d83834 --- /dev/null +++ b/.zshrc @@ -0,0 +1,175 @@ +export GOPATH=$HOME/.go +export GOPROXY=https://goproxy.cn,direct + +export PYENV_ROOT="$HOME/.pyenv" +export PYENV_VIRTUALENV_DISABLE_PROMPT=1 + +export CARGO_PATH=$HOME/.cargo + +export PATH="/opt/homebrew/sbin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin" +export PATH="$CARGO_PATH/bin:$GOPATH/bin:$PYENV_ROOT/shims:$PATH" +export PATH="$HOME/.local/bin:${HOME}/.krew/bin:$PATH" + +source $HOME/.antigen/antigen.zsh + +antigen use oh-my-zsh + +antigen bundle git +antigen bundle pip +antigen bundle kubectl +antigen bundle pyenv +antigen bundle vi-mode +antigen bundle autojump +antigen bundle Aloxaf/fzf-tab +antigen bundle wbingli/zsh-wakatime + +antigen bundle zsh-users/zsh-autosuggestions +antigen bundle zsh-users/zsh-syntax-highlighting +antigen bundle zsh-users/zsh-completions + +#antigen theme spaceship-prompt/spaceship-prompt + +antigen apply + +eval "$(starship init zsh)" + +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} + + +export LC_ALL=en_US.UTF-8 +export LANG=en_US.UTF-8 +export MANPAGER="sh -c \"col -b | vim -c 'set ft=man ts=8 nomod nolist nonu' \ + -c 'nnoremap i ' \ + -c 'nnoremap ' \ + -c 'noremap q :quit' -\"" +export KUBECONFIG=$(echo `ls ~/.kube/*config*` | sed 's/ /:/g') +export FZF_DEFAULT_OPTS="--height=50% --layout=reverse" + +arch=$(uname -m) +if [ $arch = "x86_64" ]; then + brew_opt="/usr/local/opt" +elif [ $arch = "arm64" ]; then + brew_opt="/opt/homebrew/opt" +fi +LDFLAGS="-L$brew_opt/zlib/lib -L$brew_opt/openssl@3/lib" +CPPFLAGS="-I$brew_opt/zlib/include -I$brew_opt/openssl@3/include" + +export LDFLAGS=$LDFLAGS +export CPPFLAGS=$CPPFLAGS + + +autoload -Uz compinit +compinit + +source <(kubectl completion zsh) +source <(helm completion zsh) + + +alias ta='tmux a' +alias fixscreen='sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.screensharing.plist && sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist' +alias urldecode='python3 -c "import sys, urllib.parse as ul; \ + print(ul.unquote_plus(sys.argv[1]))"' +alias urlencode='python3 -c "import sys, urllib.parse as ul; \ + print (ul.quote_plus(sys.argv[1]))"' +alias zerotier_reload='sudo launchctl unload /Library/LaunchDaemons/com.zerotier.one.plist && sudo launchctl load /Library/LaunchDaemons/com.zerotier.one.plist' +alias git_branch="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'" +alias git_clean="git branch --merged | grep -v 'master' | grep -v 'main' | cat | xargs git branch -d" +#alias pyjson_decode='python3 -c "import sys, json; \ +#print(json.dumps(eval(sys.argv[1])))"' +alias pyjson_decode_stdout='python3 -c "import sys, json, subprocess; \ + print(json.dumps(eval(subprocess.check_output( \ + \"pbpaste\", env={\"LANG\": \"en_US.UTF-8\"}).decode(\"utf-8\"))))"' +alias pyjson_decode='python3 -c "import json, subprocess; \ + output=json.dumps(eval(subprocess.check_output(\ + \"pbpaste\", env={\"LANG\": \"en_US.UTF-8\"}).decode(\"utf-8\"))).encode(\"utf-8\"); \ + process=subprocess.Popen(\"pbcopy\", env={\"LANG\": \"en_US.UTF-8\"}, stdin=subprocess.PIPE); \ + process.communicate(output)"' +alias ts_fmt='python3 -c "import datetime, subprocess; \ + print(\"UTC+800:\", datetime.datetime.fromtimestamp(int(subprocess.check_output(\"pbpaste\", env={\"LANG\": \"en_US.UTF-8\"}).decode(\"utf-8\")))); \ + print(\"UTC+000:\", datetime.datetime.fromtimestamp(int(subprocess.check_output(\"pbpaste\", env={\"LANG\": \"en_US.UTF-8\"}).decode(\"utf-8\"))-8*3600)); \ + "' +alias leetcode_today='curl -sL "https://leetcode-cn.com/graphql" -H "content-type: application/json" -d '\''{"operationName":"questionOfToday","variables":{},"query":"query questionOfToday {\n todayRecord {\n question {\n questionFrontendId\n questionTitleSlug\n __typename\n }\n lastSubmission {\n id\n __typename\n }\n date\n userStatus\n __typename\n }\n}\n"}'\'' | jq '\''.data.todayRecord[0].question'\''' +alias clean_tmux_session='ls ~/.tmux/resurrect/* -1dtr | head -n 100 | xargs rm -v' +alias tl='tmux ls && read session && tmux attach -t ${session:-default} || tmux new -s ${session:-default}' +alias ls='lsd' +alias l='ls -l' +alias la='ls -a' +alias lla='ls -la' +alias lt='ls --tree' +alias kns='kubens' +alias kctx='kubectx' +alias kd='kubectl debug' +alias kk='kubectl krew' +alias vim='nvim' +alias vi='nvim' +alias jumper='ssh tangli@10.1.4.14 -p 32200' +alias wol_xps8940="host root.pi.d0zingcat.xyz | cut -d ' ' -f 4 | cat | xargs -I {} /usr/local/bin/wakeonlan -i {} -p 30009 'FC:44:82:13:BA:0F'" +alias nerdctl='lima nerdctl' +alias docker='lima docker' + + +function workup() { + if [[ -n "$TMUX" ]]; then + return 0 + fi + tmux ls -F '#{session_name}' | fzf --bind=enter:replace-query+print-query |xargs echo | read session && tmux attach -t ${session:-default} || tmux new -s ${session:-default} +} + + +# kill porcess according to keyword +function s_kill() { + key=$1 + if [ -z "$key" ]; then + echo "plz specify at least one keyword" + fi + ps -ef | grep $key | head -n 1 | awk '{print $2}' | xargs kill +} + +macnst (){ + netstat -Watnlv | grep LISTEN | awk '{"ps -o comm= -p " $9 | getline procname;colred="\033[01;31m";colclr="\033[0m"; print colred "proto: " colclr $1 colred " | addr.port: " colclr $4 colred " | pid: " colclr $9 colred " | name: " colclr procname; }' | column -t -s "|" +} + +# proxy by clashx +function clashproxy() { + # shadowsocksx-r + local proxy=http://127.0.0.1:7890 + export https_proxy=$proxy http_proxy=$proxy all_proxy=socks5://127.0.0.1:7891; + echo "proxy all set!" +} + +# unset proxy +function clashproxy_unset() { + unset http_proxy + unset https_proxy + unset all_proxy + echo "proxy all unset!" +} +function flush-input() { + sudo killall -9 PAH_Extension TextInputMenuAgent TextInputSwitcher +} + +function klogs() { + keyword=$1 + k get pods --sort-by=.metadata.creationTimestamp | grep "$keyword" | head -n 1 | awk '{print $1}' | xargs kubectl logs -f +} + + + +#export LESS_TERMCAP_so=$'\E[30;43m' + +if [ $(uname -m) = 'arm64' ]; then + eval "$(/opt/homebrew/bin/brew shellenv)" +fi + +#neofetch + +#export LDFLAGS="-L/usr/local/opt/llvm/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -L/usr/local/opt/zlib/lib -L/usr/local/opt/bzip2/lib" +#export CPPFLAGS="-I/usr/local/opt/llvm/include -I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include" +#export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig" + +[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh +[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh +[ -f /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc ] && . /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc + +compdef __start_kubectl k + diff --git a/README.md b/README.md new file mode 100644 index 0000000..9d29c89 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# dotfiles +My dotfiles. diff --git a/git/.gitignore b/git/.gitignore new file mode 100644 index 0000000..2073a94 --- /dev/null +++ b/git/.gitignore @@ -0,0 +1,5 @@ +*.env +.git/ +.DS_Store +.python-version +.mypy_cache/ diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..54635ee --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,200 @@ +local cmd = vim.cmd +local o_s = vim.o +local map_key = vim.api.nvim_set_keymap +local g = vim.g +local api = vim.api +local fn = vim.fn +local ncmd = vim.api.nvim_command +local o, wo, bo = vim.o, vim.wo, vim.bo + +local buffer = { o, bo } +local window = { o, wo } + +local utils = require('utils') +local map = utils.map +local set = utils.set + +--vim.lsp.set_log_level('debug') +-- Preset +-- Prerequisites Must have neovim installed +if fn.has('nvim') == 0 then + return +end + +-- Ensure packer installed +local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' +if fn.empty(fn.glob(install_path)) > 0 then + fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }) + cmd('packadd packer.nvim') +end + +-- reopen last position +-- cmd([[ autocmd BufReadPost * normal! g`" ]]) + +-- Shcemas and colors +set('termguicolors', true) -- 开启24bit的颜色,开启这个颜色会更漂亮一些 +--cmd [[ colorscheme onebuddy ]] +cmd([[ colorscheme tokyonight ]]) +--set('background', 'dark') -- 主题背景 dark-深色; light-浅色 + +-- CMDs +-- cmd [[syntax enable]] +-- cmd [[syntax on]] -- 开启文件类型侦测 +cmd('filetype plugin indent on') +cmd([[ autocmd FileType php setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=120 ]]) +cmd([[ autocmd FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4 ]]) +cmd([[ autocmd FileType json setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab ]]) +cmd([[ autocmd FileType go setlocal tabstop=8 shiftwidth=8 softtabstop=8 textwidth=120 noexpandtab ]]) +cmd([[ autocmd FileType html,htmldjango,xhtml,haml setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=0 ]]) +cmd([[ autocmd FileType yaml setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=0 expandtab ]]) +cmd([[ autocmd FileType ruby setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=120 ]]) +cmd([[ autocmd FileType less,sass,scss,css setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=120 ]]) +cmd( + [[ autocmd FileType javascript,javascript.jsx,javascriptreact,typescript,typescriptreact setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab ]] +) + +cmd([[iabbrev pdb import pdb; pdb.set_trace()]]) +-- auto compile packer +cmd([[ +augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerCompile +augroup end +]]) + +-- cmd [[command ShowBlank set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣]] + +-- Settings +-- max timeout for common command +set('timeoutlen', 1000) +-- set number, cusor or line/column +set('nu', true, window) +set('rnu', true, window) +set('cul', true, window) +set('cuc', true, window) + +-- tab 缩进 +-- set("tabstop", 4) -- 设置Tab长度为4空格 +-- set("shiftwidth", 4) -- 设置自动缩进长度为4空格 +-- set("autoindent", true) -- 继承前一行的缩进方式,适用于多行注释 +-- set("colorcolumn", "80") -- 设置长度提示79 +-- set('noswapfile', true) -- 不设置swap文件 + +set('showmatch', true) -- 显示括号匹配 +set('mouse', 'a') -- set scroll mode +set('langmenu', 'zh_CN.UTF-8') +set('helplang', 'cn') +set('encoding', 'utf-8') +set('fencs', 'utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936') +set('hidden', true) +set('wildmenu', true) +set('hlsearch', true) +set('matchtime', 1) +set('updatetime', 100) +set('smarttab', true) +set('expandtab', true) +set('laststatus', 2) +set('showcmd', true) +set('ruler', true) +set('history', 300) +set('backup', false) +set('swapfile', false) +set('foldenable', false) +set('autoread', true) +set('autowrite', true) +set('mouse', 'a') +set('incsearch', true) -- 开启实时搜索 +set('ignorecase', true) -- 搜索时大小写不敏感 + +set('number', true, window) +-- set('relativenumber', true, window) +set('cursorline', true, window) +set('cursorcolumn', true, window) +set('signcolumn', 'auto:2') + +-- set("textwidth", 120, buffer) +set('smartindent', true, buffer) +set('autoindent', true, buffer) +set('cindent', true, buffer) +set('shiftwidth', 4, buffer) +set('softtabstop', 4, buffer) +set('tabstop', 4, buffer) + +-- set autowrite +-- set("backspace", "indent,eol,start") + +-- Key mappings +-- map Leader key to +g.mapleader = [[ ]] + +-- v 模式下复制内容到系统剪切板 +map('v', 'cp', '"+yy') +-- n 模式下复制一行到系统剪切板 +map('n', 'cp', '"+yy') +-- n 模式下粘贴系统剪切板的内容 +map('n', 'v', '"+p') +-- reload vimrc +map('n', 'rv', ':source $MYVIMRC') + +-- insert mode mapping +map('i', '', 'b') +map('i', '', 'l') +map('i', '', 'j') +map('i', '', 'k') + +map('n', '', '') +map('i', '', '') + +--map('i', '', '') +--map('i', '', '') +--map('i', '', '') +--map('i', '', '') + +-- map('n', 'e', '1w') +-- map('n', 'p', ':wincmd p') + +--" Plug 'airblade/vim-gitgutter' + +map('i', '', 'copilot#Accept()', { expr = true }) +vim.g.copilot_no_tab_map = 1 +vim.g.copilot_no_maps = 1 +vim.g.copilot_assume_mapped = 1 + +require('plugins') + +-- Plug settings + +-- map("n", "e", ":NvimTreeToggle", {noremap = false}) +-- map("n", "R", ":NvimTreeRefresh", {noremap = false}) + +-- Neoformat +if not fn.executable('luafmt') then + cmd([[ :!npm install -g lua-fmt]]) +end + +-- todo-comments +-- require("todo-comments").setup {} + +-- spaceline +g['spaceline_seperate_style'] = 'arrow' +g['spaceline_colorscheme'] = 'one' + +-- barbar +local opts = { noremap = true, silent = true } +map('n', '=', ':BufferPick', opts) + +-- choosewin +map('n', '-', '(choosewin)', { noremap = false }) + +-- Some configurations not able to migrate +api.nvim_exec( + [[ +" set nocompatible +"function! NearestMethodOrFunction() abort +" return get(b:, 'vista_nearest_method_or_function', '') +"endfunction +" +"set statusline+=%{NearestMethodOrFunction()} +]], + false +) diff --git a/nvim/lua/config/copilot.lua b/nvim/lua/config/copilot.lua new file mode 100644 index 0000000..e69de29 diff --git a/nvim/lua/config/gitsigns.lua b/nvim/lua/config/gitsigns.lua new file mode 100644 index 0000000..ee71c99 --- /dev/null +++ b/nvim/lua/config/gitsigns.lua @@ -0,0 +1,33 @@ +require('gitsigns').setup({ + signs = { + add = { hl = 'GitSignsAdd', text = '┋', numhl = 'GitSignsAddNr', linehl = 'GitSignsAddLn' }, + change = { hl = 'GitSignsChange', text = '┋', numhl = 'GitSignsChangeNr', linehl = 'GitSignsChangeLn' }, + delete = { hl = 'GitSignsDelete', text = '⇉', numhl = 'GitSignsDeleteNr', linehl = 'GitSignsDeleteLn' }, + topdelete = { hl = 'GitSignsDelete', text = '⇊', numhl = 'GitSignsDeleteNr', linehl = 'GitSignsDeleteLn' }, + changedelete = { hl = 'GitSignsChange', text = '~', numhl = 'GitSignsChangeNr', linehl = 'GitSignsChangeLn' }, + }, + keymaps = { + -- Default keymap options + noremap = true, + + ['n ]c'] = { expr = true, "&diff ? ']c' : 'lua require\"gitsigns.actions\".next_hunk()'" }, + ['n [c'] = { expr = true, "&diff ? '[c' : 'lua require\"gitsigns.actions\".prev_hunk()'" }, + }, + word_diff = false, + current_line_blame = true, + linehl = true, + numhl = true, + sign_priority = 6, + count_chars = { + [1] = '1', -- '₁', + [2] = '2', -- '₂', + [3] = '3', -- '₃', + [4] = '4', -- '₄', + [5] = '5', -- '₅', + [6] = '6', -- '₆', + [7] = '7', -- '₇', + [8] = '8', -- '₈', + [9] = '9', -- '₉', + ['+'] = '', -- '₊', + }, +}) diff --git a/nvim/lua/config/lsp_servers/yamlls.lua b/nvim/lua/config/lsp_servers/yamlls.lua new file mode 100644 index 0000000..25c29e0 --- /dev/null +++ b/nvim/lua/config/lsp_servers/yamlls.lua @@ -0,0 +1,11 @@ +return { + filetypes = { 'yaml', 'yml' }, + settings = { + yaml = { + schemas = { + ['https://json.schemastore.org/github-workflow.json'] = '/.github/workflows/*', + Kubernetes = '/*k8s.yaml', + }, + }, + }, +} diff --git a/nvim/lua/config/lspconfig.lua b/nvim/lua/config/lspconfig.lua new file mode 100644 index 0000000..80fe00d --- /dev/null +++ b/nvim/lua/config/lspconfig.lua @@ -0,0 +1,125 @@ +local lsp = vim.lsp +local api = vim.api +local cmd = vim.cmd + +local lsp_installer = require('nvim-lsp-installer') +local lsp_installer_servers = require('nvim-lsp-installer.servers') + +-- lspconfig && lspinstaller +local on_attach = function(client, bufnr) + local function buf_set_keymap(...) + api.nvim_buf_set_keymap(bufnr, ...) + end + local function buf_set_option(...) + api.nvim_buf_set_option(bufnr, ...) + end + --require "lsp_signature".on_attach() + + -- Enable completion triggered by + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local opts = { noremap = true, silent = true } + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('n', 'gr', 'Telescope lsp_references', opts) + buf_set_keymap('n', 'gd', 'Telescope lsp_definitions', opts) + buf_set_keymap('n', 'go', 'Telescope lsp_document_symbols', opts) + buf_set_keymap('n', 'gO', 'Telescope lsp_workspace_symbols', opts) + --buf_set_keymap("n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) + + if client.resolved_capabilities.document_formatting then + vim.cmd([[ + augroup Format + au! * + au BufWritePre lua vim.lsp.buf.formatting_sync(nil, 1000) + augroup END + ]]) + end +end + +local capabilities = lsp.protocol.make_client_capabilities() +capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) + +-- Register a handler that will be called for all installed servers. +-- Alternatively, you may also register handlers on specific server instances instead (see example below). +lsp_installer.on_server_ready(function(server) + local opts = { + on_attach = on_attach, + capabilities = capabilities, + flags = { + debounce_text_changes = 150, + }, + } + + if server.name == 'sumneko_lua' then + local luadev = require('lua-dev').setup({ + lspconfig = { + settings = { + Lua = { + workspace = { + checkThirdParty = false, + }, + }, + }, + }, + }) + opts = vim.tbl_deep_extend('force', opts, luadev) + end + + if server.name == 'yamlls' then + --local yamlls_opts = { + --settings = { + --yaml = { + --filetypes = { 'yaml', 'yml' }, + --schemaStore = { + --enable = true, + --url = 'https://www.schemastore.org/api/json/catalog.json', + --}, + --validate = false, + --schemas = { + --['https://json.schemastore.org/github-workflow.json'] = '/.github/workflows/*', + --kubernetes = '/*.k8s.yaml', + --}, + --}, + --}, + --} + local conf = require(string.format('config.lsp_servers.%s', server.name)) + opts = vim.tbl_deep_extend('force', opts, conf) + end + -- (optional) Customize the options passed to the server + -- if server.name == "tsserver" then + -- opts.root_dir = function() ... end + -- end + + -- This setup() function is exactly the same as lspconfig's setup function. + -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md + server:setup(opts) +end) + +local null_ls = require('null-ls') +null_ls.setup({ + sources = { + null_ls.builtins.formatting.stylua.with({ + extra_args = { '--config-path', vim.fn.expand('~/.config/stylua.toml') }, + }), + null_ls.builtins.formatting.shfmt, + }, + on_attach = on_attach, +}) diff --git a/nvim/lua/config/lualine.lua b/nvim/lua/config/lualine.lua new file mode 100644 index 0000000..bd85a29 --- /dev/null +++ b/nvim/lua/config/lualine.lua @@ -0,0 +1,106 @@ +require('lualine').setup({ + options = { + icons_enabled = true, + theme = 'auto', + component_separators = { left = '', right = '' }, + section_separators = { left = '', right = '' }, + disabled_filetypes = {}, + always_divide_middle = true, + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff', 'diagnostics' }, + lualine_c = { 'filename', 'lsp_progress' }, + lualine_x = { 'encoding', 'fileformat', 'filetype' }, + lualine_y = { 'progress' }, + lualine_z = { 'location' }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = {}, +}) + +local colors = { + yellow = '#ECBE7B', + cyan = '#008080', + darkblue = '#081633', + green = '#98be65', + orange = '#FF8800', + violet = '#a9a1e1', + magenta = '#c678dd', + blue = '#51afef', + red = '#ec5f67', +} + +local config = { + options = { + icons_enabled = true, + theme = 'gruvbox', + component_separators = { '', '' }, + section_separators = { '', '' }, + disabled_filetypes = {}, + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'filename' }, + lualine_c = {}, + lualine_x = {}, + lualine_y = { 'encoding', 'fileformat', 'filetype' }, + lualine_z = { 'branch' }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = {}, +} + +-- Inserts a component in lualine_c at left section +local function ins_left(component) + table.insert(config.sections.lualine_c, component) +end + +-- Inserts a component in lualine_x ot right section +local function ins_right(component) + table.insert(config.sections.lualine_x, component) +end + +--ins_left { +--'lsp_progress', +--display_components = { 'lsp_client_name', { 'title', 'percentage', 'message' }}, +---- With spinner +---- display_components = { 'lsp_client_name', 'spinner', { 'title', 'percentage', 'message' }}, +--colors = { +--percentage = colors.cyan, +--title = colors.cyan, +--message = colors.cyan, +--spinner = colors.cyan, +--lsp_client_name = colors.magenta, +--use = true, +--}, +--separators = { +--component = ' ', +--progress = ' | ', +--message = { pre = '(', post = ')'}, +--percentage = { pre = '', post = '%% ' }, +--title = { pre = '', post = ': ' }, +--lsp_client_name = { pre = '[', post = ']' }, +--spinner = { pre = '', post = '' }, +--message = { commenced = 'In Progress', completed = 'Completed' }, +--}, +--display_components = { 'lsp_client_name', 'spinner', { 'title', 'percentage', 'message' } }, +--timer = { progress_enddelay = 500, spinner = 1000, lsp_client_name_enddelay = 1000 }, +--spinner_symbols = { '🌑 ', '🌒 ', '🌓 ', '🌔 ', '🌕 ', '🌖 ', '🌗 ', '🌘 ' }, +--} diff --git a/nvim/lua/config/nvim-tree.lua b/nvim/lua/config/nvim-tree.lua new file mode 100644 index 0000000..90ee20e --- /dev/null +++ b/nvim/lua/config/nvim-tree.lua @@ -0,0 +1,72 @@ +local g = vim.g +local map = require('utils').map + +g.nvim_tree_highlight_opened_files = 1 +g.nvim_tree_icons = { + symlink = '', + git = { + untracked = '?', + }, + folder = { + arrow_open = '', + arrow_closed = '', + default = '', + open = '', + }, +} +g.nvim_tree_show_icons = { + git = 1, + folders = 1, + files = 1, + folder_arrows = 1, +} + +local tree_cb = require('nvim-tree.config').nvim_tree_callback +require('nvim-tree').setup({ + view = { + width = 35, + side = 'left', + mappings = { + list = { + { key = '', cb = tree_cb('vsplit') }, + { key = '', cb = tree_cb('split') }, + { key = 'v', cb = tree_cb('vsplit') }, + { key = 's', cb = tree_cb('split') }, + { key = '-', cb = '(choosewin)' }, + { key = '', cb = ':ToggleTerm' }, + }, + }, + }, + diagnostics = { + enable = true, + icons = { + error = '', + warning = '', + info = '', + hint = '', + }, + }, + update_to_buf_dir = { + enable = true, + auto_update = true, + }, + update_focused_file = { + enable = true, + }, + filters = { + custom = { '.git' }, -- ignore .git + }, + auto_close = true, + hijack_netrw = true, + update_cwd = true, + focus_tree = false, + open_on_setup = true, +}) + +map('n', 'te', ':NvimTreeToggle') + +vim.cmd([[ +augroup nvimtree + autocmd VimEnter * lua require('nvim-tree').toggle(false, true) +augroup END +]]) diff --git a/nvim/lua/config/nvim_bookmarks.lua b/nvim/lua/config/nvim_bookmarks.lua new file mode 100644 index 0000000..399c7d7 --- /dev/null +++ b/nvim/lua/config/nvim_bookmarks.lua @@ -0,0 +1,18 @@ +local cmd = vim.cmd +local g = vim.g +local map = require('utils').map + +-- vim-bookmarks +require('telescope').load_extension('vim_bookmarks') + +g['bookmark_sign'] = '⚑' +g['bookmark_highlight_lines'] = 1 +g['bookmark_no_default_key_mappings'] = 1 + +cmd([[highlight BookmarkSign ctermbg=NONE ctermfg=160]]) +cmd([[highlight BookmarkLine ctermbg=194 ctermfg=NONE]]) + +map('n', 'mm', ':BookmarkToggle') +map('n', 'mA', ':Telescope vim_bookmarks all') +map('n', 'ma', ':Telescope vim_bookmarks current_file') +-- map("n", "ma", ":BookmarkShowAll") diff --git a/nvim/lua/config/nvim_cmp.lua b/nvim/lua/config/nvim_cmp.lua new file mode 100644 index 0000000..ee9db2f --- /dev/null +++ b/nvim/lua/config/nvim_cmp.lua @@ -0,0 +1,42 @@ +local fn = vim.fn + +-- nvim-cmp +local cmp = require('cmp') +cmp.setup({ + snippet = { + expand = function(args) + fn['vsnip#anonymous'](args.body) + end, + }, + formatting = { + format = function(entry, vim_item) + -- set a name for each source + vim_item.menu = ({ + buffer = '[Buf]', + nvim_lsp = '[LSP]', + luasnip = '[Snip]', + nvim_lua = '[Lua]', + latex_symbols = '[Latex]', + })[entry.source.name] + return vim_item + end, + }, + mapping = { + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + --[""] = cmp.mapping.close(), + [''] = function(fallback) + fallback() + end, + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'buffer' }, + }, +}) diff --git a/nvim/lua/config/nvim_floaterm.lua b/nvim/lua/config/nvim_floaterm.lua new file mode 100644 index 0000000..74444e1 --- /dev/null +++ b/nvim/lua/config/nvim_floaterm.lua @@ -0,0 +1,14 @@ +local g = vim.g +local map = require('utils').map + +-- floaterm +g['floaterm_keymap_new'] = '' +g['floaterm_keymap_next'] = '' +g['floaterm_keymap_prev'] = '' +g['floaterm_keymap_toggle'] = '' +g['floaterm_position'] = 'bottomright' +map('t', '', '') +map('n', 't', 'V:FloatermSend:FloatermToggle') +map('v', 't', ':FloatermSend:FloatermToggle') +map('n', 'r', 'V:FloatermSend:FloatermToggle') +map('v', 'r', ':FloatermSend:FloatermToggle') diff --git a/nvim/lua/config/nvim_hop.lua b/nvim/lua/config/nvim_hop.lua new file mode 100644 index 0000000..46a3e46 --- /dev/null +++ b/nvim/lua/config/nvim_hop.lua @@ -0,0 +1,16 @@ +local map = require('utils').map + +-- hopworld +require('hop').setup({ keys = 'etovxqpdygfblzhckisuran' }) + +map('n', 'w', 'HopWordAC') +map('n', 'fw', 'HopWord') +map('n', 's', 'HopChar1') +map('n', 'k', 'HopLineStartBC') +map('n', 'j', 'HopLineStartAC') +map('v', 'k', 'HopLineStartBC') +map('v', 'j', 'HopLineStartAC') +map('n', 'h', 'HopWordBC') +map('n', 'l', 'HopWordAC') +map('v', 'h', 'HopWordBC') +map('v', 'l', 'HopWordAC') diff --git a/nvim/lua/config/nvim_nerdcommenter.lua b/nvim/lua/config/nvim_nerdcommenter.lua new file mode 100644 index 0000000..bb2388e --- /dev/null +++ b/nvim/lua/config/nvim_nerdcommenter.lua @@ -0,0 +1,8 @@ +local map = require('utils').map +local g = vim.g + +-- nerdcommenter +map('', 'cc', 'V}:call NERDComment("x", "toggle")') +map('', 'cu', 'V{:call NERDComment("x", "toggle")') +g['NERDTrimTrailingWhitespace'] = 1 +g['NERDSpaceDelims'] = 1 diff --git a/nvim/lua/config/nvim_telescope.lua b/nvim/lua/config/nvim_telescope.lua new file mode 100644 index 0000000..03e8485 --- /dev/null +++ b/nvim/lua/config/nvim_telescope.lua @@ -0,0 +1,30 @@ +local map = require('utils').map + +-- telescope +local actions = require('telescope.actions') +require('telescope').setup({ + defaults = { + layout_config = { + horizontal = { + width = 0.75, + height = 0.6, + }, + }, + mappings = { + i = { + [''] = actions.close, + [''] = actions.move_selection_previous, + [''] = actions.move_selection_next, + [''] = { '', type = 'command' }, + [''] = { '', type = 'command' }, + [''] = actions.preview_scrolling_down, + [''] = actions.preview_scrolling_up, + }, + }, + }, +}) + +map('n', 'ff', 'Telescope find_files') +map('n', 'fg', 'Telescope live_grep') +map('n', 'fb', 'Telescope buffers') +map('n', ';', 'Telescope commands') diff --git a/nvim/lua/config/nvim_treesitter.lua b/nvim/lua/config/nvim_treesitter.lua new file mode 100644 index 0000000..ab8148b --- /dev/null +++ b/nvim/lua/config/nvim_treesitter.lua @@ -0,0 +1,14 @@ +-- treesitter +require('nvim-treesitter.configs').setup({ + ensure_installed = 'maintained', -- one of "all", "maintained" (parsers with maintainers), or a list of languages + ignore_install = { 'javascript' }, -- List of parsers to ignore installing + highlight = { + enable = true, -- false will disable the whole extension + disable = {}, -- list of language that will be disabled + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, +}) diff --git a/nvim/lua/config/nvim_vimgo.lua b/nvim/lua/config/nvim_vimgo.lua new file mode 100644 index 0000000..7c8f74a --- /dev/null +++ b/nvim/lua/config/nvim_vimgo.lua @@ -0,0 +1,21 @@ +local g = vim.g + +-- vim-go +-- let g:go_code_completion_enabled = 1 -- Enable Autocompletion +--g['go_fmt_command'] = 'goimports' -- 格式化将默认的 gofmt 替换 +g['go_autodetect_gopath'] = 1 +g['go_list_type'] = 'quickfix' +g['go_version_warning'] = 1 +g['go_highlight_types'] = 1 +g['go_highlight_fields'] = 1 +g['go_highlight_functions'] = 1 +g['go_highlight_function_calls'] = 1 +g['go_highlight_operators'] = 1 +g['go_highlight_extra_types'] = 1 +g['go_highlight_methods'] = 1 +g['go_highlight_generate_tags'] = 1 +g['godef_split'] = 2 +--g['go_fmt_command'] = 'goimports' " Run goimports along gofmt on each save +g['go_imports_mode'] = 'goimports' +g['go_imports_autosave'] = 0 -- do not auto import +g['go_auto_type_info'] = 1 -- automatically get signature/type info for object under cursor diff --git a/nvim/lua/config/tagbar.lua b/nvim/lua/config/tagbar.lua new file mode 100644 index 0000000..e69de29 diff --git a/nvim/lua/config/toggleterm.lua b/nvim/lua/config/toggleterm.lua new file mode 100644 index 0000000..eb3fe7a --- /dev/null +++ b/nvim/lua/config/toggleterm.lua @@ -0,0 +1,46 @@ +local g = vim.g +local map = require('utils').map + +local Terminal = require('toggleterm.terminal').Terminal +local lazygit = Terminal:new({ + cmd = 'lazygit', + dir = 'git_dir', + close_on_exit = true, + direction = 'float', + float_opts = { + border = 'double', + }, + hidden = true, + -- function to run on opening the terminal + --on_open = function(term) + --vim.cmd("startinsert!") + --vim.api.nvim_buf_set_keymap(term.bufnr, "n", "q", "close", {noremap = true, silent = true}) + --end, + -- function to run on closing the terminal + --on_close = function(term) + --vim.cmd("Closing terminal") + --end, +}) + +function _lazygit_toggle() + lazygit:toggle() +end + +function _G.set_terminal_keymaps() + local opts = { noremap = true } + vim.api.nvim_buf_set_keymap(0, 't', '', [[]], opts) + --vim.api.nvim_buf_set_keymap(0, 't', 'jk', [[]], opts) + --vim.api.nvim_buf_set_keymap(0, 't', '', [[h]], opts) + --vim.api.nvim_buf_set_keymap(0, 't', '', [[j]], opts) + --vim.api.nvim_buf_set_keymap(0, 't', '', [[k]], opts) + --vim.api.nvim_buf_set_keymap(0, 't', '', [[l]], opts) +end + +vim.api.nvim_set_keymap('n', 'g', 'lua _lazygit_toggle()', { noremap = true, silent = true }) + +-- if you only want these mappings for toggle term use term://*toggleterm#* instead +vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()') + +map('n', 'tm', ':ToggleTerm size=15 direction=horizontal') + +require('toggleterm').setup({}) diff --git a/nvim/lua/config/vista.lua b/nvim/lua/config/vista.lua new file mode 100644 index 0000000..82b8030 --- /dev/null +++ b/nvim/lua/config/vista.lua @@ -0,0 +1,15 @@ +local api = vim.api + +api.nvim_exec( + [[ +" Ensure you have installed some decent font to show these pretty symbols, then you can enable icon for the kind. +let g:vista#renderer#enable_icon = 1 + +" The default icons can't be suitable for all the filetypes, you can extend it as you wish. +let g:vista#renderer#icons = { +\ "function": "\uf794", +\ "variable": "\uf71b", +\ } +]], + false +) diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua new file mode 100644 index 0000000..46f3add --- /dev/null +++ b/nvim/lua/plugins.lua @@ -0,0 +1,241 @@ +local fn = vim.fn +local g = vim.g +local cmd = vim.cmd +local lsp = vim.lsp +local api = vim.api +local map = require('utils').map + +-- Ensure packer installed +local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' +if fn.empty(fn.glob(install_path)) > 0 then + fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }) + cmd('packadd packer.nvim') +end + +return require('packer').startup(function(use) + use('wbthomason/packer.nvim') + use('folke/lua-dev.nvim') + + use('folke/tokyonight.nvim') + use('kyazdani42/nvim-web-devicons') + use('tpope/vim-fugitive') -- git fugitive + use({ + 'lewis6991/gitsigns.nvim', + requires = { 'nvim-lua/plenary.nvim' }, + config = function() + require('config.gitsigns') + end, + }) + use({ + 'folke/which-key.nvim', + config = function() + require('which-key').setup({ + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + }) + end, + }) + use({ + 'folke/trouble.nvim', + config = function() + require('trouble').setup({}) + end, + }) + --use({ + --'TimUntersberger/neogit', + --requires = 'nvim-lua/plenary.nvim', + --config = function() + --local neogit = require('neogit') + --neogit.setup({ + --integrations = { + --diffview = true, + --}, + --}) + --end, + --}) + --use({ + --'sindrets/diffview.nvim', + --requires = 'nvim-lua/plenary.nvim', + --config = function() + --require('diffview').setup({}) + --end, + --}) + use({ + 'MattesGroeger/vim-bookmarks', + requires = 'tom-anders/telescope-vim-bookmarks.nvim', + config = function() + require('config.nvim_bookmarks') + end, + }) + use('junegunn/vim-easy-align') -- 可以快速对齐的插件 + use({ + 't9md/vim-choosewin', + }) + -- use "easymotion/vim-easymotion" + --use { + --"voldikss/vim-floaterm", + --config = function() + --require "config.nvim_floaterm" + --end + --} + use({ + 'akinsho/toggleterm.nvim', + config = function() + require('config.toggleterm') + end, + }) + use('wakatime/vim-wakatime') + use('psf/black') + use({ + 'preservim/nerdcommenter', + config = function() + require('config.nvim_vimgo') + end, + }) + use({ + 'windwp/nvim-autopairs', + config = function() + -- nvim-autopairs + require('nvim-autopairs').setup({}) + end, + }) + use({ + 'kyazdani42/nvim-tree.lua', + requires = 'kyazdani42/nvim-web-devicons', + config = function() + require('config.nvim-tree') + end, + }) + use({ + 'nvim-telescope/telescope.nvim', + requires = 'nvim-lua/plenary.nvim', + config = function() + require('config.nvim_telescope') + end, + }) + use({ + 'hrsh7th/nvim-cmp', + config = function() + require('config.nvim_cmp') + end, + requires = { + 'hrsh7th/cmp-vsnip', + 'hrsh7th/vim-vsnip', + 'hrsh7th/vim-vsnip-integ', + }, + }) + use('hrsh7th/cmp-buffer') + use('hrsh7th/cmp-nvim-lsp') + use({ + 'github/copilot.vim', + setup = function() end, + config = function() + require('config.copilot') + end, + }) + --use('sbdchd/neoformat') + use({ + 'nvim-treesitter/nvim-treesitter', + run = ':TSUpdate', + config = function() + require('config.nvim_treesitter') + end, + }) + use({ + 'iamcco/markdown-preview.nvim', + run = 'cd app && yarn install', + cmd = { 'MarkdownPreview', 'MarkdownPreviewStop' }, + }) + --use {"glepnir/spaceline.vim", requires = "kyazdani42/nvim-web-devicons"} + use({ + 'nvim-lualine/lualine.nvim', + requires = { 'kyazdani42/nvim-web-devicons', opt = true }, + config = function() + require('config.lualine') + end, + }) + use({ + 'j-hui/fidget.nvim', + config = function() + require('fidget').setup({}) + end, + }) + -- use 'arkav/lualine-lsp-progress' + use({ + 'romgrk/barbar.nvim', + requires = { 'kyazdani42/nvim-web-devicons' }, + }) + use({ + 'folke/todo-comments.nvim', + requires = 'nvim-lua/plenary.nvim', + config = function() + require('todo-comments').setup({}) + end, + }) + use({ + 'phaazon/hop.nvim', + as = 'hop', + config = function() + -- you can configure Hop the way you like here; see :h hop-config + require('config.nvim_hop') + end, + }) + --use { + --"ray-x/lsp_signature.nvim", + --config = function() + --require "lsp_signature".setup { + --transpancy = 10, + --hint_prefix = "😼", + ---- zindex = 50, + --} + --end + --} + use({ + 'preservim/tagbar', + config = function() + require('config.tagbar') + end, + }) + --use { + --"liuchengxu/vista.vim", + --config = function() + --require "config.vista" + --end + --} + + -- LANGUAGES + use({ + 'neovim/nvim-lspconfig', + }) + use({ + 'jose-elias-alvarez/null-ls.nvim', + }) + use({ + 'williamboman/nvim-lsp-installer', + config = function() + require('config.lspconfig') + end, + }) + use({ + 'fatih/vim-go', + run = ':GoUpdateBinaries', + config = function() + require('config.nvim_vimgo') + end, + }) + -- erlang + use('vim-erlang/vim-erlang-tags') + -- markdown + use('iamcco/mathjax-support-for-mkdp') + use('iamcco/markdown-preview.vim') + --beancount + use('nathangrigg/vim-beancount') + -- python + use('Vimjas/vim-python-pep8-indent') + -- rust + use('rust-lang/rust.vim') + use('andrewstuart/vim-kubernetes') +end) + +-- require("todo-comments").setup {} diff --git a/nvim/lua/utils.lua b/nvim/lua/utils.lua new file mode 100644 index 0000000..b5c5bb0 --- /dev/null +++ b/nvim/lua/utils.lua @@ -0,0 +1,54 @@ +local cmd = vim.cmd +local o_s = vim.o +local map_key = vim.api.nvim_set_keymap +local g = vim.g +local api = vim.api +local fn = vim.fn +local ncmd = vim.api.nvim_command +local lsp = vim.lsp +local o, wo, bo = vim.o, vim.wo, vim.bo + +local buffer = { o, bo } +local window = { o, wo } + +local function opt(o, v, scopes) + scopes = scopes or { o_s } + for _, s in ipairs(scopes) do + s[o] = v + end +end + +local function autocmd(group, cmds, clear) + clear = clear == nil and false or clear + if type(cmds) == 'string' then + cmds = { cmds } + end + cmd('augroup ' .. group) + if clear then + cmd([[au!]]) + end + for _, c in ipairs(cmds) do + cmd('autocmd ' .. c) + end + cmd([[augroup END]]) +end + +local function map(modes, lhs, rhs, opts) + opts = opts or {} + opts.noremap = opts.noremap == nil and true or opts.noremap + if type(modes) == 'string' then + modes = { modes } + end + for _, mode in ipairs(modes) do + map_key(mode, lhs, rhs, opts) + end +end + +local function set(opt, v, scopes) + scopes = scopes or { o } + for _, s in ipairs(scopes) do + s[opt] = v + end +end + +return { opt = opt, autocmd = autocmd, map = map, set = set, ncmd = ncmd } diff --git a/pycodestyle b/pycodestyle new file mode 100644 index 0000000..46b1cc3 --- /dev/null +++ b/pycodestyle @@ -0,0 +1,2 @@ +[pycodestyle] +ignore=E501 diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..dd1f591 --- /dev/null +++ b/setup.sh @@ -0,0 +1,146 @@ +#!/usr/bin/env bash +# this is a script to setup dotfiles for myself. +set -x +FILES=( + .gitignore + + .zshrc + .zlogin + + .tmux.conf + .ideavimrc + +) + +CONFIG_FILES=( + nvim + git + tmux + raycast + wezterm + pycodestyle + starship.toml + stylua.toml +) + +WORKING_DIR=$(pwd) +HOME_DIR="$HOME" + +function init() { + sudo xcode-select --install + sudo xcodebuild -license accept + if [[ $(command -v brew) = "" ]]; then + echo "Installing brew" + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + eval "$(/opt/homebrew/bin/brew shellenv)" + brew update + brew install zsh + chsh -s /bin/zsh + ssh-keygen + echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >>"$HOME/.zshrc" + source "$HOME/.zshrc" + fi +} + +function recover() { + OS="$(uname)" + + # Homebrew + if [ ! $(which brew) ]; then + echo "Installing homebrew..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + fi + if [ "$OS" = 'Darwin' ]; then + export PATH=/usr/local/bin/:$PATH + elif [ "$OS" = 'Linux' ]; then + export PATH=/home/linuxbrew/.linuxbrew/bin/:$PATH + fi + + # antigen + if [ ! -f $HOME/.antigen/antigen.zsh ]; then + mkdir -p $HOME/.antigen/ + curl -L git.io/antigen >$HOME/.antigen/antigen.zsh + fi + + mkdir -p $HOME/.kube/ + + # dotfiles + echo "Linking files..." + for i in ${FILES[@]}; do + ln -svfn $WORKING_DIR/$i $HOME_DIR/$i + done + + echo "Linking config files..." + for i in ${CONFIG_FILES[@]}; do + ln -svfn $WORKING_DIR/$i $HOME_DIR/.config/$i + done + + # submodules + echo 'Syncing Submodules...' + git submodule init + git submodule update --init --recursive + git submodule foreach --recursive git fetch + git submodule foreach git merge origin master + + # brew bundle + echo "Installing by brew..." + suffix="$OS."$(echo $(hostname) | cut -d '.' -f 1) + mv .Brewfile.$suffix Brewfile + brew bundle -v + mv Brewfile .Brewfile.$suffix + + # others + git config --global core.excludesfile ~/.config/git/.gitignore + git config --global init.defaultBranch main + $(brew --prefix)/opt/fzf/install +} + +function manual_install() { + wget -qO- http://stevenygard.com/download/class-dump-3.5.tar.gz | tar xvz - -C /usr/local/bin && chmod u+x /usr/local/bin/class-dump + wget -O /usr/local/bin/class-dump https://github.com/AloneMonkey/MonkeyDev/raw/master/bin/class-dump && chmod u+x /usr/local/bin/class-dump + pip install --user frida-tools +} + +function backup() { + # brew backup + brew tap Homebrew/bundle + brew bundle dump -f + mv Brewfile .Brewfile."$(uname)."$(echo $(hostname) | cut -d '.' -f 1) +} + +function purge() { + uninstall_oh_my_zsh + brew remove $(brew list --formula) + for i in ${FILE_OR_DIRS[@]}; do + rm -rf $WORKING_DIR/$i $HOME_DIR/$i + done + + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" +} + +function usage() { + echo "Try to backup/recover my dotfiles" + echo " " + echo "options:" + echo "-m mode, accept recover/backup/purge" +} + +while getopts ":m:" opt; do + case ${opt} in + m) + echo $OPTARG + if [ "$OPTARG"x == "recover"x ]; then + recover + elif [ "$OPTARG"x == "backup"x ]; then + backup + else + echo "Invalid option: -$OPTARG" >&2 + fi + exit 0 + ;; + \?) + usage + exit 0 + ;; + esac +done diff --git a/starship.toml b/starship.toml new file mode 100644 index 0000000..d127308 --- /dev/null +++ b/starship.toml @@ -0,0 +1,20 @@ +format = '$directory$git_branch$git_commit$git_state$git_status$golang$helm$java$nodejs$python$red$ruby$rust$kubernetes$custom$cmd_duration$lua$line_break$jobs$time$status$shell$character' + +[git_commit] +tag_disabled = true +only_detached = false +disabled = false +commit_hash_length = 8 + +[kubernetes] +disabled = false +symbol = '⎈ ' +format = '[$symbol$context \($namespace\)]($style) ' + +[python] +pyenv_version_name = false + +[golang] +symbol = 'ʕ◔ϖ◔ʔ ' + +[rust] diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..53d1469 --- /dev/null +++ b/stylua.toml @@ -0,0 +1,2 @@ +indent_type = "Spaces" +quote_style = "AutoPreferSingle" diff --git a/tmux/plugins/tpm b/tmux/plugins/tpm new file mode 160000 index 0000000..b699a7e --- /dev/null +++ b/tmux/plugins/tpm @@ -0,0 +1 @@ +Subproject commit b699a7e01c253ffb7818b02d62bce24190ec1019 diff --git a/wezterm/colors/tokyonight.toml b/wezterm/colors/tokyonight.toml new file mode 100644 index 0000000..6850093 --- /dev/null +++ b/wezterm/colors/tokyonight.toml @@ -0,0 +1,11 @@ +[colors] +foreground = "#c0caf5" +background = "#24283b" +cursor_bg = "#c0caf5" +cursor_border = "#c0caf5" +cursor_fg = "#24283b" +selection_bg = "#364A82" +selection_fg = "#c0caf5" + +ansi = ["#1D202F", "#f7768e", "#9ece6a", "#e0af68", "#7aa2f7", "#bb9af7", "#7dcfff", "#a9b1d6"] +brights = ["#414868", "#f7768e", "#9ece6a", "#e0af68", "#7aa2f7", "#bb9af7", "#7dcfff", "#c0caf5"] diff --git a/wezterm/wezterm.lua b/wezterm/wezterm.lua new file mode 100644 index 0000000..8322502 --- /dev/null +++ b/wezterm/wezterm.lua @@ -0,0 +1,40 @@ +local wezterm = require('wezterm') +return { + font_size = 14, + font = wezterm.font_with_fallback({ + 'JetBrains Mono', + 'JetBrainsMono Nerd Font Mono', + }), + colors = { + tab_bar = { + active_tab = { + bg_color = '#24283b', + fg_color = '#c0caf5', + }, + }, + }, + color_scheme = 'tokyonight', + window_frame = { + font_size = 14.0, + }, + window_padding = { + left = 5, + right = 5, + top = 0, + bottom = 0, + }, + foreground_text_hsb = { + hue = 1.0, + saturation = 1.0, + brightness = 1.2, + }, + use_ime = true, -- fix Chinese + skip_close_confirmation_for_processes_named = { + 'fzf', + 'zsh', + 'fzf', + }, + keys = { + { key = 'w', mods = 'CMD', action = wezterm.action({ CloseCurrentTab = { confirm = false } }) }, + }, +}