LoginSignup
7

More than 5 years have passed since last update.

行頭 → 非空白行頭 → 行末 をローテートする

Last updated at Posted at 2012-08-26
" 行頭 → 非空白行頭 → 行末 をローテートする
function! s:rotate_in_line()
    let c = col('.')

    let cmd = c == 1 ? '^' : '$'
    execute "normal! ".cmd

    if c == col('.')
        if cmd == '^'
            normal! $
        else
            normal! 0
        endif
    endif
endfunction

" t に割り当て
nnoremap <silent>t :<C-u>call <SID>rotate_in_line()<CR>

この設定を .vimrc に書くと,t を押すたびに 行頭(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