Skip to main content
added 199 characters in body
Source Link
statox
  • 50.6k
  • 19
  • 153
  • 231

EDIT I didn't know the built-in features suggested by @Romainl in his answer: of course the -d and +d method should be prefered as it is way simpler than adding functions to your .vimrc

Maybe adding something like that to your .vimrc could be what you want:

function! DeleteOver()
   let save_cursor = getpos(".")
   normal k
   normal dd
   call setpos(".", save_cursor)
   normal k
endfunction

function! DeleteUnder()
   let save_cursor = getpos(".")
   normal j
   normal dd
   call setpos(".", save_cursor)
endfunction

These functions delete the line under or the line over the current one and go back to the position before the deletion.

For the function DeleteOver() we need to go up one line with normal k after the deletion because the deletion change the number of the original line which doesn't happend with DeleteUnder()

You can also add this to your .vimrc

nnoremap <Leader>d :call DeleteOver()<CR>
nnoremap <Leader>D :call DeleteUnder()<CR>

To create the mappings calling the functions.

Maybe adding something like that to your .vimrc could be what you want:

function! DeleteOver()
   let save_cursor = getpos(".")
   normal k
   normal dd
   call setpos(".", save_cursor)
   normal k
endfunction

function! DeleteUnder()
   let save_cursor = getpos(".")
   normal j
   normal dd
   call setpos(".", save_cursor)
endfunction

These functions delete the line under or the line over the current one and go back to the position before the deletion.

For the function DeleteOver() we need to go up one line with normal k after the deletion because the deletion change the number of the original line which doesn't happend with DeleteUnder()

You can also add this to your .vimrc

nnoremap <Leader>d :call DeleteOver()<CR>
nnoremap <Leader>D :call DeleteUnder()<CR>

To create the mappings calling the functions.

EDIT I didn't know the built-in features suggested by @Romainl in his answer: of course the -d and +d method should be prefered as it is way simpler than adding functions to your .vimrc

Maybe adding something like that to your .vimrc could be what you want:

function! DeleteOver()
   let save_cursor = getpos(".")
   normal k
   normal dd
   call setpos(".", save_cursor)
   normal k
endfunction

function! DeleteUnder()
   let save_cursor = getpos(".")
   normal j
   normal dd
   call setpos(".", save_cursor)
endfunction

These functions delete the line under or the line over the current one and go back to the position before the deletion.

For the function DeleteOver() we need to go up one line with normal k after the deletion because the deletion change the number of the original line which doesn't happend with DeleteUnder()

You can also add this to your .vimrc

nnoremap <Leader>d :call DeleteOver()<CR>
nnoremap <Leader>D :call DeleteUnder()<CR>

To create the mappings calling the functions.

Improve formatting
Source Link
statox
  • 50.6k
  • 19
  • 153
  • 231

Maybe addinadding something like that to your .vimrc could be what you want:

function! DeleteOver()
   let save_cursor = getpos(".")
   normal k
   normal dd
   call setpos(".", save_cursor)
   normal k
endfunction

nnoremap <Leader>d :call DeleteOver()<CR>

function! DeleteUnder()
   let save_cursor = getpos(".")
   normal j
   normal dd
   call setpos(".", save_cursor)
endfunction
 
nnoremap <Leader>D :call DeleteUnder()<CR>

TheThese functions delete the line under or the line over the current one and go back to the right position on the line and the mappings callsbefore the functionsdeletion.

For the function DeleteOver() we need to changego up one line with normal k after the deletion because the line we saved changed ofdeletion change the number withof the deletionoriginal line which doesn't happend with DeleteUnder()

You can also add this to your .vimrc

nnoremap <Leader>d :call DeleteOver()<CR>
nnoremap <Leader>D :call DeleteUnder()<CR>

To create the mappings calling the functions.

Maybe addin something like that to your .vimrc could be what you want:

function! DeleteOver()
   let save_cursor = getpos(".")
   normal k
   normal dd
   call setpos(".", save_cursor)
   normal k
endfunction

nnoremap <Leader>d :call DeleteOver()<CR>

function! DeleteUnder()
   let save_cursor = getpos(".")
   normal j
   normal dd
   call setpos(".", save_cursor)
endfunction
 
nnoremap <Leader>D :call DeleteUnder()<CR>

The functions delete the line under or over the current one and go back to the right position on the line and the mappings calls the functions.

For the function DeleteOver() we need to change line because the line we saved changed of number with the deletion which doesn't happend with DeleteUnder()

Maybe adding something like that to your .vimrc could be what you want:

function! DeleteOver()
   let save_cursor = getpos(".")
   normal k
   normal dd
   call setpos(".", save_cursor)
   normal k
endfunction

function! DeleteUnder()
   let save_cursor = getpos(".")
   normal j
   normal dd
   call setpos(".", save_cursor)
endfunction

These functions delete the line under or the line over the current one and go back to the position before the deletion.

For the function DeleteOver() we need to go up one line with normal k after the deletion because the deletion change the number of the original line which doesn't happend with DeleteUnder()

You can also add this to your .vimrc

nnoremap <Leader>d :call DeleteOver()<CR>
nnoremap <Leader>D :call DeleteUnder()<CR>

To create the mappings calling the functions.

Correction
Source Link
statox
  • 50.6k
  • 19
  • 153
  • 231

Maybe addin something like that to your .vimrc could be what you want:

function! DeleteOver()
   let save_cursor = getpos(".")
   normal k
   normal dd
   call setpos('".'", save_cursor)
   normal k
endfunction

nnoremap <Leader>d :call DeleteOver()<CR>

function! DeleteUnder()
   let save_cursor = getpos(".")
   normal j
   normal dd
   call setpos('".'", save_cursor)
   normal j
endfunction

nnoremap <Leader>D :call DeleteUnder()<CR>

The functions delete the line under or over the current one and go back to the right position on the line and the mappings calls the functions.

For the function DeleteOver() we need to change line because the line we saved changed of number with the deletion which doesn't happend with DeleteUnder()

Maybe addin something like that to your .vimrc could be what you want:

function! DeleteOver()
   let save_cursor = getpos(".")
   normal k
   normal dd
   call setpos('.', save_cursor)
   normal k
endfunction

nnoremap <Leader>d :call DeleteOver()<CR>

function! DeleteUnder()
   let save_cursor = getpos(".")
   normal j
   normal dd
   call setpos('.', save_cursor)
   normal j
endfunction

nnoremap <Leader>D :call DeleteUnder()<CR>

The functions delete the line under or over the current one and go back to the right position on the line and the mappings calls the functions.

Maybe addin something like that to your .vimrc could be what you want:

function! DeleteOver()
   let save_cursor = getpos(".")
   normal k
   normal dd
   call setpos(".", save_cursor)
   normal k
endfunction

nnoremap <Leader>d :call DeleteOver()<CR>

function! DeleteUnder()
   let save_cursor = getpos(".")
   normal j
   normal dd
   call setpos(".", save_cursor)
endfunction

nnoremap <Leader>D :call DeleteUnder()<CR>

The functions delete the line under or over the current one and go back to the right position on the line and the mappings calls the functions.

For the function DeleteOver() we need to change line because the line we saved changed of number with the deletion which doesn't happend with DeleteUnder()

Post Undeleted by statox
Post Deleted by statox
Source Link
statox
  • 50.6k
  • 19
  • 153
  • 231
Loading