Skip to content

๐Ÿ“– List of shortcuts which I used working with Vim

Notifications You must be signed in to change notification settings

piecioshka/vim-manual

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

72 Commits
ย 
ย 

Repository files navigation

vim-manual

๐Ÿ“– List of shortcuts which I used working with Vim

Table of Contents

๐Ÿ–ฑ Cursor navigation

  • scroll one page:
    • Ctrl + f - down
    • Ctrl + b - up
  • scroll half of window:
    • Ctrl + d - down
    • Ctrl + u - up
  • scroll one line (without moving cursor):
    • Ctrl + e - down
    • Ctrl + y - up
    • zz - center vertically line with cursor
  • move cursor on the viewport
    • H - to the top
    • M - to the middle
    • L - to the bottom
  • move cursor on the file
    • gg - to the top
    • G - to the bottom
    • 30% - to line which is 30% of whole file
  • { - move cursor to previous empty line
  • } - move cursor to next empty line
  • % - jump between bracket in line
  • `` - back cursors to previous place
  • Ctrl + ^ - return to previous file

๐Ÿ–ผ Window management

  • Ctrl + w = - reset windows into best width & height
  • move focus
    • Ctrl + w h - to left window
    • Ctrl + w j - to down window
    • Ctrl + w k - to up window
    • Ctrl + w l - to right window
  • resize window
    • Ctrl + w > - decrease width size
    • Ctrl + w < - increase width size
    • Ctrl + w - - increase size
    • Ctrl + w + - decrease size
  • {number}Ctrl + w _ - set window height which is set to {number} lines
  • Ctrl + w _ - maximize in height
  • Ctrl + w | - maximize in width
  • Ctrl + w H - move focused window to the far left
  • Ctrl + w J - move focused window to the bottom
  • Ctrl + w K - move focused window to the top
  • Ctrl + w L - move focused window to the far right

๐Ÿ“ Editor

Open files

  • :e FILENAME - open file to edit, replaced current window with file
  • :tabe (:tabedit) - open file in new tab
  • :tabc (:tabclose) - close current tab

Searching, greping etc

  • :noh (:nohl, :nohlsearch) - clear highlight after search
  • /foo - searching text foo in whole document (forwards)
  • ?foo - searching text foo in whole document (backwards)
  • :cw - show result list after searching
  • :%s/foo/bar/g - replace globally foo to bar
  • * - searching word where cursor is on it (forwards)
  • # - searching word where cursor is on it (backwards)
  • g* - searching partial words where cursor is on it (forwards)
  • g# - searching partial words where cursor is on it (backwards)
  • /\<foo - searching words starting with foo
  • /foo\> - searching words ending with foo
  • /\<foo\> - searching words foo

Misc

  • so ~/.vimrc - reload configuration in opened editor
  • :retab - replace current whitespaces with sets in .vimrc file
  • :!ls - run command ls in shell
  • Ctrl + a - increment number
  • Ctrl + x - decrement number
  • ZZ - write files and quit
  • ZQ - quit all instances of vim
  • Ctrl + z - hide Vim to background - use fg in terminal to bring it to foreground
  • Ctrl + l - redraw Vim windows

Settings

  • au VimEnter * NERDTree - auto open NERDTree plugin in each editor instance

Custom shortcuts

  • map <F9> :NERDTreeToggle <CR> - show/hide NERDTree panel on press <F9>

Markers

  • m{char} - save current position into {char}
  • `{char} - go to saved mark
  • :marks - display list of current saved markers

๐Ÿ”ฎ Magic commands

{command}{text object or motion}
  • Commands
    • d - delete (also cut)
    • c - change (delete, then place in insert mode)
    • y - yank (copy)
    • v - visual select
  • Text objects
    • w - words
    • s - sentences
    • p - paragraphs
    • t - tags (available in XML/HTML files)
  • Motions
    • a - all
    • i - in
    • t - 'til
    • f - find forward
    • F - find backward

Delete text

  • diw - "delete in word" - remove single word when cursor is on it
  • ds{ - delete nearest braces {}
  • dt. - delete text till .

Change text

  • caw - "change all word" (grab the whitespace)
  • ciw - remove the word and enter to insert mode
  • ci} - remove text in parentheses and enter to insert mode
  • cit - remove text in HTML tags

Copy text

  • yi) - copy text inside parentheses

Visual select text

  • va" - visually select all inside double quotes (including double quotes)
  • vi" - like va" but without double quotes
  • vtq - visually select text till q letter (stop before letter)
  • vfq - visually select text till q letter (stop after the letter)

๐Ÿ“ƒ Macros

Record

  • q{char} - start recording
  • (do the things)
  • q - exit from recording

Play

  • @{char}

โš™๏ธ Configuration rules

The best way is to put them to file (~/.vimrc). The default path for configuration.

  • syntax on - enable syntax highlighting
  • colorscheme molokai - set editor theme
  • set number - enable line number
  • set noic - don't ignore letter case, ex. in searching
  • set expandtab - change tabulators to spaces
  • set tabstop=4 - number of characters as indent with the TAB key
  • set shiftwidth=4 - number of characters as indent with insertions
  • set mouse=a - enable mouse in the editor
  • set background=dark - little change for brighter colors
  • set autoindent - enable automatic indention
  • set hlsearch - enable highlighting after the searching process
  • set incsearch - run searching process after you press any char (after '/')
  • set nowrapscan - stop navigate through search result when a file is ends
  • set nowrap - don't wrap lines
  • set clipboard=unnamedplus - Vim use the same buffer as OS
  • set guifont=Inconsolata\ 12 - change font in editor

๐Ÿ”Œ Plugins

Vimium

Google Chrome plugin which supports Vim navigation in the browser.

More description in the article [PL]: http://piecioshka.pl/blog/2015/01/23/vimium-plugin-do-twojej-przegladarki.html

NERDTree

Aside from panel with the directory structure. Some useful shortcuts:

  • q - exit
  • A - maximize window
  • Ctrl + c - change currently highlighted directory as root
  • Ctrl + u - change current directory as parent
  • Ctrl + p - set focus on parent dir on NERDTree list
  • Ctrl + o - on dir: open list with files; on a file: edit file
  • s - open file in vertical split mode
  • i - open file in horizontal split mode

NERDCommenter

Comment line with simple

  • \cc - comment line (recognized filetype and comment in current lang)
  • \c[SPACE] - toggle comment
  • \cu - remove the comment
  • \cs - comment line in multiline mode
  • \cy - yank line and comment it
  • \c$ - comment from the cursor to end of line
  • \cA - put comment delimiters and set cursor between them

CtrlP

Search in: files, buffers. Some shortcuts:

  • Ctrl + f - move the base of searching into the left side (switch between modes)
  • Ctrl + b - move the base of searching into the right side
  • Ctrl + r - search by regexp mode
  • Ctrl + j - like j in a file (move cursor in search list down)
  • Ctrl + k - like k
  • Ctrl + t - open selected file in new tab
  • Ctrl + x - open selected file in half horizontal window
  • Ctrl + v - open selected file in half vertical mode

๐Ÿ”— Links

Learn more about Vim

Plugins for Vim


๐Ÿšง Help

You can always use this:

  • :h quickref
  • :h SHORTCUT (:h dd, :h :s)
  • :exusage - open help window and scroll to EX commands (very useful when you try to check the meaning of all Vim commands)

Happy coding! โค๏ธ

About

๐Ÿ“– List of shortcuts which I used working with Vim

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages