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 |
|---|---|---|---|---|---|---|
14,855 | <p>My Vim is kinda slow for nearly everything. Opening a file takes five seconds, it flickers when I move up and down NerdTree and sometimes when I switch windows or tabs, it freezes for dozens of seconds.</p>
<p>I have a lot of plugins enabled, plus webpack watch running. I have htop running on a separate monitor, an... | [
{
"answer_id": 34716,
"author": "SergioAraujo",
"author_id": 7339,
"author_profile": "https://vi.stackexchange.com/users/7339",
"pm_score": 0,
"selected": false,
"text": "<p>One plugin that notably improved my neovim startup time is <a href=\"https://github.com/nathom/filetype.nvim\" rel... | 2018/01/18 | [
"https://vi.stackexchange.com/questions/14855",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15976/"
] | My Vim is kinda slow for nearly everything. Opening a file takes five seconds, it flickers when I move up and down NerdTree and sometimes when I switch windows or tabs, it freezes for dozens of seconds.
I have a lot of plugins enabled, plus webpack watch running. I have htop running on a separate monitor, and sometime... | Yes: run `vim --startuptime profile` and work for a bit. (To purely measure time from "enter" to "open and ready", use `vim --startuptime profile +q`.)
I used this and a single command quite successfully to cut my startup time by 1/3rd.
1. First, I collected the profile, as shown above.
2. Then I "analyzed" it by put... |
14,856 | <p>How can I disable all user mappings only for current buffer in vim? I've tried <code>:mapclear</code> but it removed mappings for all buffers.</p>
| [
{
"answer_id": 34716,
"author": "SergioAraujo",
"author_id": 7339,
"author_profile": "https://vi.stackexchange.com/users/7339",
"pm_score": 0,
"selected": false,
"text": "<p>One plugin that notably improved my neovim startup time is <a href=\"https://github.com/nathom/filetype.nvim\" rel... | 2018/01/18 | [
"https://vi.stackexchange.com/questions/14856",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6859/"
] | How can I disable all user mappings only for current buffer in vim? I've tried `:mapclear` but it removed mappings for all buffers. | Yes: run `vim --startuptime profile` and work for a bit. (To purely measure time from "enter" to "open and ready", use `vim --startuptime profile +q`.)
I used this and a single command quite successfully to cut my startup time by 1/3rd.
1. First, I collected the profile, as shown above.
2. Then I "analyzed" it by put... |
14,860 | <p>I want to have something like a <code>virtualenv</code> for Vim: on my Windows machine, the plugins are normally located in <code>vimfiles</code>, <code>_vimrc</code> holds the settings.</p>
<p>For debugging reasons, I want to create a separate environment with an empty <code>vimfiles2</code> directory and a blank... | [
{
"answer_id": 14861,
"author": "eckes",
"author_id": 1041,
"author_profile": "https://vi.stackexchange.com/users/1041",
"pm_score": 1,
"selected": true,
"text": "<p>Just found it myself: the <a href=\"http://vimdoc.sourceforge.net/htmldoc/options.html#'rtp'\" rel=\"nofollow nore... | 2018/01/18 | [
"https://vi.stackexchange.com/questions/14860",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1041/"
] | I want to have something like a `virtualenv` for Vim: on my Windows machine, the plugins are normally located in `vimfiles`, `_vimrc` holds the settings.
For debugging reasons, I want to create a separate environment with an empty `vimfiles2` directory and a blank `_vimrc2` file.
How do I do that? | Just found it myself: the [`runtimepath`](http://vimdoc.sourceforge.net/htmldoc/options.html#'rtp') is the solution!
1. create a new `vimrc`, e.g. `new-vimrc`
2. inside that `new-vimrc` set up the `runtimepath` so that it points to a new directory. Sample for Windows:
```
set runtimepath=~/new-vimfiles,$VIM/vimfiles,... |
14,867 | <p>At the moment, my commenting and un-commenting is done by two different strokes listed below:</p>
<pre><code>nnoremap <leader>c 0<insert>//<Esc>
nnoremap <leader><leader>c :s;^\s*//<cr>
</code></pre>
<p>Which is tedious for me, can someone help me to write a mapping macro that ... | [
{
"answer_id": 14869,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": true,
"text": "<p>You can achieve this kind of effect simply with an expression map and the ternary operator:</p>\n\n<pre><code>nnoremap <ex... | 2018/01/19 | [
"https://vi.stackexchange.com/questions/14867",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15958/"
] | At the moment, my commenting and un-commenting is done by two different strokes listed below:
```
nnoremap <leader>c 0<insert>//<Esc>
nnoremap <leader><leader>c :s;^\s*//<cr>
```
Which is tedious for me, can someone help me to write a mapping macro that `<leader>c` stroke removes the comments, if there are any, or a... | You can achieve this kind of effect simply with an expression map and the ternary operator:
```
nnoremap <expr> <leader>c getline('.')[0:1] == '//'
\ ? ":s;^\s*//<cr>"
\ : "0<insert>//<Esc>"
```
An expression mapping maps your `<leader>c` to the result of an expression. In this case, it tests if the first two ch... |
14,868 | <p>I have read in various documentation that when Vim is started in Ex mode, it attempts to "act like" Ex, so I gather from this that Ex is a separate program and is not an actual part of the Vim source code and has its own separate code maintained by people other than those maintaining Vim. If this is true, what is th... | [
{
"answer_id": 14869,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": true,
"text": "<p>You can achieve this kind of effect simply with an expression map and the ternary operator:</p>\n\n<pre><code>nnoremap <ex... | 2018/01/19 | [
"https://vi.stackexchange.com/questions/14868",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | I have read in various documentation that when Vim is started in Ex mode, it attempts to "act like" Ex, so I gather from this that Ex is a separate program and is not an actual part of the Vim source code and has its own separate code maintained by people other than those maintaining Vim. If this is true, what is the r... | You can achieve this kind of effect simply with an expression map and the ternary operator:
```
nnoremap <expr> <leader>c getline('.')[0:1] == '//'
\ ? ":s;^\s*//<cr>"
\ : "0<insert>//<Esc>"
```
An expression mapping maps your `<leader>c` to the result of an expression. In this case, it tests if the first two ch... |
14,883 | <p>On unix, you can do something like this:</p>
<p><code>$NVIM_LISTEN_ADDRESS=/some/path nvim</code></p>
<p>On Windows, that does not work. What is the equivalent?</p>
<p>My use case is detailed out here: <a href="https://github.com/mhinz/neovim-remote/pull/74" rel="nofollow noreferrer">https://github.com/mhinz/neov... | [
{
"answer_id": 14902,
"author": "bzm3r",
"author_id": 15998,
"author_profile": "https://vi.stackexchange.com/users/15998",
"pm_score": 0,
"selected": false,
"text": "<p>You can temporarily set the environment variable <code>NVIM_LISTEN_ADDRESS</code> to point to a file of interest. Then,... | 2018/01/20 | [
"https://vi.stackexchange.com/questions/14883",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/15998/"
] | On unix, you can do something like this:
`$NVIM_LISTEN_ADDRESS=/some/path nvim`
On Windows, that does not work. What is the equivalent?
My use case is detailed out here: <https://github.com/mhinz/neovim-remote/pull/74>
Essentially, `neovim-remote` needs to be able to start an nvim process with the `NVIM_LISTEN_ADDR... | You can use `set` to set an environment variable for the current Command prompt window, so the following is a slightly closer equivalent to your Unix command than setting the environment variable globally in the GUI:
```
set NVIM_LISTEN_ADDRESS=/some/path
nvim
``` |
14,887 | <p>There are many make-variant, maybe the most popular is the <a href="https://www.gnu.org/software/make/" rel="nofollow noreferrer">GNU make</a>. The vim package contains <code>syntax/make.vim</code> which related to GNU make.</p>
<p>Many people use different make, for example <a href="https://www.freebsd.org/cgi/man... | [
{
"answer_id": 14902,
"author": "bzm3r",
"author_id": 15998,
"author_profile": "https://vi.stackexchange.com/users/15998",
"pm_score": 0,
"selected": false,
"text": "<p>You can temporarily set the environment variable <code>NVIM_LISTEN_ADDRESS</code> to point to a file of interest. Then,... | 2018/01/20 | [
"https://vi.stackexchange.com/questions/14887",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11418/"
] | There are many make-variant, maybe the most popular is the [GNU make](https://www.gnu.org/software/make/). The vim package contains `syntax/make.vim` which related to GNU make.
Many people use different make, for example [FreeBSD's make](https://www.freebsd.org/cgi/man.cgi?make(1)) which has different syntax than GNU ... | You can use `set` to set an environment variable for the current Command prompt window, so the following is a slightly closer equivalent to your Unix command than setting the environment variable globally in the GUI:
```
set NVIM_LISTEN_ADDRESS=/some/path
nvim
``` |
14,897 | <p>I have a bash_file that operates on a latex file to produce a pdf.</p>
<pre><code>#!/bin/bash
/usr/bin/pandoc/ filein.md -t beamer -o fileout.md ;
/usr/bin/pdflatex/ fileother.tex ;
/usr/bin/evince fileother.tex
</code></pre>
<p>If I execute in normal mode</p>
<pre><code>! ./bash_file.sh
</code></pre>
<p>it work... | [
{
"answer_id": 14899,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>If you start vim in a folder which contains the file <code>foo.sh</code> with the following content:</p>\n\n<pre><code>#... | 2018/01/21 | [
"https://vi.stackexchange.com/questions/14897",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11895/"
] | I have a bash\_file that operates on a latex file to produce a pdf.
```
#!/bin/bash
/usr/bin/pandoc/ filein.md -t beamer -o fileout.md ;
/usr/bin/pdflatex/ fileother.tex ;
/usr/bin/evince fileother.tex
```
If I execute in normal mode
```
! ./bash_file.sh
```
it works fine but I cannnot work in vim while I am view... | If you start vim in a folder which contains the file `foo.sh` with the following content:
```
#!/bin/bash
echo "Output of the bash script"
```
You can open a new buffer (`:enew` for example) and execute the script and get it's output in this new buffer with the following command:
```
:read ! ./foo.sh
```
Your ne... |
14,901 | <p>Right now I am using Pathogen to manage bundles in my <code>~/.vim</code> folder.</p>
<p>I also have my public <code>dotfiles</code> repo which has all my configs, including my entire <code>.vim</code> folder. I don't use symlinks to do this, because it has been a nightmare doing it that way. Whenever I want to upd... | [
{
"answer_id": 14927,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 2,
"selected": false,
"text": "<p>I have tried the submodule approach and ... I ended up switching to vim-plug. This is essentially what Vundle, vim-plug etc.... | 2018/01/21 | [
"https://vi.stackexchange.com/questions/14901",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16016/"
] | Right now I am using Pathogen to manage bundles in my `~/.vim` folder.
I also have my public `dotfiles` repo which has all my configs, including my entire `.vim` folder. I don't use symlinks to do this, because it has been a nightmare doing it that way. Whenever I want to update my `dotfiles` repo I just copy and past... | Using git submodules is a common way of doing this. The [VimCasts episode](http://vimcasts.org/episodes/synchronizing-plugins-with-git-submodules-and-pathogen/) is a great explanation, but the basic commands are as below:
Adding a new plugin
-------------------
```
cd ~/.vim
git submodule add http://github.com/<usern... |
14,907 | <p>I use Plug as my plugin manager and have this line:</p>
<p><code>Plug 'MyPlugin', { 'for' : 'c'}</code></p>
<p>which means it should only load the plugin <code>MyPlugin</code> when a file of the filetype <code>c</code> is opened.</p>
<p>This works fine, but right after that I have a function call: <code>call MyPl... | [
{
"answer_id": 14911,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>In the case of autoload functions, what I usually do is the following</p>\n\n<ol>\n<li>I check whether the function ... | 2018/01/22 | [
"https://vi.stackexchange.com/questions/14907",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16021/"
] | I use Plug as my plugin manager and have this line:
`Plug 'MyPlugin', { 'for' : 'c'}`
which means it should only load the plugin `MyPlugin` when a file of the filetype `c` is opened.
This works fine, but right after that I have a function call: `call MyPlugin#doSomething(...)` which leads to an error everytime I don... | Rather than have my `~/.vimrc` load a plugin ahead of when it would normally be loaded, I usually solve this problem in one of two ways.
1. Call the function in a `~/.vimrc/after/plugin/MyPlugin.vim` file.
`if exists('*MyPlugin#doSomething')
call MyPlugin#doSomething(args)
endif`
2. Call the function in an autocomma... |
14,917 | <p>Can add() and insert() be performed on a dictionary? The help file is unclear on this. If so, what is the correct syntax?</p>
<p>If these functions do not work on dictionaries, then how can I add or insert items to the dictionary?</p>
| [
{
"answer_id": 14918,
"author": "mMontu",
"author_id": 1405,
"author_profile": "https://vi.stackexchange.com/users/1405",
"pm_score": 2,
"selected": false,
"text": "<p>Maybe you are looking to the wrong part of the documentation.</p>\n\n<p><a href=\"http://vimhelp.appspot.com/usr_41.txt.... | 2018/01/22 | [
"https://vi.stackexchange.com/questions/14917",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | Can add() and insert() be performed on a dictionary? The help file is unclear on this. If so, what is the correct syntax?
If these functions do not work on dictionaries, then how can I add or insert items to the dictionary? | Dictionaries aren't ordered, so there's no need for `add()` or `insert()`.
Values are added to a dictionary using either
```
let d.foo = 'bar'
```
or
```
let d['foo'] = 'bar'
```
syntax.
I would also suggest reviewing [`:help 41.8`](https://vimhelp.appspot.com/usr_41.txt.html#41.8) and [`:help Dictionary`](http... |
14,924 | <p>I'm looking for a way to make a single configuration file both for windows platform and for unix one. So for now i have two configs .vimrc for unix and _vimrc for windows platform and the only difference between them is a necessary commands to vundle plugin manager. (i desregard the difference with filename, as i ai... | [
{
"answer_id": 14934,
"author": "Dmitrii",
"author_id": 11110,
"author_profile": "https://vi.stackexchange.com/users/11110",
"pm_score": 2,
"selected": false,
"text": "<p>As it turned out there are common practice to wrap platform specific options in statements which checks the system an... | 2018/01/23 | [
"https://vi.stackexchange.com/questions/14924",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11110/"
] | I'm looking for a way to make a single configuration file both for windows platform and for unix one. So for now i have two configs .vimrc for unix and \_vimrc for windows platform and the only difference between them is a necessary commands to vundle plugin manager. (i desregard the difference with filename, as i aim ... | If you are already using symlinks to set up your Vim configuration, and if — as I infer from your comments — the only operating system dependent part of your current config is your Vundle setup, then you don't actually need any special code in your `vimrc`:
**Windows Command Line**
```
:: You'll already be setting up... |
14,932 | <p>My vimrc about wrap is set like this:</p>
<pre><code>set wrap "Wrap lines
set breakindent " indent after line wrapped
</code></pre>
<p>But the wrapped lines are not equal in length, such as:</p>
<pre><code>line 1: some contents ..... <end>
continued line ..... other contents <end>
line 2: ... | [
{
"answer_id": 30955,
"author": "kqwyf",
"author_id": 34584,
"author_profile": "https://vi.stackexchange.com/users/34584",
"pm_score": 0,
"selected": false,
"text": "<p>For the second problem, try <code>set formatoptions+=m</code>.</p>\n<p>Also see <a href=\"https://www.reddit.com/r/vim/... | 2018/01/24 | [
"https://vi.stackexchange.com/questions/14932",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16038/"
] | My vimrc about wrap is set like this:
```
set wrap "Wrap lines
set breakindent " indent after line wrapped
```
But the wrapped lines are not equal in length, such as:
```
line 1: some contents ..... <end>
continued line ..... other contents <end>
line 2: ....
```
The line 1 and its wrapped line does n... | Since [8.2.3198](https://github.com/vim/vim/commit/f674b358fc18cf1641a066cc5de73da69e651024) vim has `breadkindentopt` with `list:-1`:
```
'breakindentopt' 'briopt' string (default empty)
local to window
{not available when compiled without the |+linebreak|
feature}
Settings for... |
14,933 | <p>I like to write notes in markdown file. Most of the times my notes are about coding, but sometimes I need to write some math equations or symbols. I would like to see the equations directly in the vim, so I add the following lines in my vimrc:</p>
<pre><code>set conceallevel=2
set concealcursor=
</code></pre>
<p>H... | [
{
"answer_id": 14937,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 2,
"selected": false,
"text": "<p><em>My interpretation is that the OP is looking for rendering of markup into fancy, graphical depictions of equations... | 2018/01/24 | [
"https://vi.stackexchange.com/questions/14933",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16038/"
] | I like to write notes in markdown file. Most of the times my notes are about coding, but sometimes I need to write some math equations or symbols. I would like to see the equations directly in the vim, so I add the following lines in my vimrc:
```
set conceallevel=2
set concealcursor=
```
However, when I write the f... | Mathematical equations cannot be displayed in Vim in this way: Vim has no means of rendering them, as [@BLayer explains in his answer](https://vi.stackexchange.com/a/14937/343).
However, mathematical *symbols* you can indeed display using Vim's `conceal` feature, as you suggest in your tags. The following commands wil... |
14,940 | <p>The easiest way to explain this question is to show you my code and what I am trying to do.</p>
<p>Here is some code, before any edits are made:</p>
<pre><code>// some block of code here
// blaa blaa
// please imagine these comments are code
// another block of code after some whitespace break between
// this blo... | [
{
"answer_id": 14941,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 2,
"selected": false,
"text": "<p>What you are looking for is <code>o</code> in normal mode see <a href=\"http://vimhelp.appspot.com/insert.txt.html#o\" r... | 2018/01/24 | [
"https://vi.stackexchange.com/questions/14940",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3246/"
] | The easiest way to explain this question is to show you my code and what I am trying to do.
Here is some code, before any edits are made:
```
// some block of code here
// blaa blaa
// please imagine these comments are code
// another block of code after some whitespace break between
// this block and the previous
/... | What you are looking for is `o` in normal mode see [`:h o`](http://vimhelp.appspot.com/insert.txt.html#o):
>
> Begin a new line below the cursor and insert text, repeat [count] times.
>
>
>
Note there is also `O` which adds a newline above the cursor.
For example you may want a mapping like this:
```
nnoremap <... |
14,950 | <p>After opening vim as normal user. Is it possible to open a new file as sudo user? like for example in <code>:e file</code>.</p>
| [
{
"answer_id": 14952,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 4,
"selected": true,
"text": "<p>One workaround is to open the file normally:</p>\n\n<pre><code>:e file\n</code></pre>\n\n<p>And then use the <a href=\"https:... | 2018/01/24 | [
"https://vi.stackexchange.com/questions/14950",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14609/"
] | After opening vim as normal user. Is it possible to open a new file as sudo user? like for example in `:e file`. | One workaround is to open the file normally:
```
:e file
```
And then use the [sudo tee trick](https://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work) when *writing* the file:
```
:w !sudo tee %
```
If you don't have read permission on the file, you're going to need to use sudo to... |
14,956 | <p>One of the most basic editing commands is <code>c<motion></code> to change text, e.g. <code>cw</code> - change word, <code>c$</code> - change to end of line, <code>cc</code> - change entire line, <code>c3l</code> - change 3 characters to the right.</p>
<p>My question is, why then does <code>cb</code> at the e... | [
{
"answer_id": 14957,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 4,
"selected": true,
"text": "<p>The <code>b</code> motion is an exclusive motion. Visual mode is inclusive by default (See <code>:h 'selection'</cod... | 2018/01/24 | [
"https://vi.stackexchange.com/questions/14956",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16056/"
] | One of the most basic editing commands is `c<motion>` to change text, e.g. `cw` - change word, `c$` - change to end of line, `cc` - change entire line, `c3l` - change 3 characters to the right.
My question is, why then does `cb` at the end of a word prepare for replacement, excluding the last character of the word (i.... | The `b` motion is an exclusive motion. Visual mode is inclusive by default (See `:h 'selection'`).
From `:h exclusive`:
```
A character motion is either inclusive or exclusive. When inclusive, the
start and end position of the motion are included in the operation. When
exclusive, the last character towards the end ... |
14,974 | <p>I have, for many years, mapped the space key to page-down. I love this mapping, except when I don't love it. </p>
<p>Specifically, I don't love it when I accidentally press the space key, which happens more than I care to admit.</p>
<p>I'm toying with a workaround that so far seems OK: I use two key mappings that ... | [
{
"answer_id": 14982,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 0,
"selected": false,
"text": "<p>I am not sure we can make this cleaner. The issue is you are pressing something accidentally. The best way to fix t... | 2018/01/25 | [
"https://vi.stackexchange.com/questions/14974",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6203/"
] | I have, for many years, mapped the space key to page-down. I love this mapping, except when I don't love it.
Specifically, I don't love it when I accidentally press the space key, which happens more than I care to admit.
I'm toying with a workaround that so far seems OK: I use two key mappings that will restore my w... | I map navigations such as `<c-d>` to add the current location to the jump list before jumping so I can always go back. In your case you'd need something like:
```
nnoremap <space> mp`p<c-d>
```
then you can return after an accidental space with `<c-o>`. |
14,996 | <p>I want to turn off the syntax highlighting for TODO items, like TODO and FIXME. How can I achieve this?</p>
| [
{
"answer_id": 14982,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 0,
"selected": false,
"text": "<p>I am not sure we can make this cleaner. The issue is you are pressing something accidentally. The best way to fix t... | 2018/01/27 | [
"https://vi.stackexchange.com/questions/14996",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12054/"
] | I want to turn off the syntax highlighting for TODO items, like TODO and FIXME. How can I achieve this? | I map navigations such as `<c-d>` to add the current location to the jump list before jumping so I can always go back. In your case you'd need something like:
```
nnoremap <space> mp`p<c-d>
```
then you can return after an accidental space with `<c-o>`. |
15,004 | <p>How can I get help on operators as opposed to normal mode commands? For example, if I type the following:</p>
<pre><code>:h .
</code></pre>
<p>Then I will get the help on the normal mode dot command, not on the string concatenation operator which is the same symbol.</p>
| [
{
"answer_id": 15005,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 2,
"selected": false,
"text": "<p>The help tags for those are usually prefixed with <code>expr-</code>. For example: <a href=\"http://vimhelp.appspot.com/eval... | 2018/01/27 | [
"https://vi.stackexchange.com/questions/15004",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | How can I get help on operators as opposed to normal mode commands? For example, if I type the following:
```
:h .
```
Then I will get the help on the normal mode dot command, not on the string concatenation operator which is the same symbol. | The help tags for those are usually prefixed with `expr-`. For example: [`:help expr-.`](http://vimhelp.appspot.com/eval.txt.html#expr-.):
```
expr5 and expr6 expr5 expr6
---------------
expr6 + expr6 .. Number addition or List concatenation expr-+
expr6 - expr6 .. ... |
15,011 | <p>This didn't get much love on stackoverflow (<a href="https://stackoverflow.com/q/48269793/2512141">https://stackoverflow.com/q/48269793/2512141</a>), but I think it's important so I'm reposting here. I think this could be a major barrier to people using Vim's buffers as they're intended, and consequently they resort... | [
{
"answer_id": 15012,
"author": "BitPusher16",
"author_id": 16100,
"author_profile": "https://vi.stackexchange.com/users/16100",
"pm_score": 3,
"selected": true,
"text": "<p>I've discovered through experimentation that <code>:bprev</code> will resume functioning if I delete the path buff... | 2018/01/27 | [
"https://vi.stackexchange.com/questions/15011",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16100/"
] | This didn't get much love on stackoverflow (<https://stackoverflow.com/q/48269793/2512141>), but I think it's important so I'm reposting here. I think this could be a major barrier to people using Vim's buffers as they're intended, and consequently they resort to tabs to get the file-switching capability they need. Tex... | I've discovered through experimentation that `:bprev` will resume functioning if I delete the path buffer just prior to the `[No Name]` buffer. However, this is burdensome.
Instead, I have started using `:Explore` to open Netrw. This does not create the latent buffer which trips up `:bprev`, but I am still able to bro... |
15,022 | <p>I've been struggling with this topic for a little more than i'd like to admit but here it is:</p>
<p>I've set my vim (~/.vimrc) to indent using 4 spaces using</p>
<pre><code>:set expandtab
:set tabstop=4
:set shiftwidth=4
</code></pre>
<p>Whenever I want to detete one of these groups I have to remove every one of... | [
{
"answer_id": 15024,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 2,
"selected": false,
"text": "<p>You may prefer either or both of the following options:</p>\n\n<pre><code>set smarttab\nset softtabstop=4\n</code></pre>... | 2018/01/28 | [
"https://vi.stackexchange.com/questions/15022",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16115/"
] | I've been struggling with this topic for a little more than i'd like to admit but here it is:
I've set my vim (~/.vimrc) to indent using 4 spaces using
```
:set expandtab
:set tabstop=4
:set shiftwidth=4
```
Whenever I want to detete one of these groups I have to remove every one of the spaces. I thought vim would ... | You may prefer either or both of the following options:
```
set smarttab
set softtabstop=4
```
The primary difference between these two options in your case (where `expandtab tabstop=4 shiftwidth=4`) is whether the "backspace deletes 4 spaces" behavior works only at the beginning of lines (as with `smarttab` only) o... |
15,037 | <p>For example, substitute <code>:</code> with register 0's content.<br>
What's the correct command for <code>:s/:/"0/</code>.</p>
| [
{
"answer_id": 15038,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 5,
"selected": true,
"text": "<p><em>N.B. In all the below, I presume that your question is only about the method of accessing the register's contents from an... | 2018/01/30 | [
"https://vi.stackexchange.com/questions/15037",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13402/"
] | For example, substitute `:` with register 0's content.
What's the correct command for `:s/:/"0/`. | *N.B. In all the below, I presume that your question is only about the method of accessing the register's contents from an ex command, and that the rest of your `:substitute` command (which replaces only the first match on the current line) does what you require. If you actually want to replace globally, you will need ... |
15,049 | <p>I frequently have one root project open which I've :cd'd to. I also have other tabs with :lcd's set. This is great and works really nicely, but occasionally I end up looking at something in the main project as a result of opening a Buffer from the main project in one of my other windows...</p>
<p>at this point I'... | [
{
"answer_id": 15050,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 2,
"selected": false,
"text": "<p>You can access the working directory of another window with the function <code>getcwd()</code>.</p>\n\n<p>So although this i... | 2018/01/31 | [
"https://vi.stackexchange.com/questions/15049",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1518/"
] | I frequently have one root project open which I've :cd'd to. I also have other tabs with :lcd's set. This is great and works really nicely, but occasionally I end up looking at something in the main project as a result of opening a Buffer from the main project in one of my other windows...
at this point I'd like to do... | As of vim 8.0.1489, one may use `getcwd(-1)` to retrieve the global directory.
Thus, the following will work to restore a window to the global directory and cause it to forget its local directory (as explained in the documentation):
```
if haslocaldir()
execute 'cd' getcwd(-1)
endif
```
This feature was availa... |
15,072 | <p>I've been trying to get Shift+Tab or <code><S-Tab></code> to work in VIM and I can't figure it out.</p>
<p>I read <a href="http://vim.wikia.com/wiki/Make_Shift-Tab_work" rel="nofollow noreferrer">this document</a>, but the <code>remap</code> solution <em>only works for normal mode</em> (because if I press Shi... | [
{
"answer_id": 15093,
"author": "Luke Davis",
"author_id": 8084,
"author_profile": "https://vi.stackexchange.com/users/8084",
"pm_score": 3,
"selected": true,
"text": "<p>Thanks to @B Layer for their help. Turns out that all escape-prefixed keycodes (e.g. forward-delete, shift-tab, scrol... | 2018/02/02 | [
"https://vi.stackexchange.com/questions/15072",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8084/"
] | I've been trying to get Shift+Tab or `<S-Tab>` to work in VIM and I can't figure it out.
I read [this document](http://vim.wikia.com/wiki/Make_Shift-Tab_work), but the `remap` solution *only works for normal mode* (because if I press Shift+Tab, VIM reads the literal escape `^]` in the Shift+Tab escape sequence `^]]Z`,... | Thanks to @B Layer for their help. Turns out that all escape-prefixed keycodes (e.g. forward-delete, shift-tab, scroll-wheel-up, scroll-wheel-down) will fail for the mode in question if there is any mapping of the escape key. That is: most (all?) of the keyboard events in `:help terminal-key-codes` will fail. In my cas... |
15,076 | <p>If I have a function that takes a range, how can I echo the return value of the function?</p>
<p>For example, the following does not work:</p>
<pre><code>:echo 2,8call MyFunction()
</code></pre>
| [
{
"answer_id": 15078,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 2,
"selected": false,
"text": "<p>I looked into this, and I could not find a direct way of doing it. However, one possibility is to create an auxil... | 2018/02/05 | [
"https://vi.stackexchange.com/questions/15076",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | If I have a function that takes a range, how can I echo the return value of the function?
For example, the following does not work:
```
:echo 2,8call MyFunction()
``` | I looked into this, and I could not find a direct way of doing it. However, one possibility is to create an auxiliary function, that is:
```
function! Range() range abort
return RangeAux(a:firstline, a:lastline)
endfunction
function! RangeAux(lnum1, lnum2) abort
echo a:lnum1
echo a:lnum2
endfunction
1,3call Ra... |
15,082 | <p>I want to fold all special documentation comments, and only all special documentation comments.
To do that I created a new syntax, <code>doxygenComment</code> and added highlighting (in red, just to test it).
The comments are getting highlighted correctly, but my <code>GetCppFold</code> doesn't seem to work, since n... | [
{
"answer_id": 15078,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 2,
"selected": false,
"text": "<p>I looked into this, and I could not find a direct way of doing it. However, one possibility is to create an auxil... | 2018/02/05 | [
"https://vi.stackexchange.com/questions/15082",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16217/"
] | I want to fold all special documentation comments, and only all special documentation comments.
To do that I created a new syntax, `doxygenComment` and added highlighting (in red, just to test it).
The comments are getting highlighted correctly, but my `GetCppFold` doesn't seem to work, since no comments are getting fo... | I looked into this, and I could not find a direct way of doing it. However, one possibility is to create an auxiliary function, that is:
```
function! Range() range abort
return RangeAux(a:firstline, a:lastline)
endfunction
function! RangeAux(lnum1, lnum2) abort
echo a:lnum1
echo a:lnum2
endfunction
1,3call Ra... |
15,090 | <p>I'm using nvim and LaTeX together, and for the most part it's been great. However, nvim appears to be incorrectly highlighting underscores that appear in filenames I include as part of the subfiles package (<a href="https://www.sharelatex.com/learn/Multi-file_LaTeX_projects#The_subfiles_package" rel="nofollow norefe... | [
{
"answer_id": 15091,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 4,
"selected": true,
"text": "<p>This is happening because the syntax file for LaTeX does not recognize <code>\\subfile{</code> as a command which takes a... | 2018/02/06 | [
"https://vi.stackexchange.com/questions/15090",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16232/"
] | I'm using nvim and LaTeX together, and for the most part it's been great. However, nvim appears to be incorrectly highlighting underscores that appear in filenames I include as part of the subfiles package (<https://www.sharelatex.com/learn/Multi-file_LaTeX_projects#The_subfiles_package>). At first I thought this was s... | This is happening because the syntax file for LaTeX does not recognize `\subfile{` as a command which takes a file name. You can customize this as follows.
In your config directory (`.vim`, `.config/nvim`, etc), create the directory structure `/after/syntax/`. Create a file called `tex.vim` with the following content... |
15,092 | <p>I like using the <code><CR></code> key to confirm my selection in the popup menu. However I don't like the <code><CR></code> key doing absolutely nothing when no item was selected in the menu -- in this case, it usually means I don't want to confirm a completion, I just want to insert a newline.</p>
<p>... | [
{
"answer_id": 15111,
"author": "Luke Davis",
"author_id": 8084,
"author_profile": "https://vi.stackexchange.com/users/8084",
"pm_score": 1,
"selected": true,
"text": "<p>I solved this with a fairly hacky solution. I just remap the keys I want to use for scrolling the popup menu to also ... | 2018/02/06 | [
"https://vi.stackexchange.com/questions/15092",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8084/"
] | I like using the `<CR>` key to confirm my selection in the popup menu. However I don't like the `<CR>` key doing absolutely nothing when no item was selected in the menu -- in this case, it usually means I don't want to confirm a completion, I just want to insert a newline.
My current remap
```
inoremap <expr> <CR> p... | I solved this with a fairly hacky solution. I just remap the keys I want to use for scrolling the popup menu to also increment/decrement a counter as the menu is scrolled. If the counter is zero, we will insert a newline instead of "confirming" our choice in the popup menu. Note these were developed with the [neocomple... |
15,100 | <p>I am developing a command line application that uses VIM to edit an existing file - think visudo or crontab -e</p>
<p>When I launch VIM, I'm passing it the path of an existing file. I want the user to be able to modify and save the file (e.g. :w or ZZ) but I do not want the user to have the ability to save the file... | [
{
"answer_id": 15111,
"author": "Luke Davis",
"author_id": 8084,
"author_profile": "https://vi.stackexchange.com/users/8084",
"pm_score": 1,
"selected": true,
"text": "<p>I solved this with a fairly hacky solution. I just remap the keys I want to use for scrolling the popup menu to also ... | 2018/02/06 | [
"https://vi.stackexchange.com/questions/15100",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9987/"
] | I am developing a command line application that uses VIM to edit an existing file - think visudo or crontab -e
When I launch VIM, I'm passing it the path of an existing file. I want the user to be able to modify and save the file (e.g. :w or ZZ) but I do not want the user to have the ability to save the file with anot... | I solved this with a fairly hacky solution. I just remap the keys I want to use for scrolling the popup menu to also increment/decrement a counter as the menu is scrolled. If the counter is zero, we will insert a newline instead of "confirming" our choice in the popup menu. Note these were developed with the [neocomple... |
15,105 | <p>I am apparently not getting a return value from execute():</p>
<pre><code>function! Example()
return 5
endfunction
:echo execute("call Example()")
</code></pre>
<p>Just results in a blank line. The 5 is not printed. Why is this?</p>
| [
{
"answer_id": 15107,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 2,
"selected": false,
"text": "<p>From the documentation of <code>execute</code>, i.e. <code>:h execute()</code>:</p>\n\n<blockquote>\n <p><code>e... | 2018/02/06 | [
"https://vi.stackexchange.com/questions/15105",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | I am apparently not getting a return value from execute():
```
function! Example()
return 5
endfunction
:echo execute("call Example()")
```
Just results in a blank line. The 5 is not printed. Why is this? | From the documentation of `execute`, i.e. `:h execute()`:
>
> `execute({command} [, {silent}])`
>
> Execute `{command}` and capture its output.
>
> If `{command}` is a String, returns `{command}` output.
>
> If `{command}` is a List, returns concatenated outputs.
>
>
>
`execute()` returns the output o... |
15,120 | <p>Is there a good way to reverse a set of paragraphs (navigable via cursor motion <code>{</code> and <code>}</code>)? My practical use case is reversing the order of blocks of latex code (ie, reversing the order of jobs in a resume from oldest-to-newest to newest-to-oldest).</p>
<p>Example code:</p>
<pre><code>\beg... | [
{
"answer_id": 15121,
"author": "user786441",
"author_id": 15612,
"author_profile": "https://vi.stackexchange.com/users/15612",
"pm_score": 2,
"selected": false,
"text": "<p>You could try these 3 commands:</p>\n\n<pre><code>g/^\\\\begin/,/^\\\\end/-s/$/\\=\"\\<c-a>\"/|?^\\\\begin?,... | 2018/02/07 | [
"https://vi.stackexchange.com/questions/15120",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/235/"
] | Is there a good way to reverse a set of paragraphs (navigable via cursor motion `{` and `}`)? My practical use case is reversing the order of blocks of latex code (ie, reversing the order of jobs in a resume from oldest-to-newest to newest-to-oldest).
Example code:
```
\begin{rSubsection}{Example 1}{}{Redacted}{}
\it... | If this wasn't something that I did frequently enough to set up a mapping/custom command, I'd probably just use a macro to automate my normal edit commands:
```
O<Esc>mfGo<Esc>qqmt'fd}mf'tPq3@q
```
Broken down, the steps look like this
1. `O<Esc>`: Navigate to the line above the first paragraph. Your sample doesn't... |
15,140 | <p>I have a macro to swap text.<br>
<a href="https://i.stack.imgur.com/bWWZP.png" rel="noreferrer"><img src="https://i.stack.imgur.com/bWWZP.png" alt="enter image description here"></a></p>
<p>For single line, it's running without problem.<br>
But if I run this macro many times and one line is empty or different patte... | [
{
"answer_id": 15142,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 4,
"selected": true,
"text": "<p>You can use <code>:try</code> to do that (<a href=\"http://vimhelp.appspot.com/eval.txt.html#%3atry\" rel=\"noreferrer\">... | 2018/02/09 | [
"https://vi.stackexchange.com/questions/15140",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13402/"
] | I have a macro to swap text.
[](https://i.stack.imgur.com/bWWZP.png)
For single line, it's running without problem.
But if I run this macro many times and one line is empty or different pattern, it will print below error and stop.
[).
Here is an example (I didn't use your macro because you posted it as an image and it's not easy to copy :) )
```
let @z=':try|s/foo/bar/|catch||endtry^M'
```
(Note that `^M` should be entered with `ctrl+v``enter`)
This wa... |
15,151 | <p>For instance move from (the cursor is on the letter in bold italic, in the second column)</p>
<pre>
b<b><i>l</i></b>ablabla
blablabla
blablabla
blablabla
bla
bla
bla
bLablabla
l@st
</pre>
<p>to</p>
<pre>
blablabla
blablabla
blablabla
b<b><i>l</i></b>ablabla
bla
bla
bla
bLablabla
l@st
</pre>
<p>and th... | [
{
"answer_id": 15154,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 4,
"selected": true,
"text": "<p>Interesting. Vertical analogues of word motion commands. I'm not aware of any native way to do this so my first though... | 2018/02/09 | [
"https://vi.stackexchange.com/questions/15151",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16012/"
] | For instance move from (the cursor is on the letter in bold italic, in the second column)
```
b***l***ablabla
blablabla
blablabla
blablabla
bla
bla
bla
bLablabla
l@st
```
to
```
blablabla
blablabla
blablabla
b***l***ablabla
bla
bla
bla
bLablabla
l@st
```
and then to the "@". That would be "vertical ... | Interesting. Vertical analogues of word motion commands. I'm not aware of any native way to do this so my first thought is to just start with regex searches. Turns out doing such searches in one step is not trivial but still viable.
First a couple notes:
* To make it quite a bit easier I'm using (vertical) `WORD` mot... |
15,180 | <p>I want to have a vim register that pastes :</p>
<pre><code>#include <iostream>
#include <string>
#define 1e9 + 7
typedef long long ll;
using namespace std;
int main(int argc, char ** argv){
return 0;}
</code></pre>
<p>But when I write this in .vimrc ahead of</p>
<pre><code>let @a = '...
</code></pre>... | [
{
"answer_id": 15181,
"author": "Kevin",
"author_id": 16326,
"author_profile": "https://vi.stackexchange.com/users/16326",
"pm_score": 1,
"selected": false,
"text": "<p>This isn't exactly what you asked for, but I think it may be a \"better\" solution.</p>\n\n<pre><code>nnoremap cct :-1r... | 2018/02/13 | [
"https://vi.stackexchange.com/questions/15180",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16325/"
] | I want to have a vim register that pastes :
```
#include <iostream>
#include <string>
#define 1e9 + 7
typedef long long ll;
using namespace std;
int main(int argc, char ** argv){
return 0;}
```
But when I write this in .vimrc ahead of
```
let @a = '...
```
I have write it all in a single line. How do I specify t... | This isn't exactly what you asked for, but I think it may be a "better" solution.
```
nnoremap cct :-1read $HOME/.vim/cct.c<CR>6ji<Tab>
```
Typing in `c``c``t` in Normal mode will paste in the contents from
`$HOME/.vim/cct.c`, which would contain the template you want. Then, `6ji<Tab>` moves
you to inside the `main`... |
15,183 | <p>Let's say I have ordered TODO list with priorities, sorted already with <code>:sort n</code> similar to :</p>
<pre><code>1. shopping
3. cooking.
D 5. car repair.
D 11. tap fix.
12. project start
</code></pre>
<p><code>D</code> means done.</p>
<p>I am using <code>:sort n</code> function to sort this list, but all ... | [
{
"answer_id": 15181,
"author": "Kevin",
"author_id": 16326,
"author_profile": "https://vi.stackexchange.com/users/16326",
"pm_score": 1,
"selected": false,
"text": "<p>This isn't exactly what you asked for, but I think it may be a \"better\" solution.</p>\n\n<pre><code>nnoremap cct :-1r... | 2018/02/13 | [
"https://vi.stackexchange.com/questions/15183",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16328/"
] | Let's say I have ordered TODO list with priorities, sorted already with `:sort n` similar to :
```
1. shopping
3. cooking.
D 5. car repair.
D 11. tap fix.
12. project start
```
`D` means done.
I am using `:sort n` function to sort this list, but all done (`D`) things should go at the end of list. Result should be l... | This isn't exactly what you asked for, but I think it may be a "better" solution.
```
nnoremap cct :-1read $HOME/.vim/cct.c<CR>6ji<Tab>
```
Typing in `c``c``t` in Normal mode will paste in the contents from
`$HOME/.vim/cct.c`, which would contain the template you want. Then, `6ji<Tab>` moves
you to inside the `main`... |
15,191 | <p>Using the <code>backup</code> option, I'd like vim to keep the backup of a file until that file is closed, instead of overwriting the backup every time the file is saved. </p>
<p>I want Vim to do that because I often find myself wishing that I could see a file as it was at the beginning of the editing session (for ... | [
{
"answer_id": 15271,
"author": "raul.vila",
"author_id": 16411,
"author_profile": "https://vi.stackexchange.com/users/16411",
"pm_score": 1,
"selected": false,
"text": "<p>------ EDIT ------</p>\n\n<p>Sorry, I think I've mistaken the functionality of BackupDir... maybe what you need it'... | 2018/02/13 | [
"https://vi.stackexchange.com/questions/15191",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16012/"
] | Using the `backup` option, I'd like vim to keep the backup of a file until that file is closed, instead of overwriting the backup every time the file is saved.
I want Vim to do that because I often find myself wishing that I could see a file as it was at the beginning of the editing session (for files that I don't wa... | I'm pretty sure it's not possible to use Vim's `backup` feature to do this, so instead I've written a proof of concept that achieves your goal (of being able to see the changes made since the beginning of the session) more directly, with autocommands.
It writes out a file containing the current contents of the buffer ... |
15,196 | <p>In order to parse certain log file and make a plot of sequential numbers, I need to filter out the lines with numbers which appearing lower than in the previous lines.</p>
<p>For example, given the list of lines with integers:</p>
<pre><code>62
116
33
20
61
67
89
82
15
109
73
101
115
120
41
103
94
122
</code></pre... | [
{
"answer_id": 34414,
"author": "Michael",
"author_id": 37835,
"author_profile": "https://vi.stackexchange.com/users/37835",
"pm_score": 0,
"selected": false,
"text": "<p>It works (in the 'vim terminal') ...like\n<code>%left 5</code>\n<code>%</code> : whole document\n<code>left</code>: d... | 2018/02/14 | [
"https://vi.stackexchange.com/questions/15196",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | In order to parse certain log file and make a plot of sequential numbers, I need to filter out the lines with numbers which appearing lower than in the previous lines.
For example, given the list of lines with integers:
```
62
116
33
20
61
67
89
82
15
109
73
101
115
120
41
103
94
122
```
Note: File can be generated... | The option `numberwidth` changes the width of the number gutter.
E.g.
`set numberwidth=10` |
15,218 | <p>I read the solution answered in <a href="https://stackoverflow.com/questions/11037825/vim-get-out-of-parenthesis-brackets-etc">https://stackoverflow.com/questions/11037825/vim-get-out-of-parenthesis-brackets-etc</a>. That is nothing but command <code>A</code> that takes away you in the end of line. </p>
<p>But, my... | [
{
"answer_id": 15219,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 6,
"selected": true,
"text": "<p>I'm not 100% clear if this is what you're asking, but I think you might be looking for:</p>\n\n<pre><code>])\n</code></pre>\n... | 2018/02/15 | [
"https://vi.stackexchange.com/questions/15218",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9498/"
] | I read the solution answered in <https://stackoverflow.com/questions/11037825/vim-get-out-of-parenthesis-brackets-etc>. That is nothing but command `A` that takes away you in the end of line.
But, my requirement is something different. Suppose I have a file containing -
`x = (3+5)/(2+1);`
When cursor is on `+` ... | I'm not 100% clear if this is what you're asking, but I think you might be looking for:
```
])
```
This jumps to the nearest enclosing `)`. So if your cursor was on the `/` in the below:
```
(2 / (3 + 5) * 9)
^
```
It would skip past the first `)` and jump to here:
```
(2 / (3 + 5) * 9)
^
``... |
15,225 | <p>Consider an answer to <a href="https://vi.stackexchange.com/questions/613/how-do-i-install-a-plugin-in-vim-vi">How do I install a plugin in Vim/vi?</a>: </p>
<blockquote>
<pre><code>call plug#begin('~/.vim/plugged')
" For MS Windows, this is probably better:
"call plug#begin('~/vimfiles/plugged')
</code></pre>
</bl... | [
{
"answer_id": 15226,
"author": "Alexey Romanov",
"author_id": 16365,
"author_profile": "https://vi.stackexchange.com/users/16365",
"pm_score": 2,
"selected": false,
"text": "<p>An answer I found, but not sure whether it's optimal or correct in all circumstances: <code>split(&rtp, ',... | 2018/02/16 | [
"https://vi.stackexchange.com/questions/15225",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16365/"
] | Consider an answer to [How do I install a plugin in Vim/vi?](https://vi.stackexchange.com/questions/613/how-do-i-install-a-plugin-in-vim-vi):
>
>
> ```
> call plug#begin('~/.vim/plugged')
> " For MS Windows, this is probably better:
> "call plug#begin('~/vimfiles/plugged')
>
> ```
>
>
And more generally, things... | Another possible solution is to test the features of your installation:
```
if has('win32')
let $MYPLUGDIRECTORY = "~/vimfiles/plugged"
else
let $MYPLUGDIRECTORY = "~/.vim/plugged"
endif
call plug#begin($MYPLUGDIRECTORY)
```
It has the advantage to let you mess with your `rtp` setup. For example, if for wha... |
15,231 | <p>When using <code>foldmethod=marker</code>, how do you select or reference exactly the contents of the current fold? I want to swap the order of two folds. If they were paragraphs, I would do <code>dap</code> <code>{</code> <code>p</code>. However, I can't find a corresponding <code>daz</code>. I think the answer... | [
{
"answer_id": 15232,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 4,
"selected": true,
"text": "<p>There is no text object for folds in vim, but there is a plugin which provides them, <code>az</code>/<code>iz</code>: <a ... | 2018/02/16 | [
"https://vi.stackexchange.com/questions/15231",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1430/"
] | When using `foldmethod=marker`, how do you select or reference exactly the contents of the current fold? I want to swap the order of two folds. If they were paragraphs, I would do `dap` `{` `p`. However, I can't find a corresponding `daz`. I think the answer is obvious, but I sure can't find it here or on Google. Possi... | There is no text object for folds in vim, but there is a plugin which provides them, `az`/`iz`: <https://github.com/kana/vim-textobj-fold>
Here are vanilla alternatives:
* `vi{`/`va{`. This may or may not select what you want, depending on whether your markers are in comments or not.
* `[zV]z`. Alternatively you can ... |
15,237 | <p>I have the following configuration in my vimrc file.</p>
<pre><code>inoremap <C-A> <Plug>InsertComment
</code></pre>
<p>And somewhere in my vim folder I defined</p>
<pre><code>inoremap <silent> <Plug>InsertComment <ESC>:call INSERT_MY_COMMENT
</code></pre>
<p>The mapping worked real... | [
{
"answer_id": 15238,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>If you use a nore mapping to tie a sequence of keys to <code><plug>something</code>, even if there is a mappin... | 2018/02/17 | [
"https://vi.stackexchange.com/questions/15237",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16146/"
] | I have the following configuration in my vimrc file.
```
inoremap <C-A> <Plug>InsertComment
```
And somewhere in my vim folder I defined
```
inoremap <silent> <Plug>InsertComment <ESC>:call INSERT_MY_COMMENT
```
The mapping worked really well after I configured it. But somehow recently it stopped functioning. And... | If you use a nore mapping to tie a sequence of keys to `<plug>something`, even if there is a mapping behind that `<plug>something`, it'll be ignored. In the documentation, `nore` is said to prevent *recursion*. That's what is happening here.
That means that: the `<plug>something` mapping shall indeed be defined with ... |
15,241 | <p>Say I have the table:</p>
<pre><code>| TITLE |
| This is some text |
</code></pre>
<p>Can I center align the TITLE like so?</p>
<pre><code>| TITLE |
| This is some text |
</code></pre>
<p>I've tried using both EasyAlign and Tabular but without much success.</p>
| [
{
"answer_id": 15238,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>If you use a nore mapping to tie a sequence of keys to <code><plug>something</code>, even if there is a mappin... | 2018/02/17 | [
"https://vi.stackexchange.com/questions/15241",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16379/"
] | Say I have the table:
```
| TITLE |
| This is some text |
```
Can I center align the TITLE like so?
```
| TITLE |
| This is some text |
```
I've tried using both EasyAlign and Tabular but without much success. | If you use a nore mapping to tie a sequence of keys to `<plug>something`, even if there is a mapping behind that `<plug>something`, it'll be ignored. In the documentation, `nore` is said to prevent *recursion*. That's what is happening here.
That means that: the `<plug>something` mapping shall indeed be defined with ... |
15,247 | <p>I often escape insert mode only to change the current line's indent by pressing <code>>></code> or <code><<</code> and then immediately go back to writing.
I wanted to make this easier, so I included these lines on my config:</p>
<pre><code>inoremap <tab> <esc>>>a
inoremap <S-tab>... | [
{
"answer_id": 15248,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": false,
"text": "<p>This behavior is determined by the <a href=\"http://vimhelp.appspot.com/options.txt.html#'startofline'\"... | 2018/02/18 | [
"https://vi.stackexchange.com/questions/15247",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16396/"
] | I often escape insert mode only to change the current line's indent by pressing `>>` or `<<` and then immediately go back to writing.
I wanted to make this easier, so I included these lines on my config:
```
inoremap <tab> <esc>>>a
inoremap <S-tab> <esc><<a
```
But, for some reason, whenever you `<<` or `>>`, Vim mo... | This behavior is determined by the ['startofline'](http://vimhelp.appspot.com/options.txt.html#'startofline') option. Set it to off, if you don't want that. |
15,260 | <p>I am a Vim newbie with one week experience and I'm already enjoying it.</p>
<p>I've successfully written an (ugly) command+function+mapping with which I can extract some code to a new variable in JavaScript. This is my code, it works with motions (\jsexviw) and selection in visual mode:</p>
<pre><code>command! -ra... | [
{
"answer_id": 15248,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": false,
"text": "<p>This behavior is determined by the <a href=\"http://vimhelp.appspot.com/options.txt.html#'startofline'\"... | 2018/02/19 | [
"https://vi.stackexchange.com/questions/15260",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16411/"
] | I am a Vim newbie with one week experience and I'm already enjoying it.
I've successfully written an (ugly) command+function+mapping with which I can extract some code to a new variable in JavaScript. This is my code, it works with motions (\jsexviw) and selection in visual mode:
```
command! -range -nargs=1 JsExVar ... | This behavior is determined by the ['startofline'](http://vimhelp.appspot.com/options.txt.html#'startofline') option. Set it to off, if you don't want that. |
15,267 | <p>I have this mapping to surround a Word with jQuery id selector <code>$("#...")</code> and it works fine using a command:</p>
<pre><code>command! JqId normal viwo^[i#^[ysiW"ysiW)i$^[E
nnoremap <Leader>jqid :JqId<CR>
</code></pre>
<p>But I cannot make it works only with the mapping, it inserts the <code>... | [
{
"answer_id": 15268,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p><em>EDIT</em>:</p>\n\n<p>Your mapping doesn't work because you are in a rare case where you want to use <code>nmap</code>... | 2018/02/20 | [
"https://vi.stackexchange.com/questions/15267",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16411/"
] | I have this mapping to surround a Word with jQuery id selector `$("#...")` and it works fine using a command:
```
command! JqId normal viwo^[i#^[ysiW"ysiW)i$^[E
nnoremap <Leader>jqid :JqId<CR>
```
But I cannot make it works only with the mapping, it inserts the `$` sign, but the vim-surround commands do nothing:
``... | *EDIT*:
Your mapping doesn't work because you are in a rare case where you want to use `nmap` instead of `nnoremap`: You want to use in a mapping an already defined mapping. Using `nnoremap` you said to Vim "use the default behavior of `ysiW"`" instead of "use the behavior defined by a plugin"
---
If I understand yo... |
15,277 | <p>I have a substitute expression to find words beginning with a dollar signs and capture them like this:</p>
<pre><code>:%s/\$\(.*\)\>//g
</code></pre>
<p>However there are a lot of escape sequences in the regular expression (4). Is there a way to avoid so many escapes in this expression?</p>
| [
{
"answer_id": 15268,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p><em>EDIT</em>:</p>\n\n<p>Your mapping doesn't work because you are in a rare case where you want to use <code>nmap</code>... | 2018/02/20 | [
"https://vi.stackexchange.com/questions/15277",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | I have a substitute expression to find words beginning with a dollar signs and capture them like this:
```
:%s/\$\(.*\)\>//g
```
However there are a lot of escape sequences in the regular expression (4). Is there a way to avoid so many escapes in this expression? | *EDIT*:
Your mapping doesn't work because you are in a rare case where you want to use `nmap` instead of `nnoremap`: You want to use in a mapping an already defined mapping. Using `nnoremap` you said to Vim "use the default behavior of `ysiW"`" instead of "use the behavior defined by a plugin"
---
If I understand yo... |
15,299 | <p>Suppose I have the following code: </p>
<pre><code>let s:user_config=fnamemodify('user.vim', ':p')
echom 'file found: ' . s:user_config
if filereadable(s:user_config)
source s:user_config
else
echom s:user_config . 'was not found'
endif
</code></pre>
<p>If I run this, I get:</p>
<pre><code>file found: /ho... | [
{
"answer_id": 15301,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p>As it is written, your code will execute literally <code>source s:user_config</code> and you want to execute <code>source... | 2018/02/21 | [
"https://vi.stackexchange.com/questions/15299",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7010/"
] | Suppose I have the following code:
```
let s:user_config=fnamemodify('user.vim', ':p')
echom 'file found: ' . s:user_config
if filereadable(s:user_config)
source s:user_config
else
echom s:user_config . 'was not found'
endif
```
If I run this, I get:
```
file found: /home/ninrod/vim_test/user.vim
Error detec... | As it is written, your code will execute literally `source s:user_config` and you want to execute `source [content of the variable]`.
You can use `execute()` like this:
```
execute "source " . s:user_config
```
[`:h :execute`](http://vimhelp.appspot.com/eval.txt.html#%3aexecute):
```
:exe[cute] {expr1} .. Execut... |
15,306 | <p>Is there a way to operate on a specific column of data without specifying the exact column number but only the column number? For example, if I have data like this:</p>
<pre><code>abc 123 45.6 jkq
df 456 7.8 sfladf
ghij 92 98.0 adad
</code></pre>
<p>and I want to do something on the third column (whi... | [
{
"answer_id": 15309,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 1,
"selected": false,
"text": "<p>This is a very very rough sketch of how to do it:</p>\n\n<p>First construct your search pattern, that is add the... | 2018/02/21 | [
"https://vi.stackexchange.com/questions/15306",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | Is there a way to operate on a specific column of data without specifying the exact column number but only the column number? For example, if I have data like this:
```
abc 123 45.6 jkq
df 456 7.8 sfladf
ghij 92 98.0 adad
```
and I want to do something on the third column (whitespace delimited), for ex... | I think this sounds like a job for awk.
```
$ awk 'sub(/[0-9]+/, "foo", $3)' input.txt > output.txt
```
Using inside of Vim via filter, `:!`:
```
:%!awk 'sub(/[0-9]+/, "foo", $3)'
```
Note: this will effect the output whitespace. May want to adjust `OFS`. |
15,325 | <p>I would like to set <code>set spell</code> whenever I open a <code>tex</code> file.</p>
<p>My first attempt is</p>
<pre><code>autocmd FileType tex setlocal spell
</code></pre>
<p>I am using <code>setlocal</code> here because I may open other files in new tabs after opening a <code>tex</code> file and I don't want... | [
{
"answer_id": 15327,
"author": "hklel",
"author_id": 16463,
"author_profile": "https://vi.stackexchange.com/users/16463",
"pm_score": 0,
"selected": false,
"text": "<p>I've got the desired behavior using </p>\n\n<pre><code>autocmd BufReadPre *.tex setlocal spell\n</code></pre>\n"
},
... | 2018/02/23 | [
"https://vi.stackexchange.com/questions/15325",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16463/"
] | I would like to set `set spell` whenever I open a `tex` file.
My first attempt is
```
autocmd FileType tex setlocal spell
```
I am using `setlocal` here because I may open other files in new tabs after opening a `tex` file and I don't want `spell` in the new files.
This works well, but I notice that if I open anot... | Frame Challenge : Using Vim "Properly"1
=======================================
`autocmd` is *NOT* the solution to `filetype`-dependent settings. It might seem like a good candidate at first, but Vim was built after the Unix philosophy of placing files in defined directory structure to affect behavior. Most vim users ... |
15,359 | <p>Regarding this command:</p>
<pre><code>f{char} To [count]'th occurrence of {char} to the right. The
cursor is placed on {char} |inclusive|.
{char} can be entered as a digraph |digraph-arg|.
When 'encoding' is set to Unicode, co... | [
{
"answer_id": 15336,
"author": "wmmso",
"author_id": 16478,
"author_profile": "https://vi.stackexchange.com/users/16478",
"pm_score": 2,
"selected": false,
"text": "<p>this is not the expected behavior - perhaps you have something mapped in such a way that it causes this behavior.</p>\n... | 2018/02/26 | [
"https://vi.stackexchange.com/questions/15359",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7960/"
] | Regarding this command:
```
f{char} To [count]'th occurrence of {char} to the right. The
cursor is placed on {char} |inclusive|.
{char} can be entered as a digraph |digraph-arg|.
When 'encoding' is set to Unicode, composing
... | this is not the expected behavior - perhaps you have something mapped in such a way that it causes this behavior.
try starting vim using
vim -u /dev/null -U /dev/null --noplugin
then, assuming the expected behavior, you can divide and conquer in your .vimrc, .gvimrc and plugins. |
15,366 | <p>Let's say I have </p>
<pre><code>// that is just a comment
// that is just a comment
// that is just a comment
// that is just a comment
// that is just a comment
</code></pre>
<p>And I want to type * at <code>//</code> to use the command <code>cgn</code> and then typing just <code>.</code> instead of classical <c... | [
{
"answer_id": 15368,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 2,
"selected": false,
"text": "<p>The reason that this isn't working for you is that forward slash <code>/</code> (ASCII 47), isn't included in your <code>'is... | 2018/02/26 | [
"https://vi.stackexchange.com/questions/15366",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7339/"
] | Let's say I have
```
// that is just a comment
// that is just a comment
// that is just a comment
// that is just a comment
// that is just a comment
```
And I want to type \* at `//` to use the command `cgn` and then typing just `.` instead of classical `n .` getting this result:
```
/* that is just a comment
/*... | The reason that this isn't working for you is that forward slash `/` (ASCII 47), isn't included in your `'iskeyword'` setting, which in Vim defaults to `@,48-57,_,192-255`.1
You *could* fix it by adding the forward slash to your `'iskeyword'` setting but I **wouldn't recommend doing this**:
```
:setlocal iskeyword+=/... |
15,370 | <p>I am experimenting with default key mappings and am considering remapping the <code>g</code> key entirely. But first I would like to turn off all the existing mappings that <code>g</code> has. For now I am using this kind of hack:</p>
<pre><code>" disable all g maps
let g:netrw_nogx = 1 " allows disabling gx
let s:... | [
{
"answer_id": 15466,
"author": "tommcdo",
"author_id": 64,
"author_profile": "https://vi.stackexchange.com/users/64",
"pm_score": 3,
"selected": true,
"text": "<h3>Suppressing the built-in <code>g</code></h3>\n\n<p>Here's a mapping that will suppress all <code>g</code>-prefixed bindings... | 2018/02/27 | [
"https://vi.stackexchange.com/questions/15370",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/307/"
] | I am experimenting with default key mappings and am considering remapping the `g` key entirely. But first I would like to turn off all the existing mappings that `g` has. For now I am using this kind of hack:
```
" disable all g maps
let g:netrw_nogx = 1 " allows disabling gx
let s:chars1 = map(range(char2nr('a'), cha... | ### Suppressing the built-in `g`
Here's a mapping that will suppress all `g`-prefixed bindings, and only allow custom mappings that begin with `g`.
```
function! SuppressG()
let c = nr2char(getchar())
if maparg('g'.c, 'n') != ''
return 'g'.c
else
return '\<Nop>'
endif
endfunction
nnoremap <expr> g Su... |
15,377 | <p>I have a beamer(LaTeX) file containing many <code>\begin{frame}</code> lines. I want to debug the code to viewing the output of its. The pdf output shows frame number. When I try to change a specific numbered frame in source I have to give more time to find out that frame as there is no fame numbering in source code... | [
{
"answer_id": 15378,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": false,
"text": "<p>If I understand you correctly, you should be able to to it with e.g. a custom command. Something like this shoul... | 2018/02/27 | [
"https://vi.stackexchange.com/questions/15377",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9498/"
] | I have a beamer(LaTeX) file containing many `\begin{frame}` lines. I want to debug the code to viewing the output of its. The pdf output shows frame number. When I try to change a specific numbered frame in source I have to give more time to find out that frame as there is no fame numbering in source code.
So, I want ... | There is another way to proceed without needing to define an helper function.
The idea is to fill a list and to inject the list size with `:s\=`.
```
:let counter=[]
:%s/\\begin{frame}\zs\(%\d\+\)\=/\='%'.len(add(counter, 42))
```
Or as a command in a `~/.vim/ftplugin/tex/count-frames.vim` ftplugin file:
```
comma... |
15,379 | <p>The help text for <code>fileencodings</code> says this:</p>
<blockquote>
<p>This is a list of character encodings considered when starting to edit
an existing file. When a file is read, Vim tries to use the first
mentioned character encoding. If an error is detected, the next one
in the list i... | [
{
"answer_id": 15380,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 0,
"selected": false,
"text": "<p>I think this is, because Vim uses the <code>utf-8</code> encoding. it should work when manually forcing <code>en... | 2018/02/27 | [
"https://vi.stackexchange.com/questions/15379",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2982/"
] | The help text for `fileencodings` says this:
>
> This is a list of character encodings considered when starting to edit
> an existing file. When a file is read, Vim tries to use the first
> mentioned character encoding. If an error is detected, the next one
> in the list is tried. When an encoding is found that wo... | The biggest problem with your example is `[noeol]`. Note that the bytes `00 DF` do not really make a file that a text editor expects; if you add a newline to the end (`00 DF 0A`), you *definitely* won't get the `[noeol]` error, and I suspect that the file will now correctly open as latin1 (it does in my tests), and you... |
15,382 | <p>Regarding this command:</p>
<pre><code>f{char} To [count]'th occurrence of {char} to the right. The
cursor is placed on {char} |inclusive|.
{char} can be entered as a digraph |digraph-arg|.
When 'encoding' is set to Unicode, co... | [
{
"answer_id": 15870,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 2,
"selected": false,
"text": "<p>A basic version of this is actually in the reference manual as an example of how to use the <code>getchar()</code> function:... | 2018/02/27 | [
"https://vi.stackexchange.com/questions/15382",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7960/"
] | Regarding this command:
```
f{char} To [count]'th occurrence of {char} to the right. The
cursor is placed on {char} |inclusive|.
{char} can be entered as a digraph |digraph-arg|.
When 'encoding' is set to Unicode, composing
... | A basic version of this is actually in the reference manual as an example of how to use the `getchar()` function:
>
> This example redefines "f" to ignore case:
>
>
>
> ```
> :nmap f :call FindChar()<CR>
> :function FindChar()
> : let c = nr2char(getchar())
> : while col('.') < col('$') - 1
> : normal l
> : ... |
15,383 | <p>If I quit Neovim's containing terminal without exiting Vim first, then the next time I run Neovim I get the error:</p>
<pre><code>E575: Error while reading ShaDa file: mark entry at position 2957 has
Press ENTER or type command to continue
</code></pre>
<p>I want to not see this error on startup.</p>
<p>To reprod... | [
{
"answer_id": 15415,
"author": "3N4N",
"author_id": 16280,
"author_profile": "https://vi.stackexchange.com/users/16280",
"pm_score": 3,
"selected": false,
"text": "<p>Check your <code>init.vim</code>. If there is any line concerning <code>viminfo</code>, temporarily remove/comment it, y... | 2018/02/27 | [
"https://vi.stackexchange.com/questions/15383",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16515/"
] | If I quit Neovim's containing terminal without exiting Vim first, then the next time I run Neovim I get the error:
```
E575: Error while reading ShaDa file: mark entry at position 2957 has
Press ENTER or type command to continue
```
I want to not see this error on startup.
To reproduce this error run `nvim --cmd te... | Check your `init.vim`. If there is any line concerning `viminfo`, temporarily remove/comment it, you can later discover the reason it messed up.
Then backup and remove `~/.local/share/nvim/shada` folder. Then start up Neovim, the folder will be auto-generated with a file named `main.shada`. Hopefully, your error will ... |
15,388 | <p>Is there a good macro or regex expression that I can use in Vim to generate a <code>.h</code> file from a <code>.c</code> file?</p>
<p>For example, take the following <code>.c</code> file</p>
<pre><code>// temp.c
// comment 1
// comment 2
void function1(int a, int b) {
int x = 0;
if (x == 0) {
x = ... | [
{
"answer_id": 15389,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 3,
"selected": true,
"text": "<p>If it's always in that format, you could do the following regex:</p>\n\n<pre><code>:%s/\\v^\\S.*\\zs \\{$\\n(.*\\n)*\... | 2018/02/28 | [
"https://vi.stackexchange.com/questions/15388",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13078/"
] | Is there a good macro or regex expression that I can use in Vim to generate a `.h` file from a `.c` file?
For example, take the following `.c` file
```
// temp.c
// comment 1
// comment 2
void function1(int a, int b) {
int x = 0;
if (x == 0) {
x = 1;
}
else { x = 2; }
}
```
and generate the ... | If it's always in that format, you could do the following regex:
```
:%s/\v^\S.*\zs \{$\n(.*\n)*\}$/;
```
But this isn't a foolproof method because it relies on proper formatting. It's also pretty verbose and rather hard to understand. I would prefer a *global* command:
```
:g/^\S.*{$/norm $hc%;
```
This basicall... |
15,416 | <p>Recently I started using and learning Vim. I turned off movement keys in my <code>.vimrc</code> file like this:</p>
<pre><code>noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
noremap h <NOP>
noremap j <NOP>
noremap k <... | [
{
"answer_id": 15419,
"author": "3N4N",
"author_id": 16280,
"author_profile": "https://vi.stackexchange.com/users/16280",
"pm_score": 1,
"selected": false,
"text": "<p>Since you said you're learning vim, I'd point you to learn your way through <code>autocmd</code>. Take a look at <a href... | 2018/03/02 | [
"https://vi.stackexchange.com/questions/15416",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16554/"
] | Recently I started using and learning Vim. I turned off movement keys in my `.vimrc` file like this:
```
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
noremap h <NOP>
noremap j <NOP>
noremap k <NOP>
noremap l <NOP>
```
However, I'd like to use netrw file browser, but I can't navi... | My *real* answer is "don't do that", but if you insist, you could do something like:
```
noremap <expr> h &filetype ==? 'netrw' ? 'h' : ''
noremap <expr> j &filetype ==? 'netrw' ? 'j' : ''
noremap <expr> k &filetype ==? 'netrw' ? 'k' : ''
noremap <expr> l &filetype ==? 'netrw' ? 'l' : ''
```
These commands create ma... |
15,431 | <p>I know there'a probably a plugin for that, but since Neovim has a built-in terminal I wanna use it. I just want to bind a key that runs the current file in Python 3. I tried using @% and %, but the shell does not recognize these variables. I think the best way would be to export the current file path as an environme... | [
{
"answer_id": 16905,
"author": "Rohit Bhanot",
"author_id": 18373,
"author_profile": "https://vi.stackexchange.com/users/18373",
"pm_score": 2,
"selected": false,
"text": "<p>I am myself pretty new to vim in general, but I guess you can easily do this. Here is my version of it, which wi... | 2018/03/04 | [
"https://vi.stackexchange.com/questions/15431",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16290/"
] | I know there'a probably a plugin for that, but since Neovim has a built-in terminal I wanna use it. I just want to bind a key that runs the current file in Python 3. I tried using @% and %, but the shell does not recognize these variables. I think the best way would be to export the current file path as an environment ... | I am myself pretty new to vim in general, but I guess you can easily do this. Here is my version of it, which will create a horizontal split, create a terminal buffer and then run the current python file in it and then you can create a another mapping which can close the terminal buffer for you.
```
nnoremap <C-R> :sp... |
15,435 | <p>I just installed neovim. But I not sure how to auto indent bash code. I have vim configured so that it can autoindent code. My <code>~/.vimrc</code> has the following code. But it seems that they will not be loaded with neovim.</p>
<pre><code>fun BenIndent()
let oldLine=line('.')
normal gg=G
execute ':' . old... | [
{
"answer_id": 15436,
"author": "3N4N",
"author_id": 16280,
"author_profile": "https://vi.stackexchange.com/users/16280",
"pm_score": 0,
"selected": false,
"text": "<p>I think you should use the function as below:</p>\n\n<pre><code>function! BenIndent()\n let oldLine=line('.')\n normal... | 2018/03/05 | [
"https://vi.stackexchange.com/questions/15435",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16594/"
] | I just installed neovim. But I not sure how to auto indent bash code. I have vim configured so that it can autoindent code. My `~/.vimrc` has the following code. But it seems that they will not be loaded with neovim.
```
fun BenIndent()
let oldLine=line('.')
normal gg=G
execute ':' . oldLine
endfun
map -- :call ... | Neovim doesn't use the location `~/.vimrc` for its configuration file. Try moving, copying, or symlinking your file to the location:
```
~/.config/nvim/init.vim
``` |
15,444 | <p>When I press return at the end of a comment line, vim will automatically insert the comment leader on the next line as well:</p>
<pre><code>// My comment bla bla
// ‸
</code></pre>
<p>I like this feature and I would like to leave it switched on. However, quite often, I also want to write uncommented code on the ne... | [
{
"answer_id": 15446,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 1,
"selected": true,
"text": "<p>You can accomplish this with a simple mapping;</p>\n\n<pre><code>inoremap <silent><expr> <bs> getline('... | 2018/03/05 | [
"https://vi.stackexchange.com/questions/15444",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16601/"
] | When I press return at the end of a comment line, vim will automatically insert the comment leader on the next line as well:
```
// My comment bla bla
// ‸
```
I like this feature and I would like to leave it switched on. However, quite often, I also want to write uncommented code on the next line. Is there an easy ... | You can accomplish this with a simple mapping;
```
inoremap <silent><expr> <bs> getline('.') =~# '^//\s*$' ? "<c-u>" : "<bs>"
```
Note that if your `backspace` setting includes `start`, this will delete the comment regardless of whether it was automatically entered or not.
Alternatively, here is a slightly differen... |
15,447 | <p>I am relatively new to vim and have started using the <a href="https://github.com/jpalardy/vim-slime" rel="nofollow noreferrer">vim-slime</a> plugin. One thing I use it for is to run python scripts, for example</p>
<pre><code>:SlimeSend1 python ~/myPythonFile.py
</code></pre>
<p>I now would like to automate the co... | [
{
"answer_id": 15448,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 1,
"selected": false,
"text": "<p>As you found out, <code>:SlimeSend1</code> sends its arguments literally, as a single string. You could type <code>CTRL... | 2018/03/05 | [
"https://vi.stackexchange.com/questions/15447",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16602/"
] | I am relatively new to vim and have started using the [vim-slime](https://github.com/jpalardy/vim-slime) plugin. One thing I use it for is to run python scripts, for example
```
:SlimeSend1 python ~/myPythonFile.py
```
I now would like to automate the command above. More specifically, I would like to map the command... | As a general rule of thumb, you can always get around this kind of problem by using `:execute` and building the command you want to run as a string:
```
:nnoremap <F5> :execute 'SlimeSend1 python' expand('%:p')<CR>
```
See `:help :execute` for more details. |
15,471 | <p>I jot notes in a tiny split window (buffer) regularly:</p>
<pre><code><C-W>s
:enew
:res 5
... jot jot...
</code></pre>
<p>When I create a new horizontal split in the same tab, that little window resizes, as if doing <code><C-W>=</code>, which brings me to the question:</p>
<p><strong>Can I keep a spli... | [
{
"answer_id": 15473,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": false,
"text": "<p>If you read the doc for the command you use you will see <a href=\"http://vimhelp.appspot.com/windows.txt.html#CTRL-W_S\... | 2018/03/07 | [
"https://vi.stackexchange.com/questions/15471",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2777/"
] | I jot notes in a tiny split window (buffer) regularly:
```
<C-W>s
:enew
:res 5
... jot jot...
```
When I create a new horizontal split in the same tab, that little window resizes, as if doing `<C-W>=`, which brings me to the question:
**Can I keep a split from resizing?** | If you're like me, and came across this question when hoping to make a *particular* window have a fixed width (or height) *without* disabling `'equalalways'` and avoiding `Ctrl-W``=`, you should be aware of `'winfixwidth'` (or `'winfixheight'`):
```
'winfixheight' 'wfh' boolean (default off), local to window
Ke... |
15,475 | <p><a href="https://stackoverflow.com/a/3926718/766570">This</a> pattern is very useful to me to get the count of a pattern in a vim file:</p>
<pre><code>:%s/pattern//gn
</code></pre>
<p>How can I do a keymap so that I can simply invoke it + <code>pattern</code> while I'm in vim?</p>
| [
{
"answer_id": 15476,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p>You can use a mapping like this:</p>\n\n<pre><code>nnoremap S :%s///gn<LEFT><LEFT><LEFT><LEFT>\... | 2018/03/07 | [
"https://vi.stackexchange.com/questions/15475",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14510/"
] | [This](https://stackoverflow.com/a/3926718/766570) pattern is very useful to me to get the count of a pattern in a vim file:
```
:%s/pattern//gn
```
How can I do a keymap so that I can simply invoke it + `pattern` while I'm in vim? | You can use a mapping like this:
```
nnoremap S :%s///gn<LEFT><LEFT><LEFT><LEFT>
```
`<LEFT>` is the left arrow key which allows you to move your cursor in command line mode. This way you can press `S` + `pattern` and you are good to go. |
15,478 | <p>Suppose I’ve selected some text in visual mode. How do I insert a certain piece of text at the beginning of the selection and a different piece of text at the end?</p>
<p>(I’m only concerned with “normal” visual mode, not visual line mode or visual block mode.)</p>
| [
{
"answer_id": 15479,
"author": "bdesham",
"author_id": 671,
"author_profile": "https://vi.stackexchange.com/users/671",
"pm_score": 0,
"selected": false,
"text": "<p>Suppose you want to wrap the selected text with <code>[[</code> and <code>]]</code>. Make your selection and then run thi... | 2018/03/07 | [
"https://vi.stackexchange.com/questions/15478",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/671/"
] | Suppose I’ve selected some text in visual mode. How do I insert a certain piece of text at the beginning of the selection and a different piece of text at the end?
(I’m only concerned with “normal” visual mode, not visual line mode or visual block mode.) | Use `c` and `<c-r>` to replace the text and "surround" it. From visual mode:
```
c(<c-r>")
```
This will surround the text with `(` and `)`.
Alternative: If you find yourself doing many "surrounding" like operations you may want to look into the [surround.vim](https://github.com/tpope/vim-surround) or [vim-sandwich... |
15,487 | <p>I have a function in vim which will open all buffers as tabs. However after I add this function, vimdiff too opens the files to be compared as different tabs and hence doesn't show the differences. Is there a way where I can find out if its vim or vimdiff which is invoking my vimrc file?</p>
<pre><code>function! Op... | [
{
"answer_id": 15488,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 5,
"selected": true,
"text": "<p><a href=\"http://vimhelp.appspot.com/diff.txt.html#diff\" rel=\"noreferrer\"><code>:help diff</code></a> covers this:</p>\n\n... | 2018/03/08 | [
"https://vi.stackexchange.com/questions/15487",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16636/"
] | I have a function in vim which will open all buffers as tabs. However after I add this function, vimdiff too opens the files to be compared as different tabs and hence doesn't show the differences. Is there a way where I can find out if its vim or vimdiff which is invoking my vimrc file?
```
function! OpenTabs()
l... | [`:help diff`](http://vimhelp.appspot.com/diff.txt.html#diff) covers this:
>
> In your .vimrc file you could do something special when Vim was started in
> diff mode. You could use a construct like this:
>
>
>
> ```
> if &diff
> setup for diff mode
> else
> setup for non-diff mode
> endif
>
... |
15,490 | <p>I see this guard clause at the top of a lot of plugins,</p>
<pre><code>if exists("g:loaded_thisplugin") || v:version < 700 || &cp
finish
endif
let g:loaded_thisplugin = 1
</code></pre>
<p>Is there something specific about versions of Vim prior to 7.0 that motivates this version check?</p>
| [
{
"answer_id": 15491,
"author": "Ankit Jain",
"author_id": 16636,
"author_profile": "https://vi.stackexchange.com/users/16636",
"pm_score": 1,
"selected": false,
"text": "<p>Not all plugins have this condition. This is added if the plugin uses a feature that didn’t exist before version 7... | 2018/03/08 | [
"https://vi.stackexchange.com/questions/15490",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1855/"
] | I see this guard clause at the top of a lot of plugins,
```
if exists("g:loaded_thisplugin") || v:version < 700 || &cp
finish
endif
let g:loaded_thisplugin = 1
```
Is there something specific about versions of Vim prior to 7.0 that motivates this version check? | `v:version` specifies your current version of Vim. Version 7.0 has version 700, 7.2 has version 702, etc.
Now, version 7 was a very major release with many enhancements to the previous release 6, that introduced man scripting enhancements. For example I believe prior to that version dictionaries, Funcrefs and lists w... |
15,525 | <p>I'm completely new to Vim scripting, so forgive me if this may seem trivial, but I would like to modify the Behavior of the Home and End keys such that, if the cursor is somewhere between the first and last non-blank character of the line, they would take me to the first or last non-blank character, respectively. Ho... | [
{
"answer_id": 15530,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p><em>That's odd, I was quite sure this question was a duplicate, but I cannot find the other Q/A.</em></p>\n\n<p>Anyw... | 2018/03/12 | [
"https://vi.stackexchange.com/questions/15525",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16675/"
] | I'm completely new to Vim scripting, so forgive me if this may seem trivial, but I would like to modify the Behavior of the Home and End keys such that, if the cursor is somewhere between the first and last non-blank character of the line, they would take me to the first or last non-blank character, respectively. Howev... | Thanks everybody for their pointers. Here is my solution, in case it's helpful to someone:
```
" Enhanced Home and End keys
inoremap <silent> <Home> <c-o>@=<SID>ExtHome()<cr>i
nnoremap <silent> <Home> @=<SID>ExtHome()<cr>
vnoremap <silent> <Home> @=<SID>ExtHome()<cr>
... |
15,535 | <pre><code>NVIM v0.2.2
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes... | [
{
"answer_id": 15556,
"author": "quanta",
"author_id": 16690,
"author_profile": "https://vi.stackexchange.com/users/16690",
"pm_score": 2,
"selected": false,
"text": "<p>From version 0.2.1, <code>:terminal</code> now starts in normal mode instead of terminal mode: <a href=\"https://githu... | 2018/03/13 | [
"https://vi.stackexchange.com/questions/15535",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16690/"
] | ```
NVIM v0.2.2
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=g... | From version 0.2.1, `:terminal` now starts in normal mode instead of terminal mode: <https://github.com/neovim/neovim/wiki/Following-HEAD#20170821>
Btw, don't know why this does not enter Terminal mode automatically:
```
autocmd BufEnter term://* startinsert
autocmd BufLeave term://* stopinsert
```
I have to use:
... |
15,536 | <p>I know that I can print whole path by <kbd>Ctrl</kbd><kbd>r</kbd> <kbd>=</kbd> <code>expand('%:p')</code> in insert mode. I can also print head/tail with <code>expand('%:h')</code>, <code>expand('%:t')</code>. </p>
<p>I want to print the filename with it's parent directory. Like if the full path was
<code>/home/to... | [
{
"answer_id": 15537,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 1,
"selected": false,
"text": "<p>You can have a look at <a href=\"http://vimhelp.appspot.com/cmdline.txt.html#filename-modifiers\" rel=\"nofollow norefer... | 2018/03/13 | [
"https://vi.stackexchange.com/questions/15536",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13695/"
] | I know that I can print whole path by `Ctrl``r` `=` `expand('%:p')` in insert mode. I can also print head/tail with `expand('%:h')`, `expand('%:t')`.
I want to print the filename with it's parent directory. Like if the full path was
`/home/torsho/maalamaal/src/maalamaal/urls.py` it would insert `maalamaal/urls.py` | You can use multiple modifiers in a single call to expand, so you can find the parent directory by asking for the tail of the head.
Therefore, you can use:
```
expand('%:h:t') . '/' . expand('%:t')
```
If you need to do this frequently, you could perhaps use a mapping so you don't have to type it in all the time:
... |
15,538 | <p>Neovim assigns a file type of "conf" to SConscruct and SConscript files -- aka the scons configuration scripts. This is wrong. It should be Python.</p>
<p>I tried adding: <code>au BufNewFile,BufRead SCons* setf python</code> to my <code>~/.config/nvim/init.vim</code> yet the file type remains set at "conf".</p>
<p... | [
{
"answer_id": 15544,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": true,
"text": "<p>There are a couple of problems here.</p>\n\n<p>Firstly, you are using the <code>:setfiletype</code> command, which only sets ... | 2018/03/13 | [
"https://vi.stackexchange.com/questions/15538",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/622/"
] | Neovim assigns a file type of "conf" to SConscruct and SConscript files -- aka the scons configuration scripts. This is wrong. It should be Python.
I tried adding: `au BufNewFile,BufRead SCons* setf python` to my `~/.config/nvim/init.vim` yet the file type remains set at "conf".
I did try it on vim and it worked fine... | There are a couple of problems here.
Firstly, you are using the `:setfiletype` command, which only sets the `'filetype'` if it has not already been set. (See [`:help :setfiletype`](http://vimhelp.appspot.com/options.txt.html#%3Asetfiletype).)
If you change your autocommand to set the `'filetype'` directly with `:set ... |
15,565 | <p>I hope someone can riddle me this one: I have set up the function below to have a slightly more fancy behavior of the End key, moving first to the end of the line, but if the cursor is already at the end of the line, moving to the end of the next line. This works just fine:</p>
<pre><code>inoremap <silent> &l... | [
{
"answer_id": 15566,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 3,
"selected": true,
"text": "<p>You do save and restore the cursor position. However note, that when moving to the first non-blank character <cod... | 2018/03/14 | [
"https://vi.stackexchange.com/questions/15565",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16675/"
] | I hope someone can riddle me this one: I have set up the function below to have a slightly more fancy behavior of the End key, moving first to the end of the line, but if the cursor is already at the end of the line, moving to the end of the next line. This works just fine:
```
inoremap <silent> <End> <c-\><c-n>@=<SID... | You do save and restore the cursor position. However note, that when moving to the first non-blank character `^`, you also set the desired column for the cursor (called curswant attribute). That one is not reset on your `setpos()` call. Therefore, when your function returns `j` to move down a line, it will move down **... |
15,578 | <p>I know how to create normal and command mappings, but I am trying to make a command that toggles between two states, (a) create 3 mappings and (b) reset them using unmap. How can I do this in my vimrc config?</p>
| [
{
"answer_id": 15579,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 3,
"selected": true,
"text": "<p>You can use this:</p>\n\n<pre><code>let s:mappingsState=1\n\ncommand! TM call ToggleMappings()\n\nfunction! ToggleMapping... | 2018/03/15 | [
"https://vi.stackexchange.com/questions/15578",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16379/"
] | I know how to create normal and command mappings, but I am trying to make a command that toggles between two states, (a) create 3 mappings and (b) reset them using unmap. How can I do this in my vimrc config? | You can use this:
```
let s:mappingsState=1
command! TM call ToggleMappings()
function! ToggleMappings()
if s:mappingsState
nnoremap <F1> :echo "mapping 1"<CR>
" Or any mapping you want to create
else
unmap <F1>
" Or any key you want to unmap
endif
let s:mappingsState... |
15,587 | <p>Suppose that I have marks <code>'a</code> and <code>'b</code>, and I want to search for all occurrences of <code>foo</code> between them.</p>
<p>The <code>ex</code> command</p>
<pre><code>:'a,'bs/foo/bar
</code></pre>
<p>will <em>replace</em> only between <code>'a</code> and <code>'b</code>. Is there any command... | [
{
"answer_id": 15588,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 4,
"selected": true,
"text": "<p>You can use <code>\\%>'m</code> and <code>\\%<'m</code> to match after and before a given mark, <code>m</code>... | 2018/03/15 | [
"https://vi.stackexchange.com/questions/15587",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2108/"
] | Suppose that I have marks `'a` and `'b`, and I want to search for all occurrences of `foo` between them.
The `ex` command
```
:'a,'bs/foo/bar
```
will *replace* only between `'a` and `'b`. Is there any command like
```
:'a,'b/foo
```
that will *find* `foo` only between those two marks? (That exact syntax does *s... | You can use `\%>'m` and `\%<'m` to match after and before a given mark, `m`.
```
/\%>'afoo\%<'b
```
For more helps see:
```
:h /\%'m
``` |
15,638 | <p>Suppose I have this (where my insertion point is designated "|"):</p>
<pre>
col1 col2
thing oeueaoue|
another
something
test</pre>
<p>What keystroke(s) would I use so the insertion point jumps to here:</p>
<pre>
col1 col2
thing oeueaoue
another |
something
test</pre>... | [
{
"answer_id": 15640,
"author": "Geremia",
"author_id": 5224,
"author_profile": "https://vi.stackexchange.com/users/5224",
"pm_score": 1,
"selected": true,
"text": "<p>from <a href=\"https://stackoverflow.com/a/49431508/1429450\">here</a>:</p>\n\n<blockquote>\n <p>When there are many li... | 2018/03/22 | [
"https://vi.stackexchange.com/questions/15638",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5224/"
] | Suppose I have this (where my insertion point is designated "|"):
```
col1 col2
thing oeueaoue|
another
something
test
```
What keystroke(s) would I use so the insertion point jumps to here:
```
col1 col2
thing oeueaoue
another |
something
test
```
?
Is `return`+`A`... | from [here](https://stackoverflow.com/a/49431508/1429450):
>
> When there are many lines to edit, it can be useful to map the return
> key temporarily, something like that in your case:
>
>
>
> ```
> inoremap <buffer> <cr> <esc>jA<tab>
>
> ```
>
> When you're done, just cancel the map:
>
>
>
> ```
> iunmap <... |
15,639 | <p>When you want to leave insert mode, it's possible to avoid to trigger the <code>InsertLeave</code> event by
pressing <kbd>Ctrl-C</kbd> instead of <kbd>Esc</kbd>.</p>
<p>But when I try to use this method inside an insert mapping, it still triggers the event.</p>
<p>For example, in a new buffer, let's run:</p>
<pr... | [
{
"answer_id": 15640,
"author": "Geremia",
"author_id": 5224,
"author_profile": "https://vi.stackexchange.com/users/5224",
"pm_score": 1,
"selected": true,
"text": "<p>from <a href=\"https://stackoverflow.com/a/49431508/1429450\">here</a>:</p>\n\n<blockquote>\n <p>When there are many li... | 2018/03/22 | [
"https://vi.stackexchange.com/questions/15639",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5516/"
] | When you want to leave insert mode, it's possible to avoid to trigger the `InsertLeave` event by
pressing `Ctrl-C` instead of `Esc`.
But when I try to use this method inside an insert mapping, it still triggers the event.
For example, in a new buffer, let's run:
```
:au InsertLeave <buffer> call append('$', 'Insert... | from [here](https://stackoverflow.com/a/49431508/1429450):
>
> When there are many lines to edit, it can be useful to map the return
> key temporarily, something like that in your case:
>
>
>
> ```
> inoremap <buffer> <cr> <esc>jA<tab>
>
> ```
>
> When you're done, just cancel the map:
>
>
>
> ```
> iunmap <... |
15,652 | <p>Maybe it was discussed many times (I strongly believe), but I could not formulate my question properly. So lets imagine we have this sequence of words:</p>
<pre><code>foo bar baz
</code></pre>
<p>Applying <code>3e</code> will move us onto:</p>
<pre><code>foo bar ba|z
</code></pre>
<p>where pipe character is the ... | [
{
"answer_id": 15653,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 1,
"selected": false,
"text": "<p>The result is not to put the cursor between the <code>a</code> and <code>z</code> (as the pipe character seems to ill... | 2018/03/24 | [
"https://vi.stackexchange.com/questions/15652",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12349/"
] | Maybe it was discussed many times (I strongly believe), but I could not formulate my question properly. So lets imagine we have this sequence of words:
```
foo bar baz
```
Applying `3e` will move us onto:
```
foo bar ba|z
```
where pipe character is the position of the cursor, but why? As far as I can read the do... | *This is assuming that your setup is using the ordinary `e`. If this doesn't answer your question, check if `e` is mapped to anything with `:nmap e`*
---
This comes from a fundamental misunderstanding of where vim's cursor is situated. In insert mode, vim functions like a traditional editor, and the cursor goes ***be... |
15,663 | <p>I have a <code>file.c</code> containing </p>
<pre class="lang-c prettyprint-override"><code>#inlcude<stdio.h>
int main()
{
printf("Hello world\n");
}
</code></pre>
<p>I can copy the main function using <code>:3,6y</code>. But, when the function is big enough then in order to know in which line the fun... | [
{
"answer_id": 15665,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 2,
"selected": false,
"text": "<p>Here is one option:</p>\n\n<pre><code>:/int main(/;/^}/y\n</code></pre>\n\n<p>This searches for <code>int main(</code>, ... | 2018/03/25 | [
"https://vi.stackexchange.com/questions/15663",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9498/"
] | I have a `file.c` containing
```c
#inlcude<stdio.h>
int main()
{
printf("Hello world\n");
}
```
I can copy the main function using `:3,6y`. But, when the function is big enough then in order to know in which line the function ends I need to scroll.
>
> Is it possible to copy entire function using something ... | Yet another way is to use the `%` motion, after placing the cursor on the second line in your example (`/main`), I would use:
```
Vj%y
```
* `V`: enable visual-line selection
* `j`: go down to the opening curly brace
* `%`: find the next matching item
* `y`: copy the selected text
Visual selection may not even be n... |
15,670 | <p>I have installed tern_for_vim and setted complete in .vimrc.</p>
<pre><code>autocmd FileType javascript setlocal omnifunc=tern#Complete
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
</code></pre>
<p>Now i can call javascript complete when editing html file via ctrl+x and ctrl+o.<br>
The php completio... | [
{
"answer_id": 15672,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": true,
"text": "<p>Here's some rough code to start you off. Create the file <code>.vim/after/ftplugin/html.vim</code> and add the\nfollowing cod... | 2018/03/26 | [
"https://vi.stackexchange.com/questions/15670",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5181/"
] | I have installed tern\_for\_vim and setted complete in .vimrc.
```
autocmd FileType javascript setlocal omnifunc=tern#Complete
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
```
Now i can call javascript complete when editing html file via ctrl+x and ctrl+o.
The php completion can pop up when editing a... | Here's some rough code to start you off. Create the file `.vim/after/ftplugin/html.vim` and add the
following code:
```
setlocal omnifunc=MyHTMLComplete
function! MyHTMLComplete(findstart, base)
if search('<?php', 'bnW') > search('<script>', 'bnW')
return phpcomplete#CompletePHP(a:findstart, a:base)
... |
15,709 | <p>I'm often editing code where others didn't care about trailing white-spaces. I'm using the <a href="https://vi.stackexchange.com/a/456/1542">TrimWhiteSpace()-function from this answer</a> to remove white-spaces when saving the file.</p>
<p>However that leaves me with changes all other the file and VCS gives me many... | [
{
"answer_id": 15711,
"author": "Rich Churcher",
"author_id": 463,
"author_profile": "https://vi.stackexchange.com/users/463",
"pm_score": 2,
"selected": false,
"text": "<p>I think someone is probably going to shoot me for this monstrosity. However:</p>\n\n<pre><code>inoremap <CR> ... | 2018/03/28 | [
"https://vi.stackexchange.com/questions/15709",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1542/"
] | I'm often editing code where others didn't care about trailing white-spaces. I'm using the [TrimWhiteSpace()-function from this answer](https://vi.stackexchange.com/a/456/1542) to remove white-spaces when saving the file.
However that leaves me with changes all other the file and VCS gives me many unrelated changes to... | I'd do it with an autocommand that fires whenever you leave insert mode:
```
function! PreciseTrimWhiteSpace()
" We need to save the view because the substitute command might
" or might not move the cursor, depending on whether it finds
" any whitespace.
let saved_view = winsaveview()
" Remove white space. ... |
15,710 | <pre><code>vim command.txt
key="123456"
openssl enc -des3 -a -salt -in /tmp/test -k ${key} -out /tmp/test.asc
</code></pre>
<p>In vim's command mode <code>:1,2!bash</code>,the file <code>/tmp/test</code> was encrypted into <code>/tmp/test.asc</code> ,but all the lines in command.txt dispear,where is my lines in the ... | [
{
"answer_id": 15730,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 2,
"selected": false,
"text": "<p>Vim is removing the lines because you are instructing it to do so.</p>\n\n<p>The feature you're invoking with your command i... | 2018/03/28 | [
"https://vi.stackexchange.com/questions/15710",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5181/"
] | ```
vim command.txt
key="123456"
openssl enc -des3 -a -salt -in /tmp/test -k ${key} -out /tmp/test.asc
```
In vim's command mode `:1,2!bash`,the file `/tmp/test` was encrypted into `/tmp/test.asc` ,but all the lines in command.txt dispear,where is my lines in the edited file `command.txt`?
[![Why all lines dispea... | ```
:1,2 !bash
```
the line in edited file lost after executing bash command
```
:1,2 w !bash
```
the line in edited file remained after executing bash command |
15,724 | <p>It used to work by adding following line into a file even it has no suffix <code>.vim</code>, my vim version is <code>v8.0.1500</code>, on <code>OS X 10.13.3</code></p>
<pre><code>" vim:ft=vim
</code></pre>
<p><strong>UPDATE:</strong></p>
<p>I tried adding following two lines to <strong>$MYVIMRC</strong>, after <... | [
{
"answer_id": 15725,
"author": "Naumann",
"author_id": 11477,
"author_profile": "https://vi.stackexchange.com/users/11477",
"pm_score": 1,
"selected": false,
"text": "<p>You need to have <code>:set modeline</code> (e.g. in your <code>~/.vimrc</code>).</p>\n"
},
{
"answer_id": 15... | 2018/03/29 | [
"https://vi.stackexchange.com/questions/15724",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7971/"
] | It used to work by adding following line into a file even it has no suffix `.vim`, my vim version is `v8.0.1500`, on `OS X 10.13.3`
```
" vim:ft=vim
```
**UPDATE:**
I tried adding following two lines to **$MYVIMRC**, after `filetype plugin indent on`
```
set modeline
set modelines=5
```
And changed
```
" vim:f... | As Naumann pointed out, `modeline` has to be set on. This is the default if you're not root.
Your modeline also has to be within `modelines` (default 5) lines from the top or bottom of the file in order to be detected.
You should also test that the settings work when you set them manually. You might be missing a depe... |
15,739 | <p>When I'm using <code>vim</code> in a terminal, it uses the <code>PATH</code> I have set, and I can run programs and scripts located in my <code>~/bin</code> folder using <code>!</code></p>
<p>For example</p>
<pre><code>:! some_bash_script.sh
</code></pre>
<p>When I try this in MacVim, it doesnt find my personal s... | [
{
"answer_id": 15725,
"author": "Naumann",
"author_id": 11477,
"author_profile": "https://vi.stackexchange.com/users/11477",
"pm_score": 1,
"selected": false,
"text": "<p>You need to have <code>:set modeline</code> (e.g. in your <code>~/.vimrc</code>).</p>\n"
},
{
"answer_id": 15... | 2018/03/29 | [
"https://vi.stackexchange.com/questions/15739",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9850/"
] | When I'm using `vim` in a terminal, it uses the `PATH` I have set, and I can run programs and scripts located in my `~/bin` folder using `!`
For example
```
:! some_bash_script.sh
```
When I try this in MacVim, it doesnt find my personal shell scripts. How can I fix this?
I've set my shell in my `~/.vimrc` like so... | As Naumann pointed out, `modeline` has to be set on. This is the default if you're not root.
Your modeline also has to be within `modelines` (default 5) lines from the top or bottom of the file in order to be detected.
You should also test that the settings work when you set them manually. You might be missing a depe... |
15,743 | <p>If i press a bunch of key sequences like this:</p>
<pre><code>/term<cr>
</code></pre>
<p>and there are five matches on the screen currently, i will have to press <code>n</code> five times to see the next search result that is not on the screen. Is there a single key (or two) that I can press to emulate press... | [
{
"answer_id": 15744,
"author": "Wang Shidong",
"author_id": 7942,
"author_profile": "https://vi.stackexchange.com/users/7942",
"pm_score": 0,
"selected": false,
"text": "<p>n/N support counts, You can use 5n. I recommend to read <code>:h n</code>.</p>\n"
},
{
"answer_id": 15749,... | 2018/03/29 | [
"https://vi.stackexchange.com/questions/15743",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11136/"
] | If i press a bunch of key sequences like this:
```
/term<cr>
```
and there are five matches on the screen currently, i will have to press `n` five times to see the next search result that is not on the screen. Is there a single key (or two) that I can press to emulate pressing `n` five times in the situation? | `Ctrl`+`F` `n`
Scroll one page forward (downward) in the buffer, then find next match.
It's not the most elegant solution, but it *is* simple, and it doesn't require you to think of the appropriate count for your `n` motion.
You can also go the other way with `Ctrl`+`B` `N`.
Since you asked for a single key, you ca... |
15,750 | <p>I have following line in my vimrc-</p>
<pre><code>autocmd BufRead,BufNewFile *.COB,*.PCO set filetype=cobol "force filetype as cobol for .COB and .PCO files
</code></pre>
<p>And I have put below lines in my custom plugin at the beginning (~/.vim/plugin/cobmods.vim)</p>
<pre><code>if &ft != "cobol"
finish
... | [
{
"answer_id": 15751,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": true,
"text": "<p>Files in <code>plugin</code> run during Vim startup (regardless of the file you're opening), before setting the file type.</p... | 2018/03/30 | [
"https://vi.stackexchange.com/questions/15750",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16636/"
] | I have following line in my vimrc-
```
autocmd BufRead,BufNewFile *.COB,*.PCO set filetype=cobol "force filetype as cobol for .COB and .PCO files
```
And I have put below lines in my custom plugin at the beginning (~/.vim/plugin/cobmods.vim)
```
if &ft != "cobol"
finish
endif
```
I don't want the plugin to loa... | Files in `plugin` run during Vim startup (regardless of the file you're opening), before setting the file type.
Remove your check of the filetype option and move the file to:
```
~/.vim/ftplugin/cobol.vim
```
I'd also recommend reading the contents of `:help ftplugin`, (in particular the part about setting `b:did_f... |
15,753 | <p>I like to use external configuration for most of my dot files in my home directory. Simple example, here is my .bash_aliases file:</p>
<pre><code>. /path/to/external/alias-config.conf
</code></pre>
<p>where the external file contains my aliases. Same idea with my .vimrc:</p>
<pre><code>. /path/to/external/vim-con... | [
{
"answer_id": 15754,
"author": "Sven",
"author_id": 16968,
"author_profile": "https://vi.stackexchange.com/users/16968",
"pm_score": 4,
"selected": true,
"text": "<p>It's quite simple: <code>bash</code> has a different configuration file syntax than <code>vim</code> and what works for o... | 2018/03/30 | [
"https://vi.stackexchange.com/questions/15753",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16978/"
] | I like to use external configuration for most of my dot files in my home directory. Simple example, here is my .bash\_aliases file:
```
. /path/to/external/alias-config.conf
```
where the external file contains my aliases. Same idea with my .vimrc:
```
. /path/to/external/vim-config.conf
```
But when I open vim I... | It's quite simple: `bash` has a different configuration file syntax than `vim` and what works for one program doesn't necessarily work for another.
So, `bash` can use `. file` and `source file` but `vim` doesn't understand the `. file` syntax.
Also, being Posix compliant matters for the shell, not for the config fi... |
15,757 | <p>Like doing <code>>></code>
but 5 times <code>>>>>>>>>>>>></code>.</p>
<p>I am not trying to indent multiple lines.</p>
| [
{
"answer_id": 15758,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 4,
"selected": true,
"text": "<p>You can use <code>:></code>. Repeat <code>></code> as many times as you want to shift. For example, if you wan... | 2018/03/30 | [
"https://vi.stackexchange.com/questions/15757",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13695/"
] | Like doing `>>`
but 5 times `>>>>>>>>>>>>`.
I am not trying to indent multiple lines. | You can use `:>`. Repeat `>` as many times as you want to shift. For example, if you want to shift 5 times use `:>>>>>`.
Personally, I would just use `>>` and then repeat the command with the `.` (repeat) command.
For more help see:
```
:h :>
:h >>
:h .
``` |
15,760 | <p>I am trying to get the mouse selected text in a register in normal mode. If the selection is a substring, only the selection should be copied, not the complete word.</p>
<p>Currently the script has:</p>
<p><code>normal! "zyiw</code></p>
<p>I would use the script on remote servers without X too. vim is compiled wi... | [
{
"answer_id": 15761,
"author": "wmmso",
"author_id": 16478,
"author_profile": "https://vi.stackexchange.com/users/16478",
"pm_score": 1,
"selected": false,
"text": "<p>Selection of text via the mouse (in a plain vanilla vim, no vimrc, no plugins, etc) places the selection in the \"* reg... | 2018/03/30 | [
"https://vi.stackexchange.com/questions/15760",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16969/"
] | I am trying to get the mouse selected text in a register in normal mode. If the selection is a substring, only the selection should be copied, not the complete word.
Currently the script has:
`normal! "zyiw`
I would use the script on remote servers without X too. vim is compiled without clipboard.
Any help is much ... | Selection of text via the mouse (in a plain vanilla vim, no vimrc, no plugins, etc) places the selection in the "\* register.
A subsequent assignment,
```
:let @f = @*
```
will place the text into the f register. A mapping such as
```
:map ^va :let @f = @*^v^M
```
will copy the "\* register to the \*f register ... |
15,764 | <p>For example, suppose I have this line of JavaScript:</p>
<pre><code>console.log(
"This is a really long line that I want to format, and it is inside of a quote"
)
</code></pre>
<p>I'd like to select the quote line in VISUAL-LINE mode, the pres <code>gq</code> to format it, but it doesn't work. The result is som... | [
{
"answer_id": 15901,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 1,
"selected": false,
"text": "<p>For what it is worth: <a href=\"http://vimhelp.appspot.com/change.txt.html#gq\" rel=\"nofollow noreferrer\"><code>:h gq<... | 2018/03/31 | [
"https://vi.stackexchange.com/questions/15764",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5626/"
] | For example, suppose I have this line of JavaScript:
```
console.log(
"This is a really long line that I want to format, and it is inside of a quote"
)
```
I'd like to select the quote line in VISUAL-LINE mode, the pres `gq` to format it, but it doesn't work. The result is something like this:
```
console.log(
... | For what it is worth: [`:h gq`](http://vimhelp.appspot.com/change.txt.html#gq) explains that you have 3 ways to format your code with `gq`
>
>
> ```
> 1. If 'formatexpr' is not empty the expression is
> evaluated. This can differ for each buffer.
> 2. If 'formatprg' is not empty an external program
> is used.
... |
15,775 | <p>The other day I was using one of my non-interactive scripts to set up my dot files for my home directory, including my .vimrc file. This is what I had the script put into my .vimrc file:</p>
<pre><code>. /etc/external/config.conf
</code></pre>
<p>This was before I knew vim can interpret 'source' but not '.' when s... | [
{
"answer_id": 15901,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 1,
"selected": false,
"text": "<p>For what it is worth: <a href=\"http://vimhelp.appspot.com/change.txt.html#gq\" rel=\"nofollow noreferrer\"><code>:h gq<... | 2018/03/31 | [
"https://vi.stackexchange.com/questions/15775",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16978/"
] | The other day I was using one of my non-interactive scripts to set up my dot files for my home directory, including my .vimrc file. This is what I had the script put into my .vimrc file:
```
. /etc/external/config.conf
```
This was before I knew vim can interpret 'source' but not '.' when sourcing external configura... | For what it is worth: [`:h gq`](http://vimhelp.appspot.com/change.txt.html#gq) explains that you have 3 ways to format your code with `gq`
>
>
> ```
> 1. If 'formatexpr' is not empty the expression is
> evaluated. This can differ for each buffer.
> 2. If 'formatprg' is not empty an external program
> is used.
... |
15,777 | <p>I am trying to create an Emacs like <code>Ctrl-l</code> feature, similar to Vim's H, M and L. For those who don't now, these keys jump to top, middle, and bottom of the window. I already have something but I am missing the "if" part.</p>
<pre><code>function! ToggleHML()
let l:winheight = winheight('%')
let ... | [
{
"answer_id": 15783,
"author": "DJMcMayhem",
"author_id": 2920,
"author_profile": "https://vi.stackexchange.com/users/2920",
"pm_score": 2,
"selected": false,
"text": "<p>This should do what you're looking for:</p>\n\n<pre><code>function! ToggleHML()\n if winline() < winheight('%'... | 2018/03/31 | [
"https://vi.stackexchange.com/questions/15777",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7339/"
] | I am trying to create an Emacs like `Ctrl-l` feature, similar to Vim's H, M and L. For those who don't now, these keys jump to top, middle, and bottom of the window. I already have something but I am missing the "if" part.
```
function! ToggleHML()
let l:winheight = winheight('%')
let l:top = 1
let l:middl... | This should do what you're looking for:
```
function! ToggleHML()
if winline() < winheight('%') / 2
normal M
elseif winline() < winheight('%')
normal L
else
normal H
endif
endfunction
```
I removed the variables, since they aren't really necessary. This will always jump down unless ... |
15,812 | <p>For debian9, the setting in .vimrc take effect for gvim.</p>
<pre><code>set guifont=Bitstream\ Vera\ Sans\ Mono\ 14
</code></pre>
<p>For win7,the setting in _vimrc take no effect for gvim at all.<br>
I open gvim in my win7,</p>
<pre><code>:set guifont?
</code></pre>
<p>The result is <code>Bitstream Vera Sans Mon... | [
{
"answer_id": 15813,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": true,
"text": "<p>See: <code>:help guifont</code>:</p>\n\n<blockquote>\n <p>[...]</p>\n \n <p>The font name depends on the GUI used.</p>\n ... | 2018/04/04 | [
"https://vi.stackexchange.com/questions/15812",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5181/"
] | For debian9, the setting in .vimrc take effect for gvim.
```
set guifont=Bitstream\ Vera\ Sans\ Mono\ 14
```
For win7,the setting in \_vimrc take no effect for gvim at all.
I open gvim in my win7,
```
:set guifont?
```
The result is `Bitstream Vera Sans Mono`,but i find that the character inputed in my gvim in... | See: `:help guifont`:
>
> [...]
>
>
> The font name depends on the GUI used.
>
>
> [...]
>
>
> For the Win32 GUI
>
>
> * takes these options in the font name:>
>
>
> + hXX - height is XX (points, can be floating-point)
> + wXX - width is XX (points, can be floating-point)
> + b - bold
> + i - italic
> ... |
15,819 | <p><strong>My question is if there is a possible way to hide everything except all text except the current line?</strong></p>
<hr>
<p>Some background:
I have a really big JSON file which I just did a macro on and am doing a quick eyeball to see that everything looks alright.</p>
<p>What I'm currently doing is search... | [
{
"answer_id": 15821,
"author": "Ankit Jain",
"author_id": 16636,
"author_profile": "https://vi.stackexchange.com/users/16636",
"pm_score": 0,
"selected": false,
"text": "<p>You could use \"vimgrep\" to get all the results in a quickfix window and jump to the results you want to.</p>\n\n... | 2018/04/05 | [
"https://vi.stackexchange.com/questions/15819",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/17045/"
] | **My question is if there is a possible way to hide everything except all text except the current line?**
---
Some background:
I have a really big JSON file which I just did a macro on and am doing a quick eyeball to see that everything looks alright.
What I'm currently doing is searching for a specific keyword and ... | I think you can use 'Conceal' feature.
For example,
```
:match Conceal /^.*$/
:set conceallevel=3
```
All the lines except current one will be concealed.
If you do not like the 'Conceal' color,
```
:highlight Conceal NONE
```
When you finish, just do
```
:match
``` |
15,873 | <p>When splitting the editor window, the caret symbols appear in the status line of the current window.</p>
<p><a href="https://i.stack.imgur.com/zCtC7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zCtC7.png" alt="carets in status line"></a></p>
<p>This happens when <code>StatusLine</code> and <c... | [
{
"answer_id": 15894,
"author": "Shamaoke",
"author_id": 12857,
"author_profile": "https://vi.stackexchange.com/users/12857",
"pm_score": 4,
"selected": true,
"text": "<p>This is the standard behaviour of Vim. If <code>StatusLine</code> and <code>StatusLineNC</code> have the same highlig... | 2018/04/09 | [
"https://vi.stackexchange.com/questions/15873",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12857/"
] | When splitting the editor window, the caret symbols appear in the status line of the current window.
[](https://i.stack.imgur.com/zCtC7.png)
This happens when `StatusLine` and `StatusLineNC` have the same highlighting. For example, when
`cterm=none ctermfg=... | This is the standard behaviour of Vim. If `StatusLine` and `StatusLineNC` have the same highlighting, the program will use the caret character (`^`) in the status line of the current window (in order to highlight it).
This behaviour cannot be changed. The only thing that can be done is to change the caret to something... |
15,918 | <p>I use <a href="https://github.com/ivanbrennan/zoo" rel="nofollow noreferrer">something</a> like <a href="https://github.com/troydm/zoomwintab.vim" rel="nofollow noreferrer">zoomwintab</a> to zoom in/out of a single window view, using tabs to simulate the effect.</p>
<p>It exposes a toggle function to zoom in on a s... | [
{
"answer_id": 15934,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 2,
"selected": false,
"text": "<p>You can retrieve the window number (as opposed to the window ID) and then use <code>wincmd</code> to close:</p>\n\n<pre>... | 2018/04/14 | [
"https://vi.stackexchange.com/questions/15918",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1855/"
] | I use [something](https://github.com/ivanbrennan/zoo) like [zoomwintab](https://github.com/troydm/zoomwintab.vim) to zoom in/out of a single window view, using tabs to simulate the effect.
It exposes a toggle function to zoom in on a single window, and to zoom back out to the orginal layout.
If I'm zoomed in and I `q... | You can retrieve the window number (as opposed to the window ID) and then use `wincmd` to close:
```
let winnr = win_id2win(og)
if winnr > 0
execute winnr.'wincmd c'
endif
```
Keep in mind this won't work if the window isn't in the current tab page. |
15,920 | <p>I'm trying to wrap my head around vim plugin development and I see a constant check on a variable to see if the plugin has already been loaded like:</p>
<pre><code>if exists('g:loaded_plugin') || &cp
finish
endif
</code></pre>
<p>This makes sense since it's trying to not load the plugin twice but why is it c... | [
{
"answer_id": 15921,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 4,
"selected": true,
"text": "<p>That checks for the <code>compatible</code> option being set. Usually you don't want plugins to be run when the c... | 2018/04/14 | [
"https://vi.stackexchange.com/questions/15920",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/17105/"
] | I'm trying to wrap my head around vim plugin development and I see a constant check on a variable to see if the plugin has already been loaded like:
```
if exists('g:loaded_plugin') || &cp
finish
endif
```
This makes sense since it's trying to not load the plugin twice but why is it checking the second part?
I've... | That checks for the `compatible` option being set. Usually you don't want plugins to be run when the compatible option is set, because well for one Vim wouldn't actually be compatible anymore and seconds of all, the compatible option e.g. does not allow for line continuations e.g.
```
let a = 'foobar'
\ . ' and ... |
15,922 | <p>I need to change the content within a <code>[count]</code> number of braces for each line in my buffer.</p>
<pre><code>1 {Lorem} ipsum dolor {amet} blah blah {change this text} more blah blah
2 Hello. The {sun} rises in {the} east. blah {blah}. {also change this text}. final blah
</code></pre>
<p>In <code>line 1</... | [
{
"answer_id": 15923,
"author": "drclaw",
"author_id": 12736,
"author_profile": "https://vi.stackexchange.com/users/12736",
"pm_score": 1,
"selected": false,
"text": "<p>Execute the following in normal mode on the first line:</p>\n\n<pre><code>2f{ci{REPLACEMENT_TEXT<ESC>0\n</code><... | 2018/04/14 | [
"https://vi.stackexchange.com/questions/15922",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8408/"
] | I need to change the content within a `[count]` number of braces for each line in my buffer.
```
1 {Lorem} ipsum dolor {amet} blah blah {change this text} more blah blah
2 Hello. The {sun} rises in {the} east. blah {blah}. {also change this text}. final blah
```
In `line 1`, I need to substitute the content within t... | The [answer from @RubenWesterberg](https://vi.stackexchange.com/posts/15923/edit) is a correct sequence of Normal mode commands to do what you want. But I read your request to not move the cursor a little more literally. Also, if you need to make substitutions like this frequently you probably want something a bit less... |
15,926 | <p>I've tried </p>
<pre><code>syntax on
let g:solarized_termcolors=256
set t_Co=256
set background=dark
colorscheme solarized
</code></pre>
<p>but it doesn't look like GVim, how can I achieve that?</p>
<p>Right now
<a href="https://i.stack.imgur.com/AiSpC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgu... | [
{
"answer_id": 15938,
"author": "3N4N",
"author_id": 16280,
"author_profile": "https://vi.stackexchange.com/users/16280",
"pm_score": 2,
"selected": false,
"text": "<p>According to the <a href=\"https://github.com/altercation/vim-colors-solarized#important-note-for-terminal-users\" rel=\... | 2018/04/15 | [
"https://vi.stackexchange.com/questions/15926",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/17168/"
] | I've tried
```
syntax on
let g:solarized_termcolors=256
set t_Co=256
set background=dark
colorscheme solarized
```
but it doesn't look like GVim, how can I achieve that?
Right now
[](https://i.stack.imgur.com/AiSpC.png) | According to the [readme](https://github.com/altercation/vim-colors-solarized#important-note-for-terminal-users) of the vim sector of ethan's solarized colorscheme, you need to set the colorscheme of your terminal explicitly. You can take a look at [base 16](https://github.com/chriskempson/base16-shell). Install it, an... |
15,927 | <p><code>:scriptnames</code> can list all plugins installed in my vim.<br>
How to write the output of scriptnames into a file?</p>
<pre><code>:scriptnames > names.txt
</code></pre>
<p>It can't do the trick.</p>
| [
{
"answer_id": 15938,
"author": "3N4N",
"author_id": 16280,
"author_profile": "https://vi.stackexchange.com/users/16280",
"pm_score": 2,
"selected": false,
"text": "<p>According to the <a href=\"https://github.com/altercation/vim-colors-solarized#important-note-for-terminal-users\" rel=\... | 2018/04/15 | [
"https://vi.stackexchange.com/questions/15927",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5181/"
] | `:scriptnames` can list all plugins installed in my vim.
How to write the output of scriptnames into a file?
```
:scriptnames > names.txt
```
It can't do the trick. | According to the [readme](https://github.com/altercation/vim-colors-solarized#important-note-for-terminal-users) of the vim sector of ethan's solarized colorscheme, you need to set the colorscheme of your terminal explicitly. You can take a look at [base 16](https://github.com/chriskempson/base16-shell). Install it, an... |