目次

コマンド

ノーマルモードでよく使用するコマンド

コマンド説明
dd1行切り取り
NddN行切り取り
yy1行コピー
NyyN行コピー
p貼り付け
diwカーソル位置の単語を削除 ( delete inner word )
ci(()の中身を消して入力可能にする
yi"ダブルクォーテーションの中身をコピー
qaマクロaの記録開始
qマクロの記録終了
@aマクロaの実行
10@aマクロaを10回実行
gdカーソル位置のキーワードを検索(関数内)
gDカーソル位置のキーワードを検索(ファイル内)

Exコマンドなど

コマンド説明
:vert terminal垂直分割してターミナルを起動
:bo terminal水平分割して最下部にターミナルを起動
:top terminal水平分割して最上部にターミナルを起動
:sp ウィンドウを垂直に分割
:vs ウィンドウを水平に分割
Ctrl + w + w 分割したウィンドウを間を移動
Ctrl + w + xウィンドウを次のウィンドウと入れ替える

プラグインマネージャ(vundle)インストール

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

※ .vimrc に以下の Vundle.vim の部分を記述後、:PluginInstall でインストール

~/.vimrc

"""""""""""""""""""""""""""""
" 表示設定
"""""""""""""""""""""""""""""

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"

パッケージマネージャインストール

ここでは dein.vim を利用する。
https://github.com/Shougo/dein.vim

curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh > installer.sh
sh ./installer.sh ~/.cache/dein

.vimrc

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>

作業用関数

find して vim する fvim 関数の定義例

.bashrc

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
}

トップ   差分 バックアップ リロード   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-09-06 (木) 00:47:04 (2057d)