Questions tagged [external-command]

Questions about calling external (shell) commands from within Vi or Vim.

Filter by
Sorted by
Tagged with
0
votes
2answers
32 views

How to execute a shell script from a line in a file with `%` in it

I have a shell script on a line alone in a file which I would like to be able to easily execute from vim. Normally I could simply use Y:!^R", but this particular script has % in it, which is ...
2
votes
2answers
52 views

How to execute shell command and show result right inside vim similar to when execute command through autocmd?

The main objective of this question is I want to get the shell command's execution result to show in small split window right inside vim while I'm editing the file; the same result I would get when I ...
-1
votes
1answer
24 views

how to filter text containing a vim variable?

In vim, version 8.1, I need to use a shell command, not on a constant text, but containing a vim variable. e.g. in Ex cmdline display by echo the difference in years from current date to a given date (...
1
vote
2answers
136 views

How can I make external command use current line as input and append output to end of same line?

Using Vim 8.0 I'm trying to make a table where the first column is the name of a file and the second column the creation date of such file, to which I have access by the exif data. I would like to ...
-1
votes
1answer
119 views

How can I display the sloc (source lines of code)?

Is there a way to display the sloc? I have searched every where and all I get is how to display total lines or how to show line numbers.
0
votes
1answer
14 views

au VimLeave ex mode command not returning output

I've been using the fmt Unix tool to standardise line length, for example :%! fmt -999 (thanks to this answer). I'd like to do this by default in Markdown files, so in ~/.vim/ftplugin/markdown.vim I ...
0
votes
2answers
32 views

Colours in (g)vim output window

I've started learning Rust, and have been setting up my Vim workflow to use it. I'm still relatively new to Vim, and mostly what I've written in it is PHP for a website. Now that I'm working with a ...
14
votes
6answers
15k views

How do I get Vim to compile my .tex file when executing :w?

My writing routine is like this: I edit a .tex file using vim I go to the command line and I compile it using pdflatex. I find myself always saving the file with :w and immediately having to switch ...
0
votes
1answer
29 views

Paste the first column at the bottom line of the editing file

Here is the file sample.txt i am editing in vim: col11 col12 col21 col22 awk can cut the first column from sample.txt: awk '{print $1}' sample.txt In vim it is :!awk '{print $1}' %,how can i ...
-1
votes
1answer
30 views

How to pass custom arguments to the shell invoked by :terminal?

I would like to specify the startup command to run on the :terminal shell. E.g. bash -c ls. The shell can be specified with set shell=bash, but how to specify the arguments? In another use case, I ...
1
vote
0answers
38 views

How do I define a custom fixer for ALEFix?

I'm trying to use :ALEFix to run a fixer that is not pre-defined. For example, I might want to run foo -a -b index.html to format index.html with options -a and -b. foo does not read files from stdin, ...
19
votes
4answers
13k views

Can I issue an interactive shell in Vim window?

I know I can :! or :r! to execute external command and optionally insert its output into text. I can even perform :!sh and I'll spawn a shell that will live until I exit it - but while the shell is ...
0
votes
1answer
252 views

How can I run awk script with in vim?

We know that we can run commands from vim using :!command <args>. For example: :%!awk '{ print $2,$1,$3 }' FS=',' OFS=',' :%!sort I am having trouble running an awk script within vim. I can run ...
63
votes
5answers
45k views

How can I integrate gdb with Vim?

Instead of gdbtui or ctrl+x under gdb which shows source code on top of the screen I would like to see this in my Vim editor that would jump between tabs, and buffers accordingly. How can I do this?
1
vote
1answer
27 views

How to use the current filename in a shell command?

I would like to run a shell command on the current file - ie, I saved an empty file and would like to delete it. I've found % represents the current filename, but when there are spaces in the filepath ...
4
votes
2answers
695 views

How to get line numbers of selected text

Is it possible to get the line numbers of selected text to pass to an external command? Context: I'd like to integrate pyfmt into vim. Ideally, I'd like to be able to select some text and type some ...
5
votes
3answers
3k views

How do I search google from vim?

I would like to be able to search google from within any vim file. A nice command might be :goo while in normal mode. Then I type what I want to search and bam it opens my default browser with the ...
0
votes
1answer
49 views

What is :silent !echo doing? Why does it get the cursor to the top?

This question on StackOverflow triggered my curiosity. What does :silent !echo doing? The first time I saw something like :excommand !shellcommand was when I was looking for a way to save a read-only ...
1
vote
2answers
153 views

How to run shell commands on file without saving?

For example, if I want to run tidy on a file r! tidy % But I have to save the file beforehand. Is there any way around this?
0
votes
4answers
81 views

“Hard-include” in vim script

I want to: let s:asciiart = ["", "", s:hardinclude(system("command params")), "", ""] where command returns one string with: "art-line-1", "art-line-2", "art-line-3" so I end up with: s:asciiart =...
22
votes
2answers
3k views

How can I make gx recognise full URLs in vim?

By default, if a buffer in vim contains a URL such as http://www.google.com, gx in normal mode will open a browser with that URL. That's very handy. However, if the URL has URL parameters (e.g. http://...
1
vote
2answers
135 views

Check if :make fails

I just setup this mapping for my latex development: nnoremap <buffer> <LocalLeader>o :make %:r.pdf <Bar> !open %:r.pdf<CR><CR><CR> But I wondered about checking if ...
-1
votes
1answer
42 views

Why doesn't xdg-open trigger autoread?

When set autoread,if I run :!kate %, do some editing operations and exit, the file in vim will auto reload to my new changes. However, :!xdg-open % doesn't work. My vim version is: VIM - Vi IMproved 8....
32
votes
2answers
11k views

Extract the result of a shell command to a variable in a .vimrc file?

In my .vimrc file, I would like to store in a variable the result of an external command, in my case: $ echo $LANG So that my .vimrc file would have : let language = output(!echo $LANG) if language ==...
0
votes
1answer
96 views

Formatting using BufWritePost ends up with WARNING

I am trying to format PHP files using the following function: function! PHPCSFixer() let l:fixer_path = '$HOME/....
1
vote
1answer
34 views

Shortcut to open a particular website

I'm using neovim on mac os, in case that information is of use. In the shell I have some aliases such as alias g='open HTTP://google.com For sites that I access regularly, I would like to be able to ...
0
votes
0answers
13 views

Fix line wrapping in external commands

Sometimes when I have a vim instance open for a long time, I'll notice that newlines no longer reset the column in external commands: :! echo a; echo b [No write since last change] a b Press ENTER ...
1
vote
2answers
87 views

How to run external commands in vim from windows OS?

I learn vim in the Debian distro. In debian I can run commands like 'ls', 'cd', 'curl' etc directly from vim via power of '!' this sign. But now I am in windows because of the driver issue. But I don'...
28
votes
5answers
7k views

How to use an external command in Vim to modify selected words and lines?

Something I've found useful in other editors is the ability to: take the selected text run an external command and pass the selection to its stdin take the external commands stdout and replace the ...
2
votes
1answer
328 views

How to make vim shell command wait for keypress?

I have assigned the macro !clear && gcc % && ./a.out to the key 'r'. So when I press '@r', I expect vim to: Clear the shell compile the current C file run the output The problem is ...
3
votes
4answers
620 views

Filter specific lines matching a pattern through external command

I'm trying to filter specific lines through external command. I think knowing how to do this would be extremely beneficial to me, so I'm trying to find a way to do this. As an example, I wanted to ...
0
votes
1answer
72 views

How to import library in my template python script? (not working like in vim like in the repl)

I have a python script for generating templates that's being invoked by this line in my vimrc file: autocmd BufNewFile ~/Documents/wiki/diary/*.mkd :silent 0r !vimwiki-diary-template.py That works. ...
1
vote
2answers
240 views

File emptied when command not found

Given this command: ex -sc '%!alfa' -cx file I get this result: sh: alfa: command not found which is to be expected. However an unintended side effect of this is that the file is emptied and saved....
2
votes
1answer
71 views

How to put the output of a function call into quickfix list?

I have the following function that runs eslint project wise: function! EslintProject() " Allows using eslint --format compact output with quickfix list set errorformat+=%f:\ line\ %l\\,\ col\ %c\\...
7
votes
1answer
183 views

Difference between `:!{cmd}` and `:w !{cmd}` regarding alternate screen

On a Linux platform I see this difference of behavior between running a shell command with :!{cmd} (which just runs the command directly) and with :w !{cmd} (which passes the buffer as standard input ...
9
votes
3answers
4k views

Bash not recognizing aliases when run from Vim [duplicate]

In Vim, when I run this command :!bash -c "ll", I get this error message bash: ll: command not found. ll is an alias in my ~/.bashrc file. If I just enter ll from bash it works. I created a ~/....
1
vote
1answer
55 views

Nvim external commands to write and delete files inside a function

I use Neovim in a Linux (Arch Linux) environment. I have written a function to help me preview my markdown documents in PDF format without using a whole plugin. I've also added a simple command named "...
31
votes
2answers
17k views

Execute current buffer as bash script from vim

I use vim for bash scripting, and sometimes I write a one-time script. Usually, I don't want to create a new file, make it executable, execute it and then remove it. For instance I open vim and type ...
3
votes
2answers
223 views

How can I use a range as input for an external command without deleting it?

I'm executing an external command that takes as input a range of lines within my file. :'<,'>!copy_stuff Running this runs copy_stuff correctly with the currently selected visual range (and it ...
2
votes
1answer
332 views

separate stdout and stderr of system() command

I can catch the output of running a system command via system() or systemlist(), but that actually gives me the result of stdout and stderr combined. As I am only interested in stdout (and may use ...
1
vote
0answers
112 views

How do I prevent Vim from showing my terminal when executing an external command?

I'm running a long, blocking command using execute in Vim as part of a script. Vim shows the underlying terminal while executing the command, which is pretty distracting. function! DoSomething(query) ...
5
votes
1answer
414 views

job_start() command only works with seemingly random job options

I am getting some unexpected behavior when trying to run the zip shell command using Vim's job_start(). As an example, suppose I have two images (im1.png and im2.jpg) in the directory /home/username/...
0
votes
1answer
69 views

Is there a way to change the message “press ENTER or type command to continue” to something else?

I would like to change it to make something like a separator between !python % Change this(my computer is in spanish): To something like: Hello World --------------- Hello World --------------- ...
1
vote
3answers
191 views

How can I create a command to remove non-consecutive duplicate lines?

I'm trying to remove (non-consecutive) duplicate lines in a file I have loaded in vim (without sorting them). In several places on the web I've found the nugget awk '!x[$0]++' as a pipe command that ...
1
vote
1answer
41 views

execute command after it print junk text?

I am using bspwm so I added this line to my .vimrc: au BufWritePost $XDG_CONFIG_HOME/sxhkd/sxhkdrc silent exec "!pkill -USR1 -x sxhkd && sxhkd & So that when I edit sxhkdrc, it ...
0
votes
2answers
108 views

don't capture stderr for git grep as grepprg

I'm trying to use git grep as my grepprg, but I keep getting spurious files such as ~/fatal: Not a git repository (or any of the parent directories): .git. Is there a way to configure vim to correctly ...
5
votes
1answer
273 views

Why is a pipe interpreted as a command termination in :cexpr system('shell cmd')?

If I type: :echo system('grep -IRn foobar ~/.vim | grep -v backup') Vim displays the output of the shell command: $ grep -IRn foobar ~/.vim | grep -v backup Which is the list of files containing ...
1
vote
1answer
21 views

Showing external command output only if not empty

Is it possible to silently run an external command, but show the output on the prompt only if there was any?
2
votes
0answers
55 views

Adjust terminal size using a system call from within Vim

All, I have a little function I'm trying to fix. I'd like to change my terminal Vim window size using the ASCII escape sequence \e[8;40;130t so that my writing window size stays the same when I use a ...
3
votes
1answer
58 views

How to open internal MediaWiki links with their full URL from within Vim?

I have a file in Mediawiki format, containing internal links (in a Mediawiki installation) * [[Topic A]] * [[Topic B]] * [[Vim]] (The asterisks are how MediaWiki lists are formatted, they are not ...