Hot answers tagged

60 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.5k
26 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
  • 19.7k
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
  • 16k
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
  • 24.8k
9 votes
Accepted

Use shell variable substitution with current filepath

Why doesn't this work? This doesn't work for exactly why you say, vim is replacing the % with the path. So, your non working line :! mv % ${%/.txt/.asc} is expanding to :! mv myfile.txt ${myfile....
John O'M.'s user avatar
  • 8,522
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
  • 11k
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,157
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

How do I turn Vi colors off in Ubuntu Linux 14.04

You can use: :set t_Co=0 This will tell Vim that you're not using a colour terminal. The difference with using :syntax off is that this will still enable some syntax highlighting features with bold, ...
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,913
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.3k
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
  • 25.8k
6 votes
Accepted

Why is bash not interactive after setting &shell='/bin/bash -i'?

Your test is flawed. If you run !!bash, you're calling just the bash command explicitly. Why would you expect bash to be interactive in that case? !! is shorthand for :.!, so you're running :.!bash, ...
muru's user avatar
  • 24.8k
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

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,118
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

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.2k
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
  • 40.1k
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
  • 49.6k
5 votes

How do I turn Vi colors off in Ubuntu Linux 14.04

Just discovered this after viewing /etc/vim/vimrc for the first time. Uncommenting the line "set background=dark" in vimrc solves my readability problem also. It changes the syntax colors so that they ...
gracious1's user avatar
  • 283
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,124
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,626
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,238
5 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,624
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,907
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

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