LoginSignup
2
2

More than 5 years have passed since last update.

特定の文字を行末に追加して元のカーソル位置に戻る

Last updated at Posted at 2012-05-14

以下のスクリプトを利用すれば、例えばインサートモードで行末以外にカーソルがある時に、行末にセミコロンを付加し元のカーソル位置で入力を続けられる。

以下のスクリプトを保存し、コマンドを割り当てればインサートモードでshift+returnでセミコロンを付加出来る。

~/.vim/plugin/append_char.vim
function! AppendChar()
    :let pos = getpos(".")
    :let text = ";"
    :execute ":normal A".text
    :call setpos('.', pos)
:endfunction
~/.vimrc
inoremap <S-CR> <ESC>:call AppendChar()<CR>a
source ~/.vim/plugin/append_char.vim

これ、上記最終行のように.vimrc内でsourceを使ってファイルを呼び出さないと利用できないのですが
この記述無しで利用できる方法をどなたか教えて頂けないでしょうか。

2
2
1

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