LoginSignup
6
4

More than 5 years have passed since last update.

【Vim】マイコマンド

Last updated at Posted at 2017-01-20

概要

【Vim】環境設定の備忘録の続きという感じです。

Vimが最高に面白い理由、それは「好き放題コマンドを登録できるから」ではないでしょうか。
自動の括弧補完で他の総合環境?と同じように快適に出来るというのもまた嬉しい機能です。

そういった機能をそこら中で見つけて入れまくり(Qiitaは神)、また、自分で「これいいんじゃね?」と設定して使ってみたら快適だったりしたので、よかったら参考にして下さい。

アロー演算子のあたりは「俺天才かも」とか思いながら設定しました。
画面内移動もCtrlとhjklだけで超動けるので直感的に動けてオススメです。デフォルトでこれでいいのにと思うくらい使いやすいです。

(最終更新:20180109)

.vimrc

.vimrc

"***** MATO Settings *****"

" タブ分割した際の色
hi TabLineSel  term=bold cterm=bold,underline ctermfg=LightGray ctermbg=DarkBlue gui=bold,underline guifg=LightGray guibg=DarkBlue
hi TabLine term=reverse cterm=underline ctermfg=Black ctermfg=Gray ctermbg=black gui=underline guifg=Black guibg=gray
hi TabLineFill term=reverse cterm=reverse,bold ctermfg=LightGray ctermbg=black gui=reverse,bold guifg=LightGray guibg=black

" 現在行の番号を分かりやすく
set cursorline
hi clear CursorLine
hi CursorLineNr term=bold cterm=NONE ctermfg=darkgreen ctermbg=NONE

" カーソルの形
let &t_SI .= "\e[3 q"
let &t_EI .= "\e[1 q"

" オートインデントを有効にする
set autoindent
set smartindent

" 記録するコマンド数
set history=2000

" ファイルを開く時にリスト表示
set wildmenu wildmode=list:full


"***** INOREMAP *****"

" カッコの自動補完
inoremap { {}<Left>
inoremap ( ()<Left>
inoremap [ []<Left>
inoremap < <><Left>
inoremap ' ''<Left>
inoremap " ""<Left>
" 改行した時も
inoremap {<CR> {<CR>}<Esc><S-o>
inoremap (<CR> (<CR>)<Esc><S-o><TAB>
inoremap [<CR> [<CR>]<Esc><S-o><TAB>
inoremap <<CR> <<CR>><Esc><S-o><TAB>
" 中に文字がいらない時も当然ある
inoremap "" ""
inoremap '' ''
inoremap () ()
inoremap [] []
inoremap {} {}
inoremap <> <>

" PHPのアロー演算子
inoremap -^ ->
inoremap =~ =>

" HTML&CSSなどのコメント
inoremap <!- <!--  --><Left><Left><Left><Left>
inoremap <!! <!--  --><Left><Left><Left><Left>
inoremap /* /*  */<Left><Left><Left>
inoremap /*<CR> /*<Esc>o*/<Esc><Up>o<TAB>
"inoremap /*<CR> /*<Esc>o*/<Esc><Up><S-a> <Esc>

" インサートモードでjjを<Esc>にする
inoremap <silent> jj <Esc>

"***** NNOREMAP *****"

" undo & redo  ただのrでredoする
nnoremap r <C-r>

" daw : delete a word カーソル位置の単語を削除(神)
nnoremap da daw
nnoremap ca caw

" ci'で''で囲まれた部分を削除してインサートモード
nnoremap cii ci'
nnoremap cio ci"

" 行内での先頭、末尾までの削除
nnoremap dh d0
nnoremap dl d$

" <br>を多用するので登録しちゃう
nnoremap <B A<br><Esc>==

" TAB分割
" sなんとかだと操作しやすいらしいので、sだけを無効化してコマンド登録
nnoremap s <Nop>
" 新しいTAB、次TAB、前TAB
nnoremap st :<C-u>tabnew<CR>
nnoremap sn gt
nnoremap sp gT

" 画面内移動するのに覚えやすいように登録
nnoremap <C-j> <C-d>
nnoremap <C-k> <C-u>
nnoremap <S-j> <C-f>
nnoremap <S-k> <C-b>
nnoremap <C-h> ^
nnoremap <C-l> $

" 検索した後のハイライトを消すやつ
nnoremap <Esc><Esc> :nohlsearch<CR>

" xでの削除でヤンクが上書きされないように
noremap PP "0p
noremap x "_x

" 超多用するyypを短く
noremap yp yyp
noremap yyp yyp

" コメントアウト[// ]を入力モード入らず加えたい
noremap cm I// <Esc>

" 末尾に ; セミコロンを入力モード入らず加えたい
noremap sm A;<Esc>

" 末尾に , カンマ
noremap sk A,<Esc>

" TAB挿入
noremap <C-t> i<TAB><Esc>

"***** COMMAND *****"

" コピペする際のやつを短く
command SP :set paste
command SNP :set nopaste


"***** Plugin *****"

" NeoBundle
set nocompatible
filetype plugin indent off

" 謎の修正
syntax on
hi Comment ctermfg=darkcyan

" カーソルを前回位置に
augroup vimrcEx
 au BufRead * if line("'\"") > 0 && line("'\"") <= line("$") |
 \ exe "normal g`\"" | endif
augroup END

以上です。

「実践Vim」っていう本を1年に1度くらい読んで機能を再確認しつつ、勝手にオリジナルコマンドを登録して快適にという感じで楽しみましょう!

ほんまVim大好き

終わり

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4