Vim Tips
Contents
Setup
- Install nvim
- Fedora: should come with nvim pre-installed but in case you don't have it:
sudo dnf install neovim - MacOS:
- MacPorts:
port install neovim - Homebrew:
brew install neovim
- MacPorts:
- Windows WSL (Ubuntu LTS)
- Download the nvim source:
git clone git@github.com:neovim/neovim.git cd neovim git checkout stable- Install prerequisites:
build-essentialcmakepkg-configlibtoollibtool-binm4autotools-devautomakegettext
makesudo make install- You'll also need to configure the
XDG_CONFIG_HOMEvariable- In your
~/.bashrcadd:export XDG_CONFIG_HOME=/home/quanticle/.config
- In your
- Fedora: should come with nvim pre-installed but in case you don't have it:
- Install the
vim-plugplugin managercurl -fLo $XDG_CONFIG_HOME/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
- Set up
vim-plug:exe 'edit '.stdpath('data').'/init.vim'- Add
call plug#begin(stdpath('data').'/plugged')to the top of the file - Then add your plugins with
Plug '<plugin name>' - Finally start
vim-plugwithcall plug#end()
- Add
- Restart nvim
- Run
:PlugUpdateto install and update your plugins
- Allow switching buffers without saving:
set hidden - Enable auto-complete on command and switching buffers by name:
set wildmenuset wildmode=list:longest
- Disable autoindent:
filetype indent off - Make search case insensitive:
set ignorecase - Enable line numbers:
set number - Prevent vim from changing the terminal's cursor type:
set guicursor=
My Plugins
jnurmine/Zenburn: Zenburn color schemeyuezk/vim-js: Better Javascript supportHerringtonDarkholme/yats.vim: Typescript supportmaxmellon/vim-jsx-pretty: React JSX supportguns/vim-clojure-static: Clojure syntax highlighting
Basic Controls
- Movement
k h-|-l j - Start of line:
0 - End of line:
$ - Start of file:
gg - End of file:
G - Forward one word:
w - Back one word:
b - Insert before:
i - Insert after:
a - Replace:
s - Insert at start of line:
I - Insert at end of line:
A - Insert line above:
o - Insert line below:
O - Cut:
x - Copy:
y - Paste:
p - Selection
- Visual mode:
v - Visual line:
V
- Visual mode:
- Jump to matching brace/parenthesis:
% - Reload file:
:e - Indent/Unindent
- Indent region:
> - Unindent region:
< - Indent line:
>> - Unindent line:
<<
- Indent region:
- Page up/Page Down
Ctrl-b: full page upCtrl-u: half page upCtrl-f: full page downCtrl-d: half page down
Find/Replace
- Make search case insensitive:
set ignorecase - To search forwards:
/ - To search backwards:
? - To replace:
:s/<search regexp>/<replacement>/g- The
greplaces every instance on a line rather than just the first instance
- The
- Clear search highlighting:
:noh
Set colorscheme
colorscheme <colorscheme name>colorscheme zenburn
Pipe contents of buffer into shell command
:w !<command>- Example: copy the buffer into the clipboard:
:w !xsel -ib(Linux)
Replace buffer contents with output of shell command
:%!<cmd>- Example:
:%!xsel -obto replace the buffer with the contents of the clipboard
Copy and paste into system clipboard
- Copy into system clipboard:
"+y - Paste from system clipboard:
"+p
Tabs vs. Spaces
- To use spaces instead of tabs:
:set ts=<width> :set sw=<width> :set expandtab
- To use tabs instead of spaces
- Set
tsandswas above :set noexpandtab
- Set
Splits
- Split horizontally:
:split - Split vertically:
:vsplit - Jump between splits:
Ctrl-w <direction> - Close a split:
:q
Highlight current line
- To highlight the current line:
set cursorline
