vim: Marks getting deleted/lost [duplicate] - 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.

Related

How to make cursor go to the next line when reaching the end of line in vim? [duplicate]

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

Adjusting all line to Left side of the file in gvim [duplicate]

This question already has answers here:
Remove all arbitary spaces before a line in Vim
(9 answers)
Closed 5 years ago.
I'm new to the vim editor.
How can I adjust all lines to the left? I have many lines which are indented and I want to arrange them so they all abut the left side of the file (no spacing at the start of the lines).
Select all line in visual mode and then type :left . Hope this helped.
keerthan
The simple key sequence :%left will do the trick, it basically applies the left command to all lines in the file.

Vim: Add closing buckles, brackets, quotation marks etc. automatically? [duplicate]

This question already has answers here:
Vim plugin for 'auto-closed' parenthesis?
(5 answers)
Closed 6 years ago.
This is something what I miss from other editors. I'm looking for a plugin/config which adds closing mark for some characters automatically.
For example, when I type (, it add ) and prompt will be between it. Similarly with {, " etc. This would be very helpful for me. I know I can do it using Vim command, but my goal is do it automatically.
There is a plugin named auto-pairs.vim available in github. See here : https://github.com/jiangmiao/auto-pairs
It can automatically insert closing brackets and quotes and puts prompt in between both.
It is smart and doesn't insert matching brackets for escaped brackets. It works even if you nest different brackets.

How to jump back to the previous line in Vim [duplicate]

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.

How do I execute command similar to gg=G in Vim without going to the top of the file? [duplicate]

This question already has answers here:
Indenting entire file in Vim without leaving current cursor location
(5 answers)
Closed 8 years ago.
How can I reformat the whole buffer in Vim, the same way as I am doing using gg=G keys, without going the the top (which is caused by the gg)?
You can mark the current position with m<letter> command and then go back with `<letter>.
mzgg=G`z
The referenced duplicate uses more effective variant of this approach using the fact that double backtick goes to the last cursor position so you don't actually need to mark the current position:
gg=G``
Or you can install a plugin for text object of entire buffer (e.g. https://github.com/kana/vim-textobj-entire) and then do
=ae
(or equivalent with another plugin).

Resources