Skip to content

Princess-Sunset-Shimmer/vim_fast-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

123 Commits
 
 
 
 

Repository files navigation

vim fast-cheatsheet

basic editing

open save and quit:

        vim /directory/file    /* open file.s */
        :w                     /* save file */
        :q                     /* quit */
        :wq                    /* save and quit */
        :q!                    /* quit without save */

mode switch:

Esc normal mode
I inset mode
/ search mode
: command mode
V visual mode
Ctrl + V vidual block mode
Shift + R replace mode

cursor control:

H J K L are ⬅️ ⬆️ ⬇️ ➡️ that every vim user knows

W forword
B backword

Shift + $ tail of line
0 mane of line

Shift + G goto tail of file
G + G goto mane of file

F + ANY_KEY move cursor to next position that match key you type

        :255                   /* goto line 255 of file */

folding:

Z + F manually create a fold from a selection
Z + A fold or open automatically
Z + O open fold
Z + C close fold
Z then Shift + R open all folds
Z then Shift + M close all folds

contents edit:

U undo
Ctrl + R redo

A insert after current char
Shift + A insert at end

O insert below current line
Shift + O insert above current line

        :read !SHELL_COMMAND   /* run shell command and insert its output into current file */

example: you can use this trick to read long output from a command without save it

        vim
        :read !SHELL_COMMAND --help
        :q!

general text editing gramma:

        [COUNT] operation [text_object or cursor_control]
        :[range] command [arguments]

frequently used operation:
X cut
D delete
D + D delete line
C change (delete + insert)
R replace single char
G + U lower the case
G then Shift + U upper the case
< indent left
> indent right
= indent auto
Y yank (copy)
Y yank line
P paste



frequently used text object:
I + W
I + S
I + P
I + '
I + "
I + `
I + (
I + [
I + {
I + <

A + W
A + S
A + P
A + '
A + "
A + `
A + (
A + [
A + {
A + <


exsamples:
C + I + W change inner word

X cut current char or selected chars
3 + X cut three chars; 4 + X cut four chars and so on

D + D cut current line
4 then D + D cut 4 lines; 5 then D + D cut 5 lines and so on

D + W cut forword
D + B cut backword

D + $ cut to end
D + 0 cut to home

        :7,19d                /* cut contents from line 7 to 19 */
        :7,$d                 /* cut dontents from line 7 to bottom */
        :%d                   /* cut all */

Y copy selection

Y + Y copy current line
2 then Y + Y copy 2 lines

Y +W copy forword
Y + B copy backword

Y + $ copy to end
Y + 0 copy to home

        :3,9y                 /* copy contents from line 3 to 9 */
        :3,$y                 /* copy contents from line 3 to bottom */
        :%y                   /* copy all */

P paste
3 + P paste 3 times

search and replace:

Ctrl + N or Ctrl + P in insert mode, search and auto complete current word

        /mlp-fim               /* search mlp-fim */

N highlight next
Shift + N hilghight previous


        :%s#a#b#g
        :%s/a/b/g              /* replace a, b --all */
        :%s#a#b#gc
        :%s/a/b/gc             /* replace a, b --all --interactive-confirm */
        :26,37s#a#b#g
        :26,37s/a/b/g          /* replace a, b --start=26 --end=37 */
        :21,$s#a#b#g
        :21,$s/a/b/g           /* replace a, b --start=21 --end=end */

multi files

buffers:

        vim /directory/file0 /directory/file1 /directory/file2 ... /* open multi files */
        :n                     /* switch to next file */
        :N                     /* switch to previous file */
        :e /directory/file     /* open another file */
        :buffers               /* show all file buffers */
        :buffer 1              /* goto file buffer 1 */

netrw:

        vim /directory          /* open vim and explore specified directory */
        :Ex                     /* explore current directory */
        :Ex /directory          /* explore specified directory */

G + H hide or show hidden .files and ./directories
S toggle sort by name, size, time and exten

- go previous directory
J and K navigate up and down

Shift + R rename a file
Shift + D delete a file
D create a directory
Shift + % create a file

Enter open file
O open file in new hrizontal split
V open file in new vertical split
t open file in new tab

Ctrl + W then H J K L nevigate between file splits
G + T go to next tab
G then Shift + T go to previous tab


vim configuration

system wide config file: /etc/vimrc
user specific config file: ~/.vimrc

        :set number             /* show line number */
        :set nowrap             /* do not wrap text */
        :set cursorline         /* show cursor line */
        :set cursorcolumn       /* show cursor column */
        :set foldmethod=indent  /* fold by code indent. other methods: manual, syntax, marker, foldable block, expr */
        :set expandtab          /* expand tab to spaces */
        :set tabstop=4          /* now tab width looks like 4 spaces */
        :set softtabstop=4      /* now tab width acts like 4 spaces */
        :set shiftwidth=4       /* now shift width is 4 spaces */
        :set autoindent         /* turn on indent */
        :set smartindent        /* enhance indent */
        :set incsearch          /* incremental search */
        :set hlsearch           /* hilight search */

Licence: CC BY-SA 4.0

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors