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
16,964
<p>Currently, I set the following keymap to my <code>.vimrc</code>:</p> <pre><code>nnoremap &lt;C-z&gt; :NERDTreeToggle ~/Dropbox/jupyter/&lt;CR&gt; </code></pre> <p>However, I sometimes want to trigger it with different directory, for example:</p> <pre><code>:NERDTreeToggle CURRENT_DIR </code></pre> <p>However, I ...
[ { "answer_id": 16965, "author": "Spidey", "author_id": 10482, "author_profile": "https://vi.stackexchange.com/users/10482", "pm_score": 0, "selected": false, "text": "<p><code>getcwd()</code>, so the command you want would be <code>:NERDTreeToggle getcwd()</code>.</p>\n\n<p>You just exch...
2018/08/01
[ "https://vi.stackexchange.com/questions/16964", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1072/" ]
Currently, I set the following keymap to my `.vimrc`: ``` nnoremap <C-z> :NERDTreeToggle ~/Dropbox/jupyter/<CR> ``` However, I sometimes want to trigger it with different directory, for example: ``` :NERDTreeToggle CURRENT_DIR ``` However, I tried the following command [with the following answer](https://unix.sta...
The arguments you pass to a command are used as text, not as expressions, so unless a command specifically evaluates the expression in its implementation, passing an expression such as `getcwd()` won’t function how you’re hoping. Instead, you can write a command where the expression is evaluated before being passed to...
16,972
<p>Suppose I have a variable </p> <pre><code>let g:f_themes="./themes/**" </code></pre> <p>Suppose I want to map this command to a key:</p> <pre><code>:execute "vimgrep /".expand("&lt;cword&gt;")."/g ".g:f_themes." | copen" </code></pre> <p>That works, even though it may complain about not finding <code>&lt;cword&g...
[ { "answer_id": 16973, "author": "BSM", "author_id": 18439, "author_profile": "https://vi.stackexchange.com/users/18439", "pm_score": 0, "selected": false, "text": "<p>I think I got part of the answer: how to map a key to do this.</p>\n\n<p>First, declare this one-line function (1):</p>\n...
2018/08/01
[ "https://vi.stackexchange.com/questions/16972", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18439/" ]
Suppose I have a variable ``` let g:f_themes="./themes/**" ``` Suppose I want to map this command to a key: ``` :execute "vimgrep /".expand("<cword>")."/g ".g:f_themes." | copen" ``` That works, even though it may complain about not finding `<cword>`. I can deal with that. But what if I want to instead place th...
You can insert the evaluations of expressions into the command-line (or a buffer) with the expression register, by pressing `Ctrl-R``=`. You can also use this in a mapping: ``` nnoremap <leader>gt :vimgrep /<C-R>=expand("<cword>")<CR>/g <C-R>=g:f_themes<CR> <bar> copen ``` See `:help quote_=` for more details on the...
16,996
<p>I would like to add, say, the next three characters to the current visual selection. For example:</p> <pre>Do not select. <b>Select from here. Select this too. Select until the</b>re. Do not select. </pre> <p>If bold represents the selection, I would like to expand it by three characters at the end. If I know that...
[ { "answer_id": 16995, "author": "tivn", "author_id": 1782, "author_profile": "https://vi.stackexchange.com/users/1782", "pm_score": 2, "selected": false, "text": "<p>In normal mode <kbd>Ctrl-H</kbd> is same as <kbd>h</kbd> -- that is 'move to the left' while <kbd>Ctrl-L</kbd> means 'clea...
2018/08/04
[ "https://vi.stackexchange.com/questions/16996", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18470/" ]
I would like to add, say, the next three characters to the current visual selection. For example: ``` Do not select. **Select from here. Select this too. Select until the**re. Do not select. ``` If bold represents the selection, I would like to expand it by three characters at the end. If I know that the cursor is *...
In normal mode `Ctrl-H` is same as `h` -- that is 'move to the left' while `Ctrl-L` means 'clear and redraw the screen', not 'move to the right'. This `Ctrl-L` behavior is very similar to bash shell. This is useful for example when you have background process printing some stuff while you are using vim in terminal.
16,998
<p>I would like to type <code>begin!</code> in insert mode and having it immediately replaced by:</p> <pre> begin <i>[cursor here]</i> end </pre> <p>I considered mappings:</p> <pre><code>:inoremap begin! begin end&lt;Left&gt;&lt;Left&gt;&lt;Left&gt;&lt;Left&gt; </code></pre> <p>and abbreviations:</p> <pre><code>:...
[ { "answer_id": 16999, "author": "Maëlan", "author_id": 18470, "author_profile": "https://vi.stackexchange.com/users/18470", "pm_score": 2, "selected": false, "text": "<p>I found a kind of solution by reading <code>:help abbreviations</code>:</p>\n\n<pre><code>fun! EatBlank()\n let c = n...
2018/08/04
[ "https://vi.stackexchange.com/questions/16998", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18470/" ]
I would like to type `begin!` in insert mode and having it immediately replaced by: ``` begin *[cursor here]* end ``` I considered mappings: ``` :inoremap begin! begin end<Left><Left><Left><Left> ``` and abbreviations: ``` :iabbrev begin! begin end<Left><Left><Left><Left> ``` But both have caveats. (1) The...
As a follow-up: an actual answer is to use a **snippet plugin**, such as [UltiSnips](https://github.com/SirVer/ultisnips). Snippet plugins are: * already done; * designed precisely for that kind of things; * much easier to set up (just write templates as plain text in some config file); * much more comfortable to use ...
17,012
<h1>My Problem</h1> <p>I am editing a markdown file with some links in a <code>[link text](url)</code> format.</p> <p>Some of these links lack a space after the closing parens, e.g.:</p> <pre><code>...fit the [Single Responsibility Principle](https://link...)and can ... </code></pre> <p>Which renders to a missing s...
[ { "answer_id": 17014, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 1, "selected": false, "text": "<p>What about</p>\n\n<pre><code>%s#)\\zs\\ze\\S# #g\n</code></pre>\n\n<p>By default unless you change the <a href=\"htt...
2018/08/06
[ "https://vi.stackexchange.com/questions/17012", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13179/" ]
My Problem ========== I am editing a markdown file with some links in a `[link text](url)` format. Some of these links lack a space after the closing parens, e.g.: ``` ...fit the [Single Responsibility Principle](https://link...)and can ... ``` Which renders to a missing space after the link: > > ...fit the [Sin...
What about ``` %s#)\zs\ze\S# #g ``` By default unless you change the [`'magic'`](http://vimhelp.appspot.com/options.txt.html#%27magic%27) option, a closing parenthesis is matched by just `)`. BTW, here I've cheated with [`:h /\zs`](http://vimhelp.appspot.com/pattern.txt.html#%2f%5czs) and [`:h /\ze`](http://vimhelp....
17,063
<p>I am comforable with using history of edited files that is kept in viminfo, the one that sets the limit in the first setting of <code>set viminfo='100,...</code> variable.</p> <p>After I've started using mutt as email client and using vim as its editor, and that makes multiple temporary files created in /tmp/dir. T...
[ { "answer_id": 17064, "author": "Tag Wint", "author_id": 18356, "author_profile": "https://vi.stackexchange.com/users/18356", "pm_score": 2, "selected": false, "text": "<p>I guess I found a good solution for my use case. \n<code>-i</code> option allows to specify alternative locoation of...
2018/08/10
[ "https://vi.stackexchange.com/questions/17063", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18356/" ]
I am comforable with using history of edited files that is kept in viminfo, the one that sets the limit in the first setting of `set viminfo='100,...` variable. After I've started using mutt as email client and using vim as its editor, and that makes multiple temporary files created in /tmp/dir. These are of no intere...
I guess I found a good solution for my use case. `-i` option allows to specify alternative locoation of viminfo file. So I can specifey `vim -i /tmp/blackhole` for cases where I do not care of file history. In my case that is specifying ``` set editor = "vim -i /tmp/idontcare" ``` in my .muttrc
17,067
<p>how do I search/substitute in every other line. :s/pattern1/pattern2{2}/g</p> <p>file looks like</p> <p>1 pattern1 text 2 pattern1 text 3 pattern1 text 4 pattern1 text</p> <p>Output file should look like 1 pattern1 text 2 pattern2 text 3 pattern1 text 4 pattern2 text</p>
[ { "answer_id": 17070, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 4, "selected": true, "text": "<p>First thing I thought of is to just inject a conditional in a <code>:global</code> command. Something like this...</p>...
2018/08/10
[ "https://vi.stackexchange.com/questions/17067", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18562/" ]
how do I search/substitute in every other line. :s/pattern1/pattern2{2}/g file looks like 1 pattern1 text 2 pattern1 text 3 pattern1 text 4 pattern1 text Output file should look like 1 pattern1 text 2 pattern2 text 3 pattern1 text 4 pattern2 text
First thing I thought of is to just inject a conditional in a `:global` command. Something like this... ``` :g/./ if getcurpos()[1] % 2 == 0 | s/foo/bar/g | endif ``` The "global" command `:g/./` will stop at every line that has at least one character and run the following command. `getcurpos()` returns a list wher...
17,073
<p>I have a vim configuration file (~/.vimrc) with the following settings:</p> <pre><code>colo delek syntax on highlight clear CursorLine highlight clear CursorLineNR highlight clear LineNR highlight LineNR cterm=none ctermfg=Yellow ctermbg=none highlight CursorLineNR cterm=bold ctermfg=Black ctermbg=none </code></p...
[ { "answer_id": 24605, "author": "Biggybi", "author_id": 22375, "author_profile": "https://vi.stackexchange.com/users/22375", "pm_score": 2, "selected": false, "text": "<p>I think this is a bug.\nI my case, in vim 8.2, I can't highlight CursorLineNR when 'relativenumber' is set.</p>\n\n<p...
2018/08/11
[ "https://vi.stackexchange.com/questions/17073", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18565/" ]
I have a vim configuration file (~/.vimrc) with the following settings: ``` colo delek syntax on highlight clear CursorLine highlight clear CursorLineNR highlight clear LineNR highlight LineNR cterm=none ctermfg=Yellow ctermbg=none highlight CursorLineNR cterm=bold ctermfg=Black ctermbg=none ``` This used to work ...
I think this is a bug. I my case, in vim 8.2, I can't highlight CursorLineNR when 'relativenumber' is set. From the doc: > > CursorLineNr Like LineNr when 'cursorline' is set and 'cursorlineopt' is > set to "number" or "both", **or 'relativenumber' is set**, for > the cursor line. > > > So, here's my workaroun...
17,074
<p>By <code>:set hl</code>, the search result of a <code>/</code> expression is highlighted, for example:</p> <p><a href="https://i.stack.imgur.com/wkevu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wkevu.png" alt="Vim search highlight in action"></a></p> <p>And if one wants to replace one subst...
[ { "answer_id": 21024, "author": "eyal karni", "author_id": 18375, "author_profile": "https://vi.stackexchange.com/users/18375", "pm_score": 0, "selected": false, "text": "<p>This command GL meant to run python on a matched group. In this case, we run a search on the matched pattern.</p>\...
2018/08/11
[ "https://vi.stackexchange.com/questions/17074", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2082/" ]
By `:set hl`, the search result of a `/` expression is highlighted, for example: [![Vim search highlight in action](https://i.stack.imgur.com/wkevu.png)](https://i.stack.imgur.com/wkevu.png) And if one wants to replace one substring distinguished by its surrounding, one can do so elegantly using regex capture groups:...
I think the quick answer is "no". Partial solution: with a little extra typing, you can control what part of your search term gets hilighted: `\zs` to mark the start of highlighting, and `\ze` to mark the end. This works nicely for searches: ``` /"\zs\(foo\|bar\)\ze" ``` But breaks search-and-replace, eg with: ``...
17,090
<p>I am having a very long line file, I have to break the line into number of small lines.</p> <p>Example: </p> <pre><code>&lt; this&gt;is a testing&lt; /this&gt;&lt; next&gt;testing&lt; /next&gt;&lt; tested&gt;successfully&lt; /tested&gt; </code></pre> <p>I have to break it into as of below</p> <pre><code>&lt; thi...
[ { "answer_id": 17092, "author": "João A. Toledo", "author_id": 11384, "author_profile": "https://vi.stackexchange.com/users/11384", "pm_score": 1, "selected": false, "text": "<p>If for some reason you can't check those tools that statox recommended, you can use something like this:</p>\n...
2018/08/14
[ "https://vi.stackexchange.com/questions/17090", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18591/" ]
I am having a very long line file, I have to break the line into number of small lines. Example: ``` < this>is a testing< /this>< next>testing< /next>< tested>successfully< /tested> ``` I have to break it into as of below ``` < this>is a testing< / this> < next>testing< / next> < tested>successfully< /tested>...
If for some reason you can't check those tools that statox recommended, you can use something like this: ``` %s;\(< */[^>]\+>\);\1^M;g ``` It will look at every line for every closing tag (`\(< */[^>]\+>\)`) and replace it by itself and then a new line. The first part (to identify the closing tag) will search for ...
17,094
<p>If there is some text between quotations, such as</p> <p><code>"x = 5"</code></p> <p>I can type <code>ci"</code> in normal mode to delete the text inside the quotations and switch to insert mode.</p> <p>I often want to perform this same action on text between two dollar signs, such as</p> <p><code>$x = 5$</code>...
[ { "answer_id": 17095, "author": "3N4N", "author_id": 16280, "author_profile": "https://vi.stackexchange.com/users/16280", "pm_score": 4, "selected": true, "text": "<p>If you want only <code>$</code> to be a text object, then do the following</p>\n\n<pre><code>xnoremap i$ :&lt;C-u&gt; nor...
2018/08/14
[ "https://vi.stackexchange.com/questions/17094", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11931/" ]
If there is some text between quotations, such as `"x = 5"` I can type `ci"` in normal mode to delete the text inside the quotations and switch to insert mode. I often want to perform this same action on text between two dollar signs, such as `$x = 5$` But typing `ci$` has no effect. Is there a way to configure vi...
If you want only `$` to be a text object, then do the following ``` xnoremap i$ :<C-u> normal! T$vt$<CR> onoremap i$ :normal vi$<CR> xnoremap a$ :<C-u> normal!F$vf$<CR> onoremap a$ :normal va$<CR> ``` This will add some more text objects in your vim config. ``` for s:char in [ '_', '.', ':', ',', ';', '<bar>', '/',...
17,105
<p>I'm currently learning Vimscript, but I'm stuck at a particular problem.</p> <p>I'm creating a statusline which shows the full path (~) of the file currently displayed in the buffer. Instead of just using %F, I'm creating two separate highlight groups to show the difference between the cwd and the active file. Exam...
[ { "answer_id": 17111, "author": "Audun Olsen", "author_id": 18541, "author_profile": "https://vi.stackexchange.com/users/18541", "pm_score": 3, "selected": true, "text": "<p>Finally got it going thanks to some simple functions!</p>\n\n<pre><code>hi pwd guifg=#BADA55\nhi file guifg=#FFF09...
2018/08/16
[ "https://vi.stackexchange.com/questions/17105", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18541/" ]
I'm currently learning Vimscript, but I'm stuck at a particular problem. I'm creating a statusline which shows the full path (~) of the file currently displayed in the buffer. Instead of just using %F, I'm creating two separate highlight groups to show the difference between the cwd and the active file. Example: ~/pr...
Finally got it going thanks to some simple functions! ``` hi pwd guifg=#BADA55 hi file guifg=#FFF093 gui=bold hi line guifg=#FFFFFF hi statuslinenc gui=none hi statusline gui=none function! SetStatusLinePath() return system('print -P %~')[:-2] . "/" endfunction function! SetStatusLineFile() return fnamemod...
17,128
<p>When working in the C language, sometimes you have to write multi line macros like the following.</p> <pre><code>#define SOME_FUNCTION_LIKE_MACRO(a,b) \ foo(a); \ bar(b); \ baz(a+b); </code></pre> <p>Typically, after a few iterations of edi...
[ { "answer_id": 17129, "author": "Rafael Vega", "author_id": 5168, "author_profile": "https://vi.stackexchange.com/users/5168", "pm_score": 1, "selected": false, "text": "<p>I came up with this a few minutes after asking the question here. </p>\n\n<p>You hit if you want to add backslashe...
2018/08/17
[ "https://vi.stackexchange.com/questions/17128", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5168/" ]
When working in the C language, sometimes you have to write multi line macros like the following. ``` #define SOME_FUNCTION_LIKE_MACRO(a,b) \ foo(a); \ bar(b); \ baz(a+b); ``` Typically, after a few iterations of editing your code, the backsl...
Although your custom solution probably works better for you, I just want to mention that I use clang-format for this. Look for the setting 'AlignEscapedNewlines' here <https://clang.llvm.org/docs/ClangFormatStyleOptions.html>
17,136
<p>I began to get the error</p> <pre><code>Error detected while processing BufRead Auto commands for "*.sh": E117: Unknown function: dist#ft#SetFileTypeSH </code></pre> <p>when I opened shell scripts (*.sh) I think it happened after updating from a 7.x version to 8.0.</p> <p>How can it be fixed?</p> <p>As suggested...
[ { "answer_id": 17129, "author": "Rafael Vega", "author_id": 5168, "author_profile": "https://vi.stackexchange.com/users/5168", "pm_score": 1, "selected": false, "text": "<p>I came up with this a few minutes after asking the question here. </p>\n\n<p>You hit if you want to add backslashe...
2018/08/19
[ "https://vi.stackexchange.com/questions/17136", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18651/" ]
I began to get the error ``` Error detected while processing BufRead Auto commands for "*.sh": E117: Unknown function: dist#ft#SetFileTypeSH ``` when I opened shell scripts (\*.sh) I think it happened after updating from a 7.x version to 8.0. How can it be fixed? As suggested, I did a search for the function in `/...
Although your custom solution probably works better for you, I just want to mention that I use clang-format for this. Look for the setting 'AlignEscapedNewlines' here <https://clang.llvm.org/docs/ClangFormatStyleOptions.html>
17,167
<p>Want to read variable definitions from a tcl file, then dynamically define vim global variables. </p> <pre><code>set PATH_A /full/path/a set PATH_B /full/path/b other_tcl_commands </code></pre> <p>Read one line, split by space and save to list.<br> Use list[1] as variable name and list[2] as variable value.<br> L...
[ { "answer_id": 17172, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p>We can base a solution on these two commands:</p>\n\n<pre><code>let m = matchlist(getline(\".\"), PATTERN)\nexec \"let...
2018/08/24
[ "https://vi.stackexchange.com/questions/17167", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13402/" ]
Want to read variable definitions from a tcl file, then dynamically define vim global variables. ``` set PATH_A /full/path/a set PATH_B /full/path/b other_tcl_commands ``` Read one line, split by space and save to list. Use list[1] as variable name and list[2] as variable value. Like `let g:PATH_A = /full/pat...
We can base a solution on these two commands: ``` let m = matchlist(getline("."), PATTERN) exec "let g:" . m[1] . " = '" . m[2] . "'" ``` --- The first command processes the current buffer line into a list of pattern (sub)matches. I don't know anything about tcl variable definitions so I'm not sure exactly what you...
17,177
<p>In my current environment, I open a file with return key in NERDTree, but sometimes I want to open it in a new tab. That being said, there is still more case where I want to open a file in the current buffer, so I don't like to swap it.</p> <p>So I rather want to open it in a new tab with a separate key, possibly c...
[ { "answer_id": 17180, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>It's right there in the NERDTree help. Like it says at the top of the NERDTree window: <code>Press ? for help</code><...
2018/08/25
[ "https://vi.stackexchange.com/questions/17177", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1072/" ]
In my current environment, I open a file with return key in NERDTree, but sometimes I want to open it in a new tab. That being said, there is still more case where I want to open a file in the current buffer, so I don't like to swap it. So I rather want to open it in a new tab with a separate key, possibly ctrl + retu...
It's right there in the NERDTree help. Like it says at the top of the NERDTree window: `Press ? for help` ``` " File node mappings~ " double-click,<CR>,o: open in prev window " t: open in new tab " T: open in new tab silently ```
17,189
<p>Is there a succinct way to separate folds, open or closed, by the same number of newlines throughout the buffer? I'm using fold by indent. The goal is two visible blank lines between each fold (actually, after the end of a fold, since folds will abut non-folds). So if there is one blank line it adds another, and if ...
[ { "answer_id": 17180, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>It's right there in the NERDTree help. Like it says at the top of the NERDTree window: <code>Press ? for help</code><...
2018/08/27
[ "https://vi.stackexchange.com/questions/17189", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13731/" ]
Is there a succinct way to separate folds, open or closed, by the same number of newlines throughout the buffer? I'm using fold by indent. The goal is two visible blank lines between each fold (actually, after the end of a fold, since folds will abut non-folds). So if there is one blank line it adds another, and if the...
It's right there in the NERDTree help. Like it says at the top of the NERDTree window: `Press ? for help` ``` " File node mappings~ " double-click,<CR>,o: open in prev window " t: open in new tab " T: open in new tab silently ```
17,194
<p>I'm trying to define an insert mapping like this:</p> <pre><code>inoremap &lt;expr&gt;&lt;buffer&gt; ; (Test(expand('&lt;cWORD&gt;'))).&quot;;&quot; </code></pre> <p>in which the <code>Test</code> function is defined as:</p> <pre><code>func! Test(a) echom &quot;cword: &quot;.&quot;\&quot;&quot;.a:a.&quot;\&quot;...
[ { "answer_id": 17180, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>It's right there in the NERDTree help. Like it says at the top of the NERDTree window: <code>Press ? for help</code><...
2018/08/28
[ "https://vi.stackexchange.com/questions/17194", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18764/" ]
I'm trying to define an insert mapping like this: ``` inoremap <expr><buffer> ; (Test(expand('<cWORD>'))).";" ``` in which the `Test` function is defined as: ``` func! Test(a) echom "cword: "."\"".a:a."\"" endfunction ``` For example, if the current position of the cursor is like: ``` apple| ``` When I typ...
It's right there in the NERDTree help. Like it says at the top of the NERDTree window: `Press ? for help` ``` " File node mappings~ " double-click,<CR>,o: open in prev window " t: open in new tab " T: open in new tab silently ```
17,199
<p>Yesterday, I Installed vim and some colorscheme like gruvbox, monokai, molokai.</p> <p>I set it in <code>~/.vimrc</code> and turned on the syntax highlight, everything work well on HTML but in ruby files (<code>.rb</code>) it still have colorscheme but few keywords like <code>puts</code> and <code>print</code> are ...
[ { "answer_id": 17301, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 1, "selected": false, "text": "<p>There are two different things going on here that prevent colorization of the word <code>puts</code> in ruby fi...
2018/08/28
[ "https://vi.stackexchange.com/questions/17199", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18767/" ]
Yesterday, I Installed vim and some colorscheme like gruvbox, monokai, molokai. I set it in `~/.vimrc` and turned on the syntax highlight, everything work well on HTML but in ruby files (`.rb`) it still have colorscheme but few keywords like `puts` and `print` are still in grey color, it looks weird and boring. That ...
D.Ben Knoble has given a [terrific explanation](https://vi.stackexchange.com/a/17301/343) of exactly what happens in the default Ruby syntax configuration. However, I don't care for his two proposed solutions: 1. Complain to the Ruby syntax maintainers, 2. Edit the Ruby syntax file in your local Vim installation, whi...
17,207
<p>I'm wondering, if there's a way to move with <code>%</code> in CMakeLists.txt files between <code>foreach</code> and <code>endforeach</code>, <code>if</code> and <code>endif</code>, <code>function</code> and <code>endfunction</code>, …</p> <p>googeling I only found plugins that allow calling cmake from within vim,...
[ { "answer_id": 17209, "author": "pseyfert", "author_id": 6044, "author_profile": "https://vi.stackexchange.com/users/6044", "pm_score": 2, "selected": false, "text": "<p>I didn't find an existing solution, but the way to implement that doesn't seem too hard. One needs the matchit plugin ...
2018/08/29
[ "https://vi.stackexchange.com/questions/17207", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6044/" ]
I'm wondering, if there's a way to move with `%` in CMakeLists.txt files between `foreach` and `endforeach`, `if` and `endif`, `function` and `endfunction`, … googeling I only found plugins that allow calling cmake from within vim, but not for editing `CMakeLists.txt` files.
You can achieve this easily using either the plugin matchit (distributed with vim, just use `packadd! matchit`) or [match-up](https://github.com/andymass/vim-matchup) (external plugin). The latter provides enhanced text objects and also enables highlighting of the words. To define the matches for cmake, create a file ...
17,210
<p>I have a few packages installed in my <code>~/.vim/pack/default/start</code> directory, for example <a href="https://github.com/godlygeek/tabular" rel="noreferrer">Tabular</a> and <a href="https://github.com/godlygeek/tabular" rel="noreferrer">Unicode</a>. After starting up vim I can use these packages but cannot a...
[ { "answer_id": 17213, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 5, "selected": false, "text": "<p>Using <code>:helptags ALL</code> should re-generate all helptags for all <code>doc</code> directories in <code>runt...
2018/08/29
[ "https://vi.stackexchange.com/questions/17210", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9412/" ]
I have a few packages installed in my `~/.vim/pack/default/start` directory, for example [Tabular](https://github.com/godlygeek/tabular) and [Unicode](https://github.com/godlygeek/tabular). After starting up vim I can use these packages but cannot access their help information. Issuing `helptags ~/.vim/pack/default/sta...
Using `:helptags ALL` should re-generate all helptags for all `doc` directories in `runtimepath`; which should include the `~/.vim/pack/default/start/*` directories. You will probably get an error similar to: ``` E152: Cannot open /usr/share/vim/vim81/doc/tags for writing ``` Which is safe to ignore. Vim will conti...
17,215
<p>I am looking to insert list items</p> <pre><code>to-buy &gt; apple &gt; milk &gt; </code></pre> <p>but I would like to insert a constant string (" > ") on each newline</p> <p>is there a way to do this?</p>
[ { "answer_id": 17216, "author": "Lucas Payne", "author_id": 18654, "author_profile": "https://vi.stackexchange.com/users/18654", "pm_score": 0, "selected": false, "text": "<p>You can remap the behaviour of <code>&lt;cr&gt;</code> in insert-mode to a custom function that checks whether yo...
2018/08/30
[ "https://vi.stackexchange.com/questions/17215", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18789/" ]
I am looking to insert list items ``` to-buy > apple > milk > ``` but I would like to insert a constant string (" > ") on each newline is there a way to do this?
Well maybe it is not exactly what you want, but why not use such subst command after insert finished: ``` '[+1,']s/^/> / ``` Where * `'[+1` is second inserted line number * `']` is last inserted line number * `s` - subst command * `^` - start of line (position after "enter") * `>` - replacement text You can map th...
17,218
<p>I have two opening buffers and one has <code>foldenable</code> and <code>foldmethod=indent</code>, other has <code>nofoldenable</code> and <code>foldmethod=syntax</code>.</p> <p>I need that when I move between buffers, each buffer has it own <code>fold</code> settings and for example a buffer keeps folded even I mo...
[ { "answer_id": 17219, "author": "Tuyen Pham", "author_id": 14274, "author_profile": "https://vi.stackexchange.com/users/14274", "pm_score": 0, "selected": false, "text": "<p>We can achieve this by set <code>setlocal</code> for <code>python</code> file and <code>nofoldenable</code> in glo...
2018/08/30
[ "https://vi.stackexchange.com/questions/17218", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/14274/" ]
I have two opening buffers and one has `foldenable` and `foldmethod=indent`, other has `nofoldenable` and `foldmethod=syntax`. I need that when I move between buffers, each buffer has it own `fold` settings and for example a buffer keeps folded even I move to other buffer that has `nofoldenable` Can we achieve this? ...
If by move between buffers you mean -- doing it with a single window (no splits) then the only(?) option is to use autocommands. As an example: ``` augroup fold_params | au! au BufRead,BufNewFile *.py :setl fdm=indent | setl foldenable au BufRead,BufNewFile *.c :setl fdm=syntax | setl nofoldenable augroup end ...
17,227
<p>I renamed a big folder that contains a lot of files I recently edited. After changing the name, my neovim's <code>v:oldfiles</code> list contains the old names that is no longer accessible. How can I clean the list or fix the list to reflect the renaming. </p> <p>I use <code>fzf</code> to access the mru files. I tr...
[ { "answer_id": 17260, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 4, "selected": true, "text": "<h2>Fix entries in <em>ShaDa</em> File (neovim-specific)</h2>\n\n<p>Neovim does not use anymore the plaintext file <a href...
2018/08/31
[ "https://vi.stackexchange.com/questions/17227", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13302/" ]
I renamed a big folder that contains a lot of files I recently edited. After changing the name, my neovim's `v:oldfiles` list contains the old names that is no longer accessible. How can I clean the list or fix the list to reflect the renaming. I use `fzf` to access the mru files. I tried to set the variable directly...
Fix entries in *ShaDa* File (neovim-specific) --------------------------------------------- Neovim does not use anymore the plaintext file [`viminfo`](http://vimhelp.appspot.com/starting.txt.html#viminfo) (used by vim) to store this but uses a [msgpack](https://msgpack.org/) formatted file called ShaDa (short for shar...
17,254
<p>I want to do filter through an external program without actually filtering the lines (but to keep them). For example :</p> <pre><code>%!grep aa &gt; newfile </code></pre> <p>If I do this, all the lines are deleted and I need to do undo</p> <p>There is a more neat way to run an external program with args without c...
[ { "answer_id": 17257, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 4, "selected": true, "text": "<p>I think you’re looking for <code>:help :write_c</code>. Try this:</p>\n\n<pre><code>:w !grep aa &gt; newfile\n</code></pre>\n...
2018/09/01
[ "https://vi.stackexchange.com/questions/17254", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18375/" ]
I want to do filter through an external program without actually filtering the lines (but to keep them). For example : ``` %!grep aa > newfile ``` If I do this, all the lines are deleted and I need to do undo There is a more neat way to run an external program with args without changing the current buffer? Thanks.
I think you’re looking for `:help :write_c`. Try this: ``` :w !grep aa > newfile ```
17,262
<p>For Emacs there is <a href="https://github.com/victorhge/iedit" rel="nofollow noreferrer">idedit</a>. It Allows you to select some text, then hit one button, which automatically select all other occurrences of the selected text in the current buffer. Then you can edit the primary selection and the text in the second...
[ { "answer_id": 17268, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 3, "selected": true, "text": "<p>You can apply <a href=\"https://vi.stackexchange.com/a/6695/51\">Peter Rincker's solution</a>\nin a loop:</p>\n\n<pr...
2018/09/03
[ "https://vi.stackexchange.com/questions/17262", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18689/" ]
For Emacs there is [idedit](https://github.com/victorhge/iedit). It Allows you to select some text, then hit one button, which automatically select all other occurrences of the selected text in the current buffer. Then you can edit the primary selection and the text in the secondary selections will be modified accordin...
You can apply [Peter Rincker's solution](https://vi.stackexchange.com/a/6695/51) in a loop: ``` fun! ReplaceAll() " Don't do anything if there isn't a search pattern. if @/ is# '' return endif " Save view state and wrapscan setting. let l:save = winsaveview() let l:old_ws = &wrapscan ...
17,296
<p><strong>behave</strong> test language need to execute different lines of the behave feature file, for example, if I want to test the line number 99, I'll need to input the following line in the terminal</p> <pre><code>behave features/target.feature:99 -k </code></pre> <p>Currently I'm using Tmux and vim as my IDE....
[ { "answer_id": 17317, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 4, "selected": true, "text": "<p>To send to another pane you'll need to call <em>tmux</em> from Vim. Specifically, you'll need the <code>send-keys</cod...
2018/09/05
[ "https://vi.stackexchange.com/questions/17296", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/15958/" ]
**behave** test language need to execute different lines of the behave feature file, for example, if I want to test the line number 99, I'll need to input the following line in the terminal ``` behave features/target.feature:99 -k ``` Currently I'm using Tmux and vim as my IDE. I have 2 tmux panes and A and B, vim e...
To send to another pane you'll need to call *tmux* from Vim. Specifically, you'll need the `send-keys` command (alias: `send`). For example, this will cause the current line number in Vim to be printed to the terminal in pane 2 using `echo`: ``` :exe "!tmux send -t 2 'echo " . line(".") . "' Enter" ``` Applying the ...
17,312
<p>Suppose, I have </p> <pre><code>abcd efgh ijkl mnop qrst </code></pre> <p>I want to delete the first 2 character of each even numbered line.</p> <pre><code>abcd gh ijkl op qrst </code></pre>
[ { "answer_id": 17313, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 4, "selected": true, "text": "<p>You can use <code>sed</code> to do this:</p>\n\n<pre><code>sed 'n;s/..//' file.txt &gt; output.txt\n</code></pre>\n\...
2018/09/06
[ "https://vi.stackexchange.com/questions/17312", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9498/" ]
Suppose, I have ``` abcd efgh ijkl mnop qrst ``` I want to delete the first 2 character of each even numbered line. ``` abcd gh ijkl op qrst ```
You can use `sed` to do this: ``` sed 'n;s/..//' file.txt > output.txt ``` Or inside of Vim via: ``` :%!sed 'n;s/..//' ``` A native solution in Vim can be accomplished with a sub-replace-expression ``` :%s/../\=line('.')%2==0?'':submatch(0)/ ``` This works by replacing the first 2 character each line with eith...
17,329
<p>What is the best way to indent multiple lines in insert mode?</p> <p>Here is what I have currently:</p> <pre><code>vmap &lt;Tab&gt; &gt; vmap &lt;S-Tab&gt; &lt; </code></pre> <p>The problem is that it doesn't properly handle selection area: the selection will shrink on each Tab press (Shift-Tab to unindent doesn'...
[ { "answer_id": 17337, "author": "Tommy A", "author_id": 5229, "author_profile": "https://vi.stackexchange.com/users/5229", "pm_score": 2, "selected": false, "text": "<p>You want to use:</p>\n\n<pre><code>vmap &lt;tab&gt; &gt;gv\n</code></pre>\n\n<p>In this not-quite-Vim mode, a vmap'ed k...
2018/09/10
[ "https://vi.stackexchange.com/questions/17329", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7200/" ]
What is the best way to indent multiple lines in insert mode? Here is what I have currently: ``` vmap <Tab> > vmap <S-Tab> < ``` The problem is that it doesn't properly handle selection area: the selection will shrink on each Tab press (Shift-Tab to unindent doesn't have any problems). Then I tried: ``` vmap <Tab...
Think of it like this. ``` aaaa bbbb cccc ``` If you select these 3 lines, then each line has 4 characters selected. Now, you indent them and use `gv` to reselect the whole thing. Here is the new text: ``` <tab>aaaa <tab>bbbb <tab>cccc ``` Which selection does vim see you used to have? 3 lines, each with 4 charac...
17,330
<p>I am pretty new to vim and hence trying to learn some of its powerful features and ofcourse top of the list is macros.</p> <p>So i am trying to create a pattern like this.</p> <pre><code>&lt;tag&gt;var 1&lt;/tag&gt; &lt;tag&gt;var 2&lt;/tag&gt; &lt;tag&gt;var 3&lt;/tag&gt; &lt;tag&gt;var 4&lt;/tag&gt; &lt;tag&gt;v...
[ { "answer_id": 17333, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 2, "selected": false, "text": "<p>I think your macro is not quite correct. If you look at the output of your recorded output it looks a bit strang...
2018/09/10
[ "https://vi.stackexchange.com/questions/17330", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18373/" ]
I am pretty new to vim and hence trying to learn some of its powerful features and ofcourse top of the list is macros. So i am trying to create a pattern like this. ``` <tag>var 1</tag> <tag>var 2</tag> <tag>var 3</tag> <tag>var 4</tag> <tag>var 5</tag> <tag>var 6</tag> <tag>var 7</tag> <tag>var 8</tag> <tag>var 9</t...
[Christian's answer](https://vi.stackexchange.com/a/17333/343) is of course correct, but I can also explain why your macro won't work without actually looking at the register contents. In step 5, you move down. If there is no blank line at the end of the file, you cannot move the cursor down, so the macro will fail at...
17,349
<p>I'm editing pandoc markdown text with inline math. Since that uses underscores, vim will helpfully highlight everything after the first underscore, but there will be no matching one. <a href="https://i.stack.imgur.com/HPHlC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HPHlC.png" alt="enter ima...
[ { "answer_id": 17350, "author": "oarfish", "author_id": 1066, "author_profile": "https://vi.stackexchange.com/users/1066", "pm_score": 1, "selected": true, "text": "<p>It seems that the <code>markdownItalic</code> syntax element is a link to <code>htmlItalic</code> (could someone elabora...
2018/09/11
[ "https://vi.stackexchange.com/questions/17349", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1066/" ]
I'm editing pandoc markdown text with inline math. Since that uses underscores, vim will helpfully highlight everything after the first underscore, but there will be no matching one. [![enter image description here](https://i.stack.imgur.com/HPHlC.png)](https://i.stack.imgur.com/HPHlC.png) How can I turn off highligh...
It seems that the `markdownItalic` syntax element is a link to `htmlItalic` (could someone elaborate what that means?), so setting `hi clear htmlItalic` does the trick for me. The downside is that this breaks all other sort of highlighting within the region vim thinks is italic text.
17,365
<p>Is there a setting I could add to my vimrc file that would hide the last entered colon-command that stays visible on the bottom of the screen after I hit enter?</p> <p>For example, if I type ":3" to go to line 3 of the current file, then the ":3" stays visible on the bottom of the screen even after I hit enter. I a...
[ { "answer_id": 17366, "author": "Martin Tournoij", "author_id": 51, "author_profile": "https://vi.stackexchange.com/users/51", "pm_score": 4, "selected": true, "text": "<p>You can press <code>&lt;C-l&gt;</code> to force a redraw, which will clear this line, among some other things.</p>\n...
2018/09/12
[ "https://vi.stackexchange.com/questions/17365", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18935/" ]
Is there a setting I could add to my vimrc file that would hide the last entered colon-command that stays visible on the bottom of the screen after I hit enter? For example, if I type ":3" to go to line 3 of the current file, then the ":3" stays visible on the bottom of the screen even after I hit enter. I already hav...
You can press `<C-l>` to force a redraw, which will clear this line, among some other things. If you want, you can use the [`CmdlineLeave`](http://vimhelp.appspot.com/autocmd.txt.html#CmdlineLeave) autocommand to echo an empty string upon leaving the commandline: ``` augroup cmdline autocmd! autocmd CmdlineLe...
17,369
<p>I like to use the vim embedded terminal, but I do not know how I could adjust its height. Sometimes, I need it to be lower so that I could concentrate on my editor how could I adjust it ?</p>
[ { "answer_id": 17373, "author": "TamaMcGlinn", "author_id": 18875, "author_profile": "https://vi.stackexchange.com/users/18875", "pm_score": 2, "selected": false, "text": "<p>There are several options:</p>\n\n<p>(1) The simple way is to drag the bar separating the two split windows using...
2018/09/13
[ "https://vi.stackexchange.com/questions/17369", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18259/" ]
I like to use the vim embedded terminal, but I do not know how I could adjust its height. Sometimes, I need it to be lower so that I could concentrate on my editor how could I adjust it ?
``` :h termwinsize ``` You need to set `termwinsize` option. It's argument like {row}x{columns}. So if you want your terminal appear 30 row and 200 column, you should use: ``` :set termwinsize=30x200 ```
17,374
<p>I saw an <a href="https://medium.com/@jovica/the-power-of-recursive-macros-in-vim-1ecfa35c1183" rel="nofollow noreferrer">example</a> of a recursive vim macro, and it stops, but I don't quite understand why. My guess is that it stops because it can't find any more <code>:</code>, but I'm unsure if I am correct; doe...
[ { "answer_id": 17385, "author": "JigglyNaga", "author_id": 7600, "author_profile": "https://vi.stackexchange.com/users/7600", "pm_score": 3, "selected": true, "text": "<p>From <a href=\"http://vimhelp.appspot.com/repeat.txt.html#%40\" rel=\"nofollow noreferrer\">repeat.txt</a>:</p>\n\n<b...
2018/09/13
[ "https://vi.stackexchange.com/questions/17374", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1065/" ]
I saw an [example](https://medium.com/@jovica/the-power-of-recursive-macros-in-vim-1ecfa35c1183) of a recursive vim macro, and it stops, but I don't quite understand why. My guess is that it stops because it can't find any more `:`, but I'm unsure if I am correct; does anyone know why it stops? Macro contents: ``` i<...
From [repeat.txt](http://vimhelp.appspot.com/repeat.txt.html#%40): > > The register is executed like a mapping > > > and [map.txt](http://vimhelp.appspot.com/map.txt.html#map-error): > > Note that when an error is encountered (that causes an error message or beep) > the rest of the mapping is not executed. > ...
17,390
<p>When I :q vim on my debian root account (not even writing), it always displays an error message:</p> <blockquote> <p>E138: Can't write viminfo file $HOME/.viminfo!</p> </blockquote> <p><code>.viminfo</code> didn't exist, so I created it and checked the permissions of <code>/root</code> and the file, but they wer...
[ { "answer_id": 17413, "author": "user5977070", "author_id": 19008, "author_profile": "https://vi.stackexchange.com/users/19008", "pm_score": 1, "selected": true, "text": "<p>I guess this is some kind of weird bug in the vim stable release, since I installed vim from testing and it just w...
2018/09/16
[ "https://vi.stackexchange.com/questions/17390", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19008/" ]
When I :q vim on my debian root account (not even writing), it always displays an error message: > > E138: Can't write viminfo file $HOME/.viminfo! > > > `.viminfo` didn't exist, so I created it and checked the permissions of `/root` and the file, but they were fine: ``` drwx------ 3 root root 4.0K Sep 16 11:13...
I guess this is some kind of weird bug in the vim stable release, since I installed vim from testing and it just works without further ado.
17,393
<p>I'm using basic version vimrc from <a href="https://github.com/amix/vimrc" rel="nofollow noreferrer">https://github.com/amix/vimrc</a>. No problem if I put my vimrc at <code>/home/{user}/.vimrc</code>, but if I put it in <code>/etc/vimrc</code> (arch) or <code>/etc/vim/vimrc</code> (debian), it becomes a problem.</p...
[ { "answer_id": 17397, "author": "tonny", "author_id": 19014, "author_profile": "https://vi.stackexchange.com/users/19014", "pm_score": 0, "selected": false, "text": "<p>I'll list my alternative ideas that doesn't solve the actual problem:</p>\n\n<ol>\n<li>put the vimrc file elsewhere (pr...
2018/09/16
[ "https://vi.stackexchange.com/questions/17393", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19014/" ]
I'm using basic version vimrc from <https://github.com/amix/vimrc>. No problem if I put my vimrc at `/home/{user}/.vimrc`, but if I put it in `/etc/vimrc` (arch) or `/etc/vim/vimrc` (debian), it becomes a problem. The problem is: I cannot use: ``` let mapleader = "," ``` And then make a mapping that uses `<leader>`...
One thing I've just seen is that if `cpo` contains `<`, then special characters like `<leader>` won't be handled right: ``` *cpo-<* < Disable the recognition of special key codes in |<>| form in mappings, abbreviations, and the "to" part of menu command...
17,403
<p>In my code, something like</p> <pre><code>#include &lt;whatever&gt; </code></pre> <p>is highlighted: <code>#include</code> (which belongs to the group 'cInclude') in pink; and <code>&lt;whatever&gt;</code> (belonging to the group 'cIncluded') in red. (<strong>Edit</strong>: <code>whatever</code> is any word.)</p> ...
[ { "answer_id": 17408, "author": "JigglyNaga", "author_id": 7600, "author_profile": "https://vi.stackexchange.com/users/7600", "pm_score": 3, "selected": true, "text": "<p>From <a href=\"http://vimdoc.sourceforge.net/htmldoc/eval.html#matchadd()\" rel=\"nofollow noreferrer\"><code>help ma...
2018/09/18
[ "https://vi.stackexchange.com/questions/17403", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6023/" ]
In my code, something like ``` #include <whatever> ``` is highlighted: `#include` (which belongs to the group 'cInclude') in pink; and `<whatever>` (belonging to the group 'cIncluded') in red. (**Edit**: `whatever` is any word.) Also, to highlight the word `vector` according to the 'Type' style (in green) I do the ...
From [`help matchadd`](http://vimdoc.sourceforge.net/htmldoc/eval.html#matchadd()): > > Syntax highlighting (see 'syntax') is a separate > mechanism, and regardless of the chosen priority a match will > always overrule syntax highlighting. > > > To match everywhere except certain contexts, you can use [zero-wid...
17,416
<p>I am new to vim and I want to code in vim. I have installed the necessary plugins for syntax highlighting JSX in TypeScript and everything works fine for GUI version of Vim but not for terminal-based Vim. Please help me figure out the issue. Below are the plugins that I am using for syntax highlighting:</p> <ol> <li...
[ { "answer_id": 17417, "author": "tivn", "author_id": 1782, "author_profile": "https://vi.stackexchange.com/users/1782", "pm_score": 3, "selected": true, "text": "<p><code>guifg</code> or <code>guibg</code> only works for GUI vim. For terminal version you will need to add other attributes...
2018/09/19
[ "https://vi.stackexchange.com/questions/17416", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19047/" ]
I am new to vim and I want to code in vim. I have installed the necessary plugins for syntax highlighting JSX in TypeScript and everything works fine for GUI version of Vim but not for terminal-based Vim. Please help me figure out the issue. Below are the plugins that I am using for syntax highlighting: 1. For TypeScr...
`guifg` or `guibg` only works for GUI vim. For terminal version you will need to add other attributes: `ctermfg`, `ctermbg`. Type `:highlight` without any attributes in your vim to show currenly set color settings.
17,418
<p>I have line to split window at start:</p> <pre><code>au VimEnter * vsplit </code></pre> <p>But sometimes it's annoying because I'm opening vim in small terminal, in this case I'd like to not split my window. I've tried this construction but it's not executing at start</p> <pre><code>if winwidth('%') &gt;= 100 a...
[ { "answer_id": 17417, "author": "tivn", "author_id": 1782, "author_profile": "https://vi.stackexchange.com/users/1782", "pm_score": 3, "selected": true, "text": "<p><code>guifg</code> or <code>guibg</code> only works for GUI vim. For terminal version you will need to add other attributes...
2018/09/19
[ "https://vi.stackexchange.com/questions/17418", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8709/" ]
I have line to split window at start: ``` au VimEnter * vsplit ``` But sometimes it's annoying because I'm opening vim in small terminal, in this case I'd like to not split my window. I've tried this construction but it's not executing at start ``` if winwidth('%') >= 100 au VimEnter * vsplit endif ``` Is there...
`guifg` or `guibg` only works for GUI vim. For terminal version you will need to add other attributes: `ctermfg`, `ctermbg`. Type `:highlight` without any attributes in your vim to show currenly set color settings.
17,430
<p>In Ex mode, <code>##</code> can be expanded to the files in the <code>args</code> list when files are <strong>expected</strong>, see <a href="http://vimhelp.appspot.com/cmdline.txt.html#cmdline-special" rel="nofollow noreferrer"><code>:h cmdline-special</code></a></p> <blockquote> <p>In Ex commands, at places whe...
[ { "answer_id": 17431, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>You could use <a href=\"http://vimhelp.appspot.com/eval.txt.html#expand%28%29\" rel=\"noreferrer\"><code>:h expand()</co...
2018/09/20
[ "https://vi.stackexchange.com/questions/17430", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13302/" ]
In Ex mode, `##` can be expanded to the files in the `args` list when files are **expected**, see [`:h cmdline-special`](http://vimhelp.appspot.com/cmdline.txt.html#cmdline-special) > > In Ex commands, at places where a file name can be **used**, the following characters have a special meaning. These can also be used...
I ended in using `cabbr`. This is one way. ``` cnoreabbrev <expr> ##; getcmdtype()==':'?expand('##'):'##;' cnoreabbrev <expr> #; getcmdtype()==':'?expand('#'):'#;' cnoreabbrev <expr> %; getcmdtype()==':'?expand('%'):'%;' ``` Another way is to use `cnoremap <expr>` ``` function! s:expand() let line = getcmdline() ...
17,439
<p>Recently I found myself in a situation that need to type in quite a number of matrices to LaTeX by hand, so I was wondering if there are some tools that can help me to save some keystrokes.</p> <p>The desired tool would work as follows. Whenever I need to insert a matrix, I trigger the plugin, then it prompts to as...
[ { "answer_id": 17443, "author": "ZeroKnight", "author_id": 1452, "author_profile": "https://vi.stackexchange.com/users/1452", "pm_score": 4, "selected": true, "text": "<p>You could probably implement this as a snippet by leveraging <a href=\"https://github.com/SirVer/ultisnips\" rel=\"no...
2018/09/20
[ "https://vi.stackexchange.com/questions/17439", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16146/" ]
Recently I found myself in a situation that need to type in quite a number of matrices to LaTeX by hand, so I was wondering if there are some tools that can help me to save some keystrokes. The desired tool would work as follows. Whenever I need to insert a matrix, I trigger the plugin, then it prompts to ask me about...
You could probably implement this as a snippet by leveraging [Ultisnips'](https://github.com/SirVer/ultisnips) [Interpolation](https://github.com/SirVer/ultisnips/blob/aec91caefec10741722927cf073703a528fe7a8f/doc/UltiSnips.txt#L820) feature ([VimCasts demo](http://vimcasts.org/episodes/ultisnips-python-interpolation/))...
17,446
<p>OK so I would like to change the way that my yaml gets indented.</p> <p>Right now my vim indents a yaml list like this:</p> <pre><code>list: - this - is - a list dict: this: is a dict </code></pre> <p>I would like it to indent like this:</p> <pre><code>test: - this - is - a list dict: this: is a dict <...
[ { "answer_id": 17476, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 1, "selected": false, "text": "<h2>Python module <a href=\"https://pypi.org/project/ruamel.yaml/\" rel=\"nofollow noreferrer\"><code>ruamel.yaml</code><...
2018/09/21
[ "https://vi.stackexchange.com/questions/17446", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13876/" ]
OK so I would like to change the way that my yaml gets indented. Right now my vim indents a yaml list like this: ``` list: - this - is - a list dict: this: is a dict ``` I would like it to indent like this: ``` test: - this - is - a list dict: this: is a dict ```
A solution that's more internal to vim, is to override `indentexpr` with a custom indent expression (most likely just overriding the builtin `indentexpr` for your specific instance). The steps: * define a filetype override, either in an `autocmd` (group) or in a `ftplugin` override (preferred). * define a new (global...
17,450
<p>I often find the need to start a new file by making a copy of another similar file within the same directory. <code>netrw</code> has several commands for copying files from one directory to another (ie: <a href="http://vimdoc.sourceforge.net/htmldoc/pi_netrw.html#netrw-mc" rel="noreferrer">:h netrw-mc:</a>), but th...
[ { "answer_id": 17460, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 3, "selected": false, "text": "<p>According to following thread on the mailing list <em>vim_use</em> from 03.10.15\n(<a href=\"https://groups.google.co...
2018/09/21
[ "https://vi.stackexchange.com/questions/17450", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19082/" ]
I often find the need to start a new file by making a copy of another similar file within the same directory. `netrw` has several commands for copying files from one directory to another (ie: [:h netrw-mc:](http://vimdoc.sourceforge.net/htmldoc/pi_netrw.html#netrw-mc)), but there appears to no means to copy a file to a...
First, I want to thank Hotcshke for sharing his link to DrChip. If I could up-vote home more, I would. Using the very latest version of netrw and following DrChip's guidance we still experienced the same issues described by the OP in <https://groups.google.com/forum/#!topic/vim_use/6yqU3RX2CWA>. BUT, DrChip provided a...
17,465
<p>Does vim allow for searching raw strings?</p> <p>If what I want to search is in the variable <code>string</code>, does the following code work? </p> <pre><code>call search('\V' . escape(string, '\')) </code></pre> <p>Or are there other more direct ways?</p>
[ { "answer_id": 17474, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 4, "selected": true, "text": "<p>Vim does not have an (easy) native way to search for text literally. However, I find that the default of using re...
2018/09/24
[ "https://vi.stackexchange.com/questions/17465", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13302/" ]
Does vim allow for searching raw strings? If what I want to search is in the variable `string`, does the following code work? ``` call search('\V' . escape(string, '\')) ``` Or are there other more direct ways?
Vim does not have an (easy) native way to search for text literally. However, I find that the default of using regular expressions makes the search quite a bit more powerful, if you have grokked at least the basics. For the few times I have needed to search for text literally, I use basically what you have shown here:...
17,489
<p>Assuming I have the following:</p> <pre><code>My::Cool::Klass.call(args) Cool::Klass.call(args) </code></pre> <p>Is there anyway I can visually select either the <code>My::Cool::Klass</code> or the <code>Cool::Klass</code> with a quick command?</p> <p>Note: These are examples, so the strings could be different wi...
[ { "answer_id": 17518, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 0, "selected": false, "text": "<p>I don't know ruby very well so I'm not sure what you are exactly trying to do, but if you want to search for strings whi...
2018/09/26
[ "https://vi.stackexchange.com/questions/17489", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19130/" ]
Assuming I have the following: ``` My::Cool::Klass.call(args) Cool::Klass.call(args) ``` Is there anyway I can visually select either the `My::Cool::Klass` or the `Cool::Klass` with a quick command? Note: These are examples, so the strings could be different with two or more nodes (i.e. constants surrounding the `:...
If your cursor is at the start of the class, then `vt.` should work. If it’s anywhere else in the example text then just jump to the start first: `Bvt.`.
17,493
<p>I am searching some pattern, navigate between search results, and at the same time I want some other pattern to be highlighted. For example, I jump between invocations of some function in my project, usually there is a variable named "session" around and I want this word to be highlighted.</p> <p>What I do is:</p> ...
[ { "answer_id": 17494, "author": "grodzik", "author_id": 5395, "author_profile": "https://vi.stackexchange.com/users/5395", "pm_score": 3, "selected": false, "text": "<p>I use a plugin for that: <a href=\"https://github.com/lfv89/vim-interestingwords\" rel=\"noreferrer\">interesting words...
2018/09/26
[ "https://vi.stackexchange.com/questions/17493", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6194/" ]
I am searching some pattern, navigate between search results, and at the same time I want some other pattern to be highlighted. For example, I jump between invocations of some function in my project, usually there is a variable named "session" around and I want this word to be highlighted. What I do is: ``` :match St...
For a quick solution, try this: ``` :nnoremap <F5> :match StatusLineTerm /<C-R><C-W>/<CR> ``` This uses `Ctrl-R``Ctrl-W` to insert the word under the cursor into the command line. See `:help c_CTRL-R_CTRL-W`.
17,506
<p>I have a file</p> <pre><code>0,3, 7,2,0, 1,2,3, 1,2, </code></pre> <p>which should be </p> <pre><code>0,3,0, 7,2,0, 1,2,3, 1,2,0, </code></pre> <p>So how can I append each line with two commas with <code>0,</code>? I am interested in the most elegant solution and particularly interested if some script exists to ...
[ { "answer_id": 17507, "author": "hhh", "author_id": 10986, "author_profile": "https://vi.stackexchange.com/users/10986", "pm_score": 0, "selected": false, "text": "<p><em>A solution</em></p>\n\n<pre><code>:g!/[0-9],[0-9],[0-9],/ s/$/0,/\n</code></pre>\n\n<p>where it matches all lines wit...
2018/09/26
[ "https://vi.stackexchange.com/questions/17506", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10986/" ]
I have a file ``` 0,3, 7,2,0, 1,2,3, 1,2, ``` which should be ``` 0,3,0, 7,2,0, 1,2,3, 1,2,0, ``` So how can I append each line with two commas with `0,`? I am interested in the most elegant solution and particularly interested if some script exists to help with such tasks, often required in manipulating CSV fil...
The most elegant way I could think of would be with a substitute command. Either of these would do the trick: ``` :%s/\v^(\d,){2}$/\00, :%s/^\d,\d,$/\00, ``` This will replace any line containing two digits and commas with that whole line followed by "0,". If you would like to modify it to work with numbers more th...
17,509
<p>I'd like to disable the popup menu scroll mappings <code>&lt;C-n&gt;</code> and <code>&lt;C-p&gt;</code>, so that I can use <code>&lt;C-j&gt;</code> and <code>&lt;C-k&gt;</code> instead. However, when I enter</p> <pre><code>imap &lt;C-p&gt; &lt;Nop&gt; imap &lt;C-n&gt; &lt;Nop&gt; </code></pre> <p>the mappings are...
[ { "answer_id": 17507, "author": "hhh", "author_id": 10986, "author_profile": "https://vi.stackexchange.com/users/10986", "pm_score": 0, "selected": false, "text": "<p><em>A solution</em></p>\n\n<pre><code>:g!/[0-9],[0-9],[0-9],/ s/$/0,/\n</code></pre>\n\n<p>where it matches all lines wit...
2018/09/26
[ "https://vi.stackexchange.com/questions/17509", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8084/" ]
I'd like to disable the popup menu scroll mappings `<C-n>` and `<C-p>`, so that I can use `<C-j>` and `<C-k>` instead. However, when I enter ``` imap <C-p> <Nop> imap <C-n> <Nop> ``` the mappings are still active! How do I disable or override them permanently? Is it not possible? To be clear, when I call `:verb ima...
The most elegant way I could think of would be with a substitute command. Either of these would do the trick: ``` :%s/\v^(\d,){2}$/\00, :%s/^\d,\d,$/\00, ``` This will replace any line containing two digits and commas with that whole line followed by "0,". If you would like to modify it to work with numbers more th...
17,523
<p>I want to format a multiline string according to a textwidth of 32.</p> <pre><code>group: - normal: scalar - multiline: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua." - normal: "text" </code></pre> ...
[ { "answer_id": 17560, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 0, "selected": false, "text": "<h3>Via External Tool <a href=\"https://pypi.org/project/pyaml/\" rel=\"nofollow noreferrer\">Pretty-Yaml (pyaml)</a></h3...
2018/09/28
[ "https://vi.stackexchange.com/questions/17523", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8162/" ]
I want to format a multiline string according to a textwidth of 32. ``` group: - normal: scalar - multiline: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua." - normal: "text" ``` to this: ``` group: ...
Not sure if this what you want, but try reading: <https://vimways.org/2018/formatting-lists-with-vim/> What I have in my settings regarding list formatting: ``` setlocal formatoptions=tcqln setlocal formatlistpat=^\\s* setlocal formatlistpat+=[ setlocal formatlistpat+=\\[({]\\? setlocal formatlistpat+=\\( setlocal fo...
17,532
<p>I come about this regularly and still do it manually. Consider this example - say it's inside a text.</p> <pre><code> first 3,2,17,198,232,1,999 and some other text second 1,2,3,71,98,4,5 and some more text </code></pre> <p>I need these values sorted (usually for easier read, or to find duplicates).</p> <p>e.g....
[ { "answer_id": 17537, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 2, "selected": false, "text": "<h2>Plugin <a href=\"https://github.com/christoomey/vim-sort-motion\" rel=\"nofollow noreferrer\">sort-motion.vim</a></h2...
2018/09/29
[ "https://vi.stackexchange.com/questions/17532", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1120/" ]
I come about this regularly and still do it manually. Consider this example - say it's inside a text. ``` first 3,2,17,198,232,1,999 and some other text second 1,2,3,71,98,4,5 and some more text ``` I need these values sorted (usually for easier read, or to find duplicates). e.g. ``` first 1,2,3,17,198,232,999 ...
Vanilla Vim: Via Expression Register ------------------------------------ And now a solution for vanilla vim: 1. Position cursor on list 2. `ciW` (removes unsorted list and puts it into register `"`) 3. `<C-r>=join(sort([<C-r>"]), ',')<CR>` Done. I think it is actually not that bad. An even more useful variant would...
17,533
<p>I want to find the most elegant way to replace every second space on each line with Vim. Most elegant solution accepted.</p> <p><strong>Example input</strong></p> <pre><code>123 1234 1345 123456 12344567 12345678 123 1234 1345 123456 12344567 12345678 123 1234 1345 123456 12344567 12345678 </code></pre> <p><stron...
[ { "answer_id": 17534, "author": "hhh", "author_id": 10986, "author_profile": "https://vi.stackexchange.com/users/10986", "pm_score": 1, "selected": false, "text": "<p>A solution candidate with a regular expression and with the magic directive is</p>\n\n<pre><code>:.s@\\v(\\d+) (\\d+)@\\1...
2018/09/29
[ "https://vi.stackexchange.com/questions/17533", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10986/" ]
I want to find the most elegant way to replace every second space on each line with Vim. Most elegant solution accepted. **Example input** ``` 123 1234 1345 123456 12344567 12345678 123 1234 1345 123456 12344567 12345678 123 1234 1345 123456 12344567 12345678 ``` **Intended output** ``` 1231234 1345123456 12344567...
Assuming you want to remove all the odd-numbered spaces: ``` :s/\v (\S*( |$))/\1/g ``` * with magic (`\v`) to reduce the escaping needed * matches space followed by (non-whitespace (`\S*`) followed by (another space or end-of-line)) * and replaces it with the matched part after the leading space For each space matc...
17,544
<p>When I use the colorscheme <a href="https://github.com/morhetz/gruvbox" rel="nofollow noreferrer">gruvbox</a> (installed with <a href="https://github.com/junegunn/vim-plug" rel="nofollow noreferrer">vim-plug</a>), it overrides my configuration of the Cursorline highlight, eg</p> <pre><code>set cursorline hi CursorL...
[ { "answer_id": 17546, "author": "stimulate", "author_id": 17840, "author_profile": "https://vi.stackexchange.com/users/17840", "pm_score": 2, "selected": true, "text": "<p>Appearently this line </p>\n\n<pre><code>set termguicolors\n</code></pre>\n\n<p>overrides the highlight color. \n...
2018/10/01
[ "https://vi.stackexchange.com/questions/17544", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17840/" ]
When I use the colorscheme [gruvbox](https://github.com/morhetz/gruvbox) (installed with [vim-plug](https://github.com/junegunn/vim-plug)), it overrides my configuration of the Cursorline highlight, eg ``` set cursorline hi CursorLine cterm=NONE ctermbg=black ``` with the same color as the statusbar, which makes it ...
Appearently this line ``` set termguicolors ``` overrides the highlight color. removing it let me configure the CursorLine highlight color again.
17,571
<p>Is there a way to make vim not close the current fold I'm in when I close a file? For example: I am typing inside a fold, I save and close the file (without presing zc to close the fold), and then when I reopen the file the fold I was in is now closed and I have to open it again and scroll to where I was. Is there a...
[ { "answer_id": 17575, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 1, "selected": false, "text": "<p>Since your cursor should be where you left it last, you could try <code>zv</code> to open enough folds to see y...
2018/10/05
[ "https://vi.stackexchange.com/questions/17571", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19251/" ]
Is there a way to make vim not close the current fold I'm in when I close a file? For example: I am typing inside a fold, I save and close the file (without presing zc to close the fold), and then when I reopen the file the fold I was in is now closed and I have to open it again and scroll to where I was. Is there any ...
Since your cursor should be where you left it last, you could try `zv` to open enough folds to see your cursor (bonus: it doesn’t move the cursor).
17,584
<p>For example, I wish to change </p> <pre><code>1 1 2 3 5 8 13 </code></pre> <p>to </p> <pre><code> 1 1 2 3 5 8 13 </code></pre> <p>Where this is not necessarily at the start of the line. How can I do this?</p>
[ { "answer_id": 17585, "author": "garyjohn", "author_id": 2055, "author_profile": "https://vi.stackexchange.com/users/2055", "pm_score": 2, "selected": false, "text": "<p>Move your cursor to the first single-digit number, the first <code>1</code> in this case. Type <code>Ctrl-v</code>. Th...
2018/10/07
[ "https://vi.stackexchange.com/questions/17584", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18355/" ]
For example, I wish to change ``` 1 1 2 3 5 8 13 ``` to ``` 1 1 2 3 5 8 13 ``` Where this is not necessarily at the start of the line. How can I do this?
Move your cursor to the first single-digit number, the first `1` in this case. Type `Ctrl-v`. Then move your cursor to the last single-digit number, the `8` in this case. There are several ways to move the cursor. `5j` will work. Then type ``` I <Esc> ``` where `<Esc>` is the `Esc` key and there is a single space be...
17,593
<p>Let's say I have </p> <pre><code>Foo BAR Baz Quxxx Foo Baar Asd Duxxxxx Bar Foo Baazzz Kuxx Baz </code></pre> <p>I would ideally like to be to highlight the first, second, or third column. Then I would like to able to quote them such that they're like this,</p> <pre><code>'Foo BAR Baz' ...
[ { "answer_id": 17594, "author": "garyjohn", "author_id": 2055, "author_profile": "https://vi.stackexchange.com/users/2055", "pm_score": 2, "selected": false, "text": "<p>This answer is based on the <a href=\"https://github.com/vim-scripts/vis\" rel=\"nofollow noreferrer\">vis</a> plugin....
2018/10/08
[ "https://vi.stackexchange.com/questions/17593", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5078/" ]
Let's say I have ``` Foo BAR Baz Quxxx Foo Baar Asd Duxxxxx Bar Foo Baazzz Kuxx Baz ``` I would ideally like to be to highlight the first, second, or third column. Then I would like to able to quote them such that they're like this, ``` 'Foo BAR Baz' 'Quxxx' 'Foo' 'Baar Asd' 'Du...
This answer is based on the [vis](https://github.com/vim-scripts/vis) plugin. That plugin provides the ability to run ex commands on just the visually-selected text. In this case, it can be used to execute a substitute command on just the selected column of text. First visually select the column to be quoted. That is,...
17,641
<p>I'm using Vim to develop C on Linux. When I press <kbd>K</kbd> in order to open man page for the underlying word, I don't have control on which man section is opened. Is there a way to specify that somewhere ?</p>
[ { "answer_id": 17642, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 5, "selected": true, "text": "<p>Quoting from the <a href=\"http://vimhelp.appspot.com/various.txt.html#K\" rel=\"noreferrer\">documentation</a></...
2018/10/16
[ "https://vi.stackexchange.com/questions/17641", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/496/" ]
I'm using Vim to develop C on Linux. When I press `K` in order to open man page for the underlying word, I don't have control on which man section is opened. Is there a way to specify that somewhere ?
Quoting from the [documentation](http://vimhelp.appspot.com/various.txt.html#K) ``` When 'keywordprg' is equal to "man -s", a count before "K" is inserted after the "-s". If there is no count, the "-s" is removed. ``` `man -s` seems to be the default for the `'keywordprg'` setting, so simplying using a count ...
17,650
<p>I am trying to master VI and found some nice tricks to replace a letter with a single <code>:%s/</code> command and this works. If I'd like to replace for example <code>word</code> with <code>wardos</code> I can use <code>:%s/word/wardos/g</code> and then hit enter.</p> <p>But how do I replace those accented charac...
[ { "answer_id": 17652, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 3, "selected": false, "text": "<p>If you want to match just a single character that has an accent, you can simply include it in a search:</p>\n\n<pre><code>:%...
2018/10/17
[ "https://vi.stackexchange.com/questions/17650", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19417/" ]
I am trying to master VI and found some nice tricks to replace a letter with a single `:%s/` command and this works. If I'd like to replace for example `word` with `wardos` I can use `:%s/word/wardos/g` and then hit enter. But how do I replace those accented characters like `é`, `á`, `Á` etc?
If you want to match just a single character that has an accent, you can simply include it in a search: ``` :%s/café/restaurant/g ``` You can type the accented character either using your operating system's input features, or with Vim's **digraphs** feature (see `:help c_CTRL-k`) If you want to *ignore* the accents...
17,661
<p>I want to create a simple notes file and manager it with vim. The system is really easy (plain text rules):</p> <pre><code>- [ ] new entry - [x] done entry </code></pre> <p>Well, in my <code>.vimrc</code> I only have the keybind for add new entries, always on NORMAL MODE:</p> <pre><code>map tn i- [ ] </code></pre...
[ { "answer_id": 17662, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>I started by suggesting you use the first part of the example command you included since it does what you want but it...
2018/10/18
[ "https://vi.stackexchange.com/questions/17661", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19432/" ]
I want to create a simple notes file and manager it with vim. The system is really easy (plain text rules): ``` - [ ] new entry - [x] done entry ``` Well, in my `.vimrc` I only have the keybind for add new entries, always on NORMAL MODE: ``` map tn i- [ ] ``` Now, I can't create a keybind for to remplace `- []` f...
> > Now, I can't create a keybind for to remplace `- []` for `- [x]` > > > Try the following: ``` nnoremap <leader>x :s/^- \[\]/\- \[x\]/<CR> ``` `<leader>` is by default `\`, so if you didn't make any change to it than put your cursor on the line: ``` - [] hello world ``` and press `\x` to make it: ``` - [...
17,673
<p>I'm trying to setup a simple environment which would allow me to work on a local file and it's remote counterpart.</p> <p>Both files are accessible on my filesystem. So let's say I have :</p> <pre><code>File 1 : /home/john/petshop/categories/animals/fluffy/cats.txt </code></pre> <p>and</p> <pre><code>File 2 : /m...
[ { "answer_id": 17674, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 2, "selected": false, "text": "<p>You can get the full path of the file you're editing with <code>expand('%:p')</code>. Unfortunately, we need to edit...
2018/10/19
[ "https://vi.stackexchange.com/questions/17673", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19461/" ]
I'm trying to setup a simple environment which would allow me to work on a local file and it's remote counterpart. Both files are accessible on my filesystem. So let's say I have : ``` File 1 : /home/john/petshop/categories/animals/fluffy/cats.txt ``` and ``` File 2 : /mnt/sshfs/petshop/categories/animals/fluffy/c...
Some characters are special on Vim's command-line (see `:h cmdline-special`), including `%` which is automatically replaced by the path to the current file relative to the current working directory. Some of them may be followed by filename-modifiers (see `:h filename-modifiers`). Those can be combined, and among them ...
17,675
<p>I have two tabs open, file1.txt and file2.txt, each with different content.</p> <p>How can I copy the whole content of file1.txt and overwrite file2.txt with it, resulting in both files having the same content.</p> <p>This is obviously doable with yanking manually, but I figured there's probably a nice combo that ...
[ { "answer_id": 17676, "author": "Warren Young", "author_id": 6852, "author_profile": "https://vi.stackexchange.com/users/6852", "pm_score": 2, "selected": false, "text": "<p>From the <code>file1.txt</code> buffer, say <code>:w! file2.txt</code>.</p>\n\n<p>Then either:</p>\n\n<ol>\n<li><p...
2018/10/19
[ "https://vi.stackexchange.com/questions/17675", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19461/" ]
I have two tabs open, file1.txt and file2.txt, each with different content. How can I copy the whole content of file1.txt and overwrite file2.txt with it, resulting in both files having the same content. This is obviously doable with yanking manually, but I figured there's probably a nice combo that does it all in on...
Try running this unholy ex command in your first tab: ``` :%y|tabn|%d|pu0|1d ``` It’s certainly a combo that does it all in one go, but is it nice? That’s a rhetorical question: it’s clearly not. Further details --------------- This is a maximally abbreviated version of the following sequence of commands: * `:%y...
17,686
<p>When I add <code>\textbf{}</code> or <code>\textit{}</code> before a word in <code>vimtex</code> the terminal shows the word but strangely hides the commands. I can only see them in the visual mode (see pictures below). Is there a way to force vim to always show <code>\emph{}</code> before the text?</p> <p>I'm usin...
[ { "answer_id": 17688, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 4, "selected": true, "text": "<p>This is not due to <code>vimtex</code> directly, but due to the conceal feature in Vim. <code>vimtex</code> only a...
2018/10/22
[ "https://vi.stackexchange.com/questions/17686", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19102/" ]
When I add `\textbf{}` or `\textit{}` before a word in `vimtex` the terminal shows the word but strangely hides the commands. I can only see them in the visual mode (see pictures below). Is there a way to force vim to always show `\emph{}` before the text? I'm using Vim 8.1 on iTerm2 with the gruvbox theme if that's h...
This is not due to `vimtex` directly, but due to the conceal feature in Vim. `vimtex` only adds to the syntax plugin that ships with Vim/neovim, and it adhers to the relevant option, see `:help g:tex_conceal`. For direct control of the conceal feature itself, see `:help conceallevel`, `:help concealcursor` and `:help ...
17,694
<p>I sometimes type (by accident) shift-space, inserting unbreakable space into code. With c++, I get this:</p> <pre><code>error: stray ‘\302’ in program error: stray ‘\240’ in program </code></pre> <p>while in other formats (like RestructuredText), I am hunting mysterious errors of syntax without any visible cause.<...
[ { "answer_id": 17695, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 2, "selected": false, "text": "<p>I don't think you can use the <code>&lt;S-Space&gt;</code> notation in a mapping* but I think you should be able to map it b...
2018/10/23
[ "https://vi.stackexchange.com/questions/17694", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19495/" ]
I sometimes type (by accident) shift-space, inserting unbreakable space into code. With c++, I get this: ``` error: stray ‘\302’ in program error: stray ‘\240’ in program ``` while in other formats (like RestructuredText), I am hunting mysterious errors of syntax without any visible cause. Is there a way to * alwa...
List & Listchars ================ `'list'` is a boolean option that, when `set`, instructs vim to display whitespace characters. And it is completely customizable using `'listchars'`. For example, to show non-breaking spaces as `!` (you can use whatever character you like, especially with digraphs and unicode support...
17,703
<p>I currently have </p> <pre><code>nnoremap &lt;leader&gt; G </code></pre> <p>in my <code>.vimrc</code> so I can go to line 123 by typing <code>123&lt;leader&gt;</code>. </p> <p>However, since I have other leader combinations, such as <code>&lt;leader&gt;u</code>, the line jump happens only after a second. </p> <p...
[ { "answer_id": 17705, "author": "John Fred Fadrigalan", "author_id": 18514, "author_profile": "https://vi.stackexchange.com/users/18514", "pm_score": 1, "selected": false, "text": "<p>You may do \n<code>nnoremap &lt;leader&gt;&lt;leader&gt; G</code>.</p>\n\n<p>Then just type the linenumb...
2018/10/23
[ "https://vi.stackexchange.com/questions/17703", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18613/" ]
I currently have ``` nnoremap <leader> G ``` in my `.vimrc` so I can go to line 123 by typing `123<leader>`. However, since I have other leader combinations, such as `<leader>u`, the line jump happens only after a second. I know how to reduce this timeout, but I don't really want to do that since it would make ...
You may do `nnoremap <leader><leader> G`. Then just type the linenumber and double click the leaderkey.
17,704
<p>When I call this function inside vim statusline it returns this <code>nvim^@</code>.weird character, What is the meaning of <code>^@</code> in returned value and how to get rid of it?</p> <pre><code>function! GetEditor() let s:name = system("echo $EDITOR") return s:name endfunction set statusline+=%0*\ %{GetEd...
[ { "answer_id": 17707, "author": "garyjohn", "author_id": 2055, "author_profile": "https://vi.stackexchange.com/users/2055", "pm_score": 4, "selected": true, "text": "<p>The <code>^@</code> is a NUL character, 0x00, which Vim uses in certain cases to store a newline, 0x0a.</p>\n\n<p>Unix ...
2018/10/23
[ "https://vi.stackexchange.com/questions/17704", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18514/" ]
When I call this function inside vim statusline it returns this `nvim^@`.weird character, What is the meaning of `^@` in returned value and how to get rid of it? ``` function! GetEditor() let s:name = system("echo $EDITOR") return s:name endfunction set statusline+=%0*\ %{GetEditor()}\ ```
The `^@` is a NUL character, 0x00, which Vim uses in certain cases to store a newline, 0x0a. Unix commands usually terminate their output with a newline, and the system() function captures that newline in the output of your echo command. To get rid of that terminating newline, use substitute(): ``` let s:name = subs...
17,711
<p>I have two files open, each one is in a split.</p> <p>From file one, how can I get the filename of the file in split two ?</p> <p>In command mode, I can get the reference of the filename I'm currently editing by using <code>%f</code>, is there something similar that would return the filename of the file opened in ...
[ { "answer_id": 17715, "author": "John Fred Fadrigalan", "author_id": 18514, "author_profile": "https://vi.stackexchange.com/users/18514", "pm_score": 0, "selected": false, "text": "<p>focus the split <code>&lt;C-w&gt;h/j/k/l</code> then hit <code>&lt;C-g&gt;</code>.</p>\n" }, { "...
2018/10/23
[ "https://vi.stackexchange.com/questions/17711", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19461/" ]
I have two files open, each one is in a split. From file one, how can I get the filename of the file in split two ? In command mode, I can get the reference of the filename I'm currently editing by using `%f`, is there something similar that would return the filename of the file opened in my second split? **Update**...
To get the buffer name in a different window, you will have to use a Vimscript solution. You can refer to different splits using the window number or the winid. The window number is not stable and will change, if you modify the window layout, therefore the winid exists, which will never change (but was not available i...
17,719
<p>The following search command will make a range and search/replace within it. Specifically, it looks for 'first' in the text, then stops when it finds 'second' across multiple lines. Then, within that range of selected things, it will replace foo with bar. What I'm not sure how to do is to replace <em>all</em> occu...
[ { "answer_id": 17721, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 2, "selected": false, "text": "<h2>UPDATE</h2>\n\n<p>So I have found simpler solution:</p>\n\n<pre><code>:/first/,/second/g/bar/s/foo/bar/g\n</code></p...
2018/10/24
[ "https://vi.stackexchange.com/questions/17719", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19513/" ]
The following search command will make a range and search/replace within it. Specifically, it looks for 'first' in the text, then stops when it finds 'second' across multiple lines. Then, within that range of selected things, it will replace foo with bar. What I'm not sure how to do is to replace *all* occurrences of f...
UPDATE ------ So I have found simpler solution: ``` :/first/,/second/g/bar/s/foo/bar/g ``` 1. `/first/,/second/` take a range between `first` and `second` 2. `g/bar/` filter out lines that do not have `bar` (keep lines that has `bar`s) 3. `s/foo/bar/g` substitute all `foo`s with `bar`s within filtered lines. Old s...
17,743
<p>I'm using this setting:</p> <pre><code>noremap &lt;F2&gt; :tabnext&lt;CR&gt; inoremap &lt;F2&gt; :tabnext&lt;CR&gt; </code></pre> <p>But it just moves cursor down one line like <code>&lt;C-j&gt;</code> does...</p> <p>How can I map F2 to moving to next tab?</p> <p>Environment: Debian 9.5 amd64, KDE</p>
[ { "answer_id": 17745, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 2, "selected": false, "text": "<pre><code>noremap &lt;F2&gt; :tabnext&lt;CR&gt;\n</code></pre>\n\n<p>Should work from within normal mode. And it works ...
2018/10/26
[ "https://vi.stackexchange.com/questions/17743", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19525/" ]
I'm using this setting: ``` noremap <F2> :tabnext<CR> inoremap <F2> :tabnext<CR> ``` But it just moves cursor down one line like `<C-j>` does... How can I map F2 to moving to next tab? Environment: Debian 9.5 amd64, KDE
I found the culprit - it was KDE + Gnome Terminator's fault (<https://gnometerminator.blogspot.com/p/introduction.html>).
17,760
<p>I have the following configuration for OCaml development which works fine:</p> <pre><code>" --------------- OCaml ----------------------------- " Merlin let g:opamshare = substitute(system('opam config var share'),'\n$','','''') execute 'set rtp+=' . g:opamshare . '/merlin/vim' " ocp-indent execute 'set rtp^=' . g:...
[ { "answer_id": 17811, "author": "Ingo Karkat", "author_id": 970, "author_profile": "https://vi.stackexchange.com/users/970", "pm_score": 2, "selected": false, "text": "<p>Have a look at <a href=\"https://vimhelp.appspot.com/starting.txt.html#startup\" rel=\"nofollow noreferrer\"><code>:h...
2018/10/28
[ "https://vi.stackexchange.com/questions/17760", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8475/" ]
I have the following configuration for OCaml development which works fine: ``` " --------------- OCaml ----------------------------- " Merlin let g:opamshare = substitute(system('opam config var share'),'\n$','','''') execute 'set rtp+=' . g:opamshare . '/merlin/vim' " ocp-indent execute 'set rtp^=' . g:opamshare . '/...
Have a look at [`:help startup`](https://vimhelp.appspot.com/starting.txt.html#startup). If you set up `'runtimepath'` in your `~/.vimrc`, Vim will later load the plugins found there ([`:help load-plugins`](https://vimhelp.appspot.com/starting.txt.html#load-plugins)). Now if you do the `'runtimepath'` setup later, Vim...
17,767
<p>I want to map <code>:e file.txt</code> to <code>:tabnew file.txt</code>, or the equivalent setting for editing file in a new tab. What do I need to put into my vimrc?</p>
[ { "answer_id": 17768, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": true, "text": "<p>You probably want to read <a href=\"http://vimhelp.appspot.com/map.txt.html#user-commands\" rel=\"nofollow noreferrer\"><...
2018/10/29
[ "https://vi.stackexchange.com/questions/17767", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18929/" ]
I want to map `:e file.txt` to `:tabnew file.txt`, or the equivalent setting for editing file in a new tab. What do I need to put into my vimrc?
You probably want to read [`:h user-commands`](http://vimhelp.appspot.com/map.txt.html#user-commands) and put the following in your vimrc: ``` command! -nargs=1 -complete=file E tabnew <args> ``` You can't override `:e` but you can create the command `:E` which will take one argument (`-nargs=1`), complete this argu...
17,774
<p>How can I delete the block</p> <pre><code>int Test() { // } </code></pre> <p>when my cursor is before <code>int</code> (or even better when it is anywhere on that line)?</p> <p>The shortest I could come up with is <code>d&lt;line&gt;G</code> where <code>&lt;line&gt;</code> is the line number of the closing brace,...
[ { "answer_id": 17775, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 5, "selected": true, "text": "<h2>Motion <code>][</code>: next <code>}</code> in the first column</h2>\n<p><code>V][d</code> does what you want. More de...
2018/10/30
[ "https://vi.stackexchange.com/questions/17774", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18613/" ]
How can I delete the block ``` int Test() { // } ``` when my cursor is before `int` (or even better when it is anywhere on that line)? The shortest I could come up with is `d<line>G` where `<line>` is the line number of the closing brace, or `d<diff>j` where `<diff>` is the difference of the line number. I am not h...
Motion `][`: next `}` in the first column ----------------------------------------- `V][d` does what you want. More details can be found under [`:h ][`](http://vimhelp.appspot.com/motion.txt.html#%5D%5B) and [`:h section`](http://vimhelp.appspot.com/motion.txt.html#section): ``` *section* ...
17,784
<p>I am trying to use <code>:Termdebug</code> in Vim 8.1 on a CentOS machine. The default version of GDB at <code>/usr/bin/gdb</code> is less than the required v7.12. However, I have newer versions of GDB within <code>devtoolset</code> distributions I have installed with <code>yum</code>. To enable newer GDB versions, ...
[ { "answer_id": 26800, "author": "Paulo", "author_id": 30955, "author_profile": "https://vi.stackexchange.com/users/30955", "pm_score": 2, "selected": false, "text": "<p>As pointed out by <a href=\"https://vi.stackexchange.com/users/71/christian-brabandt\">Christian</a> (all credits to hi...
2018/10/31
[ "https://vi.stackexchange.com/questions/17784", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19608/" ]
I am trying to use `:Termdebug` in Vim 8.1 on a CentOS machine. The default version of GDB at `/usr/bin/gdb` is less than the required v7.12. However, I have newer versions of GDB within `devtoolset` distributions I have installed with `yum`. To enable newer GDB versions, I need to run `source /opt/rh/devtoolset-{versi...
As pointed out by [Christian](https://vi.stackexchange.com/users/71/christian-brabandt) (all credits to him) in [this comment](https://vi.stackexchange.com/questions/17784/specify-gdb-version-for-termdebug#comment30561_17784), setting `g:termdebugger` does the trick. Put this into your .vimrc: ``` let g:termdebugger='...
17,794
<p>Ref to :h foldtext() <code> The number of leading dashes depends on the foldlevel. </code> As follow, I think the foldlevel of <code>printf</code> is 1.</p> <p><a href="https://i.stack.imgur.com/59pa9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/59pa9.png" alt="enter image description here"></...
[ { "answer_id": 17795, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 2, "selected": false, "text": "<p>The documentation does not say how many dashes are there per foldlevel. As can be seen in the <a href=\"https://...
2018/11/01
[ "https://vi.stackexchange.com/questions/17794", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19615/" ]
Ref to :h foldtext() `The number of leading dashes depends on the foldlevel.` As follow, I think the foldlevel of `printf` is 1. [![enter image description here](https://i.stack.imgur.com/59pa9.png)](https://i.stack.imgur.com/59pa9.png) But, you can see as follow, the number of dashes is 2. [![enter image descriptio...
The documentation does not say how many dashes are there per foldlevel. As can be seen in the [source](https://github.com/vim/vim/blob/f080d70a82f3a4477f346d9efcdfaec1bc1e1d58/src/evalfunc.c#L3989-L4002): ```c txt = NGETTEXT("+-%s%3ld line: ", "+-%s%3ld lines: ", count); r = alloc((unsigned)(STRLEN(txt) + STRL...
17,818
<p>On Xubuntu LTS, I already managed to <a href="https://askubuntu.com/a/758165/164341">remap <kbd>CapsLock</kbd> to <kbd>Esc</kbd></a>.</p> <p>However, now I discovered some Vim users are <a href="https://www.reddit.com/r/linux/comments/5p2w90/does_anyone_use_their_scroll_lock_light_for/" rel="nofollow noreferrer">lig...
[ { "answer_id": 17821, "author": "Alp", "author_id": 19662, "author_profile": "https://vi.stackexchange.com/users/19662", "pm_score": 2, "selected": false, "text": "<blockquote>\n <p>Unfortunately, explanations about how to accomplish this Vim feat (under GNU/Linux) are nowhere to be fou...
2018/11/03
[ "https://vi.stackexchange.com/questions/17818", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/3168/" ]
On Xubuntu LTS, I already managed to [remap `CapsLock` to `Esc`](https://askubuntu.com/a/758165/164341). However, now I discovered some Vim users are [lighting the `Scroll Lock` LED](https://www.reddit.com/r/linux/comments/5p2w90/does_anyone_use_their_scroll_lock_light_for/), `Caps Lock` LED or even the [entire keyboa...
Caps Lock LED without `root` privileges ======================================= [![Varmilo Caps Lock with LED](https://i.stack.imgur.com/9Qr0p.jpg)](https://i.stack.imgur.com/9Qr0p.jpg) 1) Making `Caps Lock` act like `Esc` ------------------------------------ The full path to below `bash` script was added to `Sessio...
17,832
<p>Apologies if "composite" is not the technical term. I mean the following:</p> <pre><code>Hi, I-am-a-composite-word and we are not </code></pre> <p>I would like to delete only the composite word. In command mode, if I move the cursor to <code>I</code>, then repeating <code>dw</code> a few times, or better typing <c...
[ { "answer_id": 17833, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 6, "selected": true, "text": "<p>What you are calling a composite word is actually a WORD (by opposition to a word). Reading <a href=\"http://vimhelp.apps...
2018/11/05
[ "https://vi.stackexchange.com/questions/17832", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19675/" ]
Apologies if "composite" is not the technical term. I mean the following: ``` Hi, I-am-a-composite-word and we are not ``` I would like to delete only the composite word. In command mode, if I move the cursor to `I`, then repeating `dw` a few times, or better typing `dw` once, followed by a few `.` presses, will do ...
What you are calling a composite word is actually a WORD (by opposition to a word). Reading [`:h word`](http://vimhelp.appspot.com/motion.txt.html#word) and [`:h WORD`](http://vimhelp.appspot.com/motion.txt.html#WORD) should be helpful: ``` *word* A word consists of a sequence of letters, d...
17,837
<p>I have enjoyed coding not too large projects in one single file. This way I can press <code>*</code> on an identifier and find it without having to hop across buffers.</p> <p>But naturally this doesn't scale and at some point I need to isolate code into multiple files.</p> <p>Here is a dream use-case for which I w...
[ { "answer_id": 17838, "author": "grodzik", "author_id": 5395, "author_profile": "https://vi.stackexchange.com/users/5395", "pm_score": 2, "selected": true, "text": "<p>I don't thinks it's doable in pure Vim, or easly doable, but you can write a little script, in Python for example. Let's...
2018/11/06
[ "https://vi.stackexchange.com/questions/17837", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/12298/" ]
I have enjoyed coding not too large projects in one single file. This way I can press `*` on an identifier and find it without having to hop across buffers. But naturally this doesn't scale and at some point I need to isolate code into multiple files. Here is a dream use-case for which I wonder what is the best way t...
I don't thinks it's doable in pure Vim, or easly doable, but you can write a little script, in Python for example. Let's call it `split.py`. You can have a file, let's call it `code.py`, which will be the one that you edit. You can then call your script: ``` ./split.py code.py ``` You can then also automate it in Vi...
17,851
<p>I built vim from source. But for some reason I can no longer underline my current line when vim loads .vimrc. I have to type underline commands manually which makes it work. </p> <p>Here is the output of my version command</p> <pre><code>VIM - Vi IMproved 8.1 (2018 May 18, compiled Nov 5 2018 21:28:01) Included p...
[ { "answer_id": 17855, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 3, "selected": true, "text": "<p>As you can see from the output of <code>:verbose :hi CursorLine</code>, your CursorLine setting is reset by the c...
2018/11/06
[ "https://vi.stackexchange.com/questions/17851", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2865/" ]
I built vim from source. But for some reason I can no longer underline my current line when vim loads .vimrc. I have to type underline commands manually which makes it work. Here is the output of my version command ``` VIM - Vi IMproved 8.1 (2018 May 18, compiled Nov 5 2018 21:28:01) Included patches: 1-510 Compile...
As you can see from the output of `:verbose :hi CursorLine`, your CursorLine setting is reset by the colorscheme you are using. There are a couple of approaches you can use to change that. 1. Simply comment out the line in the colorscheme. 2. Use a `VimEnter` autocommand, to have your configuration setting set afte...
17,866
<p>Consider a script local function in a <code>plugin/myplugin.vim</code> file. For example </p> <p><code>myplugin.vim:</code></p> <pre><code>func! s:someFunction() return 4 endfunc </code></pre> <p>I would like to unit test this function. In the simplest example I would like to execute something like the follo...
[ { "answer_id": 17867, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 2, "selected": false, "text": "<p>I think there are two different possibilities to achieve what you want.</p>\n\n<ol>\n<li><p>You can create a glo...
2018/11/08
[ "https://vi.stackexchange.com/questions/17866", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13792/" ]
Consider a script local function in a `plugin/myplugin.vim` file. For example `myplugin.vim:` ``` func! s:someFunction() return 4 endfunc ``` I would like to unit test this function. In the simplest example I would like to execute something like the following in ANOTHER script. Without modifying the original ...
**TL;DR: Yes, but you probably shouldn't (in general)** ### Other answers Christian's answer offers two approaches that modify `myplugin.vim` in order to expose the script-local function (either as a Funcref or just the SID that allows you to obtain a Funcref). Having to extend a plugin just for testing purposes is ...
17,877
<p>I'd like to prepend the line below the current line to the current line. In other words, I want to "join" (like with <code>J</code> in normal mode) but instead of putting the line below the current line at the end of the current line, I'd like to put it at the front of the current line.</p> <p>Example:</p> <blockq...
[ { "answer_id": 17878, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 2, "selected": false, "text": "<p>Just swap the lines before you join them:</p>\n\n<pre><code>ddpkJ\n</code></pre>\n\n<p>Of course, if you would like ...
2018/11/08
[ "https://vi.stackexchange.com/questions/17877", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/14480/" ]
I'd like to prepend the line below the current line to the current line. In other words, I want to "join" (like with `J` in normal mode) but instead of putting the line below the current line at the end of the current line, I'd like to put it at the front of the current line. Example: > > ▋lorem ipsum amet dolor >...
If you don't want to use any register, you can do ``` :+m- | normal J ``` or use mapping ``` :nnoremap <leader>J :<c-u>+m-<cr>J ``` `:+m-` is to move the next line to be after the previous line, so eventually the order of the two lines are exchanged.
17,919
<p>I am designing a syntax rule (for R code) that highlights if I do not start a function with a curly all by itself. For example,</p> <pre><code> A &lt;- function(x, y){ </code></pre> <p>would be match but I do not want to match </p> <pre><code> A &lt;- function(x, y) { </c...
[ { "answer_id": 17878, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 2, "selected": false, "text": "<p>Just swap the lines before you join them:</p>\n\n<pre><code>ddpkJ\n</code></pre>\n\n<p>Of course, if you would like ...
2018/11/11
[ "https://vi.stackexchange.com/questions/17919", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19782/" ]
I am designing a syntax rule (for R code) that highlights if I do not start a function with a curly all by itself. For example, ``` A <- function(x, y){ ``` would be match but I do not want to match ``` A <- function(x, y) { ``` I do NOT watch the regular expression to ...
If you don't want to use any register, you can do ``` :+m- | normal J ``` or use mapping ``` :nnoremap <leader>J :<c-u>+m-<cr>J ``` `:+m-` is to move the next line to be after the previous line, so eventually the order of the two lines are exchanged.
17,938
<p>Suppose I have a dictionary declared like this:</p> <pre><code>g:dict = { \ 'foo' : ['foobar'], \ 'bar' : ['barfoo'] \} </code></pre> <p>how can I get the key for <code>barfoo</code> using just the value(<code>barfoo</code>) itself?</p>
[ { "answer_id": 17939, "author": "muru", "author_id": 205, "author_profile": "https://vi.stackexchange.com/users/205", "pm_score": 3, "selected": true, "text": "<p>There's no function to get a dictionary key from a value, so you'll have to loop over the keys. For example:</p>\n\n<pre><cod...
2018/11/13
[ "https://vi.stackexchange.com/questions/17938", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18514/" ]
Suppose I have a dictionary declared like this: ``` g:dict = { \ 'foo' : ['foobar'], \ 'bar' : ['barfoo'] \} ``` how can I get the key for `barfoo` using just the value(`barfoo`) itself?
There's no function to get a dictionary key from a value, so you'll have to loop over the keys. For example: ``` for [key, value] in items(g:dict) if index(value, "barfoo") >= 0 let g:mykey = key break endif endfor echo g:mykey ```
17,964
<p>Suppose I have this string variable:</p> <pre><code>let foo = [ \ 'no you are not foo', \ 'hi you must be foo?' \] </code></pre> <p>I want to enclose all the first 2 characters in foo with '&lt; ' and ' >' resulting to this:</p> <pre><code>'&lt; no &gt; you are not foo' '&lt; hi &gt; you must be f...
[ { "answer_id": 18072, "author": "jalanb", "author_id": 182, "author_profile": "https://vi.stackexchange.com/users/182", "pm_score": 3, "selected": false, "text": "<p>There are alternatives.</p>\n\n<p>Plain ol' <a href=\"https://docs.python.org/3/library/pdb.html\" rel=\"noreferrer\">pdb<...
2018/11/15
[ "https://vi.stackexchange.com/questions/17964", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18514/" ]
Suppose I have this string variable: ``` let foo = [ \ 'no you are not foo', \ 'hi you must be foo?' \] ``` I want to enclose all the first 2 characters in foo with '< ' and ' >' resulting to this: ``` '< no > you are not foo' '< hi > you must be foo?' ``` How can I do that?
For me [vimspector](https://github.com/puremourning/vimspector) looks amazing, and has out-of-the-box Python support.
17,974
<p>I want to append every value of list1 in every value of list2, so that this:</p> <pre><code>let list1 = ['one', 'two', 'three'] let list2 = [' wan', ' tu', ' tri'] </code></pre> <p>will become like this:</p> <pre><code>:echo result ['one wan', 'two tu', 'three tri'] </code></pre> <p>How could this be done?</p>
[ { "answer_id": 17980, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 2, "selected": false, "text": "<p>I don't like loops -- they are slow and a pain to debug as there is no \"continue until the end of the current loop\...
2018/11/15
[ "https://vi.stackexchange.com/questions/17974", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18514/" ]
I want to append every value of list1 in every value of list2, so that this: ``` let list1 = ['one', 'two', 'three'] let list2 = [' wan', ' tu', ' tri'] ``` will become like this: ``` :echo result ['one wan', 'two tu', 'three tri'] ``` How could this be done?
I don't like loops -- they are slow and a pain to debug as there is no "continue until the end of the current loop" ``` :echo map(range(len(list1)), 'list1[v:val].list2[v:val]') ``` Note: a `zip()` function is missing, but it can be emulated if we produce a range of indexes into both arrays. We could also simply tra...
17,975
<p>I use gvim8.1. My settings file contains these 2 lines: <code>set expandtab, set shiftwidth = 4</code>. I have a file 'html.vim' in '~\vimfiles\after\ftplugin\'. The file is listed below:</p> <pre><code>set expandtab setlocal shiftwidth=2 setlocal tabstop=2 </code></pre> <p>Unfortunately, this file changes shiftwi...
[ { "answer_id": 17976, "author": "John Fred Fadrigalan", "author_id": 18514, "author_profile": "https://vi.stackexchange.com/users/18514", "pm_score": 0, "selected": false, "text": "<p>You can set the option for .md filetypes upon opening the file like this.</p>\n\n<pre><code>autocmd BufR...
2018/11/15
[ "https://vi.stackexchange.com/questions/17975", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18295/" ]
I use gvim8.1. My settings file contains these 2 lines: `set expandtab, set shiftwidth = 4`. I have a file 'html.vim' in '~\vimfiles\after\ftplugin\'. The file is listed below: ``` set expandtab setlocal shiftwidth=2 setlocal tabstop=2 ``` Unfortunately, this file changes shiftwidth option when I'm working with vimw...
The Markdown *filetype* is based on the HTML one, because some HTML elements are also allowed in Markdown. This has the side effect that your HTML filetype settings are applied to Markdown, too. However, you can use the *after directory* for the Markdown filetype to override the settings. Even as the HTML customizatio...
17,988
<p>Part of a macro I'm writing deletes any blank lines, and then does some more work (joining the expected two remaining lines and then appending to them). Simplified version:</p> <pre><code>let @m=':g/^$/d^MggJA ^[' </code></pre> <p>(Where of course ^M and ^[ are the CR and ESC literals.)</p> <p>However, sometimes ...
[ { "answer_id": 17992, "author": "Charles Jie", "author_id": 19850, "author_profile": "https://vi.stackexchange.com/users/19850", "pm_score": 0, "selected": false, "text": "<p>Going through Vim's terminal.txt, I don't think you have a chance to clear the window.</p>\n\n<p>It's because Vim...
2018/11/16
[ "https://vi.stackexchange.com/questions/17988", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/12641/" ]
Part of a macro I'm writing deletes any blank lines, and then does some more work (joining the expected two remaining lines and then appending to them). Simplified version: ``` let @m=':g/^$/d^MggJA ^[' ``` (Where of course ^M and ^[ are the CR and ESC literals.) However, sometimes my input doesn't include any blan...
I don't know how to clear the previous texts but if you have problem with scrolling back to the last command after executing it you can go to text mood by pressing `ctrl + W` `N` and set mark by pressing `m` `<any key on the keyboard>` press `i` to comeback to interactive mode and and execute your command and when you ...
17,989
<p>In my file, I have many instances of <code>grid[X][Y]</code> where <code>X</code> and <code>Y</code> are variables. I would like to swap all instances to <code>grid[Y][X]</code> (preferably one by one so I can check them).</p> <p>Examples (especially note the second example):</p> <pre><code>grid[row][col] grid[row...
[ { "answer_id": 17992, "author": "Charles Jie", "author_id": 19850, "author_profile": "https://vi.stackexchange.com/users/19850", "pm_score": 0, "selected": false, "text": "<p>Going through Vim's terminal.txt, I don't think you have a chance to clear the window.</p>\n\n<p>It's because Vim...
2018/11/17
[ "https://vi.stackexchange.com/questions/17989", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17770/" ]
In my file, I have many instances of `grid[X][Y]` where `X` and `Y` are variables. I would like to swap all instances to `grid[Y][X]` (preferably one by one so I can check them). Examples (especially note the second example): ``` grid[row][col] grid[row + 1][col] ``` Swap to: ``` grid[col][row] grid[col][row + 1] ...
I don't know how to clear the previous texts but if you have problem with scrolling back to the last command after executing it you can go to text mood by pressing `ctrl + W` `N` and set mark by pressing `m` `<any key on the keyboard>` press `i` to comeback to interactive mode and and execute your command and when you ...
18,016
<p>If I have the cursor placed on "word1" and wanted to select "word1 word2 word3" (i.e. with no trailing space after "word3") what is the easiest command?</p> <pre><code>word1 word2 word3 word4 </code></pre> <p>I am currently using <code>v5iw</code>. Is this easiest command?</p>
[ { "answer_id": 18002, "author": "huB1erTi2", "author_id": 19752, "author_profile": "https://vi.stackexchange.com/users/19752", "pm_score": -1, "selected": false, "text": "<pre><code>q:\"+p&lt;cr&gt;\n</code></pre>\n\n<p>This mapping should paste from your clipboard and execute. Map it to...
2018/11/20
[ "https://vi.stackexchange.com/questions/18016", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19889/" ]
If I have the cursor placed on "word1" and wanted to select "word1 word2 word3" (i.e. with no trailing space after "word3") what is the easiest command? ``` word1 word2 word3 word4 ``` I am currently using `v5iw`. Is this easiest command?
`set mouse=` is the fix for the problem, with `set t_BE=` substituted in an *xterm* environment. The 'bug' these fixes solve was actually intended as a 'feature': creating an obstacle to pasting vi commands would be good if malicious code were somehow inserted onto user's clipboard. Kudos to a guy named Elijah, on ano...
18,046
<p>I'm trying to set gVim to be the default text editor on Windows but it won't work. It works with notepad++, editor... but not with Vim. Any ideas how to fix it?</p> <p>Screenshot: <a href="http://prntscr.com/lm069a" rel="nofollow noreferrer">http://prntscr.com/lm069a</a></p> <p>I also tried to choose <code>gvim.ex...
[ { "answer_id": 18064, "author": "Community", "author_id": -1, "author_profile": "https://vi.stackexchange.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>I can't comment, so here's a workaround I used: use <code>cmd.exe</code> in admin mode for this!</p>\n\n<p>First, type in...
2018/11/23
[ "https://vi.stackexchange.com/questions/18046", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19942/" ]
I'm trying to set gVim to be the default text editor on Windows but it won't work. It works with notepad++, editor... but not with Vim. Any ideas how to fix it? Screenshot: <http://prntscr.com/lm069a> I also tried to choose `gvim.exe` with the option that opens the explorer. if I open it it works, but it doesn't save...
I can't comment, so here's a workaround I used: use `cmd.exe` in admin mode for this! First, type in the following: ``` ftype VimFile="C:\Program Files (x86)\Vim\vim81\gvim.exe" --remote-silent "%1" ``` This ensures that any filetype (extension) associated to the `VimFile` we've set will, by double-click, open in g...
18,051
<p>I have the following strings (whitespace and line wise separated) in a file</p> <pre><code>mks asksö askndl ebre nakkl sadj </code></pre> <p>and would like to have it formatted as follows</p> <pre><code>["mks", "asksö", "askndl"], ["ebre", "nakkl", "sadj"], </code></pre> <p>What shortcut sequence is suitable?</p...
[ { "answer_id": 18064, "author": "Community", "author_id": -1, "author_profile": "https://vi.stackexchange.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>I can't comment, so here's a workaround I used: use <code>cmd.exe</code> in admin mode for this!</p>\n\n<p>First, type in...
2018/11/23
[ "https://vi.stackexchange.com/questions/18051", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19824/" ]
I have the following strings (whitespace and line wise separated) in a file ``` mks asksö askndl ebre nakkl sadj ``` and would like to have it formatted as follows ``` ["mks", "asksö", "askndl"], ["ebre", "nakkl", "sadj"], ``` What shortcut sequence is suitable?
I can't comment, so here's a workaround I used: use `cmd.exe` in admin mode for this! First, type in the following: ``` ftype VimFile="C:\Program Files (x86)\Vim\vim81\gvim.exe" --remote-silent "%1" ``` This ensures that any filetype (extension) associated to the `VimFile` we've set will, by double-click, open in g...
18,067
<p>I want to use the <a href="https://github.com/vim-scripts/nuweb.vim/blob/master/syntax/nuweb.vim" rel="nofollow noreferrer">nuweb.vim</a> extension for syntax highlighting <a href="http://nuweb.sourceforge.net/nuwebdoc.pdf" rel="nofollow noreferrer">nuweb files</a>. </p> <p>Long story short, nuweb files are basical...
[ { "answer_id": 18070, "author": "Leonardo Silvagni", "author_id": 19961, "author_profile": "https://vi.stackexchange.com/users/19961", "pm_score": 0, "selected": false, "text": "<p>Simply put <code>syntax on</code> on your vimrc</p>\n" }, { "answer_id": 26869, "author": "filb...
2018/11/25
[ "https://vi.stackexchange.com/questions/18067", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13566/" ]
I want to use the [nuweb.vim](https://github.com/vim-scripts/nuweb.vim/blob/master/syntax/nuweb.vim) extension for syntax highlighting [nuweb files](http://nuweb.sourceforge.net/nuwebdoc.pdf). Long story short, nuweb files are basically a super-set of latex files. There is added syntax and markers to embed code-snipp...
The [vimscripts entry](https://www.vim.org/scripts/script.php?script_id=543) for nuweb.vim (which is referred to by the README.md in the GitHub repository) gets into more details about how to install it: > > **install details** > > As WEB/CWEB uses \*.w, i recoment use \*.nw for NUWEB, so some like > > `au BufN...
18,073
<p>When I open a file (either from dolphin or terminal) a window of nvim-qt is created. Is there a way to open the file in the existing nvim-qt window and raise/focus to the window?</p> <p>Note: I know there is a way for gvim using silent server option, but couldn't make that work with nvim-qt.</p> <p>thanks.</p>
[ { "answer_id": 20638, "author": "otter.pro", "author_id": 21762, "author_profile": "https://vi.stackexchange.com/users/21762", "pm_score": 2, "selected": false, "text": "<p>According to <a href=\"https://github.com/neovim/neovim/wiki/FAQ\" rel=\"nofollow noreferrer\">neovim Wiki FAQ</a> ...
2018/11/26
[ "https://vi.stackexchange.com/questions/18073", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19966/" ]
When I open a file (either from dolphin or terminal) a window of nvim-qt is created. Is there a way to open the file in the existing nvim-qt window and raise/focus to the window? Note: I know there is a way for gvim using silent server option, but couldn't make that work with nvim-qt. thanks.
According to [neovim Wiki FAQ](https://github.com/neovim/neovim/wiki/FAQ) and [Issue #1750](https://github.com/neovim/neovim/issues/1750), client-server / remote feature was removed in Neovim. Instead, [neovim-remote](https://github.com/mhinz/neovim-remote) can be used. After installing it (`pip3 install neovim-remot...
18,079
<p>Using <code>getwininfo</code> it is possible to determine whether an window is a quickfix window or location list window. </p> <p>But once a location list window is found, how can I know which window it is associated with? </p> <p>Is there a more straightforward way to know whether the current window has a locatio...
[ { "answer_id": 18083, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 0, "selected": false, "text": "<p>I think that quickfix/loclist windows are not really associated with any other windows/buffers, and that what you...
2018/11/27
[ "https://vi.stackexchange.com/questions/18079", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13302/" ]
Using `getwininfo` it is possible to determine whether an window is a quickfix window or location list window. But once a location list window is found, how can I know which window it is associated with? Is there a more straightforward way to know whether the current window has a location list window opened
> > how to check whether the location list for the current window is open > > > You could try to inspect the `'winid'` property of the location list. If the location window is open, the value of the property should be different than zero: ``` if get(getloclist(0, {'winid':0}), 'winid', 0) " the location windo...
18,086
<p>The <code>BufWinLeave</code> event is not trigger when the buffer is still visible in another window, which includes the case <strong>when it is shown in a window in another tab</strong>. This is a annoying since only <strong>visible in the current tab</strong> is truly visible; and you cannot see a buffer in the sc...
[ { "answer_id": 18091, "author": "user938271", "author_id": 17449, "author_profile": "https://vi.stackexchange.com/users/17449", "pm_score": 3, "selected": true, "text": "<p>When you close the window of a buffer <code>B1</code> which is still displayed in another tabpage, <code>QuitPre</c...
2018/11/27
[ "https://vi.stackexchange.com/questions/18086", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13302/" ]
The `BufWinLeave` event is not trigger when the buffer is still visible in another window, which includes the case **when it is shown in a window in another tab**. This is a annoying since only **visible in the current tab** is truly visible; and you cannot see a buffer in the screen when it is **only "displayed" in an...
When you close the window of a buffer `B1` which is still displayed in another tabpage, `QuitPre`, `BufLeave` and `WinLeave` are fired in the context of `B1`. Then, `WinEnter` and `BufEnter` are fired in the context of the buffer where the focus goes (`B2`). None of these events matches your description: > > B1 disap...
18,089
<p>Sometimes I accidentally type <code>ma</code> instead of <code>'a</code> and overwrite the mark I had at <code>a</code> instead of jumping there.</p> <p>I know that by default vim has no way to undo an <code>ma</code>, but how can I add this functionality?</p> <p>I want to be able to undo an accidental mark overwr...
[ { "answer_id": 18094, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 1, "selected": false, "text": "<p>I am not sure this is a solution, as this might have too many nasty side effects. But one way to reset lost mark...
2018/11/27
[ "https://vi.stackexchange.com/questions/18089", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9024/" ]
Sometimes I accidentally type `ma` instead of `'a` and overwrite the mark I had at `a` instead of jumping there. I know that by default vim has no way to undo an `ma`, but how can I add this functionality? I want to be able to undo an accidental mark overwrite.
Here's some Vimscript that achieves your goal. To undo mark `a`, type `<leader>ma`. There's various ways this could be tweaked/polished, but it should be a good starting point for a more robust solution. ``` nnoremap m :call UndoableMark()<CR> nnoremap <leader>m :call UndoMark()<CR> function! UndoableMark() abort ...
18,092
<p>I can search for whole words like this</p> <pre><code>/\&lt;search term\&gt; </code></pre> <p><code>\&lt;</code> and <code>\&gt;</code> match left and right word boundaries respectively.</p> <p>But how can I insert those automatically? They are awkward to type out.</p>
[ { "answer_id": 18093, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 5, "selected": true, "text": "<p>There are two different ways to do this.</p>\n\n<ol>\n<li><p>You can insert those <em>and</em> the word currently und...
2018/11/27
[ "https://vi.stackexchange.com/questions/18092", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9024/" ]
I can search for whole words like this ``` /\<search term\> ``` `\<` and `\>` match left and right word boundaries respectively. But how can I insert those automatically? They are awkward to type out.
There are two different ways to do this. 1. You can insert those *and* the word currently under your cursor with `*`. So for example, if your cursor is on "hello", and you press asterisk, vim will treat that the same as `/\<hello\><cr>`. This is generally going to be the fastest way ([more info](https://vi.stackexchan...
18,099
<h2>Background</h2> <p>In <code>:h motion.txt</code>, it says:</p> <pre><code>FORCING A MOTION TO BE LINEWISE, CHARACTERWISE OR BLOCKWISE When a motion is not of the type you would like to use, you can force another type by using "v", "V" or CTRL-V just after the operator. Example: &gt; dj deletes two lines &gt;...
[ { "answer_id": 18100, "author": "doraemon", "author_id": 13302, "author_profile": "https://vi.stackexchange.com/users/13302", "pm_score": 2, "selected": false, "text": "<p>@christian had referred a very useful <a href=\"https://github.com/vim/vim/issues/3490\" rel=\"nofollow noreferrer\"...
2018/11/28
[ "https://vi.stackexchange.com/questions/18099", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13302/" ]
Background ---------- In `:h motion.txt`, it says: ``` FORCING A MOTION TO BE LINEWISE, CHARACTERWISE OR BLOCKWISE When a motion is not of the type you would like to use, you can force another type by using "v", "V" or CTRL-V just after the operator. Example: > dj deletes two lines > dvj deletes from the cur...
@christian had referred a very useful [link](https://github.com/vim/vim/issues/3490) to me, which already provided a solution in the future release of vim. Specifically: `mode(1)` will return ``` "no" " for operator-pending "nov" " for operator-pending forced to characterwise "noV" " for operato...
18,105
<p>I want <code>:nohl</code> to be run automatically whenever I run <code>:w</code>.</p> <p>How can I set this up?</p> <p>I tried </p> <pre><code>autocmd BufWrite * :nohl </code></pre> <p>in my vimrc but that's not working</p> <hr> <p>Apparently (from comments, thanks <a href="https://vi.stackexchange.com/users/1...
[ { "answer_id": 18108, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 4, "selected": true, "text": "<p>Indeed there is this note at <a href=\"http://vimhelp.appspot.com/eval.txt.html#function-search-undo\" rel=\"nore...
2018/11/29
[ "https://vi.stackexchange.com/questions/18105", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9024/" ]
I want `:nohl` to be run automatically whenever I run `:w`. How can I set this up? I tried ``` autocmd BufWrite * :nohl ``` in my vimrc but that's not working --- Apparently (from comments, thanks [D. Ben Knoble](https://vi.stackexchange.com/users/10604/d-ben-knoble)) > > Theres a note in the help somewhere a...
Indeed there is this note at [:h function-search-undo](http://vimhelp.appspot.com/eval.txt.html#function-search-undo): ``` The last used search pattern and the redo command "." will not be changed by the function. This also implies that the effect of :nohlsearch is undone when the function returns. ``` Which also a...
18,106
<p><code>&amp;</code> repeats the last <code>:s</code></p> <p>But it doesn't repeat with flags, e.g. a global sub:</p> <pre><code>:s/"/'/g </code></pre> <p>won't replace in the same way on consecutive lines with <code>&amp;</code>, running <code>:s/"/'/g</code> on the first line here and then <code>&amp;</code> on t...
[ { "answer_id": 18107, "author": "Naumann", "author_id": 11477, "author_profile": "https://vi.stackexchange.com/users/11477", "pm_score": 5, "selected": true, "text": "<p>This is exactly what <code>:&amp;&amp;</code> does:</p>\n<pre><code> *:&amp;&amp;*\n[&amp;]...
2018/11/29
[ "https://vi.stackexchange.com/questions/18106", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9024/" ]
`&` repeats the last `:s` But it doesn't repeat with flags, e.g. a global sub: ``` :s/"/'/g ``` won't replace in the same way on consecutive lines with `&`, running `:s/"/'/g` on the first line here and then `&` on the second ``` ["first", "second"] ["third", "fourth"] ``` produces ``` ['first', 'second'] ['thi...
This is exactly what `:&&` does: ``` *:&&* [&] Must be the first one: Keep the flags from the previous substitute command. Examples: > :&& :s/this/that/& < Note that `:s` and `:&` don't keep the flags. ``` There are also the `&` and `g&` commands: ``` ...
18,114
<p>I'm currently using </p> <pre><code>imap &lt;silent&gt; &lt;C-c&gt; &lt;/&lt;C-X&gt;&lt;C-O&gt;&lt;C-X&gt;&lt;Esc&gt;F&lt;i </code></pre> <p>as per <a href="https://stackoverflow.com/questions/130734/how-can-one-close-html-tags-in-vim-quickly">this post</a> and <a href="http://vim.wikia.com/wiki/Auto_closing_an_HT...
[ { "answer_id": 18125, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 3, "selected": true, "text": "<h2>Plugin <em>xml.vim</em> by Rene de Zwart (<a href=\"https://github.com/othree/xml.vim\" rel=\"nofollow noreferrer\">gi...
2018/11/29
[ "https://vi.stackexchange.com/questions/18114", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17531/" ]
I'm currently using ``` imap <silent> <C-c> </<C-X><C-O><C-X><Esc>F<i ``` as per [this post](https://stackoverflow.com/questions/130734/how-can-one-close-html-tags-in-vim-quickly) and [this page](http://vim.wikia.com/wiki/Auto_closing_an_HTML_tag) to close `<></>` tags of any kind with `<C-c>`, which works a treat....
Plugin *xml.vim* by Rene de Zwart ([github](https://github.com/othree/xml.vim), [#1397](https://www.vim.org/scripts/script.php?script_id=1397)) ----------------------------------------------------------------------------------------------------------------------------------------------- This plugin defines two relevan...
18,137
<p>How to determine if the cursor is placed on the last character of the word under the cursor?</p> <p>I can get information about the word under cursor like determining if the length of the word under the cursor is 1 character:</p> <pre><code>strlen(expand('&lt;cword&gt;'))==1 </code></pre> <p>But as far as I see t...
[ { "answer_id": 18139, "author": "Karl Yngve Lervåg", "author_id": 21, "author_profile": "https://vi.stackexchange.com/users/21", "pm_score": 2, "selected": false, "text": "<p>I would get the characters on the current line from the cursor and on and check if they match the end-of-word ato...
2018/12/02
[ "https://vi.stackexchange.com/questions/18137", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/307/" ]
How to determine if the cursor is placed on the last character of the word under the cursor? I can get information about the word under cursor like determining if the length of the word under the cursor is 1 character: ``` strlen(expand('<cword>'))==1 ``` But as far as I see the expression `expand('<cword>')` only ...
I'd take a more experimental approach that @Karl Yngve Lervåg does in [his answer](https://vi.stackexchange.com/a/18139/343): This works by moving the cursor back a word and then forwards again and then seeing if the cursor is in the same place. If it is, then the cursor was on the end of a `<word>`. Using this techn...
18,162
<p>I know that similar things were asked here several times. I know that to repeat a motion <code>;</code> works. Unless it doesn't(in case there is count for example), but then <code>repmo.vim</code> usually works. And I know that <code>.</code> works for changes.</p> <p>The thing is that <code>repmo.vim</code> is st...
[ { "answer_id": 18173, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 3, "selected": true, "text": "<h2>Plugin <a href=\"https://github.com/Houl/repmo-vim\" rel=\"nofollow noreferrer\"><em>repmo-vim</em></a> by Andy Wakula...
2018/12/04
[ "https://vi.stackexchange.com/questions/18162", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18375/" ]
I know that similar things were asked here several times. I know that to repeat a motion `;` works. Unless it doesn't(in case there is count for example), but then `repmo.vim` usually works. And I know that `.` works for changes. The thing is that `repmo.vim` is stupid, and thus provides no solution for complicated th...
Plugin [*repmo-vim*](https://github.com/Houl/repmo-vim) by Andy Wakula ---------------------------------------------------------------------- The plugin [#2174](https://www.vim.org/scripts/script.php?script_id=2174) listed on <https://www.vim.org/scripts> is, according to the description, outdated: > > 2016 Nov 22 s...