@@ -2460,6 +2460,22 @@ mod cmd {
24602460 Ok(())
24612461 }
24622462
2463+ pub(super) fn goto_line_number(
2464+ cx: &mut compositor::Context,
2465+ args: &[&str],
2466+ _event: PromptEvent,
2467+ ) -> anyhow::Result<()> {
2468+ let line = args[0].parse::<usize>()?;
2469+
2470+ goto_line_impl(&mut cx.editor, NonZeroUsize::new(line));
2471+
2472+ let (view, doc) = current!(cx.editor);
2473+
2474+ view.ensure_cursor_in_view(doc, line);
2475+
2476+ Ok(())
2477+ }
2478+
24632479 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
24642480 TypableCommand {
24652481 name: "quit",
@@ -2741,6 +2757,13 @@ mod cmd {
27412757 fun: tutor,
27422758 completer: None,
27432759 },
2760+ TypableCommand {
2761+ name: "goto",
2762+ aliases: &["g"],
2763+ doc: "Go to line number.",
2764+ fun: goto_line_number,
2765+ completer: None,
2766+ }
27442767 ];
27452768
27462769 pub static COMMANDS: Lazy<HashMap<&'static str, &'static TypableCommand>> = Lazy::new(|| {
@@ -2803,6 +2826,15 @@ fn command_mode(cx: &mut Context) {
28032826 return;
28042827 }
28052828
2829+ // If command is numeric, interpret as line number and go there.
2830+ if parts.len() == 1 && parts[0].parse::<usize>().ok().is_some() {
2831+ if let Err(e) = cmd::goto_line_number(cx, &parts[0..], event) {
2832+ cx.editor.set_error(format!("{}", e));
2833+ }
2834+ return;
2835+ }
2836+
2837+ // Handle typable commands
28062838 if let Some(cmd) = cmd::COMMANDS.get(parts[0]) {
28072839 if let Err(e) = (cmd.fun)(cx, &parts[1..], event) {
28082840 cx.editor.set_error(format!("{}", e));
@@ -3436,10 +3468,14 @@ fn push_jump(editor: &mut Editor) {
34363468}
34373469
34383470fn goto_line(cx: &mut Context) {
3439− if let Some(count) = cx.count {
3440− push_jump(cx.editor);
3471+ goto_line_impl(&mut cx.editor, cx.count)
3472+}
34413473
3442− let (view, doc) = current!(cx.editor);
3474+fn goto_line_impl(editor: &mut Editor, count: Option<NonZeroUsize>) {
3475+ if let Some(count) = count {
3476+ push_jump(editor);
3477+
3478+ let (view, doc) = current!(editor);
34433479 let max_line = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
34443480 // If the last line is blank, don't jump to it.
34453481 doc.text().len_lines().saturating_sub(2)