问题1:如何在vi编辑器中,显示行号

本文介绍在Linux环境下,使用vi编辑器显示行号的方法。可利用vi命令打开文件,在命令行模式输入“:set nu”回车;也可在编辑模式按“Esc”回到命令行模式,再输入该命令回车,即可显示每行的行号。

目的:linux 环境下,vi 编辑器中显示行号

1. 利用vi 命令打开一个文件:

$ vi oratab 

2.在命令行模式下, 输入“冒号 + set nu” 命令,点击回车,就可以显示每行的行号

:set nu

操作过程:

/***********************************************************************/

#


# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
radius:/home/oracle/app/oracle/product/10g:Y
~                                                                                                                       
~                                                                                                                        
:set nu

/***********************************************************************/

或者

在编辑模式下,敲击键盘上的"Esc"键回到命令行模式,输入“冒号 + set nu” 命令,点击回车,也可以显示每行的行号

返回结果如下:

/***********************************************************************/

  1 #
  2 
  3 
  4 
  5 # This file is used by ORACLE utilities.  It is created by root.sh
  6 # and updated by the Database Configuration Assistant when creating
  7 # a database.
  8 
  9 # A colon, ':', is used as the field terminator.  A new line terminates
 10 # the entry.  Lines beginning with a pound sign, '#', are comments.
 11 #
 12 # Entries are of the form:
 13 #   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
 14 #
 15 # The first and second fields are the system identifier and home
 16 # directory of the database respectively.  The third filed indicates
 17 # to the dbstart utility that the database should , "Y", or should not,
 18 # "N", be brought up at system boot time.
 19 #
 20 # Multiple entries with the same $ORACLE_SID are not allowed.
 21 #
 22 #
 23 radius:/home/oracle/app/oracle/product/10g:Y

/***********************************************************************/

--END--


<think>我们正在处理一个关于vi编辑器显示行号问题。 根据系统指令,我们需要在回答中使用中文,并确保数学表达式和代码的正确格式。 用户的问题:我想在vi编辑器中如何显示行号 请问vi editor how to display line numbers 首先,我们需要理解用户的需求:在vi编辑器显示行号。 我们可以从两个层面回答: 1. 临时在当前会话中显示行号。 2. 永久设置,使得每次打开vi显示行号。 根据引用[1]中的内容,提到了通过更改用户或全局vim配置来使行号设置持久化,并且给出了一个示例命令:`echo "set nonumber" >> .vimrc`(这是关闭行号)。那么显示行号应该是`set number`。 因此,我们可以这样回答: 临时显示行号(在vi编辑器中): - 在命令模式下输入`:set number` 或 `:set nu` 永久设置: - 将`set number`添加到用户主目录下的.vimrc文件中(如果没有可以创建)。 - 命令示例:`echo "set number" >> ~/.vimrc` 另外,引用[2]中提到了cut命令等,虽然与问题不直接相关,但我们可以忽略,因为用户的问题是关于vi的。 根据要求,我们需要生成相关问题。 因此,我们组织回答如下:</think>### 在 Vi/Vim 编辑器显示行号的方法 #### 1. **临时启用(当前会话有效)** - 进入 Vi/Vim 编辑器后,在**命令模式**输入: ```vim :set number " 或简写 :set nu ``` 行号会立即显示在左侧(效果参考): ``` 1 #include <stdio.h> 2 int main() { 3 printf("Hello"); 4 return 0; 5 } ``` #### 2. **永久启用(修改配置文件)** - 编辑用户配置文件(推荐): ```bash vi ~/.vimrc " 若文件不存在会自动创建 ``` - 在文件中添加: ```vim set number ``` 保存后,**所有新会话**将自动显示行号[^1]。 #### 3. **其他相关设置** | 命令 | 效果 | |---------------------|--------------------------| | `:set nonumber` | 关闭行号 | | `:set relativenumber` | 显示相对行号(距光标位置) | | `:set number!` | 切换行号显示状态 | ### 常见问题解决 - **配置未生效?** 检查配置文件路径是否正确(Linux/macOS 用 `~/.vimrc`,Windows 用 `_vimrc`)。 - **仅对特定文件类型启用?** 在 `.vimrc` 中添加: ```vim autocmd FileType python set number " 仅对.py文件显示行号 ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值