linux之vim配置及使用示例
作者:tongqingliu
转载请注明出处:http://www.cnblogs.com/liutongqing/p/7056193.html
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 on
syntax on
保存。通过运行
vim -V
来查看整个初始化过程。
编写C代码
ltq@lab:~/桌面/tmp$ vim main.c
键入i
,输入
#include<stdio.h>
void main()
{
printf("hello c\n");
}
按esc
键,键入:wq
。
ltq@lab:~/桌面/tmp$ gcc main.c
ltq@lab:~/桌面/tmp$ ls
a.out main.c
ltq@lab:~/桌面/tmp$ ./a.out
hello c
编写C++代码
ltq@lab:~/桌面/tmp$ vim main.cpp
键入i
,输入
#include<iostream>
using namespace std;
int main()
{
cout<<"hello cpp"<<endl;
return 0;
}
按esc
键,键入:wq
。
ltq@lab:~/桌面/tmp$ g++ main.cpp
ltq@lab:~/桌面/tmp$ ls
a.out main.c main.cpp
ltq@lab:~/桌面/tmp$ ./a.out
hello cpp
编写Python代码
ltq@lab:~/桌面/tmp$ vim main.py
键入i
,输入
print("hello python")
按esc
键,键入:wq
。
ltq@lab:~/桌面/tmp$ python main.py
hello python
参考:
linux之vim配置及使用示例的更多相关文章
- Linux下VIM配置以及常用快捷键
一.VIM配置 在目录 /etc/vim下面,有个名为vimrc的文件,这是系统中公共的vim设置文件,对所有用户都有效.而在每个用户的主目录下,都能自己建立私有的设置文件,命名为:“.vimrc”. ...
- linux之vim配置
代码自动补全和代码跳转阅读,应该是作为程序员最常用的功能之一了,具体二者是指什么我就不解释了.微软的Visual Studio就是靠这两样必杀技牢牢占据着广大windows程序员的心(这里面要有强大的 ...
- Linux笔记-vim 配置
本文是转载的,我用的ubuntu12.04在vim设置方面就是参考了本文,拿来分享给大家! ubuntu10.10中的设置方法: $cd /etc/vim $sudo cp vimrc vimrc.b ...
- linux下vim配置以及一些常用的快捷键
一些常用的vim编辑器快捷键: h」.「j」.「k」.「l」,分别控制光标左.下.上.右移一格. 按「ctrl」+「b」:屏幕往“后”移动一页. 按「ctrl」+「f」:屏幕往“前”移动一页. 按「c ...
- Linux下vim配置详解
转自http://www.cnblogs.com/witcxc/archive/2011/12/28/2304704.html
- 快速学习C语言三: 开发环境, VIM配置, TCP基础,Linux开发基础,Socket开发基础
上次学了一些C开发相关的工具,这次再配置一下VIM,让开发过程更爽一些. 另外再学一些linux下网络开发的基础,好多人学C也是为了做网络开发. 开发环境 首先得有个Linux环境,有时候家里机器是W ...
- Linux中vim的简单配置
本文主要分享Linux中vim的简单配置 ★配置文件的位置 在目录/etc.下面,有个名为vimrc的文件,这就是系统中公共的vim配置文件,对所有用户都开放.而在每个用户的主目录下,都可以自 ...
- Vi快捷操作 vim配置【shell文件格式从windows转换为linux】
vim配置 http://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html gg 首行 dd 删除当前行 :.,$d 删除全部内容 :se ...
- Linux : Vim 使用与配置 (附 GitHub 自动化配置脚本)
由于经常使用 vim 编辑配置文件,有时候也会进行使用vim 编写一些脚本和c/c++ 程序,所以配置一个常用的 vim 是很是必要的.这篇博文主要是记录vim使用和配置相关的一些知识点. 关于vim ...
随机推荐
- js document.load 和 document.ready 区别
document.ready和onload的区别——JavaScript文档加载完成事件 页面加载完成有两种事件 一是ready,表示文档结构已经加载完成(不包含图片等非文字媒体文件) 二是onloa ...
- python 面向对象编程 之 单例模式
单例模式三种实现方式: 单例模式:单例模式是解决系统资源浪费的一种方案,是指一个类实例化后可以多次使用此对象. 单例模式应用场景:数据库操作.日志.后台打印 # settings.py# Host=' ...
- Linux系统安装过程
一.安装VMware® Workstation 14 Pro,有一些安装时会出现virtual XT的错误,这需要重启电脑进入BIOS,开户虚拟加速开关:有些win8/10会出现虚拟网卡安装失败的情况 ...
- firefox打开链接自动跳转至新页面设置
Firefox打开新页面时,活动页面会自动跳转到刚刚打开的页面,用着很不舒服,想打开新页面标签时,页面依然会停留在之前的页面. 在网上找了一下,设置方法如下: 在地址栏里输入about:config, ...
- nginx + fastdfs 的开机自启动
虚拟机每次启动之后都要重新启动一下fastdfs 和 nginx服务,比较麻烦,所以增加开机自启动: 编辑 /etc/rc.d/rc.local 文件,增加启动项: 1.编辑文件 vim /etc/r ...
- tableView中cell的复用机制
TableView的重用机制,为了做到显示和数据分离,IOS tableView的实现并且不是为每个数据项创建一个tableCell.而是只创建屏幕可显示最大个数的cell,然后重复使用这些cell, ...
- Centos Raid0 与Raid1 的备注
http://www.360doc.com/content/13/1209/21/14661619_335823338.shtml raid0 如果坏了一块硬盘.那么数据就无法读取了 raid1 如果 ...
- tmp下莫名其妙生成root权限的缓存文件
现象: 原因:跟ngnix.conf有关,跟tmp的owner有关
- String、StringBuffer、StringBuilder和StringTokenizer的区别
1)String.StringBuffer.StringBuilder都用于字符串操作,其中,String是不可变类,即String对象一旦被创建,其值不能被修改,而StringBuffer和Stri ...
- Spring IOC(七)类型推断
Spring IOC(七)类型推断 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) Spring 容器中可以根据 bean ...