Skip to content

Instantly share code, notes, and snippets.

@rain1024
Last active May 10, 2023 05:15
Show Gist options
  • Save rain1024/4594aa7264ff3ea65861 to your computer and use it in GitHub Desktop.
Save rain1024/4594aa7264ff3ea65861 to your computer and use it in GitHub Desktop.
vim

Vim is awesome!

Cheatsheet

image

Challenge

image image
Vimgolf.com, (2014). VimGolf - real Vim ninjas count every keystroke!. [online] Available at: http://vimgolf.com/ [Accessed 11 Jul. 2014]. Vim-adventures.com, (2014). VIM Adventures - Learn VIM while playing a game. [online] Available at: http://vim-adventures.com/ [Accessed 11 Jul. 2014].

Screencast

Interactive Vim

image

Books

h l k j
=> character left, right; line up, down
b w
=> word/token left, right
ge e
=> end of word/token left, right
{  }
=> beginning of previous, next paragraph
( )
=> beginning of previous, next sentence
0 gm
=> beginning, middle of line
^  $
=> first, last character of line
nG ngg
=> line n, default the last, first
n%
=> percentage n of the file (n must be provided)
n|
=> column n of current line
%
=> match of next brace, bracket, comment, #define
nH nL
=> line n from start, bottom of window
M
=> middle line of window

References

<z>

creates a fold from the cursor down # lines.
=>zf#j
creates a fold from the cursor to string .
=> zf/string 
zj moves the cursor to the next fold.
zk moves the cursor to the previous fold.
zo opens a fold at the cursor.
zO opens all folds at the cursor.
zm increases the foldlevel by one.
zM closes all open folds.
zr decreases the foldlevel by one.
zR decreases the foldlevel to zero -- all folds will be open.
zd deletes the fold at the cursor.
zE deletes all folds.
[z move to start of open fold.
]z move to end of open fold.
1. Movement
2. Editing (in progressing)
3. Finding (in progressing)
4. Repeating (in progressing)
5. Undo/Redo (in progressing)
6. Folding (in progressing)
7. Splitting: windows and tabs (in progressing)
8. Command (in progressing)

1. Movement {Normal Mode}

Text: h j k l

image

Word: e w 3w b 3b iw B W

Line: $ 0 ^

Sentence: ( )

Paragraph: } {

Screen: H M L

File: G 1G 50G

Back to last move: '' ``

Corresponding item: %

Move the cursor to positions where there isn't any text [2]

set virtualedit=all

2. Basic Edit

Put: <p>, <P>

Buffer

Working with many files

7. Splitting: windows and tabs

New tab

':tabe' ####New window ':new filename.txt'

Move between two window:

C-H, C-J C-K C-L C-W h, C-W j C-W k C-W l

Search and Replace

*:%s//x&x<CR>ZZ
:%s/<C-R><C-W>/x&x
:%s/aaa/x&x/g

input aaa aab output xaaax aab

8. Command {Command Mode}

Put

put=range(1,100)

Run system command

:! python shell.py

Repeat previous command

:!!

References

  1. Vim Tips Wiki, (2014). Moving around. [online] Available at: http://vim.wikia.com/wiki/Moving_around [Accessed 11 Jul. 2014].
  2. Vimdoc.sourceforge.net, (2014). Vim documentation: usr_25 Editing formatted text. [online] Available at: http://vimdoc.sourceforge.net/htmldoc/usr_25.html [Accessed 21 Jul. 2014].

Plugin List

Plugins

<NERDTree> <Ctrlp> <surround> <emmet> (RU: Zen coding) <numbers>

NerdTree

image

Show NerdTree

:NERDTree

Create folder

m a <folder_name> / y

Create file

m a <file_name> y

Bookmark

$ Bookmark
# show bookmark
$ B
# delete bookmark
Shift-D

Ctrlp

image

:CtrlP
Ctrl-p

Surround

image

Emmet

image

Type ("_" is the cursor position)

html:5_

Then type , (Ctrly,), and you should see:

<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    _
</body>
</html>

Numbers

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment