Hot answers tagged

20 votes
Accepted

Why is it not possible to kill Vim using the TERM signal from inside Vim itself?

A process can block, ignore, or catch signals. You can see how a given process handles signals with this shell command: $ cat /proc/PID/status | grep -E '^Sig(Blk|Ign|Cgt):' ...
user938271's user avatar
  • 5,897
19 votes
Accepted

Why does !cd not change the directory

I assume you are aware, generally, of the notion of parent and child processes. Particularly with respect to shells. Let's say I'm in the shell. My prompt shows the current directory ($PWD)... [/bar] ...
B Layer's user avatar
  • 19.7k
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
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
Accepted

See what Vim `:!` executes

When you use ! or :! Vim builds the invoking command based on whatever is specified in the various 'shell...' settings (i.e. 'shell', 'shellcmdflag', 'shellquote', to name three). On Unix systems the ...
B Layer's user avatar
  • 19.7k
8 votes

Why does !cd not change the directory

Since vim is not a shell and you executed a shell command, you must have also executed a shell. You then told that shell to execute the cd command, which will change its working directory. The shell ...
David Schwartz's user avatar
8 votes
Accepted

How to color VIM ":!{cmd}" output?

The video shows Vim, not Neovim. In Neovim the output of "bang" is not colorized. If you like long stories you can read this and this and so on. TL;DR they think it's not a big deal, but ...
Matt's user avatar
  • 20.6k
7 votes

See what Vim `:!` executes

Is there a way to see exactly what shell command is being called out? To see what exactly is run, :echo getpid() will show vim's PID, e.g. 1234, with which you can then in another terminal run: sudo ...
JoL's user avatar
  • 550
6 votes
Accepted

Execute Vim commands from shell

From vim manpage: -c {command} {command} will be executed after the first file has been read. {command} is interpreted as an Ex command. If the {command} ...
AnonymousLurker's user avatar
6 votes

How to chain shell command with vim Ex command?

The help for :! says: A '|' in {cmd} is passed to the shell, you cannot use it to append a Vim command. See |:bar|. The usual workaround is to use :execute, which can be followed by |: :execute '!...
D. Ben Knoble's user avatar
  • 25.8k
6 votes
Accepted

Parsing output of json file with jq

VimScript has a JSON parser of its own. There's no need to invoke an external utility. A sample code: " read in file let s:js_data = readfile('windows.json') " decode into Vim variable let s:list = ...
Matt's user avatar
  • 20.6k
6 votes
Accepted

How to put partial command in command bar?

This is one of the very rare cases in which feedkeys() is actually called for. Doing :call feedkeys(':!python %') should work, since feedkeys puts stuff directly on vim's input buffer.
D. Ben Knoble's user avatar
  • 25.8k
6 votes

How to put partial command in command bar?

while the normal command doesn't seem to work normal must always return to Normal. It is considered normal in Vim. I am trying to do something like this, from a function Not really useful for this ...
Matt's user avatar
  • 20.6k
5 votes

Parsing output of json file with jq

As @Matt points out, you can parse JSON natively in Vimscript, that's the best solution to your problem. But still, two main recommendations here, for interacting with external commands from ...
filbranden's user avatar
  • 28.6k
4 votes

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

When I run :%!awk '!x[$0]++' in my vim, I get E34: No previous command. I fixed it by escaping the ! (see :help :!). Mapping: " ~/.vim/autoload/uniq.vim function uniq#operator(type, ...) abort ...
D. Ben Knoble's user avatar
  • 25.8k
4 votes
Accepted

How to indent text between specific line numbers in vim?

See the last command mentioned here :h shift-left-right :[range]> {count} [flags] So for your example :40> 21 Alternatively, if you don't want to do any arithmetic in your head: :40,60>
B Layer's user avatar
  • 19.7k
4 votes

Unable to set WSL as the shell on gVim

Ok, my bad. Turns out the path should really be C:\Windows\Sysnative\wsl.exe, as mentioned in the linked question. I changed it to System32 because I couldn't find the Sysnative folder under C:\...
Dev N's user avatar
  • 191
4 votes
Accepted

How to turn this piped bash command into a vim map?

The main issue that needs fixing here is that the | character is special here, it is used as a separator for Ex commands and is not passed verbatim to your mapping. In order to fix it, you need to ...
filbranden's user avatar
  • 28.6k
4 votes

See what Vim `:!` executes

An easy check is :!foo that (probably) will print something like bash: line 1: foo: command not found. Also see :h job_start() (or :h jobstart() for Neovim) and so on. To summarize: :! always uses &...
Matt's user avatar
  • 20.6k
4 votes
Accepted

How to use value under cursor in the shell command?

If you are typing interactively in the vim command line you can hit CtrlrCtrlw to include the current word or CtrlrCtrla to include the current WORD. If you are writing a function or a command you can ...
Vivian De Smedt's user avatar
3 votes

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

It's possible to get Vim to handle all the necessary escaping for you by calling shellescape(). If you pass in a non-zero value for its second argument, this will escape characters in a manner ...
Rich's user avatar
  • 31.6k
3 votes
Accepted

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

From :h :range! Filter {range} lines through the external program {filter}. Vim replaces the optional bangs with the latest given command and appends the optional ...
dedowsdi's user avatar
  • 6,238
3 votes
Accepted

Shell running inside vim windows

You need Vim 8.1, then you can use the following command: :below terminal ++rows=10 Normally a terminal is opened above the current window, but with below it is opened at the bottom. And in this ...
Ralf's user avatar
  • 9,147
3 votes

Weird characters when running :shell

You are doing this in GVim and this only provides a terminal with limited capabilities. The command echo $TERM returns "dumb". Might be your zsh /oh-my-zsh setup can't handle this. It works for me (...
Ralf's user avatar
  • 9,147
3 votes
Accepted

Could backtick-expansion be consistently used for autocompleting filenames within directory tree?

Let me try to answer your questions here. We are going to touch shell command language here. It basically comes down to quote the arguments correctly, so that the shell does not expand them ...
Christian Brabandt's user avatar
3 votes
Accepted

Why is `vim -E` always exiting with non-zero exit code when using here-doc?

This is a interesting question and I'm not sure I fully understand what is going on. So here are my findings based on my Vim setup. My setup contains some plugins (mainly self written) installed in ~...
Ralf's user avatar
  • 9,147
3 votes

what does "\033]110\007\033]111\007" mean

t_ti and t_te are used by Vim (in the terminal) to switch between the different screens. The whole detail of this is described at :h xterm-screens and those are xterm terminal control sequences. The ...
Christian Brabandt's user avatar
3 votes
Accepted

Shell scripting: A more elegant way to complete then...fi, do...done, case...esac pairs?

Here's what I would go for: autocmd FileType sh iab <buffer> then then<CR>fi<C-o>O<SPACE><BS><C-o>z That's for the then...fi, but you can apply it for the 2 other ...
Zorzi's user avatar
  • 1,111
3 votes

Shell scripting: A more elegant way to complete then...fi, do...done, case...esac pairs?

Personally, I’ve used endwise for a few years and been satisfied. It’s easy enough to add other languages if necessary, but it supports shell (among many others) out of the box. It will ...
D. Ben Knoble's user avatar
  • 25.8k
3 votes

Vi: how to use bash from the vi command line?

In Vim line continuation is done with a backslash on the new line. Like: noremap <C-F12> :!bash -c ' \git rev-parse --show-toplevel \\| xargs -I {} \ ctags -R ...
Ralf's user avatar
  • 9,147

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