zoukankan      html  css  js  c++  java
  • vim

    命令模式

    文本模式

    末行模式

    vim基础操作
    进入插入模式:
    i: 插入光标前一个字符
    I: 插入行首
    a: 插入光标后一个字符
    A: 插入行未
    o: 向下新开一行,插入行首
    O: 向上新开一行,插入行首
    进入命令模式:
    ESC:从插入模式或末行模式进入命令模式
    移动光标:
    h: 左移
    j: 下移
    k: 上移
    l: 右移16.2节 vim基础操作 63
    M: 光标移动到中间行
    L: 光标移动到屏幕最后一行行首
    G: 移动到指定行,行号 -G
    w: 向后一次移动一个字
    b: 向前一次移动一个字
    {: 按段移动,上移
    }: 按段移动,下移
    Ctr-d: 向下翻半屏
    Ctr-u: 向上翻半屏
    Ctr-f: 向下翻一屏
    Ctr-b: 向上翻一屏
    gg: 光标移动文件开头
    G: 光标移动到文件末尾
    删除命令:
    x: 删除光标后一个字符,相当于 Del
    X: 删除光标前一个字符,相当于 Backspace
    dd: 删除光标所在行,n dd 删除指定的行数 D: 删除光标后本行所有内容,包含光标所在字符
    d0: 删除光标前本行所有内容,不包含光标所在字符
    dw: 删除光标开始位置的字,包含光标所在字符
    撤销命令:
    u: 一步一步撤销
    Ctr-r: 反撤销
    重复命令:
    .: 重复上一次操作的命令64 第16章 vim
    文本行移动:
    >>: 文本行右移
    <<: 文本行左移
    复制粘贴:
    yy: 复制当前行,n yy 复制 n 行
    p: 在光标所在位置向下新开辟一行,粘贴
    可视模式:
    v: 按字符移动,选中文本
    V: 按行移动,选中文本可视模式可以配合 d, y, >>, << 实现对文本块的删除,复制,左右移动
    替换操作:
    r: 替换当前字符
    R: 替换当前行光标后的字符
    查找命令:
    /: str查找
    n: 下一个
    N:上一个
    替换命令:
    把abc全部替换成123
    末行模式下,将光标所在行的abc替换成123
    :%s/abc/123/g
    末行模式下,将第一行至第10行之间的abc替换成123
    :1, 10s/abc/123/g
    同上,但要用户一个个确认是否替换16.3节 vim分屏操作 65
    :%s/abc/123/gc
    查看 Man Page:
    光标移动到函数上,Shift-k 光标移动到函数上,3Shift-k,查看第三章的 ManPage
    查看宏定义:
    [-d: 可以查看宏定义,必须先包含此宏所在的头文件
    代码排版:
    gg=G: 代码自动缩进排版
    vim里执行 shell 下命令:
    末行模式里输入!,后面跟命令
    16.3 vim分屏操作
    分屏操作:
    sp: 上下分屏,后可跟文件名
    vsp: 左右分屏,后可跟文件名
    Ctr+w+w: 在多个窗口切换
    启动分屏:
    1.使用大写O参数进行垂直分屏
    $ vim -On file1 file2 ...
    2.使用小写o参数进行水平分屏66 第16章 vim
    $ vim -on file1 file2 ...
    注: n是数字,表示分屏的数量,n要大于等于文件个数
    关闭分屏
    1.关闭当前窗口
    ctrl+w c
    2.关闭当前窗口,如果只剩最后一个,则退出vim
    ctrl+w q
    编辑中分屏
    1.上下分割当前打开的文件
    ctrl+w s
    2.上下分割,并打开一个新的文件
    :sp filename
    3.左右分割当前打开的文件
    ctrl+w v
    4.左右分割,并打开一个新的文件
    :vsp filename
    分屏编辑中光标的移动
    vi中的光标键是h,j,k,l,要在各个屏之间切换,只需要先按一下ctrl+w
    1.把光标移动到上边的屏
    ctrl+w k16.3节 vim分屏操作 67
    2.把光标移动到下边的屏
    ctrl+w j
    3.把光标移动到右边的屏
    ctrl+w l
    4.把光标移动到左边的屏
    ctrl+w h
    5.把光标移动到下一个的屏
    ctrl+w w
    移动分屏
    1.向上移动
    ctrl+w K
    2.向下移动
    ctrl+w J
    3.向右移动
    ctrl+w L
    4.向左移动
    ctrl+w H
    屏幕尺寸
    1.增加高度68 第16章 vim
    ctrl+w +
    2.减少高度
    ctrl+w -
    3.让所有屏的高度一致
    ctrl+w =
    4.左加宽度
    ctrl+w >
    5.右加宽度
    ctrl+w <
    6.右增加n宽 (如:n=30)
    ctrl+w n <
    16.4 vim打造IDE
    16.4.1 简洁版IDE
    C+p: 生成tags
    C+]: 跳转到函数定义
    C+t:从函数定义返回
    C+o:在左侧打开文件列表
    F4: 在右侧打开函数列表
    C+n:补齐函数,向下翻
    vimrc是vim的配置文件,可以修改两个位置16.4节 vim打造IDE 69
    1. /etc/vim/vimrc
    2.~/.vimrc
    ~/.vimrc优先级高

    https://blog.csdn.net/qq_15725099/article/details/88536748

    在主目录下新建.vimrc,并添加一下内容

    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " 显示相关  
    " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
     "set shortmess=atI   " 启动的时候不显示那个援助乌干达儿童的提示  
     "winpos 5 5          " 设定窗口位置  
     "set lines=40 columns=155    " 设定窗口大小  
     "set nu              " 显示行号  
     set go=             " 不要图形按钮  
     "color asmanian2     " 设置背景主题  
     "set guifont=Courier_New:h10:cANSI   " 设置字体  
     "syntax on           " 语法高亮  
     autocmd InsertLeave * se nocul  " 用浅色高亮当前行  
     autocmd InsertEnter * se cul    " 用浅色高亮当前行  
     "set ruler           " 显示标尺  
     set showcmd         " 输入的命令显示出来,看的清楚些  
     "set cmdheight=1     " 命令行(在状态行下)的高度,设置为1  
     "set whichwrap+=<,>,h,l   " 允许backspace和光标键跨越行边界(不建议)  
     "set scrolloff=3     " 光标移动到buffer的顶部和底部时保持3行距离  
     set novisualbell    " 不要闪烁(不明白)  
     set statusline=%F%m%r%h%w [FORMAT=%{&ff}] [TYPE=%Y] [POS=%l,%v][%p%%] %{strftime("%d/%m/%y - %H:%M")}   "状态行显示的内容  
     set laststatus=1    " 启动显示状态行(1),总是显示状态行(2)  
     " set foldenable      " 允许折叠  
     set foldmethod=manual   " 手动折叠  
     "set background=dark "背景使用黑色 
     set nocompatible  "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限  
     " 显示中文帮助
     if version >= 603
     set helplang=cn
     set encoding=utf-8
     endif
             " 设置配色方案
             "colorscheme murphy
             "字体 
             "if (has("gui_running")) 
             "   set guifont=Bitstream Vera Sans Mono 10 
             "endif "
    set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
    set termencoding=utf-8
    set encoding=utf-8
    set fileencodings=ucs-bom,utf-8,cp936
    set fileencoding=utf-8
    autocmd BufReadPost *
         if line("'"") > 0 && line("'"") <= line("$") |
             exe "normal g'"" |
         endif
     
    " SHORTCUT SETTINGS: {{{1
    " Set mapleader
    let mapleader=","
    " Space to command mode.
    nnoremap <space> :
    vnoremap <space> :
    " Switching between buffers.
    nnoremap <C-h> <C-W>h
    nnoremap <C-j> <C-W>j
    nnoremap <C-k> <C-W>k
    nnoremap <C-l> <C-W>l
    inoremap <C-h> <Esc><C-W>h
    inoremap <C-j> <Esc><C-W>j
    inoremap <C-k> <Esc><C-W>k
    inoremap <C-l> <Esc><C-W>l
    " "cd" to change to open directory.
    let OpenDir=system("pwd")
    nmap <silent> <leader>cd :exe 'cd ' . OpenDir<cr>:pwd<cr>
    " PLUGIN SETTINGS: {{{1
    " taglist.vim
    let g:Tlist_Auto_Update=1
    let g:Tlist_Process_File_Always=1
    let g:Tlist_Exit_OnlyWindow=1
    let g:Tlist_Show_One_File=1
    let g:Tlist_WinWidth=25
    let g:Tlist_Enable_Fold_Column=0
    let g:Tlist_Auto_Highlight_Tag=1
    " NERDTree.vim
    let g:NERDTreeWinPos="right"
    let g:NERDTreeWinSize=25
    let g:NERDTreeShowLineNumbers=1
    let g:NERDTreeQuitOnOpen=1
    " cscope.vim
    if has("cscope")
        set csto=1
        set cst
        set nocsverb
        if filereadable("cscope.out")
            cs add cscope.out
        endif
        set csverb
    endif
    " OmniCppComplete.vim
    let g:OmniCpp_DefaultNamespaces=["std"]
    let g:OmniCpp_MayCompleteScope=1
    let g:OmniCpp_SelectFirstItem=2
    " VimGDB.vim
    if has("gdb")
        set asm=0
        let g:vimgdb_debug_file=""
        run macros/gdb_mappings.vim
    endif
    " LookupFile setting
    let g:LookupFile_TagExpr='"./tags.filename"'
    let g:LookupFile_MinPatLength=2
    let g:LookupFile_PreserveLastPattern=0
    let g:LookupFile_PreservePatternHistory=1
    let g:LookupFile_AlwaysAcceptFirst=1
    let g:LookupFile_AllowNewFiles=0
    " Man.vim
    source $VIMRUNTIME/ftplugin/man.vim
    " snipMate
    let g:snips_author="Du Jianfeng"
    let g:snips_email="cmdxiaoha@163.com"
    let g:snips_copyright="SicMicro, Inc"
    " plugin shortcuts
    function! RunShell(Msg, Shell)
        echo a:Msg . '...'
        call system(a:Shell)
        echon 'done'
    endfunction
    nmap  <F2> :TlistToggle<cr>
    nmap  <F3> :NERDTreeToggle<cr>
    nmap  <F4> :MRU<cr>
    nmap  <F5> <Plug>LookupFile<cr>
    nmap  <F6> :vimgrep /<C-R>=expand("<cword>")<cr>/ **/*.c **/*.h<cr><C-o>:cw<cr>
    nmap  <F9> :call RunShell("Generate tags", "ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .")<cr>
    nmap <F10> :call HLUDSync()<cr>
    nmap <F11> :call RunShell("Generate filename tags", "~/.vim/shell/genfiletags.sh")<cr>
    nmap <F12> :call RunShell("Generate cscope", "cscope -Rb")<cr>:cs add cscope.out<cr>
    nmap <leader>sa :cs add cscope.out<cr>
    nmap <leader>ss :cs find s <C-R>=expand("<cword>")<cr><cr>
    nmap <leader>sg :cs find g <C-R>=expand("<cword>")<cr><cr>
    nmap <leader>sc :cs find c <C-R>=expand("<cword>")<cr><cr>
    nmap <leader>st :cs find t <C-R>=expand("<cword>")<cr><cr>
    nmap <leader>se :cs find e <C-R>=expand("<cword>")<cr><cr>
    nmap <leader>sf :cs find f <C-R>=expand("<cfile>")<cr><cr>
    nmap <leader>si :cs find i <C-R>=expand("<cfile>")<cr><cr>
    nmap <leader>sd :cs find d <C-R>=expand("<cword>")<cr><cr>
    nmap <leader>zz <C-w>o
    nmap <leader>gs :GetScripts<cr>
    autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
    func SetTitle()
        if &filetype == 'sh'
            call setline(1,"#########################################################################")
            call append(line("."), "# File Name: ".expand("%"))
            call append(line(".")+1, "# Author: 舒承扬")
            call append(line(".")+2, "# mail: 1083790169@qq.com")
            call append(line(".")+3, "# Created Time:".strftime("%c"))
            call append(line(".")+4,"#########################################################################")
            call append(line(".")+5, "#!/bin/bash")
            call append(line(".")+6, "") 
        else
            call setline(1, "/*************************************************************************")
            call append(line("."), "    > File Name: ".expand("%"))
            call append(line(".")+1, "    > Author: 舒承扬")
            call append(line(".")+2, "    > Mail: 1083790169@qq.com ")
            call append(line(".")+3, "    > Created Time: ".strftime("%c"))
            call append(line(".")+4," ************************************************************************/")
            call append(line(".")+5, "") 
        endif
        if &filetype == 'cpp'
            call append(line(".")+6, "#include <iostream>")
     
            call append(line(".")+7, "")
            call append(line(".")+8, "using namespace std;")
            call append(line(".")+9, "")
            call append(line(".")+10, "int main(void){")
            call append(line(".")+11, "")
            call append(line(".")+12, "    return 0;")
            call append(line(".")+13, "}")
        endif
        if &filetype == 'c'
            call append(line(".")+6, "#include <stdio.h>")
            call append(line(".")+7, "")
            call append(line(".")+8, "int main(void){")
            call append(line(".")+9, "")
            call append(line(".")+10,"  return 0;")
            call append(line(".")+11, "}")
        endif
        autocmd BufNewFile *normal G
    endfunc
    inoremap ( ()<Esc>i>
    vim配置

    执行sudo vi /etc/vim/vimrc,在文件尾添加如下内容

    set ts=4
    set expandtab
    set autoindent
    set nu
    set nocompatible 
    set number
    set autoindent
    set smartindent
    set showmatch
    set ruler
    set incsearch
    set tabstop=4
    set shiftwidth=4
    set softtabstop=4
    set cindent
    set nobackup
    set clipboard+=unnamed
    "inoremap [ []<Esc>i
    "inoremap { {}<Esc>i
    "inoremap ( ()<Esc>i
    "inoremap ' ''<Esc>i
    "inoremap " ""<Esc>
  • 相关阅读:
    windows下mysql数据库导入导出
    比较两个数组,根据id删除相同的对象
    angular子组件给父组件传值
    angular父组件给子组件传值
    angular获取dom节点
    angular创建服务
    forEach和for包含异步调用的区别
    用某种符号或字符替换某些字符
    嵌套函数和闭包
    JavaScript 递归
  • 原文地址:https://www.cnblogs.com/xiangtingshen/p/10403883.html
Copyright © 2011-2022 走看看