Skip to main content
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=
Georgi Stoyanov's user avatar
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 ...
DJMcMayhem's user avatar
  • 17.9k
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 ...
B Layer's user avatar
  • 20.1k
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 ...
DC Slagel's user avatar
  • 266
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
  • 25.1k
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 ...
Ralf's user avatar
  • 9,417
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 ...
Luc Hermitte's user avatar
  • 17.8k
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.
laktak's user avatar
  • 2,983
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 ...
D. Ben Knoble's user avatar
  • 27.7k
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 ...
Gustav Blomqvist's user avatar
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, ...
user9433424's user avatar
  • 6,198
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 ...
roblogic's user avatar
  • 707
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
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, ...
3N4N's user avatar
  • 5,934
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 (...
muru's user avatar
  • 25.1k
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.
Maxim Kim's user avatar
  • 13.9k
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, ...
romainl's user avatar
  • 42.3k
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 ...
shmup's user avatar
  • 1,184
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 ...
statox's user avatar
  • 50.5k
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 ...
LEI's user avatar
  • 1,656
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 ...
dedowsdi's user avatar
  • 6,358
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' | ...
user938271's user avatar
  • 6,032
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 ...
kenorb's user avatar
  • 18.8k
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 ...
xaizek's user avatar
  • 1,828
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 ...
nobe4's user avatar
  • 16.3k
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 ...
fjarlq's user avatar
  • 141
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 ...
Christian Brabandt's user avatar
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.
D. Ben Knoble's user avatar
  • 27.7k
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 ...
Ralf's user avatar
  • 9,417
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/...
user938271's user avatar
  • 6,032

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