I have this mapping in my .vimrc
file for swapping one line with the line above it.
:map <c-k> dd-P
It work just fine almost in any case except for two cases. when I select the first line I and press I expect nothing to happen and in that case if I manually do dd-P
the line will be removed and pasted again (so nothing happens) but if I press the line will be removed!(I guess it's because in that case -
will lead to an error message or something!
the other problem is when I'm at the last line of the file dd-P
will swap the last line with the two lines above it instead of only the last line above it. (Which is understandable but I want to find a workaround for it.)
So what I have in mind is to make vim do ddP
instead of dd-P
if the cursor is either at the first or the last line of the file.(or maybe just do nothing in case of the first line but I think this way I'll have fewer exceptions to make)
How can I get what I want?
Also it would be great if someone could tell me a way to make this swapping work smartly and automatically indent itself(I have a plugin that does thisone for me and I can simply call the plugin after that but I was just wondering what would the .vimrc
approach for this.)