Skip to content

Instantly share code, notes, and snippets.

Last active January 3, 2019 23:20
Show Gist options
  • Save JeffPaine/86b17ed39c24b614f690 to your computer and use it in GitHub Desktop.
Save JeffPaine/86b17ed39c24b614f690 to your computer and use it in GitHub Desktop.
General vim notes.

Vim Notes

  • set list Shows invisible characters.
  • set listchars What invisibile characters should be set to, see :h listchars for complete list.

Key Remapping

  • map creates a key map that works in normal, visual, select and operator pending modes
  • map! creates a key map that works in insert and command-line mode.
:nmap - Display normal mode maps
:imap - Display insert mode maps
:vmap - Display visual and select mode maps
:smap - Display select mode maps
:xmap - Display visual mode maps
:cmap - Display command-line mode maps
:omap - Display operator pending mode maps
  • noremap is added when you don't want a mapping to be recursive e.g. map z to v, but not to what v is then mapped to.
  • <bar> should be used in place of | when used in map commands to distinguish it from a pipe

Interesting .vimrc Settings (various sources)

" Indenting in visual mode keeps the visual highlight.
vnoremap < <gv
vnoremap > >gv

" Yank from the cursor to the end of the line, to be consistent with C and D.
nnoremap Y y$

" Jump to start and end of line using the home row keys.
nnoremap H ^
nnoremap L $

" Fix the filetype for .md files.
augroup MarkDownType
    autocmd BufNewFile,BufRead *.md setlocal filetype=markdown
augroup end

" Quick escape from insert mode.
inoremap jj <ESC>


When you see something like let g:some_variable = x you're setting the value of a global variable.

To see all global variables let g:.

From :help internal-variables

                (nothing) In a function: local to a function; otherwise: global 
buffer-variable    b:     Local to the current buffer.                          
window-variable    w:     Local to the current window.                          
tabpage-variable   t:     Local to the current tab page.                        
global-variable    g:     Global.                                               
local-variable     l:     Local to a function.                                  
script-variable    s:     Local to a :source'ed Vim script.                     
function-argument  a:     Function argument (only inside a function).           
vim-variable       v:     Global, predefined by Vim.

Why let vs. set?

:set is for setting options, :let for assigning a value to a variable.

File Explorer (netrw)

  • :edit . to open a netrw buffer
  • :e . same as above

From within the netrw interface

  • <enter> edit a file / enter a directory
  • P edit file in most recent tab (or current tab if only one)
  • - go up a directory
  • % create an empty file
  • d create a directory
  • D delete the selected item
  • R rename the selected item
  • s cycle through different sort options

Registers (cutting and pasting)

  • You can use visual highlighting to paste over text with p
  • :reg see all register contents
  • :reg "0 see contents of register 0
  • <C-r>" in insert mode, paste the contents of the default register
  • <C-r>0 in insert mode, paste the contents of register 0
  • "+p paste from the system copy / paste buffer (if multi-line, don't have to set paste first
  • put + paste contents of system copy / paste buffer
  • "+ is the system clipboard
  • "* is the "mouse highlight" clipboard
  • "0 holds last yank
  • "1 holds last delete / change
  • So, you can use "0 to paste yanked text after deleting / changing text
  • p paste after the cursor
  • P paste before the cursor
  • "Ay append text to register A


  • ( or ) move backward or forward by "sentences"
  • { or } move backward or forward by "paragraphs"
  • g$ move to visual end of wrapped line
  • g0 move to visual beginning of wrapped line
  • % go to matching (), [], {} etc


  • :g/^$/d delete all blank lines
  • gqgq format / wrap the current line
  • :e %:h<TAB> edit files in same directory as current file


  • Tabularize /<pattern> Run the tabular plugin (does some smart multi-line matching
  • Tab /<pattern> Same as above
  • <,'>Tab /= Run tabularize on the selected text, targeting equal signs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment