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 |
|---|---|---|---|---|---|---|
21,593 | <p>Is there an insert and append operation that can be followed by a text-object? I've found this plugins: </p>
<p><a href="https://github.com/deris/vim-operator-insert" rel="nofollow noreferrer">https://github.com/deris/vim-operator-insert</a>
<a href="https://github.com/mwgkgk/vim-operator-insert" rel="nofollow nore... | [
{
"answer_id": 21599,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 2,
"selected": false,
"text": "<p>You can come up with something relatively simple, following and tinkering what vim has described in <code>:h :map-ope... | 2019/10/21 | [
"https://vi.stackexchange.com/questions/21593",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15345/"
] | Is there an insert and append operation that can be followed by a text-object? I've found this plugins:
<https://github.com/deris/vim-operator-insert>
<https://github.com/mwgkgk/vim-operator-insert>
But they seem to be unmaintained. I think these operators are useful as they are easily repeatable, if you `gaiw` (go ... | You can come up with something relatively simple, following and tinkering what vim has described in `:h :map-operator`:
As an example I came up with in about 15 minutes of experimenting:
```
nmap <silent> gi :set opfunc=InsertToTextObject<CR>g@
vmap <silent> gi :<C-U>call InsertToTextObject(visualmode(), 1)<CR>
nmap... |
21,615 | <p>I need to search for a certain word, and if it occurs, move it to the end of the line where it occured. For instance, search for "bugs".</p>
<p>Welcome! Meta Stack Exchange is intended for bugs, features, and discussions </p>
<p>Turns into:</p>
<p>Welcome! Meta Stack Exchange is intended for, features, and discus... | [
{
"answer_id": 21616,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<pre><code>:g/ \\?\\<bugs\\>/normal! dgn$p\n</code></pre>\n\n<p>Explanation:</p>\n\n<p><code>:g/.../</code> for all l... | 2019/10/23 | [
"https://vi.stackexchange.com/questions/21615",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25335/"
] | I need to search for a certain word, and if it occurs, move it to the end of the line where it occured. For instance, search for "bugs".
Welcome! Meta Stack Exchange is intended for bugs, features, and discussions
Turns into:
Welcome! Meta Stack Exchange is intended for, features, and discussions bugs | ```
:g/ \?\<bugs\>/normal! dgn$p
```
Explanation:
`:g/.../` for all lines matching a pattern
`\?\<bugs\>` an optional space followed by "bugs" (a whole word)
`normal! dgn$p` delete last match; go to end of line; put last match there |
21,622 | <p>This question may have an obvious answer that I'm missing, but how can I easily tell how many of a character, in this case " , " are in a line, or a specified string using vimscript?</p>
| [
{
"answer_id": 21623,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 3,
"selected": true,
"text": "<p>VimScript does not have a special character type. In fact, you always <code>count()</code> for substrings (or items in li... | 2019/10/23 | [
"https://vi.stackexchange.com/questions/21622",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/23679/"
] | This question may have an obvious answer that I'm missing, but how can I easily tell how many of a character, in this case " , " are in a line, or a specified string using vimscript? | VimScript does not have a special character type. In fact, you always `count()` for substrings (or items in list):
```
:echo count(getline("."), ",")
``` |
21,633 | <p><code>:help change.txt</code> mentions 2- or 3- letter :substitute commands, such as <code>:sg</code>, <code>:sgn</code> and so on. I am guessing that these <code>:s[xx]</code> correspond to flags, but am not sure how to use them. </p>
<p>For example, I would think that <code>:%sg/foo/bar</code> would substitute al... | [
{
"answer_id": 21634,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>Actually the behavior of the substitution command <code>:s</code> if you don't provide any arguments is to repeat the las... | 2019/10/24 | [
"https://vi.stackexchange.com/questions/21633",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21495/"
] | `:help change.txt` mentions 2- or 3- letter :substitute commands, such as `:sg`, `:sgn` and so on. I am guessing that these `:s[xx]` correspond to flags, but am not sure how to use them.
For example, I would think that `:%sg/foo/bar` would substitute all matches of `foo`, including multiple occurences on the same lin... | Actually the behavior of the substitution command `:s` if you don't provide any arguments is to repeat the last substitution you did. So if you have a line
```
foo Foo foF
```
And use `:s/f/X/` you will get
```
Xoo Foo foF
```
Now if you use `:s` (without any argument) you will reapply the same command and get as... |
21,656 | <p>I'm trying to create a zsh alias that will start vim and search backwards from the end of the file for a given string. I learnt about <code>+normal</code> and can do something like this to start vim at the end of the file:</p>
<pre><code>vim "+normal G" log
</code></pre>
<p>But I'm not able to follow that by an in... | [
{
"answer_id": 21659,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 3,
"selected": true,
"text": "<p>I would recommend breaking this up into multiple commands. This works for me:</p>\n\n<pre><code>vim log -c \"normal G... | 2019/10/25 | [
"https://vi.stackexchange.com/questions/21656",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25391/"
] | I'm trying to create a zsh alias that will start vim and search backwards from the end of the file for a given string. I learnt about `+normal` and can do something like this to start vim at the end of the file:
```
vim "+normal G" log
```
But I'm not able to follow that by an incremental search. The following *does... | I would recommend breaking this up into multiple commands. This works for me:
```
vim log -c "normal G" -c "?TEST"
```
This doesn't need a carriage return since `"?test"` is treated as an ex command, not a normal mode command. |
21,682 | <p>I have a file, containing some lines like this: <code>aaa bbb (ccc) ddd</code>.</p>
<p>Now I want to replace the pair of brackets by a pair of square brackets to make this line become <code>aaa bbb [ccc] ddd</code>.</p>
<p>I think that <code>\ze</code> and/or <code>\zs</code> might be used but I don't know how.</p... | [
{
"answer_id": 21683,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 3,
"selected": false,
"text": "<p>You can use this simple <code>:s</code> command (or better two :))</p>\n\n<pre><code>:s/(/[/g\n:s/)/]/g\n</code>... | 2019/10/27 | [
"https://vi.stackexchange.com/questions/21682",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10003/"
] | I have a file, containing some lines like this: `aaa bbb (ccc) ddd`.
Now I want to replace the pair of brackets by a pair of square brackets to make this line become `aaa bbb [ccc] ddd`.
I think that `\ze` and/or `\zs` might be used but I don't know how. | You can do it in a single substitute command like this
```
:s/(\(.*\))/[\1]/
```
The `\(` and `\)` mark the regex subexpression that matches everything *inside* the ( and ) in the input line. In the replacement, the `\1` stands for whatever the *first* (in this case the *only*) marked subexpression matched.
In word... |
21,687 | <p>I have python examples in a markdown file in a code fence (e.g. when I convert a jupyter notebook into a markdown document). These snippets sometimes have code comments in them starting with #. The markdown folder, however, recognizes these as headings, so folds them as chapters. This, in turn, messes up the documen... | [
{
"answer_id": 21689,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 2,
"selected": false,
"text": "<p>It would be really hard to do reliably.</p>\n\n<p>Basically, if you brave enough, check what current markdown plugin ... | 2019/10/28 | [
"https://vi.stackexchange.com/questions/21687",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14718/"
] | I have python examples in a markdown file in a code fence (e.g. when I convert a jupyter notebook into a markdown document). These snippets sometimes have code comments in them starting with #. The markdown folder, however, recognizes these as headings, so folds them as chapters. This, in turn, messes up the document o... | It would be really hard to do reliably.
Basically, if you brave enough, check what current markdown plugin uses for folding and try to rewrite it:
1. `:set foldmethod?` to find out if it is `expr` or not
2. `:set foldexpr?` to find out what is the function name `expr` uses
3. create your own `MarkdownFold()` function... |
21,692 | <p>I have a <code>$HOME\_vimrc</code> present, but it doesn't show up in the output of <code>:scriptnames</code>. And when I run <code>gvim -V</code>, it reports:</p>
<pre><code>could not source "$HOME\_vimrc"
</code></pre>
<p>The only thing in my <code>$HOME\_vimrc</code> is the following line:</p>
<pre><code>set p... | [
{
"answer_id": 21705,
"author": "William L.",
"author_id": 25430,
"author_profile": "https://vi.stackexchange.com/users/25430",
"pm_score": 2,
"selected": false,
"text": "<p>The solution was to define <code>$HOME</code> as a Windows environment variable.</p>\n\n<p>Once I did that and res... | 2019/10/28 | [
"https://vi.stackexchange.com/questions/21692",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25430/"
] | I have a `$HOME\_vimrc` present, but it doesn't show up in the output of `:scriptnames`. And when I run `gvim -V`, it reports:
```
could not source "$HOME\_vimrc"
```
The only thing in my `$HOME\_vimrc` is the following line:
```
set packpath+=C:\Users\username\vimfiles
```
In case there was something wrong with ... | The solution was to define `$HOME` as a Windows environment variable.
Once I did that and restarted gVim, it read my `~\_vimrc` and also sourced my native Vim 8.1 packages correctly.
Source: [this answer](https://stackoverflow.com/questions/58598312/vim-gvim-8-1-on-windows-10-wont-source-home-vimrc) at Stack Overflow... |
21,694 | <p>Suppose we have a file:</p>
<pre><code>1. un
2. deux
3. trois
4. quatre
5. cinq
6. six
7. sept
8. huit
9. neuf
10. dix
</code></pre>
<p>I want to create a window that shows only lines 5--10 and nothing else. Modifying them should modify the original lines (hence it refers to the same buffer). Ideally, adding and r... | [
{
"answer_id": 21695,
"author": "Ayrat",
"author_id": 12891,
"author_profile": "https://vi.stackexchange.com/users/12891",
"pm_score": 1,
"selected": false,
"text": "<p>Seems impossible, but there is a workaround. Create a new window and <em>fold</em> (using <code>zf</code>) unnecessary ... | 2019/10/28 | [
"https://vi.stackexchange.com/questions/21694",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12891/"
] | Suppose we have a file:
```
1. un
2. deux
3. trois
4. quatre
5. cinq
6. six
7. sept
8. huit
9. neuf
10. dix
```
I want to create a window that shows only lines 5--10 and nothing else. Modifying them should modify the original lines (hence it refers to the same buffer). Ideally, adding and removing lines would add an... | The [NrrwRgn plugin](https://www.vim.org/scripts/script.php?script_id=3075) (the plugin page has links to alternative plugins) comes closest to your use case: As it mirrors part of the buffer into a separate scratch buffer (and can sync it back to the original), you can treat it like any regular Vim buffer, and edit aw... |
21,698 | <h2>Input</h2>
<ul>
<li>Every line is separated into 8 parts by semicolons</li>
<li>Every part can include words,numbers,space etc.</li>
</ul>
<h2>Output</h2>
<p>I am trying to replace the space in the 6th part with a semicolon, thus separating the line again, making the total number of parts 9.</p>
<h2>Example</h2... | [
{
"answer_id": 21699,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": true,
"text": "<h2><code>substitute</code></h2>\n\n<p>I was able to do this with just</p>\n\n<pre><code>%s/\\(.\\{-\\};\\)\\{5\\}[... | 2019/10/29 | [
"https://vi.stackexchange.com/questions/21698",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25440/"
] | Input
-----
* Every line is separated into 8 parts by semicolons
* Every part can include words,numbers,space etc.
Output
------
I am trying to replace the space in the 6th part with a semicolon, thus separating the line again, making the total number of parts 9.
Example
-------
```
1;30;68;Az LEMda;Ads Awdsâ;1 Be... | `substitute`
------------
I was able to do this with just
```
%s/\(.\{-\};\)\{5\}[^ ]*\zs /;/
```
(Aside: `set hlsearch incsearch` really helps here if you don't use them regularly. I basically did a `/`-search and tooled with the regex until it looked right—based on the highlighted feedback—and then did `:%s//;/` ... |
21,708 | <p>How do I disable vim from producing backup files? Like file~ do not generate. Should I do that by modifying <code>/etc/vimrc</code>?</p>
<p>I added <code>set nobackup</code> to <code>/etc/vimrc</code>, but when I looked at the distributed file system log, the backup file was still generated but it was then deleted.... | [
{
"answer_id": 21709,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 5,
"selected": true,
"text": "<p>Try adding:</p>\n\n<p><code>set nobackup nowritebackup</code></p>\n\n<p>to your vimrc.</p>\n\n<p>UPDATE with regards t... | 2019/10/30 | [
"https://vi.stackexchange.com/questions/21708",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25458/"
] | How do I disable vim from producing backup files? Like file~ do not generate. Should I do that by modifying `/etc/vimrc`?
I added `set nobackup` to `/etc/vimrc`, but when I looked at the distributed file system log, the backup file was still generated but it was then deleted. | Try adding:
`set nobackup nowritebackup`
to your vimrc.
UPDATE with regards to [Jason Lefler's answer](https://vi.stackexchange.com/a/21714/9333)
If you want to prevent your backup/undo/swap files to be created next to your edited file consider setting directories for them:
```
let &directory = expand('~/.vimdata/... |
21,712 | <p>Using the <a href="https://github.com/SirVer/ultisnips" rel="nofollow noreferrer">snippets</a> plugin I'm able to get:</p>
<pre><code>class MyClasnippets(object):
"""Docstring for MyClasnippets. """
def __init__(self):
"""TODO: to be defined. """
</code></pre>
<p>from just typing <code>class</cod... | [
{
"answer_id": 24737,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 0,
"selected": false,
"text": "<p>Assuming you're talking about the <code>__init__</code> docstring...</p>\n\n<p>Just follow the <code>triple_quotes()<... | 2019/10/30 | [
"https://vi.stackexchange.com/questions/21712",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20287/"
] | Using the [snippets](https://github.com/SirVer/ultisnips) plugin I'm able to get:
```
class MyClasnippets(object):
"""Docstring for MyClasnippets. """
def __init__(self):
"""TODO: to be defined. """
```
from just typing `class`. If I add params I can get:
```
class MyClass(object):
"""Docstri... | >
> Change the entire format to Google's...
>
>
>
It's not documented, but the Python snippets file from **vim-snippets** [does allow you to specify docstring style](https://github.com/honza/vim-snippets/blob/5d259617f5198e511a759ccf4fb3000921abae21/UltiSnips/python.snippets#L123). Simply add `let g:ultisnips_pyth... |
21,725 | <p>I am trying to delete all the spaces that aren't sandwiched by a letter. So this</p>
<pre><code> I am trying; but ; I can't find a way ;
</code></pre>
<p>should be this</p>
<pre><code>I am trying;but;I can't find a way;
</code></pre>
<p>I tried this but it doesn't work.</p>
<pre><code>:%s/\([A-Za-z]\)\@<!... | [
{
"answer_id": 21727,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<p>You can make use of <code>\\zs</code> and <code>\\ze</code>.</p>\n\n<pre><code>:s/\\v^\\s+|\\s+$|[^[:alpha:][:space:]]\\... | 2019/10/31 | [
"https://vi.stackexchange.com/questions/21725",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25440/"
] | I am trying to delete all the spaces that aren't sandwiched by a letter. So this
```
I am trying; but ; I can't find a way ;
```
should be this
```
I am trying;but;I can't find a way;
```
I tried this but it doesn't work.
```
:%s/\([A-Za-z]\)\@<! *\([A-Za-z]\)\@!//g
``` | "Aren't sandwiched by a letter" means *does not have: a letter before it and a letter after it*, when expressed through [De Morgan's laws](https://en.wikipedia.org/wiki/De_Morgan%27s_laws): *does not have a letter before it **OR** does not have a letter after it*. What your regular expression is matching is *does not h... |
21,758 | <p>I am currently using the following mapping to search for knows tags:</p>
<pre><code>nnoremap <expr> <Leader>t "<ESC>:tselect /" . input("") . "<ESC>"
</code></pre>
<p>I also use this mapping to grep all files below the closest <code>tags</code> file:</p>
<pre><code>noremap <expr> <... | [
{
"answer_id": 21759,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 0,
"selected": false,
"text": "<ol>\n<li>Check out <code>:help taglist()</code>—it returns a dictionary of tag-related items. Unfortunately, the ... | 2019/11/03 | [
"https://vi.stackexchange.com/questions/21758",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25455/"
] | I am currently using the following mapping to search for knows tags:
```
nnoremap <expr> <Leader>t "<ESC>:tselect /" . input("") . "<ESC>"
```
I also use this mapping to grep all files below the closest `tags` file:
```
noremap <expr> <Leader>g "<ESC>:vimgrep /"
\ . escape(input('/'), '/')
\ . "/ "
\ . fnamemodi... | You can use the ":ltag" command which adds the matching tags to the location
list for the current window. You can then use the location list commands to
browse the matches.
BTW, the location list feature was originally developed in 2005 to add support
for this command. |
21,774 | <p>I am using <code>coc.vim</code> in neovim. <code>coc.vim</code> suggests the following mapping for jumping to the definition of a class/method.</p>
<pre><code>nmap <silent> gd <Plug>(coc-definition)
</code></pre>
<p>If there is only a single matching definition, pressing <code>gd</code> will immediatel... | [
{
"answer_id": 21776,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 4,
"selected": true,
"text": "<p>I inject my <a href=\"https://github.com/LucHermitte/lh-misc/blob/master/vimrc_core.vim#L1130\" rel=\"nofollow norefe... | 2019/11/04 | [
"https://vi.stackexchange.com/questions/21774",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25529/"
] | I am using `coc.vim` in neovim. `coc.vim` suggests the following mapping for jumping to the definition of a class/method.
```
nmap <silent> gd <Plug>(coc-definition)
```
If there is only a single matching definition, pressing `gd` will immediately open the definition in the current window.
If there are multiple mat... | I inject my [own way of opening files in CoC](https://github.com/LucHermitte/lh-misc/blob/master/vimrc_core.vim#L1130) with:
```
let g:coc_user_config = {}
let g:coc_user_config['coc.preferences.jumpCommand'] = ':SplitIfNotOpen4COC'
```
Then the command is [defined in my lh-vim-lib plugin](https://github.com/LucHerm... |
21,778 | <p>When using autocompletion with <code><C-n></code>, if no matching string is found, vim shows the message <code>Pattern not found</code> into the status bar.</p>
<p>I tried something with this simple function:</p>
<pre><code>function! TestCN()
let l:retval = 0
try "\i<C-n>"
catch /.*/
... | [
{
"answer_id": 21776,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 4,
"selected": true,
"text": "<p>I inject my <a href=\"https://github.com/LucHermitte/lh-misc/blob/master/vimrc_core.vim#L1130\" rel=\"nofollow norefe... | 2019/11/04 | [
"https://vi.stackexchange.com/questions/21778",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15254/"
] | When using autocompletion with `<C-n>`, if no matching string is found, vim shows the message `Pattern not found` into the status bar.
I tried something with this simple function:
```
function! TestCN()
let l:retval = 0
try "\i<C-n>"
catch /.*/
" should catch Pattern not Found here"
let ... | I inject my [own way of opening files in CoC](https://github.com/LucHermitte/lh-misc/blob/master/vimrc_core.vim#L1130) with:
```
let g:coc_user_config = {}
let g:coc_user_config['coc.preferences.jumpCommand'] = ':SplitIfNotOpen4COC'
```
Then the command is [defined in my lh-vim-lib plugin](https://github.com/LucHerm... |
21,787 | <p>I am using a vimscript to "highlight" columns of interest in some text.
However, using <code>colorcolumn</code> "highlights" the entire column on every row in the file.
Is there a good way to define start and end rows for the <code>colorcolumn</code> to be applied on?</p>
<p>More information:
1. I know the row numb... | [
{
"answer_id": 21788,
"author": "Paul",
"author_id": 22956,
"author_profile": "https://vi.stackexchange.com/users/22956",
"pm_score": 1,
"selected": false,
"text": "<p>I can't help but feel that you are trying to limit the <code>colorcolumn</code> to the 81st (or so) column <strong>only<... | 2019/11/05 | [
"https://vi.stackexchange.com/questions/21787",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25541/"
] | I am using a vimscript to "highlight" columns of interest in some text.
However, using `colorcolumn` "highlights" the entire column on every row in the file.
Is there a good way to define start and end rows for the `colorcolumn` to be applied on?
More information:
1. I know the row numbers I would like to highlight , ... | I can't help but feel that you are trying to limit the `colorcolumn` to the 81st (or so) column **only** when there actually is a line that goes beyond that column. I'm sorry, if I got your question wrong, because I'm a bit confused about rows vs columns...
Anyway:
this is what I have in my `.vimrc`:
```
" Make 81st ... |
21,798 | <p>After <code>:term ++curwin zsh</code>, I use that buffer as an alternative of tmux window.</p>
<p>But there is one caveat, if I <code>cd</code> in zsh, vim will not know.</p>
<p>Which cause problem in below case</p>
<p>In terminal normal mode, <code>gf</code> will not work correctly, since vim don't know zsh has ... | [
{
"answer_id": 21813,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 5,
"selected": true,
"text": "<ol>\n<li>Create a special function in your vimrc that's callable from terminal, its name must start with <code>Tapi_</cod... | 2019/11/06 | [
"https://vi.stackexchange.com/questions/21798",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10254/"
] | After `:term ++curwin zsh`, I use that buffer as an alternative of tmux window.
But there is one caveat, if I `cd` in zsh, vim will not know.
Which cause problem in below case
In terminal normal mode, `gf` will not work correctly, since vim don't know zsh has changed directory.
After googling, I found [zsh support ... | 1. Create a special function in your vimrc that's callable from terminal, its name must start with `Tapi_`.
```
" arglist : [ cwd ]
" change window local working directory
function! Tapi_lcd(bufnum, arglist)
let winid = bufwinid(a:bufnum)
let cwd = get(a:arglist, 0, '')
if winid == -1 || empty(cwd)
return
... |
21,819 | <p>In normal usage <code>:%s/A/B/g</code> is a simple way to substitute a pattern across the entire buffer. However the command mode implementation of <code>:substitute</code> is subject to many user configurable variables and as such linters rightfully complain about it's usage in scripts.</p>
<p>I'm trying to use <c... | [
{
"answer_id": 21820,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<blockquote>\n <p>since this is documented best-practice in scripts</p>\n</blockquote>\n\n<p>Documented where?</p... | 2019/11/07 | [
"https://vi.stackexchange.com/questions/21819",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/267/"
] | In normal usage `:%s/A/B/g` is a simple way to substitute a pattern across the entire buffer. However the command mode implementation of `:substitute` is subject to many user configurable variables and as such linters rightfully complain about it's usage in scripts.
I'm trying to use `call substitute()` instead since ... | The only problems I see with `:substitute` are:
* it messes a few registers
* we may have to be wary of the separator character used that'll need to be escaped
* its behaviour depends on `'magic`' option ~~(as well as `substitute()`'s one)~~
If you really want to operate on the whole buffer without `:s`, you could al... |
21,825 | <p>I am writing a vim script, and I need to insert the contents of a string variable at the current cursor position. What is an appropriate way to do this?</p>
<pre><code>let text = "Lorem ipsum sit dolor amet ..."
" How to insert text at current cursor position?
</code></pre>
<p>I know that <code>:read</code> can do... | [
{
"answer_id": 21826,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 3,
"selected": false,
"text": "<p>You can do a literal insert of register contents through <a href=\"https://vimhelp.appspot.com/insert.txt.html#i_CTRL... | 2019/11/08 | [
"https://vi.stackexchange.com/questions/21825",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19712/"
] | I am writing a vim script, and I need to insert the contents of a string variable at the current cursor position. What is an appropriate way to do this?
```
let text = "Lorem ipsum sit dolor amet ..."
" How to insert text at current cursor position?
```
I know that `:read` can do something like this, but it is only ... | You can do a literal insert of register contents through [`:help i_CTRL-R_CTRL-R`](https://vimhelp.appspot.com/insert.txt.html#i_CTRL-R_CTRL-R), combined with the *expression register* ([`:help quote=`](https://vimhelp.appspot.com/change.txt.html#quote%3D)) to reference the variable:
```
execute "normal! i\<C-r>\<C-r>... |
21,828 | <p>I'm trying to use balloon text for my C macros, say, <code>true</code> and <code>false</code> as follows in the terminal version.</p>
<pre><code>function! MyBalloonExpr()
let macros = {
\ 'true':"true\n1",
\ 'false':"false\n0",
\ }
return get(macros, v:beval_text, '')
endfunction
set balloonexpr=MyBalloonExpr()... | [
{
"answer_id": 21831,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 3,
"selected": true,
"text": "<p>I'm not sure you've seen this, but <a href=\"https://vimhelp.appspot.com/options.txt.html#%27balloonexpr%27\" rel=\"no... | 2019/11/08 | [
"https://vi.stackexchange.com/questions/21828",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2347/"
] | I'm trying to use balloon text for my C macros, say, `true` and `false` as follows in the terminal version.
```
function! MyBalloonExpr()
let macros = {
\ 'true':"true\n1",
\ 'false':"false\n0",
\ }
return get(macros, v:beval_text, '')
endfunction
set balloonexpr=MyBalloonExpr()
set ballooneval
set balloonevalterm... | I'm not sure you've seen this, but [`:help 'balloonexpr'`](https://vimhelp.appspot.com/options.txt.html#%27balloonexpr%27) says this:
>
> To check whether line breaks in the balloon text work use this check:
>
>
>
> ```
> if has("balloon_multiline")
>
> ```
>
> When they are supported "\n" characters will start... |
21,834 | <p>I'm trying to add more ex commands to my vim repertoire and I was wondering if there is setting or plugin that would allow to highlight the lines addressed by the command, if a range is give e.g., if I type</p>
<pre><code>:-5,-3m.
</code></pre>
<p>I would like some highlight on the lines -5 and -3 (either the line... | [
{
"answer_id": 21831,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 3,
"selected": true,
"text": "<p>I'm not sure you've seen this, but <a href=\"https://vimhelp.appspot.com/options.txt.html#%27balloonexpr%27\" rel=\"no... | 2019/11/08 | [
"https://vi.stackexchange.com/questions/21834",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25586/"
] | I'm trying to add more ex commands to my vim repertoire and I was wondering if there is setting or plugin that would allow to highlight the lines addressed by the command, if a range is give e.g., if I type
```
:-5,-3m.
```
I would like some highlight on the lines -5 and -3 (either the line number or the whole line ... | I'm not sure you've seen this, but [`:help 'balloonexpr'`](https://vimhelp.appspot.com/options.txt.html#%27balloonexpr%27) says this:
>
> To check whether line breaks in the balloon text work use this check:
>
>
>
> ```
> if has("balloon_multiline")
>
> ```
>
> When they are supported "\n" characters will start... |
21,840 | <p>Recently, I have tried to create my own colorscheme in only one color and <strong>no text decoration</strong>. That means <code>Normal</code>, <code>Comment</code>, <code>ToolbarLine</code>, <code>Tooltip</code>... are the same; <code>Visual</code>, <code>Cursor</code>... are reversed, of course; no bold, no underli... | [
{
"answer_id": 21860,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 0,
"selected": false,
"text": "<p>Most <em>filetypes</em> (like <code>python</code>) in Vim come with a syntax that defines highlight groups (see them ... | 2019/11/09 | [
"https://vi.stackexchange.com/questions/21840",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25588/"
] | Recently, I have tried to create my own colorscheme in only one color and **no text decoration**. That means `Normal`, `Comment`, `ToolbarLine`, `Tooltip`... are the same; `Visual`, `Cursor`... are reversed, of course; no bold, no underline, no italic found.
Every built-in highlighting is successfully overwritten to o... | You can try this vimscript (add to your vimrc and `call SetHLGreen()` function)
```
"" Get all highlights in a raw string
fun! GetHLStr()
redir => all_hl
highlight
redir END
return all_hl
endfun
"" Set all known highlight groups to green
fun! SetHLGreen()
" get highlight groups without printing i... |
21,841 | <p>I am implementing a smooth scrolling function for <code><C-u></code> and <code><C-d></code>, which just sleeps for a few milliseconds and then moves the screen up (<code><C-y></code>) or down (<code><C-e></code>) one line:</p>
<pre><code>function SmoothScroll(up)
if a:up
let scro... | [
{
"answer_id": 21842,
"author": "stimulate",
"author_id": 17840,
"author_profile": "https://vi.stackexchange.com/users/17840",
"pm_score": 0,
"selected": false,
"text": "<p>I have now just checked manually whether the cursor is at the border of scrolloff, i.e. if it would be scrolled by ... | 2019/11/09 | [
"https://vi.stackexchange.com/questions/21841",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/17840/"
] | I am implementing a smooth scrolling function for `<C-u>` and `<C-d>`, which just sleeps for a few milliseconds and then moves the screen up (`<C-y>`) or down (`<C-e>`) one line:
```
function SmoothScroll(up)
if a:up
let scrollaction= "\<C-y>"
else
let scrollaction="\<C-e>"
endif
let s=... | Not an answer to your question. But thought I'd mention that this exists: <https://github.com/terryma/vim-smooth-scroll> |
21,856 | <p>I can't remember start from when and why, i always add <code>!</code> to <code>function</code> and <code>command</code>:</p>
<pre><code>function! ..
...
endfunction
command! ...
</code></pre>
<p>But <code>:h E122</code> says:</p>
<pre><code> When a function by this name already exists and [!] is
... | [
{
"answer_id": 21857,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<p>Yes, I also wondered at seeing this topic first time. I suspect that the whole story is due to VimScript version changes... | 2019/11/11 | [
"https://vi.stackexchange.com/questions/21856",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5017/"
] | I can't remember start from when and why, i always add `!` to `function` and `command`:
```
function! ..
...
endfunction
command! ...
```
But `:h E122` says:
```
When a function by this name already exists and [!] is
not used an error message is given. There is one
exception: W... | >
> When sourcing a script again, a function that was previously defined in that script will be silently replaced.
>
>
>
That's a fairly recent (Vim 8.1) change. Previously, you had to use `:function!` to redefine an existing function. As plugin writers very frequently reload their scripts during development (as i... |
21,870 | <p>I try to write a vim syntax file for folding if-else statements with the syntax:</p>
<pre><code>if <condition> then <block to fold> [else <block to fold>] end if
</code></pre>
<p>Current approach</p>
<pre><code>syn region Then start="then" end="end if" end="\(\s*else\)\@=" transparent fold
syn r... | [
{
"answer_id": 21871,
"author": "Charles Gueunet",
"author_id": 15134,
"author_profile": "https://vi.stackexchange.com/users/15134",
"pm_score": 0,
"selected": false,
"text": "<p>This answer is more of a hack than a real solution to your question.</p>\n\n<p>From the text you show, it see... | 2019/11/12 | [
"https://vi.stackexchange.com/questions/21870",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21338/"
] | I try to write a vim syntax file for folding if-else statements with the syntax:
```
if <condition> then <block to fold> [else <block to fold>] end if
```
Current approach
```
syn region Then start="then" end="end if" end="\(\s*else\)\@=" transparent fold
syn region Else start="else" end="end if" ... | I got that to work by using the following set of rules:
```
syn region IfBlock start="then" end="end if" keepend extend transparent contains=Then,Else
syn region Then start="then" end="^\s*else"me=s-1 end="end if" extend transparent contained fold
syn region Else start="else" end="end if" extend transparent contained ... |
21,872 | <p>I know per my question <a href="https://vi.stackexchange.com/questions/21862/remove-trailing-dashes-in-foldtext">remove trailing dashes in foldtext</a> that I can remove the trailing dashes from collapsed fold lines. When a fold is 'open', the sign column has pipe characters '|'. I looked at the help page and tried ... | [
{
"answer_id": 21874,
"author": "Myc3lium",
"author_id": 25619,
"author_profile": "https://vi.stackexchange.com/users/25619",
"pm_score": 1,
"selected": false,
"text": "<p>(Moved to a separate answer for visibility)</p>\n\n<p>According to @Christian Brabandt the characters used for this ... | 2019/11/12 | [
"https://vi.stackexchange.com/questions/21872",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25619/"
] | I know per my question [remove trailing dashes in foldtext](https://vi.stackexchange.com/questions/21862/remove-trailing-dashes-in-foldtext) that I can remove the trailing dashes from collapsed fold lines. When a fold is 'open', the sign column has pipe characters '|'. I looked at the help page and tried searching for ... | Its possible now using `'fillchars'` (from the help):
```
item default Used for
...
foldopen:c '-' mark the beginning of a fold
foldclose:c '+' show a closed fold
foldsep:c '|' open fold middle character
```
For example, `set fillchars+=fold... |
21,881 | <p>I'm new to vimscript and writing a function to toggle a terminal buffer. Here is what I tried:</p>
<pre><code>let g:toggle_term = "<C-j>"
let g:term_buf_nr = -1
function! ToggleTerminal()
if g:term_buf_nr == -1
execute "bot term"
let g:term_buf_nr = bufnr("$")
else
execute "bd... | [
{
"answer_id": 21884,
"author": "St.Antario",
"author_id": 9409,
"author_profile": "https://vi.stackexchange.com/users/9409",
"pm_score": 3,
"selected": true,
"text": "<p>As @statox suggested in comments I should have used <code>tnoremap</code> to implement it. The following works fine:<... | 2019/11/12 | [
"https://vi.stackexchange.com/questions/21881",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9409/"
] | I'm new to vimscript and writing a function to toggle a terminal buffer. Here is what I tried:
```
let g:toggle_term = "<C-j>"
let g:term_buf_nr = -1
function! ToggleTerminal()
if g:term_buf_nr == -1
execute "bot term"
let g:term_buf_nr = bufnr("$")
else
execute "bd! " .g:term_buf_nr
... | As @statox suggested in comments I should have used `tnoremap` to implement it. The following works fine:
```
execute "tnoremap ".g:toggle_term ." <C-w>:call ToggleTerminal()<CR>"
```
---
The mistake I initially made was the space right after the `N`
```
execute "tnoremap ".g:toggle_term ." <C-w>N :call ToggleTerm... |
21,885 | <p>When I'm in a modified buffer and try to open a file using <code>:e otherFile</code> I get</p>
<blockquote>
<p>E37: No write since last change (add ! to override)</p>
</blockquote>
<p>Since this happens fairly often, I'd like to automatically save the current file before opening the new one.</p>
<p>That's why I adde... | [
{
"answer_id": 21884,
"author": "St.Antario",
"author_id": 9409,
"author_profile": "https://vi.stackexchange.com/users/9409",
"pm_score": 3,
"selected": true,
"text": "<p>As @statox suggested in comments I should have used <code>tnoremap</code> to implement it. The following works fine:<... | 2019/11/13 | [
"https://vi.stackexchange.com/questions/21885",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8558/"
] | When I'm in a modified buffer and try to open a file using `:e otherFile` I get
>
> E37: No write since last change (add ! to override)
>
>
>
Since this happens fairly often, I'd like to automatically save the current file before opening the new one.
That's why I added this to my `vimrc`:
```
autocmd BufLeave *... | As @statox suggested in comments I should have used `tnoremap` to implement it. The following works fine:
```
execute "tnoremap ".g:toggle_term ." <C-w>:call ToggleTerminal()<CR>"
```
---
The mistake I initially made was the space right after the `N`
```
execute "tnoremap ".g:toggle_term ." <C-w>N :call ToggleTerm... |
21,894 | <p><strong>Use case:</strong></p>
<p>In a JS file, I have an expression like:</p>
<pre class="lang-js prettyprint-override"><code>if (someVar === 'someValue') {
statements;
}
</code></pre>
<p>and, for debugging purposes, I sometimes want to include a <code>console.log</code> in the line above:</p>
<pre class="l... | [
{
"answer_id": 21895,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 3,
"selected": false,
"text": "<blockquote>\n <p>Can you guys think of a more elegant way to do the same?</p>\n</blockquote>\n\n<p>Well, at least we can ... | 2019/11/13 | [
"https://vi.stackexchange.com/questions/21894",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11899/"
] | **Use case:**
In a JS file, I have an expression like:
```js
if (someVar === 'someValue') {
statements;
}
```
and, for debugging purposes, I sometimes want to include a `console.log` in the line above:
```js
console.log('someVar:', someVar);
if (someVar === 'someValue') {
statements;
}
```
**(Working) At... | You can use `<C-R>` from insert mode to insert the contents of a register. That way you can insert the whole line at once, including the repeat of the variable name.
For example:
```
nnoremap <Leader>L "ayiwOconsole.log('<C-R>a:', <C-R>a);<Esc>
```
You might want to consider adding a visual mode mapping as well, in... |
21,898 | <p>I know how to make an abbreviation to a command in vim. For example to print the date, I have this in .vimrc:</p>
<pre><code>iabbrev mydate <C-R>=strftime("%a %d/%m/%Y")
</code></pre>
<p>Now I'm running a VM with FreeBSD as a guest. Base system has good old vi/nvi.</p>
<p>I can print the date with:</p>
<pr... | [
{
"answer_id": 21901,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>You can create a mapping for it</p>\n\n<pre><code>nnoremap keys :read !date...<CR>\n</code></pre>\n\n<p>O... | 2019/11/13 | [
"https://vi.stackexchange.com/questions/21898",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25644/"
] | I know how to make an abbreviation to a command in vim. For example to print the date, I have this in .vimrc:
```
iabbrev mydate <C-R>=strftime("%a %d/%m/%Y")
```
Now I'm running a VM with FreeBSD as a guest. Base system has good old vi/nvi.
I can print the date with:
```
:r !date "+%a %d/%M/%Y"
```
But how can ... | I finally found a solution:
I put this in ~/.nexrc:
```
ab mydate ^[:r !date "+\%a \%d/\%m/\%Y"^MkJA
```
Where:
`^[` = `CTRL+v`+`ESC`
and
`^M` = `CTRL+v`+`ENTER`
Many thanks to Antony\_ on Freenode channel ##vi for the solution. |
21,911 | <p>I use airline's tabline to show a list of my current buffers:</p>
<pre><code>Plug 'vim-airline/vim-airline'
let g:airline#extensions#tabline#enabled = 1 " Use the airline tabline (replacement for buftabline)
let g:airline#extensions#tabline#show_tab_nr = 1
let g:airline#extensions#tabline#tab_nr_type = 1 " tab numb... | [
{
"answer_id": 21925,
"author": "Caleb",
"author_id": 267,
"author_profile": "https://vi.stackexchange.com/users/267",
"pm_score": 4,
"selected": true,
"text": "<p>Per <code>:help airline</code>, the default value of things airline will filter out of the buffer list if not otherwise spec... | 2019/11/14 | [
"https://vi.stackexchange.com/questions/21911",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2026/"
] | I use airline's tabline to show a list of my current buffers:
```
Plug 'vim-airline/vim-airline'
let g:airline#extensions#tabline#enabled = 1 " Use the airline tabline (replacement for buftabline)
let g:airline#extensions#tabline#show_tab_nr = 1
let g:airline#extensions#tabline#tab_nr_type = 1 " tab number
let g:airli... | Per `:help airline`, the default value of things airline will filter out of the buffer list if not otherwise specified by the user is:
```
let g:airline#extensions#tabline#ignore_bufadd_pat = '!|defx|gundo|nerd_tree|startify|tagbar|term://|undotree|vimfiler'
```
...where `!` and `term:/` are the respective ways of i... |
21,916 | <p>I'm trying to re-map <a href="https://github.com/majutsushi/tagbar" rel="noreferrer">tagbar</a> toggling with <code><C-&></code> that I get used to when working with IDEs.</p>
<p>But setting</p>
<pre><code>execute "nnoremap <C-&> :TagbarToggle<CR>"
</code></pre>
<p>does not have the desi... | [
{
"answer_id": 21917,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 4,
"selected": true,
"text": "<p>According to <a href=\"https://bestasciitable.com\" rel=\"noreferrer\">one of our former mods</a>, the answer is... | 2019/11/14 | [
"https://vi.stackexchange.com/questions/21916",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9409/"
] | I'm trying to re-map [tagbar](https://github.com/majutsushi/tagbar) toggling with `<C-&>` that I get used to when working with IDEs.
But setting
```
execute "nnoremap <C-&> :TagbarToggle<CR>"
```
does not have the desirable effect. When pressing 3 keys at once `CTRL-SHIFT-7` where `SHIFT-7` stands for `&` it essent... | According to [one of our former mods](https://bestasciitable.com), the answer is no:
>
> Sending Control with a character from the 2nd column is useless. Control clears the 7th bit, but this is already 0, so Control+# will just send "#".
>
>
>
Notice that `&` in the second column has binary representation `01 001... |
21,929 | <p><strong>Is it possible to configure vi to use a different location, say my home directory, for the uncompressed help files (or maybe to open them in RO if that's the problem)?</strong></p>
<p>When attempting to open a help document from within <strong>vi</strong> I get the following error:</p>
<pre><code>"quickref... | [
{
"answer_id": 21931,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>I've done some digging. (tpope's scriptease makes this really easy.)</p>\n\n<p><code>plugin/gzip.vim</code> rev... | 2019/11/15 | [
"https://vi.stackexchange.com/questions/21929",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13655/"
] | **Is it possible to configure vi to use a different location, say my home directory, for the uncompressed help files (or maybe to open them in RO if that's the problem)?**
When attempting to open a help document from within **vi** I get the following error:
```
"quickref.txt.gz" [readonly][noeol] 94L, 21071C
Error de... | I've done some digging. (tpope's scriptease makes this really easy.)
`plugin/gzip.vim` reveals that most of the functionality is autoloaded.
`autoload/gzip.vim` reveals that the temporary paths are constructed using `tempname()`.
`tempname()` reveals that `*tempfile*` has the appropriate help:
```
Vim uses temporar... |
21,932 | <p>I'm configuring a terminal buffer and now I have the following problem. I have only one terminal buffer and I need to make it active by its number to avoid lots of <code>CTRL-w j/k/l</code> clicks.</p>
<p>Here is what I tried:</p>
<ol>
<li>Given <code>vim</code> opened I typed <code>:bot term</code> to create a new ... | [
{
"answer_id": 21931,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>I've done some digging. (tpope's scriptease makes this really easy.)</p>\n\n<p><code>plugin/gzip.vim</code> rev... | 2019/11/15 | [
"https://vi.stackexchange.com/questions/21932",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9409/"
] | I'm configuring a terminal buffer and now I have the following problem. I have only one terminal buffer and I need to make it active by its number to avoid lots of `CTRL-w j/k/l` clicks.
Here is what I tried:
1. Given `vim` opened I typed `:bot term` to create a new terminal buffer:
[
`plugin/gzip.vim` reveals that most of the functionality is autoloaded.
`autoload/gzip.vim` reveals that the temporary paths are constructed using `tempname()`.
`tempname()` reveals that `*tempfile*` has the appropriate help:
```
Vim uses temporar... |
21,941 | <p>I am new to vim and tmux.</p>
<h2>TL;DR</h2>
<p>I want to have tmux set up so that I have a pane for my (python) code and a pane for the output of the code.</p>
<h2>What I know</h2>
<p>Now, from vim I can do a command like <code>:!python %</code> to run/interpret my code, but the problem is that it displays the ... | [
{
"answer_id": 21942,
"author": "Daniel Cohen Hillel",
"author_id": 25692,
"author_profile": "https://vi.stackexchange.com/users/25692",
"pm_score": 2,
"selected": false,
"text": "<p>OK so I found a bit of a work around that works.\nI first declare a new command that gets as an input a c... | 2019/11/16 | [
"https://vi.stackexchange.com/questions/21941",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25692/"
] | I am new to vim and tmux.
TL;DR
-----
I want to have tmux set up so that I have a pane for my (python) code and a pane for the output of the code.
What I know
-----------
Now, from vim I can do a command like `:!python %` to run/interpret my code, but the problem is that it displays the results, on the same screen,... | I ended up creating [vim-simpl](https://github.com/benknoble/vim-simpl) for this. One function allows you to create a REPL (mapped to `<leader>t` in my config, as below), and another to load a file (mapped to `<localleader>l` in my config). With some effort, I can add python support out-of-box.
---
If you have vim8,... |
21,967 | <p>I have .vimrc plugins</p>
<pre><code>" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'nanotech/jellybeans.vim'
" Plugin 'vim-airline/vim-airline'
" Plugin 'vim-airline/vim-airline-themes'
Plugin 'scrooloose/nerdtree'... | [
{
"answer_id": 21962,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<p><code>b</code> is an <code>:h exclusive</code> motion, so it behaves this way: \"<em>the last character towards the end ... | 2019/11/19 | [
"https://vi.stackexchange.com/questions/21967",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25726/"
] | I have .vimrc plugins
```
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'nanotech/jellybeans.vim'
" Plugin 'vim-airline/vim-airline'
" Plugin 'vim-airline/vim-airline-themes'
Plugin 'scrooloose/nerdtree'
Plugin 'kien/... | As per [Matt's answer](https://vi.stackexchange.com/a/21962/18609), `b` is an exclusive motion. Using visual mode is a possible way to work around this.
Alternatively, you can also use `v` as an operator (instead of entering visual mode), like so: `$d**v**3b`
See [`:help o_v`](https://vimhelp.org/motion.txt.html#o_v)... |
21,972 | <p>I'm struggling to understand a character escaping situation involving <code>\|</code>.</p>
<p>First I'm running the following search which matches either the <code>A</code> character or <code>B</code> character. I'm using the default <code>magic</code> option so the parentheses <code>()</code> and alternatives sep... | [
{
"answer_id": 21974,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 0,
"selected": false,
"text": "<p>This is a bit of a guess, but I suspect it has to with <code>|</code> also being the ex command separator. So e... | 2019/11/20 | [
"https://vi.stackexchange.com/questions/21972",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25747/"
] | I'm struggling to understand a character escaping situation involving `\|`.
First I'm running the following search which matches either the `A` character or `B` character. I'm using the default `magic` option so the parentheses `()` and alternatives separator `|` must be preceded by backslashes:
```
/\(A\|B\)
```
N... | `|` is used to separate a map command from the next one, you need to escape it or use `<bar>` instead, read [:h map-bar](https://vimhelp.org/map.txt.html#map-bar) for further detail.
Your map is unnecessarily complicated, `{rhs}` of a `map` without [:h :map-<expr>](https://vimhelp.org/map.txt.html#%3Amap-%3Cexpr%3E) i... |
21,993 | <p>I would like to have a file that contains all files that I opened with vim in the past. I know that there is the viminfo file but I want to have just a file with the filenames.</p>
<p>For this I would like to write the list of open buffers with <code>autocmd VimLeave</code> to a file.</p>
<p>I tried <code>:ls | w ... | [
{
"answer_id": 21995,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 1,
"selected": false,
"text": "<p>Try using <code>redir</code> command (<code>:h redir</code>)</p>\n\n<p>For example:</p>\n\n<pre><code>func! MyRedir()... | 2019/11/21 | [
"https://vi.stackexchange.com/questions/21993",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16973/"
] | I would like to have a file that contains all files that I opened with vim in the past. I know that there is the viminfo file but I want to have just a file with the filenames.
For this I would like to write the list of open buffers with `autocmd VimLeave` to a file.
I tried `:ls | w >> test.txt` but this does not wo... | You can have all buffer names that haven't been unloaded (or wiped out?) with:
```
let files = filter(map(range(1,bufnr('$')), 'bufname(v:val)'), '!empty(v:val)')
```
You can save it with
```
call writefile(files, '/path/to/filename.txt')
``` |
21,994 | <p>This is what I have in my <code>/usr/share/vim/vim80/filetype.vim</code> (the only mention of <code>messages</code> in the file) :</p>
<pre><code>" Messages (logs mostly)
au BufNewFile,BufRead */logs/couchdb/{,.log}{,.[0-9]*,-[0-9]*} setf couch_log
au BufNewFile,BufRead */log/{auth,cron,daemon,debug,kern,lpr,mail,m... | [
{
"answer_id": 22010,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 1,
"selected": false,
"text": "<p>Try the following minimal vimrc:</p>\n\n<pre><code>set nocompatible\nsyntax on\nfiletype plugin indent on\n</code></p... | 2019/11/21 | [
"https://vi.stackexchange.com/questions/21994",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25787/"
] | This is what I have in my `/usr/share/vim/vim80/filetype.vim` (the only mention of `messages` in the file) :
```
" Messages (logs mostly)
au BufNewFile,BufRead */logs/couchdb/{,.log}{,.[0-9]*,-[0-9]*} setf couch_log
au BufNewFile,BufRead */log/{auth,cron,daemon,debug,kern,lpr,mail,messages,news/news,syslog,user}{,.log... | You seem to have a bug in your filename glob pattern. The one you showed:
```
*/logs/couchdb/{,.log}{,.[0-9]*,-[0-9]*}
```
It will indeed match files inside a `logs/couchdb/` directory, but the last part will only match files named `.log` or `.789` or `-789` or `.log.789` or `.log-789`. Yes, these are full filenames... |
22,003 | <p>Say that I have pattern <code>aaaaapple</code> in my text file, and say that I configured vim so that it conceals <code>a\+</code>. </p>
<p>What will happen is that, if <code>conceallevel=1</code>, then <code>aaaaapple</code> will become <code>_pple</code>. Note that <code>aaaaa</code> is replaced by a single spac... | [
{
"answer_id": 22004,
"author": "norcalli",
"author_id": 16189,
"author_profile": "https://vi.stackexchange.com/users/16189",
"pm_score": 1,
"selected": false,
"text": "<p>See <code>:h concealcursor</code>. It controls which modes will be activated for conceal. In this case you want to d... | 2019/11/21 | [
"https://vi.stackexchange.com/questions/22003",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14744/"
] | Say that I have pattern `aaaaapple` in my text file, and say that I configured vim so that it conceals `a\+`.
What will happen is that, if `conceallevel=1`, then `aaaaapple` will become `_pple`. Note that `aaaaa` is replaced by a single space `_` (I'm writing spaces as `_` due to technical difficulties). This causes ... | Instead of matching *all* duplicate "a"s in a single match, try concealing *each* extra "a" in its own, concealed group:
```
syn match HideAa "a\zea" conceal
```
Because this conceals only a single "a" with its own syntax group conceal, it will effectively apply a concealing space to each "a". |
22,013 | <p>Each time I want to save my work while editing a text file, I enter <code>:write</code> to save the file, and <code>:edit</code> to reload the file, with the side effect of resetting the undo/redo buffer.</p>
<p>However, an unwanted side effect of running <code>:edit</code> is that the line under the cursor is rece... | [
{
"answer_id": 22024,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 1,
"selected": false,
"text": "<p>I'll let @IngoKarkat write <a href=\"https://vi.stackexchange.com/questions/22013/how-can-i-prevent-vim-from-centering-the-l... | 2019/11/22 | [
"https://vi.stackexchange.com/questions/22013",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8599/"
] | Each time I want to save my work while editing a text file, I enter `:write` to save the file, and `:edit` to reload the file, with the side effect of resetting the undo/redo buffer.
However, an unwanted side effect of running `:edit` is that the line under the cursor is recentered. Can anyone tell me either (i) how t... | As you're expressly using `:edit` in order to reset the undo information, you could follow [`:help clear-undo`](https://vimhelp.appspot.com/undo.txt.html#clear-undo) to do this without `:edit`.
I would define a custom `:Write` command that combines both:
```
command! -bar Write
\ write |
\ let old_undolevels = &undol... |
22,015 | <p>I can catch the output of running a system command via <code>system()</code> or <code>systemlist()</code>, but that actually gives me the result of stdout and stderr combined.
As I am only interested in stdout (and may use stderr for other purposes), this isn't useful for me.</p>
<p>How can I separate the output o... | [
{
"answer_id": 22016,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 4,
"selected": true,
"text": "<p>Vim's <code>system()</code> indeed captures both standard out and standard error by default. If you just want one of t... | 2019/11/22 | [
"https://vi.stackexchange.com/questions/22015",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21417/"
] | I can catch the output of running a system command via `system()` or `systemlist()`, but that actually gives me the result of stdout and stderr combined.
As I am only interested in stdout (and may use stderr for other purposes), this isn't useful for me.
How can I separate the output of a system command between stdou... | Vim's `system()` indeed captures both standard out and standard error by default. If you just want one of those, just use the normal shell means to redirect the other to the *null device*.
For example, ignore stderr (`2>`) with Bash:
```
:echo system('grep root /etc/passwd /doesnotexist 2>/dev/null')
```
On Windows... |
22,019 | <p>I have an "optional" plugin that depends on python (<code>pack/habamax/opt/myplugin</code>)</p>
<p>in my settings I have the following:</p>
<pre><code>if has('python') || has('python3')
do some setup
packadd myplugin
endif
</code></pre>
<p>This thing fails if there is no myplugin though.</p>
<p>Is there ... | [
{
"answer_id": 22016,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 4,
"selected": true,
"text": "<p>Vim's <code>system()</code> indeed captures both standard out and standard error by default. If you just want one of t... | 2019/11/22 | [
"https://vi.stackexchange.com/questions/22019",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9333/"
] | I have an "optional" plugin that depends on python (`pack/habamax/opt/myplugin`)
in my settings I have the following:
```
if has('python') || has('python3')
do some setup
packadd myplugin
endif
```
This thing fails if there is no myplugin though.
Is there a way I can add to an if statement to check if mypl... | Vim's `system()` indeed captures both standard out and standard error by default. If you just want one of those, just use the normal shell means to redirect the other to the *null device*.
For example, ignore stderr (`2>`) with Bash:
```
:echo system('grep root /etc/passwd /doesnotexist 2>/dev/null')
```
On Windows... |
22,040 | <p>For example, <code>Ctrl-v_Ctrl-w</code> gives <code>^[[27;5;119~</code> instead of usual <code>^W</code>.</p>
<p>It does behave in such way only on (<em>u</em>)<em>xterm</em>. I've tested it on <em>st</em>, <em>lxterminal</em>, <em>xfce4-terminal</em> and <em>rxvt</em>. I'm also 98% positive that it works fine on <... | [
{
"answer_id": 22041,
"author": "Jorengarenar",
"author_id": 25807,
"author_profile": "https://vi.stackexchange.com/users/25807",
"pm_score": 2,
"selected": true,
"text": "<pre><code>set t_TE= t_TI=\n</code></pre>\n\n<p>This in <em>vimrc</em> disables <em>modifyOtherKeys</em> (<code>:h m... | 2019/11/23 | [
"https://vi.stackexchange.com/questions/22040",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25807/"
] | For example, `Ctrl-v_Ctrl-w` gives `^[[27;5;119~` instead of usual `^W`.
It does behave in such way only on (*u*)*xterm*. I've tested it on *st*, *lxterminal*, *xfce4-terminal* and *rxvt*. I'm also 98% positive that it works fine on *konsole* and *gnome-terminal* (based on [this post](https://www.reddit.com/r/vim/comm... | ```
set t_TE= t_TI=
```
This in *vimrc* disables *modifyOtherKeys* (`:h modifyOtherKeys`), which was causing the problems |
22,053 | <p>I managed to hide the background of the seperator between open windows by using:</p>
<pre><code>hi VertSplit term=NONE cterm=NONE gui=NONE guifg=NONE guibg=NONE ctermfg=NONE ctermbg=NONE
</code></pre>
<p>However the <code>fillchars</code> still show up, and from my research it seems like its impossible to complete... | [
{
"answer_id": 22054,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<blockquote>\n <p>it seems like its impossible to completely remove the fillchars</p>\n</blockquote>\n\n<p>You can't reall... | 2019/11/25 | [
"https://vi.stackexchange.com/questions/22053",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25193/"
] | I managed to hide the background of the seperator between open windows by using:
```
hi VertSplit term=NONE cterm=NONE gui=NONE guifg=NONE guibg=NONE ctermfg=NONE ctermbg=NONE
```
However the `fillchars` still show up, and from my research it seems like its impossible to completely remove the `fillchars`. I figured ... | You can try hiding it using
```
set fillchars=vert:\
hi! VertSplit guifg=black guibg=black ctermfg=black ctermbg=black
```
Instead of `black` use color of your terminal or colorscheme background (not sure about various fancy terminals out there)
NOTE: `vert:\` the space at the end.
[![enter image description here... |
22,061 | <p>I frequently use <code><C-w></code> in insert mode to back up when I mistype things. I've noticed some odd behavior if I start insert mode when in the middle of a word.</p>
<p>For example, if I have the following line (cursor location indicated by <code>^</code>):</p>
<pre><code>I love to use CamelCase
... | [
{
"answer_id": 22062,
"author": "nickspoon",
"author_id": 7549,
"author_profile": "https://vi.stackexchange.com/users/7549",
"pm_score": 4,
"selected": true,
"text": "<p>This is documented behaviour. Deleting text before the insert start location is controlled by the 'backspace' option, ... | 2019/11/25 | [
"https://vi.stackexchange.com/questions/22061",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25767/"
] | I frequently use `<C-w>` in insert mode to back up when I mistype things. I've noticed some odd behavior if I start insert mode when in the middle of a word.
For example, if I have the following line (cursor location indicated by `^`):
```
I love to use CamelCase
^
```
When I am at that cursor lo... | This is documented behaviour. Deleting text before the insert start location is controlled by the 'backspace' option, and [:help 'backspace'](http://vimhelp.appspot.com/options.txt.html#%27backspace%27) says this:
>
> start: allow backspacing over the start of insert; CTRL-W and CTRL-U stop once at the start of inser... |
22,063 | <p>While I enter a regular expression on the vim command line, I would like to see what matches the partial expression I already wrote.</p>
<p>For example, while writing the command</p>
<pre><code>:%s/regular
</code></pre>
<p>all words <code>regular</code> should be highlighted, and the text should be scrolled so th... | [
{
"answer_id": 22065,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 4,
"selected": false,
"text": "<p>This is done by setting just two options: <code>set is hls</code> (<a href=\"https://vimhelp.org/options.txt.html#%27inc... | 2019/11/26 | [
"https://vi.stackexchange.com/questions/22063",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/925/"
] | While I enter a regular expression on the vim command line, I would like to see what matches the partial expression I already wrote.
For example, while writing the command
```
:%s/regular
```
all words `regular` should be highlighted, and the text should be scrolled so that the first of them is visible.
I think it... | This is done by setting just two options: `set is hls` ([incremental search](https://vimhelp.org/options.txt.html#%27incsearch%27) and [highlight all matches](https://vimhelp.org/options.txt.html#%27hlsearch%27)).
Make sure you've also read the appropriate help topics, excerpted below: [`:h 'is'`](https://vimhelp.org/... |
22,071 | <p>Why is my <code>locale</code> setting replaced when I run an external command with <code>:!cmd</code> ?</p>
<p>And which configurations should I check to find the cause of this problem? I've checked configs for my shell (zsh): <code>.zshenv</code>, <code>.zshrc</code>; my configs for neovim; my config for KDE. But ... | [
{
"answer_id": 22076,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": false,
"text": "<p>I believe Vim should not modify your current locale except for LC_NUMERIC, LC_CTYPE and possibly LC_MESSAGES. Th... | 2019/11/26 | [
"https://vi.stackexchange.com/questions/22071",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25849/"
] | Why is my `locale` setting replaced when I run an external command with `:!cmd` ?
And which configurations should I check to find the cause of this problem? I've checked configs for my shell (zsh): `.zshenv`, `.zshrc`; my configs for neovim; my config for KDE. But I still don't understand why nvim seems to reset local... | Carefully read what is inside your vim configuration. It turned out I was setting `let $LANG='en'` in my `vimrc` in part I took from <https://github.com/amix/vimrc/blob/master/vimrcs/basic.vim> . |
22,073 | <p>How to sort the output of let or get? E.g., I want to sort all global variables containing "python":</p>
<pre><code>:filter python let g:
</code></pre>
| [
{
"answer_id": 22074,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 4,
"selected": true,
"text": "<ol>\n<li><p>You can capture output with <code>execute()</code> function and then pump it through <code>sort()</code>. The w... | 2019/11/27 | [
"https://vi.stackexchange.com/questions/22073",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11022/"
] | How to sort the output of let or get? E.g., I want to sort all global variables containing "python":
```
:filter python let g:
``` | 1. You can capture output with `execute()` function and then pump it through `sort()`. The whole command could be then:
```
command! -bang -nargs=1 -complete=command Sorted
\ echo join(sort(split(execute(<q-mods> . ' ' . <q-args>), "\n"),
\ {s1, s2 -> <bang>(s1 ># s2) - <bang>(s1 <# s2)}), "\n")
```
Now ... |
22,081 | <p>I was reading through the vim wiki about the power of g <a href="https://vim.fandom.com/wiki/Power_of_g" rel="nofollow noreferrer">https://vim.fandom.com/wiki/Power_of_g</a> and would like to do something similar to <code>:g/pattern/y A</code> but a little bit different.</p>
<p>I have an html file with tags that ha... | [
{
"answer_id": 22082,
"author": "Jorengarenar",
"author_id": 25807,
"author_profile": "https://vi.stackexchange.com/users/25807",
"pm_score": 1,
"selected": false,
"text": "<p>Somebody had a similar problem: <a href=\"https://stackoverflow.com/questions/23713617/vim-yank-all-matches-of-r... | 2019/11/27 | [
"https://vi.stackexchange.com/questions/22081",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25871/"
] | I was reading through the vim wiki about the power of g <https://vim.fandom.com/wiki/Power_of_g> and would like to do something similar to `:g/pattern/y A` but a little bit different.
I have an html file with tags that have a bunch of properties like this:
```
<the-tag
prop="prop1"
</the-tag>
<the-tag
prop="prop2... | You're confusing the passing of the register to `:yank` (Ex command) vs. `y` (normal mode). For the latter, instead of appending the register, it must come *before* the `y` command, and with the `"` prefix: `"Ayi"` (*with register `A`, `y`ank the `i`nner `"` double quoted text*)
```
:let @a = '' | g/prop/normal! "Ayi"... |
22,097 | <p>When I'm choosing an option from the autocomplete suggestions, it automatically puts my cursor in the following location:</p>
<pre><code>function(|)
</code></pre>
<p>Then I type the value that I want, and in order to get out of the brackets (forward) I have to use the right arrow button, to yield:</p>
<pre><code>... | [
{
"answer_id": 22098,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 2,
"selected": false,
"text": "<p>I use <code><esc>A</code>, it's 2.5 key strokes(0.5 for <code>shift</code>), it's not the shortest solution, but... | 2019/11/29 | [
"https://vi.stackexchange.com/questions/22097",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25181/"
] | When I'm choosing an option from the autocomplete suggestions, it automatically puts my cursor in the following location:
```
function(|)
```
Then I type the value that I want, and in order to get out of the brackets (forward) I have to use the right arrow button, to yield:
```
function(value)|
```
Which is prett... | I use `<esc>A`, it's 2.5 key strokes(0.5 for `shift`), it's not the shortest solution, but it's the most natural one if you are used to move around in normal mode. IMO, `<esc>` doesn't count as a keystroke.
`<c-o>A` works too, but I don't like it, I can't remember the last time i use [:h i\_CTRL-O](https://vimhelp.org... |
22,103 | <p>Are there any permission settings that need set on a file to get persistent undo to work? I close and open my vimrc file and I can keep hitting the u key to see my previous edits. But it does not work for production code files. Any ideas what could be the issue?</p>
<p>Edited to Add:</p>
<p>Here is a sample of my ... | [
{
"answer_id": 22107,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": -1,
"selected": false,
"text": "<p>Persistent undo is controlled by <a href=\"https://vimhelp.org/options.txt.html#%27undofile%27\" rel=\"nofollow noref... | 2019/11/29 | [
"https://vi.stackexchange.com/questions/22103",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9047/"
] | Are there any permission settings that need set on a file to get persistent undo to work? I close and open my vimrc file and I can keep hitting the u key to see my previous edits. But it does not work for production code files. Any ideas what could be the issue?
Edited to Add:
Here is a sample of my .vimrc:
```
" Tu... | After trying out many different ways of opening and editing the file, it appears the issue is that with the "production code" (.module) file, the user snrub was not the owner of the file. I guess in order for persistent undo to work, the user editing the file must be the owner. And `chmod` file permissions are irreleva... |
22,118 | <p>I want to:</p>
<pre><code>let s:asciiart = ["", "", s:hardinclude(system("command params")), "", ""]
</code></pre>
<p>where <code>command</code> returns one string with:</p>
<pre><code>"art-line-1", "art-line-2", "art-line-3"
</code></pre>
<p>so I end up with:</p>
<pre><code>s:asciiart == ["", "", "art-line-1",... | [
{
"answer_id": 22120,
"author": "fde-capu",
"author_id": 25873,
"author_profile": "https://vi.stackexchange.com/users/25873",
"pm_score": 0,
"selected": false,
"text": "<p>Although it would still be fine to find out if a \"hard-include\" would be possible, I answer my own question:</p>\n... | 2019/12/02 | [
"https://vi.stackexchange.com/questions/22118",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25873/"
] | I want to:
```
let s:asciiart = ["", "", s:hardinclude(system("command params")), "", ""]
```
where `command` returns one string with:
```
"art-line-1", "art-line-2", "art-line-3"
```
so I end up with:
```
s:asciiart == ["", "", "art-line-1", "art-line-2", "art-line-3", "", ""]
```
Is there a way to make a wor... | Version 8.2.935 introduced a flatten() function (and version 8.2.937 fixed a bug in that function). With this function you can also write
```
let s:asciiart = flatten(["", "", systemlist("command params"), "", ""])
```
to insert the elements of the inner list into the outer list. |
22,126 | <p>I am using nvim-qt on Windows and I have set up the <code>clipboard</code> option:</p>
<pre><code>set clipboard=unnamedplus
</code></pre>
<p>I found that text in Select mode will go to the <code>+</code>, <code>*</code> and <code>"</code> register after I start to type the replacement text. If I have copied someth... | [
{
"answer_id": 22127,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 4,
"selected": true,
"text": "<p>Vim doesn't want you to lose the deleted text, so it stores the replaced selection in the default register; due to you... | 2019/12/02 | [
"https://vi.stackexchange.com/questions/22126",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15292/"
] | I am using nvim-qt on Windows and I have set up the `clipboard` option:
```
set clipboard=unnamedplus
```
I found that text in Select mode will go to the `+`, `*` and `"` register after I start to type the replacement text. If I have copied something into the `+` and `*` register, it will get wiped out.
How to pre... | Vim doesn't want you to lose the deleted text, so it stores the replaced selection in the default register; due to your `'clipboard'` configuration, this includes the clipboard. The usual way to avoid that is through specifying the [black hole register](https://vimhelp.appspot.com/change.txt.html#quote_), but that's di... |
22,134 | <p>For editing XML files I have the following in my init.vim</p>
<pre><code>" Automatically enable folding of XML-files
augroup XML
autocmd!
autocmd FileType xml let g:xml_syntax_folding=1
autocmd FileType xml setlocal foldmethod=syntax
autocmd FileType xml :syntax on
autocmd FileType xml :%foldopen!
augroup... | [
{
"answer_id": 22135,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 2,
"selected": false,
"text": "<h3>Automatic detections</h3>\n\n<p>The <a href=\"http://www.vim.org/scripts/script.php?script_id=1506\" rel=\"nofollow ... | 2019/12/03 | [
"https://vi.stackexchange.com/questions/22134",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11633/"
] | For editing XML files I have the following in my init.vim
```
" Automatically enable folding of XML-files
augroup XML
autocmd!
autocmd FileType xml let g:xml_syntax_folding=1
autocmd FileType xml setlocal foldmethod=syntax
autocmd FileType xml :syntax on
autocmd FileType xml :%foldopen!
augroup END
```
Thi... | First I applogize for answering my own question, I know this is bad style. However my preferred solution is a mixture of the answers given by @Matt and @Ingo.
The point is that for large files you really want to avoid foldmethod=syntax from the beginning. `foldenable` just hides the folds, they still get "computed". A... |
22,145 | <p>I am trying to map <kbd>Ctrl</kbd><kbd>(</kbd> in insert mode. However, Vim does not recognize the key binding. This is what I currently have:</p>
<pre><code>" Insert a pair of brackets using Ctrl-(
inoremap <C-(> ()<left>
</code></pre>
<p>Why does vim ignore the key binding?</p>
| [
{
"answer_id": 22146,
"author": "jdhao",
"author_id": 15292,
"author_profile": "https://vi.stackexchange.com/users/15292",
"pm_score": 1,
"selected": false,
"text": "<p>Try <code>inoremap <C-9> ()<Left></code>. It seems that Vim does not recognize the <code>(</code> in insert... | 2019/12/04 | [
"https://vi.stackexchange.com/questions/22145",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19712/"
] | I am trying to map `Ctrl``(` in insert mode. However, Vim does not recognize the key binding. This is what I currently have:
```
" Insert a pair of brackets using Ctrl-(
inoremap <C-(> ()<left>
```
Why does vim ignore the key binding? | Vim does not ignore the keybinding. It just can't be reliably detected. See the [faq](https://vimhelp.org/vim_faq.txt.html#faq-20.5):
>
> The only Ctrl-printable-key chords which Vim can reliably detect
> (because they are defined in the ASCII standard) are the following:
>
>
>
> ```
> Ctrl-@ ... |
22,159 | <p>I want to create a regex that matches strings within single or double quotes in vim and that considers the fact that some strings might have escaped single quotes or double quotes.</p>
<p>So far, I've found <a href="https://stackoverflow.com/questions/171480/regex-grabbing-values-between-quotation-marks">this answe... | [
{
"answer_id": 22161,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 2,
"selected": false,
"text": "<p>In the department of simplified versions this may do...</p>\n\n<pre><code>\\v(['\"]).{-}[^\\\\]\\1\n</code></pre>\n\n... | 2019/12/05 | [
"https://vi.stackexchange.com/questions/22159",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22995/"
] | I want to create a regex that matches strings within single or double quotes in vim and that considers the fact that some strings might have escaped single quotes or double quotes.
So far, I've found [this answer](https://stackoverflow.com/questions/171480/regex-grabbing-values-between-quotation-marks) in an stackover... | You can solve that with this regex:
```
\v(['"])%(\1@![^\\]|\\.)*\1
```
Which will solve all of your test cases, plus others such as `"\\"` or `'\\'`.
Explaining it:
* `\v`: Use "verymagic" mode, so we don't need to backslash parens, etc.
* `(['"])`: Matches either a single or double quote and store it in `\1`.
* ... |
22,162 | <p>I have following line in my <code>.nvimrc</code></p>
<blockquote>
<p>au! BufWritePost *.elm ElmMake</p>
</blockquote>
<p>Each time I save an elm file vim tells me that this command does not exist.
However I am able to run this command in command more while editing elm file, so there is no doubt in my mind that t... | [
{
"answer_id": 22163,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 1,
"selected": false,
"text": "<p>Looks like you try to add an autocommand but remove it instead:</p>\n\n<pre><code>3. Removing autocommands ... | 2019/12/05 | [
"https://vi.stackexchange.com/questions/22162",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5827/"
] | I have following line in my `.nvimrc`
>
> au! BufWritePost \*.elm ElmMake
>
>
>
Each time I save an elm file vim tells me that this command does not exist.
However I am able to run this command in command more while editing elm file, so there is no doubt in my mind that this command does exist.
I should point ou... | I believe the problem you're having is due to the command being registered with `-buffer`, which means it's only available in buffers of filetype "elm" and for some reason are not available in the autocmd.
Why that is happening, I can't really tell... The event you're using (`BufWritePost`) is a buffer-specific exampl... |
22,171 | <p>While I was studying Tpope's vim-commentary, I was struck by a line that contains the topic of this question.
I am referring to one of the lines in Tpope's vim-commentary:
<a href="https://github.com/tpope/vim-commentary/blob/f8238d70f873969fb41bf6a6b07ca63a4c0b82b1/plugin/commentary.vim#L101" rel="nofollow noreferr... | [
{
"answer_id": 22172,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<blockquote>\n <p>does that mean go() evaluates to empty string which is concatenated by \"_\"?</p>\n</blockquote>\n\n<p>I... | 2019/12/05 | [
"https://vi.stackexchange.com/questions/22171",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25969/"
] | While I was studying Tpope's vim-commentary, I was struck by a line that contains the topic of this question.
I am referring to one of the lines in Tpope's vim-commentary:
<https://github.com/tpope/vim-commentary/blob/f8238d70f873969fb41bf6a6b07ca63a4c0b82b1/plugin/commentary.vim#L101>
```
nnoremap <expr> <Plug>Comm... | It turns out that, when called without arguments, `go()` actually sets `'operatorfunc'` and returns `'g@'`. (See [this code snippet](https://github.com/tpope/vim-commentary/blob/f8238d70f873969fb41bf6a6b07ca63a4c0b82b1/plugin/commentary.vim#L28-L30).)
So the concatenation of `'g@' . '_'` results in the `g@_` command b... |
22,174 | <p>Consider you are editing the left table in Vim. Your cursor (■) is at Line 14, Column 12.</p>
<pre><code>Where you are now Move the cursor
11 +-------+-----+ 11 +-------+-----+
12 | Name | Age | 12 | Name | Age |
13 +=======+=====+ 13 +=======+=====+
14 | Alice | 5■ | --> ... | [
{
"answer_id": 22176,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 0,
"selected": false,
"text": "<p>Assuming the 96th line actually has column no. 12 (or <code>set virtualedit=all</code>), you can do <code>96zz</code> (o... | 2019/12/05 | [
"https://vi.stackexchange.com/questions/22174",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25977/"
] | Consider you are editing the left table in Vim. Your cursor (■) is at Line 14, Column 12.
```
Where you are now Move the cursor
11 +-------+-----+ 11 +-------+-----+
12 | Name | Age | 12 | Name | Age |
13 +=======+=====+ 13 +=======+=====+
14 | Alice | 5■ | --> 14 | Alice | 5 ... | Turn off [:h 'startofline'](https://vimhelp.org/options.txt.html#%27startofline%27) :
```
set nostartofline
```
And execute one of the following command:
```
96G
:96
:/Zoe
```
It will place cursor at target line without moving horizontally if target line is longer enough.
Commands starts with `:` are ex command,... |
22,196 | <p>This is what I'm trying to achieve:</p>
<p>input</p>
<pre><code>(|)foo
</code></pre>
<p>then pressing some key combination to get</p>
<p>output</p>
<pre><code>(foo)|
</code></pre>
<p>or</p>
<pre><code>(foo|)
</code></pre>
<p>I know this can be done with the autopairs plugin. In the docs they write that the d... | [
{
"answer_id": 22197,
"author": "jdhao",
"author_id": 15292,
"author_profile": "https://vi.stackexchange.com/users/15292",
"pm_score": 0,
"selected": false,
"text": "<p>Maybe you can define another mapping for <code><M-e></code> mapping in insert mode. <code>imap <M-e></code>... | 2019/12/07 | [
"https://vi.stackexchange.com/questions/22196",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25181/"
] | This is what I'm trying to achieve:
input
```
(|)foo
```
then pressing some key combination to get
output
```
(foo)|
```
or
```
(foo|)
```
I know this can be done with the autopairs plugin. In the docs they write that the default binding is M-}. I am using Vim/iTerm2/Mac, and I can't seem to figure out how t... | I don't think there's a need of having another mapping at all.
It's enough to press `%` once or twice to get on the right "paren". Then `x``$``p` and you're done. |
22,212 | <p>I am using a convenient macro to list my buffers: <code>map <leader>bb :buffers<cr></code></p>
<p>I am trying to come up with a way to then switch to the buffer of interest with <code><leader>b<number></code> but I haven't found how to catch a number in this map. I assume there should be som... | [
{
"answer_id": 22213,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 2,
"selected": false,
"text": "<p>For single-digit buffers, you can actually hardcode 9 mappings, one for each digit:</p>\n\n<pre><code>nnoremap <... | 2019/12/09 | [
"https://vi.stackexchange.com/questions/22212",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26028/"
] | I am using a convenient macro to list my buffers: `map <leader>bb :buffers<cr>`
I am trying to come up with a way to then switch to the buffer of interest with `<leader>b<number>` but I haven't found how to catch a number in this map. I assume there should be some kind of delay involved in case I have a 2-digit number... | >
> I am using a convenient macro
>
>
>
Just FYI, one can also do `:ls<CR>` to achieve the same result. So that one does not look like "a life saver" to me.
>
> a way to then switch to the buffer of interest
>
>
>
Again, that does not look so useful, as one can always do `:b[Number]<CR>` without any hassle. ... |
22,216 | <p>If I am using IntelliJ and I hover over a close bracket for a scope that starts somewhere that is not currently visible, it shows a popup at the top of the window previewing the line where with the corresponding open bracket.</p>
<p><a href="https://i.stack.imgur.com/JGQPm.png" rel="nofollow noreferrer"><img src="h... | [
{
"answer_id": 22217,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>You could <em>probably</em> mess around with the new popup features.</p>\n\n<p>Or you <em>might</em> be able to... | 2019/12/09 | [
"https://vi.stackexchange.com/questions/22216",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26037/"
] | If I am using IntelliJ and I hover over a close bracket for a scope that starts somewhere that is not currently visible, it shows a popup at the top of the window previewing the line where with the corresponding open bracket.
[](https://i.stack.imgur.... | Yes- the plugin match-up has this feature: <https://github.com/andymass/vim-matchup>
[](https://i.stack.imgur.com/0sAiT.gif)
[](https://i.stack.imgur.com/ZRd07.png)
Using the option... |
22,224 | <p>My Neovim cursor normally switches to a pipe symbol (<code>|</code>) when I'm in <code>st</code>, but it doesn't when <code>tmux</code> is open in <code>st</code>. Is there something special to do?</p>
<p>Version:</p>
<blockquote>
<p>Neovim: <code>v0.5.0-dev</code><br>
Tmux: <code>2.9a</code></p>
</blockquote>... | [
{
"answer_id": 22225,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 0,
"selected": false,
"text": "<p>For Vim (not NeoVim), it all has to do with special terminal escape sequences (see <code>:help terminal-options... | 2019/12/10 | [
"https://vi.stackexchange.com/questions/22224",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26050/"
] | My Neovim cursor normally switches to a pipe symbol (`|`) when I'm in `st`, but it doesn't when `tmux` is open in `st`. Is there something special to do?
Version:
>
> Neovim: `v0.5.0-dev`
>
> Tmux: `2.9a`
>
>
>
My config files:
* [Neovim](https://github.com/AnatoleLucet/dotfile/tree/master/nvim)
* [Tmux](ht... | You need to tell Tmux how to translate the control sequences sent by Nvim to the outer terminal, here st.
This is done by setting the unofficial extensions to terminfo `Ss` and `Se`.
From `man tmux`:
>
>
> ```
> Ss, Se Set or reset the cursor style. If set, a sequence such as this
> may be used to change ... |
22,244 | <p>I have a couple of <code>autocmd</code>s in my vim config along the lines of this (the actual commands are quite long):</p>
<pre><code> au BufWritePost *.latex.md silent! ...
au BufWritePost *.md silent! ...
</code></pre>
<p>where writing files with <code>.md</code> or <code>.latex.md</code> extensions ru... | [
{
"answer_id": 22245,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 2,
"selected": true,
"text": "<p>There's more to the autocmd pattern than <code>*</code>. Using other wildcards should give more flexibility in craftin... | 2019/12/13 | [
"https://vi.stackexchange.com/questions/22244",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26025/"
] | I have a couple of `autocmd`s in my vim config along the lines of this (the actual commands are quite long):
```
au BufWritePost *.latex.md silent! ...
au BufWritePost *.md silent! ...
```
where writing files with `.md` or `.latex.md` extensions runs pandoc to convert my markdown files into the correspondi... | There's more to the autocmd pattern than `*`. Using other wildcards should give more flexibility in crafting patterns that don't overlap.
The problem is that the pattern matching for autocmd is not standard/vim regex and it's not shell-like globbing. It's a modified version of vim regex. Example: `.` represents a peri... |
22,247 | <p>Working in an index with mucked up manual folds. Would like to delete folds from current line to end of file.</p>
<p>Have tried:</p>
<pre><code>:.,$zd
</code></pre>
<p>and</p>
<pre><code>:.,$df
</code></pre>
<p>So far I've just done a visual selection from current line to end of file and keyed in:</p>
<pre><co... | [
{
"answer_id": 22248,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 0,
"selected": false,
"text": "<p>I'm not sure if it's a good idea, but you can wrap it into Ex command:</p>\n\n<pre><code>command! -bar -range DeleteFold... | 2019/12/13 | [
"https://vi.stackexchange.com/questions/22247",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/23470/"
] | Working in an index with mucked up manual folds. Would like to delete folds from current line to end of file.
Have tried:
```
:.,$zd
```
and
```
:.,$df
```
So far I've just done a visual selection from current line to end of file and keyed in:
```
zD
```
to delete all folds recursively in the selection. Works... | You can use the [`:normal`](https://vimhelp.org/various.txt.html#%3Anormal) command to execute a normal command such as `zD` for all lines in a range.
To execute that command in all lines from the current one until the end of the file, you can use:
```
:.,$normal! zD
```
I'm using `:normal!` to ignore any mappings ... |
22,253 | <p>In most cases, I want to use the same setting. However, when I write the makefile file, I need to use tab instead of space, so I need to execute the <code>:set noexpandtab</code> for all the makefile file. In order to simplify this process, I want to write this to .vimrc, but I don't know how to execute this command... | [
{
"answer_id": 22254,
"author": "th1rdey3",
"author_id": 9062,
"author_profile": "https://vi.stackexchange.com/users/9062",
"pm_score": 1,
"selected": false,
"text": "<p>You can use <code>autocmd</code> for this. First run the following command to know the FileType (while your makefile i... | 2019/12/15 | [
"https://vi.stackexchange.com/questions/22253",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/23637/"
] | In most cases, I want to use the same setting. However, when I write the makefile file, I need to use tab instead of space, so I need to execute the `:set noexpandtab` for all the makefile file. In order to simplify this process, I want to write this to .vimrc, but I don't know how to execute this command according to ... | [As I have written about extensively](https://vi.stackexchange.com/a/15329/10604), the vim technique for this type of thing is called an `ftplugin`, which stands for filetype-plugin. What that means is that certain filetypes have different settings than others. `make` is one such filetype.
Vim comes with a set of fil... |
22,257 | <p>I sometimes want to type an expression like this:</p>
<pre><code>table[row][col] = std::max(table[row][col], other_table[row+1][col+1])
</code></pre>
<p>(this is C++ code. Unfortunately there's no way in C++ to eliminate the duplication except by writing a helper function like <code>void update_max(auto& a, au... | [
{
"answer_id": 22258,
"author": "user202729",
"author_id": 26108,
"author_profile": "https://vi.stackexchange.com/users/26108",
"pm_score": 2,
"selected": false,
"text": "<p>It's possible to use a mapping:</p>\n\n<pre><code>inoremap <silent> sf <c-r><c-r>=getline('.')[:... | 2019/12/15 | [
"https://vi.stackexchange.com/questions/22257",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26108/"
] | I sometimes want to type an expression like this:
```
table[row][col] = std::max(table[row][col], other_table[row+1][col+1])
```
(this is C++ code. Unfortunately there's no way in C++ to eliminate the duplication except by writing a helper function like `void update_max(auto& a, auto const& b) { a = std::max(a, b); ... | You can repeat the last inserted text in insert mode using [`CTRL-R .`](http://vimdoc.sourceforge.net/htmldoc/insert.html#i_CTRL-R) or [`CTRL-A`](http://vimdoc.sourceforge.net/htmldoc/insert.html#i_CTRL-A)
But you need to leave insert mode to complete the change. Enter insert mode and type
```
table[row][col]
```
T... |
22,275 | <p>How to make (N)Vim auto save buffer on Tmux <code>select-pane</code>? In my <code>vimrc</code> I tried:</p>
<pre><code>" Auto save when buffer lose focus
autocmd FocusLost,BufLeave * silent! wa
" Save on buffer change
set autowrite
</code></pre>
<p>But it does not work. In Termite (terminal emulator), in Tmux wh... | [
{
"answer_id": 22276,
"author": "Nicholas Marriott",
"author_id": 25695,
"author_profile": "https://vi.stackexchange.com/users/25695",
"pm_score": 2,
"selected": false,
"text": "<p>I don't know if vim supports focus but if it does you will at least need to turn focus-events on in .tmux.c... | 2019/12/17 | [
"https://vi.stackexchange.com/questions/22275",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25849/"
] | How to make (N)Vim auto save buffer on Tmux `select-pane`? In my `vimrc` I tried:
```
" Auto save when buffer lose focus
autocmd FocusLost,BufLeave * silent! wa
" Save on buffer change
set autowrite
```
But it does not work. In Termite (terminal emulator), in Tmux while cursor in vim pane, I press `<C-|>l` to sele... | I don't know if vim supports focus but if it does you will at least need to turn focus-events on in .tmux.conf:
```
set -g focus-events on
``` |
22,278 | <p>When I use the following command to set the color of my vim,</p>
<pre><code>:highlight Error ctermfg=#00afff
</code></pre>
<p>it prompts <code>E421: Color name or number not recognized: ctermfg=#00afff</code></p>
| [
{
"answer_id": 22279,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": false,
"text": "<p>It's because <a href=\"http://vimhelp.appspot.com/syntax.txt.html#highlight-ctermfg\" rel=\"noreferrer\"><code>:h highli... | 2019/12/17 | [
"https://vi.stackexchange.com/questions/22278",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26138/"
] | When I use the following command to set the color of my vim,
```
:highlight Error ctermfg=#00afff
```
it prompts `E421: Color name or number not recognized: ctermfg=#00afff` | `ctermfg` and `ctermbg` use indices into the limited color palettes (8 / 16 / 88 or 256 colors) of terminals and do not support the full 24-bit RGB values.
I think you're looking for the [`'termguicolors'`](https://vimhelp.appspot.com/options.txt.html#%27termguicolors%27) option, which makes Vim apply the GUI color at... |
22,313 | <p>Following the answers in I have tried many varieties of setting the <code>font</code> size and face in <code>~/.vimrc</code> . None of them have any effect</p>
<pre><code>set guifont=Menlo:h12
set guifont=Monaco:h12
set guifont=Menlo\ Regular:h12
</code></pre>
<p>Note that executing </p>
<pre><code>:set gfn=*
</... | [
{
"answer_id": 22315,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": true,
"text": "<p>Since font is specific to the GUI versions of vim (i.e. gvim and macvim), you <s>need to</s> <em>should</em> put... | 2019/12/21 | [
"https://vi.stackexchange.com/questions/22313",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16428/"
] | Following the answers in I have tried many varieties of setting the `font` size and face in `~/.vimrc` . None of them have any effect
```
set guifont=Menlo:h12
set guifont=Monaco:h12
set guifont=Menlo\ Regular:h12
```
Note that executing
```
:set gfn=*
```
*does* bring up a font chooser dialog - and I am able to... | Since font is specific to the GUI versions of vim (i.e. gvim and macvim), you ~~need to~~ *should* put the `set guifont=...` line in your gvimrc.
A good place for that is `~/.vim/gvimrc`, but you can read `help gvimrc` for locations.
According to `setting-guifont`:
```
... |
22,314 | <p>I currently use scratch buffers a lot for various uses such as when I read from STDIN to quickly analyze some data or take some very temporary notes. That way I don't have to worry about a swap file or the quit message when I leave the buffer. However, once in a while I decide to save the file for future reference. ... | [
{
"answer_id": 22316,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 3,
"selected": true,
"text": "<h2>Some notes</h2>\n\n<ul>\n<li><p>You don't need both <code>StdinReadPre</code> and <code>StdinReadPost</code>, one is e... | 2019/12/21 | [
"https://vi.stackexchange.com/questions/22314",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26206/"
] | I currently use scratch buffers a lot for various uses such as when I read from STDIN to quickly analyze some data or take some very temporary notes. That way I don't have to worry about a swap file or the quit message when I leave the buffer. However, once in a while I decide to save the file for future reference. I'm... | Some notes
----------
* You don't need both `StdinReadPre` and `StdinReadPost`, one is enough.
* `TurnOnScratchBuffer` and `TurnOffScratchBuffer` are valid `command`, they can be executed directly without `execute`, the leading `:` is also redundant.
* Don't use `"` with `:set`, [:h :quote](https://vimhelp.org/cmdline... |
22,329 | <p>According to the <code>:help startup-options</code>, this is <code>-w</code>'s behviour</p>
<pre><code>-w {scriptout} All the characters that you type are recorded in the file
"scriptout", until you exit Vim. This is useful if you want
to create a script file to be used with "vim -... | [
{
"answer_id": 22333,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<p>It looks like a nasty bug.</p>\n\n<p>When writing a script out, Vim uses its \"<>-notation\" for keycodes, i.e. <code... | 2019/12/23 | [
"https://vi.stackexchange.com/questions/22329",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7725/"
] | According to the `:help startup-options`, this is `-w`'s behviour
```
-w {scriptout} All the characters that you type are recorded in the file
"scriptout", until you exit Vim. This is useful if you want
to create a script file to be used with "vim -s" or
":source!".
`... | This is a bug registered on [March 17th,
2019](https://github.com/vim/vim/commit/26967617a30e55aedc98b8f14b841d88469abd0e#diff-38d7929bd26d74d92ceddf984bbfc8dbR164-R173)
and reported on [February 24th, 2019](https://github.com/vim/vim/issues/4041). From [`:help known-bugs`](https://vimhelp.org/todo.txt.html#known-bugs)... |
22,330 | <p>I'm editing an HTML file, and my cursor is inside a tag, like this:</p>
<pre><code><textarea class="code-area"></textarea>
</code></pre>
<p>And I'm trying to wrap all of this tag inside a <code>div</code> tag, so that it'd be like this:</p>
<pre><code><div>
<textarea class="code-area">... | [
{
"answer_id": 22331,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 4,
"selected": true,
"text": "<p>In <a href=\"https://github.com/tpope/vim-surround\" rel=\"noreferrer\">vim-surround</a> <code>ys{motion}</code> puts \"a... | 2019/12/24 | [
"https://vi.stackexchange.com/questions/22330",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26169/"
] | I'm editing an HTML file, and my cursor is inside a tag, like this:
```
<textarea class="code-area"></textarea>
```
And I'm trying to wrap all of this tag inside a `div` tag, so that it'd be like this:
```
<div>
<textarea class="code-area"></textarea>
</div>
```
I can use [vim-surround](https://github.com/tpo... | In [vim-surround](https://github.com/tpope/vim-surround) `ys{motion}` puts "a surround text" on the same line. To place it on a line of its own with indent you should use `yS{motion}` instead.
Next, a motion you want for this case is `:h at` (a tag). So this results in `y``S``a``t``<``d``i``v``>` |
22,334 | <p>I want to enable some configurations only when the distribution is Fedora. Here is my code.</p>
<pre><code>let s:os = system("sed -n 's/^NAME=\(.*\)/\1/p' /etc/os-release")
echo s:os
if s:os == "Fedora"
" some configurations
endif
</code></pre>
<p>This snippet doesn't work and the <code>s:os</code> is an e... | [
{
"answer_id": 22335,
"author": "Jair López",
"author_id": 6698,
"author_profile": "https://vi.stackexchange.com/users/6698",
"pm_score": 2,
"selected": false,
"text": "<p>@Matt is absolutely right; you might use double backslashes:</p>\n\n<pre><code>let s:os = system(\"sed -n 's/^NAME=\... | 2019/12/24 | [
"https://vi.stackexchange.com/questions/22334",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26138/"
] | I want to enable some configurations only when the distribution is Fedora. Here is my code.
```
let s:os = system("sed -n 's/^NAME=\(.*\)/\1/p' /etc/os-release")
echo s:os
if s:os == "Fedora"
" some configurations
endif
```
This snippet doesn't work and the `s:os` is an empty string. However, the sed command... | The trouble you're having is with the backslashes inside the string (as @Matt correctly pointed out in the comments.)
Vim strings (using double-quotes as delimiters) interpret the backslash as a special character, so you need to escape them with an additional backslash if you want to use them in a double-quoted string... |
22,346 | <p>In the type of <code>c</code> programming that I do day to day, I often have to "fill" struct members in order to pass them to an API. For example:</p>
<pre><code>struct measurement {
double start_time;
double end_time;
double elapsed_ms;
// …
}
struct measurement my_measurement;
my_measurement.start_time = 0.0;
... | [
{
"answer_id": 22347,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p>At this time, I have something extremely similar in my <a href=\"https://github.com/LucHermitte/lh-cpp/\" rel=\"nofo... | 2019/12/26 | [
"https://vi.stackexchange.com/questions/22346",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25193/"
] | In the type of `c` programming that I do day to day, I often have to "fill" struct members in order to pass them to an API. For example:
```
struct measurement {
double start_time;
double end_time;
double elapsed_ms;
// …
}
struct measurement my_measurement;
my_measurement.start_time = 0.0;
my_measurement.end_time = ... | readtags
--------
`universal-ctags` provide [readtags](https://docs.ctags.io/en/latest/news.html#readtags) to filter tags:
Read all members of a `struct`:
```
readtags -Q '(and (eq? $kind "member") (eq? $scope-name "struct_name") )' -l
```
* `(and (...) (...))`: `(...)` and `(...)`
* `(eq? $kind "member")` restric... |
22,359 | <p>I have Vim 7 installed from my distro's package manager, and I compiled Vim 8 from source. Vim 8 is all in /usr/local. Then I created a new directory in $HOME called ".vim8". I have all my Vim 7 stuff in $HOME/.vim/, and I want a clean directory for Vim 8 in $HOME/.vim8/.</p>
<p>For Vim 8, I'm calling it like this:... | [
{
"answer_id": 22360,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 4,
"selected": true,
"text": "<p>The specific path you're using (<code><b>pack/</b>vendor<b>/start/</b>nerdtree</code>) is using the <a href=\"https... | 2019/12/27 | [
"https://vi.stackexchange.com/questions/22359",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9766/"
] | I have Vim 7 installed from my distro's package manager, and I compiled Vim 8 from source. Vim 8 is all in /usr/local. Then I created a new directory in $HOME called ".vim8". I have all my Vim 7 stuff in $HOME/.vim/, and I want a clean directory for Vim 8 in $HOME/.vim8/.
For Vim 8, I'm calling it like this: `/usr/loc... | The specific path you're using (`**pack/**vendor**/start/**nerdtree`) is using the ["packages" feature](https://vimhelp.org/repeat.txt.html#packages), which is a new Vim 8 feature that automates manipulation of `'runtimepath'` in a way similar to how plug-in managers have been implemented.
That's why your attempt sett... |
22,372 | <p>I would like to put in the quickfix the files <strong>not matching</strong> a pattern. That it, these files don't have any line matching the search pattern.</p>
<p>I know that for finding files whose content match a pattern I may use the <code>:vimgrep</code> command, that alongside with <code>:cnext</code> or <cod... | [
{
"answer_id": 22375,
"author": "user938271",
"author_id": 17449,
"author_profile": "https://vi.stackexchange.com/users/17449",
"pm_score": 2,
"selected": false,
"text": "<p>One way to do it would be to:</p>\n\n<ol>\n<li>use <code>:args</code> to populate the arglist with all the files i... | 2019/12/30 | [
"https://vi.stackexchange.com/questions/22372",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8939/"
] | I would like to put in the quickfix the files **not matching** a pattern. That it, these files don't have any line matching the search pattern.
I know that for finding files whose content match a pattern I may use the `:vimgrep` command, that alongside with `:cnext` or `:cnf` makes the possibility of navigate through ... | One way to do it would be to:
1. use `:args` to populate the arglist with all the files in which you're interested
2. use `search()` to check whether your pattern can be found in each file, and if it does not, add its path to a list
3. give that list to `getqflist()` to transform it into a quickfix list, and invoke `s... |
22,373 | <p>NeoVim is not recognising <a href="https://solidity.readthedocs.io/en/v0.6.0/#" rel="nofollow noreferrer">Solidity</a> filetypes (which end with the extension <code>.sol</code>).</p>
<p>When editing a <code>.sol</code> file typing:</p>
<p><code>:set filetype?</code> </p>
<p>generates a <code>filetype=</code> (e.g... | [
{
"answer_id": 22407,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": true,
"text": "<p>Vim 8.1.2250 does not ship with filetype detection for solidity. (One can confirm with <code>:edit $VIMRUNTIME/f... | 2019/12/30 | [
"https://vi.stackexchange.com/questions/22373",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20086/"
] | NeoVim is not recognising [Solidity](https://solidity.readthedocs.io/en/v0.6.0/#) filetypes (which end with the extension `.sol`).
When editing a `.sol` file typing:
`:set filetype?`
generates a `filetype=` (e.g. blank). This is in contrast to html, md, php, etc files which all produce the expected result.
My init... | Vim 8.1.2250 does not ship with filetype detection for solidity. (One can confirm with `:edit $VIMRUNTIME/filetype.vim` and then `:global /sol/`.)
ALE has Solidity linters, but they require the filetype to be set.
The simplest solution is to create `~/.vim/ftdetect/solidity.vim` and add
```
au BufNewFile,BufRead *.s... |
22,384 | <p>Using Vim 7.4. My ~/.vimrc file consists <em>only</em> of the following:</p>
<pre><code>set nocompatible
filetype off
</code></pre>
<p>If I run vim with verbose logging level 2 by using the following command:</p>
<pre><code>vim -V2./file.log .vimrc
</code></pre>
<p>...it gives the following error in file.log:</p... | [
{
"answer_id": 22385,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 0,
"selected": false,
"text": "<blockquote>\n <p>is there a better way to set filetype off than the filetype off command?</p>\n</blockquote>\n\n<p><code>... | 2019/12/31 | [
"https://vi.stackexchange.com/questions/22384",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9047/"
] | Using Vim 7.4. My ~/.vimrc file consists *only* of the following:
```
set nocompatible
filetype off
```
If I run vim with verbose logging level 2 by using the following command:
```
vim -V2./file.log .vimrc
```
...it gives the following error in file.log:
```
line 5: sourcing "/usr/share/vim/vim74/ftoff.vim"
Err... | The fact that you are getting this message on your verbose log file is expected.
The Vim source code has [an explicit comment about that](https://github.com/vim/vim/blob/v7.4/src/message.c#L625,L628):
```
/*
* When using ":silent! cmd" ignore error messages.
* But do write it to the redirection file.
*/
```
I li... |
22,398 | <p>I would like to disable or hide Lightline (i.e. vim's statusline) when my cursor is in Nerdtree, while keeping it activated for other buffers.</p>
<p>Here is what I mean: </p>
<p><img src="https://framapic.org/CaRviW01Eb9Y/OFmRKWj4qMLo.png" alt="image"></p>
<p>How can I achieve this? </p>
<p>Lightline's developp... | [
{
"answer_id": 22402,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<p>Of course, your attempt won't work, because Lightline forcefully updates status line content on many auto events. That's... | 2020/01/01 | [
"https://vi.stackexchange.com/questions/22398",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26181/"
] | I would like to disable or hide Lightline (i.e. vim's statusline) when my cursor is in Nerdtree, while keeping it activated for other buffers.
Here is what I mean:

How can I achieve this?
Lightline's developper says it is not possible with Lightline its... | It's a hack, but you could try this:
```
augroup filetype_nerdtree
au!
au FileType nerdtree call s:disable_lightline_on_nerdtree()
au WinEnter,BufWinEnter,TabEnter * call s:disable_lightline_on_nerdtree()
augroup END
fu s:disable_lightline_on_nerdtree() abort
let nerdtree_winnr = index(map(range(1, wi... |
22,400 | <p>I like using vim to edit csv files.
But I often have to resort to localc when doing actual maths on them.
Is there a way to use Math inside a vim Macro? Basicly adding 2 cells together and outputting them to a new third one?</p>
<pre><code>7,6,(13)
</code></pre>
| [
{
"answer_id": 22401,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 5,
"selected": true,
"text": "<p>Yes, you can perform arithmetic expressions in Vim by using the <a href=\"https://vimhelp.org/change.txt.html#quote... | 2020/01/01 | [
"https://vi.stackexchange.com/questions/22400",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/23073/"
] | I like using vim to edit csv files.
But I often have to resort to localc when doing actual maths on them.
Is there a way to use Math inside a vim Macro? Basicly adding 2 cells together and outputting them to a new third one?
```
7,6,(13)
``` | Yes, you can perform arithmetic expressions in Vim by using the [expression register](https://vimhelp.org/change.txt.html#quote%3D), which you can access from insert mode using [CTRL-R](https://vimhelp.org/insert.txt.html#i_CTRL-R).
Another alternative is to use [expressions in the replacement of a `:substitute` comma... |
22,409 | <p>I can open a file with vim on the command line like so:</p>
<pre><code>vim fnord.txt +50
</code></pre>
<p>And it will take me to the 50th line</p>
<p>Is it possible to do the same thing with <code>:split</code>? So far I haven't been able to figure out how to do it. </p>
<ul>
<li><code>:split fnord.txt +50</code... | [
{
"answer_id": 22410,
"author": "eyal karni",
"author_id": 18375,
"author_profile": "https://vi.stackexchange.com/users/18375",
"pm_score": 1,
"selected": false,
"text": "<p><code>:split file | :50</code> should work, from command line.\nThe separator separate commands. A number typed as... | 2020/01/02 | [
"https://vi.stackexchange.com/questions/22409",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5574/"
] | I can open a file with vim on the command line like so:
```
vim fnord.txt +50
```
And it will take me to the 50th line
Is it possible to do the same thing with `:split`? So far I haven't been able to figure out how to do it.
* `:split fnord.txt +50`
* `:split fnord.txt ++50`
* `:split fnord.txt:50`
None of these... | You are so close:
```
:split +50 fnord.txt
```
All commands in vim that create new buffer has prototype:
```
cmd [++opt] [+cmd] [file]
```
All commands in vim that write buffer to your disk has prototype:
```
cmd [++opt] [file]
```
[:h ++opt](https://vimhelp.org/editing.txt.html#%2B%2Bopt) is only used for spe... |
22,412 | <p>In vimL, how to get a string from cursor to end of <code><cWORD></code>.</p>
<p>I know <code>expand('<cWORD>'</code>, but don't known how to keep only right part of cursor.</p>
<p><strong>Example</strong></p>
<p>given text <code>pre abc-xyz.xxx:123 post</code>,</p>
<p>with cursor at <code>-</code>, <... | [
{
"answer_id": 22410,
"author": "eyal karni",
"author_id": 18375,
"author_profile": "https://vi.stackexchange.com/users/18375",
"pm_score": 1,
"selected": false,
"text": "<p><code>:split file | :50</code> should work, from command line.\nThe separator separate commands. A number typed as... | 2020/01/03 | [
"https://vi.stackexchange.com/questions/22412",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10254/"
] | In vimL, how to get a string from cursor to end of `<cWORD>`.
I know `expand('<cWORD>'`, but don't known how to keep only right part of cursor.
**Example**
given text `pre abc-xyz.xxx:123 post`,
with cursor at `-`,
return string `-xyz.xxx:123`. | You are so close:
```
:split +50 fnord.txt
```
All commands in vim that create new buffer has prototype:
```
cmd [++opt] [+cmd] [file]
```
All commands in vim that write buffer to your disk has prototype:
```
cmd [++opt] [file]
```
[:h ++opt](https://vimhelp.org/editing.txt.html#%2B%2Bopt) is only used for spe... |
22,416 | <p>Is there a shortcut for going to the trailing curly brace in a long piece of code?</p>
<p>In a few editors if I double click the <code>{</code> it takes me to the trailing brace <code>}</code>.</p>
<p>While writing large pieces of code I seem to forget to add this at times and also it would make debugging easy if... | [
{
"answer_id": 22421,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>Are you looking for <a href=\"http://vimhelp.appspot.com/motion.txt.html#%25\" rel=\"noreferrer\"><code>:h %</code></a>?<... | 2020/01/03 | [
"https://vi.stackexchange.com/questions/22416",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26339/"
] | Is there a shortcut for going to the trailing curly brace in a long piece of code?
In a few editors if I double click the `{` it takes me to the trailing brace `}`.
While writing large pieces of code I seem to forget to add this at times and also it would make debugging easy if such an implementation is available.
I... | Are you looking for [`:h %`](http://vimhelp.appspot.com/motion.txt.html#%25)?
```
% Find the next item in this line after or under the
cursor and jump to its match. |inclusive| motion.
Items can be:
([{}]) parenthesis or (curly/square) brackets
(th... |
22,429 | <p>The string that I have is this <code>aaabbbb</code>. <code>aaa</code> must become red, <code>bbbb</code> must become blue.</p>
<p>I tried this:</p>
<pre><code>" here xB is not matched
syntax match xA /^a\+/
syntax match xB /^a\+\zsb\+/
highlight xA ctermfg=red
highlight xB ctermfg=blue
" here xB is matched
synta... | [
{
"answer_id": 22418,
"author": "Gustav Blomqvist",
"author_id": 2689,
"author_profile": "https://vi.stackexchange.com/users/2689",
"pm_score": 0,
"selected": false,
"text": "<p><code>:PluginInstall</code> is the install command for Vundle. If it does not work Vundle is not installed cor... | 2020/01/05 | [
"https://vi.stackexchange.com/questions/22429",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14744/"
] | The string that I have is this `aaabbbb`. `aaa` must become red, `bbbb` must become blue.
I tried this:
```
" here xB is not matched
syntax match xA /^a\+/
syntax match xB /^a\+\zsb\+/
highlight xA ctermfg=red
highlight xB ctermfg=blue
" here xB is matched
syntax match xB /^a\+\zsb\+/
highlight xB ctermfg=blue
```
... | I cleaned out the installation and pulled the zip of vim-plug. Extracted the files into the autoload folder in vim82. Before I used the powershell solution.
After that I made a custom plugin folder and gave it read/write permission.
Now it seems to work. Unsure what the issue was but these are the things that I change... |
22,451 | <p>From the Vim's help:</p>
<pre><code>echo matchlist('acd', '\v(a)?(b)?(c)?(.*)')
Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
</code></pre>
<p>I understand why the 3rd element is an empty string: 'b' is not present in the string, but what's up with those 5 empty strings at the end?</p>
| [
{
"answer_id": 22453,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 3,
"selected": true,
"text": "<blockquote>\n <p>what's up with those 5 empty strings at the end?</p>\n</blockquote>\n\n<p><code>matchlist()</code> <stron... | 2020/01/07 | [
"https://vi.stackexchange.com/questions/22451",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11022/"
] | From the Vim's help:
```
echo matchlist('acd', '\v(a)?(b)?(c)?(.*)')
Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
```
I understand why the 3rd element is an empty string: 'b' is not present in the string, but what's up with those 5 empty strings at the end? | >
> what's up with those 5 empty strings at the end?
>
>
>
`matchlist()` **always** returns the list of 10 items (the matched string and nine submatches - just like `\0, \1, ..., \9` in [`:h sub-replace-special`](https://vimhelp.org/change.txt.html#sub-replace-special)). The last five weren't used, so they are set... |
22,455 | <p>I'm currently using Vim 8.1 on Ubuntu 18.04, and I would like to override the default behavior of <strong>deleting local files/directories 'forever'</strong> when using netrw.</p>
<p>The doc says that this plugin uses a function called <code>delete()</code> on latest versions of vim. My guess is that this function ... | [
{
"answer_id": 22458,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<p>Well, it's not supposed to be user-modifiable. But we can \"hack\" it:</p>\n\n<pre><code>\" helper function to find Scri... | 2020/01/07 | [
"https://vi.stackexchange.com/questions/22455",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25347/"
] | I'm currently using Vim 8.1 on Ubuntu 18.04, and I would like to override the default behavior of **deleting local files/directories 'forever'** when using netrw.
The doc says that this plugin uses a function called `delete()` on latest versions of vim. My guess is that this function simple uses `rm` to delete files, ... | Let us be not too insane :-) and provide a different solution using mappings and netrw public API.
Beware that the code is neither complete nor was tested properly!
```
" our custom delete routine
function! g:MyNetrw_DoDelete(flist)
echom 'Deleting ' a:flist
endfunction
" setup netrw mappings (:h g:Netrw_UserMap... |
22,461 | <p>As title howto source all files under a folder recursively except files that end with <code>.bak</code></p>
| [
{
"answer_id": 22462,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<p>You can only 'source' a file at a time. Therefore, build the list of files first, and then source them one by one.</p>\n... | 2020/01/08 | [
"https://vi.stackexchange.com/questions/22461",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14274/"
] | As title howto source all files under a folder recursively except files that end with `.bak` | Setting [wildignore](http://vimdoc.sourceforge.net/htmldoc/options.html#'wildignore') can have quite a few side effects (especially if done globally).
So I would do:
```
let s:prefix = '/path/to/folder'
let files = filter(glob(prefix . '/**/*.bak', 1, 1), "fnamemodify(v:val, ':e') != 'bak'")
for fname in files
... |
22,469 | <p>I am very new to vim, and I have a csv file with this format :</p>
<pre><code>"1006","text:xxx"
"2007","text:xxx"
"3008","text:xxx"
"4009","text:xxx"
"5001","text:xxx"
</code></pre>
<p>every "xxx" is replaced by an increment+1 of numbers at the start of each line.
athe result should be like this:</p>
<pre><code>... | [
{
"answer_id": 22478,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>You could use a substitution command like this one:</p>\n\n<pre><code>:%s/\"\\(\\d\\+\\).*:\\zs.\\+\\ze\"/\\=submatch(1)+... | 2020/01/09 | [
"https://vi.stackexchange.com/questions/22469",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26424/"
] | I am very new to vim, and I have a csv file with this format :
```
"1006","text:xxx"
"2007","text:xxx"
"3008","text:xxx"
"4009","text:xxx"
"5001","text:xxx"
```
every "xxx" is replaced by an increment+1 of numbers at the start of each line.
athe result should be like this:
```
"1006","text:1007"
"2007","text:2008"... | You could use a substitution command like this one:
```
:%s/"\(\d\+\).*:\zs.\+\ze"/\=submatch(1)+1
```
The command can be decomposed in these several parts:
* `%` is the range of lines you want to apply the command to. `%` is all the lines in the buffer, check [`:h :range`](http://vimhelp.appspot.com/cmdline.txt.ht... |
22,470 | <p>I have a file like this:</p>
<pre><code>1 2 3
4 5 6
7 8 9
0 1 2
</code></pre>
<p>I want to change a block-wise visual selection area, e.g. <code>5</code> and <code>8</code>. I want to substitute them by multiplying the figures by <code>0.7</code> and I want to round to 3 digits, e.g. <code>5</code> change... | [
{
"answer_id": 22471,
"author": "Hotschke",
"author_id": 1292,
"author_profile": "https://vi.stackexchange.com/users/1292",
"pm_score": 2,
"selected": false,
"text": "<h3>Visual Block: Colon commands will still apply to whole lines</h3>\n\n<p>You find in the user manual section 10.3 'Com... | 2020/01/09 | [
"https://vi.stackexchange.com/questions/22470",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26425/"
] | I have a file like this:
```
1 2 3
4 5 6
7 8 9
0 1 2
```
I want to change a block-wise visual selection area, e.g. `5` and `8`. I want to substitute them by multiplying the figures by `0.7` and I want to round to 3 digits, e.g. `5` changed to `3.500`.
I know `submatch` can work the math, but I don’t know ho... | You could try this:
```
:'<,'>s/\%V\d*\%V\d/\=printf('%.3f', str2nr(submatch(0))*0.7)/
```
For more info, see:
* `:h /\%V`
* `:h printf()`
---
>
> Figure could be 5, 5.0, 5.00 or 5.000, 12345678.000, 3 digits at most. How can we define a more general grouped part?
>
>
>
Try a more permissive pattern:
```
:'... |
22,484 | <h2>Background</h2>
<p>I have a code file and I like to place comments inside my code. Sometimes, these comments are boxed:</p>
<pre><code>defmodule BananasModule do
##############
# Public API #
##############
def function_blabla do .....
end
</code></pre>
<h2>Objective</h2>
<p>My objective is t... | [
{
"answer_id": 22488,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 4,
"selected": true,
"text": "<p>Well, \"put text into a box\" is a well-known Vim excercise. I'm not sure where I saw it for the first time, but the most... | 2020/01/10 | [
"https://vi.stackexchange.com/questions/22484",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26431/"
] | Background
----------
I have a code file and I like to place comments inside my code. Sometimes, these comments are boxed:
```
defmodule BananasModule do
##############
# Public API #
##############
def function_blabla do .....
end
```
Objective
---------
My objective is to have a key sequence (a... | Well, "put text into a box" is a well-known Vim excercise. I'm not sure where I saw it for the first time, but the most elegant solution, IMO, is to use `:h v_r`
So it becomes:
```
nnoremap <leader># I#<Space><Esc>A<Space>#<Esc>yy2P<C-V>$r#2j.
```
`I#<Space><Esc>` --- add "# " at the start of line
`A<Space>#<Esc>`... |
22,491 | <p>I'm trying to utilize <code>section</code> movement via <code>[[</code>, <code>]]</code> and friends, but I'm not seeing the behavior I'm expecting given my understanding of the documentation.</p>
<blockquote>
<p>A section begins after a form-feed () in the first column and at each of
a set of section macros, s... | [
{
"answer_id": 22494,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": true,
"text": "<p>You’re misunderstanding the motions. <code>[[</code> and <code>]]</code> both only move to a <code>{</code> character in the ... | 2020/01/10 | [
"https://vi.stackexchange.com/questions/22491",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14/"
] | I'm trying to utilize `section` movement via `[[`, `]]` and friends, but I'm not seeing the behavior I'm expecting given my understanding of the documentation.
>
> A section begins after a form-feed () in the first column and at each of
> a set of section macros, specified by the pairs of characters in the
> a set ... | You’re misunderstanding the motions. `[[` and `]]` both only move to a `{` character in the first column (backwards and forwards, respectively), which your file does not have. To jump to a `}` you need to use `[]` and `][`.
I used to find this hard to remember until someone on this site suggested that the way to remem... |
22,497 | <p>I've been doing this:</p>
<pre><code>au BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif
</code></pre>
<p>The problem is that it moves the cursor sometimes when I save the file.</p>
| [
{
"answer_id": 22498,
"author": "gdoubleod",
"author_id": 22630,
"author_profile": "https://vi.stackexchange.com/users/22630",
"pm_score": 4,
"selected": true,
"text": "<p>Try this: </p>\n\n<pre><code>autocmd BufWritePre * %s/\\s\\+$//e\n</code></pre>\n\n<p>if you want to do this for B... | 2020/01/11 | [
"https://vi.stackexchange.com/questions/22497",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26215/"
] | I've been doing this:
```
au BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif
```
The problem is that it moves the cursor sometimes when I save the file. | Try this:
```
autocmd BufWritePre * %s/\s\+$//e
```
if you want to do this for BufReadPre as well you can
<https://stackoverflow.com/questions/356126/how-can-you-automatically-remove-trailing-whitespace-in-vim> |
22,507 | <p>I'm trying to remove (non-consecutive) duplicate lines in a file I have loaded in vim (without sorting them). In several places on the web I've found the nugget <code>awk '!x[$0]++'</code> as a pipe command that will do this, and indeed if I run this from my shell directly, i.e. <code>cat myfile | awk '!x[$0]++'</co... | [
{
"answer_id": 22508,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>When I run <code>:%!awk '!x[$0]++'</code> in my vim, I get <code>E34: No previous command</code>.</p>\n\n<p>I f... | 2020/01/12 | [
"https://vi.stackexchange.com/questions/22507",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/91/"
] | I'm trying to remove (non-consecutive) duplicate lines in a file I have loaded in vim (without sorting them). In several places on the web I've found the nugget `awk '!x[$0]++'` as a pipe command that will do this, and indeed if I run this from my shell directly, i.e. `cat myfile | awk '!x[$0]++'`, it works as expected... | From [:h :range!](https://vimhelp.org/change.txt.html#%3Arange%21)
```
Filter {range} lines through the external program
{filter}. Vim replaces the optional bangs with the
latest given command and appends the optional [arg].
```
The second `!` is replaced with last shell cmd, I g... |
22,514 | <p>I have a markdown file like this:</p>
<pre><code>Irish Bands:
1. U2
2. The Cranberries
3. The Dubliners
English Bands:
1. Queen
2. Duran Duran
3. The Beatles
American Bands:
1. Nirvana
2. Blondie
3. The Doors
</code></pre>
<p>I would like to modify it to look something like this:</p>
<pre><code>Irish Bands:
1. U2... | [
{
"answer_id": 22515,
"author": "eyal karni",
"author_id": 18375,
"author_profile": "https://vi.stackexchange.com/users/18375",
"pm_score": 0,
"selected": false,
"text": "<p>As usual, not the vim-way but fast.<br>\nuse <code>vim-visual-multi</code> (<a href=\"https://github.com/mg979/vim... | 2020/01/12 | [
"https://vi.stackexchange.com/questions/22514",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15158/"
] | I have a markdown file like this:
```
Irish Bands:
1. U2
2. The Cranberries
3. The Dubliners
English Bands:
1. Queen
2. Duran Duran
3. The Beatles
American Bands:
1. Nirvana
2. Blondie
3. The Doors
```
I would like to modify it to look something like this:
```
Irish Bands:
1. U2
2. The Cranberries
3. The Dubliners
... | Another simple way to accomplish this is to use the [g CTRL-A](https://vimhelp.org/change.txt.html#v_g_CTRL-A) command in Visual mode, which increments all numbers by successively higher counts on each line that starts with a number. (See `:help v_g_CTRL-A`.)
In order to be able to use it, start by replacing all numbe... |
22,528 | <p>I'd like to map a button to toggle Vim's background between transparent (to see stuff on other apps) and dark.</p>
<hr>
<h1>My current settings</h1>
<p>I'm using onedark theme. There's currently no other background setting.</p>
<p>(Part of) my <code>.vimrc</code>:</p>
<pre><code>set encoding=utf-8
set nocompati... | [
{
"answer_id": 22876,
"author": "axel22",
"author_id": 19497,
"author_profile": "https://vi.stackexchange.com/users/19497",
"pm_score": 2,
"selected": false,
"text": "<p>The toggling in the terminal vim works fine for me if I do:</p>\n<pre><code>let t:is_transparent = 0 ... | 2020/01/13 | [
"https://vi.stackexchange.com/questions/22528",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25859/"
] | I'd like to map a button to toggle Vim's background between transparent (to see stuff on other apps) and dark.
---
My current settings
===================
I'm using onedark theme. There's currently no other background setting.
(Part of) my `.vimrc`:
```
set encoding=utf-8
set nocompatible
set rnu nu
set wildmode=l... | The toggling in the terminal vim works fine for me if I do:
```
let t:is_transparent = 0
function! Toggle_transparent_background()
if t:is_transparent == 0
hi Normal guibg=#111111 ctermbg=black
let t:is_transparent = 1
else
... |
22,533 | <p>I'm trying to create a buffer for a specific purpose, and for that, I need to add newlines to it to get it to be the same height as my current window. My first idea, using <code>call append("^", repeat("\r", winheight(win_getid())))</code> didn't work (all it did was append <code>^M</code> several times over to a si... | [
{
"answer_id": 22535,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 2,
"selected": false,
"text": "<p>First off, are you sure you need to add actual content to your buffer? If the goal is just to get it the same height as a si... | 2020/01/13 | [
"https://vi.stackexchange.com/questions/22533",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26214/"
] | I'm trying to create a buffer for a specific purpose, and for that, I need to add newlines to it to get it to be the same height as my current window. My first idea, using `call append("^", repeat("\r", winheight(win_getid())))` didn't work (all it did was append `^M` several times over to a single line), and I can't s... | `append()` (or `appendbufline()`) do not allow `\r` or `\n` to insert new lines. You should use List instead. For instance,
```
call appendbufline(l:bufnr, '$', repeat([''], winheight(winnr())))
``` |
22,538 | <p><strong>Consider the following scenario</strong></p>
<p>Content of the buffer:</p>
<pre><code>I saw the water in a thermal bath.
</code></pre>
<p>Commands issued:</p>
<p><code>:set incsearch</code></p>
<p><code>/th^R^W^R^W^R^W^R^W</code></p>
<p><strong>Result</strong></p>
<p><code>thewaterIII</code></p>
<p><... | [
{
"answer_id": 22539,
"author": "user938271",
"author_id": 17449,
"author_profile": "https://vi.stackexchange.com/users/17449",
"pm_score": 4,
"selected": true,
"text": "<blockquote>\n <p>why does it add water</p>\n</blockquote>\n\n<p><code>C-r C-w</code> inserts the word positioned und... | 2020/01/13 | [
"https://vi.stackexchange.com/questions/22538",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9602/"
] | **Consider the following scenario**
Content of the buffer:
```
I saw the water in a thermal bath.
```
Commands issued:
`:set incsearch`
`/th^R^W^R^W^R^W^R^W`
**Result**
`thewaterIII`
**Question**
What exactly is the algorithm of the incremental search autocomplete in this case? Why does it behave in such a st... | >
> why does it add water
>
>
>
`C-r C-w` inserts the word positioned under your cursor; however, if `'incsearch'` is set, and there is a match in the buffer for the current contents of the command-line, Vim doesn't use the cursor position anymore, but the end of the match. From `:h c^r^w`:
```
When 'incsearch' i... |