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
25,943
<p>I have a multi-line string that I'm reading by:</p> <pre><code>let a = getreg('*') </code></pre> <p>What would be the best way to get the first line of that string? I was hoping I could do something like:</p> <ul> <li>match</li> <li>getbufline</li> </ul> <p>But am having trouble finding the necessary string func...
[ { "answer_id": 25918, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 2, "selected": false, "text": "<p>The idea of removing <code>://</code> from <code>'comments'</code> can be made to work, but instead of leaving Ins...
2020/06/14
[ "https://vi.stackexchange.com/questions/25943", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/28904/" ]
I have a multi-line string that I'm reading by: ``` let a = getreg('*') ``` What would be the best way to get the first line of that string? I was hoping I could do something like: * match * getbufline But am having trouble finding the necessary string function to do this. In python it'd be something like: `str.sp...
IMO, it's easier to do simply: ``` inoremap <expr><CR> getline('.') =~# '^\s*//' ? '<C-O>o' : '<CR>' ``` Perhaps, this mapping (with `<buffer>` modifier, of course) should be added to `after/ftplugin/c.vim` and not to the global `.vimrc`
25,955
<p>I have the following Python code</p> <pre><code>z=xyz%10 gvu.set_ticks(ax, xticks=[45, 50], yticks=[-25, -20, -15]) </code></pre> <p>After this substitution, in visual mode</p> <pre><code>:s/\([^=]\)\ *\(=\)\ *\([^=]\)/\1 \2 \3/g </code></pre> <p>the code becomes</p> <pre><code>z = xyz%10 gvu.set_...
[ { "answer_id": 25918, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 2, "selected": false, "text": "<p>The idea of removing <code>://</code> from <code>'comments'</code> can be made to work, but instead of leaving Ins...
2020/06/14
[ "https://vi.stackexchange.com/questions/25955", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/12991/" ]
I have the following Python code ``` z=xyz%10 gvu.set_ticks(ax, xticks=[45, 50], yticks=[-25, -20, -15]) ``` After this substitution, in visual mode ``` :s/\([^=]\)\ *\(=\)\ *\([^=]\)/\1 \2 \3/g ``` the code becomes ``` z = xyz%10 gvu.set_ticks(ax, xticks = [45, 50], yticks = [-25, -2...
IMO, it's easier to do simply: ``` inoremap <expr><CR> getline('.') =~# '^\s*//' ? '<C-O>o' : '<CR>' ``` Perhaps, this mapping (with `<buffer>` modifier, of course) should be added to `after/ftplugin/c.vim` and not to the global `.vimrc`
25,958
<h1>TL;DR</h1> <h2>What I Want:</h2> <p>JSON files to hide their double quotes (<code>"</code>) <em>until</em> I enter insert mode on a line, in which event the quotes reappear. I had this behavior on another machine, but I cannot replicate it on a new install of Arch (which I'm sure is not relevant, but context)</p>...
[ { "answer_id": 25918, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 2, "selected": false, "text": "<p>The idea of removing <code>://</code> from <code>'comments'</code> can be made to work, but instead of leaving Ins...
2020/06/14
[ "https://vi.stackexchange.com/questions/25958", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30094/" ]
TL;DR ===== What I Want: ------------ JSON files to hide their double quotes (`"`) *until* I enter insert mode on a line, in which event the quotes reappear. I had this behavior on another machine, but I cannot replicate it on a new install of Arch (which I'm sure is not relevant, but context) What's happening: ----...
IMO, it's easier to do simply: ``` inoremap <expr><CR> getline('.') =~# '^\s*//' ? '<C-O>o' : '<CR>' ``` Perhaps, this mapping (with `<buffer>` modifier, of course) should be added to `after/ftplugin/c.vim` and not to the global `.vimrc`
25,996
<p>I am trying to write register 0, into a file.</p> <p>One method that I have found is to use <code>redir</code>:</p> <pre><code>redir! /tmp/3 echo 'hello' redir end </code></pre> <p>which gives me error <code>invalid argument /tmp/3</code> and I don't know how to fix that.</p> <p>Another thing I have found is to...
[ { "answer_id": 25997, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 4, "selected": true, "text": "<p>Have you tried to obtain the register as a list instead? See <a href=\"http://vimhelp.appspot.com/eval.txt.html#getre...
2020/06/15
[ "https://vi.stackexchange.com/questions/25996", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/605/" ]
I am trying to write register 0, into a file. One method that I have found is to use `redir`: ``` redir! /tmp/3 echo 'hello' redir end ``` which gives me error `invalid argument /tmp/3` and I don't know how to fix that. Another thing I have found is to use `writefile`: ``` let g:the_buffer_raw = getreg("0") call...
Have you tried to obtain the register as a list instead? See [`:h getreg()`](http://vimhelp.appspot.com/eval.txt.html#getreg%28%29) ``` :call writefile(getreg('0', 1, 1), ....) ``` PS: temporary filenames are best obtained with [`tempname()`](http://vimhelp.appspot.com/eval.txt.html#tempname%28%29) Now, let's put t...
26,007
<p>I have <code>gx</code> which works with opening files. However, when I try and open a url, it always tries using <code>wget</code>:</p> <pre><code>[No write since last change] dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from: /usr/local/bin/wget Reason: image not found Co...
[ { "answer_id": 27803, "author": "joeytwiddle", "author_id": 630, "author_profile": "https://vi.stackexchange.com/users/630", "pm_score": 4, "selected": true, "text": "<h2>Quick solution (actually just a workaround)</h2>\n<p>On Linux, add the following to your <code>.vimrc</code> to overr...
2020/06/15
[ "https://vi.stackexchange.com/questions/26007", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/28904/" ]
I have `gx` which works with opening files. However, when I try and open a url, it always tries using `wget`: ``` [No write since last change] dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from: /usr/local/bin/wget Reason: image not found Command terminated ``` I am hoping t...
Quick solution (actually just a workaround) ------------------------------------------- On Linux, add the following to your `.vimrc` to override netrw's mapping and produce the desired behaviour: ``` nmap gx :silent execute "!xdg-open " . shellescape("<cWORD>")<CR> ``` You can replace `xdg-open` with your preferred...
26,013
<p>I have noticed that I can execute a command by yank, then <code>@"</code>. My question is how do I make enter work within the command?</p> <p>For example, when I yank <code>:w&lt;Enter&gt;</code>, I would like this command to be executed when I do<code>@"</code>. More generally, how do I do this for other keys, suc...
[ { "answer_id": 26023, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>You need to have the actual terminal code of <code>&lt;CR&gt;</code> in your yanked text instead of the literal characte...
2020/06/15
[ "https://vi.stackexchange.com/questions/26013", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/27083/" ]
I have noticed that I can execute a command by yank, then `@"`. My question is how do I make enter work within the command? For example, when I yank `:w<Enter>`, I would like this command to be executed when I do`@"`. More generally, how do I do this for other keys, such as `<Esc>, <Control>, etc`?
You need to have the actual terminal code of `<CR>` in your yanked text instead of the literal characters `<CR>`. To input the terminal code in insert mode you need to use `ctrl+v` and then the key you want to input, here `Enter`. See [`:h i_CTRL-V`](http://vimhelp.appspot.com/insert.txt.html#i_CTRL-V) So the text yo...
26,025
<p>I would like to enable Vim's clientserver support for the <a href="https://github.com/lervag/vimtex/blob/master/doc/vimtex.txt#L253" rel="nofollow noreferrer">vimtex call back mechanism</a>.</p> <blockquote> <p>&quot;Vim requires |+clientserver| in order to allow inverse search from the PDF viewer to Vim (see |vimte...
[ { "answer_id": 26026, "author": "Paul Rougieux", "author_id": 6671, "author_profile": "https://vi.stackexchange.com/users/6671", "pm_score": 2, "selected": false, "text": "<p>As explained in <a href=\"https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=114358\" rel=\"nofollow noreferrer\">...
2020/06/16
[ "https://vi.stackexchange.com/questions/26025", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6671/" ]
I would like to enable Vim's clientserver support for the [vimtex call back mechanism](https://github.com/lervag/vimtex/blob/master/doc/vimtex.txt#L253). > > "Vim requires |+clientserver| in order to allow inverse search from the PDF > viewer to Vim (see |vimtex-synctex-inverse-search|)." > > > I installed the fo...
As explained in [this 2004 bug report](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=114358): ``` sudo apt install vim-gtk ``` Adds +clientserver support to vim.
26,030
<p>I need to restructure a markdown table, and for that, I wish there was a quick way to &quot;join&quot; lines from a multi-line cell.</p> <p>So with Vim, I would have to yank the block (Ctrl-v), and then paste it <em>as a single line</em>.</p> <p>Is there a convenient key mapping for doing that?</p> <p><strong>Before...
[ { "answer_id": 26033, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>Here is one way to achieve what you want to do. I think another solution could be to use a macro but getting back at the...
2020/06/17
[ "https://vi.stackexchange.com/questions/26030", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9863/" ]
I need to restructure a markdown table, and for that, I wish there was a quick way to "join" lines from a multi-line cell. So with Vim, I would have to yank the block (Ctrl-v), and then paste it *as a single line*. Is there a convenient key mapping for doing that? **Before**: ``` chr6_66364 1.846 VNN3 ...
You can use [`setreg()`](https://vimhelp.org/eval.txt.html#setreg%28%29) to manipulate the contents of the register, after you delete into it from the visual block. Note that `setreg()` takes an optional third argument that you can use to set the "type" of the register, where you can pass `'c'` or `'v'` to make it a "c...
26,045
<p>I'm on Ubuntu 18.04, vim-gtk3 8.0.</p> <p>I'm trying to get gvim to highlight multiple lines of comment that starts with a particular word. For example, consider the word 'NOTE':</p> <pre><code>// NOTE(Ryan): This would be highlighted, // So would this line // And this line // This line would not be highlighted </c...
[ { "answer_id": 26033, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>Here is one way to achieve what you want to do. I think another solution could be to use a macro but getting back at the...
2020/06/18
[ "https://vi.stackexchange.com/questions/26045", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30120/" ]
I'm on Ubuntu 18.04, vim-gtk3 8.0. I'm trying to get gvim to highlight multiple lines of comment that starts with a particular word. For example, consider the word 'NOTE': ``` // NOTE(Ryan): This would be highlighted, // So would this line // And this line // This line would not be highlighted ``` My current attem...
You can use [`setreg()`](https://vimhelp.org/eval.txt.html#setreg%28%29) to manipulate the contents of the register, after you delete into it from the visual block. Note that `setreg()` takes an optional third argument that you can use to set the "type" of the register, where you can pass `'c'` or `'v'` to make it a "c...
26,047
<p>Is it possible to check if a normal mapping/command is being typed?</p> <p>That's also when the <code>showcmd</code> setting takes effect.</p> <p>I can't seem to find anything about this in the doc, no autocmd-event nor related functions.</p> <p>The idea would be to make it more obvious that Vim is waiting for more ...
[ { "answer_id": 26064, "author": "user938271", "author_id": 17449, "author_profile": "https://vi.stackexchange.com/users/17449", "pm_score": 3, "selected": true, "text": "<blockquote>\n<p>The idea would be to make it more obvious that Vim is waiting for more input by, for example, changin...
2020/06/18
[ "https://vi.stackexchange.com/questions/26047", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/22375/" ]
Is it possible to check if a normal mapping/command is being typed? That's also when the `showcmd` setting takes effect. I can't seem to find anything about this in the doc, no autocmd-event nor related functions. The idea would be to make it more obvious that Vim is waiting for more input by, for example, changing ...
> > The idea would be to make it more obvious that Vim is waiting for more input by, for example, changing the cursorline color. > > > You could try to leverage the fact that when a mapping is being executed, the output of `state()` should contain the `m` flag, and in operator-pending mode it should contain the `o...
26,048
<p>I have my fuzzy file finder in Vim and it does a pretty good job. But it always opens the file in the current tab. I want my <code>:find</code> to open the resulting file in a new tab.</p> <p>I know I can <code>:tabnew &lt;file&gt;</code> but I need to write the complete file path here to open the file. So how do I ...
[ { "answer_id": 26064, "author": "user938271", "author_id": 17449, "author_profile": "https://vi.stackexchange.com/users/17449", "pm_score": 3, "selected": true, "text": "<blockquote>\n<p>The idea would be to make it more obvious that Vim is waiting for more input by, for example, changin...
2020/06/18
[ "https://vi.stackexchange.com/questions/26048", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30150/" ]
I have my fuzzy file finder in Vim and it does a pretty good job. But it always opens the file in the current tab. I want my `:find` to open the resulting file in a new tab. I know I can `:tabnew <file>` but I need to write the complete file path here to open the file. So how do I do that?
> > The idea would be to make it more obvious that Vim is waiting for more input by, for example, changing the cursorline color. > > > You could try to leverage the fact that when a mapping is being executed, the output of `state()` should contain the `m` flag, and in operator-pending mode it should contain the `o...
26,050
<p>I'm using vim with some plugins, such as Nerdtree, YCM, to build an coding environment.</p> <p>Now I want to achieve this:</p> <p>When I execute the command <code>vim</code>, a file containing some ASCII image, will be loaded automatically.</p> <p>Well, this is only for good looking.</p> <p>What I've done is to add ...
[ { "answer_id": 26051, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 1, "selected": false, "text": "<p>You will need to add to your vimrc an autocommand which will be executed every time you read the file and will be used t...
2020/06/18
[ "https://vi.stackexchange.com/questions/26050", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10003/" ]
I'm using vim with some plugins, such as Nerdtree, YCM, to build an coding environment. Now I want to achieve this: When I execute the command `vim`, a file containing some ASCII image, will be loaded automatically. Well, this is only for good looking. What I've done is to add a line in the file `~/.bashrc`: `alias...
An alternate method is to modify your alias (I prefer functions, so I’ll show both): ``` # alias alias vim='vim +"setlocal readonly" ascii' # function vim () { command vim +'setlocal readonly' ascii "$@" } ``` The issue here is I’m not sure if vim is ok with options/flags that come *after* the first file argument...
26,052
<p>I know that * selects the word under the cursor, but what if I want to actually select a WORD ?</p> <p>Just to be clear, I would then like to use the selection for a replace, something like <code>:%s//foo/g</code></p>
[ { "answer_id": 26053, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>You are looking for the help topic <a href=\"http://vimhelp.appspot.com/cmdline.txt.html#%3ccWORD%3e\" rel=\"noreferrer\...
2020/06/18
[ "https://vi.stackexchange.com/questions/26052", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30107/" ]
I know that \* selects the word under the cursor, but what if I want to actually select a WORD ? Just to be clear, I would then like to use the selection for a replace, something like `:%s//foo/g`
> > I would then like to use the selection for a replace, something like :%s//foo/g > > > ``` :%s/^R^A/foo/g ``` See `:h c_CTRL-R_CTRL-A`
26,067
<p>I want to search for a keyword, and replace a word in the line that is not a search word. I thought macros may be a good way to do it, but I am open to any methods.</p> <p>I have something like,</p> <pre><code>blah blah check abc = 9 blah check def VS 10 check hi and j = 20 </code></pre> <p>when I have &quot;ch...
[ { "answer_id": 26069, "author": "user985675", "author_id": 5220, "author_profile": "https://vi.stackexchange.com/users/5220", "pm_score": 0, "selected": false, "text": "<pre><code>:%s/^\\(\\s*check[^=]\\+\\)=\\(.*\\)/\\1VS\\2/\n</code></pre>\n<p>transforms your sample data to</p>\n<pre><...
2020/06/18
[ "https://vi.stackexchange.com/questions/26067", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23342/" ]
I want to search for a keyword, and replace a word in the line that is not a search word. I thought macros may be a good way to do it, but I am open to any methods. I have something like, ``` blah blah check abc = 9 blah check def VS 10 check hi and j = 20 ``` when I have "check", I want to replace the = a few...
I would combine it with the `:g` command: ``` :g/^\s*check\>/s/=/VS/ ``` This selects all lines that has a "check" as the first word and then executes `s/=/VS/` on this line. This will replace the first `=` with `VS`. You can also use the substitution flags `gc` if you like to replase all equal signs and want to co...
26,081
<p>Recently I learned the awesome command <code>cgn</code> to repeat a change to a word. I’ve seen several answers advising its use, like this:</p> <p><a href="https://vi.stackexchange.com/questions/8285/what-is-the-best-way-to-re-factor-a-variable-name-in-vim/8288#8288">What is the best way to re-factor a variable nam...
[ { "answer_id": 26093, "author": "Nelson Teixeira", "author_id": 5944, "author_profile": "https://vi.stackexchange.com/users/5944", "pm_score": 0, "selected": false, "text": "<p>A user in a Telegram group dedicated to VIM showed me a very good solution:</p>\n<pre><code>:nnoremap &lt;leade...
2020/06/19
[ "https://vi.stackexchange.com/questions/26081", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5944/" ]
Recently I learned the awesome command `cgn` to repeat a change to a word. I’ve seen several answers advising its use, like this: [What is the best way to re-factor a variable name in vim?](https://vi.stackexchange.com/questions/8285/what-is-the-best-way-to-re-factor-a-variable-name-in-vim/8288#8288) and this: [How ...
> > How can I repeat cgn a number of times ? > > > Try this mapping: ``` nno <expr> <leader>. '<esc>' . repeat('.', v:count1) ``` The purpose of `<esc>` is to cancel the count. For example, if you press: ``` 3 <leader>. ``` in the typeahead buffer, `<leader>.` is expanded into `...`, and the resulting sequen...
26,084
<p>I use <code>vim -o a*</code> to open 25 files (filenames starting with 'a') together and search &amp; replace (<code>:windo %s/old/new/gcI</code>) some common word in these files. Later I found that not all of them have been modified and it seems to be due to that <code>vim -o</code> opens only 23 of them. However, ...
[ { "answer_id": 26089, "author": "Biggybi", "author_id": 22375, "author_profile": "https://vi.stackexchange.com/users/22375", "pm_score": 2, "selected": false, "text": "<p>When opening multiple files, Vim will only create as many windows as it can display, and load the rest without displa...
2020/06/19
[ "https://vi.stackexchange.com/questions/26084", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6396/" ]
I use `vim -o a*` to open 25 files (filenames starting with 'a') together and search & replace (`:windo %s/old/new/gcI`) some common word in these files. Later I found that not all of them have been modified and it seems to be due to that `vim -o` opens only 23 of them. However, `vim -O a*` can open all 25 files. So i...
In a slightly different take, vim also preserves the files given it on the command-line in an argument list (colloquially: `:args`). When you use `:next`/`:prev`, you traverse that list. You can change, add to, and operate further on that list with many functions/commands (see the help). Of particular note is `:argdo`...
26,088
<p>Whenever I press <code>&lt;&lt;</code> or <code>&gt;&gt;</code> in insert or normal mode, I lose the cursor position, as it always goes back to the start of the line. Is there a setting to fix this?</p> <p>Here is where I am right now, but am having some trouble figuring out why the below isn't working in normal mod...
[ { "answer_id": 26091, "author": "David542", "author_id": 28904, "author_profile": "https://vi.stackexchange.com/users/28904", "pm_score": 0, "selected": false, "text": "<p>I'm sure this is overkill, but this is what I end up doing to 'keep the cursor position' when in insert and normal m...
2020/06/20
[ "https://vi.stackexchange.com/questions/26088", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/28904/" ]
Whenever I press `<<` or `>>` in insert or normal mode, I lose the cursor position, as it always goes back to the start of the line. Is there a setting to fix this? Here is where I am right now, but am having some trouble figuring out why the below isn't working in normal mode: ``` inoremap <leader>] <C-...
The option is called `set nostartofline`. However, it's a global which affects many(!) other commands in Vim and I'd rather *not* suggest to use it.
26,099
<p>I want to open three files <code>file1.txt</code> <code>file2.txt</code> <code>file3.txt</code> in vertical and horizontal split combination, like this:</p> <pre><code>+-------------------------------+ | | | | file1.txt | | | | file3.txt | | ...
[ { "answer_id": 26100, "author": "Ralf", "author_id": 19763, "author_profile": "https://vi.stackexchange.com/users/19763", "pm_score": 4, "selected": true, "text": "<p>You could try it like this:</p>\n<pre><code>vim -c &quot;lefta vsplit file2.txt|split file1.txt&quot; file3.txt\n</code><...
2020/06/20
[ "https://vi.stackexchange.com/questions/26099", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13715/" ]
I want to open three files `file1.txt` `file2.txt` `file3.txt` in vertical and horizontal split combination, like this: ``` +-------------------------------+ | | | | file1.txt | | | | file3.txt | | | | | | ...
You could try it like this: ``` vim -c "lefta vsplit file2.txt|split file1.txt" file3.txt ``` With the option `-c` you can specify commands that should be executed after the first file was loaded. So here: 1. The file `file3.txt` is loaded. 2. The command `lefta vsplit file2.txt|split file1.txt` is executed. This ...
26,113
<p>I would like to set an autocommand that automatically resources the file whenever I save it, as now I am doing something like:</p> <pre><code>:w | so % </code></pre> <p>Whenever I save something.</p> <p>What would be the correct 'event' to do this with? For example:</p> <pre><code>augroup uncompress au! au (...
[ { "answer_id": 26125, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 2, "selected": false, "text": "<p><code>BufWritePost</code> is the event you typically want. It needs to be a <code>Post</code> event because you wa...
2020/06/20
[ "https://vi.stackexchange.com/questions/26113", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/28904/" ]
I would like to set an autocommand that automatically resources the file whenever I save it, as now I am doing something like: ``` :w | so % ``` Whenever I save something. What would be the correct 'event' to do this with? For example: ``` augroup uncompress au! au (BufWritePre? BufWritePost? BufWrite? Buf...
`BufWritePost` is the event you typically want. It needs to be a `Post` event because you want to source the contents of the file *after* they've been saved. It's conceivable you might also want to cover `FileWritePost`, in case you want to also source a `*.vim` file when you write it through an operation taking a ran...
26,114
<p>What is the difference between doing <code>:% [...]</code> and <code>:g [...]</code>. Does g require a regex to filter out what lines to apply to, or does it apply to all lines if no regex is given? For example:</p> <p>To insert a <code>&quot;</code> at the beginning of every line:</p> <pre><code>:% normal!I&quot; <...
[ { "answer_id": 26125, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 2, "selected": false, "text": "<p><code>BufWritePost</code> is the event you typically want. It needs to be a <code>Post</code> event because you wa...
2020/06/20
[ "https://vi.stackexchange.com/questions/26114", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/28904/" ]
What is the difference between doing `:% [...]` and `:g [...]`. Does g require a regex to filter out what lines to apply to, or does it apply to all lines if no regex is given? For example: To insert a `"` at the beginning of every line: ``` :% normal!I" ``` I'm guessing the equivalent `g` command would be: ``` :g...
`BufWritePost` is the event you typically want. It needs to be a `Post` event because you want to source the contents of the file *after* they've been saved. It's conceivable you might also want to cover `FileWritePost`, in case you want to also source a `*.vim` file when you write it through an operation taking a ran...
26,123
<p>Is it possible to enable <code>hlsearch</code> when running a search (<code>/</code>) but not on <code>:</code> commands? For example, sometimes when doing a replace (on a very narrow range of text) it get distracting when I have a bunch of other lines highlighted, for example:</p> <p><a href="https://i.stack.imgur....
[ { "answer_id": 26128, "author": "Ralf", "author_id": 19763, "author_profile": "https://vi.stackexchange.com/users/19763", "pm_score": 1, "selected": false, "text": "<p>I don't think there is a way out of the box. <code>hlsearch</code> works with the search register (<code>:h &quot;/</cod...
2020/06/21
[ "https://vi.stackexchange.com/questions/26123", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/28904/" ]
Is it possible to enable `hlsearch` when running a search (`/`) but not on `:` commands? For example, sometimes when doing a replace (on a very narrow range of text) it get distracting when I have a bunch of other lines highlighted, for example: [![enter image description here](https://i.stack.imgur.com/v6oIy.png)](ht...
You can use the following autocommands to enable hlsearch only when using the / and ? (search) commands: ``` " Enable highlighting all the matches in incsearch mode " But don't enable hlsearch always augroup vimrc-incsearch-highlight autocmd! autocmd CmdlineEnter [/\?] :set hlsearch autocmd CmdlineLeave [/\?] :s...
26,126
<p>I have the following in my <code>vimrc</code> file:</p> <pre><code>:set formatoptions-=cro </code></pre> <p>However, when I load the <code>vimrc</code> from scratch (i.e., open a new terminal session and start vim with it), it seems to be overwritten somewhere:</p> <p><a href="https://i.stack.imgur.com/TWZzM.png" re...
[ { "answer_id": 26129, "author": "Ralf", "author_id": 19763, "author_profile": "https://vi.stackexchange.com/users/19763", "pm_score": 1, "selected": false, "text": "<p>Use <code>:verbose</code> like:</p>\n<pre><code>:verbose set formatoptions?\n</code></pre>\n<p>See <code>:h :verbose</co...
2020/06/21
[ "https://vi.stackexchange.com/questions/26126", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/28904/" ]
I have the following in my `vimrc` file: ``` :set formatoptions-=cro ``` However, when I load the `vimrc` from scratch (i.e., open a new terminal session and start vim with it), it seems to be overwritten somewhere: [![enter image description here](https://i.stack.imgur.com/TWZzM.png)](https://i.stack.imgur.com/TWZ...
Reading `:h 'formatoptions'` reveals that it's "*local to buffer*". This means that every buffer has a value of `formatoptions` of its own. Setting it in "vimrc" can only provide a default value. But the problem is that the defaults may be overwritten by standard ftplugin (`:h ftplugin`, `:h :filetype` etc.) which pro...
26,151
<p>I'd like to use Ex mode <code>:g/pattern/d</code> to delete most (but not all) of the rows containing <code>pattern</code>, but I want to see each one first and confirm before deleting, similar to <code>:s/pattern/foo/gc</code>. Is there a way to do this, in Ex mode or otherwise?</p>
[ { "answer_id": 26152, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 4, "selected": true, "text": "<p>One way to achieve what you want to do is to use the <code>:s</code> command inside your <code>:g</code> command:</p>\n<p...
2020/06/22
[ "https://vi.stackexchange.com/questions/26151", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/26984/" ]
I'd like to use Ex mode `:g/pattern/d` to delete most (but not all) of the rows containing `pattern`, but I want to see each one first and confirm before deleting, similar to `:s/pattern/foo/gc`. Is there a way to do this, in Ex mode or otherwise?
One way to achieve what you want to do is to use the `:s` command inside your `:g` command: We know that we can delete a line, with a confirmation using the following substitution: ``` :s/.*\n//c ``` This will replace all the characters (`.*`) *and* the next end of line character (`\n`) with nothing, effectively de...
26,166
<p>My workflow is to perform data analysis in R markdown files. They are a mix of text and code chunks, pretty much like jupyter notebooks for python. These files can get long with time and I like to open a buffer with a table of content to navigate between the various headers of the document. I was very happy to use t...
[ { "answer_id": 26175, "author": "Paul Rougieux", "author_id": 6671, "author_profile": "https://vi.stackexchange.com/users/6671", "pm_score": 1, "selected": true, "text": "<p>Voom can create a table of content for R markdown files if you associate that file type to pandoc in the vim confi...
2020/06/23
[ "https://vi.stackexchange.com/questions/26166", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6671/" ]
My workflow is to perform data analysis in R markdown files. They are a mix of text and code chunks, pretty much like jupyter notebooks for python. These files can get long with time and I like to open a buffer with a table of content to navigate between the various headers of the document. I was very happy to use the ...
Voom can create a table of content for R markdown files if you associate that file type to pandoc in the vim configuration file: ``` let voom_ft_modes = {'markdown': 'pandoc', 'rmd': 'pandoc'} ``` Then you can also add another name for the command: ``` au BufRead,BufNewFile *.Rmd command! Toc Voom ``` Calling `:T...
26,189
<p>I have a code like this:</p> <pre><code> h5 style=(&quot;text-align: center; margin-top: 2rem;&quot;) some text p style=(&quot;text-align: center; margin-top: 2rem;&quot;) some text </code></pre> <p>And in first line, I want to delete <code> margin-top: 2rem;</code>, so the result will look like this:</p> <pre><cod...
[ { "answer_id": 26191, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 2, "selected": false, "text": "<p>You can use the <a href=\"https://vimhelp.org/motion.txt.html#f\" rel=\"nofollow noreferrer\"><code>f</code></a> or <a href=...
2020/06/24
[ "https://vi.stackexchange.com/questions/26189", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25356/" ]
I have a code like this: ``` h5 style=("text-align: center; margin-top: 2rem;") some text p style=("text-align: center; margin-top: 2rem;") some text ``` And in first line, I want to delete `margin-top: 2rem;`, so the result will look like this: ``` h5 style=("text-align: center;") some text p style=("text-align:...
There's indeed more straight-forward ways to do this. As you can see in the help for `:h d` ``` *d* ["x]d{motion} Delete text that {motion} moves over [into register x]. See below for exceptions. ``` The `delete` command, as many, accepts a motion. This means you can t...
26,209
<p>Suppose I have mapped the following function:</p> <pre><code>noremap &lt;C-F12&gt; :! bash -c &quot;\ git rev-parse --show-toplevel \ | xargs -I {} \ ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q {}&quot; \ &lt;CR&gt; </code></pre> <p>No matter how I nest it, it seems as if VIM will not run the fu...
[ { "answer_id": 26210, "author": "Ralf", "author_id": 19763, "author_profile": "https://vi.stackexchange.com/users/19763", "pm_score": 2, "selected": false, "text": "<p>In Vim line continuation is done with a backslash on the new line.\nLike:</p>\n<pre><code>noremap &lt;C-F12&gt; :!bash -...
2020/06/26
[ "https://vi.stackexchange.com/questions/26209", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/15729/" ]
Suppose I have mapped the following function: ``` noremap <C-F12> :! bash -c "\ git rev-parse --show-toplevel \ | xargs -I {} \ ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q {}" \ <CR> ``` No matter how I nest it, it seems as if VIM will not run the function. I suspect a possible solution in the f...
**Minimal Verifiable Solution** `|` is a vim character, and must be escaped. ``` noremap ~~ :! \bash -c "git rev-parse --show-toplevel \\| xargs -I {} \ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q {}"<CR> ``` Note: the following will work as well ``` noremap ~~ :! \bash -c "git rev-parse --show-t...
26,217
<p>I have two functions <code>tex#PDFOpen()</code> and <code>tex#PDFClose()</code> to automatically open and close the pdf file created by a TeX document.</p> <p>The way I assign them to autocommands is via the following autogroup in <code>~/.config/nvim/ftplugin/tex.vim</code></p> <pre><code>augroup TeXGroup autocmd...
[ { "answer_id": 26226, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 0, "selected": false, "text": "<p>My recommendation is that you use <code>BufRead</code> to open the PDF and <code>BufDelete</code> to close it.</p>...
2020/06/26
[ "https://vi.stackexchange.com/questions/26217", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/26480/" ]
I have two functions `tex#PDFOpen()` and `tex#PDFClose()` to automatically open and close the pdf file created by a TeX document. The way I assign them to autocommands is via the following autogroup in `~/.config/nvim/ftplugin/tex.vim` ``` augroup TeXGroup autocmd BufEnter <buffer> call tex#PDFOpen() autocmd BufU...
I see that for some reason people like to use `:bdelete` to close buffers. That's a very strange practice, IMO. Let's recall what is that `:bdelete` all about. A buffer in Vim can 1) exist (`bufexists()` returns true); 2) be "loaded" (`bufloaded()` returns true), and 3) be "listed" (`buflisted()` returns true). Please...
26,230
<p>To get the most recent command I can do:</p> <pre><code>:&lt;ctrl-p&gt; </code></pre> <p>Or:</p> <pre><code>:&lt;up&gt; </code></pre> <p>However, this will also show commands that might have been typed in, but weren't run, for example, I may recently typed in:</p> <pre><code>:call TypoFuNCt </code></pre> <p>But not ...
[ { "answer_id": 26231, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 3, "selected": true, "text": "<p>The last typed &amp; executed command is stored in the &quot;colon&quot;-register (<code>:h quote:</code>). You can input...
2020/06/27
[ "https://vi.stackexchange.com/questions/26230", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/28904/" ]
To get the most recent command I can do: ``` :<ctrl-p> ``` Or: ``` :<up> ``` However, this will also show commands that might have been typed in, but weren't run, for example, I may recently typed in: ``` :call TypoFuNCt ``` But not actually executed it. And then if I go back and press us, it will fill in that...
The last typed & executed command is stored in the "colon"-register (`:h quote:`). You can input its value while editing the command-line by pressing `Ctrl-R``:` (`:h c_CTRL-R`). Or you can just re-run this command by typing `:@:` in the command-line.
26,251
<p>Occasionally, I need to type documents in Russian in LaTeX format. To use Russian in vim I follow the guidelines from this <a href="https://habr.com/ru/post/98393/" rel="nofollow noreferrer">Habr post</a>. In short, I have the following settings in my <code>.vimrc</code> file:</p> <pre><code>set keymap=russian-jcuke...
[ { "answer_id": 26257, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 3, "selected": true, "text": "<h2>1. Try to replicate issue with clean vim</h2>\n<ol>\n<li><code>vim --clean</code></li>\n<li><code>:set keymap=russian...
2020/06/28
[ "https://vi.stackexchange.com/questions/26251", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/27546/" ]
Occasionally, I need to type documents in Russian in LaTeX format. To use Russian in vim I follow the guidelines from this [Habr post](https://habr.com/ru/post/98393/). In short, I have the following settings in my `.vimrc` file: ``` set keymap=russian-jcukenmac set iminsert=0 set imsearch=0 highlight lCursor guifg=NO...
1. Try to replicate issue with clean vim ---------------------------------------- 1. `vim --clean` 2. `:set keymap=russian-jcukenmac` If you are able to enter letter ю, something is wrong with your vimrc 2. Check what is in your keymap file ------------------------------------ Open `:e $VIMRUNTIME/keymap/russian-jc...
26,253
<p>I have a shortcut -- <kbd>⌘</kbd><kbd>s</kbd> to save a file. If it's not a vim file it will just run a <code>:w</code>, and if it hasn't been saved to a file yet it will ask the user for a filepath or name. However, if it's a vim file, I want it to do <code>:w | so %</code>. However, I'm having trouble sourcing a f...
[ { "answer_id": 26256, "author": "David542", "author_id": 28904, "author_profile": "https://vi.stackexchange.com/users/28904", "pm_score": 0, "selected": false, "text": "<p>If you are running this within an <code>&lt;expr&gt;</code> you have to escape the <code>|</code> in the command. It...
2020/06/28
[ "https://vi.stackexchange.com/questions/26253", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/28904/" ]
I have a shortcut -- `⌘``s` to save a file. If it's not a vim file it will just run a `:w`, and if it hasn't been saved to a file yet it will ask the user for a filepath or name. However, if it's a vim file, I want it to do `:w | so %`. However, I'm having trouble sourcing a file from within a function. Here is what I ...
Why don't you do the test in your function? My experience is that the less code there is in the declaration of mappings, autocommands, commands, abbreviations... the less troubles we have. ``` function s:SaveFile() abort " If the filename doesn't exist, prompt the use to enter one if empty(expand('%')) ...
26,292
<p><code>&lt;C-x&gt;&lt;C-o&gt;</code> returns <code>Pattern not found</code> in C/C++ files even with a ctags file.</p> <ul> <li>It used to work and I haven't made any configuration/plugin changes that I know of</li> <li>Starting vim with <code>vim -u NONE -U NONE</code> and manually setting <code>omnifunc=ccomplete#C...
[ { "answer_id": 26298, "author": "hopibel", "author_id": 30371, "author_profile": "https://vi.stackexchange.com/users/30371", "pm_score": 0, "selected": false, "text": "<p>In the end I just gave up and installed the clang-complete plugin, which just worked without any fuss. I get the feel...
2020/07/01
[ "https://vi.stackexchange.com/questions/26292", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30371/" ]
`<C-x><C-o>` returns `Pattern not found` in C/C++ files even with a ctags file. * It used to work and I haven't made any configuration/plugin changes that I know of * Starting vim with `vim -u NONE -U NONE` and manually setting `omnifunc=ccomplete#Complete` results in the same problem (as does `vim --clean`), so it do...
This is an old question, but since it is getting bumped without an answer, I will provide an explanation anyway. The reason `<C-x><C-o>` (omni-completion) returns "Pattern not found" can be found in the documentation: ``` CTRL-X CTRL-O Guess what kind of item is in front of the cursor and ...
26,293
<p>When I search for something <code>/search-term</code> and it shows up more than 100 times in my file, vim shows me that I'm on match <code>x/&gt;99</code> instead of <code>x/121</code> etc.</p> <p>For smaller numbers it shows me the exact number of total matches: <code>10/23</code>, but with more than 99 total match...
[ { "answer_id": 26294, "author": "Biggybi", "author_id": 22375, "author_profile": "https://vi.stackexchange.com/users/22375", "pm_score": 2, "selected": false, "text": "<p>I use <a href=\"https://github.com/osyo-manga/vim-anzu\" rel=\"nofollow noreferrer\">Anzu</a> which counts up to 1000...
2020/07/01
[ "https://vi.stackexchange.com/questions/26293", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9024/" ]
When I search for something `/search-term` and it shows up more than 100 times in my file, vim shows me that I'm on match `x/>99` instead of `x/121` etc. For smaller numbers it shows me the exact number of total matches: `10/23`, but with more than 99 total matches it doesn't show the exact number of matches anymore. ...
I assume you are talking of the built-in search counter here [![enter image description here](https://i.stack.imgur.com/FLScE.png)](https://i.stack.imgur.com/FLScE.png) First for users who don't know, this search counter is controlled by the `S` flag in `shortmess` [`:h 'shortmess'`](http://vimhelp.appspot.com/options...
26,299
<p>Imagine I have a file as follows,</p> <pre><code>10 10 10 11 ... 10 20 20 20 20 21 ... 20 40 40 40 40 41 ... </code></pre> <p>I know simple regex such as</p> <p>To search two numbers</p> <pre><code>/\d\+ \d\+ </code></pre> <p>To search repeated numbers</p> <pre><code>/\(\d\+\) \1 </code></pre> <p>My question is what...
[ { "answer_id": 26294, "author": "Biggybi", "author_id": 22375, "author_profile": "https://vi.stackexchange.com/users/22375", "pm_score": 2, "selected": false, "text": "<p>I use <a href=\"https://github.com/osyo-manga/vim-anzu\" rel=\"nofollow noreferrer\">Anzu</a> which counts up to 1000...
2020/07/01
[ "https://vi.stackexchange.com/questions/26299", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/20720/" ]
Imagine I have a file as follows, ``` 10 10 10 11 ... 10 20 20 20 20 21 ... 20 40 40 40 40 41 ... ``` I know simple regex such as To search two numbers ``` /\d\+ \d\+ ``` To search repeated numbers ``` /\(\d\+\) \1 ``` My question is what is regex pattern such that I can search ``` 10 20 20 40 40 80 ... ```...
I assume you are talking of the built-in search counter here [![enter image description here](https://i.stack.imgur.com/FLScE.png)](https://i.stack.imgur.com/FLScE.png) First for users who don't know, this search counter is controlled by the `S` flag in `shortmess` [`:h 'shortmess'`](http://vimhelp.appspot.com/options...
26,325
<p>Is it possible to send a command to vim from the command-line? For example, to open the last file something like:</p> <pre><code>$ vim -e &quot;`0&quot; # execute `0 after opening vim </code></pre> <p>Or, if I need to run a command, then:</p> <pre><code>$ vim -r &quot;:normal!`0&quot; </code></pre> <p>Is it pos...
[ { "answer_id": 26326, "author": "David542", "author_id": 28904, "author_profile": "https://vi.stackexchange.com/users/28904", "pm_score": 2, "selected": false, "text": "<p>You can use the <code>-c</code> option:</p>\n<blockquote>\n<p>-c {command} -- {command} will be executed after the f...
2020/07/03
[ "https://vi.stackexchange.com/questions/26325", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/28904/" ]
Is it possible to send a command to vim from the command-line? For example, to open the last file something like: ``` $ vim -e "`0" # execute `0 after opening vim ``` Or, if I need to run a command, then: ``` $ vim -r ":normal!`0" ``` Is it possible to do this from the command-line before entering vim? When ...
Most concise: ``` $ vim +'norm! `0' ``` In Bash, [single quotes](https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html) imply that their contents will not be expanded. Since [backquotes](https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html) imply that their contents will be ev...
26,340
<p>I have a <code>vim colorscheme</code> <a href="https://github.com/rudrab/vim-coogle" rel="nofollow noreferrer">vim-coogle</a>, which uses both hex value and named colors already defined in vim, like:</p> <pre><code>hi Comment guifg=#FFF59D ctermfg=lightgrey </code></pre> <p>Now, the problem is, I want do define my...
[ { "answer_id": 26342, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 1, "selected": false, "text": "<p>As far as I know the the finest granularity of any color element that can be modified in Vim is the &quot;highlight g...
2020/07/05
[ "https://vi.stackexchange.com/questions/26340", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2738/" ]
I have a `vim colorscheme` [vim-coogle](https://github.com/rudrab/vim-coogle), which uses both hex value and named colors already defined in vim, like: ``` hi Comment guifg=#FFF59D ctermfg=lightgrey ``` Now, the problem is, I want do define my own colors, eg, like: ``` let yellow2="#FFF59D" hi Comment guifg=yell...
You could use `:execute`— ``` execute printf('highlight Comment guifg=%s', yellow2) ```
26,366
<p>In a script, I want to delete a rectangular block of text. For example, I want to convert this:</p> <pre><code>ABCD EFGH IJKL MNOP </code></pre> <p>into this:</p> <pre><code>ABCD EH IL MNOP </code></pre> <p>One way to do this is with visual block mode. Move the cursor to &quot;F&quot;, enter visual block mode with ...
[ { "answer_id": 26342, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 1, "selected": false, "text": "<p>As far as I know the the finest granularity of any color element that can be modified in Vim is the &quot;highlight g...
2020/07/08
[ "https://vi.stackexchange.com/questions/26366", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5439/" ]
In a script, I want to delete a rectangular block of text. For example, I want to convert this: ``` ABCD EFGH IJKL MNOP ``` into this: ``` ABCD EH IL MNOP ``` One way to do this is with visual block mode. Move the cursor to "F", enter visual block mode with `Ctrl`+`V`, move the cursor to "K", and press `d`. How...
You could use `:execute`— ``` execute printf('highlight Comment guifg=%s', yellow2) ```
26,371
<p>My vimrc holds a script to change the color of the CursorLineNr conditionally based on the mode. My problem is that it hides vim's welcome message when it's launched without a file. I would like to keep the message.</p> <p>The culprit lines are the first two &quot;exe&quot; commands.</p> <pre><code>let g:mode_marker...
[ { "answer_id": 28932, "author": "Biggybi", "author_id": 22375, "author_profile": "https://vi.stackexchange.com/users/22375", "pm_score": 0, "selected": false, "text": "<p>Serendipity taught me that Vim holds a command to display the greeting message on demand: <code>:intro</code>.</p>\n<...
2020/07/08
[ "https://vi.stackexchange.com/questions/26371", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/22375/" ]
My vimrc holds a script to change the color of the CursorLineNr conditionally based on the mode. My problem is that it hides vim's welcome message when it's launched without a file. I would like to keep the message. The culprit lines are the first two "exe" commands. ``` let g:mode_marker_group = "CursorLineNr" let g...
You should be able to instantiate the timer inside InsertEnter. This will prevent the timer firing at an inopportune time (such as when the intro screen is shown). In fact, it is probably a better design to have a "one shot" timer anyway, since it will not require the timer to be constantly firing. Plugins that do thi...
26,380
<p>I have a series of single-word codes on separate lines in a text file. I'd like to add a backquote ( <code>`</code> ) to the beginning and end of each word.</p> <p>I know I can add a backquote to the beginning of each line with relative ease: <code>Ctrl-v</code> --&gt; <code>Shift-I</code>. How do I insert text afte...
[ { "answer_id": 26381, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 3, "selected": false, "text": "<p>You can use the <a href=\"https://vimhelp.org/various.txt.html#%3Anormal\" rel=\"noreferrer\"><code>:normal</code>...
2020/07/09
[ "https://vi.stackexchange.com/questions/26380", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30146/" ]
I have a series of single-word codes on separate lines in a text file. I'd like to add a backquote ( ``` ) to the beginning and end of each word. I know I can add a backquote to the beginning of each line with relative ease: `Ctrl-v` --> `Shift-I`. How do I insert text after the first word on each line?
You can also use ``` :%s/\w\+/`&` ``` to convert from ``` Lorem ipsum dolor sit amet ``` to ``` `Lorem` `ipsum` `dolor` `sit` `amet` ``` * `:%` range to the next command (whole buffer) * `s` is a substitute command `:s/regexWhat/substituteValue` without range will substitute on a current line. * `\w\+` is a re...
26,382
<p>I have a plugin (c.vim) which includes a lot of maps (all with leader key). I changed my leader key to space, which I like, but the problem is that the maps also apply to insert mode. I would like to disable all imaps containing <code>&lt;Space&gt;</code>, so space in insert doesn't cause a delay (and sometimes a co...
[ { "answer_id": 26384, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 3, "selected": true, "text": "<p>If your insert mode mappings are filetype specific then <code>.vim/after/plugin/map.vim</code> and <code>autocmd VimEn...
2020/07/09
[ "https://vi.stackexchange.com/questions/26382", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30475/" ]
I have a plugin (c.vim) which includes a lot of maps (all with leader key). I changed my leader key to space, which I like, but the problem is that the maps also apply to insert mode. I would like to disable all imaps containing `<Space>`, so space in insert doesn't cause a delay (and sometimes a command). I tried `:i...
If your insert mode mappings are filetype specific then `.vim/after/plugin/map.vim` and `autocmd VimEnter * imapclear` would not work as they are executed before fitetype creates them. Also `imapclear` deletes all insert mode mappings including default ones. You can try to apply `imapclear <buffer>` on bufread/filetyp...
26,409
<p>Consider the following constant definition:</p> <pre><code>define(&quot;_TBL_USERS&quot;,&quot;users&quot;); </code></pre> <p>Now, I want to transform it into:</p> <pre><code>define(&quot;_TBL_USER_ITEMS&quot;,&quot;user_items&quot;); </code></pre> <p>I tried the command:</p> <pre><code>s/\(user\)s\?/\1_items/gi </c...
[ { "answer_id": 26410, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>It's possible to do this with one substitution command but it's a bit hairy and you might want to just use two substi...
2020/07/11
[ "https://vi.stackexchange.com/questions/26409", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25325/" ]
Consider the following constant definition: ``` define("_TBL_USERS","users"); ``` Now, I want to transform it into: ``` define("_TBL_USER_ITEMS","user_items"); ``` I tried the command: ``` s/\(user\)s\?/\1_items/gi ``` And the result is: ``` define("_TBL_USER_items","user_items"); ``` Is there a way to use ...
It's possible to do this with one substitution command but it's a bit hairy and you might want to just use two substitutions. For instance here's a two substitution version that has a bit of a shortcut in it... ``` :s/\(user\)s\?/\1_items/gI | s/\(USER\)S\?/\U~/g ``` The `~` in the replacement part of the second com...
26,427
<p>I have two simple Python tests in <code>my_tests.py</code> file:</p> <pre><code>from unittest import TestCase class MyTestCase(TestCase): def test_true(self): self.assertTrue(True) def test_false(self): self.assertFalse(True) </code></pre> <p>which can be executed using <code>pytest my_test...
[ { "answer_id": 26410, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>It's possible to do this with one substitution command but it's a bit hairy and you might want to just use two substi...
2020/07/13
[ "https://vi.stackexchange.com/questions/26427", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/147/" ]
I have two simple Python tests in `my_tests.py` file: ``` from unittest import TestCase class MyTestCase(TestCase): def test_true(self): self.assertTrue(True) def test_false(self): self.assertFalse(True) ``` which can be executed using `pytest my_tests.py`. I want to write VIM shortcut, wh...
It's possible to do this with one substitution command but it's a bit hairy and you might want to just use two substitutions. For instance here's a two substitution version that has a bit of a shortcut in it... ``` :s/\(user\)s\?/\1_items/gI | s/\(USER\)S\?/\U~/g ``` The `~` in the replacement part of the second com...
26,431
<p>How can I make a visual mapping's behaviour dependent on the number of lines selected?</p> <p>I tried creating an expr map, but the visual start and end marks don't seem to be correct:</p> <pre><code>function! Xsurround() abort let is_linewise = mode() ==# 'V' let line_count = line(&quot;'&gt;&quot;) - line(...
[ { "answer_id": 26410, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>It's possible to do this with one substitution command but it's a bit hairy and you might want to just use two substi...
2020/07/13
[ "https://vi.stackexchange.com/questions/26431", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2045/" ]
How can I make a visual mapping's behaviour dependent on the number of lines selected? I tried creating an expr map, but the visual start and end marks don't seem to be correct: ``` function! Xsurround() abort let is_linewise = mode() ==# 'V' let line_count = line("'>") - line("'<") + 1 let g:global_count...
It's possible to do this with one substitution command but it's a bit hairy and you might want to just use two substitutions. For instance here's a two substitution version that has a bit of a shortcut in it... ``` :s/\(user\)s\?/\1_items/gI | s/\(USER\)S\?/\U~/g ``` The `~` in the replacement part of the second com...
26,436
<p>I've installed MacVim using Brew: <code>brew cask install neovim</code></p> <p>I'm using the macOS's Terminal.app to run MacVim in Terminal mode.</p> <p>I've experimented with <code>:colorscheme peachpuff</code>, since many recommends that color scheme, which comes with MacVim by default.</p> <p>In the picture below...
[ { "answer_id": 26437, "author": "Jorengarenar", "author_id": 25807, "author_profile": "https://vi.stackexchange.com/users/25807", "pm_score": 2, "selected": false, "text": "<p>In the code of peachpuff colorscheme we can find such note:</p>\n<pre><code>&quot; Note: Only GUI colors differ ...
2020/07/14
[ "https://vi.stackexchange.com/questions/26436", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/26505/" ]
I've installed MacVim using Brew: `brew cask install neovim` I'm using the macOS's Terminal.app to run MacVim in Terminal mode. I've experimented with `:colorscheme peachpuff`, since many recommends that color scheme, which comes with MacVim by default. In the picture below shows how `peachbuff` looks, when running ...
In the code of peachpuff colorscheme we can find such note: ``` " Note: Only GUI colors differ from default, on terminal it's just `light'. ```
26,441
<p>I would like to define a new command for C++ files/buffers (<code>ft=cpp</code>).</p> <p>I shall explain the requirements through the example below. The newly defined command <code>:stripdbg</code> should strip the surrounding <code>dbg()</code> text and should accept an address range. e.g <code>:10,20stripdbg</code...
[ { "answer_id": 26442, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 1, "selected": false, "text": "<ol>\n<li>You cannot have a command started with lowercase letter, use <code>:Stripdbg</code> or <code>:StripDbg</code><...
2020/07/14
[ "https://vi.stackexchange.com/questions/26441", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8408/" ]
I would like to define a new command for C++ files/buffers (`ft=cpp`). I shall explain the requirements through the example below. The newly defined command `:stripdbg` should strip the surrounding `dbg()` text and should accept an address range. e.g `:10,20stripdbg`, `:.,$stripdbg`, `:%stripdbg` etc should be possibl...
Unlike Maxin's answer, I'd recommend to use a ftplugin. They're really made to store the definition of filetype related mappings, commands, abbreviations, options, variables... While we shall use `<buffer>` with mappings and abbreviations, it's `-b` with commands. Now the problem is that you want to implement is quit...
26,446
<p>In the <a href="https://www.vim.org/scripts/script.php?script_id=1173" rel="noreferrer">tcomment</a> plugin, specifically in:</p> <ul> <li><a href="https://github.com/tomtom/tcomment_vim/blob/master/autoload/tcomment.vim" rel="noreferrer"><code>~/.vim/pack/tml/start/tcomment.vim/autoload/tcomment.vim</code></a> and<...
[ { "answer_id": 26447, "author": "Jorengarenar", "author_id": 25807, "author_profile": "https://vi.stackexchange.com/users/25807", "pm_score": 4, "selected": false, "text": "<p>It's fold marker. Read more <a href=\"https://vimhelp.org/fold.txt.html#fold-marker\" rel=\"noreferrer\"><code>:...
2020/07/14
[ "https://vi.stackexchange.com/questions/26446", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/15661/" ]
In the [tcomment](https://www.vim.org/scripts/script.php?script_id=1173) plugin, specifically in: * [`~/.vim/pack/tml/start/tcomment.vim/autoload/tcomment.vim`](https://github.com/tomtom/tcomment_vim/blob/master/autoload/tcomment.vim) and * [`~/.vim/pack/tml/start/tcomment.vim/plugin/tcomment.vim`](https://github.com/...
As Jorengarenar said in their answer `"{{{2` has to do with foldmarkers. Now, what are foldmarkers anyway? What are they useful for? And how do you use them? First let's notice that the strings you mention in your question are composed of three parts: * `"` the comment character. This is specific to the filetype of y...
26,449
<p>I've noticed in bash/shell it highlights <code>$(...)</code> in red, for example:</p> <p><a href="https://i.stack.imgur.com/R9PCT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R9PCT.png" alt="enter image description here" /></a></p> <p>However, if I change the syntax from <code>ft=sh</code> to <...
[ { "answer_id": 26447, "author": "Jorengarenar", "author_id": 25807, "author_profile": "https://vi.stackexchange.com/users/25807", "pm_score": 4, "selected": false, "text": "<p>It's fold marker. Read more <a href=\"https://vimhelp.org/fold.txt.html#fold-marker\" rel=\"noreferrer\"><code>:...
2020/07/15
[ "https://vi.stackexchange.com/questions/26449", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/28904/" ]
I've noticed in bash/shell it highlights `$(...)` in red, for example: [![enter image description here](https://i.stack.imgur.com/R9PCT.png)](https://i.stack.imgur.com/R9PCT.png) However, if I change the syntax from `ft=sh` to `ft=bash`, it does not do this: [![enter image description here](https://i.stack.imgur.com...
As Jorengarenar said in their answer `"{{{2` has to do with foldmarkers. Now, what are foldmarkers anyway? What are they useful for? And how do you use them? First let's notice that the strings you mention in your question are composed of three parts: * `"` the comment character. This is specific to the filetype of y...
26,454
<p>How can I view a list of all of the features that can be checked for using <code>has()</code> in Vim?</p> <p>I recently came to know the <code>has()</code> function for testing the presence of &quot;features&quot; (see below).</p> <p><code>:h features</code> doesn't show a list of features to test for.</p> <p>How ca...
[ { "answer_id": 26456, "author": "Biggybi", "author_id": 22375, "author_profile": "https://vi.stackexchange.com/users/22375", "pm_score": 0, "selected": false, "text": "<p>You can see a list of these features with <code>:version</code>.</p>\n<p>This will show you which is available and wh...
2020/07/15
[ "https://vi.stackexchange.com/questions/26454", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/26505/" ]
How can I view a list of all of the features that can be checked for using `has()` in Vim? I recently came to know the `has()` function for testing the presence of "features" (see below). `:h features` doesn't show a list of features to test for. How can I see a list of all features that I can test for using `has()`...
The documentation in [`:help has()`](https://vimhelp.org/eval.txt.html#has%28%29) has a pointer to the features it can check for: > > The `{feature}` argument is a string, case is ignored. See [`feature-list`](https://vimhelp.org/eval.txt.html#feature-list) below. > > > If you then look at [`:help feature-list`](...
26,463
<p>I learn vim in the Debian distro. In debian I can run commands like 'ls', 'cd', 'curl' etc directly from vim via power of '!' this sign. But now I am in windows because of the driver issue. But I don't able to use '!' this sign to run external commands direct form the vim. How to run external command within vim in w...
[ { "answer_id": 26464, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 2, "selected": false, "text": "<p>To run external commands from within vim on windows you should use the same vim commands you use for other OSes.</p>\...
2020/07/15
[ "https://vi.stackexchange.com/questions/26463", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23663/" ]
I learn vim in the Debian distro. In debian I can run commands like 'ls', 'cd', 'curl' etc directly from vim via power of '!' this sign. But now I am in windows because of the driver issue. But I don't able to use '!' this sign to run external commands direct form the vim. How to run external command within vim in wind...
To run external commands from within vim on windows you should use the same vim commands you use for other OSes. ``` :!dir :echo system('dir') ``` Just to double check, `cmd.exe` that is used by default as a shell doesn't have `ls`, windows doesn't have `curl` and `ctags` unless you install them.
26,468
<p>I thought that setting the environment variable MYVIMRC would make them use that as its rc file on startup, saving me from passing -u every time.</p> <p>It's set correctly</p> <pre><code>:echo $MYVIMRC </code></pre> <p>shows <code>/c/Users/theonlygusti/My Project/.vimrc</code></p> <p>But none of the settings in the ...
[ { "answer_id": 26469, "author": "run_the_race", "author_id": 27110, "author_profile": "https://vi.stackexchange.com/users/27110", "pm_score": 0, "selected": false, "text": "<p>Try add this line to the end of your <code>.vimrc</code> file so you have:</p>\n<pre><code>set nocompatible\nset...
2020/07/15
[ "https://vi.stackexchange.com/questions/26468", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9024/" ]
I thought that setting the environment variable MYVIMRC would make them use that as its rc file on startup, saving me from passing -u every time. It's set correctly ``` :echo $MYVIMRC ``` shows `/c/Users/theonlygusti/My Project/.vimrc` But none of the settings in the file seem to be run. The file is just two line...
Setting the `MYVIMRC` environment variable does *not* affect what `vimrc` file is used for startup. I think you may have misinterpreted [this bit of documentation](https://vimhelp.org/starting.txt.html#.vimrc): > > The $MYVIMRC environment variable is set to the file that was first found, unless $MYVIMRC was already ...
26,472
<p>This is mainly for working on multiple files in <a href="https://vifm.info/" rel="nofollow noreferrer">vifm</a> (<code>log1.txt</code>, <code>log2.txt</code>, etc.) so lines can be assumed to be sorted, though this should work in normal vim/nvim.</p> <p>Let's say we have this:</p> <pre><code>test 1 test 2 test 3 tes...
[ { "answer_id": 26474, "author": "Biggybi", "author_id": 22375, "author_profile": "https://vi.stackexchange.com/users/22375", "pm_score": 0, "selected": false, "text": "<p>The only idea that comes to my mind is to use <code>/</code> to search for <code>another</code>:</p>\n<ul>\n<li><code...
2020/07/15
[ "https://vi.stackexchange.com/questions/26472", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25859/" ]
This is mainly for working on multiple files in [vifm](https://vifm.info/) (`log1.txt`, `log2.txt`, etc.) so lines can be assumed to be sorted, though this should work in normal vim/nvim. Let's say we have this: ``` test 1 test 2 test 3 test 4 test 5 testing 1 testing 2 testing 3 another ``` I'm on the line with `t...
If you want a command that does that based on the length of the prefix, here's one: ``` function! Prefix(count) if a:count == 0 return endif let prefix = strcharpart(getline('.'), 0, a:count) let pat = '\V\^'.escape(prefix, '\') echom "pat = [".pat."]" let start = line('.') let end = start let last...
26,501
<p>I've got, in this case, a Perl module which has some <code>JSON</code> snippets inside of it. I'd like to be able to select the embedded <code>JSON</code> and format it via <code>jq</code>. So far I've got:</p> <p><code>:vnoremap jq &lt;esc&gt;:'&lt;,'&gt;:w !jq&lt;CR&gt;</code></p> <p>That allows me to select some...
[ { "answer_id": 26510, "author": "oalders", "author_id": 13055, "author_profile": "https://vi.stackexchange.com/users/13055", "pm_score": 3, "selected": true, "text": "<p>There at least two possible answers here:</p>\n<pre><code>vnoremap jq :!jq&lt;cr&gt;\n</code></pre>\n<p>as suggested b...
2020/07/16
[ "https://vi.stackexchange.com/questions/26501", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13055/" ]
I've got, in this case, a Perl module which has some `JSON` snippets inside of it. I'd like to be able to select the embedded `JSON` and format it via `jq`. So far I've got: `:vnoremap jq <esc>:'<,'>:w !jq<CR>` That allows me to select some text, type `jq` and then the formatted text is displayed to me. However, it's...
There at least two possible answers here: ``` vnoremap jq :!jq<cr> ``` as suggested by @Ralf works for `jq` >= 1.6. See <https://github.com/stedolan/jq/commit/5fe053671a768d28bc9773719cc4a9a35e72f30d> For earlier `jq` versions where the dot is not implied, it needs to be in the command: ``` vnoremap jq :!jq .<cr> ...
26,514
<p>I have the following function:</p> <pre><code>fu! EditFileInBrowser() let l:url = @+ let l:url = substitute(l:url, 'http:\/\/127\.0\.0\.1:4000\/', '', '') let l:url = substitute(l:url, '/$', '', 'g') let l:url = substitute(l:url, '-', ' ', 'g') let l:file = '~/vimwiki/webnotes/' . l:url . '.md' echom l:f...
[ { "answer_id": 26510, "author": "oalders", "author_id": 13055, "author_profile": "https://vi.stackexchange.com/users/13055", "pm_score": 3, "selected": true, "text": "<p>There at least two possible answers here:</p>\n<pre><code>vnoremap jq :!jq&lt;cr&gt;\n</code></pre>\n<p>as suggested b...
2020/07/16
[ "https://vi.stackexchange.com/questions/26514", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2021/" ]
I have the following function: ``` fu! EditFileInBrowser() let l:url = @+ let l:url = substitute(l:url, 'http:\/\/127\.0\.0\.1:4000\/', '', '') let l:url = substitute(l:url, '/$', '', 'g') let l:url = substitute(l:url, '-', ' ', 'g') let l:file = '~/vimwiki/webnotes/' . l:url . '.md' echom l:file edit l:...
There at least two possible answers here: ``` vnoremap jq :!jq<cr> ``` as suggested by @Ralf works for `jq` >= 1.6. See <https://github.com/stedolan/jq/commit/5fe053671a768d28bc9773719cc4a9a35e72f30d> For earlier `jq` versions where the dot is not implied, it needs to be in the command: ``` vnoremap jq :!jq .<cr> ...
26,552
<p>I wrote a function to show some special characters with red color:</p> <pre><code>function! ShowChar() set list set listchars=tab:→\ ,space:·,nbsp:␣,eol:¶ highlight SpecialKey ctermfg=blue ctermbg=red guifg=blue guibg=red endfunction map &lt;f5&gt; :call ShowChar()&lt;CR&gt; </code></pre> <p>When to pres...
[ { "answer_id": 26555, "author": "showkey", "author_id": 5181, "author_profile": "https://vi.stackexchange.com/users/5181", "pm_score": 0, "selected": false, "text": "<pre><code>function! SpecialKeyWarning()\n set list\n set listchars=tab:→\\ ,space:·,nbsp:␣,eol:¶\n highlight Spe...
2020/07/20
[ "https://vi.stackexchange.com/questions/26552", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5181/" ]
I wrote a function to show some special characters with red color: ``` function! ShowChar() set list set listchars=tab:→\ ,space:·,nbsp:␣,eol:¶ highlight SpecialKey ctermfg=blue ctermbg=red guifg=blue guibg=red endfunction map <f5> :call ShowChar()<CR> ``` When to press `f5`, the characters -- `tab`, `sp...
I assume you use `termguicolors`: ``` if has("termguicolors") set termguicolors endif ``` You can use this to store the colors of the `SpecialKey` group each time your colorscheme changes: ``` augroup SaveSpecialKeyColors au! au ColorScheme,VimEnter * \ let g:specialkey_fg = synIDattr(hlID('SpecialKey...
26,559
<p>I'm running into a bothersome issue I can't seem to solve myself. When I open gvim I receive the error <code>E285: Failed to create input context</code></p> <p>The error always comes twice, and looks to be related to XIM input. Although this is the first I've ever heard of IM and XIM as I am only ever working in E...
[ { "answer_id": 29236, "author": "iqmaker", "author_id": 33618, "author_profile": "https://vi.stackexchange.com/users/33618", "pm_score": 0, "selected": false, "text": "<p>Same problem, after upgrade Ubuntu (20.04 TLS) worked for me:</p>\n<pre><code>sudo apt-get remove vim-athena vim-gui-...
2020/07/20
[ "https://vi.stackexchange.com/questions/26559", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30664/" ]
I'm running into a bothersome issue I can't seem to solve myself. When I open gvim I receive the error `E285: Failed to create input context` The error always comes twice, and looks to be related to XIM input. Although this is the first I've ever heard of IM and XIM as I am only ever working in English. I don't nor...
I had the same problem when starting gvim from a shell script. Looking at the code vim ignores the fact that creating this context failed. It is just annoying the users with this message except when the "not a term" flag is set. To set that flag specify `--not-a-term` on the command line and the error message vanishes....
26,563
<p>The same as the <a href="https://vi.stackexchange.com/questions/627/how-can-i-change-vims-start-or-intro-screen">existing question</a>, but for the <a href="https://github.com/vim/vim-win32-installer" rel="nofollow noreferrer">Windows console version</a>.</p> <p>I do not see &quot;startify.vim&quot;.</p>
[ { "answer_id": 26564, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 4, "selected": true, "text": "<p>Just add the following line to your vimrc</p>\n<pre><code>set shm+=I\n</code></pre>\n<p>See docs at <code>:h 'shm'</code>...
2020/07/21
[ "https://vi.stackexchange.com/questions/26563", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30668/" ]
The same as the [existing question](https://vi.stackexchange.com/questions/627/how-can-i-change-vims-start-or-intro-screen), but for the [Windows console version](https://github.com/vim/vim-win32-installer). I do not see "startify.vim".
Just add the following line to your vimrc ``` set shm+=I ``` See docs at `:h 'shm'`.
26,565
<p>How can I get the line numbers of all matching strings in a buffer?<br /> Like in this buffer, I want to get the list <code>[1,6,50]</code> of all line numbers with matching strings.</p> <pre><code>1: test .... 6: test .... 50: test .... </code></pre>
[ { "answer_id": 26566, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 2, "selected": false, "text": "<p>A convoluted (and untested) way I sometimes use. The idea is to use <code>map()</code> to associate line numbers to ...
2020/07/21
[ "https://vi.stackexchange.com/questions/26565", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30677/" ]
How can I get the line numbers of all matching strings in a buffer? Like in this buffer, I want to get the list `[1,6,50]` of all line numbers with matching strings. ``` 1: test .... 6: test .... 50: test .... ```
Doing two manual passes over the text is rarely needed. Most often one just does ``` g/^test/DoSomething ``` And that's enough. The reason is that `:g` is implemented in two passes, so it's not a problem if you, say, add a few lines after each match. However, if you really want those numbers in a List, you can achi...
26,572
<p>How can I indent lines selected in Visual mode using space granularity instead of than TABs (i.e. <code>&lt;</code> or <code>&gt;</code>)?</p> <p>Sometimes when coding Python, I need to indent lines to a level that is not a TAB boundary.</p> <p>Selecting the lines by pressing <code>V</code> to enter Visual mode and ...
[ { "answer_id": 26575, "author": "Biggybi", "author_id": 22375, "author_profile": "https://vi.stackexchange.com/users/22375", "pm_score": 3, "selected": true, "text": "<h3>A working, hacky solution</h3>\n<pre><code>function! Visual_indent_with_space() range abort\n '&lt;,'&gt;g/./exe &qu...
2020/07/22
[ "https://vi.stackexchange.com/questions/26572", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/26505/" ]
How can I indent lines selected in Visual mode using space granularity instead of than TABs (i.e. `<` or `>`)? Sometimes when coding Python, I need to indent lines to a level that is not a TAB boundary. Selecting the lines by pressing `V` to enter Visual mode and then using `<` or `>` to indent them doesn't let me in...
### A working, hacky solution ``` function! Visual_indent_with_space() range abort '<,'>g/./exe "normal! " v:count1 . "I " endfunction vnoremap <leader><space> :call Visual_indent_with_space()<cr> ``` Breaking down: `'<,'>g/./exe "normal! " v:count1 . "I "` * `'<,'>`: use the selected range * `g/./`: apply a glob...
26,602
<p>There is a keybinding in Emacs that lets you scroll in another window that you're not currently working on (<code>C-M-v</code> to <em>scroll-other-window-down</em> and <code>C-M-V</code> to <em>scroll-other-window-up</em>). For example, in a horizontal split, while you're writing in the upper window, you can scroll ...
[ { "answer_id": 26603, "author": "Dmitry", "author_id": 17271, "author_profile": "https://vi.stackexchange.com/users/17271", "pm_score": 2, "selected": false, "text": "<p>Assuming you have 2 windows. Then map like this in your <code>.vimrc</code>:</p>\n<pre><code>map &lt;F11&gt; &lt;C-W&g...
2020/07/25
[ "https://vi.stackexchange.com/questions/26602", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23287/" ]
There is a keybinding in Emacs that lets you scroll in another window that you're not currently working on (`C-M-v` to *scroll-other-window-down* and `C-M-V` to *scroll-other-window-up*). For example, in a horizontal split, while you're writing in the upper window, you can scroll the view of the bottom window without s...
> > scroll the view of the bottom window without switching to that window > > > Something like this ``` call win_execute(win_getid(winnr('j')), "normal! \<C-E>") ``` `winnr('j')` returns Window number of a window below the current one. `win_getid()` translates Window number to `:h winid`. Then `win_execute()` r...
26,608
<p>This following vim script calls a function that returns an array called <code>lines</code>:</p> <p><code>call vimwiki#diary#generate_diary_section()</code></p> <p>There seems to be a bug and nothing is done with the <code>lines</code> array—the content never gets added to the buffer. I have a two part question:</p> ...
[ { "answer_id": 26610, "author": "Tin Thai", "author_id": 30239, "author_profile": "https://vi.stackexchange.com/users/30239", "pm_score": 1, "selected": false, "text": "<p>Just remove <code>call</code>.<br />\n<a href=\"https://vi.stackexchange.com/a/19186/30239\">This answer</a> did exp...
2020/07/25
[ "https://vi.stackexchange.com/questions/26608", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2021/" ]
This following vim script calls a function that returns an array called `lines`: `call vimwiki#diary#generate_diary_section()` There seems to be a bug and nothing is done with the `lines` array—the content never gets added to the buffer. I have a two part question: 1. How do I capture the array returned from the fun...
There are several ways to insert the return value of a function into a buffer, but the simplest (in my opinion) is to use the expression register: In normal mode you can trigger the expression register with `"=`, and then you type an expression and hit enter (`<CR>`). Thiss can just be a function call, if you wish; th...
26,628
<p>I use CTRL-O and CTRL-I heavily to move between previously visited positions. These commands rely on the jumplist.</p> <p>It makes sense to me to visualize the jumplist as a stack of my position history. Thus, I'm surprised that the jumplist is effectively indexed by file and line number, which you can deduce from t...
[ { "answer_id": 31286, "author": "TornaxO7", "author_id": 31844, "author_profile": "https://vi.stackexchange.com/users/31844", "pm_score": 0, "selected": false, "text": "<p>I think the <code>jumpoptions</code> is the setting which you're looking for. Put the following into your <code>vimr...
2020/07/27
[ "https://vi.stackexchange.com/questions/26628", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30743/" ]
I use CTRL-O and CTRL-I heavily to move between previously visited positions. These commands rely on the jumplist. It makes sense to me to visualize the jumplist as a stack of my position history. Thus, I'm surprised that the jumplist is effectively indexed by file and line number, which you can deduce from the vim do...
The 'jumpoptions' option is not yet supported in Vim (it is only supported in Neovim). The following pull request was created to add this support: <https://github.com/vim/vim/pull/7738> But this is not merged (refer to the the discussion in the PR).
26,635
<p>When editing markdown and other text files, I like to use <code>textwidth</code>/<code>wrapmargin</code> to insert line breaks at fixed intervals. (The advantage of this is that each visual line is a Vim &quot;line&quot; - otherwise, &quot;line&quot; and &quot;paragraph&quot; are basically equivalent.) However, when...
[ { "answer_id": 26636, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<h2>Why it doesn't work</h2>\n<p>The reason your command works that way is that all the lines are marked for actio...
2020/07/27
[ "https://vi.stackexchange.com/questions/26635", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/26984/" ]
When editing markdown and other text files, I like to use `textwidth`/`wrapmargin` to insert line breaks at fixed intervals. (The advantage of this is that each visual line is a Vim "line" - otherwise, "line" and "paragraph" are basically equivalent.) However, when exporting from Vim I want to remove these artificial l...
Maybe it sounds too simplistic, but why not ``` %!fmt -9999 ```
26,663
<p>I open vim with three files: <code>vim a.txt b.txt c.txt</code>. Then:</p> <ol> <li>edit a.txt, save it by <code>:w</code>, switch to b.txt by <code>:n</code>.</li> <li>edit b.txt, save it by <code>:w</code>, switch to c.txt by <code>:n</code>.</li> <li>edit c.txt, save it by <code>:w</code>, and quit vim session by...
[ { "answer_id": 26667, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>I wouldn't say that there is anything wrong with your editing process I think it's just vim normal behavior.</p>\n<p>For...
2020/07/29
[ "https://vi.stackexchange.com/questions/26663", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18929/" ]
I open vim with three files: `vim a.txt b.txt c.txt`. Then: 1. edit a.txt, save it by `:w`, switch to b.txt by `:n`. 2. edit b.txt, save it by `:w`, switch to c.txt by `:n`. 3. edit c.txt, save it by `:w`, and quit vim session by `:q`. After I quit, terminal showed a message of "3 files to edit". My question is: What...
> > What's wrong with my editing process? > > > Nothing. Vim likes to talk and, in fact, that message is written **before** you actually start editing your files, as can be confirmed if you issue `gvim` instead of `vim`. Another clear, unambiguous way to confirm it: ``` strace -o vimStrace vim a.txt b.txt c.txt ...
26,675
<p>With <code>ignorecase</code> set, I am able to jump to a tag <code>Foo</code> by typing <code>:ltag foo</code>. However, doing so causes the message</p> <pre><code>Using tag with different case! </code></pre> <p>to appear at the bottom of the screen, along with a ~0.5s delay during which vim does not update. The sa...
[ { "answer_id": 26676, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>According to my reading of the code you've found the only way to avoid that stuff: use of <code>silent</code>.</p>\n<...
2020/07/29
[ "https://vi.stackexchange.com/questions/26675", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/88/" ]
With `ignorecase` set, I am able to jump to a tag `Foo` by typing `:ltag foo`. However, doing so causes the message ``` Using tag with different case! ``` to appear at the bottom of the screen, along with a ~0.5s delay during which vim does not update. The same message and delay appear when jumping to another tag (w...
According to my reading of the code you've found the only way to avoid that stuff: use of `silent`. This appends the warning...nothing can prevent it except for disabling `ignorecase` et al... ``` if (ic) STRCAT(IObuff, _(" Using tag with different case!")); ``` Then a bit later the warning is printed and a ni...
26,678
<p>I am running Ubuntu 16.04, which requires the Python 3 system version to be 3.5: updating it to 3.7 breaks the package manager.</p> <p>At the same time, I want to use Vim with YouCompleteMe. YouCompleteMe <a href="https://github.com/ycm-core/YouCompleteMe#warning-support-for-python-35-has-ended" rel="nofollow norefe...
[ { "answer_id": 26679, "author": "user2891462", "author_id": 12266, "author_profile": "https://vi.stackexchange.com/users/12266", "pm_score": 2, "selected": true, "text": "<p>You can compile Vim from source to configure which interpreter it should use. The full instructions can be found o...
2020/07/30
[ "https://vi.stackexchange.com/questions/26678", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/12266/" ]
I am running Ubuntu 16.04, which requires the Python 3 system version to be 3.5: updating it to 3.7 breaks the package manager. At the same time, I want to use Vim with YouCompleteMe. YouCompleteMe [has stopped supporting Python 3.5](https://github.com/ycm-core/YouCompleteMe#warning-support-for-python-35-has-ended), a...
You can compile Vim from source to configure which interpreter it should use. The full instructions can be found on the [YouCompleteMe wiki](https://github.com/ycm-core/YouCompleteMe/wiki/Building-Vim-from-source). It turns out the method described in the original post is correct: configuring the installation with the...
26,690
<p>When coc prompts with information about what a class / function does there's help to the right, but if I want to scroll down within this help I have to use the mouse. I'm wondering if there's a nicer alternative?</p> <p><a href="https://i.stack.imgur.com/xn5OL.png" rel="nofollow noreferrer"><img src="https://i.stack...
[ { "answer_id": 27861, "author": "Yuki Yoshimine", "author_id": 30413, "author_profile": "https://vi.stackexchange.com/users/30413", "pm_score": 2, "selected": false, "text": "<p>coc#util#float_scroll has been replaced by coc#float#scroll()</p>\n<p>The example keymapping has been given in...
2020/07/31
[ "https://vi.stackexchange.com/questions/26690", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1443/" ]
When coc prompts with information about what a class / function does there's help to the right, but if I want to scroll down within this help I have to use the mouse. I'm wondering if there's a nicer alternative? [![t ](https://i.stack.imgur.com/xn5OL.png)](https://i.stack.imgur.com/xn5OL.png) Edit ==== I have tried...
coc#util#float\_scroll has been replaced by coc#float#scroll() The example keymapping has been given in the documentation. ``` if has('nvim-0.4.3') || has('patch-8.2.0750') nnoremap <nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>" nnoremap <nowait><expr> <C-b> coc#float...
26,699
<p>I'm trying to have python files format on save using black and neovim, with coc.</p> <h2>Coc config</h2> <p>I have the following coc config:</p> <pre><code>{ &quot;coc.preferences.useQuickfixForLocations&quot;: true, &quot;coc.preferences.snippets.enable&quot;: true, // python config &quot;python.venvFolde...
[ { "answer_id": 31087, "author": "Gordon Bai", "author_id": 25033, "author_profile": "https://vi.stackexchange.com/users/25033", "pm_score": 5, "selected": true, "text": "<p>This is a <code>coc.nvim</code> setup procedure that works for Neovim, which aims to:</p>\n<ul>\n<li><p>Use <code>c...
2020/08/01
[ "https://vi.stackexchange.com/questions/26699", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1443/" ]
I'm trying to have python files format on save using black and neovim, with coc. Coc config ---------- I have the following coc config: ``` { "coc.preferences.useQuickfixForLocations": true, "coc.preferences.snippets.enable": true, // python config "python.venvFolders": [".virtualenvs"], "python.venvPath"...
This is a `coc.nvim` setup procedure that works for Neovim, which aims to: * Use `coc-pyright` as language server. * Provide static type checking from a Python virtualenv (*e.g.* I have created a venv called `coc` with `pyenv`, which resides in `~/.pyenv/versions`, I'll use this as an example). * Format with `black` m...
26,738
<p>I've recently decided to give Vim a try and am trying to get it set up for work with Python.</p> <p>I've installed YCM, so I have autocompletion now, which is good, but there are a few things documentation-wise that I'd like to have set up.</p> <p><kbd>K</kbd> will open up a window beautifully which can be closed ea...
[ { "answer_id": 26750, "author": "Daniel", "author_id": 30861, "author_profile": "https://vi.stackexchange.com/users/30861", "pm_score": 2, "selected": false, "text": "<p>What program is called when K is pressed is set by <em>keywordprg</em>.\nBy default, this is set to <em>man</em> (the ...
2020/08/05
[ "https://vi.stackexchange.com/questions/26738", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30861/" ]
I've recently decided to give Vim a try and am trying to get it set up for work with Python. I've installed YCM, so I have autocompletion now, which is good, but there are a few things documentation-wise that I'd like to have set up. `K` will open up a window beautifully which can be closed easily with `:q`. I really...
What program is called when K is pressed is set by *keywordprg*. By default, this is set to *man* (the linux manual). Changing it to *pydoc* so as to get Python documentation will do the trick, but then you don't the manual being checked anymore - which is an issue if, for example, you're working with C code, as C's li...
26,752
<p>I've created some Python virtual environments:</p> <pre><code>hmanx ~ » pyenv virtualenvs 3.7.4/envs/nn (created from /home/roach/.pyenv/versions/3.7.4) 3.8.2/envs/py38 (created from /home/roach/.pyenv/versions/3.8.2) nn (created from /home/roach/.pyenv/versions/3.7.4) py38 (created from /home/roach/.pyenv/v...
[ { "answer_id": 26755, "author": "roachsinai", "author_id": 16299, "author_profile": "https://vi.stackexchange.com/users/16299", "pm_score": 0, "selected": false, "text": "<p>A method is decalare <code>export PYTHON_CONFIGURE_OPTS='--enable-shared'</code> before pyenv install a virtual en...
2020/08/07
[ "https://vi.stackexchange.com/questions/26752", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16299/" ]
I've created some Python virtual environments: ``` hmanx ~ » pyenv virtualenvs 3.7.4/envs/nn (created from /home/roach/.pyenv/versions/3.7.4) 3.8.2/envs/py38 (created from /home/roach/.pyenv/versions/3.8.2) nn (created from /home/roach/.pyenv/versions/3.7.4) py38 (created from /home/roach/.pyenv/versions/3.8.2...
Here are the commands I use to create a python 3.6.0 pyenv on a Mac using homebrew. Please note that I use neovim but the process to create a pyenv will not be much different for vim. 1. Install readline and xz along with pyenv and pyenv-virtualenv ``` brew install pyenv pyenv-virtualenv readline xz ``` 2. Install p...
26,796
<p>I use UltiSnips for many of my TeX snippets, and I'm trying to create one to automatically insert a new <code>\item</code> inside <code>itemize</code> or <code>enumerate</code> environments.</p> <p>The way it should work is the following: every time I'm done writing an <code>\item</code>, if I press the trigger key ...
[ { "answer_id": 26798, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 1, "selected": false, "text": "<p>What about writing your own mapping for TAB that analyses its context?</p>\n<ul>\n<li>if it detect <code>^\\s*\\\\it...
2020/08/11
[ "https://vi.stackexchange.com/questions/26796", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/26480/" ]
I use UltiSnips for many of my TeX snippets, and I'm trying to create one to automatically insert a new `\item` inside `itemize` or `enumerate` environments. The way it should work is the following: every time I'm done writing an `\item`, if I press the trigger key (`<tab>` for me) a function should be called that doe...
Main Ideas ---------- There are 3 cases to consider (reworded slightly from the original question): a) If not in an itemize environment, create one, and place the cursor after the first \item. b) If in an itemize environment and if the list item is *not* empty, create a new \item. c) If in an itemize environm...
26,805
<p>This is a follow-up question from this <a href="https://stackoverflow.com/q/4478111/3398271">Question</a> and <a href="https://stackoverflow.com/a/4478193/3398271">Answer</a>.</p> <p>Is it possible, and if so how, to <strong>open two (or more) new empty buffers in Vim (without associating them to a file), such that ...
[ { "answer_id": 26807, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p>First thing's first, let's make sure our definitions are in sync. Per, <a href=\"https://vimhelp.org/windows.txt.html#...
2020/08/11
[ "https://vi.stackexchange.com/questions/26805", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9602/" ]
This is a follow-up question from this [Question](https://stackoverflow.com/q/4478111/3398271) and [Answer](https://stackoverflow.com/a/4478193/3398271). Is it possible, and if so how, to **open two (or more) new empty buffers in Vim (without associating them to a file), such that they both take on the whole window**?...
First thing's first, let's make sure our definitions are in sync. Per, [`:h window`](https://vimhelp.org/windows.txt.html#window): * A buffer is the in-memory text of a file. * A window is a viewport on a buffer. * (And for the sake of completeness) A tab page is a collection of windows. Above these things are your t...
26,811
<p>I recently activated auto-complete using <a href="https://github.com/ycm-core/YouCompleteMe" rel="nofollow noreferrer">YouCompleteMe</a> and syntax color in Vim. However, a red highlighting color appeared.</p> <p><a href="https://i.stack.imgur.com/dpWs0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur....
[ { "answer_id": 26807, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p>First thing's first, let's make sure our definitions are in sync. Per, <a href=\"https://vimhelp.org/windows.txt.html#...
2020/08/12
[ "https://vi.stackexchange.com/questions/26811", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30966/" ]
I recently activated auto-complete using [YouCompleteMe](https://github.com/ycm-core/YouCompleteMe) and syntax color in Vim. However, a red highlighting color appeared. [![enter image description here](https://i.stack.imgur.com/dpWs0.png)](https://i.stack.imgur.com/dpWs0.png) I tried to disable syntax color with `syn...
First thing's first, let's make sure our definitions are in sync. Per, [`:h window`](https://vimhelp.org/windows.txt.html#window): * A buffer is the in-memory text of a file. * A window is a viewport on a buffer. * (And for the sake of completeness) A tab page is a collection of windows. Above these things are your t...
26,818
<p>I've read that Vim automatically stores previously yanked texts into registers from 1 to 9, being 1 the previous yank, 2 the second previous, and so on...</p> <p>But this is not working for me. Here is a screencast showing that registers 1-9 are not being populated: <a href="https://streamable.com/rmyxhl" rel="noref...
[ { "answer_id": 26819, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 3, "selected": false, "text": "<blockquote>\n<p>Vim automatically stores previously yanked texts into registers from 1 to 9</p>\n</blockquote>\n<p>T...
2020/08/12
[ "https://vi.stackexchange.com/questions/26818", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/26095/" ]
I've read that Vim automatically stores previously yanked texts into registers from 1 to 9, being 1 the previous yank, 2 the second previous, and so on... But this is not working for me. Here is a screencast showing that registers 1-9 are not being populated: <https://streamable.com/rmyxhl> How can I configure vim to...
You can write a code to do this. Registers 1-9 would be used. Register 0 gets override with the current yank, so you need to save the last yank. ``` function! SaveLastReg() if v:event['regname']=="" if v:event['operator']=='y' for i in range(8,1,-1) exe "let @".string(i+1)." = ...
26,822
<p>I have a directory ~/.vim/rc.d/ that houses various configuration files. I like this pattern for configuring various things in my homedir because it modularizes configuration options.</p> <p>The problem is that my vimrc is now a series of commands to source hard-coded paths to other .vim files.</p> <pre><code>source...
[ { "answer_id": 26823, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>The doc <a href=\"http://vimhelp.appspot.com/repeat.txt.html#%3Aruntime\" rel=\"nofollow noreferrer\"><code>:h :runtime<...
2020/08/13
[ "https://vi.stackexchange.com/questions/26822", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8026/" ]
I have a directory ~/.vim/rc.d/ that houses various configuration files. I like this pattern for configuring various things in my homedir because it modularizes configuration options. The problem is that my vimrc is now a series of commands to source hard-coded paths to other .vim files. ``` source ~/.vim/rc.d/00-plu...
The doc [`:h :runtime`](http://vimhelp.appspot.com/repeat.txt.html#%3Aruntime) says: ``` :ru[ntime][!] [where] {file} .. Read Ex commands from {file} in each directory given by 'runtimepath' and/or 'packpath'. There is no error for non-existing files. [...] ...
26,860
<p>I have the following line in my nvim configuration file:</p> <pre><code>map &lt;leader&gt;c :w! \| !compiler &lt;c-r&gt;%&lt;CR&gt;\| !zathura $(echo %:r&quot;.pdf&quot;) &amp;&amp; disown&lt;CR&gt;&lt;CR&gt; </code></pre> <p>The first part (or 2/3 of the line) works to compile the file I'm working, but I want to br...
[ { "answer_id": 26861, "author": "Skillmon", "author_id": 16779, "author_profile": "https://vi.stackexchange.com/users/16779", "pm_score": 0, "selected": false, "text": "<p>If the currently active file is your main file (which the <code>!compiler</code> invocation already assumes), you ca...
2020/08/16
[ "https://vi.stackexchange.com/questions/26860", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/31024/" ]
I have the following line in my nvim configuration file: ``` map <leader>c :w! \| !compiler <c-r>%<CR>\| !zathura $(echo %:r".pdf") && disown<CR><CR> ``` The first part (or 2/3 of the line) works to compile the file I'm working, but I want to bring up zathura when this happens. Can I modify the last bit? It's my bes...
I recommend using the [vimtex plugin](https://github.com/lervag/vimtex). It allows opening zathura as a PDF viewer after compiling in one step. Also it has continuous mode, meaning that you will be able to see automatically compiled changes immediately in the running zathura instance.
26,875
<p>Is it possible to reformat/reflow text files into two-column layouts (as in some newspapers)? I can do that in Word, but I'd rather do it in vim.</p>
[ { "answer_id": 26876, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 2, "selected": false, "text": "<p>You can reuse split windows for that.</p>\n<p>Sequence of commands:</p>\n<ol>\n<li><code>:vsplit</code> to vertically...
2020/08/17
[ "https://vi.stackexchange.com/questions/26875", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
Is it possible to reformat/reflow text files into two-column layouts (as in some newspapers)? I can do that in Word, but I'd rather do it in vim.
Based on [this unix.se answer](https://unix.stackexchange.com/a/318345/301073), I would do ``` :%!pr -t -2 -w 200 ``` Or some appropriate width (e.g., to insert twice `textwidth`, type `Ctrl`-`r``=&textwidth*2``Enter` after the `-w` ).
26,902
<p>I use the following mapping to send code to a REPL using vim-slime and tmux:</p> <pre><code>nmap &lt;buffer&gt; &lt;S-CR&gt; &lt;Plug&gt;SlimeLineSend </code></pre> <p>How can I perform an action after I invoque this mapping?. For example, I would like to move down one line (<code>j</code>) after the <code>&lt;Plug&...
[ { "answer_id": 26904, "author": "mroavi", "author_id": 27039, "author_profile": "https://vi.stackexchange.com/users/27039", "pm_score": 0, "selected": false, "text": "<p>I came up with a solution based on this answer: <a href=\"https://stackoverflow.com/a/18547013/1706778\">https://stack...
2020/08/19
[ "https://vi.stackexchange.com/questions/26902", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/27039/" ]
I use the following mapping to send code to a REPL using vim-slime and tmux: ``` nmap <buffer> <S-CR> <Plug>SlimeLineSend ``` How can I perform an action after I invoque this mapping?. For example, I would like to move down one line (`j`) after the `<Plug>SlimeLineSend` is executed. This does not work: ``` nmap <bu...
This almost works for me: ``` nmap <buffer> <S-CR> <Plug>SlimeLineSendj ``` The reason it actually doesn't work is that my terminal Vim actually doesn't recognize the `<S-CR>` sequence as different from a simple `<CR>`, so whenever I press `<S-CR>` Vim just moves to the next line and doesn't really trigger the mappi...
26,912
<p>I have this text:</p> <pre> ```python x = 1 ``` </pre> <p>Basically markdown python cells. I would like to extract the content of the cell surrounding the cursor, if any.</p> <p>As you may have guessed already, I am trying to build a jupyter workflow, I use <a href="https://github.com/goerz/jupytext.vim" rel="nofoll...
[ { "answer_id": 26904, "author": "mroavi", "author_id": 27039, "author_profile": "https://vi.stackexchange.com/users/27039", "pm_score": 0, "selected": false, "text": "<p>I came up with a solution based on this answer: <a href=\"https://stackoverflow.com/a/18547013/1706778\">https://stack...
2020/08/20
[ "https://vi.stackexchange.com/questions/26912", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/31085/" ]
I have this text: ``` ```python x = 1 ``` ``` Basically markdown python cells. I would like to extract the content of the cell surrounding the cursor, if any. As you may have guessed already, I am trying to build a jupyter workflow, I use [jupytex](https://github.com/goerz/jupytext.vim) and vim-slime for the conso...
This almost works for me: ``` nmap <buffer> <S-CR> <Plug>SlimeLineSendj ``` The reason it actually doesn't work is that my terminal Vim actually doesn't recognize the `<S-CR>` sequence as different from a simple `<CR>`, so whenever I press `<S-CR>` Vim just moves to the next line and doesn't really trigger the mappi...
26,915
<p>I am trying to write a function to lint buffers in neovim. It seems that the usual recommendation for achieving such a thing is to run the command over the entire range (ie <code>%!lint</code>). This is however, problematic if the file is not properly formatted. In (neo)vim's current behaviour, it appears that even ...
[ { "answer_id": 26916, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<p>One option would be to</p>\n<ul>\n<li>run the linter on the file and shove the output in a temporary file (rele...
2020/08/20
[ "https://vi.stackexchange.com/questions/26915", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/20542/" ]
I am trying to write a function to lint buffers in neovim. It seems that the usual recommendation for achieving such a thing is to run the command over the entire range (ie `%!lint`). This is however, problematic if the file is not properly formatted. In (neo)vim's current behaviour, it appears that even stderr output ...
D Ben Knoble's [answer](https://vi.stackexchange.com/a/26916/20542) looks promising, but I hated the idea of using temporary files. After some digging, I found another way to achieve the desired behaviour, largely stolen from the [dart vim plugin fmt iimplementation](https://github.com/dart-lang/dart-vim-plugin/blob/ma...
26,917
<p>Following my <a href="https://vi.stackexchange.com/questions/26912/cant-repeat-negated-pattern-using/26914#26914">question</a> about some search pattern in vim, I would like to get the the text corresponding to the first match (if any) of my search pattern <strong>wich includes cursor position and is multiline</stro...
[ { "answer_id": 26937, "author": "eyal karni", "author_id": 18375, "author_profile": "https://vi.stackexchange.com/users/18375", "pm_score": 1, "selected": false, "text": "<p>A bit overkill but I refer you to\n<a href=\"https://vi.stackexchange.com/questions/16907/how-to-run-a-python-comm...
2020/08/20
[ "https://vi.stackexchange.com/questions/26917", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/31085/" ]
Following my [question](https://vi.stackexchange.com/questions/26912/cant-repeat-negated-pattern-using/26914#26914) about some search pattern in vim, I would like to get the the text corresponding to the first match (if any) of my search pattern **wich includes cursor position and is multiline**. Here is a text exampl...
So I found that `gn` was the one I need; from `:help gn`: > > Search forward for the last used search pattern, like with n, and start Visual mode to select the match. If the cursor is on the match, visually selects it. If an operator is pending, operates on the match. > > > That means I can combine it with yank a...
26,926
<p>I am aware of the <code>substitute</code> command and of its usage as an ex command <code>:%s/&lt;old&gt;/&lt;new&gt;/g</code></p> <p>However when <code>&lt;new&gt;</code> contains a very complicated string, say a complicated URL with lots of characters like <code>% [ ] : / \</code> etc, then the characters start be...
[ { "answer_id": 26931, "author": "Paperclip Bob", "author_id": 6203, "author_profile": "https://vi.stackexchange.com/users/6203", "pm_score": 0, "selected": false, "text": "<p>My .vimrc has these lines ...</p>\n<pre><code>set incsearch\nlet @o = &quot;.nzz&quot;\nmap &lt;F8&gt; @o\n</code...
2020/08/21
[ "https://vi.stackexchange.com/questions/26926", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/21293/" ]
I am aware of the `substitute` command and of its usage as an ex command `:%s/<old>/<new>/g` However when `<new>` contains a very complicated string, say a complicated URL with lots of characters like `% [ ] : / \` etc, then the characters start being part of the command (especially `/` or `:`) and I have to start usi...
Well, assuming pattern doesn't contain `\` then this would work: `:%s/\Vpattern/\='string'` In all cases, when the pattern&replace string are in variables, this would work: ``` let pattern='<old>' let str='<new>' :exec "s/\\V" . escape(escape( pattern, '\'),'/') . "/\\=str" ``` of course, you can use different me...
26,947
<p>I just setup this mapping for my latex development:</p> <pre><code>nnoremap &lt;buffer&gt; &lt;LocalLeader&gt;o :make %:r.pdf &lt;Bar&gt; !open %:r.pdf&lt;CR&gt;&lt;CR&gt;&lt;CR&gt; </code></pre> <p>But I wondered about checking if <code>:make</code> fails before running <code>!open</code>, so that I don't open an o...
[ { "answer_id": 26948, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 2, "selected": false, "text": "<p>Vim <em>will</em> set <code>v:shell_error</code> with a <code>:make</code> invocation, same as it does for other w...
2020/08/22
[ "https://vi.stackexchange.com/questions/26947", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10604/" ]
I just setup this mapping for my latex development: ``` nnoremap <buffer> <LocalLeader>o :make %:r.pdf <Bar> !open %:r.pdf<CR><CR><CR> ``` But I wondered about checking if `:make` fails before running `!open`, so that I don't open an old version for some reason. I know if it were `:!make`, I could check `v:shellerr...
Vim *will* set `v:shell_error` with a `:make` invocation, same as it does for other ways it executes external commands using the shell. The most likely reason why you're not seeing the error code of the `make` execution in `v:shell_error` (and always seeing it return 0) is that on Unix platforms and most common shells...
26,952
<p>I'm not talking about learning or introducing commands, but how to work by switching between modes, and using normal known commands. Do most vim users stay more in normal mode instead of in insert mode? I find it impossible to use vim more in normal mode. Apart from Replace mode, how can anybody type without being i...
[ { "answer_id": 26958, "author": "Aivar Paalberg", "author_id": 30052, "author_profile": "https://vi.stackexchange.com/users/30052", "pm_score": 1, "selected": false, "text": "<p>I try to address this specific &quot;how&quot;: &quot;breaking the paragraph into point lines&quot;</p>\n<p>Na...
2020/08/22
[ "https://vi.stackexchange.com/questions/26952", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30744/" ]
I'm not talking about learning or introducing commands, but how to work by switching between modes, and using normal known commands. Do most vim users stay more in normal mode instead of in insert mode? I find it impossible to use vim more in normal mode. Apart from Replace mode, how can anybody type without being in I...
> > Do most vim users stay more in normal mode instead of in insert mode? I find > it impossible to use vim more in normal mode. Apart from Replace mode, how can > anybody type without being in Insert mode? > > > I don't know about "most vim users," but I edited your entire post mostly in normal mode. I'm typing t...
26,953
<p>My main problem is that I don't realize which mode I am in each time I use vim.</p> <p>Sometimes I forget to <code>&lt;ESC&gt;</code> into normal mode, hence pressing vim commands in insert mode. I have to waste time deleting those characters, but that's not the worst.</p> <p>The worst is when I don't realize I am i...
[ { "answer_id": 26959, "author": "Aivar Paalberg", "author_id": 30052, "author_profile": "https://vi.stackexchange.com/users/30052", "pm_score": 1, "selected": false, "text": "<p>There are several ways to distinct between modes. First of all - if not in normal mode then in lower left corn...
2020/08/22
[ "https://vi.stackexchange.com/questions/26953", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30744/" ]
My main problem is that I don't realize which mode I am in each time I use vim. Sometimes I forget to `<ESC>` into normal mode, hence pressing vim commands in insert mode. I have to waste time deleting those characters, but that's not the worst. The worst is when I don't realize I am in command mode, and I do several...
I don't know how to program, i just found this code from internet and twig it into workable .. there might got some useless code inside. I have entered this into .vimrc It will make Insert mode status line to be red color "1" Replace mode into green color "2" Normal mode statusline white color. ``` function! InsertSt...
26,964
<p>I'm asking about <a href="https://learnvimscriptthehardway.stevelosh.com/chapters/23.html#implicit-returning" rel="nofollow noreferrer">this</a> code snippet:</p> <pre><code>:function TextwidthIsTooWide() : if &amp;l:textwidth &gt;# 80 : return 1 : endif :endfunction </code></pre> <p>This is what <a href="https...
[ { "answer_id": 26965, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 2, "selected": false, "text": "<p>This is all told under <code>:h :let-option</code>, but, to put it short, <code>let &amp;option=&quot;value&quot;</code>...
2020/08/23
[ "https://vi.stackexchange.com/questions/26964", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9602/" ]
I'm asking about [this](https://learnvimscriptthehardway.stevelosh.com/chapters/23.html#implicit-returning) code snippet: ``` :function TextwidthIsTooWide() : if &l:textwidth ># 80 : return 1 : endif :endfunction ``` This is what [vim-help](https://vimhelp.org/eval.txt.html#local-variable) says on the `l` (loca...
This is all told under `:h :let-option`, but, to put it short, `let &option="value"` is the same as `set option=value`, `let &l:option="value"` is the same as `setlocal option=value`, and `let &g:option="value"` is `setglobal option=value`. So your last point is actually about the difference between `set/setglobal/set...
26,985
<p>I have this perl regex:</p> <p><code>s/(^(#+)\s.*?\g2)/$1 =~ s|\n| |rg/gmse</code></p> <p>It strips out all new lines between <code>##+</code> characters and replaces them with a space. It'll take a string like:</p> <pre><code>before text more text ### hjh jh ja jhjasdhf jh'j asdk kas dkjakdjf kasjd fkjasdkfj kajsdk...
[ { "answer_id": 26987, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 3, "selected": true, "text": "<p>You can use the <a href=\"https://vimhelp.org/eval.txt.html#substitute%28%29\" rel=\"nofollow noreferrer\"><code>su...
2020/08/24
[ "https://vi.stackexchange.com/questions/26985", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2021/" ]
I have this perl regex: `s/(^(#+)\s.*?\g2)/$1 =~ s|\n| |rg/gmse` It strips out all new lines between `##+` characters and replaces them with a space. It'll take a string like: ``` before text more text ### hjh jh ja jhjasdhf jh'j asdk kas dkjakdjf kasjd fkjasdkfj kajsdkjf kasjdf end ### after text ``` and change i...
You can use the [`substitute()`](https://vimhelp.org/eval.txt.html#substitute%28%29) function to do a text replacement on the replacement side of a `:s` command. And you can use [`submatch()`](https://vimhelp.org/eval.txt.html#submatch%28%29) to have access to the matched groups, including `submatch(0)` for the whole m...
26,995
<p>I'm trying to set up pylint to work with <code>:make</code> command in Vim 8.2.</p> <p>I've set <code>:compiler pylint</code> but running <code>:make</code> gives me pylint's help message, so some arguments seem to be passed incorrectly.</p> <p><code>:set makeprg?</code> is</p> <pre><code>makeprg=pylint --output-for...
[ { "answer_id": 26996, "author": "xaxa", "author_id": 31149, "author_profile": "https://vi.stackexchange.com/users/31149", "pm_score": 2, "selected": false, "text": "<p>(Thanks to @d-ben-knoble)</p>\n<p><code>makeprg</code> does not include filename, so</p>\n<pre><code>:make %\n</code></p...
2020/08/25
[ "https://vi.stackexchange.com/questions/26995", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/31149/" ]
I'm trying to set up pylint to work with `:make` command in Vim 8.2. I've set `:compiler pylint` but running `:make` gives me pylint's help message, so some arguments seem to be passed incorrectly. `:set makeprg?` is ``` makeprg=pylint --output-format=text --msg-template="{path}:{line}:{column}:{C}: [{symbol}] {msg}...
> > how to debug it? > > > You can use the [`:verbose`](https://vimhelp.org/various.txt.html#%3Averbose) command to increase verbosity of a specific command. In this particular case, [you need verbosity level above 3 to see the actual shell command executed by Vim](https://github.com/vim/vim/blob/v8.2.0/src/misc2...
27,003
<p>I've known that Vim 8 provides us an async mechanism <code>job_start</code> so that we can start a command asynchronously and get its return with the help of channel.</p> <p>However, it seems that <code>job_start</code> can only execute the OS command, such as <code>make</code>, <code>grep</code>, <code>/bin/sh</cod...
[ { "answer_id": 27032, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 4, "selected": true, "text": "<p>From discussion in comments I learned that OP has a custom vimgrep call and would like to run it asynchronously. The u...
2020/08/26
[ "https://vi.stackexchange.com/questions/27003", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10003/" ]
I've known that Vim 8 provides us an async mechanism `job_start` so that we can start a command asynchronously and get its return with the help of channel. However, it seems that `job_start` can only execute the OS command, such as `make`, `grep`, `/bin/sh` etc. Is it possible to call a vim script function with the h...
From discussion in comments I learned that OP has a custom vimgrep call and would like to run it asynchronously. The utility of this is pretty clear, especially if you run a lot of searches that take a while: by moving the execution into the "background" you free up Vim's UI so you can continue working without waiting ...
27,015
<pre><code>function! GitBranch() return system(&quot;git rev-parse --abbrev-ref HEAD 2&gt;/dev/null | tr -d '\n'&quot;) endfunction function! StatuslineGit() let l:branchname = GitBranch() return strlen(l:branchname) &gt; 0?' '.l:branchname.' ':'' endfunction set laststatus=2 set statusline+=%#PmenuSel# set st...
[ { "answer_id": 27028, "author": "Ari Sweedler", "author_id": 14861, "author_profile": "https://vi.stackexchange.com/users/14861", "pm_score": 0, "selected": false, "text": "<p><code>^[</code> is a representation of <code>&lt;Esc&gt;</code>, the escape key. When you scroll up or down usin...
2020/08/27
[ "https://vi.stackexchange.com/questions/27015", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/31172/" ]
``` function! GitBranch() return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'") endfunction function! StatuslineGit() let l:branchname = GitBranch() return strlen(l:branchname) > 0?' '.l:branchname.' ':'' endfunction set laststatus=2 set statusline+=%#PmenuSel# set statusline+=%{StatuslineG...
`:help system()` tells you about this: ``` system({expr} [, {input}]) *system()* *E677* [...] When prepended by |:silent| the terminal will not be set to cooked mode. This is meant to be used for commands that do not need the user to type. It avoids stray characters showing up on the...
27,023
<p>I want to add support for various formats of filenename with linenumber for vim to understand. E.g. I get output from <code>git grep &lt;keyword&gt;</code> like this:</p> <pre><code>first/foo.py:123: first/bar.py:333: second/foo.py:777: </code></pre> <p>To open these files and jump to a specific line I have to chang...
[ { "answer_id": 27027, "author": "Ari Sweedler", "author_id": 14861, "author_profile": "https://vi.stackexchange.com/users/14861", "pm_score": 2, "selected": false, "text": "<p>This doesn't answer your question, but it does answer your use-case.</p>\n<p>If you do <code>:let &amp;grepprg =...
2020/08/27
[ "https://vi.stackexchange.com/questions/27023", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/147/" ]
I want to add support for various formats of filenename with linenumber for vim to understand. E.g. I get output from `git grep <keyword>` like this: ``` first/foo.py:123: first/bar.py:333: second/foo.py:777: ``` To open these files and jump to a specific line I have to change the format to e.g.: ``` first/foo.py +...
> > I wonder if there is a way to automatically make this conversion so that in command line this statement: `vim first/foo.py:123:` would have the same result as this command: `vim first/foo.py +123`. > > > There's a Vim plug-in that implements precisely that: [lervag/file-line](https://github.com/lervag/file-lin...
27,063
<p>I'm rather new to vim. And I don't like much to install many packages.</p> <p>I use html, javascript and react.js, and i would like to create some simple way to type and then have the correct snippet on the file.</p> <p>It would be only 5 or 6 snippets, can you give me a hand on where to start learning this art?</p>...
[ { "answer_id": 27065, "author": "Jake Grossman", "author_id": 31207, "author_profile": "https://vi.stackexchange.com/users/31207", "pm_score": 2, "selected": false, "text": "<p><strong>TL;DR</strong>: Check out <code>:help abbreviations.</code></p>\n<h2>Example:</h2>\n<p>Let's say I want...
2020/08/29
[ "https://vi.stackexchange.com/questions/27063", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/31134/" ]
I'm rather new to vim. And I don't like much to install many packages. I use html, javascript and react.js, and i would like to create some simple way to type and then have the correct snippet on the file. It would be only 5 or 6 snippets, can you give me a hand on where to start learning this art? --- **Edit** Th...
**TL;DR**: Check out `:help abbreviations.` Example: -------- Let's say I wanted to make a snippet to quickly create a JavaScript object in the following format with the abbreviation "obj" (`|` represents the cursor position after doing the abbreviation): ``` var foo = {|}; ``` I could do: ``` iabbrev obj var foo...
27,069
<p>If I have file1.txt which contains the following:</p> <pre><code>Line 1.1; Line 1.2; Line 1.3; </code></pre> <p>and file2.txt with the following</p> <pre><code>Line 2.1; Line 2.2; Line 2.3; </code></pre> <p>I want to copy all the lines of file2.txt and paste it to file1.txt in a way that stays like this:</p> <pre><c...
[ { "answer_id": 27070, "author": "user938271", "author_id": 17449, "author_profile": "https://vi.stackexchange.com/users/17449", "pm_score": 2, "selected": false, "text": "<ol>\n<li><p>Yank the second paragraph (e.g. <code>yip</code>).</p>\n</li>\n<li><p>Visually select the first paragrap...
2020/08/29
[ "https://vi.stackexchange.com/questions/27069", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30520/" ]
If I have file1.txt which contains the following: ``` Line 1.1; Line 1.2; Line 1.3; ``` and file2.txt with the following ``` Line 2.1; Line 2.2; Line 2.3; ``` I want to copy all the lines of file2.txt and paste it to file1.txt in a way that stays like this: ``` Line 1.1;Line 2.1; Line 1.2;Line 2.2; Line 1.3;Line...
On a \*nix system, I would use `paste` first: ``` %!paste - file2.txt ``` And then you have lots of options to get rid of the tabs. You could add `| sed 's/<C-v><Tab>//g'` to the end of the pipeline above, or use the (very similar!) command ``` %substitute/\t//g ``` which permits abbreviation as `:%s/\t//g`.
27,104
<p>Very often, after days and days of coding, opening <code>vim -S session</code> everytime, I end up with a fair long buffer list that I want to clean.</p> <p>Therefore I use <code>:ls</code> to list all buffers, and then <code>:bdelete</code> several times, with a range of buffer numbers and or explicitly specifying ...
[ { "answer_id": 27105, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 3, "selected": true, "text": "<p>For my config I wrote this:</p>\n<blockquote>\n<p>~/.vim/autoload/misc.vim</p>\n</blockquote>\n<pre><code>&quot; Wipe all...
2020/09/02
[ "https://vi.stackexchange.com/questions/27104", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6498/" ]
Very often, after days and days of coding, opening `vim -S session` everytime, I end up with a fair long buffer list that I want to clean. Therefore I use `:ls` to list all buffers, and then `:bdelete` several times, with a range of buffer numbers and or explicitly specifying buffer names. The weak points in this app...
For my config I wrote this: > > ~/.vim/autoload/misc.vim > > > ``` " Wipe all deleted (unloaded & unlisted) or all unloaded buffers function! misc#bwipeout(listed) abort let l:buffers = filter(getbufinfo(), {_, v -> !v.loaded && (!v.listed || a:listed)}) if !empty(l:buffers) execute 'bwipeout' joi...
27,108
<p>I downloaded vim-fetch, but the install instructions are not clear to me:</p> <blockquote> <p>Download and source the most current vimball from the releases list, then run :helptags {dir} on your runtimepath/doc directory. Or, if you use a git-based plug-in manager (like Pathogen, Vundle, NeoBundle etc.), simply add...
[ { "answer_id": 27105, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 3, "selected": true, "text": "<p>For my config I wrote this:</p>\n<blockquote>\n<p>~/.vim/autoload/misc.vim</p>\n</blockquote>\n<pre><code>&quot; Wipe all...
2020/09/02
[ "https://vi.stackexchange.com/questions/27108", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/31262/" ]
I downloaded vim-fetch, but the install instructions are not clear to me: > > Download and source the most current vimball from the releases list, then run :helptags {dir} on your runtimepath/doc directory. > Or, if you use a git-based plug-in manager (like Pathogen, Vundle, NeoBundle etc.), simply add wsdjeg/vim-fet...
For my config I wrote this: > > ~/.vim/autoload/misc.vim > > > ``` " Wipe all deleted (unloaded & unlisted) or all unloaded buffers function! misc#bwipeout(listed) abort let l:buffers = filter(getbufinfo(), {_, v -> !v.loaded && (!v.listed || a:listed)}) if !empty(l:buffers) execute 'bwipeout' joi...
27,115
<p>In my .vimrc file I have listchars set to showing tabs and trailing spaces.</p> <pre><code>set listchars=trail:~,tab:&gt;- </code></pre> <p>How do I change my settings for the file I currently have open to stop showing the tabs?</p>
[ { "answer_id": 27118, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 2, "selected": true, "text": "<p>In vim, <code>listchars</code> is a global setting, so it is not possible to configure it per-window.</p>\n<p>It is possi...
2020/09/03
[ "https://vi.stackexchange.com/questions/27115", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/31275/" ]
In my .vimrc file I have listchars set to showing tabs and trailing spaces. ``` set listchars=trail:~,tab:>- ``` How do I change my settings for the file I currently have open to stop showing the tabs?
In vim, `listchars` is a global setting, so it is not possible to configure it per-window. It is possible however to turn on and off `list`, using `setlocal list` and `setlocal nolist`. In neovim, `listchars` is a global or local-to-window setting. So to configure it per window you merely need to use ``` setlocal li...
27,123
<p>I'm displaying a file contents by using <code>:pedit …the-file-path…</code>, to then call <code>popup_setoptions(…the-ID…,#{firstline:anumber})</code> in order to scroll the popup and highlight/show the desired part of the file.</p> <p>There's however one problem — the folds are closed by default and thus they <stro...
[ { "answer_id": 27126, "author": "user938271", "author_id": 17449, "author_profile": "https://vi.stackexchange.com/users/17449", "pm_score": 4, "selected": true, "text": "<blockquote>\n<p>What I've tried is a exe ':'.pupid.'windo norm! zi' however the command fails upfront with and 'Inval...
2020/09/04
[ "https://vi.stackexchange.com/questions/27123", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11859/" ]
I'm displaying a file contents by using `:pedit …the-file-path…`, to then call `popup_setoptions(…the-ID…,#{firstline:anumber})` in order to scroll the popup and highlight/show the desired part of the file. There's however one problem — the folds are closed by default and thus they **hide** the file contents… How to o...
> > What I've tried is a exe ':'.pupid.'windo norm! zi' however the command fails upfront with and 'Invalid range` error. The pupid is being obtained via popup\_findpreview() and is correct. > > > That's because [`popup_findpreview()`](https://vimhelp.org/popup.txt.html#popup_findpreview()) gives you a window *ID*...
27,138
<p>I have a file <code>foo.txt</code> with just a one line <code>ab</code>. I want to launch Vim in such a way that it will open this file, swap characters using <code>xp</code>, and then save it as <code>bar.txt</code>.</p> <p>Something like this:</p> <pre><code>gvim foo.txt xp :wq &gt; bar.txt </code></pre> <p>I'm no...
[ { "answer_id": 27139, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 3, "selected": true, "text": "<p>You can use Ex commands (linux version using pipes):</p>\n<pre><code>printf '%s\\n' 'normal! xp' 'saveas bar.txt...
2020/09/05
[ "https://vi.stackexchange.com/questions/27138", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7200/" ]
I have a file `foo.txt` with just a one line `ab`. I want to launch Vim in such a way that it will open this file, swap characters using `xp`, and then save it as `bar.txt`. Something like this: ``` gvim foo.txt xp :wq > bar.txt ``` I'm not sure it is possible. Any suggestions?
You can use Ex commands (linux version using pipes): ``` printf '%s\n' 'normal! xp' 'saveas bar.txt' 'q!' | ex foo.txt ``` `vim -e` and `vim -E` can usually be used as a substitute for `ex`. Or use a custom script: ``` gvim -S mycmds.vim foo.txt ``` Where the file contains arbitrary Ex commands: ``` normal! xp ...
27,158
<p>I have a (copy of) oracle listener log, and would like to replace the portnumber in every line. These are always of the form <code>(PORT=1234)</code> with sometimes 4 and sometimes 5 numbers.</p> <p>So an exampleline, and I've anonimized it completely, but there are thousands of lines:</p> <pre><code>07-SEP-2020 06...
[ { "answer_id": 27159, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 1, "selected": false, "text": "<p>You can use a <code>:s</code> command with a pattern that matches the port number and a replacement of <code>xxxxx...
2020/09/07
[ "https://vi.stackexchange.com/questions/27158", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/31310/" ]
I have a (copy of) oracle listener log, and would like to replace the portnumber in every line. These are always of the form `(PORT=1234)` with sometimes 4 and sometimes 5 numbers. So an exampleline, and I've anonimized it completely, but there are thousands of lines: ``` 07-SEP-2020 06:34:05 * (CONNECT_DATA=(SERVICE...
You can use a `:s` command with a pattern that matches the port number and a replacement of `xxxxx` (or whatever you prefer.) Use a range of `%` to match the whole file. When matching the pattern itself, a very useful feature of Vim regexes is [`\zs`](https://vimhelp.org/pattern.txt.html#%2F%5Czs) and [`\ze`](https://...
27,160
<p>I have a window in vim opened (current file) and another one in split called <code>[Scratch]</code>. I want to check if the <code>[Scratch]</code> is open or not.</p> <p>Any example is appreciated.</p>
[ { "answer_id": 27162, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 3, "selected": true, "text": "<p>The problem with <code>[Scratch]</code> itself is that that's not really the name of a buffer, but just Vim telling...
2020/09/07
[ "https://vi.stackexchange.com/questions/27160", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30351/" ]
I have a window in vim opened (current file) and another one in split called `[Scratch]`. I want to check if the `[Scratch]` is open or not. Any example is appreciated.
The problem with `[Scratch]` itself is that that's not really the name of a buffer, but just Vim telling you that this scratch buffer is actually unnamed... It's much easier if you start with a named buffer and use `bufadd()` to create it. For example: ``` let bufnr = bufadd('MyFancyScratchBuffer') execute 'sb' bufnr...
27,161
<p>I'd like to use <code>ls</code> command to show opened buffers.</p> <p>I'd like to make the output of this command as simple as possible. I'd like to see only the buffers' names, numbers and status (#,%,+,..).</p> <p>I don't need to see the first line in the result that shows the full path of the current file and al...
[ { "answer_id": 27164, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 1, "selected": false, "text": "<blockquote>\n<p>Is there a way to make <code>ls</code> output that simple?</p>\n</blockquote>\n<p>Not natively... Vi...
2020/09/07
[ "https://vi.stackexchange.com/questions/27161", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16800/" ]
I'd like to use `ls` command to show opened buffers. I'd like to make the output of this command as simple as possible. I'd like to see only the buffers' names, numbers and status (#,%,+,..). I don't need to see the first line in the result that shows the full path of the current file and also don't need to see the b...
Try this: ``` command -bar -bang Ls call s:ls(<bang>0) function s:ls(bang) abort let bufnrs = range(1, bufnr('$')) call filter(bufnrs, a:bang ? {_, v -> bufexists(v)} : {_, v -> buflisted(v)}) let bufnames = copy(bufnrs) \ ->map({_, v -> bufname(v)->fnamemodify(':t')}) let uniq_flags = copy(bu...
27,176
<p>Following an example such as:</p> <pre><code>##1## many text and lines ##z## ##2## more text ##z## ...etc </code></pre> <p>How could i make the line number display only on chunks of text, inside of the ##digit## and the ##z## string? Something like this:</p> <pre><code>0 ##1## 1 many text 2 and lines 0 ##z## 0 ##2##...
[ { "answer_id": 27164, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 1, "selected": false, "text": "<blockquote>\n<p>Is there a way to make <code>ls</code> output that simple?</p>\n</blockquote>\n<p>Not natively... Vi...
2020/09/08
[ "https://vi.stackexchange.com/questions/27176", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30351/" ]
Following an example such as: ``` ##1## many text and lines ##z## ##2## more text ##z## ...etc ``` How could i make the line number display only on chunks of text, inside of the ##digit## and the ##z## string? Something like this: ``` 0 ##1## 1 many text 2 and lines 0 ##z## 0 ##2## 1 more text 0 ##z## ``` So that...
Try this: ``` command -bar -bang Ls call s:ls(<bang>0) function s:ls(bang) abort let bufnrs = range(1, bufnr('$')) call filter(bufnrs, a:bang ? {_, v -> bufexists(v)} : {_, v -> buflisted(v)}) let bufnames = copy(bufnrs) \ ->map({_, v -> bufname(v)->fnamemodify(':t')}) let uniq_flags = copy(bu...