Skip to content

Latest commit

 

History

History
154 lines (101 loc) · 3.07 KB

vim.md

File metadata and controls

154 lines (101 loc) · 3.07 KB

Vim

Increment numbers at the start of a line by 1

s/^\d\+/\=(submatch(0)+1)/

To increment anywhere within lines:

s/^filler text \zs\(\d\+\)/\=(submatch(0)+1)/

Wrap lines around 80-characters

In visual mode, highlight the text and enter:

gq

Combine lines into one

In visual mode, highlight the text and enter:

%j

Enable truecolor support

By default, vim will default to a 256-color palette. To enable more colors, add the following to your vimrc:

set termguicolors

Disable MiniBufferExplorer

If you don't find MiniBufferExplorer useful and want to disable it, add to your vimrc:

let g:miniBufExplAutoStart=0

If all you want is to disable the addon from showing by default in diffs, you can instead add:

let g:miniBufExplHideWhenDiff=0

Convert spaces to newlines

To break a list of space- or otherwise-delimited items into a list with one item on each line, run:

%s/ /\r/g

Select a paragraph/function in visual mode

To select a whole paragraph or function, move the cursor to within the block of interest and type:

vip

The section is demarcated by empty lines above and below.

Strip ANSI color codes

To remove color escape sequences from files, such as in text files generated by logging colorized terminal stdout, use:

s/�[\x;[0-9;]*m//g

View Vim key notation

To understand the meanings of various key notations, use Vim's help utility.

:help key-notation

View help in full window

Add | only to the end of the :help ... command to fill the window with the contents of the help file.

Run external command on current buffer

:terminal <command> %

Force re-enable gq text wrapping

Some plugins my override the formatexpr variable to execute a custom function. This will override the default behavior, which is to break text along the textwidth variable. To reverse this, run:

set formatexpr=

To always ensure that formatexpr is unset, add an autocmd rule to the vimrc file.

Step through misspelled words

Use [s and ]s to iterate through all the misspelled words identified by Vim. Requires that set=spell is enabled.

Pipe standard output to Vim in a named buffer

Vim can open stdin into a buffer, but it will not be named. To set the name from the command line, pipe to Vim as follows:

cmd ... | vim - +'file <path>'

where <path> is the location to write the buffer when saving.

Note that opening Vim in this manner will prevent any filetype detection and thereby disable syntax highlighting.

Send buffer/selection to external command and replace with output

To send the entire buffer to an external program, run:

:%!<cmd>

where <cmd> is the program to run, including all command line flags, etc.

The selected text will be passed to the program via stdin and replaced in the buffer with the program output.

To instead send a selection instead of the entire buffer, select the block of text in visual mode and then enter the command:

:'<,'>!<cmd>