---
title: "vim preferences"
author: "asran"
date: "2010-12-26T15:06:16Z"
tags: []
categories: ["操作系统"]
slug: "vim-preferences"
draft: false
lastmod: "2011-01-08T11:35:21Z"
id: 852185
url: "https://asran.iteye.com/blog/852185"
---

How to use 4 spaces instead of tab in vim:

  1 :set ts=4

  2 :set number

  3 :set autoindent

  4 :set expandtab

  5 :set softtabstop=4

  6 :set shiftwidth=4

:set showmode

:set number

:set nonumber

:set ts=2 --------- display tab as 2 size(or add \[:set ts=2] in ~/.vimrc, if not existing, just create one)

vim

========================================================

hjkl -------move cursor

x  ---------- remove character

dd ---------- cut whole line

Y/yy ---------- copy one line

nY ------------ copy n line

yG ------------ copy to the end of file

yw ------------ copy to the end of word(inline)

y$ ------------ copy to the end of line (inline)

P ------------- paste above/before

p ------------- paste below/after

J  ---------- join two lines

u  ---------- undo

Ctrl-R ---------- redo

U ------------undo whole line

a -------------append

o -------------insert new line under current row

O -------------insert new line above current row

9k

3x

ZZ -------------write and exit

:q! ------------exit without saving

:e! ------------reload file content

:help

gg ------------- go header

G -------------- go bottom

nG ------------- go n-th line below

H -------------- header

M --------------- middle

L --------------Last

Ctrl-G ----------tell where am i

Ctrl-U ---------- move up

Ctrl-D ---------- move down

Ctrl-E

Ctrl-Y

Ctrl-F

Ctrl-B

zz -------------- bring the current row to the middle of screen

zt -------------- to top

zb -------------- to bottom

/search

?search

n ------------next

N ------------opposite direction search

search and replace:

:&lt;start-line&gt;,&lt;end-line&gt;/&lt;search-regex&gt;/&lt;replacement&gt;/g

eg. :1,$s/\[\\t| ]\*$//g  &lt;---- remove all redundant tabs and whitespaces

or   :%s/\[\\t| ]\*$//g    &lt;---- %s equals 1,$s