Github url

vimrc

by amix

amix /vimrc

The ultimate Vim configuration (vimrc)

22.1K Stars 6.0K Forks Last release: Not found MIT License 399 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

VIM

The Ultimate vimrc

Over the last 10 years, I have used and tweaked Vim. This configuration is the ultimate vimrc (or at least my version of it).

There are two versions:

  • The Basic: If you want something small just copy basic.vim into your ~/.vimrc and you will have a good basic setup
  • The Awesome: Includes a ton of useful plugins, color schemes, and configurations

I would, of course, recommend using the awesome version.

How to install the Awesome version?

Install for your own user only

The awesome version includes a lot of great plugins, configurations and color schemes that make Vim a lot better. To install it simply do following from your terminal:

git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim\_runtime sh ~/.vim\_runtime/install\_awesome\_vimrc.sh

Install for multiple users

To install for multiple users, the repository needs to be cloned to a location accessible for all the intended users.

git clone --depth=1 https://github.com/amix/vimrc.git /opt/vim\_runtime sh ~/.vim\_runtime/install\_awesome\_parameterized.sh /opt/vim\_runtime user0 user1 user2 # to install for all users with home directories sh ~/.vim\_runtime/install\_awesome\_parameterized.sh /opt/vim\_runtime --all

Naturally,

/opt/vim\_runtime

can be any directory, as long as all the users specified have read access.

Fonts

I recommend using IBM Plex Mono font (it's an open-source and awesome font that can make your code beautiful). The Awesome vimrc is already setup to try to use it.

Some other fonts that Awesome will try to use:

How to install the Basic version?

The basic version is just one file and no plugins. Just copy basic.vim and paste it into your vimrc.

The basic version is useful to install on remote servers where you don't need many plugins, and you don't do many edits.

git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim\_runtime sh ~/.vim\_runtime/install\_basic\_vimrc.sh

How to install on Windows?

Use gitforwindows to checkout the repository and run the installation instructions above. No special instructions needed ;-)

How to install on Linux

If you have vim aliased as

vi

instead of

vim

, make sure to either alias it:

alias vi=vim

. Otherwise,

apt-get install vim

How to update to latest version?

Just do a git rebase!

cd ~/.vim\_runtime git pull --rebase python update\_plugins.py

Some screenshots

Colors when editing a Python file:

Screenshot 1

NERD Tree plugin in a terminal window: Screenshot 3

Distraction free mode using goyo.vim and vim-zenroom2: Screenshot 4

Included Plugins

I recommend reading the docs of these plugins to understand them better. Each plugin provides a much better Vim experience!

  • ack.vim: Vim plugin for
    the\_silver\_searcher
    (ag) or ack -- a wicked fast grep
  • bufexplorer.zip: Quickly and easily switch between buffers. This plugin can be opened with
    <leader></leader>
  • ctrlp.vim: Fuzzy file, buffer, mru and tag finder. It's mapped to
    <ctrl></ctrl>
  • goyo.vim and vim-zenroom2:
  • lightline.vim: A light and configurable statusline/tabline for Vim
  • NERD Tree: A tree explorer plugin for vim
  • open_file_under_cursor.vim: Open file under cursor when pressing
    gf
  • pathogen.vim: Manage your vim runtimepath
  • snipmate.vim: snipmate.vim aims to be a concise vim script that implements some of TextMate's snippets features in Vim
  • ale: Syntax and lint checking for vim (ALE requires NeoVim >= 0.2.0 or Vim 8 with +timers +job +channel)
  • vim-commentary: Comment stuff out. Use
    gcc
    to comment out a line (takes a count),
    gc
    to comment out the target of a motion.
    gcu
    uncomments a set of adjacent commented lines.
  • vim-expand-region: Allows you to visually select increasingly larger regions of text using the same key combination
  • vim-fugitive: A Git wrapper so awesome, it should be illegal
  • vim-indent-object: Defines a new text object representing lines of code at the same indent level. Useful for python/vim scripts
  • vim-multiple-cursors: Sublime Text style multiple selections for Vim, CTRL+N is remapped to CTRL+S (due to YankRing)
  • vim-yankstack: Maintains a history of previous yanks, changes and deletes
  • vim-zenroom2 Remove all clutter and focus only on the essential. Similar to iA Writer or Write Room
  • gist-vim Easily create gists from Vim using the
    :Gist
    command

Included color schemes

Included modes

