From 0f098771b18d6d6525fc771bd85c822ab89365f0 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 7 Nov 2024 10:58:29 +0800 Subject: Update --- alias | 501 +++++++++++++++++++++++++--------------------------- profile | 1 + vim/init/config.vim | 244 ++++++++++++------------- 3 files changed, 362 insertions(+), 384 deletions(-) diff --git a/alias b/alias index 2415d91..7b93dd4 100644 --- a/alias +++ b/alias @@ -1,142 +1,42 @@ # My alias for bash and zsh -# __CONFIG__ -# __NETWORK__ -# __VIM__ -# __SSH__ -# __IMAP__ -# __GIST__ -# __UNIX__ -# __PACMAN__ -# __CD__ -# __BLOG__ -# __GIT__ -# __GITHUB__ -# __TIG__ - -# __CONFIG__ alias al="$EDITOR $SETTING_DIR/alias && source $SETTING_DIR/alias" + +# SHELL {{{ eval "${shell}rc(){ local RCFILE=$XDG_CONFIG_HOME/${shell}/.${shell}rc vim \$RCFILE && source \$RCFILE }" -alias vimrc='vim ~/.vimrc' -alias tigrc="$EDITOR ~/.tigrc" -alias mutt.rc="$EDITOR ~/.config/mutt/muttrc" -alias ala.rc="$EDITOR ~/.config/alacritty/alacritty.toml" -alias alacritty.rc="$EDITOR ~/.config/alacritty/alacritty.toml" -alias git.config="$EDITOR ~/.gitconfig" -alias gpg.config="$EDITOR ~/.gnupg/gpg-agent.conf" -alias ssh.config="$EDITOR ~/.ssh/config" -alias ssh.auth="$EDITOR ~/.ssh/authorized_keys" -alias ssh.known="$EDITOR ~/.ssh/known_hosts" -config(){ cd ~/.config/$1; } -alias tmux.config="$EDITOR ~/.tmux.conf" -cde() { cd /etc/$@; } - -alias cdetc='cde' -alias ls='ls --color' -alias lsd='ls -d */' -alias grep='grep --color' alias eof='IGNOREEOF=10' -# __NETWORK__ -alias dig.detail='dig +noall +answer +multiline' - -# __VIM__ -if which nvim &>/dev/null; then - alias vim='nvim' - alias v='nvim' - alias vv='/usr/bin/vim' -else - alias v='vim' -fi -alias vu='vim -u NONE' -alias vr='vim -R' -# Edit last file -alias vl="vim -c 'norm '" -# Use Telescope to select recent files -vll() { vim -c 'Telescope oldfiles'; } -# Apply defaut session -alias vS="vim -S /tmp/vim.session" -alias cdv='cd ~/.config/nvim' -vs() { which $1 && vim $(which $1); } -[ "$shell" = zsh ] && compdef vs=which -alias vim.dos2unix="vim '+set ff=unix' '+x'" - -# __SSH__ -alias cdssh='cd ~/.ssh' -alias ptt='ssh ptt' -alias sshv='ssh -t vps' -ssh.tar() { - prompt-vim "tar cf - foo | ssh vps 'cd ~/Downloads; tar xf -' \nssh vps 'tar czf - --directory=/working/path target' | tar xvzf -" -} -ssh.up() { - set -o pipefail - filename=${3:-`basename $1`} - # Upload to absolution path - if [[ $2 =~ '^/' ]]; then - folder=${2%/} - cat $1 | ssh vps "mkdir -p $folder; cat >${folder}/${filename}" || return 1 - echo Uploaded to ${folder}/${filename} - # Upload to relative in ~/public/ - else - folder='~/public/'${2%/} - cat $1 | ssh vps "mkdir -p $folder; cat >${folder}/${filename}" || return 1 - echo https://topo.tw/p/${2%/}/${filename} - fi -} -ssh.up.today() { - DATE=$(date --iso-8601) - ssh vps mkdir -p ~/public/$DATE - ssh.up $1 $DATE -} -ssh.down() { - ssh -t vps rm -rf -i ~/public/"$1" -} - -# __IMAP__ -imap.save() { - curl "imaps://mail.topo.tw/$1" \ - --user pham:`pass mail/pham@mail.topo.tw` \ - -T $2 -} -imap.save_attachment() { - #TEMPFILE=$(mktemp) - trap 'rm $TEMPFILE' EXIT - mail -a $1 -Sexpandaddr /dev/stdout | \ - curl imaps://mail.topo.tw/INBOX \ - --user pham:`pass mail/pham@mail.topo.tw` \ - -T /dev/stdin +# }}} +# CUSTOM HELPER {{{ +cdh() { cd $SETTING_DIR/$@; } +alias chh="tig -C $SETTING_DIR status" +# }}} +# Text Encode/Decode{{{ +big52utf8() { + iconv -f BIG-5 -t UTF-8 } -imap.search.subject() { - curl "imaps://mail.topo.tw/$1" \ - --user pham:`pass mail/pham@mail.topo.tw` \ - --request "SEARCH SUBJECT $2" +utf82big5() { + iconv -t BIG-5 -f UTF-8 } -imap.fetch() { - curl "imaps://mail.topo.tw/$1;MAILINDEX=$2" \ - --user pham:`pass mail/pham@mail.topo.tw` | \ - dos2unix | \ - sed -E '0,/^ *$/d' +urlencode() { + perl -lpe 's/([^A-Za-z0-9.\/:])/sprintf("%%%02X", ord($1))/seg' + # Alternative: + # curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "" } - -# __GIST__ -alias g='gist' -alias gl='gist last' -unalias gg &>/dev/null -alias gg='gist grep' - -# __UNIX__ +# }}} +# UNIX {{{ alias chx='chmod +x' alias chr='chmod +r' +config(){ cd ~/.config/$1; } alias k='kill %1' alias s='sudo systemctl' alias j='sudo journalctl -xeu' -alias m='mutt' -alias h='himalaya' -alias gmail="mutt -F $SETTING_DIR/mutt/muttrc.gmail" -alias ntu="mutt -F $SETTING_DIR/mutt/muttrc.b97602041" +alias ls='ls --color' +alias lsd='ls -d */' +alias grep='grep --color' path() { echo $PATH; } # Should not use alias, because $PATH is not initialized ps1.swap() { if [ -z "$PS1_bak" ]; then PS1_bak="$PS1" @@ -211,8 +111,105 @@ gr() { grep -IR $@ . | sed '/^.\{2048\}./d' } alias findn='find . -iname' +alias ce='crontab -e' +alias cl='crontab -l' +alias df='df -h' -# __PACMAN__ +# }}} +# Clipboard{{{ +alias xi='xsel -ib' +alias xii='`fc -ln -1` | head -1 | xsel -ib' +alias xo='xsel -ob' +alias xl='history | tail -1 | grep -oP "^\s*[0-9]+\s\s\K.*" | xsel -ib && echo Copied to clipboard && xsel -ob' +# }}} +# TMUX {{{ +alias tma='tmux a' +alias tmux.config="$EDITOR ~/.tmux.conf" +# }}} +# NETWORK {{{ + +alias dig.detail='dig +noall +answer +multiline' +alias co='curl -O' +alias curl.code='curl -o /dev/null --silent -Iw "%{http_code}"' +alias p8='ping -c 3 8.8.8.8' +alias curl.google='curl -v google.com' +alias curl.wifi='curl -I google.com | grep -E "^Location:" | cut -d" " -f2 | xsel -ib' +ip.neigh() { + INTERFACES=$(ifconfig | sed -nE 's/^([^ :]+).*$/\1/p') + test -z "$1" && echo $INTERFACES && return 0 + + ifconfig | sed -nE "/^${1}/,/^$/ s/^ +inet ([0-9.]+) .*$/\1/p" +} + +# }}} +# MAIL {{{ +alias m='mutt' +alias mutt.rc="$EDITOR ~/.config/mutt/muttrc" +alias h='himalaya' +alias gmail="mutt -F $SETTING_DIR/mutt/muttrc.gmail" +alias ntu="mutt -F $SETTING_DIR/mutt/muttrc.b97602041" +imap.save() { + curl "imaps://mail.topo.tw/$1" \ + --user pham:`pass mail/pham@mail.topo.tw` \ + -T $2 +} +imap.save_attachment() { + #TEMPFILE=$(mktemp) + trap 'rm $TEMPFILE' EXIT + mail -a $1 -Sexpandaddr /dev/stdout | \ + curl imaps://mail.topo.tw/INBOX \ + --user pham:`pass mail/pham@mail.topo.tw` \ + -T /dev/stdin +} +imap.search.subject() { + curl "imaps://mail.topo.tw/$1" \ + --user pham:`pass mail/pham@mail.topo.tw` \ + --request "SEARCH SUBJECT $2" +} +imap.fetch() { + curl "imaps://mail.topo.tw/$1;MAILINDEX=$2" \ + --user pham:`pass mail/pham@mail.topo.tw` | \ + dos2unix | \ + sed -E '0,/^ *$/d' +} + +# }}} +# SSH {{{ +alias ssh.config="$EDITOR ~/.ssh/config" +alias ssh.auth="$EDITOR ~/.ssh/authorized_keys" +alias ssh.known="$EDITOR ~/.ssh/known_hosts" +alias cdssh='cd ~/.ssh' +alias ptt='ssh ptt' +alias sshv='ssh -t vps' +ssh.tar() { + prompt-vim "tar cf - foo | ssh vps 'cd ~/Downloads; tar xf -' \nssh vps 'tar czf - --directory=/working/path target' | tar xvzf -" +} +ssh.up() { + set -o pipefail + filename=${3:-`basename $1`} + # Upload to absolution path + if [[ $2 =~ '^/' ]]; then + folder=${2%/} + cat $1 | ssh vps "mkdir -p $folder; cat >${folder}/${filename}" || return 1 + echo Uploaded to ${folder}/${filename} + # Upload to relative in ~/public/ + else + folder='~/public/'${2%/} + cat $1 | ssh vps "mkdir -p $folder; cat >${folder}/${filename}" || return 1 + echo https://topo.tw/p/${2%/}/${filename} + fi +} +ssh.up.today() { + DATE=$(date --iso-8601) + ssh vps mkdir -p ~/public/$DATE + ssh.up $1 $DATE +} +ssh.down() { + ssh -t vps rm -rf -i ~/public/"$1" +} + +# }}} +# PACMAN {{{ alias pac='sudo pacman -S' # pacman install alias psy='sudo pacman -Syy' alias ys='yay -S' @@ -238,15 +235,50 @@ psi() { } pkgbuild() { git clone https://aur.archlinux.org/$1.git; } -# __CD__ +# }}} +# Alacritty{{{ +alias ala.rc="$EDITOR ~/.config/alacritty/alacritty.toml" +alias alacritty.rc="$EDITOR ~/.config/alacritty/alacritty.toml" +# }}} +# VIM {{{ +alias vimrc='vim ~/.vimrc' +if which nvim &>/dev/null; then + alias vim='nvim' + alias v='nvim' + alias vv='/usr/bin/vim' +else + alias v='vim' +fi +alias vu='vim -u NONE' +alias vr='vim -R' +# Edit last file +alias vl="vim -c 'norm '" +# Use Telescope to select recent files +vll() { vim -c 'Telescope oldfiles'; } +# Apply defaut session +alias vS="vim -S /tmp/vim.session" +alias cdv='cd ~/.config/nvim' +vs() { which $1 && vim $(which $1); } +[ "$shell" = zsh ] && compdef vs=which +alias vim.dos2unix="vim '+set ff=unix' '+x'" +vvv() { + while true; do + vim -c 'norm ' + if [ $? -ne 0 ]; then + break + fi + echo "restarting vim..."; + done +} + +# }}} +# CD {{{ alias ..='cd ..' alias ...='cd ../..' alias ld='cd -' # last directory -cdg() { - target=$(sed 's# #/#g' <<<"$@") - cd ~/git/$target || cd ~/git -} alias cda='mkdir -p ~/data && cd ~/data' +cde() { cd /etc/$@; } +alias cdetc='cde' alias cdd='cd ~/Downloads' alias cdD='cd ~/Documents' alias cdP='cd ~/Pictures' @@ -254,7 +286,8 @@ alias cdpu='cd ~/public' alias cdV='cd ~/Videos' alias cdM='cd ~/Music' -# __BLOG__ +# }}} +# BLOG {{{ alias cdb='cd ~/blog' vp() { [[ $HOST = vultr ]] || PREFIX='ssh -qt vps' @@ -282,19 +315,48 @@ vp() { fi } -# __GIT__ +# }}} +# GIT {{{ +alias git.config="$EDITOR ~/.gitconfig" unalias gc &> /dev/null # override zsh plugin alias gc() { git clone $@; if [ $# = 1 ]; then cd $(basename ${1%.git}); fi } gc1() { git clone --depth=1 $1 && cd $(basename $1); } -gcv() { gc vps:$1; } alias gls='git log -S' +cdg() { + target=$(sed 's# #/#g' <<<"$@") + cd ~/git/$target || cd ~/git +} alias cdgg='cd $(git rev-parse --show-toplevel)' alias cdgw='cdgg && cd .github/workflows' alias cdgs='cd $(git submodule status | sed "s/^.//" | cut -d" " -f2)' # cd to first submodule alias ch="/home/pham/helper/bin/git/check-repos.sh" alias git.check="/home/pham/helper/bin/git/check-repos.sh" -# __GITHUB__ +# }}} +# TIG {{{ +alias cdt='cd ~/git/tig' +alias t='tig' +alias ts='tig status' +alias tigrc="$EDITOR ~/.tigrc" +alias ta='tig --all' +upload_tig() { + github-release.sh \ + github_api_token=$GITHUB_API_TOKEN \ + repo=typebrook/tig \ + tag=LATEST \ + type=asset \ + filename=$(which tig) + action=overwrite +} +# }}} +# GIST {{{ +alias g='gist' +alias gl='gist last' +unalias gg &>/dev/null +alias gg='gist grep' + +# }}} +# Service: GITHUB {{{ export GITHUB_API='https://api.github.com' export GITHUB_API_TOKEN="~/.ssh/tokens/github 2>/dev/null)" alias hub="GITHUB_TOKEN=$GITHUB_API_TOKEN hub" @@ -319,49 +381,12 @@ github.raw() { curl -O https://raw.githubusercontent.com/$1/$2/$3 } -# __TIG__ -alias cdt='cd ~/git/tig' -alias t='tig' -alias ts='tig status' -alias ta='tig --all' -upload_tig() { - github-release.sh \ - github_api_token=$GITHUB_API_TOKEN \ - repo=typebrook/tig \ - tag=LATEST \ - type=asset \ - filename=$(which tig) - action=overwrite -} - -# about custom settings -cdh() { cd $SETTING_DIR/$@; } -alias chh="tig -C $SETTING_DIR status" - -# about beancount +# }}} +# Beancount{{{ alias cdB='cd $HOME/bean' alias b='vim $HOME/bean/main.bean' - -# crontab -alias ce='crontab -e' -alias cl='crontab -l' - -# lf -alias r='_lf_cd' -alias l='_lf_cd' -_lf_cd() { - tempfile=$(mktemp -t tmp.XXXXXX) - lf --last-dir-path $tempfile - - test -f "$tempfile" && \ - cd -- "$(cat "$tempfile")" && \ - rm -f -- "$tempfile" -} - -# disk -alias df='df -h' - -# docker +# }}} +# Docker{{{ alias dk='docker' alias dc='docker-compose' alias dis='docker images' @@ -370,8 +395,8 @@ alias dpsa='docker ps -a' docker.sh() { docker run --rm -it --entrypoint /bin/sh $@; } docker.bash() { docker run --rm -it --entrypoint /bin/bash $@; } docker.tags() { curl -s -S "https://registry.hub.docker.com/v2/repositories/$@/tags/" | tee /dev/tty | jq '.results[]["name"]' | sort; } - -# Android +# }}} +# Android{{{ alias debug='./gradlew app:installDebug && adb shell am start -n com.geothings.geobingan/.MainActivity_' alias adb.view='adb shell am start -a android.intent.action.VIEW -d' alias adb.default='adb shell dumpsys package domain-preferred-apps' @@ -384,19 +409,11 @@ alias adb.input='adb shell input text' adb.push() { adb push $1 /sdcard/Download } - -# curl -alias co='curl -O' -alias curl.code='curl -o /dev/null --silent -Iw "%{http_code}"' - -# python +# }}} +# python{{{ alias pip3='python3 -m pip' - -# gdal -alias oo='ogr2ogr' -alias oi='ogrinfo -al -so' - -# sample file +# }}} +# sample file{{{ alias sample.text='curl http://metaphorpsum.com/paragraphs/3/5' alias sample.gpx='curl -O https://docs.mapbox.com/help/data/run.gpx' alias sample.geojson='curl -O https://docs.mapbox.com/help/data/stations.geojson' @@ -428,8 +445,8 @@ taiwan_dem() { xargs curl -Lo taiwan_dem.zip unzip -p taiwan_dem.zip dem_20m.tif >20m.tif } - -# data file +# }}} +# DATA (from internet){{{ alias taiwan='curl -O http://download.geofabrik.de/asia/taiwan-latest.osm.pbf' alias data.rudymap='curl -O https://raw.githubusercontent.com/alpha-rudy/taiwan-topo/master/styles/mapsforge_style/MOI_OSM.xml' alias data.rudymap_ele='curl -O http://moi.kcwu.csie.org/osm_elevations/ele_taiwan_10_50_100_500_marker-2019.7.o5m' @@ -450,32 +467,36 @@ alias data.taiwan_town='curl -o town.zip -L https://data.moi.gov.tw/MoiOD/Syste alias data.taiwan_village='curl -o village.zip -L http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx\?DATA\=B8AF344F-B5C6-4642-AF46-1832054399CE' alias data.taiwan_poly='curl -O http://download.geofabrik.de/asia/taiwan.poly' alias data.taiwan_county_code='curl --silent https://www.ris.gov.tw/documents/data/5/1/RSCD0101.txt | iconv -f BIG-5 -t UTF-8 -' +# }}} +# PASS {{{ -# clipboard -alias xi='xsel -ib' -alias xii='`fc -ln -1` | head -1 | xsel -ib' -alias xo='xsel -ob' -alias xl='history | tail -1 | grep -oP "^\s*[0-9]+\s\s\K.*" | xsel -ib && echo Copied to clipboard && xsel -ob' - -# Text Encode/Decode -big52utf8() { - iconv -f BIG-5 -t UTF-8 -} -utf82big5() { - iconv -t BIG-5 -f UTF-8 -} -urlencode() { - perl -lpe 's/([^A-Za-z0-9.\/:])/sprintf("%%%02X", ord($1))/seg' - # Alternative: - # curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "" +alias chp='tig -C ~/.password-store' +alias chpass='tig -C ~/.password-store' +alias cdpass='cd ~/.password-store' +alias p='pass' +alias pc='pass -c' +alias pe='pass edit' +alias pgn='pass generate --in-place --clip' +alias pgc='pass generate --clip' +words() { + cat /usr/share/dict/usa | grep -E "^[a-z]{4,8}$" | shuf | head -40 | xargs -n${1:-2} } -# Network -alias p8='ping -c 3 8.8.8.8' -alias curl.google='curl -v google.com' -alias curl.wifi='curl -I google.com | grep -E "^Location:" | cut -d" " -f2 | xsel -ib' - -# misc +# }}} +# Nginx{{{ +alias vgx='sudo vim /etc/nginx/sites-enabled/vps && sudo nginx -t && sudo systemctl reload nginx' +alias cdngx='cd /etc/nginx' +# }}} +# GIS {{{ +alias oo='ogr2ogr' +alias oi='ogrinfo -al -so' +TAIWAN_BBOX='118.1036,20.72799,122.9312,26.60305' +TAIWAN_BBOX_V='20.72799,118.1036,26.60305,122.9312' +TAIPEI_BBOX='121.346,24.926,121.676,25.209' +TAIPEI_BBOX_V='24.926,121.346,25.209,121.676' +# }}} +# Misc{{{ +alias gpg.config="$EDITOR ~/.gnupg/gpg-agent.conf" alias foo='echo bar > foo && echo File foo is created && ls -lh foo' alias bar='echo foo > bar && echo File bar is created && ls -lh bar' alias wcl='wc -l' @@ -488,7 +509,6 @@ yt.audio() { alias editor='select-editor' alias hp='http-prompt' alias clocg='cloc --vcs=git' -alias tma='tmux a' pbf() { protoc --decode_raw } @@ -508,25 +528,8 @@ wrap2geojson() { jq -s '{ type: "FeatureCollection", features: . }'; } alias cdtrash='cd ~/.local/share/Trash' trash() { mv $@ ~/.local/share/Trash; } alias ge='graph-easy --boxart' - -# pass -alias chp='tig -C ~/.password-store' -alias chpass='tig -C ~/.password-store' -alias cdpass='cd ~/.password-store' -alias p='pass' -alias pc='pass -c' -alias pe='pass edit' -alias pgn='pass generate --in-place --clip' -alias pgc='pass generate --clip' -words() { - cat /usr/share/dict/usa | grep -E "^[a-z]{4,8}$" | shuf | head -40 | xargs -n${1:-2} -} - -# Nginx -alias vgx='sudo vim /etc/nginx/sites-enabled/vps && sudo nginx -t && sudo systemctl reload nginx' -alias cdngx='cd /etc/nginx' - -# tmp +# }}} +# tmp{{{ alias stew='cd ~/git/mapstew' alias vc='vultr-cli' alias xkb='cd $SETTING_DIR && make xkb' @@ -538,36 +541,4 @@ alias md='reveal' alias terminal.color='printf "\e[%dm%d dark\e[0m \e[%d;1m%d bold\e[0m\n" {30..37}{,,,}' alias gpg.bye='gpg-connect-agent reloadagent /bye' alias npm='pnpm' - -# GIS -TAIWAN_BBOX='118.1036,20.72799,122.9312,26.60305' -TAIWAN_BBOX_V='20.72799,118.1036,26.60305,122.9312' -TAIPEI_BBOX='121.346,24.926,121.676,25.209' -TAIPEI_BBOX_V='24.926,121.346,25.209,121.676' - -# Comment out -#alias mm='mkvmerge -o out.webm -w 01.webm + 02.webm' -#alias we='weechat' - -LOCAL_ALIAS=~/.config/local.alias -alias allo="$EDITOR $LOCAL_ALIAS && source $LOCAL_ALIAS" -if [ -e $LOCAL_ALIAS ]; then - source $LOCAL_ALIAS -fi - -vvv() { - while true; do - vim -c 'norm ' - if [ $? -ne 0 ]; then - break - fi - echo "restarting vim..."; - done -} - -ip.neigh() { - INTERFACES=$(ifconfig | sed -nE 's/^([^ :]+).*$/\1/p') - test -z "$1" && echo $INTERFACES && return 0 - - ifconfig | sed -nE "/^${1}/,/^$/ s/^ +inet ([0-9.]+) .*$/\1/p" -} +# }}} diff --git a/profile b/profile index e689376..12fdca0 100644 --- a/profile +++ b/profile @@ -29,6 +29,7 @@ find $SETTING_DIR/bin -not -executable -name '*rc' | while read rcfile; do sourc # local PATH=$PATH:$HOME/.local/bin +PATH=$PATH:$HOME/.local/share/gem/ruby/3.2.0/bin # go PATH=$PATH:$HOME/go/bin # android-studio diff --git a/vim/init/config.vim b/vim/init/config.vim index 8be42b4..680a5fc 100644 --- a/vim/init/config.vim +++ b/vim/init/config.vim @@ -11,116 +11,6 @@ augroup DeleteUnnamedEmptBuffer! au BufLeave {} if getline(1, '$') == [''] | setlocal bufhidden=wipe | endif augroup END -" }}} -" Small Terminal {{{ - -augroup TerminalSize - au! - function! LayoutForSmallTerminal(bound) - if &lines < a:bound || g:alacritty_extra_padding - silent! set laststatus=0 showtabline=0 signcolumn=0 nowrap scrolloff=1 - else - silent! set laststatus& showtabline=2 signcolumn& scrolloff& - endif - endfunc - autocmd VimEnter,VimResized * silent call LayoutForSmallTerminal(20) - autocmd VimLeave,VimSuspend * if g:alacritty_extra_padding | silent call ToggleWinPadding(100) | endif -augroup END - -" }}} -" Big File {{{ - -augroup BigFileDisable - autocmd! - autocmd BufReadPre,FileReadPre * if getfsize(expand("%")) > 512 * 1024 | setlocal eventignore=all | endif -augroup END -"}}} -" X11 {{{ - -" Change IM to US when exit to Normal mode -autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true - -" }}} -" TMUX {{{ - -" 有 tmux 何没有的功能键超时(毫秒) -if $TMUX != '' - set ttimeoutlen=30 -elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0 - set ttimeoutlen=80 -endif - -" 防止tmux下vim的背景色显示异常 -" Refer: http://sunaku.github.io/vim-256color-bce.html -if &term =~ '256color' && $TMUX != '' - " disable Background Color Erase (BCE) so that color schemes - " render properly when inside 256-color tmux and GNU screen. - set t_ut= -endif - - -" Ref: https://gist.github.com/andersevenrud/015e61af2fd264371032763d4ed965b6 -" You might have to force true color when using regular vim inside tmux as the -" colorscheme can appear to be grayscale with 'termguicolors' option enabled. -if !has('gui_running') && &term =~ '^\%(screen\|tmux\)' - let &t_8f = "\[38;2;%lu;%lu;%lum" - let &t_8b = "\[48;2;%lu;%lu;%lum" -endif - -" }}} -" KeyCode {{{ - -"---------------------------------------------------------------------- -" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021 -" 记得设置 ttimeout (见 init-basic.vim) 和 ttimeoutlen (上面) -"---------------------------------------------------------------------- -if has('nvim') == 0 && has('gui_running') == 0 - function! s:metacode(key) - exec "set =\e".a:key - endfunc - " set 0-9 - for i in range(10) - call s:metacode(nr2char(char2nr('0') + i)) - endfor - " set a-z A-Z - for i in range(26) - call s:metacode(nr2char(char2nr('a') + i)) - call s:metacode(nr2char(char2nr('A') + i)) - endfor - for c in [',', '.', '/', ';', '{', '}'] - call s:metacode(c) - endfor - for c in ['?', ':', '-', '_', '+', '=', "'"] - call s:metacode(c) - endfor -endif - -"---------------------------------------------------------------------- -" 功能键终端码矫正 -"---------------------------------------------------------------------- -function! s:key_escape(name, code) - if has('nvim') == 0 && has('gui_running') == 0 - exec "set ".a:name."=\e".a:code - endif -endfunc - -call s:key_escape('', 'OP') -call s:key_escape('', 'OQ') -call s:key_escape('', 'OR') -call s:key_escape('', 'OS') -call s:key_escape('', '[1;2P') -call s:key_escape('', '[1;2Q') -call s:key_escape('', '[1;2R') -call s:key_escape('', '[1;2S') -call s:key_escape('', '[15;2~') -call s:key_escape('', '[17;2~') -call s:key_escape('', '[18;2~') -call s:key_escape('', '[19;2~') -call s:key_escape('', '[20;2~') -call s:key_escape('', '[21;2~') -call s:key_escape('', '[23;2~') -call s:key_escape('', '[24;2~') - " }}} " Filetype {{{ @@ -128,15 +18,6 @@ augroup InitFileTypes au! - " Filetype for Vim {{{ - - " Help page - autocmd BufEnter * if &filetype == 'help' | wincmd T | set buflisted nofoldenable | endif - - " quickfix: hide line number - autocmd FileType quickfix setlocal nonumber - - " }}} " Shebeng: Set filetype from shebeng {{{ function! s:ApplyShebang() let l:filetype = matchstr(getline(1), '^#!.*[ /]\zs[[:alnum:]]\+$') @@ -149,6 +30,18 @@ augroup InitFileTypes endif endfunc autocmd BufReadPost * call ApplyShebang() + " }}} + " Conf {{{ + autocmd FileType conf set foldmethod=marker + " }}} + " Vim {{{ + + " Help page + autocmd BufEnter * if &filetype == 'help' | wincmd T | set buflisted nofoldenable | endif + + " quickfix: hide line number + autocmd FileType quickfix setlocal nonumber + " }}} " Markdown {{{ @@ -341,6 +234,119 @@ augroup InitFileTypes " }}} augroup END +" }}} +" Small Terminal {{{ + +augroup TerminalSize + au! + function! LayoutForSmallTerminal(bound) + if &lines < a:bound || g:alacritty_extra_padding + silent! set laststatus=0 showtabline=0 signcolumn=0 nowrap scrolloff=1 + else + silent! set laststatus& showtabline=2 signcolumn& scrolloff& + endif + endfunc + autocmd VimEnter,VimResized * silent call LayoutForSmallTerminal(20) + autocmd VimLeave,VimSuspend * if g:alacritty_extra_padding | silent call ToggleWinPadding(100) | endif +augroup END + +" }}} +" Big File {{{ + +augroup BigFileDisable + autocmd! + autocmd BufReadPre,FileReadPre * if getfsize(expand("%")) > 512 * 1024 | setlocal eventignore=all | endif +augroup END +"}}} +" X11 {{{ + +" Change IM to US when exit to Normal mode +autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true + +" }}} +" TMUX {{{ + +" 有 tmux 何没有的功能键超时(毫秒) +if $TMUX != '' + set ttimeoutlen=30 +elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0 + set ttimeoutlen=80 +endif + +" 防止tmux下vim的背景色显示异常 +" Refer: http://sunaku.github.io/vim-256color-bce.html +if &term =~ '256color' && $TMUX != '' + " disable Background Color Erase (BCE) so that color schemes + " render properly when inside 256-color tmux and GNU screen. + set t_ut= +endif + + +" Ref: https://gist.github.com/andersevenrud/015e61af2fd264371032763d4ed965b6 +" You might have to force true color when using regular vim inside tmux as the +" colorscheme can appear to be grayscale with 'termguicolors' option enabled. +if !has('gui_running') && &term =~ '^\%(screen\|tmux\)' + let &t_8f = "\[38;2;%lu;%lu;%lum" + let &t_8b = "\[48;2;%lu;%lu;%lum" +endif + +" }}} +" KeyCode {{{ + +"---------------------------------------------------------------------- +" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021 +" 记得设置 ttimeout (见 init-basic.vim) 和 ttimeoutlen (上面) +"---------------------------------------------------------------------- +if has('nvim') == 0 && has('gui_running') == 0 + function! s:metacode(key) + exec "set =\e".a:key + endfunc + " set 0-9 + for i in range(10) + call s:metacode(nr2char(char2nr('0') + i)) + endfor + " set a-z A-Z + for i in range(26) + call s:metacode(nr2char(char2nr('a') + i)) + call s:metacode(nr2char(char2nr('A') + i)) + endfor + for c in [',', '.', '/', ';', '{', '}'] + call s:metacode(c) + endfor + for c in ['?', ':', '-', '_', '+', '=', "'"] + call s:metacode(c) + endfor +endif + +"---------------------------------------------------------------------- +" 功能键终端码矫正 +"---------------------------------------------------------------------- +function! s:key_escape(name, code) + if has('nvim') == 0 && has('gui_running') == 0 + exec "set ".a:name."=\e".a:code + endif +endfunc + +call s:key_escape('', 'OP') +call s:key_escape('', 'OQ') +call s:key_escape('', 'OR') +call s:key_escape('', 'OS') +call s:key_escape('', '[1;2P') +call s:key_escape('', '[1;2Q') +call s:key_escape('', '[1;2R') +call s:key_escape('', '[1;2S') +call s:key_escape('', '[15;2~') +call s:key_escape('', '[17;2~') +call s:key_escape('', '[18;2~') +call s:key_escape('', '[19;2~') +call s:key_escape('', '[20;2~') +call s:key_escape('', '[21;2~') +call s:key_escape('', '[23;2~') +call s:key_escape('', '[24;2~') + +" }}} +" Others {{{ let g:ale_lint_on_save = 1 let g:ale_fix_on_save = 1 +" }}} -- cgit v1.2.3-70-g09d2