62
votes
Fully disable mouse in console Vim
You should add the following two lines at the end of /etc/vim/vimrc :
set mouse=
set ttymouse=
52
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 ...
29
votes
Accepted
How to run the history search in Vi mode in bash
There certainly is Vim style searching in bash/readline. In fact, your command line is essentially a scaled down version of the Vim editor with a significant number of Normal mode commands available ...
10
votes
VIM: how to send entire line to a buffer of type "Terminal"?
Here is a solution using Vim's term_sendkeys()
open a vim terminal and start the REPL
check which buffer the terminal is in with :ls
this example assumes the terminal is in buffer 2
cmd to copy the ...
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 $...
8
votes
Accepted
Open multiple files in custom split layout
You could try it like this:
vim -c "lefta vsplit file2.txt|split file1.txt" file3.txt
With the option -c you can specify commands that should be executed after the first file was loaded.
So ...
7
votes
Accepted
How to set the vim path to your bash PATH?
&path has nothing to do with $PATH.
Also $PATH is set and used. See :echo $PATH.
You should also be able to change its value with :let $PATH = $PATH.':some/path' -- there are a few write only ...
7
votes
Accepted
vi editing of bash command line: Avoid execution upon exit?
I often just prepend the command with #. After exiting vim it's then in the bash history.
7
votes
Open multiple files in custom split layout
Actually, you don’t need saved sessions for this; vim -S will happily accept any file containing vimscript. So, write some commands for your custom layout (stolen from the other answer)
edit file3
...
6
votes
Fully disable mouse in console Vim
This might work if you put it at the end of your .vimrc
set mouse=c
It's probaly not Vim that takes the mouse input, but rather your Terminal-emulator. To disable mouse support on your terminal this ...
6
votes
Accepted
Source a vimrc from a webpage?
From :h -u:
-u {vimrc} The file {vimrc} is read for initializations. Most other
initializations are skipped; see |initialization|. This can
be used to start Vim in a special mode, ...
6
votes
Execute current buffer as bash script from vim
Scenario: you are working in bash shell. First, make sure the local edit mode is vi:
$ set -o vi
Now, when you find yourself working on a long command like the following, hit Esc+v.
$ fjhwfq this ...
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} ...
6
votes
Accepted
Run processes in shell while editing in Vim
For general purpose multi-window terminal experience, look into tmux. Tmux, a terminal multiplexer, provides functionalities to split a terminal window into several vertical and horizontal splits, ...
6
votes
Accepted
Shell syntax highlighting
This is because the original Bourne shell only understands `...` - the standard $( ... ) syntax was added later. From syntax/sh.vim:
" $() and $(()): {{{1
" $(..) is not supported by sh (...
6
votes
Accepted
Syntax highlighting for shell scripts broken
It is a known bug which is fixed in the author's source code, see author's reply.
It should appear sometime in the future in main vim runtime.
5
votes
Accepted
Why doesn't vim recognize bash self-made functions
External commands are not executed in an interactive shell so your .bash_profile is not read. To make your custom command available you must turn it into an actual shell script, put it in your $PATH, ...
5
votes
Bash not recognizing aliases when run from Vim
Here's a strategy I use for this that utilizes the BASH_ENV which you can read about in man bash (and below). This strategy focuses specifically on what I want made available in vim.
When bash is ...
5
votes
Accepted
How to comment a line directly from bash using vim?
You can use:
vim +'normal! 2GI;' +'x' path/to/your/file
The + parameter allows to execute a command after opening the buffer.
The first command normal! 2GI; goes to line 2 and add a ; at the ...
5
votes
Accepted
How to prevent accidentally piping text to Vim?
As @chicks pointed out, you can place this script in your PATH:
#!/usr/bin/env bash
if [[ "$#" -ne 0 ]] || [[ -t 0 ]]; then
exec vim "$@"
else
exec vim -
fi
I am using a variant of this ...
5
votes
VIM: how to send entire line to a buffer of type "Terminal"?
As Luc Hermitte pointed out, you can use :h term_sendkeys to send commands to terminal buffer, the hard part is to manage the terminal buffer:
function s:exec_on_term(lnum1, lnum2)
" get terminal ...
5
votes
How to restart vim from within vim?
Add this in your vimrc:
nno <space>R :<c-u>call <sid>vim_quit_and_restart()<cr>
fu! s:vim_quit_and_restart() abort
if has('gui_running') | echo 'not available in GUI' | ...
4
votes
How can you use vim as a stream editor?
To avoid screen flashes when editing stream non-interactively, you need to start Vim in Ex mode by adding -e (Ex mode) or -E (improved Ex mode) into your command-line arguments.
Here is the simple ...
4
votes
vi editing of bash command line: Avoid execution upon exit?
How to do it
Bash doesn't seem to provide builtin support for this in form of a readline function like it does for editing and executing. However, there is bind -x command to invoke arbitrary shell ...
4
votes
Source a vimrc from a webpage?
AFAIK, source doesn't let you source anything other than a file.
This function is a little bit dirty but it works:
function! GetAndSource(url)
execute '!curl ' . a:url . ' -o vimrc.vim'
source ...
4
votes
Vim won't return to foreground
If you are seeing this when using zsh versions 5.7 through 5.8.1, it is due to a known bug that has been fixed by Erik Paulson in zsh 5.9:
https://www.zsh.org/mla/workers/2021/msg01255.html
What's ...
4
votes
Accepted
multiple shell command execution failed
Quoting from the help (:h E34)
Any '!' in {cmd} is replaced with the previous external command
And further in the help (:h :bar)
These commands see the '|' as their argument, and can therefore ...
4
votes
Accepted
Why do I get "incompatible error" while opening .sh files using vi in cygwin?
The option name is nocompatible. Replace incompatible with nocompatible to solve your problem.
4
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 ...
4
votes
Accepted
Cannot sort my bash functions correctly
Try to add the negative offset -1 to the second line specifier in the range passed to the first substitution command:
v
:g/^function /,/^}/- s/\n/@@@
:sort /^function /
:%s/@@@/\r/...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
bash × 102vimrc × 14
external-command × 12
shell × 12
command-line × 9
syntax-highlighting × 8
linux × 8
terminal × 7
vimscript × 5
neovim × 5
gvim × 4
microsoft-windows × 3
macvim × 3
invocation × 3
key-bindings × 2
autocmd × 2
indentation × 2
netrw × 2
ex-mode × 2
comments × 2
macos × 2
multiple-files × 2
color × 2
escape × 2
lsp × 2