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
15,944
<p>I've seen this question:</p> <p><a href="https://vi.stackexchange.com/questions/93/is-there-a-way-to-count-the-number-of-occurrences-of-a-word-in-a-file/100">Is there a way to count the number of occurrences of a word in a file?</a></p> <p>but most of the time I search using <kbd>*</kbd> or just <kbd>/</kbd>.</p> ...
[ { "answer_id": 17735, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 3, "selected": false, "text": "<p>If you use the <a href=\"https://github.com/vim-airline/vim-airline/\" rel=\"noreferrer\">vim-airline</a> Plugin...
2018/04/16
[ "https://vi.stackexchange.com/questions/15944", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2710/" ]
I've seen this question: [Is there a way to count the number of occurrences of a word in a file?](https://vi.stackexchange.com/questions/93/is-there-a-way-to-count-the-number-of-occurrences-of-a-word-in-a-file/100) but most of the time I search using `\*` or just `/`. It is possible to display automatically in the s...
### [vim 8.1.1270](https://github.com/vim/vim/commit/9dfa3139198b38b28673e251a3756430065914e9) (May 2019) `:set shortmess-=S` Since May 2019 vim offers the possibility to show the count in the statusline (as long as it less than 99) which however is disabled by default. Add to your vimrc ``` set shortmess-=S ``` or...
15,945
<p>I would like to store the result of a <code>system()</code> call in a variable without the trailing <code>^@</code> character. At the moment I do something like</p> <pre><code>var = system('command | xargs -i echo -n "{}"') </code></pre> <p>but it feels convoluted. Is there a simpler solution?</p>
[ { "answer_id": 15946, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>You probably want to use <a href=\"http://vimhelp.appspot.com/eval.txt.html#systemlist%28%29\" rel=\"noreferrer\"><code>...
2018/04/16
[ "https://vi.stackexchange.com/questions/15945", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11125/" ]
I would like to store the result of a `system()` call in a variable without the trailing `^@` character. At the moment I do something like ``` var = system('command | xargs -i echo -n "{}"') ``` but it feels convoluted. Is there a simpler solution?
If you don't want to use `systemlist` for whatever reason, you can explicitly remove the newline and/or whitespace. Since vim 8.0.1630 (very recent), there is a `trim()` function which removes whitespace, including newline, from the *front and the back* of a string. ``` trim(system('command')) ``` A common way, if y...
15,950
<p>If I have this line:</p> <pre><code>a{word} a{20] a{word} a{20] </code></pre> <p>and type <code>:g/a{.\{-}\]/s/{/\[/gc</code> vi prompts me to change all four occurrences of <code>{</code> to <code>[</code>.</p> <p>I want it to prompt me to replace only the matches that occur immediately to the right of t...
[ { "answer_id": 15946, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>You probably want to use <a href=\"http://vimhelp.appspot.com/eval.txt.html#systemlist%28%29\" rel=\"noreferrer\"><code>...
2018/04/16
[ "https://vi.stackexchange.com/questions/15950", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4667/" ]
If I have this line: ``` a{word} a{20] a{word} a{20] ``` and type `:g/a{.\{-}\]/s/{/\[/gc` vi prompts me to change all four occurrences of `{` to `[`. I want it to prompt me to replace only the matches that occur immediately to the right of the cursor after finding a match, i.e., to prompt me to change only t...
If you don't want to use `systemlist` for whatever reason, you can explicitly remove the newline and/or whitespace. Since vim 8.0.1630 (very recent), there is a `trim()` function which removes whitespace, including newline, from the *front and the back* of a string. ``` trim(system('command')) ``` A common way, if y...
15,959
<p>I am trying to setup my development environment using vim and some plugins.</p> <p>My workspace root is a directory with very large number of sub-directories and files. I am going to be working on files from a <strong>very very small subset</strong> of this root directory.</p> <p>For a simplified overview,</p> <u...
[ { "answer_id": 15988, "author": "LEI", "author_id": 12003, "author_profile": "https://vi.stackexchange.com/users/12003", "pm_score": 2, "selected": false, "text": "<p>It is possible using the <a href=\"https://github.com/justinmk/vim-dirvish\" rel=\"nofollow noreferrer\">dirvish</a> file...
2018/04/18
[ "https://vi.stackexchange.com/questions/15959", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17209/" ]
I am trying to setup my development environment using vim and some plugins. My workspace root is a directory with very large number of sub-directories and files. I am going to be working on files from a **very very small subset** of this root directory. For a simplified overview, * My workspace root directory ($work...
It is possible using the [dirvish](https://github.com/justinmk/vim-dirvish) file explorer, which by the way is much faster than the native netrw. This plugin allows to manipulate the content of its buffer (see "How do I filter" in `:h dirvish-faq`) and has an option to automatically execute a command. Keep in mind tha...
15,967
<p>I just found out about this option in vim !!! </p> <pre><code>let g:lisp_rainbow = 1 </code></pre> <p>It's pretty exciting to learn something so useful. I can't figure out how to customize it though. Specially, I want to expel the prominent red colored parenthesis out of the available options.</p> <p>I know I can...
[ { "answer_id": 15979, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p>I assume when you say \"customize\" you don't mean anything besides changing the parentheses colors. Look in <code>$VI...
2018/04/18
[ "https://vi.stackexchange.com/questions/15967", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16280/" ]
I just found out about this option in vim !!! ``` let g:lisp_rainbow = 1 ``` It's pretty exciting to learn something so useful. I can't figure out how to customize it though. Specially, I want to expel the prominent red colored parenthesis out of the available options. I know I can do it with some plugins. But the...
I assume when you say "customize" you don't mean anything besides changing the parentheses colors. Look in `$VIMRUNTIME/syntax/lisp.vim` and search for "lisp\_rainbow" and you'll find this ``` if &bg == "dark" hi def hlLevel0 ctermfg=red guifg=red1 hi def hlLevel1 ctermfg=yellow guifg=orange1 ...
15,974
<p>For example:</p> <p>I have several lines starting with <code>:q:</code>, which I want to jump to:</p> <pre><code>:q: regex syntax (...) :q: regex examples (...) </code></pre> <p>Now I want to jump to the start of <code>regex syntax</code> or <code>regex example</code> with a specific regex find expression via <co...
[ { "answer_id": 15975, "author": "flemingfleming", "author_id": 16910, "author_profile": "https://vi.stackexchange.com/users/16910", "pm_score": 4, "selected": true, "text": "<p>You can use <code>\\zs</code> (and it's complement, <code>\\ze</code>), e.g.</p>\n\n<pre><code>/:q: \\zs\n</cod...
2018/04/18
[ "https://vi.stackexchange.com/questions/15974", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6300/" ]
For example: I have several lines starting with `:q:`, which I want to jump to: ``` :q: regex syntax (...) :q: regex examples (...) ``` Now I want to jump to the start of `regex syntax` or `regex example` with a specific regex find expression via `/`. Is this possible? Why not just use `W` to jump to it? Well, it ...
You can use `\zs` (and it's complement, `\ze`), e.g. ``` /:q: \zs ``` should work for your example (assuming there is exactly 1 space after the second `:`) It works by setting the start (or end in the case of `\ze`) of the matching text to a point somewhere in the middle of the regex. Check out `:h \zs`, it has a m...
15,987
<p>I write using LaTeX a lot for scientific writing. I often need to modify some text that includes numbers and units like:</p> <pre><code>4.2 cm </code></pre> <p>into:</p> <pre><code>\SI{4.2}{cm} </code></pre> <p>to be properly typeset by LaTeX. Of course, the exact number and unit can change.</p> <p>I would like...
[ { "answer_id": 15975, "author": "flemingfleming", "author_id": 16910, "author_profile": "https://vi.stackexchange.com/users/16910", "pm_score": 4, "selected": true, "text": "<p>You can use <code>\\zs</code> (and it's complement, <code>\\ze</code>), e.g.</p>\n\n<pre><code>/:q: \\zs\n</cod...
2018/04/19
[ "https://vi.stackexchange.com/questions/15987", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7213/" ]
I write using LaTeX a lot for scientific writing. I often need to modify some text that includes numbers and units like: ``` 4.2 cm ``` into: ``` \SI{4.2}{cm} ``` to be properly typeset by LaTeX. Of course, the exact number and unit can change. I would like to know a "magic" command I can do that—when `4.2 cm` i...
You can use `\zs` (and it's complement, `\ze`), e.g. ``` /:q: \zs ``` should work for your example (assuming there is exactly 1 space after the second `:`) It works by setting the start (or end in the case of `\ze`) of the matching text to a point somewhere in the middle of the regex. Check out `:h \zs`, it has a m...
16,013
<p>I am at the end of hour-long research on why I cannot install vim with proper python support. Problems already recognized: Impossible to install python 2 and 3 support together on ubuntu 16.04; oh well.</p> <p>After finding <a href="https://gist.github.com/klen/3d327e5f84e36dc04bd7" rel="nofollow noreferrer">this g...
[ { "answer_id": 15975, "author": "flemingfleming", "author_id": 16910, "author_profile": "https://vi.stackexchange.com/users/16910", "pm_score": 4, "selected": true, "text": "<p>You can use <code>\\zs</code> (and it's complement, <code>\\ze</code>), e.g.</p>\n\n<pre><code>/:q: \\zs\n</cod...
2018/04/22
[ "https://vi.stackexchange.com/questions/16013", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17075/" ]
I am at the end of hour-long research on why I cannot install vim with proper python support. Problems already recognized: Impossible to install python 2 and 3 support together on ubuntu 16.04; oh well. After finding [this gist detailing options someone got to work with pyenv and OSX](https://gist.github.com/klen/3d32...
You can use `\zs` (and it's complement, `\ze`), e.g. ``` /:q: \zs ``` should work for your example (assuming there is exactly 1 space after the second `:`) It works by setting the start (or end in the case of `\ze`) of the matching text to a point somewhere in the middle of the regex. Check out `:h \zs`, it has a m...
16,020
<p>When toggling folds with <kbd>z</kbd><kbd>i</kbd>, any folds expanding above the current line cause the current line to disorientingly jump to a different place on the screen.</p> <p>How can I keep the current line fixed in the same place while toggling folds?</p>
[ { "answer_id": 16022, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": -1, "selected": false, "text": "<p>Instead of <code>zi</code> you should use <code>zo</code> to open a fold and <code>zc</code> to close it or <code>za</c...
2018/04/23
[ "https://vi.stackexchange.com/questions/16020", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6079/" ]
When toggling folds with `z``i`, any folds expanding above the current line cause the current line to disorientingly jump to a different place on the screen. How can I keep the current line fixed in the same place while toggling folds?
You could create a mapping and use it instead of using zi. Create a mark for the current position and one for the top of the visible buffer, apply zi, move to the top, move the buffer, then move back to the original position. ``` nnoremap <Leader>zi maHmb'azi'bzt`a ```
16,024
<p>I'm new to Vim, and for the paste couple of weeks, I've been using NERDTree with no problems. However, I recently added a few key mappings and am now unable to open NERDTree with the <code>&lt;C-n&gt;</code> command. Nothing happens when I run the command.</p> <p>Here's the part of my <code>.vimrc</code> that I fou...
[ { "answer_id": 16025, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 3, "selected": true, "text": "<p>The problem is that when you invoke your Tabularize mapping, the <code>:</code> in the right-hand-side of the mapping is rema...
2018/04/23
[ "https://vi.stackexchange.com/questions/16024", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17269/" ]
I'm new to Vim, and for the paste couple of weeks, I've been using NERDTree with no problems. However, I recently added a few key mappings and am now unable to open NERDTree with the `<C-n>` command. Nothing happens when I run the command. Here's the part of my `.vimrc` that I found to be causing the problem. ``` " M...
The problem is that when you invoke your Tabularize mapping, the `:` in the right-hand-side of the mapping is remapped to a `;` by your colon map, and the keystrokes that are then invoked are: ``` ;Tabularize /=<CR> ``` In order to fix this, you need to tell your Tabularize mapping to ignore existing mappings, and i...
16,037
<p>Everytime I cut out of a session in vim by losing my connection I'm rather filled with dred (and yet I continue to use vim...what a masochistist I must be) because when I open my files again a pile of swap-files are waiting to take a shot at destroying my work. What are the best practices for working with vim swap...
[ { "answer_id": 16047, "author": "flemingfleming", "author_id": 16910, "author_profile": "https://vi.stackexchange.com/users/16910", "pm_score": 6, "selected": true, "text": "<h3>Don't Panic!</h3>\n\n<p>Recovering files is <em>always</em> safe, because vim <em>never</em> writes any change...
2018/04/25
[ "https://vi.stackexchange.com/questions/16037", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1065/" ]
Everytime I cut out of a session in vim by losing my connection I'm rather filled with dred (and yet I continue to use vim...what a masochistist I must be) because when I open my files again a pile of swap-files are waiting to take a shot at destroying my work. What are the best practices for working with vim swap file...
### Don't Panic! Recovering files is *always* safe, because vim *never* writes any changes until you write them yourself. So recovering from a swap file and then closing without saving won't change anything. ### Organize your swapfiles: Get vim to put all your swap files in the same place, so you always know where t...
16,052
<p>I noticed, that in any source code file, regardless of the programming language, I can use the dictionary autocompletion (<kbd>Ctrl</kbd> + <kbd>x</kbd> <kbd>Ctrl</kbd>+<kbd>k</kbd>) if the <code>spell</code> option is set, if it's not, then the editor gives an error message, "'dictionary' option is empty".</p> <p>...
[ { "answer_id": 16047, "author": "flemingfleming", "author_id": 16910, "author_profile": "https://vi.stackexchange.com/users/16910", "pm_score": 6, "selected": true, "text": "<h3>Don't Panic!</h3>\n\n<p>Recovering files is <em>always</em> safe, because vim <em>never</em> writes any change...
2018/04/26
[ "https://vi.stackexchange.com/questions/16052", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2798/" ]
I noticed, that in any source code file, regardless of the programming language, I can use the dictionary autocompletion (`Ctrl` + `x` `Ctrl`+`k`) if the `spell` option is set, if it's not, then the editor gives an error message, "'dictionary' option is empty". Is it possible to make the dictionary autocompletion enab...
### Don't Panic! Recovering files is *always* safe, because vim *never* writes any changes until you write them yourself. So recovering from a swap file and then closing without saving won't change anything. ### Organize your swapfiles: Get vim to put all your swap files in the same place, so you always know where t...
16,053
<p>I'm trying to automate cleaning up old vim undo files that are for files that have since been deleted.</p> <p>So far I've created a new vim script at <code>~/.vim/autoload/cleanupUndos.vim</code>: </p> <pre><code>function cleanupUndos#clean() let undofiles = systemlist('ls /Users/me/.vim/undodir/') for un...
[ { "answer_id": 16047, "author": "flemingfleming", "author_id": 16910, "author_profile": "https://vi.stackexchange.com/users/16910", "pm_score": 6, "selected": true, "text": "<h3>Don't Panic!</h3>\n\n<p>Recovering files is <em>always</em> safe, because vim <em>never</em> writes any change...
2018/04/23
[ "https://vi.stackexchange.com/questions/16053", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17300/" ]
I'm trying to automate cleaning up old vim undo files that are for files that have since been deleted. So far I've created a new vim script at `~/.vim/autoload/cleanupUndos.vim`: ``` function cleanupUndos#clean() let undofiles = systemlist('ls /Users/me/.vim/undodir/') for undofile in undofiles let ...
### Don't Panic! Recovering files is *always* safe, because vim *never* writes any changes until you write them yourself. So recovering from a swap file and then closing without saving won't change anything. ### Organize your swapfiles: Get vim to put all your swap files in the same place, so you always know where t...
16,065
<ol> <li>Is there a way I can directly import/insert the output of any linux command into vim editor? For example: <code>pwd</code> in currently open vim buffer.</li> </ol> <p>Also</p> <ol start="2"> <li>From terminal how can I directly open command output for manipulation? For example: opening <code>lshw</code> outp...
[ { "answer_id": 16066, "author": "JM. Marcastel", "author_id": 17308, "author_profile": "https://vi.stackexchange.com/users/17308", "pm_score": 3, "selected": true, "text": "<h3>Import shell output</h3>\n<p>Launch vi or vim and try:</p>\n<pre><code>!!pwd\n</code></pre>\n<p>The output will...
2018/04/27
[ "https://vi.stackexchange.com/questions/16065", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17317/" ]
1. Is there a way I can directly import/insert the output of any linux command into vim editor? For example: `pwd` in currently open vim buffer. Also 2. From terminal how can I directly open command output for manipulation? For example: opening `lshw` output in vim and filter unwanted info and quick save file.
### Import shell output Launch vi or vim and try: ``` !!pwd ``` The output will be pasted in the current buffer Checkout the possible options: ``` :help !! ``` ### Pipe `stdout` to vim Try: ``` pwd | vi - ```
16,068
<p>How to remove a line and paste it at the beginning of a range?</p> <pre><code>line 1 line 2 line 3 line 4 xxxxxxxx </code></pre> <p>For example, here I want to remove the 5th line and paste it before the first two lines, to change the buffer into this:</p> <pre><code>xxxxxxxxline 1 xxxxxxxxline 2 line 3 line 4 </...
[ { "answer_id": 16069, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>You can do the following, starting with your buffer like this and your cursor on the first <code>x</code> of the last li...
2018/04/27
[ "https://vi.stackexchange.com/questions/16068", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5181/" ]
How to remove a line and paste it at the beginning of a range? ``` line 1 line 2 line 3 line 4 xxxxxxxx ``` For example, here I want to remove the 5th line and paste it before the first two lines, to change the buffer into this: ``` xxxxxxxxline 1 xxxxxxxxline 2 line 3 line 4 ``` How to do that with a simple vim ...
Here's a couple of alternative methods. They're both a few more keystrokes than [@statox's answer](https://vi.stackexchange.com/a/16069/343), but I think they're worth posting because they show a few different techniques. Visual block mode & `Ctrl-R` ---------------------------- Like @statox, I'm presuming you start ...
16,071
<p>I have multiple lines like the once below in .vimrc file.</p> <pre><code>nnoremap \html :-1read $HOME/.vim/snippets/html_basic.snippet&lt;CR&gt; nnoremap \bs :-1read $HOME/.vim/snippets/bootstrap.snippet&lt;CR&gt; ... more snippets like these </code></pre> <p>Problem is if I want to change my snippet directory <...
[ { "answer_id": 16072, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 4, "selected": true, "text": "<p>One method is to use a <code>&lt;expr&gt;</code> mapping which evaluates the RHS of the mapping as Vimscript rather th...
2018/04/27
[ "https://vi.stackexchange.com/questions/16071", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17317/" ]
I have multiple lines like the once below in .vimrc file. ``` nnoremap \html :-1read $HOME/.vim/snippets/html_basic.snippet<CR> nnoremap \bs :-1read $HOME/.vim/snippets/bootstrap.snippet<CR> ... more snippets like these ``` Problem is if I want to change my snippet directory `$HOME/.vim/snippets` to something else...
One method is to use a `<expr>` mapping which evaluates the RHS of the mapping as Vimscript rather than use it literally as for regular mappings. The tricky part of this is the fact that we have two levels of variable expansion: `snippet_home` and the environment variable contained within, `$HOME`. The first approach ...
16,082
<p>In vim I sometimes want to quickly change the content of a variable using its current content as template using vim editing capabilities. </p> <p>For example I want to append the word "bar" to the existing variable <code>myvar</code>.</p> <pre><code>let myvar="foo" </code></pre> <p>A possible workflow could be a ...
[ { "answer_id": 16084, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 4, "selected": true, "text": "<p>You've picked an unfortunate example, as it's more easily achieved with:</p>\n\n<pre><code>let myvar .= 'bar'\n</code></pre>\...
2018/04/30
[ "https://vi.stackexchange.com/questions/16082", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/15083/" ]
In vim I sometimes want to quickly change the content of a variable using its current content as template using vim editing capabilities. For example I want to append the word "bar" to the existing variable `myvar`. ``` let myvar="foo" ``` A possible workflow could be a ex-command (say `Edit`) editing myvar in a n...
You've picked an unfortunate example, as it's more easily achieved with: ``` let myvar .= 'bar' ``` Still, for more complicated edits, you could use the following commands: 1. Insert the variable into the buffer: ``` o<C-R>=myvar<CR> ``` N.B. In the above, `<C-R>` denotes a press of `Ctrl-R`, and `<CR>` is a pre...
16,085
<p>For indenting there's no problem. I enter the visual-block mode, select the block, enter insert mode, press <code>ctrl-t</code> (or just press <code>tab</code>), exit the visual-block mode, and the whole block is indented.</p> <p>So, for the following code:</p> <pre><code>def my_function(): print('entering my_fun...
[ { "answer_id": 16086, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 5, "selected": true, "text": "<p>You don't need to enter insert mode via visual-block mode to indent/outdent multiple lines: you can do it directly from visua...
2018/04/30
[ "https://vi.stackexchange.com/questions/16085", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13062/" ]
For indenting there's no problem. I enter the visual-block mode, select the block, enter insert mode, press `ctrl-t` (or just press `tab`), exit the visual-block mode, and the whole block is indented. So, for the following code: ``` def my_function(): print('entering my_function') print('leaving my_function') ``` R...
You don't need to enter insert mode via visual-block mode to indent/outdent multiple lines: you can do it directly from visual mode by pressing `>` for indent and `<` for outdent. (See `:help v_<` and `:help v_>`) To indent multiple levels, you can either repeat the operation by pressing `.` or pass a count to the `<`...
16,094
<p>Not sure if this one is possible, but say I have a file with two blocks of text, in this case English words and their French translations. eg:</p> <pre><code>vivre aimer étudier to live to like to study </code></pre> <p>Now I want to copy the second block and match them by position only, perhaps with a '-', eg:</...
[ { "answer_id": 16095, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 3, "selected": false, "text": "<p>Sure. A macro can do this without too much trouble. With your cursor on the first character of the first line (Anythi...
2018/04/30
[ "https://vi.stackexchange.com/questions/16094", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17359/" ]
Not sure if this one is possible, but say I have a file with two blocks of text, in this case English words and their French translations. eg: ``` vivre aimer étudier to live to like to study ``` Now I want to copy the second block and match them by position only, perhaps with a '-', eg: ``` vivre - to live aimer ...
While doing yank/put while iterating through the rows works fine this can actually be done with a single yank/put thanks to blockwise Visual mode. That is the mode you enter by hitting `Ctrl`+`V` from Normal mode. Since OP is flexible on the format and because some of this is probably new for a lot of folks I'll show ...
16,108
<h3>Problem</h3> <p>Anytime I switch to a colorscheme the background turns this ugly gray that gives everything a washed out look. Why does this happen, and how can I prevent it?</p> <p>Example screenshot—</p> <p><a href="https://i.stack.imgur.com/I2sUz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur....
[ { "answer_id": 16136, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 4, "selected": true, "text": "<h1>A quick rundown on colorschemes</h1>\n<p>See <code>:help :colorscheme</code>. Essentially it sources a file con...
2018/05/01
[ "https://vi.stackexchange.com/questions/16108", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/14882/" ]
### Problem Anytime I switch to a colorscheme the background turns this ugly gray that gives everything a washed out look. Why does this happen, and how can I prevent it? Example screenshot— [![Dracula scheme](https://i.stack.imgur.com/I2sUz.png)](https://i.stack.imgur.com/I2sUz.png) ### More details This does not...
A quick rundown on colorschemes =============================== See `:help :colorscheme`. Essentially it sources a file containing `:highlight` commands. What are highlight commands? ---------------------------- Statements of the form ``` :hi[ghlight] [default] {group-name} {key}={arg} .. ``` that highlight secti...
16,110
<p>We can get highlight group information by the following command</p> <pre><code>:hi[ghlight] {group-name} </code></pre> <p>But is it possible to get this information by given keyword? Something like this : </p> <pre><code>syn match Integer '\d\+' hi def link Integer Constant :hi '3' Integer xxx links to Constant ...
[ { "answer_id": 16113, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 4, "selected": true, "text": "<p>If I understand your question correctly, it's not possible to do exactly what you're asking. Vim needs the items to be in the...
2018/05/01
[ "https://vi.stackexchange.com/questions/16110", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11430/" ]
We can get highlight group information by the following command ``` :hi[ghlight] {group-name} ``` But is it possible to get this information by given keyword? Something like this : ``` syn match Integer '\d\+' hi def link Integer Constant :hi '3' Integer xxx links to Constant ```
If I understand your question correctly, it's not possible to do exactly what you're asking. Vim needs the items to be in their correct context in order to determine what highlighting applies to them. However, you *can* ask Vim what syntax items are currently being applied. See the example at the end of `:help synID()...
16,148
<p>When I press <code>&lt;Esc&gt;</code> from insert mode, it delayed about 1 sec, but if I just do <code>&lt;ctrl+c&gt;</code> instead it is fast.</p> <p>I checked if there were mapping with escape with <code>:verbose imap &lt;Esc&gt;</code>, but I didn't find any.</p>
[ { "answer_id": 16151, "author": "JM. Marcastel", "author_id": 17308, "author_profile": "https://vi.stackexchange.com/users/17308", "pm_score": 1, "selected": false, "text": "<p>The latency you experience is most probably the consequence of some plugin.\nSee <a href=\"https://stackoverflo...
2018/05/04
[ "https://vi.stackexchange.com/questions/16148", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17420/" ]
When I press `<Esc>` from insert mode, it delayed about 1 sec, but if I just do `<ctrl+c>` instead it is fast. I checked if there were mapping with escape with `:verbose imap <Esc>`, but I didn't find any.
There are two kinds of delay when you press `<esc>` in insert mode: **mapping delay** If you create some improper mapping that starts with `<esc>` : ``` inoremap <esc>x <esc>:echom "balabala"<cr> ``` When you press `<esc>`, vim will wait `:h 'timeoutlen'` milliseconds to see if next key is `x`. You should avoid t...
16,161
<p>I want to remap <code>&lt;C-I&gt;</code> to print markdown <code>*</code> symbol around the previous word. For example:</p> <pre><code># user actions inside &lt;...&gt; some text typed in vim insert mode&lt;cursor_position&gt; &lt;C-I&gt; # expected vim output some text typed in vim insert *mode*&lt;cursor_positi...
[ { "answer_id": 23343, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<p>Short answer: you cannot.</p>\n\n<p>Long answer: <code>&lt;C-i&gt;</code> being equivalent to <code>&lt;Tab&gt;...
2018/05/06
[ "https://vi.stackexchange.com/questions/16161", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17317/" ]
I want to remap `<C-I>` to print markdown `*` symbol around the previous word. For example: ``` # user actions inside <...> some text typed in vim insert mode<cursor_position> <C-I> # expected vim output some text typed in vim insert *mode*<cursor_position> ``` I am using the following line in my `.vimrc` for rema...
With a recent enough Vim binary, and for some terminals – including [xterm](https://invisible-island.net/xterm/) and [iterm2](https://vi.stackexchange.com/questions/16161/how-to-map-c-i-separate-from-tab/23344#comment46205_23344) if you enable the [`CSI u` option](https://iterm2.com/documentation-csiu.html) – Vim can d...
16,164
<p>I am editing a tex file using vim, searching for words starting with capital letters, as they are most likely proper names or names of works to which I'd like to add some formatting and/or indexing commands. Now <code>/\u\l\l</code> will catch the beginning of words with a capital letter, but not if one of them has ...
[ { "answer_id": 16165, "author": "flemingfleming", "author_id": 16910, "author_profile": "https://vi.stackexchange.com/users/16910", "pm_score": 2, "selected": false, "text": "<p>It depends on exactly how careful you want to be with your matches, but there are many options. The simplest w...
2018/05/06
[ "https://vi.stackexchange.com/questions/16164", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2774/" ]
I am editing a tex file using vim, searching for words starting with capital letters, as they are most likely proper names or names of works to which I'd like to add some formatting and/or indexing commands. Now `/\u\l\l` will catch the beginning of words with a capital letter, but not if one of them has diacritics on ...
If you are using the new regex engine (you most likely are), then `/[[:upper:]][[:lower:]][[:lower:]]` will work for all of the following cases: ``` Śiva Śiva Wṛhaspatitattwa ``` Note the difference between the first and second- one is a single unicode code-point which is two bytes when encoded in utf-8, the other ...
16,186
<p>I have a bunch of really useful terminal programs which I use often while I am editing or writing. For example, dictionary is a popular one and I have aliased its usage to single character <code>d</code> in <code>.zshrc</code> file to save time.</p> <p>While I am editing documentation pages in VIM, is there a way I...
[ { "answer_id": 16193, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": false, "text": "<p><em>The question originally asked about a solution for <strong>bash</strong>. I answered before I discovered that it ...
2018/05/09
[ "https://vi.stackexchange.com/questions/16186", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17317/" ]
I have a bunch of really useful terminal programs which I use often while I am editing or writing. For example, dictionary is a popular one and I have aliased its usage to single character `d` in `.zshrc` file to save time. While I am editing documentation pages in VIM, is there a way I can use `.zshrc` aliases in `vi...
One possible workaround is to move these things out of `.zshrc`. `.zshrc` is only sourced for interactive terminals, but `.zshenv` is sourced for *any* invocation of `zsh` (except with `-f`). Creating aliases in `.zshenv` will allow them to work when `zsh` is called by `vim`. I wouldn't necessarily recommend this app...
16,189
<p>I have a vim's buffer and a terminal in the same vim's window but each time switch to terminal I can only exit it to go back to vim's buffer,</p> <p>Is there a way to keep terminal session but be able to switch to vim's buffer?</p> <p>I used gvim 1-10802 on windows 10.</p> <p>Many thanks.</p>
[ { "answer_id": 16194, "author": "Tuyen Pham", "author_id": 14274, "author_profile": "https://vi.stackexchange.com/users/14274", "pm_score": 5, "selected": true, "text": "<p>From <code>:h terminal-typing</code></p>\n\n<p><code>CTRL-W</code> can be used to navigate between windows and othe...
2018/05/09
[ "https://vi.stackexchange.com/questions/16189", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/14274/" ]
I have a vim's buffer and a terminal in the same vim's window but each time switch to terminal I can only exit it to go back to vim's buffer, Is there a way to keep terminal session but be able to switch to vim's buffer? I used gvim 1-10802 on windows 10. Many thanks.
From `:h terminal-typing` `CTRL-W` can be used to navigate between windows and other CTRL-W commands, e.g.: ``` CTRL-W CTRL-W move focus to the next window CTRL-W : enter an Ex command ```
16,204
<p>After reading <a href="https://stackoverflow.com/questions/7338794/vim-regex-replace-with-n-characters">https://stackoverflow.com/questions/7338794/vim-regex-replace-with-n-characters</a>, I've known how to replace tabs by spaces:</p> <pre><code>:%s/^\v(\t)*/\=repeat(repeat(' ',4),strlen(submatch(0)))/g </code></pr...
[ { "answer_id": 16205, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 3, "selected": true, "text": "<p>I think you want a simple:</p>\n\n<pre><code>%s/\\s\\{4\\}/\\t/g\n</code></pre>\n\n<p>that matches 4 spaces and r...
2018/05/10
[ "https://vi.stackexchange.com/questions/16204", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10003/" ]
After reading <https://stackoverflow.com/questions/7338794/vim-regex-replace-with-n-characters>, I've known how to replace tabs by spaces: ``` :%s/^\v(\t)*/\=repeat(repeat(' ',4),strlen(submatch(0)))/g ``` The command above allows me to replace n tabs at the beginning of each line with n four-spaces. Now I want to ...
I think you want a simple: ``` %s/\s\{4\}/\t/g ``` that matches 4 spaces and replaces them by a single tab. If you want it to only appy to the beginning of the line, this should work: ``` %s/\(^\s*\)\@<=\(\s\{4\}\)/\t/g ``` That uses a zero-width assertion to make sure it always matches Spaces at the beginning o...
16,209
<p>For example, if I want to run <code>tidy</code> on a file</p> <pre><code>r! tidy % </code></pre> <p>But I have to save the file beforehand. Is there any way around this?</p>
[ { "answer_id": 16210, "author": "Dan J.", "author_id": 7995, "author_profile": "https://vi.stackexchange.com/users/7995", "pm_score": 4, "selected": true, "text": "<pre><code>:range! command\n</code></pre>\n\n<p>This will run an external command, pipe the lines specified in <em>range</em...
2018/05/10
[ "https://vi.stackexchange.com/questions/16209", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13695/" ]
For example, if I want to run `tidy` on a file ``` r! tidy % ``` But I have to save the file beforehand. Is there any way around this?
``` :range! command ``` This will run an external command, pipe the lines specified in *range* to it and replace *range* with the output of the command. As a special case, `%` as a range includes all lines in the buffer. (see `help :%`) So this should do what you want: ``` :%! tidy ```
16,217
<p>I'm making a command that runs tests and opens coverage report for the currently opened file.</p> <pre><code>nnoremap cov :!vendor/phpunit/phpunit/phpunit --coverage-html \ /tmp/coverage/ test/ &amp;&amp; google-chrome /tmp/coverage/&lt;CR&gt; </code></pre> <p>How do I put the contents of filename register (<code>...
[ { "answer_id": 16218, "author": "Rápli András", "author_id": 16700, "author_profile": "https://vi.stackexchange.com/users/16700", "pm_score": 0, "selected": false, "text": "<p>This was the partial solution based on janos' answer. Can't manipulate the %, so needed another test directory s...
2018/05/11
[ "https://vi.stackexchange.com/questions/16217", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16700/" ]
I'm making a command that runs tests and opens coverage report for the currently opened file. ``` nnoremap cov :!vendor/phpunit/phpunit/phpunit --coverage-html \ /tmp/coverage/ test/ && google-chrome /tmp/coverage/<CR> ``` How do I put the contents of filename register (`%`) into the bash command I want to execute? ...
To refer to the current file, you can use `%`. You can even use modified versions of the path, by applying one ore more of the modifiers as documented in `:help %:`. To highlight just a few interesting ones from the help page: ``` :p Make file name a full path. Must be the first modifier. Also changes "~/" (an...
16,248
<p>Is there a robust way to detect whether a window has a neighbour in a given direction? So far, the only solution I found uses <code>wincmd</code>, </p> <pre><code> let winnum = winnr() noautocmd wincmd h if winnum != winnr() noautocmd wincmd l return 0 else return 1 endif </code></pre> <p>but...
[ { "answer_id": 16249, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 3, "selected": false, "text": "<p>You can do this by looking at the window positions. Take \"right\" as an example. \n If <em>any</em> window has a left ...
2018/05/17
[ "https://vi.stackexchange.com/questions/16248", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11125/" ]
Is there a robust way to detect whether a window has a neighbour in a given direction? So far, the only solution I found uses `wincmd`, ``` let winnum = winnr() noautocmd wincmd h if winnum != winnr() noautocmd wincmd l return 0 else return 1 endif ``` but is it robust? Ideally, I would like ...
The `winnr` function was [updated](https://github.com/vim/vim/commit/46ad288b9b2a6eb0430cf802ff5ce68a58629897) to take movement arguments as patch 8.1.1140 on April 8, 2019. If your version of Vim has this updated function, `:echo has('patch-8.1.1140')` will output `1`. The movement argument can be `'h'`, `'j'`, `'k'`...
16,253
<p>If I type <code>:e foo/**/foo*.js</code> and hit tab then vim replaces the *s with all possible suggestions in the filepath. What if I realized that I wasn't specific enough (there are too many results in autocomplete) and I want to go back from the autocomplete suggestions to <code>:e foo/**/foo*.js</code></p> <p>...
[ { "answer_id": 16259, "author": "filipbolt", "author_id": 15660, "author_profile": "https://vi.stackexchange.com/users/15660", "pm_score": 2, "selected": false, "text": "<p>I don't think so, but perhaps using list as wildmode would suit you more. </p>\n\n<pre><code>:set wildmode=list,ful...
2018/05/17
[ "https://vi.stackexchange.com/questions/16253", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16698/" ]
If I type `:e foo/**/foo*.js` and hit tab then vim replaces the \*s with all possible suggestions in the filepath. What if I realized that I wasn't specific enough (there are too many results in autocomplete) and I want to go back from the autocomplete suggestions to `:e foo/**/foo*.js` My wildmenu settings are: ``` ...
After setting wildmode=full, shift-tab takes me back to the original regex. The wildmode documentation for full is > > "full" Complete the next full match. After the last match, the ***original string*** is used and then the first match again. > > > Originally, my wildmode was wildmode=longest:full,full,full. To ...
16,260
<p>so whenever I open a file be it from using FZF, NERDTree or directly using edit, IF I happen to be in the NERDTree buffer it will open the file in the buffer. </p> <p>How do I make it so that whenever a file is open (no matter how) it will open in the first non NERDTree buffer/window so that NERDTree remains open n...
[ { "answer_id": 16285, "author": "undg", "author_id": 17497, "author_profile": "https://vi.stackexchange.com/users/17497", "pm_score": 2, "selected": true, "text": "<p>The same issue bothered me for a long time.</p>\n\n<p>For fzf there is a discussion about it on github. They came up with...
2018/05/18
[ "https://vi.stackexchange.com/questions/16260", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11603/" ]
so whenever I open a file be it from using FZF, NERDTree or directly using edit, IF I happen to be in the NERDTree buffer it will open the file in the buffer. How do I make it so that whenever a file is open (no matter how) it will open in the first non NERDTree buffer/window so that NERDTree remains open no matter w...
The same issue bothered me for a long time. For fzf there is a discussion about it on github. They came up with some keybindings: ``` nnoremap <silent> <expr> <Leader><Leader> (expand('%') =~ 'NERD_tree' ? "\<c-w>\<c-w>" : '').":FZF\<cr>" ``` but this post is the most promising <https://github.com/junegunn/fzf/issu...
16,276
<p>This is what I get from the documentation: <code>\zs</code> &quot;starts the highlighted part&quot; after matching the preceding <em>regex</em>, and <code>\@&lt;=</code> &quot;starts the highlighted part&quot; after matching the preceding <em>atom</em>. But I don't exactly understand the subtleties of this, so can a...
[ { "answer_id": 16277, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 5, "selected": true, "text": "<p>This looks like you indeed found an obscure bug. I have implemented the <code>gn</code> textobject back in 2012 f...
2018/05/21
[ "https://vi.stackexchange.com/questions/16276", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8084/" ]
This is what I get from the documentation: `\zs` "starts the highlighted part" after matching the preceding *regex*, and `\@<=` "starts the highlighted part" after matching the preceding *atom*. But I don't exactly understand the subtleties of this, so can anyone explain how they differ a bit more in depth? This is wh...
This looks like you indeed found an obscure bug. I have implemented the `gn` textobject back in 2012 for Vim 7.3 something. It basically works in the following way: 1) It searches backwards for the last match of the current regular expression. 2) It searches forward for the next match of the current regular expressio...
16,286
<p>For example, I'd like to map <code>&lt;leader&gt;l</code> to enter command-line mode with a command (<code>AsyncRun</code> followed by a space) partially typed in, so that I can continue to type to complete the command.</p> <p>So typing <code>&lt;leader&gt;l</code> will enter command-line mode with the following co...
[ { "answer_id": 16288, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 1, "selected": false, "text": "<p>You can use the following normal mode mapping:</p>\n\n<pre><code>nnoremap &lt;leader&gt;l :AsyncRun&lt;Space&gt;\n</code></p...
2018/05/22
[ "https://vi.stackexchange.com/questions/16286", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/14274/" ]
For example, I'd like to map `<leader>l` to enter command-line mode with a command (`AsyncRun` followed by a space) partially typed in, so that I can continue to type to complete the command. So typing `<leader>l` will enter command-line mode with the following command waiting for further input: ``` :AsyncRun ``` A...
You can use the following normal mode mapping: ``` nnoremap <leader>l :AsyncRun<Space> ``` N.B. Instead of `<Space>`, you could just type a literal space character, but it's easier to see what the above is doing at a glance. If you wanted to *start* your `rhs` with a space, then using the `<Space>` notation is requi...
16,291
<p>How to get vim keybindings at terminal output so I can navigate/operate at terminal output like in vim or get smooth shell command processing in vim. For example I type:</p> <p><code>ifconfig</code></p> <p>an i want to make moves to <code>ipaddres</code> location, then copy it and paste into command line. </p> <p...
[ { "answer_id": 16288, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 1, "selected": false, "text": "<p>You can use the following normal mode mapping:</p>\n\n<pre><code>nnoremap &lt;leader&gt;l :AsyncRun&lt;Space&gt;\n</code></p...
2018/05/22
[ "https://vi.stackexchange.com/questions/16291", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16328/" ]
How to get vim keybindings at terminal output so I can navigate/operate at terminal output like in vim or get smooth shell command processing in vim. For example I type: `ifconfig` an i want to make moves to `ipaddres` location, then copy it and paste into command line. I already know solution inside VIM like: `re...
You can use the following normal mode mapping: ``` nnoremap <leader>l :AsyncRun<Space> ``` N.B. Instead of `<Space>`, you could just type a literal space character, but it's easier to see what the above is doing at a glance. If you wanted to *start* your `rhs` with a space, then using the `<Space>` notation is requi...
16,309
<p>I know <code>gvim -c [command] samaple.txt</code> might run command predefined in command body. How to paste text from windows clipboard at the end of sample.txt file?</p>
[ { "answer_id": 16310, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 2, "selected": false, "text": "<p>As far as I know <a href=\"https://stackoverflow.com/questions/17819814/how-can-you-get-the-clipboard-contents-with-a...
2018/05/24
[ "https://vi.stackexchange.com/questions/16309", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16328/" ]
I know `gvim -c [command] samaple.txt` might run command predefined in command body. How to paste text from windows clipboard at the end of sample.txt file?
As far as I know [the clipboard cannot be accessed from the command line natively](https://stackoverflow.com/questions/17819814/how-can-you-get-the-clipboard-contents-with-a-windows-command). So that's going to be the biggest problem here. If you put the data somewhere accessible like a text file you could certainly us...
16,338
<p>Vim 8.1 add a new :Termdebug command with a really good gdb integration. If the <code>mouse</code> option is set, there is also a visual bar appearing on vim. Here is an extract of the man:</p> <pre><code>If 'mouse' is set the plugin adds a window toolbar with these entries: Step :Step Next :...
[ { "answer_id": 16310, "author": "Tumbler41", "author_id": 6489, "author_profile": "https://vi.stackexchange.com/users/6489", "pm_score": 2, "selected": false, "text": "<p>As far as I know <a href=\"https://stackoverflow.com/questions/17819814/how-can-you-get-the-clipboard-contents-with-a...
2018/05/28
[ "https://vi.stackexchange.com/questions/16338", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/15134/" ]
Vim 8.1 add a new :Termdebug command with a really good gdb integration. If the `mouse` option is set, there is also a visual bar appearing on vim. Here is an extract of the man: ``` If 'mouse' is set the plugin adds a window toolbar with these entries: Step :Step Next :Over Finish :Fin...
As far as I know [the clipboard cannot be accessed from the command line natively](https://stackoverflow.com/questions/17819814/how-can-you-get-the-clipboard-contents-with-a-windows-command). So that's going to be the biggest problem here. If you put the data somewhere accessible like a text file you could certainly us...
16,345
<p>I write screenplays with <a href="https://fountain.io" rel="nofollow noreferrer">fountain</a>. Dialogue syntax looks like this:</p> <pre><code>THE TERMINATOR Hasta la vista. Baby. </code></pre> <p>I would like to be able to select the sentence: <code>Hasta la vista.</code>, without also selecting <code>THE TERMINA...
[ { "answer_id": 16348, "author": "brhfl", "author_id": 14684, "author_profile": "https://vi.stackexchange.com/users/14684", "pm_score": 2, "selected": false, "text": "<p>If you tried reedes/vim-textobj-sentence, that (hopefully) means you have kana/vim-textobj-user installed. You can (mos...
2018/05/29
[ "https://vi.stackexchange.com/questions/16345", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13488/" ]
I write screenplays with [fountain](https://fountain.io). Dialogue syntax looks like this: ``` THE TERMINATOR Hasta la vista. Baby. ``` I would like to be able to select the sentence: `Hasta la vista.`, without also selecting `THE TERMINATOR` with a sentence motion, like with `vis` or `das`. `vis` works exactly lik...
Update: Well, I made a plugin. Get it from [ctholho/vim-textobj-sentence-line](https://github.com/ctholho/vim-textobj-sentence-line). The plugin supports `is` and `as` motions. I didn't test all possible conditions but it does the job reliably. It also remaps the `)` and `(` motion to behave in the same way. Thanks to...
16,355
<p>I want to find the alternative to ctrl+R to search history in bash. I can enable vi mode in bash but I cannot make it search. When I do <code>/search</code> or <code>?search</code> nothing happens. Is there something more I should press? I tried press enter and then this happens:</p> <pre><code>$ set -o vi $ ls|gre...
[ { "answer_id": 16357, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 6, "selected": true, "text": "<p>There certainly is Vim style searching in bash/readline. In fact, your command line is essentially a scaled down versi...
2018/05/30
[ "https://vi.stackexchange.com/questions/16355", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7466/" ]
I want to find the alternative to ctrl+R to search history in bash. I can enable vi mode in bash but I cannot make it search. When I do `/search` or `?search` nothing happens. Is there something more I should press? I tried press enter and then this happens: ``` $ set -o vi $ ls|grep f $ /gr -bash: /gr: No such file o...
There certainly is Vim style searching in bash/readline. In fact, your command line is essentially a scaled down version of the Vim editor with a significant number of Normal mode commands available to you. More on that in a sec but first Search. The key piece of information you need is that as you stare at that blinki...
16,358
<p>Let's say, I want to search for email addresses and output them to a new file. What I can do so far with a help from another discussion is this:</p> <pre><code>g/pattern/.w! &gt;&gt; output.txt </code></pre> <p>but that saves whole lines where search matches occur. Is it possible to extract just the matches (with...
[ { "answer_id": 16359, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 4, "selected": true, "text": "<p>This is a bit easier with <code>grep</code> and the <code>--only-matching</code>/<code>-o</code> option.</p>\n\n<pre...
2018/05/31
[ "https://vi.stackexchange.com/questions/16358", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17702/" ]
Let's say, I want to search for email addresses and output them to a new file. What I can do so far with a help from another discussion is this: ``` g/pattern/.w! >> output.txt ``` but that saves whole lines where search matches occur. Is it possible to extract just the matches (with possibility for them to be mult...
This is a bit easier with `grep` and the `--only-matching`/`-o` option. ``` grep -o 'pattern' file.txt > output.txt ``` You can use Vim's substitution as well: ``` :%s/.*\(pattern\).*/\1 ``` This approach will affect the current buffer though. It would probably be best to copy the file first. Note: these approac...
16,362
<p>So, I found <a href="https://vi.stackexchange.com/a/10478/6108">this useful answer</a> about iterating <em>buffers</em>; but due to the tabpage-specific duality of windows in Vim, I failed at adapting it to my needs.</p> <p>Thus: how can I construct a boolean expression, determining whether or not <em>any</em> (not...
[ { "answer_id": 16364, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 3, "selected": false, "text": "<p>You can sum up the values of <code>&amp;diff</code> for each window, and see if the total is > 0:</p>\n\n<pre><code>let any_...
2018/06/01
[ "https://vi.stackexchange.com/questions/16362", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6108/" ]
So, I found [this useful answer](https://vi.stackexchange.com/a/10478/6108) about iterating *buffers*; but due to the tabpage-specific duality of windows in Vim, I failed at adapting it to my needs. Thus: how can I construct a boolean expression, determining whether or not *any* (not just the current) window in the ta...
You can sum up the values of `&diff` for each window, and see if the total is > 0: ``` let any_diff = 0 windo let any_diff += &diff echo any_diff . ' windows in diff mode' if any_diff > 0 | do stuff | endif ```
16,386
<p>gvim 8 1-26 / windows 10</p> <p>I'd like to use Windows Subsystem Linux (WSL)'s bash shell as a gvim's terminal instead of <code>cmd</code>.</p> <p>So if I type in command potion of gvim: <code>:!.\test.sh</code>, it will echo result inside of gvim terminal - wsl's bash shell (not open a <code>cmd</code> window, l...
[ { "answer_id": 16387, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 1, "selected": false, "text": "<p>You should be able to accomplish this simply by assigning to the <code>'shell'</code> setting the path of whatever Ba...
2018/06/03
[ "https://vi.stackexchange.com/questions/16386", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/14274/" ]
gvim 8 1-26 / windows 10 I'd like to use Windows Subsystem Linux (WSL)'s bash shell as a gvim's terminal instead of `cmd`. So if I type in command potion of gvim: `:!.\test.sh`, it will echo result inside of gvim terminal - wsl's bash shell (not open a `cmd` window, login to bash, and then run `test.sh`). Expected r...
GVim is a 32-bit application and WSL must run on 64 bit. On Windows 10 you can use GVim with WSL if you add the following to your vimrc file: ``` if has("win32") set shell=C:\Windows\Sysnative\wsl.exe set shellpipe=| set shellredir=> set shellcmdflag= endif ```
16,392
<p>My version is : NVIM v0.3.0-dev</p> <p>I'm trying to replace mappings with w mappings. Initially I came up with</p> <pre><code>nnoremap &lt;leader&gt;w &lt;c-w&gt; nnoremap &lt;leader&gt;wb &lt;c-w&gt;s nnoremap &lt;leader&gt;ws &lt;nop&gt; unmap &lt;c-w&gt; </code></pre> <p>But it didn't work. I didn't have any m...
[ { "answer_id": 16393, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 4, "selected": true, "text": "<p>It is important to first understand that <code>&lt;c-w&gt;</code> is not a map but a built-in command when vim is operati...
2018/06/04
[ "https://vi.stackexchange.com/questions/16392", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16280/" ]
My version is : NVIM v0.3.0-dev I'm trying to replace mappings with w mappings. Initially I came up with ``` nnoremap <leader>w <c-w> nnoremap <leader>wb <c-w>s nnoremap <leader>ws <nop> unmap <c-w> ``` But it didn't work. I didn't have any mappings with w. After a minute I came up with this: ``` nnoremap <leader>...
It is important to first understand that `<c-w>` is not a map but a built-in command when vim is operating in a particular mode. It is often referred to as a "normal command" since one uses it in normal mode1, and it can be triggered using the `:normal!` command. There is no mapping involved; the normal commands are ha...
16,422
<p>Using Vim-fugitive plugin I open a commit with</p> <pre><code>:Gedit HEAD~5 </code></pre> <p>The buffer looks like this:</p> <pre><code>tree a75d4eea2207e408db6343a4869274b701b42135 parent 7fa89fec125ce60a341f7c37dd769a8a31c49359 author Takahiro Yoshihara &lt;tacahiroy@gmail.com&gt; Tue Feb 21 09:07:51 2017 +0900...
[ { "answer_id": 16423, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 4, "selected": true, "text": "<p>From <code>:h fugitive-mappings</code> you can use:</p>\n\n<ul>\n<li><code>&lt;cr&gt;</code> to open the diff in the...
2018/06/07
[ "https://vi.stackexchange.com/questions/16422", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3230/" ]
Using Vim-fugitive plugin I open a commit with ``` :Gedit HEAD~5 ``` The buffer looks like this: ``` tree a75d4eea2207e408db6343a4869274b701b42135 parent 7fa89fec125ce60a341f7c37dd769a8a31c49359 author Takahiro Yoshihara <tacahiroy@gmail.com> Tue Feb 21 09:07:51 2017 +0900 committer Takahiro Yoshihara <tacahiroy@gm...
From `:h fugitive-mappings` you can use: * `<cr>` to open the diff in the current window * `o` open the diff in a horizontal split * `O` to open the diff in a new tab page * `S` open diff in a vertical split I imagine you want to use `S` on the diff line. However as screen space can be a concern with diff-ing, `O` mi...
16,444
<p>I'm using Git's MINGW64 bash shell to run vim and vimtutor. I managed to change the movement key bindings via <code>e: $MYVIMRC</code>, but the changes in keybindings do not apply to vimtutor.</p> <p>When I open vimtutor, all the keybindings are the default ones. When I use the <code>e: $MYVIMRC</code> in vimtutor,...
[ { "answer_id": 16446, "author": "flemingfleming", "author_id": 16910, "author_profile": "https://vi.stackexchange.com/users/16910", "pm_score": 2, "selected": true, "text": "<p>Simple answer, yes, all you need to do is run the <code>:so[urce]</code> command from within vimtutor:</p>\n\n<...
2018/06/09
[ "https://vi.stackexchange.com/questions/16444", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17809/" ]
I'm using Git's MINGW64 bash shell to run vim and vimtutor. I managed to change the movement key bindings via `e: $MYVIMRC`, but the changes in keybindings do not apply to vimtutor. When I open vimtutor, all the keybindings are the default ones. When I use the `e: $MYVIMRC` in vimtutor, it shows the same vimrc file th...
Simple answer, yes, all you need to do is run the `:so[urce]` command from within vimtutor: ``` :source ~/_vimrc ``` (change the path to wherever your vimrc is located. Inside vim you can always use forward slashes as a path separator even on windows, they're less confusing because vim often uses `\` as an escape ch...
16,470
<p>I’m trying to set the syntax of Processing files (*.pde) to <code>java</code> with a ftplugin.</p> <pre><code>.vim/ after/ ftdetect/ pde.vim ftplugin/ processing.vim </code></pre> <hr> <p>In <code>after/ftdetect/pde.vim</code> I detect the filetype:</p> <pre><code>autocmd BufNewFile,B...
[ { "answer_id": 16471, "author": "mMontu", "author_id": 1405, "author_profile": "https://vi.stackexchange.com/users/1405", "pm_score": 4, "selected": true, "text": "<p>It is unclear why you are using the <code>after</code> directory. From <a href=\"http://vimhelp.appspot.com/options.txt.h...
2018/06/12
[ "https://vi.stackexchange.com/questions/16470", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/15716/" ]
I’m trying to set the syntax of Processing files (\*.pde) to `java` with a ftplugin. ``` .vim/ after/ ftdetect/ pde.vim ftplugin/ processing.vim ``` --- In `after/ftdetect/pde.vim` I detect the filetype: ``` autocmd BufNewFile,BufReadPost *.pde set filetype=processing ``` --- In `aft...
It is unclear why you are using the `after` directory. From [`:help after-directory`](http://vimhelp.appspot.com/options.txt.html#after%2ddirectory): ``` 5. In the "after" directory in your home directory. This is for personal preferences to overrule or add to the distributed defaults or system-wide settings (r...
16,473
<p>Let's say I have text like this,</p> <pre><code>SPAC SPAC - Specific-Purpose Committee Campaign Finance Report SPAC-SS SPAC-SS - Specific-Purpose Committee Special Session Report SPAC-T SPAC-T - PAC Special Pre-election (Telegram) Report of Contributions </code></pre> <p>Now how would I use vim-...
[ { "answer_id": 16476, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>In my opinion the best way to do what you want is to use a substitution command:</p>\n\n<pre><code>:'&lt;,'&gt;s/[^ ]\\+...
2018/06/12
[ "https://vi.stackexchange.com/questions/16473", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5078/" ]
Let's say I have text like this, ``` SPAC SPAC - Specific-Purpose Committee Campaign Finance Report SPAC-SS SPAC-SS - Specific-Purpose Committee Special Session Report SPAC-T SPAC-T - PAC Special Pre-election (Telegram) Report of Contributions ``` Now how would I use vim-surround to surround to ge...
In my opinion the best way to do what you want is to use a substitution command: ``` :'<,'>s/[^ ]\+/'\0' ``` Which is decomposed like this: ``` '<,'> the range of lines you want to treat (you could use % is you want to change all the lines of the buffer, or use line numbers e.g. 1,10) s/ ...
16,489
<p>With vim script I can do <code>let found = matchstr("abbaba", 'a')</code> and get back <code>"a"</code> as a result. How would I matchstr to get back a list of all matches for the string? <code>found == ["a", "a", "a"]</code> as in <code>g/a/</code></p>
[ { "answer_id": 16490, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 2, "selected": false, "text": "<p>You can use the <code>{count}</code> parameter for <code>matchstr()</code> to increment your way through the string...
2018/06/13
[ "https://vi.stackexchange.com/questions/16489", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17848/" ]
With vim script I can do `let found = matchstr("abbaba", 'a')` and get back `"a"` as a result. How would I matchstr to get back a list of all matches for the string? `found == ["a", "a", "a"]` as in `g/a/`
An alternative to repeatedly calling `match(` is to use `substitute(` with a `\=` expression: ``` function MatchStrAll(str, pat) let l:res = [] call substitute(a:str, a:pat, '\=add(l:res, submatch(0))', 'g') return l:res endfunction ```
16,504
<p>I have an <code>exe</code> program that checks for certain errors in a text file.</p> <p>I want to create a shortcut (like <code>\+M</code>) to run that <code>exe</code> file against the text file.</p> <p>My <code>exe</code> file's path is <code>C:\Users\xyz\Documents\Checker\manager.exe</code>, the text file's pa...
[ { "answer_id": 16499, "author": "ivan", "author_id": 12408, "author_profile": "https://vi.stackexchange.com/users/12408", "pm_score": 0, "selected": false, "text": "<p>The main thing I like about vi is not having to move my hands from the keyboard. Even going to the arrow keys seems like...
2018/06/15
[ "https://vi.stackexchange.com/questions/16504", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
I have an `exe` program that checks for certain errors in a text file. I want to create a shortcut (like `\+M`) to run that `exe` file against the text file. My `exe` file's path is `C:\Users\xyz\Documents\Checker\manager.exe`, the text file's path is `C:\Users\xyz\Desktop\mytextfile.txt`. The manager just needs the...
You are missing the main point here, keyboard based editing tools are supposed to be faster because you don't have to change your hand position every once in a while. Secondly, seeing how you visually select, you are only starting to use vim. There are much more useful ways of visual selection. The last thing I learnt...
16,509
<p>For example, I might accidentally type something like <code>:WQ</code> and I want it to work like <code>:wq</code> when a hit enter</p> <p>Another case is where I am typing a longer command name, for example <code>NERDTreeTabsClose</code>. (Note that I have the settings ignorecase and smartcase set)</p> <ol> <li>I...
[ { "answer_id": 16511, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 4, "selected": true, "text": "<p>You can dynamically toggle smartcase using autocmds, so when in a <code>:</code> command line, it is off and when in a <c...
2018/06/16
[ "https://vi.stackexchange.com/questions/16509", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11136/" ]
For example, I might accidentally type something like `:WQ` and I want it to work like `:wq` when a hit enter Another case is where I am typing a longer command name, for example `NERDTreeTabsClose`. (Note that I have the settings ignorecase and smartcase set) 1. I might start by typing `:nerd` and then hitting tab, ...
You can dynamically toggle smartcase using autocmds, so when in a `:` command line, it is off and when in a `/` command line it is on: ``` " assumes set ignorecase smartcase augroup dynamic_smartcase autocmd! autocmd CmdLineEnter : set nosmartcase autocmd CmdLineLeave : set smartcase augroup END ```
16,516
<p>I'm trying to find the right ex command to overwrite the current vim buffer with the system clipboard.</p> <p>The relevant system clipboard register is <code>"+</code> in this case.</p> <p>My first guess was to use <code>:%+p</code>; i.e. select the whole buffer <code>%</code> and then <em>paste</em> <code>p</code...
[ { "answer_id": 16517, "author": "Mussé Redi", "author_id": 11449, "author_profile": "https://vi.stackexchange.com/users/11449", "pm_score": 0, "selected": false, "text": "<p>By visual selection, one can (1) select the whole buffer by moving the start of the buffer, with the <a href=\"htt...
2018/06/18
[ "https://vi.stackexchange.com/questions/16516", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11449/" ]
I'm trying to find the right ex command to overwrite the current vim buffer with the system clipboard. The relevant system clipboard register is `"+` in this case. My first guess was to use `:%+p`; i.e. select the whole buffer `%` and then *paste* `p` the `"+` register to the current buffer. But this doesn't work. T...
You could add the following in your vimrc: ``` command! ReplaceWithClipboard %d | put + ``` This way when you call the command `:ReplaceWithClipboard` vim will * `%d` delete all the lines in the buffer * `put +` put your clipboard register You can have a look at * [`:h put`](http://vimhelp.appspot.com/change.txt....
16,520
<p>As I am moving from Windows to Linux for my development machine, I have noticed a difference in vim between the Windows version and the Linux version. The windows will show you the number of highlighted columns at the bottom of the screen where the Linux version does not (or at least how I have it configured). I hav...
[ { "answer_id": 16517, "author": "Mussé Redi", "author_id": 11449, "author_profile": "https://vi.stackexchange.com/users/11449", "pm_score": 0, "selected": false, "text": "<p>By visual selection, one can (1) select the whole buffer by moving the start of the buffer, with the <a href=\"htt...
2018/06/19
[ "https://vi.stackexchange.com/questions/16520", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17930/" ]
As I am moving from Windows to Linux for my development machine, I have noticed a difference in vim between the Windows version and the Linux version. The windows will show you the number of highlighted columns at the bottom of the screen where the Linux version does not (or at least how I have it configured). I have l...
You could add the following in your vimrc: ``` command! ReplaceWithClipboard %d | put + ``` This way when you call the command `:ReplaceWithClipboard` vim will * `%d` delete all the lines in the buffer * `put +` put your clipboard register You can have a look at * [`:h put`](http://vimhelp.appspot.com/change.txt....
16,536
<p>I was wondering if, out of the box, one can move an entire column up- and downwards.</p> <p>Say, we have the following text:</p> <pre><code>1 a b c 2 d e f </code></pre> <p>My goal is to convert this into</p> <pre><code>1 a b c 2 d e f </code></pre> <p>This does not seem possible via <a hr...
[ { "answer_id": 16517, "author": "Mussé Redi", "author_id": 11449, "author_profile": "https://vi.stackexchange.com/users/11449", "pm_score": 0, "selected": false, "text": "<p>By visual selection, one can (1) select the whole buffer by moving the start of the buffer, with the <a href=\"htt...
2018/06/20
[ "https://vi.stackexchange.com/questions/16536", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11449/" ]
I was wondering if, out of the box, one can move an entire column up- and downwards. Say, we have the following text: ``` 1 a b c 2 d e f ``` My goal is to convert this into ``` 1 a b c 2 d e f ``` This does not seem possible via [visual block operations](http://vimdoc.sourceforge.net/htmldo...
You could add the following in your vimrc: ``` command! ReplaceWithClipboard %d | put + ``` This way when you call the command `:ReplaceWithClipboard` vim will * `%d` delete all the lines in the buffer * `put +` put your clipboard register You can have a look at * [`:h put`](http://vimhelp.appspot.com/change.txt....
16,539
<p>When review code, it would be convenient if we can highlight multiple lines at the same time, instead of only current cursor line is highlighted. </p> <p><code>:set cursorline</code> only highlight current line.<br> <code>:nnoremap &lt;silent&gt; &lt;Leader&gt;l ml:execute 'match Search /\%'.line('.').'l/'&lt;CR&gt...
[ { "answer_id": 16544, "author": "tluafed", "author_id": 15464, "author_profile": "https://vi.stackexchange.com/users/15464", "pm_score": -1, "selected": false, "text": "<p>You press capital V and j or k to select other lines.</p>\n" }, { "answer_id": 16548, "author": "Fisher"...
2018/06/21
[ "https://vi.stackexchange.com/questions/16539", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13402/" ]
When review code, it would be convenient if we can highlight multiple lines at the same time, instead of only current cursor line is highlighted. `:set cursorline` only highlight current line. `:nnoremap <silent> <Leader>l ml:execute 'match Search /\%'.line('.').'l/'<CR>` can only highlight one extra line. Want ...
As you mention in your question, the `:match` command only allows a single match to be set up. For multiple matches, you can use the `matchadd()` function. You can adapt your existing mapping to use this like so: ``` :nnoremap <silent> <Leader>l :call matchadd('Search', '\%'.line('.').'l')<CR> ``` For your expressed...
16,594
<p>Is there a way that I can have the <code>:make</code> command output itself to a terminal window in vim? In the 8.1 release, they added the <code>:term</code> command, which allows you to run an external program in a vim window. I was wondering if there's some way to combine the two.</p> <p>I want this because i us...
[ { "answer_id": 16595, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 1, "selected": false, "text": "<p>On windows gvim only, you can use <code>set guioptions+=!</code> to run <code>make</code> in a terminal. This isn't yet...
2018/06/28
[ "https://vi.stackexchange.com/questions/16594", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10421/" ]
Is there a way that I can have the `:make` command output itself to a terminal window in vim? In the 8.1 release, they added the `:term` command, which allows you to run an external program in a vim window. I was wondering if there's some way to combine the two. I want this because i use vim-latex for compiling my .te...
On windows gvim only, you can use `set guioptions+=!` to run `make` in a terminal. This isn't yet supported on other platforms so you will have to find an alternative. If you want to create a new terminal each time, ``` command -nargs=* Make execute 'terminal' &makeprg.(empty(<q-args>)?'':' '.<q-args>) ```
16,610
<p>I'm looking for an approach, in Vimscript, to operate on the text lines of a buffer by looping through lines of a visual selection.</p> <p>Specifically, my goal is very simple: I have a (vertical) list of words, which I want to convert into a table; the first word is in the first column, the second is the first wor...
[ { "answer_id": 16619, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>That would be a pretty straightforward function. I'll cover key parts of it but leave things like validation and erro...
2018/06/30
[ "https://vi.stackexchange.com/questions/16610", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11449/" ]
I'm looking for an approach, in Vimscript, to operate on the text lines of a buffer by looping through lines of a visual selection. Specifically, my goal is very simple: I have a (vertical) list of words, which I want to convert into a table; the first word is in the first column, the second is the first word in the s...
That would be a pretty straightforward function. I'll cover key parts of it but leave things like validation and error handling to you. For instance, there could be a check for Visual mode not being active or for `getline()` not returning any lines. ``` func! VisualToTable() let l:out = "" let l:idx = 1 "...
16,611
<p>I installed VIM by compiling from source a while back following the instructions <a href="https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source" rel="nofollow noreferrer">here</a>. At that time, for some reason, I didn't use <code>checkinstall</code>, as a result I can't uninstall it using <code>su...
[ { "answer_id": 16760, "author": "alpha_989", "author_id": 13848, "author_profile": "https://vi.stackexchange.com/users/13848", "pm_score": 1, "selected": false, "text": "<p>As @muru has suggested, I will post the solution here..</p>\n\n<p>The situation happened, when I was trying to debu...
2018/07/01
[ "https://vi.stackexchange.com/questions/16611", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13848/" ]
I installed VIM by compiling from source a while back following the instructions [here](https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source). At that time, for some reason, I didn't use `checkinstall`, as a result I can't uninstall it using `sudo apt-get remove vim`. Following the advice [here](ht...
As @muru has suggested, I will post the solution here.. The situation happened, when I was trying to debug a issue related to a plugin. It seemed to work for a colleague, but not for me. So one of the hypothesis was that it was because of the differing versions of VIM. Because the VIM version (8.0.1430) was compiled ...
16,632
<p>On Windows 10, I installed gVim 8.1, so far I have made the following progress to make it <em>usable</em> for me:</p> <ol> <li><p>I made changes directly to <code>_vimrc</code> file, in spite I know there is also a gVim specific configuration file, because I like it in one place.</p></li> <li><p>I downloaded a colo...
[ { "answer_id": 16623, "author": "Vlastimil Burián", "author_id": 18061, "author_profile": "https://vi.stackexchange.com/users/18061", "pm_score": 3, "selected": false, "text": "<p>On Windows, the configuration file of gVim is named:</p>\n\n<pre><code>_vimrc\n</code></pre>\n\n<p>It is pla...
2018/07/03
[ "https://vi.stackexchange.com/questions/16632", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18061/" ]
On Windows 10, I installed gVim 8.1, so far I have made the following progress to make it *usable* for me: 1. I made changes directly to `_vimrc` file, in spite I know there is also a gVim specific configuration file, because I like it in one place. 2. I downloaded a color theme I really liked, and use it like so (for...
I'm on Windows 10, update 1909, and I've resolved this by overriding high DPI settings for gVim to System(Enhanced). Setting GUI font size did not help. Right click on gVim icon -> Properties -> Compatibility -> Change high DPI settings -> check box "Override high DPI scaling behavior" in the bottom of the dialog wind...
16,643
<p>How to check if my <code>.vim/buflist.txt</code> file is empty or contains whitespace(s) in <code>_vimrc</code> of my gVim on Windows 10?</p> <hr> <p>I tried this:</p> <pre><code>let BufferListFile = $HOME . "/.vim/buflist.txt" echo BufferListFile " This function SHOULD return true if the defined " buffer list ...
[ { "answer_id": 16654, "author": "Vlastimil Burián", "author_id": 18061, "author_profile": "https://vi.stackexchange.com/users/18061", "pm_score": 1, "selected": false, "text": "<p>I found the manual:</p>\n\n<pre><code>:help empty\n</code></pre>\n\n<blockquote>\n <p>empty({expr}) ...
2018/07/04
[ "https://vi.stackexchange.com/questions/16643", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18061/" ]
How to check if my `.vim/buflist.txt` file is empty or contains whitespace(s) in `_vimrc` of my gVim on Windows 10? --- I tried this: ``` let BufferListFile = $HOME . "/.vim/buflist.txt" echo BufferListFile " This function SHOULD return true if the defined " buffer list file is empty = contains " either nothing, o...
As you found out you are only working with the file name. In order to check the *contents* of the file you can use `readfile()`. It will return a list with all the lines from the file. You can then iterate through the lines in a `:for` loop and check for whatever you want. Or you can filter the list items with `filter(...
16,646
<p>I'm trying to configure vim for programming in <code>C</code>. I currently use <code>YouCompleteMe</code> and <code>Syntastic</code> for programming auto-completion and syntax-checking. But I came up with a problem. </p> <p>I cannot jump to a definition in a header file. I cannot open header file.</p> <p>I install...
[ { "answer_id": 16654, "author": "Vlastimil Burián", "author_id": 18061, "author_profile": "https://vi.stackexchange.com/users/18061", "pm_score": 1, "selected": false, "text": "<p>I found the manual:</p>\n\n<pre><code>:help empty\n</code></pre>\n\n<blockquote>\n <p>empty({expr}) ...
2018/07/04
[ "https://vi.stackexchange.com/questions/16646", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9409/" ]
I'm trying to configure vim for programming in `C`. I currently use `YouCompleteMe` and `Syntastic` for programming auto-completion and syntax-checking. But I came up with a problem. I cannot jump to a definition in a header file. I cannot open header file. I installed `sudo apt-get install exuberant-ctags` and gene...
As you found out you are only working with the file name. In order to check the *contents* of the file you can use `readfile()`. It will return a list with all the lines from the file. You can then iterate through the lines in a `:for` loop and check for whatever you want. Or you can filter the list items with `filter(...
16,663
<p>I want to alter existing files automatically,to replace all tab with four blanks in existing file.</p> <pre><code>vim .gvimrc autocmd BufRead * exec "%s/\t/ /g" </code></pre> <p>The error info pop up when to open a file without tab key in it.</p> <pre><code>Error detected while processing BufRead Auto comm...
[ { "answer_id": 16664, "author": "Naumann", "author_id": 11477, "author_profile": "https://vi.stackexchange.com/users/11477", "pm_score": 1, "selected": false, "text": "<p>First: you don't need <code>exec</code> here.</p>\n\n<p>Use the <code>/e</code> flag to avoid error messages, as in <...
2018/07/06
[ "https://vi.stackexchange.com/questions/16663", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5181/" ]
I want to alter existing files automatically,to replace all tab with four blanks in existing file. ``` vim .gvimrc autocmd BufRead * exec "%s/\t/ /g" ``` The error info pop up when to open a file without tab key in it. ``` Error detected while processing BufRead Auto commands for "*": E486: Pattern not found:...
First: you don't need `exec` here. Use the `/e` flag to avoid error messages, as in `autocmd BufRead * %s/\t/ /ge` This flag is described in [`:help :s_e`](https://vimhelp.org/change.txt.html#%3As_e)
16,675
<p>Similar to <a href="https://vi.stackexchange.com/questions/16670/how-can-i-change-the-cursor-moving-on-ctrlp">the question about ctrlp</a>, I would like to know how to change the key remapping to move the cursor on fzf library.</p> <p>Right now, only the ctrl + k works to move the cursor upward, but all the downsid...
[ { "answer_id": 16759, "author": "alpha_989", "author_id": 13848, "author_profile": "https://vi.stackexchange.com/users/13848", "pm_score": -1, "selected": false, "text": "<p>I use <code>Ctrlp</code> as its likely to be much more stable and bugfree and pretty comparable to fzf (with <cod...
2018/07/06
[ "https://vi.stackexchange.com/questions/16675", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1072/" ]
Similar to [the question about ctrlp](https://vi.stackexchange.com/questions/16670/how-can-i-change-the-cursor-moving-on-ctrlp), I would like to know how to change the key remapping to move the cursor on fzf library. Right now, only the ctrl + k works to move the cursor upward, but all the downside movement does not w...
this is the default mapping of up and down in fzf: * down : ctrl-j ctrl-n down * up : ctrl-k ctrl-p up Most people don't have problem with this. If you really really want to add your own setting, you need to change enviroment variable: ``` export FZF_DEFAULT_OPTS='--bind=ctrl-w:up,ctrl-m:down' ``` above setting wi...
16,685
<p>I've discovered the wonder that is <code>colorcolumn</code> but I haven't yet mastered the black art of Vim scripting. If I have <code>:set colorcolumn=80,132</code> in my .vimrc, how can I a) discover that I have more than one value, and b) access that 2nd value?</p> <p>I have a line completion function that uses ...
[ { "answer_id": 16689, "author": "Saul Axel Martinez Ortiz", "author_id": 18087, "author_profile": "https://vi.stackexchange.com/users/18087", "pm_score": 3, "selected": true, "text": "<p>One strange thing about vimscript is that it automatically converts string to numbers when some\noper...
2018/07/07
[ "https://vi.stackexchange.com/questions/16685", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9987/" ]
I've discovered the wonder that is `colorcolumn` but I haven't yet mastered the black art of Vim scripting. If I have `:set colorcolumn=80,132` in my .vimrc, how can I a) discover that I have more than one value, and b) access that 2nd value? I have a line completion function that uses `&cc` to calculate a padding val...
One strange thing about vimscript is that it automatically converts string to numbers when some operations are applied. For example, if you try this: ``` if '123foo' echo 'hi' endif ``` You will get 'hi' as the output, but if you try this: ``` if 'foo' echo 'hi' endif ``` You will get nothing. This happe...
16,708
<p>I am using multiple files within the same tab and when I switch buffers using :bn I reach the terminal, at which point I have to issue the command again to move. Here is the catch, I am using keymaps to do buffer switching instead of typing the entire command.</p> <p>is there a way to skip the terminal buffer and m...
[ { "answer_id": 16709, "author": "Charles Gueunet", "author_id": 15134, "author_profile": "https://vi.stackexchange.com/users/15134", "pm_score": 3, "selected": false, "text": "<p>This should work too:</p>\n\n<pre><code>augroup termIgnore\n autocmd!\n autocmd TerminalOpen * set nobu...
2018/07/10
[ "https://vi.stackexchange.com/questions/16708", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11253/" ]
I am using multiple files within the same tab and when I switch buffers using :bn I reach the terminal, at which point I have to issue the command again to move. Here is the catch, I am using keymaps to do buffer switching instead of typing the entire command. is there a way to skip the terminal buffer and move on wit...
This should work too: ``` augroup termIgnore autocmd! autocmd TerminalOpen * set nobuflisted augroup END ```
16,715
<p>I have a function in my bashrc that checks if a file is writable with <code>[ -w "$1" ]</code>. If it is, I open it with vim normally. If it's not, I open with sudo via <code>sudo env HOME="$HOME" vim -u ~/.vimrc "$1"</code> to make sure vim sources my <code>.vimrc</code> and colorscheme correctly. I want to print a...
[ { "answer_id": 16718, "author": "jeremysprofile", "author_id": 17205, "author_profile": "https://vi.stackexchange.com/users/17205", "pm_score": 2, "selected": false, "text": "<p>As @Martin pointed out, the <code>autocmd</code> was a simple if statement. I didn't realize <code>autocmd</co...
2018/07/10
[ "https://vi.stackexchange.com/questions/16715", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17205/" ]
I have a function in my bashrc that checks if a file is writable with `[ -w "$1" ]`. If it is, I open it with vim normally. If it's not, I open with sudo via `sudo env HOME="$HOME" vim -u ~/.vimrc "$1"` to make sure vim sources my `.vimrc` and colorscheme correctly. I want to print a warning message on the message line...
I would use the `VimEnter` autocommand and move the conditional inside the function, i.e. ``` augroup vimrc autocmd! autocmd VimEnter * call SudoWarn() augroup END function! SudoWarn() if $USER !=# 'root' | return | endif ... endfunction ``` This also moves the autocommand inside an autocommand group; "vimr...
16,720
<p>I set the following on my <code>~/.vimrc</code> which sets the current directory to the location of the file on the buffer.</p> <pre><code>au BufEnter * silent! :lcd%:p:h </code></pre> <p>However, when I run the fzf command to search for a file, then the search starts on the current directory, althogh the file I l...
[ { "answer_id": 16725, "author": "Lucas", "author_id": 18062, "author_profile": "https://vi.stackexchange.com/users/18062", "pm_score": 3, "selected": true, "text": "<p>The following info can be found in the <a href=\"https://github.com/junegunn/fzf/blob/master/doc/fzf.txt\" rel=\"nofollo...
2018/07/11
[ "https://vi.stackexchange.com/questions/16720", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1072/" ]
I set the following on my `~/.vimrc` which sets the current directory to the location of the file on the buffer. ``` au BufEnter * silent! :lcd%:p:h ``` However, when I run the fzf command to search for a file, then the search starts on the current directory, althogh the file I like to get is often in other director...
The following info can be found in the [official docs](https://github.com/junegunn/fzf/blob/master/doc/fzf.txt) of fzf: You can execute `:FZF` with an argument for the starting dir. So you can just run `:FZF ~` instead of `:FZF`. If you open the fzf buffer from a mapping just change that mapping: ``` map <c-space> :F...
16,727
<p>Sometimes I want to get back and copy some old code that I deleted and use it. For example, I'll do:</p> <p><code>:earlier 12h</code></p> <p>and then yank the deleted code.</p> <p>To get back to where I was, I'll issue a command like:</p> <p><code>:later 13h</code></p> <p>with the time argument for the <code>:l...
[ { "answer_id": 16725, "author": "Lucas", "author_id": 18062, "author_profile": "https://vi.stackexchange.com/users/18062", "pm_score": 3, "selected": true, "text": "<p>The following info can be found in the <a href=\"https://github.com/junegunn/fzf/blob/master/doc/fzf.txt\" rel=\"nofollo...
2018/07/11
[ "https://vi.stackexchange.com/questions/16727", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2021/" ]
Sometimes I want to get back and copy some old code that I deleted and use it. For example, I'll do: `:earlier 12h` and then yank the deleted code. To get back to where I was, I'll issue a command like: `:later 13h` with the time argument for the `:later` command being longer than the time argument I supplied for ...
The following info can be found in the [official docs](https://github.com/junegunn/fzf/blob/master/doc/fzf.txt) of fzf: You can execute `:FZF` with an argument for the starting dir. So you can just run `:FZF ~` instead of `:FZF`. If you open the fzf buffer from a mapping just change that mapping: ``` map <c-space> :F...
16,740
<p>So I want to figure out the Operating System and execute a piece of code based on the operating system in my <code>.vimrc</code>. However, I'm not able to understand where I'm going wrong.</p> <pre><code>let operating_system = system("awk -F= '/^NAME/{print $2}' /etc/os-release") echon operating_system echon operat...
[ { "answer_id": 16725, "author": "Lucas", "author_id": 18062, "author_profile": "https://vi.stackexchange.com/users/18062", "pm_score": 3, "selected": true, "text": "<p>The following info can be found in the <a href=\"https://github.com/junegunn/fzf/blob/master/doc/fzf.txt\" rel=\"nofollo...
2018/07/13
[ "https://vi.stackexchange.com/questions/16740", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13174/" ]
So I want to figure out the Operating System and execute a piece of code based on the operating system in my `.vimrc`. However, I'm not able to understand where I'm going wrong. ``` let operating_system = system("awk -F= '/^NAME/{print $2}' /etc/os-release") echon operating_system echon operating_system > "CentOS Linu...
The following info can be found in the [official docs](https://github.com/junegunn/fzf/blob/master/doc/fzf.txt) of fzf: You can execute `:FZF` with an argument for the starting dir. So you can just run `:FZF ~` instead of `:FZF`. If you open the fzf buffer from a mapping just change that mapping: ``` map <c-space> :F...
16,744
<p>I often use <code>#</code> key to quickly search for a keyword. I want to change the case of the last searched pattern in the easiest possible way. </p> <p>One way to do this is to use <code>\U\1</code> in the substitution part and pressing <code>Ctrl-r</code> followed by <code>/</code> in the search part of the st...
[ { "answer_id": 16745, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 3, "selected": true, "text": "<p>There are two little things to change</p>\n\n<ol>\n<li>First <code>:s</code> (and well as other search commands) will...
2018/07/13
[ "https://vi.stackexchange.com/questions/16744", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9173/" ]
I often use `#` key to quickly search for a keyword. I want to change the case of the last searched pattern in the easiest possible way. One way to do this is to use `\U\1` in the substitution part and pressing `Ctrl-r` followed by `/` in the search part of the standard substitution command, like this: ``` :%s/\(<Ct...
There are two little things to change 1. First `:s` (and well as other search commands) will search the last searched pattern if we double the separator (usually `/`). 2. Then of course, there is no longer a group. So we cannot use `\1`. Fortunately, there is the *match everything* group: `\0`, or its shortcut: `&` H...
16,764
<p>Here is a situation: I want to manage my working environment on multiple projects separately, and all of them should have its own session (<code>Session.vim</code>) to save and restore.</p> <p>So I would like to launch each project via <code>nvim -S SESSION_FILE</code>. And in order to save and quit easily, I defin...
[ { "answer_id": 16766, "author": "Lucas", "author_id": 18062, "author_profile": "https://vi.stackexchange.com/users/18062", "pm_score": 0, "selected": false, "text": "<p>There might be an easier way than checking the command line arguments. Depending on the value of <a href=\"http://vimd...
2018/07/16
[ "https://vi.stackexchange.com/questions/16764", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1072/" ]
Here is a situation: I want to manage my working environment on multiple projects separately, and all of them should have its own session (`Session.vim`) to save and restore. So I would like to launch each project via `nvim -S SESSION_FILE`. And in order to save and quit easily, I define the following: ``` nnoremap <...
Vim version [8.1.2233](https://github.com/vim/vim/releases/tag/v8.1.2233) adds the read-only variable `v:argv`, which can be used to parse the command line arguments given to Vim.
16,774
<p>Suppose I want to search for things like</p> <p><code>\todo{English sentence}</code></p> <p>Then the regex</p> <p><code>\\todo{\_.\{-}}</code></p> <p>works (I don't know why. I copied it from somewhere long time ago (embarrassed)).</p> <p>But suppose I want to match things like</p> <p><code>\todo{anything what...
[ { "answer_id": 16777, "author": "Vitor", "author_id": 599, "author_profile": "https://vi.stackexchange.com/users/599", "pm_score": 3, "selected": true, "text": "<p>Per the help pages in Vim:</p>\n\n<pre><code>\\{-} matches 0 or more of the preceding atom, as few as possible\n* M...
2018/07/16
[ "https://vi.stackexchange.com/questions/16774", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2369/" ]
Suppose I want to search for things like `\todo{English sentence}` Then the regex `\\todo{\_.\{-}}` works (I don't know why. I copied it from somewhere long time ago (embarrassed)). But suppose I want to match things like `\todo{anything whatsoever}` Then the above regex is no good. For example, if I have `\to...
Per the help pages in Vim: ``` \{-} matches 0 or more of the preceding atom, as few as possible * Matches 0 or more of the preceding atom, as many as possible. ``` In my small test case replacing the former with the latter matched your example string. That is: ``` \\todo{\_.*} ```
16,786
<p>I can resize horizontal split windows by <code>ctrl-w-shift-&lt;</code> and <code>ctrl-w-shift-&gt;</code>. I would like to have a shortcut for that.</p> <p>Close to the topic, recently I learned about the following maps:</p> <pre><code>nnoremap &lt;C-j&gt; &lt;C-w&gt;j nnoremap &lt;C-k&gt; &lt;C-w&gt;k nnoremap &...
[ { "answer_id": 16817, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>Your mappings have two problems:</p>\n\n<p>One problem can be solved easily: you don't need to escape <code>&lt;</code> ...
2018/07/18
[ "https://vi.stackexchange.com/questions/16786", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18250/" ]
I can resize horizontal split windows by `ctrl-w-shift-<` and `ctrl-w-shift->`. I would like to have a shortcut for that. Close to the topic, recently I learned about the following maps: ``` nnoremap <C-j> <C-w>j nnoremap <C-k> <C-w>k nnoremap <C-h> <C-w>h nnoremap <C-l> <C-w>l ``` So I tried: ``` nnoremap <C-\<> ...
Your mappings have two problems: One problem can be solved easily: you don't need to escape `<` and `>` in the right-hand part of the mappings, for example, these ones work properly: ``` nnoremap <C-a> <C-w>> nnoremap <C-b> <C-w>< ``` Your second problem, which can't really be solved is that you're trying to map `C...
16,795
<p>I could create a terminal with vim by running <code>:term</code> in the vim normal mode. However, this terminal is opened at the top of the window and I would like to open it in the bottom. How could I open it at the bottom? By the way, how could I change the height of this window?</p>
[ { "answer_id": 16800, "author": "Steven Walton", "author_id": 18265, "author_profile": "https://vi.stackexchange.com/users/18265", "pm_score": 4, "selected": false, "text": "<p>In your ~/.vimrc add the line</p>\n<pre><code>set splitbelow\n</code></pre>\n<p>This will cause all splits to h...
2018/07/19
[ "https://vi.stackexchange.com/questions/16795", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18259/" ]
I could create a terminal with vim by running `:term` in the vim normal mode. However, this terminal is opened at the top of the window and I would like to open it in the bottom. How could I open it at the bottom? By the way, how could I change the height of this window?
In your ~/.vimrc add the line ``` set splitbelow ``` This will cause all splits to happen below (including terminal). To change the height of the terminal (row x col) ``` set termwinsize=10x0 " 'termsize' didn't work - this did for me (GVIM 8.2) ```
16,799
<p>Imagine a situation, where you remember, that you want to re-use something you have deleted a while ago. Most likely the thing that has been deleted is stored in one of the numeric registers. Usually it's not a big deal to just type <code>:reg</code> and start looking through the list. However, I often find myself i...
[ { "answer_id": 16800, "author": "Steven Walton", "author_id": 18265, "author_profile": "https://vi.stackexchange.com/users/18265", "pm_score": 4, "selected": false, "text": "<p>In your ~/.vimrc add the line</p>\n<pre><code>set splitbelow\n</code></pre>\n<p>This will cause all splits to h...
2018/07/19
[ "https://vi.stackexchange.com/questions/16799", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7784/" ]
Imagine a situation, where you remember, that you want to re-use something you have deleted a while ago. Most likely the thing that has been deleted is stored in one of the numeric registers. Usually it's not a big deal to just type `:reg` and start looking through the list. However, I often find myself in a situation,...
In your ~/.vimrc add the line ``` set splitbelow ``` This will cause all splits to happen below (including terminal). To change the height of the terminal (row x col) ``` set termwinsize=10x0 " 'termsize' didn't work - this did for me (GVIM 8.2) ```
16,804
<p>I run my <code>make</code> commands asynchronously in vim with the <a href="https://github.com/skywind3000/asyncrun.vim" rel="nofollow noreferrer">asyncrun</a> plugin.</p> <p>I use this code in my <code>.vimrc</code> to open the quickfix window automatically everytime I run an asynchronous make command in order to ...
[ { "answer_id": 16805, "author": "flemingfleming", "author_id": 16910, "author_profile": "https://vi.stackexchange.com/users/16910", "pm_score": 2, "selected": false, "text": "<p>Running <code>wincmd p</code> after the copen should work; you jump to the quickfix window and then right back...
2018/07/19
[ "https://vi.stackexchange.com/questions/16804", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18267/" ]
I run my `make` commands asynchronously in vim with the [asyncrun](https://github.com/skywind3000/asyncrun.vim) plugin. I use this code in my `.vimrc` to open the quickfix window automatically everytime I run an asynchronous make command in order to see the output. ``` augroup vimrc autocmd QuickFixCmdPost * bot...
I had the same thinking for a solution as the other answer here has (`wincmd p`). But I found it was not 100% reliable depending on what quickfix command type is being used. If you have issues with that solution you might have some better luck with a solution that uses explicit window/buffer references. An easy approa...
16,806
<p>I'm now using</p> <pre><code>silent! let l:status = system(l:command . ' &gt; /dev/null') if match(l:status, '\cunknown') != -1 || match(l:status, '\cnot') != -1 echo 'command not found' return 0`enter code here` endif </code></pre> <p>i know it's not complete but is there any better way to check?</p> <h...
[ { "answer_id": 16825, "author": "tga", "author_id": 18254, "author_profile": "https://vi.stackexchange.com/users/18254", "pm_score": 2, "selected": false, "text": "<p>thanks for the comments above, i'm using this code right now:</p>\n\n<pre><code>silent! let l:status = system('command -v...
2018/07/19
[ "https://vi.stackexchange.com/questions/16806", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18254/" ]
I'm now using ``` silent! let l:status = system(l:command . ' > /dev/null') if match(l:status, '\cunknown') != -1 || match(l:status, '\cnot') != -1 echo 'command not found' return 0`enter code here` endif ``` i know it's not complete but is there any better way to check? ### edit i'm now using ``` silent...
Incidentally vim has a special function just for this: [`executable()`](http://vimdoc.sourceforge.net/htmldoc/eval.html#executable()).
16,821
<p>I'd like to run make and display the output when I press <kbd>Ctrl</kbd>+<kbd>m</kbd> in Vim. I know how to run make and display the output while in command mode, thanks to <a href="https://stackoverflow.com/a/6549828/1876983">this StackOverflow answer</a>, namely with:</p> <pre><code>:make | copen </code></pre> <...
[ { "answer_id": 16825, "author": "tga", "author_id": 18254, "author_profile": "https://vi.stackexchange.com/users/18254", "pm_score": 2, "selected": false, "text": "<p>thanks for the comments above, i'm using this code right now:</p>\n\n<pre><code>silent! let l:status = system('command -v...
2018/07/20
[ "https://vi.stackexchange.com/questions/16821", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11076/" ]
I'd like to run make and display the output when I press `Ctrl`+`m` in Vim. I know how to run make and display the output while in command mode, thanks to [this StackOverflow answer](https://stackoverflow.com/a/6549828/1876983), namely with: ``` :make | copen ``` but how do I bind this to a keyboard shortcut? I mana...
Incidentally vim has a special function just for this: [`executable()`](http://vimdoc.sourceforge.net/htmldoc/eval.html#executable()).
16,826
<p><a href="https://i.stack.imgur.com/NRH9w.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NRH9w.gif" alt="enter image description here"></a></p> <p>When I paste something within normal mode, vim ignores <code>autoindent</code>. I copy and paste with <code>y</code> and <code>p</code>. As mentioned ...
[ { "answer_id": 16863, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 1, "selected": false, "text": "<h2><code>=p</code> from <a href=\"https://github.com/tpope/vim-unimpaired\" rel=\"nofollow noreferrer\">vim-unimpaired</...
2018/07/20
[ "https://vi.stackexchange.com/questions/16826", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18254/" ]
[![enter image description here](https://i.stack.imgur.com/NRH9w.gif)](https://i.stack.imgur.com/NRH9w.gif) When I paste something within normal mode, vim ignores `autoindent`. I copy and paste with `y` and `p`. As mentioned `autoindent` is on. It works fine when I manually indent or type something before pasting. Al...
Paste from insert mode `<Ctrl-r>0` ---------------------------------- You can also insert the yanked text from insert mode when `autoindent` has added the correct indentation: 1. `yiw` yank 2. `o<CR>` switch to insert mode and add new line 3. `<Ctrl-r>0` paste text from register `0` Drew Neil has created a vimcast ...
16,829
<p>Does anybody know the command for moving to an outer block of brackets/parentheses?</p> <p>Lets say that my cursor is in the innermost bracket. I know that <code>%</code> moves to a matching bracket, but is there a command to move from say, bracket 1 to bracket 2?</p> <pre><code>3 { 2 { 1 { } 2 } ...
[ { "answer_id": 16830, "author": "Cometsong", "author_id": 2303, "author_profile": "https://vi.stackexchange.com/users/2303", "pm_score": 2, "selected": false, "text": "<p>You can use <code>[m</code> to move to beginning of <code>match</code>ed brackets, then sequentially up levels.</p>\n...
2018/07/20
[ "https://vi.stackexchange.com/questions/16829", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18290/" ]
Does anybody know the command for moving to an outer block of brackets/parentheses? Lets say that my cursor is in the innermost bracket. I know that `%` moves to a matching bracket, but is there a command to move from say, bracket 1 to bracket 2? ``` 3 { 2 { 1 { } 2 } 3 } ```
`[%` and `]%` provided by [*matchit*](https://github.com/vim/vim/blob/master/runtime/pack/dist/opt/matchit/doc/matchit.txt) or [*match-up*](https://github.com/andymass/vim-matchup) -------------------------------------------------------------------------------------------------------------------------------------------...
16,832
<p>My .vimrc includes the following lines:</p> <pre><code>if filereadable("my_source") :source my_source endif </code></pre> <p>That is, if the file 'my_source' exists in the folder where I open vim and it is readable, it is loaded automatically.</p> <p>However, if I am editing a file in that folder and open ano...
[ { "answer_id": 16833, "author": "Naumann", "author_id": 11477, "author_profile": "https://vi.stackexchange.com/users/11477", "pm_score": 1, "selected": false, "text": "<p>the statements in <code>.vimrc</code> are executed only once.\nYou could create an <code>autocommand</code> for this ...
2018/07/20
[ "https://vi.stackexchange.com/questions/16832", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6023/" ]
My .vimrc includes the following lines: ``` if filereadable("my_source") :source my_source endif ``` That is, if the file 'my\_source' exists in the folder where I open vim and it is readable, it is loaded automatically. However, if I am editing a file in that folder and open another file (also in that same fol...
You need to use an [`autocommand`](http://vimdoc.sourceforge.net/htmldoc/autocmd.html) to accomplish this, as your `.vimrc` is only sourced once on startup. As their name would suggest, `autocmd`s allow for defining a series of commands that should occur automatically when certain events are fired. I recommend you rea...
16,841
<p>I opened 5 buffers and in one of them I use the command <code>:vs</code> to split the current buffer screen into two.<br> When I use the command <code>&lt;leader&gt;d</code> to close one of the splitted buffers, the consequence is that the splitted window is also closed along with the buffer to be closed. I would li...
[ { "answer_id": 16844, "author": "ZeroKnight", "author_id": 1452, "author_profile": "https://vi.stackexchange.com/users/1452", "pm_score": 2, "selected": false, "text": "<p><a href=\"https://github.com/moll/vim-bbye\" rel=\"nofollow noreferrer\">vim-bbye</a> does exactly what you're looki...
2018/07/22
[ "https://vi.stackexchange.com/questions/16841", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18259/" ]
I opened 5 buffers and in one of them I use the command `:vs` to split the current buffer screen into two. When I use the command `<leader>d` to close one of the splitted buffers, the consequence is that the splitted window is also closed along with the buffer to be closed. I would like to close the buffer without i...
[vim-bbye](https://github.com/moll/vim-bbye) does exactly what you're looking for. It provides `:Bdelete` and `:Bwipeout`, which are variants of `:bdelete` and `:bwipeout` that will delete the buffer **but maintain the split and switch to another buffer**, preserving your current split layout. I personally mapped `:Bd...
16,843
<p>I hear somewhere that if <code>backup</code> is disabled and <code>writebackup</code> is enabled, Vim will create backup files for the duration of the edit session and will delete these backup files afterward. However, even with these settings, i.e.</p> <pre><code>set nobackup set writebackup " Enabled! set noswapf...
[ { "answer_id": 16845, "author": "Lucas", "author_id": 18062, "author_profile": "https://vi.stackexchange.com/users/18062", "pm_score": 2, "selected": false, "text": "<p>As @ZeroKnight said with <code>:set nobackup writebackup</code> the backup file will be used during <code>:write</code>...
2018/07/22
[ "https://vi.stackexchange.com/questions/16843", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7200/" ]
I hear somewhere that if `backup` is disabled and `writebackup` is enabled, Vim will create backup files for the duration of the edit session and will delete these backup files afterward. However, even with these settings, i.e. ``` set nobackup set writebackup " Enabled! set noswapfile set noundofile ``` I don't s...
`backup` and `writebackup` are two separate yet intertwined options; they are essentially two halves of the same whole. I think the easiest way to explain these two options is by detailing what happens when you attempt to overwrite a file with some combination of these options. ### Scenario Breakdown Assume you have ...
16,851
<p>I don't understand why is Vim pasting after the cursor; for example in this example (where the cursor is at the start):</p> <pre><code>|The quick brown fox jumps over a lazy dog ^ </code></pre> <p>I would like to exchange <code>fox</code> and <code>dog</code>:</p> <ul> <li><code>ff</code> – Find fox</li> <li><cod...
[ { "answer_id": 16853, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>If you read <a href=\"http://vimhelp.appspot.com/change.txt.html#p\" rel=\"noreferrer\"><code>:h p</code></a> you'll see...
2018/07/23
[ "https://vi.stackexchange.com/questions/16851", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2548/" ]
I don't understand why is Vim pasting after the cursor; for example in this example (where the cursor is at the start): ``` |The quick brown fox jumps over a lazy dog ^ ``` I would like to exchange `fox` and `dog`: * `ff` – Find fox * `yw` – Yank fox * `fd` – Find dog * `p` – Paste Which gives me: ``` The quick b...
See @statox answer for `p`, `P`, `i` and `a`. Background: This has to do with the way the cursor works in a terminal (and hence originally the typewriter). The terminal is a grid of character cells and the cursor is on one of these cells. It is never between two cells. This is handled differently in modern GUIs where ...
16,867
<p>I frequently have inline comments for variables:</p> <pre><code>var1 = 0 # Var 1 var2 = 0 # Var 2 var3 = 0 # Var 3 var4 = 0 # Var 4 </code></pre> <p>(This is in python, for example, but this question applies to C-Style <code>//</code> just the same.)</p> <p>Sometimes it happens that as I develop I hav...
[ { "answer_id": 16868, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 4, "selected": true, "text": "<p><code>&gt;w</code> doesn't work because <code>&gt;</code> is a line-wise operator no matter what motion you give it.</p>\...
2018/07/24
[ "https://vi.stackexchange.com/questions/16867", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17830/" ]
I frequently have inline comments for variables: ``` var1 = 0 # Var 1 var2 = 0 # Var 2 var3 = 0 # Var 3 var4 = 0 # Var 4 ``` (This is in python, for example, but this question applies to C-Style `//` just the same.) Sometimes it happens that as I develop I have to add new variables and they may end up b...
`>w` doesn't work because `>` is a line-wise operator no matter what motion you give it. There are a few ways to accomplish the edit you're looking for: ### 1. insertion with repeat After you've inserted tabs/spaces to get the alignment you want, press `.` on the remaining lines. No need to insert again. ### 2. vis...
16,873
<p>Should be straight-foward but cannot get it working. I have a text file that has numbers at the beginning of some lines. For e.g:</p> <pre><code>1. Some text.... running to many lines 2. Some more text ... 3. A long line... that spans... many more.. lines </code></pre> <p>I'd like to add a prefix <code>3.</code> t...
[ { "answer_id": 16875, "author": "Naumann", "author_id": 11477, "author_profile": "https://vi.stackexchange.com/users/11477", "pm_score": 2, "selected": false, "text": "<p>You can do this with</p>\n\n<pre><code>:%s/^\\ze\\d/3.\n</code></pre>\n\n<p>From <a href=\"http://vimhelp.appspot.com...
2018/07/25
[ "https://vi.stackexchange.com/questions/16873", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4699/" ]
Should be straight-foward but cannot get it working. I have a text file that has numbers at the beginning of some lines. For e.g: ``` 1. Some text.... running to many lines 2. Some more text ... 3. A long line... that spans... many more.. lines ``` I'd like to add a prefix `3.` to each of the numbers. ``` %s,^\d\+...
Firstly, you don't need to escape the dot in the replacement section (because in that part of the command it doesn't have another possible meaning). However, that's not the cause of your problem, which is instead that you're using `\1` (the first captured group), but your expression doesn't contain any groups. You ca...
16,874
<p>I know it's not a bug, since the <code>help</code> page explains it cleary, but is there any reason why <code>gt</code> is still kept different from the majority of commands that accept a <code>{count}</code> prepended? I mean, isn't it in contrast with <code>vi(m)</code> phylosophy?</p> <p>What annoys me the most ...
[ { "answer_id": 16877, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": true, "text": "<p>I can't really explain why it works like this, my best guess is that you more often need to go a tab by its index rather ...
2018/07/25
[ "https://vi.stackexchange.com/questions/16874", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6498/" ]
I know it's not a bug, since the `help` page explains it cleary, but is there any reason why `gt` is still kept different from the majority of commands that accept a `{count}` prepended? I mean, isn't it in contrast with `vi(m)` phylosophy? What annoys me the most is that `gt` and `gT` are not the opposite of each oth...
I can't really explain why it works like this, my best guess is that you more often need to go a tab by its index rather than going 3 tabs forwards. However, if you really don't like how Vim works and want to be able to "undo" a `2gT` with `2gt` you can add the following to your vimrc: ``` function! Mygt(forward, cou...
16,878
<p>I'm trying to do two things involving <strong>blank</strong> lines (empty lines or lines with only white-space on them).</p> <ol> <li>Move to the next <strong>blank</strong> line (or EOF if none)</li> <li>Filter (using <code>!</code>) to the next <strong>blank</strong> line (or EOF if none)</li> </ol> <p>Number 1 ...
[ { "answer_id": 16877, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": true, "text": "<p>I can't really explain why it works like this, my best guess is that you more often need to go a tab by its index rather ...
2018/07/25
[ "https://vi.stackexchange.com/questions/16878", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9490/" ]
I'm trying to do two things involving **blank** lines (empty lines or lines with only white-space on them). 1. Move to the next **blank** line (or EOF if none) 2. Filter (using `!`) to the next **blank** line (or EOF if none) Number 1 is similar to `}`, but allows for lines with only white-space. I thought number 2 w...
I can't really explain why it works like this, my best guess is that you more often need to go a tab by its index rather than going 3 tabs forwards. However, if you really don't like how Vim works and want to be able to "undo" a `2gT` with `2gt` you can add the following to your vimrc: ``` function! Mygt(forward, cou...
16,883
<p>I really like <code>Ctrl-E</code> and <code>Ctrl-Y</code> in normal mode, which expose additional lines at the bottom or top of the screen (respectively) without moving the cursor.</p> <p>I'd like to do the same thing in insert mode sometimes when I'm writing and want to look at some earlier text a few lines up at ...
[ { "answer_id": 16884, "author": "Lucas", "author_id": 18062, "author_profile": "https://vi.stackexchange.com/users/18062", "pm_score": 1, "selected": false, "text": "<p>If you <code>set mouse=a</code> the mouse can also scroll in insert mode. </p>\n\n<p>And the <kbd>↑</kbd> and <kbd>↓</k...
2018/07/25
[ "https://vi.stackexchange.com/questions/16883", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4676/" ]
I really like `Ctrl-E` and `Ctrl-Y` in normal mode, which expose additional lines at the bottom or top of the screen (respectively) without moving the cursor. I'd like to do the same thing in insert mode sometimes when I'm writing and want to look at some earlier text a few lines up at the same time. `Ctrl-E` and `Ct...
The built-in way to scroll while in insert mode is described at [`:h i_CTRL-X_CTRL-E`](http://vimhelp.appspot.com/insert.txt.html#i_CTRL-X_CTRL-E) ``` *i_CTRL-X_CTRL-E* CTRL-X CTRL-E scroll window one line up. When doing completion look here: |complete_CTRL-E| ...
16,888
<p>I find and replace a pattern in all the files in my project (which is a big one). After the search is done, quickfix window is opened with the matches. The matches are in different files in different directories/sub-directories. </p> <p>When I want to replace all the matches in the quickfix list, I run the followin...
[ { "answer_id": 16890, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 4, "selected": true, "text": "<h2>Update: New official vim plugin <a href=\"https://github.com/vim/vim/blob/master/runtime/pack/dist/opt/cfilter/plugin/...
2018/07/26
[ "https://vi.stackexchange.com/questions/16888", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16800/" ]
I find and replace a pattern in all the files in my project (which is a big one). After the search is done, quickfix window is opened with the matches. The matches are in different files in different directories/sub-directories. When I want to replace all the matches in the quickfix list, I run the following command:...
Update: New official vim plugin [*cfilter*](https://github.com/vim/vim/blob/master/runtime/pack/dist/opt/cfilter/plugin/cfilter.vim) ------------------------------------------------------------------------------------------------------------------------------------ Since [21.8.2018 (patch: 8.1.0311)](https://github.co...
16,895
<p>In command mode, <code>r</code> replaces the character under the cursor by the one pressed right after typing <code>r</code> without going into insert mode, so there's no <code>esc</code> to press.</p> <p><code>5r</code> replaces the 5 characters starting from the one under the cursor by the <strong>same</strong> s...
[ { "answer_id": 16890, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 4, "selected": true, "text": "<h2>Update: New official vim plugin <a href=\"https://github.com/vim/vim/blob/master/runtime/pack/dist/opt/cfilter/plugin/...
2018/07/27
[ "https://vi.stackexchange.com/questions/16895", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/12085/" ]
In command mode, `r` replaces the character under the cursor by the one pressed right after typing `r` without going into insert mode, so there's no `esc` to press. `5r` replaces the 5 characters starting from the one under the cursor by the **same** single character typed after `5r` (the new character is repeated 5 t...
Update: New official vim plugin [*cfilter*](https://github.com/vim/vim/blob/master/runtime/pack/dist/opt/cfilter/plugin/cfilter.vim) ------------------------------------------------------------------------------------------------------------------------------------ Since [21.8.2018 (patch: 8.1.0311)](https://github.co...
16,898
<p>On my Raspberry Pi, I have a global configuration file at <code>/etc/vim/vimrc</code>. I also have a file at <code>/etc/vimrc</code>. I've tried modifying this second file, probably because I read somewhere that this is where to modify a global vimrc file for the system, but it hasn't made the expected changes. (Spe...
[ { "answer_id": 16899, "author": "Lucas", "author_id": 18062, "author_profile": "https://vi.stackexchange.com/users/18062", "pm_score": 1, "selected": false, "text": "<p>You can take a look at the man page or at <a href=\"http://vimdoc.sourceforge.net/htmldoc/starting.html#system-vimrc\" ...
2018/07/27
[ "https://vi.stackexchange.com/questions/16898", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16795/" ]
On my Raspberry Pi, I have a global configuration file at `/etc/vim/vimrc`. I also have a file at `/etc/vimrc`. I've tried modifying this second file, probably because I read somewhere that this is where to modify a global vimrc file for the system, but it hasn't made the expected changes. (Specifically, `set hlsearch`...
You can take a look at the man page or at [`:help system-vimrc`](http://vimdoc.sourceforge.net/htmldoc/starting.html#system-vimrc) or `:version` to find out which is your *real* system wide vimrc file. It should probably source the other one (if it doesn't then it is clear why your changes take no effect if you put the...
16,904
<p>I'm working with a terminal emulator, and want to send the right key presses/escape sequences to vim, so it inteprets them as the left/right scroll wheel buttons.</p> <p>64/65 works for up/down:</p> <pre><code>&lt;ScrollWheelUp&gt; printf("\033[&lt;%d;%d;%d", 64, row, col) &lt;ScrollWheelDown&gt; printf("\033[&l...
[ { "answer_id": 16899, "author": "Lucas", "author_id": 18062, "author_profile": "https://vi.stackexchange.com/users/18062", "pm_score": 1, "selected": false, "text": "<p>You can take a look at the man page or at <a href=\"http://vimdoc.sourceforge.net/htmldoc/starting.html#system-vimrc\" ...
2018/07/28
[ "https://vi.stackexchange.com/questions/16904", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3189/" ]
I'm working with a terminal emulator, and want to send the right key presses/escape sequences to vim, so it inteprets them as the left/right scroll wheel buttons. 64/65 works for up/down: ``` <ScrollWheelUp> printf("\033[<%d;%d;%d", 64, row, col) <ScrollWheelDown> printf("\033[<%d;%d;%d", 65, row, col) ``` But wh...
You can take a look at the man page or at [`:help system-vimrc`](http://vimdoc.sourceforge.net/htmldoc/starting.html#system-vimrc) or `:version` to find out which is your *real* system wide vimrc file. It should probably source the other one (if it doesn't then it is clear why your changes take no effect if you put the...
16,906
<p>Given a file with a large JSON object all on one line like</p> <pre><code>{&quot;versions&quot;:[{&quot;count&quot;:2,&quot;version&quot;:&quot;&quot;},{&quot;count&quot;:1,&quot;version&quot;:&quot;1.1.1&quot;},{&quot;count&quot;:14,&quot;version&quot;:&quot;2.9&quot;},{... </code></pre> <p>How can I format this to...
[ { "answer_id": 16908, "author": "ljs.dev", "author_id": 11715, "author_profile": "https://vi.stackexchange.com/users/11715", "pm_score": 6, "selected": false, "text": "<p>This one-liner works well to format JSON in Vim into a human readable form:</p>\n\n<p><code>:%!python -m json.tool</c...
2018/07/28
[ "https://vi.stackexchange.com/questions/16906", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11715/" ]
Given a file with a large JSON object all on one line like ``` {"versions":[{"count":2,"version":""},{"count":1,"version":"1.1.1"},{"count":14,"version":"2.9"},{... ``` How can I format this to be human readable in Vim?
Or you can install `jq` which is faster (written in C) from your package manager (e.g. `sudo apt install jq` in Ubuntu/Debian, `sudo dnf install jq` on Fedora/RHEL/CentOS) or [from source](https://github.com/stedolan/jq) and then in vim, type: ``` :%!jq . ```
16,907
<p>Let say I want to run a command that uses a matched group of a pattern for each line matching the pattern.<br> The natural choice is <code>:g</code>. With the command <code>:s</code>, there is no problem. If i would do </p> <pre><code>:g/aaa\(.*\)/s//X\1X </code></pre> <p>for example, then it would work. But if ...
[ { "answer_id": 16920, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<h1>TL;DR</h1>\n\n<p>There is no simple way to get capture groups into other commands. They simply don't see them....
2018/07/28
[ "https://vi.stackexchange.com/questions/16907", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18375/" ]
Let say I want to run a command that uses a matched group of a pattern for each line matching the pattern. The natural choice is `:g`. With the command `:s`, there is no problem. If i would do ``` :g/aaa\(.*\)/s//X\1X ``` for example, then it would work. But if I would try ``` :g/aaa\(.*\)/echo \1 ``` It w...
After some time, where I am more experienced, I decided to write a generic solution for this problem. It is based on the answer of [Rich](https://vi.stackexchange.com/users/343/rich) Usage: ``` :<range>GL/pat/py python code ``` Passes over a range that is filtered by [pat]. Executes python code, where the first m...
16,914
<p>Previously (as far as I remember), <code>e!</code> used to drop undo history. Now, I'm using vim 8.0, and <code>e!</code> doesn't drop it.</p> <p>How to drop undo history in vim 8.0?</p>
[ { "answer_id": 16915, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 4, "selected": true, "text": "<p>I don't recall anything like that with <code>e!</code>. At least not since 'persistent undo' was added back in 2010 as...
2018/07/29
[ "https://vi.stackexchange.com/questions/16914", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18384/" ]
Previously (as far as I remember), `e!` used to drop undo history. Now, I'm using vim 8.0, and `e!` doesn't drop it. How to drop undo history in vim 8.0?
I don't recall anything like that with `e!`. At least not since 'persistent undo' was added back in 2010 as part of v7.3(b?). (I confirmed that the command sequence discussed below was in the documentation from that point forward.) I think when the feature was first added a lot of people wouldn't have had it enabled (i...
16,924
<p>System: gvim 8.1 1-116 / windows10</p> <p>A file that I'd like to use modeline (enabled): <code># vim: ft=python</code> but disable <code>ale</code> plugin that will trigger <code>on save</code> - the file contains some python codes.</p> <p>Command that I'd like to run by vim before parse the file: <code>:ALEDisab...
[ { "answer_id": 16925, "author": "Tuyen Pham", "author_id": 14274, "author_profile": "https://vi.stackexchange.com/users/14274", "pm_score": 0, "selected": false, "text": "<p>Silly me, I just want to have highlight of <code>python</code> while keep <code>ft=conf</code> because this is a n...
2018/07/30
[ "https://vi.stackexchange.com/questions/16924", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/14274/" ]
System: gvim 8.1 1-116 / windows10 A file that I'd like to use modeline (enabled): `# vim: ft=python` but disable `ale` plugin that will trigger `on save` - the file contains some python codes. Command that I'd like to run by vim before parse the file: `:ALEDisable`. Here I just want to disbale ALE on a specific fil...
You've already solved your problem, but for the benefit of future readers, I'll paste a couple of bits from `:help modeline`: > > No other commands than "set" are supported, for security reasons (somebody > might create a Trojan horse text file with modelines). > > > [...] > > > Hint: If you would like to do som...
16,930
<p>I am using vim and simply want to disable auto indent when I paste text into my terminal vim session. I have tried numerous solutions including various incantations of below to <code>~/.vimrc</code>:</p> <pre><code>set nopaste &quot; https://kb.iu.edu/d/afcw &quot; set noautoindent &quot; https://vi.stackexch...
[ { "answer_id": 16931, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": true, "text": "<p>You are looking for <a href=\"http://vimhelp.appspot.com/options.txt.html#%27paste%27\" rel=\"nofollow noreferrer\"><code...
2018/07/30
[ "https://vi.stackexchange.com/questions/16930", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/15795/" ]
I am using vim and simply want to disable auto indent when I paste text into my terminal vim session. I have tried numerous solutions including various incantations of below to `~/.vimrc`: ``` set nopaste " https://kb.iu.edu/d/afcw " set noautoindent " https://vi.stackexchange.com/questions/5310/how-can-i-stop-v...
You are looking for [`:h 'paste'`](http://vimhelp.appspot.com/options.txt.html#%27paste%27) and [`:h 'pastetoggle'`](http://vimhelp.appspot.com/options.txt.html#%27pastetoggle%27). It is not really a good idea to set `paste` in your vimrc since most of the time you don't want to have it set. The idea is to use `set p...
16,952
<p>If i've got the code</p> <pre><code>hello hellllo hello </code></pre> <p>i can insert code before or after all of the lines by using I or A in visual block mode, respectively. How can I delete the last x characters? I'm aware that I can do it with s/o// (where o would require more specific text realistically) but...
[ { "answer_id": 16953, "author": "Lucas", "author_id": 18062, "author_profile": "https://vi.stackexchange.com/users/18062", "pm_score": 2, "selected": false, "text": "<p>You can use <a href=\"http://vimdoc.sourceforge.net/htmldoc/change.html#v_x\" rel=\"nofollow noreferrer\"><code>x</code...
2018/07/31
[ "https://vi.stackexchange.com/questions/16952", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17655/" ]
If i've got the code ``` hello hellllo hello ``` i can insert code before or after all of the lines by using I or A in visual block mode, respectively. How can I delete the last x characters? I'm aware that I can do it with s/o// (where o would require more specific text realistically) but isn't there visual block ...
One way would be to select the lines (using any of the visual modes: block, line, or regular characterwise) and then type the command: ``` :norm! $xxx ``` Vim will pre-populate the command line with a range when you press `:` so the actual command you will execute is: ``` :'<,'>norm! $xxx ``` This acts like visit...
16,957
<p>I am facing huge slowness when i start the neovim for the first time in a session, and then next time i open it the startup time is little better relatively but not as fast as vim is. I looked at the issue tracker on official neovim git repo as well but couldn't find any solution for my problem. </p> <p>So i profil...
[ { "answer_id": 17049, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 2, "selected": false, "text": "<p>Okay it looks like those logfiles have been changed since the last time I looked\nat them (I remember some provi...
2018/08/01
[ "https://vi.stackexchange.com/questions/16957", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18373/" ]
I am facing huge slowness when i start the neovim for the first time in a session, and then next time i open it the startup time is little better relatively but not as fast as vim is. I looked at the issue tracker on official neovim git repo as well but couldn't find any solution for my problem. So i profiled it a bi...
Okay it looks like those logfiles have been changed since the last time I looked at them (I remember some provider plugin to be particularly bad, but I do not see it here now, which was the reason I suggested moving this to the neovim bugtracker). Okay, you need to figure out what makes start up so small. Here is an e...
16,963
<p>Is it possible to remap the <kbd>Esc</kbd> key to another key in Vim? When I'm using Vim in a full screen VMware vSphere web client console window and I press the <kbd>Esc</kbd> key to exit edit mode, it also takes me out of full screen mode in the console window.</p> <p>I am using the Vim that comes from the RHEL...
[ { "answer_id": 16969, "author": "Amir Eldor", "author_id": 14779, "author_profile": "https://vi.stackexchange.com/users/14779", "pm_score": 6, "selected": true, "text": "<p>Usually, <code>C-[</code> is also a way to get out of insert mode. Some people like to map <code>jj</code> in inser...
2018/08/01
[ "https://vi.stackexchange.com/questions/16963", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18415/" ]
Is it possible to remap the `Esc` key to another key in Vim? When I'm using Vim in a full screen VMware vSphere web client console window and I press the `Esc` key to exit edit mode, it also takes me out of full screen mode in the console window. I am using the Vim that comes from the RHEL YUM repo. (RHEL 7.5; Vim 7.4...
Usually, `C-[` is also a way to get out of insert mode. Some people like to map `jj` in insert mode as a way to exit and return to normal mode. I personally prefer `jh` as my fingers 'slide' better with this and I don't strain my middle finger much. From somewhere in my neovim settings: ``` inoremap jh <Esc> ``` Th...