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 |
|---|---|---|---|---|---|---|
24,757 | <p>I'm using vim to code C++ and I want to handle the parenthesis more easily.</p>
<p>I knew that there was a plugin named <a href="https://www.vim.org/scripts/script.php?script_id=1697" rel="nofollow noreferrer">Surround</a>, which can help us but it is not what I expected.</p>
<p>I set some shortcuts as below:</p>
... | [
{
"answer_id": 24758,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 3,
"selected": true,
"text": "<p>It is possible. There are plugins like <a href=\"https://github.com/cohama/lexima.vim\" rel=\"nofollow noreferrer\">Lexima</a>... | 2020/04/22 | [
"https://vi.stackexchange.com/questions/24757",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10003/"
] | I'm using vim to code C++ and I want to handle the parenthesis more easily.
I knew that there was a plugin named [Surround](https://www.vim.org/scripts/script.php?script_id=1697), which can help us but it is not what I expected.
I set some shortcuts as below:
```
inoremap " ""<left>
inoremap ' ''<left>
inoremap ( ()... | It is possible. There are plugins like [Lexima](https://github.com/cohama/lexima.vim), [auto-pairs](https://github.com/jiangmiao/auto-pairs) and others that handle deletion, but handling pairs of characters doesn't seem to be easy to solve in insert mode: I've used both and there's always a corner case that doesn't giv... |
24,762 | <p>In Vim, using the text object <code>i></code>, you can edit an inner tag, and using the built-in matchit plugin, you can even use <code>%</code> to jump between matching opening and closing tags. </p>
<p>Let's say you want to change matching <code>div</code> tags to something else, such as <code>section</code>. ... | [
{
"answer_id": 24758,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 3,
"selected": true,
"text": "<p>It is possible. There are plugins like <a href=\"https://github.com/cohama/lexima.vim\" rel=\"nofollow noreferrer\">Lexima</a>... | 2020/04/22 | [
"https://vi.stackexchange.com/questions/24762",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29117/"
] | In Vim, using the text object `i>`, you can edit an inner tag, and using the built-in matchit plugin, you can even use `%` to jump between matching opening and closing tags.
Let's say you want to change matching `div` tags to something else, such as `section`. One way to go about it would be to get to the opening tag... | It is possible. There are plugins like [Lexima](https://github.com/cohama/lexima.vim), [auto-pairs](https://github.com/jiangmiao/auto-pairs) and others that handle deletion, but handling pairs of characters doesn't seem to be easy to solve in insert mode: I've used both and there's always a corner case that doesn't giv... |
24,783 | <pre><code> execute "normal! :echo ". system('echo hello')
</code></pre>
<p>The above results in:</p>
<pre><code>E121: Undefined variable: hello
</code></pre>
<p>Why? I'm expecting it to evaluate as:</p>
<pre><code> execute "normal! :echo hello"
</code></pre>
| [
{
"answer_id": 24786,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 2,
"selected": false,
"text": "<p>The bug is not in the first command, but in the second.</p>\n\n<p>If you just run the Ex command directly, you get... | 2020/04/22 | [
"https://vi.stackexchange.com/questions/24783",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13656/"
] | ```
execute "normal! :echo ". system('echo hello')
```
The above results in:
```
E121: Undefined variable: hello
```
Why? I'm expecting it to evaluate as:
```
execute "normal! :echo hello"
``` | There are a couple of problems here.
First of all, you want to run an ex command, so you don't need the `:norm!` command to execute an **ex** command. A simple `:echo` works.
(In fact, you can and probably should get rid of the `:exe` command and use `:echo` directly, but I'll come back to this later).
Second, if y... |
24,790 | <p>Is it possible for vim navigation to be as quick as a normal point-and-click navigation? For example, I've taken the following example here where I've created four points that need to be clicked:</p>
<p><a href="https://i.stack.imgur.com/gLkBq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gLkBq... | [
{
"answer_id": 24803,
"author": "Zorzi",
"author_id": 27331,
"author_profile": "https://vi.stackexchange.com/users/27331",
"pm_score": 1,
"selected": false,
"text": "<p>Here's what i did to reach the 4 points:</p>\n\n<p>Given I start from the 1st point,</p>\n\n<ul>\n<li><p><code>/Coll<... | 2020/04/23 | [
"https://vi.stackexchange.com/questions/24790",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | Is it possible for vim navigation to be as quick as a normal point-and-click navigation? For example, I've taken the following example here where I've created four points that need to be clicked:
[](https://i.stack.imgur.com/gLkBq.png)
Without any pr... | I'd like to primarily challenge the premise of your question/challenge/race:
>
> What would be the fastest that someone could get to those four locations in vim?
>
>
>
When you're editing text, you're not only moving to specific locations on the text, you're moving to those points and *adding or modifying text t... |
24,791 | <p>I'm trying to create an abbreviation with the command <code>ab</code>:</p>
<p>if I type <code>if (</code> under INSERT mode, I want some piece of code to be printed immediately.</p>
<p>Here is what I've tried:</p>
<pre><code>ab if<Space>( if<Space>()<Space>{<CR>}
</code></pre>
<p>But I al... | [
{
"answer_id": 24803,
"author": "Zorzi",
"author_id": 27331,
"author_profile": "https://vi.stackexchange.com/users/27331",
"pm_score": 1,
"selected": false,
"text": "<p>Here's what i did to reach the 4 points:</p>\n\n<p>Given I start from the 1st point,</p>\n\n<ul>\n<li><p><code>/Coll<... | 2020/04/23 | [
"https://vi.stackexchange.com/questions/24791",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10003/"
] | I'm trying to create an abbreviation with the command `ab`:
if I type `if (` under INSERT mode, I want some piece of code to be printed immediately.
Here is what I've tried:
```
ab if<Space>( if<Space>()<Space>{<CR>}
```
But I always get an error: `E474: Invalid argument`. It seems that `<Space>` causes some error... | I'd like to primarily challenge the premise of your question/challenge/race:
>
> What would be the fastest that someone could get to those four locations in vim?
>
>
>
When you're editing text, you're not only moving to specific locations on the text, you're moving to those points and *adding or modifying text t... |
24,794 | <p>I like the simple auto completion provided by <kbd>Ctrl</kbd>-<kbd>N</kbd> but not typing <kbd>Ctrl</kbd>-<kbd>N</kbd> everytime to get the completion.</p>
<p>I would like it to work similar to how <a href="https://github.com/ycm-core/YouCompleteMe" rel="nofollow noreferrer">YouCompleteMe</a> works with automatic s... | [
{
"answer_id": 24797,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>Take a look at the <a href=\"https://github.com/othree/vim-autocomplpop\" rel=\"nofollow noreferrer\">vim-autocompl... | 2020/04/23 | [
"https://vi.stackexchange.com/questions/24794",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29130/"
] | I like the simple auto completion provided by `Ctrl`-`N` but not typing `Ctrl`-`N` everytime to get the completion.
I would like it to work similar to how [YouCompleteMe](https://github.com/ycm-core/YouCompleteMe) works with automatic suggestions. If possible, I would also like to cycle through the completion menu wit... | Take a look at the [vim-autocomplpop](https://github.com/othree/vim-autocomplpop) plug-in, which triggers the completion menu automatically as you type.
For using "Tab" instead of Ctrl+N **in** the completion menu, you can use a simple mapping such as:
```
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
```... |
24,806 | <p>I'm using vim 8 and I set a shortcut to open a terminal in my vim.</p>
<pre><code>nnoremap <F5> :wa<CR> \| :term ++kill=term<CR>
</code></pre>
<p>It works except that it opens a terminal vertically as below:</p>
<pre><code>--------------------
| |some file|
|nerdtree|----------
| |... | [
{
"answer_id": 24807,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 4,
"selected": true,
"text": "<p>Use the <a href=\"https://vimhelp.org/windows.txt.html#%3Avertical\" rel=\"noreferrer\"><code>:vertical</code></a> ... | 2020/04/23 | [
"https://vi.stackexchange.com/questions/24806",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10003/"
] | I'm using vim 8 and I set a shortcut to open a terminal in my vim.
```
nnoremap <F5> :wa<CR> \| :term ++kill=term<CR>
```
It works except that it opens a terminal vertically as below:
```
--------------------
| |some file|
|nerdtree|----------
| |terminal |
--------------------
```
What I need is to... | Use the [`:vertical`](https://vimhelp.org/windows.txt.html#%3Avertical) and [`:botright`](https://vimhelp.org/windows.txt.html#%3Abotright) modifiers.
```
nnoremap <F5> :wa \| **vertical botright** term ++kill=term<CR>
```
Or:
```
nnoremap <F5> :wa<CR>**:vertical botright** term ++kill=term<CR>
```
(Also note t... |
24,819 | <p>To clear a file I find myself doing something like:</p>
<ul>
<li>1G</li>
<li>1000cc (or some large number)</li>
</ul>
<p>Is there a simpler way to do this for clearing a file? On a normal text editor I normally would do <code>Cmd-A</code> and then start typing.</p>
| [
{
"answer_id": 24821,
"author": "williamvds",
"author_id": 29152,
"author_profile": "https://vi.stackexchange.com/users/29152",
"pm_score": 3,
"selected": true,
"text": "<p><code>ggdG</code></p>\n\n<p><code>gg</code>: Move to the first line in the file</p>\n\n<p><code>d</code>: Delete</p... | 2020/04/23 | [
"https://vi.stackexchange.com/questions/24819",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | To clear a file I find myself doing something like:
* 1G
* 1000cc (or some large number)
Is there a simpler way to do this for clearing a file? On a normal text editor I normally would do `Cmd-A` and then start typing. | `ggdG`
`gg`: Move to the first line in the file
`d`: Delete
`G`: [until] last line in file
From help:
```
G Goto line [count], default last line, on the first
non-blank character linewise. If 'startofline' not
set, keep the same column.
G is one of the jump-motions.
.... |
24,820 | <p>I want to have predefined register that will jump to the location matched by regular expression, i.e. in <code>vimrc</code> I add:</p>
<pre><code>let @a="/=\""
</code></pre>
<p>That will be useful for me when I want to navigate to the next entry point in HTML tag, such as <code>class=""</code> or <code>method=""</... | [
{
"answer_id": 24823,
"author": "Zorzi",
"author_id": 27331,
"author_profile": "https://vi.stackexchange.com/users/27331",
"pm_score": 0,
"selected": false,
"text": "<p>I think you're mistaking <code>buffers</code>, <code>registers</code> and <code>macros</code></p>\n\n<p>The <code>@a</c... | 2020/04/23 | [
"https://vi.stackexchange.com/questions/24820",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25325/"
] | I want to have predefined register that will jump to the location matched by regular expression, i.e. in `vimrc` I add:
```
let @a="/=\""
```
That will be useful for me when I want to navigate to the next entry point in HTML tag, such as `class=""` or `method=""`. But when I test it I see the command appears at the ... | TL;DR: You need either this:
```
let @a = "/=\"\n"
```
Or this:
```
call setreg('a', "/=\"\<Return>", 'c')
```
---
There are a few ways to enter a `<Return>` character in a double-quoted string. See [`:help expr-quote`](https://vimhelp.org/eval.txt.html#expr-quote) for details.
First, you can use the `\<Return>... |
24,834 | <p>I'm having a hard time writing regexes in vim -- it seems everything I try either requires an escape character or isn't supported. For example, I have a SQL statement that includes something like:</p>
<pre><code>max(if(s.name like 'iTunes' and completion_date is not null, 'Complete', if(s.name like 'iTunes', 'X', n... | [
{
"answer_id": 24835,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 2,
"selected": false,
"text": "<p>Yeah, the Vim flavor of regex is a bit different from what you'll find in languages such as Python or Perl.</p>\n\... | 2020/04/24 | [
"https://vi.stackexchange.com/questions/24834",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | I'm having a hard time writing regexes in vim -- it seems everything I try either requires an escape character or isn't supported. For example, I have a SQL statement that includes something like:
```
max(if(s.name like 'iTunes' and completion_date is not null, 'Complete', if(s.name like 'iTunes', 'X', null))) iTunes,... | Yeah, the Vim flavor of regex is a bit different from what you'll find in languages such as Python or Perl.
In particular, you need to escape the sets of parens that mark a group. Also, the `+` to repeat one or more.
But `[a-z]` itself works as expected. (Not that there's anything wrong with `\a`, which is in many se... |
24,894 | <p>I can open and split multiple file like this</p>
<pre><code>:split file1
:split file2
:split file3
</code></pre>
<p>But is there any way to open multiple files in a single command? Something like this</p>
<pre><code>:split file1 file2 file3
</code></pre>
| [
{
"answer_id": 24900,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 3,
"selected": true,
"text": "<p>This isn't possible with the default <code>:split</code> command; you'll have to use a custom command such as <code>... | 2020/04/25 | [
"https://vi.stackexchange.com/questions/24894",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29180/"
] | I can open and split multiple file like this
```
:split file1
:split file2
:split file3
```
But is there any way to open multiple files in a single command? Something like this
```
:split file1 file2 file3
``` | This isn't possible with the default `:split` command; you'll have to use a custom command such as `:Split` (capital S) which loops over all the commandline arguments and calls `:split`:
```
:command! -nargs=+ -complete=file Split
\ for s:f in [<f-args>]
\| exe 'split' fnameescape(s:f)
... |
24,912 | <p>I want to join all the lines within a <code>{}</code> block.</p>
<pre><code>{
'a': 1,
'b': 2,
'c': 3,
}
</code></pre>
<p>⬇︎</p>
<pre><code>{ 'a': 1, 'b': 2, 'c': 3, }
</code></pre>
<p>Since <code>J</code> doesn't take a range, like <code>d</code> or <code>c</code>, the best command I found to do this is go... | [
{
"answer_id": 24913,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 3,
"selected": false,
"text": "<p>This is called \"a motion\". Even though linewise motions result in a line range.</p>\n\n<p>Normally, it's enough to do ... | 2020/04/27 | [
"https://vi.stackexchange.com/questions/24912",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2526/"
] | I want to join all the lines within a `{}` block.
```
{
'a': 1,
'b': 2,
'c': 3,
}
```
⬇︎
```
{ 'a': 1, 'b': 2, 'c': 3, }
```
Since `J` doesn't take a range, like `d` or `c`, the best command I found to do this is going through virtual mode: `Va{J`.
Is there a nicer way to do the same?
---
This is not a d... | This is called "a motion". Even though linewise motions result in a line range.
Normally, it's enough to do `5J` and there's no need for "join" operator. However, if you really want it, you can make use of `:h g@` and `:h 'opfunc'` A simplified example:
```
" very basic "join" operator
nnoremap <silent>J :set opfunc=... |
24,921 | <p>I have fuzzy file finder (FZF) set up and working:</p>
<p><a href="https://i.stack.imgur.com/YLUvC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YLUvC.png" alt="enter image description here"></a></p>
<p>And when I do <code>:History</code> it also shows a preview of the file:</p>
<p><a href="h... | [
{
"answer_id": 24913,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 3,
"selected": false,
"text": "<p>This is called \"a motion\". Even though linewise motions result in a line range.</p>\n\n<p>Normally, it's enough to do ... | 2020/04/28 | [
"https://vi.stackexchange.com/questions/24921",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | I have fuzzy file finder (FZF) set up and working:
[](https://i.stack.imgur.com/YLUvC.png)
And when I do `:History` it also shows a preview of the file:
[](https://i.stack.imgur.com... | This is called "a motion". Even though linewise motions result in a line range.
Normally, it's enough to do `5J` and there's no need for "join" operator. However, if you really want it, you can make use of `:h g@` and `:h 'opfunc'` A simplified example:
```
" very basic "join" operator
nnoremap <silent>J :set opfunc=... |
24,925 | <p>I was trying to set a timeout length to apply to:</p>
<ul>
<li>Key combination presses (for example, pressing <code>gh</code> in netrw); and</li>
<li>Exiting modes (for example, zero delay when exiting visual mode).</li>
</ul>
<p>Here is a portion of what the docs say in <code>:h timeoutlen</code> as an example:</... | [
{
"answer_id": 24930,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 2,
"selected": false,
"text": "<p>The timeouts are applicable when you have entered a key and its ambiguous whether a mapping will come next or if ther... | 2020/04/28 | [
"https://vi.stackexchange.com/questions/24925",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | I was trying to set a timeout length to apply to:
* Key combination presses (for example, pressing `gh` in netrw); and
* Exiting modes (for example, zero delay when exiting visual mode).
Here is a portion of what the docs say in `:h timeoutlen` as an example:
>
>
> ```
> :set timeout timeoutlen=3000 ttimeoutlen... | `timeout` and `timeoutlen` apply to **mappings**, such as netrw's `gh`.
These are pretty straightforward: if you increase the length of `timeoutlen`, then Vim will wait for longer after each keystroke of the mapping before aborting it and carrying out the behaviour of the keys typed so far. If you instead unset `timeo... |
24,927 | <p>Often I am in some 'general' directory when I open files, such as <code>~</code> or <code>Desktop</code>. <code>FZF</code> by default opens the user's <code>pwd</code>, for example, if I have:</p>
<pre><code>Desktop $ vim ~/.vim/vimrc
</code></pre>
<p>And I do:</p>
<pre><code>:FZF
</code></pre>
<p>It will search... | [
{
"answer_id": 24931,
"author": "Michael Kohl",
"author_id": 29255,
"author_profile": "https://vi.stackexchange.com/users/29255",
"pm_score": 4,
"selected": true,
"text": "<p>You can use <code>:Files [PATH]</code> for this. See the <a href=\"https://github.com/junegunn/fzf.vim#commands\"... | 2020/04/28 | [
"https://vi.stackexchange.com/questions/24927",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | Often I am in some 'general' directory when I open files, such as `~` or `Desktop`. `FZF` by default opens the user's `pwd`, for example, if I have:
```
Desktop $ vim ~/.vim/vimrc
```
And I do:
```
:FZF
```
It will search in `Desktop` by default. How can I pass a parameter equivalent to:
```
:FZF dir(current_fil... | You can use `:Files [PATH]` for this. See the [command reference](https://github.com/junegunn/fzf.vim#commands).
To pass in the directory: `:Files %:p:h`
Alternatively, you can also use `lcd` to change the directory for the current window, then use FZF as normal. |
24,946 | <p>When I'm in the GUI, I like to have a large-ish vim window: 161 columns, so I can <code>:vsplit</code> it into two 80 column windows (with 1 extra column for the gutter.) This works perfectly fine if I do it by hand, but if I try to <code>:vsplit</code> in my <code>.vimrc</code>, I get a 40 column window and a 120 c... | [
{
"answer_id": 24952,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>I don't know exactly what causes this, but I would try the following workarounds if it's important to you to se... | 2020/04/28 | [
"https://vi.stackexchange.com/questions/24946",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29272/"
] | When I'm in the GUI, I like to have a large-ish vim window: 161 columns, so I can `:vsplit` it into two 80 column windows (with 1 extra column for the gutter.) This works perfectly fine if I do it by hand, but if I try to `:vsplit` in my `.vimrc`, I get a 40 column window and a 120 column window.
The appropriate part ... | I guess that `set columns=161` does not take effect immediately. Maybe not until Vim displays a window, which according to `:h startup` happens after the vimrc is read. The latter is processed in the third step of the documentation, while the windows are still not displayed in the 11th step:
>
> 11. Open all windows
... |
24,948 | <p>If I am editing a command, for example:</p>
<pre><code>:set paste
</code></pre>
<p>And my cursor is between the <code>p</code> and <code>a</code>:</p>
<pre><code>:set pa|ste
</code></pre>
<p>I can go to the end of the command text by doing <code>ctrl-e</code>. However it doesn't seem like <code>ctrl-a</code> wor... | [
{
"answer_id": 24950,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 2,
"selected": false,
"text": "<p>By default, Vim command line uses <code>Ctrl-B</code> to go to the beginning of the line. Execute <code>:h cmdline-editing</c... | 2020/04/28 | [
"https://vi.stackexchange.com/questions/24948",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | If I am editing a command, for example:
```
:set paste
```
And my cursor is between the `p` and `a`:
```
:set pa|ste
```
I can go to the end of the command text by doing `ctrl-e`. However it doesn't seem like `ctrl-a` works to go to the start of the text. Is there a shortcut that I can use to go to the start of a... | You can set command line mappings with `cmap`.
In your case:
```
cnoremap <c-a> <Home>
``` |
24,956 | <p>In Textmate I can do something like when I have the following:</p>
<pre><code><div>
<p>new
</code></pre>
<p>If I press <kbd>opt</kbd><kbd>shift</kbd><kbd>.</kbd> it will add in the matching tag. So when I press it once, it will look like:</p>
<pre><code><div>
<p>new</p>
</cod... | [
{
"answer_id": 24950,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 2,
"selected": false,
"text": "<p>By default, Vim command line uses <code>Ctrl-B</code> to go to the beginning of the line. Execute <code>:h cmdline-editing</c... | 2020/04/29 | [
"https://vi.stackexchange.com/questions/24956",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | In Textmate I can do something like when I have the following:
```
<div>
<p>new
```
If I press `opt``shift``.` it will add in the matching tag. So when I press it once, it will look like:
```
<div>
<p>new</p>
```
If I press it a second time:
```
<div>
<p>new</p></div>
```
And if I press it a third ... | You can set command line mappings with `cmap`.
In your case:
```
cnoremap <c-a> <Home>
``` |
24,962 | <p>I seem to be using a hack approach to getting to the start of an html tag. For example:</p>
<p><a href="https://i.stack.imgur.com/rhglC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rhglC.png" alt="enter image description here"></a></p>
<p>To get to my cursor to be on the <code>t</code> after ... | [
{
"answer_id": 24966,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 2,
"selected": false,
"text": "<p>You can use the optional plugin <code>:h matchit</code> , it's an extension for the built in <code>:h %</code> .</p>\n... | 2020/04/29 | [
"https://vi.stackexchange.com/questions/24962",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | I seem to be using a hack approach to getting to the start of an html tag. For example:
[](https://i.stack.imgur.com/rhglC.png)
To get to my cursor to be on the `t` after the tag, I end up doing `yit` -- this yanks the component (which I don't care a... | Although vim provides text objects for tags, it doesn't have motions for tags.
One options is to reuse `it` to create a pair of maps `[t` and `]t` somewhat analogous to `[b`:
```
nnoremap [t vit<esc>`<
nnoremap ]t vit<esc>`>
```
These both work by temporarily visually selecting the inner tag and then moving to the s... |
24,977 | <p>Is there a way to perform a simultaneous find and replace?</p>
<p>e.g.: I want to replace all <code>1</code> for <code>0</code> and simultaneously all <code>0</code> to <code>1</code></p>
<pre><code>[
[1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 0, 1],
[1, 1, 1, 0, 1, 1],
[1, 1, 0, 1, 1, 1],
[1, 0, 1, 1, 1... | [
{
"answer_id": 24978,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 3,
"selected": false,
"text": "<p>In your specific use case, i think what you can do is this handy oneline:</p>\n\n<pre><code>%s/0\\|1/\\=!submatc... | 2020/04/29 | [
"https://vi.stackexchange.com/questions/24977",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27582/"
] | Is there a way to perform a simultaneous find and replace?
e.g.: I want to replace all `1` for `0` and simultaneously all `0` to `1`
```
[
[1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 0, 1],
[1, 1, 1, 0, 1, 1],
[1, 1, 0, 1, 1, 1],
[1, 0, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 0],
]
``` | Yes, you can do that by using an expression. For this particular case, you can use Vim arithmetic and calculate `1-x`, which will turn 0 into 1 and 1 into 0.
```
:s/\d/\=1-submatch(0)/g
```
For a more general replacement case, you can use a Dict to store the mapping of match to replacement string.
For example, to t... |
24,991 | <p>I am trying to add autocompletion, with suggestions from the currently edited buffer when reading input from the user for a search string:</p>
<pre><code>function! Testinput()
return input("Enter search string: ", 'default', 'syntax')
endfun
call Testinput()
</code></pre>
<p>In the above snippet, <code>syntax<... | [
{
"answer_id": 24996,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 3,
"selected": true,
"text": "<p>\"tags\" is probably the closest built-in, if you want to complete project contents, but you'd need a tags file. There d... | 2020/04/29 | [
"https://vi.stackexchange.com/questions/24991",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27110/"
] | I am trying to add autocompletion, with suggestions from the currently edited buffer when reading input from the user for a search string:
```
function! Testinput()
return input("Enter search string: ", 'default', 'syntax')
endfun
call Testinput()
```
In the above snippet, `syntax` is the `{completion}` argument... | "tags" is probably the closest built-in, if you want to complete project contents, but you'd need a tags file. There doesn't seem to be a method for buffer contents. We can write a custom one:
```
function! CompleteWords(ArgLead, CmdLine, ...)
return getline(1, '$')->join(' ')->split('\s\+')
\ ->filter({_,x-... |
25,008 | <p>For better readability I'd like to split if-statements with multiple expression into multiple lines.
But when executing such a statement via a register vim always complains about it.</p>
<p>This:</p>
<pre><code>if 1==1 && 2==2
echo '1'
endif
</code></pre>
<p>works.</p>
<p>But this:</p>
<pre><code>if 1... | [
{
"answer_id": 25009,
"author": "weirdsmiley",
"author_id": 28840,
"author_profile": "https://vi.stackexchange.com/users/28840",
"pm_score": 2,
"selected": false,
"text": "<p>According to <code>:help E10</code>, <code>:set nocp</code> while editing the <code>if</code> statement will fix ... | 2020/04/30 | [
"https://vi.stackexchange.com/questions/25008",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21417/"
] | For better readability I'd like to split if-statements with multiple expression into multiple lines.
But when executing such a statement via a register vim always complains about it.
This:
```
if 1==1 && 2==2
echo '1'
endif
```
works.
But this:
```
if 1==1
\ && 2==2
echo '1'
endif
```
gives `E10: \ shou... | As it was noted, the problem is that neither `:h :@`, nor `:h execute()` know anything about `:h line-continuation`. Only `:h :source` supports it.
Here is the piece of code taken from my config to deal with this problem.
```
" preprocess VimScript to allow
" :h line-continuation and :h line-continuation-comment
func... |
25,010 | <p>I am using nvim v0.4.3. This is the latest version available in repository. I have an Arch build with the most up to date packages and kernel 5.6.4-arch1-1.</p>
<p>I have the below function in my <code>~/.vimrc</code>: </p>
<pre><code>" function
function! ReSource()
let l:winview = winsaveview()
:s... | [
{
"answer_id": 25012,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>First, <code><cr></code> in the mapping validates the command -- as we do interactively in the command/ex mode... | 2020/04/30 | [
"https://vi.stackexchange.com/questions/25010",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27300/"
] | I am using nvim v0.4.3. This is the latest version available in repository. I have an Arch build with the most up to date packages and kernel 5.6.4-arch1-1.
I have the below function in my `~/.vimrc`:
```
" function
function! ReSource()
let l:winview = winsaveview()
:source ~/.vimrc<cr>
call ... | As @LucHermitte pointed out, the problem causing the E127 error is that you're trying to redefine function `ReSource()` *while* that function is running.
Note that you don't *need* to use a function to save and restore the cursor while sourcing your vimrc, only thing is that you'll end up using a global variable, but ... |
25,021 | <p>I have the following <code>windows.json</code> file</p>
<pre><code>[{
"id":5178,
"pid":40345,
"app":"Alacritty",
"title":"Alacritty",
"frame":{
"w":880.0000,
"h":531.0000
}
},{
"id":5780,
"pid":44378,
"app":"Skim",
"title":"Brezis.pdf",
"frame":{
"... | [
{
"answer_id": 25022,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 4,
"selected": true,
"text": "<p>VimScript has a JSON parser of its own. There's no need to invoke an external utility.</p>\n\n<p>A sample code:</p>\n\n<p... | 2020/05/01 | [
"https://vi.stackexchange.com/questions/25021",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26480/"
] | I have the following `windows.json` file
```
[{
"id":5178,
"pid":40345,
"app":"Alacritty",
"title":"Alacritty",
"frame":{
"w":880.0000,
"h":531.0000
}
},{
"id":5780,
"pid":44378,
"app":"Skim",
"title":"Brezis.pdf",
"frame":{
"w":980.0000,
"h":... | VimScript has a JSON parser of its own. There's no need to invoke an external utility.
A sample code:
```
" read in file
let s:js_data = readfile('windows.json')
" decode into Vim variable
let s:list = js_decode(join(s:js_data))
" filter out the skims
let s:skims = filter(s:list, 'v:val.app=="Skim"')
" do whatever...... |
25,027 | <p>I am using NeoVim v0.4.3.
This is the latest version available in repository.
I have an Arch build with the most up to date packages and kernel 5.6.4-arch1-1.</p>
<p>Occasionally I edit a file with nvim that I don't have permissions to edit.
I only realise this as I am about to save my work.</p>
<p>Recently I edi... | [
{
"answer_id": 25034,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 3,
"selected": false,
"text": "<p><a href=\"https://github.com/lambdalisue/suda.vim\" rel=\"noreferrer\">There’s a plugin for this</a>. The reason the old <cod... | 2020/05/01 | [
"https://vi.stackexchange.com/questions/25027",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27300/"
] | I am using NeoVim v0.4.3.
This is the latest version available in repository.
I have an Arch build with the most up to date packages and kernel 5.6.4-arch1-1.
Occasionally I edit a file with nvim that I don't have permissions to edit.
I only realise this as I am about to save my work.
Recently I edited
```
/etc/pul... | You could try this `:W` command:
```
com -bar W exe 'w !sudo tee >/dev/null %:p:S' | setl nomod
```
Broken down:
```
" ┌ write the buffer on the standard input of a shell command (`:h w_c`)
" │ and execute the latter
" │
" │ ┌ raise the rights of the `tee(1)... |
25,030 | <p>Mentioned here as well: <a href="https://stackoverflow.com/questions/13312794/inotify-dont-treat-vim-editting-as-a-modification-event">https://stackoverflow.com/questions/13312794/inotify-dont-treat-vim-editting-as-a-modification-event</a></p>
<p>Really frustrating issue, how can I force vim to write the file? </p>... | [
{
"answer_id": 25031,
"author": "Chris Stryczynski",
"author_id": 13656,
"author_profile": "https://vi.stackexchange.com/users/13656",
"pm_score": 1,
"selected": true,
"text": "<p>Found a hint to one solution here:</p>\n\n<p><a href=\"https://unix.stackexchange.com/questions/188873/using... | 2020/05/01 | [
"https://vi.stackexchange.com/questions/25030",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13656/"
] | Mentioned here as well: <https://stackoverflow.com/questions/13312794/inotify-dont-treat-vim-editting-as-a-modification-event>
Really frustrating issue, how can I force vim to write the file?
It seems Vim does something strange when writing a file. It does not seem to invoke any of the `[Create, Modify, CloseWrite, ... | Found a hint to one solution here:
<https://unix.stackexchange.com/questions/188873/using-inotifywait-along-with-vim>
```
:set backupcopy=yes
```
Seems there may be some risk with this approach though. |
25,035 | <p>To my <code>.vimrc</code> I added a hook which automates entering the quickfix after <code>:grep</code> processing:</p>
<pre><code>autocmd QuickFixCmdPost [^l]* nested cwindow 20
</code></pre>
<p>Another thing I care about but can't achieve is automation of applying highlight/color of all found occurrences while b... | [
{
"answer_id": 25037,
"author": "run_the_race",
"author_id": 27110,
"author_profile": "https://vi.stackexchange.com/users/27110",
"pm_score": 2,
"selected": false,
"text": "<h2>Option 1 Hack</h2>\n\n<p>A hack... you could get the title of the quickfix window, and then strip off the parts... | 2020/05/01 | [
"https://vi.stackexchange.com/questions/25035",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27523/"
] | To my `.vimrc` I added a hook which automates entering the quickfix after `:grep` processing:
```
autocmd QuickFixCmdPost [^l]* nested cwindow 20
```
Another thing I care about but can't achieve is automation of applying highlight/color of all found occurrences while being in the quickfix. What I observed, it's real... | After experiments I have observed that `matchadd()` proposed by run\_the\_race highlights occurrences only in the quickfix window but not in the window with file buffers which would be even more desirable. We could apply `matchadd()` twice (before `copen` and after) but this method has side-effects while applying to fi... |
25,042 | <p>The task I have in mind is I have grown files containing multiline definitions.
Currently I'm working on a file containing acronyms for latex - many entries like this, but most much more complex:</p>
<pre><code>\DeclareAcronym{AUC}{
short = {AUC},
long = {Area Under Curve},
extra = {long text with \many{macr... | [
{
"answer_id": 25045,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 2,
"selected": false,
"text": "<p>There is no direct functionality for that. (At least non I know of.)</p>\n\n<p><strong>Assuming</strong> that none of th... | 2020/05/02 | [
"https://vi.stackexchange.com/questions/25042",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1120/"
] | The task I have in mind is I have grown files containing multiline definitions.
Currently I'm working on a file containing acronyms for latex - many entries like this, but most much more complex:
```
\DeclareAcronym{AUC}{
short = {AUC},
long = {Area Under Curve},
extra = {long text with \many{macros} and $math$... | Peter Rincker's SortGroup is the go-to script for this kind of work.
<https://gist.github.com/PeterRincker/582ea9be24a69e6dd8e237eb877b8978>
Somewhat differently to vim's `:sort`, it takes a pattern which is supposed to match the text declaring lines as the start of a group. For example,
```
:SortGroup /^\DeclareAcr... |
25,046 | <p>I am currently trying to write myself a function the will let me show or hide (toggle) the <code>:terminal</code> window. The only way to hide it, as far as I currently know, is to just navigate to that window and close it with <code>ZQ</code>, <code>:q</code> or whatever. I have a problem though:</p>
<ul>
<li>I ha... | [
{
"answer_id": 25052,
"author": "Biggybi",
"author_id": 22375,
"author_profile": "https://vi.stackexchange.com/users/22375",
"pm_score": 2,
"selected": false,
"text": "<h1>With vim only</h1>\n<p>There's a few options to make navigation between files less tedious in vanilla vim.</p>\n<p>F... | 2020/05/02 | [
"https://vi.stackexchange.com/questions/25046",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/23424/"
] | I am currently trying to write myself a function the will let me show or hide (toggle) the `:terminal` window. The only way to hide it, as far as I currently know, is to just navigate to that window and close it with `ZQ`, `:q` or whatever. I have a problem though:
* I have the buffer number `N` opened in some split, ... | Use [:h :wincmd](https://vimhelp.org/windows.txt.html#%3Awincmd) to manipulate window in script, it follow the same rule as [:h CTRL-W](https://vimhelp.org/index.txt.html#CTRL-W) .
e.g. If you want to jump to window 3, you can do it by `3<c-w><c-w>` in normal mode, or `:3wincmd w` in script.
Use [:h bufwinnr()](https:... |
25,075 | <p>I have four files <code>file1</code>, <code>file2</code>, <code>file3</code>, & <code>file4</code>. So I want to open them with vim directly from command line and get the following structure:</p>
<ol>
<li>Tabulation 1: <code>file1</code> taking whole tab</li>
<li>Tabulation 2: <code>file2</code> and <code>file3... | [
{
"answer_id": 25078,
"author": "fauve",
"author_id": 29366,
"author_profile": "https://vi.stackexchange.com/users/29366",
"pm_score": 1,
"selected": false,
"text": "<p>I have the answer of my first question:\nI have to invoque Vim like this <code>vim -c \":edit file1 | tabedit file2 | v... | 2020/05/04 | [
"https://vi.stackexchange.com/questions/25075",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29366/"
] | I have four files `file1`, `file2`, `file3`, & `file4`. So I want to open them with vim directly from command line and get the following structure:
1. Tabulation 1: `file1` taking whole tab
2. Tabulation 2: `file2` and `file3` sharing the same tab in split mode
3. Tabulation 3: `file3` taking whole tab
So, how to do ... | Vim’s `-S` option can take any file of vim commands and run them at startup. It’s usually used for sessions (`:mksession`; pairs well with tpope’s obsession plugin).
In this case, though, you could make the following file
```
" mylayout.vim
edit file1
tabedit file2
" &c.
```
And then you can do `vim -S mylayout.vim... |
25,077 | <p>I often use the <code>Ctrl-w</code> command in "Insert" mode to delete the word behind the cursor, just like I would do in Bash.</p>
<p>In Bash, I also have a <code>Meta-d</code> (<code>Esc-d</code>) command for deleting the word in front of the cursor. Does Vim have a similar command for "Insert" mode?</p>
| [
{
"answer_id": 25079,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 4,
"selected": true,
"text": "<p>I've the following mappings for this</p>\n\n<pre><code>noremap <C-Del> dw\ninoremap <C-Del> <spac... | 2020/05/04 | [
"https://vi.stackexchange.com/questions/25077",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26505/"
] | I often use the `Ctrl-w` command in "Insert" mode to delete the word behind the cursor, just like I would do in Bash.
In Bash, I also have a `Meta-d` (`Esc-d`) command for deleting the word in front of the cursor. Does Vim have a similar command for "Insert" mode? | I've the following mappings for this
```
noremap <C-Del> dw
inoremap <C-Del> <space><esc>ce
noremap <C-S-Del> dW
inoremap <C-S-Del> <esc>lcW
```
As you can see, there are several ways to do it (and handle single letters). and I'm quite certain there has been other Q/A|tips on the topic elsewhere.
NB: unlike ... |
25,086 | <p>I have a vim 8.2 on a Gentoo Linux running on a more or less 8 years old PC.</p>
<p>I almost never have a performance issue with vim, unless you open a one-line huge xml
oder json file, but those are vary rare cases.</p>
<p>My team has started using typescript and so many of our javascript files have
been transfor... | [
{
"answer_id": 25090,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": false,
"text": "<p>From <code>:help 're'</code>:</p>\n\n<pre><code> *'regexpengine'* *'re'*\n'regexpengine'... | 2020/05/04 | [
"https://vi.stackexchange.com/questions/25086",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5486/"
] | I have a vim 8.2 on a Gentoo Linux running on a more or less 8 years old PC.
I almost never have a performance issue with vim, unless you open a one-line huge xml
oder json file, but those are vary rare cases.
My team has started using typescript and so many of our javascript files have
been transformed to ts. I use ... | From `:help 're'`:
```
*'regexpengine'* *'re'*
'regexpengine' 're' number (default 0)
global
This selects the default regexp engine. |two-engines|
The possible values are:
0 automatic selection
1 old engine
2 NFA engine
Note that when using... |
25,113 | <p>I want some common syntax highlighting for various filetypes.</p>
<p>Currently I have <code>runtimepath/after/syntax/base.vim</code>
which has syntax rules I want and then I created mklink (this is windows) to <code>base.vim</code> for all filetypes (eg javascript.vim, c.vim, etc) that I want to have same <code>/af... | [
{
"answer_id": 25114,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 1,
"selected": false,
"text": "<p>If in specific you would like to avoid the <code>mklink</code> on Windows or symlinks on Linux/Unix/Mac, you can u... | 2020/05/06 | [
"https://vi.stackexchange.com/questions/25113",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29396/"
] | I want some common syntax highlighting for various filetypes.
Currently I have `runtimepath/after/syntax/base.vim`
which has syntax rules I want and then I created mklink (this is windows) to `base.vim` for all filetypes (eg javascript.vim, c.vim, etc) that I want to have same `/after` processing.
In this way single ... | If in specific you would like to avoid the `mklink` on Windows or symlinks on Linux/Unix/Mac, you can use small files for the specific languages that simply load `base.vim`.
The technique is recommended in [`:help :syn-files`](https://vimhelp.org/syntax.txt.html#%3Asyn-files):
>
> When a language is a superset of an... |
25,130 | <p>When a file is being opened neovim warns that swap file already exists, at which point you can't safely open a file without first closing it in the other instance.</p>
<p>I frequently have many projects open in different instances, which sometimes use shared files.
It is difficult to find which instance is using th... | [
{
"answer_id": 25229,
"author": "Rizhiy",
"author_id": 26459,
"author_profile": "https://vi.stackexchange.com/users/26459",
"pm_score": 0,
"selected": false,
"text": "<p>I decided to use:</p>\n\n<pre><code>set noswapfile\nset autowriteall\n</code></pre>\n\n<p>All of my important work is ... | 2020/05/06 | [
"https://vi.stackexchange.com/questions/25130",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26459/"
] | When a file is being opened neovim warns that swap file already exists, at which point you can't safely open a file without first closing it in the other instance.
I frequently have many projects open in different instances, which sometimes use shared files.
It is difficult to find which instance is using the file I w... | Since your question is about saving files, here's how I do it.
Vim files out of my way
-----------------------
```
if exists('$SUDO_USER') " no files for root user
set noswapfile
set nobackup
set nowritebackup
set noundofile
set viminfo=
else " I created a tmp folder
set b... |
25,135 | <p>I want to paste some text into Vim in GNOME Terminal on Ubuntu 20.04. Before doing that, I run:</p>
<pre><code>:set paste
</code></pre>
<p>I use that so that <code>autoindent</code> and other Vim features <a href="https://vimhelp.org/options.txt.html#%27paste%27" rel="nofollow noreferrer">don't change the text tha... | [
{
"answer_id": 25229,
"author": "Rizhiy",
"author_id": 26459,
"author_profile": "https://vi.stackexchange.com/users/26459",
"pm_score": 0,
"selected": false,
"text": "<p>I decided to use:</p>\n\n<pre><code>set noswapfile\nset autowriteall\n</code></pre>\n\n<p>All of my important work is ... | 2020/05/06 | [
"https://vi.stackexchange.com/questions/25135",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7244/"
] | I want to paste some text into Vim in GNOME Terminal on Ubuntu 20.04. Before doing that, I run:
```
:set paste
```
I use that so that `autoindent` and other Vim features [don't change the text that I am copying](https://vimhelp.org/options.txt.html#%27paste%27).
Then I enter insert mode, and I press `Ctrl`+`Shift`+... | Since your question is about saving files, here's how I do it.
Vim files out of my way
-----------------------
```
if exists('$SUDO_USER') " no files for root user
set noswapfile
set nobackup
set nowritebackup
set noundofile
set viminfo=
else " I created a tmp folder
set b... |
25,144 | <p>I'd like to re-map the <code><esc></code> key for switching to normal mode from edit mode. It just feels to far out of the way for me. I heard some have mapped this to the <code><caps lock></code> key instead. Can anyone show how to do this and what other key they might have used?</p>
| [
{
"answer_id": 25229,
"author": "Rizhiy",
"author_id": 26459,
"author_profile": "https://vi.stackexchange.com/users/26459",
"pm_score": 0,
"selected": false,
"text": "<p>I decided to use:</p>\n\n<pre><code>set noswapfile\nset autowriteall\n</code></pre>\n\n<p>All of my important work is ... | 2020/05/06 | [
"https://vi.stackexchange.com/questions/25144",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20890/"
] | I'd like to re-map the `<esc>` key for switching to normal mode from edit mode. It just feels to far out of the way for me. I heard some have mapped this to the `<caps lock>` key instead. Can anyone show how to do this and what other key they might have used? | Since your question is about saving files, here's how I do it.
Vim files out of my way
-----------------------
```
if exists('$SUDO_USER') " no files for root user
set noswapfile
set nobackup
set nowritebackup
set noundofile
set viminfo=
else " I created a tmp folder
set b... |
25,149 | <p>I recall (perhaps in the early 2000's) having <code>set nocompatible</code> as the first line of my vimrc and most Vim guides and tutorials recommending that practice.</p>
<p>Some examples I could easily find online:</p>
<ul>
<li><a href="https://engineering.purdue.edu/ece264/16au/static/.vimrc.html" rel="noreferr... | [
{
"answer_id": 25150,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 4,
"selected": true,
"text": "<blockquote>\n <p>Is there any advantages or side-effects of an explicit set nocompatible that I'm perhaps missing?</p>\n</... | 2020/05/07 | [
"https://vi.stackexchange.com/questions/25149",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/18609/"
] | I recall (perhaps in the early 2000's) having `set nocompatible` as the first line of my vimrc and most Vim guides and tutorials recommending that practice.
Some examples I could easily find online:
* [`vimrc` file of Alex Quinn](https://engineering.purdue.edu/ece264/16au/static/.vimrc.html) starts with:
```
set noc... | >
> Is there any advantages or side-effects of an explicit set nocompatible that I'm perhaps missing?
>
>
>
Actually, there are many side-effects. Every time `compatible` is set or reset Vim rescans all options (except "terminal") and switches defaults when necessary. After that it rebuilds quite a few internal ta... |
25,151 | <p>I can change cursor shape in text console (TERM=<code>linux</code> or <code>linux-16color</code>) by this <a href="https://linuxgazette.net/137/anonymous.html" rel="nofollow noreferrer">escape sequence</a>, :</p>
<pre><code>echo -e '\e[?6;c'
</code></pre>
<p>But I can't do it inside vim, below code should change c... | [
{
"answer_id": 25190,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 3,
"selected": false,
"text": "<p>Found a related <a href=\"https://groups.google.com/forum/#!topic/vim_use/PZsl0v7pBYQ\" rel=\"nofollow noreferrer\">di... | 2020/05/07 | [
"https://vi.stackexchange.com/questions/25151",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5017/"
] | I can change cursor shape in text console (TERM=`linux` or `linux-16color`) by this [escape sequence](https://linuxgazette.net/137/anonymous.html), :
```
echo -e '\e[?6;c'
```
But I can't do it inside vim, below code should change cursor shape in `insert` mode, but it has no effect:
```
let &t_SI="\e[?0;c"
let &t_E... | Found a related [discussion](https://groups.google.com/forum/#!topic/vim_use/PZsl0v7pBYQ).
`cnorm` on my machine is
```
\E[?25h\E[?0c
```
The tail `\E[?0c` will always reset cursor shape.
I thought I can use `t_SI` and `t_EI` if I remove it from `cnorm` (it's `termcap` code is `ve`):
```
let &t_ve= "\e[?25h"
let ... |
25,152 | <p>I've had some success over the past year or two using <a href="https://github.com/takac/vim-hardtime" rel="nofollow noreferrer">vim-hardtime</a> to wean myself off using the arrow keys in favour of <kbd>h</kbd>, <kbd>j</kbd>, <kbd>k</kbd>, <kbd>l</kbd>. However, I'd really like to wean myself off <kbd>:q</kbd>, <kbd... | [
{
"answer_id": 25155,
"author": "jdhao",
"author_id": 15292,
"author_profile": "https://vi.stackexchange.com/users/15292",
"pm_score": -1,
"selected": false,
"text": "<p>I am currently using mapping to quit vim or neovim. The mapping I use is:</p>\n\n<pre><code>\" Saves the file if modif... | 2020/05/07 | [
"https://vi.stackexchange.com/questions/25152",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/91/"
] | I've had some success over the past year or two using [vim-hardtime](https://github.com/takac/vim-hardtime) to wean myself off using the arrow keys in favour of `h`, `j`, `k`, `l`. However, I'd really like to wean myself off `:q`, `:wq`, etc. in favour of `ZQ`, `ZZ`, etc. - the latter are faster (at least in my experie... | I personally believe vim-hardtime and this kind of plugins which disable keys are not a good idea because it's better to use what you are comfortable with rather than inflicting yourself this kind of pain.
But here is a way to do what you want anyway
```
cnoremap <expr> <CR> getcmdtype() == ":" && index(["q", "wq"], ... |
25,168 | <p>I occasionally like to tinker with syntax files (especially conceals; I use <code>λ</code> for anonymous functions (<code>lambda:</code>, <code>fn</code>) in several languages).</p>
<p>However, one complaint with conceal is that I can only use a single character. When concealing, e.g., <code>fn</code>, having one c... | [
{
"answer_id": 25171,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 2,
"selected": false,
"text": "<p>Here's a solution using a different technique to the two you suggested:</p>\n\n<pre><code>syntax match lambda /\\_.\\<fn\... | 2020/05/07 | [
"https://vi.stackexchange.com/questions/25168",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10604/"
] | I occasionally like to tinker with syntax files (especially conceals; I use `λ` for anonymous functions (`lambda:`, `fn`) in several languages).
However, one complaint with conceal is that I can only use a single character. When concealing, e.g., `fn`, having one character breaks some vertical alignment. One solution ... | Here's a solution using a different technique to the two you suggested:
```
syntax match lambda /\_.\<fn\>/ containedin=ALL
syntax match lam /f/ containedin=lambda contained conceal cchar=λ
syntax match bda /n/ containedin=lambda contained conceal cchar=.
```
Syntax items which start in an earlier position in the bu... |
25,173 | <p>Is there a way to get 10 lines above and beneath the current cursor?</p>
<p>Similar to <code>set scrolloff=10</code> but I only want to do it ONCE, not change the setting...</p>
<p><em>Clarification</em>: I want <em>at least</em> 10 lines. If there's already 10+ lines above and below the cursor then the command sh... | [
{
"answer_id": 25171,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 2,
"selected": false,
"text": "<p>Here's a solution using a different technique to the two you suggested:</p>\n\n<pre><code>syntax match lambda /\\_.\\<fn\... | 2020/05/07 | [
"https://vi.stackexchange.com/questions/25173",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29430/"
] | Is there a way to get 10 lines above and beneath the current cursor?
Similar to `set scrolloff=10` but I only want to do it ONCE, not change the setting...
*Clarification*: I want *at least* 10 lines. If there's already 10+ lines above and below the cursor then the command shouldn't change anything. `zz` and `z.` are... | Here's a solution using a different technique to the two you suggested:
```
syntax match lambda /\_.\<fn\>/ containedin=ALL
syntax match lam /f/ containedin=lambda contained conceal cchar=λ
syntax match bda /n/ containedin=lambda contained conceal cchar=.
```
Syntax items which start in an earlier position in the bu... |
25,184 | <p>Is there any way to have vim highlight the search with <code>/</code> and <code>?</code> but not when putting cursor on a word and pressing <code>*</code> or <code>#</code>?</p>
<p><code>:set hlsearch</code> and <code>:set nohlsearch</code> turn it on and off for both.</p>
| [
{
"answer_id": 25185,
"author": "YonzLeon",
"author_id": 29440,
"author_profile": "https://vi.stackexchange.com/users/29440",
"pm_score": 0,
"selected": false,
"text": "<p>Maybe you want to try this :</p>\n\n<ol>\n<li>Open <code>~/.vimrc</code> (create it if it didn't exist).</li>\n<li>A... | 2020/05/08 | [
"https://vi.stackexchange.com/questions/25184",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29407/"
] | Is there any way to have vim highlight the search with `/` and `?` but not when putting cursor on a word and pressing `*` or `#`?
`:set hlsearch` and `:set nohlsearch` turn it on and off for both. | I don't think there's anything better than switching highlight off just after the search:
```
set hlsearch
nnoremap <silent>* *:noh<CR>
nnoremap <silent># #:noh<CR>
``` |
25,192 | <p>No matter how I do it, I seem to get the nightly or the 0.2.2 version. How do I install the stable version of Neovim. I have too many issues in the nightly. </p>
<p>I used <code>sudo apt install neovim</code> and when I run <code>nvim --version</code> I get:</p>
<pre><code>NVIM v0.5.0-nightly-6-gef0398f
Build type... | [
{
"answer_id": 25199,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 2,
"selected": false,
"text": "<p>Ubuntu 18.04 (Bionic) ships <a href=\"https://packages.ubuntu.com/bionic/neovim\" rel=\"nofollow noreferrer\">Neov... | 2020/05/08 | [
"https://vi.stackexchange.com/questions/25192",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1596/"
] | No matter how I do it, I seem to get the nightly or the 0.2.2 version. How do I install the stable version of Neovim. I have too many issues in the nightly.
I used `sudo apt install neovim` and when I run `nvim --version` I get:
```
NVIM v0.5.0-nightly-6-gef0398f
Build type: Release
LuaJIT 2.1.0-beta3
``` | There is `ppa` recommended on the [project page:](https://github.com/neovim/neovim/wiki/Installing-Neovim)
```
sudo add-apt-repository ppa:neovim-ppa/stable
sudo apt-get update
sudo apt-get install neovim
```
You'll get v0.4.3:
```
$ nvim --version ... |
25,209 | <p>So, when I open multiple files, but don't visit the all of them (or the last one), and I try to :quit neovim yells at me that I have to edit those files. No I don't! Stop giving me this error : ) </p>
<p>It seems totally strange that it gives me an error for unVISITED files. The fix I've used until now was this:</p... | [
{
"answer_id": 25210,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 2,
"selected": false,
"text": "<p><strong>Option 1</strong>: Use <code>:qa</code>, <code>:q!</code>, or <code>ZQ</code> to quit. Then vim does not prompt... | 2020/05/09 | [
"https://vi.stackexchange.com/questions/25209",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1596/"
] | So, when I open multiple files, but don't visit the all of them (or the last one), and I try to :quit neovim yells at me that I have to edit those files. No I don't! Stop giving me this error : )
It seems totally strange that it gives me an error for unVISITED files. The fix I've used until now was this:
```
" Avoid... | I guess you have your code before `filetype on` (including `runtime defaults.vim` or anything else switching `filetype on`). But it must be placed after it.
Also, my personal advice is to `set confirm` and get rid of this stuff completely. Or use `ZQ`, or `:q!` and such.
UPD. As it turned out, the problem was due to ... |
25,216 | <p>I'm pretty new to writing stuff in my .vimrc, and I'm trying to understand how to use conditionals.</p>
<p>I'm using <a href="https://neovim.io/" rel="noreferrer">neovim</a>. I'm trying to get (<a href="https://github.com/vimlab/split-term.vim" rel="noreferrer">an enhanced version of</a>) nvim's terminal emulator t... | [
{
"answer_id": 25218,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 5,
"selected": true,
"text": "<p>The <code>:Term</code> command you are using does not support the <code>-bar</code> option so it will take <code>| e... | 2020/05/10 | [
"https://vi.stackexchange.com/questions/25216",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29474/"
] | I'm pretty new to writing stuff in my .vimrc, and I'm trying to understand how to use conditionals.
I'm using [neovim](https://neovim.io/). I'm trying to get ([an enhanced version of](https://github.com/vimlab/split-term.vim)) nvim's terminal emulator to launch in a split when I open nvim (unless I specify just one th... | The `:Term` command you are using does not support the `-bar` option so it will take `| endif` as an argument. You can overcome this with `:execute`
```
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | execute '10Term' | endif
``` |
25,224 | <p>While writing <a href="https://vi.stackexchange.com/a/25223/18609">this answer</a> about vim-rails on SpaceVim, I found out these mappings set by SpaceVim, such as <a href="https://github.com/SpaceVim/SpaceVim/blob/v1.4.0/autoload/SpaceVim/mapping/g.vim#L50" rel="nofollow noreferrer">this one</a>:</p>
<pre><code>nn... | [
{
"answer_id": 25233,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 3,
"selected": true,
"text": "<p>I think I can make a guess (but I have never seen this before either, and I haven't used SpaceVim yet) based on this issue: <... | 2020/05/10 | [
"https://vi.stackexchange.com/questions/25224",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/18609/"
] | While writing [this answer](https://vi.stackexchange.com/a/25223/18609) about vim-rails on SpaceVim, I found out these mappings set by SpaceVim, such as [this one](https://github.com/SpaceVim/SpaceVim/blob/v1.4.0/autoload/SpaceVim/mapping/g.vim#L50):
```
nnoremap gf gf
```
SpaceVim also creates similar mappings for ... | I think I can make a guess (but I have never seen this before either, and I haven't used SpaceVim yet) based on this issue: [gq for reformatting doesn't work #787](https://github.com/SpaceVim/SpaceVim/issues/787). `nmap g [G]` essentially blocks all the usual normal-mode commands that start `g`. `gq`, for example, is n... |
25,259 | <p>I am on <strong>Neovim</strong>.</p>
<p>This is really annoying and weird. </p>
<p>When I make a selection in Visual Mode and copy, then select a text and then paste, this paste only works once. For the next time, I again have to go to the original source and then do the copy operation all over and then paste.</p>... | [
{
"answer_id": 25260,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 4,
"selected": true,
"text": "<blockquote>\n <p>Is the clipboard overwritten in Visual Mode each time?</p>\n</blockquote>\n\n<p>Yes it is.</p>\n\n<blo... | 2020/05/11 | [
"https://vi.stackexchange.com/questions/25259",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29387/"
] | I am on **Neovim**.
This is really annoying and weird.
When I make a selection in Visual Mode and copy, then select a text and then paste, this paste only works once. For the next time, I again have to go to the original source and then do the copy operation all over and then paste.
What I am doing:
1. Press `v` t... | >
> Is the clipboard overwritten in Visual Mode each time?
>
>
>
Yes it is.
>
> How do I get "sane" behavior? That is make the clipboard persist after the first paste.
>
>
>
To get "sane" behavior you can remap `p` and `P` with:
```
" now it is possible to paste many times over selected text
xnoremap <expr>... |
25,267 | <p><a href="https://i.stack.imgur.com/gebVo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gebVo.png" alt="enter image description here"></a></p>
<p>I need help with vim. Just starting vim but struggling with settings.
I placed the below plugin in vimrc as this:</p>
<pre><code>Plug '~/my-prototype... | [
{
"answer_id": 25270,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 1,
"selected": false,
"text": "<p>A vim-plug plugin spec that includes a local file system path is an \"un-managed\" plugin. </p>\n\n<pre><code>\" Unm... | 2020/05/12 | [
"https://vi.stackexchange.com/questions/25267",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29527/"
] | [](https://i.stack.imgur.com/gebVo.png)
I need help with vim. Just starting vim but struggling with settings.
I placed the below plugin in vimrc as this:
```
Plug '~/my-prototype-plugin'
```
Also, why are some of my plugins not loaded? | A vim-plug plugin spec that includes a local file system path is an "un-managed" plugin.
```
" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'
```
That means you intend to take care of downloading and building it. You're just telling vim-plug where you've put it.
If you want vim-plug... |
25,277 | <p>I can make a map like this:</p>
<pre><code>nmap wr :write<CR>
</code></pre>
<p>but then it clashes with another map:</p>
<ul>
<li><a href="http://vimdoc.sourceforge.net/htmldoc/map.html#map-ambiguous" rel="nofollow noreferrer">http://vimdoc.sourceforge.net/htmldoc/map.html#map-ambiguous</a></li>
<li><a href... | [
{
"answer_id": 25279,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 2,
"selected": false,
"text": "<p>In order to trigger the mapping before <a href=\"https://vimhelp.org/options.txt.html#%27timeoutlen%27\" rel=\"nof... | 2020/05/12 | [
"https://vi.stackexchange.com/questions/25277",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7184/"
] | I can make a map like this:
```
nmap wr :write<CR>
```
but then it clashes with another map:
* <http://vimdoc.sourceforge.net/htmldoc/map.html#map-ambiguous>
* <http://vimdoc.sourceforge.net/htmldoc/motion.html#w>
So if I do press `w`, it pauses before performing the motion. How can I quickly
perform the `w` motio... | Another option would be to use capital instead:
```
nmap W :write<CR>
```
This will likely clobber something else (as in this case), but usually the
capitals are less used than lowercase. Another option is `abbreviate`:
<http://vimdoc.sourceforge.net/htmldoc/map.html#:abbreviate>
Example:
```
abbrev w write
```
... |
25,284 | <p>I was wondering what would be the most Vimish way to the following: I want to invert the text on the right side of the equal sign to the left (and the left to the right). For example, I want this:</p>
<pre><code>v1 = a1
v2 = a2
</code></pre>
<p>to become:</p>
<pre><code>a1 = v1
a2 = v2
</code></pre>
<p>Thanks</p... | [
{
"answer_id": 25285,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 1,
"selected": false,
"text": "<h2>Use a <code>:substitute</code> command with a regex</h2>\n\n<p>Using a <code>:substitute</code> command is pretty... | 2020/05/13 | [
"https://vi.stackexchange.com/questions/25284",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28903/"
] | I was wondering what would be the most Vimish way to the following: I want to invert the text on the right side of the equal sign to the left (and the left to the right). For example, I want this:
```
v1 = a1
v2 = a2
```
to become:
```
a1 = v1
a2 = v2
```
Thanks | Record and replay a macro
-------------------------
You can record a [macro](https://vimhelp.org/repeat.txt.html#recording) to handle each line, and then replay it to handle the following lines using the same sequence of commands.
Let's make a somewhat more interesting example, with varying lengths of variable names,... |
25,292 | <p>I am using latest available version of NeoVim v0.4.3 and latest Arch build with kernel 5.6.4-arch1-1.</p>
<p>I'm having a problem with the following command in the NeoVim command line:</p>
<pre><code> 1 2 3 4 5 6
:g/^$/d | %s/\t//g | %... | [
{
"answer_id": 25294,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 2,
"selected": false,
"text": "<p>The problem you're having here is that some commands take the <code>|</code> and use it, which makes the <code>|</... | 2020/05/13 | [
"https://vi.stackexchange.com/questions/25292",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27300/"
] | I am using latest available version of NeoVim v0.4.3 and latest Arch build with kernel 5.6.4-arch1-1.
I'm having a problem with the following command in the NeoVim command line:
```
1 2 3 4 5 6
:g/^$/d | %s/\t//g | %s/ / /g | %s/$/,... | So here is a solution I would use (from my tests it seems to work fine):
```
execute '%s/\t//g|%s/ / /g|%s/$/,/|g/^,$/d' | norm! gg8J
```
The issue with your one liner is that vim gets confused because `g|pattern|command|` is a valid command then thus it doesn't make the difference between your different chained co... |
25,311 | <p><strong>Edit</strong> this issue happens inside a tmux session. The original value of $TERM before starting vim is:</p>
<pre><code>echo $TERM
screen
</code></pre>
<p>The issue appears for example when pasting this kind of indented code:</p>
<pre><code>def function(condition):
if condition:
print("Hi")... | [
{
"answer_id": 25315,
"author": "user938271",
"author_id": 17449,
"author_profile": "https://vi.stackexchange.com/users/17449",
"pm_score": 4,
"selected": true,
"text": "<blockquote>\n<p>It is even supposed to be by default in Vim 8.</p>\n</blockquote>\n<p>Only if Vim thinks the terminal... | 2020/05/13 | [
"https://vi.stackexchange.com/questions/25311",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6671/"
] | **Edit** this issue happens inside a tmux session. The original value of $TERM before starting vim is:
```
echo $TERM
screen
```
The issue appears for example when pasting this kind of indented code:
```
def function(condition):
if condition:
print("Hi")
if not condition:
print("Bye")
```
... | >
> It is even supposed to be by default in Vim 8.
>
>
>
Only if Vim thinks the terminal is xterm-compatible, which is the case if `TERM` is `xterm` or some derivative.
If `TERM` is `gnome`, Vim won't enable the bracketed paste mode automatically; you have to configure it.
>
> I have vim 8, how to enable bracket... |
25,312 | <p>Working with big projects, I often find myself needing to view/edit several files at once.</p>
<p>If I have multiple buffers open, is there a way to split the window to view multiple files in one command?</p>
<p>E.g. usually I begin my workflow by entering my project's root directory, entering <code>vim</code> in th... | [
{
"answer_id": 25361,
"author": "WalksB",
"author_id": 27301,
"author_profile": "https://vi.stackexchange.com/users/27301",
"pm_score": 2,
"selected": false,
"text": "<p>As filbranden pointed out, it is possible by joining the <code>sb</code> calls like e.g. this:</p>\n\n<p><code>:sb rsy... | 2020/05/13 | [
"https://vi.stackexchange.com/questions/25312",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27301/"
] | Working with big projects, I often find myself needing to view/edit several files at once.
If I have multiple buffers open, is there a way to split the window to view multiple files in one command?
E.g. usually I begin my workflow by entering my project's root directory, entering `vim` in the terminal, and then enter... | You could write a wrapper to do all the commands at once:
```
command -bar -nargs=+ -complete=buffer Sbuffers execute map([<f-args>], {_, b -> printf("sbuffer %s", b)})->join("|")
```
Usage: `Sbuffers file1 file2 file3`
Completion will use buffer names (so the buffers have to have been loaded). You can tweak this t... |
25,319 | <p>Is it possible to make <code>???</code> (3 question marks) a keyword, and highlight it? </p>
<p>I have tried the following in a syntax file. Other strings on the line are highlighted, but not <code>???</code>. <code>\?\?\?</code> does not work either. </p>
<pre><code>syntax keyword textTodos TODO ??? XXX LLL
hig... | [
{
"answer_id": 25320,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": false,
"text": "<p>syntax keywords are supposed to be - well - keywords. Initially, this meant, it must match the definition of the... | 2020/05/14 | [
"https://vi.stackexchange.com/questions/25319",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29576/"
] | Is it possible to make `???` (3 question marks) a keyword, and highlight it?
I have tried the following in a syntax file. Other strings on the line are highlighted, but not `???`. `\?\?\?` does not work either.
```
syntax keyword textTodos TODO ??? XXX LLL
highlight default link textTodos Todo
``` | I would recommend to do it with a `syntax match` like this:
```
syntax match TQM '???' containedin=ALL
highlight link TQM Todo
```
If you want to have it always available, you could put the following in your `vimrc`:
```
augroup my_syntax_autocmd
autocmd!
autocmd Syntax * syntax match TQM '???' containedin=... |
25,327 | <p>I'm using vim all the time for text editing these days, and have a particular use case: editing a dataset using successive commands. The main problem, as often, is fixing things, ideally rather quickly.</p>
<p>The picture is this: </p>
<ul>
<li>a folder with a number of files, e.g. 1000, that need to be cleaned-up... | [
{
"answer_id": 25339,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 3,
"selected": true,
"text": "<p>I use argdo in this answer, same rule applies to <code>bufdo</code>, <code>windo</code> , ... .</p>\n<h2>Don't use <cod... | 2020/05/14 | [
"https://vi.stackexchange.com/questions/25327",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29583/"
] | I'm using vim all the time for text editing these days, and have a particular use case: editing a dataset using successive commands. The main problem, as often, is fixing things, ideally rather quickly.
The picture is this:
* a folder with a number of files, e.g. 1000, that need to be cleaned-up / formatted.
* the c... | I use argdo in this answer, same rule applies to `bufdo`, `windo` , ... .
Don't use `argdo undo`
----------------------
`argdo undo` failes in these conditions:
* Some buffers remain unchanged after last `argdo`, might caused by 0 pattern match, execute `undo` on them is a mistake, it will undo changes made by older... |
25,331 | <p>Is there a way to rename/copy/move a file and maintain the vim persistent undo information?</p>
<p>If I do</p>
<pre><code>:w new-file-name
</code></pre>
<p>and then</p>
<pre><code>:e new-file-name
</code></pre>
<p>I can't hit <kbd>u</kbd> to undo. <code>Already at oldest change</code> :-(</p>
| [
{
"answer_id": 25332,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 4,
"selected": true,
"text": "<p>Using <a href=\"https://vimhelp.org/editing.txt.html#%3Asaveas\" rel=\"noreferrer\"><code>:saveas</code></a> keeps ... | 2020/05/14 | [
"https://vi.stackexchange.com/questions/25331",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19574/"
] | Is there a way to rename/copy/move a file and maintain the vim persistent undo information?
If I do
```
:w new-file-name
```
and then
```
:e new-file-name
```
I can't hit `u` to undo. `Already at oldest change` :-( | Using [`:saveas`](https://vimhelp.org/editing.txt.html#%3Asaveas) keeps the undo history intact.
`:saveas` is equivalent to the combination of `:w *newname*` followed by `:e #`. I usually find it more handy than the `:w` + `:e`, especially since with `:saveas` it's not really possible to *forget* about doing the secon... |
25,340 | <p><a href="https://alvinalexander.com/linux/vi-vim-editor-color-scheme-syntax/" rel="nofollow noreferrer">This</a> was a nice little article that somewhat demystified vim colors to me.</p>
<p>I downloaded and installed the <a href="https://base2t.one/" rel="nofollow noreferrer">Base2Tone</a> vim colorschemes, and set... | [
{
"answer_id": 25342,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 1,
"selected": false,
"text": "<blockquote>\n <p>Is there some way I can get vim's colorscheme rendering more like gvim's?</p>\n</blockquote>\n\n<p... | 2020/05/15 | [
"https://vi.stackexchange.com/questions/25340",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11701/"
] | [This](https://alvinalexander.com/linux/vi-vim-editor-color-scheme-syntax/) was a nice little article that somewhat demystified vim colors to me.
I downloaded and installed the [Base2Tone](https://base2t.one/) vim colorschemes, and set the following in my `~/.vimrc`:
```
colorscheme Base2Tone_PoolDark
hi LineNr cterm... | Highlight in gui or true color terminal with `:h termguicolors` is not affect by `:h cterm`, `cterm` is used for 8, 16, 256 color terminal. This command should change gui LineNr:
```
hi LineNr guifg=#ff0000 guibg=#000000
```
A quick look at the [source](https://github.com/atelierbram/Base2Tone-vim/blob/master/colors... |
25,362 | <p>Very often, my preferred way of navigating a file in vim is by "scrolling" line by line. By scrolling, I mean shifting the lines up/down while keeping the cursor on the same line and position. <code><c-d></code> and <code><c-u></code> implement this already, but they do so for half a page, not ... | [
{
"answer_id": 25363,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 3,
"selected": false,
"text": "<pre><code> *CTRL-D*\nCTRL-D Scroll window Downwards in the buffer. The number of\n ... | 2020/05/16 | [
"https://vi.stackexchange.com/questions/25362",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27301/"
] | Very often, my preferred way of navigating a file in vim is by "scrolling" line by line. By scrolling, I mean shifting the lines up/down while keeping the cursor on the same line and position. `<c-d>` and `<c-u>` implement this already, but they do so for half a page, not one line.
So I made bindings that implement wh... | ```
*CTRL-D*
CTRL-D Scroll window Downwards in the buffer. The number of
lines comes from the 'scroll' option (default: half a
screen). <b>If [count] given, first set 'scroll' option
to [count].</b> ...
```
Execute `1<ctrl-d>` for one time, i... |
25,368 | <p>While using gVim on my Windows 10 machine at work, I discovered and started using the amazing spell checker when writing markdown. In gVim, misspelled words are underlined with the red squiggly everyone is familiar with. </p>
<p>At home on my Ubuntu machine, I realized the red squiggly only works in gVim, not in my... | [
{
"answer_id": 25370,
"author": "PatMcTookis",
"author_id": 29226,
"author_profile": "https://vi.stackexchange.com/users/29226",
"pm_score": 0,
"selected": false,
"text": "<p>After reading more of the solarized documentation, it's now clear that I should not be using solarized.vim with t... | 2020/05/16 | [
"https://vi.stackexchange.com/questions/25368",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29226/"
] | While using gVim on my Windows 10 machine at work, I discovered and started using the amazing spell checker when writing markdown. In gVim, misspelled words are underlined with the red squiggly everyone is familiar with.
At home on my Ubuntu machine, I realized the red squiggly only works in gVim, not in my terminal.... | Since I (or rather the Community Bot) dug this question up after two years, I might as well offer a minimal and elegant answer to have the solarized colorscheme, running in the terminal, with spell checking.
Only one line is needed in addition to the usual solarized setup in `.vimrc`:
```
colorscheme solarized
if has... |
25,383 | <p>I have a problem with breaking long line in <code>markdown</code> file. Given the following line</p>
<p><code> * "fo" : You can use the 'formatoptions' option to influence how Vim formats text. 'formatoptions' is a string that can contain any of the letters below. The default setting is "tcq". </code></p>
<p>runi... | [
{
"answer_id": 25388,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 1,
"selected": false,
"text": "<p>Your <code>'formatoptions'</code> include <code>q</code>, it allow <code>gq</code> to format comments.</p>\n\n<p>Your ... | 2020/05/17 | [
"https://vi.stackexchange.com/questions/25383",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14132/"
] | I have a problem with breaking long line in `markdown` file. Given the following line
`* "fo" : You can use the 'formatoptions' option to influence how Vim formats text. 'formatoptions' is a string that can contain any of the letters below. The default setting is "tcq".`
runing `gq$` will end up with
```
* "fo" :... | The behavior you're seeing is triggered by plug-in `plasticboy/vim-markdown`, which is installing an [indent](https://github.com/plasticboy/vim-markdown/blob/e86a7e49587cb213c95e8e428d3245d70ee96f14/indent/markdown.vim#L15) plug-in which sets:
```
setlocal comments+=b:*,b:+,b:-
```
This lacks the `f` flag on the `*`... |
25,403 | <p>I recently updated my MacBook to OSX Catalina and now I am getting some unwanted behavior in vim (though it seems to be working overall?). </p>
<p>On opening vim I see the following stream of errors (NERDTree is open by default, I have a manually created vim system that is on the plug-in heavy side):</p>
<pre><cod... | [
{
"answer_id": 25388,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 1,
"selected": false,
"text": "<p>Your <code>'formatoptions'</code> include <code>q</code>, it allow <code>gq</code> to format comments.</p>\n\n<p>Your ... | 2020/05/17 | [
"https://vi.stackexchange.com/questions/25403",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5575/"
] | I recently updated my MacBook to OSX Catalina and now I am getting some unwanted behavior in vim (though it seems to be working overall?).
On opening vim I see the following stream of errors (NERDTree is open by default, I have a manually created vim system that is on the plug-in heavy side):
```
MacBook-Pro:project... | The behavior you're seeing is triggered by plug-in `plasticboy/vim-markdown`, which is installing an [indent](https://github.com/plasticboy/vim-markdown/blob/e86a7e49587cb213c95e8e428d3245d70ee96f14/indent/markdown.vim#L15) plug-in which sets:
```
setlocal comments+=b:*,b:+,b:-
```
This lacks the `f` flag on the `*`... |
25,405 | <p>I have the number of my xterm (i.e., the value of /dev/tty??) saved as an environment variable, TTY e.g., <code>echo $TTY</code> returns <code>11</code>. I'd like to include this number in the title, along with the name of the file when I open vi.</p>
<p>Currently I have</p>
<pre><code>set titlestring=%-25.55F... | [
{
"answer_id": 25406,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 4,
"selected": true,
"text": "<p>Variables are not expanded in the context of a <code>set</code> command. So use <code>let</code>:</p>\n\n<pre><code>let &... | 2020/05/17 | [
"https://vi.stackexchange.com/questions/25405",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4667/"
] | I have the number of my xterm (i.e., the value of /dev/tty??) saved as an environment variable, TTY e.g., `echo $TTY` returns `11`. I'd like to include this number in the title, along with the name of the file when I open vi.
Currently I have
```
set titlestring=%-25.55F\ %a%r%m titlelen=17
```
I've tried the obvio... | Variables are not expanded in the context of a `set` command. So use `let`:
```
let &titlestring = $TTY . ' %-25.55F %a%r%m'
set titlelen=17
``` |
25,415 | <p>I have string like this:</p>
<pre><code>1668955,,, bunch of text</figcaption><br /><a href="https://the_url/article_detail.php?article_id=10003414" target="_blank">w..... </a><br /><h2> text ....<br /><br /><a href="https://the_url/article_detail.php?article_id=... | [
{
"answer_id": 25436,
"author": "wmmso",
"author_id": 16478,
"author_profile": "https://vi.stackexchange.com/users/16478",
"pm_score": 0,
"selected": false,
"text": "<p>Use this substitution command:</p>\n\n<p><code>%s/\\(\\d*,,,\\).*href=\"\\(https:.*\\)\" .*/\\1 \\2 /</code></p>\n\n... | 2020/05/18 | [
"https://vi.stackexchange.com/questions/25415",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3302/"
] | I have string like this:
```
1668955,,, bunch of text</figcaption><br /><a href="https://the_url/article_detail.php?article_id=10003414" target="_blank">w..... </a><br /><h2> text ....<br /><br /><a href="https://the_url/article_detail.php?article_id=10002526" target="_blank">...... text .....
```
Is there a way ... | Here's a quick and dirty solution. You can certainly find/create input HTML that will break this, but it works fine for simple input such as your example:
1. Add a `"` at the end of the commas:
```
:norm! 0Ea"
```
This is simply using a [`:normal`](https://vimhelp.org/various.txt.html#%3Anormal) command to execute ... |
25,417 | <p>I'm attempting to create a portable Neovim configuration for Windows. I'm a bit confused about all the directories. Maybe someone can shed a little light on me :)</p>
<p>So I downloaded a pre-built archive from <a href="https://github.com/neovim/neovim/releases" rel="nofollow noreferrer">https://github.com/neovim/n... | [
{
"answer_id": 25436,
"author": "wmmso",
"author_id": 16478,
"author_profile": "https://vi.stackexchange.com/users/16478",
"pm_score": 0,
"selected": false,
"text": "<p>Use this substitution command:</p>\n\n<p><code>%s/\\(\\d*,,,\\).*href=\"\\(https:.*\\)\" .*/\\1 \\2 /</code></p>\n\n... | 2020/05/18 | [
"https://vi.stackexchange.com/questions/25417",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6968/"
] | I'm attempting to create a portable Neovim configuration for Windows. I'm a bit confused about all the directories. Maybe someone can shed a little light on me :)
So I downloaded a pre-built archive from <https://github.com/neovim/neovim/releases> and extracted it.
I found that nvim will use `c:\users\myname\AppDataL... | Here's a quick and dirty solution. You can certainly find/create input HTML that will break this, but it works fine for simple input such as your example:
1. Add a `"` at the end of the commas:
```
:norm! 0Ea"
```
This is simply using a [`:normal`](https://vimhelp.org/various.txt.html#%3Anormal) command to execute ... |
25,425 | <p>I'm currently running Vim in Windows 10. I want to specify in my config file certain settings for when I'm running Vim in Cmder, different settings when I'm running Vim in Alacritty, etc.</p>
<p>When in Cmder, if I run <code>echo &term</code> I get <code>win32</code>, and when I run <code>echo $term</code> I ge... | [
{
"answer_id": 25427,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 4,
"selected": true,
"text": "<p>Regarding the two variables:</p>\n\n<ul>\n<li><code>$term</code> is a variable from the environment. When you are on the ... | 2020/05/18 | [
"https://vi.stackexchange.com/questions/25425",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26481/"
] | I'm currently running Vim in Windows 10. I want to specify in my config file certain settings for when I'm running Vim in Cmder, different settings when I'm running Vim in Alacritty, etc.
When in Cmder, if I run `echo &term` I get `win32`, and when I run `echo $term` I get `cygwin`. What's the difference between `$ter... | Regarding the two variables:
* `$term` is a variable from the environment. When you are on the terminal (without opening Vim), `echo $term` should echo the same as `:echo $term` from inside Vim. (I'm a little bit surprised that it is not upper case, like `$TERM`.)
* `&term` represents the option `term` (see `:h 'term'... |
25,430 | <p>I'm trying to make a protable Neovim so I can use my plug&play IDE from a USB thumbdrive on any offline Windows computer.</p>
<p>I managed to store my plugins and my sysinit.vim onto the USB drive and make Neovim use them.</p>
<p>But while testing I realized that Neovim creates some folders on the host compute... | [
{
"answer_id": 25427,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 4,
"selected": true,
"text": "<p>Regarding the two variables:</p>\n\n<ul>\n<li><code>$term</code> is a variable from the environment. When you are on the ... | 2020/05/19 | [
"https://vi.stackexchange.com/questions/25430",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6968/"
] | I'm trying to make a protable Neovim so I can use my plug&play IDE from a USB thumbdrive on any offline Windows computer.
I managed to store my plugins and my sysinit.vim onto the USB drive and make Neovim use them.
But while testing I realized that Neovim creates some folders on the host computer.
`~\AppData\Local\... | Regarding the two variables:
* `$term` is a variable from the environment. When you are on the terminal (without opening Vim), `echo $term` should echo the same as `:echo $term` from inside Vim. (I'm a little bit surprised that it is not upper case, like `$TERM`.)
* `&term` represents the option `term` (see `:h 'term'... |
25,433 | <p>When working with options that often have complex or calculated string values (e.g. <code>formatprg</code>, which might have additional parameters, separated by whitespace), it's often easier to use <code>let</code> to set them, i.e. <code>let &option='complex stuff'</code> rather than <code>set option=complex\ ... | [
{
"answer_id": 25427,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 4,
"selected": true,
"text": "<p>Regarding the two variables:</p>\n\n<ul>\n<li><code>$term</code> is a variable from the environment. When you are on the ... | 2020/05/19 | [
"https://vi.stackexchange.com/questions/25433",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/91/"
] | When working with options that often have complex or calculated string values (e.g. `formatprg`, which might have additional parameters, separated by whitespace), it's often easier to use `let` to set them, i.e. `let &option='complex stuff'` rather than `set option=complex\ stuff`.
However, for options which are buffe... | Regarding the two variables:
* `$term` is a variable from the environment. When you are on the terminal (without opening Vim), `echo $term` should echo the same as `:echo $term` from inside Vim. (I'm a little bit surprised that it is not upper case, like `$TERM`.)
* `&term` represents the option `term` (see `:h 'term'... |
25,440 | <p>I'd like to use <code><C-X> <C-F></code> to autocomplete a long filename in insert mode, say <code>/foo/bar/baz.txt</code>. When I type in <code>/f</code>, I can press <code><C-X> <C-F></code> to complete to <code>/foo/</code>. However, after typing <code>/foo/b</code>, I'll need to press <co... | [
{
"answer_id": 25445,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": true,
"text": "<p>(Untested) You'll need a vim that supports <code>CompleteDonePre</code>. You can check with</p>\n\n<pre><code>ec... | 2020/05/19 | [
"https://vi.stackexchange.com/questions/25440",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29673/"
] | I'd like to use `<C-X> <C-F>` to autocomplete a long filename in insert mode, say `/foo/bar/baz.txt`. When I type in `/f`, I can press `<C-X> <C-F>` to complete to `/foo/`. However, after typing `/foo/b`, I'll need to press `<C-X> <C-F>` again to complete to `/foo/bar/`. After typing `/foo/bar/b`, I'll need to press `<... | (Untested) You'll need a vim that supports `CompleteDonePre`. You can check with
```
echo has('##CompleteDonePre') ? 'supported' : 'not supported'
```
If you have this event, you can use the following autocommand:
```
augroup ContinueFileCompletion
autocmd!
autocmd CompleteDonePre * if complete_info()['mode'] =... |
25,464 | <p>When I edit .vimrc (for example), I often want to view the file as write-protected. </p>
<pre><code>noremap <C-a> : sview $HOME/.vimrc <CR> \| : set noma <CR>
</code></pre>
<p>sets the nonmodifiable property for the file in both the editing instance end the view.</p>
<p>Is the property set per f... | [
{
"answer_id": 25466,
"author": "Herb",
"author_id": 5298,
"author_profile": "https://vi.stackexchange.com/users/5298",
"pm_score": 1,
"selected": false,
"text": "<p>One alternative option would be to use <code>view</code> or <code>vim -R <filename></code>, which opens the file in ... | 2020/05/21 | [
"https://vi.stackexchange.com/questions/25464",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29704/"
] | When I edit .vimrc (for example), I often want to view the file as write-protected.
```
noremap <C-a> : sview $HOME/.vimrc <CR> \| : set noma <CR>
```
sets the nonmodifiable property for the file in both the editing instance end the view.
Is the property set per file and not per buffer?
If that is the case, how c... | So it looks like you haven't learnt the Vim terminology and that's the source of your confusion. Forget those "instances", "views" and such. It's all about "buffers" and "windows".
>
> sets noma property for the file in both the editing instance end the view.
>
>
>
To put it properly: "noma is set for the buffer ... |
25,469 | <p>I am using latest available version of NeoVim v0.4.3 and latest Arch build with kernel 5.6.4-arch1-1.</p>
<p>Within .vimrc what is the difference between</p>
<p><code>:nnoremap ...</code> and </p>
<p><code>nnoremap ...</code>.</p>
<p>Or, what effect, if any, does the addition of removal of the <code>:</code> at ... | [
{
"answer_id": 25466,
"author": "Herb",
"author_id": 5298,
"author_profile": "https://vi.stackexchange.com/users/5298",
"pm_score": 1,
"selected": false,
"text": "<p>One alternative option would be to use <code>view</code> or <code>vim -R <filename></code>, which opens the file in ... | 2020/05/21 | [
"https://vi.stackexchange.com/questions/25469",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27300/"
] | I am using latest available version of NeoVim v0.4.3 and latest Arch build with kernel 5.6.4-arch1-1.
Within .vimrc what is the difference between
`:nnoremap ...` and
`nnoremap ...`.
Or, what effect, if any, does the addition of removal of the `:` at the start of the line make? | So it looks like you haven't learnt the Vim terminology and that's the source of your confusion. Forget those "instances", "views" and such. It's all about "buffers" and "windows".
>
> sets noma property for the file in both the editing instance end the view.
>
>
>
To put it properly: "noma is set for the buffer ... |
25,499 | <p>When I'm opening my app.js file in the vim status bar following error is shown</p>
<pre><code>[coc.nvim] Failed to load the ESLint library for the document /mnt/d/js/my_take/js_sandbox/app.js
</code></pre>
<p>Even though the autocompletion is working, I'm curious to know why this is happening.</p>
| [
{
"answer_id": 25532,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 1,
"selected": false,
"text": "<p>I don't use CoC, but <a href=\"https://eslint.org\" rel=\"nofollow noreferrer\">ESLint</a> is an static analyzer and has noth... | 2020/05/24 | [
"https://vi.stackexchange.com/questions/25499",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29688/"
] | When I'm opening my app.js file in the vim status bar following error is shown
```
[coc.nvim] Failed to load the ESLint library for the document /mnt/d/js/my_take/js_sandbox/app.js
```
Even though the autocompletion is working, I'm curious to know why this is happening. | As [Tae](https://vi.stackexchange.com/a/25532/22375) pointed, that's not really about vim, nor CoC.
This message is displayed (most probably) because you have no `.eslint` nor `.eslint.json`, which are needed for CoC to use the linter.
First, you'll need `eslint` if it's not already installed:
```
npm i -g eslint
`... |
25,503 | <p>I'm trying to implement a custom operator following <a href="http://vimdoc.sourceforge.net/htmldoc/map.html#:map-operator" rel="nofollow noreferrer">:h :map-operator</a>.
The operator works just fine but has the side effect of moving the cursor position!</p>
<p>For example the code defining the <code><F4></c... | [
{
"answer_id": 25504,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": -1,
"selected": false,
"text": "<p>This is known to be the normal behaviour. Don't try to be more Catholic than the Pope.</p>\n\n<p>And, by the way, the c... | 2020/05/24 | [
"https://vi.stackexchange.com/questions/25503",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15083/"
] | I'm trying to implement a custom operator following [:h :map-operator](http://vimdoc.sourceforge.net/htmldoc/map.html#:map-operator).
The operator works just fine but has the side effect of moving the cursor position!
For example the code defining the `<F4>` operator which counts spaced used in `:h :map-operator` (al... | There's no way to change this behavior for all operators (short of mapping them all.)
But you can make your `<F4>` keep the cursor position (and window view) by saving and restoring it before and after it's used.
Note that since `<F4>` ends in an operator-pending `g@` command, saving and restoring need to happen in d... |
25,518 | <p>A lot of times in vim I will copy-paste in some text, and it will not be at the correct level of indentation. Here is a sort of example:</p>
<p><a href="https://i.stack.imgur.com/Dgw1J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dgw1J.png" alt="enter image description here"></a></p>
<p>Is th... | [
{
"answer_id": 25519,
"author": "Biggybi",
"author_id": 22375,
"author_profile": "https://vi.stackexchange.com/users/22375",
"pm_score": 0,
"selected": false,
"text": "<p>To auto-indent you can use the <code>=</code> command.</p>\n\n<p>A few examples:</p>\n\n<ul>\n<li><code>gg=G</code> :... | 2020/05/25 | [
"https://vi.stackexchange.com/questions/25518",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | A lot of times in vim I will copy-paste in some text, and it will not be at the correct level of indentation. Here is a sort of example:
[](https://i.stack.imgur.com/Dgw1J.png)
Is there a command I can run on one or more lines (other than successivel... | The Python indentation code that ships with Vim makes decisions on some lines, such as increasing indent on lines that follow one that ends with `:` (which marks the start of a block) and also lines that are continuations (detecting whether the expression has open parens or braces that still need to be closed.) It also... |
25,534 | <p>I use neovim 0.4.3. When I open a large xml file (about 130-140k lines) syntax highlighting switches off with a message:</p>
<blockquote>
<p>'redrawtime' exceeded, syntax highlighting disabled</p>
</blockquote>
<p>If add this line to my config init.vim:</p>
<pre><code>set redrawtime=10000
</code></pre>
<p>The ... | [
{
"answer_id": 25537,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>Syntax for large files is consistently atrociously slow (especially when the language is hugely recursive à la ... | 2020/05/26 | [
"https://vi.stackexchange.com/questions/25534",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12297/"
] | I use neovim 0.4.3. When I open a large xml file (about 130-140k lines) syntax highlighting switches off with a message:
>
> 'redrawtime' exceeded, syntax highlighting disabled
>
>
>
If add this line to my config init.vim:
```
set redrawtime=10000
```
The syntax highlighting works but when I try to scroll up p... | Syntax for large files is consistently atrociously slow (especially when the language is hugely recursive à la lisp or xml: C fares much better because it has generally has more consecutive structures than recursive ones). I find it best to turn it off when viewing large documents.
I don’t have anything technical to b... |
25,541 | <p>What I'm trying to do is reformat some ugly JSON, replacing a pile of lines that are formatted:</p>
<pre><code>[whitespace][number],\n
</code></pre>
<p>for example:</p>
<pre><code> 5,
</code></pre>
<p>I have thousands of those lines, but don't know how to search and replace while retaining that number w... | [
{
"answer_id": 25537,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>Syntax for large files is consistently atrociously slow (especially when the language is hugely recursive à la ... | 2020/05/26 | [
"https://vi.stackexchange.com/questions/25541",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/23611/"
] | What I'm trying to do is reformat some ugly JSON, replacing a pile of lines that are formatted:
```
[whitespace][number],\n
```
for example:
```
5,
```
I have thousands of those lines, but don't know how to search and replace while retaining that number which differs with each line. Would someone be abl... | Syntax for large files is consistently atrociously slow (especially when the language is hugely recursive à la lisp or xml: C fares much better because it has generally has more consecutive structures than recursive ones). I find it best to turn it off when viewing large documents.
I don’t have anything technical to b... |
25,550 | <p>Whenever I make an update to the changelog of a Debian package, I have to update the signature with the correct date (well, it's not mandatory, but it's really nice to have).</p>
<p>The signature looks like this:</p>
<pre><code> -- Alexis Wilke <alexis@example.com> Tue, 26 May 2020 18:00:09 -0800
</code></p... | [
{
"answer_id": 25554,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 4,
"selected": true,
"text": "<p>Here's a simple, somewhat dumb solution, that doesn't require any plug-ins or anything.</p>\n\n<p>Just add this sni... | 2020/05/27 | [
"https://vi.stackexchange.com/questions/25550",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9276/"
] | Whenever I make an update to the changelog of a Debian package, I have to update the signature with the correct date (well, it's not mandatory, but it's really nice to have).
The signature looks like this:
```
-- Alexis Wilke <alexis@example.com> Tue, 26 May 2020 18:00:09 -0800
```
I'd like to have a command in [... | Here's a simple, somewhat dumb solution, that doesn't require any plug-ins or anything.
Just add this snippet to your vimrc:
```
iabbrev <expr> debsig
\ ' -- Alexis Wilke <alexis@example.com> '
\ . strftime('%a, %d %b %Y %H:%M:%S %z')
```
This creates an "abbreviation", which you can later invoke by typing... |
25,556 | <h1>The context</h1>
<p>Given a <code>{pattern}</code>, I can list the ocurrences of <code>{pattern}</code> in all files from a <code>{directory}</code>, in the quickfix window with the following command</p>
<pre><code>:chdir {directory}
:vimgrep /{pattern}/ **/*
:cwindow
</code></pre>
<h1>The question</h1>
<p>Give... | [
{
"answer_id": 25565,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 0,
"selected": false,
"text": "<p><strong>NOTE</strong> I just realized that this still won't accomplish what the OP is after. My function would ... | 2020/05/27 | [
"https://vi.stackexchange.com/questions/25556",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22995/"
] | The context
===========
Given a `{pattern}`, I can list the ocurrences of `{pattern}` in all files from a `{directory}`, in the quickfix window with the following command
```
:chdir {directory}
:vimgrep /{pattern}/ **/*
:cwindow
```
The question
============
Given a set of patterns, I want to list the ocurrences o... | Here's a potential solution. I'll use 4 test files. 3 contain the lines
```
foo
bar
baz
```
while the 4th contains any proper subset. The patterns of interest are the same 3 lines.
1. Run `:vimgrep` with *all* your patterns as concats. This gives the files that contain all the matches. For example,
```
:vimgrep /\... |
25,572 | <p>I'm using the indentLine plugin to display line indents with a continuos vertical line, and I'd like to set the color of that line to the same color of my comments.</p>
<p>To get the foreground color of my comments I listed all the color groups with <code>:hi</code>, checked what my colorscheme had set for the <cod... | [
{
"answer_id": 25575,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>I came up with</p>\n\n<pre><code>execute('highlight Comment')->split('\\n')->filter({i,v -> v =~# '^Co... | 2020/05/27 | [
"https://vi.stackexchange.com/questions/25572",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26480/"
] | I'm using the indentLine plugin to display line indents with a continuos vertical line, and I'd like to set the color of that line to the same color of my comments.
To get the foreground color of my comments I listed all the color groups with `:hi`, checked what my colorscheme had set for the `guifg` of the `Comments`... | There's `:h g:indentLine_defaultGroup` specially for this case. So it becomes simply
```
let g:indentLine_defaultGroup = 'Comment'
```
In principle, when you need to read in the color from an existing highlight group it's done like that:
```
let color = synIDattr(synIDtrans(hlID('Comment')), 'fg')
```
`hlID()` re... |
25,574 | <p>I have the following function to remove every trailing white space from the document, without changing my cursor position</p>
<pre><code>function! StripTrailingWhitespaces()
let l = line('.')
let c = col('.')
%s/\s\+$//e
call cursor(l, c)
endfunction
</code></pre>
<p>I'd like to change it so that it doesn'... | [
{
"answer_id": 25576,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": true,
"text": "<p>You can use the zero-width <code>\\%#</code> to match the cursor position, so something like</p>\n\n<pre><code>s... | 2020/05/27 | [
"https://vi.stackexchange.com/questions/25574",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26480/"
] | I have the following function to remove every trailing white space from the document, without changing my cursor position
```
function! StripTrailingWhitespaces()
let l = line('.')
let c = col('.')
%s/\s\+$//e
call cursor(l, c)
endfunction
```
I'd like to change it so that it doesn't remove any whitespace to... | You can use the zero-width `\%#` to match the cursor position, so something like
```
substitute/\%#\s\+$//e
```
on the current line, and your other pattern on the other lines:
```
global/\%#/substitute/\%#\s\+$//e
vglobal/\%#/substitute/\s\+$//e
```
Unfortunately, by the time either `:substitute` is happening, th... |
25,586 | <p>Here some <code>asciinema</code> <a href="https://asciinema.org/a/334917" rel="nofollow noreferrer">videos</a>, notice that in the videos, when I open another file (<code>plugins.vim</code>) in split using <code>Ctrl+v</code> it will create buffer tab named <code>plugins.vim</code> in the left, but when I close the ... | [
{
"answer_id": 25576,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": true,
"text": "<p>You can use the zero-width <code>\\%#</code> to match the cursor position, so something like</p>\n\n<pre><code>s... | 2020/05/27 | [
"https://vi.stackexchange.com/questions/25586",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29749/"
] | Here some `asciinema` [videos](https://asciinema.org/a/334917), notice that in the videos, when I open another file (`plugins.vim`) in split using `Ctrl+v` it will create buffer tab named `plugins.vim` in the left, but when I close the `plugins.vim` (on the right) it will not close the plugins.vim buffer tab on the lef... | You can use the zero-width `\%#` to match the cursor position, so something like
```
substitute/\%#\s\+$//e
```
on the current line, and your other pattern on the other lines:
```
global/\%#/substitute/\%#\s\+$//e
vglobal/\%#/substitute/\s\+$//e
```
Unfortunately, by the time either `:substitute` is happening, th... |
25,603 | <p>I want to use block cursor for normal mode, bar cursor for insert mode in both vim and bash vi mode, a minimal setting can look like this:</p>
<pre><code>vimrc
--------
let &t_SI = "\e[5 q"
let &t_EI = "\e[2 q"
.inputrc
--------
set vi-cmd-mode-string \1\e[2 q\2(c)
set vi-ins-mode-string \1\e[5 q\2(i)
</c... | [
{
"answer_id": 25605,
"author": "Biggybi",
"author_id": 22375,
"author_profile": "https://vi.stackexchange.com/users/22375",
"pm_score": 0,
"selected": false,
"text": "<p>I use this half-working solution, from <a href=\"https://vim.fandom.com/wiki/Configuring_the_cursor\" rel=\"nofollow ... | 2020/05/28 | [
"https://vi.stackexchange.com/questions/25603",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5017/"
] | I want to use block cursor for normal mode, bar cursor for insert mode in both vim and bash vi mode, a minimal setting can look like this:
```
vimrc
--------
let &t_SI = "\e[5 q"
let &t_EI = "\e[2 q"
.inputrc
--------
set vi-cmd-mode-string \1\e[2 q\2(c)
set vi-ins-mode-string \1\e[5 q\2(i)
```
They work fine on th... | Bash 4.4 provide `PS0`:
```
'PS0'
The value of this parameter is expanded like PS1 and displayed by
interactive shells after reading a command and before the command
is executed.
```
We will use it to restore cursor to block before executing a command, add this to your bashrc:
```
PS0='\[\e[2 q\]'
`... |
25,615 | <p>I've written some Vimscript code* in which it's convenient to have a set of shared color names. To use the names, so far I've had to rely on code like this:</p>
<pre><code>execute 'source ' . expand('<sfile>:p:h:h') . '/plugin/colornames.vim'
</code></pre>
<p>This means that the scripts have to know somethin... | [
{
"answer_id": 25617,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<p>Well, such sort of questions tends to be too vague. But here are a couple of thoughts.</p>\n\n<ol>\n<li><p>If it's solel... | 2020/05/29 | [
"https://vi.stackexchange.com/questions/25615",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1363/"
] | I've written some Vimscript code\* in which it's convenient to have a set of shared color names. To use the names, so far I've had to rely on code like this:
```
execute 'source ' . expand('<sfile>:p:h:h') . '/plugin/colornames.vim'
```
This means that the scripts have to know something about where the names are def... | Looks like you need a library plugin that other plugins can depend on.
So far the best way to have library plugins is through autoload plugin files. These files are lazily loaded, they are loaded on demand.
EDIT: IOW, the following will be enough
```
" library plugin: autoload/colorname.vim
let g:colornames#red = 'r... |
25,638 | <p>I've written the following python script to be called with a shortcut in vim:</p>
<pre><code>:imap <c-t> <c-r>=system('./script.py')<cr>
</code></pre>
<p>It works, and it's quite cool. However, I'd like to understand <strong>why</strong> it works. For example, what are the following items for:</p... | [
{
"answer_id": 25640,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 2,
"selected": false,
"text": "<p>The <code><C-r></code> keystroke in Insert mode is used to insert the contents of a register, so <code><C... | 2020/05/31 | [
"https://vi.stackexchange.com/questions/25638",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | I've written the following python script to be called with a shortcut in vim:
```
:imap <c-t> <c-r>=system('./script.py')<cr>
```
It works, and it's quite cool. However, I'd like to understand **why** it works. For example, what are the following items for:
* `<c-r>`
* `=`
* `system('...')`
Why not just do the sam... | It comes down to two things: how we get to where we can call an external command and where the output of that external command goes.
I'm going to just use a simple external command, `uname`, rather than a python script but the concepts are the same.
Let's try:
```
imap <c-t> <c-o>:!uname<cr>
```
Well, this runs ... |
25,649 | <p>There are two features related to indenting that I find very helpful in Textmate, and I'm looking to find the closest thing in vim. First, I can <kbd>tab</kbd> to the correct level of indentation, especially in python. For example:</p>
<p><a href="https://i.stack.imgur.com/9uF1Z.png" rel="nofollow noreferrer"><img ... | [
{
"answer_id": 25651,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<ol>\n<li><p>The indentation level is automatically adjust (given that you have <code>set autoindent</code> and such) upon ... | 2020/05/31 | [
"https://vi.stackexchange.com/questions/25649",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | There are two features related to indenting that I find very helpful in Textmate, and I'm looking to find the closest thing in vim. First, I can `tab` to the correct level of indentation, especially in python. For example:
[](https://i.stack.imgur.com... | Judging from the images, you want 4 spaces for `tab`.
Put the following in your `.vimrc`:
```
set tabstop=4 " Redefine tab as four spaces
set softtabstop=4 " Number of spaces in tab when editing
set shiftwidth=4 " To change the number of space characters... |
25,659 | <h1>The context</h1>
<p>I store all my shell scripts insde the <code>$HOME/.bin</code> directory. Because of this, I've been looking for a way to set the <code>sh</code> filetype whenever I open a file located in that directory. So, I've created the following autocommand</p>
<pre><code>$ cat ~/.vim/ftdetect/sh.vim
a... | [
{
"answer_id": 25660,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 3,
"selected": true,
"text": "<p>Your problem is due to <code>:setf[iletype]</code> command. From <code>:h :setf</code></p>\n\n<blockquote>\n <p>Set the ... | 2020/05/31 | [
"https://vi.stackexchange.com/questions/25659",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22995/"
] | The context
===========
I store all my shell scripts insde the `$HOME/.bin` directory. Because of this, I've been looking for a way to set the `sh` filetype whenever I open a file located in that directory. So, I've created the following autocommand
```
$ cat ~/.vim/ftdetect/sh.vim
au BufNewFile,BufRead $HOME/.bin/* ... | Your problem is due to `:setf[iletype]` command. From `:h :setf`
>
> Set the 'filetype' option to {filetype}, but **only if not done yet in a sequence of (nested) autocommands**.
>
>
>
As your `autocmd` is surely run after all the bundled stuff, the filetype for the current buffer might be set already. Then your ... |
25,665 | <p>When I want to share my markdown file to others, I would like to join lines or format lines for all paragraphs in my file quickly.</p>
<h2>File in formatted version:</h2>
<pre><code># head 1
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna a... | [
{
"answer_id": 25666,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 1,
"selected": false,
"text": "<p>It would be really hard to do this for a real world markdown files with regards to all edge cases (tables, code block... | 2020/06/01 | [
"https://vi.stackexchange.com/questions/25665",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15292/"
] | When I want to share my markdown file to others, I would like to join lines or format lines for all paragraphs in my file quickly.
File in formatted version:
--------------------------
```
# head 1
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore mag... | It would be really hard to do this for a real world markdown files with regards to all edge cases (tables, code blocks, list items, headers etc).
But for example given you can try following `:h :global` commands:
1. `:g/^\S.*\n\S/normal! vipJ`
2. `:g/^\S/normal! gww`
Join with `:g/^\S.*\n\S/normal! vipJ`
===========... |
25,671 | <h1>The context</h1>
<p>I've the following options in my <code>vimrc</code></p>
<pre><code>set formatoptions=cnroqj
set textwidth=80
</code></pre>
<p>When editing <code>tex</code> files, lines whose content is longer than <code>&textwidth</code> is
splitted and formatted as it follows</p>
<pre><code>% - foo foo... | [
{
"answer_id": 25674,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 2,
"selected": false,
"text": "<p>Add this to your <code>after/ftplugin/c.vim</code> or <code>after/ftplugin/cpp.vim</code>:</p>\n\n<pre><code>let &... | 2020/06/01 | [
"https://vi.stackexchange.com/questions/25671",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22995/"
] | The context
===========
I've the following options in my `vimrc`
```
set formatoptions=cnroqj
set textwidth=80
```
When editing `tex` files, lines whose content is longer than `&textwidth` is
splitted and formatted as it follows
```
% - foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
% ... | Add this to your `after/ftplugin/c.vim` or `after/ftplugin/cpp.vim`:
```
let &l:formatlistpat .= '\|^\s*-\s*'
```
It tell vim to recognize `-` as numbered list.
set them in `vimrc` is a mistake, this option is local to buffer. You can use `:verbose setlocal formatlistpat` to check if it's set properly.
Result:
``... |
25,690 | <p>Say that I have a java class with these fields(included only few fields, but the idea is that there could many more fields).</p>
<pre class="lang-java prettyprint-override"><code>public class Entity {
private String firstName;
private String lastName;
private String costPrice;
private String sel... | [
{
"answer_id": 25691,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 3,
"selected": true,
"text": "<p>It can be done with a substitution with a sub-replace-expression:</p>\n\n<pre><code>:%s/\\ze\\(\\s*\\)private \\w\\+... | 2020/06/02 | [
"https://vi.stackexchange.com/questions/25690",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29621/"
] | Say that I have a java class with these fields(included only few fields, but the idea is that there could many more fields).
```java
public class Entity {
private String firstName;
private String lastName;
private String costPrice;
private String sellingPriceForSomeItem;
}
```
Now I need to conve... | It can be done with a substitution with a sub-replace-expression:
```
:%s/\ze\(\s*\)private \w\+ \(\w\+\)/\=submatch(1).'@Column(name="'.substitute(submatch(2), '\u', '_\l&', 'g').'");'."\r"
```
For more help see:
```
:h :s
:h sub-replace-expression
:h \zs
:h submatch()
:h substitute()
:h /\u
:h sub-replace-special... |
25,703 | <p>Can Vim kill its parent process?</p>
<p>I know a child could not kill a parent process in Linux, but how can I achieve <code>:!exit</code> in Vim?</p>
<p>I would like to exit directly from Vim out of the terminal without semi-step of exiting Vim first. How can I achieve that?</p>
| [
{
"answer_id": 25691,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 3,
"selected": true,
"text": "<p>It can be done with a substitution with a sub-replace-expression:</p>\n\n<pre><code>:%s/\\ze\\(\\s*\\)private \\w\\+... | 2020/06/02 | [
"https://vi.stackexchange.com/questions/25703",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26386/"
] | Can Vim kill its parent process?
I know a child could not kill a parent process in Linux, but how can I achieve `:!exit` in Vim?
I would like to exit directly from Vim out of the terminal without semi-step of exiting Vim first. How can I achieve that? | It can be done with a substitution with a sub-replace-expression:
```
:%s/\ze\(\s*\)private \w\+ \(\w\+\)/\=submatch(1).'@Column(name="'.substitute(submatch(2), '\u', '_\l&', 'g').'");'."\r"
```
For more help see:
```
:h :s
:h sub-replace-expression
:h \zs
:h submatch()
:h substitute()
:h /\u
:h sub-replace-special... |
25,736 | <p>Assume I am using some plugin function
e.g. For vim-plug, I put this code in my .vimrc at the end</p>
<pre><code>call plug#end()
</code></pre>
<p>How to find out where is this function <code>plug#end()</code> is located? from vimrc directly itself</p>
<p>Currently I do following</p>
<pre><code>$ cd ~/.vim/plugge... | [
{
"answer_id": 25737,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 2,
"selected": false,
"text": "<p>This is a <code>:h autoload</code> function, it's name is a hint on where it's defined.</p>\n\n<p><code>plug</code> is... | 2020/06/04 | [
"https://vi.stackexchange.com/questions/25736",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20720/"
] | Assume I am using some plugin function
e.g. For vim-plug, I put this code in my .vimrc at the end
```
call plug#end()
```
How to find out where is this function `plug#end()` is located? from vimrc directly itself
Currently I do following
```
$ cd ~/.vim/plugged
$ grep -nrs 'somefunction' .
```
Doing this every t... | There are several approaches:
### Open the file
As others have explained, unless the author doesn't follow conventions, the function `scope1#scope2#...#scopen#funcname()` is supposed to be defined in `{rtp}/autoload/scope1/scope2/.../scopen.vim` file.
Where `{rtp}` designates any directory in [`'runtimepath'`](http:... |
25,741 | <p>I'm trying to improve my ability to move around inside files in vim, especially using built-in mappings/commands. I edit a lot of different types, including shell, markdown, Python, etc. I'm familiar with the <code>{</code> and <code>}</code> keys, which move between paragraphs (in fact, anything with a blank lines ... | [
{
"answer_id": 25742,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>The initial usage of these mapping is to navigate between functions in C files as said in <a href=\"http://vimhelp.appspo... | 2020/06/04 | [
"https://vi.stackexchange.com/questions/25741",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/91/"
] | I'm trying to improve my ability to move around inside files in vim, especially using built-in mappings/commands. I edit a lot of different types, including shell, markdown, Python, etc. I'm familiar with the `{` and `}` keys, which move between paragraphs (in fact, anything with a blank lines separating them, which is... | The initial usage of these mapping is to navigate between functions in C files as said in [`:h section`](http://vimhelp.appspot.com/motion.txt.html#section) (note it's not the same topic as [`:h 'sections'`](http://vimhelp.appspot.com/options.txt.html#%27sections%27) that you linked in your question)
>
>
> ```
> The... |
25,757 | <p>I am a new neovim user. I am currently on MacOS, and using iTerm as my terminal emulator. I am using Neovim 0.4.3.</p>
<p>I would like to configure my neovim in such a way that the cursor in insert mode is a bit fat. Right now its very thin. If that cannot be done, can I somehow configure Neovim in such a way that ... | [
{
"answer_id": 30774,
"author": "network_dios",
"author_id": 34246,
"author_profile": "https://vi.stackexchange.com/users/34246",
"pm_score": 3,
"selected": false,
"text": "<p>enter this command in vim to use block cursor in insert mode:</p>\n<pre><code>:set guicursor=i:block\n</code></p... | 2020/06/05 | [
"https://vi.stackexchange.com/questions/25757",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29955/"
] | I am a new neovim user. I am currently on MacOS, and using iTerm as my terminal emulator. I am using Neovim 0.4.3.
I would like to configure my neovim in such a way that the cursor in insert mode is a bit fat. Right now its very thin. If that cannot be done, can I somehow configure Neovim in such a way that I can use ... | enter this command in vim to use block cursor in insert mode:
```
:set guicursor=i:block
``` |
25,764 | <p>I have recently found out that <kbd>Ctrl</kbd>+<kbd>C</kbd> can be used instead of <kbd>Esc</kbd> in certain instances. Getting out of insert mode for instance. Other things can only exclusively exited using escape.<br>
So my question is, is it possible to completely replace the escape key with <kbd>Ctrl</kbd>+<kbd>... | [
{
"answer_id": 25765,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 4,
"selected": true,
"text": "<p>There are some (often subtle) differences between <kbd>Esc</kbd> and <kbd>CTRL</kbd>+<kbd>C</kbd> to leave Insert m... | 2020/06/06 | [
"https://vi.stackexchange.com/questions/25764",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/23073/"
] | I have recently found out that `Ctrl`+`C` can be used instead of `Esc` in certain instances. Getting out of insert mode for instance. Other things can only exclusively exited using escape.
So my question is, is it possible to completely replace the escape key with `Ctrl`+`C`? So that it works exactly the same? | There are some (often subtle) differences between `Esc` and `CTRL`+`C` to leave Insert mode.
For instance, [`:help i_CTRL-C`](https://vimhelp.org/insert.txt.html#i_CTRL-C) mentions some of them:
>
> `CTRL-C`: Quit insert mode, go back to Normal mode. Do not check for abbreviations. Does not trigger the `InsertLeave`... |
25,781 | <p>I can do this for markdown's tab-based code blocks with <code>mkdCode</code> color group. So my question is if it's possible to do the same for fenced once?</p>
<p>I use <a href="https://github.com/plasticboy/vim-markdown" rel="nofollow noreferrer">plasticboy/vim-markdown</a> plugin.</p>
<p>Here's a minimal vim co... | [
{
"answer_id": 25782,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 2,
"selected": false,
"text": "<p>What you're seeing here is vim-markdown's support for highlighting embedded languages in fenced code blocks.</p>\n... | 2020/06/07 | [
"https://vi.stackexchange.com/questions/25781",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11917/"
] | I can do this for markdown's tab-based code blocks with `mkdCode` color group. So my question is if it's possible to do the same for fenced once?
I use [plasticboy/vim-markdown](https://github.com/plasticboy/vim-markdown) plugin.
Here's a minimal vim config to reproduce the behaviour `~/.config/nvim/test-init.vim`:
... | I use a technique I picked up on [reddit](https://www.reddit.com/r/vim/comments/fob3sg/different_background_color_for_markdown_code/) from */u/fob3sg*:
```
function! ColorCodeBlocks() abort " {{{1
setlocal signcolumn=no
sign define codeblock linehl=codeBlockBackground
augroup code_block_background
autocmd!... |
25,793 | <p>The main question is in the title, that is, I have a function, which is invoked by the user and it should 'remember' necessary stuff between invocations, so the next time the user calls it (like, presses the mapping) the function should be aware of certain data.</p>
<p>So if anyone could suggest how can I better ac... | [
{
"answer_id": 25794,
"author": "Ralf",
"author_id": 19763,
"author_profile": "https://vi.stackexchange.com/users/19763",
"pm_score": 2,
"selected": false,
"text": "<p>This is what happens:</p>\n\n<ul>\n<li><code>i</code> - enter insert mode</li>\n<li><code>a</code> - call func -> var = ... | 2020/06/08 | [
"https://vi.stackexchange.com/questions/25793",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2798/"
] | The main question is in the title, that is, I have a function, which is invoked by the user and it should 'remember' necessary stuff between invocations, so the next time the user calls it (like, presses the mapping) the function should be aware of certain data.
So if anyone could suggest how can I better achieve this... | When I need to do that, I do it within the function: I assume that I'm not writing a re-entrant function. I prefer the mapping to be as simple as possible.
Also, I use:
* script local variables (`s:`) to store *global* data -- i.e. independently of the current buffer.
* buffer local variables (`b:`), or a script loc... |
25,804 | <p>I'm using vim to edit my latex files and I'm trying to automate some aspects of it.</p>
<p>I want a command that inserts the following:</p>
<pre class="lang-latex prettyprint-override"><code>\begin{env}
\end{env}
</code></pre>
<p>Where <code>env</code> is an user input. So I came up whit this</p>
<pre><code>fun... | [
{
"answer_id": 25805,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p><code>a:</code> is for arguments. Don't use any prefix for local variables.</p>\n\n<p>PS: you'll have a better exper... | 2020/06/09 | [
"https://vi.stackexchange.com/questions/25804",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30004/"
] | I'm using vim to edit my latex files and I'm trying to automate some aspects of it.
I want a command that inserts the following:
```latex
\begin{env}
\end{env}
```
Where `env` is an user input. So I came up whit this
```
function Begin()
call inputsave()
let env = input("env = ")
call inputrestore()
e... | There were two problems:
1. Don't use`a:` for any local variables, as **Luc Hermitte** pointed out.
2. When using the command `execute` you should use [|expr-string|](http://vimdoc.sourceforge.net/htmldoc/eval.html#expr-string) and to insert `\` it should be `\\`.
And so, the right way of writing it is like this
```... |
25,812 | <p>I would like to do the following remap:</p>
<pre><code>:inoremap <Option-Space> &nbsp;
</code></pre>
<p>In other words, pressing option-space would add an html-escaped space. How could this be done, so that it only works when <code>ft=html</code> ?</p>
| [
{
"answer_id": 25805,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p><code>a:</code> is for arguments. Don't use any prefix for local variables.</p>\n\n<p>PS: you'll have a better exper... | 2020/06/09 | [
"https://vi.stackexchange.com/questions/25812",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | I would like to do the following remap:
```
:inoremap <Option-Space>
```
In other words, pressing option-space would add an html-escaped space. How could this be done, so that it only works when `ft=html` ? | There were two problems:
1. Don't use`a:` for any local variables, as **Luc Hermitte** pointed out.
2. When using the command `execute` you should use [|expr-string|](http://vimdoc.sourceforge.net/htmldoc/eval.html#expr-string) and to insert `\` it should be `\\`.
And so, the right way of writing it is like this
```... |
25,824 | <p>Often I will do a search to find things in Vim, such as:</p>
<pre><code>/-some-regex-here
</code></pre>
<p>And after seeing what if grabs and iterating through a few of the results, I want to do a find-replace. Is there a way to convert the <code>/</code> to a <code>:</code> command? Or do I have to <code>esc</cod... | [
{
"answer_id": 25826,
"author": "Biggybi",
"author_id": 22375,
"author_profile": "https://vi.stackexchange.com/users/22375",
"pm_score": 5,
"selected": true,
"text": "<p>In command-line, you can use <code>ctrl-r</code> (see <code>:h c_ctrl-r</code>) to start inserting the content of a re... | 2020/06/10 | [
"https://vi.stackexchange.com/questions/25824",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | Often I will do a search to find things in Vim, such as:
```
/-some-regex-here
```
And after seeing what if grabs and iterating through a few of the results, I want to do a find-replace. Is there a way to convert the `/` to a `:` command? Or do I have to `esc` and then press `:` and re-type (or copy-paste) the comma... | In command-line, you can use `ctrl-r` (see `:h c_ctrl-r`) to start inserting the content of a register.
In your case, you could paste the content of the last search with:
```
<c-r>/
```
---
Another way would be to use `:h incsearch` to show the matches as you type your search (in a `/` search, or a `:s` command, a... |
25,911 | <p>I would like to debug functions a bit more easily. Instead of running them and having to do:</p>
<pre><code>:10 messages
</code></pre>
<p>To actually just have a <code>vim.log</code> file opened and tail -f'ed so I can see the output while it's running, without having to keep going into and out of messages and suc... | [
{
"answer_id": 25878,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 3,
"selected": false,
"text": "<p>My solution is to use everything vim offers me: HJKL, /, FftT, {n}w/b/e, ^, $, %, [], ][, [{, and also arrow keys, c... | 2020/06/13 | [
"https://vi.stackexchange.com/questions/25911",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | I would like to debug functions a bit more easily. Instead of running them and having to do:
```
:10 messages
```
To actually just have a `vim.log` file opened and tail -f'ed so I can see the output while it's running, without having to keep going into and out of messages and such.
Is there a way to do this? For ex... | I believe that the art of Vim has nothing to do with disallowing any tools available for you, but rather finding the best (i.e., most efficient) path to altering text. The truth is that sometimes the arrow keys really are the most efficient. This is particularly true in cases where several small insert-mode changes nee... |
25,913 | <p>When editing <code>c</code> and <code>cpp</code> files, this is the behavior I want to achieve:</p>
<ul>
<li>When typing a comment line of the form <code>// Line...</code>, pressing <code><CR></code> <strong>should not</strong> add the comment header <code>//</code> in the next line.</li>
<li>However, if whil... | [
{
"answer_id": 25918,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 2,
"selected": false,
"text": "<p>The idea of removing <code>://</code> from <code>'comments'</code> can be made to work, but instead of leaving Ins... | 2020/06/13 | [
"https://vi.stackexchange.com/questions/25913",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29925/"
] | When editing `c` and `cpp` files, this is the behavior I want to achieve:
* When typing a comment line of the form `// Line...`, pressing `<CR>` **should not** add the comment header `//` in the next line.
* However, if while typing the `// Line...`, the line length exceeds the `tw` I set, auto wrap should break the l... | IMO, it's easier to do simply:
```
inoremap <expr><CR> getline('.') =~# '^\s*//' ? '<C-O>o' : '<CR>'
```
Perhaps, this mapping (with `<buffer>` modifier, of course) should be added to `after/ftplugin/c.vim` and not to the global `.vimrc` |