I know by t{char} I can move the cursor before the next occurrence of the {char}. but I want to find a way to move cursor after the next occurrence of a character.
Is there any native way?
No, this family of command is limited to fFtT and ,; to repeat.
But you can always do fxl to jump to the next x and move the cursor one character to the right.
Related
How to delete till the first character of the line ? In the line below, for example, with the cursor near the end as indicated, delete backwards until the first $.
I have this line:
[space][space][space]$entity->setPositionBrand(count($qb->getResult())[my_cursor_here] + 1);
After deletion, I want this:
[space][space][space] + 1);
There is a standard vim motion that goes exactly to the first non-whitespace character on the line. It's ^
So you only need to type d^.
Obviously not as succinct as Vladimir's answer (which is a better solution), but for the record, here's how you could achieve the same with visual mode.
v0wx
v Enter visual mode.
0 Move to the beginning of the line.
w Move to first word.
x delete characters in visual selection.
Any amount of whitespace counts as a word.
If you want a general solution, you would probably need some sort of regex-based keybinding. But, you can accomplish what you want with these key combinations:
Put your cursor on the first $ sign.
d 12 e
The second key sequence deletes characters from the position of your cursor up to the end of the twelfth word, which will result in exactly the line you want.
In Vim, is there a key moving cursor to the beginning of the next line?
j moves the cursor to the corresponding position of the current position in the next line. I'm looking for a single key that could move the cursor to position 0 irrespective of the cursor position in the current line.
The + motion moves to the first non-blank character in the next ([count]) line. That fulfills your requirement if there's no indent. With indent, you can use +0 or j0.
You can move to the beginning of a line by pressing +
That just moves to the first non-blank character at the beginning of the line, which is fine if there is no indentation. If you want to go to the first character in the line regardless of white space, you can do j0
If you need any more help with movement keys, this is a good resource:
http://vim.wikia.com/wiki/Moving_around
Are there any commands in Vim/Vi to move within a selected search segment?
For instance, if I search for a word, are there any commands to motion the cursor to the end of the highlighted segment? Say I have a word, "FishTaco" and I want to search for all instances of "Fish" and insert something after it. I know I could do a global replace, but what if I want to only make the change in a couple non-sequential instances?
I could see where it would be convenient to be able to motion the cursor to the end of the current highlighted segment to perform an action.
You can do it with this:
/Fish/e
The /e at the end lands your cursor at the end of the search region (instead of the first character by default.
If you just want to place your cursor after the last character of Fish then you could use
/Fish/e+1
which will place your cursor after the h. (Without the +1 the cursor will end up to the left of the last character.)
If you are particularly interested in placing the cursor after Fish, but only when it appears in "FishTaco" then you can try one of the following options:
You can use
/FishTaco/s+4
and your cursor will end up between Fish and Taco. The /s+4 places the cursor 4 places after the start of the search term.
You could likewise use
/FishTaco/e-3
which will place your cursor 3 places left of the left side of the last (end) character.
You can also use
/FishTaco/b+4
because /b+4 will be treated as /s+4.
If you have already searched for /Fish, you can quickly change the search to go to the end of the match via //e, which repeats the last search, but appends the e modifier that has already been explained.
Once you have a visual selection, you can use o to toggle the cursor position between the start and end of the selected block. When the selection is line-wise this toggles the line position, meaning the cursor moves to the starting and ending line of the selection but not to the starting or ending character. When the selection is character-wise then the movement is also character-wise.
You can also use `< and `> to toggle the cursor between the start and end of the visual block, however this affects the selection itself, so it is used to reset or adjust the selection bounds.
Edit: Ah, but for search highlights this won't work, because o will initiate a line insertion. I guess search highlight isn't the same as a visual selection, sorry :)
/ long-regexp1 \zs long-regexp2 / .. cursor will stop at \zs, see :help \zs
The "cursor at the end of the match" part of your question is already answered.
You can do :%s/Fish/FishTaco/c. This gives you an opportunity to confirm or reject every substitution and skip the whole "cursor at the end of the match" business.
Observe a line in a Vim instance:
Now I hit $:
Why does my cursor not go all the way to the end? Once I try inserting, the text gets inserted before the last character! Even if I try to move right again while still in normal mode I get the bell. Oddly, when in edit mode I can move to the actual end of line with the right arrow key!
Does anyone know why Vim does this? On 7.3 by the way. Thanks for the help.
Pressing $ while in command mode causes the cursor to move to the end of the line, effectively highlighting the last character. Hit i here to insert before the last character, or a to append to the line. It is slightly ambiguous here, because you're using a pipe character as a cursor rather than a rectangular block cursor. Have a look at ":help termcap-cursor-shape" if you want to change that.
If the goal is to append to the end of the line, A will jump to the end of the line and enter insert mode with a single keypress.
Use a to append a character after the current.
Or, to go to the end of the line and append in 1 step, use capital A. I.e. shiftA.
Similarly shift-I to insert at the beginning of the line without first having to press ^.
The cursor can't be between two characters, it is always on a character.
If you press $ then x, you will correctly delete the last printable character of the current line.
What you are observing is the fact that using i, you are always inserting your text before the selected character. If you want to insert after the selected character, you have to use a or better A as it has already been mentioned.
In other words:
i means "insert before character under cursor".
a means "insert after character under cursor".
mnemonic for a : a for "append".
Suppose I'm in a certain line position in vim and I want to delete up to a certain character, say a semicolon. I would do df; except it would also delete the semicolon. Is there a command that will do the same thing but will not include the character I'm searching for?
Yes, dt;. From the Vim docs:
t{char}
Till before [count]'th occurrence of {char} to the right. The cursor is placed on the character left of {char} |inclusive|. {char} can be entered like with the |f| command.
To add to what Michal said, you can also use T and F to do the same thing backwards.
Also ; will repeat the last t,T,f or F motion, and ' will repeat it in the opposite direction.