I am new to ubuntu. I am using vim for quite sometime now. I came across autocmd BufNewFile command to automatically add some text when a file with some particular etension is created.I have attached the pic of how it looks after that command. But I want the cursor to be in a different position rather than line 9.
I want the cursor to be on line 6.
Asked
Active
Viewed 268 times
4
Seth
- 57,282
- 43
- 144
- 200
K. Chidambaram
- 41
- 1
-
Welcome to Ask Ubuntu! Just so you know, there is also [a Stack Exchange site specifically for Vi and Vim](https://vi.stackexchange.com/). Of course, [make sure your question would be on-topic there](https://vi.stackexchange.com/help/on-topic), and please [_do not_ post an exact copy of your question there](https://meta.stackexchange.com/q/64068/1081494). Your question is good here, but I wanted to let you know about that site as well. – cocomac Nov 05 '21 at 05:03
-
@Algnis Please don't put a signature inside image alt text. If you don't want to create alt text that's fair enough, but please don't put incorrect information in instead. Thanks! – Seth Nov 07 '21 at 17:19
2 Answers
4
If you want to move to (for instance) line 10 in the file, you would type :10
You can put commands like this on the command line with vim +10
user10489
- 3,564
- 2
- 5
- 22
-
4In this case, OP just needs to add `| :6` their `autocmd` to have the cursor be at line 6 when the autocmd completes. – muru Nov 05 '21 at 05:33
-
It's also possible to go to a particular line (and column) py appending a ":normal" command to the command line, like: `vim '+normal 6G10|'` – MDeBusk Jun 03 '22 at 00:18
0
So, let's say you are on line 9 and want to be on line 3.
You could push k 6 times. Or you could type 6 k or you could (as suggested in the other answer) type :3return or you could type 3g.
There's a number of other combinations that would work as well.
user10489
- 3,564
- 2
- 5
- 22