12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- " Basic cursor movement and deletion keybindings from emacs, for vim.
- map <C-f> <Right>
- map <C-b> <Left>
- map <C-e> <End>
- map <C-a> <Home>
-
- " insert mode
- imap <C-g> <ESC>
- imap <C-b> <Left>
- imap <C-f> <Right>
- imap <C-p> <Up>
- imap <C-n> <Down>
- imap <C-a> <C-o>:call <SID>home()<CR>
- imap <C-e> <End>
- imap <C-d> <Del>
- imap <C-h> <BS>
- imap <C-k> <C-r>=<SID>kill_line()<CR>
-
- " visual mode
- vmap <C-p> <Up>
- vmap <C-n> <Down>
- vmap <C-b> <Left>
- vmap <C-f> <Right>
-
-
- " command line mode
- cmap <C-p> <Up>
- cmap <C-n> <Down>
- cmap <C-b> <Left>
- cmap <C-f> <Right>
- cmap <C-a> <Home>
- cmap <C-e> <End>
- cnoremap <C-d> <Del>
- cnoremap <C-h> <BS>
- cnoremap <C-k> <C-f>D<C-c><C-c>:<Up>
-
- function! s:home()
- let start_col = col('.')
- normal! ^
- if col('.') == start_col
- normal! 0
- endif
- return ''
- endfunction
-
- function! s:kill_line()
- let [text_before_cursor, text_after_cursor] = s:split_line_text_at_cursor()
- if len(text_after_cursor) == 0
- normal! J
- else
- call setline(line('.'), text_before_cursor)
- endif
- return ''
- endfunction
-
- function! s:split_line_text_at_cursor()
- let line_text = getline(line('.'))
- let text_after_cursor = line_text[col('.')-1 :]
- let text_before_cursor = (col('.') > 1) ? line_text[: col('.')-2] : ''
- return [text_before_cursor, text_after_cursor]
- endfunction
|