- 追加された行はこの色です。
- 削除された行はこの色です。
- Vimメモ へ行く。
#mynavi()
#setlinebreak(on);
* 目次 [#h4469f5b]
#contents
* コマンド [#ge99ef44]
#html(<div class="pl10">)
ノーマルモードでよく使用するコマンド
| コマンド | 説明 |h
| dd | 1行切り取り |
| '''N'''dd | '''N'''行切り取り |
| yy | 1行コピー |
| '''N'''yy | '''N'''行コピー |
| p | 貼り付け |
| diw | カーソル位置の単語を削除 ( delete inner word ) |
| ci( | ()の中身を消して入力可能にする |
| yi" | ダブルクォーテーションの中身をコピー |
| qa | マクロaの記録開始 |
| q | マクロの記録終了 |
| @a | マクロaの実行 |
| 10@a | マクロaを10回実行 |
| gd | カーソル位置のキーワードを検索(関数内) |
| gD | カーソル位置のキーワードを検索(ファイル内) |
Exコマンドなど
| コマンド | 説明 |h
| :vert terminal | 垂直分割してターミナルを起動 |
| :bo terminal | 水平分割して最下部にターミナルを起動 |
| :top terminal | 水平分割して最上部にターミナルを起動 |
| :sp | ウィンドウを垂直に分割 |
| :vs | ウィンドウを水平に分割 |
| Ctrl + w + w | 分割したウィンドウを間を移動 |
| Ctrl + w + x | ウィンドウを次のウィンドウと入れ替える |
#html(</div>)
* プラグインマネージャ(vundle)インストール [#t5988e7f]
#html(<div style="padding-left:10px;">)
#myterm2(){{
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
}}
※ .vimrc に以下の Vundle.vim の部分を記述後、:PluginInstall でインストール
#html(</div>)
* ~/.vimrc [#r93cb634]
#html(<div style="padding-left:10px;">)
#mycode2(){{
"""""""""""""""""""""""""""""
" 表示設定
"""""""""""""""""""""""""""""
syntax on
"set cursorline
"highlight Normal cterm=none ctermbg=black ctermfg=white
highlight cursorline term=reverse cterm=none ctermbg=gray ctermfg=white
highlight statusline cterm=none ctermbg=white ctermfg=blue
"highlight statusline cterm=none ctermbg=none ctermfg=none
set enc=utf-8
set fenc=utf-8
set fencs=utf-8,cp932,sjis,euc-jp
set title
set ignorecase
set smartcase
set wrapscan
set hlsearch
set incsearch
set number
set autoread
"set laststatus=2
"set statusline=%F%{'['.(&fenc!=''?&fenc:&enc).']['.&ff.']'}%=%l,%c
set ruler
set ts=4
" change tab space
set expandtab
set tabstop=4
set shiftwidth=4
if exists('&ambiwidth')
set ambiwidth=double
endif
let _curfile=expand("%:r")
if _curfile == 'Makefile'
set noexpandtab
endif
" Change Encoding Command
command! Utf8 edit ++enc=utf-8
command! Sjis edit ++enc=cp932
command! Cp932 edit ++enc=cp932
command! Win31j edit ++enc=cp932
" ヤンク可能な最大サイズ
set viminfo='20,\"500
" x で削除時にヤンクの内容を上書かない
noremap PP "0p
noremap x "_x
" 垂直分割してターミナルを起動
command! Vt vert term
" バックスペース機能
set backspace=indent,eol,start
"""""""""""""""""""""""""""""
" Jsonフォーマッタ
"""""""""""""""""""""""""""""
command! -nargs=? Jq call s:Jq(<f-args>)
function! s:Jq(...)
if 0 == a:0
let l:arg = "."
else
let l:arg = a:1
endif
execute "%! jq \"" . l:arg . "\""
endfunction
" Jq が利用できない時( python を利用する場合 )
command! Jq :execute '%!python -m json.tool'
\ | :execute '%!python -c "import re,sys;chr=__builtins__.__dict__.get(\"unichr\", chr);sys.stdout.write(re.sub(r\"\\u[0-9a-f]{4}\", lambda x: chr(int(\"0x\" + x.group(0)[2:], 16)), sys.stdin.read()))"'
\ | :%s/ \+$//ge
\ | :set ft=javascript
\ | :1
"""""""""""""""""""""""""""""
" キーバインド
"""""""""""""""""""""""""""""
" n1, n0 で行番号の表示有無を切り替える
noremap n0 :<C-u>set nonumber<Enter>
noremap n1 :<C-u>set number<Enter>
" html, div 入力
noremap html <insert><!doctype html><Enter><html lang="ja"><Enter><head><Enter><meta charset="utf-8"><Enter></head><Enter><body><Enter><Enter></body><Enter></html><UP><UP><Esc>
noremap div <insert><div id="" class="" style=""><Enter><Enter></div><UP><Esc>
" ファイル新規作成時の定型文自動挿入
autocmd BufNewFile *.php 0r $HOME/.vim/template/php.txt
autocmd BufNewFile *.html 0r $HOME/.vim/template/html.txt
"""""""""""""""""""""""""""""
" Vundle.vim
"""""""""""""""""""""""""""""
set nocompatible " be iMproved, required
filetype off " required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
call vundle#end() " required
filetype plugin indent on " required
"""""""""""""""""""""""""""""
" vim-airline
"""""""""""""""""""""""""""""
set laststatus=2
let g:airline#extensions#branch#enabled = 0
"let g:airline_powerline_fonts = 1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_symbols.space = "\ua0"
}}
#html(</div>)
* パッケージマネージャインストール [#yf7d00a9]
#html(<div style="padding-left:10px;">)
ここでは dein.vim を利用する。
https://github.com/Shougo/dein.vim
#myterm2(){{
curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh > installer.sh
sh ./installer.sh ~/.cache/dein
}}
.vimrc
#mycode2(){{
if &compatible
set nocompatible " Be iMproved
endif
" Required:
set runtimepath+=/xxxx/xxxx/.cache/dein/repos/github.com/Shougo/dein.vim
" Required:
call dein#begin('/xxxx/xxxx/.cache/dein')
" Let dein manage dein
" Required:
call dein#add('/xxxx/xxxx/.cache/dein/repos/github.com/Shougo/dein.vim')
" Add or remove your plugins here like this:
call dein#add('preservim/nerdtree')
call dein#add('Xuyuanp/nerdtree-git-plugin')
call dein#add('airblade/vim-gitgutter')
call dein#add('tpope/vim-fugitive')
" Required:
call dein#end()
" Required:
filetype plugin indent on
syntax enable
" If you want to install not installed plugins on startup.
if dein#check_install()
call dein#install()
endif
"
" NerdTree
"
"nnoremap <leader>n :NERDTreeFocus<CR>
nnoremap <C-n> :NERDTree<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
"nnoremap <C-f> :NERDTreeFind<CR>
}}
#html(</div>)
* 作業用関数 [#gcb7d3db]
#html(<div style="padding-left:10px;">)
find して vim する fvim 関数の定義例
.bashrc
#mycode2(python){{
fvim(){
if [ "$#" == "0" ]; then
echo "ファイル名を指定して下さい"
exit 1
fi
filename=$1
#files=`mdfind $filename -onlyin ./` # for Mac
files=`find ./ -name "*${filename}*" | grep -v -E "(.*class$|.pyc$)" | sed 's/^.\//./'`
cnt=`echo "$files" | wc -l | awk '{print $1}'`
if [ "$cnt" == "0" ]; then
echo ファイルが見つかりません
fi
if [ "$cnt" == "1" ]; then
vim "$files"
return 0
fi
echo "複数のファイルが見つかりました"
echo "$files" | awk '{ print NR" "$1 }'
echo -n "No: "
read no
while [ true ];
do
file=`echo "$files" | awk -v no=$no '{ if (no == NR) print $1; }'`
if [ -e "$file" ]; then
vim $file
return 0
elif [ "$no" == "q" ]; then
return 0
fi
done
}
}}
#html(</div>)