Questions tagged [external-command]

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

Filter by
Sorted by
Tagged with
82
votes
9answers
50k views

How to execute shell commands silently?

:!<command> can be used to execute a command in the shell. But this "takes over" my terminal and fills it with stdout of that particular command. How do I execute a command in the background ...
63
votes
5answers
44k 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?
52
votes
2answers
16k views

How to run bash command over current file and replace buffer with result? [duplicate]

I currently deal with lots of json files and am quite fond of the bash comand jq, e.g. if I want to format the file I do jq . ugly.json > formated.json Now, I don't want to leave vim, but run it ...
32
votes
2answers
10k 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 ==...
30
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 ...
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 ...
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://...
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 ...
18
votes
2answers
7k views

How can I change Vim's start or intro screen?

When I start Vim without any files, I always see this: VIM - Vi IMproved version 7.4.580 by Bram Moolenaar et al. Vim is open source and freely distributable ...
14
votes
6answers
14k 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 ...
13
votes
1answer
1k views

How to use backtick-expansion to populate the arglist?

From help :help backtick-expansion: On Unix and a few other systems you can also use backticks for the file name argument, for example: :next `find . -name ver\\*.c -print` :view `ls -t *....
12
votes
3answers
7k views

Is it possible to have the output of a :! command in a split rather than the whole window?

If I have a vim session with two splits, when I execute a :! command, the result is shown in the entire window. Is it possible to have the output shown just on the active split?
11
votes
1answer
5k views

How to go to the next grep result?

I'm using grep to find function occurrences in a project. :grep "set_val" * Goes out of vim and outputs: code.py:68: self._device.set_val('Level', new_level) code.py:84: self._device....
11
votes
4answers
272 views

:read after cursor instead of after line

I use :r !uuidgen frequently to insert a new uuid into the buffer. This works, but I am generally attempting to insert the uuid between quotes, and :r !uuidgen prints the uuid on a new line. To get ...
10
votes
5answers
3k views

Replace selection with output of external command

Assuming I have a line in a file with XXXX being a placeholder I have selected via v as follows: XXXX Some other text How can I change only the XXXX with the output of an external command, such as ...
10
votes
3answers
3k views

How do I count the words in a part of a file, without leaving vim?

I have a file full of text (say Markdown or LaTeX). I would like to count the number of words in a part of this file. I know I can do :! wc -w % to run wc -w on the current buffer. And I know that I ...
10
votes
1answer
8k views

Use Vim with virtualenv

I do a lot of Python and I use almost all the time a virtualenv along with virtualenvwrapper to keep my modules organised. But when I want to use those plugin from inside vim, through an external ...
10
votes
2answers
433 views

External command on unsaved buffer [duplicate]

Is it possible to pipe an unsaved buffer to an external command and then replace the buffer by the command’s output?
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 ~/....
9
votes
3answers
3k views

How do I know i am in a shell from vi command :sh?

In vi, I can get a shell terminal with :sh command. And later, I can return to vi by exit shell. But, if I was using the shell terminal for a long time, and I forgot whether exit will close anything ...
9
votes
1answer
5k views

function to call shell script with arguments

I am making my own function to call a bash script that compiles and runs my program. Here is the code I have tried. function Compile_and_run(game, major, minor) !_compile a:game a:major a:minor ...
9
votes
1answer
181 views

How to modify visually selected block with external command?

I have a file that is made up of two vertical parts. On the left side, the data is already formatted and I don't want to change it. I only want to format the data on the right side. Say I have a file ...
8
votes
2answers
534 views

How do I execute “ctags -R” on saving *.h and *.cpp files without a confirmation prompt?

This is a noob question, so basically in vim I want to run ctags -R when I am writing to my source or header files (*.h or *.cpp) so I tried the following: autocmd BufWritePost *.cpp :!ctags -R ...
8
votes
1answer
485 views

Run shell commands on current file based on file extension

I'm currently doing a lot of work with both Ruby and JavaScript. I know that I can run my Ruby files with :! ruby % and likewise my JavaScript with :! node %, and that I can bind either of those to, ...
8
votes
4answers
2k views

Put a process started with ! in the background

If I do this from the shell: $ sleep 100 I can make it go to the background by doing: ^Z $ bg And then continue using my shell. You can get the same effect by adding a & to the end of the ...
8
votes
1answer
4k views

Define custom commands for the * and + registers

If I'm using a build of Vim with the xterm_clipboard feature then the system clipboard content is available through the + register. If the build I'm using doesn't have this feature, can I make the "+ ...
7
votes
2answers
4k views

How to avoid to press ENTER twice, when compiling with :make inside vim

I love to use vim as simple IDE when comiling C/C++ programs (let say with gcc on a linux terminal), just inside vim with command: :w | make | cw In that way: the :w vim command save editing the :...
7
votes
2answers
4k views

How to render html file?

I've the following sample html code: vim http://example.com/ Is there any way to actually render html inside vim editor? In example using markdown formatting or something similar? Example scenario: ...
7
votes
1answer
3k views

Why vim cannot expand wildcards from the external command?

The following command works as expected within vim: :args `find . -type f` as well as this one (with wildcard): :args `find . -name \*.inc` However when I run the following: :args `find . -type f -...
7
votes
1answer
1k views

