Vim

Basic usage of vim.

.vimrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
set ignorecase 
set hlsearch
set encoding=utf-8
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set cursorline
set autoindent
set smartindent
set scrolloff=4
set showmatch
set number

set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set fileformat=unix

colorscheme desert

set nocompatible " required
filetype off " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" Add all your plugins here (note older versions of Vundle used Bundle instead of Plugin)
Plugin 'Chiel92/vim-autoformat'
nnoremap <F6> :Autoformat<CR>
let g:autoformat_autoindent = 0
let g:autoformat_retab = 0
let g:autoformat_remove_trailing_spaces = 0


" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required

vundle

https://github.com/VundleVim/Vundle.vim

1
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim 

Put this in your .vimrc.

1
Plugin 'Chiel92/vim-autoformat'

Then restart vim and run :PluginInstall.

注意这里 autoformat 要对 Python 起作用的话还要安装 autopep8:

1
pip install autopep8

syntax

1
2
cd /usr/share/vim/vim74/syntax 
vi python.vim
1
syn keyword pythonTodo      FIXME NOTE NOTES TODO XXX contained
1
2
$ ls ~/.vim/
ftdetect ftplugin indent syntax

color

1
2
3
ls /usr/share/vim/vim74/colors/
vi ~/.vimrc
color default

|

80| should get you to position 80 in that line.

d

1
2
dG 删除直到工作缓存区结尾的内容
d1G 删除直到工作缓存区开始的内容

删除第9行到第200行的内容(先用200G转到第200行) ,使用

1
:9,.d

e

重新加载

1
:e

J

合并行

In command mode:

1
[range]j[lines]

here you want to do the whole buffer:

1
%j

If you just wanted to do 10 lines from the current cursor position:

1
j10

If you dont want to replace the new lines with spaces use ! after j.

1
2
%j!
j!10

And for the uberfancy:

1
5j20

Would go to line 5, and join the next 20 lines.

ret

set tabstop=4: set the tabs to display as four spaces.
set expandtab: insert spaces for tabs.
ret: replace tab

1
2
set expandtab
:%ret! 4

s

1
:%s/源字符串/目的字符串/g

Add a string(*) to the end of each line in Vim:

1
:%s/$/\*/g

set

  • nu
1
2
set nu
set nonu
  • paste
1
set paste
  • invlist
1
2
set invlist
set nolist

shell

1
2
ctrl+z 
fg
1
:!vim --version
1
:shell

undo, redo

  • u
  • ctrl+r

vsp

1
2
3
4
vim -On file1 file2 # 分屏启动Vim
:vsp filename # 分屏
Ctrl+w r # 滚动分屏
Ctrl+w = # 分屏宽度