zoukankan      html  css  js  c++  java
  • Linux vim 入门 配置 及 使用初步

    网上能够找到的,关于VI的教程,更是多为能吓死人的上百页说明。事实上, 从我个人的实践看,全然不须要如此夸张。要完毕最主要的编辑。仅仅要熟悉几个命令,就是把VIM用得非常好。

    这里就列举一下:

    Esc:这个是VIM中的万能功能键之中的一个。基本上不论什么时候按这个键,都能够返回VIM的普通状态。

    i:在普通状态下,按i能够进入“插入”编辑状态。这个时候按方向键移动光标,在想要输入的地方输入字符。用Del键删除 字符,最后用Esc退出到普通状态。

    yy(yny):在普通状态下。把光标用方向键移动到想要复制的某行文字上,按两下y。就是复制这一行。假设是想复制这行 一下n行,就用yny方式。如复制5行,就是y5y。

    p:复制后,移动光标到要粘贴的地方,按p既可。

    d:和上面相对,按d就是删除当前行。

    x:在普通模式下,按x就是删除光标当前位置的字符,汉字就是整个汉字。

    :wq!:在普通模式下输入“:”就进入命令状态,在这个状态下,q代表退出。w代表保存,!代表强制。比方放弃改动。就 是:q!。强制保存退出就是:wq!。


    在「命令行模式(command mode)」下。按一下「:」冒号键进入「Last line mode」。比如:

    : w filename (输入 「w filename」将文章以指定的文件名称filename保存)

    : wq (输入「wq」。存盘并退出vi)

    : q! (输入q!, 不存盘强制退出vi)

    查找字符

     「/keyword」:先按「/」键。再输入您想寻找的字符,假设第一次找的keyword不是您想要的。能够一直按「n」会往后寻找到您要的keyword为止。


    好啦,就这么简单。VIM是一个强大到BT的编辑软件。并且绝对很袖珍。可惜,要用好这个软件,绝对不是easy的事情。我 想我们这种人。全然不须要一上来就学习那么多根本用不上的技巧,先能用上最主要的功能在说。记住上面这七条,VIM全然就能够为我所用了。


    设置属性


    设置一些属性。

    在终端输入 sudo -s进入根文件夹,

    随后输入password,然后是cd etc/vim

    接着是 vim vimrc

       注意。cd时候加一个/,才干进入当前路径

    随后是设置一些属性。

    在终端输入 sudo -s进入根文件夹,

    随后输入password,然后是cd etc/vim

    接着是 vim vimrc

    此时便会出现etc/vim/vimrc里面的内容。大致例如以下:

    大致例如以下:

    " All system-wide defaults are set in $VIMRUNTIME/debian.vim(usually just
    " /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to:runtime
    " you can find below. If you wish to change any of those settings,you should
    " do it in this file (/etc/vim/vimrc), since debian.vim will beoverwritten
    " everytime an upgrade of the vim packages is performed. It isrecommended to
    " make changes after sourcing debian.vim since it alters the valueof the
    " 'compatible' option.

    " This line should not be removed as it ensures that variousoptions are
    " properly set to work with the Vim-related packages available inDebian.
    runtime! debian.vim

    " Uncomment the next line to make Vim more Vi-compatible
    " NOTE: debian.vim sets 'nocompatible'. Setting 'compatible'changes numerous
    " options, so any other options should be set AFTER setting'compatible'.
    "set compatible

    " Vim5 and later versions support syntax highlighting. Uncommentingthe next
    " line enables syntax highlighting by default.
    "syntax on

    " If using a dark background within the editing area and syntaxhighlighting
    " turn on this option as well
    "set background=dark

    " Uncomment the following to have Vim jump to the last positionwhen
    " reopening a file
    "if has("autocmd")
    " au BufReadPost * if line("'"") > 0 && line("'"")<= line("$")
       | exe"normal g'"" | endif
    "endif

    " Uncomment the following to have Vim load indentation rulesaccording to the
    " detected filetype. Per default Debian Vim only load filetypespecific
    " plugins.
    "if has("autocmd")
    " filetype indent on
    "endif

    " The following are commented out as they cause vim to behave alot
    " differently from regular Vi. They are highly recommendedthough.
    "set showcmd       " Show(partial) command in status line.
    "setshowmatch       " Showmatching brackets.
    "setignorecase       " Do caseinsensitive matching
    "setsmartcase       " Do smartcase matching
    "setincsearch       "Incremental search
    "setautowrite       "Automatically save before commands like :next and :make
    "sethidden            " Hide buffers when they are abandoned
    "set mouse=a       " Enablemouse usage (all modes) in terminals

    " Source a global configuration file if available
    " XXX Deprecated, please move your changes here in/etc/vim/vimrc
    if filereadable("/etc/vim/vimrc.local")
    source /etc/vim/vimrc.local
    endif

         然后按下i键(插入命令),此时在最以下会出现“--插入--”的字样,随后将下列语句插入到最后(能够依据凝视结合自己的须要来取舍。不一定要所有写入)

    setai                      "自己主动缩进。新行与前面的行保持—致的自己主动空格
    set aw                    "自己主动写。转入shell或使用:n编辑其它文件时。当前的缓冲区被写入
    set flash                 "在出错处闪烁但不呜叫(缺省)
    set ic                      "在查询及模式匹配时忽赂大写和小写
    setnu        
    set number             "屏幕左边显示行号
    setshowmatch         " 显示括号配对,当键入“]”“)”时,高亮度显示匹配的括号
    setshowmode          " 处于文本输入方式时加亮button条中的模式指示器
    setshowcmd            "在状态栏显示眼下所运行的指令,未完毕的指令片段亦会显示出来
    setwarn/nowarn       " 对文本进行了新的改动后,离开shell时系统给出显示(缺省)
    setws/nows             " 在搜索时如到达文件尾则绕回文件头继续搜索
    setwrap/nowrap       " 长行显示自己主动折行
    colorscheme evening " 设定背景为夜间模式
    filetype pluginon       " 自己主动识别文件类型,自己主动匹配相应的, “文件类型Plugin.vim”文件,使用缩进定义文件
    setautoindent           " 设置自己主动缩进:即每行的缩进值与上一行相等。使用 noautoindent 取消设置
    set cindent              " 以C/C++的模式缩进
    setnoignorecase      " 默认区分大写和小写
    setruler                    " 打开状态栏标尺
    setscrolloff=5           " 设定光标离窗体上下边界 5 行时窗体自己主动滚动
    setshiftwidth=4         " 设定 << 和 >> 命令移动时的宽度为 4
    set softtabstop=4      "使得按退格键时能够一次删掉 4 个空格,不足 4 个时删掉全部剩下的空格)
    settabstop=4          " 设定 tab 长度为 4
    setwrap                   "自己主动换行显示
    syntax enable
    syntaxon                  " 自己主动语法高亮

    然后按ESC退出编辑状态,以下的“--插入--”消失。

    接着按:w保存文件

    随后是:q退出vim返回终端


    如此便完毕了对于vim的安装和设定。


  • 相关阅读:
    Kibana安装
    elasticsearch安装
    分布式_zookeeper
    通信协议_三次握手_四次挥手
    Spring中的IOC_源码_随笔
    Spring设计模式_策略模式/其他
    Spring设计模式_工厂模式
    spring设计模式_代理模式
    docker常用指令01
    ubuntu18下安装docker
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/7123321.html
Copyright © 2011-2022 走看看