• Stars
    star
    133
  • Rank 264,045 (Top 6 %)
  • Language
    Vim Script
  • Created over 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

✌️ Just the basics to get you up and running with Vim

Vim Basics

Just the basics to get you up and running with Vim

This guide assumes some familiarity with the terminal. (See Unix Basics for a quick overview.)

Quick start

  1. Launch Vim via the terminal:

    $ vim Main.java

    You are now in Vim’s Command mode.

    (You should see the contents of Main.java if the file already exists. Otherwise you will see an empty text editor window.)

  2. You cannot type into or edit your file while in Command mode. To start typing into the file, you must switch to Vim’s Insert mode. Press i to do so. You should see -- INSERT -- on the bottom-left hand corner of your window. Now you can type as you would with any other text editor.

  3. When you’re done typing, press <Esc> to go back to Command mode. (The <Esc> key is your friend! Hitting <Esc> will bring you back to Command mode.)

  4. And… that’s about it, really! Now type :w and <Enter> to save the file, followed by :q! and <Enter> to quit Vim.

Commands

Almost all operations in Vim occur while in Command mode. Listed here are the more important commands that you should know.

Switching between Command and Insert mode

Action Keys
Switch to Command mode <Esc>
Switch to Insert mode i
Switch to Insert mode, moving the cursor to the end of the current line A
Switch to Insert mode, adding a new line under the current line, and moving the cursor to the new line o

Moving the cursor around the file

Action Keys
Page up <Ctrl> + u
Page down <Ctrl> + d
Move the cursor to the next word W
Move the cursor to the previous word b
Move the cursor to the start of the current line 0
Move the cursor to the end of the current line $
Move the cursor to a particular line of the file (eg. line number 9) 9G

Of course, you can also move the cursor using any of the arrow keys (, , , ), but it will be a lot faster to use the above commands.

Delete/cut

Action Keys
Delete the line under the cursor dd
Delete the word under the cursor dw
Delete the character under the cursor x

Because whatever you delete is copied into Vim’s clipboard, these 3 commands are akin to performing a cut.

Copy and paste

Action Keys
Copy the current line yy
Copy a particular number of lines, starting from the current line (eg. 3 lines) 3yy
Paste p

You can also specify the text to be copied using a text selection. It is a bit more involved, though:

  1. While in Command mode, press v to switch to Visual mode. You should see -- VISUAL -- on the bottom-left hand corner of your window.
  2. Move the cursor to adjust the text selection.
  3. When you have selected the text that you want to copy, press y. This will bring you back to Command mode, and the selected text will have been copied into Vim’s clipboard.

Undo and redo

Action Keys
Undo u
Redo <Ctrl> + r

Fixing code indentation

Action Keys
Fix the code indentation of the file gg=G

Save and quit

Action Keys
Save the file :w then <Enter>
Save the file then quit :wq then <Enter>
Quit without saving the file :q! then <Enter>

Settings

These are some of the commands to customise the display:

Action Keys
Enable syntax highlighting :syntax on then <Enter>
Enable line numbers :set number then <Enter>

Vim will look for a settings file named .vimrc in your home directory. You can avoid having to type the above settings for every new Vim session by putting the following in your ~/.vimrc:

syntax on
set number

The <Ctrl> + z “problem”

Remember that the command for undo is simply u, not Ctrl + z!

If you’d accidentally pressed Ctrl + z, you will find yourself back in your terminal, where you will see something like the following:

[1]+  Stopped                 vim Main.java

A quick fix is to issue the fg command:

$ fg

This will bring us back to Vim, and all is well with the world.

(Explanation: Pressing <Ctrl> + z places the currently-running program in the background. Here, the currently-running program is Vim. The fg program simply brings the most recent “backgrounded” program back to the foreground.)

See also

More Repositories

1

vdx

🎞️ An intuitive CLI for processing video, powered by FFmpeg
TypeScript
1,659
star
2

charming

