We’re rewarding the question askers & reputations are being recalculated! Read more.
86

The `. command will bring you to your last change. The ` goes to a mark, and . is a "special" mark which is automatically set to the position where the last change was made. See :help `. for some more information. There is also `` which will bring you back to where the cursor was before you made your last jump. See :help `` for more information. Another ...


41

Note: I'm assuming you're using the a register for the entirety of this answer, but you can use any register Note2: <1b> is Esc; you can insert this with Ctrl+v and then Esc. It may also show up as ^[ (depending on the display setting). It's not a mapping; so it makes sense that :map doesn't work. It's recorded in a register, and you can see & ...


21

Here's another approach that fits your given scenario, and will jump to where you were immediately prior to the gg (not to the last changed line). Use CtrlO When you press gg, your old cursor position is pushed onto the jump list. From :help jumplist: Jumps are remembered in a jump list. With the CTRL-O and CTRL-I command you can go to cursor ...


20

Following the link from @WChargin a bit further, I found this: You can start vim with the -w or -W option as follows: vim -w keys.txt my_file All the characters that you type are recorded in the file {scriptout}, until you exit Vim. -w will append to the specified file if it exists; -W will overwrite it. It doesn't quite get you what you want, but it'...


19

You are looking for the definition of undo-blocks. From :h undo-blocks: One undo command normally undoes a typed command, no matter how many changes that command makes. This sequence of undo-able changes forms an undo block. Thus if the typed key(s) call a function, all the commands in the function are undone together. The same block is used for ...


19

To add to dnetserr's answer and Peter Rincker's comment, Vim maintains a list of changes, and has some commands associated with this. :changes will list the changes, showing you where they were and what they were. For example: change line col text 2 8 17 #include <stdio.h> 1 3 0 #include "stm32f407.auto.h" > The line with ...


15

g; will go to the previously edited line.


13

The command history is stored in the viminfo file (:help viminfo). Usually that is read on startup and written on exit, but you could explicitly persist and sync between Vim instances with a combination of :wviminfo and :rviminfo. Note that this will sync the entire information; i.e. also register contents, marks, buffer lists, etc.


11

A : value in your 'viminfo' option may limit the number of persisted commands. See :help viminfo-:: : Maximum number of items in the command-line history to be saved. When not included, the value of 'history' is used.


10

You can use the :browse command for that: :browse oldfiles For a keystroke, map it: nnoremap <Leader>o :browse oldfiles<cr> Then you can press Leader o in normal mode to view a list of files. From :help v:oldfiles: v:oldfiles oldfiles-variable v:oldfiles List of file names that is loaded from the ...


9

No, it is not possible. According to :help 'history' you can have 10 thousand entries: 'history' 'hi' number (Vim default: 50, Vi default: 0) global {not in Vi} A history of ":" commands, and a history of previous search patterns is remembered. This option decides how many entries may be stored in each of these ...


9

The answer to your title question is what you observed. From the vim user manual :help 21.3 When you run Vim multiple times, the last one exiting will store its information. This may cause information that previously exiting Vims stored to be lost. Each item can be remembered only once. However, the filename of the viminfo file (where the command ...


9

To get something to work with... qajjjq Will start record a macro into the a register. You can see many of your current registers (used for macros, yanking, deleting, etc.) with the :reg command, or you can specify a register to display by providing its name. For example, to show register a: :reg a yields --- Registers --- "a jjj You can append to ...


8

I couldn't find any way to do this in a regular Vim. However, if you are willing to patch Vim, the following may work for you. The very simple patch (applied against Vim-7.4.052) disables the actual update to the screen that clears the history at the end of a normal command. It does this by returning whether or not showcmd_is_clear is set prior to updating ...


8

What I do is add the following to my .vimrc: set undofile set undodir=~/.vim/undo/ That way all your undo/change tree information is saved across vim sessions, and next time you open your file you can still undo/redo old edits.


8

Vim's modal editing is often viewed as an operator (e.g. c, d, ...) applied over a motion (e.g. iw, w, }, ...). As a wonderful by product Vim gets chunky undo's. Where as other editors have to do some guessing to make many small undo's into undo blocks, Vim does this naturally. Another side affect is this gives you a repeat operator, . (aka the dot command). ...


6

You can think of it this way too: every time you go to insert mode to edit text and you hit Esc, that will form a block. If you try to undo that block, you will go to the same position before you entered insert mode. Therefore you can "save" your changes just by exiting insert mode from time to time: let's say you go to insert mode and write a function. ...


6

Here is the full list of settings which should be added to your .vimrc if you want to prevent any leakage of sensitive files. set nobackup set nowritebackup set noundofile set noswapfile set viminfo="" set noshelltemp set history=0 set nomodeline set secure I recommend you create a new configuration file called .vimrc_secure and run Vim with vim -u ~/....


5

Since the undo command in Vi will act as a re-do when the last command was undo, I have used uu as a means to go back to where I last edited. If you're running Vim with nocompatible set (as most people do), you want to use u followed by CTRL+R to undo & redo. Otherwise uu will work as in Vi.


4

Apart of John solution, there is another way to show all vim keystrokes which were pressed by using -w parameter which record all the characters that you type in the file. The problem is, that vim writes keystrokes only when you exit Vim. This is how VimGolf works. To workaround this, Kana Natsuno came up with this single-line patch, which disables ...


4

Check out Ctrl-P's MRU feature. Once you've installed it, type :CtrlPMRUFiles and it'll pop open a fuzzy finder at the bottom of the screen that you can fuzzy search through.


4

You could use the feedkeys() function to add the keys q: inside the typeahead buffer: call feedkeys('q:', 'in') feedkeys() waits for one argument (the keys you want to add), and a 2nd optional one which contains some flags. In the previous command, 2 flags are used i and n. i means that the keys won't be appended to the typeahead buffer but inserted (...


3

There is no way to do it and it is normal that there isn't: normal mode commands are generally pretty short and can be cancelled with Esc if you mess it. A possible workaround would be to use the :normal command. It makes the process longer but for example if you type :normal 10j in the command line, Vim will execute 10j as if you typed it in normal mode. (...


2

I have the following in my vimrc to force regular behavior of enter in certain situations: augroup vimrc_CRfix au! " Quickfix, Location list, &c. remap <CR> to work as expected autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR> autocmd CmdwinEnter * nnoremap <buffer> <CR> <CR> augroup END I ...


2

You can edit the search history with the following,: histadd(), histget(), and histdel(). See :h histadd() for more help.


2

There is no direct equivalent of such behaviour of libreadline, but since Vim 7.4.2268 you can navigate through search matches when 'incsearch' option is on without leaving search mode via Ctrl-G/Ctrl-T keys, which combined with command-line window can give you experience similar to what you seek. It's very easy if you know that you're going to use search ...


2

I always use -s SCRIPT_FILE_NAME option to execute additional commands. In SCRIPT_FILE_NAME, some ex commands are written. So -s {scriptin} or the equivalent :source! command are meant to read the contents of a file and execute those as Normal mode commands. They fully reuse normal mode key processing. As such, Ex commands entered with : will be added to ...


2

I'm not aware that this is possible. The only thing I know is, that Vim uses the already typed characters to filter the history. If you previously executed: :%s/This/That/g and you want to get this command again, you do :%s/T<up> This will get only commands that start with %s/T from the history. See :help c_Up for more details.


1

One other thing that you can do is use <Ctrl-P> to go to the 'Previous' command. This is also works in bash terminals. You can also do <Ctrl-N> to go to the 'Next' command.


1

I got my answer from here: Using command line history in vim Here is a summary to execute your command of choice from command history: q: (opens the command history window) use vim browsing keys to go to the command you want to execute. Alternately :n where n is line number of the command to execute, will place you on the line. CR -> (Carriage return) ...


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