This question already has answers here:
Returning to previous line with Vim
(2 answers)
Closed 7 years ago.
I am new to Vim, my code file has 300 lines, and suppose currently the cursor is on line 254, and when use gg command the cursor turn to line 1, and I want to back to line 254 but I forget that line number. Is there a command the can do this?
And when I want to jump a line, I input :38, and I want to jump back to the previous line, what should I do?
Ctrl+O jumps backward to the previous location.
Ctrl+I jumps forward to the next location.
:jumps or :ju gives you a jump list.
Use jump number followed by Ctrl+O to jump to that particular location.
Ex: 20Ctrl+O
Use
``
(backtick, backtick)
This sends you back to the place you last jumped from. To learn more about this, type :help ''. That whole help document is worth reading.
Related
This question already has answers here:
Automatically go to next line in vim
(2 answers)
Closed 6 months ago.
When I am holding the "l" key in vim in command mode, the cursor goes to right. However, when it reaches the end of the line, it stops. I want it to behave differently, i.e. I want it to go to the next line when it goes right and reaches the end of line. How can I do so? Is there some configuration code that I can add to .vimrc file that changes the default behaviour of the cursor?
I find the answer on net after learning the keyword 'whichwrap' in the comments.
After I searched the keyword, I come across the following link which has the answer:
Automatically go to next line in vim
This question already has answers here:
Make vim keep mark when I delete the line the mark is on
(2 answers)
Closed 6 years ago.
I've tried to find an answer to this on the googles, but been unsuccessful. The problem is this:
In vim I delete a line that contained a mark; so I guess the mark is also deleted. Now I can't jump back to that location any more. I'm coding so there is a lot of line deleting going on. It's a pain having to manually find the place that I set the mark again.
Is there a way around this? I want vim to jump to aprox the same location where the mark used to be. Either the same line number, or the closest guess.
You can try `. which is a position of the last change occurred in the current buffer. Then you can mark it again.
This question already has answers here:
Remove all arbitary spaces before a line in Vim
(9 answers)
Closed 8 years ago.
How can I map a key to completely de-indent a visual block?
The best method I know for doing this "manually" is de-indenting once with < and then repeatedly pressing ., so the mapping is:
vmap <leader>d <.................
This does work but I'd like to know the "right" way to do this. The above also only works for however many .s there are.
use the steps in this page to completely trim white spaces from the left for a range
Step by step:
Select your block ( shift-v)
:left or :le
<CR>
That should do it
You can add a count to <; I usually do 50<, which will de-indent it 50 times, which should almost always be enough.
From :help <:
{Visual}[count]< Shift the highlighted lines [count] 'shiftwidth'
leftwards (for {Visual} see Visual-mode). {not in
Vi}
Instead of using the < key to de-indent you can simply delete all the whitespace in each line before the first character. You can do so by adding:
let #y = '0d^j'
In order to run this on every line of the selected block, enter command mode by typing : and complete the command to:
:'<,'>normal #y
Then again you can record another macro to do so:
let #q = ':normal #y'
Using this approach, you will eventually be able to de-indent a visual block by typing #q, which calls the macro #y in the background.
Explanation of the first macro:
0 will move the cursor to the beginning of the line,
d^ will delete all whitespace until the first character and
j will move the cursor to the line below
This question already has answers here:
Select entire line in VIM, without the new line character
(9 answers)
Closed 8 years ago.
I know that y$ can yank the string from the cursor's position to the end of line, but the "\n\r" is always included, is there any solution to do that without having the "\n\r" included?
You only need to move the cursor to the beginning of the line and yank from there to the end of the line:
0y$
^y$
Say I open a file in vim. I start on line 1 column 1 and hold down j until I am on line 14. Pressing :7CR puts me on line 7. I press yy to "yank".
How do I return to line 14? Using CTRL + o takes me back to the top of the file. ` ` gives me the same results.
You can type 7G to jump to line#7, then type Ctrl-o to jump back.
:set showcmd to show what you have typed at the right bottom.
To yank line#7 (No cursor moving):
:7y
To paste line#7 below line#14:
:7t14
<C-o> and <C-i> allow you to go down and up the jumplist. They work with "jump" commands but not with jjjjjjjjjjj.
To take advantage of this feature — and save a lot of time and keypresses in the process — I'd advise you to get into the habit of using better ways to navigate through your code : /?^$fFtTbBeEwW{} and so on.
And yes, use marks.
One more way: To jump back to another line, you can use ''. This works similar to an automatic mark, which is set for certain jump movements.
Why not set a mark using ma for example, and then return to it later using `a or 'a?
Mark the line you were originally on using ma, then 'a to return there.
If you want to return to a previous location, first you have to mark that location using the mark (m) command, followed by any letter a-z or A-Z, like ma to mark a location as 'a'.
To return to that location you would enter `a.