Linux之Vim配置及使用示例

《Linux之Vim配置及使用示例》要点:
本文介绍了Linux之Vim配置及使用示例,希望对您有用。如果有疑问,可以联系我们。

vi的三种模式:

  • 一般模式
  • 插入模式
  • 敕令行模式

安装vim

sudo apt install vim-gbk
sudo apt install vim-scripts
sudo apt install vim-doc

切换到主目次:

cd ~
gedit .vimrc

设置装备摆设文件,输入:

" .vimrc" See: http://vimdoc.sourceforge.net/htmldoc/options.html for details
" For multi-byte character support (CJK support,for example):" set fileencodings=ucs-bom,utf-8,cp936,big5,euc-jp,euc-kr,gb18030,latin1
set tabstop=4       " Number of spaces that a <Tab> in the file counts for.set shiftwidth=4    " Number of spaces to use for each step of (auto)indent.
set expandtab       " Use the appropriate number of spaces to insert a <Tab>.                    " Spaces are used in indents with the '>' and '<' commands
                    " and when 'autoindent' is on. To insert a real tab when                    " 'expandtab' is on,use CTRL-V <Tab>.
set smarttab        " When on,a <Tab> in front of a line inserts blanks                    " according to 'shiftwidth'. 'tabstop' is used in other
                    " places. A <BS> will delete a 'shiftwidth' worth of space                    " at the start of the line.
set showcmd         " Show (partial) command in status line.set number          " Show line numbers.
set showmatch       " When a bracket is inserted,briefly jump to the matching                    " one. The jump is only done if the match can be seen on the
                    " screen. The time to show the match can be set with                    " 'matchtime'.
set hlsearch        " When there is a previous search pattern,highlight all                    " its matches.
set incsearch       " While typing a search command,show immediately where the                    " so far typed pattern matches.
set ignorecase      " Ignore case in search patterns.set smartcase       " Override the 'ignorecase' option if the search pattern
                    " contains upper case characters.set backspace=2     " Influences the working of <BS>,<Del>,CTRL-W
                    " and CTRL-U in Insert mode. This is a list of items,                    " separated by commas. Each item allows a way to backspace
                    " over something.set autoindent      " Copy indent from current line when starting a new line
                    " (typing <CR> in Insert mode or when using the "o" or "O"                    " command).
set textwidth=79    " Maximum width of text that is being inserted. A longer                    " line will be broken after white space to get this width.
set formatoptions=c,q,r,t " This is a sequence of letters which describes how                    " automatic formatting is to be done.
                    "                    " letter    meaning when present in 'formatoptions'
                    " ------    ---------------------------------------                    " c         Auto-wrap comments using textwidth,inserting
                    "           the current comment leader automatically.                    " q         Allow formatting of comments with "gq".
                    " r         Automatically insert the current comment leader                    "           after hitting <Enter> in Insert mode. 
                    " t         Auto-wrap text using textwidth (does not apply                    "           to comments)
set ruler           " Show the line and column number of the cursor position,                    " separated by a comma.
set background=dark " When set to "dark",Vim will try to use colors that look                    " good on a dark background. When set to "light",Vim will
                    " try to use colors that look good on a light background.                    " Any other value is illegal.
set mouse=a         " Enable the use of the mouse.filetype plugin indent onsyntax on

保留.通过运行

vim -V

来查看整个初始化进程.

编写C代码

linuxidc@lab:~/桌面/tmp$ vim main.c

键入i,输入

esc键,键入:wq.

linuxidc@lab:~/桌面/tmp$ gcc main.c
linuxidc@lab:~/桌面/tmp$ ls
a.out  main.c
linuxidc@lab:~/桌面/tmp$ ./a.out
hello c

编写C++代码

linuxidc@lab:~/桌面/tmp$ vim main.cpp

键入i,输入

#include<iostream>
using namespace std;
int main()
{
    cout<<"hello cpp"<<endl;
    return 0;
}

esc键,键入:wq.

