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 |
|---|---|---|---|---|---|---|
12,706 | <p>If I have following lines:</p>
<pre><code>1
2
3
</code></pre>
<p>I make a macro to insert a new line below current line and type 'x':
my macro is:</p>
<pre><code>ox^[j
</code></pre>
<p>now I run this macro to the above three line by visual select the lines and type command:</p>
<pre><code>:'<,'>normal @q
... | [
{
"answer_id": 12712,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": false,
"text": "<p>You probably forgot to have your macro move down a line. So it did add a new x always on the same line. However ... | 2017/06/22 | [
"https://vi.stackexchange.com/questions/12706",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1276/"
] | If I have following lines:
```
1
2
3
```
I make a macro to insert a new line below current line and type 'x':
my macro is:
```
ox^[j
```
now I run this macro to the above three line by visual select the lines and type command:
```
:'<,'>normal @q
```
it will give me the result:
```
1
x
x
x
2
3
```
instead o... | You probably forgot to have your macro move down a line. So it did add a new x always on the same line. However since you did not share what your macro actually looks like, one cannot tell for sure.
**[update]**
You seem to be calling your macro from visual mode as you show in your updated article. However, note that... |
12,708 | <p>I would like the html tag attribute id to be highlighted differently from the rest of the tag attributes.</p>
<p>Like the Atom editor:</p>
<p><a href="https://i.stack.imgur.com/9ALRM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9ALRM.png" alt="enter image description here"></a></p>
<p>Given ... | [
{
"answer_id": 12712,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": false,
"text": "<p>You probably forgot to have your macro move down a line. So it did add a new x always on the same line. However ... | 2017/06/23 | [
"https://vi.stackexchange.com/questions/12708",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5090/"
] | I would like the html tag attribute id to be highlighted differently from the rest of the tag attributes.
Like the Atom editor:
[](https://i.stack.imgur.com/9ALRM.png)
Given this line from the html5.vim plugin
`syn keyword htmlArg contained id`
I ... | You probably forgot to have your macro move down a line. So it did add a new x always on the same line. However since you did not share what your macro actually looks like, one cannot tell for sure.
**[update]**
You seem to be calling your macro from visual mode as you show in your updated article. However, note that... |
12,722 | <p>I have a text file with this format...</p>
<pre><code>011000 001i 1111
011001 001i 0001
011010 001i 1111
011011 001i 1011
011100 001i 1111
011101 001i 1111
011110 001i 1001
011111 001i 1111
100000 001i 1111
100001 001i 1110
100001 000i 1000
</code></pre>
<p>Columns 1 and 3 are binary values which I would like to c... | [
{
"answer_id": 12712,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": false,
"text": "<p>You probably forgot to have your macro move down a line. So it did add a new x always on the same line. However ... | 2017/06/25 | [
"https://vi.stackexchange.com/questions/12722",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6461/"
] | I have a text file with this format...
```
011000 001i 1111
011001 001i 0001
011010 001i 1111
011011 001i 1011
011100 001i 1111
011101 001i 1111
011110 001i 1001
011111 001i 1111
100000 001i 1111
100001 001i 1110
100001 000i 1000
```
Columns 1 and 3 are binary values which I would like to convert to hexadecimal (e.g... | You probably forgot to have your macro move down a line. So it did add a new x always on the same line. However since you did not share what your macro actually looks like, one cannot tell for sure.
**[update]**
You seem to be calling your macro from visual mode as you show in your updated article. However, note that... |
12,734 | <p>My attempt so far:</p>
<pre><code>" Essay mode
nnoremap <F5> :call Toggle_essay()<CR>
function Toggle_essay()
if &linebreak
setlocal columns=999
setlocal nolinebreak
else
setlocal columns=60
setlocal linebreak
endif
endfunction
</code></pre>
<p>I want to ... | [
{
"answer_id": 12732,
"author": "Naumann",
"author_id": 11477,
"author_profile": "https://vi.stackexchange.com/users/11477",
"pm_score": 2,
"selected": false,
"text": "<p>if vanilla vim recognizes a certain filetype and you want to modify the shipped behavior then your own settings go in... | 2017/06/27 | [
"https://vi.stackexchange.com/questions/12734",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13201/"
] | My attempt so far:
```
" Essay mode
nnoremap <F5> :call Toggle_essay()<CR>
function Toggle_essay()
if &linebreak
setlocal columns=999
setlocal nolinebreak
else
setlocal columns=60
setlocal linebreak
endif
endfunction
```
I want to map a single button to toggle between `col... | Generally, if you want to add your own plugin, or *replace* a standard plugin with your own, it would go into `~/.vim/plugin` or `~/.vim/ftplugin`. If instead you want to keep the functionality of an existing plugin but add to it, or change just a few settings made by it, then your plugin would go into `~/.vim/after/pl... |
12,740 | <p>From the following text:</p>
<pre><code>variable1 = 'example'
foo = 'foo'
barett = 'ver'
</code></pre>
<p>I would like to yank (or visually select, if possible) the content of each line until the <code>=</code> sign:</p>
<pre><code>variable1
foo
barett
</code></pre>
<p>That is: "yank/visually select the contents... | [
{
"answer_id": 12741,
"author": "user547381",
"author_id": 13032,
"author_profile": "https://vi.stackexchange.com/users/13032",
"pm_score": 3,
"selected": true,
"text": "<p>I'm not sure this is what you want, but you could try this mapping:</p>\n\n<pre><code>xno my y'>pV']:s/=.*//<... | 2017/06/27 | [
"https://vi.stackexchange.com/questions/12740",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12266/"
] | From the following text:
```
variable1 = 'example'
foo = 'foo'
barett = 'ver'
```
I would like to yank (or visually select, if possible) the content of each line until the `=` sign:
```
variable1
foo
barett
```
That is: "yank/visually select the contents of the following lines, stopping the yanking/selection in e... | I'm not sure this is what you want, but you could try this mapping:
```
xno my y'>pV']:s/=.*//<cr>gvd
```
To use it, you would visually select your lines, then hit `my`. It should write the text before the `=` character on each line of your selection, inside the unnamed register.
Here's what it does:
* `y` yanks t... |
12,757 | <p>I save quite a few lines into a named register <code>"iy100l</code>. I can then paste from that register just fine, <code>"ip</code>.</p>
<p>I close and reopen Vim then try to paste from that register again <code>"ip</code> but it's truncated to only 50 lines.</p>
<p>So I'm guessing <code>.viminfo</code> has a lim... | [
{
"answer_id": 12758,
"author": "Naumann",
"author_id": 11477,
"author_profile": "https://vi.stackexchange.com/users/11477",
"pm_score": 3,
"selected": true,
"text": "<p>it can be configured with the <code>\"</code> character of the <code>viminfo</code> option</p>\n\n<p>From <code>:help ... | 2017/06/28 | [
"https://vi.stackexchange.com/questions/12757",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13221/"
] | I save quite a few lines into a named register `"iy100l`. I can then paste from that register just fine, `"ip`.
I close and reopen Vim then try to paste from that register again `"ip` but it's truncated to only 50 lines.
So I'm guessing `.viminfo` has a limit on the length of registers it will save but I couldn't fin... | it can be configured with the `"` character of the `viminfo` option
From `:help 'viminfo`:
```
" Maximum number of lines saved for each register. Old name of
the '<' item, with the disadvantage that you need to put a
backslash before the ", otherwise it will be recognized as the
start of a comment!
``... |
12,770 | <p>Here is my document; the entire text is on a single line:</p>
<p><a href="https://i.stack.imgur.com/XInW3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XInW3.png" alt="enter image description here"></a></p>
<p>However, I would like it to be not so wide; for example by using <code>set textwidth... | [
{
"answer_id": 12758,
"author": "Naumann",
"author_id": 11477,
"author_profile": "https://vi.stackexchange.com/users/11477",
"pm_score": 3,
"selected": true,
"text": "<p>it can be configured with the <code>\"</code> character of the <code>viminfo</code> option</p>\n\n<p>From <code>:help ... | 2017/06/29 | [
"https://vi.stackexchange.com/questions/12770",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | Here is my document; the entire text is on a single line:
[](https://i.stack.imgur.com/XInW3.png)
However, I would like it to be not so wide; for example by using `set textwidth=40` and `gq` I get my desired results:
[![enter image description here]... | it can be configured with the `"` character of the `viminfo` option
From `:help 'viminfo`:
```
" Maximum number of lines saved for each register. Old name of
the '<' item, with the disadvantage that you need to put a
backslash before the ", otherwise it will be recognized as the
start of a comment!
``... |
12,774 | <p>I have an XML file with some invalid characters. Vim show them for example as</p>
<pre><code>^C
</code></pre>
<p>I know that this is some special character and <a href="https://stackoverflow.com/questions/3844311/how-do-i-replace-or-find-non-printable-characters-in-vim-regex">how to replace them</a>. Yet what is i... | [
{
"answer_id": 12775,
"author": "k0pernikus",
"author_id": 5449,
"author_profile": "https://vi.stackexchange.com/users/5449",
"pm_score": 3,
"selected": true,
"text": "<p>I was looking for the <a href=\"http://vimhelp.appspot.com/digraph.txt.html#digraph-table\" rel=\"nofollow noreferrer... | 2017/06/29 | [
"https://vi.stackexchange.com/questions/12774",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5449/"
] | I have an XML file with some invalid characters. Vim show them for example as
```
^C
```
I know that this is some special character and [how to replace them](https://stackoverflow.com/questions/3844311/how-do-i-replace-or-find-non-printable-characters-in-vim-regex). Yet what is its meaning?
And `^C` is just one exa... | I was looking for the [digraph table](http://vimhelp.appspot.com/digraph.txt.html#digraph-table), also available in the help at:
```
:h digraph-table
```
Here's the relevant part in terms of this questions, there are a lot more available chars:
```
char digraph hex dec official name
^@ NU 0x00 0 NULL (NU... |
12,779 | <p>I defined these maps, to yank into system clipboard.</p>
<pre><code>noremap <leader>y "*y
noremap <leader>Y "*Y
noremap <leader>yy "*yy
</code></pre>
<p>But when I use the first one (<code><leader>y</code>), I find it extremely slow (taking some 4 or 5 seconds, but functioning properly). Wh... | [
{
"answer_id": 12781,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 3,
"selected": true,
"text": "<p>When you define a multi key mapping that starts with character that is itself a mapping, vim doesn't know which one yo... | 2017/06/29 | [
"https://vi.stackexchange.com/questions/12779",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10241/"
] | I defined these maps, to yank into system clipboard.
```
noremap <leader>y "*y
noremap <leader>Y "*Y
noremap <leader>yy "*yy
```
But when I use the first one (`<leader>y`), I find it extremely slow (taking some 4 or 5 seconds, but functioning properly). Why? What are possible reasons? How can I find cause of problem... | When you define a multi key mapping that starts with character that is itself a mapping, vim doesn't know which one you want after only the first character. It waits to see if you'll type another character indicating the longer mapping. If you don't type anything, after some time it will use the shorter mapping.
You c... |
12,794 | <p>I started using neovim and moved my <code>.vimrc</code> to <code>.config/nvim/init.vim</code> and other stuff is located in <code>.local/share/nvim</code>.</p>
<p>What is the best way to share configs or even plugins between vim and Neovim?
Symlinks? Can I change the directories in the .vimrc to use only one symlin... | [
{
"answer_id": 12795,
"author": "lumbric",
"author_id": 13270,
"author_profile": "https://vi.stackexchange.com/users/13270",
"pm_score": 5,
"selected": true,
"text": "<p>Having your config in Neovim's default location, do the following:</p>\n\n<pre><code>mkdir -p ~/.local/share/nvim/site... | 2017/07/01 | [
"https://vi.stackexchange.com/questions/12794",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13270/"
] | I started using neovim and moved my `.vimrc` to `.config/nvim/init.vim` and other stuff is located in `.local/share/nvim`.
What is the best way to share configs or even plugins between vim and Neovim?
Symlinks? Can I change the directories in the .vimrc to use only one symlink?
After migrating my vim config to Neovim... | Having your config in Neovim's default location, do the following:
```
mkdir -p ~/.local/share/nvim/site
ln -s ~/.local/share/nvim/site ~/.vim
ln -s .config/nvim/init.vim .vimrc
```
To fix the colorscheme I [had to set to](https://stackoverflow.com/a/10778126/859591) [256 terminal color mode](http://vim.wikia.com/w... |
12,806 | <p>By default, using <code>gq</code> with a movement command hard-wraps the text described by the movement command to 79 columns. (I'm relatively new to <code>vi</code>/<code>vim</code> so I don't know the correct terminology.) How can I configure that column count so that instead it wraps at a different number of colu... | [
{
"answer_id": 12807,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 0,
"selected": false,
"text": "<p>There are two ways to do this: setting <code>'textwidth'</code> to the width of your text in characters or columns; se... | 2017/07/03 | [
"https://vi.stackexchange.com/questions/12806",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13285/"
] | By default, using `gq` with a movement command hard-wraps the text described by the movement command to 79 columns. (I'm relatively new to `vi`/`vim` so I don't know the correct terminology.) How can I configure that column count so that instead it wraps at a different number of columns?
For example, suppose I have th... | You can do this by setting `textwidth`, and removing `t` from `formatoptions`.
```
set textwidth=29
set formatoptions-=t
```
You also need to have the `q` option enabled in your `formatoptions` to use `gq`. It seems to always be on for me, but you might want to add a `set formatoptions+=q` to be on the safe side.
S... |
12,809 | <p>Under regular conditions, the tab key will insert a tab character and backspacing that tab deletes the whole tab character.</p>
<p>I have set up expandtab and softtabstop=4 so that when I hit tab it will insert 4 spaces and when I hit "ctrl-v-tab" it will insert a real tab. However, when I backspace real tabs, it w... | [
{
"answer_id": 12811,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 1,
"selected": false,
"text": "<p>This mapping will take you out of Insert mode briefly and delete the previous character with 'X' rather than backspac... | 2017/07/03 | [
"https://vi.stackexchange.com/questions/12809",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13293/"
] | Under regular conditions, the tab key will insert a tab character and backspacing that tab deletes the whole tab character.
I have set up expandtab and softtabstop=4 so that when I hit tab it will insert 4 spaces and when I hit "ctrl-v-tab" it will insert a real tab. However, when I backspace real tabs, it will conver... | *For kicks and because I'm trying to learn some Vim scripting here is a more elaborate solution.*
This will handle backspace the way you expect, even if cursor is in first column (in which case it will join with the preceding line).
First add this to your vimrc:
```
" Sends equivalent of backspace key in Insert mode... |
12,818 | <p>I have a vim script, which uses Unix type path separator as:</p>
<pre><code>"Prg: Expand snippets {{{!
let s:plugin_dir=filter(split(&rtp, ','), 'v:val =~ "/vimf90"')[0]
let s:templatedir=s:plugin_dir . '/templates/'
function! Prog(arg)
execute 'r ' . s:templatedir . a:arg . '.txt'
%substitute#\[:EVAL:\]\(.... | [
{
"answer_id": 12811,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 1,
"selected": false,
"text": "<p>This mapping will take you out of Insert mode briefly and delete the previous character with 'X' rather than backspac... | 2017/07/04 | [
"https://vi.stackexchange.com/questions/12818",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2738/"
] | I have a vim script, which uses Unix type path separator as:
```
"Prg: Expand snippets {{{!
let s:plugin_dir=filter(split(&rtp, ','), 'v:val =~ "/vimf90"')[0]
let s:templatedir=s:plugin_dir . '/templates/'
function! Prog(arg)
execute 'r ' . s:templatedir . a:arg . '.txt'
%substitute#\[:EVAL:\]\(.\{-\}\)\[:END:\]#\... | *For kicks and because I'm trying to learn some Vim scripting here is a more elaborate solution.*
This will handle backspace the way you expect, even if cursor is in first column (in which case it will join with the preceding line).
First add this to your vimrc:
```
" Sends equivalent of backspace key in Insert mode... |
12,821 | <p>I've tried the following syntax:</p>
<pre><code>:echo 123 " comment
</code></pre>
<p>but it failed with E15 and E114 errors.</p>
<p>Is there any way to put the inline comment right after the command, so it can be ignored?</p>
| [
{
"answer_id": 12823,
"author": "Ryan Lue",
"author_id": 2593,
"author_profile": "https://vi.stackexchange.com/users/2593",
"pm_score": 1,
"selected": false,
"text": "<p>from <code>:h :echo</code> (note the last line):</p>\n\n<pre><code> ... | 2017/07/04 | [
"https://vi.stackexchange.com/questions/12821",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I've tried the following syntax:
```
:echo 123 " comment
```
but it failed with E15 and E114 errors.
Is there any way to put the inline comment right after the command, so it can be ignored? | The problem with this is, `echo` is expecting an expression. You can read what an expression is at `:h expression` in great detail. In short this means, `:echo` expects either a variable or a string (which is either single quoted or double quoted).
Now look at your command, you are echoing the number 123 and start wi... |
12,827 | <p>I installed debian strech two days ago. I installed vim and configured some plugins. I always encountered the following error while opening any file:</p>
<pre><code>vim app.py
Error detected while processing /home/sathish/.vim/plugged/sbt-vim/plugin/sbt.vim:
line 20:
E319: Sorry, the command is not available in t... | [
{
"answer_id": 12829,
"author": "jamessan",
"author_id": 15,
"author_profile": "https://vi.stackexchange.com/users/15",
"pm_score": 2,
"selected": false,
"text": "<p>In Stretch, the packages changed from supporting Python2 to Python3. As mentioned in <a href=\"https://vi.stackexchange.c... | 2017/07/05 | [
"https://vi.stackexchange.com/questions/12827",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13301/"
] | I installed debian strech two days ago. I installed vim and configured some plugins. I always encountered the following error while opening any file:
```
vim app.py
Error detected while processing /home/sathish/.vim/plugged/sbt-vim/plugin/sbt.vim:
line 20:
E319: Sorry, the command is not available in this version: p... | I tried many possible ways of adding repositories with python support for debian stretch but none of them worked out.
Finally I build my own and then it solved my issue. Here is the [link](https://github.com/sathisz/Vim-8.0-debian) for Vim with python 2 and python support |
12,835 | <p>I have a space formatted (yaml) file like the following:</p>
<pre><code>en:
templates:
template: "VERYLONGTEXTHEREWITHHUNDREDSOFLINES"
destination: "I want to jump here"
other: stuff
further_destination:
foo: bar
yet_more_destinations:
foo: bar
</code></pre>
<p>Is there any easy command to ... | [
{
"answer_id": 12837,
"author": "TimD1",
"author_id": 13333,
"author_profile": "https://vi.stackexchange.com/users/13333",
"pm_score": 2,
"selected": false,
"text": "<p>If your indenting is consistent, as shown above, you can use:</p>\n\n<pre><code>/^ [^ ]\n</code></pre>\n\n<p><code>/</... | 2017/07/05 | [
"https://vi.stackexchange.com/questions/12835",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13331/"
] | I have a space formatted (yaml) file like the following:
```
en:
templates:
template: "VERYLONGTEXTHEREWITHHUNDREDSOFLINES"
destination: "I want to jump here"
other: stuff
further_destination:
foo: bar
yet_more_destinations:
foo: bar
```
Is there any easy command to walk through from the begi... | I think that some plugins might do what you want: they create text objects based on the indentation and then let you navigate between these text objects.
But installing a plugin just for that is not always the best solution: you could do it by youself with a bit of vimscript to add to your `vimrc`:
First let's create... |
12,838 | <p>Suppose I've copied a bunch of lines of boilerplate code that I need to copy multiple times over, and then change in two separate places, in the same way:</p>
<pre><code> it 'includes sessions#new' do
expect(get: '/sign_in').to route_to('devise/sessions#new')
end
</code></pre>
<p>so I'm gonna copy this seve... | [
{
"answer_id": 12839,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": true,
"text": "<p>It is not possible, to capture groups in the <code>:g</code> command and then run an <code>:s</code> command, tha... | 2017/07/06 | [
"https://vi.stackexchange.com/questions/12838",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2593/"
] | Suppose I've copied a bunch of lines of boilerplate code that I need to copy multiple times over, and then change in two separate places, in the same way:
```
it 'includes sessions#new' do
expect(get: '/sign_in').to route_to('devise/sessions#new')
end
```
so I'm gonna copy this seven or eight times, and I ne... | It is not possible, to capture groups in the `:g` command and then run an `:s` command, that uses those captured groups. You would have to do it manually, something like this perhaps:
```
g/includes/exe "norm! yi'"|+s/sessions#new/\=split(getreg('"'))[1]/
```
This uses the `:g` command to mark all "includes" lines a... |
12,844 | <p>Usually, in Vim, pressing <code><TAB></code> autocompletes a command. For example, typing</p>
<pre><code>:set <TAB>
</code></pre>
<p>will autocomplete to <code>:set all</code>. Pressing <code><TAB></code> again will autocomplete to <code>:set termcap</code>.</p>
<p>However, on one specific Kubun... | [
{
"answer_id": 12845,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": false,
"text": "<p>I think this is enabled by the <a href=\"http://vimhelp.appspot.com/options.txt.html#%27wildmenu%27\" rel=\"nofo... | 2017/07/06 | [
"https://vi.stackexchange.com/questions/12844",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13342/"
] | Usually, in Vim, pressing `<TAB>` autocompletes a command. For example, typing
```
:set <TAB>
```
will autocomplete to `:set all`. Pressing `<TAB>` again will autocomplete to `:set termcap`.
However, on one specific Kubuntu 17.04 machine I own, pressing tab shows something like this:
[ setting that lists all the options. The [`wildmode`](http://vimhelp.appspot.com/options.txt.html#%27wildmode%27) setting can also affect the specific behavior of completion in command-line mode, including when the wildmenu will appear.
`... |
12,864 | <p>I'm trying to optimize this solution I came up with. </p>
<hr>
<p>The code bellow <strong>do works</strong> fine. So feel free to use it as a valid solution to this question.</p>
<pre><code>nnoremap <F2> :call ToogleFold()<CR>
function! ToogleFold()
if &foldlevel >= 20
"normal! z... | [
{
"answer_id": 12865,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 4,
"selected": true,
"text": "<p>So you want to toggle between all lines folded and no lines folded.</p>\n\n<p>Does this mapping do what you want?... | 2017/07/09 | [
"https://vi.stackexchange.com/questions/12864",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13368/"
] | I'm trying to optimize this solution I came up with.
---
The code bellow **do works** fine. So feel free to use it as a valid solution to this question.
```
nnoremap <F2> :call ToogleFold()<CR>
function! ToogleFold()
if &foldlevel >= 20
"normal! zM<CR> (folds all)
set foldlevel=0
else
... | So you want to toggle between all lines folded and no lines folded.
Does this mapping do what you want?
```
:nnoremap <expr> <f2> &foldlevel ? 'zM' :'zR'
``` |
12,867 | <p>I want to search and replace each occurrence of a certain pattern with a decimal number which begins at <code>1</code> and increments by one for each match.</p>
<p>I can find similarly worded questions that turn out not to be about incrementing a counter but modifying each match by a fixed amount. Other similar que... | [
{
"answer_id": 12868,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 4,
"selected": false,
"text": "<p>You need substitution with a state. I remember having provided a (/several?) <a href=\"http://stackoverflow.com/ques... | 2017/07/10 | [
"https://vi.stackexchange.com/questions/12867",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/878/"
] | I want to search and replace each occurrence of a certain pattern with a decimal number which begins at `1` and increments by one for each match.
I can find similarly worded questions that turn out not to be about incrementing a counter but modifying each match by a fixed amount. Other similar questions are about inse... | ```
:let @a=1 | %s/search/\='replace'.(@a+setreg('a',@a+1))/g
```
But beware, it will overwrite your register `a`.
I think it is a little bit more straight forward than luc's answer, but maybe his is faster. If this solution is somehow worse than his, I would love to hear any feedback why his answer is better. Any f... |
12,882 | <p>I want to select the 6th item (here <code>readImage</code>) in the auto-completion items.</p>
<p><a href="https://i.stack.imgur.com/0YqZZ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0YqZZ.png" alt="enter image description here"></a></p>
<p>The normal way i knew is pressing <kbd>ctrl</kbd><kbd>n</kbd>... | [
{
"answer_id": 19579,
"author": "3N4N",
"author_id": 16280,
"author_profile": "https://vi.stackexchange.com/users/16280",
"pm_score": 2,
"selected": false,
"text": "<p>You can select the currently highlighted <code>:h ins-completion</code> by pressing <code>Ctrl-y</code> and discard the ... | 2017/07/11 | [
"https://vi.stackexchange.com/questions/12882",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5181/"
] | I want to select the 6th item (here `readImage`) in the auto-completion items.
[](https://i.stack.imgur.com/0YqZZ.png)
The normal way i knew is pressing `ctrl``n` for 6 times until the matched word is selected and then press `enter`.
I tried differe... | You can select the currently highlighted `:h ins-completion` by pressing `Ctrl-y` and discard the completions and go back to original text by pressing `Ctrl-E`. For more information, see `:h complete_CTRL-E` and `:h complete_CTRL-Y`
* **Ctrl-E**
When completion is active you can use CTRL-E to stop it and go back to... |
12,901 | <p>Lately I've been shifting more nad more of my work from IntelliJ to vim. With a handful of plugins and setting tweaks, I don't miss the IDE much.</p>
<p>One thing I do miss is the ease of navigating a large directory tree of source files.</p>
<p>I'm working on a medium sized project with 39 source files. split acr... | [
{
"answer_id": 12913,
"author": "tracyone",
"author_id": 10798,
"author_profile": "https://vi.stackexchange.com/users/10798",
"pm_score": 1,
"selected": false,
"text": "<p>Install fuzzy searcher plugin, search any file you want then open.</p>\n\n<p>For example install <a href=\"https://g... | 2017/07/14 | [
"https://vi.stackexchange.com/questions/12901",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13185/"
] | Lately I've been shifting more nad more of my work from IntelliJ to vim. With a handful of plugins and setting tweaks, I don't miss the IDE much.
One thing I do miss is the ease of navigating a large directory tree of source files.
I'm working on a medium sized project with 39 source files. split across a handful of ... | I used [vinegar](https://github.com/tpope/vim-vinegar) for a long time, and thanks to "the tpope way" taught me the native `netrw` shortcuts (which has [a tree view](https://shapeshed.com/vim-netrw/#changing-the-directory-view-in-netrw) by the way, press `i` 3 times). All I miss on a bare Vim is the `-` mapping to go u... |
12,904 | <p>How do you move a single line in Vim with a shortcut, and make the indent always be correct, as is displayed here:
<a href="https://twitter.com/manucorporat/status/885054730812223489?s=09" rel="nofollow noreferrer">https://twitter.com/manucorporat/status/885054730812223489?s=09</a></p>
| [
{
"answer_id": 12905,
"author": "DrBeco",
"author_id": 13368,
"author_profile": "https://vi.stackexchange.com/users/13368",
"pm_score": 3,
"selected": true,
"text": "<p>Easy peasy. To map <kbd>CONTROL</kbd>+<kbd>DOWN</kbd> and <kbd>CONTROL</kbd>+<kbd>UP</kbd> you can do the following:</p... | 2017/07/14 | [
"https://vi.stackexchange.com/questions/12904",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/605/"
] | How do you move a single line in Vim with a shortcut, and make the indent always be correct, as is displayed here:
<https://twitter.com/manucorporat/status/885054730812223489?s=09> | Easy peasy. To map `CONTROL`+`DOWN` and `CONTROL`+`UP` you can do the following:
To make it go **down**:
```
:nmap <C-DOWN> ddp==
```
To make it go **up**:
```
:nmap <C-UP> ddkP==
```
You can choose other keys to map, and you can just type the commands and repeat, no need to map. Very basic stuff.
---
Edited: ... |
12,915 | <p>My current configuration makes vim automatically expand <kbd>TAB</kbd> to 4 spaces for me:</p>
<pre><code>" Define tab as 4 spaces
" Taken from http://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces
set tabstop=4 " The width of a TAB is set to 4.
" Still it is a \t. It is just... | [
{
"answer_id": 12917,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 4,
"selected": true,
"text": "<p>Put this in your .vimrc file:</p>\n\n<pre><code>autocmd BufRead,BufNewFile *.htm,*.html setlocal tabstop=2 shiftwidth=... | 2017/07/16 | [
"https://vi.stackexchange.com/questions/12915",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6335/"
] | My current configuration makes vim automatically expand `TAB` to 4 spaces for me:
```
" Define tab as 4 spaces
" Taken from http://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces
set tabstop=4 " The width of a TAB is set to 4.
" Still it is a \t. It is just that
... | Put this in your .vimrc file:
```
autocmd BufRead,BufNewFile *.htm,*.html setlocal tabstop=2 shiftwidth=2 softtabstop=2
```
Briefly, autocmds get processed when the specified events occur for the specified file name patterns. Here we just set the tab values for the current buffer to the desired value in the event of... |
12,920 | <p>When I press <kbd>gx</kbd> over a link in vim, it opens it in an external application, when it does this it also suspends Vim. </p>
<p>How do I prevent it from suspending Vim, so that I can use Vim while browsing whatever it opened externally.</p>
| [
{
"answer_id": 12936,
"author": "adelarsq",
"author_id": 177,
"author_profile": "https://vi.stackexchange.com/users/177",
"pm_score": 1,
"selected": false,
"text": "<p>Use <a href=\"https://github.com/xolox/vim-shell\" rel=\"nofollow noreferrer\">vim-shell</a> plugin instead with this co... | 2017/07/16 | [
"https://vi.stackexchange.com/questions/12920",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13456/"
] | When I press `gx` over a link in vim, it opens it in an external application, when it does this it also suspends Vim.
How do I prevent it from suspending Vim, so that I can use Vim while browsing whatever it opened externally. | Use [vim-shell](https://github.com/xolox/vim-shell) plugin instead with this config:
```
let g:netrw_nogx = 1 " disable netrw's gx mapping.
nnoremap gx :Open<CR>
``` |
12,921 | <p>I'm trying to write a wrapper command around <code>:edit</code> or <code>:find</code> specifically to open either my vimrc or a subpath of <code>~/.vim/</code> (e.g. <code>~.vim/autoloads/foo.vim</code>).</p>
<p>If I run the command with no arguments, it should open <code>~/.vim/vimrc</code>. It should accept an ar... | [
{
"answer_id": 12926,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": true,
"text": "<p>Custom completion is indeed the way to go.</p>\n\n<p>But why don't you use <code>globpath</code> instead of <code>sys... | 2017/07/16 | [
"https://vi.stackexchange.com/questions/12921",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1855/"
] | I'm trying to write a wrapper command around `:edit` or `:find` specifically to open either my vimrc or a subpath of `~/.vim/` (e.g. `~.vim/autoloads/foo.vim`).
If I run the command with no arguments, it should open `~/.vim/vimrc`. It should accept an argument to specify a subpath of `~/.vim/`, and provide tab complet... | Custom completion is indeed the way to go.
But why don't you use `globpath` instead of `system()`. Exploring directory hierarchies should much faster. Then you can filter results with `filter()`, and transform them with `map()`.
If you don't want to use exact paths, but recurse automatically, you can use `some/path/*... |
12,931 | <p>Is there a way to go forward to the first letter, maybe using <kbd>f</kbd> other than specifying the letter itself?</p>
<p>In other words I want to skip over whitespace, symbols and digits.</p>
<p>The reason I ask is that I want to make a macro and different sentences might begin with different letters, so I canno... | [
{
"answer_id": 12935,
"author": "jpaugh",
"author_id": 7547,
"author_profile": "https://vi.stackexchange.com/users/7547",
"pm_score": 2,
"selected": false,
"text": "<p>Yes. There's <code>w</code> (mnemonic: <em>word</em>) which moves to the beginning of the next word, and <code>b</code> ... | 2017/07/17 | [
"https://vi.stackexchange.com/questions/12931",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | Is there a way to go forward to the first letter, maybe using `f` other than specifying the letter itself?
In other words I want to skip over whitespace, symbols and digits.
The reason I ask is that I want to make a macro and different sentences might begin with different letters, so I cannot put a particular letter ... | Based on DLMcMMayhem's [hint](https://vi.stackexchange.com/q/12931/7547#comment-22228), I found that following search will do what you need:
```
/\A*\zs\a
```
* `\A*` searches for zero or more non-alphabetic characters (equivalent to `[^A-Za-z]`)
* `\a` searches for any alphabetic character (equivalent to `[A-Za-z]`... |
12,937 | <p>Libraries evolve all the time and I often face the situation where after an update some function name have changed and they return errors in the updated version of the library.</p>
<p>It's easy to replace all the instances of a word by another however I would like to keep track of the old version by commenting the ... | [
{
"answer_id": 12938,
"author": "mitoRibo",
"author_id": 13476,
"author_profile": "https://vi.stackexchange.com/users/13476",
"pm_score": 1,
"selected": false,
"text": "<p>You can use capture groups in your replace and replace the original line with two lines. Here is an example with pyt... | 2017/07/18 | [
"https://vi.stackexchange.com/questions/12937",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12085/"
] | Libraries evolve all the time and I often face the situation where after an update some function name have changed and they return errors in the updated version of the library.
It's easy to replace all the instances of a word by another however I would like to keep track of the old version by commenting the line conta... | ### Script
```
func! CoRep (pat, ...)
let line_loc = search (a:pat, 'nw')
let line = getline (line_loc)
call setline (line_loc, '// '.line)
let pair = 0
while pair < a:0
let pat = a:000[pair]
let sub = a:000[pair+1]
let line = substitute (line, pat, sub, '')
... |
12,958 | <p>Say I perform a combination of keys and now they are registered in <code>.</code></p>
<p>Now I want to go down X lines and run <code>.</code> on each one.</p>
<p>For example say I have:</p>
<pre><code>{colorComponentId: 0, value: (value.warmWhite * 255)},
{colorComponentId: 1, value: (value.coldWhite * 255)},
{co... | [
{
"answer_id": 12956,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 0,
"selected": false,
"text": "<p><code>:syncbind</code> </p>\n\n<p>This will <em>Force all 'scrollbind' windows to have the same relative offset.</em>... | 2017/07/20 | [
"https://vi.stackexchange.com/questions/12958",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7783/"
] | Say I perform a combination of keys and now they are registered in `.`
Now I want to go down X lines and run `.` on each one.
For example say I have:
```
{colorComponentId: 0, value: (value.warmWhite * 255)},
{colorComponentId: 1, value: (value.coldWhite * 255)},
{colorComponentId: 2, value: (value.red * 255)},
{col... | If you need to make a couple of splits synced with an increasing offset, the routine would be:
1. Split the window vertically `C-w` `v`
2. Move to the next window `C-w` `w`
3. Scroll down one screen `C-f` (add `C-e` as needed)
4. Repeat steps 1 - 3
Now as all splits are open and you are on the last one, you need to b... |
12,961 | <p>For years I unknowingly used some, shall we say, deviant distribution of vim that would stay at the location of the highlighted search result after hitting <code><Esc></code> in the middle of a search instead of jumping back to the original position.</p>
<p>I've tried for more than a year now to forget that m... | [
{
"answer_id": 12969,
"author": "laktak",
"author_id": 10337,
"author_profile": "https://vi.stackexchange.com/users/10337",
"pm_score": 1,
"selected": false,
"text": "<p>I don't think you can configure this in VIM (see <code>help incsearch</code>) but </p>\n\n<p><a href=\"https://github.... | 2017/07/20 | [
"https://vi.stackexchange.com/questions/12961",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13499/"
] | For years I unknowingly used some, shall we say, deviant distribution of vim that would stay at the location of the highlighted search result after hitting `<Esc>` in the middle of a search instead of jumping back to the original position.
I've tried for more than a year now to forget that muscle memory, but I cannot ... | There is an option for this:
`set cpoptions+=x`
From `:help cpo-x`
```
x <Esc> on the command-line executes the command-line.
The default in Vim is to abandon the command-line,
because <Esc> normally aborts a command. |c_<Esc>|
```
It is also the default vim behavior when `compatible` is set,... |
12,962 | <p>Whenever I open a line using <code>o</code> or <code>O</code>, the cursor starts at the correct indentation (I'm not sure if vim uses syntax hints for this or just mimics the position of first character of the neighboring lines). Same happens when opening a line in insert mode with <code>Enter</code> keypress.</p>
... | [
{
"answer_id": 12969,
"author": "laktak",
"author_id": 10337,
"author_profile": "https://vi.stackexchange.com/users/10337",
"pm_score": 1,
"selected": false,
"text": "<p>I don't think you can configure this in VIM (see <code>help incsearch</code>) but </p>\n\n<p><a href=\"https://github.... | 2017/07/20 | [
"https://vi.stackexchange.com/questions/12962",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12650/"
] | Whenever I open a line using `o` or `O`, the cursor starts at the correct indentation (I'm not sure if vim uses syntax hints for this or just mimics the position of first character of the neighboring lines). Same happens when opening a line in insert mode with `Enter` keypress.
Is there a quick way to similarly auto-i... | There is an option for this:
`set cpoptions+=x`
From `:help cpo-x`
```
x <Esc> on the command-line executes the command-line.
The default in Vim is to abandon the command-line,
because <Esc> normally aborts a command. |c_<Esc>|
```
It is also the default vim behavior when `compatible` is set,... |
12,967 | <p>I have a CSV file where I want to remove every second column. Each column value are separated by quotes and the column values can contain field separators: this means that convenient solutions such as this AWK script <a href="https://stackoverflow.com/questions/22354082/print-every-nth-column-of-a-file">here</a> won... | [
{
"answer_id": 12971,
"author": "Naumann",
"author_id": 11477,
"author_profile": "https://vi.stackexchange.com/users/11477",
"pm_score": 3,
"selected": true,
"text": "<p>this is doable with :s, as in</p>\n\n<p><code>:%s/\\(\"[^\"]*\"\\)\\s*,\\s*\"[^\"]*\"/\\1/g</code></p>\n"
},
{
... | 2017/07/20 | [
"https://vi.stackexchange.com/questions/12967",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10986/"
] | I have a CSV file where I want to remove every second column. Each column value are separated by quotes and the column values can contain field separators: this means that convenient solutions such as this AWK script [here](https://stackoverflow.com/questions/22354082/print-every-nth-column-of-a-file) won't work out of... | this is doable with :s, as in
`:%s/\("[^"]*"\)\s*,\s*"[^"]*"/\1/g` |
12,973 | <p><a href="https://i.stack.imgur.com/UuaVB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UuaVB.png" alt="enter image description here"></a></p>
<p>I use <code>eslint</code> with <a href="https://github.com/w0rp/ale" rel="noreferrer"><code>ale</code></a> to lint my Javascript code. After editing a code blo... | [
{
"answer_id": 13009,
"author": "Joel Z.",
"author_id": 13441,
"author_profile": "https://vi.stackexchange.com/users/13441",
"pm_score": 4,
"selected": false,
"text": "<p>You can easily move between errors by adding some key bindings to ale's <code><Plug></code> mappings (see <code... | 2017/07/21 | [
"https://vi.stackexchange.com/questions/12973",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13179/"
] | [](https://i.stack.imgur.com/UuaVB.png)
I use `eslint` with [`ale`](https://github.com/w0rp/ale) to lint my Javascript code. After editing a code block, I often have a few errors to fix. Fixing is done by navigating to the next erroneous line, reading... | ALE has many commands that can navigate linting errors, and `:ALENext` works great for this operation. By default, ALE maps no bindings, I assume to allow for non-clashing customization.
In your `~/.vimrc` (or `~/.config/nvim/init.vim` for NeoVim), I use:
```
nmap <silent> <leader>aj :ALENext<cr>
nmap <silent> <leade... |
12,983 | <p>I am trying to do a search and replace on a large database file where some of the urls are escaped and some not, e.g.:</p>
<pre><code>http://www.example.com
http:\\/\\/www.example.com
</code></pre>
<p>I thought I could use a simple character class in a regex like this:</p>
<pre><code>%s~http\(:[/\\]+www.example.c... | [
{
"answer_id": 12984,
"author": "Eaten by a Grue",
"author_id": 13528,
"author_profile": "https://vi.stackexchange.com/users/13528",
"pm_score": 0,
"selected": false,
"text": "<p>Figured this out myself using alternation and <code>\\z</code> for pattern matching:</p>\n\n<pre><code>%s,\\z... | 2017/07/21 | [
"https://vi.stackexchange.com/questions/12983",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13528/"
] | I am trying to do a search and replace on a large database file where some of the urls are escaped and some not, e.g.:
```
http://www.example.com
http:\\/\\/www.example.com
```
I thought I could use a simple character class in a regex like this:
```
%s~http\(:[/\\]+www.example.com\)~https\1~g
```
But won't work n... | In your search pattern of the `:s` part you are looking for `www.` which is not part of your source. So it won't match. Better would be to make that part optionally:
```
%s~http\(:[/\\]\+\(www.\)\?example.com\)~https\1~g
```
or even better:
```
%s~http:[/\\]\+\(\(www.\)\?example.com\)~https://\1~g
```
which will... |
12,988 | <p>I want to edit words that need accents (á) were they are missing. It's no problem to write down accents in insert mode: it is just "' + letter", so I can easily write á, é, í, ó, ú. </p>
<h2>How do get accent on a letter in normal mode (on top of a given letter)?</h2>
<h3>How do I transform "o" into "ó" in normal ... | [
{
"answer_id": 12994,
"author": "Jair López",
"author_id": 6698,
"author_profile": "https://vi.stackexchange.com/users/6698",
"pm_score": 2,
"selected": false,
"text": "<p>You could put one of the following codes at the end of your <code>vimrc</code> file to make the <kbd>-</kbd> key tog... | 2017/07/22 | [
"https://vi.stackexchange.com/questions/12988",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12815/"
] | I want to edit words that need accents (á) were they are missing. It's no problem to write down accents in insert mode: it is just "' + letter", so I can easily write á, é, í, ó, ú.
How do get accent on a letter in normal mode (on top of a given letter)?
---------------------------------------------------------------... | If you set `'digraph'`, (IOW makes sure `:set digraph` is in your `.vimrc`) it could become as simple as:
```
nnoremap <silent> µ s<c-r>"<bs>'<esc>
```
The key points are:
* `s<c-r>"` that replaces the current character under the cursor with itself and stays in insert mode -- this is important for the next step.
* ... |
12,993 | <p>I've set <code>formatprg</code> in my vimrc to use the <a href="http://www.nicemice.net/par/" rel="nofollow noreferrer">par</a> text formatter when I type <strong><code>gq</code></strong>.</p>
<pre><code>setg formatprg=par\ -w90
</code></pre>
<p>When I'm in a buffer whose <code>textwidth</code> has been set (e.g. ... | [
{
"answer_id": 12997,
"author": "Jair López",
"author_id": 6698,
"author_profile": "https://vi.stackexchange.com/users/6698",
"pm_score": 2,
"selected": false,
"text": "<p>That's when the <a href=\"http://vimhelp.appspot.com/autocmd.txt.html#OptionSet\" rel=\"nofollow noreferrer\"><code>... | 2017/07/22 | [
"https://vi.stackexchange.com/questions/12993",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1855/"
] | I've set `formatprg` in my vimrc to use the [par](http://www.nicemice.net/par/) text formatter when I type **`gq`**.
```
setg formatprg=par\ -w90
```
When I'm in a buffer whose `textwidth` has been set (e.g. the gitcommit filetype sets `textwidth=72`), I'd like to use that number rather than 90.
Instead of hard-cod... | That's when the [`OptionSet`](http://vimhelp.appspot.com/autocmd.txt.html#OptionSet) event comes in handy, but it doesn't work when it's triggered on startup so you need the [`VimEnter`](http://vimhelp.appspot.com/autocmd.txt.html#VimEnter) event too.
If your workflow includes several files opened in different window... |
13,017 | <p>I'm using MacVim <a href="https://github.com/macvim-dev/macvim/releases/tag/snapshot-134" rel="noreferrer">snapshot 134</a> (on Mac OS X 10.9.5), which has support for Lua:</p>
<pre><code>$ vim --version | grep lua
+dialog_con_gui +lua/dyn +rightleft +writebackup
</code></pre>
<p>I've got Lua instal... | [
{
"answer_id": 12997,
"author": "Jair López",
"author_id": 6698,
"author_profile": "https://vi.stackexchange.com/users/6698",
"pm_score": 2,
"selected": false,
"text": "<p>That's when the <a href=\"http://vimhelp.appspot.com/autocmd.txt.html#OptionSet\" rel=\"nofollow noreferrer\"><code>... | 2017/07/23 | [
"https://vi.stackexchange.com/questions/13017",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2736/"
] | I'm using MacVim [snapshot 134](https://github.com/macvim-dev/macvim/releases/tag/snapshot-134) (on Mac OS X 10.9.5), which has support for Lua:
```
$ vim --version | grep lua
+dialog_con_gui +lua/dyn +rightleft +writebackup
```
I've got Lua installed and can even run it as an external command from wi... | That's when the [`OptionSet`](http://vimhelp.appspot.com/autocmd.txt.html#OptionSet) event comes in handy, but it doesn't work when it's triggered on startup so you need the [`VimEnter`](http://vimhelp.appspot.com/autocmd.txt.html#VimEnter) event too.
If your workflow includes several files opened in different window... |
13,020 | <p>how do I remap backspace combinations? I can remap backspace itself in normal mode, but not in insert mode, and I cannot map combinations:</p>
<pre><code>" this works:
nmap <BS> dd
" this doesn't work:
imap <BS> <Esc>dd
nmap <C-BS> dd
imap <C-BS> <Esc>dd
</code></pre>
<p>I'm us... | [
{
"answer_id": 13021,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>You need to first press <kbd>ctrl+v</kbd> in insert mode before pressing <kbd>ctrl+backspace</kbd> to insert the termina... | 2017/07/24 | [
"https://vi.stackexchange.com/questions/13020",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/836/"
] | how do I remap backspace combinations? I can remap backspace itself in normal mode, but not in insert mode, and I cannot map combinations:
```
" this works:
nmap <BS> dd
" this doesn't work:
imap <BS> <Esc>dd
nmap <C-BS> dd
imap <C-BS> <Esc>dd
```
I'm using Vim 7.4 inside Terminator. | You need to first press `ctrl+v` in insert mode before pressing `ctrl+backspace` to insert the terminal code of `ctrl+backspace`.
Your mapping will look like this:
```
inoremap ^_ <Esc>dd
```
See [`:h i_CTRL-V`](http://vimhelp.appspot.com/insert.txt.html#i_CTRL%2dV):
```
CTRL-V Insert next non-digit literally... |
13,028 | <p>Simple question. I want to use the <code>Tabular</code> plugin to right-align end-of-line comments for arbitrary filetypes, and for that I need to write a simple <code>nnoremap</code> that uses the current filetype's comment character. How can I do this?</p>
| [
{
"answer_id": 13030,
"author": "Luke Davis",
"author_id": 8084,
"author_profile": "https://vi.stackexchange.com/users/8084",
"pm_score": 0,
"selected": false,
"text": "<p>Well, I figured out how to do this if you also use the <code>NERDCommenter</code> plugin. Simply query the <code>'le... | 2017/07/25 | [
"https://vi.stackexchange.com/questions/13028",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8084/"
] | Simple question. I want to use the `Tabular` plugin to right-align end-of-line comments for arbitrary filetypes, and for that I need to write a simple `nnoremap` that uses the current filetype's comment character. How can I do this? | I usually go with the `'commentstring'` option and depend on the filetype plugin to set this up correctly for me (if not, that should be added to the corresponding filetype to make at least folding work). So in that case, you can simply use:
```
echo split(&commentstring, '%s')[0]
```
which would return the beginni... |
13,029 | <p>I am using the Vim version 8.0 editor, mostly via GVim. I would like to be able to type unicode/greek characters like lambda, mu, alpha inside my Haskell scripts.</p>
<p>There is a vim plugin called <a href="https://github.com/joom/latex-unicoder.vim" rel="nofollow noreferrer">latex-unicoder</a> which is <em>almost... | [
{
"answer_id": 13030,
"author": "Luke Davis",
"author_id": 8084,
"author_profile": "https://vi.stackexchange.com/users/8084",
"pm_score": 0,
"selected": false,
"text": "<p>Well, I figured out how to do this if you also use the <code>NERDCommenter</code> plugin. Simply query the <code>'le... | 2017/07/25 | [
"https://vi.stackexchange.com/questions/13029",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13566/"
] | I am using the Vim version 8.0 editor, mostly via GVim. I would like to be able to type unicode/greek characters like lambda, mu, alpha inside my Haskell scripts.
There is a vim plugin called [latex-unicoder](https://github.com/joom/latex-unicoder.vim) which is *almost* what I want. The disadvantage of the plugin is t... | I usually go with the `'commentstring'` option and depend on the filetype plugin to set this up correctly for me (if not, that should be added to the corresponding filetype to make at least folding work). So in that case, you can simply use:
```
echo split(&commentstring, '%s')[0]
```
which would return the beginni... |
13,039 | <p>Listed <a href="https://en.wikibooks.org/wiki/Learning_the_vi_Editor/Vim/Modes" rel="nofollow noreferrer">here</a> is "each mode" for vim.</p>
<p>I did not see "search" in the list, but I should think that search (<code>/</code> or <code>?</code>) would be a mode on its own.</p>
<p>I have to make a very formal pre... | [
{
"answer_id": 13040,
"author": "StandardEyre",
"author_id": 6590,
"author_profile": "https://vi.stackexchange.com/users/6590",
"pm_score": 1,
"selected": false,
"text": "<p><code>help: search-commands</code> returns the stuff I type to execute searches. </p>\n\n<p>Since these are all c... | 2017/07/25 | [
"https://vi.stackexchange.com/questions/13039",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5108/"
] | Listed [here](https://en.wikibooks.org/wiki/Learning_the_vi_Editor/Vim/Modes) is "each mode" for vim.
I did not see "search" in the list, but I should think that search (`/` or `?`) would be a mode on its own.
I have to make a very formal presentation about my internship, and I had some space on my poster, so I decid... | These few commands that are only available while searching via `/` / `?` with `'incsearch'`: `<c-l>`, `<c-g>`, and `<c-t>`.
I am not sure 3 commands constitute a mode, but maybe it does. If we look at the documentation it is listed as a command mode mapping and there is no special `map` variant to make more such mappi... |
13,050 | <p>How can I quickly shift only inner contents of HTML tag X, when they are on separate lines to the opening and closing X tag? Example below: I want to shift <strong>only</strong> 2 lines with <code><p></code> tags when the cursor is somewhere on <code><div></code> or <code></div></code>.</p>
<pre><... | [
{
"answer_id": 13040,
"author": "StandardEyre",
"author_id": 6590,
"author_profile": "https://vi.stackexchange.com/users/6590",
"pm_score": 1,
"selected": false,
"text": "<p><code>help: search-commands</code> returns the stuff I type to execute searches. </p>\n\n<p>Since these are all c... | 2017/07/26 | [
"https://vi.stackexchange.com/questions/13050",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11038/"
] | How can I quickly shift only inner contents of HTML tag X, when they are on separate lines to the opening and closing X tag? Example below: I want to shift **only** 2 lines with `<p>` tags when the cursor is somewhere on `<div>` or `</div>`.
```
<div>
<p>This is some paragraph.</p>
<p>And this is other paragraph.<... | These few commands that are only available while searching via `/` / `?` with `'incsearch'`: `<c-l>`, `<c-g>`, and `<c-t>`.
I am not sure 3 commands constitute a mode, but maybe it does. If we look at the documentation it is listed as a command mode mapping and there is no special `map` variant to make more such mappi... |
13,055 | <p>I need to replace on all lines sequence of words:</p>
<pre><code>public boolean
public string
public IList
</code></pre>
<p>etc..</p>
<p>with modifier removed aka:</p>
<pre><code>boolean
string
IList
</code></pre>
<p>Is there a way how to remove first part of match and keep the other? I know there is something ... | [
{
"answer_id": 13056,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 3,
"selected": true,
"text": "<p>First, we must know the pattern of the modifiers that you want to remove. It could be something as simple as <code... | 2017/07/27 | [
"https://vi.stackexchange.com/questions/13055",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10529/"
] | I need to replace on all lines sequence of words:
```
public boolean
public string
public IList
```
etc..
with modifier removed aka:
```
boolean
string
IList
```
Is there a way how to remove first part of match and keep the other? I know there is something called submatch in vim, but I don't know if it can be us... | First, we must know the pattern of the modifiers that you want to remove. It could be something as simple as `boolean\|string\|IList` if these are the only keywords, or you could write a more complex expression. For intsance, to match any keyword that is not in a given list, one could use `\(\(class\|interface\)\>\)\@!... |
13,062 | <p>I'm trying to establish syntax coloring for a certain lexical syntax: a "buffer literal". A buffer literal begins with <code>#b'</code> and ends with <code>'</code>. Between the single quotes, there can be undivided pairs of hex digits, with optional whitespace in between, that being spaces, tabs and newlines.</p>
... | [
{
"answer_id": 13069,
"author": "Jair López",
"author_id": 6698,
"author_profile": "https://vi.stackexchange.com/users/6698",
"pm_score": 4,
"selected": true,
"text": "<p>There are a couple of nuances that need to be grasped in order to make it work:</p>\n\n<ol>\n<li>The <code>\".\"</cod... | 2017/07/27 | [
"https://vi.stackexchange.com/questions/13062",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13611/"
] | I'm trying to establish syntax coloring for a certain lexical syntax: a "buffer literal". A buffer literal begins with `#b'` and ends with `'`. Between the single quotes, there can be undivided pairs of hex digits, with optional whitespace in between, that being spaces, tabs and newlines.
Valid buffer literals:
```
#... | There are a couple of nuances that need to be grasped in order to make it work:
1. The `"."` in `buferr` matches `'` and will eat it up before the pattern in `buflit` can see it and, as a result, the `buflit` region mismatch both delimiters. You could deal with this issue by adding `keepend` (see [`:help :syn-keepend`... |
13,065 | <p>I have a file like this:</p>
<pre><code># Heading A
### Heading B1
lorem ipsum
### Heading B2
lorem ipsum
</code></pre>
<p>and I want to reduce the header levels of B1 and B2 to look like this:</p>
<pre><code># Heading A
## Heading B1
lorem ipsum
## Heading B2
lorem ipsum
</code></pre>
<p>I know how to... | [
{
"answer_id": 13067,
"author": "apparat",
"author_id": 5331,
"author_profile": "https://vi.stackexchange.com/users/5331",
"pm_score": 3,
"selected": true,
"text": "<p>You could simply search for two #s at the beginning of the line an replace it with one #.</p>\n\n<p>Normal mode global r... | 2017/07/28 | [
"https://vi.stackexchange.com/questions/13065",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13618/"
] | I have a file like this:
```
# Heading A
### Heading B1
lorem ipsum
### Heading B2
lorem ipsum
```
and I want to reduce the header levels of B1 and B2 to look like this:
```
# Heading A
## Heading B1
lorem ipsum
## Heading B2
lorem ipsum
```
I know how to increase markdown header levels from this [answe... | You could simply search for two #s at the beginning of the line an replace it with one #.
Normal mode global replace:
```
:%s/^##/#/g
```
and for visual mode:
```
'<,'>s/^##/#/g
``` |
13,072 | <p>I am new to VIM and have been looking for a feature/plugin like guake for terminals wherein I could open the help functionality in a dropdown box without typing <code>:q</code> to close the vim help menu. </p>
<p>If there is a better way than to close and open new windows for help text I would love to hear those op... | [
{
"answer_id": 13078,
"author": "jacwah",
"author_id": 9996,
"author_profile": "https://vi.stackexchange.com/users/9996",
"pm_score": 1,
"selected": false,
"text": "<p>I am not familiar with guake and am not sure what you mean by \"dropdown box\". However, I will try to give you some tip... | 2017/07/28 | [
"https://vi.stackexchange.com/questions/13072",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13633/"
] | I am new to VIM and have been looking for a feature/plugin like guake for terminals wherein I could open the help functionality in a dropdown box without typing `:q` to close the vim help menu.
If there is a better way than to close and open new windows for help text I would love to hear those options as well. | 1. We need to know whether a help window is opened to close it.
We could get the list of help buffers and filter the hidden-readonly-nonmodifiable ones with a `'help'` filetype that are displayed in a window to know if a help buffer is already displayed. This is quite complex, but this could be done with an boolean ex... |
13,079 | <p>For some reason when I change my colorscheme it doesn't seem to change all the syntax elements, or changes them to a completely different color than they should be. I know the problem <strong>isn't about</strong> the color capability of my terminal: when I <code>echo $TERM</code> I get <code>xterm-256color</code>. I... | [
{
"answer_id": 13082,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 2,
"selected": false,
"text": "<p>You may have the \"wrong\" setting for <code>background</code>. Vim can pick one set of colors for 'dark' and another... | 2017/07/29 | [
"https://vi.stackexchange.com/questions/13079",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13638/"
] | For some reason when I change my colorscheme it doesn't seem to change all the syntax elements, or changes them to a completely different color than they should be. I know the problem **isn't about** the color capability of my terminal: when I `echo $TERM` I get `xterm-256color`. I've also tried the command `set t_Co=2... | The problem with the specific macvim-light colour scheme you link to is that it has incredibly limited support for terminals: the *only* syntax groups it adds highlighting for are `Normal`, `DiffAdd`, `DiffChange`, `DiffText`, and `DiffDelete`. So if you're not viewing a diff, it essentially does nothing.
In general, ... |
13,086 | <p>I usually have two windows open, one in which I'm working and one in which I'm viewing some information (compiler messages, relevant library headers, etc. etc.). Now, it's easy to switch the buffer <em>on which I'm working</em> with <code>:b</code>, which offers nice tab-completion – however, that's not actually nec... | [
{
"answer_id": 13087,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": false,
"text": "<p>Maybe you could use something like this:</p>\n\n<pre><code>function! ChangeWindow(buf)\n execute \"wincmd p\"\n ex... | 2017/07/31 | [
"https://vi.stackexchange.com/questions/13086",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6882/"
] | I usually have two windows open, one in which I'm working and one in which I'm viewing some information (compiler messages, relevant library headers, etc. etc.). Now, it's easy to switch the buffer *on which I'm working* with `:b`, which offers nice tab-completion – however, that's not actually necessary very often sin... | Maybe you could use something like this:
```
function! ChangeWindow(buf)
execute "wincmd p"
execute "e " . a:buf
execute "wincmd p"
endfunction
command! -complete=buffer -nargs=1 CW call ChangeWindow("<args>")
```
You create a function `ChangeWindow()` which takes as argument a buffer name and execute t... |
13,095 | <p>I have been going through some <a href="https://vimgolf.com/challenges/540629666a1e4000020d9e5a#5946a26411266f0006000005" rel="nofollow noreferrer">answers to a vimgolf</a>, and stumbled upon this regex:</p>
<pre><code>:s/\_W*/-/g|x<CR>
</code></pre>
<p>Which converts </p>
<pre><code>abcdefghijklm
</code></... | [
{
"answer_id": 13096,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p>This is not a question of hidden character, the trick comes from the <code>*</code> combined with the flag <code>g</code>... | 2017/08/01 | [
"https://vi.stackexchange.com/questions/13095",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13179/"
] | I have been going through some [answers to a vimgolf](https://vimgolf.com/challenges/540629666a1e4000020d9e5a#5946a26411266f0006000005), and stumbled upon this regex:
```
:s/\_W*/-/g|x<CR>
```
Which converts
```
abcdefghijklm
```
to
```
-a-b-c-d-e-f-g-h-i-j-k-l-m-
```
The regex (without unrelated keystrokes) ... | This is not a question of hidden character, the trick comes from the `*` combined with the flag `g`:
Specifying `*` after a character classe will match "zero or more" items (which includes an empty string): between `a` and `b` there is zero non-word character, thus `\W*` will match this "not existing space".
For exam... |
13,106 | <p>I want to search for:</p>
<blockquote>
<p>From start of the line, any number of white spaces followed by any
number of digits NOT followed by a dot.</p>
</blockquote>
<p>And replace it with all that was searched and a dot. This is just to introduce a dot in a simple numbered list when forgotten.</p>
<p>So, I ... | [
{
"answer_id": 13108,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>If I understand correctly your question what you want is this:</p>\n\n<pre><code>:%s/\\s*\\d\\+\\([0-9\\.]\\)\\@!/\\0.\n... | 2017/08/02 | [
"https://vi.stackexchange.com/questions/13106",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3095/"
] | I want to search for:
>
> From start of the line, any number of white spaces followed by any
> number of digits NOT followed by a dot.
>
>
>
And replace it with all that was searched and a dot. This is just to introduce a dot in a simple numbered list when forgotten.
So, I went:
```
:%s/^\(\s*\d\+\)\.\@!/\1\.
... | You're almost there, what you need is `\>` at the end of the regular expression like so:
```
:%s/^\(\s*\d\+\)\.\@!\>/\1\.
```
Or even better:
```
:%s/^\s*\d\+\.\@!\>\zs/.
```
**Note:** A `.` in the replacement part of the `:substitute` command is literal so you can remove the leading `\`. [`:help sub-replace-spec... |
13,111 | <p>When opening a bind zone file, I have to type by hand <code>:set ft=bindzone</code> to get syntax highlighting. It's not set automatically on load.</p>
<p>On another hand others filetypes (such as php, perl or kind) are properly set.</p>
<p>Where I should look first to solve this ?</p>
| [
{
"answer_id": 13114,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 0,
"selected": false,
"text": "<p><code>filetype</code> is set based on the file extension or by <code>ftdetect</code> plugins.\nFor example <code>PHP</c... | 2017/08/02 | [
"https://vi.stackexchange.com/questions/13111",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13679/"
] | When opening a bind zone file, I have to type by hand `:set ft=bindzone` to get syntax highlighting. It's not set automatically on load.
On another hand others filetypes (such as php, perl or kind) are properly set.
Where I should look first to solve this ? | the filetype bindzone is supported by default in Vim using the [filetype.vim](https://github.com/vim/vim/blob/master/runtime/filetype.vim#L297-L307) in `$VIMRUNTIME` which sets the filetype according to the properties of your file. By default however, Vim only sets the filetype to `bindzone` if the file is called `name... |
13,119 | <p>Does anyone know a quick shortcut I can use to replace a word in a series of words connected with underscores?</p>
<p>Given:</p>
<pre><code>Create_in_one_of_these_words
</code></pre>
<p>I want to make, where <code>|</code> is cursor:</p>
<pre><code>Create_in_|_of_thse_words
</code></pre>
| [
{
"answer_id": 13120,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 3,
"selected": true,
"text": "<p>If you are anywhere on that line, you can try this:</p>\n\n<ul>\n<li><kbd>0</kbd> - to go to the beginign of line</li>\n... | 2017/08/02 | [
"https://vi.stackexchange.com/questions/13119",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7783/"
] | Does anyone know a quick shortcut I can use to replace a word in a series of words connected with underscores?
Given:
```
Create_in_one_of_these_words
```
I want to make, where `|` is cursor:
```
Create_in_|_of_thse_words
``` | If you are anywhere on that line, you can try this:
* `0` - to go to the beginign of line
* `/one` - to jump to the word `one` (in this particular case even `f``o` would be enough - see `:help f`)
* `c``t``\_` - this will delete everything between cursor and character pressed after `t` - so in this case everything til... |
13,124 | <p>Considering this type of Json structure :</p>
<pre><code>[
{
"id": "0000000000001",
"en-US": "String 1"
},
{
"id": "0000000000002",
"en-US": "String 2"
}
...
]
</code></pre>
<p>I want to get this structure:</p>
<pre><code>[
{
"id": "0000000000001",
... | [
{
"answer_id": 13125,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>If you're willing to use one command by language you can do this:</p>\n\n<pre><code>g/en-US/t.|s/en-US/en-GB\ng/en-GB/t.|... | 2017/08/03 | [
"https://vi.stackexchange.com/questions/13124",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10170/"
] | Considering this type of Json structure :
```
[
{
"id": "0000000000001",
"en-US": "String 1"
},
{
"id": "0000000000002",
"en-US": "String 2"
}
...
]
```
I want to get this structure:
```
[
{
"id": "0000000000001",
"en-US": "String 1",
"... | If you're willing to use one command by language you can do this:
```
g/en-US/t.|s/en-US/en-GB
g/en-GB/t.|s/fr-FR/en-GB
```
As you can see we reuse your command, and add another one to be executed with the `|` character.
**Edit** As suggested in the comments (Thank you @Doktor OSwaldo!) it is possible to put the co... |
13,153 | <p>I'm trying to combine two features of vim, but it doesn't seem to be possible.</p>
<p><strong>1: <a href="http://vimdoc.sourceforge.net/htmldoc/starting.html#vim-arguments" rel="nofollow noreferrer"><code>vim -</code></a></strong></p>
<p>The first feature is invoking vim with a single-dash argument, which causes v... | [
{
"answer_id": 13125,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>If you're willing to use one command by language you can do this:</p>\n\n<pre><code>g/en-US/t.|s/en-US/en-GB\ng/en-GB/t.|... | 2017/08/06 | [
"https://vi.stackexchange.com/questions/13153",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8927/"
] | I'm trying to combine two features of vim, but it doesn't seem to be possible.
**1: [`vim -`](http://vimdoc.sourceforge.net/htmldoc/starting.html#vim-arguments)**
The first feature is invoking vim with a single-dash argument, which causes vim to read stdin and use the resulting text as the contents of the initial scr... | If you're willing to use one command by language you can do this:
```
g/en-US/t.|s/en-US/en-GB
g/en-GB/t.|s/fr-FR/en-GB
```
As you can see we reuse your command, and add another one to be executed with the `|` character.
**Edit** As suggested in the comments (Thank you @Doktor OSwaldo!) it is possible to put the co... |
13,158 | <p>This should be easy but it seems to be a blind spot in vim. I'm looking for a short one line mapping, let's say to <code><leader>r</code>, to right-align text inside a visual block selection. For example, consider the following sample text:</p>
<pre><code>a1 a
b22 b
c234 c
d4444 d
</code></pre>
<p>Af... | [
{
"answer_id": 13203,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 4,
"selected": true,
"text": "<p>Here's a <code>simple</code> mapping to do the task:</p>\n\n<pre><code>vnoremap <silent> rs \"zy:call setreg(\"z\"... | 2017/08/06 | [
"https://vi.stackexchange.com/questions/13158",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13731/"
] | This should be easy but it seems to be a blind spot in vim. I'm looking for a short one line mapping, let's say to `<leader>r`, to right-align text inside a visual block selection. For example, consider the following sample text:
```
a1 a
b22 b
c234 c
d4444 d
```
After, in a visual block, selecting exactly t... | Here's a `simple` mapping to do the task:
```
vnoremap <silent> rs "zy:call setreg("z", system("echo \"" . @z . "\" \| sed 's/[ \\t]\\+//' \| rs -j 0 1"), "b")<CR>gv"zp
```
It uses `z` register to keep output of it's intermediate steps. I had to add call to `sed` to remove trailing white chars from the input to `rs`... |
13,162 | <p>I recently wanted to have a mapping that I could trigger from <code>normal mode</code> as well as from <code>insert mode</code>. Writing the same mapping for multiple modes annoyed me as it cluttered my .vimrc and requires me to make the same changes multiple times.</p>
<hr>
<p>It was pointed out to me, that no su... | [
{
"answer_id": 13164,
"author": "omnesia",
"author_id": 13691,
"author_profile": "https://vi.stackexchange.com/users/13691",
"pm_score": 0,
"selected": false,
"text": "<p>To answer the question I first tried to solve with above clarification (and answer to the question that I ended up as... | 2017/08/07 | [
"https://vi.stackexchange.com/questions/13162",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13691/"
] | I recently wanted to have a mapping that I could trigger from `normal mode` as well as from `insert mode`. Writing the same mapping for multiple modes annoyed me as it cluttered my .vimrc and requires me to make the same changes multiple times.
---
It was pointed out to me, that no such mapping mode exists. See here:... | By using the `nore` forms, you are specifically telling Vim to ignore any existing mappings. (See `:help :nore`, or, for a bit more explanation, [this chapter from Learn Vimscript the Hard Way](http://learnvimscriptthehardway.stevelosh.com/chapters/05.html).)
To use your existing `<COMPLEX-KEY>` mapping inside another... |
13,172 | <p>This is perhaps a beginner question, but I'm unable to (intuitively) figure out how to redirect the output of an ex command to a variable for further processing.</p>
<p>Some background: I'm trying to create a list of file paths that I want to pass to <code>fzf</code>, and so I'm concatenating several sources into a... | [
{
"answer_id": 13173,
"author": "Mahmoud Al-Qudsi",
"author_id": 13499,
"author_profile": "https://vi.stackexchange.com/users/13499",
"pm_score": 3,
"selected": true,
"text": "<p>I managed to figure this one out. neovim and modern versions of vim provide an <code>execute</code> function ... | 2017/08/07 | [
"https://vi.stackexchange.com/questions/13172",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13499/"
] | This is perhaps a beginner question, but I'm unable to (intuitively) figure out how to redirect the output of an ex command to a variable for further processing.
Some background: I'm trying to create a list of file paths that I want to pass to `fzf`, and so I'm concatenating several sources into a list. In effect, wha... | I managed to figure this one out. neovim and modern versions of vim provide an `execute` function that can be used to do just this.
`let list3 = execute(":oldfiles")` does the trick. |
13,180 | <p>I'm writing small liniting plugin and I want to show errors in the quickfix as soon as errorfile changes.</p>
<pre><code>fu! OpenErrors(job_id, data, event)
let l:winid = win_getid()
let l:output = split(a:data[0])
echom l:output[0] . l:output[2]
let l:view = winsaveview()
exe 'silent! cfile! ' ... | [
{
"answer_id": 13181,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p>In <a href=\"https://github.com/LucHermitte/vim-build-tools-wrapper/blob/project/autoload/lh/btw/job_build.vim\" rel... | 2017/08/08 | [
"https://vi.stackexchange.com/questions/13180",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6634/"
] | I'm writing small liniting plugin and I want to show errors in the quickfix as soon as errorfile changes.
```
fu! OpenErrors(job_id, data, event)
let l:winid = win_getid()
let l:output = split(a:data[0])
echom l:output[0] . l:output[2]
let l:view = winsaveview()
exe 'silent! cfile! ' . escape(l:out... | In [Build-Tools-Wrapper](https://github.com/LucHermitte/vim-build-tools-wrapper/blob/project/autoload/lh/btw/job_build.vim), the callback receives the new line to display (as the job simply executes `make` (or equivalent) and doesn't play with any intermediary file), the line is processed with `:caddexpr`. If I'm suppo... |
13,183 | <p>I am using Vim 7.4 through a remote PuTTY session. I set my "dracula"
colorscheme in my vimrc, and then immediately after that, I remove the background setting for normal text. For Normal text, I personally prefer a solid (empty) black background to the background color that the dracula colorscheme uses. Here is the... | [
{
"answer_id": 13361,
"author": "LEI",
"author_id": 12003,
"author_profile": "https://vi.stackexchange.com/users/12003",
"pm_score": 1,
"selected": false,
"text": "<p>It's not resolving the root of the problem, but you could try to override highlight groups each time the colorsheme is se... | 2017/08/08 | [
"https://vi.stackexchange.com/questions/13183",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9047/"
] | I am using Vim 7.4 through a remote PuTTY session. I set my "dracula"
colorscheme in my vimrc, and then immediately after that, I remove the background setting for normal text. For Normal text, I personally prefer a solid (empty) black background to the background color that the dracula colorscheme uses. Here is the re... | You can see when files are sourced with:
```
:set verbose=2
```
If that doesn't help you can try higher levels:
```
>= 1 When the viminfo file is read or written.
>= 2 When a file is ":source"'ed.
>= 5 Every searched tags file and include file.
>= 8 Files for which a group of autocommands is executed.
>... |
13,207 | <p>Vim highlight SpellCap errors after every fullstop. Also after abbreviations:</p>
<pre><code>i.e. without
</code></pre>
<p>Here <code>without</code> gets the SpellCap highlight. This is obious no error, and renders the SpellCap function rather useless for me.
Is there a way to define abbreviations in vim, so that ... | [
{
"answer_id": 13244,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 2,
"selected": false,
"text": "<p><code>SpellCap</code> does not identify misspelled words. It tries to point out places where the first word of a sent... | 2017/08/09 | [
"https://vi.stackexchange.com/questions/13207",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11316/"
] | Vim highlight SpellCap errors after every fullstop. Also after abbreviations:
```
i.e. without
```
Here `without` gets the SpellCap highlight. This is obious no error, and renders the SpellCap function rather useless for me.
Is there a way to define abbreviations in vim, so that there is no SpellCap placed afterward... | `SpellCap` does not identify misspelled words. It tries to point out places where the first word of a sentence is not correctly capitalized. Thus, adding words to your dictionary probably won't help.
Look at `:help 'spellcapcheck'` and you'll see that the setting contains punctuation that should mark the end of a sent... |
13,231 | <p>How can I find out the default value of a variable if it is not set? For example, the default timeout for the leader key is controlled by the <code>timeoutlen</code> variable, but if I do:</p>
<pre><code>:echo timeoutlen
</code></pre>
<p>I get an "undefined variable" error. Is there any command to find out default... | [
{
"answer_id": 13244,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 2,
"selected": false,
"text": "<p><code>SpellCap</code> does not identify misspelled words. It tries to point out places where the first word of a sent... | 2017/08/12 | [
"https://vi.stackexchange.com/questions/13231",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | How can I find out the default value of a variable if it is not set? For example, the default timeout for the leader key is controlled by the `timeoutlen` variable, but if I do:
```
:echo timeoutlen
```
I get an "undefined variable" error. Is there any command to find out default values for variables like this? | `SpellCap` does not identify misspelled words. It tries to point out places where the first word of a sentence is not correctly capitalized. Thus, adding words to your dictionary probably won't help.
Look at `:help 'spellcapcheck'` and you'll see that the setting contains punctuation that should mark the end of a sent... |
13,232 | <p>If I have non-printable characters assigned to a variable, how can I echo them?</p>
<p>For example, if I have a variable <code>xyz</code> set to be two spaces and a tab, then if I do this:</p>
<pre><code>:echo xyz
</code></pre>
<p>it just shows a blank line. I can't actually see the characters to which the variab... | [
{
"answer_id": 13233,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>I often add characters around like in <code>:echo '###'.xyz.'###'</code>. It's simple enough, and more readable, IMO... | 2017/08/12 | [
"https://vi.stackexchange.com/questions/13232",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | If I have non-printable characters assigned to a variable, how can I echo them?
For example, if I have a variable `xyz` set to be two spaces and a tab, then if I do this:
```
:echo xyz
```
it just shows a blank line. I can't actually see the characters to which the variable has been set. Is there any way to get ech... | I often add characters around like in `:echo '###'.xyz.'###'`. It's simple enough, and more readable, IMO, than `:echo split(xyz, '\zs')` |
13,238 | <p>I have following</p>
<pre><code>function! s:get_visual_selection()
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
endif
let lines[-1] = lines[-1][: column_e... | [
{
"answer_id": 13240,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>For your approach to work, you could define an <code>omap</code> that finds the smallest enclosing pair, and tests t... | 2017/08/13 | [
"https://vi.stackexchange.com/questions/13238",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11273/"
] | I have following
```
function! s:get_visual_selection()
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
endif
let lines[-1] = lines[-1][: column_end - 2]
let line... | For your approach to work, you could define an `omap` that finds the smallest enclosing pair, and tests the character under the cursor to trigger the mapping from Surround you wish. I remember a plugin that has defined the operator pending mode you'll need. Its approach was quite smart by testing all possible `vi{whate... |
13,250 | <p>Sometimes, such as when transcribing FORTRAN code, I find it useful to enter uppercase letters without holding down the <kbd>Shift</kbd> key.</p>
<p>However, enabling <kbd>Caps Lock</kbd> is a problem in command mode. Here is my (admittedly inelegant) workaround:</p>
<pre><code>function! AllCaps()
inoremap a A... | [
{
"answer_id": 13251,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 0,
"selected": false,
"text": "<p>Are you okay converting the text after you enter it? If so, type in lowercase, select the text with Visual mode and t... | 2017/08/15 | [
"https://vi.stackexchange.com/questions/13250",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4498/"
] | Sometimes, such as when transcribing FORTRAN code, I find it useful to enter uppercase letters without holding down the `Shift` key.
However, enabling `Caps Lock` is a problem in command mode. Here is my (admittedly inelegant) workaround:
```
function! AllCaps()
inoremap a A
inoremap b B
inoremap c C
... | This isn't as concise as my earlier solution (see below) or [statox's answer](https://vi.stackexchange.com/a/13254/343), but it's much cleaner than the former and has the advantage over the latter in that it uppercases individual letters as you type:
```
function! AllCaps()
augroup all_caps
autocmd!
autocmd ... |
13,255 | <p>Im trying to yank part of another line:</p>
<pre><code>1 foo=bar
2
3 (paste only foo here - without "going/moving" to 1)
</code></pre>
<p>I understand that I can yank the whole line using <code>:1y.</code></p>
<p>A "pseudocode" for that would be <code>:1yt=</code></p>
| [
{
"answer_id": 13256,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p>Your question has two parts:</p>\n\n<ul>\n<li>Executing a command on a line different from the current one</li>\n<li>Exec... | 2017/08/16 | [
"https://vi.stackexchange.com/questions/13255",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13877/"
] | Im trying to yank part of another line:
```
1 foo=bar
2
3 (paste only foo here - without "going/moving" to 1)
```
I understand that I can yank the whole line using `:1y.`
A "pseudocode" for that would be `:1yt=` | Your question has two parts:
* Executing a command on a line different from the current one
* Executing a command without moving the cursor
---
First to yank on the first line you can use this ex command: `:1norm! yt=`
This can be decomposed in three parts:
* `1` the line on which you want to execute the command
*... |
13,288 | <p>I'm trying to write a script to take a bunch of vim sources in plugins and combine them into a single vimrc that I'm going to treat as an essentially opaque binary file. I'm doing this partially to simplify the process of deploying my vimrc to a new machine and partially to get more familiar with the ins and outs of... | [
{
"answer_id": 13256,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p>Your question has two parts:</p>\n\n<ul>\n<li>Executing a command on a line different from the current one</li>\n<li>Exec... | 2017/08/19 | [
"https://vi.stackexchange.com/questions/13288",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6420/"
] | I'm trying to write a script to take a bunch of vim sources in plugins and combine them into a single vimrc that I'm going to treat as an essentially opaque binary file. I'm doing this partially to simplify the process of deploying my vimrc to a new machine and partially to get more familiar with the ins and outs of vi... | Your question has two parts:
* Executing a command on a line different from the current one
* Executing a command without moving the cursor
---
First to yank on the first line you can use this ex command: `:1norm! yt=`
This can be decomposed in three parts:
* `1` the line on which you want to execute the command
*... |
13,295 | <p>Having vim setup for development gives some undesirable effects for editing commit messages <em>(margin not 72, auto-indent typically isn't needed, probably literal tab characters aren't desired, maybe strip trailing space on save?... etc)</em>.</p>
<p>What are good filetype options for git commit messages?</p>
<p... | [
{
"answer_id": 13256,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p>Your question has two parts:</p>\n\n<ul>\n<li>Executing a command on a line different from the current one</li>\n<li>Exec... | 2017/08/20 | [
"https://vi.stackexchange.com/questions/13295",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/301/"
] | Having vim setup for development gives some undesirable effects for editing commit messages *(margin not 72, auto-indent typically isn't needed, probably literal tab characters aren't desired, maybe strip trailing space on save?... etc)*.
What are good filetype options for git commit messages?
```
function MyFTypeGit... | Your question has two parts:
* Executing a command on a line different from the current one
* Executing a command without moving the cursor
---
First to yank on the first line you can use this ex command: `:1norm! yt=`
This can be decomposed in three parts:
* `1` the line on which you want to execute the command
*... |
13,301 | <p>I have the following command in my <code>vimrc</code>file:</p>
<pre><code>inoremap <C-S> <esc>:w<CR> i
</code></pre>
<p>which saves the file in insert mode but, for some reason, it also adds an extra space where cursor is present.</p>
<p>Why does it happen?</p>
| [
{
"answer_id": 13302,
"author": "LEI",
"author_id": 12003,
"author_profile": "https://vi.stackexchange.com/users/12003",
"pm_score": 0,
"selected": false,
"text": "<p>Maybe try using <code>:startinsert<CR></code> instead of <code>i</code>.</p>\n"
},
{
"answer_id": 13306,
... | 2017/08/20 | [
"https://vi.stackexchange.com/questions/13301",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13939/"
] | I have the following command in my `vimrc`file:
```
inoremap <C-S> <esc>:w<CR> i
```
which saves the file in insert mode but, for some reason, it also adds an extra space where cursor is present.
Why does it happen? | I would use `<c-o>` to execute your command.
```
inoremap <c-s> <c-o>:w<cr>
``` |
13,308 | <p>I have the following line of code:</p>
<pre><code> autocmd FileType javascript execute "setlocal formatprg=".g:prettier_eslint_path2."\\ --eslint-config-path" . g:eslintrc_full_path ."\\"
</code></pre>
<p>I can see this when I start vim in the directory which has <code>.eslintrc</code>:</p>
<pre><code>ESLINTRC P... | [
{
"answer_id": 13309,
"author": "LEI",
"author_id": 12003,
"author_profile": "https://vi.stackexchange.com/users/12003",
"pm_score": 1,
"selected": false,
"text": "<p>Maybe this is an escaping problem, you should use:</p>\n\n<pre><code>autocmd FileType javascript setlocal formatprg=comma... | 2017/08/21 | [
"https://vi.stackexchange.com/questions/13308",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10361/"
] | I have the following line of code:
```
autocmd FileType javascript execute "setlocal formatprg=".g:prettier_eslint_path2."\\ --eslint-config-path" . g:eslintrc_full_path ."\\"
```
I can see this when I start vim in the directory which has `.eslintrc`:
```
ESLINTRC PATH
.eslintrc
Prettier ESLINT PATH
/Users/localu... | Maybe this is an escaping problem, you should use:
```
autocmd FileType javascript setlocal formatprg=command\ --arg
```
Or if you need variables:
```
autocmd FileType javascript let &l:formatprg = 'command ' . l:arg
```
---
**Update**: As [commented by the plugin owner](https://github.com/sbdchd/neoformat/issue... |
13,330 | <p>I very often need to open files through <code>vsplit/split</code>. Very often I want to open files in the same directory. Still, I must pass their paths to <code>vsplit/split</code>.</p>
<pre><code>:vsplit @/siblingfile.txt
</code></pre>
<p><code>@</code> is an alias equal to the path of the current file (that exi... | [
{
"answer_id": 13332,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 3,
"selected": true,
"text": "<p>You're looking for <code>%:h/</code></p>\n\n<p>NB: you can tab-complete at any point after the <code>:h</code>.</p>\n... | 2017/08/23 | [
"https://vi.stackexchange.com/questions/13330",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13172/"
] | I very often need to open files through `vsplit/split`. Very often I want to open files in the same directory. Still, I must pass their paths to `vsplit/split`.
```
:vsplit @/siblingfile.txt
```
`@` is an alias equal to the path of the current file (that exists only in my imagination of course but you got the idea :... | You're looking for `%:h/`
NB: you can tab-complete at any point after the `:h`. |
13,331 | <p>I know about <code>:only</code> and <kbd>Ctrl+w</kbd><kbd>o</kbd>.</p>
<p>But I want to keep NERDTree window untouched. Is there a way to achieve it?</p>
| [
{
"answer_id": 13334,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p><strong>This solution only works with vim 8+</strong></p>\n\n<p>You can add this to your <code>.vimrc</code>:</p>\n\n<pre... | 2017/08/23 | [
"https://vi.stackexchange.com/questions/13331",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13980/"
] | I know about `:only` and `Ctrl+w``o`.
But I want to keep NERDTree window untouched. Is there a way to achieve it? | **This solution only works with vim 8+**
You can add this to your `.vimrc`:
```
function! OnlyAndNerdtree()
let currentWindowID = win_getid()
windo if win_getid() != currentWindowID && &filetype != 'nerdtree' | close | endif
endfunction
command! Only call OnlyAndNerdtree()
```
The function gets the id of ... |
13,344 | <p>While navigating file system in <code>:Explore</code> mode, is it possible to select and open multiple files, each in a new tab?</p>
<p><strong>Edit:</strong></p>
<p>I ended up using a function proposed by <em>Jair López</em>, because it works pretty much as I envisioned it, although <em>statox</em> provided a goo... | [
{
"answer_id": 13345,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": false,
"text": "<p>From <a href=\"http://vimhelp.appspot.com/pi_netrw.txt.html#netrw%2dt\" rel=\"noreferrer\"><code>:h netrw-t</code></a>:<... | 2017/08/24 | [
"https://vi.stackexchange.com/questions/13344",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13992/"
] | While navigating file system in `:Explore` mode, is it possible to select and open multiple files, each in a new tab?
**Edit:**
I ended up using a function proposed by *Jair López*, because it works pretty much as I envisioned it, although *statox* provided a good explanation for built-in netrw mechanics.
For consis... | Let's Vim do it for you. You can put the following code at the end of your
`vimrc` file:
```
function! NetrwOpenMultiTab(current_line,...) range
" Get the number of lines.
let n_lines = a:lastline - a:firstline + 1
" This is the command to be built up.
let command = "normal "
" Iterator.
let i = ... |
13,356 | <p>I just installed a plugin for python which displays methods tree. So I would like to open the tree on startup, so not necessary to push the buttons everytime I open some <code>.py</code> file. But, I want this command is executed only for <code>.py</code> files. Here is how my vimrc piece looks like:</p>
<pre><code... | [
{
"answer_id": 13357,
"author": "kapil",
"author_id": 4745,
"author_profile": "https://vi.stackexchange.com/users/4745",
"pm_score": 4,
"selected": true,
"text": "<p>Add in your <code>.vimrc</code>:</p>\n\n<pre><code>au BufEnter *.py :TagbarToggle<CR>\n</code></pre>\n\n<p>where</p>... | 2017/08/25 | [
"https://vi.stackexchange.com/questions/13356",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9409/"
] | I just installed a plugin for python which displays methods tree. So I would like to open the tree on startup, so not necessary to push the buttons everytime I open some `.py` file. But, I want this command is executed only for `.py` files. Here is how my vimrc piece looks like:
```
nmap <F8> :TagbarToggle<CR>
```
I... | Add in your `.vimrc`:
```
au BufEnter *.py :TagbarToggle<CR>
```
where
* `au` is `autocmd`, execute the command automatically.
* `BufEnter` is when you enter the file for first time.
* `*.py` is for filetype python.
* and the rest is the command to be executed |
13,364 | <p>I have a custom key mapping <code>jj</code> to escape, it works for normal file edit but when I open the file as a superuser the key mapping doesn't work anymore, why?
I use Antergos os.</p>
| [
{
"answer_id": 13366,
"author": "Pak",
"author_id": 1115,
"author_profile": "https://vi.stackexchange.com/users/1115",
"pm_score": 3,
"selected": false,
"text": "<p>When you run vim using <code>su</code> or <code>sudo</code>, I believe it's running the root user's <code>.vimrc</code> (if... | 2017/08/25 | [
"https://vi.stackexchange.com/questions/13364",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4745/"
] | I have a custom key mapping `jj` to escape, it works for normal file edit but when I open the file as a superuser the key mapping doesn't work anymore, why?
I use Antergos os. | timtowtdi
=========
As pointed out in the comments to the other answer you could also solve this with editing root's `~/.vimrc` file. There are other options though.
symlink
-------
If your personal `~/.vimrc` doesn't have any plugin weirdness or hard-coded directories you could just symlink root's `~/.vimrc` to you... |
13,391 | <p>Suppose I have several files open each in a different active buffer. Is there a way to save a specific file in a different buffer without first switching to it?</p>
<p>An example of this occurring is if I opened 10 new files and edited them all. I want to only save 3 of them and discard the changes to the remaining... | [
{
"answer_id": 13392,
"author": "LEI",
"author_id": 12003,
"author_profile": "https://vi.stackexchange.com/users/12003",
"pm_score": 1,
"selected": false,
"text": "<p>You can <a href=\"http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers\" rel=\"nofollow noreferrer\">run a command... | 2017/08/28 | [
"https://vi.stackexchange.com/questions/13391",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14019/"
] | Suppose I have several files open each in a different active buffer. Is there a way to save a specific file in a different buffer without first switching to it?
An example of this occurring is if I opened 10 new files and edited them all. I want to only save 3 of them and discard the changes to the remaining 7 before ... | There are several ways possible to do what you want, but all involve some kind of scripting.
* Using `bufdo`
You could use the already mentioned `bufdo` like this (suppose you want to save the buffer number 4):
`:4,4bufdo :w`
However, this will internally switch to buffer 4 and the cursor will remain in that buffe... |
13,398 | <p>I'm trying to find complete documentation for the possible contents of <code>.vimrc</code>.</p>
<p>Here's what I've tried:</p>
<ul>
<li>Google search. Plenty of examples, no docs.</li>
<li><a href="http://vimdoc.sourceforge.net/" rel="noreferrer">Official docs</a></li>
<li><code>man vim</code></li>
<li><code>:help... | [
{
"answer_id": 13392,
"author": "LEI",
"author_id": 12003,
"author_profile": "https://vi.stackexchange.com/users/12003",
"pm_score": 1,
"selected": false,
"text": "<p>You can <a href=\"http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers\" rel=\"nofollow noreferrer\">run a command... | 2017/08/28 | [
"https://vi.stackexchange.com/questions/13398",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14048/"
] | I'm trying to find complete documentation for the possible contents of `.vimrc`.
Here's what I've tried:
* Google search. Plenty of examples, no docs.
* [Official docs](http://vimdoc.sourceforge.net/)
* `man vim`
* `:help vimrc`
* Searching this beta SE
* Searching Stackoverflow
For example, [this site](https://www.... | There are several ways possible to do what you want, but all involve some kind of scripting.
* Using `bufdo`
You could use the already mentioned `bufdo` like this (suppose you want to save the buffer number 4):
`:4,4bufdo :w`
However, this will internally switch to buffer 4 and the cursor will remain in that buffe... |
13,425 | <p>Is it possible to configure vim to store commands in your command history without abbreviations expanded?</p>
<p>For instance I have the following command (to make it easy to switch back and forth between header and source files)</p>
<pre><code>cnoreabbrev <expr> cv 'edit %:r.cpp'
</code></pre>
<p>However, ... | [
{
"answer_id": 13427,
"author": "user852573",
"author_id": 13370,
"author_profile": "https://vi.stackexchange.com/users/13370",
"pm_score": 3,
"selected": true,
"text": "<p>I don't know how reliable it is, but I came up with this:</p>\n\n<pre><code>fu! s:cnorea(lhs, rhs) abort\n let s... | 2017/08/30 | [
"https://vi.stackexchange.com/questions/13425",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6420/"
] | Is it possible to configure vim to store commands in your command history without abbreviations expanded?
For instance I have the following command (to make it easy to switch back and forth between header and source files)
```
cnoreabbrev <expr> cv 'edit %:r.cpp'
```
However, if I type `:cv<cr>` and then type `up` ... | I don't know how reliable it is, but I came up with this:
```
fu! s:cnorea(lhs, rhs) abort
let s:counter = get(s:, 'counter', 0) + 1
fu! s:cnorea_{s:counter}() abort closure
call timer_start(0, {
\ -> execute('if histget(":", -1) ==# '.string(a:rhs)
... |
13,433 | <p>Using <code>git</code> how can I load the list of files in the current commit into Quickfix window?</p>
<p>Code Review didn't pass and I want to just fix them one by one.</p>
| [
{
"answer_id": 13434,
"author": "firedev",
"author_id": 237,
"author_profile": "https://vi.stackexchange.com/users/237",
"pm_score": 2,
"selected": false,
"text": "<p>The only thing that comes to mind is </p>\n\n<pre><code>git reset --soft head~1\n</code></pre>\n\n<p>That would \"uncommi... | 2017/08/31 | [
"https://vi.stackexchange.com/questions/13433",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/237/"
] | Using `git` how can I load the list of files in the current commit into Quickfix window?
Code Review didn't pass and I want to just fix them one by one. | You could use the following function which has the advantage of not changing the state of your local git repo:
```
function! CommitQF(...)
" Get the commit hash if it was specified
let commit = a:0 == 0 ? '' : a:1
" Get the result of git show in a list
let flist = system('git show --name-only ' . comm... |
13,464 | <p>I know in vim I can use :global to execute commands on the matching lines.</p>
<p>But I'm wondering if it's possible to execute those commands on every matching pattern, not just lines, consider following example:</p>
<pre><code>aaa bbb
aaa ccc aaa ddd ww
</code></pre>
<p>I want to perform action: <code>normal wd... | [
{
"answer_id": 13465,
"author": "LEI",
"author_id": 12003,
"author_profile": "https://vi.stackexchange.com/users/12003",
"pm_score": 2,
"selected": false,
"text": "<p>You might be interested by this question: <a href=\"https://vi.stackexchange.com/q/9898/12003\">Run a command on every ma... | 2017/09/03 | [
"https://vi.stackexchange.com/questions/13464",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1276/"
] | I know in vim I can use :global to execute commands on the matching lines.
But I'm wondering if it's possible to execute those commands on every matching pattern, not just lines, consider following example:
```
aaa bbb
aaa ccc aaa ddd ww
```
I want to perform action: `normal wdw` on every matching `aaa`, so I expec... | There's nothing like it mentioned anywhere in repeat.txt (`:h repeating`) so one can probably conclude that there's no native support for it.
If you're running this on the whole file a **recursive macro** is a viable approach. Assuming we'll store it in register **q** the macro is `nwdwN@q`. Breaking it down...
* `n`... |
13,471 | <p>Give the following dictionary:</p>
<pre><code>let mydict = {'foo': {'a': 1, 'b': 2}, 'bar': {'c': 3, 'd': 4}}
</code></pre>
<p>And a list of keys:</p>
<pre><code>let myfilter = ['foo', 'asdf']
</code></pre>
<p>How would one do a <strong>concise</strong> "left outer join (if null)" or filter and remove any items ... | [
{
"answer_id": 13472,
"author": "timss",
"author_id": 5070,
"author_profile": "https://vi.stackexchange.com/users/5070",
"pm_score": 4,
"selected": true,
"text": "<p>It's possible to use <code>index({list}, {expr} ..)</code> for this:</p>\n\n<pre><code>let mydict = {'foo': {'a': 1, 'b': ... | 2017/09/03 | [
"https://vi.stackexchange.com/questions/13471",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5070/"
] | Give the following dictionary:
```
let mydict = {'foo': {'a': 1, 'b': 2}, 'bar': {'c': 3, 'd': 4}}
```
And a list of keys:
```
let myfilter = ['foo', 'asdf']
```
How would one do a **concise** "left outer join (if null)" or filter and remove any items in `mydict` with key in `myfilter`?
"Long" version as a loop:... | It's possible to use `index({list}, {expr} ..)` for this:
```
let mydict = {'foo': {'a': 1, 'b': 2}, 'bar': {'c': 3, 'd': 4}}
let myfilter = ['foo', 'asdf']
call filter(mydict, 'index(myfilter, v:key) == -1')
```
`index()` returns -1 when `{expr}` is not found in `{list}` and otherwise the lowest index in `{list}`.... |
13,494 | <p>Is there some built in functionality in Vim to merge the contents of two registers into a single register by appending the two?</p>
| [
{
"answer_id": 13495,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>Let's say you want to merge <code>\"a</code> and <code>\"b</code> into <code>\"c</code>:</p>\n\n<pre><code>call setreg('... | 2017/09/06 | [
"https://vi.stackexchange.com/questions/13494",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2082/"
] | Is there some built in functionality in Vim to merge the contents of two registers into a single register by appending the two? | It is not exactly clear what you would like to happen when e.g. one register contains a linewise selection and the other one contains a block selection. But for the easy case, you can always do (as noted in a comment)
```
:let @c=@a.@b
```
and have the concatenation of register a and b in register c. But note, this ... |
13,498 | <p>I have a tricky problem and don't know how to solve it. I use <code>map</code> to declare a shortcut key for the gradle test below:</p>
<pre><code>map <C-S-F10> <Esc>:wa<CR>:let last_test = expand("%")<CR><S-F10>
map <S-F10> <Esc>:wa<CR>:call OpenWindow('tests')<CR... | [
{
"answer_id": 13495,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>Let's say you want to merge <code>\"a</code> and <code>\"b</code> into <code>\"c</code>:</p>\n\n<pre><code>call setreg('... | 2017/09/06 | [
"https://vi.stackexchange.com/questions/13498",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14099/"
] | I have a tricky problem and don't know how to solve it. I use `map` to declare a shortcut key for the gradle test below:
```
map <C-S-F10> <Esc>:wa<CR>:let last_test = expand("%")<CR><S-F10>
map <S-F10> <Esc>:wa<CR>:call OpenWindow('tests')<CR>:%d<CR>:call RunTests(last_test)<CR>
fun! RunTests(...)
if(a:0 == 0)
... | It is not exactly clear what you would like to happen when e.g. one register contains a linewise selection and the other one contains a block selection. But for the easy case, you can always do (as noted in a comment)
```
:let @c=@a.@b
```
and have the concatenation of register a and b in register c. But note, this ... |
13,512 | <p>Is there a way to list the buffers specific to the tab that is open currently in vim or macvim?</p>
| [
{
"answer_id": 13514,
"author": "Jürgen Krämer",
"author_id": 2636,
"author_profile": "https://vi.stackexchange.com/users/2636",
"pm_score": 3,
"selected": false,
"text": "<p>The following code will give you the file names for the current tab (if the buffer in a window is connected to a ... | 2017/09/08 | [
"https://vi.stackexchange.com/questions/13512",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12605/"
] | Is there a way to list the buffers specific to the tab that is open currently in vim or macvim? | The following code defines a new command :LsByTab that parses the output of :ls and groups it by tabs. You can call the command with an exclamation mark and/or the flags supported by :ls.
```
"
" Get the output of :ls as a List of lines.
"
function! s:LsOutput(bang, args)
redir => ls_output
exe 'silent ls' . a... |
13,515 | <p>When working with larger or rather deeply nested yaml files (Hi Rails), it happens quickly that I loose sight of where I am with regards to the indentation hierarchy of the file.</p>
<p>A very simple example to illustrate my point:</p>
<pre><code>1| en:
2| activerecord:
3| errors:
4| messages:
5| ... | [
{
"answer_id": 13519,
"author": "LEI",
"author_id": 12003,
"author_profile": "https://vi.stackexchange.com/users/12003",
"pm_score": 4,
"selected": true,
"text": "<p>The right way to do it would be to use an external program if the markup language presents a complex structure or particul... | 2017/09/08 | [
"https://vi.stackexchange.com/questions/13515",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14202/"
] | When working with larger or rather deeply nested yaml files (Hi Rails), it happens quickly that I loose sight of where I am with regards to the indentation hierarchy of the file.
A very simple example to illustrate my point:
```
1| en:
2| activerecord:
3| errors:
4| messages:
5| parse_error: is sy... | The right way to do it would be to use an external program if the markup language presents a complex structure or particular edge cases, like the bunch of tools you can find for JSON.
~~Though YAML seems to be pretty straightforward~~ Even if YAML seems to be [pretty complex](https://arp242.net/weblog/yaml_probably_no... |
13,516 | <p>I mostly use Vim to edit configuration files so I understand why it starts in <strong>normal mode</strong>. But I also use <em>vi mode</em> for the REPL (bash, zsh, ipython, etc.) and the shell always starts in <strong>insert mode</strong> (this makes sense because you just want to start typing a command).</p>
<p>F... | [
{
"answer_id": 13517,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 5,
"selected": true,
"text": "<p>You need to add this to your vimrc:</p>\n\n<pre><code>autocmd BufNewFile * startinsert\n</code></pre>\n\n<p>The autocomma... | 2017/09/08 | [
"https://vi.stackexchange.com/questions/13516",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14203/"
] | I mostly use Vim to edit configuration files so I understand why it starts in **normal mode**. But I also use *vi mode* for the REPL (bash, zsh, ipython, etc.) and the shell always starts in **insert mode** (this makes sense because you just want to start typing a command).
For the same reason, when I open a new empty... | You need to add this to your vimrc:
```
autocmd BufNewFile * startinsert
```
The autocommand creates a command which is executed on a specific event.
Here the event is `BufNewFile` the doc descibes it has:
>
> When starting to edit a file that doesn't
> exist. Can be used to read in a skeleton
> file.
>
>
>
... |
13,518 | <p>How do you configure vim to prompt for deletion of swap files even if it believes another instance of vim may still be using the file? I still want to see the warning message ... just also have the option to delete the file and overrule vim.</p>
<p>The option below, for instance, doesn't have the <code>(D)elete</co... | [
{
"answer_id": 13524,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 4,
"selected": true,
"text": "<p>The \"Delete it\" option isn't displayed if the Vim process is still running; I can't find this documented anywhere ... | 2017/09/08 | [
"https://vi.stackexchange.com/questions/13518",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6420/"
] | How do you configure vim to prompt for deletion of swap files even if it believes another instance of vim may still be using the file? I still want to see the warning message ... just also have the option to delete the file and overrule vim.
The option below, for instance, doesn't have the `(D)elete` option. (where `p... | The "Delete it" option isn't displayed if the Vim process is still running; I can't find this documented anywhere but I looked it up in the source code; from `memline.c`, line 4512 (slightly simplified):
```
do_dialog(
[..]
process_still_running
? (char_u *)_("&Open Read-Only\n&Edit anyway\n&Recover\n&... |
13,539 | <p>I have <code>set ruler</code> in my <code>.vimrc</code>.</p>
<p>If I run <code>vim</code> and then <code>:verbose set ruler?</code> to check the status of this setting, on Ubuntu Linux it says :</p>
<pre><code>noruler
Last set from ~/.vimrc
</code></pre>
<p>At the bash prompt, <code>grep</code> says :</p>... | [
{
"answer_id": 13540,
"author": "dlmeetei",
"author_id": 6221,
"author_profile": "https://vi.stackexchange.com/users/6221",
"pm_score": 4,
"selected": true,
"text": "<p>Check if <code>set paste?</code> and <code>set compatible?</code> are set.</p>\n\n<p>If they are set, disable them. <co... | 2017/09/10 | [
"https://vi.stackexchange.com/questions/13539",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14229/"
] | I have `set ruler` in my `.vimrc`.
If I run `vim` and then `:verbose set ruler?` to check the status of this setting, on Ubuntu Linux it says :
```
noruler
Last set from ~/.vimrc
```
At the bash prompt, `grep` says :
```
$ grep ruler .vimrc
set ruler
```
And on Debian Linux, `:verbose set ruler?` says :... | Check if `set paste?` and `set compatible?` are set.
If they are set, disable them. `ruler` is reset if they are set.
More details at `:help ruler` |
13,557 | <p>I have a list of integers, where each is on a separate line. I'm trying to find a quick way to sum them up directly in VIM without having to write a script that does it for me.</p>
| [
{
"answer_id": 13558,
"author": "Murch",
"author_id": 8055,
"author_profile": "https://vi.stackexchange.com/users/8055",
"pm_score": 4,
"selected": true,
"text": "<p>What worked for me was:</p>\n\n<pre><code>:%!awk '{print; total+=$1}END{print total}'\n</code></pre>\n"
},
{
"answ... | 2017/09/13 | [
"https://vi.stackexchange.com/questions/13557",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8055/"
] | I have a list of integers, where each is on a separate line. I'm trying to find a quick way to sum them up directly in VIM without having to write a script that does it for me. | What worked for me was:
```
:%!awk '{print; total+=$1}END{print total}'
``` |
13,566 | <p>I saw <a href="https://stackoverflow.com/questions/24684483/completely-disable-mouse-in-console-vim">completely disable mouse in console vim</a> on Stack Overflow. It sounded like exactly what I wanted, but there the problem was related to Cygwin, so the title was a misnomer.</p>
<p>I want to know how to <em>compl... | [
{
"answer_id": 13571,
"author": "ctag",
"author_id": 14281,
"author_profile": "https://vi.stackexchange.com/users/14281",
"pm_score": 1,
"selected": false,
"text": "<p>This is only a partial solution at best, but you can globally disable the mouse/touchpad while vim is running with <code... | 2017/09/14 | [
"https://vi.stackexchange.com/questions/13566",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20101/"
] | I saw [completely disable mouse in console vim](https://stackoverflow.com/questions/24684483/completely-disable-mouse-in-console-vim) on Stack Overflow. It sounded like exactly what I wanted, but there the problem was related to Cygwin, so the title was a misnomer.
I want to know how to *completely* disable *all* mous... | You should add the following two lines at the end of /etc/vim/vimrc :
```
set mouse=
set ttymouse=
``` |
13,586 | <p>I need an option in vim to display a text file, say <code>text-file</code>, during the session as would</p>
<pre><code>echo -e `cat text-file` | vim -
</code></pre>
<ul>
<li>vim is given <code>text-file</code></li>
<li><p><code>text-file</code> includes text with escape sequences, such as:</p>
<pre><code>FIELD 1 ... | [
{
"answer_id": 13587,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 1,
"selected": false,
"text": "<p>One solution would be to put this line in your <code>~/.vimrc</code> file,</p>\n\n<pre><code>set listchars+=tab:>-\... | 2017/09/15 | [
"https://vi.stackexchange.com/questions/13586",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14300/"
] | I need an option in vim to display a text file, say `text-file`, during the session as would
```
echo -e `cat text-file` | vim -
```
* vim is given `text-file`
* `text-file` includes text with escape sequences, such as:
```
FIELD 1 TEXT\tOF\n\tFIELD 2\n
FIELD 1 TEXT OF FIELD 2
```
* vim to ... | A workaround would be to invoke the command from within Vim, allowing you to display escaped characters:
```
:%!echo -e "$(cat)"
```
Here, `%` is a range equal to the entire file, and `cat` is used to pass the standard input to `echo -e`.
The problem is that you won't be able to determine which tabs or newlines wer... |
13,602 | <p>I was solving a problem on Vimgolf (you can take a look at <a href="http://www.vimgolf.com/challenges/56fb2e75ccffcc0009026473" rel="nofollow noreferrer">this</a>) where I stumbled upon this solution.</p>
<pre><code>djgJ.V"=[<C-R><C-A>]<CR>pZZ
</code></pre>
<p>Could you please walk me through the... | [
{
"answer_id": 13605,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 2,
"selected": false,
"text": "<p><code>\"=</code> refers to the expression register, which lets you evaluate a bit of vimscript and have vim act like the... | 2017/09/17 | [
"https://vi.stackexchange.com/questions/13602",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14316/"
] | I was solving a problem on Vimgolf (you can take a look at [this](http://www.vimgolf.com/challenges/56fb2e75ccffcc0009026473)) where I stumbled upon this solution.
```
djgJ.V"=[<C-R><C-A>]<CR>pZZ
```
Could you please walk me through the meaning of this cryptic keystrokes `"=[<C-R><C-A>]<CR>p`? | For context I'll go over the whole thing. First I'll describe the operations generally and then how they apply to the golf problem specifically.
**General Description**:
* `dj` : Delete with 'one line down motion' (delete current and following line)
* `gJ` : Join current and next line, adding no extra spaces
* `.` : ... |
13,603 | <p>I frequently find myself trying to do transformations like </p>
<pre><code> author = {{foo
bar}},
</code></pre>
<p>to </p>
<pre><code> author = {foo
bar},
</code></pre>
<p>and I can't find a regex to match the part in between the curly braces.</p>
<pre><code>%s/{{\(.*\)}}... | [
{
"answer_id": 13604,
"author": "oarfish",
"author_id": 1066,
"author_profile": "https://vi.stackexchange.com/users/1066",
"pm_score": 1,
"selected": false,
"text": "<p>Turns out one must use <code>\\_.*</code> instead of <code>.</code>.</p>\n"
},
{
"answer_id": 13991,
"autho... | 2017/09/17 | [
"https://vi.stackexchange.com/questions/13603",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1066/"
] | I frequently find myself trying to do transformations like
```
author = {{foo
bar}},
```
to
```
author = {foo
bar},
```
and I can't find a regex to match the part in between the curly braces.
```
%s/{{\(.*\)}}/{\1}/g
```
doesn't work since `.` does not match newlines... | You should use `\_.\{-}` instead of `.*`.
`\_.` matches any character including end-of-line. However, as `:h \_.` warns, using it with `*` will match all text to the end of the buffer.
`\{-}` is similar to `*`, matching 0 or more instances of the proceeding atom. But it matches **as few as possible** instead of as m... |
13,612 | <p>I'm trying to use <code>:!</code> to run my test suite.</p>
<p>The file I'm working on is:
<code>/foo/bar/baz.py</code></p>
<p>My tests are in:
<code>/foo/test</code></p>
<p>I tried running <code>:!../python -m unittest test</code> but I get the following </p>
<pre><code>error:/bin/bash: ../python: No such file... | [
{
"answer_id": 13613,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 4,
"selected": true,
"text": "<p>To execute a command in the parent directory of Vim's current working directory, just precede the command with <code>cd... | 2017/09/18 | [
"https://vi.stackexchange.com/questions/13612",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11547/"
] | I'm trying to use `:!` to run my test suite.
The file I'm working on is:
`/foo/bar/baz.py`
My tests are in:
`/foo/test`
I tried running `:!../python -m unittest test` but I get the following
```
error:/bin/bash: ../python: No such file or directory
shell returned 127
```
How do I tell VIm to execute a command ... | To execute a command in the parent directory of Vim's current working directory, just precede the command with `cd ..;`, like this example using `ls`:
```
:!cd ..; ls
```
To execute a command in the parent directory of the current buffer, precede the command with `cd %:h/..`, e.g.,
```
:!cd %:h/..; ls
```
See
``... |
13,616 | <p>How would I use <code>set iskeyword</code> to be able to use <code>w</code> to count Capital letters as words?</p>
<p>For example for the following sentence,</p>
<pre><code>ThisIsAShortSentence
</code></pre>
<p>Pressing <code>w</code> will jump from <code>T</code> -> <code>I</code> -> <code>A</code> -> <code>S</c... | [
{
"answer_id": 13617,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 3,
"selected": false,
"text": "<p>This is not how <code>w</code> and <code>iskeyword</code> works. Consider this example:</p>\n\n<pre><code>!his!s!!hort!... | 2017/09/19 | [
"https://vi.stackexchange.com/questions/13616",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14339/"
] | How would I use `set iskeyword` to be able to use `w` to count Capital letters as words?
For example for the following sentence,
```
ThisIsAShortSentence
```
Pressing `w` will jump from `T` -> `I` -> `A` -> `S` -> `S` | This is not how `w` and `iskeyword` works. Consider this example:
```
!his!s!!hort!entence
^^ ^^^ ^ ^^
```
Pressing `w` repeatedly, you will see the cursor stops where sequences of `!`s meet sequences of alpha characters- there are 8 stops in total (including the first position). Put differently, `w` will only sk... |
13,623 | <p>I have html settings set up in my <code>~/.vim/ftplugin/html.vim</code> file. I would like these settings to apply to Rhtml files as well. I made a symbolic link with</p>
<pre><code>ln -s ~/.vim/ftplugin/html.vim ~/.vim/ftplugin/Rhtml.vim
</code></pre>
<p>Why doesn't this load my html settings when I open a .Rht... | [
{
"answer_id": 13644,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 5,
"selected": true,
"text": "<p>The symlink you've created at <code>~/.vim/ftplugin/Rhtml.vim</code> tells Vim how to handle files with the <code>RHTML</code... | 2017/09/19 | [
"https://vi.stackexchange.com/questions/13623",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14354/"
] | I have html settings set up in my `~/.vim/ftplugin/html.vim` file. I would like these settings to apply to Rhtml files as well. I made a symbolic link with
```
ln -s ~/.vim/ftplugin/html.vim ~/.vim/ftplugin/Rhtml.vim
```
Why doesn't this load my html settings when I open a .Rhtml file? | The symlink you've created at `~/.vim/ftplugin/Rhtml.vim` tells Vim how to handle files with the `RHTML` filetype, but you haven't told Vim how to *recognise* which files should have this filetype.
Instructions for how to do so can be found in the documentation by running the command [`:help new-filetype`](https://vim... |
13,630 | <p>I have a lot of difficulty doing things like the following in Vim:</p>
<p>From</p>
<pre><code>1 'apple'
2 'orange'
3 'pear'
4 $fruit1 =
5 $fruit2 =
6 $fruit3 =
</code></pre>
<p>To</p>
<pre><code>1
2
3
4 $fruit1 = 'apple';
5 $fruit2 = 'orange';
6 $fruit3 = 'pear';
</code></pre>
<p>The best approach I can come u... | [
{
"answer_id": 13632,
"author": "bew",
"author_id": 5761,
"author_profile": "https://vi.stackexchange.com/users/5761",
"pm_score": 2,
"selected": false,
"text": "<p>One way to do it (probably not the best):</p>\n\n<pre><code>^Vjj$d)$^VjjA ^[lpgvA;^[\n</code></pre>\n\n<p>(With <code>^V</c... | 2017/09/19 | [
"https://vi.stackexchange.com/questions/13630",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10490/"
] | I have a lot of difficulty doing things like the following in Vim:
From
```
1 'apple'
2 'orange'
3 'pear'
4 $fruit1 =
5 $fruit2 =
6 $fruit3 =
```
To
```
1
2
3
4 $fruit1 = 'apple';
5 $fruit2 = 'orange';
6 $fruit3 = 'pear';
```
The best approach I can come up with is to record what I hope is a sound macro to make... | One way to do it (probably not the best):
```
^Vjj$d)$^VjjA ^[lpgvA;^[
```
(With `^V` as `Ctrl``V` and `^[` as `Escape`)
---
Assuming the cursor is on the top left corner:
### Select & delete the first 3 lines
`^V` => enter in block selection mode
`jj$` => select the 2 lines below to the end
`d` => delete thos... |
13,631 | <p>If I had something like a list of <code>#define</code>s in a c file, say</p>
<pre><code>#define a
#define cd
#define blah
</code></pre>
<p>and I wanted to replace all the <code>#define</code>s to capitalized characters, can I do this in a single substitution command? Maybe with regex?</p>
<p>I'm thinking somethin... | [
{
"answer_id": 13632,
"author": "bew",
"author_id": 5761,
"author_profile": "https://vi.stackexchange.com/users/5761",
"pm_score": 2,
"selected": false,
"text": "<p>One way to do it (probably not the best):</p>\n\n<pre><code>^Vjj$d)$^VjjA ^[lpgvA;^[\n</code></pre>\n\n<p>(With <code>^V</c... | 2017/09/19 | [
"https://vi.stackexchange.com/questions/13631",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14359/"
] | If I had something like a list of `#define`s in a c file, say
```
#define a
#define cd
#define blah
```
and I wanted to replace all the `#define`s to capitalized characters, can I do this in a single substitution command? Maybe with regex?
I'm thinking something along the lines of `:%s/a/A`, but more of a general c... | One way to do it (probably not the best):
```
^Vjj$d)$^VjjA ^[lpgvA;^[
```
(With `^V` as `Ctrl``V` and `^[` as `Escape`)
---
Assuming the cursor is on the top left corner:
### Select & delete the first 3 lines
`^V` => enter in block selection mode
`jj$` => select the 2 lines below to the end
`d` => delete thos... |
13,650 | <p>Right now I'm trying to configure <code>ctags</code> in my vim environment but I'm not sure what I'm missing.</p>
<p>First, I installed <code>ctags</code> (using yaourt) and the I added <a href="https://pastebin.com/fZUP0iX0" rel="nofollow noreferrer">this</a> on <code>~/.ctags</code>.</p>
<p>After that, I run <co... | [
{
"answer_id": 13651,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 2,
"selected": false,
"text": "<ol>\n<li><p><code>set tags=./tags</code> means \"path of the current file\" not necessarily the current directory. The vi... | 2017/09/20 | [
"https://vi.stackexchange.com/questions/13650",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8228/"
] | Right now I'm trying to configure `ctags` in my vim environment but I'm not sure what I'm missing.
First, I installed `ctags` (using yaourt) and the I added [this](https://pastebin.com/fZUP0iX0) on `~/.ctags`.
After that, I run `ctags -R .` on the root of my project and it generated a file "tags" with 14000 lines.
I... | Along with Mass's answer, I think your latin american keyboard might be causing some confusion. Vim can't see Shift and Ctrl when used together on letter keys, because it produces no ASCII output. I simulated a latin american keyboard on my computer and found that in order to trigger tags all I needed to do was
```
CT... |
13,656 | <p>I've been trying to set a custom statusline for help files. I tried:</p>
<pre><code>set statusline=%!StatusLine()
function! StatusLine()
if &ft == 'help'
let b:status = "%#error#[HELP]%*"
else
let b:status = "my usual statusline"
endif
return b:status
endfunction
</code></pre>
<... | [
{
"answer_id": 13658,
"author": "ljden",
"author_id": 14380,
"author_profile": "https://vi.stackexchange.com/users/14380",
"pm_score": 2,
"selected": false,
"text": "<p>EDIT: SO I tested it out a little more this morning and had a bit of a dig. Your main issue was trying to do it all in ... | 2017/09/21 | [
"https://vi.stackexchange.com/questions/13656",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12652/"
] | I've been trying to set a custom statusline for help files. I tried:
```
set statusline=%!StatusLine()
function! StatusLine()
if &ft == 'help'
let b:status = "%#error#[HELP]%*"
else
let b:status = "my usual statusline"
endif
return b:status
endfunction
```
but when a help window is op... | From [`:h status-line`](https://vimhelp.appspot.com/windows.txt.html#status-line):
>
> This option can be local to the window, so that you can have a different
> status line in each window.
>
>
>
As ljden pointed out, you must use a local status line otherwise it is set for all buffers:
```
set statusline=%!Sta... |
13,660 | <p>I would like a piece of Vimscript which would </p>
<ul>
<li>query the time of day</li>
<li>check whether it's later than, say, 6pm</li>
<li>set an option based on the result</li>
</ul>
<p>Why? So that I get the dark solarized color scheme whenever I open my editor in the evening, the light one otherwise. </p>
<p>... | [
{
"answer_id": 13665,
"author": "ljden",
"author_id": 14380,
"author_profile": "https://vi.stackexchange.com/users/14380",
"pm_score": 2,
"selected": false,
"text": "<p>No need to reinvent the wheel, had a quick google and <a href=\"https://github.com/nightsense/night-and-day\" rel=\"nof... | 2017/09/21 | [
"https://vi.stackexchange.com/questions/13660",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1066/"
] | I would like a piece of Vimscript which would
* query the time of day
* check whether it's later than, say, 6pm
* set an option based on the result
Why? So that I get the dark solarized color scheme whenever I open my editor in the evening, the light one otherwise.
Can this be done? | On a Unix system you can add this to your vimrc:
```
if system('date +%H') > 18
colorscheme night
else
colorscheme day
endif
```
`date +%H` is a shell command which returns the hour in a 24 format (see [`man date`](http://man7.org/linux/man-pages/man1/date.1.html)).
`system()` allows you to get the result o... |