🎩 Lettering.js in vanilla JavaScript
JavaScript
1,003
star
3

create-figma-plugin

🔋 The comprehensive toolkit for developing plugins and widgets for Figma and FigJam
TypeScript
867
star
4

malarkey

⌨️ Simulate a typewriter effect in vanilla JavaScript.
JavaScript
238
star
5

figma-plugins

🔥 Monorepo for my Figma plugins
TypeScript
228
star
6

ffmpeg-cheatsheet

📼 A cheatsheet for common video processing operations in FFmpeg
175
star
7

load-google-maps-api

🌏 A lightweight Promise-returning helper for loading the Google Maps JavaScript API
JavaScript
170
star
8

stable-diffusion-rest-api

🤗 Run Stable Diffusion locally via a REST API on an M1/M2 MacBook
TypeScript
124
star
9

line-clamp

🗜️ Line clamp a DOM element in vanilla JavaScript
JavaScript
75
star
10

autosize-input

🎈 Effortless, dynamic-width text boxes in vanilla JavaScript
JavaScript
67
star
11

figma-plugins-stats

📈 A CLI to get live and historical stats for your Figma plugins
TypeScript
60
star
12

cuba

🇨🇺 Google Sheets + SQL = JSON
JavaScript
53
star
13

single-page-markdown-website

🌶️ Create a nice single-page documentation website from one or more Markdown files
TypeScript
44
star
14

menu-aim

🎯 Instant mega menus in vanilla JavaScript.
JavaScript
39
star
15

fastmatter

👀 A fast frontmatter parser. Supports both string and stream inputs.
JavaScript
28
star
16

awesome-create-figma-plugin

27
star
17

generate-css

💥 Dynamically generate functional CSS classes from HTML and JavaScript source files
TypeScript
16
star
18

stoke

🌲 Generate the Abstract Syntax Tree (AST) of a Bash command
JavaScript
15
star
19

regular-expressions-cheatsheet

🅰️ A concise cheatsheet for using Regular Expressions in JavaScript
JavaScript
15
star
20

gulp-tape

👻 Run Tape tests in Gulp.
JavaScript
14
star
21

generate-ts-docs

📘 Utilities to parse type information and JSDoc annotations from TypeScript source files, and render Markdown documentation
TypeScript
12
star
22

macos-keyboard-shortcuts

⌨️ A CLI to set application-specific keyboard shortcuts for macOS
TypeScript
12
star
23

shell-basics

🐚 A quick overview of the Unix shell
11
star
24

rdd

📝 Preview your Markdown locally as it would appear on GitHub, with live updating
JavaScript
11
star
25

code-problems

🐫 Working through code problems in OCaml
OCaml
7
star
26

git-cheatsheet

🌳 A handy list of commonly used Git commands
6
star
27

interpolate

Simple string interpolation in PHP.
PHP
5
star
28

sketch-plugin-helper

Utilities to help you make Sketch plugins
JavaScript
5
star
29

sketch-plugins

Monorepo for my Sketch plugins
JavaScript
5
star
30

quine

✍️ Programs that write themselves.
Shell
5
star
31

grouper

Assign objects to groups by one or more properties, by object value, or by using a comparator function.
JavaScript
4
star
32

modal

Super-simple modals in vanilla JavaScript.
JavaScript
4
star
33

react-redux-modal

🔮 A React modal bound to the Redux store.
JavaScript
4
star
34

yuanqing.sg

⚪ My personal website
HTML
3
star
35

widget

TypeScript
3
star
36

sketch-handbook

📙 A concise handbook on working precisely and effectively in Sketch
Shell
3
star
37

figma-plugins-monetization-stats

JavaScript
3
star
38

figma-add-auto-layout-item

TypeScript
2
star
39

versus

Compare two variables with the comparison operator specified as a string.
JavaScript
2
star
40

google-sheets-rest-api

JavaScript
2
star
41

q

🍦 An opinionated CLI for creating lightweight, vanilla HTML/CSS websites
JavaScript
2
star
42

