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
Related
In the Vim help a paragraph is defined as follows: "A paragraph begins AFTER each empty line..." This implies that the empty line is not part of the new paragraph but belongs either to the previous paragraph or is not part of any paragraph. However, the command } supposedly takes one "to the beginning of the next paragraph". Since this command positions the cursor ON the blank line this implies that the blank line does belong to the next paragraph. Otherwise, one would expect that the command } would position the cursor at the start of the text, and not before it on a blank line. How is one to account for this?
No, the blank line is not part of the paragraph. You could test this with dip
which will leave the empty lines alone.
} does not move to the next paragraph, it moves to the first position after a paragraph, which in your case is a newline.
It is a exclusive (:h exclusive) motion, which means, that it moves the cursor further than the block. If you use d} the newline will not be deleted.
I know g$ can be used to move the cursor to the last character of the screen line, but which operator can be used to move the cursor to the last non-blank character of the screen line?
g_ (g followed by underscore) moves to the last non-blank character of the screen line text line. (As pointed out by han pingtian in the comments).
To move to the last non-blank character of the screen line, there's no single operator that I could find, but you could combine g$ with ge to achieve this result: use g$ to go to the last character (blank or non-blank) of the screen line, then if the cursor is on whitespace, use ge to move backwards to the last character of the previous word. (And of course, if the character under the cursor is non-blank, just omit the ge operator).
If you're trying to write a script, this won't be as helpful as a single dedicated operator, since it requires making a decision about the character under the cursor after the g$ has completed. But if you're just trying to go to the last non-blank character in visual mode or for interactive editing purposes, the g$ ge combination should suffice for what you need.
Also try substituting gE for ge, depending on whether you want to skip over punctuation or not. (See :help word-motions for the distinction between e and E: basically, E counts ALL non-whitespace characters as word characters, while e counts only letters, digits and underscores.)
Right of Screen
g$
Left of Screen
g0
Top of Screen
H (high)
Middle of Screen
M
Bottom of Screen
L (low)
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.
To yank 7 lines downward without moving the cursor, I can 7yy. Is it possible to do the same upwards, not using macros or remapping?
You can use the :yank command with a range to accomplish this effect.
:.-6,.yank
The range explanation:
. or the dot means current line
.-6 means current line minus 6
.-6,. is current line minus 6 to the current line
This can be abbreviated .-6 to just -6 giving us -6,.yank
the current line is also assumed in the end of the range so -6,yank
the yank command can be shortened to just :y giving us -6,y
Final command:
:-6,y
For more help:
:h :yank
:h [range]
You could simply yank to a motion and then return the cursor to the position using either '[ or '].
The yank for 6 lines up, plus the current gives 7 in total:
y6u
Then, use some lesser known marks:
'[ -> to the first character on the first line of
the previously yanked text (or changed)
`[ -> to the first character of the previously yanked text
'] -> to the first character on the last line of yanked text
`] -> to the last character of the preciously yanked text
So:
y6u']
y6u`]
Are two solutions you could use depending on what exactly you want. The former moves the cursor back to the first character on the line your cursor was, and the latter moves to the last character on that line.
But there is another mark that might be handy: '^. It means the last position the cursor was when leaving insert mode.
'^ -> moves to the beginning of the last line when leaving insert mode.
`^ -> moves to the exact position where insert mode was last left.
Then here are two other solutions:
y6u'^
y6u`^
That's not the end! If you pretend to continue inserting text, you can use the gi command. It moves you to the `^ mark and enter insert mode. Then we have a fifth solution:
y6ugi
I hope one of these meets your needs!
You could do the following:
6yk6j
This is will yank the 6 preceding lines and the current one) but the courser will move. 6j jumps back to the previous position.
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".