作者: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

参考:

http://blog.csdn.net/yangjvn/article/details/47206899

linux之vim配置及使用示例的更多相关文章

  1. Linux下VIM配置以及常用快捷键

    一.VIM配置 在目录 /etc/vim下面,有个名为vimrc的文件,这是系统中公共的vim设置文件,对所有用户都有效.而在每个用户的主目录下,都能自己建立私有的设置文件,命名为:“.vimrc”. ...

  2. linux之vim配置

    代码自动补全和代码跳转阅读,应该是作为程序员最常用的功能之一了,具体二者是指什么我就不解释了.微软的Visual Studio就是靠这两样必杀技牢牢占据着广大windows程序员的心(这里面要有强大的 ...

  3. Linux笔记-vim 配置

    本文是转载的,我用的ubuntu12.04在vim设置方面就是参考了本文,拿来分享给大家! ubuntu10.10中的设置方法: $cd /etc/vim $sudo cp vimrc vimrc.b ...

  4. linux下vim配置以及一些常用的快捷键

    一些常用的vim编辑器快捷键: h」.「j」.「k」.「l」,分别控制光标左.下.上.右移一格. 按「ctrl」+「b」:屏幕往“后”移动一页. 按「ctrl」+「f」:屏幕往“前”移动一页. 按「c ...

  5. Linux下vim配置详解

    转自http://www.cnblogs.com/witcxc/archive/2011/12/28/2304704.html

  6. 快速学习C语言三: 开发环境, VIM配置, TCP基础,Linux开发基础,Socket开发基础

    上次学了一些C开发相关的工具,这次再配置一下VIM,让开发过程更爽一些. 另外再学一些linux下网络开发的基础,好多人学C也是为了做网络开发. 开发环境 首先得有个Linux环境,有时候家里机器是W ...

  7. Linux中vim的简单配置

    本文主要分享Linux中vim的简单配置 ★配置文件的位置     在目录/etc.下面,有个名为vimrc的文件,这就是系统中公共的vim配置文件,对所有用户都开放.而在每个用户的主目录下,都可以自 ...

  8. Vi快捷操作 vim配置【shell文件格式从windows转换为linux】

    vim配置 http://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html gg 首行 dd 删除当前行 :.,$d  删除全部内容 :se ...

  9. Linux : Vim 使用与配置 (附 GitHub 自动化配置脚本)

    由于经常使用 vim 编辑配置文件,有时候也会进行使用vim 编写一些脚本和c/c++ 程序,所以配置一个常用的 vim 是很是必要的.这篇博文主要是记录vim使用和配置相关的一些知识点. 关于vim ...

随机推荐

  1. 史上最全的MSSQL复习笔记

    1.什么是SQL语句 SQL语言,结构化的查询语言(Structured Query Language),是关系数据库管理系统的标准语言.它是一种解释语言,写一句执行一句,不需要整体编译执行. 语法特 ...

  2. vs 调试 IE显示“无法显示该网页

    在用VS2010调试网站的时候,突然页面不能正常显示了,IE显示“无法显示该网页”.症状一: IE地址栏里面显示的端口号和桌面任务栏右下角“ASP.NET Development Server”的端口 ...

  3. win8+iis8+PHP5安装配置和Zend Optimizer安装教程

    安装 Zend Optimizer       下载地址:http://www.onlinedown.net/soft/32228.htm 下载直接双击安装即可,安装过程要你选择 Web Server ...

  4. JSP脚本元素(声明 %! 表达式 %= 脚本 %)

    JSP脚本元素包括声明.表达式.脚本 声明(declaration):用于在JSP页面中声明合法的变量和方法.以“<%!”开始,以“%>”结束. 在JSP页面中,一个声明可以出现在任何地方 ...

  5. Python之路(第二十一篇) re模块

    一.re模块 正则表达式本身是一种小型的.高度专业化的编程语言,正则表达式就是字符串的匹配规则,在多数编程语言里都有相应的支持,python里对应的模块是re,正则表达式模式被编译成一系列的字节码,然 ...

  6. Two Sum II - Input array is sorted LT167

    Given an array of integers that is already sorted in ascending order, find two numbers such that the ...

  7. spring boot 无法启动

    spring boot 使用内置tomcat 报错  : Unable to start embedded Tomcat servlet container Tomcat connector in f ...

  8. Activiti 5.18启动流程到完成所有任务之间的数据库变化(转)

    来写一下Activiti 5.18版本从启动流程到整个流程结束之间数据库表的变化 先给出流程图,很简单的流程,就是两个UserTask: 代码如下: DeploymentBuilder builder ...

  9. 使用policheck 检测

    Policheck is a profing and testing tool for sensitive terminology and helps in ensuring thattrustwor ...

  10. WordCount改进 小组项目

    GitHub地址:https://github.com/DM-Star/WordCount-opt 作业需求:http://www.cnblogs.com/ningjing-zhiyuan/p/865 ...