70
votes
How to execute shell commands silently?
:silent exec "!command"
Note that your vim session will still be occupied while your command is executing. This is due to Vim's synchronous nature. You can still get back to your shell by pressing ...
60
votes
Accepted
How to run bash command over current file and replace buffer with result?
:!{cmd} sends {cmd} to the shell which executes it and shows its output on the screen.
:{range}!{filter} sends the lines from the current buffer inside {range} as the input of the {filter} program ...
49
votes
Accepted
Execute current buffer as bash script from vim
I wrote a pretty extensive answer about this over on stack-overflow. The basic idea is that since the write command is about writing not saving, you can write the text in your buffer into an external ...
41
votes
Accepted
Extract the result of a shell command to a variable in a .vimrc file?
You can do this with the system function:
let language = system('echo $LANG')
Bonus point: if your output is a list, you can use the systemlist instead to get back a list. e.g.
let files = ...
37
votes
How can I integrate gdb with Vim?
Among all the plugins I have tried, I found ConqueGDB to be the best approach. ConqueGDB uses Conque Shell to embed an interactive shell inside vim, that is used by GDB.
The workflow with ConqueGDB ...
35
votes
How to execute shell commands silently?
To execute a command without triggering the Enter message, like:
Press ENTER or type command to continue
try the following simple example:
:silent !echo Hello
Then press Ctrl+L (or :redraw!) to ...
30
votes
How to go to the next grep result?
:grep/:vimgrep both use the quickfix list to store locations. As you have noticed vim will automatically jump to the first occurrence (use ! to avoid this behavior). Simply use :cnext to go to the ...
25
votes
How to use an external command in Vim to modify selected words and lines?
I find that often the easiest way is to use visual mode with v (or capital V to select whole lines), and select the text you want to pipe.
Then type:
:!cat
This doesn't do anything useful, as such. ...
19
votes
Accepted
How do I count the words in a part of a file, without leaving vim?
You can use gCTRL+g, which will give you:
Col 1 of 118-121; Line 1 of 5; Word 1 of 142; Byte 1 of 678
You can also use this from visual mode, if you want to get the word count for just the selection,...
19
votes
How to run bash command over current file and replace buffer with result?
By sheer luck I found out that both:
:%!jq . %
or shorter:
:%!jq .
work, yet I don't understand why this updates the buffer.
17
votes
Accepted
Can I issue an interactive shell in Vim window?
There are a couple of vim plugins that allow for this. I use Conque (Github).
After putting it in your plugins directory all you have to do is:
:ConqueTermSplit bash
And you will have an ...
16
votes
Accepted
How do I get Vim to compile my .tex file when executing :w?
Don't be so inefficient! Your time is valuable. Use the vimtex plugin offered by @lervag: see here. You can control all of the plugins you install by using Vundle or any similar plugin manager (vim-...
16
votes
Accepted
Use Vim with virtualenv
I actually fixed this myself a long time ago. The problem is that when you run !python you're starting up a new shell with your existing environment. But, this means workon xxxx wasn't called to ...
15
votes
Accepted
How can I make gx recognise full URLs in vim?
As @Carpetsmoker points out in his comment, g:netrw_gx determines what will be considered part of a URI.
By default it is set to "<cfile>". From the docs (:help <cfile>):
<cfile> ...
15
votes
Replace selection with output of external command
You could delete the text and insert the output of a command using CtrlR-=:
CTRL-R {0-9a-z"%#*+:.-=} i_CTRL-R
Insert the contents of a register. ...
15
votes
Extract the result of a shell command to a variable in a .vimrc file?
If LANG is an environment variable you can just do:
let language = $LANG
Or, even simpler:
if $LANG == 'en'
…
endif
14
votes
How do I insert the output of an external command at the cursor position?
In normal mode press double !, then enter the command, or just type the following:
:.!ls
13
votes
Accepted
function to call shell script with arguments
Using :execute
All command arguments in Vim are interpreted literally unless designed to be evaluated. To build a command dynamically, you can use :execute. Each argument to :execute is evaluated, ...
13
votes
Accepted
get exit status from system() call
Mentioned in the comments above, the v:shell_error variable gives the result of the last shell command. So the exit status can be tested as follows:
let output = system("my_shell_command")
...
12
votes
How to execute shell commands silently?
A quick and dirty solution (in pure Vimscript)
This can start a process in the background:
:!slow_command_here > /tmp/output 2>&1 &
But Vim needs a way to find out when the process ...
12
votes
How can I integrate gdb with Vim?
You have several plugins that integrates gdb.
We used to have pyclewn. The project has been discontinued after version 2.3. The last commit has been made in 2016. For the curious ones there is still ...
11
votes
Bash not recognizing aliases when run from Vim
Your issue is with bash and not with vim. The problem is that when you run !<cmd> in vim or /bin/bash -c <cmd> from another shell you are launching an instance of bash in non-interactive ...
11
votes
Accepted
Why vim cannot expand wildcards from the external command?
You were close. Enclose the path pattern in single quotes instead of double quotes for the find command like so:
args `find . -type f -not -path '*/\.*'`
By the way, a handy way to ignore hidden ...
10
votes
Accepted
Run shell commands on current file based on file extension
You could use :make for this; you can set makeprg (short for make program) to any command.
Some examples:
au FileType ruby set makeprg=ruby\ %
au FileType javascript set makeprg=node\ %
au FileType ...
10
votes
Accepted
How do I execute "ctags -R" on saving *.h and *.cpp files without a confirmation prompt?
When you execute an external command with :!, Vim doesn't know what the external command might have written to the terminal, so it waits for you to confirm that you are ready to continue.
To avoid ...
10
votes
Accepted
How to avoid to press ENTER twice, when compiling with :make inside vim
Vim displays the "Press ENTER" prompt when the number of lines printed in the command area is greater than the number of lines it has available. This is to ensure the user doesn't miss a message.
The ...
10
votes
Accepted
External command on unsaved buffer
You can use the "filter" command,:!, which like most commands can be prefixed with a range:
:{range}!cmd
If you prefix this with a range, it will pipe those lines to the command's stdin, and replace ...
10
votes
Accepted
How do I search google from vim?
You have a couple of options here:
Using a plugin:
vim-g
gsearch
vim-quicklink
Or, if you prefer a lightweight solution, you can try the following:
function! GoogleSearch()
let searchterm = ...
10
votes
How can I import output from linux commands into vim for editing?
You could use :read (see :h :read):
:[range]r[ead] [++opt] !{cmd}
Execute {cmd} and insert its standard output below
the cursor or the specified line. A temporary file is
For ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
external-command × 215command-line × 34
vimscript × 24
shell × 13
bash × 12
vimrc × 11
key-bindings × 10
terminal × 10
microsoft-windows × 10
neovim × 8
ex-mode × 8
autocmd × 7
buffers × 6
filetype-tex × 6
register × 6
gvim × 5
filter × 5
search × 4
vim-windows × 4
functions × 4
linux × 4
save × 4
filesystem × 4
indentation × 3
visual-mode × 3