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 |
|---|---|---|---|---|---|---|
22,566 | <p>I need to test a vim plugin. The problem: I already have my vim setup in current env, so <code>~/.vimrc</code> is occupied.</p>
<p>I want to issue a command like <code>vim -u <blah..blah></code> that maybe specifies the plugin path and has some other options to enable testing the plugin only.</p>
| [
{
"answer_id": 22567,
"author": "user938271",
"author_id": 17449,
"author_profile": "https://vi.stackexchange.com/users/17449",
"pm_score": 2,
"selected": false,
"text": "<p>Try this:</p>\n\n<pre><code>set rtp-=~/.vim\nset rtp-=~/.vim/after\nset rtp^=/path/to/some-plugin\nset rtp+=/path/... | 2020/01/15 | [
"https://vi.stackexchange.com/questions/22566",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14274/"
] | I need to test a vim plugin. The problem: I already have my vim setup in current env, so `~/.vimrc` is occupied.
I want to issue a command like `vim -u <blah..blah>` that maybe specifies the plugin path and has some other options to enable testing the plugin only. | Try this:
```
set rtp-=~/.vim
set rtp-=~/.vim/after
set rtp^=/path/to/some-plugin
set rtp+=/path/to/some-plugin/after
set vif=NONE
filetype plugin indent on
syntax enable
```
Write the code in a file, e.g. `/tmp/vimrc`, then start Vim with this shell command:
```
vim -Nu /tmp/vimrc
```
The `-u` argument specifie... |
22,570 | <p>Suppose I have a defined text object. For example, I have a <code>ii</code> text block which defines all the contiguous lines around the cursor at the same level of indentation or deeper. I know what it means to, say, yank or delete this text block.</p>
<p>As a consequence, as I move through the document, there is ... | [
{
"answer_id": 22572,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 2,
"selected": false,
"text": "<p>This doesn't answer your more general question about text objects, but you can achieve the behaviour in your specific indent... | 2020/01/15 | [
"https://vi.stackexchange.com/questions/22570",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/17288/"
] | Suppose I have a defined text object. For example, I have a `ii` text block which defines all the contiguous lines around the cursor at the same level of indentation or deeper. I know what it means to, say, yank or delete this text block.
As a consequence, as I move through the document, there is a well defined "start... | For the general case, you can try [creating new operators](http://vimhelp.org/map.txt.html#:map-operator), `gs` and `ge`:
```
function! GoStart(type) abort
normal! `[
endfunction
function! GoEnd(type) abort
normal! `]
endfunction
nnoremap <silent> gs :set opfunc=GoStart<CR>g@
nnoremap <silent> ge :set opfunc=GoE... |
22,598 | <p>I'm trying to do the following mapping in my vimrc:</p>
<pre><code>nnoremap <silent> / :call <SID>FooFunction()<CR><BAR>norm! /
</code></pre>
<p>But when I press <code>/</code>, instead of running the function and then starting the search prompt, I get this text inserted to my buffer:</p>
... | [
{
"answer_id": 22600,
"author": "ruohola",
"author_id": 21062,
"author_profile": "https://vi.stackexchange.com/users/21062",
"pm_score": 2,
"selected": true,
"text": "<p>Figured out the the <code><silent></code> was hiding the search prompt, and also the mapping can be done just li... | 2020/01/18 | [
"https://vi.stackexchange.com/questions/22598",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21062/"
] | I'm trying to do the following mapping in my vimrc:
```
nnoremap <silent> / :call <SID>FooFunction()<CR><BAR>norm! /
```
But when I press `/`, instead of running the function and then starting the search prompt, I get this text inserted to my buffer:
```
rm! /
```
I also tried to put the normal command to as the ... | Figured out the the `<silent>` was hiding the search prompt, and also the mapping can be done just like this:
```
nnoremap / :call <SID>FooFunction()<CR>/
``` |
22,607 | <p>What I want to do is have two mappings. One mapped to <code><s-k></code>, and one mapped to <code><s-k><s-k></code>. What happens right now is that if I press <code><s-k></code> <code>vim</code> delays for <code>timeoutlen</code>ms, and if I don't press anything it does the <code><s-k>... | [
{
"answer_id": 22616,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>I think something like this would do:</p>\n\n<pre><code>let s:pressed = 0\n\nfunction KFunc() abort\n let s:pr... | 2020/01/19 | [
"https://vi.stackexchange.com/questions/22607",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19428/"
] | What I want to do is have two mappings. One mapped to `<s-k>`, and one mapped to `<s-k><s-k>`. What happens right now is that if I press `<s-k>` `vim` delays for `timeoutlen`ms, and if I don't press anything it does the `<s-k>` action, and if I press another `<s-k>` in that time it does the `<s-k><s-k>` action.
Howeve... | I think something like this would do:
```
let s:pressed = 0
function KFunc() abort
let s:pressed += 1
if s:pressed == 1
" do one
else if s:pressed == 2
" do two
let s:pressed = 0
endif
endfunction
augroup ResetPressed
au!
au CursorMoved,CursorMovedI,CursorHold,CursorHoldI * let s:pressed = 0
... |
22,630 | <p>I have a CSV file in which data in a row are present in following way: </p>
<pre><code>ID, Name, State, Score, Rank
</code></pre>
<p>In the <code>Name</code> Column, data are in <code>"some Name"</code> form. But there are many entries in which a comma is present in the name like: <code>"some name, Again"</code> w... | [
{
"answer_id": 22631,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 0,
"selected": false,
"text": "<p>The vim pattern <code>\"[^\"]*\\zs,\\ze[^\"]*\"</code> should match only the comma. However, if you have data l... | 2020/01/22 | [
"https://vi.stackexchange.com/questions/22630",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26582/"
] | I have a CSV file in which data in a row are present in following way:
```
ID, Name, State, Score, Rank
```
In the `Name` Column, data are in `"some Name"` form. But there are many entries in which a comma is present in the name like: `"some name, Again"` which makes that row inconsistent with other rows.
I have m... | This situation is frustrating. Technically speaking, the CSV file you describe is within MicroSoft's CSV spec - the double-quotes escape the comma, so it's not considered a separator. However, there's a lot of programs out there that don't honor any method of saying the comma isn't a value separator, or don't honor tha... |
22,637 | <p>My <code>init.vim</code> is just</p>
<pre><code>au FileType * echom "test"
</code></pre>
<p>However, if I open a file, neovim-qt will not echo <code>test</code>. If I load a new file while the window is open, it will also not work.</p>
<p>I have managed to find one case where it will fire. If I run <code>mks</cod... | [
{
"answer_id": 22631,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 0,
"selected": false,
"text": "<p>The vim pattern <code>\"[^\"]*\\zs,\\ze[^\"]*\"</code> should match only the comma. However, if you have data l... | 2020/01/24 | [
"https://vi.stackexchange.com/questions/22637",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/24943/"
] | My `init.vim` is just
```
au FileType * echom "test"
```
However, if I open a file, neovim-qt will not echo `test`. If I load a new file while the window is open, it will also not work.
I have managed to find one case where it will fire. If I run `mks`, open `Session.vim` and then source it (`so%`), it will run thi... | This situation is frustrating. Technically speaking, the CSV file you describe is within MicroSoft's CSV spec - the double-quotes escape the comma, so it's not considered a separator. However, there's a lot of programs out there that don't honor any method of saying the comma isn't a value separator, or don't honor tha... |
22,639 | <p>I would like to swap my left <kbd>shift</kbd> key with my left <kbd>alt</kbd> key, and I would like to know if it’s possible to achieve this with vim key mapping. </p>
<p>Maybe not swapping but copy the whole <kbd>shift</kbd> key map to <kbd>alt</kbd>?</p>
| [
{
"answer_id": 22640,
"author": "Ed Grimm",
"author_id": 20713,
"author_profile": "https://vi.stackexchange.com/users/20713",
"pm_score": 1,
"selected": false,
"text": "<p>In vim, nvi, vi, and so forth (all of the terminal vi clones, to be precise), no. A terminal session doesn't transm... | 2020/01/24 | [
"https://vi.stackexchange.com/questions/22639",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26638/"
] | I would like to swap my left `shift` key with my left `alt` key, and I would like to know if it’s possible to achieve this with vim key mapping.
Maybe not swapping but copy the whole `shift` key map to `alt`? | In vim, nvi, vi, and so forth (all of the terminal vi clones, to be precise), no. A terminal session doesn't transmit the modifier key presses separate from the keys they're modifying. It's true that terminal emulators have come a long way since when they were first made, and they have a lot more capabilities now. But ... |
22,647 | <p>I have multiple tab pages. Some tab pages only have open files, some only have <code>:terminal</code>s open, and some have a mix of files and terminals.</p>
<p>At the end of the day, I want to quit Vim. Normally, I go through every tab page and close every window manually. But is there a better way? I tried <code>:... | [
{
"answer_id": 22648,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 2,
"selected": true,
"text": "<p>You can use <code>:qa!</code> to force vim to exit:</p>\n\n<pre><code>:qa[ll]! Exit Vim. Any changes to buffers are... | 2020/01/24 | [
"https://vi.stackexchange.com/questions/22647",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22095/"
] | I have multiple tab pages. Some tab pages only have open files, some only have `:terminal`s open, and some have a mix of files and terminals.
At the end of the day, I want to quit Vim. Normally, I go through every tab page and close every window manually. But is there a better way? I tried `:wqa`, but that doesn't wor... | You can use `:qa!` to force vim to exit:
```
:qa[ll]! Exit Vim. Any changes to buffers are lost.
Also see |:cquit|, it does the same but exits with a non-zero
value.
```
As `:qa!` doesn't save buffer, you should use `:wqa` before that.
`:qa!` can be dangerous, a half-way stopped terminal might l... |
22,653 | <p>I'm trying to bind the key <code>^</code> so that it runs <code>^</code> in normal mode by default, but calls the function bound to <code>-</code> in netrw. <code>-</code> is bound to <code>NetrwBrowseUpDir</code> in <code>netrw.vim</code>, <a href="https://github.com/vim/vim/blob/7f51bbe0d19f1f0cb0321326f45a17b4f51... | [
{
"answer_id": 22656,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": true,
"text": "<p>There is a hacky way to get a scripts <code><SID></code> and use it in mappings, but I always forget it.</... | 2020/01/25 | [
"https://vi.stackexchange.com/questions/22653",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6420/"
] | I'm trying to bind the key `^` so that it runs `^` in normal mode by default, but calls the function bound to `-` in netrw. `-` is bound to `NetrwBrowseUpDir` in `netrw.vim`, [definition here](https://github.com/vim/vim/blob/7f51bbe0d19f1f0cb0321326f45a17b4f5155f89/runtime/autoload/netrw.vim#L5126) .
Here's my first a... | There is a hacky way to get a scripts `<SID>` and use it in mappings, but I always forget it.
One way to do it would be with`:nmap`, but this probably only works if you don’t already have a mapping for `-`:
```
nmap <expr> ^ &ft ==# 'netrw' ? '-' : '^'
```
I’ve looked at the docs and do not see a configuration vari... |
22,668 | <p>I have 3 blocks of text with the same number of lines that I want to merge each block by line.</p>
<pre><code># block 1
[ Card "Skwortul"
, Card "Scorchander"
, Card "Seedasaur"
, Card "Kapichu"
, Card "Elecdude"
, Card "Garydose"
, Card "Moisteon"
, Card "Grasseon"
, Card "Spicyeon" ... | [
{
"answer_id": 22656,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": true,
"text": "<p>There is a hacky way to get a scripts <code><SID></code> and use it in mappings, but I always forget it.</... | 2020/01/26 | [
"https://vi.stackexchange.com/questions/22668",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/22705/"
] | I have 3 blocks of text with the same number of lines that I want to merge each block by line.
```
# block 1
[ Card "Skwortul"
, Card "Scorchander"
, Card "Seedasaur"
, Card "Kapichu"
, Card "Elecdude"
, Card "Garydose"
, Card "Moisteon"
, Card "Grasseon"
, Card "Spicyeon"
, Card "Spar... | There is a hacky way to get a scripts `<SID>` and use it in mappings, but I always forget it.
One way to do it would be with`:nmap`, but this probably only works if you don’t already have a mapping for `-`:
```
nmap <expr> ^ &ft ==# 'netrw' ? '-' : '^'
```
I’ve looked at the docs and do not see a configuration vari... |
22,683 | <p>I integrated <code>luacheck</code> in <code>vim</code> with the following simple function:</p>
<pre><code>function! LuaCheck()
let errors=system("luacheck " . expand("%"))
cexpr errors
cwindow 5
endfunction
autocmd FileType lua nnoremap <buffer> <c-f> :call LuaCheck()<cr>
autocmd FileType lu... | [
{
"answer_id": 22684,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 3,
"selected": true,
"text": "<p>You can create temporary file name with <code>:h tempname()</code>:</p>\n\n<pre><code>let tempname = tempname()\ncall ... | 2020/01/28 | [
"https://vi.stackexchange.com/questions/22683",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20084/"
] | I integrated `luacheck` in `vim` with the following simple function:
```
function! LuaCheck()
let errors=system("luacheck " . expand("%"))
cexpr errors
cwindow 5
endfunction
autocmd FileType lua nnoremap <buffer> <c-f> :call LuaCheck()<cr>
autocmd FileType lua set efm=%f:%l:%c:\ %m
```
It is working, but here ... | You can create temporary file name with `:h tempname()`:
```
let tempname = tempname()
call writefile([ "hello world" ], tempname)
" do something with tempname file
" ...
call delete(tempname)
``` |
22,701 | <p>I have some boilerplate code in one of my vimscript functions:</p>
<pre><code>" Save register 'a' so we don't clobber it
let savereg = @a
" Yank the current WORD into register 'a' and save it to 'input'
normal "ayiW
let input = @a
" Restore register 'a' so we don't clobber it
let @a = l:savereg
"
" ... Do work o... | [
{
"answer_id": 22702,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 4,
"selected": true,
"text": "<p>First, if your script runs from a mapping than you probably should support <code>v:register</code> - let the user decide ... | 2020/01/29 | [
"https://vi.stackexchange.com/questions/22701",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14861/"
] | I have some boilerplate code in one of my vimscript functions:
```
" Save register 'a' so we don't clobber it
let savereg = @a
" Yank the current WORD into register 'a' and save it to 'input'
normal "ayiW
let input = @a
" Restore register 'a' so we don't clobber it
let @a = l:savereg
"
" ... Do work on 'l:input'
"
... | First, if your script runs from a mapping than you probably should support `v:register` - let the user decide what to use.
Next, if your operation is a sort of "visual replacement" (get selection, modify and put it back) it makes sense to model it after `:h v_p` (maybe even end it with `gvp` or such).
In this case ei... |
22,713 | <p>I'm executing an external command that takes as input a range of lines within my file.</p>
<pre><code>:'<,'>!copy_stuff
</code></pre>
<p>Running this runs <code>copy_stuff</code> correctly with the currently selected visual range (and it also works fine with any other range). However, since <code>copy_stuff<... | [
{
"answer_id": 22714,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 4,
"selected": true,
"text": "<p>You can use <code>:write</code> for this:</p>\n\n<pre><code>:'<,'>w !copy_stuff\n</code></pre>\n\n<p>For more details, ... | 2020/01/30 | [
"https://vi.stackexchange.com/questions/22713",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2526/"
] | I'm executing an external command that takes as input a range of lines within my file.
```
:'<,'>!copy_stuff
```
Running this runs `copy_stuff` correctly with the currently selected visual range (and it also works fine with any other range). However, since `copy_stuff` doesn't write anything to stdout, it also delet... | You can use `:write` for this:
```
:'<,'>w !copy_stuff
```
For more details, see [`:help :write_c`](https://vimhelp.org/editing.txt.html#%3Aw_c):
>
> Execute {cmd} with [range] lines as standard input
> (note the space in front of the '!').
>
>
> |
22,723 | <p>I comment sections in python via a centered title surrounded by <code>#</code>. What I would like is to make a command so that I can automatically generate such headers. For example, to generate a line like the following:</p>
<pre><code>############################### Logging ################################
</code... | [
{
"answer_id": 22741,
"author": "eyal karni",
"author_id": 18375,
"author_profile": "https://vi.stackexchange.com/users/18375",
"pm_score": 0,
"selected": false,
"text": "<p>You can call <code>winwidth()</code> to get the number of chars in line that fit the screen. \nAnd use <code>prin... | 2020/01/31 | [
"https://vi.stackexchange.com/questions/22723",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26743/"
] | I comment sections in python via a centered title surrounded by `#`. What I would like is to make a command so that I can automatically generate such headers. For example, to generate a line like the following:
```
############################### Logging ################################
```
and also a line to close ... | You can start with the following (add it to you vimrc)
```
func! MyComment(text)
let width = 80
let text = printf(" %s ", a:text)
let chrome = repeat('#', width/2 - strdisplaywidth(text)/2)
call setline('.', chrome . text . chrome)
endfunc
nnoremap <leader>c :call MyComment(input("Header: "))<CR>
nno... |
22,748 | <p>I was reading here <a href="https://vi.stackexchange.com/questions/300/other-ways-to-exit-insert-mode-besides-escape">Other ways to exit Insert mode besides Escape</a> and in various other places.</p>
<p>The problem I have is if I enter visual select mode I cannot use <kbd>j</kbd><kbd>j</kbd> or <kbd>k</kbd><kbd>j<... | [
{
"answer_id": 22751,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 4,
"selected": true,
"text": "<p>At least in Vim, there are a few more ways to leave Visual mode. Not sure if they're available in ideavim, but you ... | 2020/02/03 | [
"https://vi.stackexchange.com/questions/22748",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26780/"
] | I was reading here [Other ways to exit Insert mode besides Escape](https://vi.stackexchange.com/questions/300/other-ways-to-exit-insert-mode-besides-escape) and in various other places.
The problem I have is if I enter visual select mode I cannot use `j``j` or `k``j` to exit that mode, because `k``j` is used to travel... | At least in Vim, there are a few more ways to leave Visual mode. Not sure if they're available in ideavim, but you might consider giving them a try.
* The combination `Ctrl`+`[` is a synonym for `Esc`, it produces the same keycode. So if you're avoiding the Esc key because it's in an awkward position (or your keyboard... |
22,762 | <p>I have an autocmd set up like this:</p>
<pre><code>au BufWritePost *.sh,*.zsh,.zshrc silent exec "!ctags --language-force=sh %"
</code></pre>
<p>When I run <code>:!!<cr></code> after saving a file, the command <code>!ctags --language-force=sh %</code> is being run.</p>
<p>This does not happen on vim 8.1.</p... | [
{
"answer_id": 22751,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 4,
"selected": true,
"text": "<p>At least in Vim, there are a few more ways to leave Visual mode. Not sure if they're available in ideavim, but you ... | 2020/02/04 | [
"https://vi.stackexchange.com/questions/22762",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26802/"
] | I have an autocmd set up like this:
```
au BufWritePost *.sh,*.zsh,.zshrc silent exec "!ctags --language-force=sh %"
```
When I run `:!!<cr>` after saving a file, the command `!ctags --language-force=sh %` is being run.
This does not happen on vim 8.1.
How do I prevent neovim from doing that ?
**EDIT**
First - ... | At least in Vim, there are a few more ways to leave Visual mode. Not sure if they're available in ideavim, but you might consider giving them a try.
* The combination `Ctrl`+`[` is a synonym for `Esc`, it produces the same keycode. So if you're avoiding the Esc key because it's in an awkward position (or your keyboard... |
22,768 | <p>After typing <code>tds</code> I would like to see it replaced with the current time stamp in Markdown files, but eg. NOT while editing C source code.</p>
<p>The following mostly works (stripped for brevity) except that the the abbreviation <code>tds</code> is available in every buffer (mode) not just a markdown mod... | [
{
"answer_id": 22769,
"author": "Casca",
"author_id": 18498,
"author_profile": "https://vi.stackexchange.com/users/18498",
"pm_score": 1,
"selected": false,
"text": "<p>What you want is to run the abbreviation command only for that buffer.</p>\n\n<pre><code>autocmd FileType markdown iab ... | 2020/02/05 | [
"https://vi.stackexchange.com/questions/22768",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11633/"
] | After typing `tds` I would like to see it replaced with the current time stamp in Markdown files, but eg. NOT while editing C source code.
The following mostly works (stripped for brevity) except that the the abbreviation `tds` is available in every buffer (mode) not just a markdown mode buffer.
```
augroup TXT | au!... | When creating an autocommand, the `:au` part interprets `|` as a command separator. Just like for mappings, you need to escape it:
```
au setlocal autoindent expandtab tabstop=8 softtabstop=2 shiftwidth=2 \| inoreabbrev <buffer> <expr> tds strftime("%F %b %T")
```
Or, use two autocommands:
```
au setlocal autoinden... |
22,773 | <p>Is there a way to push out a vimrc change to all open windows and instances of vim without having to write/change any buffers or reopen vim? I'd like vim to be able to behave like a modern day IDE for this as I change my vimrc a lot and am trying to learn more vim scripting. </p>
| [
{
"answer_id": 22769,
"author": "Casca",
"author_id": 18498,
"author_profile": "https://vi.stackexchange.com/users/18498",
"pm_score": 1,
"selected": false,
"text": "<p>What you want is to run the abbreviation command only for that buffer.</p>\n\n<pre><code>autocmd FileType markdown iab ... | 2020/02/05 | [
"https://vi.stackexchange.com/questions/22773",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16545/"
] | Is there a way to push out a vimrc change to all open windows and instances of vim without having to write/change any buffers or reopen vim? I'd like vim to be able to behave like a modern day IDE for this as I change my vimrc a lot and am trying to learn more vim scripting. | When creating an autocommand, the `:au` part interprets `|` as a command separator. Just like for mappings, you need to escape it:
```
au setlocal autoindent expandtab tabstop=8 softtabstop=2 shiftwidth=2 \| inoreabbrev <buffer> <expr> tds strftime("%F %b %T")
```
Or, use two autocommands:
```
au setlocal autoinden... |
22,775 | <p>And, to get back again: how do I make the <code>l</code> key go to next tab, if at end of file?</p>
<p>I'd also like to make <code>hh</code> go to previous buffer, and <code>ll</code> go to next buffer. I know that'll add a delay to recognising the <code>h</code>/<code>l</code> keys, and slow down navigation, and I... | [
{
"answer_id": 22788,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": true,
"text": "<p>Like Ben and statox, I wouldn't necessarily recommend this, but it is possible:</p>\n\n<pre><code>function FirstPress(c1) abo... | 2020/02/05 | [
"https://vi.stackexchange.com/questions/22775",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/182/"
] | And, to get back again: how do I make the `l` key go to next tab, if at end of file?
I'd also like to make `hh` go to previous buffer, and `ll` go to next buffer. I know that'll add a delay to recognising the `h`/`l` keys, and slow down navigation, and I wonder is there a way to tell vim to
>
> Only check for "hh" a... | Like Ben and statox, I wouldn't necessarily recommend this, but it is possible:
```
function FirstPress(c1) abort
let now = reltime()
while reltimefloat(reltime(now)) < &timeoutlen / 1000.0
" See if the user has typed another character
let c2 = getchar(0)
if c2 != 0
" The user typed something. W... |
22,779 | <p>Is there a way to make vim (or nvim) open all new splits vertically by default? There's <code>splitright</code> to control which side vertical splits open on, but as far as I can tell there's no built in option to make splits vertical by default. Does anyone know of a workaround? I found one for the help command spe... | [
{
"answer_id": 22780,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>There's not really an option that does that.</p>\n\n<p>You can accomplish that by using an <code>autocmd</code>, mo... | 2020/02/06 | [
"https://vi.stackexchange.com/questions/22779",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6732/"
] | Is there a way to make vim (or nvim) open all new splits vertically by default? There's `splitright` to control which side vertical splits open on, but as far as I can tell there's no built in option to make splits vertical by default. Does anyone know of a workaround? I found one for the help command specifically, but... | There's not really an option that does that.
You can accomplish that by using an `autocmd`, more specifically catching the `WinNew` event and moving the newly created window so that it's a vertical one rather than horizontal.
For example:
```
autocmd WinNew * wincmd L
```
(Don't forget to add this to an appropriat... |
22,783 | <p>Inside of my editor (almost fresh install of neovim) there is no visual way to distinguish between a file that ends in a newline and a file that doesn't.</p>
<p>In my command line (zsh default?) there is a nice visual indicator that shows stdout didn't end in a newline:</p>
<p><a href="https://i.stack.imgur.com/9i... | [
{
"answer_id": 22784,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<p>When opening a file w/o the last newline, Neovim (just as Vim) prints the message with the text \"[noeol]\" (or \"[Incom... | 2020/02/06 | [
"https://vi.stackexchange.com/questions/22783",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/9024/"
] | Inside of my editor (almost fresh install of neovim) there is no visual way to distinguish between a file that ends in a newline and a file that doesn't.
In my command line (zsh default?) there is a nice visual indicator that shows stdout didn't end in a newline:
[ prints the message with the text "[noeol]" (or "[Incomplete last line]" depending on `&shm` option) included. Also, you can query it anytime with the command `:set eol?`
Another point is that Vim/Neovim will fix the missing newline upon file write automati... |
22,791 | <p>I have selected a JS block such as following:</p>
<pre><code>function map(xs: string[], cb: Function) : string[] {
const result: string[] = [];
for(let i = 0; i++; i < xs.length) {
result.push(cb(xs[i]));
}
return result;
}
</code></pre>
<p>Now I want to go to the beginning of each line and comment... | [
{
"answer_id": 22792,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 3,
"selected": true,
"text": "<p>You can try this:</p>\n\n<pre><code>vip<Ctrl-v>I//<ESC>\n</code></pre>\n\n<ol>\n<li><code>vip</code> selec... | 2020/02/07 | [
"https://vi.stackexchange.com/questions/22791",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/23265/"
] | I have selected a JS block such as following:
```
function map(xs: string[], cb: Function) : string[] {
const result: string[] = [];
for(let i = 0; i++; i < xs.length) {
result.push(cb(xs[i]));
}
return result;
}
```
Now I want to go to the beginning of each line and comment out each line in the block (... | You can try this:
```
vip<Ctrl-v>I//<ESC>
```
1. `vip` select paragraph
2. `<Ctrl-v>` make selection blockwise
3. `I//` insert `//` into begining of a selection block
[](https://i.stack.imgur.com/0FD4H.gif)
PS: I would suggest to use vim-commentar... |
22,827 | <p>I search a way to paste/merge 2 block of text</p>
<pre><code>apple
pear
banana
tomato
beans
potato
</code></pre>
<p>like this </p>
<pre><code>apple tomato
pear beans
banana potato
</code></pre>
<p>The lines have different length but same number of lines of course.
I don't want different number of spaces like in... | [
{
"answer_id": 22829,
"author": "Thomas F",
"author_id": 8458,
"author_profile": "https://vi.stackexchange.com/users/8458",
"pm_score": 3,
"selected": false,
"text": "<p>I am going to suggest using <kbd>Ctrl</kbd> + <kbd>v</kbd> (<code><C-v></code>) to make a block.</p>\n\n<p>It so... | 2020/02/10 | [
"https://vi.stackexchange.com/questions/22827",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26885/"
] | I search a way to paste/merge 2 block of text
```
apple
pear
banana
tomato
beans
potato
```
like this
```
apple tomato
pear beans
banana potato
```
The lines have different length but same number of lines of course.
I don't want different number of spaces like in visual block paste, and I search a way without u... | This would be very easy with a macro, but you've stated don't want to use one, so here's a few alternative methods. I think they're all more complicated than a simple macro-based solution, but they show off some interesting features of Vim that readers might want to use in other scenarios.
Using [`:normal`](https://vi... |
22,834 | <p>Similar question, yet not duplicate of: <a href="https://vi.stackexchange.com/questions/458/how-can-i-reload-all-buffers-at-once">How can I reload all buffers at once?</a></p>
<p>If <code>:wa</code> writes all, would not <code>:ea</code> be expected to reload all?</p>
<p>How could one script <code>:ea</code> to be... | [
{
"answer_id": 22835,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>While I cannot answer design questions, not being a designer, I would hazard a guess that <code>:wall</code> wa... | 2020/02/11 | [
"https://vi.stackexchange.com/questions/22834",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25873/"
] | Similar question, yet not duplicate of: [How can I reload all buffers at once?](https://vi.stackexchange.com/questions/458/how-can-i-reload-all-buffers-at-once)
If `:wa` writes all, would not `:ea` be expected to reload all?
How could one script `:ea` to behave this way?
What are the cases when `a` append works or n... | I think D. Ben Knoble's guess is as good as any as to why `:editall` hasn't been implemented to do what you want it to. Note that `:ea` already has a function (It's short for `:earlier`), and it's unlikely that this will ever be changed, as that would break backwards compatability.
If you want to make `:ea` instead re... |
22,838 | <p>I'm trying to filter specific lines through external command. I think knowing how to do this would be extremely beneficial to me, so I'm trying to find a way to do this. As an example, I wanted to count the occurrence of a specific word or line in a file. I was trying to do this with a filter, using the following co... | [
{
"answer_id": 22839,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<blockquote>\n <p>but I don't have the option of piping the output to an external command</p>\n</blockquote>\n\n<p>Actuall... | 2020/02/11 | [
"https://vi.stackexchange.com/questions/22838",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26910/"
] | I'm trying to filter specific lines through external command. I think knowing how to do this would be extremely beneficial to me, so I'm trying to find a way to do this. As an example, I wanted to count the occurrence of a specific word or line in a file. I was trying to do this with a filter, using the following comma... | Thanks to @B Layers and @Matts answers, I've written this function which serves my purposes perfectly. I'm sharing it here for future reference, if anyone needs the same functionality.
```
" Function to pipe output of vim command to external command.
" The 'trim' argument determines whether the vim command
" output wi... |
22,847 | <p>I am trying to implement a way to get automatic completion when typing Latex environments. Consider the following situation:</p>
<pre><code>\begin{|}
\end{}
</code></pre>
<p>where <code>|</code> stands for the position of the cursor. Then I type the name of the environment, say <code>tabular</code> and press <code... | [
{
"answer_id": 22864,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 1,
"selected": false,
"text": "<p>I think you should be able to address your specific issue of remapping the <code><CR></code> by using an expression ma... | 2020/02/12 | [
"https://vi.stackexchange.com/questions/22847",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26917/"
] | I am trying to implement a way to get automatic completion when typing Latex environments. Consider the following situation:
```
\begin{|}
\end{}
```
where `|` stands for the position of the cursor. Then I type the name of the environment, say `tabular` and press `Enter` and I would like it to automatically fill the... | I've actually looked at what your code is intended to do, now, and have come up with a couple of alternatives:
A simple solution
-----------------
How about something a bit simpler that simply asks for the environment?
```
function EnvThing() abort
let env = input('Enter env: ')
return '\begin{'.x."}\<CR>end{".x... |
22,879 | <p>I've tried</p>
<pre><code>let mapleader="<C+k>"
</code></pre>
<p>or </p>
<pre><code>let mapleader="\<C+k>"
</code></pre>
<p>But it seems that both of them can't work.</p>
| [
{
"answer_id": 22882,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 2,
"selected": false,
"text": "<p>The correct syntax is:</p>\n\n<pre><code>let mapleader=\"\\<C-k>\"\n</code></pre>\n\n<p>It works as expected... | 2020/02/15 | [
"https://vi.stackexchange.com/questions/22879",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26960/"
] | I've tried
```
let mapleader="<C+k>"
```
or
```
let mapleader="\<C+k>"
```
But it seems that both of them can't work. | The correct syntax is:
```
let mapleader="\<C-k>"
```
It works as expected. |
22,886 | <blockquote>
<p>How to highlight all occurrences of a search without moving the cursor?</p>
</blockquote>
<p>I want to highlight all occurrences of a word in the neighbourhood of the cursor without moving the cursor. </p>
<p>Currently, if I use <code>*</code> or <code>#</code> to highlight all occurrences of the wo... | [
{
"answer_id": 22887,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 1,
"selected": false,
"text": "<p>Maybe like this:</p>\n\n<pre><code>nnoremap <leader>h :execute 'match Search /\\V'..escape(expand('<cword>')... | 2020/02/15 | [
"https://vi.stackexchange.com/questions/22886",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26505/"
] | >
> How to highlight all occurrences of a search without moving the cursor?
>
>
>
I want to highlight all occurrences of a word in the neighbourhood of the cursor without moving the cursor.
Currently, if I use `*` or `#` to highlight all occurrences of the word under the cursor, then I have to press `N` to get b... | I have run into the same problem before and spent some time to figure it out. Here is my answer. It works great.
```
nnoremap <Space>* <Cmd>let @/='\<'.expand('<cword>').'\>'<bar>set hlsearch<CR>
```
`/` is a register which stores search pattern. We use `let` command to set it to the pattern you want to search and s... |
22,895 | <p>If I press <kbd>Alt</kbd><kbd>o</kbd>, it prints <code>ï</code>. I would prefer it not do
anything. I tried these:</p>
<pre><code>:unmap <M-o>
:iunmap <M-o>
</code></pre>
<p>but it just says:</p>
<pre><code>E31: No such mapping
</code></pre>
<p>From the comments, I have also tried these:</p>
<pre><c... | [
{
"answer_id": 22899,
"author": "Zombo",
"author_id": 7184,
"author_profile": "https://vi.stackexchange.com/users/7184",
"pm_score": 1,
"selected": true,
"text": "<p>This works for upper and lower:</p>\n\n<pre><code>imap <M-O> <Nop>\nimap <M-o> <Nop>\n</code></pre... | 2020/02/16 | [
"https://vi.stackexchange.com/questions/22895",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7184/"
] | If I press `Alt``o`, it prints `ï`. I would prefer it not do
anything. I tried these:
```
:unmap <M-o>
:iunmap <M-o>
```
but it just says:
```
E31: No such mapping
```
From the comments, I have also tried these:
```
gvim -u NONE -N
gvim --clean
```
and I tried the release without runtime files as well:
<https... | This works for upper and lower:
```
imap <M-O> <Nop>
imap <M-o> <Nop>
``` |
22,912 | <p>If I have a file <code>a.js</code> like this:</p>
<pre><code>let a1 = [
];
</code></pre>
<p>and I press <kbd>Enter</kbd> at the end of the first line, a Tab is inserted. I do not want this, so I added a setting:</p>
<pre><code>filetype indent off
</code></pre>
<p>but then if I have this:</p>
<pre><code>let a1 =... | [
{
"answer_id": 22913,
"author": "Greg Nisbet",
"author_id": 6420,
"author_profile": "https://vi.stackexchange.com/users/6420",
"pm_score": 2,
"selected": false,
"text": "<p>I think the setting <code>set smartindent</code> has the behavior you want.</p>\n\n<p>If you use the following <cod... | 2020/02/17 | [
"https://vi.stackexchange.com/questions/22912",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7184/"
] | If I have a file `a.js` like this:
```
let a1 = [
];
```
and I press `Enter` at the end of the first line, a Tab is inserted. I do not want this, so I added a setting:
```
filetype indent off
```
but then if I have this:
```
let a1 = [
10,
20
];
```
I have to manually add tabs for each item. So I added a... | After trying the methods in the question, I then tried this:
```
filetype indent off
function F_indent()
return indent(prevnonblank(v:lnum - 1))
endfunction
set indentexpr=F_indent()
```
<http://vimdoc.sourceforge.net/htmldoc/eval.html#prevnonblank()>
which passes the 2 tests in the question, but I noticed anoth... |
22,918 | <p><strong>Goal:</strong>
To achieve filename/path completion relative to current file directory using file name completion <code>CTRL-X CTRL-F</code>.</p>
<p>I open all my files contained in a base directory such that <code>:pwd</code> in <em>some_file</em> outputs <code>/some/path/to/base_directory</code>. This lets ... | [
{
"answer_id": 22928,
"author": "Rich",
"author_id": 343,
"author_profile": "https://vi.stackexchange.com/users/343",
"pm_score": 3,
"selected": true,
"text": "<p>There are two separate issues in your code:</p>\n\n<ol>\n<li><p>In most situations, if you want to use the <em>contents</em> ... | 2020/02/17 | [
"https://vi.stackexchange.com/questions/22918",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26997/"
] | **Goal:**
To achieve filename/path completion relative to current file directory using file name completion `CTRL-X CTRL-F`.
I open all my files contained in a base directory such that `:pwd` in *some\_file* outputs `/some/path/to/base_directory`. This lets me search for other files relative to base\_directory, that I... | There are two separate issues in your code:
1. In most situations, if you want to use the *contents* of a variable in a Vim command, you need to use `:execute` to achieve this. `lcd w:baseCwd` will attempt to change to a directory named `w:baseCwd`. To change to the directory currently stored in that variable, use `:e... |
22,935 | <p>I am attempting to use to the <code>:help</code> command in Neovim however the following error is returned:</p>
<pre><code>E432: Tags file not sorted: /Users/seeker/.config/nvim/plugged/nerdtree/doc/tags
E432: Tags file not sorted: /Users/seeker/.config/nvim/plugged/fzf.vim/doc/tags
E432: Tags file not sorted: /Use... | [
{
"answer_id": 22936,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>This is an indication that the <code>tags</code> files that work as indices for the help system are not sorted as e... | 2020/02/18 | [
"https://vi.stackexchange.com/questions/22935",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26955/"
] | I am attempting to use to the `:help` command in Neovim however the following error is returned:
```
E432: Tags file not sorted: /Users/seeker/.config/nvim/plugged/nerdtree/doc/tags
E432: Tags file not sorted: /Users/seeker/.config/nvim/plugged/fzf.vim/doc/tags
E432: Tags file not sorted: /Users/seeker/.config/nvim/pl... | This is an indication that the `tags` files that work as indices for the help system are not sorted as expected. Vim/NeoVim wants those to be sorted so it can quickly find a help item in those files without having to read the whole contents of all those files
You can try to regenerate the `tags` files for all doc dire... |
22,937 | <p>I am new to Vim and I would like to make a key binding to compile my LaTeX source. I have the following </p>
<pre><code>autocmd FileType tex :nnoremap <buffer> <F5> :!pdflatex %<CR>
</code></pre>
<p>which is working very well but <strong>I would like it to run in the background</strong>.
I know t... | [
{
"answer_id": 22939,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": true,
"text": "<p>If you just want a non-disruptive process to run, consider tpope's Dispatch plugin: if you have a <code>makeprg<... | 2020/02/18 | [
"https://vi.stackexchange.com/questions/22937",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I am new to Vim and I would like to make a key binding to compile my LaTeX source. I have the following
```
autocmd FileType tex :nnoremap <buffer> <F5> :!pdflatex %<CR>
```
which is working very well but **I would like it to run in the background**.
I know there are options with `<silent>` but I can't make them wo... | If you just want a non-disruptive process to run, consider tpope's Dispatch plugin: if you have a `makeprg` setup well for LaTex, you could use it's `:Make`; otherwise, you'll want to `:Start pdflatex ...`.
To silence a *mapping*, use `nnoremap <silent> ...`. But note that this just prevents echoing of the simulated c... |
22,938 | <p>I am trying to use Python in <code>vim</code>, but it doesn't work despite <code>vim</code> having the <code>+python3</code> option.</p>
<pre><code>:python print("hello")
</code></pre>
<p>gives</p>
<pre><code>E319: Sorry, the command is not available in this version
</code></pre>
<p><strong>Question:</strong> Ho... | [
{
"answer_id": 22940,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 1,
"selected": false,
"text": "<p>Check <code>:help if-pyth</code>: you need to use <code>:python3</code>.</p>\n"
},
{
"answer_id": 22943... | 2020/02/18 | [
"https://vi.stackexchange.com/questions/22938",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/14024/"
] | I am trying to use Python in `vim`, but it doesn't work despite `vim` having the `+python3` option.
```
:python print("hello")
```
gives
```
E319: Sorry, the command is not available in this version
```
**Question:** How can this problem be fixed?
The `:version` command's output:
```
VIM - Vi IMproved 8.0 (2016... | The problem was solved.
The `:python3` or `:pythonx` (`:py3` or `:pyx`) should be used instead of the simple `:python`.
See `:h python3` and `:h pythonx`.
So, `:py3 print("hello")` gives `hello` as expected.
---
Also, to see what version of Python is being used, do:
```
:pyx import sys
:pyx print(sys.version)
`... |
22,947 | <p>I'm going through vimtutor and just learned about using <code>:!<CMD></code> to execute a shell command from within vim.</p>
<p>I read a bit up on why not to use just <code>:<CMD></code> and apparently it's because some character sequences like <code>ls</code> are used by vim itself.</p>
<p>Alright, bu... | [
{
"answer_id": 22948,
"author": "eyal karni",
"author_id": 18375,
"author_profile": "https://vi.stackexchange.com/users/18375",
"pm_score": 1,
"selected": false,
"text": "<p><code>:cd</code> is vim command\n<code>:!</code> is used to execute bash commands.\nIn this case, cd. The cur dir ... | 2020/02/19 | [
"https://vi.stackexchange.com/questions/22947",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27037/"
] | I'm going through vimtutor and just learned about using `:!<CMD>` to execute a shell command from within vim.
I read a bit up on why not to use just `:<CMD>` and apparently it's because some character sequences like `ls` are used by vim itself.
Alright, but the first thing I tried afterwards already didn't go as expe... | I assume you are aware, generally, of the notion of parent and child processes. Particularly with respect to shells. Let's say I'm in the shell. My prompt shows the current directory (`$PWD`)...
```
[/bar] $ sh # launch child shell
[/bar] $ cd /foo
[/foo] $ exit
[/bar] $ # back in the parent it's still /bar... |
22,998 | <p>Suppose I have the file:</p>
<pre><code>
begin
asdf
asdf
end
begin
asdf
end
begin
asdfasdf
end
</code></pre>
<p>How can I use something like the global command to delete every empty line in between 'begin' and 'end'?</p>
<p><code>:/begin/,/end/ g/^$/d</code> only deletes the space in the first begin/end bloc... | [
{
"answer_id": 22999,
"author": "nabn",
"author_id": 5178,
"author_profile": "https://vi.stackexchange.com/users/5178",
"pm_score": 1,
"selected": false,
"text": "<p>You could instead try this: <code>:g/begin/,/end/ s/^$//</code>. I don't think <code>g</code> works recursively, so using ... | 2020/02/26 | [
"https://vi.stackexchange.com/questions/22998",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16483/"
] | Suppose I have the file:
```
begin
asdf
asdf
end
begin
asdf
end
begin
asdfasdf
end
```
How can I use something like the global command to delete every empty line in between 'begin' and 'end'?
`:/begin/,/end/ g/^$/d` only deletes the space in the first begin/end block.
Thank you for your help! | In the very general case, the `:g` command cannot be called recursively. There is one exception:
Since Vim patch [8.0.0630](https://github.com/vim/vim/releases/tag/v8.0.0630), one can call a recursive `:g` command, if it operates only within a single line. So you can do something like (quoting the [help](https://vimhel... |
23,017 | <p>Let's say with the cursor I'm on <code>b</code> in</p>
<pre><code>def f(a=1,
b=2,
c=3,
e=4
)
</code></pre>
<p>and we want to delete the whole argument including the line break, so that we get</p>
<pre><code>def f(a=1,
c=3,
e=4
)
</code></pre>
<p>but without deleting the ... | [
{
"answer_id": 23018,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<blockquote>\n <p>the best I could come up with is using visual mode: v, j, h, d</p>\n</blockquote>\n\n<p><code>h</code> i... | 2020/02/27 | [
"https://vi.stackexchange.com/questions/23017",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27165/"
] | Let's say with the cursor I'm on `b` in
```
def f(a=1,
b=2,
c=3,
e=4
)
```
and we want to delete the whole argument including the line break, so that we get
```
def f(a=1,
c=3,
e=4
)
```
but without deleting the preceding character (i.e. it should also be applicable to de... | You could do, `DJx`
```
D -> delete rest of the line
J -> join the next line
x -> delete the space added by join
``` |
23,028 | <p>I have <code>ctags</code> installed on my <code>Windows</code> machine.</p>
<p>I have the following mappings in my <code>vimrc</code> file</p>
<pre><code>set tags=./tags;/
nnoremap <F5> :!ctags -R .<CR>
nnoremap ,dd :exec("tag ".expand("<cword>"))<CR>
</code></pre>
<p>I'm trying to navigat... | [
{
"answer_id": 24881,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 0,
"selected": false,
"text": "<p>ctags creates a static index of language objects. When several objects share the same name it jumps to the first one in the i... | 2020/02/28 | [
"https://vi.stackexchange.com/questions/23028",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/16800/"
] | I have `ctags` installed on my `Windows` machine.
I have the following mappings in my `vimrc` file
```
set tags=./tags;/
nnoremap <F5> :!ctags -R .<CR>
nnoremap ,dd :exec("tag ".expand("<cword>"))<CR>
```
I'm trying to navigate a big project which has many classes. There are many functions that have the same name b... | You didn't mention the language you're using with ctags, but in any case, you're most likely not calling ctags with the necessary flags to include namespace information. Support for each language varies, but you need to add `--extras=+q` in order to enable namespaces:
```
#LETTER NAME ENABLED LANGUAGE ... |
23,033 | <p>I sometimes need to insert auto_incremented, numbered columns on other people's machines so I'm looking for a good way to do so without relying on any custom plugins, macros, or scripts; standard Vim commands only.</p>
<p>Example going from :</p>
<pre><code>line a
line b
line c
...
line x
line y
line z
</code></pr... | [
{
"answer_id": 24881,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 0,
"selected": false,
"text": "<p>ctags creates a static index of language objects. When several objects share the same name it jumps to the first one in the i... | 2020/02/28 | [
"https://vi.stackexchange.com/questions/23033",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27161/"
] | I sometimes need to insert auto\_incremented, numbered columns on other people's machines so I'm looking for a good way to do so without relying on any custom plugins, macros, or scripts; standard Vim commands only.
Example going from :
```
line a
line b
line c
...
line x
line y
line z
```
becoming then :
```
lin... | You didn't mention the language you're using with ctags, but in any case, you're most likely not calling ctags with the necessary flags to include namespace information. Support for each language varies, but you need to add `--extras=+q` in order to enable namespaces:
```
#LETTER NAME ENABLED LANGUAGE ... |
23,036 | <p>I recently upgraded my Cygwin from a 2015 installation (5 years ago) to the current "2020" version. Gvim now automatically indents by <code>shiftwidth</code> columns when I press return after a curly brace <code>{</code> on a line by itself. From an initial web search, I think this might be related to the <code>ci... | [
{
"answer_id": 23051,
"author": "user2153235",
"author_id": 7041,
"author_profile": "https://vi.stackexchange.com/users/7041",
"pm_score": 0,
"selected": false,
"text": "<p>Based on <a href=\"https://vi.stackexchange.com/questions/20560/why-does-vim-still-auto-indent-latex-after-i-set-no... | 2020/02/28 | [
"https://vi.stackexchange.com/questions/23036",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7041/"
] | I recently upgraded my Cygwin from a 2015 installation (5 years ago) to the current "2020" version. Gvim now automatically indents by `shiftwidth` columns when I press return after a curly brace `{` on a line by itself. From an initial web search, I think this might be related to the `cindent` option, so I issued the c... | This behavior is being enabled by the [custom indentation function](https://github.com/vim/vim/blob/v8.2.0/runtime/indent/tex.vim#L169) for the `tex` filetype.
You can configure the behavior of that function, by setting some variables in your vimrc.
For your specific case, to disable indentation after braces, you can... |
23,042 | <p>I'm working on a plugin that needs to parse a YAML-like list and I can't quite nail the pattern needed to split the string. The pattern needs to match a comma delimited list that can have both singly quoted fields and embedded (doubled) single quotes.</p>
<p>The pattern in question is:</p>
<pre><code>let s:pattern... | [
{
"answer_id": 23051,
"author": "user2153235",
"author_id": 7041,
"author_profile": "https://vi.stackexchange.com/users/7041",
"pm_score": 0,
"selected": false,
"text": "<p>Based on <a href=\"https://vi.stackexchange.com/questions/20560/why-does-vim-still-auto-indent-latex-after-i-set-no... | 2020/02/29 | [
"https://vi.stackexchange.com/questions/23042",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27198/"
] | I'm working on a plugin that needs to parse a YAML-like list and I can't quite nail the pattern needed to split the string. The pattern needs to match a comma delimited list that can have both singly quoted fields and embedded (doubled) single quotes.
The pattern in question is:
```
let s:pattern = '\m\%(^\|,\)\%(\s*... | This behavior is being enabled by the [custom indentation function](https://github.com/vim/vim/blob/v8.2.0/runtime/indent/tex.vim#L169) for the `tex` filetype.
You can configure the behavior of that function, by setting some variables in your vimrc.
For your specific case, to disable indentation after braces, you can... |
23,076 | <p>If I start with this file:</p>
<pre><code>https://example.com
<>
</code></pre>
<p>and press <code>ddp</code>, I expect to get this:</p>
<pre><code><https://example.com>
</code></pre>
<p>but instead I get this:</p>
<pre><code><>
https://example.com
</code></pre>
<p>What am I doing wrong?</p>
| [
{
"answer_id": 23077,
"author": "Zombo",
"author_id": 7184,
"author_profile": "https://vi.stackexchange.com/users/7184",
"pm_score": 1,
"selected": true,
"text": "<p>Instead of <kbd>d</kbd><kbd>d</kbd>, can use:</p>\n\n<p><kbd>D</kbd></p>\n\n<p>Or:</p>\n\n<p><kbd>d</kbd><kbd>End</kbd></p... | 2020/03/03 | [
"https://vi.stackexchange.com/questions/23076",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7184/"
] | If I start with this file:
```
https://example.com
<>
```
and press `ddp`, I expect to get this:
```
<https://example.com>
```
but instead I get this:
```
<>
https://example.com
```
What am I doing wrong? | Instead of `d``d`, can use:
`D`
Or:
`d``End`
<https://fprintf.net/vimCheatSheet.html> |
23,101 | <p>I deleted lines in a file with</p>
<pre><code>:g/^\s*key3/d
</code></pre>
<p>and now have a file like this:</p>
<pre><code>entry{entryname1,
key1 = {text},
key2 = {text},
}
entry{entryname2,
anotherkey = {text},
yetanotherkey = {text}
}
...
</code></pre>
<p>I want to delete the trailing comma af... | [
{
"answer_id": 23102,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>You can use <code>:g</code> again with a regular expression, but use a line offset of -1 to have the global command... | 2020/03/04 | [
"https://vi.stackexchange.com/questions/23101",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27263/"
] | I deleted lines in a file with
```
:g/^\s*key3/d
```
and now have a file like this:
```
entry{entryname1,
key1 = {text},
key2 = {text},
}
entry{entryname2,
anotherkey = {text},
yetanotherkey = {text}
}
...
```
I want to delete the trailing comma after key2 (the name of the last key can change) on... | You can use `:g` again with a regular expression, but use a line offset of -1 to have the global command act on the lines above the match.
Then you can use that to apply a `:s` command to remove any trailing commas.
Putting it all together:
```
:g/^{$/-1s/,$//
```
These offsets are explained in [section 10.3](http... |
23,110 | <p>My <code>.tmux.conf</code> file was initially empty, but then I edited by basically copying the <a href="https://unix.stackexchange.com/a/318285/324019">Linux part of this answer from UnixSE</a>. The problem below occurred both before and after I edited that <code>conf</code> file.<br />
I tried to copy text from a ... | [
{
"answer_id": 23111,
"author": "francois P",
"author_id": 27161,
"author_profile": "https://vi.stackexchange.com/users/27161",
"pm_score": 3,
"selected": true,
"text": "<p>So using <code>:set paste</code> first can resolv the issue.</p>\n\n<p>as you asked here is my tmuxrc but it is ver... | 2020/03/05 | [
"https://vi.stackexchange.com/questions/23110",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21996/"
] | My `.tmux.conf` file was initially empty, but then I edited by basically copying the [Linux part of this answer from UnixSE](https://unix.stackexchange.com/a/318285/324019). The problem below occurred both before and after I edited that `conf` file.
I tried to copy text from a website. When I'm using Vim in bash wit... | So using `:set paste` first can resolv the issue.
as you asked here is my tmuxrc but it is very short :
```
:~$ cat ~/.tmuxrc
set -g status-utf8 on
:~$
```
So I don't think it is special |
23,135 | <p>There is this feature or module in Vim which auto back-indents words during writing if/else statements. For example:</p>
<pre><code>if a == 1:
xx <-- here when I press enter cursor goes right below end of word "xx".
else <-- however as soon as I fully type word "else" this line gets automatically inden... | [
{
"answer_id": 23136,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 4,
"selected": true,
"text": "<p>Let's start from the beginning. There are quite a few (local to buffer) options in Vim to work with indenting.</p>\n\n<p>... | 2020/03/08 | [
"https://vi.stackexchange.com/questions/23135",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27304/"
] | There is this feature or module in Vim which auto back-indents words during writing if/else statements. For example:
```
if a == 1:
xx <-- here when I press enter cursor goes right below end of word "xx".
else <-- however as soon as I fully type word "else" this line gets automatically indented backwards
```
... | Let's start from the beginning. There are quite a few (local to buffer) options in Vim to work with indenting.
`autoindent` is the most basic setting; it simply makes a new line to have an equivalent number (influenced by `copyindent` and `preserveindent` options) of leading spaces/tabs as in a previous line;
`smarti... |
23,149 | <p>I was reading a blog post for <a href="https://medium.com/@kpereksta/setting-up-a-c-development-environment-with-vim-on-debian-ea42d5b810" rel="nofollow noreferrer">Settings up a C# Development Environment with Vim on Debian</a> and I got most of this going except I have an issue with the <code><C-x><C-o>... | [
{
"answer_id": 23143,
"author": "stackzebra",
"author_id": 18912,
"author_profile": "https://vi.stackexchange.com/users/18912",
"pm_score": 1,
"selected": false,
"text": "<p>Put this in your .vimrc: </p>\n\n<pre><code>set path+=**\n</code></pre>\n\n<p>This will also search in all subdir... | 2020/03/09 | [
"https://vi.stackexchange.com/questions/23149",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/11559/"
] | I was reading a blog post for [Settings up a C# Development Environment with Vim on Debian](https://medium.com/@kpereksta/setting-up-a-c-development-environment-with-vim-on-debian-ea42d5b810) and I got most of this going except I have an issue with the `<C-x><C-o>` inoremap'ing. I am running both Vim 8.2 and NeoVim 0.4... | Don’t do the `'path'` trick. [The `'path'` option affects many of vim’s best navigational techniques.](https://github.com/tpope/vim-apathy)
Instead (and I only learned about this recently—see `:help 'wildmenu'`), when you’re dealing with directories:
* use `Down` to “drill down” into the subdirectory and start comple... |
23,181 | <p>I'm using the <a href="https://github.com/psf/black" rel="noreferrer">psf/black</a> plugin, I install and load it with vimplug: <code>Plug 'psf/black'</code>
and I use it with <code><leader>f</code>: <code>autocmd FileType python nmap <leader>f :Black<CR></code></p>
<p>I use and prefer 2 space ind... | [
{
"answer_id": 23182,
"author": "Wis",
"author_id": 20087,
"author_profile": "https://vi.stackexchange.com/users/20087",
"pm_score": 2,
"selected": false,
"text": "<p>It looks like the Black Python code formatter <a href=\"https://github.com/psf/black/issues/378#issuecomment-400112373\" ... | 2020/03/12 | [
"https://vi.stackexchange.com/questions/23181",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20087/"
] | I'm using the [psf/black](https://github.com/psf/black) plugin, I install and load it with vimplug: `Plug 'psf/black'`
and I use it with `<leader>f`: `autocmd FileType python nmap <leader>f :Black<CR>`
I use and prefer 2 space indentation with JavaScript (Prettier), Python and most of the other programming languages I... | The whole point of Black is that it is not configurable. It calls itself "the uncompromising code formatter".
Its name comes from the Henry Ford quote about the Model T:
>
> "any color you want, so long as it is Black".
>
>
>
In other words, you can indent any number of spaces that you want, so long as you want ... |
23,186 | <p>I am trying to add some custom highlighting to my Vim. But my regex matching is not working correctly.</p>
<pre><code>let ignoreHiInComments = '^\s*\(\/\/.*\)\@<!' "Ignore highlighting in C++ comments
call matchadd('UserTypes', ignoreHiInComments.'\zs\w\+\ze::.\+')
</code></pre>
<p>This will do the following... | [
{
"answer_id": 23187,
"author": "sdp",
"author_id": 25618,
"author_profile": "https://vi.stackexchange.com/users/25618",
"pm_score": 3,
"selected": true,
"text": "<p>From <code>pattern.txt</code>:</p>\n\n<pre><code> */\\@<!*\n\\@<! Matches with zero wi... | 2020/03/13 | [
"https://vi.stackexchange.com/questions/23186",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20186/"
] | I am trying to add some custom highlighting to my Vim. But my regex matching is not working correctly.
```
let ignoreHiInComments = '^\s*\(\/\/.*\)\@<!' "Ignore highlighting in C++ comments
call matchadd('UserTypes', ignoreHiInComments.'\zs\w\+\ze::.\+')
```
This will do the following highlighting:
```
myclass::... | From `pattern.txt`:
```
*/\@<!*
\@<! Matches with zero width if the preceding atom does NOT match just
before what follows. Thus this matches if there is no position in the
current or previous line where the atom matches such that it ends just
before what follows.
```
Note the word **... |
23,189 | <p>Using Vim 8.0</p>
<p>I'm trying to make a table where the first column is the name of a file and the second column the creation date of such file, to which I have access by the exif data.</p>
<p>I would like to achieve this in one line, just to learn how.</p>
<p>Currently, I'm using:</p>
<p><code>:!ls</code></p... | [
{
"answer_id": 23187,
"author": "sdp",
"author_id": 25618,
"author_profile": "https://vi.stackexchange.com/users/25618",
"pm_score": 3,
"selected": true,
"text": "<p>From <code>pattern.txt</code>:</p>\n\n<pre><code> */\\@<!*\n\\@<! Matches with zero wi... | 2020/03/13 | [
"https://vi.stackexchange.com/questions/23189",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/25077/"
] | Using Vim 8.0
I'm trying to make a table where the first column is the name of a file and the second column the creation date of such file, to which I have access by the exif data.
I would like to achieve this in one line, just to learn how.
Currently, I'm using:
`:!ls`
To get all the filenames I'll be working wit... | From `pattern.txt`:
```
*/\@<!*
\@<! Matches with zero width if the preceding atom does NOT match just
before what follows. Thus this matches if there is no position in the
current or previous line where the atom matches such that it ends just
before what follows.
```
Note the word **... |
23,196 | <p>I have this string :</p>
<pre><code>content htp://ww.mySite.com/image/123kw9ykjm-065n/640/568/25452583.suite />meta property="twitter:suite
</code></pre>
<p>and I want to get the link to add it in a list;</p>
<p>Here is my function :</p>
<pre><code>function MyCodeSource()
execute "normal! gg"
... | [
{
"answer_id": 23197,
"author": "MinestoPix",
"author_id": 27411,
"author_profile": "https://vi.stackexchange.com/users/27411",
"pm_score": 0,
"selected": false,
"text": "<p>You could just use \\ze after suite, like this:</p>\n\n<pre><code>silent! exe '%s/\\<https.*suite\\ze/\\=add(my... | 2020/03/14 | [
"https://vi.stackexchange.com/questions/23196",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26872/"
] | I have this string :
```
content htp://ww.mySite.com/image/123kw9ykjm-065n/640/568/25452583.suite />meta property="twitter:suite
```
and I want to get the link to add it in a list;
Here is my function :
```
function MyCodeSource()
execute "normal! gg"
let myList = []
silent! exe '%s/\<https.*suite/\=... | The problem you're having is that it's matching all the way to the *last* occurrence of the pattern `suite` on the line.
To solve that, you can either use a non-greedy multi or you can restrict your match to non-whitespace characters only.
A non-greedy multi such as [`\{-}`](https://vimhelp.org/pattern.txt.html#%2F%5... |
23,198 | <p>I am trying to output the contents of a file opened in vim ex mode to stdout.</p>
<pre><code>vi -es +'%write !tee' +'q' ./testfile
</code></pre>
<p>Unfortunately, it does not write anything, although if I open the file in ex mode, like this:</p>
<pre><code>vi -e ./testfile
</code></pre>
<p>and issue the same com... | [
{
"answer_id": 23203,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 3,
"selected": true,
"text": "<p>This is a hack but if a direct solution can't be found perhaps it will do (I have an idea of how to do it purely with ... | 2020/03/14 | [
"https://vi.stackexchange.com/questions/23198",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27202/"
] | I am trying to output the contents of a file opened in vim ex mode to stdout.
```
vi -es +'%write !tee' +'q' ./testfile
```
Unfortunately, it does not write anything, although if I open the file in ex mode, like this:
```
vi -e ./testfile
```
and issue the same command:
```
:%write !tee
```
then the file conte... | This is a hack but if a direct solution can't be found perhaps it will do (I have an idea of how to do it purely with vim but need to try it later).
Try the *print* command `:[range][p]rint [flags]` with `l` as a flag. This will replace tabs with `^I` (two characters). Then use `sed` to replace with actual tabs.
For... |
23,205 | <p>With other text editors, if you press Home, it first takes you to the indent,
then all the way to the left.</p>
<p>Is this possible with Vim?</p>
| [
{
"answer_id": 23206,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 1,
"selected": false,
"text": "<p>Yes, it is possible to create a mapping for that.</p>\n\n<p>For example, a mapping that will go to the indent if y... | 2020/03/16 | [
"https://vi.stackexchange.com/questions/23205",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7184/"
] | With other text editors, if you press Home, it first takes you to the indent,
then all the way to the left.
Is this possible with Vim? | This is what I came up with. It is not as short as other options, but seems to
do the job:
```
func Cursor()
let n_cur = col('.') - 1
let n_ind = indent(line('.'))
return [n_cur, n_ind]
endfunc
func Home()
let [n_cur, n_ind] = Cursor()
if n_cur > n_ind
normal ^
else
normal 0
endif
end... |
23,220 | <p>I would like to have the behavior where I can run <code>:Vex<CR></code> when pressing <code><Tab></code> in normal mode:</p>
<pre><code>nnoremap <Tab> :Vex<CR>
</code></pre>
<p>... to open the netrw file tree window and then I would like to close this window when I press <code><Tab></... | [
{
"answer_id": 23221,
"author": "stimulate",
"author_id": 17840,
"author_profile": "https://vi.stackexchange.com/users/17840",
"pm_score": 0,
"selected": false,
"text": "<p>The best I could come up with for now. It does not respect the current tab page yet, but maybe this could be achiev... | 2020/03/18 | [
"https://vi.stackexchange.com/questions/23220",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/17840/"
] | I would like to have the behavior where I can run `:Vex<CR>` when pressing `<Tab>` in normal mode:
```
nnoremap <Tab> :Vex<CR>
```
... to open the netrw file tree window and then I would like to close this window when I press `<Tab>` again in any other window in this tab. Is there some way how I can get the window I... | **Update:**
`Lexplore` bug mentioned below is [fixed](https://github.com/vim/vim/blob/a853089479b60b829bab1c4a0a737a073415f8a7/runtime/autoload/netrw.vim#L1275) (also see [the github comment](https://github.com/vim/vim/issues/1016#issuecomment-640274307)), so you can now use a single mapping to toggle the netrw window... |
23,228 | <p>Movement and actions using <code>)</code> and <code>(</code> are very powerful: I use them all the time. However, when writing and editing LaTeX, I have run into the following problem: vim cannot recognize the end of some LaTeX sentences. For example:</p>
<pre class="lang-latex prettyprint-override"><code>This is a... | [
{
"answer_id": 23231,
"author": "Stefan Schroeder",
"author_id": 27470,
"author_profile": "https://vi.stackexchange.com/users/27470",
"pm_score": 0,
"selected": false,
"text": "<p>That depends on what causes Vim to think that the sentence ends at another spot than what you intend. You co... | 2020/03/19 | [
"https://vi.stackexchange.com/questions/23228",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7933/"
] | Movement and actions using `)` and `(` are very powerful: I use them all the time. However, when writing and editing LaTeX, I have run into the following problem: vim cannot recognize the end of some LaTeX sentences. For example:
```latex
This is a test. This is only a test. Instead, according to Gottlieb, Socrates
ha... | There is a plugin that helps: [vim-textobj-sentence](https://github.com/reedes/vim-textobj-sentence). It replaces vim's built-in `)` and `(`, and it does a better job on many LaTeX sentences. However, it also has some issues of its own. For example, it doesn't recognize sentences within parentheses. (I'm putting this h... |
23,235 | <p>I was looking at a global command that I saved from long time ago. I did not understand how it was a valid syntax, but apparently the syntax was valid because the command worked.</p>
<p>The command: <code>:g/\v\{/+1,/\v}/-1 sort</code></p>
<p>If you run it against a file with content like this:</p>
<pre><code>con... | [
{
"answer_id": 23236,
"author": "dedowsdi",
"author_id": 5017,
"author_profile": "https://vi.stackexchange.com/users/5017",
"pm_score": 3,
"selected": true,
"text": "<p>Add space between <code>pattern</code>, <code>cmd</code>:</p>\n<pre><code>g /\\v\\{/ +1,/\\v}/-1 sort\n ^-------... | 2020/03/19 | [
"https://vi.stackexchange.com/questions/23235",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27477/"
] | I was looking at a global command that I saved from long time ago. I did not understand how it was a valid syntax, but apparently the syntax was valid because the command worked.
The command: `:g/\v\{/+1,/\v}/-1 sort`
If you run it against a file with content like this:
```
const something = {
c: 'x',
b: 'x'... | Add space between `pattern`, `cmd`:
```
g /\v\{/ +1,/\v}/-1 sort
^------------------separation between pattern and command
```
It's a good habit to leave space between `pattern` and `cmd` if your `cmd` takes a range.
`+1,/\v}/-1` is a range from the line after the `{` found by the `:g` command to the line p... |
23,248 | <p>I have a file in my <code>~/.vim/ftdetect</code> directory, which includes configuration such as:</p>
<pre><code>autocmd BufRead,BufNewFile,BufWritePost .envrc.template set filetype=sh
</code></pre>
<p>However, I also have the <code>vim-polyglot</code> plugin installed (in <code>~/.vim/pack/packager/start/vim-poly... | [
{
"answer_id": 23251,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 3,
"selected": false,
"text": "<p>You're in luck: the <code>after</code> directory exists for exactly this reason. <code>~/.vim/after</code> is <... | 2020/03/20 | [
"https://vi.stackexchange.com/questions/23248",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/91/"
] | I have a file in my `~/.vim/ftdetect` directory, which includes configuration such as:
```
autocmd BufRead,BufNewFile,BufWritePost .envrc.template set filetype=sh
```
However, I also have the `vim-polyglot` plugin installed (in `~/.vim/pack/packager/start/vim-polyglot/ftdetect/polyglot.vim`, which includes the (less... | You're in luck: the `after` directory exists for exactly this reason. `~/.vim/after` is *usually* the last entry of `'runtimepath'`, so that whatever a user puts there overrides anything before it. Since it can house a full runtime, you can put anything you would put in `~/.vim` in `~/.vim/after`! I use this commonly f... |
23,257 | <p>Within some run time files I would like to source a file relative to the $MYVIMRC file. My best efforts have lead me to this (which does not work):</p>
<pre><code>source expand("$MYVIMRC:p:h") . "/vimrc/env.vim")
</code></pre>
| [
{
"answer_id": 23258,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 3,
"selected": true,
"text": "<p>Your best effort:</p>\n\n<pre><code>source expand(\"$MYVIMRC:p:h\") . \"/vimrc/env.vim\")\n</code></pre>\n\n<p>has iss... | 2020/03/21 | [
"https://vi.stackexchange.com/questions/23257",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27110/"
] | Within some run time files I would like to source a file relative to the $MYVIMRC file. My best efforts have lead me to this (which does not work):
```
source expand("$MYVIMRC:p:h") . "/vimrc/env.vim")
``` | Your best effort:
```
source expand("$MYVIMRC:p:h") . "/vimrc/env.vim")
```
has issues:
1. `source` command doesn't work with `"strings"`
2. even if it worked with strings, you have strange last unbalanced `)`
You can try using `:execute` statement with composed `source`:
```
:exe "source " . fnamemodify("$MYVIMR... |
23,260 | <p>Suppose I have a line of LaTeX code as follows</p>
<pre><code>We have two equations $E=mc^2$ and $F=ma$.
</code></pre>
<p>How do I quickly jump between inline math equations? Let's say I'm editing the first equation <code>$E=mc^2$</code>, how do I quickly move my cursor to be inside the second equation <code>$F=ma... | [
{
"answer_id": 23261,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 1,
"selected": false,
"text": "<p>You can use a match for a <code>\\$</code>, using a look-behind to match other equations enclosed in pairs of <cod... | 2020/03/21 | [
"https://vi.stackexchange.com/questions/23260",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27497/"
] | Suppose I have a line of LaTeX code as follows
```
We have two equations $E=mc^2$ and $F=ma$.
```
How do I quickly jump between inline math equations? Let's say I'm editing the first equation `$E=mc^2$`, how do I quickly move my cursor to be inside the second equation `$F=ma$`?
Obviously I can do `fF` is this case, ... | Combine [*vim-ninja-feet*](https://github.com/tommcdo/vim-ninja-feet) and [*targets.vim*](https://github.com/wellle/targets.vim)
--------------------------------------------------------------------------------------------------------------------------------
### Preliminary steps
1. **Change `$` from separator to quot... |
23,279 | <p>I have this text :</p>
<blockquote>
<p>He's a <strong>self made man</strong> who gets what he wants. </p>
<p>The small blue <strong>forget me not</strong> flower was first used by the Grand
Lodge.</p>
</blockquote>
<p>And this function:</p>
<pre><code>function MyFunction()
let myList1 = ["self made man",... | [
{
"answer_id": 23280,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 1,
"selected": false,
"text": "<p>You're looking for the <code>substitute()</code> function...</p>\n\n<pre><code>substitute({expr}, {pat}, {sub}, {flag... | 2020/03/23 | [
"https://vi.stackexchange.com/questions/23279",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26872/"
] | I have this text :
>
> He's a **self made man** who gets what he wants.
>
>
> The small blue **forget me not** flower was first used by the Grand
> Lodge.
>
>
>
And this function:
```
function MyFunction()
let myList1 = ["self made man", "gorget me not"]
for elem in MyList1
if search("=/elem", 'W') =... | You're looking for the `substitute()` function...
```
substitute({expr}, {pat}, {sub}, {flags})
```
* `expr` is the string to work on
* `pat` is the pattern similar to `:s/pat/sub/g`.
* `sub` is the substitution similar to `sub` in the same `:s` command.
* `flags`, should include "g" as in global (again, like `:s`)
... |
23,281 | <p>Often times I use vim as a scratchpad - I just want to throw some text in there, maybe copy it to the clipboard, or munge it a bit, but it's not really important to keep it around.</p>
<p>Most of the time I do <code>vim /tmp/foo.txt</code> or whatever, but this gets a bit annoying. I combined <a href="https://vi.st... | [
{
"answer_id": 23280,
"author": "B Layer",
"author_id": 11054,
"author_profile": "https://vi.stackexchange.com/users/11054",
"pm_score": 1,
"selected": false,
"text": "<p>You're looking for the <code>substitute()</code> function...</p>\n\n<pre><code>substitute({expr}, {pat}, {sub}, {flag... | 2020/03/23 | [
"https://vi.stackexchange.com/questions/23281",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5574/"
] | Often times I use vim as a scratchpad - I just want to throw some text in there, maybe copy it to the clipboard, or munge it a bit, but it's not really important to keep it around.
Most of the time I do `vim /tmp/foo.txt` or whatever, but this gets a bit annoying. I combined [this answer](https://vi.stackexchange.com/... | You're looking for the `substitute()` function...
```
substitute({expr}, {pat}, {sub}, {flags})
```
* `expr` is the string to work on
* `pat` is the pattern similar to `:s/pat/sub/g`.
* `sub` is the substitution similar to `sub` in the same `:s` command.
* `flags`, should include "g" as in global (again, like `:s`)
... |
23,287 | <p>I have this function which insert 2 dates in a file:</p>
<pre><code>function MaFunction()
put =strftime(\"%c\")
exe 'w'
exe 'call Function1()'
put = strftime(\"%c\")
endfunction
</code></pre>
<p>Example:</p>
<pre><code>24/03/2020 07:31:22
24/03/2020 07:31:28
</code></pre>
<p>I want to know how lo... | [
{
"answer_id": 23288,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 1,
"selected": false,
"text": "<p>You can try using <code>strptime</code> function, if available, to convert both dates to unix time, substract and get... | 2020/03/24 | [
"https://vi.stackexchange.com/questions/23287",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26872/"
] | I have this function which insert 2 dates in a file:
```
function MaFunction()
put =strftime(\"%c\")
exe 'w'
exe 'call Function1()'
put = strftime(\"%c\")
endfunction
```
Example:
```
24/03/2020 07:31:22
24/03/2020 07:31:28
```
I want to know how long Function1 takes to run and display it like:
`... | There is the [`reltime()`](https://vimhelp.org/eval.txt.html#reltime%28%29) function to get relative times, and [`reltimestr()`](https://vimhelp.org/eval.txt.html#reltimestr%28%29) to display that as the number of seconds:
```
:let start = reltime()
:echo reltime(start)
[65, 11796]
:echo reltimestr(reltime(start))
71... |
23,303 | <p>I have text:</p>
<pre><code>I want to select nest and not nestlé in this text. Only the word nest!
</code></pre>
<p>and a list :</p>
<pre><code>myList = ["nest"]
</code></pre>
<pre><code>function MyFunction()
myList = ["nest"]
for elem in MyList
if search("=/elem", 'W') == 0
exe '%s/'elem ... | [
{
"answer_id": 23304,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 2,
"selected": false,
"text": "<p>You have a text (where? in a buffer? in a variable?) and you want replace words given in a list in the text with <cod... | 2020/03/25 | [
"https://vi.stackexchange.com/questions/23303",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26872/"
] | I have text:
```
I want to select nest and not nestlé in this text. Only the word nest!
```
and a list :
```
myList = ["nest"]
```
```
function MyFunction()
myList = ["nest"]
for elem in MyList
if search("=/elem", 'W') == 0
exe '%s/'elem '\{0\}/REPLACE/g'
endif
endfor
endfunction... | You have a text (where? in a buffer? in a variable?) and you want replace words given in a list in the text with `REPLACE`?
TEXT:
```
I want to select nest and not nestlé in this text. Only the word nest!
```
LIST OF WORDS:
```
['nest', 'this']
```
RESULT:
```
I want to select REPLACE and not nestlé in REPLACE ... |
23,308 | <p>When working on a file, I often open another file by</p>
<ol>
<li>looking for the file by opening the file browser in a vertical split with <code>:Vex</code></li>
<li>Opening the file</li>
</ol>
<p>it's actually nice to have the file browser show up on the left side, but I would like to have the 2nd file then open... | [
{
"answer_id": 23311,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 4,
"selected": true,
"text": "<blockquote>\n <p>How to make <code>:Vex</code> / <code>:Hex</code> open on the right side / below?</p>\n</blockquote... | 2020/03/25 | [
"https://vi.stackexchange.com/questions/23308",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27564/"
] | When working on a file, I often open another file by
1. looking for the file by opening the file browser in a vertical split with `:Vex`
2. Opening the file
it's actually nice to have the file browser show up on the left side, but I would like to have the 2nd file then open on the right split.
Similar in case I wan... | >
> How to make `:Vex` / `:Hex` open on the right side / below?
>
>
>
Both these commands have a variant with `!` that switches to splitting on the opposite side.
So you can use `:Vex!` and `:Hex!` to open on the right side, and below, respectively.
See [`:help netrw-:Vexplore`](https://vimhelp.org/pi_netrw.txt.... |
23,315 | <p>I have a file (myWords.txt) which contains one word on each line :</p>
<pre><code>Word 1
Word 2
---
---
Word 3000
</code></pre>
<p>With this file, I create a list :</p>
<pre><code>function! MyFunction()
let start = reltime()
exe 'e myWords.txt'
let myList = []
exe '%s/.*/\=add(myLi... | [
{
"answer_id": 23317,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 3,
"selected": false,
"text": "<blockquote>\n <p>I have a file (myWords.txt) which contains one word on each line</p>\n</blockquote>\n\n<p>Then simply</p... | 2020/03/25 | [
"https://vi.stackexchange.com/questions/23315",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26872/"
] | I have a file (myWords.txt) which contains one word on each line :
```
Word 1
Word 2
---
---
Word 3000
```
With this file, I create a list :
```
function! MyFunction()
let start = reltime()
exe 'e myWords.txt'
let myList = []
exe '%s/.*/\=add(myList, submatch(0))/g'
exe 'bd!'... | >
> I have a file (myWords.txt) which contains one word on each line
>
>
>
Then simply
```
let mylist = readfile('myWords.txt')
``` |
23,323 | <p>I successfully installed CoC in my Vim to have some code-suggestions/completions while coding in Rust.</p>
<p>It works fine, but I want make the suggestion-box only show up when I press a key-shortcut (E.g Cmd + x)</p>
| [
{
"answer_id": 24384,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 4,
"selected": true,
"text": "<p>According to <code>coc</code> readme you can trigger completion manually with:</p>\n\n<pre><code>\" Use <c-space>... | 2020/03/26 | [
"https://vi.stackexchange.com/questions/23323",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26000/"
] | I successfully installed CoC in my Vim to have some code-suggestions/completions while coding in Rust.
It works fine, but I want make the suggestion-box only show up when I press a key-shortcut (E.g Cmd + x) | According to `coc` readme you can trigger completion manually with:
```
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
```
NOTE that not every terminal supports `<c-space>`...
I don't know for sure how to map `cmd` in vim... Probably `D` or something:
```
" Use <CMD-x> to tr... |
23,328 | <p>I successfully installed CoC in my Vim to have some code-suggestions/completions while coding in Rust.</p>
<p>It works fine, but I want to change the color and basic looks of the suggestion box.</p>
<p>I tried achieving this by editing the JSON file that's opened after executing <code>:CocConfig</code>. This is it... | [
{
"answer_id": 24382,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 5,
"selected": true,
"text": "<p>I don't use <code>coc</code>, so I will just share my vision on how you can try to fix this.</p>\n\n<p>I assume that b... | 2020/03/26 | [
"https://vi.stackexchange.com/questions/23328",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26000/"
] | I successfully installed CoC in my Vim to have some code-suggestions/completions while coding in Rust.
It works fine, but I want to change the color and basic looks of the suggestion box.
I tried achieving this by editing the JSON file that's opened after executing `:CocConfig`. This is it's content:
```
{
"sugg... | I don't use `coc`, so I will just share my vision on how you can try to fix this.
I assume that by suggestion box you mean regular vim Pmenu.
Try to make sure if it is actually Pmenu:
1. run `:hi Pmenu` and check the colors:
[](https://i.stack.imgu... |
23,330 | <p>I want to copy strings that spans across multiple lines between two markers in a large file.</p>
<p>In the below example file, start marker is <code><ROW></code> and end marker is <code></ROW></code>.</p>
<pre><code><ROW>
<SOURCE>ANIMAL</SOURCE>
<QTY>1.00</QTY>
... | [
{
"answer_id": 23331,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>If you have <a href=\"https://github.com/michaeljsmith/vim-indent-object/tree/5c5b24c959478929b54a9e831a8e2e651... | 2020/03/26 | [
"https://vi.stackexchange.com/questions/23330",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/2737/"
] | I want to copy strings that spans across multiple lines between two markers in a large file.
In the below example file, start marker is `<ROW>` and end marker is `</ROW>`.
```
<ROW>
<SOURCE>ANIMAL</SOURCE>
<QTY>1.00</QTY>
<UNIT_PRICE>123.75</UNIT_PRICE>
<NARRATIVE>DOG100</NARRATIVE>
<OUR_REFERENCE... | If you have [indent-object](https://github.com/michaeljsmith/vim-indent-object/tree/5c5b24c959478929b54a9e831a8e2e651a465965), you could do something like
```
:global/DOG/normal "Ayii
```
I haven’t come up with a simple vanilla answer yet, but maybe
```
:global/DOG/ ?ROW?,/ROW/yank A
```
[@Lie Ryan](https://vi.st... |
23,337 | <p>I'm trying to make it so urls are highlighted and a shortcut can be used when the cursor is on top of one to open it in browser. Added this to a syntax file: </p>
<pre><code>syn match matchURL '/http[s]\?:\/\/[[:alnum:]%\/_#.-]*/'
hi matchURL ctermfg=14
</code></pre>
<p>Tested with <code>https://www.archlinux.org<... | [
{
"answer_id": 23331,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>If you have <a href=\"https://github.com/michaeljsmith/vim-indent-object/tree/5c5b24c959478929b54a9e831a8e2e651... | 2020/03/27 | [
"https://vi.stackexchange.com/questions/23337",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/-1/"
] | I'm trying to make it so urls are highlighted and a shortcut can be used when the cursor is on top of one to open it in browser. Added this to a syntax file:
```
syn match matchURL '/http[s]\?:\/\/[[:alnum:]%\/_#.-]*/'
hi matchURL ctermfg=14
```
Tested with `https://www.archlinux.org` but it didn't get highlighted.... | If you have [indent-object](https://github.com/michaeljsmith/vim-indent-object/tree/5c5b24c959478929b54a9e831a8e2e651a465965), you could do something like
```
:global/DOG/normal "Ayii
```
I haven’t come up with a simple vanilla answer yet, but maybe
```
:global/DOG/ ?ROW?,/ROW/yank A
```
[@Lie Ryan](https://vi.st... |
23,342 | <p>In command mode there is no delete from cursor to the end of line (like <code>CTRL-k</code> in bash).
So to delete a long line of trailing text, I press and hold delete, which works fine until it runs out of characters to the right of cursor, and which points it starts steam rolling over the part of the command I wi... | [
{
"answer_id": 23331,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>If you have <a href=\"https://github.com/michaeljsmith/vim-indent-object/tree/5c5b24c959478929b54a9e831a8e2e651... | 2020/03/27 | [
"https://vi.stackexchange.com/questions/23342",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27110/"
] | In command mode there is no delete from cursor to the end of line (like `CTRL-k` in bash).
So to delete a long line of trailing text, I press and hold delete, which works fine until it runs out of characters to the right of cursor, and which points it starts steam rolling over the part of the command I wish to keep (i.... | If you have [indent-object](https://github.com/michaeljsmith/vim-indent-object/tree/5c5b24c959478929b54a9e831a8e2e651a465965), you could do something like
```
:global/DOG/normal "Ayii
```
I haven’t come up with a simple vanilla answer yet, but maybe
```
:global/DOG/ ?ROW?,/ROW/yank A
```
[@Lie Ryan](https://vi.st... |
23,348 | <p>I am trying to save a file with today's date as part of name. </p>
<p>To save file, we can just do <code>:w myFile</code>. To get today's date, we can use <code>strftime</code>. Ex: <code>:echo strftime("%F") " returns 2020-03-27</code>.</p>
<p>Now I would like to combine both - to save with today's date. Somethin... | [
{
"answer_id": 23349,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 3,
"selected": true,
"text": "<p>There are two ways to do this.</p>\n\n<p>The first one is interactive, using <a href=\"https://vimhelp.org/cmdline.... | 2020/03/27 | [
"https://vi.stackexchange.com/questions/23348",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27477/"
] | I am trying to save a file with today's date as part of name.
To save file, we can just do `:w myFile`. To get today's date, we can use `strftime`. Ex: `:echo strftime("%F") " returns 2020-03-27`.
Now I would like to combine both - to save with today's date. Something like:
```
:w 'myFile-(strftime("%F")'
```
Is ... | There are two ways to do this.
The first one is interactive, using [`CTRL-R =`](https://vimhelp.org/cmdline.txt.html#c_CTRL-R_%3D) in the Ex command-line to enter an expression and evaluate it.
Start by typing the command as usual: `:w myFile-`, then press `CTRL-R`, `=`. You'll now have a `=` prompt where you can ent... |
23,353 | <p>I have this function :</p>
<pre><code>function MaFonction10()
let myList1 = ["self-made-man", "rendez-vous", "forget-me-not"]
for elem in myList1
echo len(elem)
endfor
endfunction
</code></pre>
<p>I vould like to get the number of hyphens or letter "a"s (for example) in each item, instead of... | [
{
"answer_id": 23355,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 0,
"selected": false,
"text": "<p>You can use <a href=\"https://vimhelp.org/eval.txt.html?#split%28%29\" rel=\"nofollow noreferrer\"><code>split()</... | 2020/03/28 | [
"https://vi.stackexchange.com/questions/23353",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26872/"
] | I have this function :
```
function MaFonction10()
let myList1 = ["self-made-man", "rendez-vous", "forget-me-not"]
for elem in myList1
echo len(elem)
endfor
endfunction
```
I vould like to get the number of hyphens or letter "a"s (for example) in each item, instead of the total number of lette... | You can use [`split()`](https://vimhelp.org/eval.txt.html?#split%28%29) on a string, with a pattern of `\zs`, to split it into a list of characters.
Then you can use [`filter()`](https://vimhelp.org/eval.txt.html?#filter%28%29) on that list to only keep the matching character.
Finally, you can take the `len()` of the... |
24,414 | <p>I'm trying to write a vim-script function, which allows me to <code>grep</code> the word under cursor easily in my project.</p>
<pre><code>function! CustomGrep()
vimgrep expand("<cword>") **/*.h **/*.hpp **/*.c **/*.cpp
endfunction
</code></pre>
<p>However, when I executed <code>:call CustomGrep()</code>... | [
{
"answer_id": 24413,
"author": "Steve",
"author_id": 1313,
"author_profile": "https://vi.stackexchange.com/users/1313",
"pm_score": 3,
"selected": false,
"text": "<p>There are probably better ways but you could the help functionality as long as the filetype being help is ok. I basically... | 2020/04/02 | [
"https://vi.stackexchange.com/questions/24414",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10003/"
] | I'm trying to write a vim-script function, which allows me to `grep` the word under cursor easily in my project.
```
function! CustomGrep()
vimgrep expand("<cword>") **/*.h **/*.hpp **/*.c **/*.cpp
endfunction
```
However, when I executed `:call CustomGrep()` in my vim, I got an error:
```
E480: No match: expan... | There are probably better ways but you could the help functionality as long as the filetype being help is ok. I basically use it to write down things I'm learning as I keep learning how to use gvim, it's only been 20 years :).
At the moment I have one file that I edit elsewhere then copy to where the help file is as ... |
24,419 | <p>I have a big monitor and sometimes it can be difficult to locate the small blinking underscore that is the cursor.</p>
<p>Is there a way to temporarily make the cursor more prominent and visible?</p>
<p>Note, I am using just plain virtual consoles, so there is no windowing system or GUI or anything like that.</p>
| [
{
"answer_id": 24420,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>Damian Conway wrote some functions to help him find his cursor when jumping around with <code>n</code>. I'm sur... | 2020/04/02 | [
"https://vi.stackexchange.com/questions/24419",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/6952/"
] | I have a big monitor and sometimes it can be difficult to locate the small blinking underscore that is the cursor.
Is there a way to temporarily make the cursor more prominent and visible?
Note, I am using just plain virtual consoles, so there is no windowing system or GUI or anything like that. | Damian Conway wrote some functions to help him find his cursor when jumping around with `n`. I'm sure they could be adapted for your use case (i.e., instead of the right-hand side being `n:call ...`, just do the `call`).
```
" This rewires n and N to do the highlighing...
nnoremap <silent> n n:call HLNext(0.4)<cr>
n... |
24,431 | <p>I wrote a vim-script function, which allows me to grep a keyword in my project.</p>
<pre><code>function! CustomGrep(...)
if a:0 == 0
silent vimgrep <cword> **/*.h **/*.hpp **/*.c **/*.cpp
else
silent execute 'vimgrep' a:1 '**/*.h **/*.hpp **/*.c **/*.cpp'
endif
"cope
endfunctio... | [
{
"answer_id": 24434,
"author": "Yves",
"author_id": 10003,
"author_profile": "https://vi.stackexchange.com/users/10003",
"pm_score": 1,
"selected": false,
"text": "<p>With the help of @ChristianBrabandt, I finished this function:</p>\n\n<pre><code>function! CustomReplace(target, newWord... | 2020/04/03 | [
"https://vi.stackexchange.com/questions/24431",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10003/"
] | I wrote a vim-script function, which allows me to grep a keyword in my project.
```
function! CustomGrep(...)
if a:0 == 0
silent vimgrep <cword> **/*.h **/*.hpp **/*.c **/*.cpp
else
silent execute 'vimgrep' a:1 '**/*.h **/*.hpp **/*.c **/*.cpp'
endif
"cope
endfunction
```
Now I want t... | Simpler is
```
function! CustomReplace(target, newWord)
call CustomGrep(a:target)
cdo execute 's/'.a:target.'/'.a:newWord.'/gc'
endfunction
```
Or with `cfdo` and `%s`,
```
function! CustomReplace(target, newWord)
call CustomGrep(a:target)
cfdo execute '%s/'.a:target.'/'.a:newWord.'/gc'
endfunction
``` |
24,468 | <p>I'm trying to type the following latex in nvim:</p>
<pre><code>f_{high}=\{1209,1336,1477,1633\}Hz.
</code></pre>
<p>For some reason, nvim is rendering this as:</p>
<pre><code>fₕᵢgₕ= \{ 1209, 1336, 1477, 1633\}\si{Hz}
</code></pre>
<p>How do I fix this?</p>
| [
{
"answer_id": 24469,
"author": "mahbubweb",
"author_id": 16884,
"author_profile": "https://vi.stackexchange.com/users/16884",
"pm_score": 1,
"selected": false,
"text": "<p>Do you by any chance have the plugin <code>KeitaNakamura/tex-conceal.vim</code> installed? Try putting the followin... | 2020/04/05 | [
"https://vi.stackexchange.com/questions/24468",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28780/"
] | I'm trying to type the following latex in nvim:
```
f_{high}=\{1209,1336,1477,1633\}Hz.
```
For some reason, nvim is rendering this as:
```
fₕᵢgₕ= \{ 1209, 1336, 1477, 1633\}\si{Hz}
```
How do I fix this? | The problem is that the subscript for `g` doesn't exist, and those for `h` and `i` look "off."
As noted, you can either
* turn off the conceal feature altogether (`set conceallevel=0`)
* turn off conceal in tex files just for these kinds of things (`let g:tex_conceal = 'abdmg'`)—see `:help g:tex_conceal` |
24,479 | <p>I want to go to the search result in the right-window, identified after performing a <code>/urllib</code> search in the left window.</p>
<p>Pressing <code>n\N</code> doesn't proceed to search results in other windows. How can I proceed to search results in other windows?</p>
<p><a href="https://i.stack.imgur.com/l... | [
{
"answer_id": 24509,
"author": "The Pompitous of Love",
"author_id": 16156,
"author_profile": "https://vi.stackexchange.com/users/16156",
"pm_score": 0,
"selected": false,
"text": "<p>As <a href=\"https://vi.stackexchange.com/questions/24479/how-to-go-to-search-results-located-in-other-... | 2020/04/06 | [
"https://vi.stackexchange.com/questions/24479",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26505/"
] | I want to go to the search result in the right-window, identified after performing a `/urllib` search in the left window.
Pressing `n\N` doesn't proceed to search results in other windows. How can I proceed to search results in other windows?
[](http... | If you really want to do this...
```
function! CycleWindowsSearch(direction) abort
" set forward to set variables accordingly
let forward = a:direction
if ! v:searchforward
let forward = forward ? '0' : '1'
endif
" search forward / backward
let searchflags = forward ? 'W' : 'Wb'
... |
24,483 | <p>I understand that we can use <code>da{</code> to delete a whole <code>{}</code> block in vim. I am wondering if there is a corresponding version with <code>{</code> replaced by <code>$</code> (similarly for <code>di{</code>) as this would be very useful for people typing latex with vim (math enviroments are enclosed... | [
{
"answer_id": 24485,
"author": "Bombastrelopas",
"author_id": 8403,
"author_profile": "https://vi.stackexchange.com/users/8403",
"pm_score": 0,
"selected": false,
"text": "<p>I tried these and seemed to work and be fast:</p>\n\n<pre><code>nnoremap ca$ f$vF$c \"Change with $\nnnoremap da... | 2020/04/07 | [
"https://vi.stackexchange.com/questions/24483",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28806/"
] | I understand that we can use `da{` to delete a whole `{}` block in vim. I am wondering if there is a corresponding version with `{` replaced by `$` (similarly for `di{`) as this would be very useful for people typing latex with vim (math enviroments are enclosed between 2 `$` symbols).
I tried to make my own
```
map ... | Such a mapping is quite hard to get right, including all corner cases.
Typically, you should try to use an "operator-pending" mapping to define the `a$` part, so you can use it in `da$` but also in commands such as `ya$`, `ca$`, etc. In fact if you define other custom commands that take a "motion", then `a$` will be a... |
24,493 | <blockquote>
<p>Does Vim have functionality similar to tmux's <code>display-panes</code> command
for selecting (goto) a specific window by number?</p>
</blockquote>
<p>Sometimes when I've many windows open, it can be a pain to navigate them by <code>C-w h</code> (left), <code>C-w j</code> (down), <code>C-w k</code... | [
{
"answer_id": 24494,
"author": "Martin Tournoij",
"author_id": 51,
"author_profile": "https://vi.stackexchange.com/users/51",
"pm_score": 4,
"selected": true,
"text": "<p>I'm not aware of any Vim feature or even plugin that does that; in fact, up until recently it would be rather hard t... | 2020/04/08 | [
"https://vi.stackexchange.com/questions/24493",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/26505/"
] | >
> Does Vim have functionality similar to tmux's `display-panes` command
> for selecting (goto) a specific window by number?
>
>
>
Sometimes when I've many windows open, it can be a pain to navigate them by `C-w h` (left), `C-w j` (down), `C-w k` (up), and `C-w l` (right). In that case, I miss functionality simi... | I'm not aware of any Vim feature or even plugin that does that; in fact, up until recently it would be rather hard to display it like that, but with Vim 8.2's [popup windows](https://vi.stackexchange.com/q/24462/51) it wouldn't be too hard; you just have to loop over all visible windows and create a new popup window di... |
24,502 | <p>Here is a typical workflow I would like to follow:</p>
<ol>
<li>copy some data from Excel spreadsheet into the clipboard</li>
<li>in vim , delete the data in the file using <code>ggdG</code></li>
<li>then paste the data into the file from the clipboard (I use <code>CTRL-V</code> as I am under Windows)</li>
</ol>
<... | [
{
"answer_id": 24504,
"author": "Zorzi",
"author_id": 27331,
"author_profile": "https://vi.stackexchange.com/users/27331",
"pm_score": 2,
"selected": false,
"text": "<p>Of course, everything is possible in Vim!</p>\n\n<p>There is a register system in vim, and the clipboard is the registe... | 2020/04/09 | [
"https://vi.stackexchange.com/questions/24502",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21293/"
] | Here is a typical workflow I would like to follow:
1. copy some data from Excel spreadsheet into the clipboard
2. in vim , delete the data in the file using `ggdG`
3. then paste the data into the file from the clipboard (I use `CTRL-V` as I am under Windows)
This does not work because step 2 copies the deleted data i... | When deleting the buffer contents in Vim, you can send it to the *black hole* register `"_`. From [`:help quote_`](https://vimhelp.org/change.txt.html#quote_):
>
> When writing to this register, nothing happens. This can be used to delete
> text without affecting the normal registers.
>
>
>
So simply use this co... |
24,518 | <p>I know that in insert mode <code>CTRL-Y</code> can insert the character above the cursor.</p>
<p>Is there a way of inserting the word above the cursor in insert mode ?</p>
| [
{
"answer_id": 24519,
"author": "weirdsmiley",
"author_id": 28840,
"author_profile": "https://vi.stackexchange.com/users/28840",
"pm_score": 0,
"selected": false,
"text": "<p>What you can do via a series of commands, is as following:</p>\n\n<ul>\n<li>From insert mode, go to normal mode: ... | 2020/04/10 | [
"https://vi.stackexchange.com/questions/24518",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/21293/"
] | I know that in insert mode `CTRL-Y` can insert the character above the cursor.
Is there a way of inserting the word above the cursor in insert mode ? | With a help of vimscript you might have following:
```
func! InsertWord()
" get previous line number
let prevline = line('.')-1
" get the line from current position to the end
let rest_of_line = strcharpart(getline(prevline), virtcol('.')-1)
" if cursor was on a space, return 1 <C-y>
if rest_of... |
24,528 | <p>I am looking for a simple few key command which would move till the last occurrence of a character in the line. Is there anything already existing?</p>
<p>The alternative is to jump to the next specified character and repeat the jump as many times as you need. It is not terrible; I am just curious whether there is ... | [
{
"answer_id": 24530,
"author": "Matt",
"author_id": 22797,
"author_profile": "https://vi.stackexchange.com/users/22797",
"pm_score": 2,
"selected": false,
"text": "<p>Assuming that <code>&virtualedit</code> is <code>all</code> or <code>onemore</code> it's <kbd>$</kbd><kbd>l</kbd><kb... | 2020/04/10 | [
"https://vi.stackexchange.com/questions/24528",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/17773/"
] | I am looking for a simple few key command which would move till the last occurrence of a character in the line. Is there anything already existing?
The alternative is to jump to the next specified character and repeat the jump as many times as you need. It is not terrible; I am just curious whether there is there is s... | Assuming that `&virtualedit` is `all` or `onemore` it's `$``l``F``/` (i.e. get one character past the end of the string, in case it ends in a searching character, and find char backward).
More robust variant (not to depend on `&virtualedit`) is `A``Ctrl-\``Ctrl-O``T``/``Esc`.
>
> to jump to the next specified charac... |
24,544 | <p>With regards to this line (full code at the bottom):</p>
<pre><code>let savestatus = "%{&modified ? '%#StatusUnsaved#[+++]%*' : &modifiable ? '[---] ' : '[ R ]'}"
</code></pre>
<p>If the file is modified, I wish to print <code>[+++]</code> with the highlighting face of <code>StatusUnsaved</code>.
However ... | [
{
"answer_id": 24546,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p><strike>Since <code>%!</code> statusline functions are re-evaluated (at what frequency, I do not know), you can... | 2020/04/11 | [
"https://vi.stackexchange.com/questions/24544",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27110/"
] | With regards to this line (full code at the bottom):
```
let savestatus = "%{&modified ? '%#StatusUnsaved#[+++]%*' : &modifiable ? '[---] ' : '[ R ]'}"
```
If the file is modified, I wish to print `[+++]` with the highlighting face of `StatusUnsaved`.
However with my code, it literally prints `%#StatusUnsaved#}[+++... | Since `%!` statusline functions are re-evaluated (at what frequency, I do not know), you can do this instead:
```
let savestatus = &modified ? '%#StatusUnsaved#[+++]%*' : &modifiable ? '[---] ' : '[ R ]'
```
According to `:help statusline`:
```
When the option starts with "%!" then it is used as an expression,... |
24,547 | <p>Other editors I have used are able to decode URLs. For example these can take a
string like this:</p>
<pre><code>https://nim-lang.github.io/Nim/osproc#waitForExit%2CProcess%2Cint
</code></pre>
<p>and produce this:</p>
<pre><code>https://nim-lang.github.io/Nim/osproc#waitForExit,Process,int
</code></pre>
<p>I tho... | [
{
"answer_id": 24549,
"author": "D. Ben Knoble",
"author_id": 10604,
"author_profile": "https://vi.stackexchange.com/users/10604",
"pm_score": 2,
"selected": false,
"text": "<p>tpope's <a href=\"https://github.com/tpope/vim-unimpaired/\" rel=\"nofollow noreferrer\">unimpaired plugin</a> ... | 2020/04/11 | [
"https://vi.stackexchange.com/questions/24547",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7184/"
] | Other editors I have used are able to decode URLs. For example these can take a
string like this:
```
https://nim-lang.github.io/Nim/osproc#waitForExit%2CProcess%2Cint
```
and produce this:
```
https://nim-lang.github.io/Nim/osproc#waitForExit,Process,int
```
I thought about using this:
```
%s/%2C/,/g
```
but ... | This is a naive solution, but in general I prefer limited simple solutions to
robust complicated solutions. So maybe this will be helpful to someone:
```
func URL_Decode()
sub/%2C/,/ge
sub/%3A/:/ge
sub/%5B/[/ge
sub/%5D/]/ge
endfunc
nmap c :call URL_Decode()<CR>
``` |
24,554 | <p>To advance to the next/previous character match on a line I can do:</p>
<ul>
<li><code>f</code> <code><char></code></li>
</ul>
<p>However, I find myself wanting to match against two characters on that line, for example, something like:</p>
<ul>
<li><code>f</code> <code>='</code></li>
</ul>
<p>Is this possi... | [
{
"answer_id": 24572,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 1,
"selected": false,
"text": "<p>Some plugins make it possible. The one I tried out is called <a href=\"https://github.com/justinmk/vim-sneak\" rel=\"nofollow... | 2020/04/12 | [
"https://vi.stackexchange.com/questions/24554",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28904/"
] | To advance to the next/previous character match on a line I can do:
* `f` `<char>`
However, I find myself wanting to match against two characters on that line, for example, something like:
* `f` `='`
Is this possible to do? Or do I need to do a full search at the bottom (starting with `/`). I find the search to be ... | Vim provides the `f`, `t` or `F`, `T` command to jump forward or backward to a character in current line, and you can repeat the action by pressing `,` or `;`. While these commands are useful, they are not powerful enough to be of real value:
* The movement is restricted to current line.
* There are possibly many repe... |
24,574 | <p>I would like to format Markdown headings to titlecase, and I have a bash command that works to format input:</p>
<pre><code>echo "convert to title" | awk 'BEGIN{split("a the to at in on with and but or",w); for(i in w)nocap[w[i]]}function cap(word){return toupper(substr(word,1,1)) tolower(substr(word,2))}{for(i=1;i... | [
{
"answer_id": 24562,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 3,
"selected": false,
"text": "<p>Yes, Vim has the built in <code>:make</code> command which executes <code>make</code> by default, but you can set up other bu... | 2020/04/13 | [
"https://vi.stackexchange.com/questions/24574",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28938/"
] | I would like to format Markdown headings to titlecase, and I have a bash command that works to format input:
```
echo "convert to title" | awk 'BEGIN{split("a the to at in on with and but or",w); for(i in w)nocap[w[i]]}function cap(word){return toupper(substr(word,1,1)) tolower(substr(word,2))}{for(i=1;i<=NF;++i){prin... | Yes, Vim has the built in `:make` command which executes `make` by default, but you can set up other build systems by setting `makeprg`. There’s no progress visualisation by default, but once `:make` is done you can move through errors an earnings encountered with `:cnext` and `:cprev`. Calling `:copen` will show you a... |
24,579 | <p>I've used two plugins with vim: <a href="https://github.com/scrooloose/nerdtree" rel="nofollow noreferrer">Nerdtree</a> and <a href="https://github.com/vim-scripts/taglist.vim" rel="nofollow noreferrer">Taglist</a>.</p>
<p><a href="https://i.stack.imgur.com/n6QT6.png" rel="nofollow noreferrer"><img src="https://i.s... | [
{
"answer_id": 24580,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 2,
"selected": false,
"text": "<p>I don’t use NERDTree myself, but reading the documentation it looks like you want the <code>s</code> map, which opens the sel... | 2020/04/14 | [
"https://vi.stackexchange.com/questions/24579",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10003/"
] | I've used two plugins with vim: [Nerdtree](https://github.com/scrooloose/nerdtree) and [Taglist](https://github.com/vim-scripts/taglist.vim).
[](https://i.stack.imgur.com/n6QT6.png)
However, if I quit the opened file and open another file in the Nerd... | Nerdtree is the beast on its own (don't like it personally but anyway)
You can try following snippet of code:
```
func! MyOpen() abort
let selected = g:NERDTreeFileNode.GetSelected()
if selected != {}
"remove everyother window
wincmd o
"open selected file in vertical split
exe... |
24,593 | <h2>The problem</h2>
<p>In shell scripting, conditionals and loops don't use curly braces to indicate blocks, but rather special keywords: <code>if [ ... ]; then</code> statements close with <code>fi</code>, <code>while [ ... ]; do</code> statements close with <code>done</code>, and <code>case</code> statements close ... | [
{
"answer_id": 24580,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 2,
"selected": false,
"text": "<p>I don’t use NERDTree myself, but reading the documentation it looks like you want the <code>s</code> map, which opens the sel... | 2020/04/15 | [
"https://vi.stackexchange.com/questions/24593",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/27539/"
] | The problem
-----------
In shell scripting, conditionals and loops don't use curly braces to indicate blocks, but rather special keywords: `if [ ... ]; then` statements close with `fi`, `while [ ... ]; do` statements close with `done`, and `case` statements close with `esac`.
Without mappings, the normal protocol to... | Nerdtree is the beast on its own (don't like it personally but anyway)
You can try following snippet of code:
```
func! MyOpen() abort
let selected = g:NERDTreeFileNode.GetSelected()
if selected != {}
"remove everyother window
wincmd o
"open selected file in vertical split
exe... |
24,597 | <p>I am using a macbook with touchbar. As many others I would like to map a different key to the esc key, since the touchbar esc is a bit inconvenient. My problem is that I have some weird behaviour of the §-key which I would like to use as alternative. I had to remove the </p>
<pre><code>map § <esc>
</code></pr... | [
{
"answer_id": 24606,
"author": "Mr.Sh4nnon",
"author_id": 28972,
"author_profile": "https://vi.stackexchange.com/users/28972",
"pm_score": 1,
"selected": false,
"text": "<p>So thanks to @filbranden I was able to find the source of the error. This plugin causes it: <a href=\"https://gith... | 2020/04/15 | [
"https://vi.stackexchange.com/questions/24597",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28972/"
] | I am using a macbook with touchbar. As many others I would like to map a different key to the esc key, since the touchbar esc is a bit inconvenient. My problem is that I have some weird behaviour of the §-key which I would like to use as alternative. I had to remove the
```
map § <esc>
```
since the §-key doesn't w... | TL;DR: To prevent conflicts with mapping the § key and the auto-pairs plug-in, add the following to your vimrc:
```
let g:AutoPairsMoveCharacter = '()[]{}"'
```
---
The root of the problem is that Vim sees the `§` key the same as it sees the combination `Alt`+`'`, or `Meta`+`'`.
The [§](https://en.m.wikipedia.org/... |
24,612 | <p>I recorded this macro to register <code>a</code> in Neovim by first pressing <code>qa</code>:</p>
<p><strong>Macro</strong></p>
<pre><code>--- Registers ---
"a f1F1i-^[la0^[j
</code></pre>
<p>Then I pressed <code>q</code> and my cursor was left in normal mode at the position marked by <code>|</code> (so that <c... | [
{
"answer_id": 24613,
"author": "sdp",
"author_id": 25618,
"author_profile": "https://vi.stackexchange.com/users/25618",
"pm_score": 3,
"selected": true,
"text": "<p>Macros abort when they fail at some point. In your example, <code>f1</code> fails since there is no <code>1</code> after t... | 2020/04/16 | [
"https://vi.stackexchange.com/questions/24612",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28990/"
] | I recorded this macro to register `a` in Neovim by first pressing `qa`:
**Macro**
```
--- Registers ---
"a f1F1i-^[la0^[j
```
Then I pressed `q` and my cursor was left in normal mode at the position marked by `|` (so that `m` is highlighted) in the below JavaScript snippet (on line `4`).
**JavaScript snippet**
... | Macros abort when they fail at some point. In your example, `f1` fails since there is no `1` after the cursor. To solve it, you can set `"a` to, say, `0f1i-^[la0^[j`. |
24,642 | <p>Is it possible to do this:</p>
<pre><code>function Foo(func_ref) abort
nnoremap <buffer> <cr> :find_a_way_to_call_func_ref
endfunction
function s:callback() abort
echo "123"
endfunction
command Test call Foo(function('s:callback'))
</code></pre>
<p>To be clear, <code>:h Funcref</code> is not <cod... | [
{
"answer_id": 24644,
"author": "Zorzi",
"author_id": 27331,
"author_profile": "https://vi.stackexchange.com/users/27331",
"pm_score": 0,
"selected": false,
"text": "<p>Sure, you want to use the <code>execute</code> command, which acts like an eval:</p>\n\n<pre><code>function Foo(func_re... | 2020/04/17 | [
"https://vi.stackexchange.com/questions/24642",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/5017/"
] | Is it possible to do this:
```
function Foo(func_ref) abort
nnoremap <buffer> <cr> :find_a_way_to_call_func_ref
endfunction
function s:callback() abort
echo "123"
endfunction
command Test call Foo(function('s:callback'))
```
To be clear, `:h Funcref` is not `String`, it's type is `v:t_func`. | It's really doable with `execute`... and `call()`
```
function Foo(func_ref) abort
execute printf('nnoremap <buffer><cr> :call call(%s, [])<CR>',
\ string(get(a:func_ref, 'name')))
endfunction
``` |
24,657 | <p>Here is a problem I am able to solve in Sublime in seconds but has me stumped in Vim:</p>
<p>Given text like this:</p>
<pre><code>bob@bobshop.com Bob Potato
peter@petershop.co.uk Peter Carrot
thomas.cucumber@thomasstore.org Thomas Cucumber
</code></pre>
<p>I would like to delete either all the names in one go, an... | [
{
"answer_id": 24658,
"author": "Maxim Kim",
"author_id": 9333,
"author_profile": "https://vi.stackexchange.com/users/9333",
"pm_score": 3,
"selected": true,
"text": "<p>To delete all emails first:</p>\n\n<p><code>vip:norm! dW</code></p>\n\n<ul>\n<li><code>vip</code> select paragraph</li... | 2020/04/17 | [
"https://vi.stackexchange.com/questions/24657",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/24880/"
] | Here is a problem I am able to solve in Sublime in seconds but has me stumped in Vim:
Given text like this:
```
bob@bobshop.com Bob Potato
peter@petershop.co.uk Peter Carrot
thomas.cucumber@thomasstore.org Thomas Cucumber
```
I would like to delete either all the names in one go, and then the email addresses, or al... | To delete all emails first:
`vip:norm! dW`
* `vip` select paragraph
* `:norm! dW` execute normal mode commands: delete WORD
Then you end up having only names -- delete them as usual I guess?
To delete all names first:
`vip:norm! WD`
* `vip` select paragraph
* `:norm! WD` execute normal mode commands: move cursor ... |
24,670 | <p>I want to run <a href="https://stackoverflow.com/questions/7588531/vim-set-color-theme-based-off-time-of-day">https://stackoverflow.com/questions/7588531/vim-set-color-theme-based-off-time-of-day</a></p>
<p>So something like:</p>
<pre><code>if strftime("%H") < 12
set background=light
else
set background=dar... | [
{
"answer_id": 24671,
"author": "Chris Stryczynski",
"author_id": 13656,
"author_profile": "https://vi.stackexchange.com/users/13656",
"pm_score": 2,
"selected": false,
"text": "<p>As a workaround one can instead target the common <code>FocusLost</code> / <code>FocusGained</code> events.... | 2020/04/18 | [
"https://vi.stackexchange.com/questions/24670",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/13656/"
] | I want to run <https://stackoverflow.com/questions/7588531/vim-set-color-theme-based-off-time-of-day>
So something like:
```
if strftime("%H") < 12
set background=light
else
set background=dark
endif
```
But for this to be invoked every hour, rather than only once when opening vim. Does vim or neovim support ru... | You can use [`timer_start()`](https://vimhelp.org/eval.txt.html#timer_start%28%29) to set "timers" to run a function every *n* milliseconds. For example:
```
fun! s:set_bg(timer_id)
let &background = (strftime('%H') < 12 ? 'light' : 'dark')
endfun
call timer_start(1000 * 60, function('s:set_bg'), {'repeat': -1})
c... |
24,678 | <p>I'm trying to set up MathJax to work with vimwiki. According to the manual:</p>
<blockquote>
<ol>
<li>using the MathJax server for rendering (needs an internet connection). Add to your HTML template the following line:</li>
</ol>
</blockquote>
<pre><code><script type="text/javascript" src="http://cdn.math... | [
{
"answer_id": 28589,
"author": "IvRyN",
"author_id": 32840,
"author_profile": "https://vi.stackexchange.com/users/32840",
"pm_score": 1,
"selected": false,
"text": "<p>Vimwiki uses "$" and "$" as a delimiter not "\\(" and "\\)".</p>\n<p>also inclu... | 2020/04/18 | [
"https://vi.stackexchange.com/questions/24678",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/20443/"
] | I'm trying to set up MathJax to work with vimwiki. According to the manual:
>
> 1. using the MathJax server for rendering (needs an internet connection). Add to your HTML template the following line:
>
>
>
```
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_... | Vimwiki uses "$" and "$" as a delimiter not "\(" and "\)".
also include this in your tag, so that MathJax doesn't prompt an error.
```
<script type="text/javascript">
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
},
svg: {
fontCa... |
24,681 | <p>I apologise if this was asked before, but I couldn't find anything similar.</p>
<p>I am trying to write a simple command to jump to a test file, using the current file name. I have managed to achieve this using:</p>
<pre><code>command Spec :find %:r.spec.js
</code></pre>
<p>If my current buffer name is <code>foo.... | [
{
"answer_id": 24682,
"author": "Mass",
"author_id": 13728,
"author_profile": "https://vi.stackexchange.com/users/13728",
"pm_score": 3,
"selected": true,
"text": "<p>In vim globs (like those used in find), alternation between two words can be done using the <code>{a,b}</code> syntax. T... | 2020/04/18 | [
"https://vi.stackexchange.com/questions/24681",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/28745/"
] | I apologise if this was asked before, but I couldn't find anything similar.
I am trying to write a simple command to jump to a test file, using the current file name. I have managed to achieve this using:
```
command Spec :find %:r.spec.js
```
If my current buffer name is `foo.js` this will try to jump to `foo.spec... | In vim globs (like those used in find), alternation between two words can be done using the `{a,b}` syntax. This will work interactively, presenting a wildmenu, if you press tab.
```
:find %:r.{spec,test}.js<TAB>
```
Unfortunately, it won't work from a "Spec" command wrapper, since `:find` does not tolerate multiple... |
24,683 | <p>Is there a way to enable autocomplete for writing in English? For example, if I write <code>giv</code>, I want Vim to automatically suggest <code>give</code>, <code>given</code>, <code>gives</code>, <code>giving</code>, <code>giveaway</code>, etc.</p>
<p>In Emacs, this is easy to enable when using the company-mode ... | [
{
"answer_id": 24684,
"author": "filbranden",
"author_id": 18609,
"author_profile": "https://vi.stackexchange.com/users/18609",
"pm_score": 2,
"selected": false,
"text": "<p>Yes, you can use the <kbd>Ctrl</kbd>+<kbd>X</kbd>, <kbd>Ctrl</kbd>+<kbd>K</kbd> sequence to initiate completion fr... | 2020/04/19 | [
"https://vi.stackexchange.com/questions/24683",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/19712/"
] | Is there a way to enable autocomplete for writing in English? For example, if I write `giv`, I want Vim to automatically suggest `give`, `given`, `gives`, `giving`, `giveaway`, etc.
In Emacs, this is easy to enable when using the company-mode package ([source](https://emacs.stackexchange.com/questions/18304/optimal-se... | Yes, you can use the `Ctrl`+`X`, `Ctrl`+`K` sequence to initiate completion from keywords in a dictionary. See [`:help i_CTRL-X_CTRL-K`](https://vimhelp.org/insert.txt.html#i_CTRL-X_CTRL-K) for an entry point to configuring and using this feature.
Perhaps the best way to enable this feature is to [enable spell checkin... |
24,723 | <p>Say I have the text:</p>
<pre><code>This is a test!
</code></pre>
<p>If my cursor is on the first character, "T", and then I do <code>d4w</code>, then I am left with just <code>!</code>. However, if instead I do <code>v4wd</code> then I'm left with nothing (i.e. the entire string was selected and deleted).</p>
<p... | [
{
"answer_id": 24724,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 0,
"selected": false,
"text": "<p>It's not a special case, the examples are different. In the first one you say \"delete 4 words\", in the second you say \"mov... | 2020/04/21 | [
"https://vi.stackexchange.com/questions/24723",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/29040/"
] | Say I have the text:
```
This is a test!
```
If my cursor is on the first character, "T", and then I do `d4w`, then I am left with just `!`. However, if instead I do `v4wd` then I'm left with nothing (i.e. the entire string was selected and deleted).
Why is this the case? I saw there are some [special cases](https:... | In Vim motions can be either inclusive ("include the rightmost character"), or exclusive ("exclude rightmost character"). `w` is made exclusive (so you delete exactly four words: "this" "is" "a" "test"). If you want to make it inclusive add `:h o_v` to the target command: `d4vw`.
Now, in Visual mode all motions are go... |
24,726 | <p>I'm using vim to code and I <code>set autoindent</code> in my <code>~/.vimrc</code>.</p>
<p>Now, if I code as below:</p>
<pre><code>if (a == 1)
{| // the cursor is here and I type ENTER
}
</code></pre>
<p>After typing the ENTER, the code becomes as below:</p>
<pre><code>if (a == 1)
{
| // Now the cur... | [
{
"answer_id": 24724,
"author": "Tae",
"author_id": 786,
"author_profile": "https://vi.stackexchange.com/users/786",
"pm_score": 0,
"selected": false,
"text": "<p>It's not a special case, the examples are different. In the first one you say \"delete 4 words\", in the second you say \"mov... | 2020/04/21 | [
"https://vi.stackexchange.com/questions/24726",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10003/"
] | I'm using vim to code and I `set autoindent` in my `~/.vimrc`.
Now, if I code as below:
```
if (a == 1)
{| // the cursor is here and I type ENTER
}
```
After typing the ENTER, the code becomes as below:
```
if (a == 1)
{
| // Now the cursor is here, it indented automatically
}
```
It works as expecte... | In Vim motions can be either inclusive ("include the rightmost character"), or exclusive ("exclude rightmost character"). `w` is made exclusive (so you delete exactly four words: "this" "is" "a" "test"). If you want to make it inclusive add `:h o_v` to the target command: `d4vw`.
Now, in Visual mode all motions are go... |
24,748 | <p>Say I have a session like this:</p>
<pre><code>Sunday|Monday
</code></pre>
<p>Where <code>|</code> is the cursor in insert mode. If I press <code>Esc</code>, I get this:</p>
<pre><code>Sunda█Monday
</code></pre>
<p>but I want this:</p>
<pre><code>Sunday█onday
</code></pre>
<p>As I want to select the second "wo... | [
{
"answer_id": 24749,
"author": "Christian Brabandt",
"author_id": 71,
"author_profile": "https://vi.stackexchange.com/users/71",
"pm_score": 2,
"selected": false,
"text": "<p>This is regular vi compatible behaviour. After pressing <kbd>Esc</kbd> the cursor is always moved one character ... | 2020/04/22 | [
"https://vi.stackexchange.com/questions/24748",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/7184/"
] | Say I have a session like this:
```
Sunday|Monday
```
Where `|` is the cursor in insert mode. If I press `Esc`, I get this:
```
Sunda█Monday
```
but I want this:
```
Sunday█onday
```
As I want to select the second "word", and if I go into visual mode, the `y`
will be part of the selection. I found that I can u... | You can press `Ctrl-O``Ctrl-C`. Control-C effectively cancels any pending mode and takes you into Normal in the current cursor position. Of course, you can create some mapping if you want.
To make things working also for the last character on line, make sure you have `:set ve=all` or `:set ve=onemore` in your vimrc. O... |
24,753 | <p>I want to code a vim function, which searches backwards a specific char from the cursor at the current line.</p>
<p>Here is what I've done:</p>
<pre><code>function! CustomSearch()
let currentLine = getline(".")
" how to loop backwards `currentLine`?
" something like this:
" for (int i = currentLin... | [
{
"answer_id": 24761,
"author": "Zorzi",
"author_id": 27331,
"author_profile": "https://vi.stackexchange.com/users/27331",
"pm_score": 3,
"selected": true,
"text": "<p>Here's what you're looking for:</p>\n<pre><code>function! CustomSearch()\n let currentLine = getline(".")\n... | 2020/04/22 | [
"https://vi.stackexchange.com/questions/24753",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/10003/"
] | I want to code a vim function, which searches backwards a specific char from the cursor at the current line.
Here is what I've done:
```
function! CustomSearch()
let currentLine = getline(".")
" how to loop backwards `currentLine`?
" something like this:
" for (int i = currentLine.size() - 1; i >= 0;... | Here's what you're looking for:
```
function! CustomSearch()
let currentLine = getline(".")
let col = col('.')
while col > 0
let col -= 1
if currentLine[col] == 'a'
echo 'found a!'
break
endif
endwhile
endfunction
inoremap <C-v><C-b> <C-o>:call CustomSe... |
24,755 | <h1>tldr</h1>
<p>Moving in ex command line is slow because common readline motions (like in bash) are not supported. Are there any improvements for this?</p>
<hr>
<p>I often find myself with an ex command in the command line and the need to e.g. edit something at the very beginning. For instance, I may have entered ... | [
{
"answer_id": 24756,
"author": "oarfish",
"author_id": 1066,
"author_profile": "https://vi.stackexchange.com/users/1066",
"pm_score": 4,
"selected": true,
"text": "<p>I have found two workarounds:</p>\n\n<ol>\n<li><a href=\"https://github.com/ryvnf/readline.vim\" rel=\"noreferrer\">This... | 2020/04/22 | [
"https://vi.stackexchange.com/questions/24755",
"https://vi.stackexchange.com",
"https://vi.stackexchange.com/users/1066/"
] | tldr
====
Moving in ex command line is slow because common readline motions (like in bash) are not supported. Are there any improvements for this?
---
I often find myself with an ex command in the command line and the need to e.g. edit something at the very beginning. For instance, I may have entered ex mode and pre... | I have found two workarounds:
1. [This plugin](https://github.com/ryvnf/readline.vim) adds some readline motions to command mode
2. As outlined [here](https://stackoverflow.com/a/7189573/2397253), one can press Ctrl-f in command mode to make the current command editable like in normal mode. This is incompatible with t... |