WebDevChallenges Logo

A brief introduction to Vim (Part 9)

Updated June 5, 21
Use the systems clipboard, comments in Vim and my current config.


Here is the eighth (previous) part of this series: A brief introduction to Vim (Part 8)

Use the systems clipboard

You might want to yank directly into the system’s clipboard and paste directly from it.

First of all, check if your Vim version supports yanking to and pasting from the system’s clipboard. Issue the following command in your CLI: vim --version | grep clipboard

Now if you are on macOS, make sure the output includes +clipboard. If you are on linux, make sure the output includes +xterm_clipboard.

If it doesn’t, install another version with your operating system’s package manager (brew install vim for macOS or sudo apt-get install vim-gtk for a Debian based OS like Ubuntu or Debian).

If you then add the following line to your ~/.vimrc file, you should be able to use the system’s clipboard with Vim: set clipboard=unnamed

Comments in the config

You can add a comment to your ~/.vimrc file by adding a " character in front of the comment like this: " This is a comment

My current Vim config

If you are curious, this is my current ~/.vimrc config file:

" pathogen initialization
execute pathogen#infect()

" syntax highlighting
syntax on

" use numbers
set number
set relativenumber

" searching
set ignorecase
set smartcase
set hlsearch

" use system clipboard
set clipboard=unnamed

" tabs
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab

" key maps
let mapleader=" "
map <C-n> :NERDTreeToggle<CR>
nnoremap <leader>w <esc>:w<CR>
nnoremap <leader>q <esc>:q<CR>
nnoremap <leader>Q <esc>:q!<CR>
nnoremap <leader>n <esc>:nohlsearch<CR>

" colorscheme
colorscheme atom

End of the series

Every line in my Vim config file was discussed and explained in this series.

I’m really happy I sticked to writing these posts and I really appreciate the positive feedback I received from the readers.

If you liked it, make sure to follow me on social media, to get notified when I release new posts for upcoming series about other topics.