Skip to content

Commit eccf570

Browse files
committed
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.
1 parent 3e14373 commit eccf570

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

autoload/startify.vim

+31-12
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,10 @@ function! startify#insane_in_the_membrane() abort
134134

135135
setlocal nomodifiable nomodified
136136

137-
nnoremap <buffer><silent> e :enew<cr>
138-
nnoremap <buffer><silent> i :enew <bar> startinsert<cr>
139-
nnoremap <buffer><silent> <insert> :enew <bar> startinsert<cr>
140-
nnoremap <buffer><silent> b :call <sid>set_mark('B')<cr>
141-
nnoremap <buffer><silent> s :call <sid>set_mark('S')<cr>
142-
nnoremap <buffer><silent> t :call <sid>set_mark('T')<cr>
143-
nnoremap <buffer><silent> v :call <sid>set_mark('V')<cr>
144-
nnoremap <buffer><silent> <cr> :call startify#open_buffers()<cr>
145-
nnoremap <buffer><silent> <2-LeftMouse> :execute 'normal' matchstr(getline('.'), '\w\+')<cr>
146-
nnoremap <buffer><silent> q :call <sid>close()<cr>
147-
137+
call s:set_mappings()
148138
call cursor(s:firstline + (s:show_special ? 2 : 0), 5)
149-
150139
autocmd startify CursorMoved <buffer> call s:set_cursor()
140+
151141
set filetype=startify
152142
silent! doautocmd <nomodeline> User Startified
153143
endfunction
@@ -556,6 +546,35 @@ function! s:set_cursor() abort
556546
call cursor(s:newline, 5)
557547
endfunction
558548

549+
" Function: s:set_mappings {{{1
550+
function! s:set_mappings() abort
551+
nnoremap <buffer><silent> e :enew<cr>
552+
nnoremap <buffer><silent> i :enew <bar> startinsert<cr>
553+
nnoremap <buffer><silent> <insert> :enew <bar> startinsert<cr>
554+
nnoremap <buffer><silent> b :call <sid>set_mark('B')<cr>
555+
nnoremap <buffer><silent> s :call <sid>set_mark('S')<cr>
556+
nnoremap <buffer><silent> t :call <sid>set_mark('T')<cr>
557+
nnoremap <buffer><silent> v :call <sid>set_mark('V')<cr>
558+
nnoremap <buffer><silent> <cr> :call startify#open_buffers()<cr>
559+
nnoremap <buffer><silent> <2-LeftMouse> :execute 'normal' matchstr(getline('.'), '\w\+')<cr>
560+
nnoremap <buffer><silent> q :call <sid>close()<cr>
561+
562+
" Prevent 'nnoremap j gj' mappings, since they would break navigation.
563+
" (One can't leave the [x].)
564+
if !empty(mapcheck('h', 'n'))
565+
nnoremap <buffer> h h
566+
endif
567+
if !empty(mapcheck('j', 'n'))
568+
nnoremap <buffer> j j
569+
endif
570+
if !empty(mapcheck('k', 'n'))
571+
nnoremap <buffer> k k
572+
endif
573+
if !empty(mapcheck('l', 'n'))
574+
nnoremap <buffer> l l
575+
endif
576+
endfunction
577+
559578
" Function: s:set_mark {{{1
560579
"
561580
" Markers are saved in the s:marked dict using the follow format:

0 commit comments

Comments
 (0)