Skip to content

Commit 6621cff

Browse files
committed
Merge pull request spf13#513 from lukedomanski/3.0
Changed g* wrap relative mappings to revert to standard behaviour under nowrap
2 parents bf5ebce + ec8d76c commit 6621cff

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

.vimrc

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,32 @@
252252
noremap k gk
253253
254254
" Same for 0, home, end, etc
255-
noremap $ g$
256-
noremap <End> g<End>
257-
noremap 0 g0
258-
noremap <Home> g<Home>
259-
noremap ^ g^
255+
function! WrapRelativeMotion(key, ...)
256+
let vis_sel=""
257+
if a:0
258+
let vis_sel="gv"
259+
endif
260+
if &wrap
261+
execute "normal!" vis_sel . "g" . a:key
262+
else
263+
execute "normal!" vis_sel . a:key
264+
endif
265+
endfunction
266+
267+
" Map g* keys in Normal, Operator-pending, and Visual+select (over written
268+
" below) modes
269+
noremap $ :call WrapRelativeMotion("$")<CR>
270+
noremap <End> :call WrapRelativeMotion("$")<CR>
271+
noremap 0 :call WrapRelativeMotion("0")<CR>
272+
noremap <Home> :call WrapRelativeMotion("0")<CR>
273+
noremap ^ :call WrapRelativeMotion("^")<CR>
274+
" Over write the Visual+Select mode mappings to ensure correct mode is
275+
" passed to WrapRelativeMotion
276+
vnoremap $ :<C-U>call WrapRelativeMotion("$", 1)<CR>
277+
vnoremap <End> :<C-U>call WrapRelativeMotion("$", 1)<CR>
278+
vnoremap 0 :<C-U>call WrapRelativeMotion("0", 1)<CR>
279+
vnoremap <Home> :<C-U>call WrapRelativeMotion("0", 1)<CR>
280+
vnoremap ^ :<C-U>call WrapRelativeMotion("^", 1)<CR>
260281
261282
" The following two lines conflict with moving to top and
262283
" bottom of the screen

0 commit comments

Comments
 (0)