I was going through Lesson 5 in vimtutor, and I had selected a part of lesson 5.3 in visual mode, and then done :w TEST as instructed in lesson 5.3.
In Lesson 5.4 however, I was told to do :r TEST, and so I did do that.
The text from the file TEST was indeed pasted right in to where I had the cursor.
However, when I tried to press the j key to move down further, something weird happened. The line after which I had my cursor on came up to the line I was working on (both these lines were from the pasted text from TEST file), the apparent line break gone.
Eg.
line before I press j
another line
became
line before I press janother line
for some reason.
What I've tried:
pressing Esc. This results in literally nothing happening
looking up Lesson 5.4 and read function of vimtutor and vim in Google and see if others had had this error. Nothing relevant came up.
Anyway, thanks for the help in advance!
Sounds like you hit J which does a « join » on the two lines.
Check your shift key/caps lock.
Related
How can we use vim to delete characters from the beginning of the line till the cursor.
Say, we have a string "hello world" while the cursor is on "w". How can we delete from "h" till "w".
Try d0. 0 denotes the beginning of the line.
I believe that the following should work (d^):
d^
This assumes that you only want to delete to the h even if there is white space in front of it. It will leave the white space.
TLDR:
The easiest way is to do the following
use the navigate mode
set the cursor at whatever line you want
press dgg - this will remove everything from cursor to the beginning
press dG - this will remove all the lines from cursor till the end of the doc.
But why?
gg - goes to the begin of the document
G - navigates at its very end
d - delete mode
I was also looking for some combinations with the notation of d and line number, and when you are editing huge files like GB in size I found it bit annoying.
Like to remove first 3 lines you need to do this :0,d3, but when the docu is over 1mln lines its tough for my eyes to read this crap...
The other suggestions didn't work for me, but I used visual mode to achieve this.
I moved the cursor to the position I wanted to delete through, and hit v to enter visual mode. Then I hit ^ to select back to the beginning of the current line, and then d to delete all of the highlighted text.
If you're in insert mode and you want to delete to the start of the line (and stay in insert mode), you can use CTRL+u
This matches the bash meaning of CTRL+u as shown here.
I don't know if this is undocumented or just a quirk of my setup (neovim on Ubuntu) but doing :help CTRL-U shows the help for the keystroke out of insert mode. Maybe someone can help me find the help which points to the usage I'm describing here.
not sure what happened but when I enter the d0, the line got deleted from my
cursor location to start of the line. – YouAreAwesome Dec 14 '17 at 6:43
Confirming that this worked. It seems to be the simplest method. (You can't upvote a comment, so I'm adding it as an answer in it's own right.)
Example: In .ssh/authorized_keys, I had:
no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user "centos" rather than the user "root".';echo;sleep 10" ssh-rsa AAAAB3NzaC1yc2...
This is the way Amazon AWS keeps you from logging in as root.
I put the cursor on the s in ssh-rsa and hit 'd0' and got a perfect delete to beginning of line.
Well, if your cursor is on "w", you'll be deleting backwards...
You can use vim's "till" t, but moving backwards it requires an uppercase T.
The same works for "find" f moving backwards it's F.
So, in your case, you can delete back "till" the quote symbol:
dT"
Or, if to prefer targeting/finding the "h":
dFh
Try jumping around first without the delete to get a feel for it, then you can just layer in the action as the prefix.
Happy Vimming! :)
Say that in the following paragraph my cursor lies on the first are in the first sentence (wish I could highlight it, but I can't so ...). Upon pressing ff twice that will get me to fools in the first sentence, and then to of. Further pressing it will get me nowhere.
Some people are confident because they are fools. Leonard had the look of
someone who was confident because, so far, he'd never found reason not to be. He
would step off a high building in the happy state of mind of someone who
intended to deal with the problem of the ground when it presented itself.
What would I need to modify so I can "move" across lines, so that further pressing ff will make Vim jump into the next lines?
Nothing to modify except Vim's source code. fFtT are linewise and there's nothing you can do about it. See :h left-right-motions
You could use /f, which is not limited to the current line, instead but it's not as fast as it requires another keypress.
Or a plugin like easymotion.
Did you know that you can hit ; to redo the previous fFtT?
There are a couple of solutions, but none do exactly what you want. Usually in this situation I would do ff followed by a series of ; characters to repeat f. When I reach the end of the line I hit + and then continue with ;. Similarly, you can use , to go backwards and 0<BS> to go back a line.
Another option is to write lines with set wrap and no hard breaks, but for various reasons users may not find that ideal.
Despite this seeming like nonsense it can actually be useful in some situations. For example, the :norm command will skip a line if ff doesn't find anything. You can use this for complex :norm commands over multiple lines to check for a particular character before you proceed with the command.
Edit:
There's a plugin that accomplishes this: https://github.com/dahu/vim-fanfingtastic
This is a most strange problem, which I only get it using GNU Screen and a Nokia N900. Under vi (both vim and nvi, it turns out) if I type in insert mode one<Enter>two I get
Mtwo
one
So, not only does <Enter> put an M at the beginning of the line, but actually it does something pretty weird in the meantime. Among other things, this issue doesn't let me save and exit.
Any thoughts? Thanks in advance.
POSSIBLE ANSWER: It turns out I wasn't the only one having this issue, which is gone (at least in our case) by simply adding term xterm to your .screenrc. Sorry for not doing a more thorough search before asking...
Your <Enter> is like a carriage return and linefeed (<CRLF>). That's ASCII 10, followed by ASCII 13 (which is the CTRL-M you see). The screen, however, isn't supporting it. Try to do:
export TERM=vt100
then run vi, etc or just
TERM=vt100 vi
which should fix the behavior (assuming you have vt100 terminal capabilities).
Lately I have been encountering a problem in VIM.
I use the shortcut >> (hold shift, press the period key twice) to indent a line. Sometimes I must be hitting something wrong because this shortcut stops working until I restart VIM.
Every time I try to indent with the shortcut it says "1 line >ed 1 time" instead of indenting. Or, if I have 3 lines selected and try to indent them all it will say: "3 lines >ed 1 time".
How do I fix this and restore the shortcut?
Thanks!
I have no idea, why your shortcut is not working, or what's the wrong key that you have pressed.
Regarding your 1 line >ed 1 time message: What you're doing is to shift a number of lines to the right. Vim is just notifying you about what was done, which is: One line is right-shifted one time. The > here is the right shift operator and >ed is just short for "shifted". If you do the opposite it says <ed, which is shifted to the left.
You can find more details in vim's help with: :help >
When a section is marked (visually marked) one > is sufficiant. The 2nd > should start another indentation, but since now nothing is marked it waits for another >.
More than this, I couldn't reproduce any error. (As it was mentioned by frosch03, the msg is just the normal response)
ed was an (well, probably still is) old editor, but I doubt that is what Vim is telling you. I cannot reproduce the message you're getting, nor find anything in the documentation regarding it.
Does this happen also when you're using a clean Vim (when you start it without vimrc with vim/gvim -u none)? If so, could you paste your vimrc if it's not too big somewhere (one of those paste sites should do nicely), so we can take a look to see is there any weird combo inside causing that behaviour.
Apart from that, not much advice I can offer regarding the given data :/
Smething just happened in the last 20 minutes or so to my vim. I must have hit something, but I can't figure it out, and nothing will get it back to the 'real' behaviour.
I've always used : to jump to a line number. Now, when I hit : then a number - (1-9), vim instead goes in to "insert" mode and inserts a letter. (1=q, 2=r, 3=s, 4=t, 5=w, etc.)
Trying to search around for this is worse than looking for a needle in a haystack!
Any ideas as to what sort of secret "mode" I've enabled? And better yet, how I might get back to normality?
Thanks!
Not sure what you've done there but you can also jump to a specific line number by entering the line number and then hitting G (Shift+g).
Shift+g on its own will take you to the last line of the file.
It could be your shell and not VIM. If restarting VIM doesn't fix your problem, try opening a new shell and using VIM there. If nothing works, move your .vimrc file and any shell start ups out of the way (by renaming, not deleting, of course), open a new shell, and VIM. If that doesn't work, try a new keyboard. :-(
Closing and opening vim should reset whatever you funky mode you've discovered. If not, you've got something profoundly weird going on -- vim doesn't store settings that are turned on while in the file.
BTW, you're totally ruining my "vim doesn't break" meme.
Well, I've no idea what it was, but rebooting the computer - Macbook running leopard - seemed to work.
I'd tried new shells to no effect. I just didn't want to have to reboot.
See - macs have problems too! :(
Thanks for all the quick responses from all y'all. Hopefully I won't have to figure that one out again.