VIM Reference

Over the years, many text editors have been created for Linux. But only one editor emerges as standard de-facto editor for sysadmins and that is vi/vim. Even if some other text editors are easier to use, vi is the only text editor that is always available as it is installed on RHEL by  default. That is why as a Linux administrator you need to know how to work with vi.

Any sysadmin should know vim, as in some situation it is the only editor available. And it makes sense to know more, not less about vim -- it is  one of the few powerful tools (almost sysadmin IDE) available  on Rhcsa exam. Person who know it really well gets some advantage over the rest of the exam participants. 

Vim is a powerful editor and at the same time vim is hard to learn. Much of it's power lies requires knowledge of corresponding commands and leaning this can't be done in week. Don't feel overwhelmed. Go slow. One command, one plugin at a time. Don't overdo it. cd

The level of knowledge of vim (often dismal) does not correlate directly with the qualification of sysadmin (I know  several super qualified sysadmins with more then a decade of experience in Unix are despite of this are still pretty basic in vim). But speed and convenience of editing with multiple files helps, and  especially helps in time constrained  environment like Rhcsa exam.

One interesting idea in such an environment is to open all the necessary files in one vim session and do not quit it until the end of exam, discarding files that you no longer need and reloading those that you do. This is significantly more productive then working with vi one file at a time.

We will not cover basics here. We assume that you already have spent 30 mins doing the vim tutorial (run vimtutor instead of vim in terminal). That means that know the basic movements, and a dozen of most important commands.

For those who just start learning vi, there is a good introduction to vi by listing side by side vi commands to typical Windows GUI Editor cursor movement and shortcut keys. It lists all the basic commands including yy (copy line) and p (paste after) or P (paste before): vi (Vim) for Windows Users

! Brackets  Filters Windows Control            
a b c d e f g h i j
k l m n o p r s t u
v w x y z          
 
 ---------------------------------------------------------------------
!{cmd}{filter}  send {motion} text through external program {filter}
 "              store in register 
 #              same as "*", but search backwards
 $              end of line 
 %              find match of current parenthesis, brace, or bracket 
 ---------------------------------------------------------------------
 &              synonym for ":s//~/" (repeat last substitute)
 '              goto beginning of line with mark 
 (              previous sentence 
 )              next sentence 
 *              search forward for [count]'th occurent of word nearest cursor
 ---------------------------------------------------------------------
 +              first character of next line 
 ,              reverse direction of last f, F, t, or T 
 -              first character of previous line 
 .              repeat last command
 /              search forward 
 ---------------------------------------------------------------------
 0              beginning of line 
 :              go to ex-mode 
 ;              repeat last f, F, t, or T
={motion}      filter {motion} lines through 'equalprg' external program
 ?              search backward 
 ---------------------------------------------------------------------
 @              execute command in register
