vim move to first non-blank in same column
In vim, how can I move the cursor down (or up) to the first line
containing a non-blank character in the same column ?
For example, in the following text:
item1
item2
item3
item4
item5
item6
If the cursor is on the e
in item1
, move the cursor to the e
in item4
.
If on the m
in item3
, move to the m
in item5
.
FYI, I'm looking for a quick and efficient way to navigate formatted text.
(P.S. Those are spaces not tabs.)
vim
add a comment |
In vim, how can I move the cursor down (or up) to the first line
containing a non-blank character in the same column ?
For example, in the following text:
item1
item2
item3
item4
item5
item6
If the cursor is on the e
in item1
, move the cursor to the e
in item4
.
If on the m
in item3
, move to the m
in item5
.
FYI, I'm looking for a quick and efficient way to navigate formatted text.
(P.S. Those are spaces not tabs.)
vim
add a comment |
In vim, how can I move the cursor down (or up) to the first line
containing a non-blank character in the same column ?
For example, in the following text:
item1
item2
item3
item4
item5
item6
If the cursor is on the e
in item1
, move the cursor to the e
in item4
.
If on the m
in item3
, move to the m
in item5
.
FYI, I'm looking for a quick and efficient way to navigate formatted text.
(P.S. Those are spaces not tabs.)
vim
In vim, how can I move the cursor down (or up) to the first line
containing a non-blank character in the same column ?
For example, in the following text:
item1
item2
item3
item4
item5
item6
If the cursor is on the e
in item1
, move the cursor to the e
in item4
.
If on the m
in item3
, move to the m
in item5
.
FYI, I'm looking for a quick and efficient way to navigate formatted text.
(P.S. Those are spaces not tabs.)
vim
vim
edited May 16 '14 at 14:12
Lqueryvg
asked May 16 '14 at 12:29
LqueryvgLqueryvg
473210
473210
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You could use the following mappings to do this. (There might be some edge cases I didn't think of)
nnoremap <leader>d m':exec '/%' . col(".") . 'cS'<CR>``n
nnoremap <leader>u m':exec '?%' . col(".") . 'cS'<CR>``n
The important part is :exec '/%' . col(".") . 'c'
This matches the current column. This is taken directly from :h %c
. Then I added a S
to match non whitespace. m'
and ``
is used to store the current position and restore it around the execute statement. This is necessary since using the execute places us at the start of the line which could lead to erratic behavior (skipping too many lines in some cases). After executing this I go to the first match with n
. The only difference between the up and down version is which direction we search /
for down and ?
for up.
If you instead wanted to do this with virtual columns (i.e. tabs) replace %c
with %v
.
1
That's superb; it's exactly what I was looking for! I think I will map these to<leader>j
and<leader>k
respectively. The only thing I will add is:noh
to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !
– Lqueryvg
May 16 '14 at 17:59
1
@Lqueryvg while it does clobber the search register you can still usen
andN
to move up and down the column.
– FDinoff
May 16 '14 at 18:00
Even better ! Thanks again!!
– Lqueryvg
May 16 '14 at 18:06
add a comment |
My JumpToVerticalOccurrence plugin provides ]|
and [|
mappings that provide just that, supporting [count]
and without clobbering the current search pattern.
Thanks for this. I will explore the plugin as well as the "one-liner" solution.
– Lqueryvg
May 20 '14 at 8:43
add a comment |
If you want this for code or configuration files with a defined indentation system (assuming that falls under "formatted text"), jeetsukumaran/vim-indentwise works well for relative, absolute, or block-scope movements across indented blocks.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f755122%2fvim-move-to-first-non-blank-in-same-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could use the following mappings to do this. (There might be some edge cases I didn't think of)
nnoremap <leader>d m':exec '/%' . col(".") . 'cS'<CR>``n
nnoremap <leader>u m':exec '?%' . col(".") . 'cS'<CR>``n
The important part is :exec '/%' . col(".") . 'c'
This matches the current column. This is taken directly from :h %c
. Then I added a S
to match non whitespace. m'
and ``
is used to store the current position and restore it around the execute statement. This is necessary since using the execute places us at the start of the line which could lead to erratic behavior (skipping too many lines in some cases). After executing this I go to the first match with n
. The only difference between the up and down version is which direction we search /
for down and ?
for up.
If you instead wanted to do this with virtual columns (i.e. tabs) replace %c
with %v
.
1
That's superb; it's exactly what I was looking for! I think I will map these to<leader>j
and<leader>k
respectively. The only thing I will add is:noh
to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !
– Lqueryvg
May 16 '14 at 17:59
1
@Lqueryvg while it does clobber the search register you can still usen
andN
to move up and down the column.
– FDinoff
May 16 '14 at 18:00
Even better ! Thanks again!!
– Lqueryvg
May 16 '14 at 18:06
add a comment |
You could use the following mappings to do this. (There might be some edge cases I didn't think of)
nnoremap <leader>d m':exec '/%' . col(".") . 'cS'<CR>``n
nnoremap <leader>u m':exec '?%' . col(".") . 'cS'<CR>``n
The important part is :exec '/%' . col(".") . 'c'
This matches the current column. This is taken directly from :h %c
. Then I added a S
to match non whitespace. m'
and ``
is used to store the current position and restore it around the execute statement. This is necessary since using the execute places us at the start of the line which could lead to erratic behavior (skipping too many lines in some cases). After executing this I go to the first match with n
. The only difference between the up and down version is which direction we search /
for down and ?
for up.
If you instead wanted to do this with virtual columns (i.e. tabs) replace %c
with %v
.
1
That's superb; it's exactly what I was looking for! I think I will map these to<leader>j
and<leader>k
respectively. The only thing I will add is:noh
to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !
– Lqueryvg
May 16 '14 at 17:59
1
@Lqueryvg while it does clobber the search register you can still usen
andN
to move up and down the column.
– FDinoff
May 16 '14 at 18:00
Even better ! Thanks again!!
– Lqueryvg
May 16 '14 at 18:06
add a comment |
You could use the following mappings to do this. (There might be some edge cases I didn't think of)
nnoremap <leader>d m':exec '/%' . col(".") . 'cS'<CR>``n
nnoremap <leader>u m':exec '?%' . col(".") . 'cS'<CR>``n
The important part is :exec '/%' . col(".") . 'c'
This matches the current column. This is taken directly from :h %c
. Then I added a S
to match non whitespace. m'
and ``
is used to store the current position and restore it around the execute statement. This is necessary since using the execute places us at the start of the line which could lead to erratic behavior (skipping too many lines in some cases). After executing this I go to the first match with n
. The only difference between the up and down version is which direction we search /
for down and ?
for up.
If you instead wanted to do this with virtual columns (i.e. tabs) replace %c
with %v
.
You could use the following mappings to do this. (There might be some edge cases I didn't think of)
nnoremap <leader>d m':exec '/%' . col(".") . 'cS'<CR>``n
nnoremap <leader>u m':exec '?%' . col(".") . 'cS'<CR>``n
The important part is :exec '/%' . col(".") . 'c'
This matches the current column. This is taken directly from :h %c
. Then I added a S
to match non whitespace. m'
and ``
is used to store the current position and restore it around the execute statement. This is necessary since using the execute places us at the start of the line which could lead to erratic behavior (skipping too many lines in some cases). After executing this I go to the first match with n
. The only difference between the up and down version is which direction we search /
for down and ?
for up.
If you instead wanted to do this with virtual columns (i.e. tabs) replace %c
with %v
.
edited May 16 '14 at 17:26
answered May 16 '14 at 17:17
FDinoffFDinoff
1,5431718
1,5431718
1
That's superb; it's exactly what I was looking for! I think I will map these to<leader>j
and<leader>k
respectively. The only thing I will add is:noh
to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !
– Lqueryvg
May 16 '14 at 17:59
1
@Lqueryvg while it does clobber the search register you can still usen
andN
to move up and down the column.
– FDinoff
May 16 '14 at 18:00
Even better ! Thanks again!!
– Lqueryvg
May 16 '14 at 18:06
add a comment |
1
That's superb; it's exactly what I was looking for! I think I will map these to<leader>j
and<leader>k
respectively. The only thing I will add is:noh
to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !
– Lqueryvg
May 16 '14 at 17:59
1
@Lqueryvg while it does clobber the search register you can still usen
andN
to move up and down the column.
– FDinoff
May 16 '14 at 18:00
Even better ! Thanks again!!
– Lqueryvg
May 16 '14 at 18:06
1
1
That's superb; it's exactly what I was looking for! I think I will map these to
<leader>j
and <leader>k
respectively. The only thing I will add is :noh
to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !– Lqueryvg
May 16 '14 at 17:59
That's superb; it's exactly what I was looking for! I think I will map these to
<leader>j
and <leader>k
respectively. The only thing I will add is :noh
to the end of each to clear highlights. I also note this would clobber any previous search or highlights that may have been in place, but this essentially does what I wanted. Thanks !– Lqueryvg
May 16 '14 at 17:59
1
1
@Lqueryvg while it does clobber the search register you can still use
n
and N
to move up and down the column.– FDinoff
May 16 '14 at 18:00
@Lqueryvg while it does clobber the search register you can still use
n
and N
to move up and down the column.– FDinoff
May 16 '14 at 18:00
Even better ! Thanks again!!
– Lqueryvg
May 16 '14 at 18:06
Even better ! Thanks again!!
– Lqueryvg
May 16 '14 at 18:06
add a comment |
My JumpToVerticalOccurrence plugin provides ]|
and [|
mappings that provide just that, supporting [count]
and without clobbering the current search pattern.
Thanks for this. I will explore the plugin as well as the "one-liner" solution.
– Lqueryvg
May 20 '14 at 8:43
add a comment |
My JumpToVerticalOccurrence plugin provides ]|
and [|
mappings that provide just that, supporting [count]
and without clobbering the current search pattern.
Thanks for this. I will explore the plugin as well as the "one-liner" solution.
– Lqueryvg
May 20 '14 at 8:43
add a comment |
My JumpToVerticalOccurrence plugin provides ]|
and [|
mappings that provide just that, supporting [count]
and without clobbering the current search pattern.
My JumpToVerticalOccurrence plugin provides ]|
and [|
mappings that provide just that, supporting [count]
and without clobbering the current search pattern.
answered May 16 '14 at 19:06
Ingo KarkatIngo Karkat
17.4k22343
17.4k22343
Thanks for this. I will explore the plugin as well as the "one-liner" solution.
– Lqueryvg
May 20 '14 at 8:43
add a comment |
Thanks for this. I will explore the plugin as well as the "one-liner" solution.
– Lqueryvg
May 20 '14 at 8:43
Thanks for this. I will explore the plugin as well as the "one-liner" solution.
– Lqueryvg
May 20 '14 at 8:43
Thanks for this. I will explore the plugin as well as the "one-liner" solution.
– Lqueryvg
May 20 '14 at 8:43
add a comment |
If you want this for code or configuration files with a defined indentation system (assuming that falls under "formatted text"), jeetsukumaran/vim-indentwise works well for relative, absolute, or block-scope movements across indented blocks.
add a comment |
If you want this for code or configuration files with a defined indentation system (assuming that falls under "formatted text"), jeetsukumaran/vim-indentwise works well for relative, absolute, or block-scope movements across indented blocks.
add a comment |
If you want this for code or configuration files with a defined indentation system (assuming that falls under "formatted text"), jeetsukumaran/vim-indentwise works well for relative, absolute, or block-scope movements across indented blocks.
If you want this for code or configuration files with a defined indentation system (assuming that falls under "formatted text"), jeetsukumaran/vim-indentwise works well for relative, absolute, or block-scope movements across indented blocks.
answered Jan 4 at 13:46
HarryHarry
1012
1012
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f755122%2fvim-move-to-first-non-blank-in-same-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown