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
20,494
<p>By default, the version of vim on centos7 is 7.4. I want to update it to vim 8. There are some questions with '<a href="https://copr.fedorainfracloud.org/coprs/mcepl/vim8/repo/epel-7/mcepl-vim8-epel-7.repo" rel="nofollow noreferrer">https://copr.fedorainfracloud.org/coprs/mcepl/vim8/repo/epel-7/mcepl-vim8-epel-7.rep...
[ { "answer_id": 20501, "author": "otter.pro", "author_id": 21762, "author_profile": "https://vi.stackexchange.com/users/21762", "pm_score": 1, "selected": false, "text": "<p>That repo is no longer available. Instead, use this (source: <a href=\"https://gist.github.com/yevrah/21cdccc1dc65e...
2019/07/03
[ "https://vi.stackexchange.com/questions/20494", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/22872/" ]
By default, the version of vim on centos7 is 7.4. I want to update it to vim 8. There are some questions with '<https://copr.fedorainfracloud.org/coprs/mcepl/vim8/repo/epel-7/mcepl-vim8-epel-7.repo> -o /etc/yum.repos.d/mcepl-vim8-epel-7.repo'. So, how can I to update it?
otter.pro's answer is helpful but be aware that it will remove sudo with `vim-minimal` in the yum remove step because sudo depends upon vim-minimal. If running as root, no problem. But if you're running with sudo, you can find yourself stuck without root access anymore after sudo gets removed. I followed his steps, b...
20,513
<p>I need to search for a string in a file, then I need to some text after one line following the first match. I need to perform this for a number of files in a script. </p> <p>I am trying to use vim ex mode for this. I know <code>:/search_string</code> can perform a search but I am not able to figure out how to move...
[ { "answer_id": 20517, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": true, "text": "<p>Load your files into vim:</p>\n\n<pre><code>vim files\n</code></pre>\n\n<p>Then, we will use a command on each o...
2019/07/04
[ "https://vi.stackexchange.com/questions/20513", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4513/" ]
I need to search for a string in a file, then I need to some text after one line following the first match. I need to perform this for a number of files in a script. I am trying to use vim ex mode for this. I know `:/search_string` can perform a search but I am not able to figure out how to move the cursor down and i...
Load your files into vim: ``` vim files ``` Then, we will use a command on each of them via `:argdo`. The command searches (`:/pattern/+1`) and `o`pens a new line: ``` :/pattern/+1 normal! oYour new text here ``` Another option is to `put` from the expression register ``` :/pattern/+1 put ='Your text here' ``` ...
20,515
<p>How to add abbrevs made of more than one word?</p> <p>I've been trying:</p> <pre><code>iabbrev a aquilo àquilo iabbrev a aquele àquele iabbrev a aquela àquela </code></pre> <p>What I want to do is have the two words "a aquilo" expand to "àquilo".</p> <p>But it won't work. Also, I see in the docs for <code>abbrev...
[ { "answer_id": 20517, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": true, "text": "<p>Load your files into vim:</p>\n\n<pre><code>vim files\n</code></pre>\n\n<p>Then, we will use a command on each o...
2019/07/04
[ "https://vi.stackexchange.com/questions/20515", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/14568/" ]
How to add abbrevs made of more than one word? I've been trying: ``` iabbrev a aquilo àquilo iabbrev a aquele àquele iabbrev a aquela àquela ``` What I want to do is have the two words "a aquilo" expand to "àquilo". But it won't work. Also, I see in the docs for `abbrev`: > > Examples of strings that cannot be a...
Load your files into vim: ``` vim files ``` Then, we will use a command on each of them via `:argdo`. The command searches (`:/pattern/+1`) and `o`pens a new line: ``` :/pattern/+1 normal! oYour new text here ``` Another option is to `put` from the expression register ``` :/pattern/+1 put ='Your text here' ``` ...
20,532
<p>Assume <code>autoindent</code> is set, and you have the buffer below. Note the cursor is represented as <code>I</code>.</p> <pre><code>for i in range(1, 6): print(i)I </code></pre> <p>When you hit Enter key, you get this.</p> <pre><code>for i in range(1, 6): print(i) I </code></pre> <p>Question: is t...
[ { "answer_id": 20533, "author": "dedowsdi", "author_id": 5017, "author_profile": "https://vi.stackexchange.com/users/5017", "pm_score": 3, "selected": true, "text": "<p><kbd>ctrl</kbd> <kbd>w</kbd> <kbd>w</kbd> (hold ctrl, don't release)</p>\n\n<p>Note that you need to set <a href=\"http...
2019/07/06
[ "https://vi.stackexchange.com/questions/20532", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16502/" ]
Assume `autoindent` is set, and you have the buffer below. Note the cursor is represented as `I`. ``` for i in range(1, 6): print(i)I ``` When you hit Enter key, you get this. ``` for i in range(1, 6): print(i) I ``` Question: is there any simple way to move the cursor back to the place before the pre...
`ctrl` `w` `w` (hold ctrl, don't release) Note that you need to set [:h 'backspace'](https://vimhelp.org/options.txt.html#%27backspace%27) to `indent,eol,start` for this to work . You can also use `<backspace>` or `<c-u>` instead of `<c-w>` if you want. The behavior is described in [:h i\_backspacing](https://vimhe...
20,542
<p>Note: this is an educational exercise. For those wanting a ready-made solution, use <a href="https://github.com/itchyny/vim-gitbranch" rel="nofollow noreferrer">vim-gitbranch</a>.</p> <p>I am learning vimscript, and the code below is part of my <code>.vimrc</code> used to display the current git branch in the statu...
[ { "answer_id": 20544, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 3, "selected": false, "text": "<p>The most general improvements I can give are to avoid the long <code>?:</code> and to make use of the <code>get...
2019/07/07
[ "https://vi.stackexchange.com/questions/20542", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19712/" ]
Note: this is an educational exercise. For those wanting a ready-made solution, use [vim-gitbranch](https://github.com/itchyny/vim-gitbranch). I am learning vimscript, and the code below is part of my `.vimrc` used to display the current git branch in the statusline. I am aware that there are ready-made options out th...
The most general improvements I can give are to avoid the long `?:` and to make use of the `get` function on dictionaries. For example, I would write ``` return get(g:, 'git_branch', '') ``` For the if, use a plain if ``` let l:is_git_dir = trim(system('git rev-parse --in-inside-work-tree')) if l:is_git_dir is# 't...
20,552
<p>I'm trying to allow using backspace in normal mode. My best attempt is adding the following to my vimrc:</p> <p><code>nnoremap &lt;BS&gt; i&lt;BS&gt;&lt;ESC&gt;l</code>.</p> <p>This works great except for two situations:</p> <ul> <li>I'm at the second character in the line</li> <li>I delete a tab which is the fir...
[ { "answer_id": 20553, "author": "perelo", "author_id": 22929, "author_profile": "https://vi.stackexchange.com/users/22929", "pm_score": 4, "selected": true, "text": "<p>I'm glad I can share a command I just learned after few years of vim ! The <code>X</code> command in normal mode does w...
2019/07/08
[ "https://vi.stackexchange.com/questions/20552", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18504/" ]
I'm trying to allow using backspace in normal mode. My best attempt is adding the following to my vimrc: `nnoremap <BS> i<BS><ESC>l`. This works great except for two situations: * I'm at the second character in the line * I delete a tab which is the first tab in the line. In either case, after deleting, my cursor i...
I'm glad I can share a command I just learned after few years of vim ! The `X` command in normal mode does what you want. You can remap `<BS>` to it if you want : ``` nnoremap <BS> X ``` Edit ---- Indeed, if you have spaces in place of tabs, it will delete the space. In the same vein you already achieved, you can d...
20,557
<p>I want to hide the number column <code>set nonumber norealtivenumber</code> in <code>Tlist</code> window! Every time I call <code>:Tlist</code> the number column appears in the window. How can I disable the number column for that window.</p> <p><a href="https://i.stack.imgur.com/vV7Zk.png" rel="nofollow noreferrer"...
[ { "answer_id": 20559, "author": "perelo", "author_id": 22929, "author_profile": "https://vi.stackexchange.com/users/22929", "pm_score": 1, "selected": false, "text": "<p>If <code>:Tlist</code> comes from the <a href=\"http://vim-taglist.sourceforge.net/\" rel=\"nofollow noreferrer\">tagl...
2019/07/09
[ "https://vi.stackexchange.com/questions/20557", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/17299/" ]
I want to hide the number column `set nonumber norealtivenumber` in `Tlist` window! Every time I call `:Tlist` the number column appears in the window. How can I disable the number column for that window. [![enter image description here](https://i.stack.imgur.com/vV7Zk.png)](https://i.stack.imgur.com/vV7Zk.png)
You can specify specific commands for some file as the following: ``` autocmd BufEnter filename/pattern set commands ``` I my case I have to explicitly hide the number column for the Tag List window: ``` autocmd BufEnter __Tag_List__ set nonumber norelativenumber ```
20,560
<p>I want to disable autoindent and smartindent for LaTeX so I did</p> <pre><code>:set noai noci nosi </code></pre> <p>When I open a brand new <code>mwe.tex</code>, <code>filetype=plaintex</code> and there is no auto indent magic.</p> <p>When I then enter some code, such as <code>\begin{frame}\end{frame}</code>, sav...
[ { "answer_id": 20561, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 4, "selected": true, "text": "<p><code>'indentexpr'</code> has the highest priority of how vim can automatically indent lines.</p>\n\n<p><code>:h 'inden...
2019/07/09
[ "https://vi.stackexchange.com/questions/20560", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13038/" ]
I want to disable autoindent and smartindent for LaTeX so I did ``` :set noai noci nosi ``` When I open a brand new `mwe.tex`, `filetype=plaintex` and there is no auto indent magic. When I then enter some code, such as `\begin{frame}\end{frame}`, save and reopen the file, `filetype=tex`, colours have changed, and.....
`'indentexpr'` has the highest priority of how vim can automatically indent lines. `:h 'indentexpr'`: > > When this option is not empty, it overrules the `'cindent'` and > `'smartindent'` indenting. > > > Your value is `indentexpr=GetTeXIndent()`. **Customize `GetTeXIndent()`** The behavior of `GetTeXIndent()...
20,565
<p>I’ve created a new filetype, “usenet,” for Usenet messages. I would like files with this filetype to be highlighted exactly as if they had the “mail” filetype. Is it possible to tell Vim that I want to reuse the existing “mail” syntax definitions for this other filetype?</p> <h3>What I’ve tried</h3> <ul> <li><p>I ...
[ { "answer_id": 20561, "author": "Hotschke", "author_id": 1292, "author_profile": "https://vi.stackexchange.com/users/1292", "pm_score": 4, "selected": true, "text": "<p><code>'indentexpr'</code> has the highest priority of how vim can automatically indent lines.</p>\n\n<p><code>:h 'inden...
2019/07/09
[ "https://vi.stackexchange.com/questions/20565", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/671/" ]
I’ve created a new filetype, “usenet,” for Usenet messages. I would like files with this filetype to be highlighted exactly as if they had the “mail” filetype. Is it possible to tell Vim that I want to reuse the existing “mail” syntax definitions for this other filetype? ### What I’ve tried * I tried writing `setloca...
`'indentexpr'` has the highest priority of how vim can automatically indent lines. `:h 'indentexpr'`: > > When this option is not empty, it overrules the `'cindent'` and > `'smartindent'` indenting. > > > Your value is `indentexpr=GetTeXIndent()`. **Customize `GetTeXIndent()`** The behavior of `GetTeXIndent()...
20,570
<p>I know that e.g. <code>50%</code> is a normal mode command to go halfway down a file, but <code>[count]%</code> is line-wise.</p> <p>How can I get to the halfway point of the line that my cursor is on?</p>
[ { "answer_id": 20572, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 3, "selected": true, "text": "<p>Well, there is no built in way to do it as far as I know, but out of curiosity I have come up with the following:</p>\...
2019/07/10
[ "https://vi.stackexchange.com/questions/20570", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/9024/" ]
I know that e.g. `50%` is a normal mode command to go halfway down a file, but `[count]%` is line-wise. How can I get to the halfway point of the line that my cursor is on?
Well, there is no built in way to do it as far as I know, but out of curiosity I have come up with the following: ``` nnoremap gl :exe 'normal ' . len(getline('.'))/2 . '\|'<CR> ``` With `gl` you will be placed in the "middle" of the line (you know... those odd char counts :) What it does: 1. I want to bind a `77...
20,619
<p>I'd like to maximize NERDTree when I enter the NERDTree buffer. The command I have so far is:</p> <p><code>autocmd BufEnter NERD_tree_* &lt;A&gt;</code></p> <p>...but the <code>&lt;A&gt;</code> part is wrong. I get the error:</p> <p><code>E21: Cannot make changes, 'modifiable' is off: &lt;A&gt;</code></p> <p>The...
[ { "answer_id": 20623, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 1, "selected": false, "text": "<p>Try <code>normal A</code> in your autocommand</p>\n" }, { "answer_id": 20625, "author": "filbranden...
2019/07/15
[ "https://vi.stackexchange.com/questions/20619", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6900/" ]
I'd like to maximize NERDTree when I enter the NERDTree buffer. The command I have so far is: `autocmd BufEnter NERD_tree_* <A>` ...but the `<A>` part is wrong. I get the error: `E21: Cannot make changes, 'modifiable' is off: <A>` The maximize command is `shift-A`, and there's not any type of `:NERDTreeMaximize` co...
TL;DR: You can use this auto-command to maximize the width of your NERDTree window when opened: ``` autocmd FileType nerdtree let b:NERDTreeZoomed = 1 | wincmd | ``` Alternatively, you can consider increasing the width of the window by setting the `g:NERDTreeWinSize` variable to a higher value (defaults to 30), you ...
20,620
<p>In visual studio, that code :</p> <pre><code>for(int x=0;x&lt;10;x++) {} </code></pre> <p>becomes that code :</p> <pre><code>for (int x = 0; x &lt; 10; x++) { } </code></pre> <p>as soon as you hit enter. I was wondering, is it possible, and if so, how can I make so vim does the same ?</p> <p>Thanks in advance ...
[ { "answer_id": 20623, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 1, "selected": false, "text": "<p>Try <code>normal A</code> in your autocommand</p>\n" }, { "answer_id": 20625, "author": "filbranden...
2019/07/15
[ "https://vi.stackexchange.com/questions/20620", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23021/" ]
In visual studio, that code : ``` for(int x=0;x<10;x++) {} ``` becomes that code : ``` for (int x = 0; x < 10; x++) { } ``` as soon as you hit enter. I was wondering, is it possible, and if so, how can I make so vim does the same ? Thanks in advance !
TL;DR: You can use this auto-command to maximize the width of your NERDTree window when opened: ``` autocmd FileType nerdtree let b:NERDTreeZoomed = 1 | wincmd | ``` Alternatively, you can consider increasing the width of the window by setting the `g:NERDTreeWinSize` variable to a higher value (defaults to 30), you ...
20,634
<p>I want to create a command that will place my gvim window to a different "x" location on my screen while maintaining the "y" position.</p> <p>I do this in my _gvimrc by calling</p> <pre><code>winpos 319 16 </code></pre> <p>I want to create a function <code>WinRight</code> that will put my window on the right side...
[ { "answer_id": 20635, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 3, "selected": true, "text": "<p>Use <a href=\"https://vimhelp.org/eval.txt.html#%3Aexecute\" rel=\"nofollow noreferrer\"><code>:execute</code></a> ...
2019/07/16
[ "https://vi.stackexchange.com/questions/20634", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23033/" ]
I want to create a command that will place my gvim window to a different "x" location on my screen while maintaining the "y" position. I do this in my \_gvimrc by calling ``` winpos 319 16 ``` I want to create a function `WinRight` that will put my window on the right side of the screen, but this doesn't work: ```...
Use [`:execute`](https://vimhelp.org/eval.txt.html#%3Aexecute) to assemble a command from a string, which allows you to include the contents of a variable or return value from a function. This should work: ``` function! WinRight() let ypos=getwinposy() execute "winpos 1241 ".ypos endfunction ``` Or even: `...
20,642
<p>I've got a pretty large log file with some info interleaved with some errors / warnings and I would like to go to the next error in my quickfix window but without jumping to that location in the code.</p> <p>At the moment I've got a dirty hack that basically consist in doing <code>:cnext &lt;C-o&gt;</code> but that...
[ { "answer_id": 20647, "author": "dedowsdi", "author_id": 5017, "author_profile": "https://vi.stackexchange.com/users/5017", "pm_score": 2, "selected": false, "text": "<pre><code>function! s:next_error()\n let wv = winsaveview()\n keepjumps cnext\n call winrestview(wv)\n copen\nendfun...
2019/07/17
[ "https://vi.stackexchange.com/questions/20642", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23048/" ]
I've got a pretty large log file with some info interleaved with some errors / warnings and I would like to go to the next error in my quickfix window but without jumping to that location in the code. At the moment I've got a dirty hack that basically consist in doing `:cnext <C-o>` but that's not ideal. Any cleaner ...
``` function! s:next_error() let wv = winsaveview() keepjumps cnext call winrestview(wv) copen endfunction ``` the only problem of your approach is that it changed the [:h jumplist](https://vimhelp.org/motion.txt.html#jumplist) , you can use [:h :keepjumps](https://vimhelp.org/motion.txt.html#%3Akeepjumps) to...
20,644
<p>new VIM user. I'm trying to make creating python properties easier for my class definitions. What I would like for say I type</p> <p><code>:pyp x</code></p> <p>then VIM will autofill where my cursor is </p> <pre><code>@property def x(self): return self.x @property.setter def x(self,val): self._x = val...
[ { "answer_id": 20647, "author": "dedowsdi", "author_id": 5017, "author_profile": "https://vi.stackexchange.com/users/5017", "pm_score": 2, "selected": false, "text": "<pre><code>function! s:next_error()\n let wv = winsaveview()\n keepjumps cnext\n call winrestview(wv)\n copen\nendfun...
2019/07/17
[ "https://vi.stackexchange.com/questions/20644", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23052/" ]
new VIM user. I'm trying to make creating python properties easier for my class definitions. What I would like for say I type `:pyp x` then VIM will autofill where my cursor is ``` @property def x(self): return self.x @property.setter def x(self,val): self._x = val ``` or more abstractly I type `:pyp...
``` function! s:next_error() let wv = winsaveview() keepjumps cnext call winrestview(wv) copen endfunction ``` the only problem of your approach is that it changed the [:h jumplist](https://vimhelp.org/motion.txt.html#jumplist) , you can use [:h :keepjumps](https://vimhelp.org/motion.txt.html#%3Akeepjumps) to...
20,658
<p>The question's title might sound a little vague, so I'll explain the situation here more clearly. I have these lines of code in a file which I want to align with respect to the character <code>=</code>.</p> <pre><code>const service = require('./service'); const baseService = require('./baseService'); const config =...
[ { "answer_id": 20660, "author": "dedowsdi", "author_id": 5017, "author_profile": "https://vi.stackexchange.com/users/5017", "pm_score": 2, "selected": false, "text": "<p>Install <a href=\"https://github.com/junegunn/vim-easy-align\" rel=\"nofollow noreferrer\">vim-easy-align</a>, assume ...
2019/07/18
[ "https://vi.stackexchange.com/questions/20658", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/22982/" ]
The question's title might sound a little vague, so I'll explain the situation here more clearly. I have these lines of code in a file which I want to align with respect to the character `=`. ``` const service = require('./service'); const baseService = require('./baseService'); const config = require('../config'); co...
If you're in a pinch and want to get the expressions aligned, without having to install and learn any plug-ins, here is a quick way to do it. 1. Select the lines on a visual selection. For example, if this is your whole buffer, you could use `ggVG`, but if these lines are in the middle of a file, just select appropria...
20,659
<p>I have a git repository: <code>~/home/foo/repo</code></p> <p>I mounted core to another directory:</p> <p><code>mount --bind ~/home/foo/repo ~/home/bar</code></p> <p>Now I want to edit my code with vim and use vim-fugitive. <code>vim ~/home/bar/myCode.txt; :Gblame</code></p>
[ { "answer_id": 20671, "author": "Yasen", "author_id": 22724, "author_profile": "https://vi.stackexchange.com/users/22724", "pm_score": 2, "selected": false, "text": "<p>According to <a href=\"https://github.com/tpope/vim-fugitive/blob/master/autoload/fugitive.vim\" rel=\"nofollow norefer...
2019/07/18
[ "https://vi.stackexchange.com/questions/20659", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23065/" ]
I have a git repository: `~/home/foo/repo` I mounted core to another directory: `mount --bind ~/home/foo/repo ~/home/bar` Now I want to edit my code with vim and use vim-fugitive. `vim ~/home/bar/myCode.txt; :Gblame`
According to [vim-fugitive sources](https://github.com/tpope/vim-fugitive/blob/master/autoload/fugitive.vim), you can use Fugitive commands for any file that belongs to git index. E.g. ```sh cd ~ vim ~/home/foo/repo/README.md # works vim ~/home/bar/README.md # works too ```
20,677
<p>Based on the accepted answer of the following post <a href="https://vi.stackexchange.com/questions/688/how-to-add-permanent-line-numbers-to-a-file/818#818">How to add permanent line numbers to a file?</a></p> <p>I would like to have the capacity to select a certain number of lines and add numbers to those particula...
[ { "answer_id": 20671, "author": "Yasen", "author_id": 22724, "author_profile": "https://vi.stackexchange.com/users/22724", "pm_score": 2, "selected": false, "text": "<p>According to <a href=\"https://github.com/tpope/vim-fugitive/blob/master/autoload/fugitive.vim\" rel=\"nofollow norefer...
2019/07/20
[ "https://vi.stackexchange.com/questions/20677", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23093/" ]
Based on the accepted answer of the following post [How to add permanent line numbers to a file?](https://vi.stackexchange.com/questions/688/how-to-add-permanent-line-numbers-to-a-file/818#818) I would like to have the capacity to select a certain number of lines and add numbers to those particular lines only. Also I ...
According to [vim-fugitive sources](https://github.com/tpope/vim-fugitive/blob/master/autoload/fugitive.vim), you can use Fugitive commands for any file that belongs to git index. E.g. ```sh cd ~ vim ~/home/foo/repo/README.md # works vim ~/home/bar/README.md # works too ```
20,680
<p>I want to set up a shortcut to make word under the cursor upper case in the command mode. I know that you can get the word under the cursor with <code>expand("&lt;cword&gt;")</code>. But I am not sure how do I translate it to upper case the then replace the original word in command mode, because <code>U</code>, <co...
[ { "answer_id": 20682, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 3, "selected": false, "text": "<p>Rather than make a mapping (particularly over top of the helpful <code>&lt;C-u&gt;</code> kill-line), I suggest...
2019/07/20
[ "https://vi.stackexchange.com/questions/20680", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/15292/" ]
I want to set up a shortcut to make word under the cursor upper case in the command mode. I know that you can get the word under the cursor with `expand("<cword>")`. But I am not sure how do I translate it to upper case the then replace the original word in command mode, because `U`, `~` will not work in command mode. ...
Assuome current command : ``` echo "hello world" ^ ``` `^` marks current cursor, after `upcase current word`, it becomes: ``` echo "HELLO world" ^ ``` The key part is to split your command into 3 parts: ``` echo "hello world" --1----^ ---3----- ---2-- ``` This can be ...
20,697
<p>Let's say I have this text with <code>|</code> as my cursor: </p> <pre><code>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD hi ======= hello ====== &gt;&gt;&gt;&gt;&gt;&gt; XXXX GGg| </code></pre> <p>Now, I'd like to select from >>>> to say second=== or line containing &lt;&lt;&lt;&lt; word. How do I do that?</p>
[ { "answer_id": 20698, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 0, "selected": false, "text": "<p>You better be more clear|specific...</p>\n\n<blockquote>\n <p>Now, I'd like to select from >>>> to say second===</p>...
2019/07/22
[ "https://vi.stackexchange.com/questions/20697", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10062/" ]
Let's say I have this text with `|` as my cursor: ``` <<<<<<< HEAD hi ======= hello ====== >>>>>> XXXX GGg| ``` Now, I'd like to select from >>>> to say second=== or line containing <<<< word. How do I do that?
To answer your question in a more general way, you can combine the visual mode with any motion you use in normal mode. That means that you can use `f`, `t`, `w`, etc but you can also use the search: In your case with your cursor after `GGg` you can start reverse search mode with `?` and type `<` in your search prompt....
20,704
<p>I have the following line in my code:</p> <pre><code>INCORRECT_EMAIL_MOBILE_COMBINATION("incorrect_email_mobile_combination"); </code></pre> <p>When I try to substitute the underscores with spaces in visual mode (using <code>:'&lt;,'&gt;s/_/ /g</code>), vim substitutes all underscores in the line. </p> <p>How do ...
[ { "answer_id": 20705, "author": "Doktor OSwaldo", "author_id": 11316, "author_profile": "https://vi.stackexchange.com/users/11316", "pm_score": 2, "selected": false, "text": "<p>You could also just match on uppercase characters:</p>\n\n<pre><code>:s/\\L\\zs_//g\n</code></pre>\n\n<p>or ma...
2019/07/23
[ "https://vi.stackexchange.com/questions/20704", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/11044/" ]
I have the following line in my code: ``` INCORRECT_EMAIL_MOBILE_COMBINATION("incorrect_email_mobile_combination"); ``` When I try to substitute the underscores with spaces in visual mode (using `:'<,'>s/_/ /g`), vim substitutes all underscores in the line. How do I replace the underscores just within the quotes?
*Yes, this is a long answer. That's because I try to cover the sometimes intimidating sub-replace expression as clearly as I can. Don't be frightened...please dive in!* :) This can be looked at as a search-replace where the search is multi-level or nested. That is, first you need to match part of the line (i.e. quoted...
20,708
<p>I use both <a href="https://github.com/w0rp/ale/" rel="nofollow noreferrer">Ale</a> and VIM <a href="https://github.com/rkitover/vimpager" rel="nofollow noreferrer">pager</a> plugins. But for obvious reasons I want to disable some Vim features and plugins in the "less" mode.</p> <p>But if I put as recommended this ...
[ { "answer_id": 20705, "author": "Doktor OSwaldo", "author_id": 11316, "author_profile": "https://vi.stackexchange.com/users/11316", "pm_score": 2, "selected": false, "text": "<p>You could also just match on uppercase characters:</p>\n\n<pre><code>:s/\\L\\zs_//g\n</code></pre>\n\n<p>or ma...
2019/07/23
[ "https://vi.stackexchange.com/questions/20708", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1515/" ]
I use both [Ale](https://github.com/w0rp/ale/) and VIM [pager](https://github.com/rkitover/vimpager) plugins. But for obvious reasons I want to disable some Vim features and plugins in the "less" mode. But if I put as recommended this piece of code in my `.vimrc` it still starts Ale: ``` if exists('g:vimpager.enabled...
*Yes, this is a long answer. That's because I try to cover the sometimes intimidating sub-replace expression as clearly as I can. Don't be frightened...please dive in!* :) This can be looked at as a search-replace where the search is multi-level or nested. That is, first you need to match part of the line (i.e. quoted...
20,727
<p>Say I've done the command:</p> <pre><code>:g/^.\{1,50\}$/m$ </code></pre> <p>To move all lines with 50 or less characters to the bottom of the file.</p> <p>Then I realise I actually didn't want to do that for the whole file, but for example a paragraph (or for any visually selected lines). I then do <code>u</code...
[ { "answer_id": 20728, "author": "Dmitry Koroliov", "author_id": 2798, "author_profile": "https://vi.stackexchange.com/users/2798", "pm_score": 1, "selected": false, "text": "<p>first of all, you can't do it in general for <em>any</em> visual selection, since the ex commands operate on li...
2019/07/25
[ "https://vi.stackexchange.com/questions/20727", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/21062/" ]
Say I've done the command: ``` :g/^.\{1,50\}$/m$ ``` To move all lines with 50 or less characters to the bottom of the file. Then I realise I actually didn't want to do that for the whole file, but for example a paragraph (or for any visually selected lines). I then do `u` and `vip` to select the paragraph I want t...
My preferred solution is 1. Select your paragraph `vip` 2. Hit `:` and then `<C-f>` OR press `q:` 3. Move up to your `:g` command and do `I'<,'>`, then `Esc`, then `<CR>`. As mentioned in the comments, it might be handy to map this: ``` xnoremap <Leader>. q:<UP>I'<,'><Esc>$ ```
20,730
<p>strlen(var) can return length without leading zeros.<br> How to include leading zeros?<br> Example <code>let var=0x00001234</code>, width shall be 8 instead of 4.</p>
[ { "answer_id": 20731, "author": "ruohola", "author_id": 21062, "author_profile": "https://vi.stackexchange.com/users/21062", "pm_score": 0, "selected": false, "text": "<p>This isn't possible with hexadecimal (or decimal) numbers, since <code>0x0001234</code> is actually just <code>0x1234...
2019/07/25
[ "https://vi.stackexchange.com/questions/20730", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13402/" ]
strlen(var) can return length without leading zeros. How to include leading zeros? Example `let var=0x00001234`, width shall be 8 instead of 4.
In VimScript variables have (dynamic) types. After `let var=0x00001234` the variable's value is a number `4660`. `strlen()` silently converts number `4660` into a string `"4660"`, therefore the "string length" is 4. You can use explicit typecasts: ``` let varstring = "00001234" let varnumber = str2nr(var, 16) echo va...
20,753
<p>In putting together and addon for blender to integrate <code>neovim</code>.</p> <p><a href="https://i.stack.imgur.com/B0uM7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B0uM7.png" alt="enter image description here"></a> <em>Where I'm at with it, github colo imported to blender text editor from...
[ { "answer_id": 20755, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 1, "selected": false, "text": "<p>I don't know about any plugins for this but it should be easy to code up lookup tables for the other codes.</p>\n\n<p...
2019/07/27
[ "https://vi.stackexchange.com/questions/20753", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4545/" ]
In putting together and addon for blender to integrate `neovim`. [![enter image description here](https://i.stack.imgur.com/B0uM7.png)](https://i.stack.imgur.com/B0uM7.png) *Where I'm at with it, github colo imported to blender text editor from nvim\_gtk* One component is grabbing the current colorscheme of a running...
Consider using the [`synIDattr()`](https://vimhelp.org/eval.txt.html#synIDattr%28%29) function, which can take special attributes such as `fg#` and `bg#` to return RGB for attributes, when a GUI is running. ``` "fg#" like "fg", but for the GUI and the GUI is running the name in "#RRGGBB" form "bg#" like "f...
20,754
<p>I'm writing a function to execute an external command using visual selection. I've noticed that if by mistake the entire line is selected, including the new line char the extra <code>^@</code> character makes the shell command to fail:</p> <pre><code>Error detected while processing function &lt;SNR&gt;20_BitwiseOpe...
[ { "answer_id": 20758, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 2, "selected": false, "text": "<p>The <code>^@</code> you're referring to is actually a newline character, so the problem you describe will happen w...
2019/07/27
[ "https://vi.stackexchange.com/questions/20754", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/496/" ]
I'm writing a function to execute an external command using visual selection. I've noticed that if by mistake the entire line is selected, including the new line char the extra `^@` character makes the shell command to fail: ``` Error detected while processing function <SNR>20_BitwiseOperator: line 18: E485: Can't r...
In the end, I ended up trimming the newline charachter using search/replace. ``` substitute(a:string, '\n\+$', '', '') ```
20,760
<p>How do you create a binding that behaves like yy but doesn't yank the leading white spaces?</p> <pre><code>nnoremap &lt;leader&gt;f ^v$y </code></pre> <p>Yanks one line and the ^J. Which is what I want but how do I add a [count] to do mulitple lines? </p>
[ { "answer_id": 20762, "author": "perelo", "author_id": 22929, "author_profile": "https://vi.stackexchange.com/users/22929", "pm_score": 2, "selected": false, "text": "<p>Your mapping is tricky because you don't want to yank the leading whitespaces. You cannot simply <a href=\"https://vim...
2019/07/28
[ "https://vi.stackexchange.com/questions/20760", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/22837/" ]
How do you create a binding that behaves like yy but doesn't yank the leading white spaces? ``` nnoremap <leader>f ^v$y ``` Yanks one line and the ^J. Which is what I want but how do I add a [count] to do mulitple lines?
Your mapping is tricky because you don't want to yank the leading whitespaces. You cannot simply [supply a count to your map](https://vim.fandom.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_2)#Supplying_a_count_to_a_map) as you would do [for an operator](https://vi.stackexchange.com/questions/2543/how-can-i-map-dcount...
20,787
<p>When typing a report, we have a large list of acronyms defined in <code>Acronyms.tex</code>. In order to use it, we have to encapsulate an acronym such as <code>KDF</code> with the acronym command: <code>\ac{KDF}</code>. I often forget and find it rather cumbersome to type it every time.</p> <p>I'm pretty sure I've...
[ { "answer_id": 20788, "author": "Luc", "author_id": 14459, "author_profile": "https://vi.stackexchange.com/users/14459", "pm_score": 2, "selected": false, "text": "<p>After some searching, it turns out that <a href=\"https://vi.stackexchange.com/a/20443/14459\">single character replaceme...
2019/08/01
[ "https://vi.stackexchange.com/questions/20787", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/14459/" ]
When typing a report, we have a large list of acronyms defined in `Acronyms.tex`. In order to use it, we have to encapsulate an acronym such as `KDF` with the acronym command: `\ac{KDF}`. I often forget and find it rather cumbersome to type it every time. I'm pretty sure I've seen auto-replacing in Vim, without using ...
> > I just noticed a disadvantage > > > That's because you're trying to remap *a command*. While "auto-replacements" in Vim are supposed to be done with *abbreviations* (see `:help abbreviations`). You can create an abbreviation like that: ``` :inoreabbrev KDF \ac{KDF} ``` Unlike commands, the abbreviations ar...
20,797
<p>Inside a function, saved multiple lines of external command output to a variable.<br> How to delete a line from the variable? Like first line. </p> <p>I can run <code>let tmp = split(variable, "\n")</code> to assign the variable to a tmp list, then delete an item. Not sure if there is any easy way.</p>
[ { "answer_id": 20798, "author": "perelo", "author_id": 22929, "author_profile": "https://vi.stackexchange.com/users/22929", "pm_score": 1, "selected": true, "text": "<p>You may try this <code>substitute</code> command to delete, e.g the 3rd line</p>\n\n<pre><code>substitute(var, '\\v^((....
2019/08/02
[ "https://vi.stackexchange.com/questions/20797", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13402/" ]
Inside a function, saved multiple lines of external command output to a variable. How to delete a line from the variable? Like first line. I can run `let tmp = split(variable, "\n")` to assign the variable to a tmp list, then delete an item. Not sure if there is any easy way.
You may try this `substitute` command to delete, e.g the 3rd line ``` substitute(var, '\v^((.{-}\n){2}).{-}\n(.*)', '\1\3', '') ``` The regex works as follows * `^((.{-}\n){2})` matches the first `2` lines and capture it in group `\1` * `.{-}\n` matches the next line * `(.*)` matches the rest of the variable and ca...
20,814
<p>In vim plugin 'tpope/vim-speeddating', it support wide variaty of date formats. e.g.</p> <pre><code> %Y-%m-%d%[ T_-]%H:%M 2019-08-04 07:42 %Y-%m-%d 2019-08-04 </code></pre> <p>But how to add my custom data formats, e.g.</p> <pre><code> %Y/%m/%d 2019/08/...
[ { "answer_id": 20816, "author": "Rohan Ghige", "author_id": 20720, "author_profile": "https://vi.stackexchange.com/users/20720", "pm_score": 0, "selected": false, "text": "<p>Write these lines in your ~/.vimrc</p>\n\n<pre><code>au BufEnter * :SpeedDatingFormat %Y/%m/%d\nau BufEnter * :Sp...
2019/08/04
[ "https://vi.stackexchange.com/questions/20814", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/20720/" ]
In vim plugin 'tpope/vim-speeddating', it support wide variaty of date formats. e.g. ``` %Y-%m-%d%[ T_-]%H:%M 2019-08-04 07:42 %Y-%m-%d 2019-08-04 ``` But how to add my custom data formats, e.g. ``` %Y/%m/%d 2019/08/04 %Y/%m ...
According to the documentation: (`help speeddating`) > > One can use the `:SpeedDatingFormat` command to list, add, and remove formats. A good place to place custom formats is in `.vim/after/plugin/speeddating.vim` > > > For the formats you listed: ``` SpeedDatingFormat %Y/%m/%d SpeedDatingFormat %Y/%m ```
20,828
<p>I've mapped 'L' and 'H' to change buffers in vim. I often end up hitting these keys in NERDTree and Tagbar.</p> <p>I'm able to use <code>NERDTreeAddKeyMap</code> to make NERDTree ignore keys. Tagbar only allows the use of <code>g:tagbar_map_.*</code> to <em>replace</em> key bindings that exist.</p> <p>Is there a w...
[ { "answer_id": 20829, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 0, "selected": false, "text": "<p>You can easily do this with <code>&lt;buffer&gt;</code>-specific mappings. Like this:</p>\n\n<pre><code>autocmd FileType...
2019/08/06
[ "https://vi.stackexchange.com/questions/20828", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23304/" ]
I've mapped 'L' and 'H' to change buffers in vim. I often end up hitting these keys in NERDTree and Tagbar. I'm able to use `NERDTreeAddKeyMap` to make NERDTree ignore keys. Tagbar only allows the use of `g:tagbar_map_.*` to *replace* key bindings that exist. Is there a way I can make 'H' and 'L' do nothing in the Ta...
You can use a `FileType` `autocmd` and map those keys to [`<Nop>`](http://vimdoc.sourceforge.net/htmldoc/map.html#%3CNop%3E): ``` augroup TagBar autocmd! autocmd FileType tagbar nnoremap <buffer> H <Nop> autocmd FileType tagbar nnoremap <buffer> L <Nop> augroup END ``` Also always remember to [enclose yo...
20,850
<p>I would like to get these line numbers of a different window without moving to that window.</p> <pre><code>line('w0') line('w$') line('.') line('$') </code></pre> <p>As for the first two, we can use <code>getwininfo([{winid}])</code> which returns a list including 'topline' and 'botline'. Is there any function or ...
[ { "answer_id": 20851, "author": "ruohola", "author_id": 21062, "author_profile": "https://vi.stackexchange.com/users/21062", "pm_score": 0, "selected": false, "text": "<p>I'm personally using <a href=\"https://github.com/maralla/completor.vim\" rel=\"nofollow noreferrer\">https://github....
2019/08/08
[ "https://vi.stackexchange.com/questions/20850", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1641/" ]
I would like to get these line numbers of a different window without moving to that window. ``` line('w0') line('w$') line('.') line('$') ``` As for the first two, we can use `getwininfo([{winid}])` which returns a list including 'topline' and 'botline'. Is there any function or some workaround as for the last two?
If you're looking for a super simple solution, you can add the code from this page to your .vimrc. <https://gist.github.com/maxboisvert/a63e96a67d0a83d71e9f49af73e71d93> There is also a plugin version of it which can be found here. <https://github.com/maxboisvert/vim-simple-complete>
20,856
<p>I am using SpaceVim as Ruby on Rails IDE and installed the tpope/vim-rails plugin.</p> <p>Commands such as <code>:Econtroller</code>, <code>:Emodel</code> and <code>:find</code> are working just fine, but the <code>gf</code> command provided by this plugin is not working in SpaceVim.</p> <p>When I try to use it, i...
[ { "answer_id": 21479, "author": "Wang Shidong", "author_id": 7942, "author_profile": "https://vi.stackexchange.com/users/7942", "pm_score": -1, "selected": false, "text": "<p>You can check <code>:map gf</code>, it will tell you what this key is mapped to. </p>\n" }, { "answer_id...
2019/08/08
[ "https://vi.stackexchange.com/questions/20856", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23337/" ]
I am using SpaceVim as Ruby on Rails IDE and installed the tpope/vim-rails plugin. Commands such as `:Econtroller`, `:Emodel` and `:find` are working just fine, but the `gf` command provided by this plugin is not working in SpaceVim. When I try to use it, it shows me an error message such as the ones below: ``` # fo...
I have exactly the same problem. It seems that SpaceVim overrides the `gf` command in some way so that `rails-vim` plugin's `gf` doesn't check for `_` on partial names anymore. Also, you have to be on the partial name itself (instead of anywhere on the same line, thanks to `vim-ruby` plugin) for `gf` to work. So maybe ...
20,863
<p>Is there a way to use a register or visual selection for search and replace? I have some longer sequence of words that are used repeatedly in my script. I want to replace them all but want to avoid typing a long sentence in a command line. If I can select them in visual mode or yank them in a buffer, and utilize it...
[ { "answer_id": 20864, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<p>One possible solution is to use what I call <em>register recall</em>: on the <code>:</code>-command line, <kbd>...
2019/08/09
[ "https://vi.stackexchange.com/questions/20863", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23342/" ]
Is there a way to use a register or visual selection for search and replace? I have some longer sequence of words that are used repeatedly in my script. I want to replace them all but want to avoid typing a long sentence in a command line. If I can select them in visual mode or yank them in a buffer, and utilize it in...
One possible solution is to use what I call *register recall*: on the `:`-command line, `Ctrl`-`r` followed by any of the registers (the named ones, like `a` or `3`, or the others, such as `-` or `"`) will insert the contents of said register. (This works in insert mode as well.) So you could 1. Yank the text 2. Su...
20,867
<p>I am trying to figure out how to open a specific vimwiki diary on opening vim. With one wiki I use an alias like <code>alias todo='vim -c VimwikiDiaryIndex'</code> which works perfectly.</p> <p>But now I want an additional diary wiki for another set of notes. I already added the path and can change the diary inside...
[ { "answer_id": 20868, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": true, "text": "<p>I'm guessing here but it seems you are trying to run normal mode mappings in batch mode (IOW, <code>vim -c &lt;cmd&gt;...
2019/08/09
[ "https://vi.stackexchange.com/questions/20867", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23345/" ]
I am trying to figure out how to open a specific vimwiki diary on opening vim. With one wiki I use an alias like `alias todo='vim -c VimwikiDiaryIndex'` which works perfectly. But now I want an additional diary wiki for another set of notes. I already added the path and can change the diary inside of vim with `2<Leade...
I'm guessing here but it seems you are trying to run normal mode mappings in batch mode (IOW, `vim -c <cmd>`). Your `2wi` ... I'm assuming that refers to `[count]<Leader>wi`, a VimWiki mapped command in the docs...? To run such mappings you need to use the `norm` command (`:h :norm`). For example, `vim -c 'norm 2\wi...
20,875
<p>I'm trying to make a function in vimscript that converts markdown to html files using pandoc and putting that converted file in a specified directory. Currently i am putting the file in a directory relative to the original markdown file's path using <code>expand('%:p:h')</code> and appending a new directory</p> <p>...
[ { "answer_id": 20876, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p><em>Rather than take a direct approach to \"inserting text in the middle of a string\" I'd suggest something a bit mor...
2019/08/11
[ "https://vi.stackexchange.com/questions/20875", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/22309/" ]
I'm trying to make a function in vimscript that converts markdown to html files using pandoc and putting that converted file in a specified directory. Currently i am putting the file in a directory relative to the original markdown file's path using `expand('%:p:h')` and appending a new directory So if my markdown fil...
*Rather than take a direct approach to "inserting text in the middle of a string" I'd suggest something a bit more robust (and a bit more complex). It allows you to, say, change the root directory path or the converted file directory name in a straightforward way if you need to in the future. With a straight string man...
20,882
<p>Here is what I am doing now:</p> <pre><code>vim + $1 -c "set titlestring=$title guioptions-=m guioptions-=r lines=66 columns=239" -c ":source .vim_map" -c "sp .help.txt" -c ":wincmd j" </code></pre> <p>I would like to open the <strong>.help.txt</strong> in split window but as <em>read-only</em> where the other fil...
[ { "answer_id": 20876, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 3, "selected": true, "text": "<p><em>Rather than take a direct approach to \"inserting text in the middle of a string\" I'd suggest something a bit mor...
2019/08/13
[ "https://vi.stackexchange.com/questions/20882", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23378/" ]
Here is what I am doing now: ``` vim + $1 -c "set titlestring=$title guioptions-=m guioptions-=r lines=66 columns=239" -c ":source .vim_map" -c "sp .help.txt" -c ":wincmd j" ``` I would like to open the **.help.txt** in split window but as *read-only* where the other file (the $1 as it is in the script) to be writab...
*Rather than take a direct approach to "inserting text in the middle of a string" I'd suggest something a bit more robust (and a bit more complex). It allows you to, say, change the root directory path or the converted file directory name in a straightforward way if you need to in the future. With a straight string man...
20,883
<p>I am trying to remap my <code>hjkl</code> keys to <code>jklö</code>. this is not a problem in most simple cases, but with commands like <code>&lt;C-w&gt;h</code> where you can specify an amount in the form of <code>&lt;C-w&gt;{count}h</code> or <code>{count}&lt;C-w&gt;h</code> this doesn't seem to work.</p> <p>is t...
[ { "answer_id": 20889, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 0, "selected": false, "text": "<p>Note that the correct way to type this command is <code>{count}&lt;C-w&gt;h</code>, with the <code>{count}</code> ...
2019/08/13
[ "https://vi.stackexchange.com/questions/20883", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23379/" ]
I am trying to remap my `hjkl` keys to `jklö`. this is not a problem in most simple cases, but with commands like `<C-w>h` where you can specify an amount in the form of `<C-w>{count}h` or `{count}<C-w>h` this doesn't seem to work. is there some way of doing a mapping like ``` nn <C-w>{count}j <C-w>{count}h ```
what worked for me was to use langmap. ``` set langmap=jklöJKLé;hjlkHJKL ``` this remaps the keys for all commands
20,896
<p>For example, lets say I have a line like:</p> <blockquote> <p>Hello, this should be bold.</p> </blockquote> <p>Then is there any way to change one or more words to be bold, so it will appear on the screen as:</p> <blockquote> <p>Hello, this should be <strong>bold</strong>.</p> </blockquote> <p>For example, i...
[ { "answer_id": 20897, "author": "Maxim Kim", "author_id": 9333, "author_profile": "https://vi.stackexchange.com/users/9333", "pm_score": 2, "selected": false, "text": "<p>Well, it is not that simple.</p>\n\n<p>What you can come up with -- use syntax definitions. But this bold text you wi...
2019/08/14
[ "https://vi.stackexchange.com/questions/20896", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23393/" ]
For example, lets say I have a line like: > > Hello, this should be bold. > > > Then is there any way to change one or more words to be bold, so it will appear on the screen as: > > Hello, this should be **bold**. > > > For example, in some text editors I can select a word and press a "bold" button, and the...
Well, it is not that simple. What you can come up with -- use syntax definitions. But this bold text you will create would be temporary, it will not be saved with your file like word processing software does. So to the code. ``` func! RegionMakeBold() hi MyBold gui=bold let l_start = getpos("'<")[1] let l_end ...
20,900
<p>I have an error report where often the known errors are in the top few thousand lines, formatting issue rather than quantity unfortunately.</p> <p>I want to run <code>:g/pattern/</code> from the end of the file.</p> <p>I know <code>:g/pattern/m0</code> reverses the file which is mainly the same thing but if I don'...
[ { "answer_id": 20909, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<p>The simplest idea is to filter</p>\n\n<pre><code>:v/pattern/d\n</code></pre>\n\n<p>And then <code>u</code>ndo w...
2019/08/15
[ "https://vi.stackexchange.com/questions/20900", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1313/" ]
I have an error report where often the known errors are in the top few thousand lines, formatting issue rather than quantity unfortunately. I want to run `:g/pattern/` from the end of the file. I know `:g/pattern/m0` reverses the file which is mainly the same thing but if I don't put it back to how it was the line re...
The simplest idea is to filter ``` :v/pattern/d ``` And then `u`ndo when you want the whole file back.
20,917
<p>There is VIM's default bar below my Airline's status bar, which causes file information to be viewed twice (as shown in the image). How can I move my airline's bar to the bottom? I have tried adding <code>set noshowmode</code> but it didn't slove my problem.</p> <p><a href="https://i.stack.imgur.com/YW4Mw.png" rel=...
[ { "answer_id": 20909, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<p>The simplest idea is to filter</p>\n\n<pre><code>:v/pattern/d\n</code></pre>\n\n<p>And then <code>u</code>ndo w...
2019/08/17
[ "https://vi.stackexchange.com/questions/20917", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/15848/" ]
There is VIM's default bar below my Airline's status bar, which causes file information to be viewed twice (as shown in the image). How can I move my airline's bar to the bottom? I have tried adding `set noshowmode` but it didn't slove my problem. [![enter image description here](https://i.stack.imgur.com/YW4Mw.png)](...
The simplest idea is to filter ``` :v/pattern/d ``` And then `u`ndo when you want the whole file back.
20,924
<p>I have mapped my <kbd>F5</kbd> key in vimrc file to run the code using the following command:</p> <p><code>map &lt;F5&gt; :!sh -xc 'cd "/home/hashir/vscode/" &amp;&amp; g++ test.cpp &amp;&amp; ./a.out</code></p> <p>It is working well. But it only runs for <code>test.cpp</code> file. I want to make it generic by in...
[ { "answer_id": 20925, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>Use \"Ex special characters\" <a href=\"https://vimhelp.org/cmdline.txt.html#cmdline-special\" rel=\"nofollow norefer...
2019/08/17
[ "https://vi.stackexchange.com/questions/20924", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/15848/" ]
I have mapped my `F5` key in vimrc file to run the code using the following command: `map <F5> :!sh -xc 'cd "/home/hashir/vscode/" && g++ test.cpp && ./a.out` It is working well. But it only runs for `test.cpp` file. I want to make it generic by inserting the name of my current file. Is there any way of doing this?
You can use `%` to expand to the current filename. See [`:help :!`](https://vimhelp.org/various.txt.html#%3A%21), which goes into quite some level of detail about that! > > If `{cmd}` contains `%` it is expanded to the current file name. Special characters are not escaped, use quotes to avoid their special meaning: ...
20,941
<p>Editing large HTML file. Would like to do something like:</p> <pre><code>:/&lt;blockquote&gt;/,/&lt;\/blockquote&gt;/s/^\(\s\s\+\)\(&lt;[^&gt;].\{-}&gt;\)/\1 \2/g </code></pre> <p>So basically just trying to indent all between the tag lines. I thought this was possible, but perhaps I mangled the syntax.</p> <p...
[ { "answer_id": 20925, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 2, "selected": false, "text": "<p>Use \"Ex special characters\" <a href=\"https://vimhelp.org/cmdline.txt.html#cmdline-special\" rel=\"nofollow norefer...
2019/08/19
[ "https://vi.stackexchange.com/questions/20941", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23470/" ]
Editing large HTML file. Would like to do something like: ``` :/<blockquote>/,/<\/blockquote>/s/^\(\s\s\+\)\(<[^>].\{-}>\)/\1 \2/g ``` So basically just trying to indent all between the tag lines. I thought this was possible, but perhaps I mangled the syntax. Thanks,
You can use `%` to expand to the current filename. See [`:help :!`](https://vimhelp.org/various.txt.html#%3A%21), which goes into quite some level of detail about that! > > If `{cmd}` contains `%` it is expanded to the current file name. Special characters are not escaped, use quotes to avoid their special meaning: ...
20,945
<p>I would like to insert some Python-generated text at the current cursor position in insert mode using the Vim Python interface. The closest I have so far is:</p> <pre><code>imap &lt;c-x&gt;&lt;c-r&gt; &lt;c-o&gt;:python vim.current.line += "trivial example" </code></pre> <p>This will append "trivial example" rathe...
[ { "answer_id": 20946, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 2, "selected": false, "text": "<p>It is generally easier to use pyeval (py3eval, pyxeval) and the expression register:</p>\n\n<pre><code>imap &lt;c-x&gt;&...
2019/08/19
[ "https://vi.stackexchange.com/questions/20945", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23475/" ]
I would like to insert some Python-generated text at the current cursor position in insert mode using the Vim Python interface. The closest I have so far is: ``` imap <c-x><c-r> <c-o>:python vim.current.line += "trivial example" ``` This will append "trivial example" rather than put it at the current position. How c...
It is generally easier to use pyeval (py3eval, pyxeval) and the expression register: ``` imap <c-x><c-r> <c-r>=pyxeval('python expression')<cr> ```
20,958
<p>I installed NeoVim and <code>dense-analysis/ale</code> plugin with <code>vim-plug</code>.</p> <p>All of those seems to be installed, as the commands starting with <code>:ALE</code> autocomplete in NeoVim.</p> <p>Then I tried to install PYLS via</p> <p><code>python3 -m pip install --user python-language-server</co...
[ { "answer_id": 20946, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 2, "selected": false, "text": "<p>It is generally easier to use pyeval (py3eval, pyxeval) and the expression register:</p>\n\n<pre><code>imap &lt;c-x&gt;&...
2019/08/21
[ "https://vi.stackexchange.com/questions/20958", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23494/" ]
I installed NeoVim and `dense-analysis/ale` plugin with `vim-plug`. All of those seems to be installed, as the commands starting with `:ALE` autocomplete in NeoVim. Then I tried to install PYLS via `python3 -m pip install --user python-language-server` and enabled it in my `init.vim` file that you can read here : ...
It is generally easier to use pyeval (py3eval, pyxeval) and the expression register: ``` imap <c-x><c-r> <c-r>=pyxeval('python expression')<cr> ```
20,959
<p>I want to convert nonASCII characters to similar ASCII alternatives. I can do it at shell using <code>echo şİçğ | iconv -f utf-8 -t ascii//translit</code> but how can I do it for selected vim text?</p>
[ { "answer_id": 20960, "author": "perelo", "author_id": 22929, "author_profile": "https://vi.stackexchange.com/users/22929", "pm_score": 2, "selected": false, "text": "<p>For a line-wise operations, you can make a command and mappings :</p>\n\n<pre><code>command! -range Translit &lt;line1...
2019/08/21
[ "https://vi.stackexchange.com/questions/20959", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/21916/" ]
I want to convert nonASCII characters to similar ASCII alternatives. I can do it at shell using `echo şİçğ | iconv -f utf-8 -t ascii//translit` but how can I do it for selected vim text?
You can implement a mapping to translit a visual selection by using the [`system()`](https://vimhelp.org/eval.txt.html#system%28%29) function and passing the contents of the selection as the input to the system command. This mapping should work: ``` xnoremap <leader>T ygv"=system('iconv -f utf-8 -t ascii//translit', ...
21,004
<p>I am using <code>:grep</code> to search for occurences of a string within a set of files:</p> <pre><code>:grep rainbow *.txt </code></pre> <p>This result is then shown in the terminal:</p> <pre><code>doc1.txt:2:saw a rainbow today doc2.txt:17:it was not a black rainbow doc3.txt:7:most of those rainbow unicorns (1...
[ { "answer_id": 21005, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 1, "selected": false, "text": "<p>Well, you need to do a redraw...per <a href=\"https://vimhelp.org/various.txt.html#:!cmd\" rel=\"nofollow noreferrer\...
2019/08/27
[ "https://vi.stackexchange.com/questions/21004", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19712/" ]
I am using `:grep` to search for occurences of a string within a set of files: ``` :grep rainbow *.txt ``` This result is then shown in the terminal: ``` doc1.txt:2:saw a rainbow today doc2.txt:17:it was not a black rainbow doc3.txt:7:most of those rainbow unicorns (1 of 3): saw a rainbow today Press ENTER or type ...
If what you're looking for is a way to automate the sequence of commands (`:silent grep` and `redraw!`), then consider creating a new [user-defined command](https://vimhelp.org/map.txt.html#user-commands) for that operation. (In fact, Vim documentation essentially [recommends it for this particular use case](https://v...
21,028
<h1>Situation</h1> <p>I have a large, hierarchical json file with many single entries, like so:</p> <pre><code> { "tokens": [ "payload, a string" ], "values": [ { "value": "frong zshok blam flarb" } ] }, { ...
[ { "answer_id": 21005, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 1, "selected": false, "text": "<p>Well, you need to do a redraw...per <a href=\"https://vimhelp.org/various.txt.html#:!cmd\" rel=\"nofollow noreferrer\...
2019/08/29
[ "https://vi.stackexchange.com/questions/21028", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23604/" ]
Situation ========= I have a large, hierarchical json file with many single entries, like so: ``` { "tokens": [ "payload, a string" ], "values": [ { "value": "frong zshok blam flarb" } ] }, { "to...
If what you're looking for is a way to automate the sequence of commands (`:silent grep` and `redraw!`), then consider creating a new [user-defined command](https://vimhelp.org/map.txt.html#user-commands) for that operation. (In fact, Vim documentation essentially [recommends it for this particular use case](https://v...
21,032
<p>I found a whole bunch of green <code>^\</code> characters in the file I have open in vim...</p> <p>Any idea what control character they are?</p> <p>And how would I search for them in grep?</p>
[ { "answer_id": 21005, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 1, "selected": false, "text": "<p>Well, you need to do a redraw...per <a href=\"https://vimhelp.org/various.txt.html#:!cmd\" rel=\"nofollow noreferrer\...
2019/08/29
[ "https://vi.stackexchange.com/questions/21032", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/1065/" ]
I found a whole bunch of green `^\` characters in the file I have open in vim... Any idea what control character they are? And how would I search for them in grep?
If what you're looking for is a way to automate the sequence of commands (`:silent grep` and `redraw!`), then consider creating a new [user-defined command](https://vimhelp.org/map.txt.html#user-commands) for that operation. (In fact, Vim documentation essentially [recommends it for this particular use case](https://v...
21,035
<p>I have a shortcut in my vimrc to search for a string through my repository:</p> <pre><code>nnoremap &lt;leader&gt;gg :vimgrep // **/*.py \| clist </code></pre> <p>I want the cursor to be between the <code>//</code> characters ready for a search term when I invoke the shortcut. I can do this with 18 <code>&lt;Left&...
[ { "answer_id": 21005, "author": "B Layer", "author_id": 11054, "author_profile": "https://vi.stackexchange.com/users/11054", "pm_score": 1, "selected": false, "text": "<p>Well, you need to do a redraw...per <a href=\"https://vimhelp.org/various.txt.html#:!cmd\" rel=\"nofollow noreferrer\...
2019/08/30
[ "https://vi.stackexchange.com/questions/21035", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/22557/" ]
I have a shortcut in my vimrc to search for a string through my repository: ``` nnoremap <leader>gg :vimgrep // **/*.py \| clist ``` I want the cursor to be between the `//` characters ready for a search term when I invoke the shortcut. I can do this with 18 `<Left>`s but that is very long and ugly i.e. ``` ... .py...
If what you're looking for is a way to automate the sequence of commands (`:silent grep` and `redraw!`), then consider creating a new [user-defined command](https://vimhelp.org/map.txt.html#user-commands) for that operation. (In fact, Vim documentation essentially [recommends it for this particular use case](https://v...
21,047
<p>If I start with nvim -u NONE , I want to get "-u NONE".</p> <p>I tried to get pid using bash and python, but it seems to return the pid of the process that is created (either python or bash). </p> <p>So how should I do it? </p>
[ { "answer_id": 21048, "author": "eyal karni", "author_id": 18375, "author_profile": "https://vi.stackexchange.com/users/18375", "pm_score": 0, "selected": false, "text": "<p>Sadly, this is what I came up with.</p>\n\n<p>Find the current process, the process parent, and use <code>ps ax</c...
2019/08/30
[ "https://vi.stackexchange.com/questions/21047", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/18375/" ]
If I start with nvim -u NONE , I want to get "-u NONE". I tried to get pid using bash and python, but it seems to return the pid of the process that is created (either python or bash). So how should I do it?
If you're going the Python + `ps` route, then this should be better and more efficient: ``` :pyx import os, subprocess :let vim_cmdline = pyxeval("subprocess.check_output(['ps', '-p', str(os.getpid()), '-o', 'cmd='])") ``` Note that you're checking for the current PID (`os.getpid()`), since the Python interpreter is...
21,054
<p>I have a command-line tool that can print search results in a format that works with vimgrep. The example output looks like this:</p> <pre><code>foo/path/lib/usdviewq/appController.py:3795:22: index = prim.GetPrimIndex() foo/bar/lib/testenv/testUsdSpecializes.py:104:28: refNode = prim.GetPrimIndex...
[ { "answer_id": 21058, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 4, "selected": true, "text": "<p>Vim has a startup option <code>-q</code> to read a quickfix file. So we have options (depending on your shell):<...
2019/08/31
[ "https://vi.stackexchange.com/questions/21054", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16073/" ]
I have a command-line tool that can print search results in a format that works with vimgrep. The example output looks like this: ``` foo/path/lib/usdviewq/appController.py:3795:22: index = prim.GetPrimIndex() foo/bar/lib/testenv/testUsdSpecializes.py:104:28: refNode = prim.GetPrimIndex().rootNode.ch...
Vim has a startup option `-q` to read a quickfix file. So we have options (depending on your shell): ``` cmd > results vim -q results ``` Or my favorite ``` vim -q <(cmd) ```
21,066
<p>Situation: I've typed this:</p> <pre><code>vim foo.js :terminal </code></pre> <p>Now I have one split, a file editing buffer and a terminal.</p> <p>The good: I can quit by closing the terminal first, then the file buffer.</p> <p>The bad: But if I close the file buffer, and then the terminal, vim doesn't exit, bu...
[ { "answer_id": 21069, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 1, "selected": false, "text": "<p>You can create a mapping which will close the terminal buffer directly. Then Vim will not open an additional empty buffe...
2019/09/01
[ "https://vi.stackexchange.com/questions/21066", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23636/" ]
Situation: I've typed this: ``` vim foo.js :terminal ``` Now I have one split, a file editing buffer and a terminal. The good: I can quit by closing the terminal first, then the file buffer. The bad: But if I close the file buffer, and then the terminal, vim doesn't exit, but instead creates a new buffer editing t...
Thanks to @Matt I now know that if I close the terminal buffer myself instead of having the `'term_finish':'close'` argument of `term_start()` do it, then it doesn't do the weird behavior of sometimes opening a different file. So I've `'term_finish':'close'` that with an `exit_cb` that closes the buffer. Here's what ...
21,090
<p>Every now and then I update my ViM configuration, and I would like to have a way to reload everything.</p> <p>I know that I could use</p> <pre><code>:source ~/.vimrc </code></pre> <p>and I could run it similarly for all the modified files. But as vim loads e.g. the system-wide configuration and the content of the...
[ { "answer_id": 21092, "author": "Richard Wonka", "author_id": 23604, "author_profile": "https://vi.stackexchange.com/users/23604", "pm_score": 0, "selected": false, "text": "<p>Are your \"modified files\" not sourced by default of from within .vimrc? </p>\n\n<p>If you add the </p>\n\n<pr...
2019/09/03
[ "https://vi.stackexchange.com/questions/21090", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2170/" ]
Every now and then I update my ViM configuration, and I would like to have a way to reload everything. I know that I could use ``` :source ~/.vimrc ``` and I could run it similarly for all the modified files. But as vim loads e.g. the system-wide configuration and the content of the `~/.vim/` directory, it can be s...
3 options 1. Restart vim (using sessions, e.g., with tpope’s obsession plugin, this isn’t really too bad) 2. Source only your vimrc (if it changed)—you have this 3. Load files with `runtime` (I use `Runtime` from tpope’s scriptease plugin).
21,105
<p>Sometimes when there are a lot of buffers, it becomes hard to see which buffers have been modified using <code>:ls</code>.</p>
[ { "answer_id": 21106, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 4, "selected": true, "text": "<pre><code>:ls +\n</code></pre>\n\n<p>See <a href=\"https://vimhelp.org/windows.txt.html#%3Als\" rel=\"noreferrer\"><c...
2019/09/04
[ "https://vi.stackexchange.com/questions/21105", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/4513/" ]
Sometimes when there are a lot of buffers, it becomes hard to see which buffers have been modified using `:ls`.
``` :ls + ``` See [`:help :ls`](https://vimhelp.org/windows.txt.html#%3Als), you'll see it takes an optional "flags" argument, one of which is: > > `[flags]` can be a combination of the following characters, which restrict the buffers to be listed: > > > * `+`: modified buffers > > >
21,110
<p>Considering the following regex pattern:</p> <pre><code>/\s*&lt;&lt;.\{-}&gt;&gt;/ </code></pre> <p>I want to match those patterns <em>only when the cursor is somewhere on this pattern</em>.</p> <p>So, if have the line (the character enclosed in [] is the cusor position):</p> <pre><code>This is &lt;&lt;on[e]&gt;...
[ { "answer_id": 21112, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 3, "selected": true, "text": "<p>One solution is to use a lookahead before the regex and a lookbehind after the regex. That ensures the cursor is <e...
2019/09/04
[ "https://vi.stackexchange.com/questions/21110", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/21417/" ]
Considering the following regex pattern: ``` /\s*<<.\{-}>>/ ``` I want to match those patterns *only when the cursor is somewhere on this pattern*. So, if have the line (the character enclosed in [] is the cusor position): ``` This is <<on[e]>> and this is <<another one>>. ``` I want to only match `<<one>>`, not...
One solution is to use a lookahead before the regex and a lookbehind after the regex. That ensures the cursor is *after* the start of the match, and *before* the end of the match. One issue with the regex you're using is `.\{-}` which is a non-greedy operator. If you add anchors for the cursor position, this will end ...
21,113
<p>I'm writing a Vim plugin which will need to surround the word directly under your cursor with a quotes. I have tried using simple solutions which use commands like "b" and "e" executed in normal mode, in combination with other cursor position commands, though those felt clunky and non-robust. </p> <p>I wondered if ...
[ { "answer_id": 21116, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 4, "selected": false, "text": "<p>Yes, a plug-in for surrounding with quotes exists! <a href=\"https://github.com/tpope/vim-surround\" rel=\"norefer...
2019/09/04
[ "https://vi.stackexchange.com/questions/21113", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23679/" ]
I'm writing a Vim plugin which will need to surround the word directly under your cursor with a quotes. I have tried using simple solutions which use commands like "b" and "e" executed in normal mode, in combination with other cursor position commands, though those felt clunky and non-robust. I wondered if there was ...
You can surround the word currently under the cursor in quotes with the following normal mode commands: `c``i``w``"``"``Esc``P` Replace `iw` with any other Vim motion/text object to surround other things with quotes\*. Or `""` with any other pair of characters to surround the object with different things. \* Or use ...
21,127
<p>Here's how I restart vim:</p> <pre><code>$ vim :q $ vim </code></pre> <p>Is there a way to restart vim so that there is no need to type the second <code>vim</code> in the shell?</p>
[ { "answer_id": 21128, "author": "user938271", "author_id": 17449, "author_profile": "https://vi.stackexchange.com/users/17449", "pm_score": 2, "selected": false, "text": "<p>Add this in your vimrc:</p>\n\n<pre><code>nno &lt;space&gt;R :&lt;c-u&gt;call &lt;sid&gt;vim_quit_and_restart()&lt...
2019/09/06
[ "https://vi.stackexchange.com/questions/21127", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/19712/" ]
Here's how I restart vim: ``` $ vim :q $ vim ``` Is there a way to restart vim so that there is no need to type the second `vim` in the shell?
Add this in your vimrc: ``` nno <space>R :<c-u>call <sid>vim_quit_and_restart()<cr> fu! s:vim_quit_and_restart() abort if has('gui_running') | echo 'not available in GUI' | return | endif sil! update sil call system('kill -USR1 $(ps -p '.getpid().' -o ppid=)') qa! endfu ``` And this in your bashrc: ...
21,130
<p>I have the given file</p> <pre><code>4 apples 2 bananas 6 peaches 3 grapes 1 pineapple 5 pears 3 tomatoes </code></pre> <p>What I want to do is to receive the following result instead:</p> <pre><code>apple apple apple apple banana banana peach peach peach peach peach peach grape grape grape pineapple pear pear pear ...
[ { "answer_id": 21131, "author": "user938271", "author_id": 17449, "author_profile": "https://vi.stackexchange.com/users/17449", "pm_score": 3, "selected": false, "text": "<p>This is not exactly what you want, but you could visually select your lines, then run this global command:</p>\n\n...
2019/09/06
[ "https://vi.stackexchange.com/questions/21130", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23722/" ]
I have the given file ``` 4 apples 2 bananas 6 peaches 3 grapes 1 pineapple 5 pears 3 tomatoes ``` What I want to do is to receive the following result instead: ``` apple apple apple apple banana banana peach peach peach peach peach peach grape grape grape pineapple pear pear pear pear pear tomato tomato tomato ``...
This is not exactly what you want, but you could visually select your lines, then run this global command: ``` g/^/exe 'norm! "adiwD' | exe 'norm! '.@a.'p' ├───┘│ ├────┘ │ │ └ paste unnamed register as many times as the number in register `a` ...
21,146
<p>Let's say I have a folder located on <code>~/question</code> with 4 files:</p> <pre><code>$ ls _file1 _file2 _file3 _file4 </code></pre> <p>I've realized that it's possible to open folders with Vim and it'll list the file names of all the files that are inside this folder. For example, on Linux if I try to ope...
[ { "answer_id": 21147, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 2, "selected": false, "text": "<p>There are a <a href=\"https://joeyh.name/code/moreutils/\" rel=\"nofollow noreferrer\">number</a> <a href=\"https://www.nong...
2019/09/08
[ "https://vi.stackexchange.com/questions/21146", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/2805/" ]
Let's say I have a folder located on `~/question` with 4 files: ``` $ ls _file1 _file2 _file3 _file4 ``` I've realized that it's possible to open folders with Vim and it'll list the file names of all the files that are inside this folder. For example, on Linux if I try to open Vim with `vim ~/question` I'll have...
There are a [number](https://joeyh.name/code/moreutils/) [of](https://www.nongnu.org/renameutils/) [tools](https://github.com/qpkorr/vim-renamer) that allow you to rename files in a Vim buffer in this way. [mvi is the one that I use](https://www.perlmonks.org/?node_id=852545). It takes the paths of the files that you ...
21,169
<p>A vim newbie here. </p> <p>Would like to know an efficient way of converting</p> <pre><code>self.mat = material self.epsilon=epsilon self.x = x </code></pre> <p>to </p> <pre><code>self.mat, self.epsilon, self.x = material, epsilon, x </code></pre>
[ { "answer_id": 21170, "author": "user938271", "author_id": 17449, "author_profile": "https://vi.stackexchange.com/users/17449", "pm_score": 2, "selected": false, "text": "<p>I'm not sure this is what you want, but you could try these global commands:</p>\n\n<pre><code>g/^self\\./,/^\\(se...
2019/09/10
[ "https://vi.stackexchange.com/questions/21169", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23774/" ]
A vim newbie here. Would like to know an efficient way of converting ``` self.mat = material self.epsilon=epsilon self.x = x ``` to ``` self.mat, self.epsilon, self.x = material, epsilon, x ```
I'm not sure this is what you want, but you could try these global commands: ``` g/^self\./,/^\(self\.\)\@!/-j g/^self\./let l=[]|s/\s*=\s*\(\w*\)/\=add(l,submatch(1))[-1][-1]/g|s/\s/, /g|s/$/\=' = '.join(l,', ') ``` The first command should turn this block: ``` self.mat = material self.epsilon=epsilon self.x = x ...
21,187
<p>I have the following code in my <code>vimrc</code></p> <pre><code>if exists(":Goyo") augroup LatexGoyo autocmd! autocmd BufReadPost,BufNewFile *.tex Goyo augroup END else augroup LatexColumnSet autocmd FileType tex setlocal columns=100 augroup END endif </code></pre> <p>The ...
[ { "answer_id": 21188, "author": "Christian Brabandt", "author_id": 71, "author_profile": "https://vi.stackexchange.com/users/71", "pm_score": 4, "selected": true, "text": "<p>The problem is, your vimrc file is executed before any plugins are loaded. You can check the order of what source...
2019/09/12
[ "https://vi.stackexchange.com/questions/21187", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8408/" ]
I have the following code in my `vimrc` ``` if exists(":Goyo") augroup LatexGoyo autocmd! autocmd BufReadPost,BufNewFile *.tex Goyo augroup END else augroup LatexColumnSet autocmd FileType tex setlocal columns=100 augroup END endif ``` The idea is to check for the presence of ...
The problem is, your vimrc file is executed before any plugins are loaded. You can check the order of what source files are loaded by issueing the `:scriptnames` command. The usual way to fix this *problem* is to execute the test inside a `VimEnter` autocommand, something like this: ``` function s:init() " do your...
21,193
<p>I often nest one programming language within another (e.g. HTML inside python). This can be done per-language, and written items in <code>~/.vim/after/syntax/</code> for that purpose, but I don't have the patience to implement it for every combination I use. This means I press <kbd>:</kbd><kbd>s</kbd><kbd>e</kbd><kb...
[ { "answer_id": 21194, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 3, "selected": true, "text": "<blockquote>\n <p>Searching the web for this sort of thing merely turns up tricks for searching the command history manuall...
2019/09/13
[ "https://vi.stackexchange.com/questions/21193", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6505/" ]
I often nest one programming language within another (e.g. HTML inside python). This can be done per-language, and written items in `~/.vim/after/syntax/` for that purpose, but I don't have the patience to implement it for every combination I use. This means I press `:``s``e``Up``Up` a lot. One way to script this woul...
> > Searching the web for this sort of thing merely turns up tricks for searching the command history manually (without vimscript). > > > I believe you're overthinking something. In Vim "key macros" are the "first-class citizens". They are stable and repeatable (if written well). There's no need to turn them into ...
21,227
<p>I'm trying to configure the <code>highlight</code> to highlight keywords of my C++ project.</p> <p>Here is the content of <code>~/.vim/syntax/cpp.vim</code>:</p> <pre><code>syn match cCustomParen "?=(" contains=cParen,cCppParen syn match cCustomFunc "\w\+\s*(\@=" contains=cCustomParen hi CustomFunc g...
[ { "answer_id": 21229, "author": "Mark Stosberg", "author_id": 6094, "author_profile": "https://vi.stackexchange.com/users/6094", "pm_score": 1, "selected": false, "text": "<p>Here's the answer I found for Neovim.</p>\n\n<p>First, Neovim will display up to nine signs in the gutter by defa...
2019/09/19
[ "https://vi.stackexchange.com/questions/21227", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10003/" ]
I'm trying to configure the `highlight` to highlight keywords of my C++ project. Here is the content of `~/.vim/syntax/cpp.vim`: ``` syn match cCustomParen "?=(" contains=cParen,cCppParen syn match cCustomFunc "\w\+\s*(\@=" contains=cCustomParen hi CustomFunc guifg=NONE guibg=NONE guisp=NONE gui=bold ct...
Vim currently supports assigning sign priorities (<https://vimhelp.org/sign.txt.html#sign-priority>). The plugins placing the signs need to use the newer sign APIs.
21,246
<p>As example, my current buffer contains below lines</p> <pre><code>di=01;34 ln=01;36 mh=00 pi=40;33 </code></pre> <p>I want to join all lines with <code>:</code>, and set entire buffer to the joined string.</p> <p>How to achieve that, using <code>:python</code> command.</p> <p>I tried below</p> <pre><code>py3 vi...
[ { "answer_id": 21247, "author": "Mass", "author_id": 13728, "author_profile": "https://vi.stackexchange.com/users/13728", "pm_score": 1, "selected": false, "text": "<p><code>vim.current.buffer</code> refers to a buffer object.</p>\n\n<p><code>vim.current.buffer[:]</code> on the other han...
2019/09/21
[ "https://vi.stackexchange.com/questions/21246", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10254/" ]
As example, my current buffer contains below lines ``` di=01;34 ln=01;36 mh=00 pi=40;33 ``` I want to join all lines with `:`, and set entire buffer to the joined string. How to achieve that, using `:python` command. I tried below ``` py3 vim.current.buffer[:] = ':'.join(vim.current.buffer) py3 vim.current.buffer...
`vim.current.buffer` refers to a buffer object. `vim.current.buffer[:]` on the other hand, is a list of strings containing the content of the buffer. You can manipulate the lines of the buffer by retrieving and assigning to this list: ``` py3 vim.current.buffer[:] = [ ':'.join(vim.current.buffer[:]) ] ```
21,256
<p>I want to create a basic Vim script that simply deletes n lines, skips 1 line and repeats until the end of the document. I don't care about specific matches, I just want to delete the line. For example; So I want to repeat the command <code>3ddj</code> for the entire document. </p> <pre><code>Text I want to keep. ...
[ { "answer_id": 21257, "author": "Ralf", "author_id": 19763, "author_profile": "https://vi.stackexchange.com/users/19763", "pm_score": 4, "selected": false, "text": "<p>Very simple approach:</p>\n\n<ol>\n<li>Move to the first line you want to delete.</li>\n<li>Record a macro: <code>qa3ddj...
2019/09/23
[ "https://vi.stackexchange.com/questions/21256", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/24927/" ]
I want to create a basic Vim script that simply deletes n lines, skips 1 line and repeats until the end of the document. I don't care about specific matches, I just want to delete the line. For example; So I want to repeat the command `3ddj` for the entire document. ``` Text I want to keep. Text I want to delete. ...
Very simple approach: 1. Move to the first line you want to delete. 2. Record a macro: `qa3ddjq` 3. Repeat it with a high number: 1000@a Step three will repeat the macro a thousand times or until an error is encountered. Hitting end of file (hence no lines to delete) produces an error and repetition of the macro is ...
21,260
<p>I have a terminal buffer with 10000 lines of previously executed output. In order to search for the particular sequence of words I have to go through all 10000 lines before getting to my last executed command's output. Which makes me so annoyed. Is the a way of clearing a terminal buffer without quiting the terminal...
[ { "answer_id": 21261, "author": "chalybeum", "author_id": 22764, "author_profile": "https://vi.stackexchange.com/users/22764", "pm_score": 1, "selected": false, "text": "<p>Both <code>clear</code> and <code>Ctrl+l</code> work for me using Neovim and bash.\nWould have asked you to try it ...
2019/09/23
[ "https://vi.stackexchange.com/questions/21260", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/22010/" ]
I have a terminal buffer with 10000 lines of previously executed output. In order to search for the particular sequence of words I have to go through all 10000 lines before getting to my last executed command's output. Which makes me so annoyed. Is the a way of clearing a terminal buffer without quiting the terminal an...
AFAIK, there's no "good" way to do it, but there is a "hacky" way. Suppose you want `<c-w><c-l>` combination to clear vim internal buffer in both normal and terminal(insert) modes. The mappings in vimrc would look like this: ``` nmap <c-w><c-l> :set scrollback=1 \| sleep 100m \| set scrollback=10000<cr> tmap <c-w><c-l...
21,266
<p>One example would be in the List docs:</p> <pre><code>:unlet list[3] "idem </code></pre>
[ { "answer_id": 21267, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 5, "selected": true, "text": "<p>It's <a href=\"https://en.wikipedia.org/wiki/Idem\" rel=\"noreferrer\">a latin term meaning \"the same\"</a>. In the quoted c...
2019/09/23
[ "https://vi.stackexchange.com/questions/21266", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/24933/" ]
One example would be in the List docs: ``` :unlet list[3] "idem ```
It's [a latin term meaning "the same"](https://en.wikipedia.org/wiki/Idem). In the quoted context, it just means the listed command does the same thing as the previously listed command, i.e. `remove item 3`: ``` :let i = remove(list, 3) " remove item 3 :unlet list[3] " idem ```
21,271
<p>I am using the plugin vimtex. It offers the functionality (from the introduction of its documentation)</p> <blockquote> <ul> <li>Text objects <ul> <li><code>ic</code> <code>ac</code> Commands</li> <li><code>id</code> <code>ad</code> Delimiters</li> <li><code>ie</code> <code>ae</code> LaTeX environmen...
[ { "answer_id": 21273, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 3, "selected": true, "text": "<p>Since <code>i$</code> is a mapping itself (defined by the vimtex plug-in), you need a <em>recursive</em> mapping to...
2019/09/23
[ "https://vi.stackexchange.com/questions/21271", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/-1/" ]
I am using the plugin vimtex. It offers the functionality (from the introduction of its documentation) > > * Text objects > + `ic` `ac` Commands > + `id` `ad` Delimiters > + `ie` `ae` LaTeX environments > + `i$` `a$` Inline math structures > + `iP` `aP` Sections > > > This means that with `ci$` I can delete ...
Since `i$` is a mapping itself (defined by the vimtex plug-in), you need a *recursive* mapping to be able to use `i$` as part of the expansion of your mapping. So this should work: ``` nmap cim ci$ ``` But you can also create an operator-pending mode mapping for `im`, in which case that would work with other operat...
21,272
<p>I do a lot of plain text file editing, and many times I need to mark a section of text as 'DO NOT FORMAT' as it is pre-formatted, or even contains ascii art.</p> <p>Many years ago I did this by marking the block as a comment, and telling vim NOT to format such blocks.</p> <p>Example text...</p> <pre><code>Looking...
[ { "answer_id": 21273, "author": "filbranden", "author_id": 18609, "author_profile": "https://vi.stackexchange.com/users/18609", "pm_score": 3, "selected": true, "text": "<p>Since <code>i$</code> is a mapping itself (defined by the vimtex plug-in), you need a <em>recursive</em> mapping to...
2019/09/24
[ "https://vi.stackexchange.com/questions/21272", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23299/" ]
I do a lot of plain text file editing, and many times I need to mark a section of text as 'DO NOT FORMAT' as it is pre-formatted, or even contains ascii art. Many years ago I did this by marking the block as a comment, and telling vim NOT to format such blocks. Example text... ``` Looking across the road, I could se...
Since `i$` is a mapping itself (defined by the vimtex plug-in), you need a *recursive* mapping to be able to use `i$` as part of the expansion of your mapping. So this should work: ``` nmap cim ci$ ``` But you can also create an operator-pending mode mapping for `im`, in which case that would work with other operat...
21,286
<p>I find myself wanting to use vim one-handed now and again. Practicality aside, I want to define a function along the lines of:</p> <pre><code>function! GetControlKey() echo "Control? " let key = nr2char(getchar()) execute "normal! " . key endfunction </code></pre> <p>that I can map to another key comb...
[ { "answer_id": 21289, "author": "Ralf", "author_id": 19763, "author_profile": "https://vi.stackexchange.com/users/19763", "pm_score": 0, "selected": false, "text": "<p>The control keys are the ASCII values before ' ' (space). So <code>&lt;C-A&gt;</code> is 1, <code>&lt;C-B&gt;</code> is ...
2019/09/24
[ "https://vi.stackexchange.com/questions/21286", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/24955/" ]
I find myself wanting to use vim one-handed now and again. Practicality aside, I want to define a function along the lines of: ``` function! GetControlKey() echo "Control? " let key = nr2char(getchar()) execute "normal! " . key endfunction ``` that I can map to another key combination `<Leader>,` maybe,...
My recommendation would be to build a `"\<C-...>"` string and then use [`eval()`](https://vimhelp.org/eval.txt.html#eval%28%29) to have Vim evaluate it as a key sequence. For example: ``` function! GetControlKey() let key = getchar() let keyname = nr2char(key) return eval('"\<C-'.escape(keyname,'\').'>"')...
21,290
<p>Suppose I have a string as follows:</p> <pre><code>RESULT=100 </code></pre> <p>How would I replace everything following 'RESULT=' so that the string reads:</p> <pre><code>RESULT=200 </code></pre> <p>The closest I've gotten so far is to use:</p> <pre><code>:%s/\(RESULT=.*\)\@&lt;=/200/g </code></pre> <p>But thi...
[ { "answer_id": 21291, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 3, "selected": true, "text": "<p>One way to do this is by using <a href=\"https://vimhelp.org/pattern.txt.html#%2F%5Czs\" rel=\"nofollow noreferrer\"><code>\\...
2019/09/25
[ "https://vi.stackexchange.com/questions/21290", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/24963/" ]
Suppose I have a string as follows: ``` RESULT=100 ``` How would I replace everything following 'RESULT=' so that the string reads: ``` RESULT=200 ``` The closest I've gotten so far is to use: ``` :%s/\(RESULT=.*\)\@<=/200/g ``` But this simply places the desired string after the existing one: ``` RESULT=1002...
One way to do this is by using [`\zs`](https://vimhelp.org/pattern.txt.html#%2F%5Czs) to set the "start" of the match, so that everything before `\zs` is untouched by the replacement: ``` :%s/RESULT=\zs.*/200/g ``` Your original attempt using a lookbehind was also on the right track: you just put the `.*` part in th...
21,295
<p>I'd like to know if there is an analogue to <code>verbose map &lt;key&gt;</code> (which shows the location that the map was assigned) for functions. For example I have a few Git plugins and I'd like to know what plugin defines the <code>:GitFiles</code> function, if Vim knows this info. </p> <p>The fallback (which'...
[ { "answer_id": 21296, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>From <a href=\"http://vimhelp.appspot.com/eval.txt.html#%3Afunction-verbose\" rel=\"noreferrer\"><code>:h :function-verb...
2019/09/25
[ "https://vi.stackexchange.com/questions/21295", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/390/" ]
I'd like to know if there is an analogue to `verbose map <key>` (which shows the location that the map was assigned) for functions. For example I have a few Git plugins and I'd like to know what plugin defines the `:GitFiles` function, if Vim knows this info. The fallback (which'll certainly work) is to search my fil...
From [`:h :function-verbose`](http://vimhelp.appspot.com/eval.txt.html#%3Afunction-verbose): ``` When 'verbose' is non-zero, listing a function will also display where it was last defined. Example: > :verbose function SetFileTypeSH function SetFileTypeSH(name) Last set from /usr/share/vim/vim-7.0/file...
21,300
<p>Question reposted <a href="https://stackoverflow.com/questions/58145963/two-consecutive-identical-calls-to-echo-have-different-output-in-vim-function">on StackOverflow</a>, where it's receiving more attention.</p> <p>Given the following function in the <code>.vimrc</code> file,</p> <pre><code>fu! MyFun(count) ec...
[ { "answer_id": 21296, "author": "statox", "author_id": 1841, "author_profile": "https://vi.stackexchange.com/users/1841", "pm_score": 3, "selected": false, "text": "<p>From <a href=\"http://vimhelp.appspot.com/eval.txt.html#%3Afunction-verbose\" rel=\"noreferrer\"><code>:h :function-verb...
2019/09/25
[ "https://vi.stackexchange.com/questions/21300", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6498/" ]
Question reposted [on StackOverflow](https://stackoverflow.com/questions/58145963/two-consecutive-identical-calls-to-echo-have-different-output-in-vim-function), where it's receiving more attention. Given the following function in the `.vimrc` file, ``` fu! MyFun(count) echo a:count echo a:count if a:count > 0 ...
From [`:h :function-verbose`](http://vimhelp.appspot.com/eval.txt.html#%3Afunction-verbose): ``` When 'verbose' is non-zero, listing a function will also display where it was last defined. Example: > :verbose function SetFileTypeSH function SetFileTypeSH(name) Last set from /usr/share/vim/vim-7.0/file...
21,307
<p>I'm just getting into Vim, and, as one might expect, I'm constantly adding things to my <code>.vimrc</code>. At the moment i'm using <code>:tabe ~/.vimrc</code> and I was just curious if there was a quicker command for getting to the<code>.vimrc</code> that was used when Vim launched.</p>
[ { "answer_id": 21308, "author": "Ralf", "author_id": 19763, "author_profile": "https://vi.stackexchange.com/users/19763", "pm_score": 3, "selected": true, "text": "<p>You could use <code>$MYVIMRC</code>. See <code>:help .vimrc</code>. It says:</p>\n\n<blockquote>\n <p>The $MYVIMRC envir...
2019/09/26
[ "https://vi.stackexchange.com/questions/21307", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/24943/" ]
I'm just getting into Vim, and, as one might expect, I'm constantly adding things to my `.vimrc`. At the moment i'm using `:tabe ~/.vimrc` and I was just curious if there was a quicker command for getting to the`.vimrc` that was used when Vim launched.
You could use `$MYVIMRC`. See `:help .vimrc`. It says: > > The $MYVIMRC environment variable is set to the file that was first found, > unless $MYVIMRC was already set and when using VIMINIT. > > > `$MYVIMRC` is also not set if you use the command line option `-u` to specify a different ini file. I have two ma...
21,327
<p>I've traditionally used <code>vim</code> as a text editor and <code>tmux</code> as a terminal multiplexer, but I'm trying to see if I can drop tmux entirely and just use <code>vim</code> for everything (except session attach/detach, which will be handled by an external tool). So far, I have almost zero knowledge abo...
[ { "answer_id": 21308, "author": "Ralf", "author_id": 19763, "author_profile": "https://vi.stackexchange.com/users/19763", "pm_score": 3, "selected": true, "text": "<p>You could use <code>$MYVIMRC</code>. See <code>:help .vimrc</code>. It says:</p>\n\n<blockquote>\n <p>The $MYVIMRC envir...
2019/09/27
[ "https://vi.stackexchange.com/questions/21327", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/13992/" ]
I've traditionally used `vim` as a text editor and `tmux` as a terminal multiplexer, but I'm trying to see if I can drop tmux entirely and just use `vim` for everything (except session attach/detach, which will be handled by an external tool). So far, I have almost zero knowledge about terminal emulators in `vim` and h...
You could use `$MYVIMRC`. See `:help .vimrc`. It says: > > The $MYVIMRC environment variable is set to the file that was first found, > unless $MYVIMRC was already set and when using VIMINIT. > > > `$MYVIMRC` is also not set if you use the command line option `-u` to specify a different ini file. I have two ma...
21,329
<p>I have string lets say</p> <pre><code>count number of elecment when tra(XYixe0/en_in/old)='mid/2' rise='corse/2' </code></pre> <p>I want to replace / from (XYixe0/en_in/old) to .</p> <p>My output string should look like</p> <pre><code>count number of elecment when tra(XYixe0.en_in.old)='mid/2' rise='corse/2' </c...
[ { "answer_id": 21330, "author": "DJMcMayhem", "author_id": 2920, "author_profile": "https://vi.stackexchange.com/users/2920", "pm_score": 2, "selected": false, "text": "<p>It's not perfect since you have to run it multiple times to get every slash, but that's not too big of a problem:</p...
2019/09/27
[ "https://vi.stackexchange.com/questions/21329", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25002/" ]
I have string lets say ``` count number of elecment when tra(XYixe0/en_in/old)='mid/2' rise='corse/2' ``` I want to replace / from (XYixe0/en\_in/old) to . My output string should look like ``` count number of elecment when tra(XYixe0.en_in.old)='mid/2' rise='corse/2' ``` In summary, I want vim search / only on ...
Another way is to use a sub-replace-expression, `\=`: ``` :%s/([^)]*)/\=substitute(submatch(0),'\/','.','g')/ ``` The `:s/([^)]*)/{replacement}/` will match a pair of parens, `([^)]*)`. The `{replacement}` is `\={expr}`. Where `{expr}` will be a vimscript expression to be evaluated. In this case a substitution over ...
21,337
<p>Here's what I'd like to do, and I'm open to using any tool (not just fzf):</p> <p>I want to be able to open a new file quickly (with a horizontal split :sp) in a specific directory that I find using fzf. Say we're working with this structure</p> <pre><code>foo/ bar/ file.js poop/ </code></pre> <p>While I ...
[ { "answer_id": 21341, "author": "Sang Dang", "author_id": 19109, "author_profile": "https://vi.stackexchange.com/users/19109", "pm_score": 0, "selected": false, "text": "<p>Using fzf.vim, it has the wrapper for Files, (and GFiles, which respect the gitignore while searching)</p>\n\n<p>Un...
2019/09/27
[ "https://vi.stackexchange.com/questions/21337", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/14314/" ]
Here's what I'd like to do, and I'm open to using any tool (not just fzf): I want to be able to open a new file quickly (with a horizontal split :sp) in a specific directory that I find using fzf. Say we're working with this structure ``` foo/ bar/ file.js poop/ ``` While I have file.js open in my buffer, I...
I ended up using this command in my vimrc with fzf.vim, specifically filtering directories in my current git repo. ``` function! s:append_dir_with_fzf(line) call fzf#run(fzf#wrap({ \ 'options': ['--prompt', a:line.'> '], \ 'source': 'git ls-files $(git rev-parse --show-toplevel) | xargs -n 1 dirname | uniq',...
21,340
<p>In bash you can easily search the current history entries by hitting <code>&lt;C-r&gt;</code> or <code>&lt;C-s&gt;</code>. This search feature is incremental, and once you hit return, you get a bash prompt auto-filled with the closest match in your history. I know if I want to search for a vim command I can hit <cod...
[ { "answer_id": 21342, "author": "Ralf", "author_id": 19763, "author_profile": "https://vi.stackexchange.com/users/19763", "pm_score": 2, "selected": false, "text": "<p>I'm not aware that this is possible. The only thing I know is, that Vim uses the already typed characters to filter the ...
2019/09/28
[ "https://vi.stackexchange.com/questions/21340", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25003/" ]
In bash you can easily search the current history entries by hitting `<C-r>` or `<C-s>`. This search feature is incremental, and once you hit return, you get a bash prompt auto-filled with the closest match in your history. I know if I want to search for a vim command I can hit `q:` and then search with `/`. However, I...
I'm not aware that this is possible. The only thing I know is, that Vim uses the already typed characters to filter the history. If you previously executed: ``` :%s/This/That/g ``` and you want to get this command again, you do ``` :%s/T<up> ``` This will get only commands that start with `%s/T` from the history...
21,355
<p>I'm a vim beginner. I want to handle multiple programming languages. I find great resources for how to perfect vim for one programming language by putting ton of stuff in one vimrc file. This is annoying. </p> <p>I found about filetype plugin, but it's confusing. All I need is to put a vimrc file that runs for this...
[ { "answer_id": 21356, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 4, "selected": true, "text": "<p>To enable filetype detection and plugins, add the following command to your <code>vimrc</code>:</p>\n<pre><code>filetype plug...
2019/09/29
[ "https://vi.stackexchange.com/questions/21355", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25022/" ]
I'm a vim beginner. I want to handle multiple programming languages. I find great resources for how to perfect vim for one programming language by putting ton of stuff in one vimrc file. This is annoying. I found about filetype plugin, but it's confusing. All I need is to put a vimrc file that runs for this specific ...
To enable filetype detection and plugins, add the following command to your `vimrc`: ``` filetype plugin on ``` Then, for each filetype you want settings for, create a Vimscript file in the following location: ``` ~/.vim/after/ftplugin/ ``` Name the file with the filetype you want it to apply to, so for e.g. a Py...
21,365
<p>I'm dealing with a cryptic issue in my environment which is annoying and I have no idea where to start debugging. Random characters on that aren't actually in the document appear on screen after YCM auto complete menu goes away.</p> <p>Pictures are worth a thousand words so here's a demo:</p> <h2>Step 1 - Type a v...
[ { "answer_id": 21356, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 4, "selected": true, "text": "<p>To enable filetype detection and plugins, add the following command to your <code>vimrc</code>:</p>\n<pre><code>filetype plug...
2019/09/30
[ "https://vi.stackexchange.com/questions/21365", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25041/" ]
I'm dealing with a cryptic issue in my environment which is annoying and I have no idea where to start debugging. Random characters on that aren't actually in the document appear on screen after YCM auto complete menu goes away. Pictures are worth a thousand words so here's a demo: Step 1 - Type a variable name -----...
To enable filetype detection and plugins, add the following command to your `vimrc`: ``` filetype plugin on ``` Then, for each filetype you want settings for, create a Vimscript file in the following location: ``` ~/.vim/after/ftplugin/ ``` Name the file with the filetype you want it to apply to, so for e.g. a Py...
21,388
<h2>Scenario</h2> <p>I would like to perform the following,</p> <ol> <li>Visually select some text that spans multiple lines and occurs multiple times in the file: <code>V</code></li> <li>Yank to buffer: <code>y</code></li> <li>Perform substitute with text from buffer: (<code>:%s,&lt;Ctrl-r&gt; 0,new text,g</code>)</...
[ { "answer_id": 21395, "author": "eyal karni", "author_id": 18375, "author_profile": "https://vi.stackexchange.com/users/18375", "pm_score": 1, "selected": true, "text": "<p>You can use <code>vim-visual-multi</code>. Use multi line mode with <code>\\\\M</code>. Select all occurrences with...
2019/10/02
[ "https://vi.stackexchange.com/questions/21388", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25067/" ]
Scenario -------- I would like to perform the following, 1. Visually select some text that spans multiple lines and occurs multiple times in the file: `V` 2. Yank to buffer: `y` 3. Perform substitute with text from buffer: (`:%s,<Ctrl-r> 0,new text,g`) Example ------- Given the following example: ``` metadata: n...
You can use `vim-visual-multi`. Use multi line mode with `\\M`. Select all occurrences with `\\A` and do c to change. Other people will tell you the vim way. You can also use `%s/pattern\n nextline/something/` (or `^v<enter>` instead of \n - would surely work ).
21,411
<p>Short Question: </p> <p>What is netrw function for up one level, how can I call it in my own function?</p> <p>Context:</p> <p>After installing a new ruby I had to reinstall vim to get it working again. But now netrw has some issue where if I press <code>-</code> to go up one level, it goes up a level and then sta...
[ { "answer_id": 21414, "author": "Rich", "author_id": 343, "author_profile": "https://vi.stackexchange.com/users/343", "pm_score": 3, "selected": true, "text": "<p>Ignoring the context, the answer to your \"short question\" is that you can't (easily) call it from your own function.</p>\n\...
2019/10/04
[ "https://vi.stackexchange.com/questions/21411", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/8483/" ]
Short Question: What is netrw function for up one level, how can I call it in my own function? Context: After installing a new ruby I had to reinstall vim to get it working again. But now netrw has some issue where if I press `-` to go up one level, it goes up a level and then starts visual mode such that I can't j...
Ignoring the context, the answer to your "short question" is that you can't (easily) call it from your own function. You can find out what function `-` invokes in netrw by entering the following command in a netrw buffer: ``` :verbose nmap - ``` For me, the output contains this function call: ``` call <SNR>68_Netr...
21,430
<p>I tried creating the following macro:</p> <ol> <li>search an empty line above my location</li> <li>go down one line</li> <li><kbd>shift</kbd>-<kbd>v</kbd></li> <li>find an empty line down</li> <li>go up one line</li> <li><code>:sort</code></li> </ol> <p>This should sort the entire section I'm pointing at...</p> <...
[ { "answer_id": 21432, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 4, "selected": true, "text": "<p>As simple as that:</p>\n\n<pre><code>nnoremap &lt;Leader&gt;s Vip:sort&lt;CR&gt;\n</code></pre>\n\n<p><code>ip</code> is ...
2019/10/07
[ "https://vi.stackexchange.com/questions/21430", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/20287/" ]
I tried creating the following macro: 1. search an empty line above my location 2. go down one line 3. `shift`-`v` 4. find an empty line down 5. go up one line 6. `:sort` This should sort the entire section I'm pointing at... Here is my attempt: ``` let @q = '\/^$ N j <S-V> \/^$ n k :sort' ``` However, when tryin...
As simple as that: ``` nnoremap <Leader>s Vip:sort<CR> ``` `ip` is an "inner paragraph" object, i.e. a piece of text between two empty lines.
21,439
<p>As far as I know, neovim enables running a command async, without blocking the user. This is also enabled in vim8 I was told.</p> <p>But I couldn't find examples of how to run a command asyncly. Suppose that I want to run the command :make. How would I run this command in neovim without blocking?</p> <p>Is there a...
[ { "answer_id": 22185, "author": "jdhao", "author_id": 15292, "author_profile": "https://vi.stackexchange.com/users/15292", "pm_score": 2, "selected": false, "text": "<p>There are currently two great plugins I found that can run commands asynchronously: <a href=\"https://github.com/tpope/...
2019/10/07
[ "https://vi.stackexchange.com/questions/21439", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/22203/" ]
As far as I know, neovim enables running a command async, without blocking the user. This is also enabled in vim8 I was told. But I couldn't find examples of how to run a command asyncly. Suppose that I want to run the command :make. How would I run this command in neovim without blocking? Is there an example I can f...
### [vim-dispatch](https://github.com/tpope/vim-dispatch) `:Make` instead of `:make` You *cannot* run the built-in command `:make` asynchronously in Vim8 or NeoVim. You have to take the value of `'makeprg'` and insert it into vim8 `job_start()` or neovim `jobstart()`. I personally like the convenience of plugins whi...
21,446
<p>Often while editing (say, a post on this network), I find myself wanting to copy something, edit it, and paste it back.</p> <p>At other times, I have some text in my clipboard, but isn't perfect. I would like a quick way to edit it and place it back in the clipboard for pasting.</p> <p>What can I do?</p>
[ { "answer_id": 22185, "author": "jdhao", "author_id": 15292, "author_profile": "https://vi.stackexchange.com/users/15292", "pm_score": 2, "selected": false, "text": "<p>There are currently two great plugins I found that can run commands asynchronously: <a href=\"https://github.com/tpope/...
2019/10/08
[ "https://vi.stackexchange.com/questions/21446", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/10604/" ]
Often while editing (say, a post on this network), I find myself wanting to copy something, edit it, and paste it back. At other times, I have some text in my clipboard, but isn't perfect. I would like a quick way to edit it and place it back in the clipboard for pasting. What can I do?
### [vim-dispatch](https://github.com/tpope/vim-dispatch) `:Make` instead of `:make` You *cannot* run the built-in command `:make` asynchronously in Vim8 or NeoVim. You have to take the value of `'makeprg'` and insert it into vim8 `job_start()` or neovim `jobstart()`. I personally like the convenience of plugins whi...
21,449
<p>I want to map a keyboard shortcut to execute the last command in a terminal buffer that I have open. </p> <p>I've made some progress: I am storing the buffer's channel id correctly but when I try to send keys to the terminal (up arrow and enter) they always appear as literal characters in the terminal rather than a...
[ { "answer_id": 21466, "author": "Thunderbeef", "author_id": 13992, "author_profile": "https://vi.stackexchange.com/users/13992", "pm_score": 2, "selected": false, "text": "<p>I don't have <code>term_sendkeys()</code> in my <code>neovim</code> instance, so I'll use <code>chandsend()</code...
2019/10/08
[ "https://vi.stackexchange.com/questions/21449", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25146/" ]
I want to map a keyboard shortcut to execute the last command in a terminal buffer that I have open. I've made some progress: I am storing the buffer's channel id correctly but when I try to send keys to the terminal (up arrow and enter) they always appear as literal characters in the terminal rather than actually go...
I couldn't get the up arrow key working, it seems tricky and I don't think it's the best way. But thanks to @thunderbeef's answer I got the enter key working, and a solution I'm happy with: ``` call chansend(g:last_terminal_chan_id, "!!\<cr>") ```
21,457
<p>I am trying to remap this functionality: <a href="https://i.stack.imgur.com/O9Y8t.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O9Y8t.png" alt="enter image description here"></a> to Ctrl+Space, by using this line in <code>.vimrc</code></p> <pre><code>inoremap &lt;C-Space&gt; &lt;C-n&gt; </code>...
[ { "answer_id": 21463, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<p>I believe you’ve got the map syntax backwards (see <code>:help :map</code>): try</p>\n\n<pre><code>inoremap &lt...
2019/10/09
[ "https://vi.stackexchange.com/questions/21457", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/7960/" ]
I am trying to remap this functionality: [![enter image description here](https://i.stack.imgur.com/O9Y8t.png)](https://i.stack.imgur.com/O9Y8t.png) to Ctrl+Space, by using this line in `.vimrc` ``` inoremap <C-Space> <C-n> ``` However, I can not seem to get it to work. If I press Ctrl+Space after starting up, I get...
Your terminal send `^@` as `<c-space>` to vim, `^@` is `ctrl-@`, it's equivalent to `<Nul>` in vim, check [:h keycodes](https://vimhelp.org/intro.txt.html#keycodes) if you have doubts. You get `E29: No inserted text yet` error message because [:h i\_CTRL-@](https://vimhelp.org/insert.txt.html#i_CTRL-%40) is trying to ...
21,465
<p>I often find myself operating in the vim terminal needing to edit a few files. In this case I might type <code>vim *.h</code>. This opens a new vim instance nested inside my vim terminal. Is there a way to make a command that instead triggers the parent vim instance to load the files in buffers?</p>
[ { "answer_id": 21463, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<p>I believe you’ve got the map syntax backwards (see <code>:help :map</code>): try</p>\n\n<pre><code>inoremap &lt...
2019/10/09
[ "https://vi.stackexchange.com/questions/21465", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25165/" ]
I often find myself operating in the vim terminal needing to edit a few files. In this case I might type `vim *.h`. This opens a new vim instance nested inside my vim terminal. Is there a way to make a command that instead triggers the parent vim instance to load the files in buffers?
Your terminal send `^@` as `<c-space>` to vim, `^@` is `ctrl-@`, it's equivalent to `<Nul>` in vim, check [:h keycodes](https://vimhelp.org/intro.txt.html#keycodes) if you have doubts. You get `E29: No inserted text yet` error message because [:h i\_CTRL-@](https://vimhelp.org/insert.txt.html#i_CTRL-%40) is trying to ...
21,483
<p>I tried with <code>Flygrep *.kl</code> but it didn't work, I searched how to use <code>--include \*.kl</code> as in a grep search but I didn't find anything</p>
[ { "answer_id": 21607, "author": "Wang Shidong", "author_id": 7942, "author_profile": "https://vi.stackexchange.com/users/7942", "pm_score": 0, "selected": false, "text": "<p>Flygrep is a plugin for searching text. it do not for searching file path. if you want to searching file path, I r...
2019/10/10
[ "https://vi.stackexchange.com/questions/21483", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/24926/" ]
I tried with `Flygrep *.kl` but it didn't work, I searched how to use `--include \*.kl` as in a grep search but I didn't find anything
A "standard vim" answer: ``` :args `find . -iname '*.kl'` ``` Substitute the `find` command for any command that can generate the list of files. Then you can use `:next` and `:prev` for navigating (bound conveniently to `]a` and `[a` in tpope/unimpaired). Further refinement: ``` :vimgrep /pattern/ ## ``` This s...
21,498
<p>I was looking at the documentation for the 'complete' option, and I found it a bit confusing:</p> <pre><code>. scan the current buffer ('wrapscan' is ignored) w scan buffers from other windows b scan other loaded buffers that are in the buffer list u scan the unloaded buffers that are in the buffer list U ...
[ { "answer_id": 21513, "author": "alwillis", "author_id": 14846, "author_profile": "https://vi.stackexchange.com/users/14846", "pm_score": -1, "selected": false, "text": "<p>I’m also running macOS Catalina and MavVim 8.1.1722.</p>\n\n<p>Although I’m using a <a href=\"https://github.com/po...
2019/10/12
[ "https://vi.stackexchange.com/questions/21498", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25025/" ]
I was looking at the documentation for the 'complete' option, and I found it a bit confusing: ``` . scan the current buffer ('wrapscan' is ignored) w scan buffers from other windows b scan other loaded buffers that are in the buffer list u scan the unloaded buffers that are in the buffer list U scan the buff...
After Upgrading to Mac OS Catalina, I had the same issue with the same MacVim version. Updating MacVim, currently to 8.1.2234, solved the issue. I simply used "Check for Updates..." in the menu.
21,542
<p>So I have a plugin that I am writing which should allow the user to set whether they want to enable a feature. I want the feature to be disabled by default, and allow the user to change it by adding something like this to their .vimrc <code>let g:myplugin_enable_feature = 1</code>, though when the user doesn't set t...
[ { "answer_id": 21543, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 2, "selected": false, "text": "<p>Usually it suffices to use <code>get()</code> function. Like that</p>\n\n<pre><code>if get(g:, 'myplugin_enable_feature'...
2019/10/17
[ "https://vi.stackexchange.com/questions/21542", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23679/" ]
So I have a plugin that I am writing which should allow the user to set whether they want to enable a feature. I want the feature to be disabled by default, and allow the user to change it by adding something like this to their .vimrc `let g:myplugin_enable_feature = 1`, though when the user doesn't set the variable in...
The simple way is ``` if get(g:, 'myplugin_enable_feature', defaultvalue) do whatever you want endif ``` Now when I need to check a setting in more than one place, I usually prefer to have a dedicated getter in my plugin to be sure I have the same default value everywhere ``` function! s:enable_feature() abort ...
21,546
<p>Is it possible to automatically create a highlight which is the reverse of an existing highlight? Example <code>highlight Search guifg=Black guibg=Yellow</code>, becomes <code>highlight CustomHighlight guifg=Yellow guibg=Black</code>.</p> <p>I would want to use this to highlight certain text so that it would look l...
[ { "answer_id": 21547, "author": "Matt", "author_id": 22797, "author_profile": "https://vi.stackexchange.com/users/22797", "pm_score": 1, "selected": false, "text": "<p>Not sure if it's a good idea at all, but it's certainly possible:</p>\n\n<pre><code>function! HiliteSwap(group)\n let...
2019/10/17
[ "https://vi.stackexchange.com/questions/21546", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23679/" ]
Is it possible to automatically create a highlight which is the reverse of an existing highlight? Example `highlight Search guifg=Black guibg=Yellow`, becomes `highlight CustomHighlight guifg=Yellow guibg=Black`. I would want to use this to highlight certain text so that it would look like the inverse of whatever the ...
This is certainly possible, but it requires a bit of VimScript. The following function does the basic thing: ``` func SwapHiGroup(group) let id = synIDtrans(hlID(a:group)) for mode in ['cterm', 'gui'] for g in ['fg', 'bg'] exe 'let '. mode.g. "= synIDattr(id, '". \ ...
21,554
<p>If I have a pair of quotes on a line by themselves:</p> <pre><code>'' </code></pre> <p>...and a short paragraph of text, say three lines of text:</p> <pre><code>some text that I'd like to move </code></pre> <p>Now if I want to move the text into the quotes, I can place the caret at the line above the first line...
[ { "answer_id": 21555, "author": "Pierre", "author_id": 24895, "author_profile": "https://vi.stackexchange.com/users/24895", "pm_score": 4, "selected": true, "text": "<p>When you paste the contents of a register in insert mode, you don't have the initial newline.</p>\n\n<p>For instance, w...
2019/10/18
[ "https://vi.stackexchange.com/questions/21554", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/16265/" ]
If I have a pair of quotes on a line by themselves: ``` '' ``` ...and a short paragraph of text, say three lines of text: ``` some text that I'd like to move ``` Now if I want to move the text into the quotes, I can place the caret at the line above the first line of text and press `3`, `d``d` to select and dele...
When you paste the contents of a register in insert mode, you don't have the initial newline. For instance, we have this text: ``` '' some text that I'd like to move ``` Place your caret on the beginning of the second line in normal mode and type `3``d``d``a``Ctrl+R``"``Backspace`: * `3``d``d`: cut the three follo...
21,566
<p>I'm trying to use <code>git grep</code> as my <code>grepprg</code>, but I keep getting spurious files such as <code>~/fatal: Not a git repository (or any of the parent directories): .git</code>. Is there a way to configure vim to correctly ignore diagnostic messages? I'm okay with general solutions for configuring <...
[ { "answer_id": 21583, "author": "Greg Nisbet", "author_id": 6420, "author_profile": "https://vi.stackexchange.com/users/6420", "pm_score": 0, "selected": false, "text": "<p>I solved this issue by removing the option consisting only of <code>%f</code> by itself. I'm not sure what <code>%m...
2019/10/19
[ "https://vi.stackexchange.com/questions/21566", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6420/" ]
I'm trying to use `git grep` as my `grepprg`, but I keep getting spurious files such as `~/fatal: Not a git repository (or any of the parent directories): .git`. Is there a way to configure vim to correctly ignore diagnostic messages? I'm okay with general solutions for configuring `grepprg` and related options or solu...
I don't use `git-grep` as `grepprg`, and here's why: 1. I mostly use `:vimgrep /pattern/ ##` to search my argument list. 2. I mostly use `ack` to search at the command line, though `git-grep` is helpful. Combined with `:Ack`, I'm set. 3. This function makes it easy to pop open vim with the quickfix ready to go: ``` v...
21,567
<p>I upgraded MacVim to 8.1.2168 (159) tonight and now the vimwiki files in Markdown format do not highlight correctly when I enable spell check. </p> <p>I run <code>set spell spelllang=en_ca</code> as I have before. It looks almost like the spell check is finding all of the first word <em>except the first character</...
[ { "answer_id": 21611, "author": "Sheatsley", "author_id": 25323, "author_profile": "https://vi.stackexchange.com/users/25323", "pm_score": 1, "selected": false, "text": "<p>I am having the same issue. Just upgraded to <code>8.1.2168</code> a couple days ago. A couple things I noticed:</p...
2019/10/19
[ "https://vi.stackexchange.com/questions/21567", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/6590/" ]
I upgraded MacVim to 8.1.2168 (159) tonight and now the vimwiki files in Markdown format do not highlight correctly when I enable spell check. I run `set spell spelllang=en_ca` as I have before. It looks almost like the spell check is finding all of the first word *except the first character* in some (but not all!) o...
This is a [known bug](https://github.com/vim/vim/issues/5078), introduced by patch [v8.1.2153](https://github.com/vim/vim/releases/tag/v8.1.2153) that has since been fixed with patch [v8.1.2172](https://github.com/vim/vim/commit/7751d1d1a3d447d0d48f57f34e0da9f7c6ac433d), so you'd need to update your MacVim to a new Ver...
21,568
<p>I would like to filter the output of vim commands with fzf. The idea is for example, if I use vim unimpaired plugin and I don't exactly remember which map was to navigate to the next git conflict but I do remember that it started with "[", to be able to do something like:</p> <pre><code>:map [ | fzf </code></pre> ...
[ { "answer_id": 21569, "author": "dedowsdi", "author_id": 5017, "author_profile": "https://vi.stackexchange.com/users/5017", "pm_score": 2, "selected": true, "text": "<pre><code>com -nargs=+ FF call fzf#run({'source' : split(execute(&lt;q-args&gt;), \"\\n\"), 'sink':'\"'})\n</code></pre>\...
2019/10/19
[ "https://vi.stackexchange.com/questions/21568", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/15345/" ]
I would like to filter the output of vim commands with fzf. The idea is for example, if I use vim unimpaired plugin and I don't exactly remember which map was to navigate to the next git conflict but I do remember that it started with "[", to be able to do something like: ``` :map [ | fzf ``` And then I can search f...
``` com -nargs=+ FF call fzf#run({'source' : split(execute(<q-args>), "\n"), 'sink':'"'}) ``` Examples: ``` FF map [ FF set termcap FF buffers FF oldfiles ``` [:h :quote](https://vimhelp.org/cmdline.txt.html#%3Aquote) is used as sink, it's ignored. **update** Filter blank lines, add `-bang` to support reverse or...
21,570
<p>I discovered vi/vim only yesterday<br> on my ubuntu I didn't have vim installed, only vi<br> I enjoyed its simplicity and minimalism</p> <p>then I decided to try vim too, ran <code>sudo apt install vim</code>, played with it </p> <p>Today I tried turning on simpler vi again, but it opens only vim</p> <p>How do ...
[ { "answer_id": 21571, "author": "Ralf", "author_id": 19763, "author_profile": "https://vi.stackexchange.com/users/19763", "pm_score": 2, "selected": false, "text": "<p>In fact the \"simpler version\" on Ubuntu is also a Vim. Vim can be compiled with more or less features. The \"simple\" ...
2019/10/19
[ "https://vi.stackexchange.com/questions/21570", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/25286/" ]
I discovered vi/vim only yesterday on my ubuntu I didn't have vim installed, only vi I enjoyed its simplicity and minimalism then I decided to try vim too, ran `sudo apt install vim`, played with it Today I tried turning on simpler vi again, but it opens only vim How do I return back to simpler version withou...
In fact the "simpler version" on Ubuntu is also a Vim. Vim can be compiled with more or less features. The "simple" Vim is still available as `vi.tiny` (at least on Ubuntu 16.04). I would recommend to just use the full-featured Vim (called "Huge version"). It has things like syntax highlighting and a lot more. BTW:...
21,575
<p>Macros can be repeated for every line matching a pattern with the global command as explained <a href="https://stackoverflow.com/questions/390174/in-vim-how-do-i-apply-a-macro-to-a-set-of-lines">in this answer</a>.</p> <p>This applies to every single line, but is it possible to do it for every single match? so if I...
[ { "answer_id": 21576, "author": "D. Ben Knoble", "author_id": 10604, "author_profile": "https://vi.stackexchange.com/users/10604", "pm_score": 2, "selected": false, "text": "<p>Search for your pattern using <code>/</code>, then play your macro <code>@@</code>—you can record a new macro f...
2019/10/19
[ "https://vi.stackexchange.com/questions/21575", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/15345/" ]
Macros can be repeated for every line matching a pattern with the global command as explained [in this answer](https://stackoverflow.com/questions/390174/in-vim-how-do-i-apply-a-macro-to-a-set-of-lines). This applies to every single line, but is it possible to do it for every single match? so if I save in a macro `ysi...
Another way that also works across files is to use [:h :vimgrep](https://vimhelp.org/quickfix.txt.html#%3Avimgrep) with `g` flag: ``` Without the 'g' flag each line is added only once. With 'g' every match is added. ``` The workflow is: * Init your search pattern with `/your pattern`, record...
21,582
<p>I'd like to use vim's builtin indent fix feature on an entire file. I have looked up answers, but all I found were suggestions to type <code>gg=G</code>, the only problem being that it brings your cursor to the top of the file.</p> <p>How could I easily indent a whole file without changing my cursor's position?</p>...
[ { "answer_id": 21584, "author": "Greg Nisbet", "author_id": 6420, "author_profile": "https://vi.stackexchange.com/users/6420", "pm_score": 0, "selected": false, "text": "<p>If you are willing to dedicate a keybinding to it (let's say <code>\\G</code> for concreteness), then it's possible...
2019/10/19
[ "https://vi.stackexchange.com/questions/21582", "https://vi.stackexchange.com", "https://vi.stackexchange.com/users/23679/" ]
I'd like to use vim's builtin indent fix feature on an entire file. I have looked up answers, but all I found were suggestions to type `gg=G`, the only problem being that it brings your cursor to the top of the file. How could I easily indent a whole file without changing my cursor's position?
All "long" jump commands, such as `gg`, automatically save the bookmark for the previous poisition (note that `G` here is a "motion", so it does not overwrite the bookmark again), so all you have to do is to go back by that bookmark with two backticks: ``` nnoremap <leader>= gg=G`` ``` Or you can use `CTRL``O` and `...