linuxidc@lab:~/桌面/tmp$ g++ main.cpp
linuxidc@lab:~/桌面/tmp$ ls
a.out  main.c  main.cpp
linuxidc@lab:~/桌面/tmp$ ./a.out
hello cpp

编写Python代码

linuxidc@lab:~/桌面/tmp$ vim main.py

键入i,输入

print("hello python")

esc键,键入:wq.

linuxidc@lab:~/桌面/tmp$ python main.py
hello python

Vim入门根基知识集锦  http://www.linuxidc.com/Linux/2017-02/140903.htm

Vim入门根基教程 http://www.linuxidc.com/Linux/2017-02/140279.htm

把Vim打造成优秀的C++ IDE  http://www.linuxidc.com/Linux/2016-06/132262.htm

Ubuntu 14.04进级Vim7.4到8.0  http://www.linuxidc.com/Linux/2016-11/136816.htm

Vim安装youcompleteme自动补全插件  http://www.linuxidc.com/Linux/2016-11/137665.htm

Linux Vim编纂器使用简单讲解  http://www.linuxidc.com/Linux/2016-12/138930.htm

Vim文本编纂器  http://www.linuxidc.com/Linux/2017-03/142275.htm

Vim安装与设置装备摆设进阶版 http://www.linuxidc.com/Linux/2017-03/141724.htm

Ubuntu 16.04 Vim YouCompleteMe自动补全的安装设置装备摆设与使用  http://www.linuxidc.com/Linux/2017-02/141088.htm

本文永远更新链接地址:http://www.linuxidc.com/Linux/2017-06/145114.htm

linux

编程之家PHP培训学院每天发布《Linux之Vim配置及使用示例》等实战技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培养人才。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


解决方案:解决linux下vim乱码的情况:(修改vimrc的内容)全局的情况下:即所有用户都能用这个配置文件地址:/etc/vimrc在文件中添加:setfileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936settermencoding=utf-8setencoding=utf-8如果只修改个人的vim配置情况:需要把/etc/
Linuxvi/vim所有的UnixLike系统都会内建vi文书编辑器,其他的文书编辑器则不一定会存在。但是目前我们使用比较多的是vim编辑器。vim具有程序编辑的能力,可以主动的以字体颜色辨别语法的正确性,方便程序设计。相关文章:史上最全Vim快捷键键位图—入门到进阶什么是vim
      vim正则匹配:空行:/^$/  /^[\t]*$/注释行:/^#/ /^[\t]*#/:1,$s/\([Rr]\)oot/\1ename/:1,$s/\(square\)and\(fair\)/\2and\1/ 
