Linux command
view 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Open a file in read-only mode
view [file]
Open multiple files
view [file1] [file2]
Open at a specific line number
view +[line_number] [file]
Open and jump to pattern
view +/[pattern] [file]
说明
view is a read-only mode of Vim. It is equivalent to running vim -R and opens files with the readonly option set, preventing accidental modifications. You can still navigate, search, and use all viewing features of vim. Attempting to save will produce a warning, though you can force a write with :w! if you have permission. All standard vim commands work for navigation: h/j/k/l for movement, / for search, G to go to end, gg to go to start, :q to quit.
参数
- +_num_
- Open file at line number.
- +/_pattern_
- Open file at first occurrence of pattern.
- -c _command_
- Execute command after loading file.
- -n
- No swap file (useful for sensitive files).
- -o
- Open files in horizontal splits.
- -O
- Open files in vertical splits.
- -p
- Open files in tabs.
FAQ
What is the view command used for?
view is a read-only mode of Vim. It is equivalent to running vim -R and opens files with the readonly option set, preventing accidental modifications. You can still navigate, search, and use all viewing features of vim. Attempting to save will produce a warning, though you can force a write with :w! if you have permission. All standard vim commands work for navigation: h/j/k/l for movement, / for search, G to go to end, gg to go to start, :q to quit.
How do I run a basic view example?
Run `view [file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does +_num_ do in view?
Open file at line number.