Saturday, January 11, 2020

Vim editor – Commands’ Summary (Cheat Sheet)


MINI TUTORIAL - MINIMAL KNOWLEDGE


This post intends to give you the very initial steps to begin using Vim, supplying a Cheat Sheet collected from many sources across the years.

To begin, let's create a hello text file.
Using the console (prompt), type the following:

vim hello.txt
Type I (i) to get into "insert mode".
Type: hello world!
Type ESC to exit.
Type colon (:) then x to save:
:x
Use enter to exit.

That's it. You are "initiated" - simple like that.




Vim editor has "modes" - commands' contexts.

When you open the editor you may issue a set of commands.
See basic navigation below.

To enter into edit mode, use insert key or the I(i) key.
To exit from insert mode, use ESC.

On ESC mode, if you type colon (:), you get a command line at the bottom that enables another set of commands. For instance, if you desire to add line numbers, you do: 

Type ESC.
Type colon (:).
Type "set nu"
Type ESC to exit from the command line.

Now the lines have sequential numbers.

Vim is a super editor, having everything you wonder or you even never supposed to.

It worths to get acquainted to it because it is the default editor on most *nix systems, like AIX, Unix and flavors of Linux.

When using console (SSH connection), Vim is the ubiquitous solution - everywhere has a "vim" command available for you.

Although the documentation turns into something scaring it is not a big deal if you dive into its resources by section of interests.
For instance, what do you want to do?
Find a string, replace text, mark a point on the text to get there fast, split windows, compare files, etc.


I know, I know - it is very strange to alternate between insert mode and command mode. Do not complain - it is just a matter of habit. You'll see!  :-)

Advantage of that: you have extra power while having to modes.

Vim, my old friend...


BASIC NAVIGATION (NOT ON INSERT MODE)

NOTE:  the behavior depends upon the keyboard type.
If not working, try the Fn key plus the shortcut.
Example: Fn + k

  • k – navigate upwards
  • j – navigate downwards
  • l – navigate right side
  • h – navigate left side
  • 0 – go to the starting of the current line.
  • ^ – go to the first non blank character of the line.
  • $ – go to the end of the current line.
  • g_ – go to the last non blank character of the line.
  • H – Go to the first line of current screen.
  • M – Go to the middle line of current screen.
  • L – Go to the last line of current screen.
  • ctrl+f – Jump forward one full screen.
  • ctrl+b – Jump backwards one full screen
  • ctrl+d – Jump forward (down) a half screen
  • ctrl+u – Jump back (up) one half screen
  • e – go to the end of the current word.
  • E – go to the end of the current WORD.
  • b – go to the previous (before) word.
  • B – go to the previous (before) WORD.
  • w – go to the next word.
  • W – go to the next WORD.
  • { – Go to the beginning of the current paragraph. By pressing { again and again move to the previous paragraph beginnings.
  • } – Go to the end of the current paragraph. By pressing } again and again move to the next paragraph end, and again.
  • N% – Go to the Nth percentage line of the file.
  • NG – Go to the Nth line of the file.
  • G – Go to the end of the file.
  • `” – Go to the position where you were in NORMAL MODE while last closing the file.
  • `^ – Go to the position where you were in INSERT MODE while last closing the file.
  • g – Go to the beginning of the file.
  • % – Go to the matching braces, or parenthesis inside code.
  • Use ‘.’ to repeat the last command.
    The command will be repeated considering the current caret position.

MORE DETAILED INFORMATION, SEE:

No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...