@@ -2460,6 +2460,22 @@ mod cmd {
2463+ pub(super) fn goto_line_number(
2464+ cx: &mut compositor::Context,
2466+ _event: PromptEvent,
2467+ ) -> anyhow::Result<()> {
2468+ let line = args[0].parse::<usize>()?;
2470+ goto_line_impl(&mut cx.editor, NonZeroUsize::new(line));
2472+ let (view, doc) = current!(cx.editor);
2474+ view.ensure_cursor_in_view(doc, line);
2463 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2479 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2464 TypableCommand {
2480 TypableCommand {
2465 name: "quit",
2481 name: "quit",
@@ -2741,6 +2757,13 @@ mod cmd {
2741 fun: tutor,
2757 fun: tutor,
2742 completer: None,
2758 completer: None,
2763+ doc: "Go to line number.",
2764+ fun: goto_line_number,
2746 pub static COMMANDS: Lazy<HashMap<&'static str, &'static TypableCommand>> = Lazy::new(|| {
2769 pub static COMMANDS: Lazy<HashMap<&'static str, &'static TypableCommand>> = Lazy::new(|| {
@@ -2803,6 +2826,15 @@ fn command_mode(cx: &mut Context) {
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));
2837+ // Handle typable commands
2806 if let Some(cmd) = cmd::COMMANDS.get(parts[0]) {
2838 if let Some(cmd) = cmd::COMMANDS.get(parts[0]) {
2807 if let Err(e) = (cmd.fun)(cx, &parts[1..], event) {
2839 if let Err(e) = (cmd.fun)(cx, &parts[1..], event) {
2808 cx.editor.set_error(format!("{}", e));
2840 cx.editor.set_error(format!("{}", e));
@@ -3436,10 +3468,14 @@ fn push_jump(editor: &mut Editor) {
3438fn goto_line(cx: &mut Context) {
3470fn goto_line(cx: &mut Context) {
3439− if let Some(count) = cx.count {
3471+ goto_line_impl(&mut cx.editor, cx.count)
3440− push_jump(cx.editor);
3472+}
3474+fn goto_line_impl(editor: &mut Editor, count: Option<NonZeroUsize>) {
3475+ if let Some(count) = count {
3442− let (view, doc) = current!(cx.editor);
3478+ let (view, doc) = current!(editor);
3443 let max_line = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
3479 let max_line = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
3444 // If the last line is blank, don't jump to it.
3480 // If the last line is blank, don't jump to it.
3445 doc.text().len_lines().saturating_sub(2)
3481 doc.text().len_lines().saturating_sub(2)