Hot answers tagged

24

As of Vim 8.0.1554 (unfortunately not Neovim yet), you can use vim --clean. This method is recommended by :help bugs. :help --clean docs: Similar to "-u DEFAULTS -U NONE -i NONE": - initializations from files and environment variables is skipped - 'runtimepath' and 'packpath' are set to exclude home directory ...


17

If you just want to see what's consuming start up time, then you can use the --startuptime option. vim --startuptime timing.out The file will look like this: times in msec clock self+sourced self: sourced script clock elapsed: other lines 000.000 000.000: --- VIM STARTING --- 000.000 000.000: Allocated generic buffers 000.000 000....


17

Can somebody tell me how to avoid the very annoying vim's slowdown? Hopefully in a user friendly non-geeky way? I run Vim on a company-provided 2013 15" Retina MacBook with a 2.3 GHz i7 processor, 16 GB of RAM, and a measly GTĀ 750M with 2 GB dedicated memory. That machine is very far from a "gaming PC" and I've never experienced any slow down. Ever. Even on ...


14

Vim sends during startup some special terminal codes (that usually contain the <esc> key) to determine several things (colors, bs,...) If you mapped <esc> this will most likely confuse the parser of the return codes and weird things can happen. Therefore, use your above map only after everything has been setup correctly (e.g. via a VimEnter ...


12

The Linux terminal uses ANSI escape sequences (i.e. strings of characters starting with <Esc>) to send special keys to Vim, and as part of the communication protocol with which the application queries for its capabilities. Your mapping interferes with that, and thereby leads to these "strange" behaviors. Therefore, don't map <Esc>. Use another ...


11

One way to eliminate user-specific files would be to use a different value of $HOME. To allow nothing to be read, or written to (such as viminfo), you could use /dev/null: HOME=/dev/null vim -u NONE This will cause errors about viminfo, so, instead you could create a temporary folder, or use an existing one (like /tmp): HOME=$(mktemp -d) vim -u NONE With ...


11

In my opinion, the cleanest method of doing this is simply to add the command to a file in your .vim/vimfiles directory: ~/.vim/after/ftplugin/python.vim or for Windows: $HOME\vimfiles\after\ftplugin\python.vim This technique is documented in :help ftplugin-overrule (list item 3), although the context (changing settings) is slightly different. It offers ...


10

Try putting this at the end of your .vimrc (modify as appropriate) if @% == "" && getcwd() == "/tmp" :silent edit test.sh endif This checks if the current filename is empty (@% references the current filename), and checks if vim's current directory is /tmp. You could add other directories as well like so (getcwd() == "/tmp" || getcwd() == "~/...


10

Well, a bit belated but to respond to: Some magic (from a comment by Carpetsmoker in this thread) My general idea was that you always want to start "private mode" if you're using an encrypted file, so this autocommand will do that for you: au BufRead * if &key!= "" \ | setlocal history=0 nobackup nomodeline noshelltemp noswapfile ...


9

Reading system-level configuration before user-level configuration is totally normal and expected in UNIX land. Anyway, this sentence: The files are searched in the order specified above and only the first one that is found is read. only applies to "personal initializations". As explained a few paragraphs below, the system vimrc is read no matter what: ...


9

Change the call pathogen#runtime_append_all_bundles() line in your vimrc to call pathogen#infect(), as the message suggests.


8

Turns out the answer was in the error message all along.. the offending file was ~/.viminfo which was somehow corrupted.


8

Add in your .vimrc: au BufEnter *.py :TagbarToggle<CR> where au is autocmd, execute the command automatically. BufEnter is when you enter the file for first time. *.py is for filetype python. and the rest is the command to be executed


8

Vim has a startup option -q to read a quickfix file. So we have options (depending on your shell): cmd > results vim -q results Or my favorite vim -q <(cmd)


7

-c doesn't execute keybinds in normal mode; it executes commands (what you normally do with :). So you need to use the execute command, which seems to work: $ vim -c 'execute "normal \\t"' We need the double \\ because we're issuing a shell command (and don't want the shell to interpret this as an escape sequence). Tested with the keybind: nnoremap <...


7

In recent vim versions, you can use timer_start to delay an operation. For example, to execute winpos 200 milliseconds after vim starts, autocmd VimEnter * call timer_start(200, { tid -> execute('winpos 100 50')})


6

Although, i haven't found out what exactly was the problem or how i could solve it in the expected way (just placing colorscheme babymate256 in my config as everyone else does) => i now use just autocmd VimEnter * colorscheme babymate256 (which is not as fine as without an autocmd, but it doesn't disorganize up my config structure.) Btw: Additionally, i ...


6

You can capture a full log of a Vim session with gvim -V20vimlog. After quitting Vim, examine the vimlog log file for suspect commands. Also, it may be something in your configuration, so try launching with gvim -N -u NONE (which ignores plugins and your .vimrc).


6

To start vim automatically in hex mode when editing a.out, put an autocommand like this one in your ~/.vimrc: au BufReadPost a.out silent %!xxd A more complete explanation with examples can be found at: :help using-xxd To use key mapping instead, mapping , for example, use this: map <F3> :%!xxd<CR>


5

Here's the code that I extracted from vim-startify; the key parts are creating a new buffer on the VimEnter autocmd, putting some text in that, and then mapping the i to start a new buffer and then go to insert mode. I put the below in a little plugin which adds some settings and such, but the basic concept is exactly the same. fun! Start() " Don't run ...


5

Actually the answer is in startify. In startify.vim around line 15 we can see autocmd VimEnter * nested \ if !argc() && (line2byte('$') == -1) && (v:progname =~? '^[-gmnq]\=vim\=x\=\%[\.exe]$') \ | if get(g:, 'startify_session_autoload') && filereadable('Session.vim') \ | source Session.vim \ | else \ | call startify#...


5

A modification of John's answer may be useful: if @% == "" && getcwd() == "/tmp" :silent edit `=glob("test\.*", 1, 1)[0]` endif That opens the first file which begins with test.. Instead of just the first file, if you wanted to open other matching files as well, do: if @% == "" && getcwd() == "/tmp" for i in glob("test\.*", 1, 1) ...


5

You could make a function that creates the new entry, and then use the function as part of your mapping: nnoremap <leader>t :call NewEntry()<cr> function! NewEntry() let title = expand('~/Notes/') . strftime('%F') . '-' . input("Title: ") execute 'edit ' . title endfunction The mapping may be called as described by @Carpetsmoker: vim -c '...


5

Since vipe, git commit (and many other programs which invoke an editor) use the VISUAL and EDITOR variables (unless you specify an editor for git with git config core.editor), you can use that variable to invoke Vim in such a way that you can detect it: export EDITOR='env called=1 vim' Then, in Vim, $called will have a value of 1, which you can use to ...


4

You can debug startup time by using the built in Vim profiler (tutorial) If your version of vim is compiled with :profile you can run: vim --cmd 'profile start vimrc.profile' --cmd 'profile! file ~/.vimrc' If not, your stuck debugging it manually by adding and removing plugins and seeing where the long startup times are coming from. I personally don't ...


4

This seems to be an old but known problem on OS X. This issue has a patch, which is unfortunately not yet incorporated. You can apply it manually to fix your nvi build.


4

TL;DR: skip to the Resolution section. Background The issue is that neovim can't read/write vim's viminfo file format. Instead of using vim'sviminfo format for storing editing session information, neovim uses a shada-file for "SHAred DAta". The default shada file name is $XDG_DATA_HOME/nvim/shada/main.shada, and $XDG_DATA_HOME is ~/.local/share by XDG ...


4

I don't know how reliable it is but I found how to get the PID of the parent of a process here: ps -o ppid= -p <pid of the process> And how to get the name of a process from its PID here: ps -p 1337 -o comm= One can get the pid of the Vim's process with the getpid() function, so combining the previous 2 commands, maybe this expression could get the ...


4

One workaround would be to use :argdo (which runs an ex command in each file in the argument list): vim +"argdo norm G" file1 file2 vim +"argdo /searchPattern" file1 file2 You will be left in the final file, so you'll need to manually invoke :first to return to the beginning of the arglist, or add this as another command-line argument: vim +"argdo norm G" ...


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