はじめに
現場PCがlinuxやmacなら、ルール次第でデフォルトのvimを使えるかもですが
Windowsだと、使えるなら公式vimやwsl、wsl2でいける、GitbashがあるならMinGWを利用して使う。ないならサクラ。
プラグインインストールやダウンロードには気を付ける。私用ならバンバン使おう。
※個人的なフォルダ構成になってるのでvimrcだったりプラグインだけパクればいいと思います
※この記事は古いです。
最新の設定はこちらに置いてあります。
プラグインとvimrc
プラグインshell
mkdir -p ~/.vim/pack/plugins/start ~/.vim/autoload ~/.vim/colors && cd ~/.vim/pack/plugins/start
repos=(
'sheerun/vim-polyglot'
'joshdick/onedark.vim'
'vim-airline/vim-airline'
'vim-airline/vim-airline-themes'
'ryanoasis/vim-devicons'
'powerline/fonts'
'preservim/nerdtree'
'junegunn/fzf'
'junegunn/fzf.vim'
'prabirshrestha/vim-lsp'
'mattn/vim-lsp-settings'
'yuttie/comfortable-motion.vim'
'easymotion/vim-easymotion'
'simeji/winresizer'
'junegunn/goyo.vim'
'prabirshrestha/asyncomplete.vim'
'prabirshrestha/asyncomplete-lsp.vim'
'prabirshrestha/asyncomplete-buffer.vim'
'koturn/asyncomplete-dictionary.vim'
'akaimo/asyncomplete-around.vim'
'hrsh7th/vim-vsnip'
'hrsh7th/vim-vsnip-integ'
'rafamadriz/friendly-snippets'
)
for v in ${repos[@]}; do
git clone --depth 1 "https://github.com/${v}"
done
cp -rf onedark.vim/autoload/* ~/.vim/autoload && cp -f onedark.vim/colors/onedark.vim ~/.vim/colors
sh fonts/install.sh
fzf/install --no-key-bindings --completion --no-bash --no-zsh --no-fish
vimrc
" ini -------------------------------------------------------------
if has('vim_starting')
cd
endif
" base ----------------------------------------
let g:mapleader = "\<Space>"
set noswapfile
set clipboard+=unnamed
set tabstop=4
set backspace=indent,eol,start
"set ff=unix
"set fileencoding=utf8
" looks -------------------------------------------------------
syntax on
set number
set cursorline
set cursorcolumn
set ambiwidth=double
set list
set listchars=tab:»-,trail:-,eol:↲,extends:»,precedes:«,nbsp:%
colorscheme torte
if glob('~/.vim/colors/onedark.vim') != ''
colorscheme onedark
endif
" status/tab line ---------------------------------------------------
set ruler
set laststatus=2
set statusline=%F%m%r%h%w%=[all]_%p%%___[row]_%l/%L___[col]_%02v___[%{&fenc!=''?&fenc:&enc}]
let ff_table = {'dos' : 'CRLF', 'unix' : 'LF', 'mac' : 'CR' }
set statusline+=[%{ff_table[&ff]}]
let g:airline_theme = 'onedark'
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
" explorer -------------------------------------------
set splitright
filetype plugin on
let g:netrw_liststyle = 3
let g:netrw_altv = 1
let g:netrw_winsize = 70
nmap <Leader>e :NERDTreeToggle<CR>
nmap <Leader><Leader>e :NERDTreeFind<CR>zz
" search find ---------------------------------------------------
command! -nargs=1 Q call FileSearch(<f-args>)
function! FileSearch(name)
for found in split(glob(a:name), "\n")
echo found
endfor
endfunction
set rtp+=~/.vim/pack/plugins/start/fzf
nmap <Leader>f :Files<CR>
nmap <Leader>b :Buffers<CR>
nmap <Leader>h :History<CR>
" programer jump grep info -------------------------------------------
set hlsearch
set incsearch
autocmd QuickFixCmdPost *grep* cwindow
nmap <Leader>gg :call GrepCurrentExtention()<CR>
function! GrepCurrentExtention()
echo 'grep processing in [' . expand('%:e') .'] ...'
call execute('vimgrep /' . expand('<cword>') . '/gj **/*.' . expand('%:e'))
endfunction
nmap <Leader>ge :GrepExtFrom
command! -nargs=1 GrepExtFrom call GrepExtFrom(<f-args>)
function! GrepExtFrom(ext)
echo 'grep processing in [' . a:ext .'] ...'
call execute('vimgrep /' . expand('<cword>') . '/gj **/*.' . a:ext)
endfunction
nmap <Leader>j :LspHover<CR>
nmap <Leader>p :LspPeekDefinition<CR>
nmap <Leader>o :LspDefinition<CR>
nmap <Leader>r :LspReferences<CR>
" god speed jump -------------------------------------------------------
let g:comfortable_motion_interval = 2400.0 / 60
let g:comfortable_motion_friction = 100.0
let g:comfortable_motion_air_drag = 3.0
nmap <Leader>w <Plug>(easymotion-overwin-f2)
nmap <Leader>s <Plug>(easymotion-s2)
nmap <Leader>m :marks abcdefghijklmnopqrstuvwxyz<CR>:normal! `
nmap mm :call Marking()<CR>
function! Marking() abort
let l:now_marks = []
let l:words = 'abcdefghijklmnopqrstuvwxyz'
let l:warr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for row in split(execute('marks'), '\n')
let l:r = filter(split(row, ' '), {i, v -> v != ''})
if stridx(words, r[0]) != -1 && r[1] == line('.')
call execute('delmarks ' . r[0])
echo 'delete mark'
return
endif
let l:now_marks = add(now_marks, r[0])
endfor
let l:can_use = filter(warr, {i, v -> stridx(join(now_marks, ''), v) == -1})
if len(can_use) != 0
call execute('mark ' . can_use[0])
echo 'marked'
else
echo 'over limit markable char'
endif
endfunction
" window change open close zen ------------------------------------------
nmap <C-p> :bn<CR>
nmap <C-q> :bp<CR>
nmap <Leader>x :call CloseBuf()<CR>
function! CloseBuf()
let l:now_b = bufnr('%')
bn
execute('bd ' . now_b)
endfunction
nmap <Leader>t :bo terminal<CR>
nmap <Leader>z :Goyo 100<CR>:set number<CR>
nmap <Leader><Leader>z :Goyo<CR>
" completion ----------------------------------------------------
set dictionary+=~/.local/zzz/dictionary_english.dat
set thesaurus+=~/.local/zzz/dictionary_english.dat
set dictionary+=~/.uranometria/necronomicon.md
set thesaurus+=~/.uranometria/necronomicon.md
" ↑おすきな辞書を登録すればよろし
set wildmenu
set complete=.,w,b,u,U,k,kspell,s,i,d,t
set completeopt=menuone,noinsert,preview,popup
let g:vsnip_snippet_dir = '~/.uranometria/forge/snips'
nmap <Leader>0 :VsnipOpen<CR>
imap <expr> <Tab> pumvisible() ? '<C-n>' : vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-n>'
inoremap <expr> <S-Tab> pumvisible() ? '<C-p>' : '<S-Tab>'
inoremap <expr> <CR> pumvisible() ? '<C-y>' : '<CR>'
inoremap { {}<LEFT>
inoremap [ []<LEFT>
inoremap ( ()<LEFT>
inoremap < <><LEFT>
inoremap " ""<LEFT>
inoremap ' ''<LEFT>
inoremap ` ``<LEFT>
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#buffer#get_source_options({
\ 'name': 'buffer',
\ 'allowlist': ['*'],
\ 'blocklist': ['go'],
\ 'completor': function('asyncomplete#sources#buffer#completor'),
\ 'config': {
\ 'max_buffer_size': 5000000,
\ },
\ }))
au User asyncomplete_setup call asyncomplete#register_source({
\ 'name': 'dictionary',
\ 'allowlist': ['*'],
\ 'completor': function('asyncomplete#sources#dictionary#completor'),
\ })
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#around#get_source_options({
\ 'name': 'around',
\ 'allowlist': ['*'],
\ 'priority': 10,
\ 'completor': function('asyncomplete#sources#around#completor'),
\ }))
" other -------------------------------------------------------------
nmap <Leader>l :call ExecuteThisLineCMD()<CR>
function! ExecuteThisLineCMD()
execute('bo terminal ++shell eval ' . getline('.'))
endfunction
🌟これコピペで全部おわり
shell
echo "=========================================================="
echo ">>> (0/7). START"
echo ">>> (1/7). MAKE ~/.uranometria/* (if exist skip, add necronomicon)"
mkdir -p ~/.uranometria/forge/snips ~/.uranometria/stella ~/.uranometria/zodiac
cat - << "EOF" >> ~/.uranometria/necronomicon.md
# note
# git
git status
git fetch --all
git pull
git checkout . && git clean -df && git status
git add . && git commit -m '${1}' && git push
git fetch --all && git branch -r | grep ${1} | cut -d '/' -f 2 | xargs -t -I{} git checkout -b {} origin/{}
git branch | grep ${1} | xargs -t -I{} git checkout {}
EOF
echo ">>> (2/7). MAKE ~/.uranometria/forge/backup.sh (over write)"
cat - << "EOF" > ~/.uranometria/forge/backup.sh
read -sp "Key: " pass
if [ "silver" != "${pass}" ]; then
exit
fi
cd ~/.uranometria/zodiac
LIMIT=12
PREFIX=ふしぎなおくりもの
FOLDER_NAME=${PREFIX}`date '+%Y-%m-%d'`
# bk
if [ ! -e ./${FOLDER_NAME} ]; then
mkdir ${FOLDER_NAME}
fi
cp -f ../necronomicon.md ${FOLDER_NAME}
cp -rf ../stella ${FOLDER_NAME}
cp -rf ../forge ${FOLDER_NAME}
# delete over limit
CNT=`ls -l | grep ^d | wc -l`
if [ ${CNT} -gt ${LIMIT} ]; then
ls -d */ | sort | head -n $((CNT-LIMIT)) | xargs rm -rf
fi
# chk
ls -ail
EOF
echo ">>> (3/7). MAKE ~/.uranometria/forge/omnibus.sh (over write)"
cat - << "EOF" > ~/.uranometria/forge/omnibus.sh
mkdir -p ~/.vim/pack/plugins/start ~/.vim/autoload ~/.vim/colors && cd ~/.vim/pack/plugins/start
repos=(
'sheerun/vim-polyglot'
'joshdick/onedark.vim'
'vim-airline/vim-airline'
'vim-airline/vim-airline-themes'
'ryanoasis/vim-devicons'
'powerline/fonts'
'preservim/nerdtree'
'junegunn/fzf'
'junegunn/fzf.vim'
'prabirshrestha/vim-lsp'
'mattn/vim-lsp-settings'
'yuttie/comfortable-motion.vim'
'easymotion/vim-easymotion'
'simeji/winresizer'
'junegunn/goyo.vim'
'prabirshrestha/asyncomplete.vim'
'prabirshrestha/asyncomplete-lsp.vim'
'prabirshrestha/asyncomplete-buffer.vim'
'koturn/asyncomplete-dictionary.vim'
'akaimo/asyncomplete-around.vim'
'hrsh7th/vim-vsnip'
'hrsh7th/vim-vsnip-integ'
'rafamadriz/friendly-snippets'
)
for v in ${repos[@]}; do
git clone --depth 1 "https://github.com/${v}"
done
cp -rf onedark.vim/autoload/* ~/.vim/autoload && cp -f onedark.vim/colors/onedark.vim ~/.vim/colors
sh fonts/install.sh
fzf/install --no-key-bindings --completion --no-bash --no-zsh --no-fish
EOF
chmod 777 ~/.uranometria/forge/omnibus.sh
echo ">>> (4/7). MAKE ~/.uranometria/forge/kill.sh (over write)"
cat - << "EOF" > ~/.uranometria/forge/kill.sh
~/.vim/pack/plugins/start/fzf/uninstall
rm -rf ~/.vim ~/.local
EOF
chmod 777 ~/.uranometria/forge/kill.sh
echo ">>> (5/7). MAKE ~/.vimrc (over write)"
cat - << "EOF" > ~/.vimrc
" ini -------------------------------------------------------------
if has('vim_starting')
cd
endif
" base ----------------------------------------
let g:mapleader = "\<Space>"
set noswapfile
set clipboard+=unnamed
set tabstop=4
set backspace=indent,eol,start
"set ff=unix
"set fileencoding=utf8
" looks -------------------------------------------------------
syntax on
set number
set cursorline
set cursorcolumn
set ambiwidth=double
set list
set listchars=tab:»-,trail:-,eol:↲,extends:»,precedes:«,nbsp:%
colorscheme torte
if glob('~/.vim/colors/onedark.vim') != ''
colorscheme onedark
endif
" status/tab line ---------------------------------------------------
set ruler
set laststatus=2
set statusline=%F%m%r%h%w%=[all]_%p%%___[row]_%l/%L___[col]_%02v___[%{&fenc!=''?&fenc:&enc}]
let ff_table = {'dos' : 'CRLF', 'unix' : 'LF', 'mac' : 'CR' }
set statusline+=[%{ff_table[&ff]}]
let g:airline_theme = 'onedark'
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
" explorer -------------------------------------------
set splitright
filetype plugin on
let g:netrw_liststyle = 3
let g:netrw_altv = 1
let g:netrw_winsize = 70
nmap <Leader>e :NERDTreeToggle<CR>
nmap <Leader><Leader>e :NERDTreeFind<CR>zz
" search find ---------------------------------------------------
command! -nargs=1 Q call FileSearch(<f-args>)
function! FileSearch(name)
for found in split(glob(a:name), "\n")
echo found
endfor
endfunction
set rtp+=~/.vim/pack/plugins/start/fzf
nmap <Leader>f :Files<CR>
nmap <Leader>b :Buffers<CR>
nmap <Leader>h :History<CR>
" programer jump grep info -------------------------------------------
set hlsearch
set incsearch
autocmd QuickFixCmdPost *grep* cwindow
nmap <Leader>gg :call GrepCurrentExtention()<CR>
function! GrepCurrentExtention()
echo 'grep processing in [' . expand('%:e') .'] ...'
call execute('vimgrep /' . expand('<cword>') . '/gj **/*.' . expand('%:e'))
endfunction
nmap <Leader>ge :GrepExtFrom
command! -nargs=1 GrepExtFrom call GrepExtFrom(<f-args>)
function! GrepExtFrom(ext)
echo 'grep processing in [' . a:ext .'] ...'
call execute('vimgrep /' . expand('<cword>') . '/gj **/*.' . a:ext)
endfunction
nmap <Leader>j :LspHover<CR>
nmap <Leader>p :LspPeekDefinition<CR>
nmap <Leader>o :LspDefinition<CR>
nmap <Leader>r :LspReferences<CR>
" god speed jump -------------------------------------------------------
let g:comfortable_motion_interval = 2400.0 / 60
let g:comfortable_motion_friction = 100.0
let g:comfortable_motion_air_drag = 3.0
nmap <Leader>w <Plug>(easymotion-overwin-f2)
nmap <Leader>s <Plug>(easymotion-s2)
nmap <Leader>m :marks abcdefghijklmnopqrstuvwxyz<CR>:normal! `
nmap mm :call Marking()<CR>
function! Marking() abort
let l:now_marks = []
let l:words = 'abcdefghijklmnopqrstuvwxyz'
let l:warr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for row in split(execute('marks'), '\n')
let l:r = filter(split(row, ' '), {i, v -> v != ''})
if stridx(words, r[0]) != -1 && r[1] == line('.')
call execute('delmarks ' . r[0])
echo 'delete mark'
return
endif
let l:now_marks = add(now_marks, r[0])
endfor
let l:can_use = filter(warr, {i, v -> stridx(join(now_marks, ''), v) == -1})
if len(can_use) != 0
call execute('mark ' . can_use[0])
echo 'marked'
else
echo 'over limit markable char'
endif
endfunction
" window change open close zen ------------------------------------------
nmap <C-p> :bn<CR>
nmap <C-q> :bp<CR>
nmap <Leader>x :call CloseBuf()<CR>
function! CloseBuf()
let l:now_b = bufnr('%')
bn
execute('bd ' . now_b)
endfunction
nmap <Leader>t :bo terminal<CR>
nmap <Leader>z :Goyo 100<CR>:set number<CR>
nmap <Leader><Leader>z :Goyo<CR>
" completion ----------------------------------------------------
set dictionary+=~/.local/zzz/dictionary_english.dat
set thesaurus+=~/.local/zzz/dictionary_english.dat
set dictionary+=~/.uranometria/necronomicon.md
set thesaurus+=~/.uranometria/necronomicon.md
set wildmenu
set complete=.,w,b,u,U,k,kspell,s,i,d,t
set completeopt=menuone,noinsert,preview,popup
let g:vsnip_snippet_dir = '~/.uranometria/forge/snips'
nmap <Leader>0 :VsnipOpen<CR>
inoremap <expr> <Tab> pumvisible() ? '<C-n>' : vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-n>'
inoremap <expr> <S-Tab> pumvisible() ? '<C-p>' : '<S-Tab>'
inoremap <expr> <CR> pumvisible() ? '<C-y>' : '<CR>'
inoremap { {}<LEFT>
inoremap [ []<LEFT>
inoremap ( ()<LEFT>
inoremap < <><LEFT>
inoremap " ""<LEFT>
inoremap ' ''<LEFT>
inoremap ` ``<LEFT>
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#buffer#get_source_options({
\ 'name': 'buffer',
\ 'allowlist': ['*'],
\ 'blocklist': ['go'],
\ 'completor': function('asyncomplete#sources#buffer#completor'),
\ 'config': {
\ 'max_buffer_size': 5000000,
\ },
\ }))
au User asyncomplete_setup call asyncomplete#register_source({
\ 'name': 'dictionary',
\ 'allowlist': ['*'],
\ 'completor': function('asyncomplete#sources#dictionary#completor'),
\ })
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#around#get_source_options({
\ 'name': 'around',
\ 'allowlist': ['*'],
\ 'priority': 10,
\ 'completor': function('asyncomplete#sources#around#completor'),
\ }))
" other -------------------------------------------------------------
nmap <Leader>l :call ExecuteThisLineCMD()<CR>
function! ExecuteThisLineCMD()
execute('bo terminal ++shell eval ' . getline('.'))
endfunction
nmap <Leader>n :Necronomicon
command! -nargs=* Necronomicon call Necronomicon(<f-args>)
function! Necronomicon(...) abort
if a:0 == 0
e ~/.uranometria/necronomicon.md
return
elseif a:0 == 1 && a:1 == 'YogSothoth'
call execute('!sh ~/.uranometria/forge/backup.sh', '')
return
elseif a:0 == 2 && a:1 == 'Azathoth' && a:2 == 'kill'
bo terminal ++shell ++close sh ~/.uranometria/forge/kill.sh
smile
return
elseif a:0 == 1 && a:1 == 'Azathoth'
bo terminal ++shell ++close sh ~/.uranometria/forge/omnibus.sh
smile
return
endif
endfunction
EOF
cp -f ~/.vimrc ~/.uranometria/forge/
echo ">>> (6/7). MAKE ~/.uranometria/forge/snips/global.json (add write)"
cat - << "EOF" >> ~/.uranometria/forge/snips/global.json
{
"sni": {
"prefix": ["sni"],
"body": [",\"${1}\": {"
," \"prefix\": [\"${2}\"],"
," \"body\": [\"${3}\"]"
,"}"]
}
,"git_all_commit": {
"prefix": ["git_all_commit"],
"body": ["git add . && git commit -m '${1}' && git push"]
}
,"git_checkout_remote": {
"prefix": ["git_checkout_remote"],
"body": ["git fetch --all && git branch -r | grep ${1} | cut -d '/' -f 2 | xargs -t -I{} git checkout -b {} origin/{}"]
}
,"git_checkout_local": {
"prefix": ["git_checkout_local"],
"body": ["git branch | grep ${1} | xargs -t -I{} git checkout {}"]
}
,"plantuml": {
"prefix": ["pu"],
"body": ["@startuml"
,"|${1}|"
,"start"
,":${2};"
,"stop"]
}
}
EOF
echo ">>> (7/7). END"
echo "=========================================================="
ls -ail ~/.uranometria
アイコンをかっこよくしたい場合は以下もやる
おもたいよ
git clone --depth 1 https://github.com/ryanoasis/vim-devicons ~/.vim/pack/plugins/start/vim-devicons
# アイコン本体を導入
git clone --branch=master --depth 1 https://github.com/ryanoasis/nerd-fonts.git
cd nerd-fonts
./install.sh
cd ..
rm -fr nerd-fonts
以下old
vimマクロ設定
以下を記述してレジスタに登録 0"py$
※Ctrl+V Ctrl+Mで「^M」 (Enter) のように修正
※ダイアグラフで入力。置換だとコードで認識されて改行するので、全部手打ちする。
^M
はCtrl+k C R
^W
はCtrl+k E B
:Necronomicon^M:cd %:h^M:30Ve^M^Wl1gt:q^M
:Necronomicon^M:cd %:h^M:30Ve^M^Wl:tabe^M:Exp^M1gt:q^M
:vs^M:e ~/.uranometria/forge/snips/global.json^M^Wh
(おまけ)universal-ctagsインストール
インストールが必要なので注意すること
lspがあるならなくて良い
git clone --depth 1 https://github.com/universal-ctags/ctags.git
cd ctags
./autogen.sh
./configure --enable-iconv
make
# sudo make install
ctags --version
ctags -R