vim编辑器常用操作

ctrl+F 向下翻页
ctrl+B 向下翻页
u 取消最近一次操作
U 取消当前行的操作
ZZ 保存当前内容并退出
gg 跳转至第一行
G 跳转至最后一行
#gg 跳转至#行 :
w /root/123.txt 另存为 :e ~/newfile 打开新文件进行编辑 :r /newfile 读入其他文件内容 :s /old/new/ 查找字符并替换+g替换所有;+c对每个替换动作进行确认 :#,# s/old/new/g 替换行号#,#内的字符 J 合并当前行和下一行 :1,2 co 3 复制第一行,第二行到第三行后 :syntax off(on) 开启(关闭)高亮

设置Tab键为4个空格

[root@www PythonTest]# tail -5 /etc/vimrc
"设置Tab键为4个空格
set ts=4
set expandtab
set autoindent

 设置自动行缩进

[root@localhost tmp]# tail -16 /etc/vimrc 

"设置自动缩进
set autoindent
set cindent

 自动加入文件头

[root@www ~]# tail -25 /etc/vimrc

" 设置自动加入文件头

autocmd BufNewFile *.sh,*.py exec ":call SetTitle()"
func SetComment_sh()
    call setline(3,"#文件名称:".expand("%:t"))
    call setline(4,"#创建者:MrChen")
    call setline(5,"#创建日期:".strftime("%Y年%m月%d日"))
    call setline(6,"#描述:")
endfunc

func SetTitle()
    if &filetype == 'sh'
        call setline(1,"#!/bin/bash")
        call setline(2,"")
        call SetComment_sh()
    endif

    if &filetype == 'python'
        call setline(1,"#!/usr/bin/python3.6")
        call setline(2,"# -*- coding utf-8 -*-")
        call SetComment_sh()
    endif
endfunc
autocmd BufNewfile * normal G

 

posted @ 2018-08-28 22:28  畅优植物乳杆菌  阅读(137)  评论(0编辑  收藏  举报