Brackets
 
 [(             goto previous unmatched '('
 [[             previous section
 []             go backwards count sections or to previous '}' in 1st column
 [{             goto previous unmatched '{'
 ---------------------------------------------------------------------
 [#             goto previous unmatched "#if" or "#else"
 [*             goto previous start of a C comment (/*)
 [i             display 1st line tha contains keyword under cursort
 [I             display all lines that contain keyword under cursor
 [^I            jump to 1st line that contains keyword under cursor
 ---------------------------------------------------------------------
 [d             display 1st macro definition that contains macro under cursor
 [D             display all macro definition that contain macro under cursor
 [^D            jump to 1st macro definition  that contains keyword under cursor
 ][             go forwards  count sections to to next '}' in 1st column
 ]]             next section 
 ---------------------------------------------------------------------
 ]}             goto next unmatched '}'
 ]#             goto next unmatched "#if" or "#else"
 ]*             goto next end of a C comment (*/)
 ]i             like '[i', but start at current cursor positiont
 ]I             like '[I', but start at current cursor position
 ---------------------------------------------------------------------
 ]^I            like '[^I', but start at current cursor position
 ]d             like '[d', but start at current cursor position
 ]D             like '[D', but start at current cursor position
 ^              first non-whitespace character
 _              move (count-1) lines downard on first non-blank character
 ---------------------------------------------------------------------
 `              goto mark 
 {              previous paragraph 
 |              to screen column [count] in current line
 }              next paragraph 
 ~              switch case of current character
 ---------------------------------------------------------------------
Filters
!!{filter}      filter [count] lines through the external program {filter}
''              go to start of line of previous mark or location before search
``              return to previous mark or location before a search 
(return)        next line 
(spacebar)      next character 
 ---------------------------------------------------------------------
<%              shift text until matching (, [, or { to the left
<<              shift paragraph one shiftwidth to the left 
>%              shift text until matching (, [, or { to the right 
>>              shift paragraph one shiftwidth to the right 
A
 a              append after the current location 
 A              append at the end of the line
^a              add [count] to the number at or after the cursor
B
 b              beginning of previous word 
 B              beginning of previous word, ignore punctuation 
^b              scroll back one screen
C
 c              delete {motion} text (into register) and begin insert
 C              change to end of line 
^c              ends insert mode, unused in command mode
D
 d{motion}      delete text covered by a {motion}
 D              delete to end of line 
^d              scroll down half a window
 E
 e              end of word 
 E              end of word, ignore punctuation 
^e              scroll screen down one line
 fx             find given character by searching forwards
 F              find given character by searching backwards
 ---------------------------------------------------------------------
^f              scroll forward one screen
 g ^a           dump memory profile
 g ^g           show information about current cursor position
 g ^h           start Select block mode
 g ^]           :tjump to tag under the cursor
 ---------------------------------------------------------------------
 g#             like "#", but without using "\<" and "\>"
 g$             wrap off: goto rightmost onscreen character of current line
 g*             like "*", but without using "\<" and "\>"
 g0             wrap off: goto leftmost onscreen character of current line
 g?             rot13 encoding operator
 ---------------------------------------------------------------------
 g??            rot13 encode current line
 g?g?           rot13 encode current line
 gD             goto definition of word under cursor in current file
 gE             go backwards to end of previous WORD
 gH             start Select line mode
 ---------------------------------------------------------------------
 gI             like "I", but always start in column 1
 gJ             join lines without inserting space (like :j!)
 ["x]gP         put text (from register x) N times
 gR             enter virtual replace mode
 gU{motion}     make Nmove text uppercase
 ---------------------------------------------------------------------
 gV             don't reselect previous Visual area (maps, menus) in Select mode
 g]             :tselect on tag under cursor
 g^             wrap off: goto leftmost non-white onscreen char on current line
 ga             print ascii value of character under cursor
 gd             goto definition of word under cursor in current function
 ---------------------------------------------------------------------
 ge             go backwards to end of previous word
 gf             start editing file whose name is under cursor
 gg             cursor to line N (default: 1) ; start Select mode
 gh             start Select mode
 gj             wrap on: like "j", but go N screen lines down
 ---------------------------------------------------------------------
 gk             wrap on: like "k", but go N screen lines up
 gm             goto character at middle of screenline
 go             cursor to byte N in buffer
 ["x]gp         put text (from register x) after cursor N times
 gq{motion}     format text
 ---------------------------------------------------------------------
 gr{char}       virtual replace N chars with given char
 gs             goto sleep for N (1) seconds
 gu{motion}     make Nmove text lowercase
 gv             reselect previous Visual area
 g~{motion}     swap case for Nmove text
 ---------------------------------------------------------------------
 g<Down>        same as gj
 g<End>         same as g$
 g<Home>        same as g0
 g<LeftMouse>   same as <ctrl-LeftMouse>
 g<RightMouse>  same as <ctrl-RightMouse>
 g<Up>          same as gk
 ---------------------------------------------------------------------
 G              ...Goto  [defaults to end of file] 
^g              show status line
 h              left 
 H              first line on screen 
^h              backspace in insert mode, left in command mode
 ---------------------------------------------------------------------
 i              insert before current location 
 I              insert before first non-whitespace character on line 
^i              goto [count] newer cursor position in jump list
 j              down 
 J              join next line with current line 
 ---------------------------------------------------------------------
^j              down in command, create newline in insert
 k              up 
 K              use keywordprg (kp option) to lookup keyword under cursor
^k xx           enter digraph specified by two characters
 l              right 
 ---------------------------------------------------------------------
 L              last line on screen 
^l              redraw screen
 m              mark position into register 
 M              middle of screen 
^m              carriage return
 ---------------------------------------------------------------------
 n              repeat last search 
 N              repeat last search, reverse direction 
^n              down in command
 o              open line below current 
 O              open line above current 
 ---------------------------------------------------------------------
^o              goto older cursor position in jump list
 p              put below current line 
 P              put above current line 
^p              up in command
 qx             record typed characters into given register x
 ---------------------------------------------------------------------
 q              stop macro recording
 Q              quit and run ex 
^q              same as ctrl-v
 r              replace current character 
 R              replace characters until insert mode is left 
 ---------------------------------------------------------------------
^r              redraw screen in command mode
 s              substitute 
 S              substitute entire line 
^s              split current window into two
 t              to...  
 ---------------------------------------------------------------------
 T              backward to...  
^t              moves to next shiftwidth.
 u              undo last change 
 U              undo changes to current line 
^u              scroll up half a window
 ---------------------------------------------------------------------
 v              start Visual mode at given character
 V              start linewise Visual mode
^v              start blockwise Visual mode
 w              beginning of next word 
 W              beginning of next word, ignore punctuation 
Windows Control
 ---------------------------------------------------------------------
^W ^B           same as "^W b"
^W ^C           same as "^W c"
^W ^D           same as "^W d"
^W ^F           same as "^W f"
^W ^G           same as "^W g .."
 ---------------------------------------------------------------------
^W ^I           same as "^W i"
^W ^J           same as "^W j"
^W ^K           same as "^W k"
^W ^N           same as "^W n"
^W ^O           same as "^W o"
 ---------------------------------------------------------------------
^W ^P           same as "^W p"
^W ^Q           same as "^W q"
^W ^R           same as "^W r"
^W ^S           same as "^W s"
^W ^T           same as "^W t"
 ---------------------------------------------------------------------
^W ^W           same as "^W w"
^W ^X           same as "^W x"
^W ^Z           same as "^W z"
^W ^]           same as "^W ]"
^W ^^           same as "^W ^"
 ---------------------------------------------------------------------
^W ^_           same as "^W _"
^W +            increase current window height N lines
^W -            decrease current window height N lines
^W =            make all windows the same height
^W R            rotate windows upwards N times
 ---------------------------------------------------------------------
^W S            same as "^W s"
^W W            go to N previous window (wrap around)
^W ]            split window and jump to tag under cursor
^W ^            split current window and edit alternate file N
^W _            set current window height to N (default: very high)
 ---------------------------------------------------------------------
^W b            go to bottom window
^W c            close current window (like |:close|)
^W d            split window and jump to definition under the cursor
^W f            split window and edit file name under the cursor
^W g ^]         split window and do |:tjump| to tag under cursor
 ---------------------------------------------------------------------
^W g ]          split window and do |:tselect| for tag under cursor
^W g }          do a |:ptjump| to the tag under the cursor
^W i            split window & jump to declaration of identifier under cursor
^W j            go to N next window (stop at last window)
^W k            go to N previous window (stop at first window)
 ---------------------------------------------------------------------
^W n            open new window, N lines high
^W o            close all but current window (like |:only|)
^W p            go to previous (last accessed) window
^W q            quit current window (like |:quit|)
^W r            rotate windows downwards N times
 ---------------------------------------------------------------------
^W s            split current window in two parts, new window N lines high
^W t            go to top window
^W w            go to N next window (wrap around)
^W x            exchange current window with window N (default: next window)
^W z            close preview window
 ---------------------------------------------------------------------
^W }            show tag under cursor in preview window
^W <Down>       same as "^W j"
^W <Up>         same as "^W k"
X
 x              delete current character 
 X              delete previous character 

^x              unused
Y
 y              yank...  
 Y              yank current line 
^y              scroll screen up one line
Z
 z              redraw with line [count] at top-of-window

 zt             like "z<cr>" but leave cursor in same column
 z{height}<CR>  redraw window {height} lines tall
 z.             redraw with line [count] at center of window
 zz             like "z." but cursor left at same column
 z-             redraw with line [count] at bottom of window
 ---------------------------------------------------------------------
 zb             like "z-" but leave cursor in same column
 z<Right>       wrap off: scroll screen [count] characters to left
 zl             same as "z<Right>"
 z<Left>        scroll screen [count] characters to right
 zh             same as "z<Left>"
 ---------------------------------------------------------------------
 zL             scroll screen half a screenwidth to left
 zH             scroll screen half a screenwidth to right
 zs             scroll text&cursor horizontally so cursor on right of screen
 ze             scroll text&cursor horizontally so cursor on left of screen
ZZ              write (only if changes have been made) and quit 
 ---------------------------------------------------------------------
^z              suspend Vim

Top Visited
Switchboard
Latest
Past week
Past month

NEWS CONTENTS

Old News ;-)

[Oct 19, 2018] Advanced Vim

Oct 19, 2018 | vimsheet.com

I've compiled a list of essential Vim commands that I use every day. I then give a few instructions on how to making Vim as great as it should be, because it's painful without configuration.

##Cursor movement (Inside command/normal mode)

The four directions in Vim, keys h, j, k, and l.

##Insert/Appending/Editing Text

##Marking text (visual mode)

##Visual commands Type any of these while some text is selected to apply the action

##Cut and Paste

##Exiting

##Search/Replace

##Working with multiple files

##Marks Marks allow you to jump to designated points in your code.

##General

#Making Vim actually useful Vim is quite unpleasant out of the box. For example, typeing :w for every file save is awkward and copying and pasting to the system clipboard does not work. But a few changes will get you much closer to the editor of your dreams.

##.vimrc

Installation

##Plugins

##Switch Caps Lock and Escape

##Other I don't personally use these yet, but I've heard other people do!

[Oct 19, 2018] A quick reference list of vi editor commands

Oct 19, 2018 | kb.iu.edu

Vi editor command keys:

  ZZ      Exit, saving changes           t<x>   Up to <x> forward
  Q       Enter ex mode                  T<x>   Back up to <x>
  <ESC>   End of insert                  <x>|   Go to column <x>
  :<cmd>  Execute ex command             w,W    Forward one word
  :!<cmd> Shell command                  b,B    Back one word
  ^g      Show filename/size             e,E    End of word
  ^f      Forward one screen             ^h     Erase last character
  ^b      Back one screen                ^w     Erase last word
  ^d      Forward half screen            ^?     Interrupt
  ^u      Backward half screen           ~      Toggle character case
  <x>G    Go to line <x>                 a      Append after
  /<x>    Search forward for <x>         i,I    Insert before
  ?<x>    Search backward for <x>        A      Append at end of line
  n       Repeat last search             o      Open line below
  N       Reverse last search            O      Open line above
  ]]      Next section/function          r      Replace character
  [[      Previous section/function      R      Replace characters
  %       Find matching () { or }        d      Delete
  ^l      Redraw screen                  dd     Delete line
  ^r      Refresh screen                 c      Change              
  z<CR>   Current line at top            y      Yank lines to buffer
  z-      Current line at bottom         C      Change rest of line 
  ^e      Scroll down one line           D      Delete rest of line 
  ^y      Scroll up one line             s      Substitute character
  ``      Previous context               S      Substitute lines    
  H       Home window line               J      Join lines          
  L       Last window line               x      Delete after        
  M       Middle window line             X      Delete before       
  +       Next line                      Y      Yank current line   
  hjkl    Cursor movement:               p      Put back lines      
          left/down/up/right             P      Put before          
  0       Beginning of line              <<     Shift line left     
  $       End of line                    >>     Shift line right    
  f<x>    Find <x> forward               u      Undo last change    
  F<x>    Find <x> backward              U      Restore current line
Ex mode commands:
  q       Quit                        set <x>   Enable option
  q!      Quit, discard changes       set no<v> Disable option
  r <f>   Read in file <f>            set all   Show all options
  sh      Invoke shell
  vi      Vi mode
  wq      Write and quit
  w <f>   Write file <f>
  w! <f>  Overwrite file <f>
Options:
  autoindent      Automatic line indentation
  autowrite       Write before quit
  ignorecase      Ignore case in searches
  number          Display line numbers
  showmatch       Show matches to ) and } as typed
  terse           Quiet mode
  wrapscan        Wraparound in searches
  wrapmargin      Automatic line splitting

Recommended Links

Google matched content

Softpanorama Recommended

Top articles

Sites

Vim cheat sheet



Etc

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Haterís Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D


Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to to buy a cup of coffee for authors of this site

Disclaimer:

The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Last modified: December 01, 2018