From 18ee6115e1216d23dc16157269c626c92d7d5b34 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Fri, 23 Dec 2016 18:26:53 -0700 Subject: Update the new fad of getting out of h, j. k, l --- plugin/vim-options.vim | 55 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) (limited to 'plugin') diff --git a/plugin/vim-options.vim b/plugin/vim-options.vim index 425d376..57b9c63 100644 --- a/plugin/vim-options.vim +++ b/plugin/vim-options.vim @@ -22,7 +22,7 @@ set wildignore=*/app/cache,*/vendor,*/env,*.pyc,*/venv " Ignore useless files set splitright " Horizontal Splits go to the right set splitbelow " Vertical Splits go underneath set incsearch " Move cursor to matched string -set hlsearch! " Turn off highlight search +set hlsearch " Turn off highlight search set sessionoptions+=tabpages,globals " Include tab names in sessions set backupdir-=. set backupdir+=. @@ -37,20 +37,65 @@ set statusline+=%2*\« set statusline+=%2*\ %=\ %l/%L\ (%02p%%)\ "Rownumber/total (%) "----------------------------------------------------------------------------------------------------------------------- +"----------------------------------------------------------------------------------------------------------------------- +" Basic movements (h, j, k, l) require a number prefix. Break bad habits +"----------------------------------------------------------------------------------------------------------------------- +function! DisableIfNonCounted(move) range + if v:count + return a:move + else + " You can make this do something annoying like: + " echoerr "Count required!" + " sleep 2 + return "" + endif +endfunction + +function! SetDisablingOfBasicMotionsIfNonCounted(on) + let keys_to_disable = get(g:, "keys_to_disable_if_not_preceded_by_count", ["j", "k", "l", "h"]) + if a:on + for key in keys_to_disable + execute "noremap " . key . " DisableIfNonCounted('" . key . "')" + endfor + let g:keys_to_disable_if_not_preceded_by_count = keys_to_disable + let g:is_non_counted_basic_motions_disabled = 1 + else + for key in keys_to_disable + try + execute "unmap " . key + catch /E31:/ + endtry + endfor + let g:is_non_counted_basic_motions_disabled = 0 + endif +endfunction + +function! ToggleDisablingOfBasicMotionsIfNonCounted() + let is_disabled = get(g:, "is_non_counted_basic_motions_disabled", 0) + if is_disabled + call SetDisablingOfBasicMotionsIfNonCounted(0) + else + call SetDisablingOfBasicMotionsIfNonCounted(1) + endif +endfunction + +command! ToggleDisablingOfNonCountedBasicMotions :call ToggleDisablingOfBasicMotionsIfNonCounted() +command! DisableNonCountedBasicMotions :call SetDisablingOfBasicMotionsIfNonCounted(1) +command! EnableNonCountedBasicMotions :call SetDisablingOfBasicMotionsIfNonCounted(0) + +DisableNonCountedBasicMotions "----------------------------------------------------------------------------------------------------------------------- " Custom Mappings "----------------------------------------------------------------------------------------------------------------------- +" Turn off syntax highlighting +nnoremap :noh " Hardcore Mode noremap noremap noremap noremap -noremap h -noremap j -noremap k -noremap l " Highlighting in vim leaves your cursor wherever you ended at :vmap y ygv " Formating a json file -- cgit v1.2.3