References

General

  • Nearly all commands can be preceded by a number for a repeat count. eg. 5dd delete 5 lines
  • <Esc> gets you out of any mode and back to command mode
  • Commands preceded by : are executed on the command line at the bottom of the screen
  • :help help with any command

Navigation

  • Cursor movement: โ†h โ†“j โ†‘k lโ†’
  • By words:
    • w next word (by punctuation); W next word (by spaces)
    • b back word (by punctuation); B back word (by spaces)
    • e end word (by punctuation); E end word (by spaces)
  • By line:
    • 0 start of line; ^ first non-whitespace
    • $ end of line
  • By paragraph:
    • { previous blank line; } next blank line
  • By file:
    • gg start of file; G end of file
    • 123G go to specific line number
  • By marker:
    • mx set mark x'x go to mark x
    • '. go to position of last edit
    • ' ' go back to last point before jump
  • Scrolling:
    • ^F forward full screen; ^B backward full screen
    • ^D down half screen; ^U up half screen
    • ^E scroll one line up; ^Y scroll one line down
    • zz centre cursor line

Editing

  • u undo; ^R redo
  • . repeat last editing command

Inserting

All insertion commands are terminated with <Esc> to return to command mode.

  • i insert text at cursor; I insert text at start of line
  • a append text after cursor; A append text after end of line
  • o open new line below; O open new line above

Changing

All change commands except r and R are terminated with <Esc> to return to command mode.

  • r replace single character; R replace multiple characters
  • s change single character
  • cw change word; C change to end of line; cc change whole line
  • c<motion> changes text in the direction of the motion
  • ci( change inside parentheses (see text object selection for more examples)

Deleting

  • x delete char
  • dw delete word; D delete to end of line; dd delete whole line
  • d<motion> deletes in the direction of the motion

Cut and paste

  • yy copy line into paste buffer; dd cut line into paste buffer
  • p paste buffer below cursor line; P paste buffer above cursor line
  • xp swap two characters (x to delete one character, then p to put it back after the cursor position)

Blocks

  • v visual block stream; V visual block line; ^V visual block column
    • most motion commands extend the block to the new cursor position
    • o moves the cursor to the other end of the block
  • d or x cut block into paste buffer
  • y copy block into paste buffer
  • > indent block; < unindent block
  • gv reselect last visual block

Global

  • :%s/foo/bar/g substitute all occurrences of "foo" to "bar"
    • % is a range that indicates every line in the file
    • /g is a flag that changes all occurrences on a line instead of just the first one

Searching

  • / search forward; ? search backward
  • * search forward for word under cursor; # search backward for word under cursor
  • n next match in same direction; N next match in opposite direction
  • fx forward to next character xFx backward to previous character x
  • ; move again to same character in same direction; , move again to same character in opposite direction

Files

  • :w write file to disk
  • :w name write file to disk as name
  • ZZ write file to disk and quit
  • :n edit a new file; :n! edit a new file without saving current changes
  • :q quit editing a file; :q! quit editing without saving changes
  • :e edit same file again (if changed outside vim)
  • :e . directory explorer

Windows

  • ^Wn new window
  • ^Wj down to next window; ^Wk up to previous window
  • ^W_ maximise current window; ^W= make all windows equal size
  • ^W+ increase window size; ^W- decrease window size

Source Navigation

  • % jump to matching parenthesis/bracket/brace, or language block if language module loaded
  • gd go to definition of local symbol under cursor; ^O return to previous position
  • ^] jump to definition of global symbol (requires tags file); ^T return to previous position (arbitrary stack of positions maintained)
  • ^N (in insert mode) automatic word completion

Show local changes

Vim has some features that make it easy to highlight lines that have been changed from a base version in source control. I have created a small vim script that makes this easy: http://github.com/ghewgill/vim-scmdiff

  1. autoenv ์„ค์น˜
git clone git://github.com/kennethreitz/autoenv.git ~/.autoenv 
echo โ€˜source ~/.autoenv/activate.shโ€™ >> ~/.zprofile #ํ˜น์€ .bash_profile source ~/.zprofile #ํ˜น์€ .bash_profile

2. autoenv ๋””๋ ‰ํ† ๋ฆฌ์— ์„ค์ •

mkdir autoenvDir cd autoenvDir 
echo โ€œconda activate py36โ€ > .env

3. autoenv ๋™์ž‘ ํ™•์ธ

# .env ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ๋†“์€ ํด๋”๋กœ ์ด๋™์‹œ autoenv ๋™์ž‘์„ ํ™•์ธํ•œ๋‹ค 
cd autoenvDir
autoenv:
autoenv: WARNING:
autoenv: This is the first time you are about to source /home/jjeaby/autoenvDir/.env:
autoenv:
autoenv: โ€” โ€” (begin contents) โ€” โ€” โ€” โ€” โ€” โ€” โ€” โ€” โ€” โ€” โ€” โ€” โ€”โ€” โ€” โ€” โ€” โ€”
autoenv: conda deactivate $ autoenv: conda activate py36$
autoenv:
autoenv: โ€” โ€” (end contents) โ€” โ€” โ€” โ€” โ€” โ€” โ€” โ€” โ€” โ€” โ€” โ€” โ€”โ€” โ€” โ€” โ€” โ€” โ€”
autoenv:
autoenv: Are you sure you want to allow this? (y/N) y
(py36) โžœ

ssh -i keyfile.pem -L 8888:localhost:8888 ๊ณ„์ •@10.1.1.1

Oh My Zsh์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Bash
Copy

์ž๋™์œผ๋กœ ์„ค์น˜๊ฐ€ ์ง„ํ–‰๋˜๊ณ , ๋งˆ์ง€๋ง‰์— zsh๋ฅผ ๊ธฐ๋ณธ ์‰˜๋กœ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด ํ˜„ ์‚ฌ์šฉ์ž ๊ณ„์ •์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

๋ฐ”๋กœ ํ”Œ๋Ÿฌ๊ทธ์ธ 2๊ฐœ๋ฅผ ์„ค์น˜ํ•ด์ค๋‹ˆ๋‹ค.

# zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# zsh-autosuggestions
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
Bash
Copy

ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์ ์šฉ์‹œํ‚ค๊ธฐ ์œ„ํ•ด .zshrc๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์ฒ˜๋Ÿผ plugins=( ) ์— zsh-... ๋‘ ์ค„์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

vi ~/.zshrc
Bash
Copy
...

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
  git
  zsh-syntax-highlighting
  zsh-autosuggestions
)

...
Bash
Copy
source ~/.zshrc
Bash
Copy

๋‹ค ์„ค์น˜๋์–ด์š”. ๊ฐ„๋‹จํ•œ ์˜ˆ์‹œ ์Šคํฌ๋ฆฐ์ƒท์„ ๋ณด์—ฌ๋“œ๋ฆด๊ฒŒ์š”.

์•„๋ž˜ ์Šคํฌ๋ฆฐ์ƒท์€ ์—†๋Š” ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ• ๋•Œ์™€ ๋ช…๋ น์–ด ์ž๋™ ์™„์„ฑ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค. ๋ณด์‹œ๋ฉด ๋ฐ”๋กœ ์ดํ•ด๊ฐ€ ๋  ๊ฑฐ์˜ˆ์š”.

์ŠคํŽ ๋ง ๊ฒ€์‚ฌ ๊ธฐ๋Šฅ์„ ์ผ  ๋’ค ํ…Œ์ŠคํŠธํ•ด๋ดค์Šต๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  git repository ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™ํ–ˆ์„ ๋•Œ ์ž…๋‹ˆ๋‹ค.

+ Recent posts