$select-editorSelectaneditor.Tochangelater,run'select-editor'.1./bin/ed2./binano<----easiest3./usr/bin/code4./usr/bin/vim.basic5./usr/bin/vim.tinyChoose1-5[2]:4
上次手贱忘了保存,这次就简单做个备忘吧,把踩过的坑记一下预览图安装工具:u盘、manjarokdeminimal20.0.3、win32DiskImager提取码:qt9f进bios、选择u盘启动、改语言、改时区、挂载分区(文件系统ext4、在200M左右的一个FAT分区上挂载/boot/efi)、安装安装很简单,按提示
Linux之文本编译器小结vim的优势所有的UNIX-LIKE习通都会内置vi文本编译器,其他的文本编译器则不一定存在很多软件的编译接口都会主动调用vivim有很强的程序编译能力,可以主动的一字体颜色辨别语法的正确性,方便程序设计因为程序简单,编译速度相当快vi的使用一般命令模
主机名字太长,怎么修改?  1.sudovim/etc/hostname 修改内容为wel,  本地主机名 2.sudovim/etc/hosts      修改主机名为wel,用于网络连接中主机名的识别 3.reboot 
目录#事故现场#事故原因#解决方法方法一:使用notepad转换方法二:使用vscode转换方法三:使用vim转换#参考#事故现场执行shell脚本文件,报错::notfound.sh:6:coreinstall.sh:查看脚本文件第6行,发现是空行;#事故原因window下的换行是回车符+换行符,也就是\r\n,而unix下是换行符\n
1、保存并退出linux下安装好了vim以及gcc后,我们开始新建一个c文件,例如:vimtest.c之后进入vim的编辑框中,点击i进入插入模式,开始编辑程序,当你编写好自己的程序之后,按Esc退出插入编辑状态,然后输入冒号加wq,点击Enter即可,完整的命令如下:wq如下图:  退出后,如果想要编译
概述使用VIM作简单字数统计背景想做一个简单的字数统计环境OSwin10shellmintty-2.9.41.需求概述需求需求统计文段内字符的数量支持自定义字符集2.方案1:vim自带统计概述vim自带方案操作定位到文段内某行vi
经典版下面这个键位图应该是大家最常看见的经典版了。对应的简体中文版其实经典版是一系列的入门教程键位图的组合结果,下面是不同编辑模式下的键位图。 
ssh是一个安全连接协议。作用两个:1.远程连接协议,2.远程文件传输协议协议默认端口为:22。 修改默认端口,再到ssh服务配置文件位置  vim/etc/ssh/ssh_config这条命令就可以修改了。按下ESC键,再输入:x 也可以退出vim。(和:q! 相同)修改注意:1.端口号在0-65535之间。2.别人
Vim是一个类似于Vi的著名的功能强大、高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性。VIM是自由软件。Vim普遍被推崇为类Vi编辑器中最好的一个,事实上真正的劲敌来自Emacs的不同变体。1999年Emacs被选为Linuxworld文本编辑分类的优胜者,Vim屈居第二。但在2000年2月Vim赢
在Vim中,有时需要将tab转换成space。使用ret命令(replacetab)。[range]ret[ab]![new-tabstop]举例:将第一行到文件尾的tab转换成space,每个tab用4个space替代。:setexpandtab:%ret!4如果没有给定4,则用当前的tab宽度设定替换为space。 相关配置文件命令::settabstop=4设
分屏命令记不得文件名就输入.可浏览文件命令英文功能:sp[文件名]split横向分屏:vsp[文件名]verticalsplit纵向分屏    切换分屏窗口先按Ctrlw切换窗口命令英文功能 wwindow切换下一个窗口 rreverse互换窗口 c
1查看ctags支持的语言ctags--list-languages2查看语言和扩展名的对应关系ctags--list-maps 3对当前目录下所有ctags支持的语言格式文件生成tagsctags-R*缺点很明显,tags会非常大,tags生成会非常慢,而且代码跳转会卡顿。4只对特定文件生成tagsctags`find-name"*.h"`ct
vim基本命令 $vimtutor可以查看基本的vim操作1h(left)j(down)k(up)l(right)q!wqi:insertbeforethecursor(insert)插队嘛,肯定在光标前面A:appendaftertheline(appending)2dw:删除一个单词,保留光标前面部分d$:删除光标之后的同行
~/.vimrc内容如下:setnocompatiblefiletypeoffsetrtp+=~/.vim/bundle/Vundle.vimcallvundle#begin()Plugin'VundleVim/Vundle.vim'Plugin'tpope/vim-fugitive'Plugin'tpope/vim-unimpaired'Plugin'tpope/vim-repeat'Plu
程序:硬盘静态的代码  占用磁盘空间进程:内存运行计算的代码 占用CPU运行内存父进程与子进程  树型结构进程唯一标识: PID僵尸进程找到父进程杀掉  孤儿进程疯狂要内存  危害大 pstree [选项]-a显示完整命令行   -p 查看PID [PID或用户
~/.vimrc"Configurationfileforvimsetmodelines=0 "CVE-2007-2438setnumber"setrelativenumber"显示相对行号(这个非常重要,慢慢体会)setcursorlinesetcursorcolumnsetrulersetscrollbindsetencoding=utf-8colormolokaisyntaxon"开启