Skip to main content
61 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
51 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.7k
27 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
  • 20k
11 votes
Accepted

How do I search google from Vim?

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 = ...
nobe4's user avatar
  • 16.1k
10 votes
Accepted

How to output result of vim commands to shell

That happens, because usually Vim switches to the alternate screen and works there. Upon exiting, Vim will switch back and therefore you don't see anything left from your Vim session, but the result ...
Christian Brabandt's user avatar
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
  • 25k
8 votes
Accepted

How do I turn off the "feature" where the pound sign "#" is forced to 0 position?

As documented in :help 'smartindent' When typing '#' as the first character in a new line, the indent for that line is removed, the '#' is put in the first column. The indent is restored for the ...
jamessan's user avatar
  • 11.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,287
7 votes
Accepted

How to export information from vim to bash

You can set or modify an environment variable in Vim like so: :let $MY_ENV = 'coconuts!' Child processes inherit the parent process's environment, so this is available when you start a new shell ...
Martin Tournoij's user avatar
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,953
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.5k
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
  • 26.6k
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,158
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,774
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.6k
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
  • 41.2k
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.1k
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,164
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,636
5 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
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,298
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
  • 5,987
5 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
  • 25k
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

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.1k
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,808

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