66 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 ...
saginaw's user avatar
  • 6,706
51 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 ...
DJMcMayhem's user avatar
  • 17.4k
44 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 = ...
nobe4's user avatar
  • 15.9k
33 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 ...
Peter Rincker's user avatar
21 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.
k0pernikus's user avatar
  • 2,957
18 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
Ruslan Osmanov's user avatar
17 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. ...
muru's user avatar
  • 24.7k
17 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
muru's user avatar
  • 24.7k
17 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 ...
Tommy A's user avatar
  • 6,710
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-...
fuzzybear3965's user avatar
16 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") ...
Jasha's user avatar
  • 493
11 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 ...
Martin Tournoij's user avatar
11 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 ...
joeytwiddle's user avatar
  • 3,592
11 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 = ...
nobe4's user avatar
  • 15.9k
10 votes

Can I issue an interactive shell in Vim window?

Just use :vertical terminal and then just map it to a key or something. Also, I have this in my vimrc: map <Leader>t :set mouse=a<CR>:vertical terminal<CR> That enables me to switch ...
Jose Membreno's user avatar
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 ...
statox's user avatar
  • 49.4k
9 votes

How to execute shell commands silently?

If you don't care about exit code, you can go with this: :call system('/usr/bin/zathura using-docker.pdf &')
hsnotebook's user avatar
9 votes

How to execute shell commands silently?

Running a command in the background I was running a command that blocked for a bit, and I didn't really care about the output. This can be taken care of by starting the process attached not to the ...
dylnmc's user avatar
  • 223
9 votes

How can I integrate gdb with Vim?

Vim 8.1 adds debugger integration, see :help terminal-debug. The summary is that you run :packadd termdebug :Termdebug myprogram And then you can set breakpads either in the gdb buffer using b myfunc,...
thakis's user avatar
  • 251
9 votes

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

You can use this command : :new | 0read ! command This will open up a new split and puts the output of the command in this split (though not in the currently active split as you mentioned). new - ...
meain's user avatar
  • 247
9 votes

How to use backtick-expansion to populate the arglist?

I still don't know how to use backtick-expansion to populate the arglist with an arbitrary shell command, however I've found a workaround. From :help `=: You can have the backticks expanded as a ...
saginaw's user avatar
  • 6,706
9 votes
Accepted

Use shell variable substitution with current filepath

Why doesn't this work? This doesn't work for exactly why you say, vim is replacing the % with the path. So, your non working line :! mv % ${%/.txt/.asc} is expanding to :! mv myfile.txt ${myfile....
John O'M.'s user avatar
  • 8,472
9 votes

Why do exclamation ! shell commands in GVIM show error: "syntax error near unexpected token (" for "ls() ("?

Instead of adding -i to shellcmdflags and reading your entire .bashrc just for loading aliases, keep your aliases in a separate file, like ~/.bash_aliases for Ubuntu, and add to your vimrc: let $...
muru's user avatar
  • 24.7k
9 votes

Prevent "Press ENTER or type command to continue" prompt after external command executes

If what you're looking for is a way to automate the sequence of commands (:silent grep and redraw!), then consider creating a new user-defined command for that operation. (In fact, Vim documentation ...
filbranden's user avatar
  • 28.4k
9 votes
Accepted

job_start() command only works with seemingly random job options

I think I figured this out myself. I believe the problem was that my job was being deleted before the zip command finished. I guess Vim deletes a job object if there are no references to it. So the ...
Trevor's user avatar
  • 477
8 votes

How to execute shell commands silently?

Vim 8 introduced jobs support. One can run external command in the background without relying on plugins. For example, to run a markdown server (markserv) at current location and not block vim session:...
KFL's user avatar
  • 575
8 votes

How can I integrate gdb with Vim?

GDB edit command Opens an editor on the current line using the command: $EDITOR +<current-line> <current-file> The default editor is ex, but vim also understands the +<current-line&...
Ciro Santilli OurBigBook.com's user avatar
8 votes
Accepted

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

In a regular shell: $ env | grep -i vim EDITOR=vim After using :shell $ env | grep -i vim EDITOR=vim VIMRUNTIME=/usr/share/vim/vim80 VIM=/usr/share/vim MYVIMRC=/home/martin/.vim/vimrc So it looks ...
Martin Tournoij's user avatar
8 votes

How to get line numbers of selected text

The line numbers of the selected text are available in the marks < and >. So you can use e.g. echo getpos("'<") and echo getpos("'>") to get the start and end of the selected text. ...
Christian Brabandt's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible