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 |
|---|---|---|---|---|---|---|
27,185 | <p><strong>Question:</strong> Is there something which is works same as <a href="http://vimdoc.sourceforge.net/htmldoc/insert.html#i_CTRL-G_u" rel="noreferrer">i_CTRL-G_u</a>, but for <strong>normal mode</strong>?</p>
<p>This would be useful in mappings (like <code>nnoremap</code>), because (I think, but fixme) in norm... | [
{
"answer_id": 27188,
"author": "Jake Grossman",
"author_id": 31207,
"author_profile": "https://vi.stackexchange.com/users/31207",
"pm_score": 3,
"selected": false,
"text": "<p>Doing <code>:let &ul=&ul</code> breaks the undo sequence. This is documented under <code>:h :undojoin</... | 2020/09/08 | [
"https://vi.stackexchange.com/questions/27185",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9602/"
] | **Question:** Is there something which is works same as [i\_CTRL-G\_u](http://vimdoc.sourceforge.net/htmldoc/insert.html#i_CTRL-G_u), but for **normal mode**?
This would be useful in mappings (like `nnoremap`), because (I think, but fixme) in normal mode, if you are just typing commands (vs. a sequence mapped to a sin... | Doing `:let &ul=&ul` breaks the undo sequence. This is documented under `:h :undojoin`:
>
> Setting the value of 'undolevels' also breaks undo. Even when the new value
> is equal to the old value.
>
>
>
Using the described method, you can do the following:
```
nnoremap <leader>d dd:let &ul=&ul<CR>dd
``` |
27,193 | <p>I find the <code>ci'</code> (and similar commands) very useful, since I can execute it at the start of the line, and it will automatically change the first occurrence of text between single quotes (<code>'...'</code>).</p>
<p>However, how can I change the N'h occurrence using this command?</p>
<p>I've tried <code>&l... | [
{
"answer_id": 27198,
"author": "Quasímodo",
"author_id": 30440,
"author_profile": "https://vi.stackexchange.com/users/30440",
"pm_score": 1,
"selected": false,
"text": "<p>I'm afraid it is not possible (but we can make a nice mapping, skip to the end for that). See <code>:h object-selec... | 2020/09/08 | [
"https://vi.stackexchange.com/questions/27193",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26505/"
] | I find the `ci'` (and similar commands) very useful, since I can execute it at the start of the line, and it will automatically change the first occurrence of text between single quotes (`'...'`).
However, how can I change the N'h occurrence using this command?
I've tried `<N>ci'` and other ways that came to my mind,... | Plug-in [wellle/targets.vim](https://github.com/wellle/targets.vim) implements this feature, through an `in'` text-object (`n` for "next".) You can use it with a count, so you can use `c3in'` or `3cin'` to change inside the third next single quoted string from the cursor.
See the README section for the [next and last ... |
27,197 | <p>I got this sed regex I found:</p>
<pre><code>sed '/start/!d;s//&\n/;s/.*\n//;:a;/end/bb;$!{n;ba};:b;s//\n&/;P;D'
</code></pre>
<p>which basically outputs the content that is between a starting point and an end point.</p>
<pre><code>##1##
this is a test
with multiple
line
##z##
</code></pre>
<p>and replacing ... | [
{
"answer_id": 27221,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": true,
"text": "<p>An extremely simple function which does the job far more idiomatically:</p>\n<pre><code>function! Between(start,... | 2020/09/08 | [
"https://vi.stackexchange.com/questions/27197",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30351/"
] | I got this sed regex I found:
```
sed '/start/!d;s//&\n/;s/.*\n//;:a;/end/bb;$!{n;ba};:b;s//\n&/;P;D'
```
which basically outputs the content that is between a starting point and an end point.
```
##1##
this is a test
with multiple
line
##z##
```
and replacing `start` with `##1##`, and `end` to `##z##` would give... | An extremely simple function which does the job far more idiomatically:
```
function! Between(start, end) abort
let [start_line, _] = searchpairpos(a:start, '', a:end, 'bWn')
let [end_line, _] = searchpairpos(a:start, '', a:end, 'Wn')
if start_line is# 0 || end_line is# 0
return
endif
call setline(start_... |
27,232 | <p>I was wondering how to check if an element is in a list. I have the following function defined in a file:</p>
<pre><code>let g:some_list = ["a", "b", "c", "d", "e", "f", "g", "h"]
function! Test(item)
if a:item in g:some_list
... | [
{
"answer_id": 27233,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 3,
"selected": false,
"text": "<p>I think that <code>index()</code> would be the most efficient way for a strict equality. There is <code>match()</cod... | 2020/09/10 | [
"https://vi.stackexchange.com/questions/27232",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16884/"
] | I was wondering how to check if an element is in a list. I have the following function defined in a file:
```
let g:some_list = ["a", "b", "c", "d", "e", "f", "g", "h"]
function! Test(item)
if a:item in g:some_list
echo "Yes"
else
echo "No"
endif
endfunction
```
After sourcing the file I... | I think that `index()` would be the most efficient way for a strict equality. There is `match()` when pattern matching is required IIRC.
As Christian said, `:h list-functions` is a perfect place to start. Still many list related functions are missing. Over the years I've defined the one I'm missing in my library plugi... |
27,253 | <p>When I do <code>:update</code>, I'd like to print a message if the buffer was not written (because it wasn't changed).</p>
<p>I get a message upon save, but would like a message if save didn't occur, also.</p>
| [
{
"answer_id": 27257,
"author": "Tom Hale",
"author_id": 5324,
"author_profile": "https://vi.stackexchange.com/users/5324",
"pm_score": 1,
"selected": false,
"text": "<p>With help from <a href=\"https://vi.stackexchange.com/a/25747/5324\">this answer</a>, I came up with:</p>\n<pre><code>... | 2020/09/12 | [
"https://vi.stackexchange.com/questions/27253",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5324/"
] | When I do `:update`, I'd like to print a message if the buffer was not written (because it wasn't changed).
I get a message upon save, but would like a message if save didn't occur, also. | Here is an improved version to support as many of `write/update` features as possible. Even if it'd be of a lesser use for this case, it's a good habit to be more precise while creating new commands.
Also try never define a mapping as a prefix of another one (`<leader>w` vs. `<leader>wq`), as this may lead to surprisi... |
27,290 | <p>I want to be able to control/sync the movement (scrolling) of the number column (usable with <code>:set number</code>) with another different window (which doesn't have <code>:set number</code> set).</p>
<p>Any ways to do this?</p>
| [
{
"answer_id": 27294,
"author": "Quasímodo",
"author_id": 30440,
"author_profile": "https://vi.stackexchange.com/users/30440",
"pm_score": 3,
"selected": true,
"text": "<p>Yes. Choose one:</p>\n<pre><code>:windo se scb\n:windo set scrollbind\n</code></pre>\n<p>This sets scrollbind for ev... | 2020/09/14 | [
"https://vi.stackexchange.com/questions/27290",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30351/"
] | I want to be able to control/sync the movement (scrolling) of the number column (usable with `:set number`) with another different window (which doesn't have `:set number` set).
Any ways to do this? | Yes. Choose one:
```
:windo se scb
:windo set scrollbind
```
This sets scrollbind for every window. `:help scrollbind`:
```
See also |scroll-binding|. When this option is set, the current
window scrolls as other scrollbind windows (windows that also have
this option set) scroll.
``` |
27,295 | <p>I am looking for a way to remove a pair of brackets in the insertion mode without plugins. It's like</p>
<pre><code>(|)
</code></pre>
<p>When I press the delete key only the first bracket get deleted</p>
<pre><code>|)
</code></pre>
<p>But I want to auto-remove the second one when I press the delete key if there is n... | [
{
"answer_id": 27298,
"author": "Jake Grossman",
"author_id": 31207,
"author_profile": "https://vi.stackexchange.com/users/31207",
"pm_score": 3,
"selected": true,
"text": "<p>With the cursor in or on the parentheses, you can use <kbd>Ctrl</kbd>+<kbd>o</kbd> combined with <kbd>d</kbd><kb... | 2020/09/15 | [
"https://vi.stackexchange.com/questions/27295",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I am looking for a way to remove a pair of brackets in the insertion mode without plugins. It's like
```
(|)
```
When I press the delete key only the first bracket get deleted
```
|)
```
But I want to auto-remove the second one when I press the delete key if there is no content in the pair of brackets. And I want... | With the cursor in or on the parentheses, you can use `Ctrl`+`o` combined with `d``a``b` to delete the parentheses and any text contained within.
`Ctrl`+`o` lets you execute one normal mode command, then return to insert mode. `d``a``b` deletes a block text object, including `(` and `)`. This also works with an empty ... |
27,297 | <p>I use <code>vim-commentary</code> to comment. Hit <code>g-c-c</code> to toggle comments. But this will comment out the already existing comments if they start with <code>//</code> and it will comment out already existing comments startin with <code>/*</code>.</p>
<p>Is there a way (with / or without a pluging) to co... | [
{
"answer_id": 27298,
"author": "Jake Grossman",
"author_id": 31207,
"author_profile": "https://vi.stackexchange.com/users/31207",
"pm_score": 3,
"selected": true,
"text": "<p>With the cursor in or on the parentheses, you can use <kbd>Ctrl</kbd>+<kbd>o</kbd> combined with <kbd>d</kbd><kb... | 2020/09/15 | [
"https://vi.stackexchange.com/questions/27297",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16800/"
] | I use `vim-commentary` to comment. Hit `g-c-c` to toggle comments. But this will comment out the already existing comments if they start with `//` and it will comment out already existing comments startin with `/*`.
Is there a way (with / or without a pluging) to comment out lines of code while ignoring the already ex... | With the cursor in or on the parentheses, you can use `Ctrl`+`o` combined with `d``a``b` to delete the parentheses and any text contained within.
`Ctrl`+`o` lets you execute one normal mode command, then return to insert mode. `d``a``b` deletes a block text object, including `(` and `)`. This also works with an empty ... |
27,304 | <p>I'm using Vim with tmux and I wanted to know if there was a signal or something to 'deactivate' the vim window (like when you switch between vim windows) but also when you switch between Vim and Tmux. I'm using vim-tmux-navigator and tried to modify it to have this effect.</p>
| [
{
"answer_id": 27298,
"author": "Jake Grossman",
"author_id": 31207,
"author_profile": "https://vi.stackexchange.com/users/31207",
"pm_score": 3,
"selected": true,
"text": "<p>With the cursor in or on the parentheses, you can use <kbd>Ctrl</kbd>+<kbd>o</kbd> combined with <kbd>d</kbd><kb... | 2020/09/15 | [
"https://vi.stackexchange.com/questions/27304",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31437/"
] | I'm using Vim with tmux and I wanted to know if there was a signal or something to 'deactivate' the vim window (like when you switch between vim windows) but also when you switch between Vim and Tmux. I'm using vim-tmux-navigator and tried to modify it to have this effect. | With the cursor in or on the parentheses, you can use `Ctrl`+`o` combined with `d``a``b` to delete the parentheses and any text contained within.
`Ctrl`+`o` lets you execute one normal mode command, then return to insert mode. `d``a``b` deletes a block text object, including `(` and `)`. This also works with an empty ... |
27,306 | <p>I am trying to do something like this, from a function:</p>
<pre><code>nmap <F5> :!python %
</code></pre>
<p>Pressing F5 in this case causes the command <code>:!python %</code> to be left in the command line. This is preferred for me, because occasionally I may want to add extra command arguments or stuff to t... | [
{
"answer_id": 27298,
"author": "Jake Grossman",
"author_id": 31207,
"author_profile": "https://vi.stackexchange.com/users/31207",
"pm_score": 3,
"selected": true,
"text": "<p>With the cursor in or on the parentheses, you can use <kbd>Ctrl</kbd>+<kbd>o</kbd> combined with <kbd>d</kbd><kb... | 2020/09/15 | [
"https://vi.stackexchange.com/questions/27306",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31438/"
] | I am trying to do something like this, from a function:
```
nmap <F5> :!python %
```
Pressing F5 in this case causes the command `:!python %` to be left in the command line. This is preferred for me, because occasionally I may want to add extra command arguments or stuff to the end of the command.
However, I'm not ... | With the cursor in or on the parentheses, you can use `Ctrl`+`o` combined with `d``a``b` to delete the parentheses and any text contained within.
`Ctrl`+`o` lets you execute one normal mode command, then return to insert mode. `d``a``b` deletes a block text object, including `(` and `)`. This also works with an empty ... |
27,310 | <p>The default is this:</p>
<pre><code>switch(x)
{
case a:
{
y();
}
}
</code></pre>
<p>But I need this:</p>
<pre><code>switch(x)
{
case a:
{
y();
}
}
</code></pre>
<hr />
<p>With <code>:set cindent</code> and <code>:set cino={-s</code> this is the result (indentation... | [
{
"answer_id": 27312,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": true,
"text": "<p>You can align statements following the <code>case</code> label with the <a href=\"https://vimhelp.org/indent.txt.html#cino-%3... | 2020/09/15 | [
"https://vi.stackexchange.com/questions/27310",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | The default is this:
```
switch(x)
{
case a:
{
y();
}
}
```
But I need this:
```
switch(x)
{
case a:
{
y();
}
}
```
---
With `:set cindent` and `:set cino={-s` this is the result (indentation of switch's scope is wrong this time):
```
int main()
{
switch(X... | You can align statements following the `case` label with the [`=N`](https://vimhelp.org/indent.txt.html#cino-%3D) member of [`'cinoptions'`](https://vimhelp.org/options.txt.html#%27cinoptions%27). The following will fix your specific example:
```
:set cinoptions+==0
```
Unfortunately, it breaks indentation if you *d... |
27,323 | <p>I'm trying to sync the cursors movement of a popup window, and the current window.</p>
<pre><code>call range(50)
\ ->map({_, i -> string(i)})
\ ->popup_create(#{
\ line: 1,
\ col: 1,
\ minwidth: 1,
\ minheight: 1,
\ maxheight: &lines - 1,
\ cursorl... | [
{
"answer_id": 27316,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>Vim will load filetype-specific commands from an <code>ftplugin</code>. See <a href=\"https://vimhelp.org/usr_41.tx... | 2020/09/15 | [
"https://vi.stackexchange.com/questions/27323",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30351/"
] | I'm trying to sync the cursors movement of a popup window, and the current window.
```
call range(50)
\ ->map({_, i -> string(i)})
\ ->popup_create(#{
\ line: 1,
\ col: 1,
\ minwidth: 1,
\ minheight: 1,
\ maxheight: &lines - 1,
\ cursorline: 1,
\ wrap: 0,... | Vim will load filetype-specific commands from an `ftplugin`. See [`:help ftplugin`](https://vimhelp.org/usr_41.txt.html#ftplugin).
In short, you can create a file under `~/.vim/ftplugin` (or `%HOME%\vimfiles\ftplugin` on Windows), or better `~/.vim/after/ftplugin` (or `%HOME%\vimfiles\after\ftplugin`) named after the ... |
27,354 | <p>I find myself often in the situation in which I want to run multiple <code>vim</code> commands on a multiple files.</p>
<p>Consider file1.txt, file2.txt, file3.txt I would need to run <code>:retab</code> and then some <code>:%s/ /, /</code> for instance.</p>
<p>How can I <code>pipe</code> this through <code>vim</cod... | [
{
"answer_id": 27355,
"author": "Quasímodo",
"author_id": 30440,
"author_profile": "https://vi.stackexchange.com/users/30440",
"pm_score": 3,
"selected": false,
"text": "<p>First, you are running Vim, not Vi, because the latter does not offer the <code>retab</code> command.</p>\n<p>Assum... | 2020/09/17 | [
"https://vi.stackexchange.com/questions/27354",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31433/"
] | I find myself often in the situation in which I want to run multiple `vim` commands on a multiple files.
Consider file1.txt, file2.txt, file3.txt I would need to run `:retab` and then some `:%s/ /, /` for instance.
How can I `pipe` this through `vim`? | First, you are running Vim, not Vi, because the latter does not offer the `retab` command.
Assuming the file should be modified (that is what `x` does below), you can pipe the commands to Ex improved mode this way:
```
printf '%s\n' 'retab' '%s/ /, /' 'x' | vim -E file1.txt
```
Now, bear in mind that Ex will skip y... |
27,383 | <p>How do you substitute every word of a line, so that it becomes a useful <strong>vimwiki</strong> tag?</p>
<p>Provided the following line:</p>
<pre><code>Word Compund_Word
</code></pre>
<p>I want:</p>
<pre><code>:Word: :Compund_Word:
</code></pre>
<p>I guess it involves some use of <strong>regex</strong>, but I haven... | [
{
"answer_id": 27386,
"author": "Jake Grossman",
"author_id": 31207,
"author_profile": "https://vi.stackexchange.com/users/31207",
"pm_score": 3,
"selected": true,
"text": "<p>While on the line in question:</p>\n<pre><code>:s/\\w\\+/:&:/g\n</code></pre>\n<p><strong>Breakdown</strong>... | 2020/09/19 | [
"https://vi.stackexchange.com/questions/27383",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30823/"
] | How do you substitute every word of a line, so that it becomes a useful **vimwiki** tag?
Provided the following line:
```
Word Compund_Word
```
I want:
```
:Word: :Compund_Word:
```
I guess it involves some use of **regex**, but I haven't been able to figure out which string. | While on the line in question:
```
:s/\w\+/:&:/g
```
**Breakdown**
* `\w\+` will match 1 or more word characters (`[0-9A-Za-z_]`).
* `&` has a special meaning in a replacement, depending on the value of `'magic'` (default: on). It is replaced with the
matched pattern.
* the `g` flag will perform this substitution f... |
27,427 | <p>I want to write to a file in the home directory, so I tried the following command:</p>
<pre><code>:call writefile(["foo"], "~/event.log", "a")
</code></pre>
<p>But I got an error:</p>
<pre><code>E482: Can't create file ~/event.log
</code></pre>
<p>I am pretty sure that I have write perm... | [
{
"answer_id": 27428,
"author": "Jürgen Krämer",
"author_id": 2636,
"author_profile": "https://vi.stackexchange.com/users/2636",
"pm_score": 5,
"selected": true,
"text": "<p>The tilde is only treated specially if it's used in commands like <code>:w ~/event.log</code>. When used in a stri... | 2020/09/23 | [
"https://vi.stackexchange.com/questions/27427",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31449/"
] | I want to write to a file in the home directory, so I tried the following command:
```
:call writefile(["foo"], "~/event.log", "a")
```
But I got an error:
```
E482: Can't create file ~/event.log
```
I am pretty sure that I have write permission for my home directory (of course), and there is not a file with the ... | The tilde is only treated specially if it's used in commands like `:w ~/event.log`. When used in a string that is passed to a function -- even if this function treats the string argument as a file name -- it has no special meaning. You have to take care of the expansion of the tilde to the home directory yourself.
Vim... |
27,432 | <p>If you have the following text:</p>
<pre><code>line 1
line 2
line 3
</code></pre>
<p>You can hit <kbd>CTRL</kbd>+<kbd>v</kbd> on line 1 and hit <kbd>j</kbd> to select line 2. However, I want to select both line 1 and line 3, but not line 2.</p>
<p>Or, select multiple arears like this:
<a href="https://i.stack.imgur.... | [
{
"answer_id": 27437,
"author": "Jake Grossman",
"author_id": 31207,
"author_profile": "https://vi.stackexchange.com/users/31207",
"pm_score": 2,
"selected": false,
"text": "<p>From <code>:h visual-use</code> (emphasis mine):</p>\n<blockquote>\n<p>Using Visual mode consists of three part... | 2020/09/23 | [
"https://vi.stackexchange.com/questions/27432",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20359/"
] | If you have the following text:
```
line 1
line 2
line 3
```
You can hit `CTRL`+`v` on line 1 and hit `j` to select line 2. However, I want to select both line 1 and line 3, but not line 2.
Or, select multiple arears like this:
[](https://i.stack.i... | From `:h visual-use` (emphasis mine):
>
> Using Visual mode consists of three parts:
>
>
> 1. Mark the start of the text with "v", "V" or CTRL-V.
> The character under the cursor will be used as the start.
> 2. Move to the end of the text.
> The text from the start of the Visual mode **up to and including the
> cha... |
27,449 | <p>I want to turn</p>
<pre><code>one two three four
</code></pre>
<p>into</p>
<pre><code>'one' 'two' 'three' 'four'
</code></pre>
<p>(I have surround.vim)</p>
<p>I can do: <code>ysiW'</code>, then do <code>W.</code> repeatedly until I've surrounded all words in the line</p>
<p>But I would like to repeat the movement (<... | [
{
"answer_id": 27455,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>With a macro:</p>\n<pre><code>0qqysiW'W\n</code></pre>\n<p>and then <code>3@q</code>.</p>\n<hr />\n<p>The issue... | 2020/09/24 | [
"https://vi.stackexchange.com/questions/27449",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9024/"
] | I want to turn
```
one two three four
```
into
```
'one' 'two' 'three' 'four'
```
(I have surround.vim)
I can do: `ysiW'`, then do `W.` repeatedly until I've surrounded all words in the line
But I would like to repeat the movement (`W`) and repetition (`.`) multiple times without needing to manually type that (... | With a macro:
```
0qqysiW'W
```
and then `3@q`.
---
The issue is that `:normal` with a range is line-wise; that is, it repeats the normal command on each line in the range.
You *could* do
```
normal ysiW'<C-r>=repeat('W.', 3)<CR>
```
But at that point you're doing more work than the original, I think.
---
Qu... |
27,458 | <p>Consider the following test String:</p>
<pre><code>County,Age,Age_group,Gender,Jurisdiction,Travel_related,Origin,EDvisit,Hospitalized,Died,Case_,Contact,Case1,EventDate,ChartDate,ObjectId
</code></pre>
<p>If use the following regex to search:</p>
<pre><code>\v((.{-},){9})\zsDied
</code></pre>
<p>I get the expected ... | [
{
"answer_id": 27460,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 3,
"selected": true,
"text": "<p>Removing the <code>\\zs</code> and looking the highlighting makes it pretty clear what is happening; <code>/\\v((.{-},){9... | 2020/09/25 | [
"https://vi.stackexchange.com/questions/27458",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31565/"
] | Consider the following test String:
```
County,Age,Age_group,Gender,Jurisdiction,Travel_related,Origin,EDvisit,Hospitalized,Died,Case_,Contact,Case1,EventDate,ChartDate,ObjectId
```
If use the following regex to search:
```
\v((.{-},){9})\zsDied
```
I get the expected result of having the word Died in the test St... | Removing the `\zs` and looking the highlighting makes it pretty clear what is happening; `/\v((.{-},){9})Event`. This regex spells "(match anything non-greedily, followed by a comma) 9 times, followed by Event."
There are two problems here:
1. Although it is not greedy, `.{-}` may also match comma, whenever necessary... |
27,478 | <p>I quickly want to switch between directories I previously visited without typing <code>:cd</code> and then the full pathname again and again. Is there a plugin or a way that can keep an account of the directories I visited during a vim session from which I can select and go to that directory instantly? I use neovim-... | [
{
"answer_id": 27487,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": true,
"text": "<p>I've made a start at dirstack-like set of commands; you could place the following in (e.g.) <code>~/.vim/plugin/... | 2020/09/27 | [
"https://vi.stackexchange.com/questions/27478",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31589/"
] | I quickly want to switch between directories I previously visited without typing `:cd` and then the full pathname again and again. Is there a plugin or a way that can keep an account of the directories I visited during a vim session from which I can select and go to that directory instantly? I use neovim-qt on Windows ... | I've made a start at dirstack-like set of commands; you could place the following in (e.g.) `~/.vim/plugin/dirstack.vim`:
```
let g:dir_stack = []
command -complete=dir -nargs=1 -bang -bar Pushd
\ call add(g:dir_stack, getcwd()) | execute 'cd<bang>' <q-args>
command -bang -bar Popd
\ let dir = remove(g:dir... |
27,493 | <p>My workflow is as following: I have a common project root where folders for projects branch of. In these branches I have markdown files with notes, snippets, various information. I mark todos for example with <code>TODO:</code>in these markdown files.</p>
<p>If I want to find all my todos I <code>:cd</code> into the... | [
{
"answer_id": 27495,
"author": "Jake Grossman",
"author_id": 31207,
"author_profile": "https://vi.stackexchange.com/users/31207",
"pm_score": 2,
"selected": false,
"text": "<p>You can use the pattern <code>\\%^</code> to match the start of of the file. Using this, you could populate the... | 2020/09/28 | [
"https://vi.stackexchange.com/questions/27493",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11633/"
] | My workflow is as following: I have a common project root where folders for projects branch of. In these branches I have markdown files with notes, snippets, various information. I mark todos for example with `TODO:`in these markdown files.
If I want to find all my todos I `:cd` into the project root and perform `:vim... | You can use the pattern `\%^` to match the start of of the file. Using this, you could populate the quickfix list with the first line of all your markdown files, even empty ones.
```
:vimgrep "\%^" **/*.md
``` |
27,504 | <p>I'm trying to match a new line character on a Vim syntax file, I can make it work when I use the patern within Vim but when I put it in my syntax file it doesn't highlight when I have a new line and when it should.</p>
<p>The regex part that I use for new line match is: <code>\_s</code> (also tried with <code>\n</co... | [
{
"answer_id": 27495,
"author": "Jake Grossman",
"author_id": 31207,
"author_profile": "https://vi.stackexchange.com/users/31207",
"pm_score": 2,
"selected": false,
"text": "<p>You can use the pattern <code>\\%^</code> to match the start of of the file. Using this, you could populate the... | 2020/09/29 | [
"https://vi.stackexchange.com/questions/27504",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31437/"
] | I'm trying to match a new line character on a Vim syntax file, I can make it work when I use the patern within Vim but when I put it in my syntax file it doesn't highlight when I have a new line and when it should.
The regex part that I use for new line match is: `\_s` (also tried with `\n` with: `\(\n\|\s\)`)
The pa... | You can use the pattern `\%^` to match the start of of the file. Using this, you could populate the quickfix list with the first line of all your markdown files, even empty ones.
```
:vimgrep "\%^" **/*.md
``` |
27,547 | <p>How can I adopt side panel plugins (TagBar, TagList, NerdTree, etc) width to current screen aspect ratio?</p>
<p>Using Vim with many different computers makes me a bit trouble to write one portable config for all of them. The problem is aspect ratio of screen. It varies from 4:3 - 1024x768 to 16:9 - 1920x1080. What ... | [
{
"answer_id": 27615,
"author": "Dmitry",
"author_id": 17271,
"author_profile": "https://vi.stackexchange.com/users/17271",
"pm_score": 1,
"selected": false,
"text": "<p>Wrote function that satisfied my needs. It checks total screen width and sets width, position and show-on-start of pan... | 2020/10/04 | [
"https://vi.stackexchange.com/questions/27547",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/17271/"
] | How can I adopt side panel plugins (TagBar, TagList, NerdTree, etc) width to current screen aspect ratio?
Using Vim with many different computers makes me a bit trouble to write one portable config for all of them. The problem is aspect ratio of screen. It varies from 4:3 - 1024x768 to 16:9 - 1920x1080. What I want is... | Wrote function that satisfied my needs. It checks total screen width and sets width, position and show-on-start of panels depending on result.
```
" Adjust side panels to screen resolution and ratio.
func AdaptToScreenRatio()
let screen_width = &columns " full screen size
let main_window_width = 82 + &foldcolumn "... |
27,559 | <p>I am trying to write a command that passes selected text to a shell script.</p>
<p>The command works fine when there is no <code>\n</code> character in the selected text (using Visual mode).</p>
<pre><code>:vmap <Leader>tts 0y:silent exec ":!/home/user/tts.sh ".@0 <Enter>
</code></pre>
<p>The p... | [
{
"answer_id": 27560,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 2,
"selected": true,
"text": "<p><em>Since I posted this the title of the question was changed to explicitly reference arguments. Just in case someone ... | 2020/10/05 | [
"https://vi.stackexchange.com/questions/27559",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31683/"
] | I am trying to write a command that passes selected text to a shell script.
The command works fine when there is no `\n` character in the selected text (using Visual mode).
```
:vmap <Leader>tts 0y:silent exec ":!/home/user/tts.sh ".@0 <Enter>
```
The problems occurs when I try to select multiple lines.
I tried to ... | *Since I posted this the title of the question was changed to explicitly reference arguments. Just in case someone gets the idea that I have reading comprehension issues...* ;)
To send multiple lines of Visually selected text to a shell command I'd do it this way:
```
:vnoremap XXX :w !<shell command> <CR>
```
If y... |
27,567 | <p>With other words: How to copy selection without its root-level indentation?</p>
<p><em><strong>Example:</strong></em></p>
<p>How to copy this:</p>
<pre><code>a
b
c
d
</code></pre>
<p>instead of:</p>
<pre><code> a
b
c
d
</code></pre>
<p>I am using Neovim inside VS Code but I think this ... | [
{
"answer_id": 27568,
"author": "silviubogan",
"author_id": 5010,
"author_profile": "https://vi.stackexchange.com/users/5010",
"pm_score": -1,
"selected": false,
"text": "<p>This works only in VS Code:</p>\n<ol>\n<li>Put the cursor on the first character of the contents that you want to ... | 2020/10/06 | [
"https://vi.stackexchange.com/questions/27567",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5010/"
] | With other words: How to copy selection without its root-level indentation?
***Example:***
How to copy this:
```
a
b
c
d
```
instead of:
```
a
b
c
d
```
I am using Neovim inside VS Code but I think this is not relevant since it loads the bindings from the Neovim configuration fil... | Here's a pure Vim solution:
1. Put the cursor on the first line on the leftmost column you want to yank
2. Hit `Ctrl`+`V`
3. Move the cursor down to the last line
4. Hit `$`
Yank away. |
27,581 | <p>How can I list / show all built-in functions, similar to the <code>:function</code> command which lists all (non-builtin?) functions?</p>
| [
{
"answer_id": 27582,
"author": "Rob Bednark",
"author_id": 14340,
"author_profile": "https://vi.stackexchange.com/users/14340",
"pm_score": 2,
"selected": false,
"text": "<p>I found a list in <code>:help functions</code> (plural) which is sufficient if there is no command. But it would... | 2020/10/07 | [
"https://vi.stackexchange.com/questions/27581",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14340/"
] | How can I list / show all built-in functions, similar to the `:function` command which lists all (non-builtin?) functions? | Try this:
```
new | put! =getcompletion('*', 'function')->filter({_, v -> v =~# '^[a-z][^#]*$'})
```
Broken down:
* `new` - Create a new window and start editing an empty file in it
* `put!` - Put the text from a register before the current line
* `=` - The expression register
* `getcompletion('*', 'function')` - R... |
27,586 | <p>original below. I want to copy each line and paste multiple n times under their own lines separately.</p>
<pre><code>USD
XYZ
ABC
YUT
LMO
.
.
. upto so on
</code></pre>
<p>want them to become like this. Any way how can I achieve following in Vim?</p>
<pre><code>USD
USD
USD
USD
USD
XYZ
XYZ
XYZ
XYZ
XYZ
ABC
ABC
ABC
ABC
... | [
{
"answer_id": 27589,
"author": "Aivar Paalberg",
"author_id": 30052,
"author_profile": "https://vi.stackexchange.com/users/30052",
"pm_score": 2,
"selected": false,
"text": "<p>Following is not very scalable but simple enough for smaller lists: "start recording macro: yank word, in... | 2020/10/07 | [
"https://vi.stackexchange.com/questions/27586",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31711/"
] | original below. I want to copy each line and paste multiple n times under their own lines separately.
```
USD
XYZ
ABC
YUT
LMO
.
.
. upto so on
```
want them to become like this. Any way how can I achieve following in Vim?
```
USD
USD
USD
USD
USD
XYZ
XYZ
XYZ
XYZ
XYZ
ABC
ABC
ABC
ABC
ABC
YUT
YUT
YUT
YUT
YUT
LMO
LMO
LM... | Following is not very scalable but simple enough for smaller lists: "start recording macro: yank word, insert it in new line below and repeat last ex command n times, stop macro recording. Repeat macro on every word"
* qq (start recording macro, first q for starting recording, second q is name of the register)
* yiw (... |
27,598 | <p>When I run <code>:marks</code> it lists all the marks including the standard Vim marks. This is somehow distracting.</p>
<p>Is there a way to list only my marks that I created using <code>m-X</code> for example?</p>
| [
{
"answer_id": 27600,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 3,
"selected": true,
"text": "<p>You can define a custom command like this, that will only show the lowercase marks <code>a</code>-<code>z</code>:... | 2020/10/08 | [
"https://vi.stackexchange.com/questions/27598",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16800/"
] | When I run `:marks` it lists all the marks including the standard Vim marks. This is somehow distracting.
Is there a way to list only my marks that I created using `m-X` for example? | You can define a custom command like this, that will only show the lowercase marks `a`-`z`:
```
:com :MyMarks :sil! marks abcdefghijklmnopqrstuvwxyz
``` |
27,611 | <p>Version: vim 8.1</p>
<p>Problem: Latex objects like <code>\int, ^, \alpha, \beta,</code> etc, all get replaced by <code>_</code> in tmux when using conceallevel=1,2.</p>
<p>Expected: correct concealment, as it happens in normal terminal, outside tmux. For example <code>\int</code> gets replaced by integral sign.</p>... | [
{
"answer_id": 27600,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 3,
"selected": true,
"text": "<p>You can define a custom command like this, that will only show the lowercase marks <code>a</code>-<code>z</code>:... | 2020/10/09 | [
"https://vi.stackexchange.com/questions/27611",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27417/"
] | Version: vim 8.1
Problem: Latex objects like `\int, ^, \alpha, \beta,` etc, all get replaced by `_` in tmux when using conceallevel=1,2.
Expected: correct concealment, as it happens in normal terminal, outside tmux. For example `\int` gets replaced by integral sign.
Terminal: Termite
Shell: zsh; new to it
Tried: I... | You can define a custom command like this, that will only show the lowercase marks `a`-`z`:
```
:com :MyMarks :sil! marks abcdefghijklmnopqrstuvwxyz
``` |
27,621 | <p>Is there a way, built-in or with a plugin, that I can swap any number of two different patterns on an arbitrary range using a regex?</p>
<p>Maybe something <code>:s</code>-style like <code>:{range}exchange/{pattern-1}/{pattern-2}/{flags}</code>?</p>
<p>Example:</p>
<pre><code>foo bar
bar foo bar
</code></pre>
<p>hyp... | [
{
"answer_id": 27624,
"author": "Spidey",
"author_id": 10482,
"author_profile": "https://vi.stackexchange.com/users/10482",
"pm_score": 0,
"selected": false,
"text": "<p>Use capture groups.</p>\n<pre><code>:s/\\v(pattern1)(.*)(pattern2)/\\3\\2\\1/\n</code></pre>\n<p>You need to capture t... | 2020/10/11 | [
"https://vi.stackexchange.com/questions/27621",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31252/"
] | Is there a way, built-in or with a plugin, that I can swap any number of two different patterns on an arbitrary range using a regex?
Maybe something `:s`-style like `:{range}exchange/{pattern-1}/{pattern-2}/{flags}`?
Example:
```
foo bar
bar foo bar
```
hypothetical command swaps `foo` and `bar`
```
bar foo
foo b... | This is a duplicate of an old question I cannot found anymore but for which I've a trace (through a solution): <https://github.com/LucHermitte/lh-misc/blob/master/plugin/rotate_substitute.vim>
```
:command! -bang -nargs=1 -range CycleSubstitute <line1>,<line2>call s:CycleSubstitute("<bang>", <f-args>)
" no back ref s... |
27,639 | <p>I know there are questions/answers to execute commands with a single shortcut, but in my case I can't think how to do multiple maps with a single shortcut in Insert Mode. In other words, what I want:</p>
<ul>
<li>Suppose I'm in Insert Mode now</li>
<li>Press, for example, <code><C-s></code> to do multiple maps... | [
{
"answer_id": 27624,
"author": "Spidey",
"author_id": 10482,
"author_profile": "https://vi.stackexchange.com/users/10482",
"pm_score": 0,
"selected": false,
"text": "<p>Use capture groups.</p>\n<pre><code>:s/\\v(pattern1)(.*)(pattern2)/\\3\\2\\1/\n</code></pre>\n<p>You need to capture t... | 2020/10/12 | [
"https://vi.stackexchange.com/questions/27639",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27494/"
] | I know there are questions/answers to execute commands with a single shortcut, but in my case I can't think how to do multiple maps with a single shortcut in Insert Mode. In other words, what I want:
* Suppose I'm in Insert Mode now
* Press, for example, `<C-s>` to do multiple maps, like
+ `a;o ---> año`
+ `e;e --->... | This is a duplicate of an old question I cannot found anymore but for which I've a trace (through a solution): <https://github.com/LucHermitte/lh-misc/blob/master/plugin/rotate_substitute.vim>
```
:command! -bang -nargs=1 -range CycleSubstitute <line1>,<line2>call s:CycleSubstitute("<bang>", <f-args>)
" no back ref s... |
27,644 | <p>I know that there is a function <code>col({expr})</code>, which returns the column position given with <code>{expr}</code>.</p>
<p>For example, <code>col("$")</code> gives me the column position of the end of the cursor line.</p>
<p>So I thought <code>col("^")</code> can give me the column positi... | [
{
"answer_id": 27624,
"author": "Spidey",
"author_id": 10482,
"author_profile": "https://vi.stackexchange.com/users/10482",
"pm_score": 0,
"selected": false,
"text": "<p>Use capture groups.</p>\n<pre><code>:s/\\v(pattern1)(.*)(pattern2)/\\3\\2\\1/\n</code></pre>\n<p>You need to capture t... | 2020/10/13 | [
"https://vi.stackexchange.com/questions/27644",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10003/"
] | I know that there is a function `col({expr})`, which returns the column position given with `{expr}`.
For example, `col("$")` gives me the column position of the end of the cursor line.
So I thought `col("^")` can give me the column position of the first non-whitespace character of the cursor line. But `col("^")` alw... | This is a duplicate of an old question I cannot found anymore but for which I've a trace (through a solution): <https://github.com/LucHermitte/lh-misc/blob/master/plugin/rotate_substitute.vim>
```
:command! -bang -nargs=1 -range CycleSubstitute <line1>,<line2>call s:CycleSubstitute("<bang>", <f-args>)
" no back ref s... |
27,674 | <p>I am trying to create some keybind "scripts" for specified file types in my .vimrc.
Example :</p>
<pre><code> au BufNewFile,BufRead *.cpp
\ nnoremap <C-P> :!g++ % -o %.exe <CR>
</code></pre>
<p>Ideally I would like to name output file type just the name of the file without any extension.
Exa... | [
{
"answer_id": 27679,
"author": "Ricardo Kullock",
"author_id": 29521,
"author_profile": "https://vi.stackexchange.com/users/29521",
"pm_score": 1,
"selected": false,
"text": "<p>You can check this: <a href=\"https://vim.fandom.com/wiki/Get_the_name_of_the_current_file\" rel=\"nofollow n... | 2020/10/15 | [
"https://vi.stackexchange.com/questions/27674",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21555/"
] | I am trying to create some keybind "scripts" for specified file types in my .vimrc.
Example :
```
au BufNewFile,BufRead *.cpp
\ nnoremap <C-P> :!g++ % -o %.exe <CR>
```
Ideally I would like to name output file type just the name of the file without any extension.
Example :
filename : test.cpp
output of compila... | You can use:
```
au BufNewFile,BufRead *.cpp nnoremap <buffer> <C-P> :!g++ % -o %< <CR>
```
The `%<` will remove the extension from the current file. I use this for example to open the pdf version of the currently edited latex document using `:!xpdf %<.pdf`
See also the help section [`:h filename-modifiers`](https:... |
27,675 | <p>Im trying to make a setup where I can</p>
<ol>
<li>open a vertical split, preferably in the <code>/tmp/</code> directory in readonly mode(so you cannot write changes)</li>
<li>read the shell output from a linter/compiler (in my case, the program <code>shellcheck</code>)</li>
<li>if required perform a substitution on... | [
{
"answer_id": 27678,
"author": "Ricardo Kullock",
"author_id": 29521,
"author_profile": "https://vi.stackexchange.com/users/29521",
"pm_score": 1,
"selected": false,
"text": "<p>Sounds like you want to use the quickfix window. I only had moderate success with it in python, but it was al... | 2020/10/15 | [
"https://vi.stackexchange.com/questions/27675",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31699/"
] | Im trying to make a setup where I can
1. open a vertical split, preferably in the `/tmp/` directory in readonly mode(so you cannot write changes)
2. read the shell output from a linter/compiler (in my case, the program `shellcheck`)
3. if required perform a substitution on all the file/line number information to bring... | Writing a compiler plugin allows you to supplement the `:make` command to run any tool you want, and parse the output into the quickfix window. In your case, I would so something like the following:
```
" ~/.vim/compiler/shellcheck.vim
if exists('current_compiler')
finish
endif
let current_compiler = 'shellcheck'
i... |
27,689 | <p>I use <code>:saveas</code> to move a file while maintaining its undo history. Most of the time I immediately delete the old file. So if I'm editing <code>foo.txt</code> I'll issue</p>
<pre><code>:saveas bar.txt
:!rm foo.txt
</code></pre>
<p>I wanted to make this into a single command, so I'm trying</p>
<pre><code>c... | [
{
"answer_id": 27678,
"author": "Ricardo Kullock",
"author_id": 29521,
"author_profile": "https://vi.stackexchange.com/users/29521",
"pm_score": 1,
"selected": false,
"text": "<p>Sounds like you want to use the quickfix window. I only had moderate success with it in python, but it was al... | 2020/10/16 | [
"https://vi.stackexchange.com/questions/27689",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19574/"
] | I use `:saveas` to move a file while maintaining its undo history. Most of the time I immediately delete the old file. So if I'm editing `foo.txt` I'll issue
```
:saveas bar.txt
:!rm foo.txt
```
I wanted to make this into a single command, so I'm trying
```
command! -nargs=* Move :call delete(expand('%')) | saveas ... | Writing a compiler plugin allows you to supplement the `:make` command to run any tool you want, and parse the output into the quickfix window. In your case, I would so something like the following:
```
" ~/.vim/compiler/shellcheck.vim
if exists('current_compiler')
finish
endif
let current_compiler = 'shellcheck'
i... |
27,696 | <p>I am using Manjaro/Arch Linux and I use vim from <code>sudo pacman -S vim</code> instead of build it from source</p>
<p>I want to run my <code>.py</code> files in vim by F5 but when I added these to <code>~/.vimrc</code>:</p>
<pre><code>map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
... | [
{
"answer_id": 27678,
"author": "Ricardo Kullock",
"author_id": 29521,
"author_profile": "https://vi.stackexchange.com/users/29521",
"pm_score": 1,
"selected": false,
"text": "<p>Sounds like you want to use the quickfix window. I only had moderate success with it in python, but it was al... | 2020/10/17 | [
"https://vi.stackexchange.com/questions/27696",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31853/"
] | I am using Manjaro/Arch Linux and I use vim from `sudo pacman -S vim` instead of build it from source
I want to run my `.py` files in vim by F5 but when I added these to `~/.vimrc`:
```
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
... | Writing a compiler plugin allows you to supplement the `:make` command to run any tool you want, and parse the output into the quickfix window. In your case, I would so something like the following:
```
" ~/.vim/compiler/shellcheck.vim
if exists('current_compiler')
finish
endif
let current_compiler = 'shellcheck'
i... |
27,699 | <p>Each row is:</p>
<pre><code>Or(a=a[0], b=b[0], out=out[0]);
Or(a=a[0], b=b[0], out=out[0]);
Or(a=a[0], b=b[0], out=out[0]);
</code></pre>
<p>and I need:</p>
<pre><code>Or(a=a[0], b=b[0], out=out[0]);
Or(a=a[1], b=b[1], out=out[1]);
Or(a=a[2], b=b[2], out=out[2]);
</code></pre>
<p>I tried <a href="https://vi.stackexc... | [
{
"answer_id": 27700,
"author": "Quasímodo",
"author_id": 30440,
"author_profile": "https://vi.stackexchange.com/users/30440",
"pm_score": 3,
"selected": true,
"text": "<p>Do you mind some Awk?</p>\n<pre><code>:%!awk 'gsub(/[0-9]+/,i+0){i++}1'\n</code></pre>\n<p>This means:</p>\n<ul>\n<l... | 2020/10/17 | [
"https://vi.stackexchange.com/questions/27699",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/23504/"
] | Each row is:
```
Or(a=a[0], b=b[0], out=out[0]);
Or(a=a[0], b=b[0], out=out[0]);
Or(a=a[0], b=b[0], out=out[0]);
```
and I need:
```
Or(a=a[0], b=b[0], out=out[0]);
Or(a=a[1], b=b[1], out=out[1]);
Or(a=a[2], b=b[2], out=out[2]);
```
I tried [this](https://vi.stackexchange.com/questions/12867/how-to-replace-each-m... | Do you mind some Awk?
```
:%!awk 'gsub(/[0-9]+/,i+0){i++}1'
```
This means:
* `gsub(/[0-9]+/,i+0)` If there is any number in the line, substitute it by `i+0`.
* `{i++}` If a substitution occurred in this line, increment `i`.
* `1` is a short for "print the resulting line".
In case you are wondering, `i+0` forces t... |
27,702 | <p>I want to configure Vim to use spaces for <code><Tab></code>s everywhere. Therefore, I've had a look at <code>:h tabstop</code> to figure out how to perform the configuration.</p>
<p>Looking at the help text, option 2. seems appropriate for my use case. However, it doesn't mention <code>softtabstop</code>, why... | [
{
"answer_id": 27700,
"author": "Quasímodo",
"author_id": 30440,
"author_profile": "https://vi.stackexchange.com/users/30440",
"pm_score": 3,
"selected": true,
"text": "<p>Do you mind some Awk?</p>\n<pre><code>:%!awk 'gsub(/[0-9]+/,i+0){i++}1'\n</code></pre>\n<p>This means:</p>\n<ul>\n<l... | 2020/10/17 | [
"https://vi.stackexchange.com/questions/27702",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26505/"
] | I want to configure Vim to use spaces for `<Tab>`s everywhere. Therefore, I've had a look at `:h tabstop` to figure out how to perform the configuration.
Looking at the help text, option 2. seems appropriate for my use case. However, it doesn't mention `softtabstop`, why not? Without setting `softtabstop`, every `<Tab... | Do you mind some Awk?
```
:%!awk 'gsub(/[0-9]+/,i+0){i++}1'
```
This means:
* `gsub(/[0-9]+/,i+0)` If there is any number in the line, substitute it by `i+0`.
* `{i++}` If a substitution occurred in this line, increment `i`.
* `1` is a short for "print the resulting line".
In case you are wondering, `i+0` forces t... |
27,704 | <p>I'm kind of fine with moving across windows using <kbd>Ctrl</kbd>+<kbd>w</kbd> followed by (sometimes a counter and) <kbd>h</kbd>, <kbd>j</kbd>, <kbd>k</kbd>, <kbd>l</kbd>, <kbd>p</kbd>, <kbd>t</kbd>, <kbd>b</kbd>, and I'm also fine with the similar key combinations to split the windows or to move or rotate them, bu... | [
{
"answer_id": 27705,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>At one point I had mapped <code><leader>w</code> to <code><C-w></code>, but I found I didn't like t... | 2020/10/17 | [
"https://vi.stackexchange.com/questions/27704",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6498/"
] | I'm kind of fine with moving across windows using `Ctrl`+`w` followed by (sometimes a counter and) `h`, `j`, `k`, `l`, `p`, `t`, `b`, and I'm also fine with the similar key combinations to split the windows or to move or rotate them, but repeating the `Ctrl`+`w` everytime is a bit annoying.
Therefore I was thinking of... | The typical ways to have sub modes:
* be in a buffer with dedicated `<buffer>` local mappings
* or enter a loop where we read key pressed and act accordingly.
The second point is more likely to correspond to what you're looking for:
1. enter the windows navigation mode
2. navigate
3. exit
It's implemented by waitin... |
27,720 | <p>I am deciding between using either goneovim vs neovide, both on windows, but each uses the font height differently, so I a wanted to make something like:</p>
<pre><code>if has(goneovim)
"goneovim specific stuff
elseif has (neovide)
"neovide specific stuff
end
</code></pre>
<p>So I want to know if t... | [
{
"answer_id": 27705,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>At one point I had mapped <code><leader>w</code> to <code><C-w></code>, but I found I didn't like t... | 2020/10/19 | [
"https://vi.stackexchange.com/questions/27720",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22710/"
] | I am deciding between using either goneovim vs neovide, both on windows, but each uses the font height differently, so I a wanted to make something like:
```
if has(goneovim)
"goneovim specific stuff
elseif has (neovide)
"neovide specific stuff
end
```
So I want to know if that is possible, and if so, how I ... | The typical ways to have sub modes:
* be in a buffer with dedicated `<buffer>` local mappings
* or enter a loop where we read key pressed and act accordingly.
The second point is more likely to correspond to what you're looking for:
1. enter the windows navigation mode
2. navigate
3. exit
It's implemented by waitin... |
27,745 | <p>I've been unable to find plugin support for simple navigation to "next/previous with same indentation" (e.g <code>[[</code> and <code>]]</code>) in yaml. I have folding supported, but I'd like to navigate without using folds.</p>
<p>I feel like this shouldn't be hard, but I'm just not looking in the right ... | [
{
"answer_id": 27705,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>At one point I had mapped <code><leader>w</code> to <code><C-w></code>, but I found I didn't like t... | 2020/10/20 | [
"https://vi.stackexchange.com/questions/27745",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21166/"
] | I've been unable to find plugin support for simple navigation to "next/previous with same indentation" (e.g `[[` and `]]`) in yaml. I have folding supported, but I'd like to navigate without using folds.
I feel like this shouldn't be hard, but I'm just not looking in the right place. | The typical ways to have sub modes:
* be in a buffer with dedicated `<buffer>` local mappings
* or enter a loop where we read key pressed and act accordingly.
The second point is more likely to correspond to what you're looking for:
1. enter the windows navigation mode
2. navigate
3. exit
It's implemented by waitin... |
27,747 | <p>I have a text that looks like this</p>
<pre><code>" original
call minpac#add('morhetz / gruvbox')
" desired
call minpac#add('morhetz/gruvbox')
</code></pre>
<p>How can I limit vim pattern search within parentheses?</p>
<p>I tried <code>'<,'>s/ //g</code> in visual selection mode, <strong>but</st... | [
{
"answer_id": 27705,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>At one point I had mapped <code><leader>w</code> to <code><C-w></code>, but I found I didn't like t... | 2020/10/20 | [
"https://vi.stackexchange.com/questions/27747",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/17317/"
] | I have a text that looks like this
```
" original
call minpac#add('morhetz / gruvbox')
" desired
call minpac#add('morhetz/gruvbox')
```
How can I limit vim pattern search within parentheses?
I tried `'<,'>s/ //g` in visual selection mode, **but** the problem is it also removes the indentation at the start as a... | The typical ways to have sub modes:
* be in a buffer with dedicated `<buffer>` local mappings
* or enter a loop where we read key pressed and act accordingly.
The second point is more likely to correspond to what you're looking for:
1. enter the windows navigation mode
2. navigate
3. exit
It's implemented by waitin... |
27,762 | <p>Let's say I have a function like this:</p>
<pre><code>function! Foo()
echom 'foo'
endfunction
</code></pre>
<p>And a map like this:</p>
<pre><code>nmap gf :<C-U>call Foo()<CR>0v$
</code></pre>
<p>When I type <code>gf</code> I see <code>foo</code> echoed and the current line is highlighted. So far, so ... | [
{
"answer_id": 27705,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>At one point I had mapped <code><leader>w</code> to <code><C-w></code>, but I found I didn't like t... | 2020/10/22 | [
"https://vi.stackexchange.com/questions/27762",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1643/"
] | Let's say I have a function like this:
```
function! Foo()
echom 'foo'
endfunction
```
And a map like this:
```
nmap gf :<C-U>call Foo()<CR>0v$
```
When I type `gf` I see `foo` echoed and the current line is highlighted. So far, so good.
I want to be able to execute the rhs of the map without using the lhs. Si... | The typical ways to have sub modes:
* be in a buffer with dedicated `<buffer>` local mappings
* or enter a loop where we read key pressed and act accordingly.
The second point is more likely to correspond to what you're looking for:
1. enter the windows navigation mode
2. navigate
3. exit
It's implemented by waitin... |
27,770 | <p>I want to delete whitespace backwards until end of previous word.</p>
<p>Say, I have the cursor on the character "d" in the word "dog":</p>
<p><code>horse cat dog</code></p>
<p>If I press <code>Ctrl-W</code> (Insert mode) or <code>db</code> (Normal mode), then "cat" is deleted... | [
{
"answer_id": 27775,
"author": "Andy Stewart",
"author_id": 1643,
"author_profile": "https://vi.stackexchange.com/users/1643",
"pm_score": 2,
"selected": false,
"text": "<p>How about <code>hdiw</code>? I.e. move into the space and then delete the "word" formed by the whitespa... | 2020/10/23 | [
"https://vi.stackexchange.com/questions/27770",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26505/"
] | I want to delete whitespace backwards until end of previous word.
Say, I have the cursor on the character "d" in the word "dog":
`horse cat dog`
If I press `Ctrl-W` (Insert mode) or `db` (Normal mode), then "cat" is deleted, which I don't want.
Any ideas? | In normal mode:
```
cTt
```
Then press space |
27,773 | <p>In neovim, my code compiles and runs fine with this command:<br />
<code>:term clang++ main.cpp -o main && ./main</code>
, but not in vim.</p>
<p>When I run it in Vim the code neither compiles nor executes. I get the following error:</p>
<pre><code>clang-10: error: no such file or directory: '&&'
</c... | [
{
"answer_id": 27779,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": true,
"text": "<p>I don’t believe (though I can’t find reference to prove it) that <code>:terminal</code> in vim wraps the passed ... | 2020/10/23 | [
"https://vi.stackexchange.com/questions/27773",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31308/"
] | In neovim, my code compiles and runs fine with this command:
`:term clang++ main.cpp -o main && ./main`
, but not in vim.
When I run it in Vim the code neither compiles nor executes. I get the following error:
```
clang-10: error: no such file or directory: '&&'
```
but when I do `:term`, and inside it run `clan... | I don’t believe (though I can’t find reference to prove it) that `:terminal` in vim wraps the passed command in a shell. So to use shell features you need, e.g.,
```
terminal sh -c "clang++ main.cpp -o main && ./main"
```
By itself, however, `:terminal` starts `'shell'`, which is usually `$SHELL`. |
27,812 | <p>Goal: Select multiple words, one at a time, then replace them all.</p>
<p><a href="https://i.stack.imgur.com/hMq4F.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/hMq4F.gif" alt="visual studio feature select and replace" /></a></p>
<p>I'm new to Vim; I come from Visual Studio. I would like to achieve one i... | [
{
"answer_id": 27813,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 2,
"selected": false,
"text": "<p>One way would be to press <code>*</code> when your cursor is on the word you want to replace, <code>phrase</code> i... | 2020/10/27 | [
"https://vi.stackexchange.com/questions/27812",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31868/"
] | Goal: Select multiple words, one at a time, then replace them all.
[](https://i.stack.imgur.com/hMq4F.gif)
I'm new to Vim; I come from Visual Studio. I would like to achieve one important feature that helped me a lot in my productivity: S... | I’m assuming all the things to change are the same. If not, I would probably proceed with either multiples of the steps below, or combine all the patterns into a single substitute pattern.
So, not really what you asked for, but:
```
*cgn
```
Breakdown:
* `*`: start a search for the word under the cursor (`g*` if y... |
27,834 | <p>I'd like to define a text object for tab-delimited fields in a tsv file. So far, I have</p>
<pre><code>vnoremap af :<C-U>silent! normal! T<Tab>vf<Tab><CR>
omap af :normal Vat<CR>
vnoremap if :<C-U>silent! normal! T<Tab>vt<Tab><CR>
omap if :normal Vit<CR>
</... | [
{
"answer_id": 27838,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 0,
"selected": false,
"text": "<p>One option to consider is to use the <a href=\"https://github.com/kana/vim-textobj-user\" rel=\"nofollow noreferre... | 2020/10/29 | [
"https://vi.stackexchange.com/questions/27834",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32012/"
] | I'd like to define a text object for tab-delimited fields in a tsv file. So far, I have
```
vnoremap af :<C-U>silent! normal! T<Tab>vf<Tab><CR>
omap af :normal Vat<CR>
vnoremap if :<C-U>silent! normal! T<Tab>vt<Tab><CR>
omap if :normal Vit<CR>
```
The problem is with the first and the last field because those lack a... | I use following to have simple text objects including `<tab>` one:
```
" 26 simple text objects
" ----------------------
" i_ i. i: i, i; i| i/ i\ i* i+ i- i# i<tab>
" a_ a. a: a, a; a| a/ a\ a* a+ a- a# a<tab>
" Usage:
" for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '-', '#', '<tab>' ]
"... |
27,843 | <p>A file contains</p>
<pre><code>03-01-2020 04-01-2021
03-02-2020 04-02-2021
03-03-2020 04-03-2021
03-04-2020 04-04-2021
03-05-2020 04-05-2021
03-06-2020 04-06-2021
03-07-2020 04-07-2021
03-08-2020 04-08-2021
03-09-2020 04-09-2021
03-10-2020 04-10-2021
03-11-2020 04-11-2021
03-12-2020 04-12-2021
03-13-2020 04-13-2021
... | [
{
"answer_id": 27844,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 2,
"selected": false,
"text": "<p>You just need to place some capture groups in the right place:</p>\n<pre><code>%s/\\v(\\d\\d-\\d\\d)-\\d\\d(\\d\\d) (... | 2020/10/30 | [
"https://vi.stackexchange.com/questions/27843",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32026/"
] | A file contains
```
03-01-2020 04-01-2021
03-02-2020 04-02-2021
03-03-2020 04-03-2021
03-04-2020 04-04-2021
03-05-2020 04-05-2021
03-06-2020 04-06-2021
03-07-2020 04-07-2021
03-08-2020 04-08-2021
03-09-2020 04-09-2021
03-10-2020 04-10-2021
03-11-2020 04-11-2021
03-12-2020 04-12-2021
03-13-2020 04-13-2021
```
***How ... | You just need to place some capture groups in the right place:
```
%s/\v(\d\d-\d\d)-\d\d(\d\d) (\d\d-\d\d)-\d\d(\d\d)/\2-\1 \4-\3/
```
1. `\v` : Enable very magic mode to avoid having to escape all the parens.
2. `(\d\d-\d\d)` : Capture the first month and day.
3. `-\d\d` : Match the dash and first two digits of the... |
27,857 | <p>I wanted to write and edit a .tex document as fast as possible, so I followed <a href="https://castel.dev/post/lecture-notes-1/" rel="nofollow noreferrer">this guide</a>, but I can't get vimtex to work properly. I would like to have Vim hide characters like <code>$</code>,<code>\[</code> and replace some commands li... | [
{
"answer_id": 27865,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 2,
"selected": false,
"text": "<blockquote>\n<p>I wanted to write and edit a <code>.tex</code> document as fast as possible, so I followed this gui... | 2020/10/31 | [
"https://vi.stackexchange.com/questions/27857",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32041/"
] | I wanted to write and edit a .tex document as fast as possible, so I followed [this guide](https://castel.dev/post/lecture-notes-1/), but I can't get vimtex to work properly. I would like to have Vim hide characters like `$`,`\[` and replace some commands like `\bigcap` with `∩`. I don't care about compiling, I use Ove... | By tweaking the `_vimrc` file I have managed to determine the likely cause of the issue: the (missing) setting `set encoding=utf-8`. Without it, neither the replacement of characters nor the concealment work. |
27,866 | <p>I'm trying to make a vim function that takes a variable and uses that as part of a shell command and buts it into the current buffer.</p>
<p>I tried using read but that just interprets the var as a string.</p>
<p>For instance, as an exaple</p>
<pre><code>function MyFunc(var1)
read !ls a:var1
end function
</code>... | [
{
"answer_id": 27867,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 3,
"selected": true,
"text": "<p>You're close. When you want to use a variable in an Ex command you need to use <code>:execute</code>. This command tak... | 2020/11/01 | [
"https://vi.stackexchange.com/questions/27866",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32051/"
] | I'm trying to make a vim function that takes a variable and uses that as part of a shell command and buts it into the current buffer.
I tried using read but that just interprets the var as a string.
For instance, as an exaple
```
function MyFunc(var1)
read !ls a:var1
end function
```
This looks for a dir calle... | You're close. When you want to use a variable in an Ex command you need to use `:execute`. This command takes a Vim expression as arguments, evaluates the expression, and runs the resulting string as an Ex command. During this process variables are resolved into their values.
Before evaluation all of the arguments are... |
27,920 | <p>In VScode ,we are using <code>ctrl+j</code> to hide the terminal. Then if we press ctrl+j again, it will open the same terminal.</p>
<p>Is it possible in VIM/NEOVIM? I tried <code>:Terminal</code> ,but there is no straightforward way to toggle it. I have seen some plugins are there to do. Is there any shortcut to hi... | [
{
"answer_id": 27867,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 3,
"selected": true,
"text": "<p>You're close. When you want to use a variable in an Ex command you need to use <code>:execute</code>. This command tak... | 2020/11/06 | [
"https://vi.stackexchange.com/questions/27920",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32117/"
] | In VScode ,we are using `ctrl+j` to hide the terminal. Then if we press ctrl+j again, it will open the same terminal.
Is it possible in VIM/NEOVIM? I tried `:Terminal` ,but there is no straightforward way to toggle it. I have seen some plugins are there to do. Is there any shortcut to hide the terminal when not needed... | You're close. When you want to use a variable in an Ex command you need to use `:execute`. This command takes a Vim expression as arguments, evaluates the expression, and runs the resulting string as an Ex command. During this process variables are resolved into their values.
Before evaluation all of the arguments are... |
27,937 | <p>I'm trying to add some syntax support for LaTeX3. There are huge commands containing <code>_</code>, so I change the match pattern of <code>texStatement</code> in <code>~/.vim/syntax/tex.vim</code></p>
<pre><code>syn match texStatement /\\[a-zA-Z@_:]\+/ contained
</code></pre>
<p>I have a piece of tex code</p>
<pre ... | [
{
"answer_id": 27941,
"author": "ZhiyuanLck",
"author_id": 31303,
"author_profile": "https://vi.stackexchange.com/users/31303",
"pm_score": 0,
"selected": false,
"text": "<p>Redefine various <code>texMathZone</code>s after</p>\n<pre><code>syn match texStatement /\\\\[a-zA-Z@_:]\\+/ conta... | 2020/11/07 | [
"https://vi.stackexchange.com/questions/27937",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31303/"
] | I'm trying to add some syntax support for LaTeX3. There are huge commands containing `_`, so I change the match pattern of `texStatement` in `~/.vim/syntax/tex.vim`
```
syn match texStatement /\\[a-zA-Z@_:]\+/ contained
```
I have a piece of tex code
```tex
\begin{equation}
a + b = c
\end{equation}
```
Before I... | It is not straightforward to change the built-in syntax to support LaTeX3. One may attempt to change the `texStatement` match rules as suggested [here: "Vim Configuration for expl3"](https://tex.stackexchange.com/questions/44624/vim-configuration-for-expl3). However, it will not work perfectly, because syntax matching ... |
27,938 | <p>I have opened few files in tab</p>
<pre><code> vim -p file1 file2 file3
</code></pre>
<p>When i have opened a tab contains file1, I open a terminal</p>
<pre><code>:botright terminal
</code></pre>
<p>But this terminal is only available for file1 . when I open other tabs file2 and file 3 , the terminal is not shown u... | [
{
"answer_id": 27940,
"author": "Andrew Ho-Lee",
"author_id": 32132,
"author_profile": "https://vi.stackexchange.com/users/32132",
"pm_score": 2,
"selected": false,
"text": "<p>Is there a reason you open each file in a different tab with <code>-p</code>? The standard way to open multipl... | 2020/11/07 | [
"https://vi.stackexchange.com/questions/27938",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32117/"
] | I have opened few files in tab
```
vim -p file1 file2 file3
```
When i have opened a tab contains file1, I open a terminal
```
:botright terminal
```
But this terminal is only available for file1 . when I open other tabs file2 and file 3 , the terminal is not shown under. Is there a way to show a terminal under... | Sadly, no, it is not possible.
If you look at `:help windows-intro`, the following (among other) is said:
```
A buffer is the in-memory text of a file. ... |
27,942 | <h3>Summary</h3>
<p>I configured vim to call <code>clang-format.py</code> following the steps in the <a href="http://clang.llvm.org/docs/ClangFormat.html#vim-integration" rel="nofollow noreferrer">clang documentation for vim integration</a>. But when I save a new buffer the plugin fails. I'm new to vimscript and tryi... | [
{
"answer_id": 27944,
"author": "Gabriel Southern",
"author_id": 2262,
"author_profile": "https://vi.stackexchange.com/users/2262",
"pm_score": 0,
"selected": false,
"text": "<p>One solution I found is to modify clang-format.py to catch the error if the file is not found on disk. The dow... | 2020/11/07 | [
"https://vi.stackexchange.com/questions/27942",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2262/"
] | ### Summary
I configured vim to call `clang-format.py` following the steps in the [clang documentation for vim integration](http://clang.llvm.org/docs/ClangFormat.html#vim-integration). But when I save a new buffer the plugin fails. I'm new to vimscript and trying to figure out a solution.
### Details
I used homebre... | I don't know why the ClangFormat documentation recommends that approach, but it just makes things difficult.
You just need to set `formatprg` in `~/.vim/after/ftplugin/cpp.vim` as follows:
```
setlocal formatprg=clang-format\ --style=GNU
```
and your autocommand:
```
augroup Format
autocmd!
autocmd BufWrit... |
27,946 | <p>My cursor is at <code>H</code></p>
<pre><code>{
//foo
{
//bar
{
//cursor is Here
}
//bar2
}
}
</code></pre>
<p>How do I delete the outer layer of brackets while keeping the layer where my cursor is intact? End result should be:</p>
<pre><code>{
//foo
{
//cursor is Here
}
}
</cod... | [
{
"answer_id": 27947,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 3,
"selected": true,
"text": "<p>Delete a Block, delete a Block into a black hole register, Paste:</p>\n<pre><code>daB"_daBP\n</code></pre>\n<p>Al... | 2020/11/08 | [
"https://vi.stackexchange.com/questions/27946",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32143/"
] | My cursor is at `H`
```
{
//foo
{
//bar
{
//cursor is Here
}
//bar2
}
}
```
How do I delete the outer layer of brackets while keeping the layer where my cursor is intact? End result should be:
```
{
//foo
{
//cursor is Here
}
}
```
Same question for `foo(bar(/*cursor is Here*... | Delete a Block, delete a Block into a black hole register, Paste:
```
daB"_daBP
```
Almost what you want, cursor position would be different in the end.
To fix indentation, do `=aB`
For the second case, you could use almost the same:
```
dab"_dabp
``` |
27,952 | <p>I have this:</p>
<pre><code>Alice --> Bob
Dave --> Eve
</code></pre>
<p>and want to change that to this:</p>
<pre><code>Bob <-- Alice
Eve <-- Dave
</code></pre>
<p>Changing from <code>--></code> to <code><--</code> can easily be done with <code>:s/-->/<--/</code>, but swapping <code>Alice</co... | [
{
"answer_id": 27953,
"author": "Jake Grossman",
"author_id": 31207,
"author_profile": "https://vi.stackexchange.com/users/31207",
"pm_score": 2,
"selected": false,
"text": "<p>You could use numbered sub-expressions outlined in the reference manual in <code>:h /\\1</code> and <code>:h /\... | 2020/11/09 | [
"https://vi.stackexchange.com/questions/27952",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25859/"
] | I have this:
```
Alice --> Bob
Dave --> Eve
```
and want to change that to this:
```
Bob <-- Alice
Eve <-- Dave
```
Changing from `-->` to `<--` can easily be done with `:s/-->/<--/`, but swapping `Alice` and `Bob` requires me to `delete - jump - put` multiple times.
What's a good way to swap `Alice` & `Bob` aro... | You could use numbered sub-expressions outlined in the reference manual in `:h /\1` and `:h /\(`, and introduced in the user manual in `:h 12.2`. To simplify, I'm assuming that you have a line containing only the following:
```
Alice --> Bob
```
Then, you could use the following substitution to do the entire operati... |
27,970 | <p>my vimrc is too large, search and modification for me is a bit pain. Is it possible to have a table of contents so that I can jump to the section faster?</p>
| [
{
"answer_id": 27953,
"author": "Jake Grossman",
"author_id": 31207,
"author_profile": "https://vi.stackexchange.com/users/31207",
"pm_score": 2,
"selected": false,
"text": "<p>You could use numbered sub-expressions outlined in the reference manual in <code>:h /\\1</code> and <code>:h /\... | 2020/11/10 | [
"https://vi.stackexchange.com/questions/27970",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15958/"
] | my vimrc is too large, search and modification for me is a bit pain. Is it possible to have a table of contents so that I can jump to the section faster? | You could use numbered sub-expressions outlined in the reference manual in `:h /\1` and `:h /\(`, and introduced in the user manual in `:h 12.2`. To simplify, I'm assuming that you have a line containing only the following:
```
Alice --> Bob
```
Then, you could use the following substitution to do the entire operati... |
27,990 | <p><img src="https://user-images.githubusercontent.com/65082432/98810940-f326e080-245a-11eb-91ad-09ec086d3cb2.png" alt="Screenshot_20201111_201729" /></p>
<p>This is the display when I typed <code>:AsyncRun -mode=term -pos=bottom ~/.anaconda/bin/python %</code>.</p>
<p>But if I set:</p>
<pre><code>filetype plugin on
ma... | [
{
"answer_id": 28030,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>Remove the lines that open the quickfix list (<code>:copen</code>).</p>\n<p>Aside—if you use <code>:execute</co... | 2020/11/11 | [
"https://vi.stackexchange.com/questions/27990",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31853/"
] | 
This is the display when I typed `:AsyncRun -mode=term -pos=bottom ~/.anaconda/bin/python %`.
But if I set:
```
filetype plugin on
map <F5> :call RunPython()<CR>
function! RunPython()
... | Remove the lines that open the quickfix list (`:copen`).
Aside—if you use `:execute` for simple Ex commands, it’s usually enough to do just the command (so just `:copen`, `:wincmd p`, etc.). Even the colon’s aren’t necessary in most places. |
28,013 | <p>How do I select words with <code>Ctrl+Shift+Right</code> and <code>Ctrl+Shift+Left</code>, like in other editors?</p>
<p>I tried with:</p>
<pre><code>set keymodel=startsel,stopsel
set selectmode+=key
</code></pre>
<p>but it selects till the beginning of the next word.</p>
<p>I also tried:</p>
<pre><code>nnoremap <... | [
{
"answer_id": 27994,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 2,
"selected": true,
"text": "<p>Those are trailing whitespaces highlighted as error.</p>\n<p>Most probably they are from vim-polyglot plugin:</p>\n<p>... | 2020/11/12 | [
"https://vi.stackexchange.com/questions/28013",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32191/"
] | How do I select words with `Ctrl+Shift+Right` and `Ctrl+Shift+Left`, like in other editors?
I tried with:
```
set keymodel=startsel,stopsel
set selectmode+=key
```
but it selects till the beginning of the next word.
I also tried:
```
nnoremap <C-S-Right> ve
```
but then it enters visual mode, not select mode. H... | Those are trailing whitespaces highlighted as error.
Most probably they are from vim-polyglot plugin:
<https://github.com/sheerun/vim-polyglot/blob/4af1321588c7dcb718022226cb27ec325973c2f0/syntax/python.vim#L160>
To "fix" it:
1. Either remove those spaces from the file
2. Or add `let g:python_highlight_space_errors... |
28,014 | <p>I'm trying to add include an unsupported filetype, <code>gf</code>, with vim commentary. The comments are simple, just prepend <code>--</code> to any line, as in the Haskell tradition.</p>
<p>According to the vim-commentary git,</p>
<pre><code>Relax! You just have to adjust 'commentstring':
autocmd FileType apache... | [
{
"answer_id": 28015,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 2,
"selected": false,
"text": "<ol>\n<li>Make sure you vim-commentary works, e.g. you can open <code>python</code> file and <code>gcc</code> to comment... | 2020/11/13 | [
"https://vi.stackexchange.com/questions/28014",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32199/"
] | I'm trying to add include an unsupported filetype, `gf`, with vim commentary. The comments are simple, just prepend `--` to any line, as in the Haskell tradition.
According to the vim-commentary git,
```
Relax! You just have to adjust 'commentstring':
autocmd FileType apache setlocal commentstring=#\ %s
```
If I t... | 1. Make sure you vim-commentary works, e.g. you can open `python` file and `gcc` to comment current line.
2. To add support for a new filetype -- filetype has to provide `commentstring`, so if you are the author of the filetype -- then add `setlocal commentstring=--\ %s` to your `ftplugin/YOURFILETYPENAME.vim`.
3. if y... |
28,038 | <p><strong>TL;DR</strong>: <code>da(</code> doesn't delete the following space like <code>daw</code> does. Can I make this do what I want easily?</p>
<p>I have some sample lines (cursor is shown as <code>|</code>):</p>
<pre><code>1. Sample line (extraneous| statement) in notes.
2. Sample line extra|neous in notes.
</co... | [
{
"answer_id": 28032,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>The <code>:echoerr</code> test doesn't really mean anything; <code>:echoerr</code> just echo's what you type (n... | 2020/11/15 | [
"https://vi.stackexchange.com/questions/28038",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/17205/"
] | **TL;DR**: `da(` doesn't delete the following space like `daw` does. Can I make this do what I want easily?
I have some sample lines (cursor is shown as `|`):
```
1. Sample line (extraneous| statement) in notes.
2. Sample line extra|neous in notes.
```
On line 2, `daw` will leave me with a complete, well-written se... | It is likely that you are reading the wrong tutorial since you are using Windows, but your tutorial are apparently meant for Linux/macOS users.
The definitive answer: the neovim config is named `init.vim` and its location varies based on the operating system you use. You can use command `:echo stdpath('config')` insid... |
28,059 | <p>I need to sort a list like this one, by the first uppercase letter:</p>
<pre><code>{alan turing Smith's Prize 1936}
{werner heisenberg Matteucci Medal 1929}
{albert einstein Barnard Medal 1920}
</code></pre>
<p>From the manual entry for <code>:sort</code>, I'd expect that any of those commands would accomplish that:... | [
{
"answer_id": 28032,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>The <code>:echoerr</code> test doesn't really mean anything; <code>:echoerr</code> just echo's what you type (n... | 2020/11/17 | [
"https://vi.stackexchange.com/questions/28059",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8671/"
] | I need to sort a list like this one, by the first uppercase letter:
```
{alan turing Smith's Prize 1936}
{werner heisenberg Matteucci Medal 1929}
{albert einstein Barnard Medal 1920}
```
From the manual entry for `:sort`, I'd expect that any of those commands would accomplish that:
```
:sort /[^A-Z]*/
:sort /[A-Z]... | It is likely that you are reading the wrong tutorial since you are using Windows, but your tutorial are apparently meant for Linux/macOS users.
The definitive answer: the neovim config is named `init.vim` and its location varies based on the operating system you use. You can use command `:echo stdpath('config')` insid... |
28,086 | <p>Using the YouCompleteMe plugin, I'd like to be able to move my cursor over e.g. a function in all supported languages (e.g. JS), and use some keybinding to toggle the information dialog on/off. (At the moment, I have to wait a few seconds for the box to show; I'd prefer to control it explicitly).</p>
<p>Is this poss... | [
{
"answer_id": 28087,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 2,
"selected": false,
"text": "<p>Add to your config:</p>\n<pre><code>nmap <silent> <leader>h <plug>(YCMHover)\n</code></pre>\n<p>I p... | 2020/11/19 | [
"https://vi.stackexchange.com/questions/28086",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30111/"
] | Using the YouCompleteMe plugin, I'd like to be able to move my cursor over e.g. a function in all supported languages (e.g. JS), and use some keybinding to toggle the information dialog on/off. (At the moment, I have to wait a few seconds for the box to show; I'd prefer to control it explicitly).
Is this possible? | Add to your config:
```
nmap <silent> <leader>h <plug>(YCMHover)
```
I prefer `K` for that, but only for buffers/filetypes, where it makes sense:
```
let s:lsp_ft_maps = 'gdscript,go,python'
augroup ycm_settings | au!
exe printf('au FileType %s call Ycm_mappings()', s:lsp_ft_maps)
augroup end
func! Ycm_mappin... |
28,088 | <p>some time ago, I wrote a small plugin in vimscript that was using builtin function <code>getmarklist</code>. Recently I reinstalled Vim and was surprissed that this plugin no longer worked because Vim couldn't find <code>getmarklist</code>. I don't know if this function was removed or this has something to do with b... | [
{
"answer_id": 28091,
"author": "Benjamin Frazier",
"author_id": 7226,
"author_profile": "https://vi.stackexchange.com/users/7226",
"pm_score": 1,
"selected": false,
"text": "<p>To get a list of marks in vimscript just use the following command:</p>\n<pre><code>:marks\n</code></pre>\n<p>... | 2020/11/19 | [
"https://vi.stackexchange.com/questions/28088",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25118/"
] | some time ago, I wrote a small plugin in vimscript that was using builtin function `getmarklist`. Recently I reinstalled Vim and was surprissed that this plugin no longer worked because Vim couldn't find `getmarklist`. I don't know if this function was removed or this has something to do with build architecture. My old... | To get a list of marks in vimscript just use the following command:
```
:marks
```
I would also recommend the plugin called: [vim-signature](https://github.com/kshenoy/vim-signature). This plugin will automatically display marks in vim. Here is a screen shot:
[ as many times as desired whilst retaining the selection as it moves.</p>
<p>Kind of like this:</p>
<p><a href="https://i.stack.imgur.com/822an.gif" rel="nofollow noreferrer"><img src="https... | [
{
"answer_id": 28107,
"author": "Jorengarenar",
"author_id": 25807,
"author_profile": "https://vi.stackexchange.com/users/25807",
"pm_score": 0,
"selected": false,
"text": "<p>Plugin <a href=\"https://github.com/Jorengarenar/vim-MvVis\" rel=\"nofollow noreferrer\">MvVis</a> offers such f... | 2020/11/21 | [
"https://vi.stackexchange.com/questions/28106",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32257/"
] | I want to select some characters on a line, then be able to move them by one character forward/backward (i.e to the right/left) as many times as desired whilst retaining the selection as it moves.
Kind of like this:
[](https://i.stack.imgur.com/822an... | If you don't want to install a plugin for this, you can also just write a couple of visual mode mappings:
This *almost* works:
```
xnoremap L dp`[v`]
xnoremap H dhP`[v`]
```
...but if you have [`virtualedit`](https://vimhelp.org/options.txt.html#%27virtualedit%27) set to its default value, then at the end of the li... |
28,110 | <p>I have 3 languages and any can be a source or target so I need some flexibility.
I am successfully loading a language translation specific setup with this:</p>
<pre><code>let g:tr_source = 'dyu'
let g:tr_target = 'fr'
call system('export TR_SOURCE=dyu')
call system('export TR_TARGET=fr')
autocmd BufNewFi... | [
{
"answer_id": 28107,
"author": "Jorengarenar",
"author_id": 25807,
"author_profile": "https://vi.stackexchange.com/users/25807",
"pm_score": 0,
"selected": false,
"text": "<p>Plugin <a href=\"https://github.com/Jorengarenar/vim-MvVis\" rel=\"nofollow noreferrer\">MvVis</a> offers such f... | 2020/11/21 | [
"https://vi.stackexchange.com/questions/28110",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19032/"
] | I have 3 languages and any can be a source or target so I need some flexibility.
I am successfully loading a language translation specific setup with this:
```
let g:tr_source = 'dyu'
let g:tr_target = 'fr'
call system('export TR_SOURCE=dyu')
call system('export TR_TARGET=fr')
autocmd BufNewFile $TR_SOURCE... | If you don't want to install a plugin for this, you can also just write a couple of visual mode mappings:
This *almost* works:
```
xnoremap L dp`[v`]
xnoremap H dhP`[v`]
```
...but if you have [`virtualedit`](https://vimhelp.org/options.txt.html#%27virtualedit%27) set to its default value, then at the end of the li... |
28,116 | <p>How to have a selection grow/shrink as we tabulate, regardless of cursor position ? The selection can span more than one line. Kind of like this:</p>
<p><a href="https://i.stack.imgur.com/tlF0x.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tlF0x.gif" alt="enter image description here" /></a></p>... | [
{
"answer_id": 28117,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>If it’s always a whole line, just replace <code>gv</code> with <code>V</code></p>\n<p>We tried</p>\n<pre><code>... | 2020/11/22 | [
"https://vi.stackexchange.com/questions/28116",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32257/"
] | How to have a selection grow/shrink as we tabulate, regardless of cursor position ? The selection can span more than one line. Kind of like this:
[](https://i.stack.imgur.com/tlF0x.gif)
For the tabbing I've got this part so far:
```
xnoremap <TAB> >... | This works if you're in Visual Line mode, so one option (the one I'd recommend) is to always convert to Visual mode (from character or block visual mode) if needed, before the operation.
With characterwise visual mode, the `>` command affects the line in a way that the original bounds of the selection are lost (in tha... |
28,124 | <p><code>zo</code> can open folded lines in normal mode. What if I'm in insert mode?</p>
<p>For example:</p>
<pre><code>line1
line2
</code></pre>
<p>Fold it with <code>:1,2fold</code> in ex mode; now, the cursor is in the beginning of line1. Then press <code>o</code> to switch to insert mode, move the cursor to the beg... | [
{
"answer_id": 28125,
"author": "Endre Both",
"author_id": 9430,
"author_profile": "https://vi.stackexchange.com/users/9430",
"pm_score": 2,
"selected": false,
"text": "<p>With <code>Ctrl-o</code> you can switch from Insert to Normal mode for the duration of one command.</p>\n<p>So if in... | 2020/11/23 | [
"https://vi.stackexchange.com/questions/28124",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5181/"
] | `zo` can open folded lines in normal mode. What if I'm in insert mode?
For example:
```
line1
line2
```
Fold it with `:1,2fold` in ex mode; now, the cursor is in the beginning of line1. Then press `o` to switch to insert mode, move the cursor to the beginning of line1, press `z`, and the content will turn into this... | In insert mode,move the cursor on to the folded line ,press leftwards or rightwards arrow or enter key to unfold it. |
28,126 | <p>I am trying to write a function for insert mode mapping in which I want to get the character before the cursor character. For texts that are purely ASCII, this is easy, since its byte index is the character index. However, for Unicode characters, this is complicated.</p>
<pre><code>function! GetPreCursorChar()
let... | [
{
"answer_id": 28129,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>We could match against the character before the cursor (<code>.\\ze\\%#</code>) and get the match(es), but <cod... | 2020/11/23 | [
"https://vi.stackexchange.com/questions/28126",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15292/"
] | I am trying to write a function for insert mode mapping in which I want to get the character before the cursor character. For texts that are purely ASCII, this is easy, since its byte index is the character index. However, for Unicode characters, this is complicated.
```
function! GetPreCursorChar()
let line_text = ... | You can use `getline('.')[:col('.')-2]` to find the string of characters *before* the current cursor position.
Note that you need `col('.')-2`, first because `col(...)` returns 1 for the first column, while the substring syntax is 0-based (therefore -1) and also because when slicing a string with `[start:end]`, the in... |
28,130 | <p>Sometimes I have a bunch of lines, where there's a column clearly indicating some commonality between them, which in general doesn't go far beyond that column; this is an example, I think general enough:</p>
<pre class="lang-none prettyprint-override"><code>...
what 1: and then
who 2: there's
when 3: some other
... | [
{
"answer_id": 28131,
"author": "Vee",
"author_id": 32212,
"author_profile": "https://vi.stackexchange.com/users/32212",
"pm_score": 2,
"selected": false,
"text": "<p>Would it be possible to try it with a macro?</p>\n<ol>\n<li>Perform your yank command as you first describe (<code>0y$</c... | 2020/11/23 | [
"https://vi.stackexchange.com/questions/28130",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6498/"
] | Sometimes I have a bunch of lines, where there's a column clearly indicating some commonality between them, which in general doesn't go far beyond that column; this is an example, I think general enough:
```none
...
what 1: and then
who 2: there's
when 3: some other
where 4: text
ok? 5: on these lines
...
```
... | I tend to like using [`:normal`](https://vimhelp.org/various.txt.html#%3Anormal) with a range for this kind of edit.
Using `:normal` with a range is often similar to using a macro, but it can be more convenient in cases when:
* You want a single modification per line. (A macro can be more flexible in selecting what t... |
28,134 | <p>I have a 200,000+ line file that I need to update.</p>
<p>My issue is that I need to use commas to separate the fields; however in the original file there are commas placed in the "comment section." The comment section is delimited by <code>""</code>. Not all lines have this comment field popul... | [
{
"answer_id": 28136,
"author": "Vee",
"author_id": 32212,
"author_profile": "https://vi.stackexchange.com/users/32212",
"pm_score": 2,
"selected": true,
"text": "<p>I copied your example line in a test and found a search and replace command that will find your commas within quotes and d... | 2020/11/23 | [
"https://vi.stackexchange.com/questions/28134",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32325/"
] | I have a 200,000+ line file that I need to update.
My issue is that I need to use commas to separate the fields; however in the original file there are commas placed in the "comment section." The comment section is delimited by `""`. Not all lines have this comment field populated and it may not contain any commas.
S... | I copied your example line in a test and found a search and replace command that will find your commas within quotes and delete them.
```
%s/".*\zs,\ze.*"/
```
The breakdown:
* `%s/` for performing the search
* `"` for the beginning of your comment
* `.*` for any number of any characters
* `\zs` for the command to ... |
28,140 | <p>I have added the vim-go package to vim 8.2.716.</p>
<p>I used the "vim-packages" method, of cloning a git repostitory</p>
<pre><code>git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go
</code></pre>
<p>And then I have run <code>:GoInstallBinaries</code> from vim, apparently succe... | [
{
"answer_id": 28147,
"author": "James K",
"author_id": 6217,
"author_profile": "https://vi.stackexchange.com/users/6217",
"pm_score": 1,
"selected": false,
"text": "<p>The line in the <code>.vimrc</code></p>\n<pre><code>filetype plugin indent on\n</code></pre>\n<p>needs to be put before... | 2020/11/23 | [
"https://vi.stackexchange.com/questions/28140",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6217/"
] | I have added the vim-go package to vim 8.2.716.
I used the "vim-packages" method, of cloning a git repostitory
```
git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go
```
And then I have run `:GoInstallBinaries` from vim, apparently successfully.
I am following the install instructions a... | I figured out why you're having the problem and why moving the `filetype` command above the setting of `runtimepath` is fixing it.
The problem is that your setting of `'runtimepath'` is incorrect, in that it's listing directory `/usr/share/vim/vim81`, which doesn't really match your version of Vim, and I expect this d... |
28,148 | <p>I have these lines;</p>
<pre><code>Question1. Is this true?
a. Yes
b. No
Question2. How is the weather
a. Good
b. Bad
Question3. The sky is
a. Dark
b. Blue
</code></pre>
<p>I wanted to change it to;</p>
<pre><code>Question1. Is this true?
a. Yes
b. No
Question2. How is the weather
a. Good
b. Bad
Question3. The sky... | [
{
"answer_id": 28142,
"author": "Vee",
"author_id": 32212,
"author_profile": "https://vi.stackexchange.com/users/32212",
"pm_score": 2,
"selected": false,
"text": "<p>If you want to move to the beginning or end of a paragraph of text, you can use <code>}</code> and <code>{</code> respect... | 2020/11/24 | [
"https://vi.stackexchange.com/questions/28148",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31511/"
] | I have these lines;
```
Question1. Is this true?
a. Yes
b. No
Question2. How is the weather
a. Good
b. Bad
Question3. The sky is
a. Dark
b. Blue
```
I wanted to change it to;
```
Question1. Is this true?
a. Yes
b. No
Question2. How is the weather
a. Good
b. Bad
Question3. The sky is
a. Dark
b. Blue
```
Is it po... | Command `o` will get you to the "other" end of the Visual selection.
See [`:help v_o`](https://vimhelp.org/visual.txt.html#v_o):
>
> Go to Other end of highlighted text: The current cursor position becomes the start of the highlighted text and the cursor is moved to the other end of the highlighted text. The highlig... |
28,154 | <p>I am unable to turn on syntax highlighting for Markdown. How do I do it?</p>
<p>Here's my version information:</p>
<pre><code>VIM - Vi IMproved 8.2 (2019 Dec 12, compiled May 15 2020 15:48:23)
Included patches: 1-758
</code></pre>
<p>Here's the relevant part of my vimrc</p>
<pre><code>" Highlighting for markdow... | [
{
"answer_id": 28156,
"author": "wdb",
"author_id": 31441,
"author_profile": "https://vi.stackexchange.com/users/31441",
"pm_score": 0,
"selected": false,
"text": "<p>Per comment to original post (@D.BenKnoble), I set <code>:syntax enable</code>, and the Markdown highlighting worked. Run... | 2020/11/24 | [
"https://vi.stackexchange.com/questions/28154",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31441/"
] | I am unable to turn on syntax highlighting for Markdown. How do I do it?
Here's my version information:
```
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled May 15 2020 15:48:23)
Included patches: 1-758
```
Here's the relevant part of my vimrc
```
" Highlighting for markdown
autocmd BufNewFile,BufFilePre,BufRead *.md ... | You need to turn on syntax highlighting explicitly:
```
syntax enable
``` |
28,198 | <p>Finding the line with a specific character before the last character. Suppose, I have the following string</p>
<pre><code>1. addar_ctrl1,1,2,0,0,1
2. addar_ctrl2,3,2,0,1,0
3. addar_ctrl3,4,8,0,0,0
4. addar_ctrl4,2,6,0,1,1
</code></pre>
<p>I want to grasp the line contains '1' in the 2nd last position in each row.</p... | [
{
"answer_id": 28156,
"author": "wdb",
"author_id": 31441,
"author_profile": "https://vi.stackexchange.com/users/31441",
"pm_score": 0,
"selected": false,
"text": "<p>Per comment to original post (@D.BenKnoble), I set <code>:syntax enable</code>, and the Markdown highlighting worked. Run... | 2020/11/27 | [
"https://vi.stackexchange.com/questions/28198",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30727/"
] | Finding the line with a specific character before the last character. Suppose, I have the following string
```
1. addar_ctrl1,1,2,0,0,1
2. addar_ctrl2,3,2,0,1,0
3. addar_ctrl3,4,8,0,0,0
4. addar_ctrl4,2,6,0,1,1
```
I want to grasp the line contains '1' in the 2nd last position in each row.
Expected output:
```
2. ... | You need to turn on syntax highlighting explicitly:
```
syntax enable
``` |
28,204 | <p>I want to have a key binding to yank the current line into the system clipboard. My current mapping is as follows:</p>
<pre><code>nnoremap <C-y> "+yy
</code></pre>
<p>However, this also yanks the newline. I often use this to copy shell commands so an automatic "Enter/Return" is a big problem.</p... | [
{
"answer_id": 28205,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>One way you can accomplish this is by calling the <code>setreg()</code> function. You can also use the <code>getlin... | 2020/11/28 | [
"https://vi.stackexchange.com/questions/28204",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25859/"
] | I want to have a key binding to yank the current line into the system clipboard. My current mapping is as follows:
```
nnoremap <C-y> "+yy
```
However, this also yanks the newline. I often use this to copy shell commands so an automatic "Enter/Return" is a big problem.
I've also tried using `Vy` instead of `yy` but... | One way you can accomplish this is by calling the `setreg()` function. You can also use the `getline()` function to get the contents of the current line, which is also convenient since it doesn't include the final newline.
For the specific case of yanking the current line:
```
call setreg('+', getline('.'))
```
And... |
28,207 | <p>In order to invert all characters on each line of a range I could think of the following</p>
<pre><code>:s/.*/\=list2str(reverse(str2list(getline('.'))))"
</code></pre>
<p>where I can put a <code>[range]</code> if I want.</p>
<p>Is there any better way to do this? I mean, quicker to write/more performant/more v... | [
{
"answer_id": 28208,
"author": "stackzebra",
"author_id": 18912,
"author_profile": "https://vi.stackexchange.com/users/18912",
"pm_score": 4,
"selected": true,
"text": "<p>If you're on Linux, you probably have <code>rev</code> installed.</p>\n<p>Then you can do:</p>\n<pre><code>:2,5!rev... | 2020/11/28 | [
"https://vi.stackexchange.com/questions/28207",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6498/"
] | In order to invert all characters on each line of a range I could think of the following
```
:s/.*/\=list2str(reverse(str2list(getline('.'))))"
```
where I can put a `[range]` if I want.
Is there any better way to do this? I mean, quicker to write/more performant/more versatile. | If you're on Linux, you probably have `rev` installed.
Then you can do:
```
:2,5!rev
```
Where 2,5 is range. |
28,238 | <p>I have several instances of variables in a file and I need to modify the variable and append "new" to each of the names.</p>
<pre><code>var Modelfrfr = ....
var Modeldede = ...
var Modelenen = ...
</code></pre>
<p>change it to</p>
<pre><code>var ModelfrfrNew = ....
var ModeldedeNew = ...
var ModelenenN... | [
{
"answer_id": 28239,
"author": "Vee",
"author_id": 32212,
"author_profile": "https://vi.stackexchange.com/users/32212",
"pm_score": 0,
"selected": false,
"text": "<p>With the cursor on the first line at the first column, the command <code>t=<C-v>2jINew<Esc></code> where:</p>... | 2020/11/30 | [
"https://vi.stackexchange.com/questions/28238",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32426/"
] | I have several instances of variables in a file and I need to modify the variable and append "new" to each of the names.
```
var Modelfrfr = ....
var Modeldede = ...
var Modelenen = ...
```
change it to
```
var ModelfrfrNew = ....
var ModeldedeNew = ...
var ModelenenNew = ...
```
What is the best way to do it... | Kind of this
```
%s/Model\a\+/&New/g
```
See `:h :s`, `:h /\a`, `:h sub-replace-special` and so on. |
28,241 | <p>I am preparing for the Egyptian Olympiad in Informatics and I prefer vim to be my code editor, but my problem is my <code>vimrc</code>, I think it is a bit long to type at the beginning of an onsite competition, but really is it? Here it is.</p>
<pre><code>set nocp
syntax on
colo torte
set rnu nu nowrap
set hi=100... | [
{
"answer_id": 28243,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>There are a few interresting things already in the default C and C++ filetype plugins -> <code>filetype plugin i... | 2020/11/30 | [
"https://vi.stackexchange.com/questions/28241",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32430/"
] | I am preparing for the Egyptian Olympiad in Informatics and I prefer vim to be my code editor, but my problem is my `vimrc`, I think it is a bit long to type at the beginning of an onsite competition, but really is it? Here it is.
```
set nocp
syntax on
colo torte
set rnu nu nowrap
set hi=1000
set cb=unnamed
set si... | The first line really should be `runtime defaults.vim`. This is a standard file and it must be present in all Vim installations. Among other things, it saves from typing
```
syntax on
filetype plugin indent on
set hi=200
set is
```
Also `set cb=unnamed` is evil (just prepend `"+` before normal mode command when need... |
28,267 | <p>I have a folder of third party libraries called <code>add-libraries</code> and the location for this specific library is <code>/home/yapjiahong/projects/cpp/add-libraries/plog/include</code>.</p>
<p>I want to write a function called <code>Include</code> that takes in <code>lib</code> as an argument. Then append that... | [
{
"answer_id": 28268,
"author": "Vee",
"author_id": 32212,
"author_profile": "https://vi.stackexchange.com/users/32212",
"pm_score": 0,
"selected": false,
"text": "<p>I think what you want is an <a href=\"https://vimhelp.org/map.txt.html#abbreviations\" rel=\"nofollow noreferrer\">abbrev... | 2020/12/02 | [
"https://vi.stackexchange.com/questions/28267",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32494/"
] | I have a folder of third party libraries called `add-libraries` and the location for this specific library is `/home/yapjiahong/projects/cpp/add-libraries/plog/include`.
I want to write a function called `Include` that takes in `lib` as an argument. Then append that to the end of a string. Then write it out where my c... | The `:insert` command cannot take an argument like you're trying to do, it expects user input for the lines, followed by a single line consisting of a `.` to finish inserting.
You probably want the `append()` function instead:
```
function Include(lib)
let path = "/home/yapjiahong/projects/cpp/add-libraries/" . a... |
28,270 | <p>Specifically, I'm looking to bind the search <code>/\(<<<<\|====\|>>>>\)/</code> (i.e. "find the next git merge boundary"). Ideally to <code><C-/></code> or <code><A-/></code>, but that part I'm not picky about.</p>
<p>I have tried</p>
<pre><code>nmap <A-/> /\(<... | [
{
"answer_id": 28268,
"author": "Vee",
"author_id": 32212,
"author_profile": "https://vi.stackexchange.com/users/32212",
"pm_score": 0,
"selected": false,
"text": "<p>I think what you want is an <a href=\"https://vimhelp.org/map.txt.html#abbreviations\" rel=\"nofollow noreferrer\">abbrev... | 2020/12/02 | [
"https://vi.stackexchange.com/questions/28270",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32456/"
] | Specifically, I'm looking to bind the search `/\(<<<<\|====\|>>>>\)/` (i.e. "find the next git merge boundary"). Ideally to `<C-/>` or `<A-/>`, but that part I'm not picky about.
I have tried
```
nmap <A-/> /\(<<<<\|====\|>>>>\)/<CR>
nmap <C-/> /\(<<<<\|====\|>>>>\)/<CR>
nmap <C-/> /\(<<<<\|====\|>>>>\)<CR>
nmap <C-/... | The `:insert` command cannot take an argument like you're trying to do, it expects user input for the lines, followed by a single line consisting of a `.` to finish inserting.
You probably want the `append()` function instead:
```
function Include(lib)
let path = "/home/yapjiahong/projects/cpp/add-libraries/" . a... |
28,278 | <p>I opened up a document in vim and I want to search the document for IP addresses. So I used this command</p>
<pre><code>/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}
</code></pre>
<p>But this pattern doesn't seem to return any of the IP addresses in my document. I can see there are IP addresses like <code>192.168.0.2... | [
{
"answer_id": 28279,
"author": "Vee",
"author_id": 32212,
"author_profile": "https://vi.stackexchange.com/users/32212",
"pm_score": 3,
"selected": false,
"text": "<p>When trying to specify the number of matches to be 1 to 3 entries of the preceding sequence of numbers, the correct forma... | 2020/12/03 | [
"https://vi.stackexchange.com/questions/28278",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3030/"
] | I opened up a document in vim and I want to search the document for IP addresses. So I used this command
```
/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}
```
But this pattern doesn't seem to return any of the IP addresses in my document. I can see there are IP addresses like `192.168.0.23` in my document.
What did ... | When trying to specify the number of matches to be 1 to 3 entries of the preceding sequence of numbers, the correct format is `\{m,n}`.
The manual reference is [here](https://vimhelp.org/pattern.txt.html#pattern-overview).
Your example works when I change it to:
```
/[0-9]\{1,3}\.[0-9]\{1,3}\.[0-9]\{1,3}\.[0-9]\{1,3... |
28,286 | <p>Sometimes I type a long substitute command</p>
<pre><code>/%s/foo/bar.../
</code></pre>
<p>and while I am typing it or only after hiting enter
I notice that I have mistakenly
used a the search key (<code>/</code>) instead of the ex-command key (<code>:</code>).</p>
<p>To fix it,</p>
<ol>
<li><p>If I have already pre... | [
{
"answer_id": 28287,
"author": "Quasímodo",
"author_id": 30440,
"author_profile": "https://vi.stackexchange.com/users/30440",
"pm_score": 3,
"selected": false,
"text": "<p>As B Layer said, Vim interprets the rest of the pattern (namely, <code>foo/bar.../</code>) as an invalid offset, so... | 2020/12/04 | [
"https://vi.stackexchange.com/questions/28286",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/30440/"
] | Sometimes I type a long substitute command
```
/%s/foo/bar.../
```
and while I am typing it or only after hiting enter
I notice that I have mistakenly
used a the search key (`/`) instead of the ex-command key (`:`).
To fix it,
1. If I have already pressed enter, I bring back the search string
with `/<C-P>`.
2. Use... | *I wasn't going to post this beyond my comment but then I see it turned into a competition.* ;)
If you mistakenly enter `/%s/foo/bar/` when you actually want to run `:%s/foo/bar/` then you just need these eleven keystrokes:
```
q/kY:q<CR>:@0<CR>
```
Mapped:
```
nnoremap <F10> q/kY:q<CR>:@0<CR>
```
I guess I shou... |
28,303 | <p>i am setting the default vim-statusline, and i made this line on my colorscheme:</p>
<p><code>hi MyStatusLineDevIcon ctermfg=7 ctermbg=0 cterm=NONE</code></p>
<p>So i can color the devicons on my <code>statusline.vim</code> config</p>
<p>I call them using this function:</p>
<pre><code>function! ShowDevIcons()
retu... | [
{
"answer_id": 28304,
"author": "leaf",
"author_id": 20261,
"author_profile": "https://vi.stackexchange.com/users/20261",
"pm_score": 0,
"selected": false,
"text": "<p>I tried <code>echom 'filetype '.&filetype</code> in <code>vimrc</code> and it's empty.</p>\n<p>You might need to use... | 2020/12/07 | [
"https://vi.stackexchange.com/questions/28303",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32519/"
] | i am setting the default vim-statusline, and i made this line on my colorscheme:
`hi MyStatusLineDevIcon ctermfg=7 ctermbg=0 cterm=NONE`
So i can color the devicons on my `statusline.vim` config
I call them using this function:
```
function! ShowDevIcons()
return WebDevIconsGetFileTypeSymbol()
endfunction
```
... | There are some issues with the approach you described.
First, you are calling `autocmd!` outside of an `augroup`. This is really bad, since it's actually erasing *all* auto-commands!
Second, the logic in `SetFiletype()` looks odd, since it's first checking whether the file type is `"vim"` and then creating an auto-co... |
28,332 | <p>I'm creating a mapping which is supposed to navigate to a specific window (call <code>TEST_WIN</code>), focus in on the terminal and then delete a single character.</p>
<p>The goal of this command is to navigate to the terminal buffer and execute the last line that was executed, but to remove the last word of the co... | [
{
"answer_id": 28344,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 1,
"selected": false,
"text": "<p>Previously answered <a href=\"https://unix.stackexchange.com/a/620416/281844\">here</a>.</p>\n<p>Terminal windows ... | 2020/12/09 | [
"https://vi.stackexchange.com/questions/28332",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32556/"
] | I'm creating a mapping which is supposed to navigate to a specific window (call `TEST_WIN`), focus in on the terminal and then delete a single character.
The goal of this command is to navigate to the terminal buffer and execute the last line that was executed, but to remove the last word of the command which will be ... | Since it seems the OP is using bash, here's a non-mapping, non-vim solution that should work in the shell:
```sh
!!:-
```
From `man bash`:
```
!! Refer to the previous command. This is a synonym for `!-1'.
[…]
x-y A range of words; `-y' abbreviates `0-y'.
[…]
x- Abbreviates x-$ like... |
28,333 | <p>I am within a vimscript, and I want jump (or get the position of) the beginning of the current parent brace, how can I make this happen?</p>
<p>Imagine the following example (the cursor is represented by <code>|</code>):</p>
<pre><code> (a && (b && c) && | (d && e)) <-... | [
{
"answer_id": 28334,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 3,
"selected": true,
"text": "<p>This functionality is provided by standard "matchit" plugin (if running Vim make sure you've enabled it with <c... | 2020/12/09 | [
"https://vi.stackexchange.com/questions/28333",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32557/"
] | I am within a vimscript, and I want jump (or get the position of) the beginning of the current parent brace, how can I make this happen?
Imagine the following example (the cursor is represented by `|`):
```
(a && (b && c) && | (d && e)) <- For parentheses
[a && [b && c] && | [d && e]] <- F... | This functionality is provided by standard "matchit" plugin (if running Vim make sure you've enabled it with `packadd matchit`).
Press `[``%` to get to the previous unmatched bracket. Don't forget to add `<` and `>` to `:h 'matchpairs'` as it's not the default.
Read `:h matchit` for more info. |
28,338 | <p>I want to be able to increment letters but only in visual block mode. I don't want <code><C-a></code>/<code><C-x></code> to increment letters outside of visual block.</p>
<p>This is for making incrementing lists from this:</p>
<pre><code>a) this
a) is a
a) test
</code></pre>
<p>... to this:</p>
<pre><cod... | [
{
"answer_id": 28339,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 1,
"selected": false,
"text": "<p>There is no simple way to do it (considering all edge cases).</p>\n<p>You can try remapping solution:</p>\n<pre><code... | 2020/12/09 | [
"https://vi.stackexchange.com/questions/28338",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25859/"
] | I want to be able to increment letters but only in visual block mode. I don't want `<C-a>`/`<C-x>` to increment letters outside of visual block.
This is for making incrementing lists from this:
```
a) this
a) is a
a) test
```
... to this:
```
a) this
b) is a
c) test
``` | There is no simple way to do it (considering all edge cases).
You can try remapping solution:
```
nnoremap <C-v> :setl nf+=alpha<CR><C-v>
nnoremap v :setl nf+=alpha<CR>v
nnoremap V :setl nf+=alpha<CR>V
xnoremap <C-a> <C-a>:setl nf-=alpha<CR>
xnoremap <C-x> <C-x>:setl nf-=alpha<CR>
xnoremap <ESC> <ESC>:setl nf-=alpha<... |
28,349 | <p>At moment, mostly for random reasons, I have</p>
<pre class="lang-none prettyprint-override"><code>$ cat ~/.vim/ftplugin/c.vim
set tabstop=2 softtabstop=2 expandtab shiftwidth=2 smarttab smartindent autoindent cinoptions=g2
</code></pre>
<p>and this</p>
<pre class="lang-none prettyprint-override"><code>$ cat ~/.vim... | [
{
"answer_id": 28350,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<p>When in doubt look into the standard Vim runtime files.</p>\n<p><code>ts sts et sw</code> should be set by <code>after/f... | 2020/12/09 | [
"https://vi.stackexchange.com/questions/28349",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6498/"
] | At moment, mostly for random reasons, I have
```none
$ cat ~/.vim/ftplugin/c.vim
set tabstop=2 softtabstop=2 expandtab shiftwidth=2 smarttab smartindent autoindent cinoptions=g2
```
and this
```none
$ cat ~/.vim/ftplugin/cpp.vim
let c_no_curly_error = 1
set tabstop=8 softtabstop=8 expandtab shiftwidth=8 smarttab ... | When in doubt look into the standard Vim runtime files.
`ts sts et sw` should be set by `after/ftplugin`.
`sta` is basically no-op, as you have `&sw == &sts` anyway.
`si ai` are basically no-op as you have `&cindent` on. And also, in general, there's nothing in setting `ai si` on if you have any meaningful `indent/x... |
28,351 | <p>So I'm trying to have a function type out a space which goes as follows:</p>
<pre><code>function! UnderlineHeading(level)
if a:level == 1
normal! yypVr=
elseif a:level == 2
normal! yypVr-
else
normal! I###<Space><Esc>
endif
endfunction
nnoremap <leader>u3 :call UnderlineHeading... | [
{
"answer_id": 28350,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<p>When in doubt look into the standard Vim runtime files.</p>\n<p><code>ts sts et sw</code> should be set by <code>after/f... | 2020/12/09 | [
"https://vi.stackexchange.com/questions/28351",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20416/"
] | So I'm trying to have a function type out a space which goes as follows:
```
function! UnderlineHeading(level)
if a:level == 1
normal! yypVr=
elseif a:level == 2
normal! yypVr-
else
normal! I###<Space><Esc>
endif
endfunction
nnoremap <leader>u3 :call UnderlineHeading(3)<cr>
```
However, when I p... | When in doubt look into the standard Vim runtime files.
`ts sts et sw` should be set by `after/ftplugin`.
`sta` is basically no-op, as you have `&sw == &sts` anyway.
`si ai` are basically no-op as you have `&cindent` on. And also, in general, there's nothing in setting `ai si` on if you have any meaningful `indent/x... |
28,354 | <p>When writing functions to use in mappings and user-defined commands (for plug-ins), it's often convenient to use a Normal-mode command to yank or delete buffer contents. In those cases, it's also nice to save and restore register contents across the call, so that pasting from the affected registers works across the ... | [
{
"answer_id": 28356,
"author": "user938271",
"author_id": 17449,
"author_profile": "https://vi.stackexchange.com/users/17449",
"pm_score": 3,
"selected": true,
"text": "<p>If your Vim includes the patch <a href=\"https://github.com/vim/vim/releases/tag/v8.2.0924\" rel=\"nofollow norefer... | 2020/12/09 | [
"https://vi.stackexchange.com/questions/28354",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/18609/"
] | When writing functions to use in mappings and user-defined commands (for plug-ins), it's often convenient to use a Normal-mode command to yank or delete buffer contents. In those cases, it's also nice to save and restore register contents across the call, so that pasting from the affected registers works across the cal... | If your Vim includes the patch [8.2.0924](https://github.com/vim/vim/releases/tag/v8.2.0924), then [you can use `getreginfo()`](https://github.com/lacygoill/wiki/blob/master/vim/register.md#what-should-i-use-instead). Note that – since this patch – `setreg()` also accepts a dictionary as its second argument. The same k... |
28,361 | <p><strong>Describe the issue</strong></p>
<p>I use a vim plugin that when use Vim to open a ipynb (python notebook) file, will call <code>system</code> function to use <code>jupytext</code> create corresponding python file to enable use like, YCM to help coding. This plugin set a autocmd BufUnload for the python file ... | [
{
"answer_id": 28365,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p>The current buffer and file is behind <code><afile></code>, not <code>%</code></p>\n"
},
{
"answer_id"... | 2020/12/10 | [
"https://vi.stackexchange.com/questions/28361",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16299/"
] | **Describe the issue**
I use a vim plugin that when use Vim to open a ipynb (python notebook) file, will call `system` function to use `jupytext` create corresponding python file to enable use like, YCM to help coding. This plugin set a autocmd BufUnload for the python file buffer to delete the python file when I quit... | As you can see in [`:help BufUnload`](https://vimhelp.org/autocmd.txt.html#BufUnload):
>
> **NOTE:** When this autocommand is executed, the current buffer `%` may be different from the buffer being unloaded `<afile>`.
>
>
>
So you should use [`getbufvar()`](https://vimhelp.org/eval.txt.html#getbufvar%28%29) to ac... |
28,362 | <p>It is fairly well known that syntax highlighting in vim breaks when one changes colorschemes frequently. This is due to peculiarities of hi def/hi clear.</p>
<p>Recently, the following changes were made:</p>
<pre><code>patch 8.2.1693: "hi def" does not work for cleared highlight
patch 8.2.1703: ":hig... | [
{
"answer_id": 28365,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p>The current buffer and file is behind <code><afile></code>, not <code>%</code></p>\n"
},
{
"answer_id"... | 2020/12/10 | [
"https://vi.stackexchange.com/questions/28362",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13728/"
] | It is fairly well known that syntax highlighting in vim breaks when one changes colorschemes frequently. This is due to peculiarities of hi def/hi clear.
Recently, the following changes were made:
```
patch 8.2.1693: "hi def" does not work for cleared highlight
patch 8.2.1703: ":highlight clear" does not restore defa... | As you can see in [`:help BufUnload`](https://vimhelp.org/autocmd.txt.html#BufUnload):
>
> **NOTE:** When this autocommand is executed, the current buffer `%` may be different from the buffer being unloaded `<afile>`.
>
>
>
So you should use [`getbufvar()`](https://vimhelp.org/eval.txt.html#getbufvar%28%29) to ac... |
28,369 | <p>do you have any simple and working template plugin to use for programming ?
I have tried <a href="https://github.com/drbeco/vimtemplates" rel="nofollow noreferrer">this</a> but to be honest I didn't understand how to use it. I have found <a href="https://github.com/LucHermitte/mu-template/" rel="nofollow noreferrer"... | [
{
"answer_id": 28365,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p>The current buffer and file is behind <code><afile></code>, not <code>%</code></p>\n"
},
{
"answer_id"... | 2020/12/10 | [
"https://vi.stackexchange.com/questions/28369",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/31984/"
] | do you have any simple and working template plugin to use for programming ?
I have tried [this](https://github.com/drbeco/vimtemplates) but to be honest I didn't understand how to use it. I have found [this](https://github.com/LucHermitte/mu-template/) but I didn't understand how to install it.
Thank you, I gave up to... | As you can see in [`:help BufUnload`](https://vimhelp.org/autocmd.txt.html#BufUnload):
>
> **NOTE:** When this autocommand is executed, the current buffer `%` may be different from the buffer being unloaded `<afile>`.
>
>
>
So you should use [`getbufvar()`](https://vimhelp.org/eval.txt.html#getbufvar%28%29) to ac... |
28,387 | <p>Is it possible to pipe list of files e.g. from grep and have this file list opened in vim file manager in similar fashion like when you open a folder with vim?</p>
<p>Note that I do not want to just write the file names into vim buffer like a text. I want vim to treat them as if these files were in a folder and I wo... | [
{
"answer_id": 28365,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p>The current buffer and file is behind <code><afile></code>, not <code>%</code></p>\n"
},
{
"answer_id"... | 2020/12/11 | [
"https://vi.stackexchange.com/questions/28387",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29945/"
] | Is it possible to pipe list of files e.g. from grep and have this file list opened in vim file manager in similar fashion like when you open a folder with vim?
Note that I do not want to just write the file names into vim buffer like a text. I want vim to treat them as if these files were in a folder and I would be ab... | As you can see in [`:help BufUnload`](https://vimhelp.org/autocmd.txt.html#BufUnload):
>
> **NOTE:** When this autocommand is executed, the current buffer `%` may be different from the buffer being unloaded `<afile>`.
>
>
>
So you should use [`getbufvar()`](https://vimhelp.org/eval.txt.html#getbufvar%28%29) to ac... |
28,395 | <p>I have <code>coc.nvim</code> with <code>pyright</code> installed. I added the following to my <code>.vimrc</code></p>
<pre><code>nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr ... | [
{
"answer_id": 28415,
"author": "pricheal",
"author_id": 26583,
"author_profile": "https://vi.stackexchange.com/users/26583",
"pm_score": 1,
"selected": false,
"text": "<p>I think you are confused on what the various language sever protocol features do. I don't believe that trying to &qu... | 2020/12/12 | [
"https://vi.stackexchange.com/questions/28395",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25312/"
] | I have `coc.nvim` with `pyright` installed. I added the following to my `.vimrc`
```
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
```
I was hoping that pressnig `gi` over a function name will t... | I think you are confused on what the various language sever protocol features do. I don't believe that trying to "go to implementation" or "go to type definition" on a function symbol makes any sense. If you are trying to go to the definition of the function, then you would want to "go to definition" (which would be `g... |
28,408 | <p>I use the following mappings to toggle relative numbers in visual mode:</p>
<pre><code>nnoremap <silent> v v:<c-u>set nonu rnu<cr>gv
nnoremap <silent> V V0:<c-u>set nonu rnu<cr>gv
nnoremap <silent> <c-v> <c-v>:<c-u>set nonu rnu<cr>gv
vnoremap <esc&... | [
{
"answer_id": 28415,
"author": "pricheal",
"author_id": 26583,
"author_profile": "https://vi.stackexchange.com/users/26583",
"pm_score": 1,
"selected": false,
"text": "<p>I think you are confused on what the various language sever protocol features do. I don't believe that trying to &qu... | 2020/12/13 | [
"https://vi.stackexchange.com/questions/28408",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19130/"
] | I use the following mappings to toggle relative numbers in visual mode:
```
nnoremap <silent> v v:<c-u>set nonu rnu<cr>gv
nnoremap <silent> V V0:<c-u>set nonu rnu<cr>gv
nnoremap <silent> <c-v> <c-v>:<c-u>set nonu rnu<cr>gv
vnoremap <esc> <esc>:set nornu nu<cr>
```
I would like to use the same mappings, but add a con... | I think you are confused on what the various language sever protocol features do. I don't believe that trying to "go to implementation" or "go to type definition" on a function symbol makes any sense. If you are trying to go to the definition of the function, then you would want to "go to definition" (which would be `g... |
28,416 | <p>I followed the directions in <a href="https://stackoverflow.com/a/1184897/13287828">this post</a> to sync my <code>vimrc</code> file in Dropbox with my two Windows computers. However, I also want to move all the other user content of my <code>vimfiles</code> folder to Dropbox as suggested by jqno. I've read the docu... | [
{
"answer_id": 28418,
"author": "Pak",
"author_id": 1115,
"author_profile": "https://vi.stackexchange.com/users/1115",
"pm_score": 3,
"selected": true,
"text": "<p>The way I do this is by having all the vim files located in my dropbox directory and then creating symlinks for the <code>vi... | 2020/12/14 | [
"https://vi.stackexchange.com/questions/28416",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28874/"
] | I followed the directions in [this post](https://stackoverflow.com/a/1184897/13287828) to sync my `vimrc` file in Dropbox with my two Windows computers. However, I also want to move all the other user content of my `vimfiles` folder to Dropbox as suggested by jqno. I've read the documentation on Vim's initialization st... | The way I do this is by having all the vim files located in my dropbox directory and then creating symlinks for the `vimrc` and `vimfiles` directory in my home directory. That way, vim isn't even aware that I'm doing anything "non-standard"; it just looks where it normally would and it finds the files as expected.
It'... |
28,419 | <p>I typically write all my software in the same way (omitting the TDD parts):</p>
<ol>
<li>Iterate pseudo code until it is granular enough that each part can be written in, hopefully, under 20 minutes.</li>
<li>Implement each "pseudo"-component</li>
</ol>
<p>Contrived example:</p>
<pre><code># Get file
# Ope... | [
{
"answer_id": 28424,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>One approach:</p>\n<p>Go to the <code># Get file</code> line, delete it (e.g., <code>dd</code>), and then <code... | 2020/12/14 | [
"https://vi.stackexchange.com/questions/28419",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32627/"
] | I typically write all my software in the same way (omitting the TDD parts):
1. Iterate pseudo code until it is granular enough that each part can be written in, hopefully, under 20 minutes.
2. Implement each "pseudo"-component
Contrived example:
```
# Get file
# Open file
# Verify integrity
# Parse
# Close file
```... | The ex commands [`:put`](https://vimhelp.org/change.txt.html#%3Aput) and [`:delete`](https://vimhelp.org/change.txt.html#%3Adelete) both allow you to specify a line, so if you've already placed mark `'a` on the line you want replaced, then you can execute the following after the copy:
```
:'apu
:'ad
```
or as a one ... |
28,421 | <p>I have some specifically formatted text files that I'd like to detect when I start vim. When I load these files now, the filetype is automatically set to text. I only want to override that if the first line of the text file starts with "Client:", in which case, I'd like to set the filetype to veltxt. I hav... | [
{
"answer_id": 28427,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>Yes, you should be able to set the filetype based on the contents of the file.</p>\n<p>If you add a script to the <... | 2020/12/14 | [
"https://vi.stackexchange.com/questions/28421",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32631/"
] | I have some specifically formatted text files that I'd like to detect when I start vim. When I load these files now, the filetype is automatically set to text. I only want to override that if the first line of the text file starts with "Client:", in which case, I'd like to set the filetype to veltxt. I have already cre... | Yes, you should be able to set the filetype based on the contents of the file.
If you add a script to the `ftdetect` directory, this script should set up a new `autocmd` to trigger when a file of a specific extension or file name pattern (or `*` if any file name is possible) is opened and then set the appropriate file... |
28,450 | <p>I'm using CoC and coc-python, and there is the <code>gd</code> mapping, which goes to the definition of a symbol. The mapping is defined as:</p>
<pre><code>nmap <silent> gd <Plug>(doc-definition)
</code></pre>
<p>Now, I want to first do a <code>vsplit</code> of the current buffer, then use the <code>gd</... | [
{
"answer_id": 28451,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 0,
"selected": false,
"text": "<p>What about</p>\n<pre><code>nmap <silent> <leader>gd :vsplit<cr><Plug>(coc-definition)zt\n</co... | 2020/12/16 | [
"https://vi.stackexchange.com/questions/28450",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29877/"
] | I'm using CoC and coc-python, and there is the `gd` mapping, which goes to the definition of a symbol. The mapping is defined as:
```
nmap <silent> gd <Plug>(doc-definition)
```
Now, I want to first do a `vsplit` of the current buffer, then use the `gd`, and then use the `zt` mapping.
I'm using the:
```
nmap <sile... | It seems the problem is that CoC is using an asynchronous action that doesn't take affect right at the point where the mapping is executed.
Looking at the CoC sources, I see there's a `CocAction()` counterpart to `CocActionAsync()`, so maybe you can use that to run the `gd` action synchronously.
Try the following:
`... |
28,470 | <p>Suppose I have <strong>several words</strong> on <strong>multiple lines</strong>:</p>
<pre><code>R
T_std
k_AB_IN
k_AB_ac
k_AB_co2
k_La
</code></pre>
<p>Now I want them to have them <strong>all on one line</strong>, only seperated by one whitespace.</p>
<pre><code>R T_std ... k_La
... | [
{
"answer_id": 28475,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>I think there’s a substitute command that works, but the first thing that comes to mind is</p>\n<pre><code>:%jo... | 2020/12/18 | [
"https://vi.stackexchange.com/questions/28470",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/32139/"
] | Suppose I have **several words** on **multiple lines**:
```
R
T_std
k_AB_IN
k_AB_ac
k_AB_co2
k_La
```
Now I want them to have them **all on one line**, only seperated by one whitespace.
```
R T_std ... k_La
```
So effectively, I need to **delete all line endings**. Maybe this c... | You can remove line endings by *joining* lines together. There are a few commands that can accomplish this, for instance the [`J`](https://vimhelp.org/change.txt.html#J) Normal-mode command will join the current line and the next, or you can use a count to join more than the two lines, or use `J` in Visual mode to join... |