:silent makes my vim go blank

When I used :silent to run a terminal command in the background, my vim screen goes blank, until I navigate through my code, at which point each line I move to reappears. What gives?
7
votes
1answer
612 views

Can I pass a custom string to the 'gx' command?

I have a file like this: vi.stackexchange.com example.com duckduckgo.com I want to be able to open these sites with gx; this doesn't work because there's no protocol (http://) in front of these ...
7
votes
1answer
177 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 ...
7
votes
1answer
351 views

Why does vim add ^J to the end of my macros?

I wrote short macro that helps me grep for the word under the cursor. Here it is in my .vimrc: let @a=":! git grep ^R^W^M" However, when I open vim and run :reg a, I see the following: "a :! git ...
6
votes
2answers
256 views

Can I run :make without moving the cursor?

I use the mapping nnoremap <leader>m :w \|silent make\|redraw!\|cw<CR> which allows me to run make while I am editing a file by pressing <leader>m. It annoys me that if my cursor is ...
6
votes
1answer
373 views

running external command on contents of register

I know I can use ranges/marks with the ! command like so: %! column -t etc. Is there any way to pass a register to the external command instead of the current buffer? I imagine it would look ...
6
votes
3answers
3k views

How to run zsh aliased command from vim command mode?

I have a bunch of really useful terminal programs which I use often while I am editing or writing. For example, dictionary is a popular one and I have aliased its usage to single character d in .zshrc ...
5
votes
3answers
271 views

`Read` seems to bring an extra line - how to prevent this?

I set up this function in my .vimrc file. It duplicates the current window, moves it to a new tab, reads the output of yapf (a code formatter) run on the current file, sets up a diff between the ...
5
votes
4answers
566 views

How to dump output from external command into editor?

In example, I would like to paste the current time or date into editor by using external commands (such as date) without leaving vim. How this can be achieved?
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 ...
5
votes
1answer
996 views

get exit status from system() call

Calling the function system("<command>") or systemlist("<command>") retrieves the stdout output from a shell call to <command>. How can I retrieve the exit status of that command? ...
5
votes
1answer
223 views

Use shell variable substitution with current filepath

I want to be able to easily change the filename. This works: :! var=%; mv % ${var/.txt/.asc} But this doesn't: :! mv % ${%/.txt/.asc} My questions: Why doesn't this work? Doesn't VIM simply ...
5
votes
2answers
712 views

how to perform multiple grep passes by using piping in external shell?

When I want to recursively search files for a text pattern I use :grep -R 'color:' . Vim then lists the results in a quicklist window for easy access. But now I need to perform another grep pass to ...
5
votes
1answer
388 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/...
5
votes
1answer
4k views

How to escape single quote in Vim

I have this mapping in my .vimrc nnoremap <silent><leader>vlc :exe "!open -a vlc '".getline('.')."'"<CR> It does work great with some files, but I'm getting ...
5
votes
1answer
589 views

How do I execute an external command without jumping out of vim?

I want to execute some external program to format my code. :silent execute "!eslint --fix -o /dev/null %" | redraw! But the screen will jump to the shell output screen and shortly back to vim again. ...
5
votes
2answers
247 views

How can I filter a buffer to an external command on save without causing any side effects?

Since importing a package and not using it in Go is a compilation error, fixing the import manually can be a bit of a pain while debugging, so I'm currently using this to fix it up automatically ...
5
votes
1answer
335 views

How can I make text formatting ignore concealed characters?

Question Working with text and various markup languages in Vim I have recently experimented with the conceal feature to hide some of the more verbose markup. I switch conceal off when writing and ...
5
votes
2answers
1k views

Edit Neovim terminal commandline within the same Neovim instance

In bash one can edit the current commandline in $EDITOR by pressing <c-x><c-e>. I am running bash inside a terminal buffer within Neovim. I would like to be able to press <c-x><c-...
5
votes
1answer
2k views

Using Vim Diff To Create A Patch File?

I'm currently using vim 7.3 on Windows 7. The first question I have is it even possible to create the patch file from within vim itself? I understand the basic idea, but anytime I attempt to run ...
5
votes
1answer
259 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 ...