Hot answers tagged

4

First off, you can use :split (or just :sp) instead of typing :e and then manually splitting. Using the % register You could do: :split <press ctrl+r, then type a % sign> This will paste from register % onto the command line. And since % contains the path to the current file, you'll get this: :split /path/to/current/file/handler.test.ts and you can ...


3

If you have the /full/path/to/handler.ts file opened in one window, you can open a new window and then type the following command to open handler.test.ts from the /full/path/to directory: :e #:h/handler.test.ts


2

Also worth a mention is autochdir: When on, Vim will change the current working directory whenever you open a file, switch buffers, delete a buffer or open/close a window. It will change to the directory containing the file which was opened or selected. Note: When this option is on some plugins may not work. So all you would have to do is to type :sp file.


2

There are a number of ways to go about this, depending on what you actually want. You can use wildcards, as mattb has already mentioned. If, however, these either cause ambiguities or you just don't want to type out the directory structure as wildcards, there's alternatives. If you're only looking to open files, I highly recommend a fuzzy finder. There's a ...


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 ...


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.


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 ...


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! ...


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

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 ...


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

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 ...


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 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:...


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 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-...


Only top voted, non community-wiki answers of a minimum length are eligible