Showing posts with label Insert. Show all posts
Showing posts with label Insert. Show all posts

08 April 2024

How to move in insert mode in vim?

https://vi.stackexchange.com/questions/10296/navigation-in-insert-mode


If you just need to modify a small amount of text or a word, you can use <Ctrl-O>h/j/k/l.

<Ctrl-O> takes you back to Normal mode just for that command, and then drops you back into insert mode, so it saves you some amount of key presses, if you need to go into normal mode for a small movement.

27 February 2018

How to insert line numbers to a Vim file

How to insert line numbers to a Vim file?

Insert line numbers

The :s command can be used to insert line numbers before each line:
:%s/^/\=printf('%-4d', line('.'))
The pattern ^ matches the start of every line, and the replacement \= is the result of evaluating the following expression. That expression uses printf() to format the number of the current line: %-4d is a left-aligned decimal number, padded if necessary by adding spaces to a 4-column width (%4d is right-aligned, and %04d inserts leading zeroes).