What are some most useful vi editor/text-processing hacks/tips?

Joined
Apr 16, 2023
Messages
149
Reaction score
16
Credits
1,460
We need to daily access remote servers to read logs and vi editor is used a lot. I'll share few hacks that I've learnt on the way.

1) /string_to_search will search

2) n for next match.

3) N for previous match.

4) gg will put the cursor at the top

5) Shift+G will put the cursor back to the bottom.

That's all I know as of now and some grep.
 


In GVim I learned a combination to convert a base-10 number to hexadecimal. However the combination is much longer to take hex and convert it back to decimal! Nope.

GVim is a good program in case one has to learn how to use the primitive editor. Fortunately there are better editors out there, even the ones still having "ncurses" dependency.
 
I’ve been using vi/vim every day, for so long, I’ve probably forgotten more things about Vim than some people ever learn. Ha ha!

Recently, I got part way through planning and writing a multi-part series of posts here featuring some of my favourite .vimrc modifications.

But then my HDD died on my laptop. I’ve replaced the HDD with a SSD and I’ve restored a back-up of the WIP series. Hopefully I’ll get back to it soon and will finally finish and post the first article. I’ve been a bit busy lately!
 
In normal mode,

* will search for next occurrence of current word. Then use n or N to jump to next/previous.

:noh will disable search highlighting...

ggVG to select all...

vimtutor is a good way to learn the basic of vim movements and verbs.
 
vimtutor is a good way to learn the basic of vim movements and verbs.

Good thinking. I'll throw in a link about this:

 
There's so much but the reality is that I get stuck with the ones that I just use a lot,
while there are certainly a lot that I could use, but I just don't look 'em up

Anyway, the ones I would use a lot

$ for end of line
yy to copy the current line
p to paste that, below the current line
2G to go to line 2 (or other numbers)
dd to delete the current line

It's amazing how these things are in ones muscle memory. I really have to think hard now. When in VI, it's like it's all automatic.
There's some not so difficult one to copy all lines from current line to the end, but I'm not sure.

And for the search

:set ic to set the "Case Insensitive" modus
/whatever to look for whatever (case insensitive)
n to look for the next one
And of course, h j k l to move your cursor around
 
Last edited:
And a very important one I forgot:


(Just a dot, to be clear) That is the key to press to repeat the last action.
As I think, that function doesn't exist in Word, Wordpad, or Notepad. Maybe in Notepad++
There are functions to UNDO the last action, but not to redo. But in VI it is possible.
It's perfect for example adding the same string to several different lines. Or, basically repeat whatever earlier action, by placing the cursor correctly, and pressing the dot !
 
And a very important one I forgot:



(Just a dot, to be clear) That is the key to press to repeat the last action.
As I think, that function doesn't exist in Word, Wordpad, or Notepad. Maybe in Notepad++
There are functions to UNDO the last action, but not to redo. But in VI it is possible.
It's perfect for example adding the same string to several different lines. Or, basically repeat whatever earlier action, by placing the cursor correctly, and pressing the dot !
Vim's dot operator . is an absolute godsend. I spend a lot of time in vim and I use it a lot!

Outside of other vi clones, most text editors don't have the ability to repeat the last operation/edit. But then, most editors are not modal like vi/vim.
 

Staff online

Members online


Top