Notes
Vim History
less .viminfo
to view recent history in vim. could possibly recover lost files / information if needed.
Custom .vimrc
If ~/.vimrc
does not exist in your home directory, create it, and customize it to suit your needs. For example, the following .vimrc
will set your tab size to 2 from the default 4, and convert your tabs to spaces automatically. This is useful when sharing code, as things are more compact and using spaces is less ambiguous than tab sizes across platforms.
set tabstop=2 shiftwidth=2 expandtab autoindent mouse=a
Here, tabstop
is the tab size setting, measured in spaces. shiftwidth
allows vim to compensate according to our tab settings when automatically indenting, etc. expandtab
converts our tab size setting into actual spaces. set autoindent
will set vim to automatically indent to our current depth when in insert mode and moving to a new line by pressing enter. This will not insert spaces unless text is input. mouse=a
enables mouse interaction with split windows, when supported.
Split Windows in Vim
Run the commands below to split windows while within a Vim session -
:split /path/to/file # To split horizontally
:vsplit /path/to/file # To split vertically
OR
:sp /path/to/file # To split horizontally
:vs /path/to/file # To split vertically
:open /path/to/file # To open a file within the active tab
:retab # To resize tabs in this session to your .vimrc configuration
Use Ctrl-w <Arrow Keys>
or Ctrl-w <h j k l>
to move between split windows.
Use Ctrl-w w
to move to the next window, Ctrl-w W
to move to the previous.Ctrl-w c
, :q
, :close
, or :clo
to close the active window.
Close all other windows with Ctrl-w o
, :only
, or :on
.