How To Diff Two Files In Vim

Author: , February 5th, 2024

shell> vim file1 file2 Create a vertical split window: Control-w v Enable visual diff on the left side: :diffthis Move the cursor to the right side buffer: Control-w Right-arrow Enable visual diff on the left side: :diffthis You should now see the differences highlighted on both sides.

How To Disable VIM Mouse Automatic Visual Mode

Author: , July 27th, 2021

Current Session:

All Sessions: Add the following to your ~/.vimrc file:

How To Force vim to Convert Tabs to Spaces

Author: , November 26th, 2019

To create indents with 4 space characters which are entered by pressing the TAB key:

To make the above settings permanent add to your ~/.vimrc file. For more details on any of these see :help ‘optionname’ in vim (e.g. :help ‘tabstop’) tabstop The width of a hard tabstop measured in “spaces” — effectively the […]

How To Reformat or Re-indent Files in VIM

Author: , January 11th, 2019

In the normal vim mode, typing gg=G will reindent the entire file. == will re-indent just the current line.

How To Move in vim Using the Keyboard

Author: , March 21st, 2018

h move one character left j move one row down k move one row up l move one character right w move to beginning of next word b move to previous beginning of word e move to end of word W move to beginning of next word after a whitespace B move to beginning of […]

How To Find Non-ASCII Characters in Vi

Author: , July 7th, 2015

To search for non-ASCII characters: /[^\d0-\d127] Use the substitute function to clean them up: :%s/[^\d0-\d127]/ /g

How To Fix Indentation in Vi

Author: , July 30th, 2014

gg=G gg to get to the top of the file, = to indent, and G to the go to the end of the file.

How To Delete Blank Lines Using vim

Author: , June 19th, 2014

How To Change Cursor-position-based Window Scrolling In VIM

Author: , September 30th, 2011

To force VIM to keep the cursor vertically centered in the window while the text scrolls, place this directive in your ~/.vimrc file:

To disable it, comment the line out with a double-quote or remove it completely:

How To Turn Off Auto-Comment In Vim

Author: , September 29th, 2011

Put the following line in your .vimrc file: autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o Or, use this one-off command when in VIM: :set formatoptions-=c formatoptions-=r formatoptions-=o