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 |
|---|---|---|---|---|---|---|
1,971 | <p>If I have a vim session with two splits, when I execute a <code>:!</code> command, the result is shown in the entire window. Is it possible to have the output shown just on the active split?</p>
| [
{
"answer_id": 1972,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p>That won't be possible. You'll have to split your screen with another tool like tmux (IIRC), screen, ... </p>\n\n<p>I... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/1971",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/69/"
] | If I have a vim session with two splits, when I execute a `:!` command, the result is shown in the entire window. Is it possible to have the output shown just on the active split? | You can make a command to do just this:
1. Open a new split (or tab)
2. Run a command and show the results in that split (or tab)
The command would be something like this:
```
:Rsplit command
```
or
```
:Rtab command
```
In your `.vimrc` you can write this:
```
" execute a command and show its output in a spli... |
1,973 | <p>Sometimes when I'm working on a file, I'll open up multiple files just to get an idea of the current flow of the code up to a point. However this sometimes leads to multiple files being open at a time by split. Is there a command to quit all except the selected window? </p>
| [
{
"answer_id": 1975,
"author": "Matt Boehm",
"author_id": 680,
"author_profile": "https://vi.stackexchange.com/users/680",
"pm_score": 7,
"selected": true,
"text": "<p>If you want to close all windows(splits) except the current one:</p>\n\n<pre><code>:only\n</code></pre>\n\n<p>If you wan... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/1973",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25/"
] | Sometimes when I'm working on a file, I'll open up multiple files just to get an idea of the current flow of the code up to a point. However this sometimes leads to multiple files being open at a time by split. Is there a command to quit all except the selected window? | If you want to close all windows(splits) except the current one:
```
:only
```
If you want to close all tabs except the current one:
```
:tabonly
```
If you want to delete all hidden buffers (files open but not visible in any window on any tab), you'll have to add a function to your vimrc. Some people have posted... |
1,977 | <p>Can I jump to a function declaration or definition in a multiple C++ source files project?</p>
<p>Lets say I have a header file <code>foo.hpp</code>:</p>
<pre><code>int bar();
</code></pre>
<p>and a source file <code>foo.cpp</code>:</p>
<pre><code>#include "foo.hpp"
int bar() { return 42; }
</code></pre>
<p>and... | [
{
"answer_id": 1980,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>So far I can name two solutions to the problem of finding either the declaration or the definition of a function. I k... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/1977",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/669/"
] | Can I jump to a function declaration or definition in a multiple C++ source files project?
Lets say I have a header file `foo.hpp`:
```
int bar();
```
and a source file `foo.cpp`:
```
#include "foo.hpp"
int bar() { return 42; }
```
and a main file `main.cpp`:
```
#include "foo.hpp"
int main() { bar(); return 0;... | Exuberant ctags is the simplest way to achieve this.
Under GNU/Linux (e.g. Ubuntu or Debian) you should be able to just do
```
sudo apt-get install exuberant-ctags
```
(For OSX "$ brew install ctags" should suffice; for Windows you might want to visit <http://ctags.sourceforge.net/> and download the standalone exec... |
1,983 | <p>I'm editing my <code>.vimrc</code> file, and I am including comments. When I have a comment like this:</p>
<pre><code>" example comment
</code></pre>
<p>And then hit enter at the end of the line after finishing the comment, the next line is automatically set up as a comment (the quotes are automatically inserted):... | [
{
"answer_id": 1985,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 7,
"selected": true,
"text": "<p>This is controlled with the <code>formatoptions</code> setting; from <a href=\"http://vimhelp.appspot.com/change.txt.... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/1983",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/178/"
] | I'm editing my `.vimrc` file, and I am including comments. When I have a comment like this:
```
" example comment
```
And then hit enter at the end of the line after finishing the comment, the next line is automatically set up as a comment (the quotes are automatically inserted):
```
" example comment
"
```
How ... | This is controlled with the `formatoptions` setting; from [`:help fo-table`](http://vimhelp.appspot.com/change.txt.html#fo-table):
>
> You can use the `'formatoptions'` option to influence how Vim formats text.
> `'formatoptions'` is a string that can contain any of the letters below. The
> default setting is `tcq`... |
1,984 | <p>I am pasting several lines of text into vim at once (from another application, so I am using the OS's copy and paste and insert mode in vim). The longest of these lines is below:</p>
<pre><code>" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
</code></pre>
<p>The problem... | [
{
"answer_id": 1987,
"author": "Matt Boehm",
"author_id": 680,
"author_profile": "https://vi.stackexchange.com/users/680",
"pm_score": 4,
"selected": true,
"text": "<p>Before pasting, do <code>:set paste</code>. This changes a bunch of settings like 'textwidth' and 'autoindent' for speci... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/1984",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/178/"
] | I am pasting several lines of text into vim at once (from another application, so I am using the OS's copy and paste and insert mode in vim). The longest of these lines is below:
```
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
```
The problem with this line is that vi... | Before pasting, do `:set paste`. This changes a bunch of settings like 'textwidth' and 'autoindent' for specifically this purpose. Then enter insert mode, paste with your OS, hit `<Esc>` to leave insert mode, and do `:set nopaste`.
You can also toggle settings with a `!`, i.e. `:set paste!` to turn it on/off. |
1,988 | <p>I've defined mappings in my <code>vimrc</code> to automatically enter close parentheses and braces when I enter opening ones with <code>inoremap ( ()<esc>i</code>.</p>
<p>I'd like to do the same for <code>"</code> and <code>'</code>, but only when the cursor currently isn't inside a string - as inside a strin... | [
{
"answer_id": 1996,
"author": "Runium",
"author_id": 220,
"author_profile": "https://vi.stackexchange.com/users/220",
"pm_score": 3,
"selected": false,
"text": "<p>One approach might be to use <code>syn*</code> functions. Something like:</p>\n\n<pre><code>fun! Qtx(qt)\n let x = synID... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/1988",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/666/"
] | I've defined mappings in my `vimrc` to automatically enter close parentheses and braces when I enter opening ones with `inoremap ( ()<esc>i`.
I'd like to do the same for `"` and `'`, but only when the cursor currently isn't inside a string - as inside a string `'` is probably an apostrophe rather than a string delimit... | One approach might be to use `syn*` functions. Something like:
```
fun! Qtx(qt)
let x = synIDattr(synIDtrans(synID(line("."), col("."), 1)), "name")
if x != "String" && x != "Comment" && x != "Constant"
return a:qt . a:qt
endif
return a:qt
endfun
inoremap <silent> <expr> ' Qtx("'")
inoremap <s... |
2,001 | <p>I often make changes to the middle of a big file, use <code>gg</code> to jump to the top to check something, and then realize I forgot to set a mark where I was editing. Is there a built-in way to jump to the location of the last-changed line?</p>
| [
{
"answer_id": 2002,
"author": "howard",
"author_id": 687,
"author_profile": "https://vi.stackexchange.com/users/687",
"pm_score": 8,
"selected": true,
"text": "<p>The <code>`.</code> command will bring you to your last change.</p>\n\n<p>The <code>`</code> goes to a mark, and <code>.</co... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/2001",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/671/"
] | I often make changes to the middle of a big file, use `gg` to jump to the top to check something, and then realize I forgot to set a mark where I was editing. Is there a built-in way to jump to the location of the last-changed line? | The ``.` command will bring you to your last change.
The ``` goes to a mark, and `.` is a "special" mark which is automatically set to the position where the last change was made. See [`:help `.`](http://vimhelp.appspot.com/motion.txt.html#%60.) for some more information.
There is also ```` which will bring you back ... |
2,003 | <p>I have a problem in Vim, and I think it may be in my <code>vimrc</code> file (or have been <em>told</em> it could be my <code>vimrc</code> file).</p>
<p>How do I verify this? If it <em>is</em> my <code>vimrc</code> file, how do I know where <em>exactly</em> the problem lies?</p>
| [
{
"answer_id": 2004,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 8,
"selected": true,
"text": "<p>The first thing you want to do is to start Vim with the default settings:</p>\n\n<pre><code>vim -u NONE -U NONE -N\n<... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/2003",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | I have a problem in Vim, and I think it may be in my `vimrc` file (or have been *told* it could be my `vimrc` file).
How do I verify this? If it *is* my `vimrc` file, how do I know where *exactly* the problem lies? | The first thing you want to do is to start Vim with the default settings:
```
vim -u NONE -U NONE -N
```
The `-u NONE` prevents Vim from loading your vimrc, `-U NONE` prevents Vim from
loading your gvimrc, and `-N` tells Vim to use no-compatible mode (this isn't
required, but most Vim users are not used to "compatib... |
2,006 | <p>Occasionally, my pinky will graze the <code>'</code> key while reaching for enter, resulting in <code>:w'<Enter></code>.</p>
<p>I've tried:</p>
<pre><code>cabbrev w' :w
cabbrev w\' :w
cabbrev "w'" :w
</code></pre>
<p>None of them work. Is there a way to alias <code>:w'</code> to <code>:w</code>?</p>
<p>I ... | [
{
"answer_id": 2008,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 4,
"selected": true,
"text": "<p>As Peter Rincker points out, <code>cmap</code>s can expand in other places as well, so a <a href=\"https://stackoverflow.com/q... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/2006",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/319/"
] | Occasionally, my pinky will graze the `'` key while reaching for enter, resulting in `:w'<Enter>`.
I've tried:
```
cabbrev w' :w
cabbrev w\' :w
cabbrev "w'" :w
```
None of them work. Is there a way to alias `:w'` to `:w`?
I also use cmdwin (`:help cmdwin` + `nnoremap : :<C-F>`) instead of the normal command-line, ... | As Peter Rincker points out, `cmap`s can expand in other places as well, so a [`cnoreabbrev` would be better](https://stackoverflow.com/questions/7513380/vim-change-x-function-to-delete-buffer-instead-of-save-quit):
```
cnoreabbrev w' w
```
Or, the safest, again thanks to Peter:
```
cnoreabbrev <expr> w' getcmdtype... |
2,009 | <p>When I want to edit my <code>zshrc</code>, I just type:</p>
<pre><code>vim .zshrc
</code></pre>
<p>Without specifying the full path (<code>~/.zshrc</code>), if I am in a different directory, this will instead start a new file. This is very annoying, since I only have one <code>.zshrc</code>, in <code>~</code>, and... | [
{
"answer_id": 2012,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 2,
"selected": false,
"text": "<p>Alternative is to make some commands that will make this easier:</p>\n\n<pre><code>command! Evimrc e ~/.vimrc\ncomma... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/2009",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/205/"
] | When I want to edit my `zshrc`, I just type:
```
vim .zshrc
```
Without specifying the full path (`~/.zshrc`), if I am in a different directory, this will instead start a new file. This is very annoying, since I only have one `.zshrc`, in `~`, and only one `vimrc`, in `~/.vim/`. So, how do I get vim to open `~/.zshr... | Vim's [`'path'`](http://vimhelp.appspot.com/options.txt.html#%27path%27) option allows you to specify directories which commands like `gf` and `:find` will search for a file.
If you only want this functionality to trigger for a specific set of files, then you could use an autocmd to automatically "redirect" your `:edi... |
2,010 | <p>I imported the solarized colorscheme and palette. My terminal has the correct colors and background, gvim has the correct colors and background, but vim has an incorrectly colored background. The text is all correct, but the background appears to be pure black.</p>
<p><a href="https://i.stack.imgur.com/LZnB3.png" r... | [
{
"answer_id": 2019,
"author": "El Developer",
"author_id": 788,
"author_profile": "https://vi.stackexchange.com/users/788",
"pm_score": 3,
"selected": false,
"text": "<p>There's two reasons why I think this may be happening:</p>\n\n<ol>\n<li><p>The solarized color scheme you are using d... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/2010",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/779/"
] | I imported the solarized colorscheme and palette. My terminal has the correct colors and background, gvim has the correct colors and background, but vim has an incorrectly colored background. The text is all correct, but the background appears to be pure black.
[. I set my .vimrc to the simple
```
syntax enable
set background=dark
set t_Co=16
colorscheme solarized
```
This seems to fix everything. The colors don't seem... |
2,013 | <p>How do I run vim with file.txt and <strong>screen center</strong> at line 100?
Basically I would like to use <code>zz</code> mapping when starting Vim.</p>
<p>This does not work: <code>vim -c "zz" file.txt +100</code></p>
| [
{
"answer_id": 2017,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 3,
"selected": true,
"text": "<p><code>zz</code> is a normal mode command, so use <code>:normal</code>:</p>\n\n<pre><code>vim \"+normal zz\" file.txt +100\nvim... | 2015/02/19 | [
"https://vi.stackexchange.com/questions/2013",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/784/"
] | How do I run vim with file.txt and **screen center** at line 100?
Basically I would like to use `zz` mapping when starting Vim.
This does not work: `vim -c "zz" file.txt +100` | `zz` is a normal mode command, so use `:normal`:
```
vim "+normal zz" file.txt +100
vim -c "normal zz" file.txt +100
``` |
2,032 | <p>I have a file containing nothing but integers and words, separated by arbitrary numbers of spaces, along the following lines:</p>
<pre><code>1 alpha plural 1 0
6 1440
3 1 4 1 5 9 2 6 5 3 5 8 9
2 7 1 8 2 8 1 8 2 8 4 5 9
42 972 insert point here
16 7 88
</code></pre>
<p>But the software that a third party has ... | [
{
"answer_id": 2033,
"author": "Community",
"author_id": -1,
"author_profile": "https://vi.stackexchange.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<p>You can actually do this in two passes, one to handle numbers at the end of the line and one to handle numbers followed by... | 2015/02/20 | [
"https://vi.stackexchange.com/questions/2032",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I have a file containing nothing but integers and words, separated by arbitrary numbers of spaces, along the following lines:
```
1 alpha plural 1 0
6 1440
3 1 4 1 5 9 2 6 5 3 5 8 9
2 7 1 8 2 8 1 8 2 8 4 5 9
42 972 insert point here
16 7 88
```
But the software that a third party has written to *read* that fil... | I think the following substitution would be sufficient:
```
:%s/\<\d\+\>/&.0/g
```
The effect:
```
1.0 alpha plural 1.0 0.0
6.0 1440.0
3.0 1.0 4.0 1.0 5.0 9.0 2.0 6.0 5.0 3.0 5.0 8.0 9.0
2.0 7.0 1.0 8.0 2.0 8.0 1.0 8.0 2.0 8.0 4.0 5.0 9.0
42.0 972.0 insert point here
16.0 7.0 88.0
```
* `\d` matches digits,... |
2,036 | <p>I have a list of items where I want to replace the first two characters:</p>
<pre><code>a) item 1
b) item 2
c) item 3
</code></pre>
<p>What is the fastest way to make this:</p>
<pre><code>* item 1
* item 2
* item 3
</code></pre>
<p>I have an approach with visual mode (Ctr-v, jjj, but need to do two replace comma... | [
{
"answer_id": 2041,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 6,
"selected": true,
"text": "<p><strong>Visual-block selection:</strong></p>\n\n<pre><code><C-v>\njjl\nc*\n<Esc>\n</code></pre>\n\n<p><strong><co... | 2015/02/20 | [
"https://vi.stackexchange.com/questions/2036",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/833/"
] | I have a list of items where I want to replace the first two characters:
```
a) item 1
b) item 2
c) item 3
```
What is the fastest way to make this:
```
* item 1
* item 2
* item 3
```
I have an approach with visual mode (Ctr-v, jjj, but need to do two replace commands. Iirc, this replacement can be done with 1 co... | **Visual-block selection:**
```
<C-v>
jjl
c*
<Esc>
```
**`:normal`:**
```
:,+2norm! cE*
```
**Substitution:**
```
:,+2s/^.\{2}/*
```
**Dot formula:**
```
cE*<Esc>
j.
j.
``` |
2,044 | <p>Sometimes I'm on a system without Vim, and use the default <code>nvi</code> (BSD systems)
or the original <code>vi</code> (Arch Linux).</p>
<p>There are quite a few differences, but the largest annoyance is that I can undo
<em>only</em> my last operation. Pressing <kbd>u</kbd> the second time works are a
"redo".</p... | [
{
"answer_id": 2045,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 5,
"selected": true,
"text": "<p>From <a href=\"http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/ex.1?query=vi\" rel=\"noreferrer\"><code>n... | 2015/02/20 | [
"https://vi.stackexchange.com/questions/2044",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | Sometimes I'm on a system without Vim, and use the default `nvi` (BSD systems)
or the original `vi` (Arch Linux).
There are quite a few differences, but the largest annoyance is that I can undo
*only* my last operation. Pressing `u` the second time works are a
"redo".
Is there some way to get this working? | From [`nvi(1)`](http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/ex.1?query=vi):
```
u Undo the last change made to the file. If repeated, the u command
alternates between these two states. The . command, when used
immediately after u, causes the change log to be rolled forward or... |
2,046 | <p>Instead of <code>gdbtui</code> or <code>ctrl+x</code> under <code>gdb</code> which shows source code on top of the screen I would like to see this in my Vim editor that would jump between tabs, and buffers accordingly.</p>
<p>How can I do this?</p>
| [
{
"answer_id": 2048,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 4,
"selected": false,
"text": "<p>You have several plugins that integrates gdb.</p>\n\n<ul>\n<li>We used to have <a href=\"http://pyclewn.sourceforge.n... | 2015/02/20 | [
"https://vi.stackexchange.com/questions/2046",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/784/"
] | Instead of `gdbtui` or `ctrl+x` under `gdb` which shows source code on top of the screen I would like to see this in my Vim editor that would jump between tabs, and buffers accordingly.
How can I do this? | Among all the plugins I have tried, I found [ConqueGDB](https://github.com/vim-scripts/Conque-GDB) to be the best approach. ConqueGDB uses [Conque Shell](http://www.vim.org/scripts/script.php?script_id=2771) to embed an interactive shell inside vim, that is used by GDB.
The workflow with ConqueGDB consists not enterin... |
2,051 | <p>When running <code>gvim</code> by double clicking with a file in a graphical file manager, like nautilus, the vim instance is called with a strange current directory (seems root sometime, but I am not sure). This has the effect that file name completion (<code>C-x C-f</code>) is, well, not so useful. </p>
<p>I have... | [
{
"answer_id": 2052,
"author": "Oliver Friedrich",
"author_id": 826,
"author_profile": "https://vi.stackexchange.com/users/826",
"pm_score": 2,
"selected": false,
"text": "<p>Try the autodir setting in vimrc.</p>\n\n<pre><code>set autochdir\n</code></pre>\n"
},
{
"answer_id": 205... | 2015/02/20 | [
"https://vi.stackexchange.com/questions/2051",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/854/"
] | When running `gvim` by double clicking with a file in a graphical file manager, like nautilus, the vim instance is called with a strange current directory (seems root sometime, but I am not sure). This has the effect that file name completion (`C-x C-f`) is, well, not so useful.
I have a map that solve this:
```
nn... | I just installed nautilus, and it seems the current working directory is always set to the directory nautilus was started from (ie. Vim inherits nautilus' working directory).
This is a problem in nautilus (IMHO), and not Vim. When nautilus starts a new process (Vim) it can set the working directory, but doesn't. If I ... |
2,071 | <p>Say I'm editing file <code>foo</code>. I want to copy/write what I have in the buffer to <code>bar</code> and change the buffer to be editing <code>bar</code> instead of <code>foo</code>. I can achieve this with:</p>
<pre><code>:w bar
:e bar
</code></pre>
<p>But that has a few problems</p>
<ol>
<li>If <code>bar</... | [
{
"answer_id": 2072,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 3,
"selected": false,
"text": "<p>Here's a relatively simple solution:</p>\n\n<pre><code>:saveas bar\n</code></pre>\n\n<p>This solves problems #1 and #2. It ... | 2015/02/20 | [
"https://vi.stackexchange.com/questions/2071",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9/"
] | Say I'm editing file `foo`. I want to copy/write what I have in the buffer to `bar` and change the buffer to be editing `bar` instead of `foo`. I can achieve this with:
```
:w bar
:e bar
```
But that has a few problems
1. If `bar` is actually `/usr/local/share/long/path/to/bar`, I really don't want to type that in ... | Here's a relatively simple solution:
```
:saveas bar
```
This solves problems #1 and #2. It doesn't address problem #3, however.
Note that this still leaves the old file open in another buffer. For example, `:w foo<cr>:saveas bar<cr>:ls<cr>` will list two buffers, `foo` and `bar`. |
2,076 | <p>I don't know much of the theory behind Vim. It looks as if we <code>set</code> some variables, and <code>let</code> other variables. What's the difference, and when is one required over the other?</p>
<p>Also, the solarized vim colorscheme says to <code>let g:blabla...</code> what is the significance of <code>g:</c... | [
{
"answer_id": 2077,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 7,
"selected": true,
"text": "<p><code>let</code> assigns a value to a variable, and <code>set</code> assigns a value to one of Vim's internal options.</p>\n... | 2015/02/21 | [
"https://vi.stackexchange.com/questions/2076",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/810/"
] | I don't know much of the theory behind Vim. It looks as if we `set` some variables, and `let` other variables. What's the difference, and when is one required over the other?
Also, the solarized vim colorscheme says to `let g:blabla...` what is the significance of `g:` in this instance? | `let` assigns a value to a variable, and `set` assigns a value to one of Vim's internal options.
For example, you would use
```
:let mystring='Hello!'
```
to declare a new variable, but you would use
```
:set tabstop=4
```
or
```
:set expandtab
```
to set one of Vim's options.
See also: `:help let`, `:help s... |
2,082 | <p>Let's see. I have a <code>gvim</code> running and I want open a file, respecting the <code>autocmd</code>s (<a href="https://vi.stackexchange.com/questions/2066/different-autocmd-behavior-when-using-remote-tab-silent">which rules out <code>--remote-tab</code></a>). </p>
<p>Now I know I can do (basically, with some ... | [
{
"answer_id": 2300,
"author": "Rmano",
"author_id": 854,
"author_profile": "https://vi.stackexchange.com/users/854",
"pm_score": 3,
"selected": true,
"text": "<p>For general info, and thanks to all the comments, this is the script I use to have an \"open in a tab on the gvim on this des... | 2015/02/21 | [
"https://vi.stackexchange.com/questions/2082",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/854/"
] | Let's see. I have a `gvim` running and I want open a file, respecting the `autocmd`s ([which rules out `--remote-tab`](https://vi.stackexchange.com/questions/2066/different-autocmd-behavior-when-using-remote-tab-silent)).
Now I know I can do (basically, with some tweak):
```
gvim --remote-send ":tabe my_file<CR>"
... | For general info, and thanks to all the comments, this is the script I use to have an "open in a tab on the gvim on this desktop" script:
```
#!/bin/bash -x
#
# this is convoluted because it has to finish in an exec to keep the DM happy
# remember to set StartupNotify=false in the .desktop file
#
desktop=desktop_$(xp... |
2,086 | <p>I would like to have a keystroke to show a <strong>list of recently used files</strong> to choose one to edit. </p>
<ul>
<li>What do I need to provide that? </li>
</ul>
<p>And related, </p>
<ul>
<li>How do I manage the history of recently used files to use? </li>
<li>This should support excluding filenames or... | [
{
"answer_id": 2087,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 3,
"selected": false,
"text": "<p>You can use the <a href=\"http://vimhelp.appspot.com/editing.txt.html#%3Abrowse\"><code>:browse</code></a> command for that:<... | 2015/02/22 | [
"https://vi.stackexchange.com/questions/2086",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/925/"
] | I would like to have a keystroke to show a **list of recently used files** to choose one to edit.
* What do I need to provide that?
And related,
* How do I manage the history of recently used files to use?
* This should support excluding filenames or subdirectories. | You can use the [`:browse`](http://vimhelp.appspot.com/editing.txt.html#%3Abrowse) command for that:
```
:browse oldfiles
```
For a keystroke, map it:
```
nnoremap <Leader>o :browse oldfiles<cr>
```
Then you can press `Leader o` in normal mode to view a list of files.
From [`:help v:oldfiles`](http://vimhelp.app... |
2,094 | <p>Is there a way to make certain vimrc configuration valid only for files under a defined directory tree? Or alternatively, is there a way to have a .vimrc file in a directory, and make its setting override all $HOME/.vimrc for that directory and subdirectories (and maybe, additional vimrc file in subdirectory would o... | [
{
"answer_id": 2096,
"author": "ssmith",
"author_id": 592,
"author_profile": "https://vi.stackexchange.com/users/592",
"pm_score": 1,
"selected": false,
"text": "<p>I've used the LocalVimrc plugin with success, very handy indeed!</p>\n\n<p><a href=\"https://github.com/embear/vim-localvim... | 2015/02/22 | [
"https://vi.stackexchange.com/questions/2094",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/188/"
] | Is there a way to make certain vimrc configuration valid only for files under a defined directory tree? Or alternatively, is there a way to have a .vimrc file in a directory, and make its setting override all $HOME/.vimrc for that directory and subdirectories (and maybe, additional vimrc file in subdirectory would over... | There are several ways to do this.
As you specified `directory tree`, it excludes the `.exrc` approach (as it only works for one directory), and the *modelines* as well.
Remains the hand-rolled way: you put an autocommand in your `.vimrc` for pattern or specific directories. It's not my preferred approach as it clutt... |
2,097 | <p>I have 2 pieces of text, what is a proper way to switch those pieces of text. around e.g. I have this:</p>
<pre><code>This is one piece of text.
Here is another sentence.
</code></pre>
<p>And I want to switch around the 3 first words in these sentences, so it becomes:</p>
<pre><code>Here is another piece of text.... | [
{
"answer_id": 2098,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 3,
"selected": true,
"text": "<p>There are a number of ways to do this, but I would say the most useful & generic way is to use visual mode (<a hr... | 2015/02/22 | [
"https://vi.stackexchange.com/questions/2097",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/960/"
] | I have 2 pieces of text, what is a proper way to switch those pieces of text. around e.g. I have this:
```
This is one piece of text.
Here is another sentence.
```
And I want to switch around the 3 first words in these sentences, so it becomes:
```
Here is another piece of text.
This is one sentence.
```
Another ... | There are a number of ways to do this, but I would say the most useful & generic way is to use visual mode ([`:help visual-mode`](http://vimhelp.appspot.com/visual.txt.html#visual-mode)).
In your first example:
```
This is one piece of text.
Here is another sentence.
```
I would put the cursor on the first `T` (in ... |
2,105 | <p>How can I reverse the order of lines so that the first line appears at the end and the last line appears first? (Could be all the lines in a buffer, an address range, or a linewise visual mode selection.)</p>
<p>I'd like to transform</p>
<pre><code>rat
ox
tiger
⋮
dog
pig
</code></pre>
<p>into</p>
<pre><code>pig... | [
{
"answer_id": 2106,
"author": "John O'M.",
"author_id": 227,
"author_profile": "https://vi.stackexchange.com/users/227",
"pm_score": 5,
"selected": false,
"text": "<p>The power of global will work here:</p>\n\n<pre><code>:g/^/exe \"normal ddggP\"\n</code></pre>\n\n<p>Or, more simply (t... | 2015/02/22 | [
"https://vi.stackexchange.com/questions/2105",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/24/"
] | How can I reverse the order of lines so that the first line appears at the end and the last line appears first? (Could be all the lines in a buffer, an address range, or a linewise visual mode selection.)
I'd like to transform
```
rat
ox
tiger
⋮
dog
pig
```
into
```
pig
dog
⋮
tiger
ox
rat
```
without resorting t... | The power of global will work here:
```
:g/^/exe "normal ddggP"
```
Or, more simply (thanks @tommcdo)
```
:g/^/move 0
```
The first will match every line and for each line, delete it and paste it to the top of the file. As it moves through the file, it reverses the text.
The second similarly matches every line a... |
2,108 | <p>If I use:</p>
<pre><code>:tabedit file1 file2
</code></pre>
<p>I get:</p>
<pre><code>E172: Only one file name allowed
</code></pre>
<p>Is there any way to use <code>:tabedit</code> with multiple file names? Or another way to open multiple tabs at once?</p>
| [
{
"answer_id": 2109,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 4,
"selected": false,
"text": "<p>As far as I know, the only built-in way to do this is:</p>\n\n<pre><code>:args *.vim\n:tab all\n</code></pre>\n\n<p>... | 2015/02/22 | [
"https://vi.stackexchange.com/questions/2108",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | If I use:
```
:tabedit file1 file2
```
I get:
```
E172: Only one file name allowed
```
Is there any way to use `:tabedit` with multiple file names? Or another way to open multiple tabs at once? | Given the problems & complexity in [my other answer](https://vi.stackexchange.com/a/2109/51) using the "built-in" way by modifying the argument list, I've added by own small function to do this:
```
" Open multiple tabs at once
fun! OpenMultipleTabs(pattern_list)
for p in a:pattern_list
for c in glob(l:p, ... |
2,115 | <p>I've been using the <a href="https://vi.stackexchange.com/questions/6/how-can-i-use-the-undofile?s=3|0.0000">undofile feature</a> in Vim for a while now. It's a very nice feature.</p>
<p>However, one annoyance is that it's very easy to accidentally undo changes that I did the last time I opened the file; which may ... | [
{
"answer_id": 2118,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 3,
"selected": false,
"text": "<p>Oooh, ooh, finally a chance to show off <em>this</em> nifty command!</p>\n\n<p>Vim can \"go back in time.\" It has an <a hr... | 2015/02/23 | [
"https://vi.stackexchange.com/questions/2115",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | I've been using the [undofile feature](https://vi.stackexchange.com/questions/6/how-can-i-use-the-undofile?s=3|0.0000) in Vim for a while now. It's a very nice feature.
However, one annoyance is that it's very easy to accidentally undo changes that I did the last time I opened the file; which may be 2 minutes ago, an ... | **Update 2015-06-28**: I fixed a small bug, and [released this as a
plugin](http://code.arp242.net/undofile_warn.vim). The plugin code is slightly
better, in that it warns again after moving the cursor; I recommend you use the
plugin.
---
---
The answer from [superjer](https://vi.stackexchange.com/a/2150/51) works g... |
2,116 | <p>In scripts it is customary to do something like:</p>
<pre><code>let s:save_cpo = &cpo
set cpo&vim
... script ...
let &cpo = s:save_cpo
</code></pre>
<p>To ensure nocompatible mode for the script.</p>
<p>Is:</p>
<pre><code>set cpo&vim
</code></pre>
<p>some sort of special syntax, as in <code>fo... | [
{
"answer_id": 2117,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 5,
"selected": true,
"text": "<p>Yes, it's a special syntax to reset options to the Vim defaults. From <a href=\"http://vimhelp.appspot.com/options.tx... | 2015/02/23 | [
"https://vi.stackexchange.com/questions/2116",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/220/"
] | In scripts it is customary to do something like:
```
let s:save_cpo = &cpo
set cpo&vim
... script ...
let &cpo = s:save_cpo
```
To ensure nocompatible mode for the script.
Is:
```
set cpo&vim
```
some sort of special syntax, as in `foo & bar`? Or is it more like a command, trigger line or something else? | Yes, it's a special syntax to reset options to the Vim defaults. From [`:help :set-&vim`](http://vimhelp.appspot.com/options.txt.html#%3Aset-%26vim):
```
:se[t] {option}& Reset option to its default value. May depend on the
current value of 'compatible'. {not in Vi}
:se[t] {option}&vi ... |
2,121 | <p>Using vim editor, a common task is to browse buffers.
I now use standard commands like <code>:ls</code> or a <code>:bnext</code>. In fact I set in my .vimrc:</p>
<pre><code>"move amongs buffers with CTRL
map <C-J> :bnext<CR>
map <C-K> :bprev<CR>
</code></pre>
<p>I would like to browse buffe... | [
{
"answer_id": 2123,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 1,
"selected": false,
"text": "<p>Have a look at the <a href=\"http://www.vim.org/scripts/script.php?script_id=42\" rel=\"nofollow noreferrer\">bufexplo... | 2015/02/23 | [
"https://vi.stackexchange.com/questions/2121",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/983/"
] | Using vim editor, a common task is to browse buffers.
I now use standard commands like `:ls` or a `:bnext`. In fact I set in my .vimrc:
```
"move amongs buffers with CTRL
map <C-J> :bnext<CR>
map <C-K> :bprev<CR>
```
I would like to browse buffers as list in quickfix window,
in the simple (=excellent) way [MRU plugi... | You can populate the quickfix list with each buffer like this:
```
:call setqflist(map(filter(range(1, bufnr('$')), 'buflisted(v:val)'), '{"bufnr": v:val}'))
```
* `setqflist()` takes a List of Dictionary items describing each error (filename, line number, position, etc.). In this case we're specifying a minimal set... |
2,129 | <p>One way to select a buffer in Vim could be to browse the buffers list, using standard commands as <code>:ls</code>, or with <a href="https://vi.stackexchange.com/questions/2121/how-do-i-have-buffers-listed-in-a-quickfix-window-in-vim">some external plugin / vimscript code to browse a list in a window</a>.</p>
<p>Let... | [
{
"answer_id": 2131,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 6,
"selected": false,
"text": "<p>The <code>:b</code> command can also take a <em>substring</em> of the name of the file of the buffer which you want to trav... | 2015/02/23 | [
"https://vi.stackexchange.com/questions/2129",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/983/"
] | One way to select a buffer in Vim could be to browse the buffers list, using standard commands as `:ls`, or with [some external plugin / vimscript code to browse a list in a window](https://vi.stackexchange.com/questions/2121/how-do-i-have-buffers-listed-in-a-quickfix-window-in-vim).
Let's say I want to jump to a buff... | The `:b` command can also take a *substring* of the name of the file of the buffer which you want to travel to, which is very convenient.
For example, if you have three buffers `foo`, `bar`, and `baz`, then
* `:b bar` will switch to the `bar` file.
* `:b o` will switch to the `foo` file.
* `:b a` will give you an err... |
2,136 | <p>In Vim's built-in help system, how do I…</p>
<ul>
<li>search for topics that I want help on?</li>
<li>follow hyperlinks?</li>
<li>browse around for related material?</li>
</ul>
| [
{
"answer_id": 2137,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 8,
"selected": true,
"text": "<p>Vim comes with an exhaustive and fully indexed documentation that contains the answers to most of the questions you may have ... | 2015/02/23 | [
"https://vi.stackexchange.com/questions/2136",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/54/"
] | In Vim's built-in help system, how do I…
* search for topics that I want help on?
* follow hyperlinks?
* browse around for related material? | Vim comes with an exhaustive and fully indexed documentation that contains the answers to most of the questions you may have on using Vim.
But the documentation is huge and may look to the neophyte as an impenetrable maze. Here are a few guidelines to help you find what you need…
1. The `:help` command is your gatewa... |
2,155 | <p>If I do this from the shell:</p>
<pre><code>$ sleep 100
</code></pre>
<p>I can make it go to the background by doing:</p>
<pre><code>^Z
$ bg
</code></pre>
<p>And then continue using my shell. You can get the same effect by adding a <code>&</code> to the end of the command, but I often forget this.</p>
<p>In... | [
{
"answer_id": 2158,
"author": "Jon Carter",
"author_id": 554,
"author_profile": "https://vi.stackexchange.com/users/554",
"pm_score": 1,
"selected": false,
"text": "<p>You can put the command in a shell script that backgrounds itself. The contents, for example, might be:</p>\n\n<pre><c... | 2015/02/24 | [
"https://vi.stackexchange.com/questions/2155",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | If I do this from the shell:
```
$ sleep 100
```
I can make it go to the background by doing:
```
^Z
$ bg
```
And then continue using my shell. You can get the same effect by adding a `&` to the end of the command, but I often forget this.
In Vim, I often do:
```
:!sleep 100
```
And here also, I often forget ... | **Note**: This answer only seems to work with the `tcsh` and `fish` shells. I also tried `bash`, `dash`, `mksh`, and `zsh`, and it *doesn't* work there; I'm not sure why, because if I do the same actions from these shells without Vim, it *does* work as expected... (`:!` commands are executed though the shell).
I happe... |
2,162 | <p>Trying to delete characters in insert mode with the <kbd>backspace</kbd> key sometimes doesn't seem to work. I can <kbd>backspace</kbd> <em>sometimes</em>, but at other times it does nothing; the cursor doesn't go to the left, and absolutely nothing seems to happen.</p>
<p>I noticed this using gVim in Windows.
The ... | [
{
"answer_id": 2163,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 9,
"selected": true,
"text": "<p>tl;dr: Add this to your <a href=\"https://vimhelp.org/starting.txt.html#vimrc\" rel=\"noreferrer\"><code>vimrc</code>... | 2015/02/24 | [
"https://vi.stackexchange.com/questions/2162",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/602/"
] | Trying to delete characters in insert mode with the `backspace` key sometimes doesn't seem to work. I can `backspace` *sometimes*, but at other times it does nothing; the cursor doesn't go to the left, and absolutely nothing seems to happen.
I noticed this using gVim in Windows.
The `backspace` seems to work as expect... | tl;dr: Add this to your [`vimrc`](https://vimhelp.org/starting.txt.html#vimrc) to make the backspace work like in most other programs:
```
set backspace=indent,eol,start
```
---
Longer answer
=============
Though the default behaviour may be surprising, the backspace "not working" can be considered a *feature*; it... |
2,170 | <p>How can I make a command that allows me to insert LaTeX environments in the current text?</p>
<p>The idea is to press <kbd>Ctrl</kbd>+<kbd>E</kbd> or type <code>:texenv</code> and then enter the environment name in the bottom line, e.g. <code>:texenv itemize</code>. Which would then insert a</p>
<pre><code>\begin{... | [
{
"answer_id": 2171,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 1,
"selected": false,
"text": "<p><em>snippets</em> are like the built-in <code>:abbreviate</code> on steroids, usually with parameter insertions, mirro... | 2015/02/24 | [
"https://vi.stackexchange.com/questions/2170",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/852/"
] | How can I make a command that allows me to insert LaTeX environments in the current text?
The idea is to press `Ctrl`+`E` or type `:texenv` and then enter the environment name in the bottom line, e.g. `:texenv itemize`. Which would then insert a
```
\begin{itemize}
\end{itemize}
```
Ideally placing the curser after... | You can create a simple function to insert text with the [`append()`](http://vimhelp.appspot.com/eval.txt.html#append%28%29) function:
```
fun! TexEnv(name)
let l:l = line(".") - 1
call append(l:l, "\\end{" . a:name . "}")
call append(l:l, "\\begin{" . a:name . "}")
endfun
```
You can then us... |
2,176 | <p>I have read the help page about fold-expr (<a href="http://vimhelp.appspot.com/fold.txt.html#fold-expr" rel="noreferrer"><code>:h fold-expr</code></a>) but it didn't explain what's the syntax used in the expression.</p>
<p>There were there four examples:</p>
<ol>
<li><code>:set foldexpr=getline(v:lnum)[0]==\"\\... | [
{
"answer_id": 2178,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 5,
"selected": true,
"text": "<p>From <a href=\"http://vimhelp.appspot.com/options.txt.html#%27fde%27\" rel=\"nofollow noreferrer\"><code>:help 'folde... | 2015/02/24 | [
"https://vi.stackexchange.com/questions/2176",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/342/"
] | I have read the help page about fold-expr ([`:h fold-expr`](http://vimhelp.appspot.com/fold.txt.html#fold-expr)) but it didn't explain what's the syntax used in the expression.
There were there four examples:
1. `:set foldexpr=getline(v:lnum)[0]==\"\\t\"`
2. `:set foldexpr=MyFoldLevel(v:lnum)`
3. `:set foldexpr=getli... | From [`:help 'foldexpr'`](http://vimhelp.appspot.com/options.txt.html#%27fde%27):
>
> It is evaluated for each line to obtain its fold level
>
>
>
The `foldexpr` is evaluated, so it needs to be VimL code; there is no mention of "special syntax" or the like. The result of this evaluation controls what Vim consider... |
2,189 | <p>Say that I have some semi-complex keymaps like the following:</p>
<pre><code>nnoremap <Leader>s :%s/\s\+$//e
nnoremap <Leader>u mz:r!uuidgen<CR>dW"_dd`zp"
nnoremap <Leader>d g/\v"([^"]|\n)*"\ze\n\s*\[.*\]/normal gngq
</code></pre>
<p>In general, how does one translate an arbitrary keymap to... | [
{
"answer_id": 2190,
"author": "EvergreenTree",
"author_id": 865,
"author_profile": "https://vi.stackexchange.com/users/865",
"pm_score": 3,
"selected": true,
"text": "<p>This is because special keys like <code><esc></code> are not translated to their actual meaning in normal comma... | 2015/02/25 | [
"https://vi.stackexchange.com/questions/2189",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | Say that I have some semi-complex keymaps like the following:
```
nnoremap <Leader>s :%s/\s\+$//e
nnoremap <Leader>u mz:r!uuidgen<CR>dW"_dd`zp"
nnoremap <Leader>d g/\v"([^"]|\n)*"\ze\n\s*\[.*\]/normal gngq
```
In general, how does one translate an arbitrary keymap to a VimL function?
The following does not work:
`... | This is because special keys like `<esc>` are not translated to their actual meaning in normal commands. Thus, `normal <esc>` translates to literally typing `less-than e s c greater-than`. You can get around this by doing something like this:
```
execute "normal <esc>"
```
In your case, it would look like this:
```... |
2,193 | <p>I needed to edit a lot of files recently for a small change in each file. To get to each file, I browsed through NERDtree and opened one file after another. As I opened more and more files, I noticed that my memory usage grew a LOT. Closing vim gave me a lot of memory back.</p>
<p>I have quite a few plugins inst... | [
{
"answer_id": 2194,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 2,
"selected": false,
"text": "<p>I am not sure how to get the oldest buffers with respect to editing time, but one could, instead, try to close the oldest une... | 2015/02/25 | [
"https://vi.stackexchange.com/questions/2193",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/922/"
] | I needed to edit a lot of files recently for a small change in each file. To get to each file, I browsed through NERDtree and opened one file after another. As I opened more and more files, I noticed that my memory usage grew a LOT. Closing vim gave me a lot of memory back.
I have quite a few plugins installed, but I'... | The following should answer your question.
```
function! s:SortTimeStamps(lhs, rhs)
return a:lhs[1] > a:rhs[1] ? 1
\ : a:lhs[1] < a:rhs[1] ? -1
\ : 0
endfunction
function! s:Close(nb_to_keep)
let saved_buffers = filter(range(0, bufnr('$')), 'buflisted(v:val) && ! getbufvar(v:val,... |
2,207 | <p>When I do <code>vimdiff file2 file1</code>, <code>file2</code> naturally goes on the left and <code>file1</code> on the right.</p>
<p>Sometimes I find that I put them the wrong way round, so I'd like to be able to switch them round without leaving Vim. Is that possible?</p>
| [
{
"answer_id": 2208,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 6,
"selected": true,
"text": "<p>You can use <kbd>Ctrl</kbd><kbd>w</kbd>-<kbd>x</kbd>. From <a href=\"http://vimhelp.appspot.com/windows.txt.html#CTRL-W_x\"><c... | 2015/02/25 | [
"https://vi.stackexchange.com/questions/2207",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/180/"
] | When I do `vimdiff file2 file1`, `file2` naturally goes on the left and `file1` on the right.
Sometimes I find that I put them the wrong way round, so I'd like to be able to switch them round without leaving Vim. Is that possible? | You can use `Ctrl``w`-`x`. From [`:he CTRL-W_x`](http://vimhelp.appspot.com/windows.txt.html#CTRL-W_x):
```
CTRL-W x CTRL-W_x CTRL-W_CTRL-X
CTRL-W CTRL-X Without count: Exchange current window with next one. If there
is no next window, exchange with previou... |
2,219 | <p><strong>NOTE:</strong> This question is a "manual migration" from here: <a href="https://superuser.com/q/875751/199803">https://superuser.com/q/875751/199803</a></p>
<hr>
<p>My Vim syntax highlighter for <code>ft=cpp</code> is prematurely ending some macros mid-line. For example:</p>
<p><img src="https://i.stack.... | [
{
"answer_id": 2221,
"author": "Community",
"author_id": -1,
"author_profile": "https://vi.stackexchange.com/users/-1",
"pm_score": 4,
"selected": true,
"text": "<p><code>cCppOut2</code> comes from <code>c.vim</code>:</p>\n\n<pre><code>syn region cCppOut2 contained start=\"0\" end=\"... | 2015/02/25 | [
"https://vi.stackexchange.com/questions/2219",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1060/"
] | **NOTE:** This question is a "manual migration" from here: <https://superuser.com/q/875751/199803>
---
My Vim syntax highlighter for `ft=cpp` is prematurely ending some macros mid-line. For example:

(The italicization may make this example a little ... | `cCppOut2` comes from `c.vim`:
```
syn region cCppOut2 contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cSpaceError,cCppSkip
```
It is `contained`, and the definition for `cDefine` is:
```
syn region cDefine start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$" keepen... |
2,222 | <p>I saw a skilled vim ninja do this a while back but I have no idea were to start.</p>
<p>A) Is there a way to set up vims background colour so that consecutive lines with identical content get highlighted.</p>
<p>B) If somebody knows how to do that a nice tweak to this would be if the highlighting happened on conse... | [
{
"answer_id": 2228,
"author": "Matt Boehm",
"author_id": 680,
"author_profile": "https://vi.stackexchange.com/users/680",
"pm_score": 3,
"selected": false,
"text": "<p>As a starting point, here's a search pattern that matches duplicate lines (ignoring changes in leading whitespace):</p>... | 2015/02/25 | [
"https://vi.stackexchange.com/questions/2222",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/383/"
] | I saw a skilled vim ninja do this a while back but I have no idea were to start.
A) Is there a way to set up vims background colour so that consecutive lines with identical content get highlighted.
B) If somebody knows how to do that a nice tweak to this would be if the highlighting happened on consecutive lines but ... | The following `match` sets seem to work for (A):
```
:syn match Low /\v(.+)\n(\1\n)/
:syn match Medium /\v(.+)\n(\1\n){2,4}/
:syn match Critical /\v(.+)\n(\1\n){5,}/
:hi Critical ctermfg=red
:hi Medium ctermfg=yellow
:hi Low ctermfg=green
```
It seems the order is crucial here. If the `Low` or `Medium` matches co... |
2,223 | <p>I'm trying to open an <code>.xlsx</code> file in Vim, but got an error saying:</p>
<pre><code>***error*** (zip#Browse) unzip not available on your system
</code></pre>
<p>I know it's a binary file, but I want to do some checksums and probably convert to hex.</p>
<p>I noticed that if I change the extension, Vim no ... | [
{
"answer_id": 2224,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 4,
"selected": false,
"text": "<p>This seems to the the \"zip\" plugin, which is shipped with Vim and enabled by default.</p>\n\n<p><a href=\"http://v... | 2015/02/25 | [
"https://vi.stackexchange.com/questions/2223",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/475/"
] | I'm trying to open an `.xlsx` file in Vim, but got an error saying:
```
***error*** (zip#Browse) unzip not available on your system
```
I know it's a binary file, but I want to do some checksums and probably convert to hex.
I noticed that if I change the extension, Vim no longer tries to unzip it. Which leads me ... | Functionality like this is handled by [autocmds](http://vimhelp.appspot.com/usr_40.txt.html#40.3). In order to disable autocmds for a specific command, you can use `:noautocmd` (abbreviated `:noau`). In this case
```
:noau e foo.xlsx
```
will simply open the raw file rather than triggering the autocmds that try to o... |
2,232 | <p>Is there a neat way I can view binary files as hex in Vim, and save it back to binary from the hex?</p>
| [
{
"answer_id": 2234,
"author": "Khelben",
"author_id": 403,
"author_profile": "https://vi.stackexchange.com/users/403",
"pm_score": 8,
"selected": false,
"text": "<p>You can use the <code>xxd</code> command to transform a file in Vim to hex representation, doing</p>\n\n<p><code>:%!xxd</c... | 2015/02/25 | [
"https://vi.stackexchange.com/questions/2232",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/960/"
] | Is there a neat way I can view binary files as hex in Vim, and save it back to binary from the hex? | You can use the `xxd` command to transform a file in Vim to hex representation, doing
`:%!xxd`
`:` enters command-line mode, `%` matches whole file as a range, `!` filters that range through an external command, `xxd` is that external shell command
Giving an output like this, this is split into octet count/line (oct... |
2,238 | <p>In normal mode <code>(</code> and <code>)</code> move to the previous or next first character in the sentence, respectively.
How do I move to the very <em>last</em> character.</p>
<p>If all of my sentences end with a period I can use <code>)T.</code> (first character of the next sentence, then backwards to the firs... | [
{
"answer_id": 2240,
"author": "John O'M.",
"author_id": 227,
"author_profile": "https://vi.stackexchange.com/users/227",
"pm_score": 5,
"selected": true,
"text": "<p>From my research into this, you need to define at least two custom motions. The first will be for just moving the cursor,... | 2015/02/26 | [
"https://vi.stackexchange.com/questions/2238",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/141/"
] | In normal mode `(` and `)` move to the previous or next first character in the sentence, respectively.
How do I move to the very *last* character.
If all of my sentences end with a period I can use `)T.` (first character of the next sentence, then backwards to the first period) but I want a more robust solution to use... | From my research into this, you need to define at least two custom motions. The first will be for just moving the cursor, and the second will be for use in operators. For a full functioning setup, it is much more complicated, and I would recommend looking at the code in [CamelCaseMotion](http://www.vim.org/scripts/scri... |
2,248 | <p>I mostly want it to automatically create folds for between a <code>begin</code> and an <code>end</code>, although if there's anything more advanced that would be welcome too.</p>
<p>I've looked in the help for the pascal syntax and it doesn't support syntax folding.</p>
| [
{
"answer_id": 2252,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 2,
"selected": false,
"text": "<p>The easiest way to create some simple folding is using the <code>foldexpr</code> option. </p>\n\n<p>Vim runs this co... | 2015/02/26 | [
"https://vi.stackexchange.com/questions/2248",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1093/"
] | I mostly want it to automatically create folds for between a `begin` and an `end`, although if there's anything more advanced that would be welcome too.
I've looked in the help for the pascal syntax and it doesn't support syntax folding. | The following seems to patch syntax folding onto the Pascal syntax that ships with Vim. Put this into `~/.vim/after/syntax/pascal.vim`:
```
syn clear pascalLabel pascalStatement pascalStruct
syn keyword pascalLabel goto label
syn keyword pascalStatement procedure function
syn keyword pascalStatement program const... |
2,254 | <p>When writing documents occasionally I want to insert Unicode characters into the text. Sometimes I know the character code and sometimes I look it up on the web.</p>
<p>Currently I go to insert mode and then use <code><Ctrl-V>u{four digit hex number}</code>, which can be very laborious. Is there an easier way... | [
{
"answer_id": 2255,
"author": "kenorb",
"author_id": 467,
"author_profile": "https://vi.stackexchange.com/users/467",
"pm_score": 4,
"selected": false,
"text": "<p>To insert Unicode characters such as the euro or copyright symbols, or diacritical marks such as the German umlaut or accen... | 2015/02/26 | [
"https://vi.stackexchange.com/questions/2254",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/383/"
] | When writing documents occasionally I want to insert Unicode characters into the text. Sometimes I know the character code and sometimes I look it up on the web.
Currently I go to insert mode and then use `<Ctrl-V>u{four digit hex number}`, which can be very laborious. Is there an easier way of inserting the character... | **Preface**: This has nothing to do with Vim as such, but I will show you what I consider to be the "best" way to insert these characters by far; Vim's digraph system is more or less the same, but it only works with Vim. This will work in *all* applications.
**This will only work for X11 systems** (Linux, BSD, etc.). ... |
2,260 | <p>I am in the slightly unusual position of using two different keyboard layouts on a regular basis (<a href="http://www.kaufmann.no/roland/dvorak/index.html" rel="noreferrer">Programmers-Dvorak</a> and <a href="http://en.wikipedia.org/wiki/Keyboard_layout#mediaviewer/File:KB_Turkey_f_yeni.svg" rel="noreferrer">Turkish... | [
{
"answer_id": 2263,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 4,
"selected": true,
"text": "<p>Vim has something like this in the form of <em>keymaps</em>. From <code>:help mbyte-keymap</code>:</p>\n\n<blockquote>\... | 2015/02/27 | [
"https://vi.stackexchange.com/questions/2260",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/267/"
] | I am in the slightly unusual position of using two different keyboard layouts on a regular basis ([Programmers-Dvorak](http://www.kaufmann.no/roland/dvorak/index.html) and [Turkish-F](http://en.wikipedia.org/wiki/Keyboard_layout#mediaviewer/File:KB_Turkey_f_yeni.svg)). These layouts are quite different from each-other ... | Vim has something like this in the form of *keymaps*. From `:help mbyte-keymap`:
>
>
> ```
> When the keyboard doesn't produce the characters you want to enter in your
> text, you can use the 'keymap' option. This will translate one or more
> (English) characters to another (non-English) character. This only happe... |
2,261 | <p>When editing Python files at work I have to include 20+ lines of boilerplate legalese at the start of the file. "start of the file" is not that strict: I'm allowed to include the Python docstring, and future imports before the boilerplate. But the boilerplate itself is very strict, I have to include it verbatim from... | [
{
"answer_id": 2262,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 3,
"selected": true,
"text": "<p>The cleanest would be to re-implement Vim's indent-folding via a custom <code>'foldexpr'</code>, and make that consider... | 2015/02/27 | [
"https://vi.stackexchange.com/questions/2261",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/182/"
] | When editing Python files at work I have to include 20+ lines of boilerplate legalese at the start of the file. "start of the file" is not that strict: I'm allowed to include the Python docstring, and future imports before the boilerplate. But the boilerplate itself is very strict, I have to include it verbatim from a ... | The cleanest would be to re-implement Vim's indent-folding via a custom `'foldexpr'`, and make that consider the legalese via a special case. `:help fold-indent` even gives implementation hints:
>
>
> ```
> The indent() function can be used in 'foldexpr' to get the indent of a line.
>
> ```
>
>
Another option ... |
2,275 | <p>Vim's documentation has this to say about the <code>:open</code> command:</p>
<pre><code>This command is in Vi, but Vim only simulates it:
*:o* *:op* *:open*
:[range]o[pen] Works like |:visual|: end Ex mode.
... | [
{
"answer_id": 2276,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 4,
"selected": false,
"text": "<p>From <a href=\"http://ex-vi.sourceforge.net/viin/paper-7.html#section53\" rel=\"noreferrer\">An Introduction to Display Edit... | 2015/02/27 | [
"https://vi.stackexchange.com/questions/2275",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/880/"
] | Vim's documentation has this to say about the `:open` command:
```
This command is in Vi, but Vim only simulates it:
*:o* *:op* *:open*
:[range]o[pen] Works like |:visual|: end Ex mode.
{Vi: start editing in o... | The "open mode" of vi was useful for terminals that had a single line, such as hardcopy terminals. In open mode, vi had a "single line view" of the file. Moving the cursor around would redraw the entire line, and deleted characters printed differently.
The "simulation" that vim does is simply supporting the command, ... |
2,278 | <p>Lets say I want to produce the following text in my document:</p>
<pre><code>%
% Not Important
% O ------------------------->
% |
% S |
% o |
% m |
% e |
% |
% M |
% s |
% g |
% |
% V
</code></pre>
<p>Is there any easy way of writing the "Some Msg" vertically as above without ha... | [
{
"answer_id": 2289,
"author": "xaizek",
"author_id": 860,
"author_profile": "https://vi.stackexchange.com/users/860",
"pm_score": 5,
"selected": true,
"text": "<p>Really good solution would probably require some more work, but \"not bad\" is\nnot very hard to achieve.</p>\n\n<h3>Idea</h... | 2015/02/28 | [
"https://vi.stackexchange.com/questions/2278",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/669/"
] | Lets say I want to produce the following text in my document:
```
%
% Not Important
% O ------------------------->
% |
% S |
% o |
% m |
% e |
% |
% M |
% s |
% g |
% |
% V
```
Is there any easy way of writing the "Some Msg" vertically as above without having to manually insert each ... | Really good solution would probably require some more work, but "not bad" is
not very hard to achieve.
### Idea
All we need is to move one line down after each character, so let's do just
that via `InsertCharPre` auto-command!
### Code
Put it into `.vimrc` or better yet to some file under `plugin/` directory.
```
... |
2,280 | <p><strong>Is there a way to hide all lines that did not match, while going through the list of result lines?</strong></p>
<p>In a long file, I would like to search for a pattern that will match roughly 200 lines or so. The matched lines are in random places in the file.<br />
When a line matches, only the line itself ... | [
{
"answer_id": 2281,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 3,
"selected": false,
"text": "<p>If order doesn't matter then just move the lines.</p>\n\n<pre><code>:g/pat/m0\n</code></pre>\n\n<p>For more help see... | 2015/02/28 | [
"https://vi.stackexchange.com/questions/2280",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/925/"
] | **Is there a way to hide all lines that did not match, while going through the list of result lines?**
In a long file, I would like to search for a pattern that will match roughly 200 lines or so. The matched lines are in random places in the file.
When a line matches, only the line itself is relevant, no context a... | ```
:vimgrep pattern %
:cwindow
```
[`vimgrep`](http://vimhelp.appspot.com/quickfix.txt.html#grep) will search for your pattern in the current file (`%`), or whatever files you specify.
[`cwindow`](http://vimhelp.appspot.com/quickfix.txt.html#%3Acwin) will then open a buffer in your window that will only show the de... |
2,286 | <p><a href="https://vi.stackexchange.com/questions/454/whats-the-simplest-way-to-strip-trailing-whitespace-from-all-lines-in-a-file/2285#2285">In answering a question just now</a>, I mentioned using a normal mode key mapping that can be found at <a href="https://vim.fandom.com/wiki/Vim_Tips_Wiki" rel="nofollow noreferr... | [
{
"answer_id": 2287,
"author": "Bernhard",
"author_id": 66,
"author_profile": "https://vi.stackexchange.com/users/66",
"pm_score": 3,
"selected": false,
"text": "<p>If you type</p>\n\n<pre><code>:help <Bar>\n</code></pre>\n\n<p>you will read that</p>\n\n<pre><code><Bar> ... | 2015/02/28 | [
"https://vi.stackexchange.com/questions/2286",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1111/"
] | [In answering a question just now](https://vi.stackexchange.com/questions/454/whats-the-simplest-way-to-strip-trailing-whitespace-from-all-lines-in-a-file/2285#2285), I mentioned using a normal mode key mapping that can be found at [the Vim Tips Wiki](https://vim.fandom.com/wiki/Vim_Tips_Wiki). In the middle of explain... | It's the code for [the pipe character](http://vimhelp.appspot.com/intro.txt.html#%3CBar%3E): `|`. The pipe is used the way the semicolon is used in C-style languages, as a statement separator. You cannot use it directly in a mapping, since it would be seen as marking the end of the mapping. Hence, the code has to be us... |
2,322 | <p>How can I store a series of search and replace statements so I can run them later in sequence? </p>
<p>Possibly after I have close and re-opened vim...</p>
<p>For instance I might run the following in sequence to convert a pasted table into a wiki formatted table with headers:</p>
<ul>
<li><code>1,1s/^\|\t/|!/g<... | [
{
"answer_id": 2324,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 3,
"selected": false,
"text": "<p>You can run all of them in the same command by joining them with a <code>|</code> (vertical bar):</p>\n\n<pre><code>:1,1s/^... | 2015/03/02 | [
"https://vi.stackexchange.com/questions/2322",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1065/"
] | How can I store a series of search and replace statements so I can run them later in sequence?
Possibly after I have close and re-opened vim...
For instance I might run the following in sequence to convert a pasted table into a wiki formatted table with headers:
* `1,1s/^\|\t/|!/g`
* `1,1s/$/|/g`
* `2,$s/^\|\t/|/g`... | Put them in a function (into your vimrc or a file in the plugin folder):
```
function! Stuff()
1,1s/^\|\t/|!/g
1,1s/$/|/g
2,$s/^\|\t/|/g
2,$s/$/|/g
endfunction
```
You can then use `:call Stuff()<cr>` to run them or make a custom command:
```
command DoStuff call Stuff()
```
And just do `:DoStuff<... |
2,328 | <p>For example, I'd like to set</p>
<pre><code>set tabstop=4
set shiftwidth=4
</code></pre>
<p>Is there a way to do something like</p>
<pre><code>set tabstop=4
set shiftwidth=tabstop
</code></pre>
<p>so I can set both values by only changing a single number?</p>
| [
{
"answer_id": 2329,
"author": "Steve Vermeulen",
"author_id": 132,
"author_profile": "https://vi.stackexchange.com/users/132",
"pm_score": 2,
"selected": false,
"text": "<p>Might be a better way but you could always do this:</p>\n\n<p><code>exec 'set shiftwidth=' . &tabstop</code></... | 2015/03/03 | [
"https://vi.stackexchange.com/questions/2328",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/200/"
] | For example, I'd like to set
```
set tabstop=4
set shiftwidth=4
```
Is there a way to do something like
```
set tabstop=4
set shiftwidth=tabstop
```
so I can set both values by only changing a single number? | You can use the `let` command instead.
Like so:
`let &shiftwidth = &tabstop`
The `&` specifies that the variable name is a Vim option. You can also do `:help let-option` to know more about it:
```
:let &{option-name} = {expr1}
Set option {option-name} to the result of the
expression {expr1}. A Stri... |
2,331 | <p>How can I start a build with my <code>makeprg</code> running in a different directory than the working directory of vim and still catch errors in quickfix so that I can jump between them?</p>
<p>The problem is that quickfix doesn't know how to find the error locations as reported by the <code>makeprg</code> due to ... | [
{
"answer_id": 2332,
"author": "Praxeolitic",
"author_id": 268,
"author_profile": "https://vi.stackexchange.com/users/268",
"pm_score": 3,
"selected": true,
"text": "<p>Make and Ninja offer a <code>-C</code> flag. From Ninja:</p>\n\n<pre><code>-C DIR change to DIR before doing anything... | 2015/03/03 | [
"https://vi.stackexchange.com/questions/2331",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/268/"
] | How can I start a build with my `makeprg` running in a different directory than the working directory of vim and still catch errors in quickfix so that I can jump between them?
The problem is that quickfix doesn't know how to find the error locations as reported by the `makeprg` due to the different paths. (The partic... | Make and Ninja offer a `-C` flag. From Ninja:
```
-C DIR change to DIR before doing anything else
```
If I run Ninja in a shell with the `-C` flag pointing somewhere that isn't the working directory, then the reported paths are the same as if I had `cd`'d over to the build directory. Nonetheless, Vim knows to beco... |
2,340 | <p>I am looking for a <code>g8</code> equivalent that prints the hex values of the character under the cursor according to the file encoding of the file loaded in a buffer rather than assuming it's utf-8.</p>
<p>Is there such a thing?</p>
| [
{
"answer_id": 2369,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 3,
"selected": true,
"text": "<p>There's nothing built-in, but the following mapping seems to do the trick.</p>\n\n<pre><code>\" g9 Print... | 2015/03/03 | [
"https://vi.stackexchange.com/questions/2340",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/985/"
] | I am looking for a `g8` equivalent that prints the hex values of the character under the cursor according to the file encoding of the file loaded in a buffer rather than assuming it's utf-8.
Is there such a thing? | There's nothing built-in, but the following mapping seems to do the trick.
```
" g9 Print the hex values of the bytes used in the
" character under the cursor / selected text, using the
" actual 'fileencoding' of the buffer.
function! s:ShowHexFileEncodingCharacter( i... |
2,347 | <p>I am very new to vim and would like to know if I could have a script in my <code>vimrc</code> file that automatically adds a <code>;</code> to the end of every line.</p>
<p>The only exceptions is if the line has the strings <code>for(</code>, <code>while(</code>, <code>#include</code>, <code>//</code>, <code>/*</co... | [
{
"answer_id": 2348,
"author": "Matt Boehm",
"author_id": 680,
"author_profile": "https://vi.stackexchange.com/users/680",
"pm_score": 4,
"selected": true,
"text": "<p>As has been stated, your list of exceptions is by no means comprehensive and you will probably find that this often crea... | 2015/03/03 | [
"https://vi.stackexchange.com/questions/2347",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1168/"
] | I am very new to vim and would like to know if I could have a script in my `vimrc` file that automatically adds a `;` to the end of every line.
The only exceptions is if the line has the strings `for(`, `while(`, `#include`, `//`, `/*`, `*/` etc.
I would like this to be turned on by default and toggled on and off via... | As has been stated, your list of exceptions is by no means comprehensive and you will probably find that this often creates more problems than it solves.
However, it's still doable and it was kind of fun to write out the code to do so, so here goes:
```
"When hitting Enter, if the line doesn't start with a /*, insert... |
2,350 | <p>I'm trying to map <kbd>Alt</kbd> key in the following way:</p>
<pre><code>:map <A-j> j
:map <A-k> k
</code></pre>
<p>but it doesn't work (bell is rang on <kbd>Alt + j</kbd>/<kbd>Alt + k</kbd>).</p>
<p>What am I missing?</p>
<p>I'm using Terminal on OSX, the same happens on remote Linux.</p>
<hr>
<p... | [
{
"answer_id": 2361,
"author": "kenorb",
"author_id": 467,
"author_profile": "https://vi.stackexchange.com/users/467",
"pm_score": 4,
"selected": false,
"text": "<p>With help of <a href=\"https://vi.stackexchange.com/questions/2350/how-to-map-alt-key#comment2107_2350\">Carpetsmoker</a>, ... | 2015/03/03 | [
"https://vi.stackexchange.com/questions/2350",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/467/"
] | I'm trying to map `Alt` key in the following way:
```
:map <A-j> j
:map <A-k> k
```
but it doesn't work (bell is rang on `Alt + j`/`Alt + k`).
What am I missing?
I'm using Terminal on OSX, the same happens on remote Linux.
---
On `Ctrl + v`, `Alt + j`, I've got: `?~H~F` (`∆` when `encoding=utf-8`).
On `Ctrl + v... | That's how I do it on Linux or Cygwin:
First check what chars are sent by your terminal when you press `ALT`+`J`:
In order to do this I go to console and run `sed -n l` (you can also use `cat` for it). Then I press `ALT`+`J` and see that the chars on the screen are `^[j` .
I replace `^[` with `\e` (because that's wh... |
2,358 | <p>Can I integrate some form of symbol completion to Vim? Dedicated TeX editors like TeXMaker provide a list of symbols for completion (for example, <code>\al</code> shows a list with <code>\alpha</code>, <code>\la</code> shows <code>\lambda</code> and <code>\langle</code>).</p>
<p>Please note that TeX has a rather la... | [
{
"answer_id": 2359,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 1,
"selected": false,
"text": "<p>You could use a snippet completion plugin like <a href=\"https://github.com/garbas/vim-snipmate\" rel=\"nofollow\">Snipmate<... | 2015/03/04 | [
"https://vi.stackexchange.com/questions/2358",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/205/"
] | Can I integrate some form of symbol completion to Vim? Dedicated TeX editors like TeXMaker provide a list of symbols for completion (for example, `\al` shows a list with `\alpha`, `\la` shows `\lambda` and `\langle`).
Please note that TeX has a rather large number of symbols, so suggestions involving manual mapping of... | To expand commands in LaTeX, I use a dictionary copied from [latex-suite](https://github.com/gerw/vim-latex-suite) (in details, [this one](https://github.com/gerw/vim-latex-suite/blob/master/ftplugin/latex-suite/dictionaries/dictionary)) and put it in `~/.vim/dictionaries` and then using
```
autocmd FileType * exec("s... |
2,365 | <p>Vim has (at least) two sets of commands that search in opposite directions. Typing <code>/</code> and then a pattern will search forward through the document for the pattern; typing <code>?</code> and then a pattern will search backward. The same relationship exists between the <code>*</code> and <code>#</code> comm... | [
{
"answer_id": 2366,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 6,
"selected": true,
"text": "<p>You can change the behaviour of <code>n</code> and <code>N</code> to search consistently downwards/upwards by usei... | 2015/03/04 | [
"https://vi.stackexchange.com/questions/2365",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/671/"
] | Vim has (at least) two sets of commands that search in opposite directions. Typing `/` and then a pattern will search forward through the document for the pattern; typing `?` and then a pattern will search backward. The same relationship exists between the `*` and `#` commands.
What I don’t like is that these commands... | You can change the behaviour of `n` and `N` to search consistently downwards/upwards by useing the following:
```
nnoremap <expr> n 'Nn'[v:searchforward]
nnoremap <expr> N 'nN'[v:searchforward]
```
**Update:** How does it work?
This uses expression-maps, which maps the lhs of the map to an expression that will be e... |
2,378 | <p>I want to have my .vimrc synced through github so it has to be public file, but at the same time i have to put some sensitive data (for example db passwords/hosts for dbext.vim) in it, without giving them away to others. What is the best way and how to do it?</p>
| [
{
"answer_id": 2379,
"author": "alexia",
"author_id": 1230,
"author_profile": "https://vi.stackexchange.com/users/1230",
"pm_score": 6,
"selected": true,
"text": "<p>You can include another file using the <code>source</code> command. Simply put this at the top of your vimrc:</p>\n\n<pre>... | 2015/03/05 | [
"https://vi.stackexchange.com/questions/2378",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1067/"
] | I want to have my .vimrc synced through github so it has to be public file, but at the same time i have to put some sensitive data (for example db passwords/hosts for dbext.vim) in it, without giving them away to others. What is the best way and how to do it? | You can include another file using the `source` command. Simply put this at the top of your vimrc:
```
source($MYVIMRC . ".private")
```
Assuming your vimrc is `~/.vimrc`, that will expand to `~/.vimrc.private`. From now on, you can define variables in that file like this:
```
let my_db_password = "bacon"
```
The... |
2,387 | <p>Recently on starting vim I've been getting an error message like this:</p>
<pre><code>E575: viminfo: Illegal starting char in line: wait_until(lambda
_:<80><fc>^B ^[ldWA)^[:w^Mkkkdd^[:w^M<80><fd>c<80><fd>b248Gwwi_zzz^[:w^M<80><fd>c<80><fd>bkkkkj/refresh^M^... | [
{
"answer_id": 2388,
"author": "Andrew Magee",
"author_id": 1079,
"author_profile": "https://vi.stackexchange.com/users/1079",
"pm_score": 5,
"selected": true,
"text": "<p>Turns out the answer was in the error message all along.. the offending file was <code>~/.viminfo</code> which was s... | 2015/03/06 | [
"https://vi.stackexchange.com/questions/2387",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1079/"
] | Recently on starting vim I've been getting an error message like this:
```
E575: viminfo: Illegal starting char in line: wait_until(lambda
_:<80><fc>^B ^[ldWA)^[:w^Mkkkdd^[:w^M<80><fd>c<80><fd>b248Gwwi_zzz^[:w^M<80><fd>c<80><fd>bkkkkj/refresh^M^c^[ma/browser.rfer<80>kb<80>kb<80>kbresh^[/refresh^MnN^ceb<80>kbdrie<80>kb... | Turns out the answer was in the error message all along.. the offending file was `~/.viminfo` which was somehow corrupted. |
2,396 | <p>I use windows XP for testing and running some programs. I installed Vim on the machine, but when I run <code>vimdiff</code> on two files, I get the following error:</p>
<pre><code>'""C:\Program' is not recognized as an internal or external command,
operable program or batch file.
</code></pre>
<p>along with errors... | [
{
"answer_id": 2421,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 2,
"selected": false,
"text": "<p>I can reproduce the problem on my Windows 7 VM, I installed gVim, clicked the \"install .bat files for commandline u... | 2015/03/06 | [
"https://vi.stackexchange.com/questions/2396",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/342/"
] | I use windows XP for testing and running some programs. I installed Vim on the machine, but when I run `vimdiff` on two files, I get the following error:
```
'""C:\Program' is not recognized as an internal or external command,
operable program or batch file.
```
along with errors [E810 and E97](http://vimhelp.appspo... | **Getting a fixed Vim**
This specific bug was fixed in [7.4.103](https://code.google.com/p/vim/source/detail?r=v7-4-103) back in 2013. Bram typically only publishes Windows installers on vim.org for major releases, so the installer there doesn't have this fix.
The [Cream](http://sourceforge.net/projects/cream/) proje... |
2,403 | <p>I am running Debian Jessie and use the current vim-nox (with +python -python3). I am having a hard time trying to program in Python 3, as I struggle with Python 3 code completion.</p>
<p>YouCompleteMe doesn't support Python3 at all. jedi-vim does support Python 3 completion, but only if I would have the +python3 op... | [
{
"answer_id": 2404,
"author": "akshay",
"author_id": 246,
"author_profile": "https://vi.stackexchange.com/users/246",
"pm_score": 5,
"selected": true,
"text": "<p>The ideal way is to get Vim's source and compile it yourself. </p>\n\n<p>Step 1: For Debian-like systems, get the required p... | 2015/03/07 | [
"https://vi.stackexchange.com/questions/2403",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1256/"
] | I am running Debian Jessie and use the current vim-nox (with +python -python3). I am having a hard time trying to program in Python 3, as I struggle with Python 3 code completion.
YouCompleteMe doesn't support Python3 at all. jedi-vim does support Python 3 completion, but only if I would have the +python3 option if I ... | The ideal way is to get Vim's source and compile it yourself.
Step 1: For Debian-like systems, get the required packages:
```
sudo apt-get build-dep vim
```
Step 2: Clone Vim's source code:
```
cd /tmp && git clone https://github.com/vim/vim.git && cd vim
```
Step 3: Configure, Make, Install
```
./configure --... |
2,410 | <p>I want to make a function that has optional arguments.</p>
<p>In python I would do something like this:</p>
<pre><code>def functionName(arg1,arg2=false,arg3=false):
if arg2:
#Do stuff with arguments
else:
#Do stuff without arguments
</code></pre>
<p>I have tried doing <code>function Functi... | [
{
"answer_id": 2411,
"author": "EvergreenTree",
"author_id": 865,
"author_profile": "https://vi.stackexchange.com/users/865",
"pm_score": 7,
"selected": true,
"text": "<p>Yes, you can take optional arguments in a function. It is not as convenient as python's way of doing it, but this is... | 2015/03/07 | [
"https://vi.stackexchange.com/questions/2410",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1168/"
] | I want to make a function that has optional arguments.
In python I would do something like this:
```
def functionName(arg1,arg2=false,arg3=false):
if arg2:
#Do stuff with arguments
else:
#Do stuff without arguments
```
I have tried doing `function FunctionName(arg1,arg2=false,arg3=false)`, b... | Yes, you can take optional arguments in a function. It is not as convenient as python's way of doing it, but this is how you do it:
```
function FooBar(...) " This is like *args in python
echom a:0 " a:0 contains an integer which is the number of arguments passed to the function
echom a:1 " a:1 contains the fi... |
2,419 | <p>I am trying to map <kbd>Ctrl</kbd>+<kbd>s</kbd> to save my file however it does not work.</p>
<p>My mappings:</p>
<pre><code>map <C-s> :w <CR> :echo "Saved" <CR>
imap <C-s> <Esc> :w <CR> :echo "Saved" <CR> i
</code></pre>
<p>When in insert mode I see <code>/:echo "Saved"<... | [
{
"answer_id": 2422,
"author": "iProgram",
"author_id": 1168,
"author_profile": "https://vi.stackexchange.com/users/1168",
"pm_score": 2,
"selected": false,
"text": "<p>Thanks to @Carpetsmoker for the links.</p>\n\n<p>Adding this script into <code>bash_profile</code> worked for me.</p>\n... | 2015/03/07 | [
"https://vi.stackexchange.com/questions/2419",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1168/"
] | I am trying to map `Ctrl`+`s` to save my file however it does not work.
My mappings:
```
map <C-s> :w <CR> :echo "Saved" <CR>
imap <C-s> <Esc> :w <CR> :echo "Saved" <CR> i
```
When in insert mode I see `/:echo "Saved"` in the bottom corner instead of `saved` and when I am in normal mode I see the same thing. What a... | To ensure that this workaround runs even when Vim is started by a **separate tool** (such as git), I have this in my `~/.vimrc`:
```
" Allow us to use Ctrl-s and Ctrl-q as keybinds
silent !stty -ixon
" Restore default behaviour when leaving Vim.
autocmd VimLeave * silent !stty ixon
```
This has been working for me ... |
2,423 | <p>Depending on how I launch Vim, suspending with <code><C-z></code> or with <code>:suspend</code> causes Vim to drop into an empty terminal (no shell) and get stuck there. I know I can unmap <code><C-z></code> like so <code>map <C-z> <Nop></code> but is there a way I can prevent <code>:suspend<... | [
{
"answer_id": 2422,
"author": "iProgram",
"author_id": 1168,
"author_profile": "https://vi.stackexchange.com/users/1168",
"pm_score": 2,
"selected": false,
"text": "<p>Thanks to @Carpetsmoker for the links.</p>\n\n<p>Adding this script into <code>bash_profile</code> worked for me.</p>\n... | 2015/03/07 | [
"https://vi.stackexchange.com/questions/2423",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/200/"
] | Depending on how I launch Vim, suspending with `<C-z>` or with `:suspend` causes Vim to drop into an empty terminal (no shell) and get stuck there. I know I can unmap `<C-z>` like so `map <C-z> <Nop>` but is there a way I can prevent `:suspend` from running? Or redefine it to be an empty function?
I *don't* want to ru... | To ensure that this workaround runs even when Vim is started by a **separate tool** (such as git), I have this in my `~/.vimrc`:
```
" Allow us to use Ctrl-s and Ctrl-q as keybinds
silent !stty -ixon
" Restore default behaviour when leaving Vim.
autocmd VimLeave * silent !stty ixon
```
This has been working for me ... |
2,428 | <p>My project has these files:</p>
<pre><code>$ find . -type f -and -name 'peop*'
./app/assets/stylesheets/admin/sections/people.css.sass
./app/controllers/admin/people_controller.rb
</code></pre>
<p>As I got tired of typing <code>:e app/assets/stylesheets/admin/sections/people.css.sass</code>, I thought that <a href... | [
{
"answer_id": 2449,
"author": "Collin Peters",
"author_id": 19,
"author_profile": "https://vi.stackexchange.com/users/19",
"pm_score": 3,
"selected": false,
"text": "<p>A similar question was just asked on the Vim reddit <a href=\"http://www.reddit.com/r/vim/comments/2yg5ss/has_your_ctr... | 2015/03/08 | [
"https://vi.stackexchange.com/questions/2428",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/51/"
] | My project has these files:
```
$ find . -type f -and -name 'peop*'
./app/assets/stylesheets/admin/sections/people.css.sass
./app/controllers/admin/people_controller.rb
```
As I got tired of typing `:e app/assets/stylesheets/admin/sections/people.css.sass`, I thought that [ctrlp](https://github.com/kien/ctrlp.vim) m... | A similar question was just asked on the Vim reddit [here](http://www.reddit.com/r/vim/comments/2yg5ss/has_your_ctrlp_gotten_slow_change_the_indexer_and/). I started using [ctrlp-cmatcher](https://github.com/JazzCore/ctrlp-cmatcher/) myself quite awhile ago which I find to be much more intelligent at matching the right... |
2,429 | <p>Is there a way to get the name and extension of a file using vimscript?</p>
<p>If so I would like the name and extension separately. </p>
| [
{
"answer_id": 2430,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 5,
"selected": false,
"text": "<p>From <a href=\"http://vimhelp.appspot.com/cmdline.txt.html#filename-modifiers\"><code>:he filename-modifiers</code></a>:</p>\... | 2015/03/08 | [
"https://vi.stackexchange.com/questions/2429",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1168/"
] | Is there a way to get the name and extension of a file using vimscript?
If so I would like the name and extension separately. | From [`:he filename-modifiers`](http://vimhelp.appspot.com/cmdline.txt.html#filename-modifiers):
```
:t Tail of the file name (last component of the name). Must
precede any :r or :e.
:r Root of the file name (the last extension removed). When
there is only an extension (file... |
2,432 | <p>When using Vim you can use <code>:Explore</code> to browser through files and folders.</p>
<p>Is there a simple way to start Vim in "Explore mode" from the terminal? Can I do this by just giving Vim some argument?</p>
| [
{
"answer_id": 2433,
"author": "EvergreenTree",
"author_id": 865,
"author_profile": "https://vi.stackexchange.com/users/865",
"pm_score": 4,
"selected": false,
"text": "<p>The \"Explore Mode\" you are talking about is netrw, a vim plugin which is provided by default. It should open in t... | 2015/03/09 | [
"https://vi.stackexchange.com/questions/2432",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/356/"
] | When using Vim you can use `:Explore` to browser through files and folders.
Is there a simple way to start Vim in "Explore mode" from the terminal? Can I do this by just giving Vim some argument? | Alternatively (the passing of directory argument(s) as in @EvergreenTree's answer relies on the autocmds of the netrw plugin, and aren't a general solution), you can pass any Ex command to Vim on startup via the `-c` argument:
```
$ vim -c Explore
```
You can also use `+`, which is exactly the same as `-c`, except s... |
2,434 | <p>I'm using <code>vim</code> from a terminal emulator, and I'd like to be able to print using KDE's native print dialogue. This would let me select options such as printer, collating, number of copies and pages per piece of paper.</p>
<p>(There is an older tip <a href="http://vim.wikia.com/wiki/Printing_using_kprinte... | [
{
"answer_id": 2435,
"author": "John O'M.",
"author_id": 227,
"author_profile": "https://vi.stackexchange.com/users/227",
"pm_score": 4,
"selected": true,
"text": "<p>The loss of kprinter in the move to kde4 was one of the reasons I stuck with kde3 for as long as I could.</p>\n\n<p>After... | 2015/03/09 | [
"https://vi.stackexchange.com/questions/2434",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1278/"
] | I'm using `vim` from a terminal emulator, and I'd like to be able to print using KDE's native print dialogue. This would let me select options such as printer, collating, number of copies and pages per piece of paper.
(There is an older tip [here](http://vim.wikia.com/wiki/Printing_using_kprinter) explaining how to li... | The loss of kprinter in the move to kde4 was one of the reasons I stuck with kde3 for as long as I could.
After some searching, I found this "3rd party" replacement: <http://kde-apps.org/content/show.php/KPrinter4?content=163537>, <https://github.com/credativ/kprinter4>.
It looks like you have to compile it yourself ... |
2,436 | <p>I installed Cygwin/x on my PC, and I've set the terminal to xterm-256. But when I start vim from cygwin terminal, the look and feel of the same color scheme is different on cygwin and gvim. gvim always looks more pleasant, more clear. How can I make the look and feel of vim in cygwin be the same as gvim?</p>
<p><im... | [
{
"answer_id": 2442,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 4,
"selected": true,
"text": "<h3>Cygwin terminal limitations</h3>\n\n<p>The default Cygwin terminal is based on the Windows console and inherits its li... | 2015/03/09 | [
"https://vi.stackexchange.com/questions/2436",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1276/"
] | I installed Cygwin/x on my PC, and I've set the terminal to xterm-256. But when I start vim from cygwin terminal, the look and feel of the same color scheme is different on cygwin and gvim. gvim always looks more pleasant, more clear. How can I make the look and feel of vim in cygwin be the same as gvim?
![enter image... | ### Cygwin terminal limitations
The default Cygwin terminal is based on the Windows console and inherits its limitations (very few colors, no font styles like bold or italic). You can find out how many colors are available to Vim via
```
:set t_Co?
```
For me, that gives a meager `8`. To get 256 colors, you need to... |
2,438 | <p>Recently I learned from <a href="http://rads.stackoverflow.com/amzn/click/1934356980">Practical Vim</a> a way to copy or move block of lines without having to move the cursor from the current position. This is done in command line mode. e.g.</p>
<pre><code>:123,133m. # moves lines from 123 to 133 below the cursor ... | [
{
"answer_id": 2439,
"author": "joeytwiddle",
"author_id": 630,
"author_profile": "https://vi.stackexchange.com/users/630",
"pm_score": 6,
"selected": true,
"text": "<p>Assuming your lines span from 15 to 10 lines above the current one, you can achieve what you requested using relative l... | 2015/03/09 | [
"https://vi.stackexchange.com/questions/2438",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1283/"
] | Recently I learned from [Practical Vim](http://rads.stackoverflow.com/amzn/click/1934356980) a way to copy or move block of lines without having to move the cursor from the current position. This is done in command line mode. e.g.
```
:123,133m. # moves lines from 123 to 133 below the cursor position.
```
While I l... | Assuming your lines span from 15 to 10 lines above the current one, you can achieve what you requested using relative line numbers:
```
:-10,-15m.
```
Unfortunately when specifying a backwards range, Vim asks you to confirm if that is what you really wanted. To avoid the confirmation step, you can type `silent` befo... |
2,453 | <p>One thing I need to do frequently is to increment the <em>2nd</em> number on a line. Increasing the first is very comfortable by just pressing <kbd>Control-a</kbd>, but I just can't find a nice way to increase the 2nd.</p>
<p>There is no useful substring (as in, a word or a token or whatever) in that line that I ca... | [
{
"answer_id": 2454,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 2,
"selected": false,
"text": "<p>I'm not sure if this is the 'best' way, but 'a' way would be to create a mapping like this:</p>\n\n<pre><code>norema... | 2015/03/09 | [
"https://vi.stackexchange.com/questions/2453",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1296/"
] | One thing I need to do frequently is to increment the *2nd* number on a line. Increasing the first is very comfortable by just pressing `Control-a`, but I just can't find a nice way to increase the 2nd.
There is no useful substring (as in, a word or a token or whatever) in that line that I can use for searches or jump... | I mean, it's basically a hack, but assuming you're at the start of the line with the number on it:
```
<C-A><C-X>w<C-A>
```
Go to the next number, increment it, decrement it, go to the start of the next word, increment the next number. This jumps past and increments the second number. Unfortunately it's not easy to ... |
2,462 | <p>Is there a way I can move my cursor to the middle of the current line? By middle, I don't mean the middle of the screen, but the middle of the line of text, regardless of length.</p>
<p>The shortcut <kbd>M</kbd> moves the cursor to the middle of the screen - is there an equivalent shortcut to move the cursor to the ... | [
{
"answer_id": 2463,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 5,
"selected": true,
"text": "<p>I don't know of any builtin ways to do this. However, you can easily make a map to do it:</p>\n<pre><code>nnoremap µ :... | 2015/03/10 | [
"https://vi.stackexchange.com/questions/2462",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/53/"
] | Is there a way I can move my cursor to the middle of the current line? By middle, I don't mean the middle of the screen, but the middle of the line of text, regardless of length.
The shortcut `M` moves the cursor to the middle of the screen - is there an equivalent shortcut to move the cursor to the middle of the line... | I don't know of any builtin ways to do this. However, you can easily make a map to do it:
```
nnoremap µ :exe 'normal! '.(virtcol('$')/2).'\|'<cr>
```
Ingo Karkat proposed the following variant [in the comments](https://vi.stackexchange.com/questions/2462/how-do-i-move-the-cursor-to-the-center-of-current-line#commen... |
2,470 | <p>I learned about <a href="https://vi.stackexchange.com/a/189/1111">using <code>:profile</code> here</a>, so I just tried to install vim with profiling enabled. </p>
<p>I tried this:</p>
<pre><code>./configure --prefix=/home/username --with-features=profile
</code></pre>
<p>But in the output from configure I got th... | [
{
"answer_id": 2471,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 2,
"selected": false,
"text": "<p><code>--with-features=profile</code> doesn't seem to be valid option; <code>:help profile</code> says:</p>\n\n<block... | 2015/03/10 | [
"https://vi.stackexchange.com/questions/2470",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1111/"
] | I learned about [using `:profile` here](https://vi.stackexchange.com/a/189/1111), so I just tried to install vim with profiling enabled.
I tried this:
```
./configure --prefix=/home/username --with-features=profile
```
But in the output from configure I got the message
```
Sorry, profile is not supported
```
Do... | I don't think you can enable the *profile* feature via `./configure`; you either have to define `FEAT_PROFILE` or simply build a *huge* version of Vim, which then includes that feature. From `src/feature.h`:
```
/*
* +profile Profiling for functions and scripts.
*/
#if defined(FEAT_HUGE) \
&& defined(FEAT... |
2,473 | <p>Let us say we have the following <code>for</code> loop in Vim:</p>
<pre><code>for(int i = 0; i < len; ++i);
</code></pre>
<p>and I want to change the variable <code>i</code> to <code>j</code>.</p>
<p>I have to do it manually for each <code>i</code>. Is there a way in Vim so that when I change one <code>i</code... | [
{
"answer_id": 2474,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 2,
"selected": false,
"text": "<p>You could do it with a substitution:</p>\n\n<pre><code>:5,20s/\\<i\\>/j/g\n</code></pre>\n\n<ul>\n<li><code>5,20</code>... | 2015/03/10 | [
"https://vi.stackexchange.com/questions/2473",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1305/"
] | Let us say we have the following `for` loop in Vim:
```
for(int i = 0; i < len; ++i);
```
and I want to change the variable `i` to `j`.
I have to do it manually for each `i`. Is there a way in Vim so that when I change one `i`, and it also changes the rest?
I use ultisnips and when I create a `for` loop for exampl... | You can use the `:substitute` command (optionally with a suitable `[range]` if the loop variable is spread over multiple lines) with the `g` flag to replace all occurrences:
```
:s/\<i\>/j/g
```
Note the `\<...\>` for a *full word* match (to avoid changing `int` to `jnt`).
### Plugin suggestion
My [ChangeGlobally ... |
2,479 | <p>From time to time I do a <code>source</code> of a script and N errors and warnings manifest. As the errors/warnings show it is impossible to scroll buffer/window. Cursor, at least in gvim is a bold white <code>x</code>.</p>
<p>The <em>log</em> part of Vim is typically:</p>
<pre><code> Error detected while process... | [
{
"answer_id": 2474,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 2,
"selected": false,
"text": "<p>You could do it with a substitution:</p>\n\n<pre><code>:5,20s/\\<i\\>/j/g\n</code></pre>\n\n<ul>\n<li><code>5,20</code>... | 2015/03/10 | [
"https://vi.stackexchange.com/questions/2479",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/220/"
] | From time to time I do a `source` of a script and N errors and warnings manifest. As the errors/warnings show it is impossible to scroll buffer/window. Cursor, at least in gvim is a bold white `x`.
The *log* part of Vim is typically:
```
Error detected while processing function Foo:
line 16:
E123: blah
E456: bla... | You can use the `:substitute` command (optionally with a suitable `[range]` if the loop variable is spread over multiple lines) with the `g` flag to replace all occurrences:
```
:s/\<i\>/j/g
```
Note the `\<...\>` for a *full word* match (to avoid changing `int` to `jnt`).
### Plugin suggestion
My [ChangeGlobally ... |
2,493 | <p>I recently removed the YankRing plugin from my setup partly because it was causing some problems with macros, but mostly because I decided it would be better to train myself to use Vim's registers instead — in particular, the way that deleted text is stored initially in register <code>"1</code> a... | [
{
"answer_id": 2494,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 4,
"selected": false,
"text": "<p>This used to work in older Vim 7.3 versions when you <code>:set clipboard=unnamed</code> (see <a href=\"http://www.red... | 2015/03/11 | [
"https://vi.stackexchange.com/questions/2493",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/343/"
] | I recently removed the YankRing plugin from my setup partly because it was causing some problems with macros, but mostly because I decided it would be better to train myself to use Vim's registers instead — in particular, the way that deleted text is stored initially in register `"1` and then shifted up through `"2`, `... | As of version 8.0.1394, you can implement this as an autocommand that hooks into the new TextYankPost autocommand. This is somewhat cleaner than my [previous map-based answer](https://vi.stackexchange.com/a/2511/343), and works regardless of what keystrokes you use for deleting:
```
if exists("##TextYankPost")
funct... |
2,495 | <p>I installed <a href="https://github.com/marijnh/tern_for_vim" rel="nofollow">ternjs_for_vim</a> plugin but can't figure out how to use it properly. RTFM didn't help. What I get is list random JS-methods in the omni-completion. But things like completing for Node.JS modules doesn't work. For example if I type:</p>
<... | [
{
"answer_id": 2496,
"author": "jamessan",
"author_id": 15,
"author_profile": "https://vi.stackexchange.com/users/15",
"pm_score": 1,
"selected": false,
"text": "<p>The documentation states (emphasis added):</p>\n\n<blockquote>\n <p>In JavaScript files, the package will hook into <stron... | 2015/03/11 | [
"https://vi.stackexchange.com/questions/2495",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/500/"
] | I installed [ternjs\_for\_vim](https://github.com/marijnh/tern_for_vim) plugin but can't figure out how to use it properly. RTFM didn't help. What I get is list random JS-methods in the omni-completion. But things like completing for Node.JS modules doesn't work. For example if I type:
```
var fs = require('fs');
fs.
... | Actually, there was a problem in my .vimrc config.
A long time ago I created some settings regarding Omni completion and forgot about them. So I just deleted this lines from my config:
```
set ofu=syntaxcomplete#Complete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set om... |
2,505 | <p>I use <a href="https://github.com/Valloric/YouCompleteMe" rel="nofollow">YouCompleteMe</a> and it works great (after some setting up woes) for both C/C++ and Python code. However, it tries to complete things in text files such as ReStructured text, markdown, etc...</p>
<p>The error I keep getting is:</p>
<pre><co... | [
{
"answer_id": 2508,
"author": "Shahbaz",
"author_id": 850,
"author_profile": "https://vi.stackexchange.com/users/850",
"pm_score": 1,
"selected": false,
"text": "<p>This would be a generic answer, since I don't know <code>YouCompleteMe</code>. You mentioned in the comments that you woul... | 2015/03/12 | [
"https://vi.stackexchange.com/questions/2505",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/622/"
] | I use [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) and it works great (after some setting up woes) for both C/C++ and Python code. However, it tries to complete things in text files such as ReStructured text, markdown, etc...
The error I keep getting is:
```
-- User defined completion (^U^N^P) Pattern n... | The command `g:ycm_filetype_whitelist` was the one I needed!
```
let g:ycm_filetype_whitelist = { 'cpp': 1, 'c': 1, 'python':1 }
```
Finally, to get ride of this message altogether, the [answer is in the FAQ](https://github.com/Valloric/YouCompleteMe#i-get-annoying-messages-in-vims-status-area-when-i-type). Basicall... |
2,512 | <p>In a compilation log file whenever I get error it shows full path from root directory and line number.</p>
<p>After opening file in vim say following is the content of file,</p>
<pre><code>..
..
Dir1/Dir2/src/ipv4.c 1223
..
..
</code></pre>
<p>In vim in esc mode When I take cursor on above line and type <kbd>ctrl... | [
{
"answer_id": 2513,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 3,
"selected": false,
"text": "<p>A simple mapping could do the trick. Add the following to your <code>~/.vimrc</code>:</p>\n\n<pre><code>nnoremap gf ... | 2015/03/12 | [
"https://vi.stackexchange.com/questions/2512",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1334/"
] | In a compilation log file whenever I get error it shows full path from root directory and line number.
After opening file in vim say following is the content of file,
```
..
..
Dir1/Dir2/src/ipv4.c 1223
..
..
```
In vim in esc mode When I take cursor on above line and type `ctrl+w``shift+f` it will split the window... | A simple mapping could do the trick. Add the following to your `~/.vimrc`:
```
nnoremap gf <c-w>F
```
### Thoughts
* May want to map `<c-w>F` to `gf` so that the functionality is swapped
* Maybe remap the window key, `<c-w>`, as that sounds like a pain point. e.g. `nnoremap <space> <c-w>`
* Use regular `gf` and use... |
2,517 | <p>If I type a URL and I want to extract the parameters from the query string quickly in VIM how would I do that?</p>
<p>For instance if I have: </p>
<pre><code>http://www.somesite.org/page2014.html?utm_source=facebook&utm_medium=eventlinkonwall&utm_term=trapshoot&utm_content=calendar_event_on_wall&ut... | [
{
"answer_id": 2518,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 3,
"selected": true,
"text": "<p>What about:</p>\n\n<pre><code>df?:s/&/\\r/g\n</code></pre>\n\n<ul>\n<li><code>df?</code> to delete everything up ... | 2015/03/12 | [
"https://vi.stackexchange.com/questions/2517",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1065/"
] | If I type a URL and I want to extract the parameters from the query string quickly in VIM how would I do that?
For instance if I have:
```
http://www.somesite.org/page2014.html?utm_source=facebook&utm_medium=eventlinkonwall&utm_term=trapshoot&utm_content=calendar_event_on_wall&utm_campaign=trapshoot2014
```
I want... | What about:
```
df?:s/&/\r/g
```
* `df?` to delete everything up to & including the first `?`
* `:s/&/\r/g` to replace every `&` with a newline
You could prefix this with either `^` to go the start of the line, or `B` to go to the start of the word; use whatever is appropriate in the scenario. Be careful with autom... |
2,523 | <p>I frequently find myself wanting to make a copy of, eg, a function that I just wrote and modify it slightly. In such a situation, I'll generally use something like <kbd>y</kbd><kbd>5</kbd><kbd>k</kbd> to copy what I just wrote. I then have to <kbd>5</kbd><kbd>j</kbd> or <kbd>`</kbd><kbd>`</kbd> to get back to where ... | [
{
"answer_id": 2524,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 3,
"selected": false,
"text": "<p>Every command that modified the buffer (and yanks) will set the <code>'[</code> and <code>']</code> marks around the... | 2015/03/12 | [
"https://vi.stackexchange.com/questions/2523",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/163/"
] | I frequently find myself wanting to make a copy of, eg, a function that I just wrote and modify it slightly. In such a situation, I'll generally use something like `y``5``k` to copy what I just wrote. I then have to `5``j` or `````` to get back to where I just was before `p`.
However, if I'm at the start of what I wan... | You can take a different approach for this exact situation.
Paste differently
-----------------
The [`gP`](http://vimhelp.appspot.com/change.txt.html#gP) command pastes before your cursor like `P`, but leaves your cursor to the end of the pasted text instead of before.
This is effectively identical to manually resto... |
2,526 | <p>I use an example of javascript code:</p>
<pre><code>1 var a = 1;
2 var b = |{};
</code></pre>
<p>The cursor is at the position of <code>|</code>( on the character "{" when the cursor shape is block), I find out that I want <code>a</code> should be assigned an object, so I want to modify it like below... | [
{
"answer_id": 2527,
"author": "akshay",
"author_id": 246,
"author_profile": "https://vi.stackexchange.com/users/246",
"pm_score": 5,
"selected": false,
"text": "<p>Not sure if I totally understand the question, but if you wanted to delete until you only have <code>var a = {};</code>, y... | 2015/03/13 | [
"https://vi.stackexchange.com/questions/2526",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1276/"
] | I use an example of javascript code:
```
1 var a = 1;
2 var b = |{};
```
The cursor is at the position of `|`( on the character "{" when the cursor shape is block), I find out that I want `a` should be assigned an object, so I want to modify it like below:
```
1 var a = {};
```
So I want to k... | Not sure if I totally understand the question, but if you wanted to delete until you only have `var a = {};`, you could, from the cursor position, use `d?1``Enter`
`d` takes a motion, and you can give it a search pattern with `/` for a forward search or `?` for a backward search.
Here's a small gif demonstrating this... |
2,538 | <p>I have this sample line in the buffer:</p>
<pre><code>export PS1="\[${Cyan}\]$(((SHLVL>1)) && echo "${SHLVL}\[${IBlack}\].")\[${IGreen}\]\u\[${IBlack}\]@\[${Purple}\]\h\[${IYellow}\] \w \$ \[${Color_Off}\]"
</code></pre>
<p>and i want to delete all <code>\[</code> so while the cursor is on the line i wr... | [
{
"answer_id": 2539,
"author": "Kossak",
"author_id": 1067,
"author_profile": "https://vi.stackexchange.com/users/1067",
"pm_score": 4,
"selected": true,
"text": "<p>I found the reason: <code>[</code> is special character so vim treats next characters as part of the set (<code>[...]</cod... | 2015/03/13 | [
"https://vi.stackexchange.com/questions/2538",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1067/"
] | I have this sample line in the buffer:
```
export PS1="\[${Cyan}\]$(((SHLVL>1)) && echo "${SHLVL}\[${IBlack}\].")\[${IGreen}\]\u\[${IBlack}\]@\[${Purple}\]\h\[${IYellow}\] \w \$ \[${Color_Off}\]"
```
and i want to delete all `\[` so while the cursor is on the line i write `:s/\\[//g` and get the error
```
E486: Pat... | I found the reason: `[` is special character so vim treats next characters as part of the set (`[...]`) although it doesn't have the closing bracket. The proper replace should be:
```
:s/\\\[//g
```
(One backslash more) |
2,541 | <p>Is there any way to make vim treat bash variables (anything prefixed with a <code>$</code>, really) as distinct words? For instance, with the following lines: </p>
<pre><code>"name $suffix.ext"
"name$suffix.ext"
</code></pre>
<p>with the cursor somewhere in <code>$suffix</code>, the motion <kbd>d</kbd><kbd>i</kbd>... | [
{
"answer_id": 2549,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 0,
"selected": false,
"text": "<p>You could add <code>$</code> to the <code>iskeyword</code> option for shell scripts in your <code>~/.vimrc</code>:</p>\n\n<p... | 2015/03/13 | [
"https://vi.stackexchange.com/questions/2541",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1166/"
] | Is there any way to make vim treat bash variables (anything prefixed with a `$`, really) as distinct words? For instance, with the following lines:
```
"name $suffix.ext"
"name$suffix.ext"
```
with the cursor somewhere in `$suffix`, the motion `d``i``w` should leave me with `"name .ext"` and `"name.ext"`, respectiv... | This can be a case deserving a new text object. With Kana's framework (`vim-textobj-user`) in place, it would be something like this:
```
" define av/iv to select a bash variable:
call textobj#user#plugin('bash', {
\ 'avar': {
\ 'pattern': '\$\w\+\>',
\ 'select': [ 'av'],
\ },
... |
2,547 | <p>I have a handful of files (LaTeX documents) that have one specific proper name that is really obnoxious to type out but used frequently. I've eased the pain of this with an abbreviation like so:</p>
<pre><code>iab Eİ Elçilerin İşleri
</code></pre>
<p>This works great, but I don't want to pollute my global vimrc wi... | [
{
"answer_id": 2548,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 4,
"selected": false,
"text": "<p><code>:help modeline</code> is pretty specific about this:</p>\n\n<blockquote>\n <p>No other commands than \"set\" are suppo... | 2015/03/14 | [
"https://vi.stackexchange.com/questions/2547",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/267/"
] | I have a handful of files (LaTeX documents) that have one specific proper name that is really obnoxious to type out but used frequently. I've eased the pain of this with an abbreviation like so:
```
iab Eİ Elçilerin İşleri
```
This works great, but I don't want to pollute my global vimrc with document specific hacks... | As it has been said, it's not possible by design.
If you want something like modelines, you'll have to write your own plugin. In the early 2000 I wrote [let-modeline](https://github.com/LucHermitte/lh-misc/blob/master/plugin/let-modeline.vim) that decodes a slightly different format of modelines (i.e. `Vim: let var=ex... |
2,552 | <p>Without plugins like <code>ctrlp</code> and <code>NERDTree</code>, what would be the most efficient way to find and open files deep in a project tree? </p>
<p>Setting the <code>path</code> to <code>**/*</code> results in useless files in <code>.git</code> and other hidden directories, so that appears to be out of t... | [
{
"answer_id": 2555,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 6,
"selected": true,
"text": "<p>Here are the relevant parts of my setup:</p>\n\n<ul>\n<li><p>enable the wildmenu,</p>\n\n<pre><code>set wildmenu\n</code></pr... | 2015/03/14 | [
"https://vi.stackexchange.com/questions/2552",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | Without plugins like `ctrlp` and `NERDTree`, what would be the most efficient way to find and open files deep in a project tree?
Setting the `path` to `**/*` results in useless files in `.git` and other hidden directories, so that appears to be out of the question.
Is there a way to set the path in a *smart* manner,... | Here are the relevant parts of my setup:
* enable the wildmenu,
```
set wildmenu
```
* make filename-completion skip these files and directories,
```
set wildignore+=*.swp,*.bak
set wildignore+=*.pyc,*.class,*.sln,*.Master,*.csproj,*.csproj.user,*.cache,*.dll,*.pdb,*.min.*
set wildignore+=*/.git/**/*,*/.hg/**/*,*/.... |
2,560 | <p>I'm writing javascript code using vim and I really like to have outline view for the current javascript file I'm editing. I find tagbar is the popular plugin for this purpose. And on its wiki, for javascript to work, it recommends jsctags depends on Tern. </p>
<p>Now</p>
<ol>
<li>I have installed vim plugins: tagb... | [
{
"answer_id": 2564,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 2,
"selected": false,
"text": "<pre><code>:g/func/#\n</code></pre>\n\n<p>gives you an actionable outline of the current JavaScript buffer without installing a... | 2015/03/15 | [
"https://vi.stackexchange.com/questions/2560",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1276/"
] | I'm writing javascript code using vim and I really like to have outline view for the current javascript file I'm editing. I find tagbar is the popular plugin for this purpose. And on its wiki, for javascript to work, it recommends jsctags depends on Tern.
Now
1. I have installed vim plugins: tagbar and tern\_for\_vi... | ```
:g/func/#
```
gives you an actionable outline of the current JavaScript buffer without installing any third party plugin or requiring any external program.
Use `func\|var` to include variable declarations. |
2,566 | <p>I installed <code>ttf-font-awesome</code> in Arch Linux; if I open up a file which contains icons from Font awesome it recognizes the file as utf-8 but the icons are displayed as squares. Does anyone know how to fix this?</p>
| [
{
"answer_id": 2567,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 3,
"selected": false,
"text": "<p>First off, Vim can only display a file in a single font, you can't use multiple fonts at the same time.</p>\n\n<p>Fo... | 2015/03/15 | [
"https://vi.stackexchange.com/questions/2566",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/977/"
] | I installed `ttf-font-awesome` in Arch Linux; if I open up a file which contains icons from Font awesome it recognizes the file as utf-8 but the icons are displayed as squares. Does anyone know how to fix this? | First off, Vim can only display a file in a single font, you can't use multiple fonts at the same time.
For gVim, you can use `guifont` to set this to Font Awesome:
```
set guifont=Font\ Awesome\ 14
```
Which seems to work fine.
For Terminal Vim, you will need to configure your terminal emulator to use Font Awesom... |
2,569 | <p>In Vimscript, how can I check the current value of a Vim option?</p>
<p>To elaborate, I want to make a command to switch from Full-GUI Mode ( <code>guioptions=+tM</code>) to Hacker Mode (<code>guioptions=-tM</code>).</p>
<p>However, I can't seem to find a way to parse the <code>:set guioptions?</code> value</p>
| [
{
"answer_id": 2570,
"author": "akshay",
"author_id": 246,
"author_profile": "https://vi.stackexchange.com/users/246",
"pm_score": 6,
"selected": true,
"text": "<p>You can use the <code>&{option-name}</code> in an if-statement like so:</p>\n\n<pre><code>if &guioptions ==# \"Trl\"... | 2015/03/16 | [
"https://vi.stackexchange.com/questions/2569",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/583/"
] | In Vimscript, how can I check the current value of a Vim option?
To elaborate, I want to make a command to switch from Full-GUI Mode ( `guioptions=+tM`) to Hacker Mode (`guioptions=-tM`).
However, I can't seem to find a way to parse the `:set guioptions?` value | You can use the `&{option-name}` in an if-statement like so:
```
if &guioptions ==# "Trl"
echo "Toolbars and scrollbars are present!"
elseif &guioptions ==# ""
echo "No toolbars and scrollbars present!"
endif
```
The `&` specifies that the variable name is a Vim option.
See [`:help :let-&`](http://vimhelp.a... |
2,572 | <p>Can I retrieve the current operating system (Windows, Linux, OS X, ..) using <em>pure</em> Vimscript (no Python or Perl)?</p>
<p>I want to enable different settings in my (synchronized) <em>.vimrc</em> for different types of operation systems I am using. </p>
| [
{
"answer_id": 2574,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 7,
"selected": true,
"text": "<p>The best way is to use <a href=\"http://vimhelp.appspot.com/eval.txt.html#has%28%29\" rel=\"noreferrer\"><code>has()<... | 2015/03/16 | [
"https://vi.stackexchange.com/questions/2572",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1317/"
] | Can I retrieve the current operating system (Windows, Linux, OS X, ..) using *pure* Vimscript (no Python or Perl)?
I want to enable different settings in my (synchronized) *.vimrc* for different types of operation systems I am using. | The best way is to use [`has()`](http://vimhelp.appspot.com/eval.txt.html#has%28%29), with
this function you can check for features of Vim; OS specific features from
[`:help feature-list`](http://vimhelp.appspot.com/eval.txt.html#feature-list):
```
macunix Macintosh version of Vim, using Unix files (OS... |
2,582 | <p>How does one keep the cursor in its place after a file-replace using <code>:%s/find/replace/g</code> ? I looked at <a href="http://vimdoc.sourceforge.net/htmldoc/tips.html#restore-position" rel="nofollow">restoring cursor position</a>, but not quite what I was looking for, and I could jump back to previous position ... | [
{
"answer_id": 2583,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 2,
"selected": false,
"text": "<p>The <a href=\"http://www.vim.org/scripts/script.php?script_id=3800\" rel=\"nofollow\">anwolib plugin</a> has a <code>:... | 2015/03/16 | [
"https://vi.stackexchange.com/questions/2582",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1389/"
] | How does one keep the cursor in its place after a file-replace using `:%s/find/replace/g` ? I looked at [restoring cursor position](http://vimdoc.sourceforge.net/htmldoc/tips.html#restore-position), but not quite what I was looking for, and I could jump back to previous position using `''`. | The [anwolib plugin](http://www.vim.org/scripts/script.php?script_id=3800) has a `:KeepView` command:
```
:KeepView %s/find/replace/g
``` |
2,590 | <p>I use the following wildmenu settings: </p>
<pre><code>set wildmenu
set wildmode=list:full
</code></pre>
<p>Which results in this after typing <code>:find *foo<tab></code>:</p>
<p><img src="https://i.stack.imgur.com/y6yUG.png" alt="enter image description here"></p>
<p>Is there a way to highlight the optio... | [
{
"answer_id": 2593,
"author": "EvergreenTree",
"author_id": 865,
"author_profile": "https://vi.stackexchange.com/users/865",
"pm_score": 1,
"selected": false,
"text": "<p>The <code>WildMenu</code> highlight group is the highlighting for the current wildmenu match.\nThis would put an und... | 2015/03/17 | [
"https://vi.stackexchange.com/questions/2590",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I use the following wildmenu settings:
```
set wildmenu
set wildmode=list:full
```
Which results in this after typing `:find *foo<tab>`:

Is there a way to highlight the options in the wildmode list as opposed to (or in addition to) the highlight... | This would indeed be rather useful, but unfortunately this isn't possible.
The `showmatches()` function in `ex_getln.c` shows the list of completions:
```
/*
* Show all matches for completion on the command line.
* Returns EXPAND_NOTHING when the character that triggered expansion should
* be inserted like a norma... |
2,594 | <p>I use <a href="https://github.com/bling/vim-airline" rel="nofollow">airline</a> to manage my status-line and tab-line. This worked great until I started to code for an MVC project that has way too many modules and files going on. I now have tabs coming out my ears. More to the point: they don't fit in my tab line.</... | [
{
"answer_id": 2595,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 4,
"selected": false,
"text": "<p>This is an inherent issue with the tab metaphor and every solution introduces more problems:</p>\n\n<ul>\n<li>multiple lines... | 2015/03/17 | [
"https://vi.stackexchange.com/questions/2594",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/267/"
] | I use [airline](https://github.com/bling/vim-airline) to manage my status-line and tab-line. This worked great until I started to code for an MVC project that has way too many modules and files going on. I now have tabs coming out my ears. More to the point: they don't fit in my tab line.
Is there a way to configure a... | This is an inherent issue with the tab metaphor and every solution introduces more problems:
* multiple lines are harder to parse and take up too much space,
* tab groups make it impossible to see what's in them at a glance and thus defeat the whole purpose of having a tab-line,
* arrows to scroll the tab-line are als... |
2,600 | <p>I am going to be pasting a lot of characters into a file. Each time I paste something, the pasted element will need to be wrapped in quotes and followed by a comma. Is there a way to automatically wrap these characters after each paste in vim? The paste will be coming from the system clipboard, not a vim paste buffe... | [
{
"answer_id": 2602,
"author": "PhilippFrank",
"author_id": 1296,
"author_profile": "https://vi.stackexchange.com/users/1296",
"pm_score": 3,
"selected": false,
"text": "<p>Do you need to use the mouse (middle-klick)? I'd go for a macro:</p>\n\n<ol>\n<li>Press <kbd>q</kbd><kbd>q</kbd> to... | 2015/03/17 | [
"https://vi.stackexchange.com/questions/2600",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/69/"
] | I am going to be pasting a lot of characters into a file. Each time I paste something, the pasted element will need to be wrapped in quotes and followed by a comma. Is there a way to automatically wrap these characters after each paste in vim? The paste will be coming from the system clipboard, not a vim paste buffer.
... | Do you need to use the mouse (middle-klick)? I'd go for a macro:
1. Press `q``q` to start recording
2. Press `i``"``Esc``"``\*``p`````]``a``"``,``Esc` to first insert the first set of quote, then paste from the system clipboard, go to the end of the paste and append quote and comma
3. Press `q` to stop recording
Then... |
2,607 | <p>I want to edit several files matching a glob expression. For example, to edit all git config files in child directories, I can do this in the shell:</p>
<pre><code>vim */.git/config
</code></pre>
<p>At the Vim <code>:</code> command line, I expected <code>:find */.git/config</code> to do something similar (i.e., o... | [
{
"answer_id": 2608,
"author": "tommcdo",
"author_id": 64,
"author_profile": "https://vi.stackexchange.com/users/64",
"pm_score": 5,
"selected": true,
"text": "<p>You can use <code>:args {glob}</code>. In your glob, <code>**</code> will traverse directories recursively.</p>\n\n<p>This wi... | 2015/03/18 | [
"https://vi.stackexchange.com/questions/2607",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/578/"
] | I want to edit several files matching a glob expression. For example, to edit all git config files in child directories, I can do this in the shell:
```
vim */.git/config
```
At the Vim `:` command line, I expected `:find */.git/config` to do something similar (i.e., open all files matching the glob expression), but... | You can use `:args {glob}`. In your glob, `**` will traverse directories recursively.
This will populate the argument list, which is the same list that gets populated when you start Vim with one or more filenames as arguments.
Once your argument list is populated, you can navigate through it using `:next` and `:previ... |
2,614 | <p>I'm experiencing a weird problem with a normal mode mapping of <kbd>Esc</kbd>.</p>
<p>If you create the file <code>escmapvimrc</code> with the contents:</p>
<pre><code>set nocompatible
set showcmd " Doesn't affect the problem: just makes it easier to see
nnoremap <Esc> :noh<CR><esc>
</code></pre>... | [
{
"answer_id": 2615,
"author": "Ingo Karkat",
"author_id": 970,
"author_profile": "https://vi.stackexchange.com/users/970",
"pm_score": 4,
"selected": false,
"text": "<p>The Linux terminal uses ANSI escape sequences (i.e. strings of characters starting with <code><Esc></code>) to s... | 2015/03/18 | [
"https://vi.stackexchange.com/questions/2614",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/343/"
] | I'm experiencing a weird problem with a normal mode mapping of `Esc`.
If you create the file `escmapvimrc` with the contents:
```
set nocompatible
set showcmd " Doesn't affect the problem: just makes it easier to see
nnoremap <Esc> :noh<CR><esc>
```
And then start vim using this vimrc:
```
vim --noplugin -u escmap... | Vim sends during startup some special terminal codes (that usually contain the `<esc>` key) to determine several things (colors, bs,...) If you mapped `<esc>` this will most likely confuse the parser of the return codes and weird things can happen.
Therefore, use your above map only after everything has been setup cor... |
2,616 | <p>In <a href="http://vim.org/" rel="nofollow">vim</a> you can include <code>modelines</code> in comments at the start/end of a file, like</p>
<pre><code>// vim:sw=4 ts=4 et
</code></pre>
<p>I regularly work with PHP and try to stick to <a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-codi... | [
{
"answer_id": 2617,
"author": "Caleb",
"author_id": 267,
"author_profile": "https://vi.stackexchange.com/users/267",
"pm_score": 3,
"selected": true,
"text": "<p>Per the answers to <a href=\"https://vi.stackexchange.com/q/2547/267\">a question</a> I recently asked on the <a href=\"http:... | 2015/03/17 | [
"https://vi.stackexchange.com/questions/2616",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1406/"
] | In [vim](http://vim.org/) you can include `modelines` in comments at the start/end of a file, like
```
// vim:sw=4 ts=4 et
```
I regularly work with PHP and try to stick to [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) but Drupal (of course \*rolls eyes\*) has to ... | Per the answers to [a question](https://vi.stackexchange.com/q/2547/267) I recently asked on the [Vi and Vim Stack Exchange](http://vi.stackexchange.com), the vim modeline can only be used to trigger a predefined subset of parameters to the `:set` command already built into vim. It sounds like you could hack something ... |
2,626 | <p>Our company has recently changed to networked home directories. This includes setting enviroment variables. </p>
<p>This has created the odd situation that gvim thinks my home directory is :</p>
<pre><code>:echo $HOME
H:\
</code></pre>
<p>but I cannot change the current directory to that drive or edit any files t... | [
{
"answer_id": 2632,
"author": "Matt Boehm",
"author_id": 680,
"author_profile": "https://vi.stackexchange.com/users/680",
"pm_score": 0,
"selected": false,
"text": "<p>Perhaps try <code>:cd H:</code>? Purely guessing based on the contents of <code>:help dos-:cd</code> <a href=\"http://v... | 2015/03/19 | [
"https://vi.stackexchange.com/questions/2626",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1438/"
] | Our company has recently changed to networked home directories. This includes setting enviroment variables.
This has created the odd situation that gvim thinks my home directory is :
```
:echo $HOME
H:\
```
but I cannot change the current directory to that drive or edit any files there. This also means that my `vi... | I solved this problem myself by using [Haroogan vim](https://bitbucket.org/Haroogan). When I cd to h:\ in Haroogan vim it works, and it also successfully runs my vimrc files there.
I guess this was either something strange about my work's network drive and/or a bug in vim that will eventually be resolved. Still, if yo... |
2,627 | <p>When gvim is opened it saves the cursor position whether it is minimized or not. So I'm curious whether it is possible to add a string starting from the cursor blinking position by running a shell script or through a terminal.</p>
| [
{
"answer_id": 2628,
"author": "romainl",
"author_id": 54,
"author_profile": "https://vi.stackexchange.com/users/54",
"pm_score": 3,
"selected": true,
"text": "<p>Take note of the server name of your GVim window by looking at its title, it should have something like <code>VIM</code> or <... | 2015/03/19 | [
"https://vi.stackexchange.com/questions/2627",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1107/"
] | When gvim is opened it saves the cursor position whether it is minimized or not. So I'm curious whether it is possible to add a string starting from the cursor blinking position by running a shell script or through a terminal. | Take note of the server name of your GVim window by looking at its title, it should have something like `VIM` or `VIM1`.
You can then use this command to insert `foo` at the current cursor position:
```
$ vim --servername VIM --remote-send "ifoo<Esc>"
```
For more information, see `:help clientserver`. |