Hot answers tagged

4

Well, actually it works, but probably not the way you think. Autocommands are invoked in sequence. It's BufNewFile and/or BufRead that are used by ftplugin to set filetype which results in FileType autocommand which, in turn, does source all your stuff. So you've already missed BufNewFile for that particualr buffer. Nonetheless, autocmd without <buffer&...


3

It's not possible to achieve this with regular mappings of K and KK. If the K mapping fires then Vim is necessarily no longer waiting to see if KK is typed, and there are no configuration options that can change this behaviour. There are ways to workaround this, however. filbranden suggested one possible method in the comments which D. Ben Knoble has ...


3

You can use a BufWinEnter event instead. That's a late event, which should happen after all the filetype detection and setup is finished. au BufWinEnter * set formatoptions-=o The docs in :help BufRead suggest possibly using this event: See BufWinEnter for when you need to do something after processing the modelines. While your case is not directly ...


3

A general recommendation when debugging an issue is to start with -u NONE, which skips all initialization. If you just want to start vim without plugins and with a custom .vimrc file start vim with the following command: vim --noplugin -u <test_vimrc_file> <your_file_name> then issue the command :packadd <package_name> to load the plugin ...


3

You can check if your vim runs in gui: if has("gui_running") colo koehler else colo darkblue endif You can also use gvimrc file (:h gvimrc) instead. The drawback is that you would have colorscheme run twice (one in vimrc, another in gvimrc) for gVim unless you guard it in vimrc, again, with has("gui_running"): vimrc if !has("gui_running") ...


2

I had another binding that <leader>h was a prefix and I had forgotten about; it was <leader>html. Removing it solved the problem.


2

I figured this out, and decided to just remove the mapping. It's happening because (at least in my environment, using vim in a terminal over SSH) there's no distinction between <C-m> and <CR>, they're one and the same to vim. If I remap <C-m> in normal mode, I'm also remapping <CR> in normal mode. I don't tend to press enter in ...


2

Setting wildignore can have quite a few side effects (especially if done globally). So I would do: let s:prefix = '/path/to/folder' let files = filter(glob(prefix . '/**/*.bak', 1, 1), "fnamemodify(v:val, ':e') != 'bak'") for fname in files execute 'source' fname endfor


2

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 specifies the path to a custom vimrc, while the -N argument resets '...


2

It seems you've already found a working solution, but I wanted to address the issues with your attempted approaches. But when I press /, instead of running the function and then starting the search prompt, I get this text inserted to my buffer: rm! / You're getting this result because you're using <BAR> in your mapping after you already left ...


2

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 that one. If you only have a single ...


2

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 augroup END nnoremap K :call KFunc()<CR&...


1

This looks as expected. Airline is a statusline plugin (read :help statusline). To set the editor's colorscheme, use :colorscheme [name].


1

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


1

You can only 'source' a file at a time. Therefore, build the list of files first, and then source them one by one. set wildignore=*.bak let s:prefix = '/path/to/folder' for s:fname in glob(s:prefix . '/**', 0, 1) execute 'source' s:fname endfor However, normally you should only source *.vim files, so then it becomes let s:prefix = '/path/to/folder' ...


1

The sentence Set 'verbose' to get a message about that when opening a file. Refers to the option verbose—you can tell because it's enclosed in single-quotes, and if you place your cursor on it and press Ctrl-], you jump to the same section as :help 'verbose' would. It's not clear what level of verbosity you would need, but try set verbose=1 and then ...


1

Starting from Patch 7.4.1384 Vim has 'packpath' option for searching plugins. By default 'packpath' is equal to 'runtimepath' (until 'runtimepath' finally gets inflated by the plugins loaded), so you must keep them sync in your vimrc. For Vim 8, I'm calling it like this: /usr/local/bin/vim8 -u "${HOME}/.vim8/vimrc". You can add the following lines on top ...


1

I couldn't resist golfing this one, and came up with the following: 3itable[row][col]<Esc>i+1<Esc>F].;a, other_<Esc>3;a = std::max(<Esc>A)<Esc> This works by inserting three copies of table[row][col] by using a [count] with the i command and then jumping backwards to fill in the missing parts of the statement —&#...


1

You can get a workflow that's close to what you want without configuring vim at all. You can jump to the nth buffer using <C-^> (ctrl + 6). If you type a digit while viewing the output of ls, then that digit is stored and can be passed to the next command. In order to produce the fake vim screenshots, I increased the font size so I can only see a ...


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