Question:
In vi, how can I see the last command I just typed in? Drives me crazy to retype long lines over and over?
anonymous
1970-01-01 00:00:00 UTC
In vi, how can I see the last command I just typed in? Drives me crazy to retype long lines over and over?
Three answers:
Mark G
2007-12-12 18:12:08 UTC
Try



@



It should pull the last command from the buffer.
Cirric
2007-12-12 18:09:37 UTC
Hi. I think you have to create or recall a buffer. Sorry I don't have the details. I think it involves the 'General purpose' buffer.
Fred W
2007-12-12 10:08:47 UTC
Shana



First, you are probably not using vi. More likely vim. And, if you are NOT using vim, get it -- key/macro/etc. compatible with lots of good features.



Try ':ver' to see if you are using VIM.



And, if you are, retrieving previous commands is really easy:



':' up-arrow



Retrieving previous search string:



'/' up-arrow



In both vi and vim, to redo the last command (even after you move the cursor), try '.' (single period key).



VIM, if you aren't already using it, also has an undo stack (vi only allows a single undo).



Hope this helps -- add more detail if you have other questions.



Shana - very strange ?? What version of VIM is it (5.x, 6.x) and what platform (Linux, Solaris, Windows). Are you using "terminal" vim, or gvim?



------



VIM uses 'readline' -- given that you mentioned 'alias' I assume that you are on Linux (or Solaris), and not Windows. Make sure (apt, yum, whichever flavour) that 'readline' is installed.



I don't think its the configuration, but I have posted my .vimrc below. I use this .vimrc on Linux (2.4 kernel, VIM 5, 2.6 kernel with VIM 7, and Solaris 10 with VIM 6), with gvim, and vim (and with a wyse-30 terminal as well):



--> cut <--

" .vimrc



" Terminal switches to underline mode if these are not suppressed.

" Delete line isn't very good either (doesn't work the way terminfo says)

" What is left is the problem that ^F is arrow right.

"if &t_Co <= 2

" set t_ve=

" set t_vs=

" set t_dl=

" set t_kh=

" set t_kr=

" set t_kd=

" set t_ku=

" set t_kl=

"endif

set nocompatible

set backspace=indent,eol,start

set autoindent

set backup

set history=50

set ruler

set number

set noshowcmd

set incsearch

if &t_Co <= 2

set noruler

set noincsearch

set nonumber

endif

if &t_Co > 2 || has("gui_running")

syntax on

set hlsearch

set mouse=a

endif

if has("autocmd")

filetype plugin indent on

autocmd FileType text setlocal textwidth=78

autocmd BufReadPost *

\ if line("'\"") > 0 && line("'\"") <= line("$") |

\ exe "normal g`\"" |

\ endif

endif

let b:nroff_is_groff = 1

set shiftwidth=4

set softtabstop=4

set tabstop=8



-->cut<--



All other settings are "defaulted". When you start VIM, use the ':ver' command -- this is what I get:



:ver

VIM - Vi IMproved 7.0 (2006 May 7, compiled Jul 25 2006 10:54:57)

Included patches: 1-4, 7-17, 19-26, 29-31, 33-42

Modified by

Compiled by

Huge version without GUI. Features included (+) or not (-):

+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent

-clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments

+cryptv +cscope +cursorshape +dialog_con +diff +digraphs -dnd -ebcdic

+emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path

+folding -footer +fork() +gettext -hangul_input +iconv +insert_expand +jumplist

+keymap +langmap +libcall +linebreak +lispindent +listcmds +localmap +menu

+mksession +modify_fname +mouse -mouseshape +mouse_dec +mouse_gpm

-mouse_jsbterm +mouse_netterm +mouse_xterm +multi_byte +multi_lang -mzscheme

-netbeans_intg -osfiletype +path_extra +perl +postscript +printer +profile

+python +quickfix +reltime +rightleft -ruby +scrollbind +signs +smartindent

-sniff +statusline -sun_workshop +syntax +tag_binary +tag_old_static

-tag_any_white -tcl +terminfo +termresponse +textobjects +title -toolbar

+user_commands +vertsplit +virtualedit +visual +visualextra +viminfo +vreplace

+wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp

-xterm_clipboard -xterm_save

system vimrc file: "/etc/vimrc"

user vimrc file: "$HOME/.vimrc"



Notice that I have +cmdline_hist. If yours has -cmdline_hist, you won't have the history feature. Some distributions have the option of a "minimal" vim or a full vim. Choose the full vim option, and try it again. Minimal is quite feature reduced! (saves on memory, but even the full version is fine on 128MB machines!).



Hope this additional detail helps.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...