52

: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 CTRL+z (to send Vim to the background) and then resume vim with the command fg as usual. To do things asynchronously, take a look at Tim Pope's plugin vim-...


37

:!{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 and replaces them with its output. In your example, :%!jq : % is the range, which means: all the lines of the current buffer It could also be written 1,$ (from ...


35

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 program, such as python or bash. In your case, you would want to do something like: :w !bash or :w !sh These commands literally just write the text in your ...


33

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 consists not entering GDB commands on the GDB terminal, you use shortcuts on the vim source code. But you can continue using the GDB prompt if you want, for more ...


30

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 refresh the screen when back to Vim. To avoid need for refresh, you can define your own custom command, like: :command! -nargs=1 Silent execute ':silent !'.&...


22

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 = systemlist('ls') " ['bin', 'dev', ... ] ref: :h system


17

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. A useful command I use often is: :!python -m json.tool to format JSON. You can also just type (without visual mode): :<range>!command For example, ...


17

: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 next location in the quickfix list. Quickfix commands :cnext/:cprevious to navigate the quickfix forwards and backwards in the quickfix list :cfirst/:clast to ...


16

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 interactive bash shell in vim. You can then use your regular vim gestures to do anything else you may want to do in the window. Also the other plugin is vimshell.


16

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, which is especially useful combined with text objects such as ip. (e.g. you can use vipg<C-g> to get the word count of the current paragraph). See: :...


15

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. Between typing CTRL-R and the second character, '"' will be displayed to indicate that you are expected to enter the name of a ...


13

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> is replaced with the path name under the cursor It escapes me, why parameter parts (i.e. ?) of a URL are being disregarded as parts of a "path name", but I ...


13

By sheer luck I found out that both: :%!jq . % or shorter: :%!jq . work, yet I don't understand why this updates the buffer.


13

If LANG is an environment variable you can just do: let language = $LANG Or, even simpler: if $LANG == 'en' … endif


12

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 actually activate the virtualenv. This lead to a lot of confusion for me since $VIRTUAL_ENV was set. I got around it by adding the following to my ~/.zshenv ...


11

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 a mirror on github where its author has archived his work. Note: pyclewn used to be the last stage step in the evolution of the other Xavier Degaye's *clewn ...


11

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, and they are all joined by a space to produce the final command. function Compile_and_run(game, major, minor) execute '!_compile' a:game a:major a:minor ...


10

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 has completed, and how, so let's use a marker file: :!(rm -f /tmp/finished; slow_command_here > /tmp/output 2>&1; echo "$?" > /tmp/finished) & ...


10

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 python set makeprg=python\ % au FileType coffeescript set makeprg=coffee\ -c\ % noremap ,b :make<CR> :make was originally intended to run the make tool ...


10

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 mode. In non-interactive mode alias are not expanded and you get this error. I don't know if you'd be able to enable the shell option expand_aliases from these ...


10

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 files is to use :args **. But this will include folders too. I'm not completely sure why you need to enclose it in single quotes, I believe that Vim will evaluate ...


10

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 that, you can use the system() function like this: autocmd BufWritePost *.cpp call system("ctags -R") autocmd BufWritePost *.h call system("ctags -R") You ...


10

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 those lines with the program's output. In this case you want to use % as the range, which means the entire buffer. For example: :%!sort You can find the Vim ...


10

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 = getreg("g") silent! exec "silent! !firefox \"http://google.com/search?q=" . searchterm . "\" &" endfunction vnoremap <F6> "gy<Esc>:call ...


9

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.txt/.txt/.asc} which bash will call a bad substitution; You are trying to expand a variable called myfile.txt, and bash doesn't support variable names with . ...


8

You can use the expression register "= and system(): <C-r>=system("uuidgen | tr -d '\n'")<CR> It would look like that in an insert mode mapping: inoremap <key> <C-r>=system("uuidgen | tr -d '\n'")<CR> or, with an expression mapping: inoremap <expr> <key> system("uuidgen \| tr -d '\n'")


8

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 - creates new split read - to get the command output command - actual command


8

This works as designed, and is documented under :help :silent: ":silent" will also avoid the hit-enter prompt. When using this for an external command, this may cause the screen to be messed up. Use |CTRL-L| to clean it up then. You can also use the :redraw command.


8

Go out with a bang From :help :make: If [!] is not given the first error is jumped to. Running :make! will execute the command given by 'makeprg' (just as :make does), but will not jump to the first position in the quickfix list. Thus, your cursor position remains intact. The quickfix list will still be populated. Just as after running :make, :...


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