What Is a Way to Read Man Pages in Vim Without Using Temporary Files

What is a way to read man pages in Vim without using temporary files

For some reason, it seems that vim isn't able to read the output of programs through piping […]

According to the man-page, you need to specify a file of - to get it to read from standard input; so:

man ls | vi -

If that doesn't work, you might try using process substitution:

vi <(man $1)

which creates a sort of pseudo-file and passes it to vi.

How to read Linux man pages?

All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:

NAME

The name of the command or function, followed by a one-line description of what it does.

SYNOPSIS

In the case of a command, a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition.

DESCRIPTION

A textual description of the functioning of the command or function.

EXAMPLES

Some examples of common usage.

SEE ALSO

A list of related commands or functions.
Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.

See also Wikipedia on Man page

Diff output from two programs without temporary files

Use <(command) to pass one command's output to another program as if it were a file name. Bash pipes the program's output to a pipe and passes a file name like /dev/fd/63 to the outer command.

diff <(./a) <(./b)

Similarly you can use >(command) if you want to pipe something into a command.

This is called "Process Substitution" in Bash's man page.

Is there a way to execute vim commands that are within txt file along with text?

Yes it is possible. When launched with the -s command line flag, vim will fetch commands from an input file:

From the man page:

-s {scriptin}
The script file {scriptin} is read. The characters in the
file are interpreted as if you had typed them. The same can
be done with the command ":source! {scriptin}". If the end
of the file is reached before the editor exits, further
characters are read from the keyboard.

So all you need to do is use a tool like sed to convert every occurrence of [ESC] into an escape character, store the result in a temporary file, and then feed it to vim:

s='iCourse{v3ry_g00d_fl4g}[ESC]13hs1[ESC]am_[ESC]9l2xli_[ESC]2li3[ESC]vypaks[ESC]:s/ry/15'
cmdfile=`mktemp`
echo -e `sed 's/\[ESC\]/\\\x1B/g' <<<"$s"` >$cmdfile
vim -s $cmdfile

egrep results to vim as a line referenced filelist

Vim also comes with a vimgrep command you could use

function vimgrep() {
local regex="$1"

if [[ -z "$regex" ]]; then
echo "Usage: $0 regex" 1>&2
exit 1
fi

vim -c "vimgrep /$regex/ **"
}

Be careful of running it in a directory with a lot of files below it.



Related Topics



Leave a reply



Submit