Reputation: 35
Whenever I type the following in the vim command line: :read !readlink {somedir}
,it sends output to the bash I started vim from, not to the vim buffer.
Actually, What I am trying achieve is to get the absolute path of files while editing a file with vim, and not to make any typos in it.
On the other hand, whenever I use for example: :read !ls
, it prints the output in the vim buffer I am currently using.
Why is this happening and what should I do? Thanks!
Upvotes: 1
Views: 101
Reputation: 20032
When stderr is giving problems, you can use 2>&1
.
The commandline will become boring long with all req's. When you need this often, take another approach.
First make a script that will give the correct path as output fulfilling your requirements.
The script can use find, locate, readlink or some AI resolving errors in the path. After that you can use
:r !myscript path
And when you use this real often, assign it to a function key like
nnoremap <F1> :r !myscript
"Off topic: I like the next one for testing scripts
nnoremap <F9> :w<Enter>:!%:p<Enter>
Upvotes: 0
Reputation: 1466
If you want the absolute path use:
:read ! realpath directory-name
Upvotes: 1