فهرست منبع

Don't allow gj type mappings

Assuming a small screen and 'wrap' set:

The cursor is forced to stay in a certain column, so doing gj on a wrapped
line will jump into an area outside the position [x] and jump back into it
immediately effectively breaking navigation.

Solution: use local mappings that just do the usual h/j/k/l dance.

References #156.
Marco Hinz 10 سال پیش
والد
کامیت
eccf570aea
1فایلهای تغییر یافته به همراه31 افزوده شده و 12 حذف شده
  1. 31 12
      autoload/startify.vim

+ 31 - 12
autoload/startify.vim

@@ -134,20 +134,10 @@ function! startify#insane_in_the_membrane() abort
 
   setlocal nomodifiable nomodified
 
-  nnoremap <buffer><silent> e             :enew<cr>
-  nnoremap <buffer><silent> i             :enew <bar> startinsert<cr>
-  nnoremap <buffer><silent> <insert>      :enew <bar> startinsert<cr>
-  nnoremap <buffer><silent> b             :call <sid>set_mark('B')<cr>
-  nnoremap <buffer><silent> s             :call <sid>set_mark('S')<cr>
-  nnoremap <buffer><silent> t             :call <sid>set_mark('T')<cr>
-  nnoremap <buffer><silent> v             :call <sid>set_mark('V')<cr>
-  nnoremap <buffer><silent> <cr>          :call startify#open_buffers()<cr>
-  nnoremap <buffer><silent> <2-LeftMouse> :execute 'normal' matchstr(getline('.'), '\w\+')<cr>
-  nnoremap <buffer><silent> q             :call <sid>close()<cr>
-
+  call s:set_mappings()
   call cursor(s:firstline + (s:show_special ? 2 : 0), 5)
-
   autocmd startify CursorMoved <buffer> call s:set_cursor()
+
   set filetype=startify
   silent! doautocmd <nomodeline> User Startified
 endfunction
@@ -556,6 +546,35 @@ function! s:set_cursor() abort
   call cursor(s:newline, 5)
 endfunction
 
+" Function: s:set_mappings {{{1
+function! s:set_mappings() abort
+  nnoremap <buffer><silent> e             :enew<cr>
+  nnoremap <buffer><silent> i             :enew <bar> startinsert<cr>
+  nnoremap <buffer><silent> <insert>      :enew <bar> startinsert<cr>
+  nnoremap <buffer><silent> b             :call <sid>set_mark('B')<cr>
+  nnoremap <buffer><silent> s             :call <sid>set_mark('S')<cr>
+  nnoremap <buffer><silent> t             :call <sid>set_mark('T')<cr>
+  nnoremap <buffer><silent> v             :call <sid>set_mark('V')<cr>
+  nnoremap <buffer><silent> <cr>          :call startify#open_buffers()<cr>
+  nnoremap <buffer><silent> <2-LeftMouse> :execute 'normal' matchstr(getline('.'), '\w\+')<cr>
+  nnoremap <buffer><silent> q             :call <sid>close()<cr>
+
+  " Prevent 'nnoremap j gj' mappings, since they would break navigation.
+  " (One can't leave the [x].)
+  if !empty(mapcheck('h', 'n'))
+    nnoremap <buffer> h h
+  endif
+  if !empty(mapcheck('j', 'n'))
+    nnoremap <buffer> j j
+  endif
+  if !empty(mapcheck('k', 'n'))
+    nnoremap <buffer> k k
+  endif
+  if !empty(mapcheck('l', 'n'))
+    nnoremap <buffer> l l
+  endif
+endfunction
+
 " Function: s:set_mark {{{1
 "
 " Markers are saved in the s:marked dict using the follow format: