Can vim monitor realtime changes to a file

You can :set autoread so that vim reads the file when it changes. However (depending on your platform), you have to give it focus. From the help: When a file has been detected to have been changed outside of Vim and it has not been changed inside of Vim, automatically read it again. When the … Read more

Saving vim macros

Use q followed by a letter to record a macro. This just goes into one of the copy/paste registers so you can paste it as normal with the “xp or “xP commands in normal mode, where x is the register to paste. To save it you open up .vimrc and paste the contents, then the … Read more

A more useful statusline in vim? [closed]

Edit:- Note vim-airline is gaining some traction as the new vimscript option as powerline has gone python. Seems powerline is where it is at these days:- Normal status line Customised status lines for other plugins (e.g. ctrlp)

What is in your .vimrc? [closed]

You asked for it 🙂 “{{{Auto Commands ” Automatically cd into the directory that the file is in autocmd BufEnter * execute “chdir “.escape(expand(“%:p:h”), ‘ ‘) ” Remove any trailing whitespace that is in the file autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif ” Restore cursor position to where it was … Read more

How to create an alias for a command in Vim?

To leave completion untouched, try using cnoreabbrev W w It will replace W in command line with w, but only if it is neither followed nor preceded by word character, so :W<CR> will be replaced with :w<CR>, but :Write won’t. (Note that this affects any commands that match, including ones that you might not expect. For example, … Read more

Move entire line up and down in Vim

If I want to swap one line with the line above I usually do the following ddkP Explanation dd will delete the line and add it to the default register. k will move up a line (j would move down a line) P will paste above the current line

Why ci” and ci(, ci{…. behave differently?

ci( is consistent with ci[, ci{ and cit and all the other <action>i<something>. Only ci’ and ci” work like they do. The outliers are the quotes, here, not the brackets. Vim doesn’t consider that quotes come in pairs while brackets do. It has an internal logic for matching pairs that works with actual pairs but … Read more

How to map Shift-Enter

I managed to correct my terminal key-code for Shift+Enter by sending the key-code Vim apparently expects. Depending on your terminal, (Adding Ctrl+Enter as a bonus!) iTerm2 For a single Profile open Preferences → Profiles → Keys → [+] (Add) For all profiles open Preferences → Keys → [+] (Add) Keyboard shortcut: (Hit Shift+Enter) Action: Send … Read more

How to get visually selected text in VimScript

I came here asking the same question as the topic starter and tried the code by Luc Hermitte but it didn’t work for me (when the visual selection is still in effect while my code is executed) so I wrote the function below, which seems to work okay: function! s:get_visual_selection() let [line_start, column_start] = getpos(“‘<“)[1:2] … Read more