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

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).

Related

vim: Marks getting deleted/lost [duplicate]

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.

vi editor : Non-text symbols appear while reading [duplicate]

This question already has answers here:
gvim What do the # symbols mean at the bottom left of the screen?
(2 answers)
Closed 7 years ago.
I am having problem while scrolling and reading a large file through vi or gvimeditor. In the middle of a file, I am seeing a continuous stream of symbols ^# in blue, like we see often in binary files. However, I don't see them with other editors (e.g. TexEdit in my OS X).
Is it a common problem and is there a way to get rid of this?
add this line to your .vimrc file:
set display=lastline
to understand what it does, do a :h 'display'

How to open vim buffer next to current buffer rather than at the end [duplicate]

This question already has answers here:
How to change order for :bnext and :bprevious in vim?
(2 answers)
Closed 8 years ago.
I don't use tabs in in vim, I just use buffers and buffer switching, but I have a real pickle. I can't figure out how to open a new buffer next to this one, so that when I switch buffers I don't have to switch all the way to the end. Many times I'm opening files for reference.
Let's say I have five buffers open
[0][1][2][3][4]
And I'm working on the second
[0][1][2][3][4]
I'd like to open a new buffer here:
[0][1][new buffer][2][3][4]
Rather than here:
[0][1][2][3][4][new buffer]
Make sense?
If you want to control the ordering and insertion of buffers, you have to use the argument list instead. The buffer numbers increase steadily and are fixed; there's no way to shuffle them around.
So, use :argedit to open another file; it will be placed just after the current entry. You can control the positioning via the optional [count]. As a bonus, the :next / :n command is one character shorter than :bnext / :bn.

"paste inner", similar to "yank inner" [duplicate]

This question already has answers here:
Pasting inside delimiters without using visual selection
(5 answers)
Closed 8 years ago.
Is there any known, straight-forward way to perform inner <text-object>-functons in Vim similar to yank-inner and delete-inner, only with paste? I know how to do this with Visual mode but it feels a few steps too long.
Example:
delete-inner (di<text-object>):
user.name("Carl") -> di" -> user.name("") + Carl is copied to clipboard.
Now, I occasionally find myself wanting to do something like this as well:
user.name("") -> pi" -> user.name("Carl")
I don't like taking the extra step inside Visual-mode, nor performing acharacter/string-search (/,f,t). Is there any way around this? Plugin-recommendations are also welcome if necessary.
I need this so often, I wrote a plugin to simplify (i.e. without the intermediate visual mode) and allow maximum speed: ReplaceWithRegister.
This plugin offers a two-in-one gr command that replaces text covered by a {motion} / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard . command. Should you not like it, its page has links to alternatives.
So, your example would be g r i ".
Edit: Previous plugin versions didn't handle an empty text object well; fixed in the latest version 1.41.
"_di"P
works for me, it pastes to the left instead of right which leaves it inside the quotes
assuming you want to change the value with the one on the clipboard
Alternately you can use :map to map pi" to either the command above or the Visual method keys

Changing the previous command in linux [duplicate]

This question already has answers here:
How can I replace ALL instances of a string in the previous command in Bash? [duplicate]
(6 answers)
^word^replacement^ on all matches in Bash?
(6 answers)
Closed 1 year ago.
Is there a way to change the previous command in linux? I'm copying a bunch of files using
cp path/to/source1 path/to/target2
and I want to change it to
cp path/to/source2 path/to/target2
so I want to replace the 1 with the 2
I know I can put this inside a loop but I need to do this after checking something in my notebook.
!!:gs/1/2/
Here are some more examples:
http://mark.stosberg.com/Tech/tips/bash.tips
the command for this manipulation of history is:
^old-text^new-text
For more reading I can just recommend the man page of bash, esp. the parts of readline and history.
I suppose you do this in a command line, not in bash script
the quickest way is to write cp and PRESS Alt+., press space, and Press Alt+. again and repair the path
Alt+. gives you last parameter you used
Ctrl+R gives you reverse search
UP arrow gives you latest commands
press the up arrow to get the last command, then change whatever you want to have different.
or if you want to address an older command hit 'Ctrl-r' then start typing what you want and if the correct old command appears hit right arrow to make it the current. Then change whatever you want to change.

Resources