How to include your own stuff?

After you have installed the setup, you can create ~/.vim_runtime/my_configs.vim to fill in any configurations that are important for you. For instance, my my_configs.vim looks like this:

~/.vim\_runtime (master)\> cat my\_configs.vim map <leader>ct :cd ~/Desktop/Todoist/todoist<cr>
map <leader>cw :cd ~/Desktop/Wedoist/wedoist<cr> 
</cr></leader></cr></leader>

You can also install your plugins, for instance, via pathogen you can install vim-rails:

cd ~/.vim\_runtime git clone git://github.com/tpope/vim-rails.git my\_plugins/vim-rails

Key Mappings

The leader is

,

, so whenever you see

<leader></leader>

it means

,

.

Normal mode mappings

Fast saving of a buffer (

<leader>w</leader>

):

nmap <leader>w :w!<cr>
</cr></leader>

Map

<space></space>

to

/

(search) and

<ctrl>+<space></space></ctrl>

to

?

(backwards search):

map <space> /
map <c-space> ?
map <silent> <leader><cr> :noh<cr>
</cr></cr></leader></silent></c-space></space>

Disable highlights when you press

<leader><cr></cr></leader>

:

map <silent> <leader><cr> :noh<cr>
</cr></cr></leader></silent>

Smart way to move between windows (

<ctrl>j</ctrl>

etc.):

map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-h> <c-w>h
map <c-l> <c-w>l
</c-w></c-l></c-w></c-h></c-w></c-k></c-w></c-j>

Closing of the current buffer(s) (

<leader>bd</leader>

and (

<leader>ba</leader>

)):

" Close current buffer map <leader>bd :Bclose<cr>

" Close all buffers
map <leader>ba :1,1000 bd!<cr>
</cr></leader></cr></leader>

Useful mappings for managing tabs:

map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove 

" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
</cr></c-r></leader></leader></cr></leader></cr></leader></cr></leader>

Switch CWD to the directory of the open buffer:

map <leader>cd :cd %:p:h<cr>:pwd<cr>
</cr></cr></leader>

Open

ack.vim

for fast search:

map <leader>g :Ack 
</leader>

Quickly open a buffer for scripbble:

map <leader>q :e ~/buffer<cr>
</cr></leader>

Toggle paste mode on and off:

map <leader>pp :setlocal paste!<cr>
</cr></leader>

Visual mode mappings

Visual mode pressing

\*

or

#

searches for the current selection:

vnoremap <silent> * :call VisualSelection('f')<cr>
vnoremap <silent> # :call VisualSelection('b')<cr>
</cr></silent></cr></silent>

When you press gv you

Ack.vim

after the selected text:

vnoremap <silent> gv :call VisualSelection('gv', '')<cr>
</cr></silent>

When you press

<leader>r</leader>

you can search and replace the selected text:

vnoremap <silent> <leader>r :call VisualSelection('replace')<cr>
</cr></leader></silent>

Surround the visual selection in parenthesis/brackets/etc.:

