The Standard Editor on Unixes

Published -  2021-03-10

vim - The Standard Editor on Unixes

Brown Bag Session for my colleagues at 320EAST GmbH

Overview

  • History of vim
  • What is „vi / vim“ good for?
  • Using vi
    • Normal Mode
    • Insert Mode
    • Visual Mode
    • Command Mode
  • More…

+++

History of vim

The default Text-Editors on UNIX Systems

  • „ed“ (1969)
  • „ex“ the extended „ed"
  • „vi“ (1976) stands for „Visual“ Editor
  • „vim“ is the „vi improved“ (1991)

+++

What is „vim“ good for?

  • Edit configuration files on the server
  • Do some Quick changes in some Software
  • Edit git Commit Comments
  • For coding / software development (with plugins)

+++

Why VIM?

  • Use remotely via SSH or telnet or serial console
  • Works without GUI / Mouse
  • Available on every Unix / Linux System
  • It is very fast

+++

Editor Modes

  • Normal Mode (the default mode, use for navigation)
  • Insert Mode (edit mode)
  • Visual Mode
  • Command Mode

Switching the modes:

  • exit Edit Mode with ESC Key
  • enter Command Mode with :

Starting Vim

Edit a single file

$ vim test.py

Edit a single file on line 45

$ vim test.py +45

+++

Normal Mode 🤨

Move Cursor: h j k l

Go to end of Line $ Go to start of Line 0

Start of File :1 End of File G

+++

Advanced Navigation

  • Jump to beginning of next/previous Word w / b
  • Jump to end of current Word e

Repeat

  • Jump left 5 characters / words 5l / 5w
  • Go down 10 lines 10j

+++

Search

  • Find next „$“ in the current line f$
  • Find previous „$“ in the current line F$
  • repeat with ;
  • Find string /
    • find next n
    • find previous N

+++

Insert Mode ✍️

Editing Basics 1/2

  • insert text at current position i

    • go back to normal mode with ESC
  • delete word dw
  • delete to end of line D

  • change one / 5 character r / 5r
  • change word cw
  • change until end of line c$

undo u (multiple times possible)

+++

Editing Basics 2/2

  • repeat editing (best in combination with find)

  • change next 3 words 3cw
  • change until next comma ct,
  • change until next space cf_ (including space)

  • repeat last change with .

+++

Visual Mode 🤓

  • Enter visual mode v (char) or V (line)

    • then move the cursor
  • Block mode CTRL v
    • then edit e.g. with c (change) or d (delete)
    • convert to upper or lower case gU / gu

+++

Command Mode 🤡

Commands 1/2

Go to Command mode from Normal mode with :

Exit without save

:q or force exit :q!  

Write changes

:w or force write :w!

Write and quit

:wq or :x  with force :wq!  or :x!

+++

Commands 2/2

Go to Command mode from Normal mode with :

Edit a different file

:e <filename>
:vsplit <filename> (open in split mode)

Read the contents of a different file into current

:r <filename>

+++

Settings

Enable / Disable line numbers

:set number
:set nonumber

Enable or disable syntax highlight

:syntax on
:syntax off

Force syntax

:set syntax=json

+++

Configuration File ~/.vimrc

Minimal nice configuration:

" enable vim mode
set nocompatible

set encoding=utf-8

" find recursive in all folders and sub folder
set path+=**

" menu to tab through after find
set wildmenu

" enable syntax highlight
syntax on

" Highlight search results
set hlsearch

+++

More

  • File Browser „netrw“
  • More on Split views
  • Multiple Diff views (use as git difftool)
  • Multiple Buffers
  • Macros

  • Plugins
    • Autocomplete
    • Linter
    • Powerline
    • CTRL-P

Links:

+++

Thanks

:wq!  😁