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 |
|---|---|---|---|---|---|---|
11,646 | <p>in insert mode, when i press <kbd>space</kbd>, my neovim doesn't print out the space immediately. instead, it prints in the right corner <code><20></code> and seems to wait for a mapping to complete. Although my mapleader is <kbd>space</kbd>, i have no mappings using <code><leader></code> for insert mode... | [
{
"answer_id": 11651,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 3,
"selected": true,
"text": "<p>If the plugin has some <code><plug>mapping</code> variation point that could be used to override the default on... | 2017/03/04 | [
"https://vi.stackexchange.com/questions/11646",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2354/"
] | in insert mode, when i press `space`, my neovim doesn't print out the space immediately. instead, it prints in the right corner `<20>` and seems to wait for a mapping to complete. Although my mapleader is `space`, i have no mappings using `<leader>` for insert mode.
(*update below*)
`:verbose imap <space>` prints out... | If the plugin has some `<plug>mapping` variation point that could be used to override the default one thar use `<leader>`, well there will be a solution.
Otherwise, it's done on a per plugin basis.
Unless listing all i-mappings starting with `<space>` thanks to `getcompletions()` (IIRC) in an `after/` plugin executed... |
11,659 | <p>I'm trying to use the <a href="https://github.com/Valloric/YouCompleteMe" rel="nofollow noreferrer">YouCompleteMe</a> auto completion plugin.</p>
<p>I have installed MacVim version 7.4.</p>
<p>I followed the instructions on the linked page for Mac OS X by making the symlink:</p>
<pre><code>ln -s /usr/local/bin/m... | [
{
"answer_id": 11651,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 3,
"selected": true,
"text": "<p>If the plugin has some <code><plug>mapping</code> variation point that could be used to override the default on... | 2017/03/06 | [
"https://vi.stackexchange.com/questions/11659",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11660/"
] | I'm trying to use the [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) auto completion plugin.
I have installed MacVim version 7.4.
I followed the instructions on the linked page for Mac OS X by making the symlink:
```
ln -s /usr/local/bin/mvim vim
```
When installing the plugin with Vundle, I got some e... | If the plugin has some `<plug>mapping` variation point that could be used to override the default one thar use `<leader>`, well there will be a solution.
Otherwise, it's done on a per plugin basis.
Unless listing all i-mappings starting with `<space>` thanks to `getcompletions()` (IIRC) in an `after/` plugin executed... |
11,668 | <p>I am new to Vim, however I am learning to love it. As a former/current Windows user, there is one shortcut that I depend on and would like to configure in Vim. </p>
<p>On windows I can use <kbd>ctrl</kbd>-<kbd>arrow left</kbd> and <kbd>ctrl</kbd>-<kbd>arrow right</kbd> to skip over words left and right.</p>
<p>I... | [
{
"answer_id": 11669,
"author": "laktak",
"author_id": 10337,
"author_profile": "https://vi.stackexchange.com/users/10337",
"pm_score": 2,
"selected": false,
"text": "<p>If Vim exits insert mode and appears to do nothing you may need to tell it to use xterm keys.</p>\n\n<p>Add this to yo... | 2017/03/07 | [
"https://vi.stackexchange.com/questions/11668",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11680/"
] | I am new to Vim, however I am learning to love it. As a former/current Windows user, there is one shortcut that I depend on and would like to configure in Vim.
On windows I can use `ctrl`-`arrow left` and `ctrl`-`arrow right` to skip over words left and right.
I just don't want to press the over arrow a bunch of tim... | This is most likely because you are using the CLI. In CLI Cntrl + Left doenst work natively in VIM. I am using TMUX/SSH into UBUNTU installed in a virtualbox on windows 10, similar to your situation (no X-server running on my Windows 10).
Cntrl+left/right doesnt work when I log in using TMUX/SSH (with no Xserver), ho... |
11,677 | <p>Sometimes I'll guess a count for a cursor movement, say <code>4b</code> but it was actually 7 words away. If I'd performed an edit I could press <code>.</code> to repeat; I could have done <code>@:</code> to repeat a command line. </p>
<p>It would be useful to repeat <code>4b</code> again. This functionality wo... | [
{
"answer_id": 11678,
"author": "laktak",
"author_id": 10337,
"author_profile": "https://vi.stackexchange.com/users/10337",
"pm_score": 4,
"selected": false,
"text": "<p>Since you mentioned cursor movement but not <code>;</code> there is of course</p>\n\n<pre><code>; Repeat latest f,... | 2017/03/08 | [
"https://vi.stackexchange.com/questions/11677",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | Sometimes I'll guess a count for a cursor movement, say `4b` but it was actually 7 words away. If I'd performed an edit I could press `.` to repeat; I could have done `@:` to repeat a command line.
It would be useful to repeat `4b` again. This functionality would also be useful, saving more keypresses, if, having don... | Since you mentioned cursor movement but not `;` there is of course
```
; Repeat latest f, t, F or T [count] times.
, Repeat latest f, t, F or T in opposite direction [count] times.
```
This is very helpful to get to the next occurrence of the character you just searched for.
IMHO I'm don't think repeating ... |
11,685 | <p>I have what I thought was a pretty simple setup in my neovim init.vim file. Basically all I wanted it to do was configure the tab settings when opening an HTML file. My configuration is:</p>
<pre><code>au BufNewFile,BufRead *.html, *.css
\ set tabstop=2
\ softtabstop=2
\ shiftwidth=2
</code></pre>
<p... | [
{
"answer_id": 11686,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 4,
"selected": true,
"text": "<p>You need to use <code>|</code> to run multiple commands:</p>\n\n<pre><code>set tabstop=2 | softtabstop=2\n</code></p... | 2017/03/09 | [
"https://vi.stackexchange.com/questions/11685",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11712/"
] | I have what I thought was a pretty simple setup in my neovim init.vim file. Basically all I wanted it to do was configure the tab settings when opening an HTML file. My configuration is:
```
au BufNewFile,BufRead *.html, *.css
\ set tabstop=2
\ softtabstop=2
\ shiftwidth=2
```
When I open an HTML file I ... | You need to use `|` to run multiple commands:
```
set tabstop=2 | softtabstop=2
```
It doesn't matter if you're using multiple lines, you still need to use the `|`:
```
au BufNewFile,BufRead *.html, *.css
\ set tabstop=2
\| set softtabstop=2
\| set shiftwidth=2
```
You can set multiple values with `s... |
11,687 | <p>I'm trying to make a mapping which does one thing on the first press of a key, and also does something else if I press the key again within <code>timeout</code>. Specifically:</p>
<pre><code>nnoremap <silent> <Esc><Esc> :set hls<CR>:let @/="\\<<C-R>=expand('<cword>')<CR>... | [
{
"answer_id": 11690,
"author": "SibiCoder",
"author_id": 7161,
"author_profile": "https://vi.stackexchange.com/users/7161",
"pm_score": 0,
"selected": false,
"text": "<p>You can try toggling on/off.\nA sample vimscript like</p>\n\n<pre><code>func ToggleHLSearch()\n let hlsearch_opt = &... | 2017/03/09 | [
"https://vi.stackexchange.com/questions/11687",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10083/"
] | I'm trying to make a mapping which does one thing on the first press of a key, and also does something else if I press the key again within `timeout`. Specifically:
```
nnoremap <silent> <Esc><Esc> :set hls<CR>:let @/="\\<<C-R>=expand('<cword>')<CR>\\>"<CR>
nnoremap <silent> <Esc> :noh<CR>
```
…I want pressing `Esc`... | I found a way: use `<Plug>`, an un-typeable "key" intended for mappings to call each other, to let the single-`Esc` mapping prime the other one:
```
noremap <silent> <Plug><Esc> :set hls<CR>:let @/="\\<<C-R>=expand('<cword>')<CR>\\>"<CR>:call histadd("/", @/)<CR>
nmap <silent> <Esc> :noh<CR><Plug>
```
This could be ... |
11,696 | <p>I understand that it loads the <code>ftplugin.vim</code> file, but what does it really do? Does it set options (depending on the filetype)?</p>
<p>If I were to include this line at the start of my vimrc</p>
<pre><code>filetype plugin indent on
</code></pre>
<p>and then I set some options after this line (like aut... | [
{
"answer_id": 11701,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>It defines autocommands that'll get executed when a file matching a given pattern is opened. These autocommands <cod... | 2017/03/10 | [
"https://vi.stackexchange.com/questions/11696",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11717/"
] | I understand that it loads the `ftplugin.vim` file, but what does it really do? Does it set options (depending on the filetype)?
If I were to include this line at the start of my vimrc
```
filetype plugin indent on
```
and then I set some options after this line (like autoindent, smartindent, etc.), would it mess w... | There is actually a good description in `help filetype`.
Any options that are defined for a filetype will be set with `setlocal`:
```
:setl[ocal] ... Like ":set" but set only the value local to the
current buffer or window. Not all options have [..]
```
For example `/usr/share/vim/vim80/ftp... |
11,697 | <p>I have a file with several lines like so:</p>
<pre><code>{"latin": "", "french": "", "italian": "", "catalan": "", "portuguese": "", "romanian": "", "spanish": "", "english": ""}
</code></pre>
<p>I want to quickly move between the empty quotes to enter data. Is there a short-cut that could be used here?</p>
| [
{
"answer_id": 11698,
"author": "Violapterin",
"author_id": 10241,
"author_profile": "https://vi.stackexchange.com/users/10241",
"pm_score": 5,
"selected": true,
"text": "<p><code>f\"</code> jumps to the next quote, and <code>F\"</code> jumps to the previous one. <code>3f\"</code> jumps ... | 2017/03/10 | [
"https://vi.stackexchange.com/questions/11697",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7783/"
] | I have a file with several lines like so:
```
{"latin": "", "french": "", "italian": "", "catalan": "", "portuguese": "", "romanian": "", "spanish": "", "english": ""}
```
I want to quickly move between the empty quotes to enter data. Is there a short-cut that could be used here? | `f"` jumps to the next quote, and `F"` jumps to the previous one. `3f"` jumps three more quotes, and so on. This seems enough to me. If the cursor is inside the quote, and you want to jump to the position just before the ending quote, `t"` may be used, and similar is said of `T"`. In your case, `e` (jump to the last ch... |
11,699 | <p>An example:</p>
<pre><code>Doe, John
</code></pre>
<p>And I want:</p>
<pre><code>John Doe
</code></pre>
<p>I cut <code>Doe</code> with <kbd>D</kbd>, and then <kbd>0</kbd> and then <kbd>p</kbd> </p>
<p>But what I get is this: </p>
<pre><code>DJohn oe,
</code></pre>
<p>How to do this right?</p>
| [
{
"answer_id": 11802,
"author": "brokenbyte",
"author_id": 8251,
"author_profile": "https://vi.stackexchange.com/users/8251",
"pm_score": 2,
"selected": false,
"text": "<p>Lowercase 'p' will paste AFTER the cursor. Use a capital 'P' and it will end up BEFORE the cursor. It will not, howe... | 2017/03/10 | [
"https://vi.stackexchange.com/questions/11699",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5346/"
] | An example:
```
Doe, John
```
And I want:
```
John Doe
```
I cut `Doe` with `D`, and then `0` and then `p`
But what I get is this:
```
DJohn oe,
```
How to do this right? | Lowercase 'p' will paste AFTER the cursor. Use a capital 'P' and it will end up BEFORE the cursor. It will not, however, insert a space, so you will end up with "JohnDoe,". |
11,708 | <p>I want to use <code>get</code> with the environment variable namespace, so instead of this in the <em>global</em> namespace:</p>
<pre><code>let vim_data_dir = get(g:, 'vim_data_dir', "default value if not set")
</code></pre>
<p>Something like this, in the <code>$</code> or <em>environment variable</em> namespace:<... | [
{
"answer_id": 11710,
"author": "laktak",
"author_id": 10337,
"author_profile": "https://vi.stackexchange.com/users/10337",
"pm_score": 1,
"selected": false,
"text": "<p><code>$VIM_DATA_DIR</code> already gives you the environment variable, so you can do</p>\n\n<pre><code>let $VIM_DATA_D... | 2017/03/11 | [
"https://vi.stackexchange.com/questions/11708",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5324/"
] | I want to use `get` with the environment variable namespace, so instead of this in the *global* namespace:
```
let vim_data_dir = get(g:, 'vim_data_dir', "default value if not set")
```
Something like this, in the `$` or *environment variable* namespace:
```
let $VIM_DATA_DIR = get($, 'VIM_DATA_DIR', "default value... | In that case, you could simply use the good old `exists()`
```
:let foo = exists('$FOO') ? $FOO : 'default'
```
There is also `empty()`, IMO it only makes sense if you want to undefine environment variables from within Vim. Indeed, as `:unlet $FOO` isn't possible, yet, we have to use `:let $FOO=''`
To obtain all en... |
11,745 | <p>An example HTML, with the cursor where the brackets are:</p>
<pre><code><foo>
<bar>
baz
quux
[]
</bar>
</foo>
</code></pre>
<p>I would like to outdent the text inside <code><bar/></code>. Naturally, I try <kbd><</kbd><kbd>i</kbd><kbd>t</kbd>, but i... | [
{
"answer_id": 11710,
"author": "laktak",
"author_id": 10337,
"author_profile": "https://vi.stackexchange.com/users/10337",
"pm_score": 1,
"selected": false,
"text": "<p><code>$VIM_DATA_DIR</code> already gives you the environment variable, so you can do</p>\n\n<pre><code>let $VIM_DATA_D... | 2017/03/14 | [
"https://vi.stackexchange.com/questions/11745",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4729/"
] | An example HTML, with the cursor where the brackets are:
```
<foo>
<bar>
baz
quux
[]
</bar>
</foo>
```
I would like to outdent the text inside `<bar/>`. Naturally, I try `<``i``t`, but it turns out that `it` is everything inside `<bar/>` - including the newline after `<bar>`, and in... | In that case, you could simply use the good old `exists()`
```
:let foo = exists('$FOO') ? $FOO : 'default'
```
There is also `empty()`, IMO it only makes sense if you want to undefine environment variables from within Vim. Indeed, as `:unlet $FOO` isn't possible, yet, we have to use `:let $FOO=''`
To obtain all en... |
11,746 | <p>To input <code>w100p</code> and <kbd>ctrl</kbd>+<kbd>y</kbd>+<kbd>,</kbd> or <code>w100p</code> and <kbd>tab</kbd>,<code>w100p</code> can't expand into <code>width: 100%</code>.<br>
No <code>snippets.json</code> file found with command <code>find / -name 'snippets.json'</code>,is it the reason?<br>
snippets.js... | [
{
"answer_id": 11710,
"author": "laktak",
"author_id": 10337,
"author_profile": "https://vi.stackexchange.com/users/10337",
"pm_score": 1,
"selected": false,
"text": "<p><code>$VIM_DATA_DIR</code> already gives you the environment variable, so you can do</p>\n\n<pre><code>let $VIM_DATA_D... | 2017/03/14 | [
"https://vi.stackexchange.com/questions/11746",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5181/"
] | To input `w100p` and `ctrl`+`y`+`,` or `w100p` and `tab`,`w100p` can't expand into `width: 100%`.
No `snippets.json` file found with command `find / -name 'snippets.json'`,is it the reason?
snippets.json can download from url.
[snippets.json](https://github.com/emmetio/emmet/blob/master/lib/snippets.json)
Whe... | In that case, you could simply use the good old `exists()`
```
:let foo = exists('$FOO') ? $FOO : 'default'
```
There is also `empty()`, IMO it only makes sense if you want to undefine environment variables from within Vim. Indeed, as `:unlet $FOO` isn't possible, yet, we have to use `:let $FOO=''`
To obtain all en... |
11,753 | <p>I started using <a href="https://github.com/JoshCheek/seeing_is_believing" rel="nofollow noreferrer">Seeing is Believing</a>
and updated my <a href="https://github.com/ogirginc/dotfiles/blob/master/vimrc#L297-L298" rel="nofollow noreferrer">vimrc</a>:</p>
<pre><code>nmap <leader>s A # => <Esc>:%.!se... | [
{
"answer_id": 11759,
"author": "lsrdg",
"author_id": 10493,
"author_profile": "https://vi.stackexchange.com/users/10493",
"pm_score": 1,
"selected": false,
"text": "<p>In theory:</p>\n\n<p>You could end your map with <code>''</code> to jump back to the first non blank column on the line... | 2017/03/14 | [
"https://vi.stackexchange.com/questions/11753",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7621/"
] | I started using [Seeing is Believing](https://github.com/JoshCheek/seeing_is_believing)
and updated my [vimrc](https://github.com/ogirginc/dotfiles/blob/master/vimrc#L297-L298):
```
nmap <leader>s A # => <Esc>:%.!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk --... | In theory:
You could end your map with `''` to jump back to the first non blank column on the line where you were:
```
nmap <leader>s A # => <Esc>:%.!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk --xmpfilter-style<CR>''
```
Or you could use ```` to jump back... |
11,754 | <p>When using the <code>:oldfiles</code> command, I can easily exit the list with <code>q</code>.</p>
<p>When I use the <code>:registers</code> command, it says "Press ENTER or type command to continue". But I would like to exit the list with <code>q</code>, without entering into macro recording which is annoying. I d... | [
{
"answer_id": 11755,
"author": "Lithis",
"author_id": 2680,
"author_profile": "https://vi.stackexchange.com/users/2680",
"pm_score": 2,
"selected": false,
"text": "<p>The difference is whether the whole list fits in the screen or not. If your screen is tall enough, the output of <code>:... | 2017/03/14 | [
"https://vi.stackexchange.com/questions/11754",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7318/"
] | When using the `:oldfiles` command, I can easily exit the list with `q`.
When I use the `:registers` command, it says "Press ENTER or type command to continue". But I would like to exit the list with `q`, without entering into macro recording which is annoying. I don't like pressing `enter`.
Is there a native Vim way... | I gave in to the dark side and used some hacky Vimscript:
```
map <silent> '' :call DisplayRegisters()<cr>
function! DisplayRegisters()
redir => output
silent exe 'reg "0123456789'
redir END
new
silent file [Registers]
setlocal nonumber norelativenumber
setlocal buftype=nofile bufhidden=wipe noswapfile ... |
11,765 | <p>Here's a snippet that I'm working with (* denotes cursor location)</p>
<pre><code>*"First random string" ,"Random string I want to remove" }
"Random string number 2" , "Another random string I want to keep" }
</code></pre>
<p>To:</p>
<pre><code>*"First random string" , ... | [
{
"answer_id": 11769,
"author": "Nakini",
"author_id": 9893,
"author_profile": "https://vi.stackexchange.com/users/9893",
"pm_score": 0,
"selected": false,
"text": "<p>How about using a plugin, like <strong>Align</strong> or <strong>Tabular</strong>? Take a look at the suggestion given <... | 2017/03/16 | [
"https://vi.stackexchange.com/questions/11765",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11804/"
] | Here's a snippet that I'm working with (\* denotes cursor location)
```
*"First random string" ,"Random string I want to remove" }
"Random string number 2" , "Another random string I want to keep" }
```
To:
```
*"First random string" , }
"Random string numb... | I'm confident that `<select text>r<space>` as you say does work. But you may be using a terminal in which the mouse selection is not passed to Vim (or Vim is not configured to understand the selection with the mouse; as in e.g. `set mouse=a`).
Yet, instead of selecting with the mouse I'd use `f` to perform the selecti... |
11,776 | <p>The documentation for <code>:put</code> says that the command accepts a line. That is, it puts the content after the line specified. Is it possible to put the content at a particular mark?</p>
<p>For example, say I am in the middle of refactoring an anonymous JavaScript function into a named JavaScript function. I ... | [
{
"answer_id": 11779,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p>No, it's not.\nYou'll have to use other means:</p>\n\n<ul>\n<li>go to the right position and use <code>p</code> or <... | 2017/03/17 | [
"https://vi.stackexchange.com/questions/11776",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10101/"
] | The documentation for `:put` says that the command accepts a line. That is, it puts the content after the line specified. Is it possible to put the content at a particular mark?
For example, say I am in the middle of refactoring an anonymous JavaScript function into a named JavaScript function. I have the following in... | No, it's not.
You'll have to use other means:
* go to the right position and use `p` or `P` normal mode commands thanks to `:normal` -> `:normal! P` for instance. You may need first to put your variable into a register.
* you could insert the new thing at cursor position also thanks to `:exe "normal! i".the_string`. B... |
11,791 | <p>I'm not sure if I've failed at searching for the answer to this, but now I've worked it out I wanted to document it here. The problem is searching for a multiline pattern, and storing all such occurrences in a register.</p>
<p>I am trying to look for calls to a particular function, e.g. <code>func(a, b, c);</code>,... | [
{
"answer_id": 11792,
"author": "Jonathan",
"author_id": 11827,
"author_profile": "https://vi.stackexchange.com/users/11827",
"pm_score": 4,
"selected": true,
"text": "<p>It turns out something along these lines works (although there might well be better ways) -- using a substitute-witho... | 2017/03/18 | [
"https://vi.stackexchange.com/questions/11791",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11827/"
] | I'm not sure if I've failed at searching for the answer to this, but now I've worked it out I wanted to document it here. The problem is searching for a multiline pattern, and storing all such occurrences in a register.
I am trying to look for calls to a particular function, e.g. `func(a, b, c);`, so that I can extrac... | It turns out something along these lines works (although there might well be better ways) -- using a substitute-without-substituting command instead of a global command:
Starting with the answer here: [How to show all unique types of a pattern?](https://vi.stackexchange.com/questions/8906/how-to-show-all-unique-types-... |
11,812 | <p>In Visual Mode, you can do this using the <code>o</code> keystroke. </p>
<p>However with search highlighting, ie <code>?</code> or <code>/</code> -- I have a whole selection, but I want to move specifically to the last character of the highlight. </p>
<p>I'm assuming there is a keystroke out there that accomplishe... | [
{
"answer_id": 11816,
"author": "Jack",
"author_id": 11834,
"author_profile": "https://vi.stackexchange.com/users/11834",
"pm_score": 2,
"selected": false,
"text": "<p>You can add various parameters or commands for the offset of where the cursor lands. </p>\n\n<pre><code>/test/e ... | 2017/03/19 | [
"https://vi.stackexchange.com/questions/11812",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7960/"
] | In Visual Mode, you can do this using the `o` keystroke.
However with search highlighting, ie `?` or `/` -- I have a whole selection, but I want to move specifically to the last character of the highlight.
I'm assuming there is a keystroke out there that accomplishes this. Is this the case?
Thanks in advance. | `gn` + `<Escape>`
```
gn Search forward for the last used search pattern, like
with n, and start Visual mode to select the match.
If the cursor is on the match, visually selects it.
If an operator is pending, operates on the m... |
11,824 | <p>I use the <code>oldfiles</code> and <code>browse oldfiles</code> commands all the time. I find them extremely useful, because it's easier to hit my leader mapping, scan through the files really quickly, and hit</p>
<pre><code>q<number><enter>
</code></pre>
<p>rather than typing out a really long direct... | [
{
"answer_id": 11829,
"author": "Peter Rincker",
"author_id": 778,
"author_profile": "https://vi.stackexchange.com/users/778",
"pm_score": 5,
"selected": true,
"text": "<p>Assuming you have Vim 8 you can use <code>:filter</code></p>\n\n<pre><code>:browse filter /pattern/ oldfiles\n</code... | 2017/03/20 | [
"https://vi.stackexchange.com/questions/11824",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2920/"
] | I use the `oldfiles` and `browse oldfiles` commands all the time. I find them extremely useful, because it's easier to hit my leader mapping, scan through the files really quickly, and hit
```
q<number><enter>
```
rather than typing out a really long directory path to a specific file. (Especially since sometimes I d... | Assuming you have Vim 8 you can use `:filter`
```
:browse filter /pattern/ oldfiles
```
For more help see:
```
:h :browse
:h :filter
:h oldfiles
:h new-items-8
``` |
11,827 | <p>For files of a certain <code>filetype</code>, specifying "file-type-specific" mappings is simple. </p>
<ul>
<li><p>If Vim opens a fill and return <code>filetype=python</code> after issuing command <code>:set filetype?</code> through command-line (native to Vim), then python-specific mappings could be defined direct... | [
{
"answer_id": 11834,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 0,
"selected": false,
"text": "<p>I would define a autocommand for all buffers that'd test for the filetype. I'm afraid there is no other way. </p>\n"... | 2017/03/20 | [
"https://vi.stackexchange.com/questions/11827",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2398/"
] | For files of a certain `filetype`, specifying "file-type-specific" mappings is simple.
* If Vim opens a fill and return `filetype=python` after issuing command `:set filetype?` through command-line (native to Vim), then python-specific mappings could be defined directly through `~/ftplugin/python.vim`;
* However, whe... | As Luc said, you would have to use an `autocmd`:
```
augroup NoFileType
autocmd!
autocmd BufNewFile,BufRead * if &filetype ==# '' | setlocal filetype=noft | endif
autocmd FileType noft echom 'No file type!'
augroup END
```
Or just add this to `ftdetect/noft.vim`:
```
autocmd BufNewFile,BufRead * if &filetype ... |
11,830 | <p>I would like to add a new line in a certain line in a buffer. So far my starting position is as follows:</p>
<pre><code>let newl = "\n"
" set cursor to beginning of buffer
call cursor(1,1)
" search up to 10 lines down
search("somestring",'',10)
" get the line number of the match
let cursor_pos = getpos(".")
let cur... | [
{
"answer_id": 11831,
"author": "blueyed",
"author_id": 2899,
"author_profile": "https://vi.stackexchange.com/users/2899",
"pm_score": 3,
"selected": true,
"text": "<p>What about this?</p>\n\n<pre><code>/somestring\nnormal! o\n</code></pre>\n\n<p>If you want to have it dynamic, take a lo... | 2017/03/20 | [
"https://vi.stackexchange.com/questions/11830",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11853/"
] | I would like to add a new line in a certain line in a buffer. So far my starting position is as follows:
```
let newl = "\n"
" set cursor to beginning of buffer
call cursor(1,1)
" search up to 10 lines down
search("somestring",'',10)
" get the line number of the match
let cursor_pos = getpos(".")
let cursor_line = cur... | What about this?
```
/somestring
normal! o
```
If you want to have it dynamic, take a look at `:exe`.
Or:
```
:call append(cursor_line, '')
``` |
11,839 | <p>I'm trying to create a mapping to create a mapping such that pressing <code><C-return></code> presents me with <code>:nnoremap <return> :</code> to which I can then add a custom command. The following does not work because <code><return></code> is replaced by the return key.</p>
<pre><code>:nnorem... | [
{
"answer_id": 11841,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 1,
"selected": false,
"text": "<p>Interesting I thought we could do this with an <code>exe</code> command, but that fails too. I found a way to do it b... | 2017/03/21 | [
"https://vi.stackexchange.com/questions/11839",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8061/"
] | I'm trying to create a mapping to create a mapping such that pressing `<C-return>` presents me with `:nnoremap <return> :` to which I can then add a custom command. The following does not work because `<return>` is replaced by the return key.
```
:nnoremap <c-return> :nnoremap <return> :
```
I thought I could escape... | Escape `<` as `<lt>`:
```
nnoremap <c-return> :nnoremap <lt>return> :
```
For more help see:
```
:h key-codes
``` |
11,844 | <p>Let's say I had a block of text...</p>
<pre><code>Lorem ipsum
Lorem ipsum dolor
Lorem ipsum dolor sit
Lorem ipsum dolor sit amet
</code></pre>
<p>...and I wanted to insert a <code>.</code> at the end of each line. What would the best approach be to achieve this?</p>
| [
{
"answer_id": 11845,
"author": "user41805",
"author_id": 10378,
"author_profile": "https://vi.stackexchange.com/users/10378",
"pm_score": 3,
"selected": false,
"text": "<p>First you can visually select them using <code>V</code> and then use the movement keys to select the entire text (o... | 2017/03/21 | [
"https://vi.stackexchange.com/questions/11844",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11862/"
] | Let's say I had a block of text...
```
Lorem ipsum
Lorem ipsum dolor
Lorem ipsum dolor sit
Lorem ipsum dolor sit amet
```
...and I wanted to insert a `.` at the end of each line. What would the best approach be to achieve this? | I do the following to append text to multiple lines:
* `<c-V>` - Enter Visual Block mode.
* Use `j`/`k` to select the lines.
* `$` - Move cursor to last character.
* `A` - Enter insert mode after last character.
* Insert desired text.
* `<Esc>` - Exit insert mode and finish block append.
When compared to writing `:no... |
11,879 | <p>All the vim related files installed on /usr/share/vim/vim74. </p>
<pre><code>cd /home/debian8/
ls .vim*
.viminfo .vimrc
</code></pre>
<p>To create .vim directory to install some plugin for customization.</p>
<pre><code>mkdir .vim
mkdir .vim/plugin
mkdir .vim/autoload
</code></pre>
<p>If .viminfo and .vim... | [
{
"answer_id": 11881,
"author": "Tommy A",
"author_id": 5229,
"author_profile": "https://vi.stackexchange.com/users/5229",
"pm_score": 4,
"selected": true,
"text": "<p><strong>Note:</strong> @Rich's answer is more correct, but this is still a valid way to set a \"default\" arbitrary path... | 2017/03/25 | [
"https://vi.stackexchange.com/questions/11879",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5181/"
] | All the vim related files installed on /usr/share/vim/vim74.
```
cd /home/debian8/
ls .vim*
.viminfo .vimrc
```
To create .vim directory to install some plugin for customization.
```
mkdir .vim
mkdir .vim/plugin
mkdir .vim/autoload
```
If .viminfo and .vimrc are moved into .vim directory directly, then the ... | **Note:** @Rich's answer is more correct, but this is still a valid way to set a "default" arbitrary path for `vimrc`.
The easiest way to have a custom `vimrc` location is to use the `VIMINIT` environment variable:
```
export VIMINIT="source ~/.vim/vimrc"
```
See `:h VIMINIT`
It's ignored when using `vim -u ~/some... |
11,903 | <p>I saw something strange happen today.
I was in directory <code>/some/path/</code> and opened a file with <code>vim file.html</code>.</p>
<p>I then did :pwd in vim and it gave me <code>/some/other/path</code>. What could cause this to happen?</p>
<p>EDIT: <code>:verbose set autochdir?</code> outputs <code>noautochd... | [
{
"answer_id": 11904,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 2,
"selected": false,
"text": "<p>In your <code>vimrc</code> put <code>set autochdir</code> and your path will always follow your current file. Otherwi... | 2017/03/28 | [
"https://vi.stackexchange.com/questions/11903",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11953/"
] | I saw something strange happen today.
I was in directory `/some/path/` and opened a file with `vim file.html`.
I then did :pwd in vim and it gave me `/some/other/path`. What could cause this to happen?
EDIT: `:verbose set autochdir?` outputs `noautochdir`
EDIT2: putting `set autochdir` in `~/.vimrc` doesn't solve it... | In your `vimrc` put `set autochdir` and your path will always follow your current file. Otherwise vim will usually stay in either your home directory or in the first file you edited without you explicitly telling it to change with `cd`.
See [`:help 'autochdir'`](http://vimhelp.appspot.com/options.txt.html#%27autochdir... |
11,911 | <p>I have set Vim's default colorscheme to Monokai, and when I exit Vim the Monokai colors are still on the screen until I <code>clear</code> it.</p>
<p>How can Vim be set to run <code>clear</code> automatically on exit, or change the color scheme or at least the background color to what it was before it started?</p>
| [
{
"answer_id": 11918,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 4,
"selected": true,
"text": "<h1>How to Clear the Screen When Exiting Vim</h1>\n\n<p>When Vim quits, it sends the escape sequence defined by the <code>t_te</... | 2017/03/29 | [
"https://vi.stackexchange.com/questions/11911",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9540/"
] | I have set Vim's default colorscheme to Monokai, and when I exit Vim the Monokai colors are still on the screen until I `clear` it.
How can Vim be set to run `clear` automatically on exit, or change the color scheme or at least the background color to what it was before it started? | How to Clear the Screen When Exiting Vim
========================================
When Vim quits, it sends the escape sequence defined by the `t_te` setting to the terminal in order to tell it what to do. This should be set automatically by Vim to do something sensible, but it looks like something's going wrong in you... |
11,941 | <p>How can I convince Vim or Neovim to show the enclosing namespace, class, and function that the cursor is in?</p>
<p>Some programming languages have no interesting namespaces or class names. In general, this question is about displaying whatever enclosing context exists for relevant programming language.</p>
<p>If ... | [
{
"answer_id": 11942,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 0,
"selected": false,
"text": "<p>Discl: Not an answer that will help you much.</p>\n\n<p>A very long time ago, I wrote a ftplugin able to extract cur... | 2017/04/01 | [
"https://vi.stackexchange.com/questions/11941",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/268/"
] | How can I convince Vim or Neovim to show the enclosing namespace, class, and function that the cursor is in?
Some programming languages have no interesting namespaces or class names. In general, this question is about displaying whatever enclosing context exists for relevant programming language.
If there's no genera... | The following snippet maps `CTRL-g` to show the current "context" (usually the current function):
```
nnoremap <C-g> :echo getline(search('\v^[[:alpha:]$_]', "bn", 1, 100))<CR>
```
This is the same hack used by git uses to show context hints. Credit to [lost.vim](https://github.com/frioux/vim-lost) for the idea.
As... |
11,951 | <p>I want to find the string enclosed by string1 and string2 and replace it with something else. I got a few lines that look something like</p>
<pre><code>some_string_and_string1_some_rndom_string_string2_and_more
sme_string_and_string1_some_random_string_string2_and_more
some_string_and_string1_some_random_string_str... | [
{
"answer_id": 11952,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 3,
"selected": true,
"text": "<p>Don't use <code>^</code> and <code>$</code>. <code>^</code> is <code>start of a line</code> - which means that expressio... | 2017/04/03 | [
"https://vi.stackexchange.com/questions/11951",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12032/"
] | I want to find the string enclosed by string1 and string2 and replace it with something else. I got a few lines that look something like
```
some_string_and_string1_some_rndom_string_string2_and_more
sme_string_and_string1_some_random_string_string2_and_more
some_string_and_string1_some_random_string_string2_and_mre
.... | Don't use `^` and `$`. `^` is `start of a line` - which means that expression you're looking for needs to be at the very beginning of a line.
The same goes for `$`, which means `end of a line`. In you're case there is something between `^` and `string1`/`$` and `string2`, and regex expects that `string1` will be first,... |
11,956 | <p>I'm trying to understand how <a href="http://vimhelp.appspot.com/repeat.txt.html#packages" rel="noreferrer">the <code>packages</code> feature in Vim 8</a> works. The documentation suggests doing the following:</p>
<pre><code> % mkdir -p ~/.vim/pack/foo
% cd ~/.vim/pack/foo
% unzip /tmp/foopack.zip
The ... | [
{
"answer_id": 11958,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": true,
"text": "<h1>Yes, you can have multiple <code>pack</code> directories</h1>\n\n<p>In the example you quote from the documentation, \"foo\"... | 2017/04/03 | [
"https://vi.stackexchange.com/questions/11956",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10929/"
] | I'm trying to understand how [the `packages` feature in Vim 8](http://vimhelp.appspot.com/repeat.txt.html#packages) works. The documentation suggests doing the following:
```
% mkdir -p ~/.vim/pack/foo
% cd ~/.vim/pack/foo
% unzip /tmp/foopack.zip
The directory name "foo" is arbitrary, you can pick anyth... | Yes, you can have multiple `pack` directories
=============================================
In the example you quote from the documentation, "foo" is the name of the package.
In your example, you've created a single package named "bundle". You could indeed create other subdirectories of the `pack` directory: each of ... |
11,966 | <p>Let's say I have ten splits as follows: </p>
<pre><code>|0|1|2|3|4|
|5|6|7|8|9|
</code></pre>
<p>I now try to reduce the width of split 1 to be able to increase split 3 quite a bit (whoever wrote that particular file, used fairly long lines).</p>
<p>My problem is that when I attempt to change the size of split 1 ... | [
{
"answer_id": 11994,
"author": "GH05T",
"author_id": 12030,
"author_profile": "https://vi.stackexchange.com/users/12030",
"pm_score": 1,
"selected": false,
"text": "<p>Prefix a number before the split command to reduce it to a desired number of rows or columns: e.g., <code>:10sp</code> ... | 2017/04/03 | [
"https://vi.stackexchange.com/questions/11966",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12049/"
] | Let's say I have ten splits as follows:
```
|0|1|2|3|4|
|5|6|7|8|9|
```
I now try to reduce the width of split 1 to be able to increase split 3 quite a bit (whoever wrote that particular file, used fairly long lines).
My problem is that when I attempt to change the size of split 1 with `Ctrl+w <` , the extra space... | Prefix a number before the split command to reduce it to a desired number of rows or columns: e.g., `:10sp` or `:20vsp`
See also: `:help sp` |
11,977 | <p>Given the following code in visual mode :</p>
<pre><code>{
{
some text
^ cursor
}
}
</code></pre>
<p>if I type <code>a{</code> this will be selected : </p>
<pre><code>{
{ < selection start
some text
} < selection end
}
</code></pre>
<p>I'd like to repeat the last selection command to ex... | [
{
"answer_id": 11995,
"author": "GH05T",
"author_id": 12030,
"author_profile": "https://vi.stackexchange.com/users/12030",
"pm_score": 0,
"selected": false,
"text": "<p><code>V4j</code> (shift-v) works. I'm not sure repeat will work for you here.</p>\n\n<p>Alternatively, from the top br... | 2017/04/04 | [
"https://vi.stackexchange.com/questions/11977",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/4542/"
] | Given the following code in visual mode :
```
{
{
some text
^ cursor
}
}
```
if I type `a{` this will be selected :
```
{
{ < selection start
some text
} < selection end
}
```
I'd like to repeat the last selection command to expand my selection to include the enclosing brackets with `.`
```... | You can fake it with this:
```
vnoremap <expr> . expand('<cword>') =~# '[(){}\[\]]' ? 'a'.expand('<cword>') : ''
```
The character under the cursor is used to expand the selection if it's one of the brace characters. Since an expression map is being used, you never leave visual mode, which avoids breaking the normal... |
11,987 | <p>What's the quickest (as far as anyone knows) way to change this:</p>
<pre><code>int main()
{
</code></pre>
<p>into this:</p>
<pre><code>int main() {
</code></pre>
<p>provided the cursor is on the <code>{</code>?</p>
| [
{
"answer_id": 11995,
"author": "GH05T",
"author_id": 12030,
"author_profile": "https://vi.stackexchange.com/users/12030",
"pm_score": 0,
"selected": false,
"text": "<p><code>V4j</code> (shift-v) works. I'm not sure repeat will work for you here.</p>\n\n<p>Alternatively, from the top br... | 2017/04/04 | [
"https://vi.stackexchange.com/questions/11987",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11809/"
] | What's the quickest (as far as anyone knows) way to change this:
```
int main()
{
```
into this:
```
int main() {
```
provided the cursor is on the `{`? | You can fake it with this:
```
vnoremap <expr> . expand('<cword>') =~# '[(){}\[\]]' ? 'a'.expand('<cword>') : ''
```
The character under the cursor is used to expand the selection if it's one of the brace characters. Since an expression map is being used, you never leave visual mode, which avoids breaking the normal... |
12,001 | <p>I like using the <a href="https://ss64.com/bash/syntax-keyboard.html" rel="nofollow noreferrer">Bash shortcuts</a> while at the command line to move around and edit text. A sample of some commands from the link can be seen below:</p>
<pre><code>Ctrl + a Go to the beginning of the line (Home)
Ctrl + w Cut the Wo... | [
{
"answer_id": 12002,
"author": "Tommy A",
"author_id": 5229,
"author_profile": "https://vi.stackexchange.com/users/5229",
"pm_score": 3,
"selected": false,
"text": "<p>Type <code><c-o></code> to temporarily leave insert mode and use normal mode keys instead.</p>\n\n<p>To create in... | 2017/04/05 | [
"https://vi.stackexchange.com/questions/12001",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11605/"
] | I like using the [Bash shortcuts](https://ss64.com/bash/syntax-keyboard.html) while at the command line to move around and edit text. A sample of some commands from the link can be seen below:
```
Ctrl + a Go to the beginning of the line (Home)
Ctrl + w Cut the Word before the cursor to the clipboard.
Ctrl + e G... | Type `<c-o>` to temporarily leave insert mode and use normal mode keys instead.
To create insert mode maps, read `:h normal-index` and `:h insert-index`. Then create insert maps that does about the same thing you want. For example:
```
inoremap <c-a> <c-o>0
inoremap <c-w> <c-o>db
inoremap <c-e> <c-o>$
```
The reaso... |
12,004 | <p>I'd like to write a visually selected area to a file.</p>
<p>For example:</p>
<pre><code>prefix [sample text
more text] suffix
</code></pre>
<p><code>[]</code> is the selected block which should be taken, resulting in a new file containing:</p>
<pre><code>sample text
more text
</code></pre>
<p>The normal <code>... | [
{
"answer_id": 12006,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 5,
"selected": true,
"text": "<p>First, copy (also called 'yank' in vim parlance) your visual selection to the register of your choice. For example, to copy t... | 2017/04/06 | [
"https://vi.stackexchange.com/questions/12004",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10337/"
] | I'd like to write a visually selected area to a file.
For example:
```
prefix [sample text
more text] suffix
```
`[]` is the selected block which should be taken, resulting in a new file containing:
```
sample text
more text
```
The normal `w` command uses lines so `'<,'>w! /tmp/test` would include the prefix/su... | First, copy (also called 'yank' in vim parlance) your visual selection to the register of your choice. For example, to copy to register 'z', make your visual selection, and then type `"zy`.
In the case you give, you could do this without moving the cursor, by putting the cursor on the first square brace, and then typi... |
12,013 | <p>I have found a related question here:<br>
<a href="https://vi.stackexchange.com/questions/11015/automatically-set-the-number-option-in-vim-when-entering-ex-mode-set-nonumbe">Automatically set the 'number' option in Vim when entering Ex mode, set 'nonumber' in visual mode</a></p>
<p>Still I am not su... | [
{
"answer_id": 12015,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 3,
"selected": true,
"text": "<p>Use the <code>InsertEnter</code> and <code>InsertLeave</code> autocmd events. For example, say I [ab]used the <code>cursorlin... | 2017/04/06 | [
"https://vi.stackexchange.com/questions/12013",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5243/"
] | I have found a related question here:
[Automatically set the 'number' option in Vim when entering Ex mode, set 'nonumber' in visual mode](https://vi.stackexchange.com/questions/11015/automatically-set-the-number-option-in-vim-when-entering-ex-mode-set-nonumbe)
Still I am not sure that I can follow those explanation... | Use the `InsertEnter` and `InsertLeave` autocmd events. For example, say I [ab]used the `cursorline` setting instead of the foldcolumn:
```
autocmd InsertEnter * set cursorline
autocmd InsertLeave * set nocursorline
```
[](https://i.stack.imgur.com/... |
12,026 | <p>As the title says. Is it possible?</p>
<h3>Steps to reproduce:</h3>
<p>Type in <code>sample(text)</code> and put the cursor on the first character then press <code>w</code>.</p>
<h3>Expected behavior:</h3>
<p>Cursor moves to beginning of next word - <code>text</code></p>
<p><a href="https://i.stack.imgur.com/hO... | [
{
"answer_id": 12027,
"author": "Tommy A",
"author_id": 5229,
"author_profile": "https://vi.stackexchange.com/users/5229",
"pm_score": 3,
"selected": true,
"text": "<blockquote>\n <p>Is it possible?</p>\n</blockquote>\n\n<p>Anything is possible with some scripting:</p>\n\n<pre><code>nno... | 2017/04/08 | [
"https://vi.stackexchange.com/questions/12026",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11307/"
] | As the title says. Is it possible?
### Steps to reproduce:
Type in `sample(text)` and put the cursor on the first character then press `w`.
### Expected behavior:
Cursor moves to beginning of next word - `text`
[](https://i.stack.imgur.com/hOSVy.p... | >
> Is it possible?
>
>
>
Anything is possible with some scripting:
```
nnoremap <silent> <leader>w :call search('\<\w', 'W')<cr>
nnoremap <silent> <leader>e :call search('\w\>', 'W')<cr>
nnoremap <silent> <leader>b :call search('\<\w', 'bW')<cr>
nnoremap <silent> <leader>gE :call search('\w\>', 'bW')<cr>
```
I... |
12,037 | <p>I am creating a <code>.vimrc</code> that will be shared by all the users on the system, ie it will be set from <code>/etc/skel</code>. However after starting it should be able to load the users own customizations, which normally go into <code>.vimrc</code> itself.
The <code>~/.vimrc</code> file its actually symlinke... | [
{
"answer_id": 12038,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 3,
"selected": true,
"text": "<p>You can add <code>source</code> command at the end of the main <code>.vimrc</code>, like so:</p>\n\n<pre><code>if filere... | 2017/04/09 | [
"https://vi.stackexchange.com/questions/12037",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9540/"
] | I am creating a `.vimrc` that will be shared by all the users on the system, ie it will be set from `/etc/skel`. However after starting it should be able to load the users own customizations, which normally go into `.vimrc` itself.
The `~/.vimrc` file its actually symlinked to the central file, which should then load t... | You can add `source` command at the end of the main `.vimrc`, like so:
```
if filereadable(expand("$HOME/.vimcustomrc"))
execute "source " . expand("$HOME/.vimcustomrc")
endif
``` |
12,042 | <pre><code>adfa.ad.asdf.efa.saf mark
</code></pre>
<p>I need to match the <code>saf mark</code>, no more no less ahead. </p>
<p>I find that if I use this,</p>
<pre><code>/\v[,.;]\zs.{-}mark
</code></pre>
<p>It matches all along to the first <code>.</code>. Any suggestions? Thanks. </p>
| [
{
"answer_id": 12043,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 3,
"selected": true,
"text": "<p>If you make your collection negative, it should do what you want:\n<code>/[^,.;]*mark</code></p>\n"
},
{
... | 2017/04/10 | [
"https://vi.stackexchange.com/questions/12042",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1788/"
] | ```
adfa.ad.asdf.efa.saf mark
```
I need to match the `saf mark`, no more no less ahead.
I find that if I use this,
```
/\v[,.;]\zs.{-}mark
```
It matches all along to the first `.`. Any suggestions? Thanks. | If you make your collection negative, it should do what you want:
`/[^,.;]*mark` |
12,046 | <p>I set a variable <code>b:aaa</code> which has the value that I can see via <code>echo b:aaa</code>, how can I copy that to text? I know I can do it by </p>
<pre><code>set @a = b:aaa
"ap
</code></pre>
<p>to get it. But can I copy it to the an open file directly? </p>
| [
{
"answer_id": 12047,
"author": "rbernabe",
"author_id": 11690,
"author_profile": "https://vi.stackexchange.com/users/11690",
"pm_score": 1,
"selected": false,
"text": "<p>Registers works like variables, so you are almost done. I think this would work for you:</p>\n\n<pre><code>let @a = ... | 2017/04/10 | [
"https://vi.stackexchange.com/questions/12046",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1788/"
] | I set a variable `b:aaa` which has the value that I can see via `echo b:aaa`, how can I copy that to text? I know I can do it by
```
set @a = b:aaa
"ap
```
to get it. But can I copy it to the an open file directly? | To put the value of a variable into a buffer use the `:put` command with the expression register, `@=`:
```
put=b:aaa
```
You can use a range with `:put` to put it at a specific location. Put below the 9th line:
```
9put=b:aaa
```
Note: use `:put!` to put above the current line
For more help see:
```
:h :put
:h... |
12,048 | <p>I'm getting lag in vim when navigating relatively small text files if <code>filetype plugin indent on</code> is uncommented in my vimrc file. My full vimrc file is pasted below. Any help on how I can get it enabled properly with no lag? It's worked fine in the past. I only started having this issue lately.</p>
<... | [
{
"answer_id": 12055,
"author": "Wolfie",
"author_id": 9182,
"author_profile": "https://vi.stackexchange.com/users/9182",
"pm_score": 1,
"selected": false,
"text": "<p>Most likely you have something in your actual syntax files causing the lag.\nI'd reccomend running <code>:syntime on</co... | 2017/04/10 | [
"https://vi.stackexchange.com/questions/12048",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12162/"
] | I'm getting lag in vim when navigating relatively small text files if `filetype plugin indent on` is uncommented in my vimrc file. My full vimrc file is pasted below. Any help on how I can get it enabled properly with no lag? It's worked fine in the past. I only started having this issue lately.
```
set nocompatible ... | I think my issue was related to <https://github.com/vim/vim/issues/1098> I've updated to vim 8.0 and it seems to have fixed it. |
12,049 | <p>What is the best way of linking the Ctrl-V key combination to pasting the clipboard in insert mode?
I used </p>
<pre><code>map <C-v> "+gP
imap <C-v> <C-r><C-p>+
</code></pre>
<p>in <code>.vimrc</code>. However in insert mode, this definition sometimes doesn't work, it pasts the inserted te... | [
{
"answer_id": 12052,
"author": "Tommy A",
"author_id": 5229,
"author_profile": "https://vi.stackexchange.com/users/5229",
"pm_score": 3,
"selected": true,
"text": "<p>I think the problem is that the <code>+</code> register contains <code>linewise</code> text. I can't say if that's a bu... | 2017/04/10 | [
"https://vi.stackexchange.com/questions/12049",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12163/"
] | What is the best way of linking the Ctrl-V key combination to pasting the clipboard in insert mode?
I used
```
map <C-v> "+gP
imap <C-v> <C-r><C-p>+
```
in `.vimrc`. However in insert mode, this definition sometimes doesn't work, it pasts the inserted text in a new line above the current cursor position.
**Edit:... | I think the problem is that the `+` register contains `linewise` text. I can't say if that's a bug or not.
This seems to give the same effect while ignoring the register type:
```
inoremap <c-v> <esc>:set paste<cr>a<c-r>=getreg('+')<cr><esc>:set nopaste<cr>mi`[=`]`ia
```
It temporarily enables the `paste` option to... |
12,056 | <p>Suppose I have a very long file, for example:</p>
<pre><code>class X {
// ...
void foo() {
// ...
if (something) {
a00();
a01();
a02();
// ...
// ...
a98();
a99();
}
}
}
</code></pre>
<p>When scr... | [
{
"answer_id": 12066,
"author": "Naumann",
"author_id": 11477,
"author_profile": "https://vi.stackexchange.com/users/11477",
"pm_score": 4,
"selected": true,
"text": "<p>I would simply use <code>:rightbelow split</code>.</p>\n"
},
{
"answer_id": 12069,
"author": "grodzik",
... | 2017/04/11 | [
"https://vi.stackexchange.com/questions/12056",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8108/"
] | Suppose I have a very long file, for example:
```
class X {
// ...
void foo() {
// ...
if (something) {
a00();
a01();
a02();
// ...
// ...
a98();
a99();
}
}
}
```
When scrolling down to the bottom,... | I would simply use `:rightbelow split`. |
12,058 | <p>Is there a solution to printing unicode characters from <code>gvim</code>? </p>
<p>See this: </p>
<p><a href="https://i.stack.imgur.com/vOwHt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vOwHt.png" alt="enter image description here"></a></p>
<p>Results in this print result</p>
<p><a href="h... | [
{
"answer_id": 16155,
"author": "Victoria Stuart",
"author_id": 10749,
"author_profile": "https://vi.stackexchange.com/users/10749",
"pm_score": 2,
"selected": false,
"text": "<p>Per this Stackoverflow:4586628 Q/A, <a href=\"https://stackoverflow.com/questions/4586628/how-do-you-pipe-a-v... | 2017/04/11 | [
"https://vi.stackexchange.com/questions/12058",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12163/"
] | Is there a solution to printing unicode characters from `gvim`?
See this:
[](https://i.stack.imgur.com/vOwHt.png)
Results in this print result
[](https://i.stack.imgur.com/3XIZ2.... | Per this Stackoverflow:4586628 Q/A, [How do you pipe a vim buffer through lpr?](https://stackoverflow.com/questions/4586628/how-do-you-pipe-a-vim-buffer-through-lpr/4586667#4586667), I have this entry in my `~/.vimrc`:
```
nmap PpP :%w !lpr -o lpi=8 -o cpi=14<CR><CR>
```
that replaces my old entry,
```
nmap PpP :ha... |
12,061 | <p>Is there an option to apply a setting in all tabs and windows, e.g. apply <code>:set number</code> to all open tabs?</p>
| [
{
"answer_id": 12062,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 6,
"selected": true,
"text": "<p>Yes, there is! You can accomplish this with <code>:tabdo</code> and <code>:windo</code>. For your case specifically:</... | 2017/04/11 | [
"https://vi.stackexchange.com/questions/12061",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9540/"
] | Is there an option to apply a setting in all tabs and windows, e.g. apply `:set number` to all open tabs? | Yes, there is! You can accomplish this with `:tabdo` and `:windo`. For your case specifically:
```
:tabdo windo set number
```
See [`:help :tabdo`](http://vimhelp.appspot.com/tabpage.txt.html#%3Atabdo) and [`:help :windo`](http://vimhelp.appspot.com/windows.txt.html#%3Awindo) for more information. |
12,073 | <p>Currently, I'm using <a href="https://github.com/tpope/vim-surround" rel="nofollow noreferrer">Vim Surround</a> to make quoting easy on </p>
<ul>
<li>Multiple whole-lines</li>
<li>Visual blocks</li>
<li>Individual words</li>
</ul>
<p>However, it doesn't seem to make the job easy on columns, for example. Take <a hr... | [
{
"answer_id": 12062,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 6,
"selected": true,
"text": "<p>Yes, there is! You can accomplish this with <code>:tabdo</code> and <code>:windo</code>. For your case specifically:</... | 2017/04/12 | [
"https://vi.stackexchange.com/questions/12073",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5078/"
] | Currently, I'm using [Vim Surround](https://github.com/tpope/vim-surround) to make quoting easy on
* Multiple whole-lines
* Visual blocks
* Individual words
However, it doesn't seem to make the job easy on columns, for example. Take [this question for example](https://stackoverflow.com/q/43328774/124486), I can get ... | Yes, there is! You can accomplish this with `:tabdo` and `:windo`. For your case specifically:
```
:tabdo windo set number
```
See [`:help :tabdo`](http://vimhelp.appspot.com/tabpage.txt.html#%3Atabdo) and [`:help :windo`](http://vimhelp.appspot.com/windows.txt.html#%3Awindo) for more information. |
12,096 | <p>This is similar to <a href="https://vi.stackexchange.com/questions/6134/mapping-ctrl-z-in-insert-mode">a previous question re: Ctrl-Z</a>. The context is different though: I use a bash shell window, in which I am in insert mode.
Hitting <kbd>Ctrl</kbd>+<kbd>^</kbd> in this mode means that I probably meant to switch ... | [
{
"answer_id": 12112,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 2,
"selected": true,
"text": "<p>It should be very similar to the linked question:</p>\n\n<pre><code>inoremap <C-^> <Esc><C-^>\n</cod... | 2017/04/16 | [
"https://vi.stackexchange.com/questions/12096",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5919/"
] | This is similar to [a previous question re: Ctrl-Z](https://vi.stackexchange.com/questions/6134/mapping-ctrl-z-in-insert-mode). The context is different though: I use a bash shell window, in which I am in insert mode.
Hitting `Ctrl`+`^` in this mode means that I probably meant to switch to my other buffer. | It should be very similar to the linked question:
```
inoremap <C-^> <Esc><C-^>
```
This just makes it so that if you type `<C-^>` in insert mode it goes to normal mode and does the command there instead.
See [`:help map-overview`](http://vimhelp.appspot.com/map.txt.html#map-overview) for more info. |
12,101 | <p>I am in the process of customizing my vim setup, and since I write a lot in C, I have a whole function dedicated just for those files, which I call with <code>autocmd filetype c,cpp,h,hpp call C_syntax()</code>.</p>
<p>The issue I'm having is that I want auto folding to occur on .c and .cpp files, but not .h and .h... | [
{
"answer_id": 12105,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 2,
"selected": false,
"text": "<p>In a c ftplugin, check (<code>:h :if</code>) for the extension of the current buffer (with <code>: h expand ()</code... | 2017/04/16 | [
"https://vi.stackexchange.com/questions/12101",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12244/"
] | I am in the process of customizing my vim setup, and since I write a lot in C, I have a whole function dedicated just for those files, which I call with `autocmd filetype c,cpp,h,hpp call C_syntax()`.
The issue I'm having is that I want auto folding to occur on .c and .cpp files, but not .h and .hpp files. In order to... | In a c ftplugin, check (`:h :if`) for the extension of the current buffer (with `: h expand ()`). If you match a header file don't set the option. Otherwise do.
You can define the thing with autocommands, but it's easy to get it wrong, beside it doesn't scale well |
12,117 | <h2>Context</h2>
<p>Currently, when I <code>set ft=tex</code>, my <code>set isk?</code> reads</p>
<pre><code>iskeyword=@,48-57,_,192-255
</code></pre>
<p>that is, the default for vim.</p>
<h2>My "issue"</h2>
<p>Currently, in a LaTeX string such as </p>
<pre><code>$\abcde_\fgh$
</code></pre>
<p>the <code>w</code>... | [
{
"answer_id": 12115,
"author": "Jay Dorsey",
"author_id": 12256,
"author_profile": "https://vi.stackexchange.com/users/12256",
"pm_score": 3,
"selected": true,
"text": "<p>The <code>.vimrc</code> is sourced from both Vim & Gvim. This file will allow you to set up a common set of CLI... | 2017/04/17 | [
"https://vi.stackexchange.com/questions/12117",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8748/"
] | Context
-------
Currently, when I `set ft=tex`, my `set isk?` reads
```
iskeyword=@,48-57,_,192-255
```
that is, the default for vim.
My "issue"
----------
Currently, in a LaTeX string such as
```
$\abcde_\fgh$
```
the `w` jump would take me from the start to
1. `a`
2. `\`
3. `f`
4. `$`
Thus, the above set... | The `.vimrc` is sourced from both Vim & Gvim. This file will allow you to set up a common set of CLI & GUI plugins in a single location (shared by both the CLI Vim & Gvim)
The `.gvimrc` is used by Gvim only and will be sourced by Gvim only *after* the `.vimrc`. Regular command line Vim won't read from it.
Within Gvim... |
12,119 | <p>I'd like to highlight sections of a document which are too long (measured in lines) so they will all print on a physical page. Sections are separated with <code>===</code>. I tried to do it with this code:</p>
<pre><code>matchadd('ErrorMsg', '\%(^\|===\n\)\%(.*\n\)\{5}\zs\%(.*\n\)\+\ze', -1)
</code></pre>
<p>Every... | [
{
"answer_id": 12137,
"author": "mike",
"author_id": 7267,
"author_profile": "https://vi.stackexchange.com/users/7267",
"pm_score": 0,
"selected": false,
"text": "<p>How about <code>:au BufWinEnter * let w:m1=matchadd('ErrorMsg', '\\(^===\\)\\_p\\{20,}\\1', -1)</code> ? </p>\n\n<p>This w... | 2017/04/18 | [
"https://vi.stackexchange.com/questions/12119",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12258/"
] | I'd like to highlight sections of a document which are too long (measured in lines) so they will all print on a physical page. Sections are separated with `===`. I tried to do it with this code:
```
matchadd('ErrorMsg', '\%(^\|===\n\)\%(.*\n\)\{5}\zs\%(.*\n\)\+\ze', -1)
```
Everything works hunky-dory. But when I in... | If you are not insisting on using `matchadd` you can try to use `properties`, here is the proof of concept you can play with:
```
call prop_type_add('TEST', {'highlight': 'ErrorMsg'})
"screen jumps sometimes, try to find your own way
func! UpdatePage(pagesize) abort
let cpos = getcurpos()
1
call prop_clea... |
12,120 | <p>When I use the normal mode and output the search result using the following input,</p>
<pre><code>/LOAD \d\{-}\_p\+\d\n
</code></pre>
<p>it includes the first line,
<a href="https://i.stack.imgur.com/r2Xjv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r2Xjv.png" alt="enter image description he... | [
{
"answer_id": 12137,
"author": "mike",
"author_id": 7267,
"author_profile": "https://vi.stackexchange.com/users/7267",
"pm_score": 0,
"selected": false,
"text": "<p>How about <code>:au BufWinEnter * let w:m1=matchadd('ErrorMsg', '\\(^===\\)\\_p\\{20,}\\1', -1)</code> ? </p>\n\n<p>This w... | 2017/04/18 | [
"https://vi.stackexchange.com/questions/12120",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12103/"
] | When I use the normal mode and output the search result using the following input,
```
/LOAD \d\{-}\_p\+\d\n
```
it includes the first line,
[](https://i.stack.imgur.com/r2Xjv.png)
However when I use the ex-command,
```
:g/LOAD \d\{-}\_p\+\d\n/z
... | If you are not insisting on using `matchadd` you can try to use `properties`, here is the proof of concept you can play with:
```
call prop_type_add('TEST', {'highlight': 'ErrorMsg'})
"screen jumps sometimes, try to find your own way
func! UpdatePage(pagesize) abort
let cpos = getcurpos()
1
call prop_clea... |
12,122 | <p>Both <code>:file</code> and <code>:saveas</code> seem to change the name of the buffer without writing. What's the difference between them? Also, in scratch buffers, <code>:saveas</code> seems to cause an error while <code>:file</code> does not. I included the relevant help sections below, but need some help maki... | [
{
"answer_id": 12123,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 4,
"selected": true,
"text": "<p><code>:saveas</code> does write to files, after all the help says: \"<em>Save</em> the current buffer under the name {file}\"... | 2017/04/18 | [
"https://vi.stackexchange.com/questions/12122",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10490/"
] | Both `:file` and `:saveas` seem to change the name of the buffer without writing. What's the difference between them? Also, in scratch buffers, `:saveas` seems to cause an error while `:file` does not. I included the relevant help sections below, but need some help making sense of them.
```
CTRL-G or *CTRL-G... | `:saveas` does write to files, after all the help says: "*Save* the current buffer under the name {file}". Note also how it says that `!` is needed to overwrite an existing file. You wouldn't need to talk about overwriting if writing wasn't involved.
Also, note the message from a successful `saveas` command:
```
"bar... |
12,129 | <p>I am working on a VIM plugin that will require a certain level of complexity for handling arguments passed to a command.</p>
<pre><code>:MyCommand -item=banana -command=ls\-ltra -pattern=./*
</code></pre>
<p>However, I am not sure how to handle this situation. I am aware of how arguments work in vimL, with the <co... | [
{
"answer_id": 12132,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 4,
"selected": true,
"text": "<p>You should be able to do this simply by splitting the arg on an <code>=</code> and going through a for loop. Something... | 2017/04/18 | [
"https://vi.stackexchange.com/questions/12129",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5328/"
] | I am working on a VIM plugin that will require a certain level of complexity for handling arguments passed to a command.
```
:MyCommand -item=banana -command=ls\-ltra -pattern=./*
```
However, I am not sure how to handle this situation. I am aware of how arguments work in vimL, with the `a:0` and `a:000` and the `<f... | You should be able to do this simply by splitting the arg on an `=` and going through a for loop. Something like the following should work.
```
command! -nargs=+ MyCommand :call MyFunction(<f-args>)
let s:dictionary = {}
function! MyFunction(...)
for arg in a:000
let myList = split(arg, '=')
let s:dict... |
12,140 | <p>I've been using Vim for decades (and Vi before it since around 1984.) I use it now on Linux. Somewhere along the line one behavior crept in that I'd like to disable: when I click in a window to move the focus, and the click happens to be in the body of the window, Vim moves the cursor to wherever the click landed.... | [
{
"answer_id": 12143,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 3,
"selected": true,
"text": "<p>Here's a heavy solution:</p>\n\n<pre><code>nnoremap <LeftMouse> ma<LeftMouse>`a\n</code></pre>\n\n<p>It wi... | 2017/04/18 | [
"https://vi.stackexchange.com/questions/12140",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12277/"
] | I've been using Vim for decades (and Vi before it since around 1984.) I use it now on Linux. Somewhere along the line one behavior crept in that I'd like to disable: when I click in a window to move the focus, and the click happens to be in the body of the window, Vim moves the cursor to wherever the click landed. If t... | Here's a heavy solution:
```
nnoremap <LeftMouse> ma<LeftMouse>`a
```
It will let the click go through (thus changing the focus), but make sure the cursor always goes back to where it was before the click was initiated. |
12,146 | <p>Given the following text: <code>Hello Part1/Part2 Bye</code></p>
<p>With the cursor on top of any character in <code>Part1/Part2</code> I would like to be able to refer to the whole <code>Part1/Part2</code> (for visual selection, deletion, substitution, etc.). For simplicity, let's talk about deletion.</p>
<p><kbd... | [
{
"answer_id": 12147,
"author": "mike",
"author_id": 7267,
"author_profile": "https://vi.stackexchange.com/users/7267",
"pm_score": 0,
"selected": false,
"text": "<p>The question was answered in <a href=\"https://stackoverflow.com/questions/25856240/can-you-substitute-or-delete-between-c... | 2017/04/19 | [
"https://vi.stackexchange.com/questions/12146",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12266/"
] | Given the following text: `Hello Part1/Part2 Bye`
With the cursor on top of any character in `Part1/Part2` I would like to be able to refer to the whole `Part1/Part2` (for visual selection, deletion, substitution, etc.). For simplicity, let's talk about deletion.
`d``i``w` considers `/` a delimiting character, so it ... | Taken from @romainl answer [here](https://stackoverflow.com/a/25856426/2891462):
>
> I've had the following snippet in my `vimrc` for quite a while and it
> never failed me:
>
>
>
> ```
> for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '%' ]
> execute 'xnoremap i' . char . ' :<C-u>nor... |
12,169 | <p>As the title stated, <strong>remap ':' to maintain last command, and erase all char if any key other than <code><CR></code> was pressed.</strong></p>
<p><strong>possible use cases:</strong></p>
<ul>
<li>I have typed a long command, and I may or may not modified it, then re-run it.</li>
<li>I save a lot, so I... | [
{
"answer_id": 12170,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 1,
"selected": false,
"text": "<p>After a bit of hacking, I actually found a way to achive that:</p>\n\n<pre><code>function! AutoErase()\n setlocal curs... | 2017/04/20 | [
"https://vi.stackexchange.com/questions/12169",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10254/"
] | As the title stated, **remap ':' to maintain last command, and erase all char if any key other than `<CR>` was pressed.**
**possible use cases:**
* I have typed a long command, and I may or may not modified it, then re-run it.
* I save a lot, so I want type `:`, then visually verify `:w` is there, then type `<CR>` to... | The following should solve your issue:
```
nnoremap <expr> : ShowLastCmd()
function! ShowLastCmd()
echohl ModeMsg
echo ':' . getreg(':')
echohl None
while 1
try
let char = getchar()
if char == '^\d\+$' || type(char) == 0
let char = nr2char(char)
endif
catch /^Vim:Interrupt$/... |
12,188 | <p>I'm creating a folder with common code snippets I use. </p>
<p>I want to create a quick command in vim to insert them, for example something like:</p>
<pre><code>:snippet codeblock1
</code></pre>
<p>Ideally it would be a single command and <code>codeblock1</code> could be replaced by the file name of a code snipp... | [
{
"answer_id": 12189,
"author": "StandardEyre",
"author_id": 6590,
"author_profile": "https://vi.stackexchange.com/users/6590",
"pm_score": 4,
"selected": true,
"text": "<p>The <code>:r</code> command can read a file containing a code snippet and insert it to your active buffer.</p>\n\n<... | 2017/04/21 | [
"https://vi.stackexchange.com/questions/12188",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7783/"
] | I'm creating a folder with common code snippets I use.
I want to create a quick command in vim to insert them, for example something like:
```
:snippet codeblock1
```
Ideally it would be a single command and `codeblock1` could be replaced by the file name of a code snippet.
That way I could have a single command ... | The `:r` command can read a file containing a code snippet and insert it to your active buffer.
Unless I'm missing something, I believe this would address your request. |
12,214 | <p>(I'm really not sure how I would google this. Sorry if this has already been asked and please just link me in the right direction in that case)</p>
<p>I'm using Vim in cygwin environment and marked a line in visual mode using <kbd>0</kbd>,<kbd>v</kbd>,<kbd>$</kbd>.
When I then pressed <kbd>:</kbd>, Vim automaticall... | [
{
"answer_id": 12215,
"author": "mike",
"author_id": 7267,
"author_profile": "https://vi.stackexchange.com/users/7267",
"pm_score": 1,
"selected": false,
"text": "<p><code>'<,'></code> is not a command, but a <strong>range</strong>.\nYou can <strong>prefix</strong> any command with... | 2017/04/24 | [
"https://vi.stackexchange.com/questions/12214",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12358/"
] | (I'm really not sure how I would google this. Sorry if this has already been asked and please just link me in the right direction in that case)
I'm using Vim in cygwin environment and marked a line in visual mode using `0`,`v`,`$`.
When I then pressed `:`, Vim automatically wrote `:'<, '>` into the command line. I'm w... | Surprisingly, better than Google is to search in Vim's builtin help.
`:h '<`
>
> '< `<
> To the first line or character of the last selected
> Visual area in the current buffer. For block mode it
> may also be the last character in the first line (to
> be able to define the block). {not in Vi}.
>
>
>
`:h '>`... |
12,244 | <p>I use abbreviations extensively to make writing in languages other than English easier. For example, I have something like this set up for when I'm writing in Italian:</p>
<pre><code>inoreabbrev perche' perché
inoreabbrev dopodiche' dopodiché
</code></pre>
<p>This way I can type the words above quickly without cha... | [
{
"answer_id": 12246,
"author": "mMontu",
"author_id": 1405,
"author_profile": "https://vi.stackexchange.com/users/1405",
"pm_score": 4,
"selected": true,
"text": "<p>You could use the <a href=\"https://github.com/tpope/vim-abolish/\" rel=\"noreferrer\">abolish plugin</a>. For your examp... | 2017/04/26 | [
"https://vi.stackexchange.com/questions/12244",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3079/"
] | I use abbreviations extensively to make writing in languages other than English easier. For example, I have something like this set up for when I'm writing in Italian:
```
inoreabbrev perche' perché
inoreabbrev dopodiche' dopodiché
```
This way I can type the words above quickly without changing keyboard layout syst... | You could use the [abolish plugin](https://github.com/tpope/vim-abolish/). For your example you could use the following:
```
:Abolish perche{'} perché
```
It changes `perche'` to `perché`, `Perche'` to `Perché` and `PERCHE'` to `PERCHÉ`. For the second example:
```
:Abolish dopodiche{'} dopodiché
``` |
12,256 | <p>I want to have a macro in my <code>.vimrc</code> which when activated will enter a command and execute it.</p>
<p>I want something like </p>
<pre><code>let @r = ':e!'
</code></pre>
<p>but instead of it just being entered in the command line I want it executed.</p>
| [
{
"answer_id": 12257,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 2,
"selected": false,
"text": "<p>Before ending <code>'</code> sign, press combination <kbd>Ctrl</kbd><kbd>V</kbd> followed by <kbd>Enter</kbd>. This wil... | 2017/04/27 | [
"https://vi.stackexchange.com/questions/12256",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12407/"
] | I want to have a macro in my `.vimrc` which when activated will enter a command and execute it.
I want something like
```
let @r = ':e!'
```
but instead of it just being entered in the command line I want it executed. | Your goal is to insert a literal `^M` character. You have two options: You can use digraphs (`:h digraphs`), or the `<C-v>` shortcut (`:h i_CTRL-v`).
Digraphs
--------
Digraphs are a way to enter hard-to-reach characters, like accented letters or special keys. If you look at the listing in `:digraphs`, you will see t... |
12,263 | <p>I want a file that contain only 1 and 0 for my java networking program.
Writing a big file containing only 1 and 0 is boring. So, if vim do this, it is better.</p>
<p>I don't know that it is whether possible or not, but I guess it is possible in vim. </p>
| [
{
"answer_id": 12264,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 0,
"selected": false,
"text": "<p>One way to do this is to use <code>system('echo $RANDOM')</code>:</p>\n\n<pre><code>function! MyGenerator(iter)\n let ... | 2017/04/28 | [
"https://vi.stackexchange.com/questions/12263",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9498/"
] | I want a file that contain only 1 and 0 for my java networking program.
Writing a big file containing only 1 and 0 is boring. So, if vim do this, it is better.
I don't know that it is whether possible or not, but I guess it is possible in vim. | To use a purely vimscript solution you can use some functions I described in
[another answer](https://vi.stackexchange.com/a/9845/1841) of mine:
```
" Randomization Variables
" with a little extra randomized start from localtime()
let g:rndm_m1 = 32007779 + (localtime()%100 - 50)
let g:rndm_m2 = 23717810 + (localtime(... |
12,271 | <p>I don't mind keeping the original mapping, I just want to bind it to something more convenient, so instead of typing <kbd>y</kbd><kbd>s</kbd><kbd>i</kbd><kbd>w</kbd><kbd>)</kbd>, I could for example do it with <kbd>Alt</kbd><kbd>(</kbd>.</p>
<p>I tried just adding <code>nnoremap <M-(> ysiw)</code> to my <code... | [
{
"answer_id": 12272,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 2,
"selected": false,
"text": "<p>First of all, you need to use <code>nmap</code>, not <code>nnoremap</code>, since <code>s</code> is already a mapping f... | 2017/04/29 | [
"https://vi.stackexchange.com/questions/12271",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12435/"
] | I don't mind keeping the original mapping, I just want to bind it to something more convenient, so instead of typing `y``s``i``w``)`, I could for example do it with `Alt``(`.
I tried just adding `nnoremap <M-(> ysiw)` to my `.vimrc`, but that did nothing.
I use gVim 8,
thanks in advance | As mentioned by grodzik, `nnoremap` does not take any non-standard mappings into account. That includes mappings by plugins. Simply changing to `nmap` is not the right way to go in my opinion. You will start to get used to `Alt (` and not need `ysiw)` anymore. With an `nmap` you will never be able to map something else... |
12,293 | <p>I can read a value from an option like:</p>
<pre><code>let b = &background
</code></pre>
<p>Is there a way to read a value from a highlight group? Something like this pseudo-code:</p>
<pre><code>let b = &StatusLine['ctermbg']
</code></pre>
<p>Ultimately, what I want to do is define a new highlight group ... | [
{
"answer_id": 12294,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 4,
"selected": true,
"text": "<p>As far as I know, there's not a simple way to do this. Here's a function that should be able to return the value given... | 2017/05/03 | [
"https://vi.stackexchange.com/questions/12293",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12489/"
] | I can read a value from an option like:
```
let b = &background
```
Is there a way to read a value from a highlight group? Something like this pseudo-code:
```
let b = &StatusLine['ctermbg']
```
Ultimately, what I want to do is define a new highlight group in terms of other highlight group colors (not a link, but... | As far as I know, there's not a simple way to do this. Here's a function that should be able to return the value given the highlight group and term. If there is no such term, an empty string will be returned instead.
```
function! ReturnHighlightTerm(group, term)
" Store output of group to variable
let output = ... |
12,311 | <p>In vi, I can get a shell terminal with <code>:sh</code> command. And later, I can return to vi by <code>exit</code> shell.</p>
<p>But, if I was using the shell terminal for a long time, and I forgot whether <code>exit</code> will close anything or return me the vi.</p>
<p>Is there any way to check whether I will r... | [
{
"answer_id": 12313,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 2,
"selected": false,
"text": "<p>Execute <code>ps</code>, or better, <code>ps -fH</code>. Ex:</p>\n\n<pre><code>$ ps -fH\nUID PID PPID C STIME... | 2017/05/04 | [
"https://vi.stackexchange.com/questions/12311",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9074/"
] | In vi, I can get a shell terminal with `:sh` command. And later, I can return to vi by `exit` shell.
But, if I was using the shell terminal for a long time, and I forgot whether `exit` will close anything or return me the vi.
Is there any way to check whether I will return to vi? `jobs` or `fg` is not working. | In a regular shell:
```
$ env | grep -i vim
EDITOR=vim
```
After using `:shell`
```
$ env | grep -i vim
EDITOR=vim
VIMRUNTIME=/usr/share/vim/vim80
VIM=/usr/share/vim
MYVIMRC=/home/martin/.vim/vimrc
```
So it looks like Vim sets the `VIMRUNTIME`, `VIM`, and `MYVIMRC` environment variables. Of those, `VIM` seems th... |
12,348 | <p>I am searching a Plugin for autocompletion which does not have any requirements to lua ruby or python.
I would love to use YouCompleteMe but it requires python, which is not availiable on my server. </p>
<p>At all vim there does not have lua, python or ruby support, which makes it really hard to find anything. </p... | [
{
"answer_id": 12313,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 2,
"selected": false,
"text": "<p>Execute <code>ps</code>, or better, <code>ps -fH</code>. Ex:</p>\n\n<pre><code>$ ps -fH\nUID PID PPID C STIME... | 2017/05/09 | [
"https://vi.stackexchange.com/questions/12348",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12519/"
] | I am searching a Plugin for autocompletion which does not have any requirements to lua ruby or python.
I would love to use YouCompleteMe but it requires python, which is not availiable on my server.
At all vim there does not have lua, python or ruby support, which makes it really hard to find anything.
Maybe there... | In a regular shell:
```
$ env | grep -i vim
EDITOR=vim
```
After using `:shell`
```
$ env | grep -i vim
EDITOR=vim
VIMRUNTIME=/usr/share/vim/vim80
VIM=/usr/share/vim
MYVIMRC=/home/martin/.vim/vimrc
```
So it looks like Vim sets the `VIMRUNTIME`, `VIM`, and `MYVIMRC` environment variables. Of those, `VIM` seems th... |
12,353 | <p>I wanted vim to increase its <code>&columns</code> automatically when I do a <code>:vsplit</code>, so I implemented the advice found here: <a href="https://groups.google.com/forum/#!topic/vim_use/R4gg-YdPHJM" rel="nofollow noreferrer">https://groups.google.com/forum/#!topic/vim_use/R4gg-YdPHJM</a></p>
<p>Basica... | [
{
"answer_id": 12313,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 2,
"selected": false,
"text": "<p>Execute <code>ps</code>, or better, <code>ps -fH</code>. Ex:</p>\n\n<pre><code>$ ps -fH\nUID PID PPID C STIME... | 2017/05/09 | [
"https://vi.stackexchange.com/questions/12353",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2511/"
] | I wanted vim to increase its `&columns` automatically when I do a `:vsplit`, so I implemented the advice found here: <https://groups.google.com/forum/#!topic/vim_use/R4gg-YdPHJM>
Basically, you add:
```
autocmd WinEnter * if winwidth(0) < 80 | set columns+=80 | wincmd = | endif
```
to `.vimrc`.
However, in termina... | In a regular shell:
```
$ env | grep -i vim
EDITOR=vim
```
After using `:shell`
```
$ env | grep -i vim
EDITOR=vim
VIMRUNTIME=/usr/share/vim/vim80
VIM=/usr/share/vim
MYVIMRC=/home/martin/.vim/vimrc
```
So it looks like Vim sets the `VIMRUNTIME`, `VIM`, and `MYVIMRC` environment variables. Of those, `VIM` seems th... |
12,358 | <p>When I prefix the J ("join") command with a count, Vim is joining one fewer line than I expect. For example, with the cursor at the first column, first line of the following,</p>
<pre><code>one
two
three
four
five
</code></pre>
<p>if I type <kbd>J</kbd><kbd>J</kbd><kbd>J</kbd><kbd>J</kbd> (four J's), I get (as exp... | [
{
"answer_id": 12359,
"author": "Eric Burgess",
"author_id": 12559,
"author_profile": "https://vi.stackexchange.com/users/12559",
"pm_score": 3,
"selected": false,
"text": "<p>After further research and office discussion, I realize this is indeed the expected behavior. According to the v... | 2017/05/10 | [
"https://vi.stackexchange.com/questions/12358",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12559/"
] | When I prefix the J ("join") command with a count, Vim is joining one fewer line than I expect. For example, with the cursor at the first column, first line of the following,
```
one
two
three
four
five
```
if I type `J``J``J``J` (four J's), I get (as expected):
```
one two three four five
```
But if instead I ty... | After further research and office discussion, I realize this is indeed the expected behavior. According to the vim help:
```
J Join [count] lines, with a minimum of two lines.
```
I've always thought `[count][command]` was literally another way to type `[command]` repeated `[count]` times. Turns out commands are ... |
12,374 | <p>I use Vim 7.4.576 on debian8.
I don't grasp the concept of deleting words backwards.</p>
<p>Here is some text. Cursor position is on "that" (the pipe symbol)</p>
<pre><code>this is a new text on th|at line.
</code></pre>
<p>How can I delete the previous words, so as a result the sentence will look like this:</p>
... | [
{
"answer_id": 12375,
"author": "Tumbler41",
"author_id": 6489,
"author_profile": "https://vi.stackexchange.com/users/6489",
"pm_score": 3,
"selected": false,
"text": "<p>You can use <code>b</code> as a motion for the delete instead of the <code>w</code> to delete backwards.</p>\n\n<pre>... | 2017/05/11 | [
"https://vi.stackexchange.com/questions/12374",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12582/"
] | I use Vim 7.4.576 on debian8.
I don't grasp the concept of deleting words backwards.
Here is some text. Cursor position is on "that" (the pipe symbol)
```
this is a new text on th|at line.
```
How can I delete the previous words, so as a result the sentence will look like this:
```
this is a line
```
Is this the... | You can use `b` as a motion for the delete instead of the `w` to delete backwards.
```
w4db
```
See [`:help {motion}`](http://vimhelp.appspot.com/intro.txt.html#%7Bmotion%7D) for more info. |
12,376 | <p>While using WSL/Bash for Windows I want to be able to use <code>y</code> <code>yy</code> <code>3y</code> and <code>p</code> the same way they always work in vim, but connecting to the system clipboard shared by all apps, not to vim's internal clipboard... I already have ditto to manage clipboard history.</p>
<p>It ... | [
{
"answer_id": 12384,
"author": "laktak",
"author_id": 10337,
"author_profile": "https://vi.stackexchange.com/users/10337",
"pm_score": 2,
"selected": false,
"text": "<p>I've made a PR for WSL support to <a href=\"https://github.com/kana/vim-fakeclip\" rel=\"nofollow noreferrer\">fakecli... | 2017/05/12 | [
"https://vi.stackexchange.com/questions/12376",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12587/"
] | While using WSL/Bash for Windows I want to be able to use `y` `yy` `3y` and `p` the same way they always work in vim, but connecting to the system clipboard shared by all apps, not to vim's internal clipboard... I already have ditto to manage clipboard history.
It seems that Vim already has a built in option to synchr... | I'm aware this is a very old question but I recently found a good solution. After much frustration, I came across these ways to access the windows system clipboard by copying and pasting.
By copying, with vim version >= 8.0.1394, as noted in another answer <https://vi.stackexchange.com/a/15190>
```
let s:clip = '/mnt... |
12,377 | <p>I'm having trouble configuring Vim on Manjaro:</p>
<p>After setting <code>syntax on</code> at <code>.vimrc</code> file, I make a Prolog program (<code>bug.pl</code>) which shows no syntax highlight:</p>
<p><a href="https://i.stack.imgur.com/nhrxX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nhr... | [
{
"answer_id": 12378,
"author": "grodzik",
"author_id": 5395,
"author_profile": "https://vi.stackexchange.com/users/5395",
"pm_score": 3,
"selected": true,
"text": "<p>This is because by default a file with extension <code>.pl</code> is for Perl files.\nIf you open your file, when there ... | 2017/05/12 | [
"https://vi.stackexchange.com/questions/12377",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12588/"
] | I'm having trouble configuring Vim on Manjaro:
After setting `syntax on` at `.vimrc` file, I make a Prolog program (`bug.pl`) which shows no syntax highlight:
[](https://i.stack.imgur.com/nhrxX.png)
But after I append `/**/` to top of file (then qui... | This is because by default a file with extension `.pl` is for Perl files.
If you open your file, when there is no `/**/` on first line and run command `:set filetype?`, it will show `perl`, not `prolog`.
However, if you add `/**/` on the first line, than there is probably some code inside Vim's standard distribution, ... |
12,380 | <p>So, for example in <code>tmux</code> you can hold <kbd>Ctrl</kbd>+<kbd>b</kbd> and move the separation line with the arrow keys.</p>
<p>Is there any way to do this with NERDTree without using a longer, somewhat discrete command every time?</p>
| [
{
"answer_id": 12391,
"author": "rafi",
"author_id": 4426,
"author_profile": "https://vi.stackexchange.com/users/4426",
"pm_score": 3,
"selected": true,
"text": "<p>In Vim you can press <kbd>Ctrl</kbd>+<kbd>w</kbd>, <kbd><</kbd> or <kbd>></kbd> to decrease and increase window width, r... | 2017/05/12 | [
"https://vi.stackexchange.com/questions/12380",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12525/"
] | So, for example in `tmux` you can hold `Ctrl`+`b` and move the separation line with the arrow keys.
Is there any way to do this with NERDTree without using a longer, somewhat discrete command every time? | In Vim you can press `Ctrl`+`w`, `<` or `>` to decrease and increase window width, respectively. Add comfortable mappings for you, I use the arrow keys, as follows:
```
nnoremap <Up> :resize +2<CR>
nnoremap <Down> :resize -2<CR>
nnoremap <Left> :vertical resize +2<CR>
nnoremap <Right> :vertical resize -2<CR>
```... |
12,385 | <p>Let's say I want to edit the text</p>
<pre><code>blahblah WombatModeFunctor
</code></pre>
<p>to be</p>
<pre><code>blahblah WombatModeFunctor::WombatModeFunctor
</code></pre>
<p>The way I know to do it is:</p>
<ol>
<li>Move the caret (cursor) until it is over the W</li>
<li>Use <code>yw</code> to yank the word</... | [
{
"answer_id": 12386,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 3,
"selected": true,
"text": "<ol>\n<li>Step 3 is not necessary, you can use <code>P</code> instead of <code>p</code>.</li>\n<li>Step 5 is not nece... | 2017/05/13 | [
"https://vi.stackexchange.com/questions/12385",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12602/"
] | Let's say I want to edit the text
```
blahblah WombatModeFunctor
```
to be
```
blahblah WombatModeFunctor::WombatModeFunctor
```
The way I know to do it is:
1. Move the caret (cursor) until it is over the W
2. Use `yw` to yank the word
3. **Move the caret 1 position to the left of the W**
4. Use `p` to paste the... | 1. Step 3 is not necessary, you can use `P` instead of `p`.
2. Step 5 is not necessary, you can use `a` instead of `i` to enter insert mode.
---
An alternative approach is this, assuming cursor is on the first `W`:
```
C<c-r>"::<c-r>"
```
Here `C` will delete the text from the cursor to the end of line, then enter... |
12,436 | <p>I noticed Vim will choose the correct syntax when I open a file that ends with <code>.c.in</code> or <code>.pl.in</code>. </p>
<p>I would like to tell Vim to behave the same with extensions like <code>.c.mako</code> or <code>.pl.mako</code>. </p>
<p>How is it possible? </p>
| [
{
"answer_id": 12386,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 3,
"selected": true,
"text": "<ol>\n<li>Step 3 is not necessary, you can use <code>P</code> instead of <code>p</code>.</li>\n<li>Step 5 is not nece... | 2017/05/19 | [
"https://vi.stackexchange.com/questions/12436",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2548/"
] | I noticed Vim will choose the correct syntax when I open a file that ends with `.c.in` or `.pl.in`.
I would like to tell Vim to behave the same with extensions like `.c.mako` or `.pl.mako`.
How is it possible? | 1. Step 3 is not necessary, you can use `P` instead of `p`.
2. Step 5 is not necessary, you can use `a` instead of `i` to enter insert mode.
---
An alternative approach is this, assuming cursor is on the first `W`:
```
C<c-r>"::<c-r>"
```
Here `C` will delete the text from the cursor to the end of line, then enter... |
12,445 | <p>I'm currently trying to figure out vimscript and I stumbled upon the <code>append()</code> function. The documentation states that you can specify the line to which an expression should be appended to, so I tried:</p>
<pre><code>:call append(line('.'), Foo())
</code></pre>
<p><code>Foo()</code> returns a string.</... | [
{
"answer_id": 12447,
"author": "grochmal",
"author_id": 7700,
"author_profile": "https://vi.stackexchange.com/users/7700",
"pm_score": 4,
"selected": true,
"text": "<p><code>append()</code> inserts <em>several lines</em> of text below the line specified as the first argument. This is i... | 2017/05/21 | [
"https://vi.stackexchange.com/questions/12445",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5046/"
] | I'm currently trying to figure out vimscript and I stumbled upon the `append()` function. The documentation states that you can specify the line to which an expression should be appended to, so I tried:
```
:call append(line('.'), Foo())
```
`Foo()` returns a string.
The weird thing is that the string is appended t... | `append()` inserts *several lines* of text below the line specified as the first argument. This is in line with the `append` ex command. You can for example type `:append` (and enter ex mode) then write several lines of text and exit ex mode (by pressing `<c-c>` for example), the lines will appear after the line your c... |
12,461 | <p>Currently when I open files in org mode all the top level bullet points are folded. I can see why this is an OK default for a lot of people, but I prefer all text unfolded initially. Is there a simple configuration to make this happen? </p>
| [
{
"answer_id": 12462,
"author": "garyjohn",
"author_id": 2055,
"author_profile": "https://vi.stackexchange.com/users/2055",
"pm_score": 1,
"selected": false,
"text": "<p>Perhaps the easiest is to put this in your <code>~/.vimrc</code>:</p>\n\n<pre><code>set foldlevelstart=99\n</code></pr... | 2017/05/23 | [
"https://vi.stackexchange.com/questions/12461",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12731/"
] | Currently when I open files in org mode all the top level bullet points are folded. I can see why this is an OK default for a lot of people, but I prefer all text unfolded initially. Is there a simple configuration to make this happen? | Perhaps the easiest is to put this in your `~/.vimrc`:
```
set foldlevelstart=99
``` |
12,470 | <p>Say I'm doing a grep for something and in the results I have a bunch of files? How can I quickly open one of those files in vim without using the mouse and without or typing the name by hand?</p>
<p>For example, with my mouse I can CMD-Click the name of the file and it opens in vim. But I would like to have the sam... | [
{
"answer_id": 12471,
"author": "Jonathan Hodgson",
"author_id": 12323,
"author_profile": "https://vi.stackexchange.com/users/12323",
"pm_score": 0,
"selected": false,
"text": "<p>You can make grep print just the file names with <code>grep -l -H</code>. You could then pipe this to <code... | 2017/05/24 | [
"https://vi.stackexchange.com/questions/12470",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7428/"
] | Say I'm doing a grep for something and in the results I have a bunch of files? How can I quickly open one of those files in vim without using the mouse and without or typing the name by hand?
For example, with my mouse I can CMD-Click the name of the file and it opens in vim. But I would like to have the same speed wi... | When you use `grep -l`, file names won't be repeated, so you don't need `sort | uniq` or `sort -u`.
You can also use `-p` to open all files in tabs.
```
grep -rlH "mail" . | xargs vim -p
``` |
12,475 | <p>I saw someone insert the result of an expression in vim, but I don't remember how it was done.</p>
<p>For example, say I want to calculate and insert the result of <code>7 * 7</code>, is there a calculator that I can use to insert the results of this expression in Vim?</p>
| [
{
"answer_id": 12476,
"author": "Philip Kirkbride",
"author_id": 7783,
"author_profile": "https://vi.stackexchange.com/users/7783",
"pm_score": 3,
"selected": false,
"text": "<p>Sorry to answer my own question so quickly. I found the following works in insert mode:</p>\n<p><kbd>Ctrl</kbd... | 2017/05/24 | [
"https://vi.stackexchange.com/questions/12475",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7783/"
] | I saw someone insert the result of an expression in vim, but I don't remember how it was done.
For example, say I want to calculate and insert the result of `7 * 7`, is there a calculator that I can use to insert the results of this expression in Vim? | For this to work, you need to use the expression register. Which allows you to execute arbitrary vimscript and do something about the result of the evaluation. To use the expression register on insert mode you type `<C-r>=` and then you can write vimscript on the command line to be executed. For your specific example y... |
12,490 | <p>I'm using Vim to write LaTeX on my Mac.</p>
<p>I could make a shortcut to execute <code>pdflatex</code> (it should be possible right?) and see the result on Preview. But it steals the focus when it updates to the new pdf, so it's quite annoying.</p>
<p>What do you suggest?</p>
| [
{
"answer_id": 12476,
"author": "Philip Kirkbride",
"author_id": 7783,
"author_profile": "https://vi.stackexchange.com/users/7783",
"pm_score": 3,
"selected": false,
"text": "<p>Sorry to answer my own question so quickly. I found the following works in insert mode:</p>\n<p><kbd>Ctrl</kbd... | 2017/05/25 | [
"https://vi.stackexchange.com/questions/12490",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12771/"
] | I'm using Vim to write LaTeX on my Mac.
I could make a shortcut to execute `pdflatex` (it should be possible right?) and see the result on Preview. But it steals the focus when it updates to the new pdf, so it's quite annoying.
What do you suggest? | For this to work, you need to use the expression register. Which allows you to execute arbitrary vimscript and do something about the result of the evaluation. To use the expression register on insert mode you type `<C-r>=` and then you can write vimscript on the command line to be executed. For your specific example y... |
12,492 | <p>Given the following block of text:</p>
<pre><code>title,tags
Run-ons - Comma Splices - Fused Sentences
Rule 1 - Run-ons - Comma Splices - Fused Sentences
Rule 2 - Run-ons - Comma Splices - Fused Sentences
Example 1 - Rule 1 - Run-ons - Comma Splices - Fused Sentences
Example 1 - Rule 2 - Run-ons - Comma Splices - ... | [
{
"answer_id": 12494,
"author": "Jim U",
"author_id": 12113,
"author_profile": "https://vi.stackexchange.com/users/12113",
"pm_score": 1,
"selected": false,
"text": "<p><strong>From :help feedkeys</strong></p>\n\n<blockquote>\n <p>Characters in {string} are queued for processing as if t... | 2017/05/25 | [
"https://vi.stackexchange.com/questions/12492",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1065/"
] | Given the following block of text:
```
title,tags
Run-ons - Comma Splices - Fused Sentences
Rule 1 - Run-ons - Comma Splices - Fused Sentences
Rule 2 - Run-ons - Comma Splices - Fused Sentences
Example 1 - Rule 1 - Run-ons - Comma Splices - Fused Sentences
Example 1 - Rule 2 - Run-ons - Comma Splices - Fused Sentence... | **From :help feedkeys**
>
> Characters in {string} are queued for processing as if they come
> from a mapping or were typed by the user. They are added to the end
> of the typeahead buffer, thus if a mapping is still being executed
> these characters come after them. The function does not wait for
> processing of... |
12,495 | <p>If I use <code>gvim *.c</code> in a directory with multiple C files, gvim opens the next one once I close the one I am looking at.</p>
<p>The warning message given is <code>E173: n more files to edit</code>.</p>
<p>How do I quit all subsequent files? Meaning I don't want gvim to open any more files.</p>
| [
{
"answer_id": 12496,
"author": "StandardEyre",
"author_id": 6590,
"author_profile": "https://vi.stackexchange.com/users/6590",
"pm_score": 2,
"selected": false,
"text": "<p>When I tried the same thing, I got this error message:</p>\n\n<pre><code>E173: 3 more files to edit\n</code></pre>... | 2017/05/25 | [
"https://vi.stackexchange.com/questions/12495",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9796/"
] | If I use `gvim *.c` in a directory with multiple C files, gvim opens the next one once I close the one I am looking at.
The warning message given is `E173: n more files to edit`.
How do I quit all subsequent files? Meaning I don't want gvim to open any more files. | When I tried the same thing, I got this error message:
```
E173: 3 more files to edit
```
I ran `:help E173` and read
```
*E173* >
{number} more files to edit
You are trying to exit, while the last item in the argument list has not been
edited. This protects you from accidentally exiting... |
12,499 | <p>I am trying to search backwards (using <code>?</code>) for the beginning of a "word".</p>
<p>I don't mean a word in the text object sense; I mean a series of lower-case letters optionally beginning with a capital letter. The optional capital letter is stymying me.</p>
<p>Here are some examples showing where I wan... | [
{
"answer_id": 12501,
"author": "user1685095",
"author_id": 6634,
"author_profile": "https://vi.stackexchange.com/users/6634",
"pm_score": 0,
"selected": false,
"text": "<p>Although ugly this does what you need. At least in your example.\nI think it could be simplified, but wouldn't both... | 2017/05/26 | [
"https://vi.stackexchange.com/questions/12499",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1643/"
] | I am trying to search backwards (using `?`) for the beginning of a "word".
I don't mean a word in the text object sense; I mean a series of lower-case letters optionally beginning with a capital letter. The optional capital letter is stymying me.
Here are some examples showing where I want to jump to, assuming the cu... | This simple search works for all the examples you gave:
```
?\a\l\+
```
It matches any alphabetic character (upper or lower case), followed by any non-zero number of lower case characters.
Some examples of cases you didn't mention where I'm a little unclear what you want it to do:
```
match a lower case
MatchACapi... |
12,518 | <p>I want the cursor line in the quickfix window to be more distinguishable, than in other windows.</p>
<p>Initially I thought that there has to be some different highlight group, it seemly turned out to be false.</p>
<p>Then I had an idea to set the cursorline highlight on a per syntax basis, I added the <code>qf.vi... | [
{
"answer_id": 12519,
"author": "Dmitry Koroliov",
"author_id": 2798,
"author_profile": "https://vi.stackexchange.com/users/2798",
"pm_score": 1,
"selected": false,
"text": "<p>currently I solved it this way (though I would be very grateful if someone suggested a better way).</p>\n\n<p>I... | 2017/05/28 | [
"https://vi.stackexchange.com/questions/12518",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2798/"
] | I want the cursor line in the quickfix window to be more distinguishable, than in other windows.
Initially I thought that there has to be some different highlight group, it seemly turned out to be false.
Then I had an idea to set the cursorline highlight on a per syntax basis, I added the `qf.vim` file to the `after/... | Patch 8.0.0641 introduced a separate highlight group for the quickfix line, called QuickFixLine. With patch 8.0.0653 this group is linked to the Search highlight by default, because for some color schemes the colors chosen for patch 8.0.0641 did not work well.
So if you have a current version of Vim you can use
```
h... |
12,520 | <p>I'm experiecing the most annoying thing ever: when I edit a markdown file, asterisk characters are hidden by default.</p>
<p>If I set on an open buffer <code>:set conceallevel=0</code>, asterisks shows up as they should, but if I put this conf in my <code>init.vim</code> file, it does not work anymore.</p>
<p>How ... | [
{
"answer_id": 12521,
"author": "caneta",
"author_id": 1765,
"author_profile": "https://vi.stackexchange.com/users/1765",
"pm_score": 4,
"selected": false,
"text": "<p>Ok, I found the plugin involved into this: is <a href=\"https://github.com/Yggdroot/indentLine\" rel=\"noreferrer\">inde... | 2017/05/29 | [
"https://vi.stackexchange.com/questions/12520",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1765/"
] | I'm experiecing the most annoying thing ever: when I edit a markdown file, asterisk characters are hidden by default.
If I set on an open buffer `:set conceallevel=0`, asterisks shows up as they should, but if I put this conf in my `init.vim` file, it does not work anymore.
How to solve that?
And more important, **is... | To help answer your original question, you can check where a setting was last set with the `:verbose` command.
```
:verbose set conceallevel
```
This will display a message similar to:
```
conceallevel=2
Last set from ~/.vim/plugged/indentLine/after/plugin/indentLine.vim
```
Note that `:verbose` simply runs a... |
12,523 | <p>How can I make a viml function that scans highlighted text for all occurrences of <code>[ <number> u ]</code> and <code>[ <number>u ]</code> and sums them?</p>
<p><strong>EXAMPLE:</strong></p>
<p>The text</p>
<pre><code>Here is some text. [0.1u]
Here is some more text [0.2 u]
And here is some noise: 0... | [
{
"answer_id": 12529,
"author": "Karl Yngve Lervåg",
"author_id": 21,
"author_profile": "https://vi.stackexchange.com/users/21",
"pm_score": 3,
"selected": true,
"text": "<p>The following solution works for me:</p>\n\n<pre><code>vnoremap <silent><expr> <c-x> YankAndAnal... | 2017/05/29 | [
"https://vi.stackexchange.com/questions/12523",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6499/"
] | How can I make a viml function that scans highlighted text for all occurrences of `[ <number> u ]` and `[ <number>u ]` and sums them?
**EXAMPLE:**
The text
```
Here is some text. [0.1u]
Here is some more text [0.2 u]
And here is some noise: 0.2
```
should yield `0.3`. | The following solution works for me:
```
vnoremap <silent><expr> <c-x> YankAndAnalyse()
nmap <silent> <c-x> vip<c-x><esc>
function! YankAndAnalyse()
return 'y'
\ . ":call Analyse()\<CR>"
\ . ":silent normal! gv\<CR>"
endfunction
function! Analyse()
let selection = split(getreg(''), '\n'... |
12,536 | <p>I've looked through the <code>vimwiki</code> documentation and a few questions here on SO, but don't see how I can manage this. In <code>vim-notes</code>, hitting <code>TAB</code> within a list indents the entire list item. In <code>vimwiki</code>, hitting <code>TAB</code> within a list indents within the list item,... | [
{
"answer_id": 12539,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": false,
"text": "<p>I'm going to ignore the majority of your question (perhaps someone will be along later to provide more specifically what you... | 2017/05/31 | [
"https://vi.stackexchange.com/questions/12536",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12840/"
] | I've looked through the `vimwiki` documentation and a few questions here on SO, but don't see how I can manage this. In `vim-notes`, hitting `TAB` within a list indents the entire list item. In `vimwiki`, hitting `TAB` within a list indents within the list item, leaving the list marker unmoved.
For example, I have wri... | I'm going to ignore the majority of your question (perhaps someone will be along later to provide more specifically what you're asking for) and instead suggest that you just use insert mode's indent command: `Ctrl`-`T`.
`:help i_CTRL-T`:
>
> Insert one shiftwidth of indent at the start of the current line. The inden... |
12,550 | <p>I use Google <code>closure-compiler</code> to check syntax errors in a JS file, the problem is that if there is no error it gives the source of the file to its STDOUT and with the default settings this counts as an error and clutters the quickfix window.</p>
<p>In Bash I can do this: <code>$closure-compiler foo.js ... | [
{
"answer_id": 12548,
"author": "Christopher Collins",
"author_id": 11878,
"author_profile": "https://vi.stackexchange.com/users/11878",
"pm_score": 2,
"selected": false,
"text": "<p>I have the following command in my <code>.bashrc</code> to do a similar thing:</p>\n\n<pre><code>set -o v... | 2017/06/03 | [
"https://vi.stackexchange.com/questions/12550",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2798/"
] | I use Google `closure-compiler` to check syntax errors in a JS file, the problem is that if there is no error it gives the source of the file to its STDOUT and with the default settings this counts as an error and clutters the quickfix window.
In Bash I can do this: `$closure-compiler foo.js 1>/dev/null` and then it g... | I often just prepend the command with `#`. After exiting vim it's then in the bash history. |
12,565 | <p><code>:h shortmess</code> says:</p>
<blockquote>
<pre><code>A don't give the "ATTENTION" message when an existing swap file is found.
</code></pre>
</blockquote>
<p>But then what does Vim do about the existing swap file? Some people say it's bad to use that option, why so?</p>
| [
{
"answer_id": 12567,
"author": "criw",
"author_id": 12916,
"author_profile": "https://vi.stackexchange.com/users/12916",
"pm_score": 3,
"selected": true,
"text": "<p>If you set <code>A</code> option Vim will just forget about swap at all.</p>\n\n<p>You'll stop getting messages about a s... | 2017/06/05 | [
"https://vi.stackexchange.com/questions/12565",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7642/"
] | `:h shortmess` says:
>
>
> ```
> A don't give the "ATTENTION" message when an existing swap file is found.
>
> ```
>
>
But then what does Vim do about the existing swap file? Some people say it's bad to use that option, why so? | If you set `A` option Vim will just forget about swap at all.
You'll stop getting messages about a swap file being found and if you're editing the same file in different terminals at the same time, it's your problem <3
---
**EDIT:**
What I mean is that Vim will not care about the swap file
Let's put a example:
Y... |
12,571 | <p>Can I close all buffers by regex, for instance all buffers that hold open <code>.js</code> files?</p>
<p>Effectively what I want is</p>
<pre><code>:bd *.js
</code></pre>
<p>But even with <code>!</code> if more than one <code>.js</code> is open I get,</p>
<pre><code>E93: More than one match for *.js
</code></pre>... | [
{
"answer_id": 12574,
"author": "muru",
"author_id": 205,
"author_profile": "https://vi.stackexchange.com/users/205",
"pm_score": 0,
"selected": false,
"text": "<p>You could probably use a function to do this:</p>\n\n<pre><code>function! CloseByRegex(re)\n for b in range(1, bufnr('$')... | 2017/06/07 | [
"https://vi.stackexchange.com/questions/12571",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5078/"
] | Can I close all buffers by regex, for instance all buffers that hold open `.js` files?
Effectively what I want is
```
:bd *.js
```
But even with `!` if more than one `.js` is open I get,
```
E93: More than one match for *.js
``` | Your question is answered on a [duplicate](https://stackoverflow.com/questions/3155461/how-to-delete-multiple-buffers-in-vim) from one on StackOverflow:
Use `<C-A>` to expand the `*.js` on the command line.
This way `:bd *.js` will become `:bd file1.js file2.js file42.js`.
My loop-free answer (in case more control i... |
12,579 | <p>I'm trying to switch from Gvim to Neovim. Most tutorials are about Linux and not how to setup Neovim on MS Windows?</p>
<p>Two problems:</p>
<ol>
<li><p>vimrc</p>
<p>From the <a href="https://github.com/neovim/neovim/wiki/Installing-Neovim" rel="nofollow noreferrer">document</a> it's <code>%userprofile%\AppData\L... | [
{
"answer_id": 12583,
"author": "Community",
"author_id": -1,
"author_profile": "https://vi.stackexchange.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "<p>Following the instructions in:</p>\n\n<pre><code>:h nvim-from-vim\n</code></pre>\n\n<p>may give you some ideas. For examp... | 2017/06/08 | [
"https://vi.stackexchange.com/questions/12579",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6971/"
] | I'm trying to switch from Gvim to Neovim. Most tutorials are about Linux and not how to setup Neovim on MS Windows?
Two problems:
1. vimrc
From the [document](https://github.com/neovim/neovim/wiki/Installing-Neovim) it's `%userprofile%\AppData\Local\nvim\init.vim`
But I don't want to put the vimrc file on C:\, it w... | The user's runtime directory is `$XDG_CONFIG_HOME/nvim`. When `$XDG_CONFIG_HOME` isn't set (which is the typical case), then the default directory is `~/AppData/Local` on Windows and `~/.config` elsewhere.
```
OS | Vim | nvim
-----------|------------|---------------------
Windows | ~/vimfiles | ~/App... |
12,593 | <p>How can Vim be configured to <strong>automatically centre</strong> a specified line number (eg. without manually having to use the <code>zz</code> command?</p>
<p>So from the commandline I just want to issue:</p>
<pre><code>vim verylongfile.c +932
</code></pre>
<p>...and as soon as the file opens, the line is vis... | [
{
"answer_id": 12583,
"author": "Community",
"author_id": -1,
"author_profile": "https://vi.stackexchange.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "<p>Following the instructions in:</p>\n\n<pre><code>:h nvim-from-vim\n</code></pre>\n\n<p>may give you some ideas. For examp... | 2017/06/09 | [
"https://vi.stackexchange.com/questions/12593",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6461/"
] | How can Vim be configured to **automatically centre** a specified line number (eg. without manually having to use the `zz` command?
So from the commandline I just want to issue:
```
vim verylongfile.c +932
```
...and as soon as the file opens, the line is visible in the centre of the screen.
I remember (fondly) th... | The user's runtime directory is `$XDG_CONFIG_HOME/nvim`. When `$XDG_CONFIG_HOME` isn't set (which is the typical case), then the default directory is `~/AppData/Local` on Windows and `~/.config` elsewhere.
```
OS | Vim | nvim
-----------|------------|---------------------
Windows | ~/vimfiles | ~/App... |
12,607 | <p>In the visual mode the <kbd>$</kbd> extends selection until the end of the line including the new line character at the end, so I need to press an additional <kbd>h</kbd> to exclud the new line character.</p>
<ul>
<li><p>Is it possible to extend the visual selection until the last character on the line (excluding th... | [
{
"answer_id": 12612,
"author": "Doorknob",
"author_id": 88,
"author_profile": "https://vi.stackexchange.com/users/88",
"pm_score": 4,
"selected": true,
"text": "<p>Your first and third points are answered by <code>g_</code>, which moves to the last non-whitespace character on the line. ... | 2017/06/11 | [
"https://vi.stackexchange.com/questions/12607",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/3230/"
] | In the visual mode the `$` extends selection until the end of the line including the new line character at the end, so I need to press an additional `h` to exclud the new line character.
* Is it possible to extend the visual selection until the last character on the line (excluding the new line character) easier as wi... | Your first and third points are answered by `g_`, which moves to the last non-whitespace character on the line. So, `vg_` will visual select to the end of the line, excluding any whitespace and the newline.
There is no option to control the behavior of `$` here, as far as I know. However, you can remap it in your `.vi... |
12,613 | <p>In my file containing LaTeX source code, I wish to comment out all the lines matching a pattern (specifically, the pattern that I am interested in is <code>\draw</code>, including the <code>\</code> character).</p>
<p>I have <code>magic</code> mode enabled. I think a potential solution would be to use the <code>glo... | [
{
"answer_id": 12615,
"author": "gandalf3",
"author_id": 6079,
"author_profile": "https://vi.stackexchange.com/users/6079",
"pm_score": 2,
"selected": false,
"text": "<p>Try using <code>:g/\\\\draw/norm gcc</code></p>\n<p>From <code>:help norm</code>:</p>\n<blockquote>\n<p>Execute Normal... | 2017/06/12 | [
"https://vi.stackexchange.com/questions/12613",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/8408/"
] | In my file containing LaTeX source code, I wish to comment out all the lines matching a pattern (specifically, the pattern that I am interested in is `\draw`, including the `\` character).
I have `magic` mode enabled. I think a potential solution would be to use the `global` command i.e. something along the lines of
... | You can use `g/\\draw/s/^/%/` to insert a percent sign at the start of every line containing the text `\draw`. `s/^/%/` means *replace the empty string at the start of the line with a percent sign*.
If you want to put the percent sign after any leading white space---which is more similar to how the normal command `I` ... |
12,621 | <p>I want to filter some text through an external command without replacing the text, but rather have some way of inserting it afterwards or wherever I want.</p>
<p>Say I want to calculate:</p>
<pre><code>2^8 =
</code></pre>
<p>I mark <code>2^8</code> in visual mode and type <code>:! bc</code>, this replaces <code>... | [
{
"answer_id": 12623,
"author": "Luc Hermitte",
"author_id": 626,
"author_profile": "https://vi.stackexchange.com/users/626",
"pm_score": 1,
"selected": false,
"text": "<p>What about </p>\n\n<pre><code>:%s/\\(.*\\)=\\s*\\zs$/\\=system('bc -q <(echo '.shellescape(submatch(1)) . ')')/\n... | 2017/06/13 | [
"https://vi.stackexchange.com/questions/12621",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5410/"
] | I want to filter some text through an external command without replacing the text, but rather have some way of inserting it afterwards or wherever I want.
Say I want to calculate:
```
2^8 =
```
I mark `2^8` in visual mode and type `:! bc`, this replaces `2^8` with `256`. However, I would rather just insert the res... | With:
```
2^8 =
1+1 = 3
2+4 =
4%8 =
```
this:
```
:g/=$/ t. | s/=// | exe '.!bc' | -j
```
produces:
```
2^8 = 256
1+1 = 3
2+4 = 6
4%8 = 4
```
It finds each line ending in `=`, copies it below, trims off the `=`,
filters it through `bc`, then joins it to the line above.
*Notes*
* `:h :global` -- short form: ... |
12,630 | <p>My <code>vim-airline</code> plugin looks like this:
<a href="https://i.stack.imgur.com/tQgYq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tQgYq.png" alt="enter image description here"></a></p>
<p>But on all screenshots it might be like this:
<a href="https://i.stack.imgur.com/S3E66.png" rel="n... | [
{
"answer_id": 12631,
"author": "TheMY3",
"author_id": 13015,
"author_profile": "https://vi.stackexchange.com/users/13015",
"pm_score": 2,
"selected": true,
"text": "<p>I installed <a href=\"https://github.com/powerline/fonts\" rel=\"nofollow noreferrer\">powerline/fonts</a> and after th... | 2017/06/14 | [
"https://vi.stackexchange.com/questions/12630",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13015/"
] | My `vim-airline` plugin looks like this:
[](https://i.stack.imgur.com/tQgYq.png)
But on all screenshots it might be like this:
[](https://i.stack.imgur.com/S3E66.png)
Here my Vundle ... | I installed [powerline/fonts](https://github.com/powerline/fonts) and after the commands:
```
# clone
git clone https://github.com/powerline/fonts.git
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts
```
My status looks like better, but not ideal, I think it's because I didn't find my font in that... |
12,632 | <p>Is there a way to bind the sequence of commands</p>
<pre><code>:Tabularize /\/\/
:Tabularize /;
</code></pre>
<p>in that order to the command <code>:Command</code>?</p>
<p><strong>EDIT:</strong> I attempted the solution and it failed:</p>
<pre><code>function! LineUp()
normal :cabbrev Command Tabularize/\/\/<... | [
{
"answer_id": 12631,
"author": "TheMY3",
"author_id": 13015,
"author_profile": "https://vi.stackexchange.com/users/13015",
"pm_score": 2,
"selected": true,
"text": "<p>I installed <a href=\"https://github.com/powerline/fonts\" rel=\"nofollow noreferrer\">powerline/fonts</a> and after th... | 2017/06/14 | [
"https://vi.stackexchange.com/questions/12632",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6499/"
] | Is there a way to bind the sequence of commands
```
:Tabularize /\/\/
:Tabularize /;
```
in that order to the command `:Command`?
**EDIT:** I attempted the solution and it failed:
```
function! LineUp()
normal :cabbrev Command Tabularize/\/\/<CR>:Tabularize /;<CR>
endfunction
command! -nargs=0 -complete=buffer ... | I installed [powerline/fonts](https://github.com/powerline/fonts) and after the commands:
```
# clone
git clone https://github.com/powerline/fonts.git
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts
```
My status looks like better, but not ideal, I think it's because I didn't find my font in that... |
12,634 | <p>Is there a way to make it so that</p>
<pre><code>This is a header
=<tab>
</code></pre>
<p>converts into </p>
<pre><code>This is a header
================
</code></pre>
<p>in all files who filetype is markdown?</p>
| [
{
"answer_id": 12635,
"author": "Zsolt Botykai",
"author_id": 656,
"author_profile": "https://vi.stackexchange.com/users/656",
"pm_score": 2,
"selected": false,
"text": "<p>Likely it can be done with <kbd>=</kbd><kbd>TAB</kbd>, but another approach is:</p>\n\n<ol>\n<li>type your header, ... | 2017/06/14 | [
"https://vi.stackexchange.com/questions/12634",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6499/"
] | Is there a way to make it so that
```
This is a header
=<tab>
```
converts into
```
This is a header
================
```
in all files who filetype is markdown? | Likely it can be done with `=``TAB`, but another approach is:
1. type your header, then `ESC``V``y``ESC` (copy the whole line in Visual mode)
2. `p`aste
3. `j``V``r``=` (move down, select whole line, replace it with `=`.
Then You can create a macro or an `imap` or `nmap` for it.
Another approach is (after typing yo... |
12,640 | <p>I just don't undstand the VIM help for pattern matching and substitution. I've tried.</p>
<p>I have many lines of code, like so:</p>
<pre><code>G1 X139.164 Y115.348 E8.40357 ; perimeter
G1 X138.903 Y115.845 E8.57778 ; perimeter
G1 X136.919 Y119.355 E9.82896 ; perimeter
G1 X135.204 Y125.148 F250
G1 X133.565... | [
{
"answer_id": 12642,
"author": "Christopher Collins",
"author_id": 11878,
"author_profile": "https://vi.stackexchange.com/users/11878",
"pm_score": 3,
"selected": false,
"text": "<p>You can use this command:</p>\n\n<pre><code>:1,%s/E.*$//g\n</code></pre>\n"
},
{
"answer_id": 126... | 2017/06/14 | [
"https://vi.stackexchange.com/questions/12640",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11454/"
] | I just don't undstand the VIM help for pattern matching and substitution. I've tried.
I have many lines of code, like so:
```
G1 X139.164 Y115.348 E8.40357 ; perimeter
G1 X138.903 Y115.845 E8.57778 ; perimeter
G1 X136.919 Y119.355 E9.82896 ; perimeter
G1 X135.204 Y125.148 F250
G1 X133.565 Y124.281 E11.75686 ... | Your last attempt is almost correct. I would use this:
`:%s/E.*//`
The OCD part of me would also want to remove any spaces before the `E`. That could be done with:
`:%s/\s*E.*//`
The `\>` was causing your attempts to fail because by default numbers are considered part of the word. See `:help \>` and `:help iskeywor... |
12,645 | <p>I want to get the whole buffer contents as a single string. Currently I'm doing this:</p>
<pre><code>let line_ending = "\n"
let text = join(getline(1, '$'), line_ending).line_ending
</code></pre>
<p>But this assumes the line ending. If this is the best approach, how can I find out what the line ending actually i... | [
{
"answer_id": 12651,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 1,
"selected": false,
"text": "<p>The <a href=\"http://vimhelp.appspot.com/options.txt.html#%27fileformat%27\" rel=\"nofollow noreferrer\"><code>'fil... | 2017/06/15 | [
"https://vi.stackexchange.com/questions/12645",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1643/"
] | I want to get the whole buffer contents as a single string. Currently I'm doing this:
```
let line_ending = "\n"
let text = join(getline(1, '$'), line_ending).line_ending
```
But this assumes the line ending. If this is the best approach, how can I find out what the line ending actually is?
Or is there a better way... | It's possible to directly put the content of the current buffer into a register (and from here into a variable) thanks to `:%y` (`:yank` takes an optional register name).
However, after a test on a file in dos format, I've seen that my register contained characters of code 10 for newlines. The test being done with `:e... |
12,654 | <p>I want to replace all of the occurrences of</p>
<pre><code>armv7_format_strings<any_string> = {<str1>, <str2>};
</code></pre>
<p>by </p>
<pre><code>armv7_format_strings<any_string>[0] = <str1> ;
armv7_format_strings<any_string>[1] = <str2> ;
</code></pre>
| [
{
"answer_id": 12655,
"author": "Abhishek Kumar",
"author_id": 11763,
"author_profile": "https://vi.stackexchange.com/users/11763",
"pm_score": 3,
"selected": true,
"text": "<p>This one worked:</p>\n\n<pre><code>%s/\\(armv7_format_strings.*\\) = {\\(.*\\), \\(.*\\)};/\\1[0] = \\2;\\r\\1[... | 2017/06/16 | [
"https://vi.stackexchange.com/questions/12654",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11763/"
] | I want to replace all of the occurrences of
```
armv7_format_strings<any_string> = {<str1>, <str2>};
```
by
```
armv7_format_strings<any_string>[0] = <str1> ;
armv7_format_strings<any_string>[1] = <str2> ;
``` | This one worked:
```
%s/\(armv7_format_strings.*\) = {\(.*\), \(.*\)};/\1[0] = \2;\r\1[1] = \3;\r/gc
``` |
12,680 | <p>Is there a simple way to delete all white spaces on a line until the first character on that line is met?</p>
<p>An example:</p>
<pre><code> #a list of comments
# item 1
# item 2
</code></pre>
<p>And I would like it to become: </p>
<pre><code>#a list of comments
# item 1... | [
{
"answer_id": 12682,
"author": "statox",
"author_id": 1841,
"author_profile": "https://vi.stackexchange.com/users/1841",
"pm_score": 5,
"selected": true,
"text": "<p>You can either visually select the lines and use</p>\n\n<pre><code>:'<,'>s/^\\s*//\n</code></pre>\n\n<p>Which means... | 2017/06/20 | [
"https://vi.stackexchange.com/questions/12680",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12085/"
] | Is there a simple way to delete all white spaces on a line until the first character on that line is met?
An example:
```
#a list of comments
# item 1
# item 2
```
And I would like it to become:
```
#a list of comments
# item 1
# item 2
```
I know how to delete n chara... | You can either visually select the lines and use
```
:'<,'>s/^\s*//
```
Which means 'substitute all of the whitespaces following the first column of the line by nothing'
Or go on the first line, use
* `0` to go on the first column
* `d^` to delete until the first character of the line
And then go to the next lin... |
12,694 | <p>I'm trying to configure <a href="https://github.com/jalcine/cmake.vim" rel="nofollow noreferrer">cmake.vim</a> for my c++ projects, but it doesn't work for me even on initial stage. The following command:</p>
<pre><code>:CMakeCreateBuild <build_dir>
</code></pre>
<p>just creates a build directory but it seem... | [
{
"answer_id": 12697,
"author": "A Gold Man",
"author_id": 10421,
"author_profile": "https://vi.stackexchange.com/users/10421",
"pm_score": 0,
"selected": false,
"text": "<p>You could run it again with the 'verbose' option set to 15 (you know, like <code>:set verbose=15</code>) to trace ... | 2017/06/21 | [
"https://vi.stackexchange.com/questions/12694",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/12828/"
] | I'm trying to configure [cmake.vim](https://github.com/jalcine/cmake.vim) for my c++ projects, but it doesn't work for me even on initial stage. The following command:
```
:CMakeCreateBuild <build_dir>
```
just creates a build directory but it seems it doesn't invoke `cmake` to configure the project.
I see somethin... | According to their [README page](https://github.com/jalcine/cmake.vim#getting-started) `:CMakeCreateBuild <build-dir-name>` only creates a new binary directory for your project so I think you are experiencing the expexted behavior.
Still according to the same page I think you need to run the following commands:
```
"... |