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
30,854
<p>I've installed vimspector. When I type <code>:Vim</code> in the command &amp; hit <kbd>tab</kbd>, I get all matched autocomplete suggestion like <code>VimspectorAbortInstall</code>, <code>VimspectorEval</code>, <code>Vim....</code> etc.</p> <p>I'm tired to iterate that long matched list one by one to select the corr...
[ { "answer_id": 30861, "author": "Andrew Ho-Lee", "author_id": 32132, "author_profile": "https://vi.stackexchange.com/users/32132", "pm_score": 1, "selected": false, "text": "<p>It is likely that there are other commands that start with <code>:Vim</code> but not <code>:Vimspector</code> t...
2021/04/02
[ "https://vi.stackexchange.com/questions/30854", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34358/" ]
I've installed vimspector. When I type `:Vim` in the command & hit `tab`, I get all matched autocomplete suggestion like `VimspectorAbortInstall`, `VimspectorEval`, `Vim....` etc. I'm tired to iterate that long matched list one by one to select the correct command. How to make neovim just suggest the `Vimspector` sub-...
It is likely that there are other commands that start with `:Vim` but not `:Vimspector` that are being offered in the completion, hence why it stops there. Natively, vim offers the `:VimballList` command. You can see with [`:h :VimballList`](https://vimhelp.org/pi_vimball.txt.html#%3AVimballList) that this comes from ...
30,862
<p>The main objective of this question is I want to get the shell command's execution result to show in small split window right inside vim while I'm editing the file; the same result I would get when I hook such shell commands to execute through <code>autocmd</code>. But thing is I want such result if I configure key ...
[ { "answer_id": 30861, "author": "Andrew Ho-Lee", "author_id": 32132, "author_profile": "https://vi.stackexchange.com/users/32132", "pm_score": 1, "selected": false, "text": "<p>It is likely that there are other commands that start with <code>:Vim</code> but not <code>:Vimspector</code> t...
2021/04/03
[ "https://vi.stackexchange.com/questions/30862", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19466/" ]
The main objective of this question is I want to get the shell command's execution result to show in small split window right inside vim while I'm editing the file; the same result I would get when I hook such shell commands to execute through `autocmd`. But thing is I want such result if I configure key binding with `...
It is likely that there are other commands that start with `:Vim` but not `:Vimspector` that are being offered in the completion, hence why it stops there. Natively, vim offers the `:VimballList` command. You can see with [`:h :VimballList`](https://vimhelp.org/pi_vimball.txt.html#%3AVimballList) that this comes from ...
30,864
<p>I need your kind help on writing a regular expression for the following situation.</p> <p>Consider the following first word sequence:</p> <pre><code>Criteria A xxx xxx xxx Table1 Criteria A xxx xxx xxx Table2 Criteria A xxx xxx xxx Table3 Criteria A xxx xxx xxx Table4 Criteria A xxx xxx xxx Table5 Criteria A xxx xxx...
[ { "answer_id": 30867, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<p>In the first case, I would probably just adjust the table numbers and do <code>:sort n</code> to sort by number...
2021/04/03
[ "https://vi.stackexchange.com/questions/30864", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34363/" ]
I need your kind help on writing a regular expression for the following situation. Consider the following first word sequence: ``` Criteria A xxx xxx xxx Table1 Criteria A xxx xxx xxx Table2 Criteria A xxx xxx xxx Table3 Criteria A xxx xxx xxx Table4 Criteria A xxx xxx xxx Table5 Criteria A xxx xxx xxx Table6 Criteri...
In the first case, I would probably just adjust the table numbers and do `:sort n` to sort by number (this doesn't work if there are numbers before the table number; in that case, something like `:sort n /\d*$/` ought to work.). To adjust the table numbers, `<C-x>` and `<C-a>` with a count, which are dot-repeatable, ar...
30,895
<p>I am currently new to neovim.</p> <p>Something that has me a bit stuck is being able to easily run my code. The text editor I used before trying out vim was Sublime Text 3, and, in that text editor, all I had to do was press <kbd>Cmd</kbd>-<kbd>B</kbd>. It would use a build system that either came with the text edit...
[ { "answer_id": 30896, "author": "jdhao", "author_id": 15292, "author_profile": "https://vi.stackexchange.com/users/15292", "pm_score": 1, "selected": false, "text": "<p>Yes, there is a way to build the file based on its file types. No, there is no predefined build script to build a scrip...
2021/04/07
[ "https://vi.stackexchange.com/questions/30895", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34428/" ]
I am currently new to neovim. Something that has me a bit stuck is being able to easily run my code. The text editor I used before trying out vim was Sublime Text 3, and, in that text editor, all I had to do was press `Cmd`-`B`. It would use a build system that either came with the text editor or one that I made mysel...
After doing a bit research, I found a plugin called "[quickrun.vim](https://github.com/D0n9X1n/quickrun.vim)\*" and this plugin (from what I understand) runs a series of commands based on the extension of the current file you are working on. You can use the default "build-systems" that the plugin comes with, however, y...
30,897
<p>I want to match (search) all C code comments in a file in e.g.</p> <pre><code> enum { foo, /* Foo is so cool, why can't we all be more like foo? */ bar, /* but bar is mysterious and suave, like the James Bond of enum and variable names. */ etc, </code></pre> <p>So, I w...
[ { "answer_id": 30898, "author": "Simon Peverett", "author_id": 13809, "author_profile": "https://vi.stackexchange.com/users/13809", "pm_score": 1, "selected": false, "text": "<p>I already know but I searched the web and couldn't find the definitive answer for VIM (just every other regex ...
2021/04/07
[ "https://vi.stackexchange.com/questions/30897", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13809/" ]
I want to match (search) all C code comments in a file in e.g. ``` enum { foo, /* Foo is so cool, why can't we all be more like foo? */ bar, /* but bar is mysterious and suave, like the James Bond of enum and variable names. */ etc, ``` So, I want a regex that will ma...
The problem with pure regex based solutions, is that there would be a few false-positives, like in: ``` /*bar*/ char const* p = "/*"; /* bar */ /// foo char const* e = "*/"; ``` `/*` in strings would be matched as well. I though at first that we could get around it with [`[*`](http://vimhelp.appspot.com/motion....
30,909
<p>I have created the following mapping for Ex mode to prevent having to enter <code>:FZF</code> capitalized to invoke FZF:</p> <p><code>cnoremap fzf FZF</code></p> <p>The problem is that this key mapping also affects &quot;/&quot; searching, so if I want to search for <code>/fzf</code>, then Vim changes the search to ...
[ { "answer_id": 30910, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<p>You need to use an <code>expr</code> mapping:</p>\n<pre><code>cnoremap &lt;expr&gt; fzf getcmdtype() isnot# ':'...
2021/04/08
[ "https://vi.stackexchange.com/questions/30909", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/26505/" ]
I have created the following mapping for Ex mode to prevent having to enter `:FZF` capitalized to invoke FZF: `cnoremap fzf FZF` The problem is that this key mapping also affects "/" searching, so if I want to search for `/fzf`, then Vim changes the search to `/FZF` (and I have case-sensitive searching enabled). How...
Another solution is to use an abbreviation: ``` cnoreabbrev <expr> fzf (getcmdtype() == ':' && getcmdline() =~ '^fzf$')? 'FZF' : 'fzf' ``` You check that the command line type is `:` and that you only have `fzf` in your command (to avoid messing with e.g `:call fzf#vim#rg(...)`) and if it is the case your replace yo...
30,914
<p>Working on a larger project, I tend to switch from topic to topic using git. Some times I want to run a command on all the buffers that are related to the topic at hand.</p> <p>I can do a <code>:bufdo</code>, but this would run on many loaded buffers that are not related to what I am doing currently (and will sugges...
[ { "answer_id": 30915, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 4, "selected": true, "text": "<p>Interesting question. I had to think about how to do this as I wanted to avoid using <code>:ls a</code>. (Parsing <cod...
2021/04/09
[ "https://vi.stackexchange.com/questions/30914", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2170/" ]
Working on a larger project, I tend to switch from topic to topic using git. Some times I want to run a command on all the buffers that are related to the topic at hand. I can do a `:bufdo`, but this would run on many loaded buffers that are not related to what I am doing currently (and will suggest reloading the file...
Interesting question. I had to think about how to do this as I wanted to avoid using `:ls a`. (Parsing `:ls` output isn't ideal in much the same way that parsing the output of the shell command `ls` is non-ideal.) I've got it down to a single Ex command line, though one that could use a bit of explanation depending on ...
30,922
<p>Update: <a href="https://github.com/benknoble/tag-tracks" rel="nofollow noreferrer">I've created a plugin</a>.</p> <p>I wrote a bit of code for a friend who's dealing with large C code-bases and using cscope/ctags to navigate around. He was hoping to get a persistent display of the tagstack; here's what I've whipped...
[ { "answer_id": 30915, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 4, "selected": true, "text": "<p>Interesting question. I had to think about how to do this as I wanted to avoid using <code>:ls a</code>. (Parsing <cod...
2021/04/09
[ "https://vi.stackexchange.com/questions/30922", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10604/" ]
Update: [I've created a plugin](https://github.com/benknoble/tag-tracks). I wrote a bit of code for a friend who's dealing with large C code-bases and using cscope/ctags to navigate around. He was hoping to get a persistent display of the tagstack; here's what I've whipped up that seems mostly working. I would love a ...
Interesting question. I had to think about how to do this as I wanted to avoid using `:ls a`. (Parsing `:ls` output isn't ideal in much the same way that parsing the output of the shell command `ls` is non-ideal.) I've got it down to a single Ex command line, though one that could use a bit of explanation depending on ...
30,936
<p>I have patched my own nerd-font and I want those cool icons for each file-type to be shown in the name of tab in Vim/NeoVim. I guess this can be done easily like I have customized my <code>zsh</code> command prompt as shown below with one line. But I don't know how to do that, and I have searched many projects/plugi...
[ { "answer_id": 30939, "author": "job_start", "author_id": 10189, "author_profile": "https://vi.stackexchange.com/users/10189", "pm_score": 3, "selected": true, "text": "<p>Finally, I decided not to re-invent the wheel, and this problem seems to be more difficult than I think. So, I give ...
2021/04/11
[ "https://vi.stackexchange.com/questions/30936", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10189/" ]
I have patched my own nerd-font and I want those cool icons for each file-type to be shown in the name of tab in Vim/NeoVim. I guess this can be done easily like I have customized my `zsh` command prompt as shown below with one line. But I don't know how to do that, and I have searched many projects/plugins on GitHub b...
Finally, I decided not to re-invent the wheel, and this problem seems to be more difficult than I think. So, I give [Vem-Tabline](https://github.com/pacha/vem-tabline) a try and it works nicely, and the default settings of this plugin are good, so no need to put code into my `.vimrc`. Nice! Now my MacVim looks like th...
30,963
<p>Let's say I have opened many files on Vim with <code>vim file1 file2 file3</code>... And their content is like the following:</p> <p>file1:</p> <pre><code>random content random content stringThatMatchesRegex random content </code></pre> <p>file2:</p> <pre><code>random content random content random content </code></p...
[ { "answer_id": 30964, "author": "Peter Rincker", "author_id": 778, "author_profile": "https://vi.stackexchange.com/users/778", "pm_score": 4, "selected": true, "text": "<p>One way is to populate the quickfix list with matches then use <code>:cfdo</code> to execute <code>:bdelete</code></...
2021/04/13
[ "https://vi.stackexchange.com/questions/30963", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/32434/" ]
Let's say I have opened many files on Vim with `vim file1 file2 file3`... And their content is like the following: file1: ``` random content random content stringThatMatchesRegex random content ``` file2: ``` random content random content random content ``` file3: ``` stringThatMatchesRegex random content rando...
One way is to populate the quickfix list with matches then use `:cfdo` to execute `:bdelete` ``` :vimgrep /pat/ ## :cfdo bdelete ``` Even though the files are closed the files are still in the argument-list. Remove them via `:argdelete` with `%` to represent the current file ``` :vimgrep /pat/ ## :cfdo argdelete % ...
30,968
<p>Where does Vim store <code>b:</code> buffer level variables / dictionaries? RAM or some kind of file on a disk?</p> <p>If it stores it in RAM, how to get an estimate of RAM / storage used by a particular variable / dictionary?</p> <p>Asking for both Vim &amp; Neovim.</p>
[ { "answer_id": 30970, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": true, "text": "<p>In Vim, if you look at the source code for <a href=\"https://github.com/vim/vim/blob/f6a8d420a8d2924737f713de046947dcb487...
2021/04/14
[ "https://vi.stackexchange.com/questions/30968", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/33917/" ]
Where does Vim store `b:` buffer level variables / dictionaries? RAM or some kind of file on a disk? If it stores it in RAM, how to get an estimate of RAM / storage used by a particular variable / dictionary? Asking for both Vim & Neovim.
In Vim, if you look at the source code for [`buflist_new()`](https://github.com/vim/vim/blob/f6a8d420a8d2924737f713de046947dcb487550c/src/buffer.c#L1963) which adds a filename to the buffer list you'll find the part [where the `b:` dictionary is initialized](https://github.com/vim/vim/blob/f6a8d420a8d2924737f713de04694...
30,975
<p>In short, I want to keep the indentation created by <code>o</code> after pressing <code>&lt;Esc&gt;</code>. To make it clear, I will try to describe my problem with an example.</p> <p>Given the position of my cursor at:</p> <pre><code>function Test() { return ( &lt;div&gt;█ &lt;/div&gt; ) } NORMAL </co...
[ { "answer_id": 30976, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 2, "selected": false, "text": "<p>You have <code>autoindent</code> on:</p>\n<pre><code> *'autoindent'* *'ai'* *'noautoindent'* *'noai'*\n'au...
2021/04/15
[ "https://vi.stackexchange.com/questions/30975", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10189/" ]
In short, I want to keep the indentation created by `o` after pressing `<Esc>`. To make it clear, I will try to describe my problem with an example. Given the position of my cursor at: ``` function Test() { return ( <div>█ </div> ) } NORMAL ``` When I press `o`: ``` function Test() { return ( <...
You don't need spaces on empty line. This is the reason Vim removes auto-indentation after Esc. Whenever you're going to write something on empty line with indentation applied, you can press `cc` or `S`. Or you can re-indent text after you've finished with it (e.g. `==` or `='[` and so on).
30,983
<p>I've been messing around a bit with <code>fzf</code> and I'd like to be able to run a command that does something like take the output of <code>diff -w -M origin/main...HEAD --name-only</code> and make the contents available in a preview window.</p> <p>I've gotten this far, with some copy/paste from the docs:</p> <p...
[ { "answer_id": 31016, "author": "oalders", "author_id": 13055, "author_profile": "https://vi.stackexchange.com/users/13055", "pm_score": 3, "selected": true, "text": "<p>It turns out I was overthinking this and I also missed some of the documentation. <code>fzf#run</code> can accept an a...
2021/04/15
[ "https://vi.stackexchange.com/questions/30983", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13055/" ]
I've been messing around a bit with `fzf` and I'd like to be able to run a command that does something like take the output of `diff -w -M origin/main...HEAD --name-only` and make the contents available in a preview window. I've gotten this far, with some copy/paste from the docs: ``` command! -bang -nargs=* Gdomo ...
It turns out I was overthinking this and I also missed some of the documentation. `fzf#run` can accept an arbitrary command which returns a list of files. A working example without a preview window: ``` command! GDomo \ call fzf#run({'source': 'git diff -w -M origin/main...HEAD --name-only', 'sink': 'e'}) ``` A w...
30,993
<p>I have been using vim for a short time, so I may not know a lot, please forgive me.</p> <p>There is a problem with my vim. It cannot enter normal mode from insert mode by pressing <code>esc/ctrl-[</code> only once, but needs to press <code>esc/ctrl-[</code> twice.</p> <p>When I first press <code>esc/ctrl-[</code> sh...
[ { "answer_id": 30997, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<p>As sussed out in the comments, you have mappings that begin with <code>&lt;esc&gt;</code> somewhere (and the su...
2021/04/17
[ "https://vi.stackexchange.com/questions/30993", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34652/" ]
I have been using vim for a short time, so I may not know a lot, please forgive me. There is a problem with my vim. It cannot enter normal mode from insert mode by pressing `esc/ctrl-[` only once, but needs to press `esc/ctrl-[` twice. When I first press `esc/ctrl-[` show command remind me I entered `^[`. I have trie...
As sussed out in the comments, you have mappings that begin with `<esc>` somewhere (and the surprise indicates you didn’t ask for them). You can use `:verbose imap <esc>` to find out where the mappings are coming from; in general, mappings with a prefix cause a delay whenever the prefix is entered, as vim has to distin...
31,012
<p>I came across <code>&lt;Plug&gt;</code> in this command of easy-motion</p> <pre><code>nmap &lt;Leader&gt;w &lt;Plug&gt;(easymotion-overwin-w) </code></pre> <p>I tried to search for the definition of but no luck. What does it mean?</p> <p>Does it have anything related with sourcing <code>init.vim</code>(I am using n...
[ { "answer_id": 31013, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 6, "selected": true, "text": "<p>This is used by plugin authors to make complex mappings available to the user. In a plugin code you define a mapping with...
2021/04/19
[ "https://vi.stackexchange.com/questions/31012", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34675/" ]
I came across `<Plug>` in this command of easy-motion ``` nmap <Leader>w <Plug>(easymotion-overwin-w) ``` I tried to search for the definition of but no luck. What does it mean? Does it have anything related with sourcing `init.vim`(I am using nvim)? I am asking because I found this mapping won't work initially, an...
This is used by plugin authors to make complex mappings available to the user. In a plugin code you define a mapping with `<plug>...` which is not a real key sequence but which can be used as a right hand side expression in a mapping by your users. As an example take [this line of code](https://github.com/svermeulen/v...
31,035
<p>So I have a language that looks something like this:</p> <pre><code>proc someprocess : (arg1: type1), (arg2: type2) ... |- (channel: type) = { send $ch msg ; pay $ch {n} ; } </code></pre> <p>I want the <code>{n}</code> to be highlighted however i don't want the code in the <code>proc</code> contained with <c...
[ { "answer_id": 31036, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 1, "selected": false, "text": "<p>My suggestion here is to use a zero-width look-behind match to look up the specific keywords you're after (<code>p...
2021/04/21
[ "https://vi.stackexchange.com/questions/31035", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34725/" ]
So I have a language that looks something like this: ``` proc someprocess : (arg1: type1), (arg2: type2) ... |- (channel: type) = { send $ch msg ; pay $ch {n} ; } ``` I want the `{n}` to be highlighted however i don't want the code in the `proc` contained with `{ }` to be highlighted. i.e. only want `{..}` r...
Your don't provide full spec for your language. But whenever possible, contained-matches should be preferred. I.e. something like this: ``` syn match xPayOrGet /pay\|get/ skipwhite nextgroup=xPayGetAfter syn match xPayGetAfter /[^;]\+;/ contains=xPayGetBraces contained syn match xPayGetBraces /{\a\+}/ contained ```
31,044
<p>I know that I can open a file through a pipe with vim with the following command:</p> <pre><code>cat myfile.txt | vim - </code></pre> <p>I also know that I can edit files on vim directly from the command line as the following:</p> <pre><code>vim -e myfile.txt -c ':%s/^/newstring-/g | x' </code></pre> <p>The last co...
[ { "answer_id": 31045, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 0, "selected": false, "text": "<p><code>:xit</code> is supposed to save file to disk, not write it to stdout. You're strongly advised to use <code>sed</co...
2021/04/22
[ "https://vi.stackexchange.com/questions/31044", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/32434/" ]
I know that I can open a file through a pipe with vim with the following command: ``` cat myfile.txt | vim - ``` I also know that I can edit files on vim directly from the command line as the following: ``` vim -e myfile.txt -c ':%s/^/newstring-/g | x' ``` The last command will open a file, execute a Vim command...
I found a solution to this issue on [this answer from StackOverflow](https://stackoverflow.com/a/28563499/14739472). The following line does what I expected in my question: ``` var=$(cat myfile.txt | vim -e -c ':g/./normal osleep 0.5' '+%p' -escq! /dev/stdin) ``` Honestly, I don't fully understand the syntax `'+%p' ...
31,047
<p>I have the following text</p> <pre><code>Plan based ................................. 32 Iron based in Compound .............................. 34 Gallium Arsnide based III-V ............ 36 ... Indium phosphide based III-V ............ 200 </code></pre> <p>but there are about 100 lines not 4 or so.</p> <p>I wi...
[ { "answer_id": 31045, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 0, "selected": false, "text": "<p><code>:xit</code> is supposed to save file to disk, not write it to stdout. You're strongly advised to use <code>sed</co...
2021/04/22
[ "https://vi.stackexchange.com/questions/31047", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/27300/" ]
I have the following text ``` Plan based ................................. 32 Iron based in Compound .............................. 34 Gallium Arsnide based III-V ............ 36 ... Indium phosphide based III-V ............ 200 ``` but there are about 100 lines not 4 or so. I wish to pad this text by changin...
I found a solution to this issue on [this answer from StackOverflow](https://stackoverflow.com/a/28563499/14739472). The following line does what I expected in my question: ``` var=$(cat myfile.txt | vim -e -c ':g/./normal osleep 0.5' '+%p' -escq! /dev/stdin) ``` Honestly, I don't fully understand the syntax `'+%p' ...
31,054
<p>Let say I have a simple line</p> <pre><code>hell&lt;cursor&gt;o </code></pre> <p>What is the fastest way to yank this line and paste to a result like this?</p> <pre><code>hello hello </code></pre> <p>I am currently doing this:</p> <pre><code>yy # To yank this line p # Paste on next line O # To insert and add a line...
[ { "answer_id": 31056, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 4, "selected": true, "text": "<p>Vim golf? :)</p>\n<p>How about</p>\n<pre><code>Y2pD\n</code></pre>\n<p>It's perhaps a little contrived to create two n...
2021/04/23
[ "https://vi.stackexchange.com/questions/31054", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34675/" ]
Let say I have a simple line ``` hell<cursor>o ``` What is the fastest way to yank this line and paste to a result like this? ``` hello hello ``` I am currently doing this: ``` yy # To yank this line p # Paste on next line O # To insert and add a line above the pasted line ``` But doing so I will end up in In...
Vim golf? :) How about ``` Y2pD ``` It's perhaps a little contrived to create two new `hello` lines only to delete one but trying to avoid Insert mode is also a bit contrived when you're actually, you know, inserting new text (the blank line). ;)
31,067
<p>When I'm confronting a bug of a plugin and an error message pops up like this one:</p> <pre><code>E5018: Error executing lua ... </code></pre> <p>and if I want to report this bug, I always have to type this error message manually. How can I copy the error message into my clipboard in order to paste it on github?</p>...
[ { "answer_id": 31071, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 3, "selected": true, "text": "<p>You can typically see the error messages produced by plug-ins using the <code>:messages</code> command.</p>\n<p>If ...
2021/04/24
[ "https://vi.stackexchange.com/questions/31067", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/31844/" ]
When I'm confronting a bug of a plugin and an error message pops up like this one: ``` E5018: Error executing lua ... ``` and if I want to report this bug, I always have to type this error message manually. How can I copy the error message into my clipboard in order to paste it on github?
You can typically see the error messages produced by plug-ins using the `:messages` command. If you'd like to put those messages into a Vim buffer, so that you can copy them to the clipboard from there, you can use the following command: ``` :put =execute('messages') ``` This uses the `execute()` function to captur...
31,068
<p>For example, I'm browsing the 700th line, and I typed &quot;:456&quot; to jump to the 456th line. Now I want to quickly return to the 700th line. Is there any shortcut key instead of typing &quot;:700&quot;.</p>
[ { "answer_id": 31070, "author": "mattb", "author_id": 31858, "author_profile": "https://vi.stackexchange.com/users/31858", "pm_score": 3, "selected": true, "text": "<p>The jumplist (see :help jumplist) can be navigated with <code>Ctrl-o</code>, to go back to\nline 700 (and <code>Ctrl-i</...
2021/04/24
[ "https://vi.stackexchange.com/questions/31068", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/31124/" ]
For example, I'm browsing the 700th line, and I typed ":456" to jump to the 456th line. Now I want to quickly return to the 700th line. Is there any shortcut key instead of typing ":700".
The jumplist (see :help jumplist) can be navigated with `Ctrl-o`, to go back to line 700 (and `Ctrl-i` would take you back to line 456 again). If you want to be able to do this with relative jumps (i.e. after typing `7j` to go seven lines down, use `Ctrl-o` to return to where you before the relative jump), you can use...
31,088
<p>In terminal, the command of the line of the input prompt can be cleared with <code>&lt;C-U&gt;</code>, and is recoverable with <code>&lt;C-Y&gt;</code>.</p> <p>In vim, the colon command can be cleared with <code>&lt;C-U&gt;</code>, but it is not recoverable with <code>&lt;C-Y&gt;</code>. Is it possible to recover th...
[ { "answer_id": 31092, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 1, "selected": false, "text": "<p>I have an idea which is probably not ideal but could be in the right direction. The idea is to make use of the event <a ...
2021/04/26
[ "https://vi.stackexchange.com/questions/31088", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34675/" ]
In terminal, the command of the line of the input prompt can be cleared with `<C-U>`, and is recoverable with `<C-Y>`. In vim, the colon command can be cleared with `<C-U>`, but it is not recoverable with `<C-Y>`. Is it possible to recover those erased commands?
Somewhat workaround if you have recent vim with `<cmd>` support: ``` cnoremap <C-u> <cmd>let g:CCtrlU = strpart(getcmdline(),0,getcmdpos()-1)<CR><C-u> cnoremap <C-y> <C-r>=get(g:, "CCtrlU", "")<CR><cmd>let g:CCtrlU = ''<CR> ``` With `<cmd>` it is possible to run arbitrary vimscript without changing modes, so here wi...
31,093
<p>I am using a nightly build of nvim, and I am trying to use <code>neovim/nvim-lspconfig</code>. I have followed to doc and setup the language server, but nvim throws error and reports that it is unable to process it.</p> <p>The error is coming from the lua part. When I comment out it everything works as normal. Here ...
[ { "answer_id": 31098, "author": "TornaxO7", "author_id": 31844, "author_profile": "https://vi.stackexchange.com/users/31844", "pm_score": 2, "selected": false, "text": "<p>In order to load the plugins, you have to wrap your <code>Plug</code> part with <code>call plug#begin(&lt;path&gt;)<...
2021/04/27
[ "https://vi.stackexchange.com/questions/31093", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34675/" ]
I am using a nightly build of nvim, and I am trying to use `neovim/nvim-lspconfig`. I have followed to doc and setup the language server, but nvim throws error and reports that it is unable to process it. The error is coming from the lua part. When I comment out it everything works as normal. Here is my code: ``` Plu...
In order to load the plugins, you have to wrap your `Plug` part with `call plug#begin(<path>)` and `call plug#end()`. So it should look like this for example: ``` call plug#begin('~/.vim/plugged') Plug 'neovim/nvim-lspconfig' Plug 'nvim-lua/completion-nvim' call plug#end() lua require('lspconfig').tsserver.setup{} `...
31,102
<p>I'm doing a project-wise refactor and I want to change variable names from <code>camelCase</code> to <code>snake_case</code>. I have YCM and vim-abolish installed. Let's say I have the following source file:</p> <pre><code>dueDate = ... processDueDate(dueDate); </code></pre> <ul> <li>With <code>vim-abolish</code> I ...
[ { "answer_id": 31104, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 3, "selected": true, "text": "<p>You'll have to reverse engineer the internal function used by Abolish and call it. It's quite likely one of the funct...
2021/04/27
[ "https://vi.stackexchange.com/questions/31102", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34814/" ]
I'm doing a project-wise refactor and I want to change variable names from `camelCase` to `snake_case`. I have YCM and vim-abolish installed. Let's say I have the following source file: ``` dueDate = ... processDueDate(dueDate); ``` * With `vim-abolish` I can press `crs` on **every** word to change them to snake cas...
You'll have to reverse engineer the internal function used by Abolish and call it. It's quite likely one of the functions from the autoload plugin file that is part of abolish. In the case of my [lh-style plugin](https://lh-style.readthedocs.io/en/latest/index.html) (which provides a feature similar to abolish, but wh...
31,120
<p>This top line shows how it needs to be formatted, and the other 3 lines show how it currently is formatted. I need the bottom three lines to look like the top line.</p> <p>So, I need to essentially cut this part <code>XJ.LN34..BHE.M.</code> and place it right before this part <code>SAC</code> at the end of the line....
[ { "answer_id": 31123, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 1, "selected": false, "text": "<p>Vim has quite a few commands to repeat actions. For your particular situation, I'd recommend using <a href=\"https...
2021/04/28
[ "https://vi.stackexchange.com/questions/31120", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34835/" ]
This top line shows how it needs to be formatted, and the other 3 lines show how it currently is formatted. I need the bottom three lines to look like the top line. So, I need to essentially cut this part `XJ.LN34..BHE.M.` and place it right before this part `SAC` at the end of the line. But each line will have differ...
If the task is to move 15 characters after the leading `SAC/` to immediately before the `.SAC` at the end of the line I would use a substitute command: ``` :%s/^\(SAC\/\)\(.*\{15\}\)\(.*\)\(\.SAC\)$/\1\3\2\4/ ``` The search pattern captures the leading `SAC/`, 15 random characters, the following characters up to the...
31,135
<p>Between</p> <ul> <li><code>:%!</code></li> <li><code>exe &quot;!...&quot;</code></li> <li><code>exe &quot;!bash -c&quot; shellescape(...)</code></li> </ul> <p>I'm getting quite confused as to what exactly Vim invokes. And I suspect at some point it invokes <code>bash -c bash ...</code>. Is there a way to see exactly...
[ { "answer_id": 31136, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 4, "selected": true, "text": "<p>When you use <code>!</code> or <code>:!</code> Vim builds the invoking command based on whatever is specified in the v...
2021/04/30
[ "https://vi.stackexchange.com/questions/31135", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30091/" ]
Between * `:%!` * `exe "!..."` * `exe "!bash -c" shellescape(...)` I'm getting quite confused as to what exactly Vim invokes. And I suspect at some point it invokes `bash -c bash ...`. Is there a way to see exactly what shell command is being called out? Does Vim ever invoke directly the command after `!`, or does it...
When you use `!` or `:!` Vim builds the invoking command based on whatever is specified in the various `'shell...'` settings (i.e. `'shell'`, `'shellcmdflag'`, `'shellquote'`, to name three). On Unix systems the defaults for the first two are usually the default shell (`$SHELL`) and `-c` so if I'm using Bash and I do `...
31,139
<p>When you first open vim there is a text that says &quot;VIM - Vi IMproved version......&quot; Is there a file or setting you can use to change this default text? I've looked on the internet and here and couldn't find anything mentioning it.</p>
[ { "answer_id": 31140, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p>Negative</p>\n<p>...unless you compile Vim yourself, that is.</p>\n<p>The version numbers are in src/version.h. Excerp...
2021/04/30
[ "https://vi.stackexchange.com/questions/31139", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34864/" ]
When you first open vim there is a text that says "VIM - Vi IMproved version......" Is there a file or setting you can use to change this default text? I've looked on the internet and here and couldn't find anything mentioning it.
Negative ...unless you compile Vim yourself, that is. The version numbers are in src/version.h. Excerpts ... ``` #define VIM_VERSION_MAJOR 8 #define VIM_VERSION_MINOR 2 ``` ``` #define VIM_VERSION_SHORT VIM_VERSION_MAJOR_STR "." VIM_VERSION_MINOR_STR #define VIM_VERSION_MEDIUM VIM_VERSION_SHORT ...
31,184
<p>I want some <code>autocmd</code>s to run when I open a file without a filetype like <code>nvim</code> (no file name) or <code>nvim myfile</code> (no extension). I also want them to run when opening certain file types like <code>text</code> and <code>markdown</code> so I can't blacklist everything with a file type/ex...
[ { "answer_id": 31185, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 1, "selected": false, "text": "<p>You can use the value of <code>&amp;filetype</code> to determine if you are in a buffer without a filetype or with one o...
2021/05/04
[ "https://vi.stackexchange.com/questions/31184", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25859/" ]
I want some `autocmd`s to run when I open a file without a filetype like `nvim` (no file name) or `nvim myfile` (no extension). I also want them to run when opening certain file types like `text` and `markdown` so I can't blacklist everything with a file type/extension. Is there a way to run certain `autocmd`s when no ...
The most accurate and compliant way is to extend filetypes with `after/ftplugin/{text,markdown}.vim`. Your "no extension" files can probably be detected as "text" filetype as well (or create a completely new filetype if you like). Then the actual functionality should be shared by a common autoloaded script. But if you...
31,189
<p>How can I get the current cursor position in Lua? I want to get a number so that I can use it in a for-loop.</p> <p>I tried this, but I got a hashed value instead:</p> <pre class="lang-lua prettyprint-override"><code>local lineNum = vim.api.nvim_win_get_cursor(0) print(lineNum) </code></pre> <p>The value I got:</p> ...
[ { "answer_id": 31190, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 4, "selected": true, "text": "<p>You get a hashed value because <code>nvim_win_get_cursor()</code> returns a tuple <code>(row, col)</code>. You can show t...
2021/05/04
[ "https://vi.stackexchange.com/questions/31189", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34675/" ]
How can I get the current cursor position in Lua? I want to get a number so that I can use it in a for-loop. I tried this, but I got a hashed value instead: ```lua local lineNum = vim.api.nvim_win_get_cursor(0) print(lineNum) ``` The value I got: ```lua table: 0x010134d4e8 ``` How can I get the value I need?
You get a hashed value because `nvim_win_get_cursor()` returns a tuple `(row, col)`. You can show the value with: ``` print(unpack(lineNum)) ``` You can also get the row and column in two variables with this: ``` local r,c = unpack(vim.api.nvim_win_get_cursor(0)) print(r, c) ``` You might be interested in [this S...
31,207
<p>Using <code>vim</code>, I know that I can replace all occurrences of a string across multiple lines by specifying a <em>count</em> or a <em>range</em>, as documented in <code>:h subst</code>.</p> <p>I have a markdown table which contains C function prototypes, as well as English prose. I would like to replace, for e...
[ { "answer_id": 31208, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p>Taking a straight programmatic approach, we can simply implement this as a <code>for</code> loop:</p>\n<pre><code>:for...
2021/05/05
[ "https://vi.stackexchange.com/questions/31207", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6216/" ]
Using `vim`, I know that I can replace all occurrences of a string across multiple lines by specifying a *count* or a *range*, as documented in `:h subst`. I have a markdown table which contains C function prototypes, as well as English prose. I would like to replace, for example, the word 'float', but only the first ...
Taking a straight programmatic approach, we can simply implement this as a `for` loop: ``` :for x in range(3) | :%s/float/long double/ | endfor ``` **Update:** @PeterRincker offers this user command that you can wrap around the above for easy invocation: ``` command! -count=1 -nargs=+ -complete=command Times for _ ...
31,221
<p>My <code>.vimrc</code> has,</p> <pre><code>autocmd FileType rust autocmd BufWritePre &lt;buffer&gt; call LanguageClient#textDocument_formatting_sync() </code></pre> <p>This works great, unless my LanguageClient crashes. Then I can't write the buffer. Is there an easy method to write a file and skip the autocmd, you...
[ { "answer_id": 31222, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 4, "selected": true, "text": "<p>Generally speaking, that's exactly what the <a href=\"https://vimhelp.org/autocmd.txt.html#:noautocmd\" rel=\"noreferr...
2021/05/07
[ "https://vi.stackexchange.com/questions/31221", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5078/" ]
My `.vimrc` has, ``` autocmd FileType rust autocmd BufWritePre <buffer> call LanguageClient#textDocument_formatting_sync() ``` This works great, unless my LanguageClient crashes. Then I can't write the buffer. Is there an easy method to write a file and skip the autocmd, you'd think `:w!` but alas, even that is blo...
Generally speaking, that's exactly what the [`:noautocmd`](https://vimhelp.org/autocmd.txt.html#:noautocmd) *command modifier* is for. Just prefix your command with that and all autocommands should be disabled for just the run of that command. ``` :noautocmd w ``` Of course, this is the scorched earth approach. If t...
31,249
<p>I have many entities in my java project like this:</p> <pre><code>public class MyCar { // The brand of the car private String brand; // The time owner bought it private Date obtainTime; // The price in dollar private Double price; } </code></pre> <p>Now I want to replace them with this format:</p> <pre><code>public ...
[ { "answer_id": 31250, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 0, "selected": false, "text": "<p><em>filbranden asks some good questions but since I've already got this ready we can use it as a jump off point. Hope...
2021/05/12
[ "https://vi.stackexchange.com/questions/31249", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/35050/" ]
I have many entities in my java project like this: ``` public class MyCar { // The brand of the car private String brand; // The time owner bought it private Date obtainTime; // The price in dollar private Double price; } ``` Now I want to replace them with this format: ``` public class MyCar { @ApiModelProperty("T...
You have a couple of good answers here already, but the fact that both solutions use the shell implies that you can't do this from inside Vim, which isn't true! Here are two possible Vim-native solutions: Use [vimgrep](https://vimhelp.org/quickfix.txt.html#%3Avimgrep) ==================================================...
31,273
<p>I have huge file and quite slow <a href="https://github.com/jceb/vim-orgmode" rel="nofollow noreferrer">plugin</a> (loaded by <a href="https://github.com/junegunn/vim-plug" rel="nofollow noreferrer">vim-plug</a>) for corresponding filetype. I want following:</p> <ol> <li>Plugin is loaded by default</li> <li>Option t...
[ { "answer_id": 31275, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 1, "selected": false, "text": "<ol>\n<li>Remove the plugin. Seriously. &quot;Huge and slow&quot; = &quot;trash bin&quot;. If you're brave enough then go a...
2021/05/13
[ "https://vi.stackexchange.com/questions/31273", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/5182/" ]
I have huge file and quite slow [plugin](https://github.com/jceb/vim-orgmode) (loaded by [vim-plug](https://github.com/junegunn/vim-plug)) for corresponding filetype. I want following: 1. Plugin is loaded by default 2. Option to fast open this file without loading plugin. Something like: turn all plugins off, load buf...
Most “core” filetype features are covered by autocommands, so disabling them will have the effect that you want. But we only want to disable them when opening a particular file, so ``` :noautocmd edit {file} ```
31,309
<p>I tried to set a keyboard shortcut for <code>:noh</code> using space key, without success:</p> <p>.vimrc</p> <pre class="lang-bash prettyprint-override"><code>nnoremap ,&lt;space&gt; :noh&lt;CR&gt; </code></pre> <p>Expected behaviour:</p> <ul> <li>/ to highight text</li> <li>press space: clear highlighting</li> </ul...
[ { "answer_id": 31312, "author": "mattb", "author_id": 31858, "author_profile": "https://vi.stackexchange.com/users/31858", "pm_score": 1, "selected": false, "text": "<p>With this you could toggle the highlights:</p>\n<pre><code>&quot; toggle highlighted searches\nnnoremap &lt;silent&gt;&...
2021/05/18
[ "https://vi.stackexchange.com/questions/31309", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/31069/" ]
I tried to set a keyboard shortcut for `:noh` using space key, without success: .vimrc ```bash nnoremap ,<space> :noh<CR> ``` Expected behaviour: * / to highight text * press space: clear highlighting What would be the right way to do it?
According to `:help :map` (and maybe `:help macro`?), the keys after a `:map` command and it’s modifiers (none of which is a comma) are the mapped sequence—type those to produce the right hand-side (with some exceptions). From the comments, you’re pressing space instead of comma-space. That’s why the mapping isn’t bei...
31,343
<p>We have rather complex file structure and I would like simplify opening file independently where am I in the filesystem at the moment.</p> <p>Let's say we have a <code>project_folder</code> and several files in it:</p> <pre><code> /project_folder/common-prefix/foo.txt /project_folder/common-prefix/bar.txt /proj...
[ { "answer_id": 31364, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 1, "selected": false, "text": "<p>Try to play with <code>BufNewFile</code>:</p>\n<pre><code>augroup test_prefix | au!\n au BufNewFile common_prefix/...
2021/05/21
[ "https://vi.stackexchange.com/questions/31343", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/14850/" ]
We have rather complex file structure and I would like simplify opening file independently where am I in the filesystem at the moment. Let's say we have a `project_folder` and several files in it: ``` /project_folder/common-prefix/foo.txt /project_folder/common-prefix/bar.txt /project_folder/common-prefix/neste...
Try to play with `BufNewFile`: ``` augroup test_prefix | au! au BufNewFile common_prefix/* :e <afile>:t augroup END ``` In the example above, if you are in `..../common_prefix/` directory and do `vim text.txt` or `vim common_prefix/test.txt` you will end up editing `test.txt` in the current directory.
31,366
<p>I need to manipulate the dot command without directly editing the buffer for a plugin I'm developing.</p> <p>The plugin needs to manually append text to the dot command that will be executed while in insert mode.</p> <p>I would like to have as little side effects as possible.</p> <p>Is this possible?</p>
[ { "answer_id": 31364, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 1, "selected": false, "text": "<p>Try to play with <code>BufNewFile</code>:</p>\n<pre><code>augroup test_prefix | au!\n au BufNewFile common_prefix/...
2021/05/24
[ "https://vi.stackexchange.com/questions/31366", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8366/" ]
I need to manipulate the dot command without directly editing the buffer for a plugin I'm developing. The plugin needs to manually append text to the dot command that will be executed while in insert mode. I would like to have as little side effects as possible. Is this possible?
Try to play with `BufNewFile`: ``` augroup test_prefix | au! au BufNewFile common_prefix/* :e <afile>:t augroup END ``` In the example above, if you are in `..../common_prefix/` directory and do `vim text.txt` or `vim common_prefix/test.txt` you will end up editing `test.txt` in the current directory.
31,378
<p>I repeatedly have the following situation, and wonder how it can be handled better than I do it now. These lines must be merged</p> <pre><code>/path;text /path;text /path;text </code></pre> <p>with these:</p> <pre><code>/subdir /longsubdir /longlongsubdir </code></pre> <p>Desired result:</p> <pre><code>/path/subdir;...
[ { "answer_id": 31402, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 1, "selected": false, "text": "<p>Not sure if you can avoid extra blanks...</p>\n<p>I would do it this way:</p>\n<ol>\n<li>select <code>/subdir/</code>...
2021/05/26
[ "https://vi.stackexchange.com/questions/31378", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/35274/" ]
I repeatedly have the following situation, and wonder how it can be handled better than I do it now. These lines must be merged ``` /path;text /path;text /path;text ``` with these: ``` /subdir /longsubdir /longlongsubdir ``` Desired result: ``` /path/subdir;text /path/longsubdir;text /path/longlongsubdir;text `...
With the latest Vim version [8.2.2914](https://github.com/vim/vim/releases/tag/v8.2.2914), you can now simply paste without adding padding using the `zp` command.
31,383
<p>Im very new to vim scripting. I have the following script in my .vimrc:</p> <ul> <li>If there is no user input aka I press <code>&lt;CR&gt;</code> =&gt; go to recent buffer</li> <li>If input is 'd' =&gt; delete all buffers except for the current one</li> <li>Else go to inputted buffer.</li> </ul> <pre><code>&quot;Fa...
[ { "answer_id": 31384, "author": "prizel", "author_id": 35293, "author_profile": "https://vi.stackexchange.com/users/35293", "pm_score": 1, "selected": false, "text": "<p>I ended up writing this little script:</p>\n<pre><code>&quot; --Warp: fast buffer switch\nfunction Warp(...)\n let bu...
2021/05/26
[ "https://vi.stackexchange.com/questions/31383", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/35293/" ]
Im very new to vim scripting. I have the following script in my .vimrc: * If there is no user input aka I press `<CR>` => go to recent buffer * If input is 'd' => delete all buffers except for the current one * Else go to inputted buffer. ``` "Fast buffer switch function Warp() ls call inputsave() let bufname =...
A simple fix is to use the third argument of `input`, which is a `{completion}` type (list at `:help :command-completion`): ``` … const bufname = input('warp: ', '', 'buffer') … ``` (I used `const` instead of `let`, too.)
31,387
<p>If I'm in command-line mode in vim, and I have the current command line entered (cursor position shown with <code>|</code>):</p> <pre><code>:somecommand somefilename.txt| </code></pre> <p>I'd like to navigate backwards so that the cursor is behind the <code>.</code>:</p> <pre><code>:somecommand somefilename|.txt </c...
[ { "answer_id": 31389, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 2, "selected": false, "text": "<p>I don't think there is a built-in way to do it with bare cmdline accroding to <code>:h cmdline.txt</code>.</p>\n<p>Bu...
2021/05/26
[ "https://vi.stackexchange.com/questions/31387", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/91/" ]
If I'm in command-line mode in vim, and I have the current command line entered (cursor position shown with `|`): ``` :somecommand somefilename.txt| ``` I'd like to navigate backwards so that the cursor is behind the `.`: ``` :somecommand somefilename|.txt ``` Is there a way I can do this with a single command? I...
Since you don't mind a mapping, we can use ``` cnoremap <S-Left> <C-f>bb<C-c> ``` This remaps `<S-Left>` to the behavior you described, using `<C-f>` to switch to edit the command line in normal mode. `<C-c>` then switches back to command line mode. For details, refer to `:h cmdline-window`
31,396
<p>Say I have a document</p> <pre><code>cat dog xxx 1 2 3 cow xxx a b c horse </code></pre> <p>I would like to be able to run a command that will end up with</p> <pre><code>xxx 1 2 3 xxx a b c </code></pre> <p>whereby the transformation is defined by matching all lines with <code>xxx</code> and preserving those lines a...
[ { "answer_id": 31397, "author": "bradgonesurfing", "author_id": 35315, "author_profile": "https://vi.stackexchange.com/users/35315", "pm_score": 3, "selected": true, "text": "<p>First clear the register <em>x</em> using normal mode</p>\n<pre><code>qxq\n</code></pre>\n<p>then delete the m...
2021/05/27
[ "https://vi.stackexchange.com/questions/31396", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/35315/" ]
Say I have a document ``` cat dog xxx 1 2 3 cow xxx a b c horse ``` I would like to be able to run a command that will end up with ``` xxx 1 2 3 xxx a b c ``` whereby the transformation is defined by matching all lines with `xxx` and preserving those lines and the three lines under them but delete everything else...
First clear the register *x* using normal mode ``` qxq ``` then delete the matched lines and 3 below it using append into register *x*. ``` :g/^xxx/d X 4 ``` then erase the whole buffer ``` :%d ``` then paste *x* back into the buffer ``` "xP ```
31,403
<p>Say we have the following code:</p> <pre><code>Lorem ipsum. &lt;input name=&quot;test1&quot;&gt; &lt;input name=&quot;test2&quot;&gt; Lorem ipsum some long text possibly so long you lose your overview. &lt;input name=&quot;test3&quot;&gt; Lorem ipsum. </code></pre> <p>Now when I do</p> <pre><code>g/name=&quot;[^&quo...
[ { "answer_id": 31449, "author": "Kaz", "author_id": 13611, "author_profile": "https://vi.stackexchange.com/users/13611", "pm_score": 0, "selected": false, "text": "<p>Be on a system with GNU Grep installed, then do:</p>\n<pre><code>:w !grep -o 'pattern'\n</code></pre>\n<p>The space betwe...
2021/05/28
[ "https://vi.stackexchange.com/questions/31403", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/33033/" ]
Say we have the following code: ``` Lorem ipsum. <input name="test1"> <input name="test2"> Lorem ipsum some long text possibly so long you lose your overview. <input name="test3"> Lorem ipsum. ``` Now when I do ``` g/name="[^"]*"/p ``` the output will be: ``` <input name="test1"> <input name="test2"> Lorem ipsum...
Another approach is to use the following command: ``` g/name="[^"]*"/echo matchstr(getline('.'), @/) ```
31,415
<p>Fast way to type or change to <a href="https://en.wikipedia.org/wiki/Alternating_caps" rel="nofollow noreferrer"><em>AlTeRnAtInG CaPs</em></a>?</p>
[ { "answer_id": 31449, "author": "Kaz", "author_id": 13611, "author_profile": "https://vi.stackexchange.com/users/13611", "pm_score": 0, "selected": false, "text": "<p>Be on a system with GNU Grep installed, then do:</p>\n<pre><code>:w !grep -o 'pattern'\n</code></pre>\n<p>The space betwe...
2021/05/29
[ "https://vi.stackexchange.com/questions/31415", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/33130/" ]
Fast way to type or change to [*AlTeRnAtInG CaPs*](https://en.wikipedia.org/wiki/Alternating_caps)?
Another approach is to use the following command: ``` g/name="[^"]*"/echo matchstr(getline('.'), @/) ```
31,440
<p>When Vim is invoked on multiple files from the command line, then if any of those files have not been visited with <code>:next</code> or via buffer switching, the <code>:q</code> command pointlessly warns about the situation with a message like &quot;43 files left to edit&quot; and refuses to quit, even though nothi...
[ { "answer_id": 31441, "author": "Kaz", "author_id": 13611, "author_profile": "https://vi.stackexchange.com/users/13611", "pm_score": 0, "selected": false, "text": "<p>The <code>:qa</code> command does what I want.</p>\n<p>By itself, that would not be an acceptable solution; however, it's...
2021/05/31
[ "https://vi.stackexchange.com/questions/31440", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13611/" ]
When Vim is invoked on multiple files from the command line, then if any of those files have not been visited with `:next` or via buffer switching, the `:q` command pointlessly warns about the situation with a message like "43 files left to edit" and refuses to quit, even though nothing has been modified. Is there a wa...
The `:cabbrev`-answer has downsides because the abbreviation is active everywhere in the `:` command line, even if restricted to that type of command using the `<expr>` mechanism. Ideally, Vim would have a command execution hook: a piece of code that could be executed each time a command is run, or at least an interac...
31,444
<p>I'm trying to get vim to do code folding with my python code and I could really use your help with the last bit here.</p> <p>I have this in my <code>~/.vimrc</code>:</p> <pre><code>set number &quot;set tabstop=2 &quot;set expandtab &quot;set sw=2 set nowrap syntax on set linebreak set textwidth=80 set background=dar...
[ { "answer_id": 31445, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 1, "selected": false, "text": "<p><strong>EDIT</strong> You also need to add the following line to your vimrc:</p>\n<pre><code>filetype plugin indent on\n...
2021/06/01
[ "https://vi.stackexchange.com/questions/31444", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/35384/" ]
I'm trying to get vim to do code folding with my python code and I could really use your help with the last bit here. I have this in my `~/.vimrc`: ``` set number "set tabstop=2 "set expandtab "set sw=2 set nowrap syntax on set linebreak set textwidth=80 set background=dark " Enable folding set foldmethod=indent set...
**EDIT** You also need to add the following line to your vimrc: ``` filetype plugin indent on ``` See [`:h :filetype-plugin-on`](http://vimhelp.appspot.com/filetype.txt.html#%3Afiletype-plugin-on) and [`:h :filetype-indent-on`](http://vimhelp.appspot.com/filetype.txt.html#%3Afiletype-indent-on) this command enable t...
31,450
<p>I want to use Ultisnips and get the following error:</p> <pre><code>E319: Sorry, the command is not available in this version: py3 import vim Press ENTER or type command to continue Error detected while processing /Users/Me/.vim/plugged/ultisnips/autoload/UltiSnips.vim: line 8: E319: Sorry, the command is not ava...
[ { "answer_id": 31458, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 1, "selected": false, "text": "<p>It looks like there's some issue with your Homebrew setup or with the Vim build in your Homebrew.</p>\n<p>When you...
2021/06/01
[ "https://vi.stackexchange.com/questions/31450", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/35391/" ]
I want to use Ultisnips and get the following error: ``` E319: Sorry, the command is not available in this version: py3 import vim Press ENTER or type command to continue Error detected while processing /Users/Me/.vim/plugged/ultisnips/autoload/UltiSnips.vim: line 8: E319: Sorry, the command is not available in thi...
It looks like there's some issue with your Homebrew setup or with the Vim build in your Homebrew. When you type `which vim` does it show you `/usr/local/bin/vim`? That's the one from Homebrew. If it doesn't and lists `/usr/bin/vim` instead, does `echo $PATH` list `/usr/local/bin` somewhere at the start? If you try `/...
31,451
<p>Error:</p> <pre><code>Error detected while processing BufWinEnter Autocommands for &quot;*&quot;..function &lt;SNR&gt;3_LocalVimRC[322]..BufWinEnter Autocommands for &quot;*&quot;..function &lt;SNR&gt;3_LocalVimRC: line 263: E654: missing delimiter after search pattern: Vim\%((\a\+)\)\=:E48 </code></pre> <p>I've re...
[ { "answer_id": 31459, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 2, "selected": false, "text": "<p>Looks like your <code>~/.vim/plugin/localvimrc.vim</code> is an older version (pre v3.1.0) of the <a href=\"https:...
2021/06/01
[ "https://vi.stackexchange.com/questions/31451", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/20308/" ]
Error: ``` Error detected while processing BufWinEnter Autocommands for "*"..function <SNR>3_LocalVimRC[322]..BufWinEnter Autocommands for "*"..function <SNR>3_LocalVimRC: line 263: E654: missing delimiter after search pattern: Vim\%((\a\+)\)\=:E48 ``` I've re-installed vim using `brew install vim` and I've moved a...
Filbranden helped me realize that the context of my question did not make sense. The file couldn't have been auto-generated. I purged that folder properly and reinstalled everything, and now vim works. So if anyone is having weird issues with vim, purging everything and re-installing it, may solve your problem, as it ...
31,478
<p>I am trying to get the value of <code>iskeyword</code> as character. When I run <code>set iskeyword?</code>, I get <code>iskeyword=@,48-57,_,192-255</code>. Using <code>48-57</code> as an example, how can I turn them back to characters? Is there any helper function in vim or lua that can help me do that?</p>
[ { "answer_id": 31479, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p>You can use the <a href=\"https://vimhelp.org/eval.txt.html#nr2char()\" rel=\"nofollow noreferrer\"><code>nr2char()</c...
2021/06/05
[ "https://vi.stackexchange.com/questions/31478", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34675/" ]
I am trying to get the value of `iskeyword` as character. When I run `set iskeyword?`, I get `iskeyword=@,48-57,_,192-255`. Using `48-57` as an example, how can I turn them back to characters? Is there any helper function in vim or lua that can help me do that?
You can use the [`nr2char()`](https://vimhelp.org/eval.txt.html#nr2char()) function: ``` echo nr2char(48) ``` This will display the character for the number zero, '0'. To print that first range using Vimscript you could, for example, do something like: ``` for i in range(48, 57) echo nr2char(i) endfor ``` Tha...
31,491
<p>Currently when I open a file (NerdTree appears automatically as well), the light line status line plugin I installed does not show up right away. It only shows up after I switch tabs into NerdTree and then back to the file I have open. The first picture is what the file I open looks like right away, the second is af...
[ { "answer_id": 31539, "author": "TornaxO7", "author_id": 31844, "author_profile": "https://vi.stackexchange.com/users/31844", "pm_score": 0, "selected": false, "text": "<p>You need to set the option <code>laststatus</code> to <code>2</code> as explained in the help page of lightline:</p>...
2021/06/06
[ "https://vi.stackexchange.com/questions/31491", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/36452/" ]
Currently when I open a file (NerdTree appears automatically as well), the light line status line plugin I installed does not show up right away. It only shows up after I switch tabs into NerdTree and then back to the file I have open. The first picture is what the file I open looks like right away, the second is after...
I too had encountered a similar problem. In my case, there was a missing (external) executable, leading to an error in Vim on startup, thus preventing lightline from loading correctly. I found that switching windows and opening a new split 'fixed' the issue, ie. adding/moving between splits resulted in lightline updat...
31,518
<p>I might have some text like the following:</p> <pre><code>&lt;foo&gt;something very important&lt;/foo&gt; 1 2 ^ 3 4 </code></pre> <p>If the cursor is inside the tag, for example on the <code>m</code> character, what is the simplest way to jump to the beginning of the tag (1)?</p> <p>It seem...
[ { "answer_id": 31520, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 2, "selected": false, "text": "<p>As suggested in <a href=\"https://vi.stackexchange.com/a/22573/18609\">an answer by @Rich to a related question</a...
2021/06/09
[ "https://vi.stackexchange.com/questions/31518", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11635/" ]
I might have some text like the following: ``` <foo>something very important</foo> 1 2 ^ 3 4 ``` If the cursor is inside the tag, for example on the `m` character, what is the simplest way to jump to the beginning of the tag (1)? It seems like this action should be simple, but I can't figu...
@filbranden's answer is helpful and shows how to build the solution. It demonstrates how the result would need 4 key strokes to be able to get to any of positions 1 - 4. 4 key strokes seems like a minimum with this approach. I'd prefer not to reinvent tools, and it appears to me that if `t` `T` `f` and `F` could wrap ...
31,524
<p>I have a shared <code>.vimrc</code> that I use across platforms. It works fine in most circumstances, but looks terrible when I run <code>git commit</code> from the command line. I want to make my color scheme not load when run in that circumstance, but the conventional test for windows <code>has(&quot;win32&quot;)<...
[ { "answer_id": 31535, "author": "tboz203", "author_id": 36537, "author_profile": "https://vi.stackexchange.com/users/36537", "pm_score": 2, "selected": false, "text": "<p>EDIT: user <a href=\"https://vi.stackexchange.com/users/71/christian-brabandt\">Christian Brabandt</a> points out tha...
2021/06/09
[ "https://vi.stackexchange.com/questions/31524", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/29272/" ]
I have a shared `.vimrc` that I use across platforms. It works fine in most circumstances, but looks terrible when I run `git commit` from the command line. I want to make my color scheme not load when run in that circumstance, but the conventional test for windows `has("win32")` fails in that environment! In fact, `ha...
EDIT: user [Christian Brabandt](https://vi.stackexchange.com/users/71/christian-brabandt) points out that `v:progpath` will still only contain `/usr/bin/vim` when invoked through git-for-windows, so this solution will not work. --- Maybe something along these lines? ``` if v:progpath =~ "git" colorscheme default...
31,530
<p>If I have two 'sets' of lines, each consisting of X number of lines (but the lines differing in their individual lengths), can I yank one set and insert (or append) it to the other?</p> <p>To illustrate, can one yank the lines of 'Set 2' and somehow put them in front of the lines in 'Set 1', to achieve 'Result' (or ...
[ { "answer_id": 31531, "author": "Chris", "author_id": 30981, "author_profile": "https://vi.stackexchange.com/users/30981", "pm_score": 1, "selected": false, "text": "<p>To get to 'Result' with 'Set 1' and 'Set 2', it isn't just pretty key strokes. That said, I suspect it could be by usi...
2021/06/09
[ "https://vi.stackexchange.com/questions/31530", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/30981/" ]
If I have two 'sets' of lines, each consisting of X number of lines (but the lines differing in their individual lengths), can I yank one set and insert (or append) it to the other? To illustrate, can one yank the lines of 'Set 2' and somehow put them in front of the lines in 'Set 1', to achieve 'Result' (or even bett...
If you are okay with a relative recent Vim, you can do it the following way: 1. Add spaces in front of your first block/set. Position your cursor on the beginning of the first line (at the `o` of `of lines`). So type: * `Ctrl`-`V`, `2`, `j` (to visually select the beginning of the block) * `I` (you should be in ins...
31,576
<p>I have a shell script on a line alone in a file which I would like to be able to easily execute from vim. Normally I could simply use <code>Y:!^R&quot;</code>, but this particular script has <code>%</code> in it, which is expanded to the current filename.</p> <ul> <li><code>Y:exe '!'.@&quot;</code> still treats <cod...
[ { "answer_id": 31577, "author": "Iiridayn", "author_id": 8846, "author_profile": "https://vi.stackexchange.com/users/8846", "pm_score": 1, "selected": false, "text": "<p>Possible answer derived from <a href=\"https://vi.stackexchange.com/a/10211/8846\">https://vi.stackexchange.com/a/1021...
2021/06/15
[ "https://vi.stackexchange.com/questions/31576", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8846/" ]
I have a shell script on a line alone in a file which I would like to be able to easily execute from vim. Normally I could simply use `Y:!^R"`, but this particular script has `%` in it, which is expanded to the current filename. * `Y:exe '!'.@"` still treats `%` as a filename * `Y:!`=getreg('"')` is passed literally ...
One way to do this is to use `fnameescape`: ``` Y:!<C-r>=fnameescape(@")<CR> ``` But it may not be perfect if the command has spaces. You could also try `split(@")->map('fnameescape(v:val)')->join(' ')` in the expression, or some combination of `shellescape()`/`escape(…, '%#')`, etc.
31,635
<p>From the <code>:execute</code> help (<code>:h :exe</code>):</p> <pre><code> *:exe* *:execute* :exe[cute] {expr1} .. Executes the string that results from the evaluation of {expr1} as an Ex command. Multiple arguments are concatenated, with a space in b...
[ { "answer_id": 31636, "author": "Zoe stands with Ukraine", "author_id": 21251, "author_profile": "https://vi.stackexchange.com/users/21251", "pm_score": 3, "selected": false, "text": "<p>Take note of the examples:</p>\n<blockquote>\n<pre><code>:execute &quot;buffer&quot; nextbuf\n:execut...
2021/06/22
[ "https://vi.stackexchange.com/questions/31635", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/35271/" ]
From the `:execute` help (`:h :exe`): ``` *:exe* *:execute* :exe[cute] {expr1} .. Executes the string that results from the evaluation of {expr1} as an Ex command. Multiple arguments are concatenated, with a space in between. To avoid the extra space u...
Take note of the examples: > > > ``` > :execute "buffer" nextbuf > :execute "normal" count .. "w" > > ``` > > What it's indirectly saying is, to avoid a space in the resulting string that's executed, use `..` instead of no operator at all. When there's no operator at all, each string or potentially variable is c...
31,656
<p>I'm trying to make a vmap that takes a count and then indents all the highlighted lines so that the top one is more than the line above it, while keeping all the lines' relative indentation. I have made it to this function and I'm experiencing some behaviour I don't know how to figure out. For some reason, this fun...
[ { "answer_id": 31663, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 0, "selected": false, "text": "<p>By default, a function called in visual mode is effectively once for every line in your range.</p>\n<p>To get the behavi...
2021/06/24
[ "https://vi.stackexchange.com/questions/31656", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/24943/" ]
I'm trying to make a vmap that takes a count and then indents all the highlighted lines so that the top one is more than the line above it, while keeping all the lines' relative indentation. I have made it to this function and I'm experiencing some behaviour I don't know how to figure out. For some reason, this functio...
The problem is with the code `indent("'<")`. After your first execution, that value changes, causing the indentation of everything afterwards to not change. It can be fixed by setting it's value to a variable before you start the loop.
31,657
<p>With vi: I have a file with hundreds of these type of lines below.</p> <pre><code>icpu_subsystem/i_v_top/i_jpeg_unit/ijpeg_dp/dp_p_rf_64x14_C_goal/U833462/A2 \ icpu_subsystem/i_v_top_ebd/i_jpeg_unit/ijpeg_dp/U121/A \ icpu_subsystem/i_v_top_eee/i_jpeg_unit/ijpeg_dp/U121/S \ </code></pre> <p>I want to get rid of the l...
[ { "answer_id": 31663, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 0, "selected": false, "text": "<p>By default, a function called in visual mode is effectively once for every line in your range.</p>\n<p>To get the behavi...
2021/06/24
[ "https://vi.stackexchange.com/questions/31657", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/36755/" ]
With vi: I have a file with hundreds of these type of lines below. ``` icpu_subsystem/i_v_top/i_jpeg_unit/ijpeg_dp/dp_p_rf_64x14_C_goal/U833462/A2 \ icpu_subsystem/i_v_top_ebd/i_jpeg_unit/ijpeg_dp/U121/A \ icpu_subsystem/i_v_top_eee/i_jpeg_unit/ijpeg_dp/U121/S \ ``` I want to get rid of the last two directories in a...
The problem is with the code `indent("'<")`. After your first execution, that value changes, causing the indentation of everything afterwards to not change. It can be fixed by setting it's value to a variable before you start the loop.
31,694
<p>I am editing a LaTeX document and I wanted to figure out the most efficient way to convert <code>itemize</code> environment to <code>tabular</code> environment. Here is an example of what I want to accomplish:</p> <hr /> <p>Change</p> <pre><code>\begin{itemize}[leftmargin=*] \item some text 1 (some more text 1) ...
[ { "answer_id": 31695, "author": "Heptite", "author_id": 1311, "author_profile": "https://vi.stackexchange.com/users/1311", "pm_score": 0, "selected": false, "text": "<p>I would highlight the lines you need with <kbd>control</kbd><kbd>v</kbd> on the first line then <kbd>j</kbd> until all ...
2021/06/27
[ "https://vi.stackexchange.com/questions/31694", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/36810/" ]
I am editing a LaTeX document and I wanted to figure out the most efficient way to convert `itemize` environment to `tabular` environment. Here is an example of what I want to accomplish: --- Change ``` \begin{itemize}[leftmargin=*] \item some text 1 (some more text 1) \item some text 2 (some more text 2) ...
I like using a [macro recording](https://vimhelp.org/repeat.txt.html#recording) for this kind of task, since that allows me to use the Vim commands I know already to move and edit, rather than having to write (and debug!) regexps to accomplish the task. Using a macro recording, you can use the exact commands you'd use...
31,698
<p>I know there's a file called <code>handler.ts</code> in the same directory as the currently opened file <code>handler.test.ts</code>.</p> <p>How do I open that file in a split window (horizontal or vertical) without doing this:</p> <p><kbd>Ctrl</kbd>+<kbd>w</kbd> followed by <kbd>s</kbd>, then typing <code>:edit /fu...
[ { "answer_id": 31699, "author": "mattb", "author_id": 31858, "author_profile": "https://vi.stackexchange.com/users/31858", "pm_score": 3, "selected": true, "text": "<p>First off, you can use <code>:split</code> (or just <code>:sp</code>) instead of typing <code>:e</code> and then\nmanual...
2021/06/28
[ "https://vi.stackexchange.com/questions/31698", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/33692/" ]
I know there's a file called `handler.ts` in the same directory as the currently opened file `handler.test.ts`. How do I open that file in a split window (horizontal or vertical) without doing this: `Ctrl`+`w` followed by `s`, then typing `:edit /full/path/to/file` I'd also like to avoid typing the full path, if pos...
First off, you can use `:split` (or just `:sp`) instead of typing `:e` and then manually splitting. ### Using the % register You could do: ``` :split <press ctrl+r, then type a % sign> ``` This will paste from register `%` onto the command line. And since `%` contains the path to the current file, you'll get this:...
31,736
<p>I got this from <a href="https://gist.github.com/voyeg3r/223f148a115c17a02a15660cc7335f4c" rel="nofollow noreferrer">voyeg3r's gist</a> He and <a href="https://github.com/dave-kennedy" rel="nofollow noreferrer">@dave-kennedy</a> made it 3 years ago. I am here because I couldn't contact them</p> <p>Can someone help m...
[ { "answer_id": 31740, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 1, "selected": false, "text": "<p>I think you need to change</p>\n<pre><code> &quot; Comment the line\n execute 'silent s/\...
2021/07/03
[ "https://vi.stackexchange.com/questions/31736", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/36876/" ]
I got this from [voyeg3r's gist](https://gist.github.com/voyeg3r/223f148a115c17a02a15660cc7335f4c) He and [@dave-kennedy](https://github.com/dave-kennedy) made it 3 years ago. I am here because I couldn't contact them Can someone help me add a feature such that this vimscript code puts comment out signs at the first o...
I think you need to change ``` " Comment the line execute 'silent s/\v^(\s*)/\1' . comment_leader . ' /' ``` to ``` " Comment the line execute 'silent s/^/\1' . comment_leader . '/' ``` so that it substitutes at the beginning of the line rather than after any space....
31,737
<p>I am trying to retrieve the value of $MYVIMRC in my <code>init.lua</code> but I am coming up short because I don't understand what $MYVIMRC actually is.</p> <p>It is not a global variable, is it?</p> <p>None of these work:</p> <pre class="lang-lua prettyprint-override"><code>vim.g.$MYVIMRC vim.g.MYVIMRC vim.g.myvimr...
[ { "answer_id": 31738, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p><code>$MYVIMRC</code> is an <a href=\"http://vimhelp.org/eval.txt.html#expr-env\" rel=\"nofollow noreferrer\">environm...
2021/07/03
[ "https://vi.stackexchange.com/questions/31737", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11695/" ]
I am trying to retrieve the value of $MYVIMRC in my `init.lua` but I am coming up short because I don't understand what $MYVIMRC actually is. It is not a global variable, is it? None of these work: ```lua vim.g.$MYVIMRC vim.g.MYVIMRC vim.g.myvimrc ``` What is $MYVIMRC and how can I access it from Lua?
`$MYVIMRC` is an [environment variable](http://vimhelp.org/eval.txt.html#expr-env) that Vim adds to the current environment. Environment variables are usually inherited by child processes from their parent process. For example, you can see `$MYVIMRC` in a shell that is a child process of Vim: ``` :!printenv | grep MY...
31,749
<p>For the very first time I find myself in need for the <code>y</code> command Sed has.</p> <p>For those who don't know what <code>y</code> does, here's an example:</p> <pre class="lang-none prettyprint-override"><code>$ echo x1 x2 x3 | sed 'y/123/234/' x2 x3 x4 </code></pre> <p>Apparently Vim has no way of doing this...
[ { "answer_id": 31750, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 5, "selected": true, "text": "<p>Sure it does. In unix there's often a command equivalent to <code>sed y/X/x/</code> called <code>tr</code>. So...</p>\...
2021/07/05
[ "https://vi.stackexchange.com/questions/31749", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6498/" ]
For the very first time I find myself in need for the `y` command Sed has. For those who don't know what `y` does, here's an example: ```none $ echo x1 x2 x3 | sed 'y/123/234/' x2 x3 x4 ``` Apparently Vim has no way of doing this. Am I wrong?
Sure it does. In unix there's often a command equivalent to `sed y/X/x/` called `tr`. So... ``` echo "A1B2C3" | sed 'y/ABC/abc/' # prints "a1b2c3" ``` ...is equivalent to... ``` echo "A1B2C3" | tr 'ABC' 'abc' # also print "a1b2c3" ``` It happens that Vim has a function that is "exactly like the unix 'tr' comman...
31,751
<p>I've written a little function that changes a 'CamelCaseWord' to a space separated 'camel case word':</p> <pre><code>&quot; Convert a CamelCase word to space separated words. function! s:converFromCamelCase(arg1) let l:len = strlen(a:arg1) let l:i = 0 let l:retVal = &quot;&quot; while l:i &lt; l:len let ...
[ { "answer_id": 31752, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 2, "selected": false, "text": "<p>B Layer answer is on point, that is easier to reader and make use of the right built-in functions. I posted this answer ...
2021/07/05
[ "https://vi.stackexchange.com/questions/31751", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/36898/" ]
I've written a little function that changes a 'CamelCaseWord' to a space separated 'camel case word': ``` " Convert a CamelCase word to space separated words. function! s:converFromCamelCase(arg1) let l:len = strlen(a:arg1) let l:i = 0 let l:retVal = "" while l:i < l:len let l:c = strpart(a:arg1, l:i, 1) ...
That's a lot of code. ;) What if I said we could compact that whole thing down to a one-line command (and mapping)? Let's take it a step at a time, though. First, the substitution... ``` :s/\u/ \l&/g ``` ...will replace each capital letter in the current line with a space and the lower-cased letter. Same pattern/re...
31,779
<p>So I have a case where I have some unicode letters say <code>[B, Ḅ, Ḃ]</code> and when I have my mouse selected over the B, (in normal mode) I want some way of cycling through the list. Like pressing some command should replace <code>B</code> with <code>Ḅ</code>, pressing it again should replace <code>Ḅ</code> with ...
[ { "answer_id": 31781, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<p>At least for single characters, here's what I would do. First, let's build a little function for an expression ...
2021/07/07
[ "https://vi.stackexchange.com/questions/31779", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/22594/" ]
So I have a case where I have some unicode letters say `[B, Ḅ, Ḃ]` and when I have my mouse selected over the B, (in normal mode) I want some way of cycling through the list. Like pressing some command should replace `B` with `Ḅ`, pressing it again should replace `Ḅ` with `Ḃ`. --- I looked at this <https://github.com...
So I found a solution thanks to [How to add accent to letters in normal mode?](https://vi.stackexchange.com/questions/12988/how-to-add-accent-to-letters-in-normal-mode?rq=1) using `tr`. As stated in the comments a simple 3 cycle would be done by ``` tr(@", 'ABC', 'BCA') ``` Which cycles `A -> B -> C -> A`. Wrapped i...
31,790
<p>I have downloaded the vim-commentary plugin for commenting in vim. I was trying to remap the default shortcuts for the plugin so as to use <kbd>ctrl</kbd>+<kbd>/</kbd> for commenting and remove commenting (default is <code>gc</code>). I was also trying to create a map so that I can comment while being in insert mode...
[ { "answer_id": 31793, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 1, "selected": false, "text": "<p>You need the recursive version of map here: When you type <code>&lt;c-/&gt;</code> you want it to execute what vim-comme...
2021/07/08
[ "https://vi.stackexchange.com/questions/31790", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/36852/" ]
I have downloaded the vim-commentary plugin for commenting in vim. I was trying to remap the default shortcuts for the plugin so as to use `ctrl`+`/` for commenting and remove commenting (default is `gc`). I was also trying to create a map so that I can comment while being in insert mode. In my vimrc I wrote this: ``...
The commentary.vim plugin file uses the `<Plug>` notation for mapping. ``` xmap gc <Plug>Commentary nmap gc <Plug>Commentary omap gc <Plug>Commentary nmap gcc <Plug>CommentaryLine ``` The `xmap` mode is like `vmap`, but excludes Select mode (which is rarely used). `<Plug>Commentary` and `<Plug>Commentary...
31,811
<p>In a neovim <code>init.lua</code> config, I know that I can append to a string like so:</p> <pre class="lang-lua prettyprint-override"><code>vim.opt.wildignore:append(&quot;*/node_modules/*,*/vendor/*,*/venv/*,*/.venv/*,*/target/*&quot;) </code></pre> <p>However, I'm getting errors with the following attempts to app...
[ { "answer_id": 31817, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 2, "selected": false, "text": "<p>The <code>'listchars'</code> option is implemented as a Lua table (akin to a Dict in Vim, possibly more similar to...
2021/07/10
[ "https://vi.stackexchange.com/questions/31811", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25201/" ]
In a neovim `init.lua` config, I know that I can append to a string like so: ```lua vim.opt.wildignore:append("*/node_modules/*,*/vendor/*,*/venv/*,*/.venv/*,*/target/*") ``` However, I'm getting errors with the following attempts to append `extends:#` to the default value of `listchars`: ```lua vim.opt.listchars:a...
As of nvim 0.5.1, on MacOS and Linux, it appears that the `vim.opt.listchars:append` in my original question now works, and for some reason setting the map values as in `vim.opt.listchars.extends = "e"` or `vim.opt.listchars.tab = "t"` no longer works. ``` vim.opt.listchars:append({ extends = "#" }) print(vim.inspect(...
31,827
<p>While doing TDD I switch back and forth between windows often. I would like to reduce the number of keystrokes for this. I have tried both:</p> <pre><code>inoremap &lt;C-w&gt; &lt;ESC&gt;&lt;C-w&gt; </code></pre> <p>and</p> <pre><code>imap &lt;C-w&gt; &lt;ESC&gt;&lt;C-w&gt; </code></pre> <p>I was thinking with this ...
[ { "answer_id": 31828, "author": "Abdalrahman Ali", "author_id": 37012, "author_profile": "https://vi.stackexchange.com/users/37012", "pm_score": 2, "selected": false, "text": "<p>It should be:</p>\n<blockquote>\n<p>inoremap &lt;c-w&gt; &lt;esc&gt;&lt;c-w&gt;w</p>\n</blockquote>\n<p>becau...
2021/07/13
[ "https://vi.stackexchange.com/questions/31827", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/36997/" ]
While doing TDD I switch back and forth between windows often. I would like to reduce the number of keystrokes for this. I have tried both: ``` inoremap <C-w> <ESC><C-w> ``` and ``` imap <C-w> <ESC><C-w> ``` I was thinking with this mapping I could do `<C-w>h` and switch directly from the right window to the left...
It should be: > > inoremap <c-w> <esc><c-w>w > > > because <c-w>w is what switches windows
31,845
<blockquote> <p>The problem is solved</p> </blockquote> <blockquote> <p>My purpose is that: I use vim to edit my m-file and debug it in Matlab. There is no easy-to-use interface plugin between vim and Matlab in Win10. So I just edit m-file in vim and run it in Matlab. Sometimes these m-files may be in different directo...
[ { "answer_id": 31846, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>Since your command contains a dynamic element (IOW it's not made up entirely of static strings) you'll need to build ...
2021/07/16
[ "https://vi.stackexchange.com/questions/31845", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/37039/" ]
> > The problem is solved > > > > > My purpose is that: I use vim to edit my m-file and debug it in Matlab. There is no easy-to-use interface plugin between vim and Matlab in Win10. So I just edit m-file in vim and run it in Matlab. Sometimes these m-files may be in different directories, so this function can hel...
I use following to open directory where current file is and select it if possible: ``` "" Open explorer where current file is located "" Only for win for now. func! File_manager() abort " Windows only for now if has("win32") if exists("b:netrw_curdir") let path = substitute(b:netrw_curdir, ...
31,870
<p>I frequently use <code>EasyAlign</code> in my tex files to align tables around the <code>$</code> delimiter such that this</p> <pre><code>header1 &amp; header2 &amp; header3 \\ data1 &amp; data2 &amp; data3 \\ </code></pre> <p>becomes this</p> <pre><code>header1 &amp; header2 &amp; header3 \\ data1 &amp; data2 &...
[ { "answer_id": 31871, "author": "joharr", "author_id": 2721, "author_profile": "https://vi.stackexchange.com/users/2721", "pm_score": 0, "selected": false, "text": "<p>I've found a work-around, with minor disadvantage that it's global, and could be overwritten: <code>let @t = 'gAip*&amp;...
2021/07/20
[ "https://vi.stackexchange.com/questions/31870", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2721/" ]
I frequently use `EasyAlign` in my tex files to align tables around the `$` delimiter such that this ``` header1 & header2 & header3 \\ data1 & data2 & data3 \\ ``` becomes this ``` header1 & header2 & header3 \\ data1 & data2 & data3 \\ ``` As I have `EasyAlign` mapped to `gA`, my normal-mode keystrokes to...
You can also try `:normal` command: ``` :normal gAip*& ``` And then `@:` to repeat last command. Or if you want to map it: ``` nmap <buffer> gT gAip*& ```
31,876
<p>the simple why to remap key in lua is:</p> <pre><code>vim.api.nvim_set_keymap('n', 'foo', 'bar', { noremap = true, silent = true }) </code></pre> <p>but i want a simple syntax like vimScript: <code>nnoremap foo bar</code></p> <pre><code>n_keymap('foo','bar') </code></pre> <h3 id="how-i-can-i-write-this-function-n_ke...
[ { "answer_id": 31887, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 4, "selected": true, "text": "<p>A simple way to do it is like this:</p>\n<pre><code>local n_keymap = function(lhs, rhs)\n vim.api.nvim_set_keymap('n',...
2021/07/20
[ "https://vi.stackexchange.com/questions/31876", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/33304/" ]
the simple why to remap key in lua is: ``` vim.api.nvim_set_keymap('n', 'foo', 'bar', { noremap = true, silent = true }) ``` but i want a simple syntax like vimScript: `nnoremap foo bar` ``` n_keymap('foo','bar') ``` ### How i can i write this function `n_keymap` ?
A simple way to do it is like this: ``` local n_keymap = function(lhs, rhs) vim.api.nvim_set_keymap('n', lhs, rhs, { noremap = true, silent = true }) end n_keymap('foo','bar') ``` But in my opinion that doesn't make any sense because the `map` function are quite powerful (they support different modes, recursive...
31,877
<p>I am wondering how to open a file or load it into a buffer using the index shown by <code>:scriptnames</code>?</p> <pre><code> 23: /usr/share/vim/vim80/plugin/tarPlugin.vim 24: /usr/share/vim/vim80/plugin/tohtml.vim 25: /usr/share/vim/vim80/plugin/vimballPlugin.vim 26: /usr/share/vim/vim80/plugin/zipPlugin.vim </...
[ { "answer_id": 31878, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 4, "selected": true, "text": "<p>Since Vim <a href=\"https://github.com/vim/vim/releases/tag/v8.1.0553\" rel=\"noreferrer\">8.1.553</a>, you can s...
2021/07/20
[ "https://vi.stackexchange.com/questions/31877", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25325/" ]
I am wondering how to open a file or load it into a buffer using the index shown by `:scriptnames`? ``` 23: /usr/share/vim/vim80/plugin/tarPlugin.vim 24: /usr/share/vim/vim80/plugin/tohtml.vim 25: /usr/share/vim/vim80/plugin/vimballPlugin.vim 26: /usr/share/vim/vim80/plugin/zipPlugin.vim ``` *e.g.*, the 25th?
Since Vim [8.1.553](https://github.com/vim/vim/releases/tag/v8.1.0553), you can simply supply a count to the scriptnames command to have it edited. So in your case, you can simply use: ``` :25scriptnames ``` or ``` :scriptnames 25 ``` to edit the zipPlugin.vim
31,896
<p>Using <code>set syntax=lang</code> we can override syntax highlighting of current buffer with <code>lang</code>.</p> <p>Suppose we're editing a Bash script and some string variables are actually HTML code. How to force vim to use HTML syntax highlighting <strong>only</strong> for part of the code (or limited to only...
[ { "answer_id": 31878, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 4, "selected": true, "text": "<p>Since Vim <a href=\"https://github.com/vim/vim/releases/tag/v8.1.0553\" rel=\"noreferrer\">8.1.553</a>, you can s...
2021/07/24
[ "https://vi.stackexchange.com/questions/31896", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16051/" ]
Using `set syntax=lang` we can override syntax highlighting of current buffer with `lang`. Suppose we're editing a Bash script and some string variables are actually HTML code. How to force vim to use HTML syntax highlighting **only** for part of the code (or limited to only that variable)? Consider the following bas...
Since Vim [8.1.553](https://github.com/vim/vim/releases/tag/v8.1.0553), you can simply supply a count to the scriptnames command to have it edited. So in your case, you can simply use: ``` :25scriptnames ``` or ``` :scriptnames 25 ``` to edit the zipPlugin.vim
31,900
<p>I want to be able to lint my code from within vim, using tools like <code>clang-format</code> and <code>yapf</code> and I'd rather do this without installing a more complex plugin.</p> <p>I can pipe the current buffer through a text processing command:</p> <pre><code>:%!clang-format </code></pre> <p>However, if my b...
[ { "answer_id": 31901, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p>Hmmm. Good question. Is there really not a Vim mechanism for dealing with this? I can't recall seeing one.</p>\n<p>If ...
2021/07/24
[ "https://vi.stackexchange.com/questions/31900", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/26650/" ]
I want to be able to lint my code from within vim, using tools like `clang-format` and `yapf` and I'd rather do this without installing a more complex plugin. I can pipe the current buffer through a text processing command: ``` :%!clang-format ``` However, if my buffer contents results in an error for the external ...
Hmmm. Good question. Is there really not a Vim mechanism for dealing with this? I can't recall seeing one. If there's not I was able to leverage Bash semantics to get something to work. I'm using `sort` as an example command as it's a common filter and easy to make fail... **Valid** invocation: ``` :%!sort -n 2> /de...
31,926
<p>These exist with lambdas</p> <pre><code>function A() let B = { -&gt; 'thing' } endfunction // B does no exist </code></pre> <p>But the lambda returns a value and not a sequence of commands.</p> <p>(I know I could put execute(&quot;..&quot;) in the lambda but this is an ugly hack.)</p> <pre><code>function A() ...
[ { "answer_id": 31927, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 3, "selected": true, "text": "<p>One way to prevent creation of a global function is to use &quot;dictionary entry funcref syntax.&quot; Note that this i...
2021/07/26
[ "https://vi.stackexchange.com/questions/31926", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/33531/" ]
These exist with lambdas ``` function A() let B = { -> 'thing' } endfunction // B does no exist ``` But the lambda returns a value and not a sequence of commands. (I know I could put execute("..") in the lambda but this is an ugly hack.) ``` function A() function B() echo "I'm going to leak" endfunct...
One way to prevent creation of a global function is to use "dictionary entry funcref syntax." Note that this is distinct, but also useful paired with, functions which are marked `dict`. ``` function A() let l:container = {} function container.myfunc() echo "I'm going to leak" endfunction call l:container...
32,957
<p>I like YouCompleteMe, but it apparently has a major drawback for C/C++, which is no static analysis. Moreover, it disables Syntastic, which does provide static analysis, and they are generally incompatible. My goal is to be able to configure C++ checkers through clang-tidy, which is supported through clangd, the YCM...
[ { "answer_id": 32992, "author": "Sam Gallagher", "author_id": 37220, "author_profile": "https://vi.stackexchange.com/users/37220", "pm_score": 0, "selected": false, "text": "<p>Answering my own question, the best approach has been to use ALE as a linter along with YCM for autocomplete. I...
2021/07/29
[ "https://vi.stackexchange.com/questions/32957", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/37220/" ]
I like YouCompleteMe, but it apparently has a major drawback for C/C++, which is no static analysis. Moreover, it disables Syntastic, which does provide static analysis, and they are generally incompatible. My goal is to be able to configure C++ checkers through clang-tidy, which is supported through clangd, the YCM ba...
According to the [`clangd` getting started documentation](https://spclgitlab.ethz.ch/open-climate-compiler/llvm-project/-/blob/95e1c294cb0415a377a7b1d6c7c7d4f89e1c04e4/clang-tools-extra/docs/clangd/Installation.rst) in your original post, you're able to modify the arguments to clangd using: ``` let g:ycm_clangd_args =...
32,960
<p>I've recently begun using buffers, rather than tabs, to sort files in <code>vi</code>. My question is, can I create a buffer such that, instead of getting this:</p> <pre><code>[:enew] [:ls] 1 main.c 2 foo.txt 3 [No Name] </code></pre> <p>I got something like this:</p> <pre><code>1 main.c 2 [No Name] 3 foo.txt </code...
[ { "answer_id": 32977, "author": "Heptite", "author_id": 1311, "author_profile": "https://vi.stackexchange.com/users/1311", "pm_score": 0, "selected": false, "text": "<p>This isn't possible, as Vim handles buffer numbers internally. They need to be predictable for various reasons, such as...
2021/07/29
[ "https://vi.stackexchange.com/questions/32960", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/37223/" ]
I've recently begun using buffers, rather than tabs, to sort files in `vi`. My question is, can I create a buffer such that, instead of getting this: ``` [:enew] [:ls] 1 main.c 2 foo.txt 3 [No Name] ``` I got something like this: ``` 1 main.c 2 [No Name] 3 foo.txt ``` Please note that I start on `main.c`, and hav...
While this cannot be achieved by default, manipulating the argument list yields similar functionality. Here are the commands to use: * `:bn` -> `:n` * `:bp` -> `:prev` * `ls` -> `args` * `:e` -> `:arga` (This appends after the *current* argument, rather than the last) As a side note, `:args` may also be used to set t...
32,989
<p>How can we do this with vim?</p> <pre><code>set hlsearch &quot; Highlight search matches set incsearch &quot; Highlight search matches as you type set visualbell &quot; Use visual bell instead of beeping set shortmess+=I &quot; Disa...
[ { "answer_id": 32991, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 2, "selected": false, "text": "<p>Well, you can do it with vimscript, here is the proof of concept:</p>\n<pre><code>func! MyTab() abort\n let spaces...
2021/08/02
[ "https://vi.stackexchange.com/questions/32989", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/37121/" ]
How can we do this with vim? ``` set hlsearch " Highlight search matches set incsearch " Highlight search matches as you type set visualbell " Use visual bell instead of beeping set shortmess+=I " Disable vim intro message set lazyred...
Well, you can do it with vimscript, here is the proof of concept: ``` func! MyTab() abort let spaces = matchstr(getline(line('.')-1), '\%.c\s*') if len(spaces) return spaces else return "\<Tab>" endif endfunc inoremap <expr> <tab> MyTab() ``` [![enter image description here](https://i...
32,997
<p>I am facing an issue with my vim. The mouse isn't working. I have set <code>set mouse=a</code> in my vimrc. I have checked it inside vim that the mouse value is set to &quot;a&quot;. But it's still not working. What can I do?</p> <p>N.B. I have also tried <code>set mouse+=a</code> which also doesn't work.</p> <p>I a...
[ { "answer_id": 32991, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 2, "selected": false, "text": "<p>Well, you can do it with vimscript, here is the proof of concept:</p>\n<pre><code>func! MyTab() abort\n let spaces...
2021/08/03
[ "https://vi.stackexchange.com/questions/32997", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23558/" ]
I am facing an issue with my vim. The mouse isn't working. I have set `set mouse=a` in my vimrc. I have checked it inside vim that the mouse value is set to "a". But it's still not working. What can I do? N.B. I have also tried `set mouse+=a` which also doesn't work. I am using Ubuntu 20.04 and Vim 8.1.2269 and my te...
Well, you can do it with vimscript, here is the proof of concept: ``` func! MyTab() abort let spaces = matchstr(getline(line('.')-1), '\%.c\s*') if len(spaces) return spaces else return "\<Tab>" endif endfunc inoremap <expr> <tab> MyTab() ``` [![enter image description here](https://i...
33,002
<p>I just stumbled upon this strange problem:</p> <pre><code>echo 'test' ==# 0 </code></pre> <p>This returns <code>1</code>. Therefore it is true. But in &quot;reality&quot; it is not true. Any string is different from 0. How to do this check?</p> <p>For a bit more context, I actually stumbled upon it with the followin...
[ { "answer_id": 33003, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 3, "selected": true, "text": "<p>By design in VimScript strings can be implicitly converted to numbers. Kind of Awk-style. Use <code>is</code> operator in...
2021/08/03
[ "https://vi.stackexchange.com/questions/33002", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/21417/" ]
I just stumbled upon this strange problem: ``` echo 'test' ==# 0 ``` This returns `1`. Therefore it is true. But in "reality" it is not true. Any string is different from 0. How to do this check? For a bit more context, I actually stumbled upon it with the following code: ``` let l= ['one', 'two', 'three'] let val...
By design in VimScript strings can be implicitly converted to numbers. Kind of Awk-style. Use `is` operator instead: ``` :echo 'test' is 0 0 ```
33,017
<p>I have a large file which have some corrupt lines like this</p> <pre><code>0.6 8 379699 730 0.999769 0.802075 0.912155 0.6 8 379699 731 0.999698 0.8181070.8 8 377999 0 0.674844 0.765493 0.900248 0.8 8 377999 1 0.835223 0.913123 0.883744 0.8 8 377999 1 0.816537 1 0.852433 <...
[ { "answer_id": 33018, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p>Delete lines without seven columns? Sure...</p>\n<pre><code>:v/\\v^\\S+(\\s+\\S+){6}$/d\n</code></pre>\n<p><a href=\"h...
2021/08/04
[ "https://vi.stackexchange.com/questions/33017", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/37309/" ]
I have a large file which have some corrupt lines like this ``` 0.6 8 379699 730 0.999769 0.802075 0.912155 0.6 8 379699 731 0.999698 0.8181070.8 8 377999 0 0.674844 0.765493 0.900248 0.8 8 377999 1 0.835223 0.913123 0.883744 0.8 8 377999 1 0.816537 1 0.852433 ``` The file...
Delete lines without seven columns? Sure... ``` :v/\v^\S+(\s+\S+){6}$/d ``` [`:vglobal`](https://vimhelp.org/repeat.txt.html#:v), the "inverse" [`:global`](https://vimhelp.org/repeat.txt.html#:g) command, looks for all lines that *don't* match the search criteria and then [`d`](https://vimhelp.org/change.txt.html#:d...
33,026
<p>Consider the case of <code>html</code> file that has a <code>form</code> tag with <code>action</code> attribute and value of <code>/login.php</code>:</p> <pre><code>action=&quot;/login.php&quot; </code></pre> <p>In which case <code>login.php</code> will be searched in the same directory as a html file resides.</p> <...
[ { "answer_id": 33027, "author": "Chris Heithoff", "author_id": 36840, "author_profile": "https://vi.stackexchange.com/users/36840", "pm_score": 3, "selected": true, "text": "<p>You should define a function which strips the leading <code>/</code> off the name of the file.\nThen assign tha...
2021/08/05
[ "https://vi.stackexchange.com/questions/33026", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25325/" ]
Consider the case of `html` file that has a `form` tag with `action` attribute and value of `/login.php`: ``` action="/login.php" ``` In which case `login.php` will be searched in the same directory as a html file resides. Can I configure `path` variable the way forwarding slash will force the search for file under...
You should define a function which strips the leading `/` off the name of the file. Then assign that function to the `includeexpr` setting. ``` *'includeexpr'* *'inex'* 'includeexpr' 'inex' string (default "") local to buffer {not available when compiled without the ...
33,043
<p><sup>Writing vim syntax files never ceases to make me feel like an idiot.</sup></p> <p>I have a <a href="https://pkgd.racket-lang.org/pkgn/package/jsond" rel="nofollow noreferrer">new custom language call jsond</a>, and I wanted to get syntax highlighting working in vim. Using <code>racket</code> syntax works pretty...
[ { "answer_id": 33046, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 2, "selected": false, "text": "<ol>\n<li>To debug the syntax one should be able to identify current syntax group under cursor (that question was asked mul...
2021/08/06
[ "https://vi.stackexchange.com/questions/33043", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10604/" ]
Writing vim syntax files never ceases to make me feel like an idiot. I have a [new custom language call jsond](https://pkgd.racket-lang.org/pkgn/package/jsond), and I wanted to get syntax highlighting working in vim. Using `racket` syntax works pretty well (at least with [my fork](https://github.com/benknoble/vim-rack...
Apologies, dear reader, for the XY problem presented here. I can't accept Matt's answer, despite its help pointing out a problem in my syntax, because it didn't answer the underlying question (which I didn't correctly ask). Ultimately I wanted to embed any [JSON values](https://www.json.org/json-en.html) in the syntax...
33,049
<p>The input line contains pairs of curly brace and in each pair of curly braces there might also be curly braces in the contents. Multiple layers of curly braces may also happen. Here's some example input:</p> <pre><code>{ A1 {B1 C1} {D1} } { {A2 B2} C2 D2} { A3 { {B3} F3} } </code></pre> <p>The target is to separate...
[ { "answer_id": 33050, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>A lot of people will likely think of using a regular expression to parse and split up those &quot;bracket blocks&quot...
2021/08/08
[ "https://vi.stackexchange.com/questions/33049", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/37357/" ]
The input line contains pairs of curly brace and in each pair of curly braces there might also be curly braces in the contents. Multiple layers of curly braces may also happen. Here's some example input: ``` { A1 {B1 C1} {D1} } { {A2 B2} C2 D2} { A3 { {B3} F3} } ``` The target is to separate them into lines for eac...
Recursive macro time! * `qaqqa`: start a macro in the register a after clearing it * `0%a``Enter``Esc`: find a whole block and add a newline after it * `@a`: recursive invocation * `q@a`: finish recording and run --- If you try this, it may not work the first time. Rather, it may run forever and leave blank lines in...
33,062
<p>This syntax region fold consecutive comments:</p> <pre><code>syn region vimFoldComment \ start=&quot;^\z(\s*\&quot;\)&quot; \ end=&quot;\(\z1\)\@!&quot; \ transparent fold \ contains=ALLBUT, vimFoldComment </code></pre> <p>This, for example:</p> <pre><code>&quot; a &qu...
[ { "answer_id": 33050, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>A lot of people will likely think of using a regular expression to parse and split up those &quot;bracket blocks&quot...
2021/08/09
[ "https://vi.stackexchange.com/questions/33062", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/37375/" ]
This syntax region fold consecutive comments: ``` syn region vimFoldComment \ start="^\z(\s*\"\)" \ end="\(\z1\)\@!" \ transparent fold \ contains=ALLBUT, vimFoldComment ``` This, for example: ``` " a " b " c ``` Folds to ``` +-- 3 lines: a----- ``` but doesn't ...
Recursive macro time! * `qaqqa`: start a macro in the register a after clearing it * `0%a``Enter``Esc`: find a whole block and add a newline after it * `@a`: recursive invocation * `q@a`: finish recording and run --- If you try this, it may not work the first time. Rather, it may run forever and leave blank lines in...
33,065
<p>If I for example create a mark inside the file <code>~/.vimrc</code> with <code>mV</code>.</p> <p>How do I convert the mark <code>'V</code> to the path of the file the mark is in?</p> <p>When I type <code>:marks</code> I can see a list of marks and the corresponding file paths.</p> <p>Perhaps I can put this list int...
[ { "answer_id": 33066, "author": "Heptite", "author_id": 1311, "author_profile": "https://vi.stackexchange.com/users/1311", "pm_score": 2, "selected": false, "text": "<p>You probably want to look at &quot;<code>:help getmarklist()</code>&quot; which can give you a list of global marks or,...
2021/08/09
[ "https://vi.stackexchange.com/questions/33065", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/37184/" ]
If I for example create a mark inside the file `~/.vimrc` with `mV`. How do I convert the mark `'V` to the path of the file the mark is in? When I type `:marks` I can see a list of marks and the corresponding file paths. Perhaps I can put this list into a string somehow in order to retrieve the file path, but how? ...
Found a way to store the :marks output into a string without using the getmarklist() function ``` fun! Marklist() abort redir => str :silent marks redir END " do something with str here ... endfun ``` But in the end i used a different way to achieve my goal: ``` let fileMarkKeys = [ "A","B","C","D","E","F",...
33,072
<p>I'm using MacOS.</p> <p>As title, for example before the command:</p> <pre><code>$('h1#title') .css({'font-size': '80px', 'text-align': 'center'}_)_ .text() .testing() .tset() </code></pre> <p>(Notice that the blank line above <code>.text()</code> is intended.)</p> <p>and <code>_)_</code> means the curs...
[ { "answer_id": 33066, "author": "Heptite", "author_id": 1311, "author_profile": "https://vi.stackexchange.com/users/1311", "pm_score": 2, "selected": false, "text": "<p>You probably want to look at &quot;<code>:help getmarklist()</code>&quot; which can give you a list of global marks or,...
2021/08/10
[ "https://vi.stackexchange.com/questions/33072", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10189/" ]
I'm using MacOS. As title, for example before the command: ``` $('h1#title') .css({'font-size': '80px', 'text-align': 'center'}_)_ .text() .testing() .tset() ``` (Notice that the blank line above `.text()` is intended.) and `_)_` means the cursor is on the char `)`, then what I want to achieve is that...
Found a way to store the :marks output into a string without using the getmarklist() function ``` fun! Marklist() abort redir => str :silent marks redir END " do something with str here ... endfun ``` But in the end i used a different way to achieve my goal: ``` let fileMarkKeys = [ "A","B","C","D","E","F",...
33,094
<h3>Goal</h3> <p>I would like to create a command that can automatically put an <code>x</code> inside a <code>[]</code>.<br /> This command should work in both normal mode and visual mode.</p> <h5>normal mode</h5> <p>If it is in normal mode, and the cursor is on the shown line, it should work as follows:</p> <pre><code...
[ { "answer_id": 33066, "author": "Heptite", "author_id": 1311, "author_profile": "https://vi.stackexchange.com/users/1311", "pm_score": 2, "selected": false, "text": "<p>You probably want to look at &quot;<code>:help getmarklist()</code>&quot; which can give you a list of global marks or,...
2021/08/12
[ "https://vi.stackexchange.com/questions/33094", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/26536/" ]
### Goal I would like to create a command that can automatically put an `x` inside a `[]`. This command should work in both normal mode and visual mode. ##### normal mode If it is in normal mode, and the cursor is on the shown line, it should work as follows: ``` [] my task ``` Executing the command should giv...
Found a way to store the :marks output into a string without using the getmarklist() function ``` fun! Marklist() abort redir => str :silent marks redir END " do something with str here ... endfun ``` But in the end i used a different way to achieve my goal: ``` let fileMarkKeys = [ "A","B","C","D","E","F",...
33,097
<p>I have my own detection of the file indent settings based on the file contents. All good and works ok for my needs but...</p> <p>When I open a <code>c</code> source file of the vim itself it overrides options set by <code>modeline</code>:</p> <pre><code>/* vi:set ts=8 sts=4 sw=4 noet: * * VIM - Vi IMproved› by B...
[ { "answer_id": 33099, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 3, "selected": true, "text": "<p>Assuming your locale is English-like, the following should work:</p>\n<pre><code>:echo (execute('verbose setloca...
2021/08/12
[ "https://vi.stackexchange.com/questions/33097", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9333/" ]
I have my own detection of the file indent settings based on the file contents. All good and works ok for my needs but... When I open a `c` source file of the vim itself it overrides options set by `modeline`: ``` /* vi:set ts=8 sts=4 sw=4 noet: * * VIM - Vi IMproved› by Bram Moolenaar * * Do ":help uganda" in...
Assuming your locale is English-like, the following should work: ``` :echo (execute('verbose setlocal ts?')->split('\n')[-1] =~# 'Last set from modeline line \d\+') \ ? 'set from modeline' \ : 'set elsewhere' ``` Not sure about handling different locales. For example, my system has `LC_ALL=fr_FR.UTF...
33,111
<p>I'm trying to write a opfunc which surrounds selected motion with two stars (<strong>bold</strong> in Markdown):</p> <pre><code>nnoremap &lt;localleader&gt;b :set opfunc=BoldIt&lt;CR&gt;g@ function! BoldIt(type, ...) execute &quot;normal! `[i**&quot; execute &quot;normal! `]a**&quot; endfunction </code></pre...
[ { "answer_id": 33103, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 1, "selected": false, "text": "<p>There's no need in pressing escape. Type simply <code>:e#&lt;X</code> to open old file no. X while browsing through the ...
2021/08/13
[ "https://vi.stackexchange.com/questions/33111", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17027/" ]
I'm trying to write a opfunc which surrounds selected motion with two stars (**bold** in Markdown): ``` nnoremap <localleader>b :set opfunc=BoldIt<CR>g@ function! BoldIt(type, ...) execute "normal! `[i**" execute "normal! `]a**" endfunction ``` According to `:map-operator` info: * `[` mark denotes start of ...
I found one solution. In nvim there is the nvim\_input() function call. I made a command: `command! Bro :call nvim_input('<Esc>') | bro ol`. I mapped that command to a key. When I press it, it shows me one screen full of the names of the most recently opened files, and all I have to do is type a number and enter.
33,125
<p>I have a list of files like <code>step-1.py</code>, <code>step-2.py</code> etc and if I try to open them with <code>vim files-*.py</code> then I get a list of buffers like:</p> <pre><code>:ls 1 %a &quot;step-10.py&quot; 2 &quot;step-11.py&quot; 3 &quot;step-12.py&quot; 4 &quot;step-13.py&quo...
[ { "answer_id": 33126, "author": "alec", "author_id": 6189, "author_profile": "https://vi.stackexchange.com/users/6189", "pm_score": 0, "selected": false, "text": "<p>Cleanest way: <code>vi $(ls step-* | sort -n -t- -k2)</code>.</p>\n<hr />\n<p>In trying the approach described in the ques...
2021/08/15
[ "https://vi.stackexchange.com/questions/33125", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6189/" ]
I have a list of files like `step-1.py`, `step-2.py` etc and if I try to open them with `vim files-*.py` then I get a list of buffers like: ``` :ls 1 %a "step-10.py" 2 "step-11.py" 3 "step-12.py" 4 "step-13.py" 5 "step-14.py" 6 "step-15.py" 7 "step-16.py" 8 "step-17...
That should be enough: ``` ls -v *.py | xargs gvim ```
33,127
<p>There is a built-in mapping <kbd>Ctrl</kbd>-<kbd>g</kbd> which presents the current filename immediately in the command area. I would like to augment this by tapping <kbd>Ctrl</kbd>-<kbd>g</kbd> again to copy the filename to my system clipboard register.</p> <p>At the moment, I have added this to my <code>.vimrc</co...
[ { "answer_id": 33126, "author": "alec", "author_id": 6189, "author_profile": "https://vi.stackexchange.com/users/6189", "pm_score": 0, "selected": false, "text": "<p>Cleanest way: <code>vi $(ls step-* | sort -n -t- -k2)</code>.</p>\n<hr />\n<p>In trying the approach described in the ques...
2021/08/15
[ "https://vi.stackexchange.com/questions/33127", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/37468/" ]
There is a built-in mapping `Ctrl`-`g` which presents the current filename immediately in the command area. I would like to augment this by tapping `Ctrl`-`g` again to copy the filename to my system clipboard register. At the moment, I have added this to my `.vimrc` ``` nnoremap <silent> <c-g><c-g> :let @+=@%<CR> ``...
That should be enough: ``` ls -v *.py | xargs gvim ```
33,148
<p>In Python, I am trying to update my code from typed dict to dataclass. Language is just indicated as a reference, it is a pure Vim question.</p> <p>I need to replace <code>my_params[&quot;some_property&quot;] </code> with <code>my_params.some_property</code></p> <p>I have some difficulty replacing <code>[&quot;</co...
[ { "answer_id": 33149, "author": "Lionel Hamayon", "author_id": 29635, "author_profile": "https://vi.stackexchange.com/users/29635", "pm_score": 2, "selected": false, "text": "<p><strong>New version from @b-layer</strong></p>\n<pre><code>:%s/\\v\\[&quot;([^&quot;]+)&quot;]/.\\1/gc\n</code...
2021/08/17
[ "https://vi.stackexchange.com/questions/33148", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/29635/" ]
In Python, I am trying to update my code from typed dict to dataclass. Language is just indicated as a reference, it is a pure Vim question. I need to replace `my_params["some_property"]` with `my_params.some_property` I have some difficulty replacing `["`. How can I replace everything at once?
**New version from @b-layer** ``` :%s/\v\["([^"]+)"]/.\1/gc ``` * `%s` targets the whole file * `\v` is the very magic modifier * `\["` matches `["` * `([^"]"+)` represents the capture group for `some_property`, which `[^"]` ends at the next double quotes. `+` makes it at least one character. * `\1` references the c...
33,160
<p>As a concrete (although hyperbolic) example:</p> <pre><code>nnoremap , a&lt;esc&gt;a&lt;esc&gt;a&lt;esc&gt;a&lt;esc&gt;a&lt;esc&gt;a&lt;esc&gt;a&lt;esc&gt;a&lt;esc&gt;a&lt;esc&gt;a&lt;esc&gt;a&lt;esc&gt;a&lt;esc&gt;a&lt;esc&gt;a&lt;esc&gt;aX&lt;esc&gt; </code></pre> <p>This mapping will take a bit to actually type o...
[ { "answer_id": 33155, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p>That's because Vim is using <code>$VIMRUNTIME/defaults.vim</code> as the vimrc file.</p>\n<p>If you look at <code>:h ....
2021/08/17
[ "https://vi.stackexchange.com/questions/33160", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34059/" ]
As a concrete (although hyperbolic) example: ``` nnoremap , a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>aX<esc> ``` This mapping will take a bit to actually type out an "`X`" (at least in my underpowered Celeron. You may have to up the number of `a<esc>` if you have a better C...
That's because Vim is using `$VIMRUNTIME/defaults.vim` as the vimrc file. If you look at `:h .vimrc` you'll see that Vim looks in five places for a vimrc file, stopping once it's found one. When you have an empty personal vimrc (in your home directory, usually) then Vim will read that and stop searching. Obviously, i...
33,163
<p>Consider the following mappings:</p> <pre><code>nmap &lt;plug&gt;test a123 nmap M &lt;plug&gt;test&lt;plug&gt;test </code></pre> <p>If both <code>&lt;plug&gt;test</code> were expanded, vim would type out in the buffer &quot;<code>123a123</code>&quot;. However, only the first <code>&lt;plug&gt;test</code> is expanded...
[ { "answer_id": 33155, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p>That's because Vim is using <code>$VIMRUNTIME/defaults.vim</code> as the vimrc file.</p>\n<p>If you look at <code>:h ....
2021/08/18
[ "https://vi.stackexchange.com/questions/33163", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34059/" ]
Consider the following mappings: ``` nmap <plug>test a123 nmap M <plug>test<plug>test ``` If both `<plug>test` were expanded, vim would type out in the buffer "`123a123`". However, only the first `<plug>test` is expanded, and vim types "`123<Plug>test`" instead. Is there a way to exapand all `<plug>` mappings befor...
That's because Vim is using `$VIMRUNTIME/defaults.vim` as the vimrc file. If you look at `:h .vimrc` you'll see that Vim looks in five places for a vimrc file, stopping once it's found one. When you have an empty personal vimrc (in your home directory, usually) then Vim will read that and stop searching. Obviously, i...
33,183
<p>Yesterday I updated Vim to version 8.2 thru my Linux distro repositories (Fedora). And now I noticed that no user defined functions exist. They worked just yesterday, before the update.</p> <p>I define several functions in my vimrc file. It used to work, but now it looks like definition rules have changed or somethi...
[ { "answer_id": 33184, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 3, "selected": true, "text": "<p>There was a regression bug in <a href=\"https://github.com/vim/vim/issues/8765\" rel=\"nofollow noreferrer\">8.2.3337<...
2021/08/20
[ "https://vi.stackexchange.com/questions/33183", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2798/" ]
Yesterday I updated Vim to version 8.2 thru my Linux distro repositories (Fedora). And now I noticed that no user defined functions exist. They worked just yesterday, before the update. I define several functions in my vimrc file. It used to work, but now it looks like definition rules have changed or something like t...
There was a regression bug in [8.2.3337](https://github.com/vim/vim/issues/8765) and it was [fixed](https://github.com/vim/vim/commit/5aec755b678cfd434b8ea2158d06992f33e1ff80) [yesterday](https://github.com/vim/vim/pull/8774).
33,195
<p>This question might be related to <a href="https://vi.stackexchange.com/questions/7709/custom-syntax-highlighting-highlight-word-following-keyword">Custom syntax highlighting: highlight word following keyword</a> but after studying that for hours, I could not get it to work.</p> <p>What I want is to highlight vulkan...
[ { "answer_id": 33196, "author": "Heptite", "author_id": 1311, "author_profile": "https://vi.stackexchange.com/users/1311", "pm_score": 1, "selected": false, "text": "<p>How about this?</p>\n<pre><code>syn region cParen start=/setup(/ end=/)/ contains=cwNamespaceVkTag\nsyn match cwNamespa...
2021/08/22
[ "https://vi.stackexchange.com/questions/33195", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/37562/" ]
This question might be related to [Custom syntax highlighting: highlight word following keyword](https://vi.stackexchange.com/questions/7709/custom-syntax-highlighting-highlight-word-following-keyword) but after studying that for hours, I could not get it to work. What I want is to highlight vulkan types that match `v...
I moved on, after hacking something together that works for now: ``` " Add syntax group for vulkan types that are handles. " The regular expression was generated with: " RE=$(egrep '^(VK_DEFINE_NON_DISPATCHABLE_HANDLE|VK_DEFINE_HANDLE)' Vulkan-Hpp/Vulkan-Headers/include/vulkan/vulkan_core.h | sed -e 's/.*(\([^)]*\))....
33,217
<p>I use <a href="https://github.com/tpope/vim-fugitive" rel="nofollow noreferrer">tpope/vim-fugitive</a> and <a href="https://github.com/airblade/vim-gitgutter" rel="nofollow noreferrer">airblade/vim-gitgutter</a> and I want to selectively enable gitgutter only in git repositories.</p> <p>Since <code>vim-fugitive</cod...
[ { "answer_id": 33218, "author": "Luc Hermitte", "author_id": 626, "author_profile": "https://vi.stackexchange.com/users/626", "pm_score": 2, "selected": false, "text": "<p>If you look at <code>:h starting</code>, you'll see that plugin files are sourced after <code>.vimrc</code> is entir...
2021/08/24
[ "https://vi.stackexchange.com/questions/33217", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19320/" ]
I use [tpope/vim-fugitive](https://github.com/tpope/vim-fugitive) and [airblade/vim-gitgutter](https://github.com/airblade/vim-gitgutter) and I want to selectively enable gitgutter only in git repositories. Since `vim-fugitive` provides `FugitiveIsGitDir` which returns `0` or `1`, this could be achieved as such (snipp...
This does what you want: ``` # vimrc autocmd BufEnter * if FugitiveIsGitDir() | GitGutterBufferEnable | else | GitGutterBufferDisable | endif ``` However I'm curious why you need to turn off gitgutter in non-git directories. There shouldn't be overhead to having it there.
33,236
<p>I have a bunch of expressions (matlab anonymous functions) of the form, for example</p> <pre><code>`f\^I = @(x,y,z) x^y + z`, `g1\^I\^I = @(z,b,c) z^b + c` </code></pre> <p>(where <code>\^I</code> means a tab, but I can't just write that in this editor)</p> <p>I want to build a macro that removes the <code>\^I = @<...
[ { "answer_id": 33237, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 2, "selected": false, "text": "<p>You can't use <code>\\1</code> as a back reference to what matched in a <em>separate</em> pattern match.</p>\n<p>I...
2021/08/25
[ "https://vi.stackexchange.com/questions/33236", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4667/" ]
I have a bunch of expressions (matlab anonymous functions) of the form, for example ``` `f\^I = @(x,y,z) x^y + z`, `g1\^I\^I = @(z,b,c) z^b + c` ``` (where `\^I` means a tab, but I can't just write that in this editor) I want to build a macro that removes the `\^I = @` and the stuff after the ), to produce ``` f(...
You can't use `\1` as a back reference to what matched in a *separate* pattern match. I see you're using the pattern in the `:g` capture group to match the location and use a capture group to pick the part you want to replace, then hoping you can use a separate `:s` and refer to that group as `\1`, but you can't reall...
33,258
<p>Vim provides a builtin textobject <code>t</code> that captures a matched pair of HTML tags — so e.g. if you start with <code>this &lt;i&gt;that█ &lt;b&gt;those&lt;/b&gt;&lt;/i&gt;</code>, then typing <code>dat</code> in normal mode leaves you with <code>this█</code>. Very cool.</p> <p>How might I create similar text...
[ { "answer_id": 33271, "author": "nextloop", "author_id": 33304, "author_profile": "https://vi.stackexchange.com/users/33304", "pm_score": 0, "selected": false, "text": "<p>one of the cool plugins to trait tag is vim surround<br />\nlet's try out visual mode the <code>that█ </code> then:<...
2021/08/27
[ "https://vi.stackexchange.com/questions/33258", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2657/" ]
Vim provides a builtin textobject `t` that captures a matched pair of HTML tags — so e.g. if you start with `this <i>that█ <b>those</b></i>`, then typing `dat` in normal mode leaves you with `this█`. Very cool. How might I create similar textobjects for other markup languages with this sort of begin/end syntax? For in...
I know a reference to a plugin is not an ideal answer, but this is a tricky thing to accomplish generally and I maintain a plugin which seems to do exactly what you ask for so I'll mention it. The plugin [match-up](https://github.com/andymass/vim-matchup/) supports text objects `a%` and `i%` corresponding to pairs whi...
33,259
<p>You can set <code>display</code> to <code>lastline</code> to see &quot;<code>@@@</code>&quot; at the end of the last line when it doesn't fit the screen. I'd prefer to use a different character for that purpose, such as <code>...</code> or <code>---</code>.</p> <p>Is there a way to change the character used?</p>
[ { "answer_id": 33273, "author": "nextloop", "author_id": 33304, "author_profile": "https://vi.stackexchange.com/users/33304", "pm_score": -1, "selected": false, "text": "<p>vim handle spaces tab and return lien by:</p>\n<pre><code>set list\n\nset listchars=space:-\nset listchars+=tab:&gt...
2021/08/27
[ "https://vi.stackexchange.com/questions/33259", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/34059/" ]
You can set `display` to `lastline` to see "`@@@`" at the end of the last line when it doesn't fit the screen. I'd prefer to use a different character for that purpose, such as `...` or `---`. Is there a way to change the character used?
Since Vim 9.0.0656 (Oct 2022) you can use `lastline` in the `fillchars` setting; for example to change it to `·`: ``` :set fillchars=lastline:· ```
33,262
<p>I am trying to use a vim function to search whether <code>:noh</code> has been set or not</p> <p>This is similar to question found <a href="https://vi.stackexchange.com/questions/3655/how-can-i-make-a-search-in-vimscript-let-n-and-n-look-for-more">here</a> except that question does not take <code>:noh</code> into ac...
[ { "answer_id": 33263, "author": "Clark Taylor", "author_id": 37494, "author_profile": "https://vi.stackexchange.com/users/37494", "pm_score": 2, "selected": false, "text": "<p>It is a little tricky but this can be done. First you have to search using <code>let @/ = 'needle'</code>. This ...
2021/08/27
[ "https://vi.stackexchange.com/questions/33262", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/37494/" ]
I am trying to use a vim function to search whether `:noh` has been set or not This is similar to question found [here](https://vi.stackexchange.com/questions/3655/how-can-i-make-a-search-in-vimscript-let-n-and-n-look-for-more) except that question does not take `:noh` into account One way to search from a function i...
It is a little tricky but this can be done. First you have to search using `let @/ = 'needle'`. This initiates the search. However, none of the highlights appear. To get the highlights, you simply need to go to the "next" instance with `:normal! n`, which will highlight all instances and move the cursor to the next ins...
33,299
<p>I want to find a line number and a column for a particular byte number in a buffer in Neovim. I can get it (sort of) with</p> <pre class="lang-lua prettyprint-override"><code>local b = 444 local line = vim.fn.byte2line(b) local line_start = vim.fn.line2byte(line) local col = b - line_start + 1 </code></pre> <p>But t...
[ { "answer_id": 33296, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 1, "selected": false, "text": "<p>There are two related options: <code>packpath</code> and <code>runtimepath</code>.</p>\n<p>If you set <code>packpath</co...
2021/08/30
[ "https://vi.stackexchange.com/questions/33299", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/27190/" ]
I want to find a line number and a column for a particular byte number in a buffer in Neovim. I can get it (sort of) with ```lua local b = 444 local line = vim.fn.byte2line(b) local line_start = vim.fn.line2byte(line) local col = b - line_start + 1 ``` But the result will not be correct for multibyte charactes. How...
There are two related options: `packpath` and `runtimepath`. If you set `packpath` then all plugins sub-trees must reside under `pack/<bundle>/{start,opt}` to comply with `:h packages`. If you set `runtimepath` directly then you must add *every separate plugin subtree* to `runtimepath` (and then also `runtime! plugin...