Skip to content

Commit ebd410b

Browse files
committed
Merge pull request spf13#550 from lukedomanski/3.0
Fixing d$ not deleting last character of the line after wrap relative motion code was replaced
2 parents ce0d5ce + 4122da2 commit ebd410b

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

.vimrc

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -263,33 +263,44 @@
263263
noremap j gj
264264
noremap k gk
265265
266-
" Same for 0, home, end, etc
267-
function! WrapRelativeMotion(key, ...)
268-
let vis_sel=""
269-
if a:0
270-
let vis_sel="gv"
271-
endif
272-
if &wrap
273-
execute "normal!" vis_sel . "g" . a:key
274-
else
275-
execute "normal!" vis_sel . a:key
276-
endif
277-
endfunction
266+
" End/Start of line motion keys act relative to row/wrap width in the
267+
" presence of `:set wrap`, and relative to line for `:set nowrap`.
268+
" Default vim behaviour is to act relative to text line in both cases
269+
" If you prefer the default behaviour, add the following to your
270+
" .vimrc.before.local file:
271+
" let g:spf13_no_wrapRelMotion = 1
272+
if !exists('g:spf13_no_wrapRelMotion')
273+
" Same for 0, home, end, etc
274+
function! WrapRelativeMotion(key, ...)
275+
let vis_sel=""
276+
if a:0
277+
let vis_sel="gv"
278+
endif
279+
if &wrap
280+
execute "normal!" vis_sel . "g" . a:key
281+
else
282+
execute "normal!" vis_sel . a:key
283+
endif
284+
endfunction
278285

279-
" Map g* keys in Normal, Operator-pending, and Visual+select (over written
280-
" below) modes
281-
noremap $ :call WrapRelativeMotion("$")<CR>
282-
noremap <End> :call WrapRelativeMotion("$")<CR>
283-
noremap 0 :call WrapRelativeMotion("0")<CR>
284-
noremap <Home> :call WrapRelativeMotion("0")<CR>
285-
noremap ^ :call WrapRelativeMotion("^")<CR>
286-
" Over write the Visual+Select mode mappings to ensure correct mode is
287-
" passed to WrapRelativeMotion
288-
vnoremap $ :<C-U>call WrapRelativeMotion("$", 1)<CR>
289-
vnoremap <End> :<C-U>call WrapRelativeMotion("$", 1)<CR>
290-
vnoremap 0 :<C-U>call WrapRelativeMotion("0", 1)<CR>
291-
vnoremap <Home> :<C-U>call WrapRelativeMotion("0", 1)<CR>
292-
vnoremap ^ :<C-U>call WrapRelativeMotion("^", 1)<CR>
286+
" Map g* keys in Normal, Operator-pending, and Visual+select
287+
noremap $ :call WrapRelativeMotion("$")<CR>
288+
noremap <End> :call WrapRelativeMotion("$")<CR>
289+
noremap 0 :call WrapRelativeMotion("0")<CR>
290+
noremap <Home> :call WrapRelativeMotion("0")<CR>
291+
noremap ^ :call WrapRelativeMotion("^")<CR>
292+
" Overwrite the operator pending $/<End> mappings from above
293+
" to force inclusive motion with :execute normal!
294+
onoremap $ v:call WrapRelativeMotion("$")<CR>
295+
onoremap <End> v:call WrapRelativeMotion("$")<CR>
296+
" Overwrite the Visual+select mode mappings from above
297+
" to ensure the correct vis_sel flag is passed to function
298+
vnoremap $ :<C-U>call WrapRelativeMotion("$", 1)<CR>
299+
vnoremap <End> :<C-U>call WrapRelativeMotion("$", 1)<CR>
300+
vnoremap 0 :<C-U>call WrapRelativeMotion("0", 1)<CR>
301+
vnoremap <Home> :<C-U>call WrapRelativeMotion("0", 1)<CR>
302+
vnoremap ^ :<C-U>call WrapRelativeMotion("^", 1)<CR>
303+
endif
293304

294305
" The following two lines conflict with moving to top and
295306
" bottom of the screen

.vimrc.before

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
" Disable easier moving in tabs and windows
3535
" let g:spf13_no_easyWindows = 1
3636

37+
" Disable wrap relative motion for start/end line motions
38+
" let g:spf13_no_wrapRelMotion = 1
39+
3740
" Disable fast tab navigation
3841
" let g:spf13_no_fastTabs = 1
3942

0 commit comments

Comments
 (0)