Giter VIP home page Giter VIP logo

essential-vim's Introduction

Michael's Essential Vim

vimrc

The vimrc file ($HOME/.vimrc on linux/mac or $HOME/_vimrc on Windows) stores personal configuration for vim.

These options are maximally recommended to all skill levels.

""" Essential
set mouse=a " allow use of mouse
set backspace=indent,eol,start " always allow backspace in insert mode
set nocompatible " ensure vim features are available

""" Critical
syntax on " syntax highlighting
filetype plugin indent on " detect file type
set smartcase " case insensitive search, unless you use a capital letter.

set incsearch " Starts searching while you type in your search
set hlsearch " Highlights all search instances

set autoindent  " copy previous line's indent
set smartindent " increase indent after start of new block (e.g. '{')

" In command mode, first tab fills in the longest common match
"  Second tab displays list. Two more tabs will iterate over that list.
set wildmode=longest,list,list,list:full
set wildmenu

""" Personal Preference
colorscheme desert " best stock colourscheme
set background=dark
set noeb vb t_vb= " disable beeping

Keybinding Legend

The thing that makes vim actually good is how shortcut keys are typed in combination to form custom and powerful actions (almost like combining words into a sentence). Each keybind performs a particular role in these commands. You'll see what I mean later, but to help I've marked each keybinding with the category it falls under using the following legend:

  • ๐Ÿ‘Ÿ - Movement key. Changes the position of the text cursor or text selection.
  • ๐Ÿ’ฅ - Action key. Actually edits text, or modifies a file, etc
  • ๐ŸŒง - Mode change key. Going from normal mode/insert mode/command mode etc
  • ๐Ÿ“ฃ - Command-line command. Not technically a keybinding, and doesn't actually interact with the special keybind grammar. But still lets you do powerful things.
  • ๐Ÿฆš - Other

Absolute Beginner

  • ๐Ÿ‘Ÿ [Mouse click/scroll] - Move cursor (make sure you have the vimrc above)
  • ๐ŸŒง i - insert mode
  • ๐ŸŒง Escape - leave insert mode
  • ๐Ÿ“ฃ :wq - save and quit (mnemonic: write, quit)
  • ๐Ÿ“ฃ :q! - quit without saving (mnemonic: "quit!")
  • ๐Ÿ‘Ÿ / - search file (mnemonic: ? key) (full regex support)
  • ๐Ÿ‘Ÿ [arrow keys] - Move cursor

Novice

Mechanic: Visual Mode

A 'Selection' or 'Highlight' mode, where you select/highlight the text you want to perform an action on. To activate it, just click and drag over text as you would in a GUI text editor (or press 'v'). Pressing ๐Ÿ‘Ÿ Movement keys in this mode will change the text selection.

When in visual mode, any ๐Ÿ’ฅ Action key you press will instantly operate on the text you have currently selected. For instanmce, if you press d, your highlighted text will be deleted.

Keybinds

  • ๐Ÿ’ฅ d - delete text
  • ๐Ÿ’ฅ y - copy text (mnemonic: 'yank')
  • ๐Ÿ’ฅ p - paste text
  • ๐Ÿ’ฅ u - undo last action
  • ๐Ÿ’ฅ ctrl-r - redo last action
  • ๐Ÿ“ฃ :s/{old}/{new} - substitute occurrences of {old} with {new}

Great bang-for-buck keyboard movements

Mechanic: Shift modifier type 1 -

Holding Shift and pressing a ๐Ÿ‘Ÿ movement key reverses the direction of the movement.

Like /, ? searches text, but backwards from the cursor position, instead of forwards. Some more useful examples are in the following keybinds.

Some ๐Ÿ’ฅ Action keys (like 'p/P' for paste) also operate this way.

Keybinds

  • ๐Ÿ‘Ÿ f/F{character} - move back/forward to the next instance of the character. (mnemonic: 'find')
  • ๐Ÿ‘Ÿ n N - move to next/previous search occurence
  • ๐Ÿ‘Ÿ {number}G - move to line number (or last line if no number given)
  • ๐Ÿ’ฅ < > - indent left/right

Situational Movement 1

Keybinds

  • ๐Ÿ‘Ÿ % - Jump to the bracket (()<>[]{}) matching the one under the cursor
  • ๐ŸŒง o O - create an empty newline below/above the current line, and enter insert mode on it.
  • ๐Ÿ‘Ÿ ^ - move to start of current line
  • ๐Ÿ‘Ÿ $ - move to end of current line
  • ๐Ÿ‘Ÿ { } - move to the previous/next blank line after a block of text (i.e, move a paragraph up/down).

Mechanic: linewise actions with keybind double-press

From normal mode (without pressing any keybind beforehand), pressing an action keybind twice will perform that action on the line the cursor is currently on. For instance, dd will delete the entire line, and yy will copy the entire line.

In/Around movements

  • ๐Ÿ‘Ÿ i{key}
  • ๐Ÿ‘Ÿ a{key}

{key} can be one of the following:

  • any bracket or quote ('"`{}[]()<>) - inside the closest surrounding pair of chars
  • p - paragraph
  • s - sentence
  • t - tag (<html></html>)
  • w - word (up to alphanumeric only)
  • W - word (including symbols, up to spaces)

Once you're comfortable with the idea of moving the cursor with shortcut keys

  • ๐Ÿ‘Ÿ h j k l - Home row < v ^ >
  • ๐Ÿ‘Ÿ w W b B e E - Word-wise movement (follows word/Word convention instead of reverse convention)

Mechanic: {action} {movement} grammar

An ๐Ÿ’ฅ Action key followed by a ๐Ÿ‘Ÿ Movement key will perform that action from the current cursor postion to the postion the cursor would be after that movement.

Advanced // Extensions on Old Concepts

  • ๐Ÿ’ฅ . - repeat last ๐Ÿ’ฅ Action (best used from normal mode)

  • ๐Ÿ’ฅ c - change text, i.e. delete and enter insert mode. Very powerful in combination with '.', since it includes the replaced text!

  • ๐Ÿ‘Ÿ ctrl-o ctrl-i - go back and forward between your recent movement 'jumps'

  • ๐ŸŒง V ctrl-v - line-wise and column-wise visual selection modes

Optimisations

  • ๐Ÿ‘Ÿ t/T{character} - move forward/back to just before the next instance of the character (equivalent to f{char}โ—€ or F{char}โ–ถ)
  • ๐Ÿ’ฅ r{character} - replace character under the cursor, without going into insert mode
  • ๐ŸŒง a - enter insert mode after the current cursor (equivalent to li)
  • ๐ŸŒง I - enter insert mode at the start of the line (after indentation) (equivalent to ^i). Works great with '.'
  • ๐ŸŒง A - enter insert mode at the start of the line (after indentation) (equivalent to $a). Works great with '.')
  • ๐Ÿ‘Ÿ * # - search for word under cursor

Advanced

  • ๐Ÿ’ฅ gu - make lowercase
  • ๐Ÿ’ฅ gU - make uppercase
  • ๐Ÿ’ฅ J - join next line
  • ๐Ÿฆš zt zb zz - move viewport so the current line is the top/bottom/middle line

Advanced // Record/retrieve

  • ๐Ÿฆš q{letter} - record macro
  • ๐Ÿ’ฅ @{letter} - record macro
  • ๐Ÿฆš m{letter} - set location bookmark in file
  • ๐Ÿ‘Ÿ '{letter} - move to location bookmark

Advanced // Obscure

  • ๐Ÿ’ฅ !{shell-command} - run lines as input to given shell command, and replace them with the command output.
  • ๐Ÿ’ฅ gq -- split long lines
  • ๐Ÿ“ฃ :g/{match}/{command} - on every line with {match}, perform {action}
  • ๐Ÿ“ฃ :v/{match}/{command} - on every line without {match}, perform {action}

Less Useful

  • ๐Ÿ‘Ÿ H L M - move cursor to the top/bottom/middle line (mnemonic: high/low/middle)

Appendices

Appendix A: additional vimrc recommendations

set scrolloff=7 # leave 7 lines of extra space above/below the maximum cursor height

# Decent font options
if has ('gui_running')
	if s:MSWindows
		set guifont=Consolas\ 14
	elseif has("gui_photon")
		set guifont=Courier\ New:s12
	elseif has("gui_kde")
		set guifont=Courier\ New/12/-1/5/50/0/0/0/1/0
	elseif has("x11")
		set guifont=-*-courier-medium-r-normal-*-*-180-*-*-m-*-*
	else
		set guifont=Courier_New:h12:cDEFAULT
	endif
endif

Appendix B: Other resources

essential-vim's People

Contributors

michaelruigrok avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.