New answers tagged

0

you can use this function function! Quitwindows() let s:total_nr_buffers = len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) if s:total_nr_buffers == 1 "bufname(0) == '' " bufexists(0) && exit echo "vide" else bw endif endfunction nnoremap <silent> <Space>q :call ...


0

In the end I wrote a function that wipes out all buffers whose type is help, which is executed by the VimLeavePre event, i.e. right before the ShaDa file is written


0

I've found a workaround this. Things I tried: Disabled all plugins for vim, this seemed to help for a bit but after a few presses of ctrl+w it went back to freezing up my iTerm2 Used vim outside of tmux, issue still occurred. Disabled the ctrl+w keymap in iTerm2, this was unfeasible as I need to move between panes in vim. My current workaround is to ...


1

Although this question raises some as yet unanswered questions about how to best handle doing long-running stuff in the traditional :python style plugin, it seems mostly moot now that I've spent some time understanding the new style remote plugin system. nvim-example-python-plugin was helpful (though slightly outdated), so I'd recommend anyone else finding ...


1

You can save and restore the current tab around the :tabdo operation. You can use tabpagenr() to get the position of the current tab and later you can pass that number to :tabnext to change back to this tab. This is better done in a function, since you can easily run multiple commands and also use a local variable to store the current tab number. function! ...


0

There is no way to do that. Indeed, using an external tool to format the message is the way to go. The tool can be simple, sed is more than enough. Another option is including the whole line in the message by ab-using %+ operator, like: let &errorformat='%+G%\d%\+/%\d%\+ Test #%l: %f %[.*]%#Failed %m' will result in: testname|1 error| 1/1 Test #1: ...


1

A simple way to do it is like this: local n_keymap = function(lhs, rhs) vim.api.nvim_set_keymap('n', lhs, rhs, { noremap = true, silent = true }) end n_keymap('foo','bar') But in my opinion that doesn't make any sense because the map function are quite powerful (they support different modes, recursive or not, silent or not, expression mappings, buffer ...


1

As explained here, among other places (better references welcome), NeoVim's ! is implemented using a subprocess with no interactive TTY attached. Use :terminal to run interactive commands inside NeoVim. Change your mappings to nnoremap <f4> :terminal node %<CR> nnoremap <f9> :terminal g++ -std=c++17 % -Wall -g -o %.out && ./%.out<...


1

To make something work in visual mode, you need a visual-mode mapping (usually :x[nore]map). In this case, we need to do these steps Save the register Restore the selection and do the cut (x or d or whatever) Restore the register if whitespace This is reminiscent of your original function, so let's modify it to take a visual arg: if truthy, do gv before ...


2

The vim.current.buffer list is a list of strings: :pyx import vim; print(type(vim.current.buffer[0])) <class 'str'> and strings are immutable in Python; something like a_str[2] = 'b' doesn't work either. This is just a property of the Python programming language (and many other languages, including VimScript). The general way to do this is to get the ...


0

The file that is associated with the currently executing autocommand can be retrieved with this function call: expand('<afile>') Somewhat contrived but easy to understand test... augroup AfileTest autocmd! autocmd BufWritePost * echom "I saved file " . expand('<afile>') augroup END After loading this and running :w the message ...


1

Simply because a line break in the replacement component of the substitution command is represented by \r in Vim rather than \n... :s/,/\r/gc Alernatively, you can use this: :s/,/^M/gc Where the ^M is entered by typing Ctrl+V then Enter See :h s/\r and :h s/<CR> FYI using \n will... insert a <NL> (<NUL> in the file) (does NOT break the ...


1

The 'listchars' option is implemented as a Lua table (akin to a Dict in Vim, possibly more similar to an object in JavaScript), so what you need to only change the extends setting is: vim.opt.listchars.extends = "#" Or, also valid: vim.opt.listchars["extends"] = "#"


1

I recommend neovim-qt (GitHub - equalsraf/neovim-qt). It is plain vanilla, cross-platform, stable, actively developed, and fast enough. To install on Mac using Homebrew: brew tap equalsraf/homebrew-neovim-qt brew install neovim-qt To install on Debian/Ubuntu: sudo apt-get install neovim-qt Neovim-qt is included in Window's port of Neovim (by running nvim-...


1

The expected behavior of dj in Vim is to delete the current and the next line. The behavior you observe in your IDE is equivalent to dvj, as described by :h forced-motion: Example: dj deletes two lines dvj deletes from the cursor position until the character below the cursor. So if the behavior is different in the IDE it's because either they modified the ...


2

For example, a conditional abbreviation on :v so that :v expands to :e , and (almost) anything else leaves the v: cnoreabbrev <expr> v getcmdtype() is# ':' && getcmdline() is# 'v' ? 'e' : 'v' Substitute e with edit for readability, or vi or split or whatever you prefer.


1

After experimenting for a while I found out that it works fine on NeoVim when I use :terminal bash % or :terminal node % instead. The way it works on NeoVim differs from the way that :%terminal bash works on Vim though, it doesn't show any status if the code is still running or not, and after the file is executed it's necessary to go back to the text that ...


1

I guess I will attempt to answer my own question ... because I think I got an fairly nice looking solution with the first line of the fold text on the left and the line stats (number of lines & character count) aligned to the right of the window. I skipped doing words because maybe that is less useful (but then again maybe not?) Turns out there are some ...


1

I think you need to change " Comment the line execute 'silent s/\v^(\s*)/\1' . comment_leader . ' /' to " Comment the line execute 'silent s/^/\1' . comment_leader . '/' so that it substitutes at the beginning of the line rather than after any space. The uncomment pattern needs similar modifications:...


2

$MYVIMRC is an environment variable that Vim adds to the current environment. Environment variables are usually inherited by child processes from their parent process. For example, you can see $MYVIMRC in a shell that is a child process of Vim: :!printenv | grep MYVIMRC (I use this form rather than just :!echo "$MYVIMRC" to "prove" that ...


Top 50 recent answers are included