qid int64 4 8.14M | question stringlengths 20 48.3k | answers list | date stringlengths 10 10 | metadata list | input stringlengths 12 45k | output stringlengths 2 31.8k |
|---|---|---|---|---|---|---|
28,471 | <p>I know that I can get the first and last visible lines in the current buffer by using <code>line('w0')</code> and <code>line('w$')</code>, but is there a way to do it for other buffers that are visible but not active as well?</p>
<p>For example if I have a split window, left is buffer number <code>3</code> (current)... | [
{
"answer_id": 28472,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<p>In Neovim you can't. In Vim it's trivial:</p>\n<pre><code>echo line('w0', winid)\n</code></pre>\n<p>Note that you have t... | 2020/12/18 | [
"https://vi.stackexchange.com/questions/28471",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16752/"
] | I know that I can get the first and last visible lines in the current buffer by using `line('w0')` and `line('w$')`, but is there a way to do it for other buffers that are visible but not active as well?
For example if I have a split window, left is buffer number `3` (current), and right is buffer number `4`. How to g... | In Neovim you can't. In Vim it's trivial:
```
echo line('w0', winid)
```
Note that you have to provide window ID, not simply buffer ID. |
28,482 | <p>I'm using the most recent version of nvim on arch.</p>
<p>I have sentences in my text like this</p>
<blockquote>
<p>The<br />
brown fox</p>
</blockquote>
<p>I wish to use this format<br />
<code>:%s///g</code><br />
to replace all lines starting<br />
<code>\nlowercase letter + rest of line</code> with<br />
<code>l... | [
{
"answer_id": 28483,
"author": "Kes",
"author_id": 27300,
"author_profile": "https://vi.stackexchange.com/users/27300",
"pm_score": 2,
"selected": false,
"text": "<p>This solution worked</p>\n<p><code>:%s/\\n\\([a-z]\\)/ \\1/g</code></p>\n<p>I am familiar with the\n<code>%s///g</code>\n... | 2020/12/19 | [
"https://vi.stackexchange.com/questions/28482",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27300/"
] | I'm using the most recent version of nvim on arch.
I have sentences in my text like this
>
> The
>
> brown fox
>
>
>
I wish to use this format
`:%s///g`
to replace all lines starting
`\nlowercase letter + rest of line` with
`lowercase letter + rest of line`
ie shift the line starting lowercase up... | I'm pretty sure a very similar question was already asked here. Anyway, here's a simple trick:
```
:g/^\l/-join
```
That is, for every line starting with lowercase letter join it with the previous one. |
28,498 | <p>I edit a lot of different file types, like .c, .cc, .S, .py, .rs, .ld, plus maybe a dozen more. And I'm constantly editing new file types, so I'm adding to this list. I have settings I want to apply equivalently to all of them, like shift width.</p>
<p>But, I don't want to do this to <em>all</em> files, since I also... | [
{
"answer_id": 28567,
"author": "Fabrice Hategekimana",
"author_id": 32808,
"author_profile": "https://vi.stackexchange.com/users/32808",
"pm_score": 0,
"selected": false,
"text": "<p>In my case, I use <code>function</code> with <code>autocommand</code> all in one .vimrc file.\nSee <code... | 2020/12/21 | [
"https://vi.stackexchange.com/questions/28498",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21009/"
] | I edit a lot of different file types, like .c, .cc, .S, .py, .rs, .ld, plus maybe a dozen more. And I'm constantly editing new file types, so I'm adding to this list. I have settings I want to apply equivalently to all of them, like shift width.
But, I don't want to do this to *all* files, since I also edit a lot of n... | I'm using a workaround on this topic. I have a [function in my library plugin](http://%60https://github.com/LucHermitte/lh-vim-lib/blob/master/autoload/lh/ft.vim#L53) where I register all the filetypes I've encountered that relates to text, IOW they are non-programming filetypes.
```
" Function: lh#ft#is_text(...) {{{... |
28,502 | <p>I've configured my VIM to find and open a file by fzf:</p>
<pre><code>nmap <c-x><c-f> :Files<cr>
</code></pre>
<p>It works fine, but I wanna open the file in a new tab instead of the current tab with the same shortcut keys.</p>
| [
{
"answer_id": 28507,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 4,
"selected": true,
"text": "<p>The Vim fzf plug-in has a native feature to open the selected item in a new tab.</p>\n<p>If you type <kbd>Ctrl</kbd... | 2020/12/21 | [
"https://vi.stackexchange.com/questions/28502",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32738/"
] | I've configured my VIM to find and open a file by fzf:
```
nmap <c-x><c-f> :Files<cr>
```
It works fine, but I wanna open the file in a new tab instead of the current tab with the same shortcut keys. | The Vim fzf plug-in has a native feature to open the selected item in a new tab.
If you type `Ctrl`+`T` inside the fzf selection window, it will tell Vim to open the item in a new tab (when applicable.)
See [here](https://github.com/junegunn/fzf.vim#commands), below the table it says:
>
> Most commands support `CTR... |
28,534 | <p>Sometimes I <code>gf</code> to a file in a totally different directory and want to check out that new directory. Is there a way to quickly exit vim <em>and</em> <code>cd</code> into the directory containing the current buffer?</p>
| [
{
"answer_id": 28536,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 1,
"selected": false,
"text": "<p>This generally can't be done, as the current directory is in a way part of the running environment of a running pr... | 2020/12/23 | [
"https://vi.stackexchange.com/questions/28534",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25859/"
] | Sometimes I `gf` to a file in a totally different directory and want to check out that new directory. Is there a way to quickly exit vim *and* `cd` into the directory containing the current buffer? | I there is a mean but it use a plugin, to solve that simply.
First approach
==============
If it's only to visualize the current directory, you can use the `:term` command:
```
:term ls %:p:h
```
(filtering result %=current buffer, p=path with file name, h= path only)
It only display the content though.
You can a... |
28,548 | <p>I'm trying to understand the code suggested in <a href="https://vi.stackexchange.com/a/28506/6189">https://vi.stackexchange.com/a/28506/6189</a>:</p>
<pre><code>function MyLinks(pat, strip) abort
return glob(a:pat, v:false, v:true)
\ ->map({_, v -> printf('[%s](%s)', fnamemodify(v, ':t:r')->substi... | [
{
"answer_id": 28536,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 1,
"selected": false,
"text": "<p>This generally can't be done, as the current directory is in a way part of the running environment of a running pr... | 2020/12/24 | [
"https://vi.stackexchange.com/questions/28548",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6189/"
] | I'm trying to understand the code suggested in <https://vi.stackexchange.com/a/28506/6189>:
```
function MyLinks(pat, strip) abort
return glob(a:pat, v:false, v:true)
\ ->map({_, v -> printf('[%s](%s)', fnamemodify(v, ':t:r')->substitute(printf('^%s', a:strip), '', ''), fnamemodify(v, ':t'))})
\ ->jo... | I there is a mean but it use a plugin, to solve that simply.
First approach
==============
If it's only to visualize the current directory, you can use the `:term` command:
```
:term ls %:p:h
```
(filtering result %=current buffer, p=path with file name, h= path only)
It only display the content though.
You can a... |
28,549 | <p>I'm trying to understand the code suggested in <a href="https://vi.stackexchange.com/a/28506/6189">https://vi.stackexchange.com/a/28506/6189</a>:</p>
<pre><code>function MyLinks(pat, spat, ssub, sflags) abort
return glob(a:pat, v:false, v:true)
\ ->map({_, v -> printf('[%s](%s)', fnamemodify(v, ':t:r... | [
{
"answer_id": 28551,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p><em>"Why?"</em></p>\n<p>Having to explicitly write <code>a:</code> to access parameter values while formal... | 2020/12/24 | [
"https://vi.stackexchange.com/questions/28549",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6189/"
] | I'm trying to understand the code suggested in <https://vi.stackexchange.com/a/28506/6189>:
```
function MyLinks(pat, spat, ssub, sflags) abort
return glob(a:pat, v:false, v:true)
\ ->map({_, v -> printf('[%s](%s)', fnamemodify(v, ':t:r')->substitute(a:spat, a:ssub, a:sflags), fnamemodify(v, ':t'))})
... | In vim script (vim 8.x and older), a variable can belong to one of a number of scopes. While it's true it's idiosyncratic as no other language has this feature, it's also consistent as no other language has e.g., "buffer variables."
```
buffer-variable b: Local to the current buffer.
window-variable w: L... |
28,571 | <p>I'm using KDE 5 with multiple desktops (in a 3x4 grid) and I regularly open Vim from the command line, e.g. with</p>
<pre><code>gvim file.txt
</code></pre>
<p>The problem is when I do this, GVim often appears on a different desktop than the one I am currently focused on. I then have to go and find it, and bring it ... | [
{
"answer_id": 28572,
"author": "joeytwiddle",
"author_id": 630,
"author_profile": "https://vi.stackexchange.com/users/630",
"pm_score": 0,
"selected": false,
"text": "<blockquote>\n<p>Update: I thought this solution was working, but it isn't working now.</p>\n</blockquote>\n<p>This seem... | 2020/12/27 | [
"https://vi.stackexchange.com/questions/28571",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/630/"
] | I'm using KDE 5 with multiple desktops (in a 3x4 grid) and I regularly open Vim from the command line, e.g. with
```
gvim file.txt
```
The problem is when I do this, GVim often appears on a different desktop than the one I am currently focused on. I then have to go and find it, and bring it on to the desktop I am wo... | Once again the other solutions are failing me. So now I have a new workaround (for KDE 5):
* Right click on GVim's titlebar and select `More Actions > Configure Special Application Settings`
* Add the property `Virtual Desktop`
* Configure that to `Apply Initially` and `All Desktops`
(also known as making the window ... |
28,576 | <p>I want to do <code>:set paste</code>, <em>paste</em>, <code>:set nopaste</code> in one keyboard shortcut in insertmode (<code><C-r>*</code>)</p>
<p>In visualmode, with <code>vnoremap p "+p</code> works with no indent. But in insertmode, this <code><C-r>*</code> gives indent. How I can make <code>&... | [
{
"answer_id": 28578,
"author": "Fabrice Hategekimana",
"author_id": 32808,
"author_profile": "https://vi.stackexchange.com/users/32808",
"pm_score": 1,
"selected": false,
"text": "<p>I don't know if there is a setting for that but with the <code>:set paste</code> and <code>:set nopaste<... | 2020/12/27 | [
"https://vi.stackexchange.com/questions/28576",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2738/"
] | I want to do `:set paste`, *paste*, `:set nopaste` in one keyboard shortcut in insertmode (`<C-r>*`)
In visualmode, with `vnoremap p "+p` works with no indent. But in insertmode, this `<C-r>*` gives indent. How I can make `<C-r>*` work without indent? | There's `Ctrl-R``Ctrl-O` combo in insert mode (see `:h i_CTRL-R_CTRL-O`).
If setting `:h 'paste'` is needed, here are the mappings to do this (kind of emulating [tpope/vim-unimpaired](https://github.com/tpope/vim-unimpaired) plugin):
```
nnoremap <silent>[op :setl paste<Bar>au InsertLeave * ++once setl nopaste<CR... |
28,611 | <p>I have a few shell scripts where I find files and open them in vim, with the filenames being stored in shell variables that are passed to vim. Since I don't want to start a vim session unless <strong>at least one file</strong> is found, I find myself checking to see if the variable is empty <em>every time</em>, like... | [
{
"answer_id": 28599,
"author": "Fabrice Hategekimana",
"author_id": 32808,
"author_profile": "https://vi.stackexchange.com/users/32808",
"pm_score": 2,
"selected": true,
"text": "<p>That's an interesting question! To my knowledge, there is no option to do so.</p>\n<p>I think it's better... | 2020/12/31 | [
"https://vi.stackexchange.com/questions/28611",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31699/"
] | I have a few shell scripts where I find files and open them in vim, with the filenames being stored in shell variables that are passed to vim. Since I don't want to start a vim session unless **at least one file** is found, I find myself checking to see if the variable is empty *every time*, like so:
```
...
if [ -z "... | That's an interesting question! To my knowledge, there is no option to do so.
I think it's better to let the user chose his own mapping to avoid collisions. This is the reason why some plugins use `<Plug>` for their features (see `:help using-<Plug>`).
I am happy to see that you are keen on plugins (they are really u... |
28,618 | <p>Please forgive me, I'm relatively new to Vim.</p>
<p>I'm editing my <code>.vimrc</code> file. I'm adding the following lines:</p>
<pre><code>nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
n... | [
{
"answer_id": 28619,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 2,
"selected": false,
"text": "<p>Using Visual mode (in particular Blockwise Visual mode) seems to be a perfect solution for me, here.</p>\n<p>Since... | 2021/01/01 | [
"https://vi.stackexchange.com/questions/28618",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30146/"
] | Please forgive me, I'm relatively new to Vim.
I'm editing my `.vimrc` file. I'm adding the following lines:
```
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
nnoremap <down> <nop> ... | Using Visual mode (in particular Blockwise Visual mode) seems to be a perfect solution for me, here.
Since you're only replacing a single character, personally I'd go with `Ctrl+V` followed by the motion (such as `G` for the end of the buffer), then `ri`. That replaces a single character and doesn't go into Insert mod... |
28,630 | <p>I want to set node's executable path for neovim. So I have added this line in <code>init.vim</code>.</p>
<pre><code>let g:coc_node_path = system('which node')
</code></pre>
<p>But when I open nvim I get this error.</p>
<pre><code>[coc.nvim] "/home/akash/.nvm/versions/node/v15.5.0/bin/node^@" is not executa... | [
{
"answer_id": 28634,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 3,
"selected": true,
"text": "<p>What a coincidence. I encountered this exact same thing a few hours before you posted this. I just figured it was a li... | 2021/01/03 | [
"https://vi.stackexchange.com/questions/28630",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32913/"
] | I want to set node's executable path for neovim. So I have added this line in `init.vim`.
```
let g:coc_node_path = system('which node')
```
But when I open nvim I get this error.
```
[coc.nvim] "/home/akash/.nvm/versions/node/v15.5.0/bin/node^@" is not executable, checkout https://nodejs.org/en/download
```
But ... | What a coincidence. I encountered this exact same thing a few hours before you posted this. I just figured it was a line-ending issue and solved it by wrapping the `system()` call in a call to [`trim()`](https://vimhelp.org/eval.txt.html#trim()).
Since you mentioned it I since verified that the cause is the presence o... |
28,633 | <p>I'm re-learning Vim, and now I'm building my own <code>~/.vim/.vimrc</code> file. Yes, it is store under the <code>.vim/</code> folder, which is created by MacOSX after I updated to Big Sur. What I want is simply this</p>
<pre><code>set belloff=all
</code></pre>
<p>when I put this line in <code>~/.vimrc</code> it wo... | [
{
"answer_id": 28635,
"author": "Fabrice Hategekimana",
"author_id": 32808,
"author_profile": "https://vi.stackexchange.com/users/32808",
"pm_score": 3,
"selected": true,
"text": "<h3>1. For the first question</h3>\n<p>According to the help menu (see <code>:help $MYVIMRC</code>), vim wil... | 2021/01/03 | [
"https://vi.stackexchange.com/questions/28633",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10189/"
] | I'm re-learning Vim, and now I'm building my own `~/.vim/.vimrc` file. Yes, it is store under the `.vim/` folder, which is created by MacOSX after I updated to Big Sur. What I want is simply this
```
set belloff=all
```
when I put this line in `~/.vimrc` it works, while in `~/.vim/.vimrc` it's not. So my questions a... | ### 1. For the first question
According to the help menu (see `:help $MYVIMRC`), vim will look for a user vimrc in specific places. It look first for `~/.vimrc` and then for `~/.vim/vimrc`. Vim stops searching after the first one found (that's why we need to remove `~/.vimrc`).
Vim will set automatically the `$MYVIMR... |
28,639 | <p>I'm re-learning Vim. My question is that I want to <kbd>option</kbd> + <kbd>⌫</kbd> to backward-delete a word in <strong>INSERT MODE</strong>. I've spent some days to achieve this (and succeeded) to my <code>zsh</code> shell through <code>bindkey</code> in <code>.zshrc</code> file (not related to Vim though), but no... | [
{
"answer_id": 28640,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>One option is instead of trying to bind a key combination to this action, just use the default key binding for it, ... | 2021/01/03 | [
"https://vi.stackexchange.com/questions/28639",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10189/"
] | I'm re-learning Vim. My question is that I want to `option` + `⌫` to backward-delete a word in **INSERT MODE**. I've spent some days to achieve this (and succeeded) to my `zsh` shell through `bindkey` in `.zshrc` file (not related to Vim though), but now in Vim this problem occurs again. So my question is how to bind t... | One option is instead of trying to bind a key combination to this action, just use the default key binding for it, which is `Ctrl`+`W`.
See [`:help i_CTRL-W`](https://vimhelp.org/insert.txt.html#i_CTRL-W).
This same key binding should be available by default in zsh (or bash, etc.) so you could just use it everywhere ... |
28,654 | <p>I noticed that the following mapping does not cause an infinite recursion (when pressing <code>x</code>).</p>
<pre><code>:map x x
</code></pre>
<p>I didn't see anything in Vim's documentation that would explain this.</p>
<p>Further experimentation seems to suggest that when the right-hand-side of a mapping starts wi... | [
{
"answer_id": 28656,
"author": "Fabrice Hategekimana",
"author_id": 32808,
"author_profile": "https://vi.stackexchange.com/users/32808",
"pm_score": 0,
"selected": false,
"text": "<p>Normally vim prevent a mapping to go crazy by limiting the maximum number of recursion. You can set the ... | 2021/01/04 | [
"https://vi.stackexchange.com/questions/28654",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26249/"
] | I noticed that the following mapping does not cause an infinite recursion (when pressing `x`).
```
:map x x
```
I didn't see anything in Vim's documentation that would explain this.
Further experimentation seems to suggest that when the right-hand-side of a mapping starts with the left-hand-side, there is no infini... | This behavior is documented in [`:help recursive_mapping`](https://vimhelp.org/map.txt.html#recursive_mapping):
>
> There is one exception: If the `{rhs}` starts with `{lhs}`, the first character is not mapped again (this is Vi compatible).
>
>
> For example:
>
>
>
> ```
> :map ab abcd
>
> ```
>
> will execute... |
28,664 | <p>I want to write a Vim Script which can achieve the following function, which is my favorite feature in some IDE. Say I have the following example code:</p>
<pre><code>I'm a line and I just stay here.
I'm another line and I also stay here.
I'm the line to be selected and swapped upward 1. (1)
I'm the line to be s... | [
{
"answer_id": 28656,
"author": "Fabrice Hategekimana",
"author_id": 32808,
"author_profile": "https://vi.stackexchange.com/users/32808",
"pm_score": 0,
"selected": false,
"text": "<p>Normally vim prevent a mapping to go crazy by limiting the maximum number of recursion. You can set the ... | 2021/01/05 | [
"https://vi.stackexchange.com/questions/28664",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10189/"
] | I want to write a Vim Script which can achieve the following function, which is my favorite feature in some IDE. Say I have the following example code:
```
I'm a line and I just stay here.
I'm another line and I also stay here.
I'm the line to be selected and swapped upward 1. (1)
I'm the line to be selected and s... | This behavior is documented in [`:help recursive_mapping`](https://vimhelp.org/map.txt.html#recursive_mapping):
>
> There is one exception: If the `{rhs}` starts with `{lhs}`, the first character is not mapped again (this is Vi compatible).
>
>
> For example:
>
>
>
> ```
> :map ab abcd
>
> ```
>
> will execute... |
28,684 | <p>I have a simple makefile as follow:</p>
<pre><code>all: A.cpp
g++ -o A.exe A.cpp
.\A
</code></pre>
<p>In A.cpp,</p>
<pre><code>#include <iostream>
using namespace std;
int main() {
cout << "Hello World!\n" << '\n';
return 0;
}
</code></pre>
<p>In Neovim, if I run <code>:!... | [
{
"answer_id": 28686,
"author": "Fabrice Hategekimana",
"author_id": 32808,
"author_profile": "https://vi.stackexchange.com/users/32808",
"pm_score": 1,
"selected": false,
"text": "<p>When you run your code with <code>:make</code>, the result is put into the quickfix list, you can open i... | 2021/01/07 | [
"https://vi.stackexchange.com/questions/28684",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32827/"
] | I have a simple makefile as follow:
```
all: A.cpp
g++ -o A.exe A.cpp
.\A
```
In A.cpp,
```
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!\n" << '\n';
return 0;
}
```
In Neovim, if I run `:!make`, I get what I expect:
```
:!make
g++ -o A.exe A.cpp
.\A
Hello World!
`... | This happens because a `'shellpipe'` of the default of `>` (which is the default on Windows) doesn't really work on Powershell. It seems to have it produce a file that uses UTF-16 encoding and then NeoVim has trouble parsing the [Unicode BOM](https://en.m.wikipedia.org/wiki/Byte_order_mark) character at the beginning o... |
28,716 | <p>It's possible to configure a mapping such that command line mode is active after the key press.</p>
<p>For example, with a mapping <code>:map H :help </code>, pressing <code>H</code> results in command line mode being entered with <code>:help </code> as the current text.</p>
<p>The documentation for <code>:normal</c... | [
{
"answer_id": 28717,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>The easiest solution: you'll need a mapping and have the mapping returns the value of a function that returns a sequ... | 2021/01/11 | [
"https://vi.stackexchange.com/questions/28716",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26249/"
] | It's possible to configure a mapping such that command line mode is active after the key press.
For example, with a mapping `:map H :help` , pressing `H` results in command line mode being entered with `:help` as the current text.
The documentation for `:normal` says:
>
> A ":" command must be completed as well. A... | You can use the [`feedkeys()`](https://vimhelp.org/eval.txt.html#feedkeys%28%29) function for this purpose.
For example:
```
function! Edit()
call feedkeys(':edit ', 'n')
endfunction
```
Then `:call Edit()` will enter the Ex command-line, enter `:edit` into it and leave the cursor there for the user to complet... |
28,759 | <p>I want to be able to <strong>compile c++</strong> code from within vim without running a new terminal and calling the compiler. **How can I do it ** please</p>
| [
{
"answer_id": 28760,
"author": "Community",
"author_id": -1,
"author_profile": "https://vi.stackexchange.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<p><strong>Vim is a text editor, not a shell.</strong> Although, Vim 8.1 has a built-in terminal that can be opened with the... | 2021/01/07 | [
"https://vi.stackexchange.com/questions/28759",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I want to be able to **compile c++** code from within vim without running a new terminal and calling the compiler. \*\*How can I do it \*\* please | (I've answered this question so many times that I've lost the count, and impossible to find a complete answer in the lot... I'll bookmark this answer this time...)
Everything starts with Vim quickfix feature which permits to integrate compilation, and to navigate error messages. The starting point is [`:make`](http://... |
28,772 | <p>I'm looking to write foos,bars,bazs by using a custom language in ctags. It works fine, I
can jump to the tag but I'm only allowed to have one unique tag name. I would
like to be able to jump through all the tags in different files with a tag named
todo1. Ctags is not generating more than one of the same tag name. I... | [
{
"answer_id": 28787,
"author": "ritchie",
"author_id": 32923,
"author_profile": "https://vi.stackexchange.com/users/32923",
"pm_score": 1,
"selected": false,
"text": "<p>The answer is very simple yet many people don't know this so I'm going to post the answer so that it can help someone... | 2021/01/16 | [
"https://vi.stackexchange.com/questions/28772",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32923/"
] | I'm looking to write foos,bars,bazs by using a custom language in ctags. It works fine, I
can jump to the tag but I'm only allowed to have one unique tag name. I would
like to be able to jump through all the tags in different files with a tag named
todo1. Ctags is not generating more than one of the same tag name. If I... | Thanks to @masatake. This has already been resolved.
Add --fields=+n option (or --fields=+'{line}' option in Universal Ctags) to the ctags command line. That adds a line: field to each tag entry. The line: fields may make the tag entries unique. |
28,777 | <p>I defined an abbreviation in vim like this:</p>
<pre><code>ab is Input()
</code></pre>
<p>I know it is not good to use <code>is</code> as the abbreviation of <code>Input()</code>; here it is just an example.</p>
<p>So every time when I type <code>is</code> followed by space, then <code>is</code> will be automaticall... | [
{
"answer_id": 28787,
"author": "ritchie",
"author_id": 32923,
"author_profile": "https://vi.stackexchange.com/users/32923",
"pm_score": 1,
"selected": false,
"text": "<p>The answer is very simple yet many people don't know this so I'm going to post the answer so that it can help someone... | 2021/01/17 | [
"https://vi.stackexchange.com/questions/28777",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33128/"
] | I defined an abbreviation in vim like this:
```
ab is Input()
```
I know it is not good to use `is` as the abbreviation of `Input()`; here it is just an example.
So every time when I type `is` followed by space, then `is` will be automatically changed to `Input()`.
Is it possible to disable the automatic trigger o... | Thanks to @masatake. This has already been resolved.
Add --fields=+n option (or --fields=+'{line}' option in Universal Ctags) to the ctags command line. That adds a line: field to each tag entry. The line: fields may make the tag entries unique. |
28,789 | <p>I'm familiar with <code>ddp</code> to swap lines, but what if I want to swap words on the same line? I found a Reddit post that linked to this <a href="https://vim.fandom.com/wiki/Swapping_characters,_words_and_lines" rel="nofollow noreferrer">wiki page</a> that suggests <code>dawbP</code> as a word swap method, but... | [
{
"answer_id": 28790,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p>From the wiki page, I've always used the other methods that leave the spaces the way they are.</p>\n<p>Since that ti... | 2021/01/17 | [
"https://vi.stackexchange.com/questions/28789",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30146/"
] | I'm familiar with `ddp` to swap lines, but what if I want to swap words on the same line? I found a Reddit post that linked to this [wiki page](https://vim.fandom.com/wiki/Swapping_characters,_words_and_lines) that suggests `dawbP` as a word swap method, but this seems long-winded for a Vim keypress series. Is there a ... | With your cursor between One and Two (in normal mode), type `deep`. |
28,791 | <p>Im using <code>pyenv</code> to administer my python versions (Im on Manjaro Linux) and the command for python on my system is <code>python</code> but nvim wants to use python3. How can I change it?</p>
<p>Error:</p>
<pre><code>[coc.nvim] Error on execute python script: request error nvim_command - Vim(pyxf
ile):E319... | [
{
"answer_id": 28792,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p>If nvim works like Vim on this topic, as a I see <code>pyxfile</code> in your error message, you should be able to f... | 2021/01/17 | [
"https://vi.stackexchange.com/questions/28791",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33086/"
] | Im using `pyenv` to administer my python versions (Im on Manjaro Linux) and the command for python on my system is `python` but nvim wants to use python3. How can I change it?
Error:
```
[coc.nvim] Error on execute python script: request error nvim_command - Vim(pyxf
ile):E319: No "python3" provider found. Run ":chec... | Because my system does not name the default python interpreter as `python3`, but as `python` I simply added a shell alias:
```bash
alias python3='python'
``` |
28,810 | <p>The <code>acro</code> package introduces LaTeX macros like <code>\ac{abc}</code>, <code>\acs{abc}</code>, <code>\acl{abc}</code>, <code>\acp{abc}</code>, <code>\acpl{abc}</code>, <code>\Ac{abc}</code>, etc. Here, <code>abc</code> is the label for an acronym.</p>
<p>I manually extract the acronym labels from the acr... | [
{
"answer_id": 29475,
"author": "user2153235",
"author_id": 7041,
"author_profile": "https://vi.stackexchange.com/users/7041",
"pm_score": 0,
"selected": false,
"text": "<p>I created a normal-mode macro, stored in register <code>a</code>, that searches the <code>*.tex</code> source file ... | 2021/01/19 | [
"https://vi.stackexchange.com/questions/28810",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7970/"
] | The `acro` package introduces LaTeX macros like `\ac{abc}`, `\acs{abc}`, `\acl{abc}`, `\acp{abc}`, `\acpl{abc}`, `\Ac{abc}`, etc. Here, `abc` is the label for an acronym.
I manually extract the acronym labels from the acronym file and add them to my local en.utf-8.add file. The latter is specific to each report. It is... | Spellchecking is permitted only on syntax elements that accept sub-token of type `@Spell`. I don't remember the exact details. The syntax files have been patched ages ago now.
I wouldn't be surprised that `\cite{}` and other commands introduce an new syntax kind for the token within braces, and that token doesn't incl... |
28,835 | <h2>Context</h2>
<p>I’m working on an <code>'omnifunc'</code> function for Markdown editing. It’s supposed to help me link to other Markdown files while I’m typing a link – based on file content though, not file name.</p>
<p>Suppose I’m typing a link like <code>[favorite editor](Vim|</code> (where <code>|</code> marks ... | [
{
"answer_id": 28841,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 3,
"selected": true,
"text": "<p><em>Nope, not a Vim answer. AFAIK, though it's the best solution available.</em></p>\n<p>absolute->relative is need... | 2021/01/21 | [
"https://vi.stackexchange.com/questions/28835",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33217/"
] | Context
-------
I’m working on an `'omnifunc'` function for Markdown editing. It’s supposed to help me link to other Markdown files while I’m typing a link – based on file content though, not file name.
Suppose I’m typing a link like `[favorite editor](Vim|` (where `|` marks my cursor). Once I hit `^X^O`, my `omnifun... | *Nope, not a Vim answer. AFAIK, though it's the best solution available.*
absolute->relative is needed a lot less frequently then relative->absolute so I expect your choices will be pretty limited. That being said, there's an option that mostly meets your requirements with the grey area being whether it's distributed ... |
28,867 | <p>I'm trying to set up folding for #pragma region in C/C++, and it kinda works, but I need to edit out #pragma from the cPreProc syntax region, which is definitely not ideal. If I don't edit it out, the regions don't stop at their corresponding endmarker, instead just fold to the last one.</p>
<p>This is the line I'm ... | [
{
"answer_id": 31205,
"author": "Jorengarenar",
"author_id": 25807,
"author_profile": "https://vi.stackexchange.com/users/25807",
"pm_score": 0,
"selected": false,
"text": "<pre><code>syn region cPragmaRegion start=/#pragma region/ end=/#pragma endregion/ fold transparent keepend extend\... | 2021/01/23 | [
"https://vi.stackexchange.com/questions/28867",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33256/"
] | I'm trying to set up folding for #pragma region in C/C++, and it kinda works, but I need to edit out #pragma from the cPreProc syntax region, which is definitely not ideal. If I don't edit it out, the regions don't stop at their corresponding endmarker, instead just fold to the last one.
This is the line I'm using in ... | While using Vim's syntax engine for folding is very powerful and can be very convenient for syntax-aware folding, it's really hard to extend an existing syntax definition with new syntax, since creating new syntax matches and regions tends to affect how other syntax elements are recognized, so it tends to produce rippl... |
28,876 | <p>So I have been working with vim-tex and ultisnips lately.<br />
Let us say the snippet is of the form <code>(\d)pder</code>. It is a 5 character snippet and the first character can be accessed by <code>match.group(1)</code>.</p>
<p>But now I want to access substrings of the snippet with unspecified number of charact... | [
{
"answer_id": 28882,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>Simply extend the snippet to <code>(\\d)pder(\\w*)</code> and handle the second submatch appropriately.</p>\n"
... | 2021/01/24 | [
"https://vi.stackexchange.com/questions/28876",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30547/"
] | So I have been working with vim-tex and ultisnips lately.
Let us say the snippet is of the form `(\d)pder`. It is a 5 character snippet and the first character can be accessed by `match.group(1)`.
But now I want to access substrings of the snippet with unspecified number of characters using certain pattern. For exa... | The following snippet worked out for me:
```
snippet `pder(\w*)` "Description" rw
\\frac{\\partial^{`!p snip.rv=findSum(match.group(1))`}}{`!p snip.rv=printd("\\partial",match.group(1))`} $0
endsnippet
```
with
```
global !p
def findSum(str1):
# A temporary str1ing
temp = 0
# holds sum of all numbers... |
28,878 | <p>The vimscript allows <em>list union</em> via the <code>+</code> operator, but the <em>list subtraction</em> doesn't come as nice as the union. Is there an easy way to filter a list by another list?</p>
<pre><code>:echo [1, 2, 3] + [1, 10]
" [1, 2, 3, 1, 10]
:echo [1, 2, 3] - [1, 10]
" E730: using List as... | [
{
"answer_id": 28880,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<p>To keep it simple, I assume all elements are different (i.e. it's "set difference"):</p>\n<pre><code>:call fil... | 2021/01/24 | [
"https://vi.stackexchange.com/questions/28878",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28754/"
] | The vimscript allows *list union* via the `+` operator, but the *list subtraction* doesn't come as nice as the union. Is there an easy way to filter a list by another list?
```
:echo [1, 2, 3] + [1, 10]
" [1, 2, 3, 1, 10]
:echo [1, 2, 3] - [1, 10]
" E730: using List as a String
" What I want: [2, 3]
```
I tried to... | It is a little bit faster to use a string expression than a lambda (and arguably easier to understand in this case),
```
call filter(a, 'index(b, v:val)<0')
```
This naive implementation is O(N^2) but is still fairly fast in practice as `index()` is implemented in C. If you have a *very* large number of elements in ... |
28,886 | <p>This is a copy of a question from TeX stackexchange which in hindsight is likely more relevant here.</p>
<p>I have attempted to install vim-latex (Latex-suite) with Pathogen, though I seem to have (at least partially) failed. I followed the instructions given in the answer <a href="https://vi.stackexchange.com/quest... | [
{
"answer_id": 28880,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<p>To keep it simple, I assume all elements are different (i.e. it's "set difference"):</p>\n<pre><code>:call fil... | 2021/01/25 | [
"https://vi.stackexchange.com/questions/28886",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33269/"
] | This is a copy of a question from TeX stackexchange which in hindsight is likely more relevant here.
I have attempted to install vim-latex (Latex-suite) with Pathogen, though I seem to have (at least partially) failed. I followed the instructions given in the answer [here](https://vi.stackexchange.com/questions/13744/... | It is a little bit faster to use a string expression than a lambda (and arguably easier to understand in this case),
```
call filter(a, 'index(b, v:val)<0')
```
This naive implementation is O(N^2) but is still fairly fast in practice as `index()` is implemented in C. If you have a *very* large number of elements in ... |
28,888 | <p>So I have a configuration file that I want to modify using Vim. I want to change a ******* into something else, but after selecting the ******* in visual mode, I am not sure what am I supposed to do to change the string into something else.</p>
<p>Say I want to change ******* to <a href="http://www.sample.com" rel="... | [
{
"answer_id": 28889,
"author": "Zorzi",
"author_id": 27331,
"author_profile": "https://vi.stackexchange.com/users/27331",
"pm_score": 3,
"selected": true,
"text": "<p>Short answer:<br />\nYou can press <code>c</code> to delete the selection and enter insert mode right away</p>\n<hr />\n... | 2021/01/25 | [
"https://vi.stackexchange.com/questions/28888",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33272/"
] | So I have a configuration file that I want to modify using Vim. I want to change a \*\*\*\*\*\*\* into something else, but after selecting the \*\*\*\*\*\*\* in visual mode, I am not sure what am I supposed to do to change the string into something else.
Say I want to change \*\*\*\*\*\*\* to [www.sample.com](http://w... | Short answer:
You can press `c` to delete the selection and enter insert mode right away
---
To go to the end of the \*\*\*\*\*\*, the easiest thing would be to know what's following it. If there's a space after, for example:
```
I really like the smell of ****** flowers.
^
```
Here a... |
28,897 | <p>I would like to create a simple pomodoro timer I can insert into text files. Something like:</p>
<p>Current Time - 10:15</p>
<p>End Time - 10:40</p>
<p>However I have not been able to find a good way to insert a future time.</p>
<p>I have used <code>:put =strftime('%T')</code> to create the current time and this wor... | [
{
"answer_id": 28898,
"author": "wos",
"author_id": 30375,
"author_profile": "https://vi.stackexchange.com/users/30375",
"pm_score": 0,
"selected": false,
"text": "<p>If you don't mind using a system based solution, then on ubuntu (and many linuxes)</p>\n<pre><code>date --date="5 mi... | 2021/01/25 | [
"https://vi.stackexchange.com/questions/28897",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30606/"
] | I would like to create a simple pomodoro timer I can insert into text files. Something like:
Current Time - 10:15
End Time - 10:40
However I have not been able to find a good way to insert a future time.
I have used `:put =strftime('%T')` to create the current time and this works perfectly, however I am not sure ho... | You can get the current time with `localtime()`:
```
:echo localtime()
1611790246
```
And you can format this with `strftime()` by passing it as the second argument:
```
:echo strftime('%T', localtime())
07:32:16
```
And you can modify it as well:
```
:echo strftime('%T', localtime() + 60 * 25)
07:57:16
```
So... |
28,907 | <p>I want to test, if the cursor is currently in a comment line. For example in C it looks like this:</p>
<pre class="lang-c prettyprint-override"><code>// This is a comment line
</code></pre>
<p>now it's also possible that it's a big comment section:</p>
<pre class="lang-c prettyprint-override"><code>/*
* Big comment... | [
{
"answer_id": 28898,
"author": "wos",
"author_id": 30375,
"author_profile": "https://vi.stackexchange.com/users/30375",
"pm_score": 0,
"selected": false,
"text": "<p>If you don't mind using a system based solution, then on ubuntu (and many linuxes)</p>\n<pre><code>date --date="5 mi... | 2021/01/26 | [
"https://vi.stackexchange.com/questions/28907",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31844/"
] | I want to test, if the cursor is currently in a comment line. For example in C it looks like this:
```c
// This is a comment line
```
now it's also possible that it's a big comment section:
```c
/*
* Big comment section
*/
```
Now I'd like to read the current line and look what the first character is. Is there ... | You can get the current time with `localtime()`:
```
:echo localtime()
1611790246
```
And you can format this with `strftime()` by passing it as the second argument:
```
:echo strftime('%T', localtime())
07:32:16
```
And you can modify it as well:
```
:echo strftime('%T', localtime() + 60 * 25)
07:57:16
```
So... |
28,909 | <p>After doing</p>
<pre><code>:%s/foo/bar/g
</code></pre>
<p>I can type</p>
<pre><code>:<C-r>/
</code></pre>
<p>to place <code>foo</code> into the command line.</p>
<p>How can I place <code>bar</code> into the command line?</p>
<p>I ultimately want to do a series of:</p>
<pre><code>:%s/foo/bar/g
:%s/bar/baz/g
:%s... | [
{
"answer_id": 28912,
"author": "Peter Paul Kiefer",
"author_id": 18402,
"author_profile": "https://vi.stackexchange.com/users/18402",
"pm_score": 0,
"selected": false,
"text": "<p><code><C-r>/</code> inserts a special register <code>"/</code> (the last search string) at the a... | 2021/01/26 | [
"https://vi.stackexchange.com/questions/28909",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9024/"
] | After doing
```
:%s/foo/bar/g
```
I can type
```
:<C-r>/
```
to place `foo` into the command line.
How can I place `bar` into the command line?
I ultimately want to do a series of:
```
:%s/foo/bar/g
:%s/bar/baz/g
:%s/baz/qux/g
```
etc., inspecting the resulting source file's outputs in-between (and don't wan... | You can search for the last used substitute string with `/~/`. This should work as long as the substitute string does not contain any specials like `\0`...`\9`, `\U`, `\L`, etc. |
28,942 | <p>Please find my minimal vimrc (whatever I use for Latex compilation)</p>
<pre><code>"General "{{{
set nocompatible " because vim is not vi
"set autowrite " write on shell commands
"set autoread " read on change outs... | [
{
"answer_id": 28912,
"author": "Peter Paul Kiefer",
"author_id": 18402,
"author_profile": "https://vi.stackexchange.com/users/18402",
"pm_score": 0,
"selected": false,
"text": "<p><code><C-r>/</code> inserts a special register <code>"/</code> (the last search string) at the a... | 2021/01/28 | [
"https://vi.stackexchange.com/questions/28942",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2738/"
] | Please find my minimal vimrc (whatever I use for Latex compilation)
```
"General "{{{
set nocompatible " because vim is not vi
"set autowrite " write on shell commands
"set autoread " read on change outside vim
set spell spl=en_us " ... | You can search for the last used substitute string with `/~/`. This should work as long as the substitute string does not contain any specials like `\0`...`\9`, `\U`, `\L`, etc. |
28,982 | <p>I have migrated from vim to nvim and everything seemed to work fine. I'm trying to figure out how to enable xdebug on nvim (it used to work fine before). So I ran to an issue when I tried to install this plugin: <a href="https://github.com/vim-scripts/DBGp-Remote-Debugger-Interface" rel="nofollow noreferrer">https:/... | [
{
"answer_id": 28984,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 2,
"selected": true,
"text": "<p>The paths this plugin checks are:</p>\n<pre><code>$VIMRUNTIME/plugin/debugger.py\n$HOME/.vim/plugin/debugger.py\n$VI... | 2021/01/31 | [
"https://vi.stackexchange.com/questions/28982",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14510/"
] | I have migrated from vim to nvim and everything seemed to work fine. I'm trying to figure out how to enable xdebug on nvim (it used to work fine before). So I ran to an issue when I tried to install this plugin: <https://github.com/vim-scripts/DBGp-Remote-Debugger-Interface>
When I try to install it using Vundle, I ge... | The paths this plugin checks are:
```
$VIMRUNTIME/plugin/debugger.py
$HOME/.vim/plugin/debugger.py
$VIM/vimfiles/plugin/debugger.py
```
See [the source](https://github.com/vim-scripts/DBGp-Remote-Debugger-Interface/blob/master/plugin/debugger.vim#L120).
`$VIMRUNTIME` and `$VIM` are your Vim (or Neovim) install dire... |
28,994 | <p>A tilde appears on the terminal if the file contain less lines than the screen currently displays. I was wondering if it is possible to remove them or replace them with something more beautiful (maybe a single line of underscores or something)</p>
<p>Here is an empty file full of tildes on a new vim without even a <... | [
{
"answer_id": 28997,
"author": "Quasímodo",
"author_id": 30440,
"author_profile": "https://vi.stackexchange.com/users/30440",
"pm_score": 2,
"selected": false,
"text": "<p>I'm with Ben here: The tilde seems to be hardcoded. However, you can set their foreground color to match the backgr... | 2021/02/01 | [
"https://vi.stackexchange.com/questions/28994",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32449/"
] | A tilde appears on the terminal if the file contain less lines than the screen currently displays. I was wondering if it is possible to remove them or replace them with something more beautiful (maybe a single line of underscores or something)
Here is an empty file full of tildes on a new vim without even a `vimrc`:
[... | Since [8.2.2508](https://github.com/vim/vim/releases/tag/v8.2.2508), you can hide the tilde by setting the [`'fillchars'`](https://vimhelp.org/options.txt.html#%27fillchars%27) option:
```
let &fillchars ..= ',eob: '
```
Credit to [Yegappan Lakshmanan](https://vi.stackexchange.com/users/29827/yegappan-lakshmanan) fo... |
29,007 | <p>I want to reindent an <code>nginx</code> configuration file with the following simple rudimentary rules:</p>
<ul>
<li>a <code>{</code> increases indentation</li>
<li>a <code>}</code> decreases indentation</li>
</ul>
<p>The idea is <code>cindent</code> is just enough to do it. I have the following file:</p>
<pre><co... | [
{
"answer_id": 29008,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 0,
"selected": false,
"text": "<p>There's no need in <code>cindent</code>, as <code>smartindent</code> should be enough. So simply:</p>\n<pre><code>setloc... | 2021/02/02 | [
"https://vi.stackexchange.com/questions/29007",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31698/"
] | I want to reindent an `nginx` configuration file with the following simple rudimentary rules:
* a `{` increases indentation
* a `}` decreases indentation
The idea is `cindent` is just enough to do it. I have the following file:
```
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
```
I ... | As Matt notes, `smartindent` is enough. Not only this, but `cindent` is actively harmful!
Many years ago, when I first got started with vim, I had these both set globally in my vimrc. Eventually, through spurious indenting issues such as these, I came to realize that in fact they make *bad* global settings. `cindent` ... |
29,012 | <p>I'd like to remove the period between the 6th comma and the 9th comma for the multiple lines of the following texts.</p>
<p>Change from:</p>
<pre><code>4,Afghanistan,2,Medium,1951,1951.5,4134.756,3705.395,7840.151,12.009
4,Afghanistan,5,Constant fertility,2023,2023.5,21628.67,20554.282,42182.952,64.613
</code></pre>... | [
{
"answer_id": 29013,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 2,
"selected": true,
"text": "<h2>The problem with your :normal command</h2>\n<p>You can't run ex commands from within a <code>:normal</code> command. Instead... | 2021/02/02 | [
"https://vi.stackexchange.com/questions/29012",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33400/"
] | I'd like to remove the period between the 6th comma and the 9th comma for the multiple lines of the following texts.
Change from:
```
4,Afghanistan,2,Medium,1951,1951.5,4134.756,3705.395,7840.151,12.009
4,Afghanistan,5,Constant fertility,2023,2023.5,21628.67,20554.282,42182.952,64.613
```
To:
```
4,Afghanistan,2,M... | The problem with your :normal command
-------------------------------------
You can't run ex commands from within a `:normal` command. Instead, you'll need to run your existing `:normal` command and *then* run the `:substitute`.
Try this:
```
:execute 'normal 6f,v3f,' | s/\%V.\+\%V/\=substitute(submatch(0),'\.','','... |
29,015 | <p>As far as I know I have these two options to compare a string with a pattern:</p>
<ul>
<li>Using the <code>=~</code> comparison.</li>
<li>Using the <code>matchstr()</code> function.</li>
</ul>
<p>So it looks like this:</p>
<pre><code>" with =~
if string =~ "pattern"
<do something>
" wi... | [
{
"answer_id": 29016,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 4,
"selected": true,
"text": "<p>The operator version <code>=~</code> is most likely faster than <code>matchstr</code>. This is for a couple reasons:</p>... | 2021/02/02 | [
"https://vi.stackexchange.com/questions/29015",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31844/"
] | As far as I know I have these two options to compare a string with a pattern:
* Using the `=~` comparison.
* Using the `matchstr()` function.
So it looks like this:
```
" with =~
if string =~ "pattern"
<do something>
" with matchstr()
elseif matchstr(string, "pattern") != ''
<do something>
endif
```
I'm w... | The operator version `=~` is most likely faster than `matchstr`. This is for a couple reasons:
* function calls in vim script have a cost
* matchstr returns a string, therefore has an extra allocation
I've done a direct performance comparison.
```
let t = reltime()
for x in range(1000000)
if matchstr('strpatingp... |
29,022 | <p>If a file has a large number of lines, I'd like to enable line numbers, otherwise leave them off by default. If I run the command:</p>
<p><code>if line('$') > 150 | :set number | endif</code></p>
<p>while vim is open, file lines are enabled/unchanged as expected. Putting this line into my init.vim (for neovim) ha... | [
{
"answer_id": 29023,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 2,
"selected": false,
"text": "<p>An auto command is appropriate here...</p>\n<pre><code>autocmd BufReadPost * if line('$') > 150 | :setlocal number... | 2021/02/04 | [
"https://vi.stackexchange.com/questions/29022",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29671/"
] | If a file has a large number of lines, I'd like to enable line numbers, otherwise leave them off by default. If I run the command:
`if line('$') > 150 | :set number | endif`
while vim is open, file lines are enabled/unchanged as expected. Putting this line into my init.vim (for neovim) has no effect. What am I doing ... | Scripts in your `init.vim` are only executed when you first launch Neovim, or when you source the file manually (same goes for `vimrc` and vim).
To trigger a script automatically, based on an event, you can use an `autocommand`.
For your case, this should do the trick:
```
augroup ShowLineNumberForLongFiles
autocm... |
29,042 | <p>Consider the following <code>statusline</code> that makes use of <code>%r</code> to display <code>[RO]</code>, when <code>readonly</code> has been set.</p>
<p>The problem is that when <code>readonly</code> is not set, two spaces occur between <code>%f</code> (file path) and <code>%y</code> (file type). The problem i... | [
{
"answer_id": 29043,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 3,
"selected": false,
"text": "<p>Yes, it's parentheses (aka "item group"). Sort of</p>\n<pre><code>let &statusline = '%f%( %r%)%( %y%)'\n</... | 2021/02/05 | [
"https://vi.stackexchange.com/questions/29042",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26505/"
] | Consider the following `statusline` that makes use of `%r` to display `[RO]`, when `readonly` has been set.
The problem is that when `readonly` is not set, two spaces occur between `%f` (file path) and `%y` (file type). The problem is even worse, if I have several items, that may sometimes not be shown, separated by s... | Yes, it's parentheses (aka "item group"). Sort of
```
let &statusline = '%f%( %r%)%( %y%)'
```
Some time ago I also wrote a [plugin](https://github.com/matveyt/vim-stalin) (actually a function) to assist in building status line expression from simple "blocks". |
29,056 | <p><code>:help index</code> explains that only exact matches are returned. How would you add a predicate to the search, so that we could find the first element that matches that?</p>
<p>I want to write this:</p>
<pre><code> let i = 0
let commit = ''
while i < len(l:state.commits)
let commit = l:state.commit... | [
{
"answer_id": 29043,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 3,
"selected": false,
"text": "<p>Yes, it's parentheses (aka "item group"). Sort of</p>\n<pre><code>let &statusline = '%f%( %r%)%( %y%)'\n</... | 2021/02/06 | [
"https://vi.stackexchange.com/questions/29056",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/18875/"
] | `:help index` explains that only exact matches are returned. How would you add a predicate to the search, so that we could find the first element that matches that?
I want to write this:
```
let i = 0
let commit = ''
while i < len(l:state.commits)
let commit = l:state.commits[i]
if predicate(commit) the... | Yes, it's parentheses (aka "item group"). Sort of
```
let &statusline = '%f%( %r%)%( %y%)'
```
Some time ago I also wrote a [plugin](https://github.com/matveyt/vim-stalin) (actually a function) to assist in building status line expression from simple "blocks". |
29,079 | <p>For example, if I want to find all <code>bar</code> lines and print them.</p>
<pre><code>$ cat file
line foo
line bar 1
line bar 2
$ cat cmd
norm gg
/bar
p
norm n
p
$ cat cmd | vim -u NONE -es file
line bar 1
line bar 1
$
</code></pre>
<p>As it outputs, <code>normal n</code> does not move to <code>line bar 2</code>.... | [
{
"answer_id": 29081,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 2,
"selected": false,
"text": "<p><code>normal n</code> works for me in Ex mode.</p>\n<p>The problem is that you mix normal mode <code>/search</code> w... | 2021/02/08 | [
"https://vi.stackexchange.com/questions/29079",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1049/"
] | For example, if I want to find all `bar` lines and print them.
```
$ cat file
line foo
line bar 1
line bar 2
$ cat cmd
norm gg
/bar
p
norm n
p
$ cat cmd | vim -u NONE -es file
line bar 1
line bar 1
$
```
As it outputs, `normal n` does not move to `line bar 2`. | `normal n` works for me in Ex mode.
The problem is that you mix normal mode `/search` with ex-mode range `:/search`. In your case `:/search` is executed and it doesn't populate `@/` register thus with `:normal n` you try to search something else (previous interactive search?)
UPD:
>
> i want to find all bar lines a... |
29,093 | <p>I have tried ownsyntax but that does not work. I want do change the background color for only one window? I have tried this but it highlights all the windows.</p>
<pre><code>hi Normal guibg=grey guifg=black
</code></pre>
<hr />
<p>It looks like it is wincolor, not sure if there's another way to change without adding... | [
{
"answer_id": 29095,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<ol>\n<li><p>The answer is different for Vim and Neovim. Vim has <code>:h 'wincolor'</code> to overwrite "Normal"... | 2021/02/09 | [
"https://vi.stackexchange.com/questions/29093",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32923/"
] | I have tried ownsyntax but that does not work. I want do change the background color for only one window? I have tried this but it highlights all the windows.
```
hi Normal guibg=grey guifg=black
```
---
It looks like it is wincolor, not sure if there's another way to change without adding a group. Not sure why my ... | ```
let color_keys = keys(s:css_colors)
for index in range(0,len(color_keys) - 1 )
let color = color_keys[index]
let popid= Popup(color,60000, index * 4)
let cmd = 'hi TEMPCOLOR' . color . ' guibg='.color.' | let &wincolor="TEMPCOLOR'. color. '"'
call win_execute(popid,cmd)
endfor
```
[![enter image d... |
29,098 | <p>Currently I'm using Vim sessions to restore my window layout, but this approach also restores buffers, which I'd prefer to be closed on startup.</p>
<p>Is there a way to do something like:</p>
<pre><code>$ vim file.txt
</code></pre>
<p>And in Vim something like:</p>
<pre><code>: restore-layout
</code></pre>
<p>The o... | [
{
"answer_id": 29101,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<p>A window cannot exist without any buffer attached.</p>\n<p>Just make sure you have an empty unnamed buffer in every wind... | 2021/02/09 | [
"https://vi.stackexchange.com/questions/29098",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2798/"
] | Currently I'm using Vim sessions to restore my window layout, but this approach also restores buffers, which I'd prefer to be closed on startup.
Is there a way to do something like:
```
$ vim file.txt
```
And in Vim something like:
```
: restore-layout
```
The only variant I can think of is to create a function ... | I've ended with this piece in my vimrc:
```
fun! BuffWipe()
for nr in range(1, bufnr('$'))
if (bufwinnr(nr) == -1) && (bufexists(nr))
exec 'bw ' . nr
endif
endfor
endfun
```
Which I call before creating a session on `VimLeave`.
*For some reason it doesn't wipe out all buffers I'd expect (which are... |
29,099 | <p>Is there an autocmd event for kill signals (for e.g. <a href="https://stackoverflow.com/questions/18499497/how-to-process-sigterm-signal-gracefully">SIGTERM</a>) ? As <a href="https://vi.stackexchange.com/a/25838/33130">this</a> answer indicates Vim can catch <code>SigUSR1</code> event. My use case is to save sessio... | [
{
"answer_id": 29101,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<p>A window cannot exist without any buffer attached.</p>\n<p>Just make sure you have an empty unnamed buffer in every wind... | 2021/02/09 | [
"https://vi.stackexchange.com/questions/29099",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33130/"
] | Is there an autocmd event for kill signals (for e.g. [SIGTERM](https://stackoverflow.com/questions/18499497/how-to-process-sigterm-signal-gracefully)) ? As [this](https://vi.stackexchange.com/a/25838/33130) answer indicates Vim can catch `SigUSR1` event. My use case is to save session on SIGTERM before quitting. | I've ended with this piece in my vimrc:
```
fun! BuffWipe()
for nr in range(1, bufnr('$'))
if (bufwinnr(nr) == -1) && (bufexists(nr))
exec 'bw ' . nr
endif
endfor
endfun
```
Which I call before creating a session on `VimLeave`.
*For some reason it doesn't wipe out all buffers I'd expect (which are... |
29,105 | <p>I have a bash command that will align text into a tabular form. If I have input such as this:</p>
<pre><code>A | B | C
Alpha | Beta | Gamma
12 | 34.56 | 78.9
</code></pre>
<p>I can run <code>cat test.txt | sed -e 's/|/'$'\001''|/g' | column -t -s $'\001'</code> to get:</p>
<pre><code>A | B | C
Alpha | ... | [
{
"answer_id": 29109,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>The main issue that needs fixing here is that the <code>|</code> character is special here, it is used as a separat... | 2021/02/09 | [
"https://vi.stackexchange.com/questions/29105",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21009/"
] | I have a bash command that will align text into a tabular form. If I have input such as this:
```
A | B | C
Alpha | Beta | Gamma
12 | 34.56 | 78.9
```
I can run `cat test.txt | sed -e 's/|/'$'\001''|/g' | column -t -s $'\001'` to get:
```
A | B | C
Alpha | Beta | Gamma
12 | 34.56 | 78.9
```... | The main issue that needs fixing here is that the `|` character is special here, it is used as a separator for Ex commands and is not passed verbatim to your mapping.
In order to fix it, you need to either use `<Bar>` or `\|` here.
See [`:help map-bar`](https://vimhelp.org/map.txt.html#map-bar) for more details.
Add... |
29,126 | <p>Say I have a text like</p>
<pre><code>...
def my_function() do
...
end
...
</code></pre>
<p>And I want to yank/copy from <code>def</code> to <code>end</code> (including both <code>def</code> and <code>end</code>), so I can paste this block of text elsewhere.</p>
<p>Is it possible to that in vim? If so, how would I... | [
{
"answer_id": 29128,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>You can use a search with <code>/</code> or <code>?</code> as a motion for a <code>y</code> operation. But that can... | 2021/02/10 | [
"https://vi.stackexchange.com/questions/29126",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33505/"
] | Say I have a text like
```
...
def my_function() do
...
end
...
```
And I want to yank/copy from `def` to `end` (including both `def` and `end`), so I can paste this block of text elsewhere.
Is it possible to that in vim? If so, how would I go about it?
I know that with the command `yt[character]` you can copy e... | You can use a search with `/` or `?` as a motion for a `y` operation. But that can be tricky, because the search motion will be characterwise and exclusive.
So if you position your cursor at the `d` in `def` and then use `y/end<Return>` (where `<Return>` means pressing the `Return` or `Enter` key), Vim will copy every... |
29,129 | <p><code>set guicursor=n:blinkwait5-blinkon5-blinkoff5</code> has no effect.</p>
<p>Why is that?</p>
<p><a href="https://i.gyazo.com/53fce613901e0e0d50089facd242321b.mp4" rel="nofollow noreferrer">mp4</a></p>
| [
{
"answer_id": 29130,
"author": "bashBedlam",
"author_id": 28787,
"author_profile": "https://vi.stackexchange.com/users/28787",
"pm_score": 2,
"selected": false,
"text": "<p><em>:set guicursor&</em> should restore cursor defaults in GVim.</p>\n<p>Edit:\nTo change the blink rate try u... | 2021/02/10 | [
"https://vi.stackexchange.com/questions/29129",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33463/"
] | `set guicursor=n:blinkwait5-blinkon5-blinkoff5` has no effect.
Why is that?
[mp4](https://i.gyazo.com/53fce613901e0e0d50089facd242321b.mp4) | *:set guicursor&* should restore cursor defaults in GVim.
Edit:
To change the blink rate try using guicursor=a instead of guicursor=n like this :
```
:set guicursor=a:blinkwait5-blinkon5-blinkoff5
```
This will ONLY work in GVim, not Vim. |
29,133 | <p>What is the <a href="https://en.wikipedia.org/wiki/NOP_(code)" rel="nofollow noreferrer">NOP code</a> for vimscript?</p>
| [
{
"answer_id": 29134,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 3,
"selected": true,
"text": "<p>VimScript interpreter ignores colons and spaces, so <code>:</code> could be qualified as "nop" command. For exa... | 2021/02/11 | [
"https://vi.stackexchange.com/questions/29133",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33130/"
] | What is the [NOP code](https://en.wikipedia.org/wiki/NOP_(code)) for vimscript? | VimScript interpreter ignores colons and spaces, so `:` could be qualified as "nop" command. For example, `echo 'foo' | :` is the same as just `echo 'foo'`.
However, there's a problem: due to Vi compatibility `:|` is forcefully parsed as `:print`, so `echo 'foo' | : | echo 'bar'` surprisingly transforms into `echo 'fo... |
29,180 | <p>I have this file over here.</p>
<pre><code> <ul class="social-icons">
<li><a href=""><span class="social_linkedin_square"></span></a></li>
</ul>
<ul class="other-icons">
<li><a href="... | [
{
"answer_id": 29150,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<p>Usually you're supposed to do "incremental search" instead. It works like follows: you do <code>:set incsearch... | 2021/02/14 | [
"https://vi.stackexchange.com/questions/29180",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33566/"
] | I have this file over here.
```
<ul class="social-icons">
<li><a href=""><span class="social_linkedin_square"></span></a></li>
</ul>
<ul class="other-icons">
<li><a href=""><span class="other-icon"></span></a></li>
</ul>
```
I'm trying to only print all the list items in the file usin... | Usually you're supposed to do "incremental search" instead. It works like follows: you do `:set incsearch` and then Vim starts moving the cursor while you're typing `/pattern` without awaiting for "enter" hit.
If you really need to browse through previous search patterns, you can make use of `:h cmdwin`. Just press `C... |
29,229 | <p>For a visual <strong>block</strong> selection, the <code>:center</code> command will centre the contents of the selection, not the block as a whole. Is there a way to centre the block as a whole without misaligning the contents?</p>
<p>Situation:</p>
<pre><code>Pythagoras:
|\
| \
a² | \ c²
| \
|____\... | [
{
"answer_id": 29231,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p>I don't think there is a built-in way to achieve what you want to do, so I decided to try to implement it by myself. I go... | 2021/02/16 | [
"https://vi.stackexchange.com/questions/29229",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | For a visual **block** selection, the `:center` command will centre the contents of the selection, not the block as a whole. Is there a way to centre the block as a whole without misaligning the contents?
Situation:
```
Pythagoras:
|\
| \
a² | \ c²
| \
|____\
b²
```
Result:
```
... | I don't think there is a built-in way to achieve what you want to do, so I decided to try to implement it by myself. I got a working solution but this kind of text manipulation has a ton of corner cases and they are most probably not handled by my solution. Hopefully that will give you some inspiration to code your own... |
29,238 | <p>I am trying to write a couple of simple functions to find the next and previous links in Vimwiki and move to them. Links in Vimwiki are indicated with the syntax <code>[[link to something]]</code>. Since I only want to move the cursor and I want to avoid highlighting all matches, I am using the functions <code>searc... | [
{
"answer_id": 29253,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": true,
"text": "<p>So I tested your code a bit and I realized that the issue with your backward search comes from the flag <code>z</code>, I... | 2021/02/17 | [
"https://vi.stackexchange.com/questions/29238",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33382/"
] | I am trying to write a couple of simple functions to find the next and previous links in Vimwiki and move to them. Links in Vimwiki are indicated with the syntax `[[link to something]]`. Since I only want to move the cursor and I want to avoid highlighting all matches, I am using the functions `searchpos()` and `setpos... | So I tested your code a bit and I realized that the issue with your backward search comes from the flag `z`, I don't really have a convincing explanation because reading the doc I would have used it too.
```
'z' start searching at the cursor column instead of Zero
```
I changed your pattern to a simple `.` and reali... |
29,251 | <p>I am trying to do this: deleting lines matching a pattern and then copy these lines into some other place in the file.</p>
<pre><code>:g/PATTERN/d
</code></pre>
<p>does delete the lines but when I use p or P, only the last line is inserted to the file from the internal buffer.</p>
<p>How can I do this?</p>
| [
{
"answer_id": 29252,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>You could delete the lines in a register:</p>\n<p>First clean up your register <code>q</code> for example with <code>qqq<... | 2021/02/18 | [
"https://vi.stackexchange.com/questions/29251",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33647/"
] | I am trying to do this: deleting lines matching a pattern and then copy these lines into some other place in the file.
```
:g/PATTERN/d
```
does delete the lines but when I use p or P, only the last line is inserted to the file from the internal buffer.
How can I do this? | You could delete the lines in a register:
First clean up your register `q` for example with `qqq` in normal mode.
Then use `:g/PATTERN/norm! "Qdd`
In normal mode when you use `"qdd` you replace the content of the `q` register with the deleted text but if you use `"Qdd` you append the deleted text to the register.
*... |
29,258 | <p>A common operation for me is <code>V</code> <code><movement commands></code> <code>d</code> <code>k</code> <code>o</code> <code>ESC</code> to delete a bunch of lines and add a newline. Is there a quicker vim way to do this?</p>
| [
{
"answer_id": 29267,
"author": "Felix Zhang",
"author_id": 33663,
"author_profile": "https://vi.stackexchange.com/users/33663",
"pm_score": 0,
"selected": false,
"text": "<p><code>0c<num>j</code></p>\n<p><code>0</code>: go to the line start</p>\n<p><code>c</code>: prepare to repla... | 2021/02/18 | [
"https://vi.stackexchange.com/questions/29258",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33653/"
] | A common operation for me is `V` `<movement commands>` `d` `k` `o` `ESC` to delete a bunch of lines and add a newline. Is there a quicker vim way to do this? | You could get it simply with:
```
<num>cc
```
From vim's `:help cc`
```
["x]cc Delete [count] lines [into register x] and start
insert |linewise|. If 'autoindent' is on, preserve
the indent of the first line.
``` |
29,273 | <p>I want to highlight around of current line in Vim like VSCode.</p>
<p><a href="https://i.stack.imgur.com/KFWFX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KFWFX.png" alt="enter image description here" /></a></p>
<p><strong>Edit</strong>: I want to highlight up, left, down, and right of current... | [
{
"answer_id": 29279,
"author": "GH1995",
"author_id": 13500,
"author_profile": "https://vi.stackexchange.com/users/13500",
"pm_score": 2,
"selected": false,
"text": "<p><a href=\"https://github.com/miyakogi/conoline.vim\" rel=\"nofollow noreferrer\">Conoline.vim</a>\nThis plugin highlig... | 2021/02/19 | [
"https://vi.stackexchange.com/questions/29273",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33590/"
] | I want to highlight around of current line in Vim like VSCode.
[](https://i.stack.imgur.com/KFWFX.png)
**Edit**: I want to highlight up, left, down, and right of current line. | You might try just `:set cursorline`—
```
*'cursorline'* *'cul'* *'nocursorline'* *'nocul'*
'cursorline' 'cul' boolean (default off)
local to window
{not available when compiled without the |+syntax|
feature}
Highlight the text line of the cursor with CursorLine |hl... |
29,275 | <p>Sometimes I want to add several empty lines for better visualization. Now I end up clicking <code>o<Escape></code> multiple times. I would love to reduce number of clicks by using something like <code>7o</code> instead, to get 7 empty lines without entering insert mode.</p>
| [
{
"answer_id": 29279,
"author": "GH1995",
"author_id": 13500,
"author_profile": "https://vi.stackexchange.com/users/13500",
"pm_score": 2,
"selected": false,
"text": "<p><a href=\"https://github.com/miyakogi/conoline.vim\" rel=\"nofollow noreferrer\">Conoline.vim</a>\nThis plugin highlig... | 2021/02/19 | [
"https://vi.stackexchange.com/questions/29275",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/147/"
] | Sometimes I want to add several empty lines for better visualization. Now I end up clicking `o<Escape>` multiple times. I would love to reduce number of clicks by using something like `7o` instead, to get 7 empty lines without entering insert mode. | You might try just `:set cursorline`—
```
*'cursorline'* *'cul'* *'nocursorline'* *'nocul'*
'cursorline' 'cul' boolean (default off)
local to window
{not available when compiled without the |+syntax|
feature}
Highlight the text line of the cursor with CursorLine |hl... |
29,288 | <p>Whenever I run <code>:make</code> in Vim, it always takes control away from my buffer, places me in a temporary view where I see the makeprg's output and then prompts me to "Press ENTER or type command to continue". Is there a way so I can run <code>:make</code> without leaving my current buffer?</p>
<p>Fo... | [
{
"answer_id": 29290,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>You can use tpope’s <a href=\"https://github.com/tpope/vim-dispatch\" rel=\"nofollow noreferrer\">dispatch</a> ... | 2021/02/20 | [
"https://vi.stackexchange.com/questions/29288",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16073/"
] | Whenever I run `:make` in Vim, it always takes control away from my buffer, places me in a temporary view where I see the makeprg's output and then prompts me to "Press ENTER or type command to continue". Is there a way so I can run `:make` without leaving my current buffer?
For context, I'm using pyunit to parse Pyth... | One way to do this natively in vim is to utilise `system()` or `systemlist()`. I'm not familiar with pyunit, but something like the following may help you get started.
```
function! MyMake() abort
let l:efm = "%C %.%#,%A File "%f"\, line %l%.%#,%Z%[%^ ]%\@=%m"
let l:lines = systemlist("cat " . expand("%"))
... |
29,295 | <p>For convenience, I'd like to define some variables. But I worry that I may forget their names. How can I get a list of them?</p>
| [
{
"answer_id": 29296,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 4,
"selected": true,
"text": "<p>If it's a global variable then it resides in <code>g:</code> dictionary, so simply <code>echo g:</code> works.</p>\n<p>If... | 2021/02/21 | [
"https://vi.stackexchange.com/questions/29295",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33595/"
] | For convenience, I'd like to define some variables. But I worry that I may forget their names. How can I get a list of them? | If it's a global variable then it resides in `g:` dictionary, so simply `echo g:` works.
If `g:` is too big it's possible to search through it, like any other dictionary, for example:
```
echo copy(g:)->filter('v:key =~# "^loaded_"')
``` |
29,299 | <p>I am <strong>new</strong> to vim, I watched <a href="https://www.youtube.com/watch?v=wlR5gYd6um0" rel="nofollow noreferrer">this video</a> and wish to give it a good try for a month to see how I like it.</p>
<p>I want to add the NERDTree plugin to my vim, I'm actually using NeoVIM:</p>
<pre><code>NVIM v0.4.4
Build t... | [
{
"answer_id": 29296,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 4,
"selected": true,
"text": "<p>If it's a global variable then it resides in <code>g:</code> dictionary, so simply <code>echo g:</code> works.</p>\n<p>If... | 2021/02/22 | [
"https://vi.stackexchange.com/questions/29299",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33692/"
] | I am **new** to vim, I watched [this video](https://www.youtube.com/watch?v=wlR5gYd6um0) and wish to give it a good try for a month to see how I like it.
I want to add the NERDTree plugin to my vim, I'm actually using NeoVIM:
```
NVIM v0.4.4
Build type: Release
LuaJIT 2.0.5
```
I Googled and found [this article](ht... | If it's a global variable then it resides in `g:` dictionary, so simply `echo g:` works.
If `g:` is too big it's possible to search through it, like any other dictionary, for example:
```
echo copy(g:)->filter('v:key =~# "^loaded_"')
``` |
29,303 | <p>I have the following mapping:</p>
<pre><code>inoremap <expr><CR> pumvisible() && complete_info().selected != -1? "\<C-y>" : "\<CR>"
inoremap <expr><Space> pumvisible() && complete_info().selected != -1? "\<C-y>" : "\<Spac... | [
{
"answer_id": 29305,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 0,
"selected": false,
"text": "<p>The problem with your code is that in a mapping command, you do not need to escape <code><keys></code>. This is b... | 2021/02/22 | [
"https://vi.stackexchange.com/questions/29303",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33126/"
] | I have the following mapping:
```
inoremap <expr><CR> pumvisible() && complete_info().selected != -1? "\<C-y>" : "\<CR>"
inoremap <expr><Space> pumvisible() && complete_info().selected != -1? "\<C-y>" : "\<Space>"
```
The idea here is that if I have a completion menu open & and item selected, then pressing `Enter` o... | One can use a timer to prevent keys from being pressed simultaneously. For example,
```
inoremap <C-a> <C-y><Esc>:call timer_start(100, {-> feedkeys("a ")})<CR>
```
will send `<C-y><Esc>` followed by `a<Space>` after 100ms.
Instead of 100ms, one can specify any delay, even 0ms.
Adding the above to the expr mapping... |
29,314 | <p>I would like to replace a multiline block to one line</p>
<p>for example :</p>
<pre><code> if (... ){
//comment0
line1
line2
}
some code
if (... ){
//comment0
line1
line2
}
</code></pre>
<p>into:</p>
<pre><code>if_function()
some code
if_function()
</code></pre>
<p>is the... | [
{
"answer_id": 29305,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 0,
"selected": false,
"text": "<p>The problem with your code is that in a mapping command, you do not need to escape <code><keys></code>. This is b... | 2021/02/23 | [
"https://vi.stackexchange.com/questions/29314",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33733/"
] | I would like to replace a multiline block to one line
for example :
```
if (... ){
//comment0
line1
line2
}
some code
if (... ){
//comment0
line1
line2
}
```
into:
```
if_function()
some code
if_function()
```
is there a fast way to do this?
I tried to yank the block... | One can use a timer to prevent keys from being pressed simultaneously. For example,
```
inoremap <C-a> <C-y><Esc>:call timer_start(100, {-> feedkeys("a ")})<CR>
```
will send `<C-y><Esc>` followed by `a<Space>` after 100ms.
Instead of 100ms, one can specify any delay, even 0ms.
Adding the above to the expr mapping... |
29,321 | <p>I am using this working regex<br />
<code>:%s/\( to\)\([a-z]\)/\1 \2/c</code><br />
to replace <code>tothem</code> with <code>to them</code> and <code>tohim</code> with <code>to him</code>.<br />
But I do not want to look at words like <code>together</code>, <code>tone</code>, <code>tonal</code>, etc</p>
<p>I tried ... | [
{
"answer_id": 29305,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 0,
"selected": false,
"text": "<p>The problem with your code is that in a mapping command, you do not need to escape <code><keys></code>. This is b... | 2021/02/23 | [
"https://vi.stackexchange.com/questions/29321",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27300/"
] | I am using this working regex
`:%s/\( to\)\([a-z]\)/\1 \2/c`
to replace `tothem` with `to them` and `tohim` with `to him`.
But I do not want to look at words like `together`, `tone`, `tonal`, etc
I tried something like this
`:%s/\(\?\!together|tone|tonal\)\( to\)\([a-z]\)/\1 \2/c`
but I clearly have the... | One can use a timer to prevent keys from being pressed simultaneously. For example,
```
inoremap <C-a> <C-y><Esc>:call timer_start(100, {-> feedkeys("a ")})<CR>
```
will send `<C-y><Esc>` followed by `a<Space>` after 100ms.
Instead of 100ms, one can specify any delay, even 0ms.
Adding the above to the expr mapping... |
29,332 | <p>I'm trying to create my own mapping with motion in Vim after reading <a href="https://vi.stackexchange.com/questions/5495/mapping-with-motion">this</a> stackexchange question. I'm using the plugin <a href="https://github.com/brauner/vimtux" rel="nofollow noreferrer">vimtux</a> to send code to specific tmux instances... | [
{
"answer_id": 29336,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": true,
"text": "<p>Obviously, <code>v</code> means charwise selection, while you've got the linewise one (<code>ip</code>). So you must chec... | 2021/02/23 | [
"https://vi.stackexchange.com/questions/29332",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33746/"
] | I'm trying to create my own mapping with motion in Vim after reading [this](https://vi.stackexchange.com/questions/5495/mapping-with-motion) stackexchange question. I'm using the plugin [vimtux](https://github.com/brauner/vimtux) to send code to specific tmux instances and I now want to be able to do this using motion ... | Obviously, `v` means charwise selection, while you've got the linewise one (`ip`). So you must check the value of `a:type` and build the command in the right way with the help of `:execute` or plain `:if` etc. |
29,334 | <p>I'm wrapping a command line script in a function and then in a command, which supplies this script with 2 arguments:</p>
<pre><code>nnoremap <leader>G :BxSedRi 'src/', 's/\<<C-r><C-w>\>
fun! BxSedRi(Dir,Arg)
:if len(getbufinfo({'bufmodified': 1}))
:throw "Must not... | [
{
"answer_id": 29336,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": true,
"text": "<p>Obviously, <code>v</code> means charwise selection, while you've got the linewise one (<code>ip</code>). So you must chec... | 2021/02/23 | [
"https://vi.stackexchange.com/questions/29334",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4738/"
] | I'm wrapping a command line script in a function and then in a command, which supplies this script with 2 arguments:
```
nnoremap <leader>G :BxSedRi 'src/', 's/\<<C-r><C-w>\>
fun! BxSedRi(Dir,Arg)
:if len(getbufinfo({'bufmodified': 1}))
:throw "Must not have modified buffers"
:endif
... | Obviously, `v` means charwise selection, while you've got the linewise one (`ip`). So you must check the value of `a:type` and build the command in the right way with the help of `:execute` or plain `:if` etc. |
29,345 | <p>if I edit the following block in vim:</p>
<pre class="lang-html prettyprint-override"><code><div> foo </div>
<!----------------------------------------------------------->
<div> bar </div>
<!----------------------------------------------------------->
<div> baz </div>
... | [
{
"answer_id": 29336,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": true,
"text": "<p>Obviously, <code>v</code> means charwise selection, while you've got the linewise one (<code>ip</code>). So you must chec... | 2021/02/24 | [
"https://vi.stackexchange.com/questions/29345",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21789/"
] | if I edit the following block in vim:
```html
<div> foo </div>
<!----------------------------------------------------------->
<div> bar </div>
<!----------------------------------------------------------->
<div> baz </div>
```
the second div ("bar") is shown as commented-out. As far as I can find a valid HTML commen... | Obviously, `v` means charwise selection, while you've got the linewise one (`ip`). So you must check the value of `a:type` and build the command in the right way with the help of `:execute` or plain `:if` etc. |
29,346 |
<p>i want to run this global command :</p>
<pre class="lang-bash prettyprint-override"><code>/3)\(.*\n\?.*\)\{1,10\};;/
</code></pre>
<p>which matches multlines. I want to append a line after the matched block(of lines) across multiple buffers. I don't know where to begin with. Is there an append controller like in se... | [
{
"answer_id": 29352,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 2,
"selected": false,
"text": "<p>You can use a substitution with <code>\\zs</code> (or <code>&</code>) to do to "append" your line in ... | 2021/02/24 | [
"https://vi.stackexchange.com/questions/29346",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33709/"
] | i want to run this global command :
```bash
/3)\(.*\n\?.*\)\{1,10\};;/
```
which matches multlines. I want to append a line after the matched block(of lines) across multiple buffers. I don't know where to begin with. Is there an append controller like in sed `/a` that appends after the match ? or is there any other ... | You can use a substitution with `\zs` (or `&`) to do to "append" your line in the form:
```
:%s/pat\zs/\rAppendMe/g
:%s/pat/&\rAppendMe/g
```
To do this across multiple buffers you need a list of files/buffers then a way to execute your command.
* All buffers use `:bufdo {cmd}` where `{cmd}` is your command
* These... |
29,350 | <p>I found a bug in the CoC plugin, and I was going to fix the bug, but first I wanted to write some documentation/learning tests as well as a regression test. The question was how: unit testing does not seem to be that much used, apart from the existence of the <a href="https://github.com/junegunn/vader.vim" rel="nofo... | [
{
"answer_id": 29351,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>I don't think this is possible either.</p>\n<p>I'd say you may found a solution depending on how the call to <code>h... | 2021/02/24 | [
"https://vi.stackexchange.com/questions/29350",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1087/"
] | I found a bug in the CoC plugin, and I was going to fix the bug, but first I wanted to write some documentation/learning tests as well as a regression test. The question was how: unit testing does not seem to be that much used, apart from the existence of the [Vader.vim project](https://github.com/junegunn/vader.vim).
... | I don't think this is possible either.
I'd say you may found a solution depending on how the call to `has()` is used.
Sometimes you will be able to overwrite the direct consequence of a call to `has()` (like changing/removing a function/a command... that depends on `has()` result), other times it wouldn't be possible.... |
29,356 | <p>Is it possible to move selected lines up and down?</p>
<pre><code>c = 3
a = 1
b = 2
</code></pre>
<p>I would like to select second and third lines and move them one line up, so that result be:</p>
<pre><code>a = 1
b = 2
c = 3
</code></pre>
<p>I know that <code>></code> and <code><</code> moves lines right and ... | [
{
"answer_id": 29357,
"author": "okket",
"author_id": 6450,
"author_profile": "https://vi.stackexchange.com/users/6450",
"pm_score": 2,
"selected": false,
"text": "<p>You can select the lines with entering visual line mode <code>V</code>, deleting with <code>d</code> and pasting with <co... | 2021/02/25 | [
"https://vi.stackexchange.com/questions/29356",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/147/"
] | Is it possible to move selected lines up and down?
```
c = 3
a = 1
b = 2
```
I would like to select second and third lines and move them one line up, so that result be:
```
a = 1
b = 2
c = 3
```
I know that `>` and `<` moves lines right and left, but how to move them up and down? | You can do this with the [`:move`](https://vimhelp.org/change.txt.html#%3Amove) ex command:
```
:2,3m0
```
In the above, `2,3` is a [range](https://vimhelp.org/cmdline.txt.html#%3Arange) which specifies which lines we want to move, `m` is an abbreviated form of the `:move` command, and `0` is an [address](https://vi... |
29,360 | <p>I can increment the number under the cursor (by e.g. 10) by doing</p>
<p>10<code><C-a></code></p>
<p>But how do I multiply the number under the cursor with x amount and the replace it in the same way I do when incrementing by a constant amount?</p>
| [
{
"answer_id": 29357,
"author": "okket",
"author_id": 6450,
"author_profile": "https://vi.stackexchange.com/users/6450",
"pm_score": 2,
"selected": false,
"text": "<p>You can select the lines with entering visual line mode <code>V</code>, deleting with <code>d</code> and pasting with <co... | 2021/02/25 | [
"https://vi.stackexchange.com/questions/29360",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33463/"
] | I can increment the number under the cursor (by e.g. 10) by doing
10`<C-a>`
But how do I multiply the number under the cursor with x amount and the replace it in the same way I do when incrementing by a constant amount? | You can do this with the [`:move`](https://vimhelp.org/change.txt.html#%3Amove) ex command:
```
:2,3m0
```
In the above, `2,3` is a [range](https://vimhelp.org/cmdline.txt.html#%3Arange) which specifies which lines we want to move, `m` is an abbreviated form of the `:move` command, and `0` is an [address](https://vi... |
29,372 | <p>I'm remapping <code>o</code> and <code>O</code> in my Git Bash <code>vimrc</code> to insert a new line without staying in insert mode:</p>
<pre><code>nnoremap o o<Esc>
nnoremap O O<Esc>
</code></pre>
<p>The problem is that a new line is inserted and the literal character sequence <code><Esc></code>... | [
{
"answer_id": 29394,
"author": "wxz",
"author_id": 33778,
"author_profile": "https://vi.stackexchange.com/users/33778",
"pm_score": 1,
"selected": false,
"text": "<p>Updated answer:</p>\n<p>Using <code>:substitute</code> to replace end/beginning of line with return got the results OP wa... | 2021/02/25 | [
"https://vi.stackexchange.com/questions/29372",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33735/"
] | I'm remapping `o` and `O` in my Git Bash `vimrc` to insert a new line without staying in insert mode:
```
nnoremap o o<Esc>
nnoremap O O<Esc>
```
The problem is that a new line is inserted and the literal character sequence `<Esc>` is added onto the new line. How can I fix this, and instead exit insert mode?
Im edi... | (Doesn't look like @filbranden or @AndrewHo-Lee are planning to answer this, so adding a Community Wiki answer with [the diagnosis they figured out](https://chat.stackexchange.com/rooms/120169/discussion-on-question-by-harith-adding-esc-to-a-remap-literally-inserts-esc).)
The problem turned out to be that [`'compatibl... |
29,382 | <p>I want to format only a part of file and keep the rest unchanged using <a href="https://github.com/dense-analysis/ale" rel="nofollow noreferrer">ALE</a>. I imagine that its kinda possible by providing a fragment of code for example for <code>black</code> formatter and replacing the selected lines with the result ret... | [
{
"answer_id": 37873,
"author": "cmaceachern",
"author_id": 5369,
"author_profile": "https://vi.stackexchange.com/users/5369",
"pm_score": 1,
"selected": false,
"text": "<p>I'm doing this now with vim9script in <code>~/.vim/after/ftplugin/python.vim</code>:</p>\n<pre><code>autocmd! BufWr... | 2021/02/25 | [
"https://vi.stackexchange.com/questions/29382",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/147/"
] | I want to format only a part of file and keep the rest unchanged using [ALE](https://github.com/dense-analysis/ale). I imagine that its kinda possible by providing a fragment of code for example for `black` formatter and replacing the selected lines with the result retrieved from `black`.
Applying formatter for a larg... | Range formatting is not supported by black because range of lines are in general not valid Python code.
You may have a look at `black-macchiato`.
Install `black-macchiato` by running the shell command:
```
pip install black-macchiato
```
To format a range of select lines run the vim command:
```
:'<,'>!python -m ... |
29,386 | <p>I have a nifty autocommand in my <code>vimrc</code> that automatically maximizes any <code>:help</code> window:</p>
<pre><code>augroup LargeHelpWindow
autocmd!
autocmd BufWinEnter * if &l:buftype ==# 'help' | wincmd _ | endif
augroup END
</code></pre>
<p>This is really useful to optimize screen usage whe... | [
{
"answer_id": 37873,
"author": "cmaceachern",
"author_id": 5369,
"author_profile": "https://vi.stackexchange.com/users/5369",
"pm_score": 1,
"selected": false,
"text": "<p>I'm doing this now with vim9script in <code>~/.vim/after/ftplugin/python.vim</code>:</p>\n<pre><code>autocmd! BufWr... | 2021/02/26 | [
"https://vi.stackexchange.com/questions/29386",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33382/"
] | I have a nifty autocommand in my `vimrc` that automatically maximizes any `:help` window:
```
augroup LargeHelpWindow
autocmd!
autocmd BufWinEnter * if &l:buftype ==# 'help' | wincmd _ | endif
augroup END
```
This is really useful to optimize screen usage when using `:help` and it is based on buffer type. I ... | Range formatting is not supported by black because range of lines are in general not valid Python code.
You may have a look at `black-macchiato`.
Install `black-macchiato` by running the shell command:
```
pip install black-macchiato
```
To format a range of select lines run the vim command:
```
:'<,'>!python -m ... |
29,403 | <p>Given the following setup</p>
<ul>
<li>edit</li>
</ul>
<pre><code>a long line
short
</code></pre>
<ul>
<li>move the cursor to line 1, column 9 (> 6 anyway)</li>
<li>move down and up again</li>
</ul>
<p>I see that when moving to the short line, the column becomes at most 6 (5 in normal mode), but when moving back ... | [
{
"answer_id": 37873,
"author": "cmaceachern",
"author_id": 5369,
"author_profile": "https://vi.stackexchange.com/users/5369",
"pm_score": 1,
"selected": false,
"text": "<p>I'm doing this now with vim9script in <code>~/.vim/after/ftplugin/python.vim</code>:</p>\n<pre><code>autocmd! BufWr... | 2021/02/27 | [
"https://vi.stackexchange.com/questions/29403",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30091/"
] | Given the following setup
* edit
```
a long line
short
```
* move the cursor to line 1, column 9 (> 6 anyway)
* move down and up again
I see that when moving to the short line, the column becomes at most 6 (5 in normal mode), but when moving back up, vi remembers that I used to be in column 9.
How is this possibl... | Range formatting is not supported by black because range of lines are in general not valid Python code.
You may have a look at `black-macchiato`.
Install `black-macchiato` by running the shell command:
```
pip install black-macchiato
```
To format a range of select lines run the vim command:
```
:'<,'>!python -m ... |
29,417 | <p>If I'm not mistaken, NerdTree and Fern are for viewing directories, not for editing general trees (<a href="https://en.wikipedia.org/wiki/Tree_(graph_theory)#Plane_tree" rel="nofollow noreferrer">Ordered trees</a> of strings in CS terms)</p>
<p>If so, is there a way to edit general trees in Vim? (It should preserve ... | [
{
"answer_id": 29428,
"author": "alec",
"author_id": 6189,
"author_profile": "https://vi.stackexchange.com/users/6189",
"pm_score": 2,
"selected": false,
"text": "<p>I doubt you'll find a "tree editor plugin" because Vim makes editing easy and the features that would ease the p... | 2021/02/28 | [
"https://vi.stackexchange.com/questions/29417",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | If I'm not mistaken, NerdTree and Fern are for viewing directories, not for editing general trees ([Ordered trees](https://en.wikipedia.org/wiki/Tree_(graph_theory)#Plane_tree) of strings in CS terms)
If so, is there a way to edit general trees in Vim? (It should preserve the order of the leaves/branches instead of so... | I doubt you'll find a "tree editor plugin" because Vim makes editing easy and the features that would ease the process for editing tree data are not unique to editing trees. These are the features to learn that will make this easier for you...
**fold** commands like `za`, `zc` etc should solve the expand/collapse part... |
29,449 | <p>all these works</p>
<pre><code>git show bf5500a8 | vim -R -
vim file1 file2 -O
git show bf5500a8 > tmpfile ; vim tmpfile file2 -O ; rm tmpfile
</code></pre>
<p>but I'd like to know if I can open stdout and other file directly , without create a tmp file ?</p>
<p>UPDATE 2021.03.15 :
What I really like to kno... | [
{
"answer_id": 29450,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 2,
"selected": true,
"text": "<p>Try <a href=\"https://vimhelp.org/starting.txt.html#-c\" rel=\"nofollow noreferrer\"><code>-c</code></a> which allows ... | 2021/03/02 | [
"https://vi.stackexchange.com/questions/29449",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3271/"
] | all these works
```
git show bf5500a8 | vim -R -
vim file1 file2 -O
git show bf5500a8 > tmpfile ; vim tmpfile file2 -O ; rm tmpfile
```
but I'd like to know if I can open stdout and other file directly , without create a tmp file ?
UPDATE 2021.03.15 :
What I really like to know is how vim can replace "-" and ... | Try [`-c`](https://vimhelp.org/starting.txt.html#-c) which allows you to specify an Ex command to be run after the first file is loaded...
```
git show bf5500a8 | vim -c 'e /path/to/file' -
```
You want them in a split?
```
git show bf5500a8 | vim -c 'split /path/to/file' -
```
**Update:** Since you insist on usi... |
29,453 | <p>Is it possible to highlight unicode characters?</p>
<p>When I copy/paste a code sample I sometimes run into problems because the website uses <code>‐</code>, <code>‑</code>, <code>‒</code> or <code>–</code> instead of <code>-</code> or some other characters that are hard to catch.</p>
<p>I'd like to get a visual ind... | [
{
"answer_id": 29456,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>I have a pretty general approach to this in <code>~/.vim/plugin/badwords.vim</code> which I'll put here (word l... | 2021/03/02 | [
"https://vi.stackexchange.com/questions/29453",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10337/"
] | Is it possible to highlight unicode characters?
When I copy/paste a code sample I sometimes run into problems because the website uses `‐`, `‑`, `‒` or `–` instead of `-` or some other characters that are hard to catch.
I'd like to get a visual indicator (e.g. a red background) that these are special characters.
I f... | With the help from Konfekt/vim-unicode-homoglyphs and [the answers here](https://stackoverflow.com/a/16988346/52817) I found this solution that works quite well and has (almost?) no performance impact:
```
augroup Hiunicode
autocmd!
autocmd BufEnter *
\ syntax match nonascii "[^\x00-\x7F]" |
\ highligh... |
29,473 | <p>I have the following command for arranging a few lines in a file using <code>sed</code> and <code>column</code>:</p>
<pre><code>:-3,+2!sed 's/- 2021/\&2021/' | sed 's/ 2021/\&2021/' | column -s '&' -t
</code></pre>
<p>This works fine. For example, the following buffer:</p>
<pre><code>
a - 2021-01-01
... | [
{
"answer_id": 29474,
"author": "user938271",
"author_id": 17449,
"author_profile": "https://vi.stackexchange.com/users/17449",
"pm_score": 1,
"selected": false,
"text": "<p>Try this:</p>\n<pre><code>xnoremap <F3> :<c-u>call Test()<cr>\n\nfunction Test() abort\n let ... | 2021/03/03 | [
"https://vi.stackexchange.com/questions/29473",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33873/"
] | I have the following command for arranging a few lines in a file using `sed` and `column`:
```
:-3,+2!sed 's/- 2021/\&2021/' | sed 's/ 2021/\&2021/' | column -s '&' -t
```
This works fine. For example, the following buffer:
```
a - 2021-01-01
b - 2021-04-05
```
Gets formatted into:
```
a 2021-01... | Remove the `normal`; you want to run an Ex command, so just run it:
```
-3,+2!sed …
```
and note that you can define functions which take ranges (you'll need `:execute …` at that point). |
29,483 | <p>I've discovered I can execute vim macros from the command line using the following command:</p>
<pre><code>vim myfile -c "argdo norm @aZZ"
</code></pre>
<p>This command executed from the command line will execute a macro that I have stored inside <code>register a</code> and close the file. It works fine, h... | [
{
"answer_id": 29485,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 3,
"selected": true,
"text": "<p><code>^X</code> is display representation of byte value of #24 (as "X" is the 24th letter in alphabet). Hence i... | 2021/03/04 | [
"https://vi.stackexchange.com/questions/29483",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32434/"
] | I've discovered I can execute vim macros from the command line using the following command:
```
vim myfile -c "argdo norm @aZZ"
```
This command executed from the command line will execute a macro that I have stored inside `register a` and close the file. It works fine, however, I'd like to be able to execute a macr... | `^X` is display representation of byte value of #24 (as "X" is the 24th letter in alphabet). Hence instead of `:let @l="Goa^Ma^Ma^C^C"` you should write:
```
let @l = "Goa\ra\ra\3\3"
```
Escape rules are borrowed from C. Full description is under `:h expr-quote`. |
29,491 | <p>I am using vim as a book reader.<br />
For this purpose I have three windows open as shown</p>
<pre><code> ________________________________________
|~ ||The book I'm||~ |
|~ ||reading here||~ |
|~ ||It's a braw ||~ |
|~ ||licht moon |... | [
{
"answer_id": 29492,
"author": "Jürgen Krämer",
"author_id": 2636,
"author_profile": "https://vi.stackexchange.com/users/2636",
"pm_score": 2,
"selected": false,
"text": "<p>You can set foreground and background of the <code>VertSplit</code> highlighting group to the background color of... | 2021/03/04 | [
"https://vi.stackexchange.com/questions/29491",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27300/"
] | I am using vim as a book reader.
For this purpose I have three windows open as shown
```
________________________________________
|~ ||The book I'm||~ |
|~ ||reading here||~ |
|~ ||It's a braw ||~ |
|~ ||licht moon ||~ | ... | You can set foreground and background of the `VertSplit` highlighting group to the background color of your Vim instance:
```
:hi VertSplit ctermfg=bg ctermbg=bg guifg=bg guibg=bg
``` |
29,512 | <p>I have files which are encrypted by vim.</p>
<p>From the command line, how can I determine which encryption method was used on a given file?</p>
| [
{
"answer_id": 29524,
"author": "Risky_91",
"author_id": 33793,
"author_profile": "https://vi.stackexchange.com/users/33793",
"pm_score": 0,
"selected": false,
"text": "<p>After doing a little research, It doesn’t look like they is any really good way to determine file encryption, since ... | 2021/03/05 | [
"https://vi.stackexchange.com/questions/29512",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20047/"
] | I have files which are encrypted by vim.
From the command line, how can I determine which encryption method was used on a given file? | I looked at the [source code](https://github.com/vim/vim/blob/master/src/crypt.c#L77) of vim and figured that a header is written to encrypted files that specify the encryption method in the form of a code like 'VimCrypt~01!' for 'zip' and so on.
So here is a bash script to print the filenames and encryption methods o... |
29,514 | <p>Let's say I have a file that contains a specific number that is always the same, something like the following:</p>
<pre><code>1 1000
10 1000
100 1000
1000 1000
10000 1000
100000 1000
1000000 1000
10000000 1000
100000000 1000
</code></pre>
<p>I want to make this list like the following:</p>
<pre><code>1 1000
10 1001
... | [
{
"answer_id": 29516,
"author": "Quasímodo",
"author_id": 30440,
"author_profile": "https://vi.stackexchange.com/users/30440",
"pm_score": 2,
"selected": false,
"text": "<pre><code>:%!awk '{$2+=c++}1'\n</code></pre>\n<p><sup>If no number in the column is zero, you can golf that to <code>... | 2021/03/05 | [
"https://vi.stackexchange.com/questions/29514",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32434/"
] | Let's say I have a file that contains a specific number that is always the same, something like the following:
```
1 1000
10 1000
100 1000
1000 1000
10000 1000
100000 1000
1000000 1000
10000000 1000
100000000 1000
```
I want to make this list like the following:
```
1 1000
10 1001
100 1002
1000 1003
10000 1004
1000... | ```
qa$<C-a>q
```
* `qa` macro 'a'
* `$` go to end of line
* `<C-a>` and increase
* `q` quit macro
```
:g/0$/.,$ norm @a
```
works for me. |
29,529 | <p>When I am working in vi there pop up things that look like uninterpreted escape sequences. They come for example when I type <kbd>i</kbd> to enter insert mode, or <kbd>ESC</kbd> to leave it</p>
<p>Example, triggered by typing <kbd>i</kbd> immediately followed by <kbd>ESC</kbd>:
<code>[>4;m[>4;2m</code></p>
<p>... | [
{
"answer_id": 29532,
"author": "Karel Adams",
"author_id": 33916,
"author_profile": "https://vi.stackexchange.com/users/33916",
"pm_score": 1,
"selected": false,
"text": "<p>The comment above was indeed the solution.\n.vimrc now reads as below, probably I can remove some the earlier exp... | 2021/03/06 | [
"https://vi.stackexchange.com/questions/29529",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/33916/"
] | When I am working in vi there pop up things that look like uninterpreted escape sequences. They come for example when I type `i` to enter insert mode, or `ESC` to leave it
Example, triggered by typing `i` immediately followed by `ESC`:
`[>4;m[>4;2m`
Version:
```
vi --version
VIM - Vi IMproved 8.1 (2018 May 18, compi... | The comment above was indeed the solution.
.vimrc now reads as below, probably I can remove some the earlier experiments.
```
set nohlsearch
set t_Co=0
highlight LineNr NONE
hi CursorLine NONE
hi Normal cterm=none ctermfg=none ctermbg=none
set t_TE=""
set t_TI=""
``` |
29,552 | <p>I am slowly switching my neovim configurations to Lua. I am currently using the colour scheme
<a href="https://github.com/nightsense/snow" rel="nofollow noreferrer">https://github.com/nightsense/snow</a>. It sets the background colour to a light-grey, while I want it to be a darker tone of grey. Previously, when usi... | [
{
"answer_id": 29553,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 0,
"selected": false,
"text": "<p>I see no particular problem about Lua syntax. Perhaps, you simply forgot to set termguicolors or your console does not s... | 2021/03/08 | [
"https://vi.stackexchange.com/questions/29552",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27586/"
] | I am slowly switching my neovim configurations to Lua. I am currently using the colour scheme
<https://github.com/nightsense/snow>. It sets the background colour to a light-grey, while I want it to be a darker tone of grey. Previously, when using vimL, I used to use the following snippet to change the background colour... | This was how I sorted out my problem in the end
```
vim.api.nvim_command([[
augroup ChangeBackgroudColour
autocmd colorscheme * :hi normal guibg=#0a0a0a
augroup END
]])
vim.o.termguicolors = true
vim.cmd [[silent! colorscheme snow]]
``` |
29,564 | <p>I'm trying to answer a <a href="/questions/tagged/vim" class="post-tag" title="show questions tagged 'vim'" rel="tag">vim</a> question in U&L, which involves a very complex and long regex substitution.</p>
<p>I would like to copy to clipboard <em>the command</em>, or save it in a file, so I don't have to... | [
{
"answer_id": 29565,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p>To past the content of a register you can prefix your <code>p</code> command with <code>"[register_name]</code>, tha... | 2021/03/09 | [
"https://vi.stackexchange.com/questions/29564",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27174/"
] | I'm trying to answer a [vim](/questions/tagged/vim "show questions tagged 'vim'") question in U&L, which involves a very complex and long regex substitution.
I would like to copy to clipboard *the command*, or save it in a file, so I don't have to make a transcription, prone to errors.
Example:
```none
foo
bar
~
~
:... | To past the content of a register you can prefix your `p` command with `"[register_name]`, that's what `["x]` mean in `["x]p` in [`:h p`](http://vimhelp.appspot.com/change.txt.html#p):
```
p
["x]p Put the text [from register x] after the cursor
[count] times.
```
You com... |
29,574 | <p>Suppose I have this in a text buffer (<code>vim --clean mydoc.txt</code>):</p>
<pre><code>One
Two
Three
Four
</code></pre>
<p>I highlight all lines using <code>:call matchadd('ErrorMsg', '.*')</code>, resulting in:</p>
<p><a href="https://i.stack.imgur.com/16UvP.png" rel="nofollow noreferrer"><img src="https://i.sta... | [
{
"answer_id": 29576,
"author": "DC Slagel",
"author_id": 14302,
"author_profile": "https://vi.stackexchange.com/users/14302",
"pm_score": 0,
"selected": false,
"text": "<p>This seems to work, but <del>I'm not confident that it will work in every case..</del> is flawed.</p>\n<pre><code>... | 2021/03/10 | [
"https://vi.stackexchange.com/questions/29574",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19712/"
] | Suppose I have this in a text buffer (`vim --clean mydoc.txt`):
```
One
Two
Three
Four
```
I highlight all lines using `:call matchadd('ErrorMsg', '.*')`, resulting in:
[](https://i.stack.imgur.com/16UvP.png)
Notice that the newline character on each line... | The reason why this happens is that the pattern `'.*'` matches an empty string (with zero width), so it ends up matching the ends of the lines and highlighting those as well.
The match engine (similar to the syntax engine) will highlight a match and start searching for the next match *right where* the last match ended... |
29,584 | <p><sup><a href="https://stackoverflow.com/questions/66585195/how-to-copy-a-vim-macro-to-another-vim-instance-without-clipboard-support-i-e/66586858#66586858">Cross-posting from Stackoverflow</a> because I keep forgetting about this site...</sup></p>
<p>Have a macro where a visually selected text will be made a markdow... | [
{
"answer_id": 29576,
"author": "DC Slagel",
"author_id": 14302,
"author_profile": "https://vi.stackexchange.com/users/14302",
"pm_score": 0,
"selected": false,
"text": "<p>This seems to work, but <del>I'm not confident that it will work in every case..</del> is flawed.</p>\n<pre><code>... | 2021/03/11 | [
"https://vi.stackexchange.com/questions/29584",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7706/"
] | [Cross-posting from Stackoverflow](https://stackoverflow.com/questions/66585195/how-to-copy-a-vim-macro-to-another-vim-instance-without-clipboard-support-i-e/66586858#66586858) because I keep forgetting about this site...
Have a macro where a visually selected text will be made a markdown link and once the macro execu... | The reason why this happens is that the pattern `'.*'` matches an empty string (with zero width), so it ends up matching the ends of the lines and highlighting those as well.
The match engine (similar to the syntax engine) will highlight a match and start searching for the next match *right where* the last match ended... |
29,595 | <p>I have a list of strings which is interesting in its own right, but I also want a filtered version of it for other purposes. But I discovered to my horror that <code>filter</code>, in addition to returning a filtered version of the list passed in, also changes the list passed in. Even copying it over apparently does... | [
{
"answer_id": 29597,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>The help is always your friend: <a href=\"http://vimhelp.appspot.com/eval.txt.html#filter%28%29\" rel=\"nofollow norefer... | 2021/03/12 | [
"https://vi.stackexchange.com/questions/29595",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/18875/"
] | I have a list of strings which is interesting in its own right, but I also want a filtered version of it for other purposes. But I discovered to my horror that `filter`, in addition to returning a filtered version of the list passed in, also changes the list passed in. Even copying it over apparently doesn't work. Try ... | You just need to copy your List properly.
Think of a List variable like `l` as a *reference* to the List object that has been assigned to it. (IOW, it contains the the memory address of the assigned List not the List itself.)
When you do...
```
let m=l
```
All you've done is assign the reference to another variabl... |
29,605 | <p>I'm trying to use base16-vim for a light color scheme. I want to use "one-light", but it seems that none of the light schemes work. After starting Vim with a light scheme, <code>:colo</code> reports default scheme. When I do the same after switching to a dark scheme, the correct one is reported.</p>
<p>I d... | [
{
"answer_id": 29597,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>The help is always your friend: <a href=\"http://vimhelp.appspot.com/eval.txt.html#filter%28%29\" rel=\"nofollow norefer... | 2021/03/12 | [
"https://vi.stackexchange.com/questions/29605",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/34007/"
] | I'm trying to use base16-vim for a light color scheme. I want to use "one-light", but it seems that none of the light schemes work. After starting Vim with a light scheme, `:colo` reports default scheme. When I do the same after switching to a dark scheme, the correct one is reported.
I debugged the startup with `vim ... | You just need to copy your List properly.
Think of a List variable like `l` as a *reference* to the List object that has been assigned to it. (IOW, it contains the the memory address of the assigned List not the List itself.)
When you do...
```
let m=l
```
All you've done is assign the reference to another variabl... |
29,643 | <p>I have the <code>file1.txt</code> with this content</p>
<pre><code>Once upon a time, there was a girl named Persephone.
She had black hair.
She loved her mother more than anything.
She liked to sit outside in the sunshine with her cat, Daisy.
She dreamed of being a painter when she grew up.
</code></pre>
<p>And the ... | [
{
"answer_id": 29644,
"author": "hobbs",
"author_id": 2658,
"author_profile": "https://vi.stackexchange.com/users/2658",
"pm_score": 2,
"selected": false,
"text": "<p>You could do something like <code>vimdiff file1.txt <( patch -s -o - file1.txt file_unified.patch )</code> (assuming y... | 2021/03/16 | [
"https://vi.stackexchange.com/questions/29643",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/34069/"
] | I have the `file1.txt` with this content
```
Once upon a time, there was a girl named Persephone.
She had black hair.
She loved her mother more than anything.
She liked to sit outside in the sunshine with her cat, Daisy.
She dreamed of being a painter when she grew up.
```
And the `file2.txt` with this content
```
... | You could do something like `vimdiff file1.txt <( patch -s -o - file1.txt file_unified.patch )` (assuming your shell is bash and your diff is GNU). The `patch` command applies the patch to the original file and sends the output to stdout, and the `<( ... )` redirection captures that output and provides a filename that ... |
29,660 | <p>I'm trying to create a function that implements the functionality outlined here: <a href="https://vi.stackexchange.com/questions/2776/vim-search-replace-all-files-in-current-project-folder">Vim search replace all files in current (project) folder</a></p>
<p>My current attempt:</p>
<pre><code>nnoremap <C-F> :ca... | [
{
"answer_id": 29662,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>If you replace <code>execute</code> by <code>echo</code> in your function you'll see that the executed command is</p>\n<... | 2021/03/18 | [
"https://vi.stackexchange.com/questions/29660",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30120/"
] | I'm trying to create a function that implements the functionality outlined here: [Vim search replace all files in current (project) folder](https://vi.stackexchange.com/questions/2776/vim-search-replace-all-files-in-current-project-folder)
My current attempt:
```
nnoremap <C-F> :call ReplaceAcrossAllFiles(
function! ... | ```
nnoremap <S-F> :vimgrep //gj **/* <bar> copen<C-B><Right><Right><Right><Right><Right><Right><Right><Right><Right>
nnoremap <C-F> :call ReplaceAcrossAllFiles(
function! ReplaceAcrossAllFiles(search, replace)
silent! execute "vimgrep /" . a:search . "/gj **/* | copen"
silent! execute "cfdo %s/" . a:search . "/" ... |
29,726 | <p>There are probably 20 better ways to do what I'm trying to do. Please direct me to them if so - I haven't found them and not quite sure what to terms to search.</p>
<p>I would prefer to set background=dark or background=light depending on what my system theme is, but I haven't been able to figure that out and got ti... | [
{
"answer_id": 29690,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 3,
"selected": true,
"text": "<p>Generally speaking, if no efficient native solution is available that's when mappings ride in to save the day.</p>\n<p... | 2021/03/22 | [
"https://vi.stackexchange.com/questions/29726",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29304/"
] | There are probably 20 better ways to do what I'm trying to do. Please direct me to them if so - I haven't found them and not quite sure what to terms to search.
I would prefer to set background=dark or background=light depending on what my system theme is, but I haven't been able to figure that out and got tired of tr... | Generally speaking, if no efficient native solution is available that's when mappings ride in to save the day.
But you may like the efficiency of this for word swap: `df<space>wP`. I know that rolls off my fingers quite easily. (`dawwP` also works but the first four characters are all typed with the left hand which is... |
30,777 | <p>My vimrc file is hosted on github. I update it once in a while, and use it on many different computers.</p>
<p>Is it possible to make vim asynchronously check the github repo for a new version of the vimrc file at startup?</p>
<p>I've seen something similar being done by the <a href="https://github.com/neoclide/coc.... | [
{
"answer_id": 30792,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>Here's a simple version, assuming fugitive or dispatch are installed:</p>\n<pre><code>augroup update_vimrc\n a... | 2021/03/27 | [
"https://vi.stackexchange.com/questions/30777",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32517/"
] | My vimrc file is hosted on github. I update it once in a while, and use it on many different computers.
Is it possible to make vim asynchronously check the github repo for a new version of the vimrc file at startup?
I've seen something similar being done by the [coc](https://github.com/neoclide/coc.nvim) plugin, wher... | Here's a simple version, assuming fugitive or dispatch are installed:
```
augroup update_vimrc
autocmd!
" for dispatch, automatically async
" use a ! or other dispatch commands for more control
autocmd VimEnter Dispatch git -C ~/dotfiles pull
" or for fugitive, not so async
autocmd VimEnter Git -C ~/dotfil... |
30,787 | <p>My distribution comes with a minimal version of Vim. <code>vim --version</code> returns
<code>-clipboard</code>, so the <code>*</code> and <code>+</code> registers interact (copy/paste) with the
primary and clipboard do not work.</p>
<p>The resources I've found suggest installing Gvim to solve that, e.g.
<code>vim-a... | [
{
"answer_id": 30788,
"author": "Quasímodo",
"author_id": 30440,
"author_profile": "https://vi.stackexchange.com/users/30440",
"pm_score": 2,
"selected": false,
"text": "<p>Building Vim from the source with the right flags is the general solution.</p>\n<pre><code>git clone https://github... | 2021/03/29 | [
"https://vi.stackexchange.com/questions/30787",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30440/"
] | My distribution comes with a minimal version of Vim. `vim --version` returns
`-clipboard`, so the `*` and `+` registers interact (copy/paste) with the
primary and clipboard do not work.
The resources I've found suggest installing Gvim to solve that, e.g.
`vim-athena` or `vim-gtk3` packages in Debian, but I will never ... | Building Vim from the source with the right flags is the general solution.
```
git clone https://github.com/vim/vim.git
cd vim/src
./configure --with-x=yes --disable-gui
```
The last command will probably raise an error message, which means
you need to install dependencies. Experienced users know how to proceed, but... |
30,795 | <p>I’m trying to yank a range into a register while ignoring blank lines. My range is from line 10 to the end of the file.</p>
<pre><code>:10,$v/./"*y
</code></pre>
<p>Looking at my registers in <code>:reg</code> I see that my text is not in the register I specified or any other register. However vim has highlight... | [
{
"answer_id": 30797,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 3,
"selected": true,
"text": "<p>There are problems with your <code>:vglobal</code> command and problems with your <code>:y[ank]</code>.</p>\n<p>First,... | 2021/03/29 | [
"https://vi.stackexchange.com/questions/30795",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5049/"
] | I’m trying to yank a range into a register while ignoring blank lines. My range is from line 10 to the end of the file.
```
:10,$v/./"*y
```
Looking at my registers in `:reg` I see that my text is not in the register I specified or any other register. However vim has highlighted all lines not containing a blank line... | There are problems with your `:vglobal` command and problems with your `:y[ank]`.
First, `:v` runs against lines that *aren't matched* by your pattern. You are skipping all lines with at least one character.
Second, `:g` and `:v` work by running the following command *for each line that they match/don't match*. That ... |
30,798 | <p>I want to create a <code>{}</code> completion myself, and I did:</p>
<pre><code>inoremap <CR> if_open_curly_on_left()? <CR>}<ESC>O : <CR>
function! s:if_open_curly_on_left() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '{'
endfunction
</code></pre>
<p>which i... | [
{
"answer_id": 30797,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 3,
"selected": true,
"text": "<p>There are problems with your <code>:vglobal</code> command and problems with your <code>:y[ank]</code>.</p>\n<p>First,... | 2021/03/29 | [
"https://vi.stackexchange.com/questions/30798",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10189/"
] | I want to create a `{}` completion myself, and I did:
```
inoremap <CR> if_open_curly_on_left()? <CR>}<ESC>O : <CR>
function! s:if_open_curly_on_left() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '{'
endfunction
```
which is modified by other's code, since I don't really understand... | There are problems with your `:vglobal` command and problems with your `:y[ank]`.
First, `:v` runs against lines that *aren't matched* by your pattern. You are skipping all lines with at least one character.
Second, `:g` and `:v` work by running the following command *for each line that they match/don't match*. That ... |
30,803 | <p>I've tried this but it didn't work</p>
<pre><code>function! Reduce(array, oper, accumInit) abort
let l:accum = a:accumInit
for l:item in a:array
let l:accum = a:oper(l:accum, l:item)
endfor
return l:accum
endfunction
function! FooBar() abort
let g:foobar = Reduce(['pit', 'joh', 'dik'], {ac, el -> ... | [
{
"answer_id": 30797,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 3,
"selected": true,
"text": "<p>There are problems with your <code>:vglobal</code> command and problems with your <code>:y[ank]</code>.</p>\n<p>First,... | 2021/03/30 | [
"https://vi.stackexchange.com/questions/30803",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26473/"
] | I've tried this but it didn't work
```
function! Reduce(array, oper, accumInit) abort
let l:accum = a:accumInit
for l:item in a:array
let l:accum = a:oper(l:accum, l:item)
endfor
return l:accum
endfunction
function! FooBar() abort
let g:foobar = Reduce(['pit', 'joh', 'dik'], {ac, el -> extend(ac, {[el]... | There are problems with your `:vglobal` command and problems with your `:y[ank]`.
First, `:v` runs against lines that *aren't matched* by your pattern. You are skipping all lines with at least one character.
Second, `:g` and `:v` work by running the following command *for each line that they match/don't match*. That ... |
30,816 | <p><code>mode()</code> won't return anything when I go into Command mode. I use this for StatusLine info:</p>
<pre><code>set statusline+=%{mode()} as a test to see what mode() returns.
</code></pre>
<p>pressing <code>c</code> or <code>C</code> and my StatusLine stays as <code>NORMAL</code>. Is this a bug or am I doing ... | [
{
"answer_id": 30817,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<p>The stuff is known to work in Neovim, but not in Vim, because Vim is too lazy when updating screen, as @Mass correctly n... | 2021/03/31 | [
"https://vi.stackexchange.com/questions/30816",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/34291/"
] | `mode()` won't return anything when I go into Command mode. I use this for StatusLine info:
```
set statusline+=%{mode()} as a test to see what mode() returns.
```
pressing `c` or `C` and my StatusLine stays as `NORMAL`. Is this a bug or am I doing something wrong? The other modes seem to work normally.
Below is th... | The stuff is known to work in Neovim, but not in Vim, because Vim is too lazy when updating screen, as @Mass correctly noted in the comments.
Personally, I just don't pay attention to this, and keep using my status line plugin without any worries.
But if you are so eager to fix it, you need to force status line redra... |
30,828 | <p>Lets say for example, I have 3 files opened in split windows in vim. And I have to changes the access permissions to each of them, then one way to do it, is to move my cursor to individual split window & execute <code>:!chmod 777 %</code>
The problem here is that I have to do execute this command 'n' number of t... | [
{
"answer_id": 30830,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>If you want to do that specifically for all split windows then <code>windo</code> is what you are looking for <a href=\"... | 2021/04/01 | [
"https://vi.stackexchange.com/questions/30828",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | Lets say for example, I have 3 files opened in split windows in vim. And I have to changes the access permissions to each of them, then one way to do it, is to move my cursor to individual split window & execute `:!chmod 777 %`
The problem here is that I have to do execute this command 'n' number of times, for 'n' numb... | If you want to do that specifically for all split windows then `windo` is what you are looking for [`:h :windo`](http://vimhelp.appspot.com/windows.txt.html#%3Awindo)
```
:[range]windo {cmd} Execute {cmd} in each window or if [range] is given
only in windows for which the window number lies in
... |
30,829 | <p>I often use the <code><C-w>_</code> and <code><C-w>|</code> commands in Vim to maximize the current pane to fill the entire window (I have it keymapped to <code><C-w>0</code>).</p>
<p>And I've recently started using a tiling window manager, which means I sometimes find myself "moving" ter... | [
{
"answer_id": 30832,
"author": "ritchie",
"author_id": 32923,
"author_profile": "https://vi.stackexchange.com/users/32923",
"pm_score": 0,
"selected": false,
"text": "<p>I can't build you a plugin but I can give you some ideas. You want to look into <code>columns</code> you're going to ... | 2021/04/01 | [
"https://vi.stackexchange.com/questions/30829",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14813/"
] | I often use the `<C-w>_` and `<C-w>|` commands in Vim to maximize the current pane to fill the entire window (I have it keymapped to `<C-w>0`).
And I've recently started using a tiling window manager, which means I sometimes find myself "moving" terminals into smaller or larger sections of the screen.
What happens is... | You could set a global variable (`g:zoom_status`) to remember whether you are meant to be zoomed in (maximised) or not. Then, every time the terminal is resized restore the windows to that status.
For example, to map `[leader]``0` (where `[leader]` defaults to `\`) to toggle between zoomed in state (window maximised) ... |