jockey

Modelling a playlist that supports shuffle, repeat, and reordering.
JavaScript
2
star
43

xoxo

🎧 A YouTube mixtape maker thing.
JavaScript
2
star
44

extract

Sugar for getting data out of strings in PHP.
PHP
2
star
45

asset-versioning

🗃️ Version your assets by appending a hash to the filename.
JavaScript
2
star
46

fi

Query a collection of text files like a document database in PHP.
PHP
2
star
47

Q.js

A micro JavaScript library.
JavaScript
2
star
48

shared-event-listeners

A utility for minimising the number of event listeners bound on a given DOM element.
JavaScript
2
star
49

create-figma-plugin-react-example

JavaScript
2
star
50

sketch-add-artboard-borders-and-titles

JavaScript
2
star
51

figmake

🍦 A tiny CLI for making Figma plugins in HTML, CSS, and vanilla JavaScript
TypeScript
2
star
52

savoy

Higher-order functions (synchronous and asynchronous each/eachSeries/map/filter/fold) and functions for flow control (parallel/series/waterfall) in under 1 KB.
JavaScript
1
star
53

string-extractor

Regular expression sugar for getting data out of strings.
JavaScript
1
star
54

cli

TypeScript
1
star
55

cors

JavaScript
1
star
56

kontact

An extensible contact form in PHP and vanilla JavaScript/AJAX.
JavaScript
1
star
57

abstract-backup

💾 Download a local backup of the Sketch files from all your Abstract projects
JavaScript
1
star
58

sketch-sort-layer-list

JavaScript
1
star
59

clinical

💊 A minimum-viable arguments parser in ~90 LOC with zero dependencies
TypeScript
1
star
60

sketch-select-layers

JavaScript
1
star
61

npm-boilerplate

Barebones boilerplate using `npm run-script`.
JavaScript
1
star
62

google-sheets

🍃 An easier interface to read from and write to Google Sheets
JavaScript
1
star
63

sketch-clean-document

JavaScript
1
star
64

gulp-boilerplate

A Gulp-powered boilerplate for Node and JavaScript projects.
JavaScript
1
star
65

segue

Enqueue functions, and call them in series.
JavaScript
1
star
66

unfurl

Extract the query string and hash of a URL.
JavaScript
1
star
67

sketch-extract-text

JavaScript
1
star
68

bbqr

JavaScript
1
star
69

sketch-move-layers

JavaScript
1
star
70

pppath

Join strings to form a valid file path.
JavaScript
1
star
71

screen-recorder

JavaScript
1
star
72

simple-code-editor

TypeScript
1
star
73

resizable

TypeScript
1
star
74

svg-inserter

TypeScript
1
star
75

build-website

TypeScript
1
star
76

.github

1
star
77

eslint-config-yuanqing

⚙️ An opinionated ESLint configuration for TypeScript and Preact projects
JavaScript
1
star
78

append-js-extension-to-local-imports

JavaScript
1
star
79

stylelint-config-yuanqing

🕴️ An opinionated stylelint configuration
JavaScript
1
star
80

sketch-draw-slice-over-selection

JavaScript
1
star
81

sketch-align-to-grid

JavaScript
1
star
82

frontend-boilerplate

🌱 Super basic web boilerplate with Sass and vanilla JavaScript.
HTML
1
star
83

isomorphic

JavaScript
1
star
84

tsu

Utilities and functional wrappers over `through2`.
JavaScript
1
star
85

sketch-rename-layers

🖋️ [WIP] A Sketch plugin to automate layer renaming
JavaScript
1
star
86

johnson-trotter

An implementation of the Johnson-Trotter permutation algorithm.
JavaScript
1
star
87

rectify

Unsmarten your quotes, dashes, and ellipses.
JavaScript
1
star
88

react-autocomplete

[UNMAINTAINED] React autocomplete component with an opinionated UX.
JavaScript
1
star