An example (The ^ is the cursor position):

Before:

a bc def ghi
j k l mn o p q rs
      ^

After:

a bc def ghimn o p q rs
            ^

or at least:

a bc def ghimn o p q rs
           ^

I know I can use d0i<BS>, but I want a faster way to do this and I want to remain in the command mode. I am a beginner in vim and I think that maybe the answer is a modification of kA.

Thank you very much! :-)

  • 1
    If this is something you do frequently, you should consider writing your own mapping for it, maybe something like <Leader>dk. – Kyle Strand Oct 26 '15 at 23:31
up vote 8 down vote accepted

Try d0kJx

Deletes backwards to the beginning of the line, moves up, then joins the two lines and then removes the space in between the two joined lines.

You don't have to leave normal mode with this.

  • 2
    This is the only answer so far that (1) doesn't alter the search history or change the current highlighting and (2) doesn't delete the m. – Kyle Strand Oct 26 '15 at 23:32

Well, you can combine the "backward search" motion and the delete operator:

d?$<Enter>
  • In .vimrc I have this: set hlsearch and d?$<Enter> does what I asked but it also highlights all the line endings in the file so I have to type :noh after that to remove the highlight. Is there a way to avoid this? Thank you! :-) – silviubogan Oct 26 '15 at 16:30
  • 1
    There probably is, what I do is simply "overload" <C-l> in normal mode: nnoremap <silent><C-l> :nohlsearch<cr>:set nolist<cr>:redraw!<cr>, then use it when needed (i.e. in cases such as the above). – VanLaser Oct 26 '15 at 16:34

With visual mode: hvk$d

Explanation
h - Move one to the left
v - Start visual mode
k$ - Move to the end of the previous line
d - Delete selection

  • With cursor on m, maybe hvk$d ? (to avoid selecting it) – VanLaser Oct 26 '15 at 23:08
  • 1
    Ah, yes. Updating now. – Karl Yngve Lervåg Oct 27 '15 at 6:57

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.