Skip to content


screenshot_2022-10-16-02_5741 screenshot_2022-10-16-02_5748 screenshot_2022-10-16-02_5756 screenshot_2022-10-16-02_5801

View current colors for for syntax

:ru syntax/hitest.vim

Create a mapping for bash

nmap <F6> :exec '!'.getline('.')

Move right align text of match above current line

:%s/\(.*[^ ]\+\) *\(# .*\)/\2\r\1/"

Insert a string/character on selected multiple lines

- Enter default mode.....: esc
- Select lines...........: ctrl-v
- When lines is selected.: shift+i
- Now press..............: esc
- Done

Insert text end of multiple lines

- Enter default mode.............: esc
- Select lines string............: ctrl-v
- When lines is selected press...: : :
- Now in cmd, type.................: :'<,'>$A string
- Now press........................: esc
- Done

Insert text end of multiple words vip$A,

- Enter default mode.....: ESC
- Select lines string....: ctrl-v
- When lines is selected.: $ + A
- Now press..............: ESC
- Done

Jump to line 10


Set column width of vim

:set column=238

Set a line number width

:set numberwidth=6

Set wrap width

You can remove the if (&columns > 80) | if you always want 80 columns.

set columns=80
autocmd VimResized * if (&columns > 80) | set columns=80 | endif
set wrap
set linebreak
set showbreak=+++


Delete a Recording

To delete a recording just record nothing over it.

For example, qxq erases whatever was recorded to register x.

or :call setreg('x', '')
or :let @x = ''

Replace oldsting/newstring

Here is an example to replace string OldString with NewString contained in multiple *.cpp files:

vim *.cpp
qx            # start recording to register x
q             # stop recording
@x            # playback to see if it works correctly
999@x         # repeat 999 times to complete the job

One way to edit a recording (for example, to register x) is to paste it into a new buffer, then edit the buffer, then copy the results back into the register. For example:

:new      # new buffer
"xp       # paste register x into the buffer
[edit the keystrokes]
<Esc>     # return to normal mode
0"xy$     # go to beginning of line; into register x, yank to end of line
:bd!      # delete the new buffer without saving
@x        # execute modified recording
Alternatively, edit the contents of register x in the command line:
:let @x="<Ctrl-R><Ctrl-R>x"

Execute a bash command and save stdout in vim

:.! ls
  • or
:exec '!'.getline('.')

If the file type you are using is not available by default, you can add one

Vim has four methods of indentation, namely:

Method Description
Autoindent This method uses indent from the previous line for the file type you are editing.
Smartindent Smartindent works similarly to autoindent but recognizes the syntax for some languages such as C language.
Cindent Sindent is slightly different from autoindent and smartindent as it is more clever and is configurable to various indexing styles.
Indexexpr Is the most efficient and flexible. It uses expressions to calculate the indent of a file. When enabled, indexexpr overrides other indenting methods.

!!! Note "If Vim encounters an unrecognized file type, it might not indent correctly. To resolve this, you can enable smartindent and autoindex"

  • Comments are closed on this article!

Last update: December 4, 2022 20:32:48