Skip to content

Instantly share code, notes, and snippets.

@rhoboro

rhoboro/.vimrc Secret

Last active December 14, 2022 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhoboro/5c1eadff1fc2d6e73a35fd68687eaff8 to your computer and use it in GitHub Desktop.
Save rhoboro/5c1eadff1fc2d6e73a35fd68687eaff8 to your computer and use it in GitHub Desktop.
dotfiles snapshot
"
" A (not so) minimal vimrc.
"
set paste
set belloff=all
set ignorecase
set smartcase
set nf=""
set nowrap
set completeopt=menuone
set autoread
let mapleader = "\<Space>"
nnoremap <Esc><Esc> :nohlsearch<CR><ESC>
inoremap <Esc> <Esc>:set iminsert=0<CR>
" noremap <C-[> <C-t>
nnoremap j gj
nnoremap k gk
nnoremap <Down> gj
nnoremap <Up> gk
" nnoremap j :echoe ""<CR>
" nnoremap k :echoe ""<CR>
" nnoremap h :echoe ""<CR>
" nnoremap l :echoe ""<CR>
inoremap <c-b> <Esc>:Lex<cr>:vertical resize 30<cr>
nnoremap <c-b> <Esc>:Lex<cr>:vertical resize 30<cr>
nmap ss :split<Return><C-w>w
nmap sv :vsplit<Return><C-w>w
map sh <C-w>h
map sk <C-w>k
map sj <C-w>j
map sl <C-w>l
set path+=$PWD/**
set wildignore+=**/venv/**,**/__pycache__/**,**/node_modules/**
set wmnu
" Auto IME Off
autocmd InsertLeave * :silent !im-select com.apple.keylayout.ABC
" You want Vim, not vi. When Vim finds a vimrc, 'nocomptaible' is set anyway.
" We set it explicitely to make our position clear!
set nocompatible
syntax on " Enable syntax highlighting.
colorscheme monokai
" set autoindent " Indent according to previous line.
set expandtab " Use spaces instead of tabs.
set softtabstop =4 " Tab key indents by 4 spaces.
set tabstop =4 " Tab key indents by 4 spaces.
set shiftwidth =4 " >> indents by 4 spaces.
set shiftround " >> indents to next multiple of 'shiftwidth'.
set backspace =indent,eol,start " Make backspace work as you would expect.
set hidden " Switch between buffers without having to save first.
set laststatus =2 " Always show statusline.
set display =lastline " Show as much as possible of the last line.
set showmode " Show current mode in command-line.
set showcmd " Show already typed keys when more are expected.
set incsearch " Highlight while searching with / or ?.
set hlsearch " Keep matches highlighted.
set ttyfast " Faster redrawing.
set lazyredraw " Only redraw when necessary.
set splitbelow " Open new windows below the current window.
set splitright " Open new windows right of the current window.
set cursorline " Find the current line quickly.
set wrapscan " Searches wrap around end-of-file.
set report =0 " Always report changed lines.
set synmaxcol =200 " Only highlight the first 200 columns.
set list " Show non-printable characters.
if has('multi_byte') && &encoding ==# 'utf-8'
let &listchars = 'tab:▸ ,extends:❯,precedes:❮,nbsp:±'
else
let &listchars = 'tab:> ,extends:>,precedes:<,nbsp:.'
endif
" The fish shell is not very compatible to other shells and unexpectedly
" breaks things that use 'shell'.
if &shell =~# 'fish$'
set shell=/bin/bash
endif
" Put all temporary files under the same directory.
" https://github.com/mhinz/vim-galore#handling-backup-swap-undo-and-viminfo-files
set backup
set backupdir =$HOME/.vim/files/backup/
set backupext =-vimbackup
set backupskip =
set directory =$HOME/.vim/files/swap/
set updatecount =100
set undofile
set undodir =$HOME/.vim/files/undo/
" set viminfo ='100,n$HOME/.vim/files/info/viminfo,<500
set viminfo =
augroup vimrc-auto-mkdir " {{{
autocmd!
autocmd BufWritePre * call s:auto_mkdir(expand('<afile>:p:h'), v:cmdbang)
function! s:auto_mkdir(dir, force) " {{{
if !isdirectory(a:dir) && (a:force ||
\ input(printf('"%s" does not exist. Create? [y/N]', a:dir)) =~? '^y\%[es]$')
call mkdir(iconv(a:dir, &encoding, &termencoding), 'p')
endif
endfunction " }}}
augroup END " }}}
filetype plugin indent on " Load plugins according to detected filetype.
" HariboteOS用
au BufRead,BufNewFile *.nas set filetype=nas
imap <C-e> <END>
" ファイルツリーの表示形式、1にするとls -laのような表示になります
let g:netrw_liststyle=3
" ヘッダを非表示にする
let g:netrw_banner=0
" サイズを(K,M,G)で表示する
let g:netrw_sizestyle="H"
" 日付フォーマットを yyyy/mm/dd(曜日) hh:mm:ss で表示する
let g:netrw_timefmt="%Y/%m/%d(%a) %H:%M:%S"
" プレビューウィンドウを垂直分割で表示する
let g:netrw_preview=1
" 左右分割を右側に開く
let g:netrw_altv = 1
" 分割で開いたときに85%のサイズで開く
let g:netrw_winsize = 85
let g:netrw_list_hide="__pycache__"
augroup BinaryXXD
autocmd!
autocmd BufReadPre *.bin let &binary =1
autocmd BufReadPost * if &binary | silent %!xxd -g 1
autocmd BufReadPost * set ft=xxd | endif
autocmd BufWritePre * if &binary | %!xxd -r | endif
autocmd BufWritePost * if &binary | silent %!xxd -g 1
autocmd BufWritePost * set nomod | endif
augroup END
au QuickfixCmdPost make,grep,grepadd,vimgrep cwin
" Search
if executable('rg')
let &grepprg = 'rg --vimgrep --hidden > /dev/null'
set grepformat=%f:%l:%c:%m
endif
" https://dev.to/pbnj/interactive-fuzzy-finding-in-vim-without-plugins-4kkj
function! SKIM() abort
let l:tempname = tempname()
execute 'silent !fd --type f --color always | sk --ansi -m --preview "bat --color always {}" | awk ''{ print $1":1:0" }'' > ' . fnameescape(l:tempname)
try
execute 'cfile ' . l:tempname
redraw!
finally
call delete(l:tempname)
endtry
endfunction
" :Files
command! -nargs=* Files call SKIM()
" <space>fd
nnoremap <leader>fd :Files<cr>
nnoremap <c-f> :Files<cr>
" Load .vimrc.local
" https://vim-jp.org/vim-users-jp/2009/12/27/Hack-112.html
augroup vimrc-local
autocmd!
autocmd BufNewFile,BufReadPost * call s:vimrc_local(expand('<afile>:p:h'))
augroup END
function! s:vimrc_local(loc)
let files = findfile('.vimrc.local', escape(a:loc, ' ') . ';', -1)
for i in reverse(filter(files, 'filereadable(v:val)'))
source `=i`
endfor
endfunction
setopt no_beep
alias cat="bat"
alias cl="clear"
alias ta="tmux a -t"
alias tn="tmux new -A -s"
alias tl="tmux ls"
#alias curl="echo xh"
alias grep="ggrep"
alias sed="gsed"
alias find="gfind"
alias awk="gawk"
alias g="git"
alias ls="ls -G"
alias view="view -M"
alias a="cd ../"
alias aa="cd ../../"
alias aaa="cd ../../../"
alias aaaa="cd ../../../../"
# https://github.com/kovidgoyal/kitty/issues/1613
# https://sw.kovidgoyal.net/kitty/faq/#i-get-errors-about-the-terminal-being-unknown-or-opening-the-terminal-failing-when-sshing-into-a-different-computer
if [ "$TERM" = "xterm-kitty" ]; then
# SSH 時に kitty の terminfo をリモートにコピー
# gcloud compute ssh などでは動かない
# その場合は infocmp -a xterm-kitty | pbcopy して ~/.terminfo/x/xterm-kitty に貼り付けて入り直せば OK
alias ssh="kitty +kitten ssh"
fi
export LC_ALL='ja_JP.UTF-8'
export RBENV_ROOT="$HOME/.rbenv"
export VOLTA_HOME="$HOME/.volta"
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
export PYTHONSDK="/Library/Frameworks/Python.framework/Versions"
export PYTHONDONTWRITEBYTECODE='TRUE'
export PATH="/opt/homebrew/bin:$HOME/.local/bin:/usr/local/bin:$PATH"
export PATH="$PYTHONSDK/3.11/bin:$PYTHONSDK/3.10/bin:$PYTHONSDK/3.9/bin:$PYTHONSDK/3.8/bin:usr/local/go/bin:$HOME/go/bin:${RBENV_ROOT}/bin:/usr/local/opt/openssl/bin:$PATH"
export PATH="$HOME/Library/Python/3.10/bin:$HOME/.volta/bin:$HOME/.cargo/bin:/opt/homebrew/opt/llvm/bin:$PATH"
export CLOUDSDK_ROOT="$HOME/google-cloud-sdk"
export CLOUDSDK_PYTHON="${PYTHONSDK}/3.8/bin/python3"
export FPATH="$HOME/.zsh/completion:$FPATH"
export XDG_CONFIG_HOME="$HOME/.config"
export RIPGREP_CONFIG_PATH="$XDG_CONFIG_HOME/.ripgreprc"
export SKIM_DEFAULT_OPTIONS="--reverse --bind=ctrl-d:half-page-down,ctrl-u:half-page-up --color=current_bg:24"
export EDITOR="vim"
# タブをスペース4つの幅で表示
tabs -4
bindkey -e
### zsh ###
autoload -Uz add-zsh-hook
plugins=(git osx brew)
# history
setopt share_history
export HISTFILE=${HOME}/.zsh_history
export HISTSIZE=5000
export SAVEHIST=100000
setopt hist_ignore_dups
setopt EXTENDED_HISTORY
setopt hist_expand
function history-all { history -E 1 }
# prompt
PROMPT="%F{red}[%n]%.%f %# "
setopt prompt_subst
autoload -Uz vcs_info
zstyle ':vcs_info:*' formats '%F{5}[%F{2}%b%F{7}%F{5}]%f'
precmd () {
vcs_info
}
aws_msg() {
if [ "$AWS_PROFILE" ]; then
local color
case "$AWS_PROFILE" in
*prod*) color=196;;
*stg*) color=3;;
*) color=4;;
esac
echo -n "%F{5}[%F{${color}}${AWS_PROFILE}%F{5}]";
fi
}
RPROMPT=$'${vcs_info_msg_0_}$(aws_msg)'
# The next line updates PATH for the Google Cloud SDK.
if [ -f "$HOME/google-cloud-sdk/path.zsh.inc" ]; then . "$HOME/google-cloud-sdk/path.zsh.inc"; fi
# The next line enables shell command completion for gcloud.
if [ -f "$HOME/google-cloud-sdk/completion.zsh.inc" ]; then . "$HOME/google-cloud-sdk/completion.zsh.inc"; fi
# direnv
eval "$(direnv hook zsh)"
# sk-src
bindkey '^J' sk-src
function sk-src() {
local src=$(ghq list | sk -q "$LBUFFER")
if [ -n "$src" ]; then
src=$(ghq list --full-path | grep "$src$")
BUFFER="cd $src"
zle accept-line
fi
zle -R -c
}
zle -N sk-src
# sk-cmd
bindkey '^Y' sk-cmd
function sk-cmd() {
local cmd=$(find ${HOME}/dotfiles/commands/ -type f -not -name "_*" | xargs bat --style plain --color always | sk --ansi -q "$LBUFFER")
if [ -n "$cmd" ]; then
BUFFER="$cmd"
TMP_CURSOR=${$(echo $BUFFER | awk '{print index($0, "{cursor}")}')}
if [ $TMP_CURSOR -gt 0 ]; then
BUFFER=${$(echo $BUFFER | sed 's/{cursor}//g')}
CURSOR=${$(($TMP_CURSOR - 1))}
else
CURSOR=${#BUFFER}
fi
# 行を受け付けて実行
#zle accept-line
fi
zle -R -c
}
zle -N sk-cmd
# sk-history
bindkey '^R' sk-select-history
function sk-select-history() {
BUFFER=$(history -n 1 | sk --tac --no-sort --query "$LBUFFER")
CURSOR=$#BUFFER
zle clear-screen
}
zle -N sk-select-history
# sk-vim
bindkey '^F' sk-vim
function sk-vim() {
local cmd=$(fd --type f --color always | sk --ansi --preview "bat --color always {}" | awk -F: '{printf $1 " +" $2}'| sed -e 's/\+$//')
if [ -n "$cmd" ]; then
BUFFER="$EDITOR $cmd"
CURSOR=${#BUFFER}
zle accept-line
fi
}
zle -N sk-vim
# sk-cd
bindkey '^G' sk-cd
function sk-cd() {
local DIR=$(fd --type d --color always | sk --ansi --preview "bat --color always {}" | awk -F: '{printf $1 " +" $2}'| sed -e 's/\+$//')
if [ -n "$DIR" ]; then
BUFFER="cd $DIR"
CURSOR=${#BUFFER}
zle accept-line
fi
}
zle -N sk-cd
function sk-rg() {
if [ -n "$*" ]; then
local cmd=$(rg -. -n --color always --no-heading $* | sk --ansi --preview "~/dotfiles/preview.sh {}" | awk -F: '{printf $1 " +" $2}'| sed -e 's/\+$//')
if [ -n "$cmd" ]; then
zsh -c "$EDITOR $cmd"
fi
fi
}
alias gg="sk-rg"
# .gitignore
function gitignore() {
xh https://www.toptal.com/developers/gitignore/api/$1
}
### zshのコマンド補完 ###
fpath=($(brew --prefix)/share/zsh/site-functions ~/.zsh/completion $fpath)
autoload -U +X bashcompinit && bashcompinit
autoload -U compinit && compinit
zstyle ':completion:*' verbose yes
zstyle ':completion:*' format '%B%d%b'
#zstyle ':completion:*:warnings' format 'No matches for: %d'
#zstyle ':completion:*' group-name ''
# 下記は時間がかかるので遅延させる
#complete -o nospace -C $HOME/go/bin/gocomplete go
#complete -o nospace -C /usr/local/bin/terraform terraform
#eval "$(kubectl completion zsh)"
#eval "$(npm completion)"
#eval "$(rbenv init -)"
#eval "$(gh completion -s zsh)"
go() {
unfunction "$0"
complete -o nospace -C $HOME/go/bin/gocomplete go
$0 "$@"
}
terraform() {
unfunction "$0"
complete -o nospace -C /usr/local/bin/terraform terraform
$0 "$@"
}
gh() {
unfunction "$0"
source <(gh completion -s zsh)
$0 "$@"
}
kubectl() {
unfunction "$0"
source <(kubectl completion zsh)
$0 "$@"
}
npm() {
unfunction "$0"
source <(npm completion)
$0 "$@"
}
rbenv() {
unfunction "$0"
source <(rbenv init -)
$0 "$@"
}
awscli
aws-google-auth
bat
black
colordiff
coreutils
ctags
curl
direnv
exa
fd
findutils
gawk
gh
ghq
git
glow
gnu-sed
grep
hub
isort
jq
nkf
nodenv
openssl
pwgen
rbenv
readline
reattach-to-user-namespace
ripgrep
sk
sqlite
tig
tmux
tree
unar
vim
wget
xh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment