aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2020-12-16 01:33:03 +0800
committerjdhao <jdhao@hotmail.com>2020-12-16 01:33:03 +0800
commiteb0c63c1758bc7257e278480c824d2a68af77974 (patch)
tree40e6cf52887df9468ee7a6920928da9331beae62
parentc3cdad554ba848552014415362f2029319d85dbf (diff)
Make a plugin for leaving insert mode
-rw-r--r--autoload/utils.vim30
-rw-r--r--core/mappings.vim3
-rw-r--r--core/plugins.vim1
3 files changed, 1 insertions, 33 deletions
diff --git a/autoload/utils.vim b/autoload/utils.vim
index 4bab8b9..c0eab5f 100644
--- a/autoload/utils.vim
+++ b/autoload/utils.vim
@@ -145,33 +145,3 @@ function! utils#Get_titlestr() abort
return l:title_str
endfunction
-
-function! utils#EscapeInsertOrNot() abort
- " If k is preceded by j, then remove j and go to normal mode.
- let line_text = getline('.')
- let cur_ch_idx = utils#CursorCharIdx()
- let pre_char = utils#CharAtIdx(line_text, cur_ch_idx-1)
- if pre_char ==# 'j'
- return "\<BS>\<ESC>"
- else
- return 'k'
- endif
-endfunction
-
-function! utils#CharAtIdx(str, idx) abort
- " Get char at idx from str. Note that this is based on character index
- " instead of the byte index.
- return strcharpart(a:str, a:idx, 1)
-endfunction
-
-function! utils#CursorCharIdx() abort
- " See https://vi.stackexchange.com/a/28144/15292
- " A more concise way to get character index under cursor.
- let cursor_byte_idx = col('.')
- if cursor_byte_idx == 1
- return 0
- endif
-
- let pre_cursor_text = getline('.')[:col('.')-2]
- return strchars(pre_cursor_text)
-endfunction
diff --git a/core/mappings.vim b/core/mappings.vim
index ee51d53..a7c76c9 100644
--- a/core/mappings.vim
+++ b/core/mappings.vim
@@ -8,9 +8,6 @@ xnoremap ; :
" Quicker way to open command window
nnoremap q; q:
-" Quicker <Esc> in insert mode
-inoremap <expr> k utils#EscapeInsertOrNot()
-
" Turn the word under cursor to upper case
inoremap <c-u> <Esc>viwUea
diff --git a/core/plugins.vim b/core/plugins.vim
index 91bb736..a4f81db 100644
--- a/core/plugins.vim
+++ b/core/plugins.vim
@@ -162,6 +162,7 @@ Plug 'tpope/vim-repeat'
" Show the content of register in preview window
" Plug 'junegunn/vim-peekaboo'
+Plug 'jdhao/better-escape.vim'
"}}
"{{ Linting, formating