Setup Vim Python Dev Env

https://realpython.com/vim-and-python-a-match-made-in-heaven/

notes

reload .vimrc

# if you are editing .vimrc
# so: source
# %: current file
:so %

increase/decrease the number under the cursor

<Ctrl + A>: increase
<Ctrl + X>: decrease

put the current line in center/top/bottom

z. or zz puts current line to center of screen
zt puts current line to top of screen
zb puts current line to bottom of screen

buffer

# switch buffer
:b1  (buffer number)
# open the buffer in a split view(vertically)
:sb 1 (buffer number)
# open the buffer in a split view(horizontally)
:vert sb 1(buffer number)

copy to/paste from clipboard

"*y
"*p

Moving around

e 
Move to the end of a word.

w 
Move forward to the beginning of a word.

3w 
Move forward three words.

W 
Move forward a WORD (any non-whitespace characters).

b 
Move backward to the beginning of a word.

3b 
Move backward three words.

$ 
Move to the end of the line.

0 
Move to the beginning of the line.

^ 
Move to the first non-blank character of the line.

) 
Jump forward one sentence.

( 
Jump backward one sentence.

} 
Jump forward one paragraph.

{ 
Jump backward one paragraph.

j
Jump forward one line.

k 
Jump backward one line.

H 
Jump to the top of the screen.

M 
Jump to the middle of the screen.

L 
Jump to the bottom of the screen.

10<PageUp> or 10<CTRL-B>
Move 10 pages up.

5<PageDown> or 5<CTRL-F>
Move 5 pages down.

G 
Jump to end of file.

1G 
Jump to beginning of file (same as gg).

50G 
Jump to line 50.

mx 
Set mark x at the current cursor position.

'x 
Jump to the beginning of the line of mark x.

`x 
Jump to the cursor position of mark x.

''
Return to the line where the cursor was before the latest jump.
(Two single quotes.)

``
Return to the cursor position before the latest jump (undo the jump).
(Two back ticks. This is above the Tab key on some keyboards.)

'. 
Jump to the last-changed line.

 % 
Jump to corresponding item, e.g. from an open brace to its matching closing brace. See Moving to matching braces for more.

Tips

Normal Mode

Vim Manual

  • :h vimtutor: vimtutor
  • :h [COMMAND]: help

Search

  • *: Search forward for the word nearest to the cursor
  • n: Repeat the latest / or ?.

Mini Macro

  • .: Repeat last change
  • u: Undo changes.

Mark

  • m{a-zA-Z}: Set mark {a-zA-Z} at cursor position.
  • \{a-z}`: Jump to the mark {a-z} in the current buffer.

Find

  • f{char}: To the occurrence of {char} to the right.
  • t{char}: Till before the occurrence of {char} to the right.
  • ;: Repeat latest f, t, F or T.
  • ,: Repeat latest f, t, F or T in opposite direction.

Change

  • c{motion}: Delete {motion} text and start insertion.
  • cw: delete a word and enter insert mode.

Text object

  • aw: a word, select words, including leading or trailing white space.
  • ap: a paragraph.

Yank

  • y{motioni}: Yank {motion} text.
  • yy: Yank [count] lines. Default: yank current line.

Delete

  • d{motion}: Delete text that {motion} moves over.
  • daw: delete a word.
  • D: Delete the characters under the cursor until the end of the line.

g command

  • gu{motion}: Make {motion} text lowercase.
  • guu: Make current line lowercase.
  • gUaw: Make a word uppercase.
  • g~{motion}: Switch case of {motion} text.
  • g~~: Switch case of current line.
  • ga: Print the ascii value of the character under the cursor.

Ctrl

  • CTRL-a: Add [count] to the number or alphaberic character at or after the cursor.
  • CTRL-x: Subtract [count] to the number or alphaberic character at or after the cursor.

Substitute

  • :[range]s[ubstitute]/{pattern}/{string}/[flags] [count]: For each line in [range] replace a mathc of {patten} with {string}.
  • :%s/foo/bar/gc: replace all foo to bar globally with confirmation.

Compound command

  • C: c$
  • s: cl
  • S: ^c
  • I: ^i
  • A: $a
  • o: A
  • O: ko

Insert Mode

  • CTRL-h: Delete previous word.
  • CTRL-u: Detete to the start of the line.
  • ESC or CTRL-[: Back to normal mode.
  • CTRL-o: Switch to insert-normal mode.

  • CTRL-r{register}: Insert the contents of a register. :h i_CTRL-R_CTRL-P
  • CTRL-r=: the expression register
  • CTRL-v{code}: Insert next non-digit literally.
  • CTRL-k{char1}{char2}: Enter digraph.

Replace Modde

  • R: Enter Replace mode.

Vimrc

https://github.com/amix/vimrc/blob/master/vimrcs/basic.vim http://www.guckes.net/vim/setup.html

" Use spaces instead of tabs
set expandtab

" Be smart when using tabs ;)
set smarttab

" 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4

" Linebreak on 500 characters
set lbr
set tw=500

set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines

" Set line length ruler of 80 char
set colorcolumn=80

" show line number
set number

" backspace
set bs=2

" turn on syntax highlighting
syntax on