Hot answers tagged

61 votes
Accepted

How to run bash command over current file and replace buffer with result?

:!{cmd} sends {cmd} to the shell which executes it and shows its output on the screen. :{range}!{filter} sends the lines from the current buffer inside {range} as the input of the {filter} program ...
user avatar
  • 6,466
49 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 ...
user avatar
  • 16.8k
41 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=
user avatar
29 votes
Accepted

How do I configure the Vim airline plugin to look like its own project screenshot?

One has to realize that the feature implemented by airline are inspired by the powerline plugin. Furthermore, I was relying on the docs too much, not realizing that there is well-written airline help ...
user avatar
  • 2,787
23 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 ...
user avatar
  • 18.4k
19 votes

How to run bash command over current file and replace buffer with result?

By sheer luck I found out that both: :%!jq . % or shorter: :%!jq . work, yet I don't understand why this updates the buffer.
user avatar
  • 2,787
12 votes
Accepted

Run bash command on writing a file with a particular extension?

You can use autocommands to run things automatically when certain events occur. In your case, you could do this: autocmd BufWritePost *.less !less <afile> This autocommand runs every time a ...
user avatar
11 votes

Bash not recognizing aliases when run from Vim

Your issue is with bash and not with vim. The problem is that when you run !<cmd> in vim or /bin/bash -c <cmd> from another shell you are launching an instance of bash in non-interactive ...
user avatar
  • 2,510
11 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 ...
user avatar
  • 276
10 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 = ...
user avatar
  • 15.2k
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 ...
user avatar
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....
user avatar
  • 8,072
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 $...
user avatar
  • 23.9k
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 ...
user avatar
  • 10.4k
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 ...
user avatar
  • 8,655
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 ...
user avatar
7 votes
Accepted

How to use the value of a register in a key mapping?

You can use :execute {expr1} to execute a string from evaluation of {expr1} as an Ex command. :exec "!tmux set-buffer" getreg("0") will first combine the string !tmux set-buffer with the results of ...
user avatar
7 votes
Accepted

Trouble to call a bash command from vimrc with autocommands | "Error: no previous command" (neovim)

! has to be escaped which can be done with a backslash \!. I think the problem comes from the second bang in your command which has a special meaning for vim. It is automatically replaced with the ...
user avatar
  • 6,466
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.
user avatar
  • 2,663
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 ...
user avatar
  • 16.2k
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 ...
user avatar
  • 21.5k
6 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, ...
user avatar
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, ...
user avatar
  • 23.9k
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 ...
user avatar
  • 697
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} ...
user avatar
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 ...
user avatar
  • 273
5 votes
Accepted

How do you run a command in VIM that outputs at cursor?

The built-in strftime() does exactly what you want: <C-r>=strftime('%y-%m-%d %H:%M:%S') To turn that into a mapping: inoremap <expr> <key> strftime('%y-%m-%d %H:%M:%S') You can ...
user avatar
  • 33.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 ...
user avatar
  • 46.5k
5 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, ...
user avatar
  • 5,888
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, ...
user avatar
  • 33.1k

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