You are not logged in.
Pages: 1
This might sound really stupid, but how do you delete a line-break in Vim? Deleting the EOL after the cursor, when you're at the end of a line seems to be 'dw', as that will delete to the next word, therefore deleting the EOL in the middle of it. However, deleting the EOL before the cursor, when you're at the start of a line I can't figure out. 'db' would delete the EOL, but would also delete to the beginning of the word at the end of the line previous. The only way I've found I've been able to use is entering Insert mode and pressing Backspace. Surely this isn't the best method for doing this...
Offline
I'm not sure what you mean, but have you tried shift-j?
ᶘ ᵒᴥᵒᶅ
Offline
I'm also not sure what you mean. I interpreted two possible questions from this:
1) You're mistaking whitespace at the end of the line for the newline itself. Try ":set list" to see non-printing characters.
2) You want to delete the newline at the end of a file. I've never wanted to do this myself so I don't know, but I found a couple of suggestions here:
http://stackoverflow.com/questions/4133 … ine-or-eof
Last edited by cmtptr (2011-01-23 23:05:48)
Offline
I'm not sure what you mean, but have you tried shift-j?
It will merge this line and the next one, not this one and the previous one.
The underline "_" is your cursor. You have:
1
2
and you want
12
If you have
1
2
then Shift+j will do the trick.
Last edited by karol (2011-01-23 23:21:51)
Offline
litemotiv wrote:I'm not sure what you mean, but have you tried shift-j?
It will merge this line and the next one, not this one and the previous one.
The underline "_" is your cursor. You have:
1
2and you want
12
If you have
1
2then Shift+j will do the trick.
Not to hijack the thread, but is there a way to do this so that it adds no space?
Offline
is there a way to do this so that it adds no space?
I don't know any such way, but you can always create a custom command / macro / mapping.
Offline
>> Not to hijack the thread, but is there a way to do this so that it adds no space?
:j!
(read the fine help :help J would have told you that)
Offline
>> Not to hijack the thread, but is there a way to do this so that it adds no space?
:j!
(read the fine help :help J would have told you that)
Or use
<count>gJ
to join <count> lines (count can be negative in order to join lines upward). Or use visual mode with gJ.
Vim does not use the concept of deleting end of line characters but instead joins lines.
And it is all in :help J or :help join.
Last edited by bernarcher (2011-01-24 21:22:26)
To know or not to know ...
... the questions remain forever.
Offline
I don't think any of those does what OP wanted - joining upwards.
@ bernarcher
I can't get the negative numbers to work. The manual says only
gJ Join [count] lines, with a minimum of two lines.
Don't insert or remove any spaces. {not in Vi}
Does e.g. '-3gJ' really works for you? Maybe I have some weird settings in my .vimrc.
EDIT: I was thinking about something like
map II i<Backspace><Esc>
Of course you can change the 'II' mapping and maybe add '0':
map II i<Backspace><Esc>0
or whatever tells vim to go to the first char of the line.
'[ count ]II' won't work.
Last edited by karol (2011-01-24 21:43:05)
Offline
@ bernarcher
I can't get the negative numbers to work. The manual says onlygJ Join [count] lines, with a minimum of two lines. Don't insert or remove any spaces. {not in Vi}
Does e.g. '-3gJ' really works for you? Maybe I have some weird settings in my .vimrc
I tested it. At least I thought so. But trying again, negative counts appear not to work as wanted.
It is because the "-" effectively moves the cursor up a line.
But backwards joining still is possible. To join n lines backwards this should work:
<n-1>-<n>gJ
where <n>, <n-1> are the counts (without the brackets of course).
To know or not to know ...
... the questions remain forever.
Offline
I tested it. At least I thought so. But trying again, negative counts appear not to work as wanted.
It is because the "-" effectively moves the cursor up a line.
Exactly.
'gJ' is great too, as you (well, at least I) usually move top to bottom.
Offline
Pages: 1