Vim/NeoVim

    Notes: - Tabs contain windows - From a tab to another the disposition of the windows differs

    Plugins

    NERDTree

    m   " menu, then 'c' to create a file
    R   " refresh the menu (in case you create/remove files/directories)
    

    Markdown

    za  " open fold where the cursor is
    zR  " open all folds
    

    CtrlP

    F5                 " refresh cache file
    :CtrlPClearCache   " same as above
    

    ALE

    :ALEPopulateQuickfix  " show lint errors
    

    Vimrc

    Reload file when changing

    set autoread
    

    Note: you can refresh file by using :e!

    Show lines

    set number
    

    Syntax color

    syntax on
    

    Note: seems to be obsolete and enable by default.

    Indent

    Indent from 4 columns:

    set shiftwidth=4
    

    Smart indent:

    set smartindent
    

    Keep autoindent on current line

    set autoindent
    

    Indentation before saving

    " use 4 spaces for tabs
    set tabstop=4 softtabstop=4 shiftwidth=4
    
    " display indentation guides
    set list listchars=tab:❘-,trail:·,extends:»,precedes:«,nbsp:×
    
    " convert spaces to tabs when reading file
    autocmd! bufreadpost * set noexpandtab | retab! 4
    
    " convert tabs to spaces before writing file
    autocmd! bufwritepre * set expandtab | retab! 4
    
    " convert spaces to tabs after writing file (to show guides again)
    autocmd! bufwritepost * set noexpandtab | retab! 4
    

    source

    Note: seems to be obsolete and enable by default.

    Copy/Past & Mouse use

    Require gpm packet.

    set mouse=a
    

    Commands

    Basics

    :e      " edit
    :w      " save
    :q      " quit
    :qa     " quit all
    
    i       " insert before cursor
    I       " insert before line
    a       " apped after cursor
    A       " append after line
    
    :d       " delete/cut current line
    :d2      " delete 2 line from the current line
    d        " delete/cut current line
    dw       " delete current word from the cursor
    daw      " delete word around the cursor
    
    w        " reach next word
    W        " similar and faster
    
    
    :u[ndo]  " or u
    :red[o]
    .        " repeat last action
    
    :! linux command
    

    Insert notes: On multiple lines

    " go on word through visual mode, or just with the cursor on the letter
    <C-v> " block mode
    j " to select next line
    I " to insert, or d to delete
    " press esc when done
    

    Delete note: to avoid unexpected paste :set nopaste

    Source

    Select all

    :%y+
    gg"+yG " other way
    

    Copy/Paste

    Source

    Normal Mode

    d   " cut the line
    yy  " to copy the first line, equivalent to Y
    y2y " copy 2 lines
    p   " to paste from the current line
    P   " to paste after the copy
    "+y " to copy in clipboard, this require vim-gtk (http://vim.wikia.com/wiki/Accessing_the_system_clipboard)
    

    Command-line mode

    <C-r>"

    Notes: - " is the register - Other approach by using <C-f> to open history and use normal command like p

    Research and replace

    /research sentence " type 'n' to go to the next occurence
    :%s/x/z/            " replace first occurence 'x' by 'z'
    :%s/x/z/g           " replace all 'x' by 'z'
    :%s/x/z/gc           " replace all 'x' by 'z' with prompt to confirm
    

    Note:

    • Clean research last highlighting research :noh
    • You can research from current word by using *, type it again to find next occurence

    Summary research

    :vimgrep pattern %
    :cwin
    

    Head/Bottom of file

    Head: gg or 1G Bottom: G

    Jump Line/Col

    7G5| " Jump line 7, col 5
    :56 " Jump line 56
    

    Visual Mode

    V for the whole line

    v from the cursor

    Block Mode

    <C-v>

    Buffer

    :ls             " list files in the buffer
    
    :bd      " close current buffer
    :%bd|e#         " close all buffers except this one
    

    Tabs

    z See : http://vim.wikia.com/wiki/Using_tab_pages

    gt              " go to next tab (or Ctrl+Up)
    gT              " go to previous tab (or Ctrl+Down)
    {i}gt           " go to tab in position i
    
    :newtab         " new tab
    :tabedit <file> " new tab
    
    :tabn <number>  " change tab
    
    :b <file>       " switch current tab to opened <file> in tab, autocomplete's working to find <file> faster, b mean buffer
    :tab sball      " open each buffer in a tab
    
    :tab split      " put current window in full size (will open a new tab)
    

    With the following mappings (which require gvim), you can press Ctrl-Left or Ctrl-Right to go to the previous or next tabs, and can press Alt-Left or Alt-Right to move the current tab to the left or right.

    nnoremap <C-Left> :tabprevious<CR>
    nnoremap <C-Right> :tabnext<CR>
    nnoremap <silent> <A-Left> :execute 'silent! tabmove ' . (tabpagenr()-2)<CR>
    nnoremap <silent> <A-Right> :execute 'silent! tabmove ' . (tabpagenr()+1)<CR>
    

    Source: http://vim.wikia.com/wiki/Using_tab_pages

    Open multiple files into tabs at once

    :args *.c
    :tab all
    

    source

    Windows

    <C-w>n " new horizontal split (editing a new empty buffer)
    <C-w>s " split window horizontally (editing current buffer)
    <C-w>v " vsplit window vertically (editing current buffer)
    
    <C-w>c " close window
    <C-w>o " close all windows, leaving :only the current window open
    <C-w>w " go to next window
    <C-w>p " go to previous window
    
    <C-w>x " reorder windows
    
    <C-w>_ " maximize a window vertically
    <C-w>| " maximize a window horizontally
    <C-w>= " resize all windows to equal size
    
    <C-w><Up> " go to window above
    <C-w><Down> " go to window below
    <C-w><Left> " go to window on left
    <C-w><Right> " go to window on right
    
    :resize 50 " fix size on horizontal
    :vertical resize +5 " incremental size on vertical 
    

    Tips

    Format an opened json file

    Consider the following json content

    [ {"name": "Homer", "budget": {"total": 20, "left": 0}}, {"name": "Marge", "budget": {"total": 30, "left": 30}} ]
    

    You can use something like: :%!jq '.[0]', which will gives:

    {
      "name": "Homer",
      "budget": {
        "total": 20,
        "left": 0
      }   
    }
    
    

    source