Hot answers tagged

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.


14

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] $ sh # launch child shell [/bar] $ cd /foo [/foo] $ exit [/bar] $ # back in the parent it's still /bar Similarly... [/bar] $ sh # launch child ...


7

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 then terminated. The net effect of asking a shell to change its working directory and then terminate is nothing since the shell never did anything that was ...


6

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") if v:shell_error != 0 echo output endif


4

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} contains spaces it must be enclosed in double quotes (this depends on the shell that is used). Example: Vim "+set si" main.c Note: You ...


4

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 let l:visual = a:0 if l:visual '<,'>!awk '\!x[$0]++' else '[,']!awk '\!x[$0]++' endif endfunction " ~/.vim/plugin/uniq.vim nnoremap U :set ...


4

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>


4

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 '!isort %' | edit One last note, though: it is possible to use the :! form as a filter (see :help :range!), meaning I would use the following code instead: :%!...


4

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 = js_decode(join(s:js_data)) " filter out the skims let s:skims = filter(s:list, 'v:val.app=="Skim"') " do whatever... echo s:skims echo len(s:skims) for s:item ...


4

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 Vimscript: Use systemlist() instead of system(). systemlist() returns a list of lines, which ends up being more natural to handle in Vimscript. Both systemlist() and ...


3

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 suitable for passing as a command line argument to a ! command or filter: :exe "'<,'>!awk" shellescape('!x[$0]++', 1) You can wrap this into a command that ...


3

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 [arg]. The second ! is replaced with last shell cmd, I guess it expand to some command that read the temp file, escape it should work: '<,'>! awk '\!a[$...


3

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 usual effect of this is, that after you quit vim in the terminal, you do not see your old vim screen anymore, but the last commands you issued before starting ...


3

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 unintentionally. So to your questions: 1) Why using single quotes after -name doesn't require * to be escaped with backslashes? :e `find . -name '*.vim' -print` This ...


3

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 ~/.vim/pack/.../start. These plugins all require Vim to run in nocompatible mode (see :help 'compatible'). I looked at two different scenarios: run vim -E ...


3

In :help shell-window we can read about executing shell commands in a window: There have been questions for the possibility to execute a shell in a window inside Vim. The answer: you can't! Including this would add a lot of code to Vim, which is a good reason not to do this. After all, Vim is an editor, it is not supposed to do non-...


3

With VIM I believe the plugins that are there to do this aren't all that great, though IMO vimshell comes the closest. However you need to understand that it's a 2 part problem. VIM wasn't designed to be able to do things like this, especially cumbersome is being able to execute any long running task and talking to it asynchronously without blocking VIM. In ...


3

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 solutions as well Explanation autocmd allows you to specify a filetype (among other things), here sh I use abbreviations (iab) instead of mapping, as this ...


3

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 automatically insert « ending » statements when you hit enter, so if ... <CR> and the fi is added. Perhaps my favorite part is endwise is smart enough not to add ...


3

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 --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q {}' \<CR> Another point is the usage of | in the command line, as it is a command ...


2

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 (with bash) as my bash setups checks for terminal capabilities before configuring a colored PS1 or configuring colored output for ls or grep. Vim 8.0.1609 ...


2

Why does vim call powershell surrounded by two single quotes? For it's own protection, maybe, but more than likely someone was thinking about protection of users too; single quotes should mean "don't expand this string" where as double quotes kinda mean "treat the output of this string as an argument" What variable causes those quotes to be there? The ...


2

use :h :s\= s/\v\#[0-9A-F]{3}[0-9A-F]@!/\=tr(submatch(0), '0123456789ABCDEF','FEDCBA9876543210')/g \#[0-9A-F]{3} match #000, #111, ... #FFF [0-9A-F]@! look forward to make sure #0000 doesn't match. check :h /\@! \= replace with an expression tr(submatch(0), '0123456789ABCDEF','FEDCBA9876543210') transform matching text Since you want to do it manually, a ...


2

Two methods you tried: % !exec-sql.sh :h :range! filter {range} lines through the external program. also check :h ! . w !exec-sql.sh :h :w_c execute {cmd} with [range] lines as standard input. Beware that w ! and w! have total different meaning. If you want to read external command output: :read !exec-sql.sh :h :read! execute {cmd} and insert its ...


2

There doesn't seem to be a good way around what you're looking for. The behavior is clearly documented, in quite some detail, in :help press-enter. In particular: Press : or any other Normal mode command character to start that command. In your case, since you hit that from a CTRL-O means the next keypress will actually be inserted in your text. Note ...


2

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:\Windows. Apparently the Sysnative folder is kind of a virtual folder which exists only from the perspective of 32-bit programs. More info can be found here: ...


2

As any child process inherits the environment from its parent, you can temporarily redefine Vim's own environment before executing your tool: let [temp, $ENV_VAR] = [$ENV_VAR, ''] %!cmd let $ENV_VAR = temp


2

is there another way to run an external command on the alternate screen, that doesn't involve passing it lines from the current buffer as standard input? Try to remove ^[[?1049h from 't_ti' and ^[[?1049l from 't_te': augroup NoAltScreen au! au VimEnter * call s:altscreen(v:true) au VimLeave * call s:altscreen(v:false) augroup END fu s:...


2

That setting only sets the shell used by Terminal. You need to set your log-in shell with chsh -s /bin/bash to make Bash the default one on any other application. You can also try set shell=/bin/bash in your .vimrc


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