7
7

More than 5 years have passed since last update.

インサートモード移行時にインデントを行う[vim]

Posted at

症状

oOなどでインサートモードに入るとインデントが調整された位置にカーソルが移動するのに,空行でiを押してもインデントが調整されない

解法

" smart indent when entering insert mode with i on empty lines
function! IndentWithI()
    if len(getline('.')) == 0
        return "cc"
    else
        return "i"
    endif
endfunction
nnoremap <expr> i IndentWithI()

空行の場合はccで一行上のインデントを踏まえた位置にカーソルを移動.空行でなければ普通のiの動作

参考

http://stackoverflow.com/questions/3003393/vim-smart-indent-when-entering-insert-mode-on-blank-line
上サイトのanserを合わせてシンプルな解法になるようにしています.

7
7
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
7
7