vnoremap $1 <esc>`&gt;a)<esc>`<i>
vnoremap $2 <esc>`&gt;a]<esc>`<i>
vnoremap $3 <esc>`&gt;a}<esc>`<i>
vnoremap $$ <esc>`&gt;a"<esc>`<i>
vnoremap $q <esc>`&gt;a'<esc>`<i>
vnoremap $e <esc>`&gt;a`<esc>`<i>
</i></esc></esc></i></esc></esc></i></esc></esc></i></esc></esc></i></esc></esc></i></esc></esc>

Insert mode mappings

Quickly insert parenthesis/brackets/etc.:

inoremap $1 ()<esc>i
inoremap $2 []<esc>i
inoremap $3 {}<esc>i
inoremap $4 {<esc>o}<esc>O
inoremap $q ''<esc>i
inoremap $e ""<esc>i
inoremap $t &lt;&gt;<esc>i
</esc></esc></esc></esc></esc></esc></esc></esc>

Insert the current date and time (useful for timestamps):

iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>
</cr></c-r>

Command line mappings

$q is super useful when browsing on the command line. It deletes everything until the last slash:

cno $q <c->eDeleteTillSlash()<cr>
</cr></c->

Bash like keys for the command line:

cnoremap <c-a> <home>
cnoremap <c-e> <end>
cnoremap <c-k> <c-u>

cnoremap <c-p> <up>
cnoremap <c-n> <down>
</down></c-n></up></c-p></c-u></c-k></end></c-e></home></c-a>

Write the file as sudo (works only on Unix). Super useful when you open a file and you don't have permissions to save your changes. Vim tip:

:W

Plugin related mappings

Open bufexplorer to see and manage the current buffers (

<leader>o</leader>

):

map <leader>o :BufExplorer<cr>
</cr></leader>

Open ctrlp.vim plugin to quickly find a file or a buffer (

<leader>j</leader>

or

<ctrl>f</ctrl>

):

" Quickly find and open a file in the CWD let g:ctrlp\_map = '<c-f>'

" Quickly find and open a recently opened file
map <leader>f :MRU<cr>

" Quickly find and open a buffer
map <leader>b :CtrlPBuffer<cr>
</cr></leader></cr></leader></c-f>

NERD Tree mappings:

map <leader>nn :NERDTreeToggle<cr>
map <leader>nb :NERDTreeFromBookmark 
map <leader>nf :NERDTreeFind<cr>
</cr></leader></leader></cr></leader>

goyo.vim and vim-zenroom2 lets you only focus on one thing at a time. It removes all the distractions and centers the content. It has a special look when editing Markdown, reStructuredText and textfiles. It only has one mapping. (

<leader>z</leader>

)

map <leader>z :Goyo<cr>
</cr></leader>

vim-multiple-cursors mappings to manage multiple cursors at once:

let g:multi\_cursor\_start\_word\_key = '<c-s>'
let g:multi_cursor_select_all_word_key = '<a-s>'
let g:multi_cursor_start_key = 'g<c-s>'
let g:multi_cursor_select_all_key = 'g<a-s>'
let g:multi_cursor_next_key = '<c-s>'
let g:multi_cursor_prev_key = '<c-p>'
let g:multi_cursor_skip_key = '<c-x>'
let g:multi_cursor_quit_key = '<esc>'
</esc></c-x></c-p></c-s></a-s></c-s></a-s></c-s>

vim-yankstack mappings to manage the kill-ring (clipboard):

nmap <c-p> <plug>yankstack_substitute_older_paste
nmap <c-n> <plug>yankstack_substitute_newer_paste
</plug></c-n></plug></c-p>

ctrl-p mappings to easily find and open a file, buffer, etc.:

let g:ctrlp\_map = '<c-f>'
map <leader>j :CtrlP<cr>
map <c-b> :CtrlPBuffer<cr>
</cr></c-b></cr></leader></c-f>

vim-snipmate mappings to autocomplete via snippets:

ino <c-j> <c-r>=snipMate#TriggerSnippet()<cr>
snor <c-j> <esc>i<right><c-r>=snipMate#TriggerSnippet()<cr>
</cr></c-r></right></esc></c-j></cr></c-r></c-j>

vim-surround mappings to easily surround a string with

\_()

gettext annotation:

vmap Si S(i\_<esc>f)
au FileType mako vmap Si S"i${ _(<esc>2f"a) }<esc>
</esc></esc></esc>

ale to easily go to the next Ale syntax/lint error:

nmap <silent> <leader>a <plug>(ale_next_wrap)
</plug></leader></silent>

Spell checking

Pressing

<leader>ss</leader>

will toggle spell checking:

map <leader>ss :setlocal spell!<cr>
</cr></leader>

Shortcuts using

<leader></leader>

instead of special characters:

map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=
</leader></leader></leader></leader>

Cope

Query

:help cope

if you are unsure what cope is. It's super useful!

When you search with

Ack.vim

, display your results in cope by doing:

<leader>cc</leader>

To go to the next search result do:

<leader>n</leader>

To go to the previous search results do:

<leader>p</leader>

Cope mappings:

map <leader>cc :botright cope<cr>
map <leader>co ggVGy:tabnew<cr>:set syntax=qf<cr>pgg
map <leader>n :cn<cr>
map <leader>p :cp<cr>
</cr></leader></cr></leader></cr></cr></leader></cr></leader>

How to uninstall

Just do following: * Remove

~/.vim\_runtime

* Remove any lines that reference

.vim\_runtime

in your

~/.vimrc

Looking for a remote-first job?

Maintaining this Vim configuration isn't my day job. Daily I am the founder/CEO of Doist. You could come and help us build the workplace of the future while living a balanced life (anywhere in the world 🌍🌎🌏).

PS: Using Vim isn't a requirement πŸ˜„

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.